Corrected session initiation logic

This commit is contained in:
netkas 2025-01-27 03:38:11 -05:00
parent efc74cfa49
commit 93eff1320f

View file

@ -243,9 +243,10 @@
self::returnError(403, StandardError::FORBIDDEN, 'Unauthorized: The requested peer is disabled/banned'); self::returnError(403, StandardError::FORBIDDEN, 'Unauthorized: The requested peer is disabled/banned');
return; return;
} }
// If-clause for handling the host peer, host peers are always enabled unless the fist clause is true // If-clause for handling the host peer, host peers are always enabled unless the fist clause is true
// in which case the host was blocked by this server. // in which case the host was blocked by this server.
elseif($clientRequest->getIdentifyAs()->getUsername() === ReservedUsernames::HOST->value) if($clientRequest->getIdentifyAs()->getUsername() === ReservedUsernames::HOST->value)
{ {
// If the host is not registered, register it // If the host is not registered, register it
if($registeredPeer === null) if($registeredPeer === null)
@ -262,8 +263,8 @@
} }
} }
} }
// Otherwise the peer isn't registered, so we need to register it
else if($registeredPeer === null)
{ {
// Check if registration is enabled // Check if registration is enabled
if(!Configuration::getRegistrationConfiguration()->isRegistrationEnabled()) if(!Configuration::getRegistrationConfiguration()->isRegistrationEnabled())
@ -290,22 +291,24 @@
clientPublicEncryptionKey: $clientPublicEncryptionKey, clientPublicEncryptionKey: $clientPublicEncryptionKey,
serverEncryptionKeyPair: $serverEncryptionKeyPair serverEncryptionKeyPair: $serverEncryptionKeyPair
); );
// The server responds back with the session UUID & The server's public encryption key as the header
http_response_code(201); // Created
header('Content-Type: text/plain');
header(StandardHeaders::ENCRYPTION_PUBLIC_KEY->value . ': ' . $serverEncryptionKeyPair->getPublicKey());
print($sessionUuid); // Return the session UUID
} }
catch(InvalidArgumentException $e) catch(InvalidArgumentException $e)
{ {
// This is usually thrown due to an invalid input // This is usually thrown due to an invalid input
self::returnError(400, StandardError::BAD_REQUEST, $e->getMessage(), $e); self::returnError(400, StandardError::BAD_REQUEST, $e->getMessage(), $e);
return;
} }
catch(Exception $e) catch(Exception $e)
{ {
self::returnError(500, StandardError::INTERNAL_SERVER_ERROR, 'An internal error occurred while initiating the session', $e); self::returnError(500, StandardError::INTERNAL_SERVER_ERROR, 'An internal error occurred while initiating the session', $e);
return;
} }
// The server responds back with the session UUID & The server's public encryption key as the header
http_response_code(201); // Created
header('Content-Type: text/plain');
header(StandardHeaders::ENCRYPTION_PUBLIC_KEY->value . ': ' . $serverEncryptionKeyPair->getPublicKey());
print($sessionUuid); // Return the session UUID
} }
/** /**