Dont abort a session when there is an invalid FTN presented

This commit is contained in:
Deon George 2023-09-18 21:22:21 +10:00
parent eb40f94e37
commit 4343774079
4 changed files with 36 additions and 16 deletions

View File

@ -12,7 +12,7 @@ use App\Classes\Crypt;
use App\Classes\Protocol as BaseProtocol; use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\SocketClient; use App\Classes\Sock\SocketClient;
use App\Classes\Sock\SocketException; use App\Classes\Sock\SocketException;
use App\Exceptions\FileGrewException; use App\Exceptions\{FileGrewException,InvalidFTNException};
use App\Models\Address; use App\Models\Address;
final class Binkp extends BaseProtocol final class Binkp extends BaseProtocol
@ -700,6 +700,11 @@ final class Binkp extends BaseProtocol
Log::info(sprintf('%s:- Got AKA [%s]',self::LOGKEY,$rem_aka)); Log::info(sprintf('%s:- Got AKA [%s]',self::LOGKEY,$rem_aka));
} }
} catch (InvalidFTNException $e) {
Log::error(sprintf('%s:! AKA is INVALID [%s] (%s), ignoring',self::LOGKEY,$rem_aka,$e->getMessage()));
continue;
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error(sprintf('%s:! AKA is INVALID [%s] (%d:%s-%s)',self::LOGKEY,$rem_aka,$e->getLine(),$e->getFile(),$e->getMessage())); Log::error(sprintf('%s:! AKA is INVALID [%s] (%d:%s-%s)',self::LOGKEY,$rem_aka,$e->getLine(),$e->getFile(),$e->getMessage()));

View File

@ -3,12 +3,12 @@
namespace App\Classes\Protocol; namespace App\Classes\Protocol;
use Carbon\Carbon; use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use App\Classes\Protocol as BaseProtocol; use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\SocketClient; use App\Classes\Sock\SocketClient;
use App\Classes\Sock\SocketException; use App\Classes\Sock\SocketException;
use App\Exceptions\InvalidFTNException;
use App\Models\{Address,Setup}; use App\Models\{Address,Setup};
use App\Interfaces\CRC as CRCInterface; use App\Interfaces\CRC as CRCInterface;
use App\Interfaces\Zmodem as ZmodemInterface; use App\Interfaces\Zmodem as ZmodemInterface;
@ -88,7 +88,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* @param SocketClient $client * @param SocketClient $client
* @return int|null * @return int|null
* @throws SocketException * @throws SocketException
* @throws Exception * @throws \Exception
*/ */
public function onConnect(SocketClient $client): ?int public function onConnect(SocketClient $client): ?int
{ {
@ -108,7 +108,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
/** /**
* Send our welcome banner * Send our welcome banner
* *
* @throws Exception * @throws \Exception
*/ */
private function emsi_banner(): void private function emsi_banner(): void
{ {
@ -123,7 +123,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* Create the EMSI_DAT * Create the EMSI_DAT
* *
* @return string * @return string
* @throws Exception * @throws \Exception
*/ */
private function emsi_makedat(): string private function emsi_makedat(): string
{ {
@ -273,7 +273,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* *
* @param string $str * @param string $str
* @return int * @return int
* @throws Exception * @throws \Exception
*/ */
private function emsi_parsedat(string $str): int private function emsi_parsedat(string $str): int
{ {
@ -328,10 +328,15 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
continue; continue;
} }
} catch (Exception) { } catch (InvalidFTNException $e) {
Log::error(sprintf('%s: ! AKA is INVALID [%s]',self::LOGKEY,$rem_aka)); Log::error(sprintf('%s:! AKA is INVALID [%s] (%s), ignoring',self::LOGKEY,$rem_aka,$e->getMessage()));
continue; continue;
} catch (\Exception) {
Log::error(sprintf('%s: ! AKA is INVALID [%s]',self::LOGKEY,$rem_aka));
return self::S_FAILURE|self::S_ADDTRY;
} }
// Check if the remote has our AKA // Check if the remote has our AKA
@ -504,7 +509,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* STEP 2A, RECEIVE EMSI HANDSHAKE * STEP 2A, RECEIVE EMSI HANDSHAKE
* *
* @throws SocketException * @throws SocketException
* @throws Exception * @throws \Exception
*/ */
private function emsi_recv(int $mode): int private function emsi_recv(int $mode): int
{ {
@ -683,7 +688,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* STEP 2B, TRANSMIT EMSI HANDSHAKE * STEP 2B, TRANSMIT EMSI HANDSHAKE
* *
* @throws SocketException * @throws SocketException
* @throws Exception * @throws \Exception
*/ */
private function emsi_send(): int private function emsi_send(): int
{ {
@ -822,7 +827,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* STEP 1, EMSI INIT * STEP 1, EMSI INIT
* *
* @throws SocketException * @throws SocketException
* @throws Exception * @throws \Exception
*/ */
protected function protocol_init(): int protected function protocol_init(): int
{ {
@ -969,7 +974,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* Setup our EMSI session * Setup our EMSI session
* *
* @return int * @return int
* @throws Exception * @throws \Exception
*/ */
protected function protocol_session(): int protected function protocol_session(): int
{ {
@ -1194,7 +1199,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* *
* @param int $zap * @param int $zap
* @return bool * @return bool
* @throws Exception * @throws \Exception
*/ */
private function wazoosend(int $zap): bool private function wazoosend(int $zap): bool
{ {

View File

@ -0,0 +1,9 @@
<?php
namespace App\Exceptions;
use Exception;
class InvalidFTNException extends Exception
{
}

View File

@ -9,6 +9,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use App\Classes\FTN\{Message,Packet}; use App\Classes\FTN\{Message,Packet};
use App\Exceptions\InvalidFTNException;
use App\Http\Controllers\DomainController; use App\Http\Controllers\DomainController;
use App\Traits\ScopeActive; use App\Traits\ScopeActive;
@ -821,16 +822,16 @@ class Address extends Model
public static function parseFTN(string $ftn): array public static function parseFTN(string $ftn): array
{ {
if (! preg_match(sprintf('#^%s$#',self::ftn_regex),strtolower($ftn),$matches)) if (! preg_match(sprintf('#^%s$#',self::ftn_regex),strtolower($ftn),$matches))
throw new \Exception('Invalid FTN: '.$ftn); throw new InvalidFTNException(sprintf('Invalid FTN: %s - regex failed',$ftn));
// Check our numbers are correct. // Check our numbers are correct.
foreach ([1,2,3] as $i) { foreach ([1,2,3] as $i) {
if ((! is_numeric($matches[$i])) || ($matches[$i] > DomainController::NUMBER_MAX)) if ((! is_numeric($matches[$i])) || ($matches[$i] > DomainController::NUMBER_MAX))
throw new \Exception('Invalid FTN: '.$ftn); throw new InvalidFTNException(sprintf('Invalid FTN: %s - zone, host or node address invalid',$ftn));
} }
if (isset($matches[5]) AND ((! is_numeric($matches[$i])) || ($matches[5] > DomainController::NUMBER_MAX))) if (isset($matches[5]) AND ((! is_numeric($matches[$i])) || ($matches[5] > DomainController::NUMBER_MAX)))
throw new \Exception('Invalid FTN: '.$ftn); throw new InvalidFTNException(sprintf('Invalid FTN: %s - point address invalid',$ftn));
return [ return [
'z'=>(int)$matches[1], 'z'=>(int)$matches[1],