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\Sock\SocketClient;
use App\Classes\Sock\SocketException;
use App\Exceptions\FileGrewException;
use App\Exceptions\{FileGrewException,InvalidFTNException};
use App\Models\Address;
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));
}
} catch (InvalidFTNException $e) {
Log::error(sprintf('%s:! AKA is INVALID [%s] (%s), ignoring',self::LOGKEY,$rem_aka,$e->getMessage()));
continue;
} catch (\Exception $e) {
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;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol as BaseProtocol;
use App\Classes\Sock\SocketClient;
use App\Classes\Sock\SocketException;
use App\Exceptions\InvalidFTNException;
use App\Models\{Address,Setup};
use App\Interfaces\CRC as CRCInterface;
use App\Interfaces\Zmodem as ZmodemInterface;
@ -88,7 +88,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* @param SocketClient $client
* @return int|null
* @throws SocketException
* @throws Exception
* @throws \Exception
*/
public function onConnect(SocketClient $client): ?int
{
@ -108,7 +108,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
/**
* Send our welcome banner
*
* @throws Exception
* @throws \Exception
*/
private function emsi_banner(): void
{
@ -123,7 +123,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* Create the EMSI_DAT
*
* @return string
* @throws Exception
* @throws \Exception
*/
private function emsi_makedat(): string
{
@ -273,7 +273,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*
* @param string $str
* @return int
* @throws Exception
* @throws \Exception
*/
private function emsi_parsedat(string $str): int
{
@ -328,10 +328,15 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
continue;
}
} catch (Exception) {
Log::error(sprintf('%s: ! AKA is INVALID [%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) {
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
@ -504,7 +509,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* STEP 2A, RECEIVE EMSI HANDSHAKE
*
* @throws SocketException
* @throws Exception
* @throws \Exception
*/
private function emsi_recv(int $mode): int
{
@ -683,7 +688,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* STEP 2B, TRANSMIT EMSI HANDSHAKE
*
* @throws SocketException
* @throws Exception
* @throws \Exception
*/
private function emsi_send(): int
{
@ -822,7 +827,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* STEP 1, EMSI INIT
*
* @throws SocketException
* @throws Exception
* @throws \Exception
*/
protected function protocol_init(): int
{
@ -969,7 +974,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
* Setup our EMSI session
*
* @return int
* @throws Exception
* @throws \Exception
*/
protected function protocol_session(): int
{
@ -1194,7 +1199,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*
* @param int $zap
* @return bool
* @throws Exception
* @throws \Exception
*/
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 App\Classes\FTN\{Message,Packet};
use App\Exceptions\InvalidFTNException;
use App\Http\Controllers\DomainController;
use App\Traits\ScopeActive;
@ -821,16 +822,16 @@ class Address extends Model
public static function parseFTN(string $ftn): array
{
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.
foreach ([1,2,3] as $i) {
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)))
throw new \Exception('Invalid FTN: '.$ftn);
throw new InvalidFTNException(sprintf('Invalid FTN: %s - point address invalid',$ftn));
return [
'z'=>(int)$matches[1],