isPasswordRequired()) { return $rpcRequest->produceError(StandardError::FORBIDDEN, 'A password is required for this server'); } // Check if the password parameter is present if(!$rpcRequest->containsParameter('password')) { throw new MissingRpcArgumentException('password'); } try { // Get the peer $requestingPeer = $request->getPeer(); // Check if the password is set if (!PasswordManager::usesPassword($requestingPeer->getUuid())) { return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, "Cannot delete password when one isn't already set"); } // Verify the existing password before deleting it if (!PasswordManager::verifyPassword($requestingPeer->getUuid(), (string)$rpcRequest->getParameter('password'))) { return $rpcRequest->produceResponse(false); } // Delete the password PasswordManager::deletePassword($requestingPeer->getUuid()); } catch(CryptographyException) { return $rpcRequest->produceError(StandardError::CRYPTOGRAPHIC_ERROR, 'Failed to delete password due to a cryptographic error'); } catch (DatabaseOperationException $e) { throw new StandardRpcException('Failed to delete password due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e); } // Success return $rpcRequest->produceResponse(true); } }