Made message signing in Cryptography use SHA512 as the message content for... #1
2 changed files with 87 additions and 2 deletions
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Enums\Types\ContactRelationshipType;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\StandardException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\ContactManager;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\PeerAddress;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
use Socialbox\Socialbox;
|
||||
|
||||
class AddressBookAddContact extends Method
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
if(!$rpcRequest->containsParameter('peer'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required \'peer\' parameter');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new StandardException('Invalid peer address', StandardError::RPC_INVALID_ARGUMENTS, $e);
|
||||
}
|
||||
|
||||
if($rpcRequest->containsParameter('relationship'))
|
||||
{
|
||||
$relationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship')));
|
||||
if($relationship === null)
|
||||
{
|
||||
throw new StandardException('Invalid relationship type', StandardError::RPC_INVALID_ARGUMENTS);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$relationship = ContactRelationshipType::MUTUAL;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Resolve the peer, this would throw a StandardException if something goes wrong
|
||||
Socialbox::resolvePeer($address);
|
||||
|
||||
// Check if the contact already exists
|
||||
$peer = $request->getPeer();
|
||||
if(ContactManager::isContact($peer, $address))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact already exists');
|
||||
}
|
||||
|
||||
// Create the contact
|
||||
ContactManager::createContact($peer, $address, $relationship);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException('Failed to add contact', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
// Return success
|
||||
return $rpcRequest->produceResponse(true);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
use Socialbox\Classes\StandardMethods\AcceptCommunityGuidelines;
|
||||
use Socialbox\Classes\StandardMethods\AcceptPrivacyPolicy;
|
||||
use Socialbox\Classes\StandardMethods\AcceptTermsOfService;
|
||||
use Socialbox\Classes\StandardMethods\AddressBookAddContact;
|
||||
use Socialbox\Classes\StandardMethods\Authenticate;
|
||||
use Socialbox\Classes\StandardMethods\GetAllowedMethods;
|
||||
use Socialbox\Classes\StandardMethods\GetCommunityGuidelines;
|
||||
|
@ -96,6 +97,8 @@
|
|||
case SETTINGS_ADD_SIGNING_KEY = 'settingsAddSigningKey';
|
||||
case SETTINGS_GET_SIGNING_KEYS = 'settingsGetSigningKeys';
|
||||
|
||||
case ADDRESS_BOOK_ADD_CONTACT = 'addressBookAddContact';
|
||||
|
||||
case AUTHENTICATE = 'authenticate';
|
||||
case RESOLVE_PEER = 'resolvePeer';
|
||||
|
||||
|
@ -145,6 +148,8 @@
|
|||
self::SETTINGS_ADD_SIGNING_KEY => SettingsAddSigningKey::execute($request, $rpcRequest),
|
||||
self::SETTINGS_GET_SIGNING_KEYS => SettingsGetSigningKeys::execute($request, $rpcRequest),
|
||||
|
||||
self::ADDRESS_BOOK_ADD_CONTACT => AddressBookAddContact::execute($request, $rpcRequest),
|
||||
|
||||
self::AUTHENTICATE => Authenticate::execute($request, $rpcRequest),
|
||||
self::RESOLVE_PEER => ResolvePeer::execute($request, $rpcRequest),
|
||||
|
||||
|
@ -234,7 +239,8 @@
|
|||
/**
|
||||
* Retrieves a list of external methods based on the client's session state.
|
||||
*
|
||||
* @param ClientRequest
|
||||
* @param ClientRequest $clientRequest The client request object containing all the request parameters
|
||||
* @return array Returns an array methods that are available for external sessions
|
||||
*/
|
||||
private static function getExternalMethods(ClientRequest $clientRequest): array
|
||||
{
|
||||
|
@ -273,7 +279,9 @@
|
|||
self::SETTINGS_SET_EMAIL,
|
||||
self::SETTINGS_SET_PHONE,
|
||||
self::SETTINGS_SET_BIRTHDAY,
|
||||
self::RESOLVE_PEER
|
||||
self::RESOLVE_PEER,
|
||||
|
||||
self::ADDRESS_BOOK_ADD_CONTACT
|
||||
];
|
||||
|
||||
// Prevent the user from deleting their display name if it is required
|
||||
|
@ -335,6 +343,8 @@
|
|||
return [];
|
||||
}
|
||||
|
||||
$methods = [];
|
||||
|
||||
// If the flag `VER_PRIVACY_POLICY` is set, then the user can accept the privacy policy
|
||||
if($session->flagExists(SessionFlags::VER_PRIVACY_POLICY))
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue