Esempio n. 1
0
    def setUp(self):
        super(TestMACResponsePayload, self).setUp()

        self.unique_identifier = attributes.UniqueIdentifier(value='1')
        self.mac_data = objects.MACData(value=(
            b'\x99\x8b\x55\x59\x90\x9b\x85\x87\x5b\x90\x63\x13\x12\xbb\x32\x9f'
            b'\x6a\xc4\xed\x97\x6e\xac\x99\xe5\x21\x53\xc4\x19\x28\xf2\x2a\x5b'
            b'\xef\x79\xa4\xbe\x05\x3b\x31\x49\x19\xe0\x75\x23\xb9\xbe\xc8\x23'
            b'\x35\x60\x7e\x49\xba\xa9\x7e\xe0\x9e\x6b\x3d\x55\xf4\x51\xff\x7c'
        ))

        self.encoding_full = utils.BytearrayStream((
            b'\x42\x00\x7c\x01\x00\x00\x00\x58\x42\x00\x94\x07\x00\x00\x00\x01'
            b'\x31\x00\x00\x00\x00\x00\x00\x00\x42\x00\xc6\x08\x00\x00\x00\x40'
            b'\x99\x8b\x55\x59\x90\x9b\x85\x87\x5b\x90\x63\x13\x12\xbb\x32\x9f'
            b'\x6a\xc4\xed\x97\x6e\xac\x99\xe5\x21\x53\xc4\x19\x28\xf2\x2a\x5b'
            b'\xef\x79\xa4\xbe\x05\x3b\x31\x49\x19\xe0\x75\x23\xb9\xbe\xc8\x23'
            b'\x35\x60\x7e\x49\xba\xa9\x7e\xe0\x9e\x6b\x3d\x55\xf4\x51\xff\x7c'
        ))
        self.encoding_no_unique_identifier = utils.BytearrayStream((
            b'\x42\x00\x7c\x01\x00\x00\x00\x48\x42\x00\xc6\x08\x00\x00\x00\x40'
            b'\x99\x8b\x55\x59\x90\x9b\x85\x87\x5b\x90\x63\x13\x12\xbb\x32\x9f'
            b'\x6a\xc4\xed\x97\x6e\xac\x99\xe5\x21\x53\xc4\x19\x28\xf2\x2a\x5b'
            b'\xef\x79\xa4\xbe\x05\x3b\x31\x49\x19\xe0\x75\x23\xb9\xbe\xc8\x23'
            b'\x35\x60\x7e\x49\xba\xa9\x7e\xe0\x9e\x6b\x3d\x55\xf4\x51\xff\x7c'
        ))
        self.encoding_no_mac_data = utils.BytearrayStream((
            b'\x42\x00\x7c\x01\x00\x00\x00\x10\x42\x00\x94\x07\x00\x00\x00\x01'
            b'\x31\x00\x00\x00\x00\x00\x00\x00'))
Esempio n. 2
0
    def test_mac_on_invalid_inputs(self):
        """
        Test that a TypeError exception is raised when wrong type
        of arguments are given to mac operation.
        """
        uuid = 'aaaaaaaa-1111-2222-3333-ffffffffffff'
        uuid_invalid = int(123)

        algorithm = enums.CryptographicAlgorithm.HMAC_SHA256
        algorithm_invalid = enums.CryptographicUsageMask.MAC_GENERATE

        data = (b'\x00\x01\x02\x03\x04')
        data_invalid = int(123)

        result = results.MACResult(contents.ResultStatus(
            enums.ResultStatus.SUCCESS),
                                   uuid=attr.UniqueIdentifier(uuid),
                                   mac_data=obj.MACData(data))

        args = [uuid_invalid, algorithm, data]
        with ProxyKmipClient() as client:
            client.proxy.mac.return_value = result
            self.assertRaises(TypeError, client.mac, *args)

        args = [uuid, algorithm_invalid, data]
        with ProxyKmipClient() as client:
            client.proxy.mac.return_value = result
            self.assertRaises(TypeError, client.mac, *args)

        args = [uuid, algorithm, data_invalid]
        with ProxyKmipClient() as client:
            client.proxy.mac.return_value = result
            self.assertRaises(TypeError, client.mac, *args)
Esempio n. 3
0
    def test_mac(self):
        """
        Test the MAC client with proper input.
        """
        uuid = 'aaaaaaaa-1111-2222-3333-ffffffffffff'
        algorithm = enums.CryptographicAlgorithm.HMAC_SHA256
        data = (b'\x00\x01\x02\x03\x04')

        result = results.MACResult(contents.ResultStatus(
            enums.ResultStatus.SUCCESS),
                                   uuid=attr.UniqueIdentifier(uuid),
                                   mac_data=obj.MACData(data))

        with ProxyKmipClient() as client:
            client.proxy.mac.return_value = result

            uid, mac_data = client.mac(uuid, algorithm, data)
            self.assertEqual(uid, uuid)
            self.assertEqual(mac_data, data)