def test_SigningSomeTextWithKey1AndVerifyingWithPubkey1_DoesNotRaiseInvalidSignature( self): plain_text = "some text" key, pubkey = rsa.generate_keys() valid_signature = rsa.sign(key, plain_text) rsa.verify(pubkey, valid_signature, plain_text)
def test_SigningSomeTextWithKey1AndVerifyingWithPubkey1_RaisesInvalidSignature( self): plain_text = "some text" key_1, pubkey_1 = rsa.generate_keys() key_2, pubkey_2 = rsa.generate_keys() with raises(rsa.InvalidSignature): valid_signature = rsa.sign(key_1, plain_text) rsa.verify(pubkey_2, valid_signature, plain_text)
def verify(public_key, signature, group_uuid, issuer, borrower, value, description, uome_uuid): array = [ group_uuid, issuer, borrower, str(value), description, uome_uuid ] return rsa.verify(public_key, signature, *array)
def test_correct_inputs(self): group_name = 'test_name' key = example_keys.G1_pub signature = sign(example_keys.G1_priv, group_name, key) message_data = msg.RegisterGroup.make_request(group_name=group_name, group_key=key, group_signature=signature) raw_response = self.client.post(reverse('main_server_app:register_group'), {'data': message_data.dumps()}) response = msg.RegisterGroup.load_response(raw_response.content.decode()) assert raw_response.status_code == 201 signature_content = [response.group_uuid, group_name, key] verify(settings.PUBLIC_KEY, response.main_signature, *signature_content)
def verify(cls, key, signature_name, signature, **parameters): """ Verifies a single signature described in the class attribute "signatures_formats". The signature to verify is chosen with "signature_name". The values can be given in any order but they must be gives as keyword arguments that match the names of the parameters present in the signature format. :param key: :param signature_name: :param signature: :param parameters: :raises KeyError: signature_name is not the name of a signature for this class :raises AttributeError: at least one signature parameter was not given :raises TypeError: --Currently not implemented-- :raises InvalidSignature: the signature is invalid, either wrong key or wrong data """ signature_values = cls._order_signature_parameters( signature_name, **parameters) verify(key, signature, *signature_values)
def test_VerifyingACompletelyBrokenSignature_RaisesInvalidSignature(self): key, pubkey = rsa.generate_keys() with raises(rsa.InvalidSignature): rsa.verify(pubkey, "completelyBogûsÇigna_!ture", "not a chance!")