def cleanup_cards(self, *cards): for card in cards: request = RevokeCardRequest( card_id=card.id, ) self._request_signer.authority_sign(request, config.VIRGIL_APP_ID, self._app_private_key) self._client.revoke_card_from_request(request)
def test_self_sign_revoke_card_request(self): alice_keys = self._crypto.generate_keys() request = RevokeCardRequest(card_id="some_card_id") self._request_signer.self_sign(request, alice_keys.private_key) self.assertEqual( len(request.signatures), 1, ) self._assertVerify( list(request.signatures.values())[0], request.snapshot, alice_keys.public_key)
def revoke(self, card): # type: (VirgilCard) -> None """Revokes a VirgilCard from Virgil Services. Args: card: The card to be revoked. """ revoke_card_request = RevokeCardRequest( card.id, RevokeCardRequest.Reasons.Unspecified) app_key = self.context.credentials.get_app_key(self.context.crypto) snapshot_fingerprint = self.context.crypto.calculate_fingerprint( revoke_card_request.snapshot) signature = VirgilBuffer( self.context.crypto.sign(snapshot_fingerprint.value, app_key)).to_string("base64") revoke_card_request.signatures = { self.context.credentials.app_id: signature } self.context.client.revoke_card_from_request(revoke_card_request)
def test_authority_sign_revoke_card_request(self): request = RevokeCardRequest(card_id="some_card_id", ) self._request_signer.authority_sign( request, config.VIRGIL_APP_ID, self._app_private_key, ) self.assertEqual( len(request.signatures), 1, ) self.assertEqual( list(request.signatures.keys())[0], config.VIRGIL_APP_ID) self._assertVerify( list(request.signatures.values())[0], request.snapshot, self._crypto.extract_public_key(self._app_private_key))
def test_self_and_authority_sign_revoke_card_request(self): alice_keys = self._crypto.generate_keys() request = RevokeCardRequest(card_id="some_card_id") self._request_signer.self_sign(request, alice_keys.private_key) self._request_signer.authority_sign( request, config.VIRGIL_APP_ID, self._app_private_key, ) self.assertEqual( len(request.signatures), 2, ) authority_signature = request.signatures.pop(config.VIRGIL_APP_ID) self._assertVerify( authority_signature, request.snapshot, self._crypto.extract_public_key(self._app_private_key)) self._assertVerify( list(request.signatures.values())[0], request.snapshot, alice_keys.public_key)
def test_revoke_card_removes_created_card(self): alice_keys = self._crypto.generate_keys() virgil_app_id = config.VIRGIL_APP_ID create_card_request = CreateCardRequest( "alice", "username", self._crypto.export_public_key(alice_keys.public_key) ) self._request_signer.self_sign( create_card_request, alice_keys.private_key ) self._request_signer.authority_sign( create_card_request, virgil_app_id, self._app_private_key ) card = self._client.create_card_from_request(create_card_request) revoke_card_request = RevokeCardRequest( card_id=card.id ) self._request_signer.authority_sign(revoke_card_request, config.VIRGIL_APP_ID, self._app_private_key) self._client.revoke_card_from_request(revoke_card_request)