Made message signing in Cryptography use SHA512 as the message content for... #1

Closed
netkas wants to merge 421 commits from master into dev
5 changed files with 68 additions and 9 deletions
Showing only changes of commit 014b63705b - Show all commits

View file

@ -76,6 +76,11 @@
$this->serverPublicKey = $resolvedServer->getPublicKey(); $this->serverPublicKey = $resolvedServer->getPublicKey();
$this->rpcEndpoint = $resolvedServer->getEndpoint(); $this->rpcEndpoint = $resolvedServer->getEndpoint();
if(empty($this->serverPublicKey))
{
throw new ResolutionException('Failed to resolve domain: No public key found for the server');
}
// Attempt to create an encrypted session with the server // Attempt to create an encrypted session with the server
$this->sessionUuid = $this->createSession(); $this->sessionUuid = $this->createSession();
$this->sendDheExchange(); $this->sendDheExchange();

View file

@ -38,22 +38,18 @@
} }
$fullRecord = self::concatenateTxtRecords($txtRecords); $fullRecord = self::concatenateTxtRecords($txtRecords);
if (preg_match(self::PATTERN, $fullRecord, $matches)) if (preg_match(self::PATTERN, $fullRecord, $matches))
{ {
$endpoint = trim($matches[1]); $endpoint = trim($matches[1]);
$publicKey = trim(str_replace(' ', '', $matches[2])); $publicKey = trim(str_replace(' ', '', $matches[2]));
if (empty($endpoint)) if (empty($endpoint))
{ {
throw new ResolutionException(sprintf("Failed to resolve RPC endpoint for %s", $domain)); throw new ResolutionException(sprintf("Failed to resolve RPC endpoint for %s", $domain));
} }
if (empty($publicKey)) if (empty($publicKey))
{ {
throw new ResolutionException(sprintf("Failed to resolve public key for %s", $domain)); throw new ResolutionException(sprintf("Failed to resolve public key for %s", $domain));
} }
return new ResolvedServer($endpoint, $publicKey); return new ResolvedServer($endpoint, $publicKey);
} }
else else
@ -74,23 +70,26 @@
} }
/** /**
* Concatenates an array of TXT records into a single string. * Concatenates an array of TXT records into a single string, filtering for SocialBox records.
* *
* @param array $txtRecords An array of TXT records, where each record is expected to have a 'txt' key. * @param array $txtRecords An array of TXT records, where each record is expected to have a 'txt' key.
* @return string A concatenated string of all TXT records. * @return string A concatenated string of all relevant TXT records.
*/ */
private static function concatenateTxtRecords(array $txtRecords): string private static function concatenateTxtRecords(array $txtRecords): string
{ {
$fullRecordBuilder = ''; $fullRecordBuilder = '';
foreach ($txtRecords as $txt) foreach ($txtRecords as $txt)
{ {
if (isset($txt['txt'])) if (isset($txt['txt']))
{ {
$fullRecordBuilder .= trim($txt['txt'], '" '); $record = trim($txt['txt'], '" ');
// Only include records that start with v=socialbox
if (stripos($record, 'v=socialbox') === 0)
{
$fullRecordBuilder .= $record;
}
} }
} }
return $fullRecordBuilder; return $fullRecordBuilder;
} }
} }

View file

@ -83,6 +83,7 @@ class Utilities
if ($decoded === false) if ($decoded === false)
{ {
var_dump($data);
throw new InvalidArgumentException('Failed to decode data from Base64'); throw new InvalidArgumentException('Failed to decode data from Base64');
} }

View file

@ -43,4 +43,54 @@
)->getResponse()->getResult(); )->getResponse()->getResult();
} }
/**
* Retrieves the privacy policy from the server.
*
* @return string Returns the privacy policy as a string.
* @throws RpcException Thrown if the RPC request fails.
*/
public function getPrivacyPolicy(): string
{
return $this->sendRequest(
new RpcRequest('getPrivacyPolicy', Utilities::randomCrc32())
)->getResponse()->getResult();
}
/**
* Accepts the privacy policy by sending a request to the server.
*
* @return true Returns true if the privacy policy is successfully accepted.
* @throws RpcException Thrown if the RPC request fails.
*/
public function acceptPrivacyPolicy(): true
{
return (bool)$this->sendRequest(
new RpcRequest('acceptPrivacyPolicy', Utilities::randomCrc32())
)->getResponse()->getResult();
}
/**
* Retrieves the terms of service from the server.
*
* @return string Returns the terms of service as a string.
* @throws RpcException Thrown if the RPC request fails.
*/
public function getTermsOfService(): string
{
return $this->sendRequest(new RpcRequest('getTermsOfService', Utilities::randomCrc32())
)->getResponse()->getResult();
}
/**
* Sends a request to accept the terms of service and verifies the response.
*
* @return true Returns true if the terms of service are successfully accepted.
* @throws RpcException Thrown if the RPC request fails.
*/
public function acceptTermsOfService(): true
{
return (bool)$this->sendRequest(
new RpcRequest('acceptTermsOfService', Utilities::randomCrc32())
)->getResponse()->getResult();
}
} }

View file

@ -5,6 +5,10 @@
$client = new \Socialbox\SocialClient(generateRandomPeer()); $client = new \Socialbox\SocialClient(generateRandomPeer());
var_dump($client->ping()); var_dump($client->ping());
var_dump($client->getPrivacyPolicy());
var_dump($client->acceptPrivacyPolicy());
var_dump($client->getTermsOfService());
var_dump($client->acceptTermsOfService());
function generateRandomPeer() function generateRandomPeer()
{ {