diff --git a/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookRevokeSignature.php b/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookRevokeSignature.php new file mode 100644 index 0000000..6053658 --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookRevokeSignature.php @@ -0,0 +1,89 @@ +containsParameter('peer')) + { + throw new MissingRpcArgumentException('peer'); + } + + try + { + $address = PeerAddress::fromAddress($rpcRequest->getParameter('peer')); + } + catch(InvalidArgumentException $e) + { + throw new InvalidRpcArgumentException('peer', $e->getMessage()); + } + + if(!$rpcRequest->containsParameter('uuid')) + { + throw new MissingRpcArgumentException('uuid'); + } + + try + { + $uuid = Uuid::fromString($rpcRequest->getParameter('uuid')); + } + catch(InvalidArgumentException $e) + { + throw new InvalidRpcArgumentException('uuid', $e->getMessage()); + } + + try + { + // Check if the contact already exists + $peer = $request->getPeer(); + $contact = ContactManager::getContact($peer, $address); + } + catch (DatabaseOperationException $e) + { + throw new StandardRpcException('Failed to check contact state with calling peer', StandardError::INTERNAL_SERVER_ERROR, $e); + } + + if($contact === null) + { + return $rpcRequest->produceResponse(false); + } + + try + { + if(!ContactManager::contactSigningKeyUuidExists($contact, $uuid)) + { + return $rpcRequest->produceResponse(false); + } + + ContactManager::removeContactSigningKey($contact, $uuid); + } + catch (DatabaseOperationException $e) + { + throw new StandardRpcException('Failed to remove contact signature', StandardError::INTERNAL_SERVER_ERROR, $e); + } + + // Return success + return $rpcRequest->produceResponse(true); + } + } \ No newline at end of file diff --git a/src/Socialbox/Managers/ContactManager.php b/src/Socialbox/Managers/ContactManager.php index bd183af..f05c42b 100644 --- a/src/Socialbox/Managers/ContactManager.php +++ b/src/Socialbox/Managers/ContactManager.php @@ -371,6 +371,26 @@ } } + public static function removeContactSigningKey(string|ContactDatabaseRecord $contactUuid, string $signatureUuid): void + { + if($contactUuid instanceof ContactDatabaseRecord) + { + $contactUuid = $contactUuid->getUuid(); + } + + try + { + $statement = Database::getConnection()->prepare('DELETE FROM contacts_known_keys WHERE contact_uuid=:contact_uuid AND signature_uuid=:signature_uuid'); + $statement->bindParam(':contact_uuid', $contactUuid); + $statement->bindParam(':signature_uuid', $signatureUuid); + $statement->execute(); + } + catch(PDOException $e) + { + throw new DatabaseOperationException('Failed to remove a signing key from a contact in the database', $e); + } + } + /** * Determines if a signing key UUID exists for a contact in the database. *