コード例 #1
0
    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)
コード例 #2
0
    def sign(private_key, group_uuid, issuer, borrower, value, description,
             uome_uuid):

        array = [
            group_uuid, issuer, borrower,
            str(value), description, uome_uuid
        ]
        return rsa.sign(private_key, *array)
コード例 #3
0
    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)
コード例 #4
0
    def test_invalid_signature(self):
        group_name = 'test_name'
        key = example_keys.G1_pub

        signature = sign(example_keys.G1_priv, group_name)
        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()})

        assert raw_response.status_code == 401
コード例 #5
0
    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)
コード例 #6
0
    def sign(cls, key, signature_name, **parameters):
        """
        Signs a single signature described in the class attribute "signatures_formats".
        The signature to sign 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 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--
        """
        signature_values = cls._order_signature_parameters(
            signature_name, **parameters)

        return sign(key, *signature_values)
コード例 #7
0
    def test_SigningSomeNonStringValues(self):
        values = ["hey", 10, 56.4, 'ho']
        key, pubkey = rsa.generate_keys()

        rsa.sign(key, *values)