Implemented hide AKA, Minor Node::class changes, other fixes

This commit is contained in:
Deon George
2021-08-14 16:14:22 +10:00
parent 569201e972
commit 4048289cf3
7 changed files with 86 additions and 35 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Classes\Protocol;
use App\Models\Setup;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Arr;
@@ -24,11 +25,11 @@ final class Binkp extends BaseProtocol
private const MAX_BLKSIZE = 0x7fff; /* max block size */
/* options */
private const O_NO = 0;
private const O_WANT = 1;
private const O_WE = 2;
private const O_THEY = 4;
private const O_NEED = 8;
private const O_NO = 0; /* I/They dont a capability? */
private const O_WANT = 1; /* I want a capability, but can be persuaded */
private const O_WE = 2; /* We agree on a capability */
private const O_THEY = 4; /* They want a capability */
private const O_NEED = 8; /* I want a capability, and wont compromise */
private const O_EXT = 16;
private const O_YES = 32;
@@ -142,9 +143,23 @@ final class Binkp extends BaseProtocol
}
// If we are originating, we'll show the remote our address in the same network
// @todo Implement hiding our AKAs not in this network.
if ($this->originate)
if ($this->originate) {
if ($this->setup->optionGet(Setup::O_HIDEAKA)) {
$addresses = collect();
foreach ($this->node->aka_remote_authed as $ao)
$addresses = $addresses->merge($this->setup->system->match($ao->zone));
Log::debug(sprintf('%s: - Presenting limited AKAs [%s]',__METHOD__,$addresses->pluck('ftn')->join(',')));
} else {
$addresses = $this->setup->system->addresses;
Log::debug(sprintf('%s: - Presenting ALL our AKAs [%s]',__METHOD__,$addresses->pluck('ftn')->join(',')));
}
$this->msgs(self::BPM_ADR,$this->setup->system->addresses->pluck('ftn')->join(' '));
}
}
/**
@@ -154,16 +169,16 @@ final class Binkp extends BaseProtocol
{
Log::debug(sprintf('%s: + Start',__METHOD__));
if ($this->setup->opt_nd == self::O_WE || $this->setup->opt_nd == self::O_THEY)
if (($this->setup->opt_nd == self::O_WE) || ($this->setup->opt_nd == self::O_THEY))
$this->setup->opt_nd = self::O_NO;
if (! $this->setup->phone)
$this->setup->phone = '-Unpublished-';
if ( ! $this->optionGet(self::O_PWD) || $this->setup->opt_md != self::O_YES)
if (! $this->optionGet(self::O_PWD) || ($this->setup->opt_md != self::O_YES))
$this->setup->opt_cr = self::O_NO;
if (($this->setup->opt_cr&self::O_WE ) && ($this->setup->opt_cr&self::O_THEY)) {
if (($this->setup->opt_cr&self::O_WE) && ($this->setup->opt_cr&self::O_THEY)) {
dump('Enable crypting messages');
/*
@@ -192,10 +207,10 @@ final class Binkp extends BaseProtocol
if ($this->setup->opt_nd&self::O_WE || ($this->originate && ($this->setup->opt_nr&self::O_WANT) && $this->node->get_versionint() > 100))
$this->setup->opt_nr |= self::O_WE;
if (($this->setup->opt_cht&self::O_WE ) && ($this->setup->opt_cht&self::O_WANT))
if (($this->setup->opt_cht&self::O_WE) && ($this->setup->opt_cht&self::O_WANT))
$this->setup->opt_cht = self::O_YES;
$this->setup->opt_mb = ($this->node->get_versionint() > 100 || ($this->setup->opt_mb&self::O_WE)) ? self::O_YES : self::O_NO;
$this->setup->opt_mb = (($this->node->get_versionint() > 100) || ($this->setup->opt_mb&self::O_WE)) ? self::O_YES : self::O_NO;
if ($this->node->get_versionint() > 100)
$this->sessionClear(self::SE_DELAYEOB);
@@ -665,9 +680,23 @@ final class Binkp extends BaseProtocol
$this->optionSet(self::O_PWD);
// If we are not the originator, we'll show our addresses in common.
// @todo make this an option to hideAKAs or not
if (! $this->originate)
$this->msgs(self::BPM_ADR,$this->setup->system->addresses->pluck('ftn')->join(' '));
if (! $this->originate) {
if ($this->setup->optionGet(Setup::O_HIDEAKA)) {
$addresses = collect();
foreach ($this->node->aka_remote as $ao)
$addresses = $addresses->merge($this->setup->system->match($ao->zone));
Log::debug(sprintf('%s: - Presenting limited AKAs [%s]',__METHOD__,$addresses->pluck('ftn')->join(',')));
} else {
$addresses = $this->setup->system->addresses;
Log::debug(sprintf('%s: - Presenting ALL our AKAs [%s]',__METHOD__,$addresses->pluck('ftn')->join(',')));
}
$this->msgs(self::BPM_ADR,$addresses->pluck('ftn')->join(' '));
}
return 1;
}
@@ -704,7 +733,7 @@ final class Binkp extends BaseProtocol
if (! $this->send->total_count && $this->sessionGet(self::SE_NOFILES)) {
// Add our mail to the queue if we have authenticated
if ($this->node->aka_authed)
foreach ($this->node->aka_remote as $ao) {
foreach ($this->node->aka_remote_authed as $ao) {
Log::debug(sprintf('%s: - Checking for any new mail to [%s]',__METHOD__,$ao->ftn));
$this->send->mail($ao);
}
@@ -981,7 +1010,6 @@ final class Binkp extends BaseProtocol
$data = $this->skip_blanks(substr($buf,4));
while ($data && ($p = $this->strsep($data,' '))) {
if (! strcmp($p,'NR')) {
$this->setup->opt_nr |= self::O_WE;
@@ -1046,7 +1074,7 @@ final class Binkp extends BaseProtocol
$buf = $this->skip_blanks($buf);
if (($this->optionGet(self::O_PWD)) && $buf) {
if ($this->optionGet(self::O_PWD) && $buf) {
while (($t = $this->strsep($buf," \t")))
if (strcmp($t,'non-secure') == 0) {
Log::debug(sprintf('%s: - Non Secure',__METHOD__));
@@ -1060,7 +1088,7 @@ final class Binkp extends BaseProtocol
// Add our mail to the queue if we have authenticated
if ($this->node->aka_authed)
foreach ($this->node->aka_remote as $ao) {
foreach ($this->node->aka_remote_authed as $ao) {
$this->send->mail($ao);
}
@@ -1136,7 +1164,7 @@ final class Binkp extends BaseProtocol
($this->setup->opt_nd&self::O_THEY) ? ' ND' : '',
($this->setup->opt_mb&self::O_WANT) ? ' MB' : '',
($this->setup->opt_cht&self::O_WANT) ? ' CHAT' : '',
((! ($this->setup->opt_nd&self::O_WE)) != (! ($this->setup->opt_nd&self::O_THEY))) ? ' NDA': '',
(! ($this->setup->opt_nd&self::O_WE) != (! ($this->setup->opt_nd&self::O_THEY))) ? ' NDA': '',
(($this->setup->opt_cr&self::O_WE) && ($this->setup->opt_cr&self::O_THEY )) ? ' CRYPT' : '');
if (strlen($tmp))
@@ -1144,7 +1172,7 @@ final class Binkp extends BaseProtocol
// Add our mail to the queue if we have authenticated
if ($this->node->aka_authed)
foreach ($this->node->aka_remote as $ao) {
foreach ($this->node->aka_remote_authed as $ao) {
$this->send->mail($ao);
}