예제 #1
0
    def test_register_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to register a key.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(contents.ResultStatus(status),
                                         contents.ResultReason(reason),
                                         contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        # Key encoding obtained from Section 14.2 of the KMIP 1.1 test
        # documentation.
        key_value = (
            b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E'
            b'\x0F')
        key = objects.SymmetricKey(enums.CryptographicAlgorithm.AES, 128,
                                   key_value)

        client = ProxyKmipClient()
        client.open()
        client.proxy.register.return_value = result
        args = [key]

        self.assertRaisesRegexp(KmipOperationFailure, error_msg,
                                client.register, *args)
예제 #2
0
 def test_open(self):
     """
     Test that the client can open a connection.
     """
     client = ProxyKmipClient()
     client.open()
     client.proxy.open.assert_called_with()
예제 #3
0
    def test_register_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to register a key.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(
            contents.ResultStatus(status),
            contents.ResultReason(reason),
            contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        # Key encoding obtained from Section 14.2 of the KMIP 1.1 test
        # documentation.
        key_value = (
            b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E'
            b'\x0F')
        key = objects.SymmetricKey(
            enums.CryptographicAlgorithm.AES, 128, key_value)

        client = ProxyKmipClient()
        client.open()
        client.proxy.register.return_value = result
        args = [key]

        self.assertRaisesRegexp(
            KmipOperationFailure, error_msg, client.register, *args)
예제 #4
0
 def test_open(self):
     """
     Test that the client can open a connection.
     """
     client = ProxyKmipClient()
     client.open()
     client.proxy.open.assert_called_with()
예제 #5
0
    def test_mac_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to generate MAC.
        """
        uuid = 'aaaaaaaa-1111-2222-3333-ffffffffffff'
        algorithm = enums.CryptographicAlgorithm.HMAC_SHA256
        data = (b'\x00\x01\x02\x03\x04')

        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(contents.ResultStatus(status),
                                         contents.ResultReason(reason),
                                         contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        client = ProxyKmipClient()
        client.open()
        client.proxy.mac.return_value = result
        args = [uuid, algorithm, data]

        self.assertRaisesRegexp(KmipOperationFailure, error_msg, client.mac,
                                *args)
예제 #6
0
 def test_close(self):
     """
     Test that the client can close an open connection.
     """
     client = ProxyKmipClient()
     client.open()
     client.close()
     client.proxy.close.assert_called_with()
예제 #7
0
 def test_open_on_open(self):
     """
     Test that a ClientConnectionFailure exception is raised when trying
     to open an opened client connection.
     """
     client = ProxyKmipClient()
     client.open()
     self.assertRaises(ClientConnectionFailure, client.open)
예제 #8
0
 def test_open_on_open(self):
     """
     Test that a ClientConnectionFailure exception is raised when trying
     to open an opened client connection.
     """
     client = ProxyKmipClient()
     client.open()
     self.assertRaises(ClientConnectionFailure, client.open)
예제 #9
0
 def test_close(self):
     """
     Test that the client can close an open connection.
     """
     client = ProxyKmipClient()
     client.open()
     client.close()
     client.proxy.close.assert_called_with()
예제 #10
0
    def test_build_common_attributes(self):
        """
        Test that the right attribute objects are created.
        """
        client = ProxyKmipClient()
        client.open()

        operation_policy_name = 'test'
        common_attributes = client._build_common_attributes(
            operation_policy_name=operation_policy_name)

        self.assertEqual(1, len(common_attributes))

        opn = common_attributes[0]
        self.assertIsInstance(opn, obj.Attribute)
        self.assertIsInstance(opn.attribute_name, obj.Attribute.AttributeName)
        self.assertIsInstance(opn.attribute_value, attr.OperationPolicyName)
        self.assertEqual(opn.attribute_name.value, 'Operation Policy Name')
        self.assertEqual(opn.attribute_value.value, 'test')
예제 #11
0
    def test_create_key_pair_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to create an asymmetric key pair.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(contents.ResultStatus(status),
                                         contents.ResultReason(reason),
                                         contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        client = ProxyKmipClient()
        client.open()
        client.proxy.create_key_pair.return_value = result
        args = [enums.CryptographicAlgorithm.RSA, 2048]

        self.assertRaisesRegexp(KmipOperationFailure, error_msg,
                                client.create_key_pair, *args)
예제 #12
0
    def test_get_attribute_list_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to retrieve the attribute names of a managed object.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(contents.ResultStatus(status),
                                         contents.ResultReason(reason),
                                         contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        client = ProxyKmipClient()
        client.open()
        client.proxy.get_attribute_list.return_value = result
        args = ['id']

        self.assertRaisesRegexp(KmipOperationFailure, error_msg,
                                client.get_attribute_list, *args)
예제 #13
0
    def test_destroy_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to destroy a secret.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(contents.ResultStatus(status),
                                         contents.ResultReason(reason),
                                         contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        client = ProxyKmipClient()
        client.open()
        client.proxy.destroy.return_value = result
        args = ['id']

        self.assertRaisesRegexp(KmipOperationFailure, error_msg,
                                client.destroy, *args)
예제 #14
0
    def test_destroy_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to destroy a secret.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(
            contents.ResultStatus(status),
            contents.ResultReason(reason),
            contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        client = ProxyKmipClient()
        client.open()
        client.proxy.destroy.return_value = result
        args = ['id']

        self.assertRaisesRegexp(
            KmipOperationFailure, error_msg, client.destroy, *args)
예제 #15
0
    def test_get_attribute_list_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        backend fails to retrieve the attribute names of a managed object.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(
            contents.ResultStatus(status),
            contents.ResultReason(reason),
            contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        client = ProxyKmipClient()
        client.open()
        client.proxy.get_attribute_list.return_value = result
        args = ['id']

        self.assertRaisesRegexp(
            KmipOperationFailure, error_msg, client.get_attribute_list, *args)
예제 #16
0
    def test_create_on_operation_failure(self):
        """
        Test that a KmipOperationFailure exception is raised when the
        the backend fails to create a symmetric key.
        """
        status = enums.ResultStatus.OPERATION_FAILED
        reason = enums.ResultReason.GENERAL_FAILURE
        message = "Test failure message"

        result = results.OperationResult(
            contents.ResultStatus(status),
            contents.ResultReason(reason),
            contents.ResultMessage(message))
        error_msg = str(KmipOperationFailure(status, reason, message))

        client = ProxyKmipClient()
        client.open()
        client.proxy.create.return_value = result
        args = [enums.CryptographicAlgorithm.AES, 256]

        self.assertRaisesRegexp(
            KmipOperationFailure, error_msg, client.create, *args)
예제 #17
0
client = ProxyKmipClient(
    hostname='127.0.0.1',
    port=5696,
    cert='../test_data/client.pem',
    key='../test_data/client.key',
    ca='../test_data/ca.pem',
    #ssl_version=ssl.PROTOCOL_TLSv1,
    # username='******',
    # password='******'
    #config='client',
    #config_file='pykmip.conf',
    #kmip_version=KMIPVersion.KMIP_1_2
)

print("Connecting...")
client.open()

key_id = client.create(
    enums.CryptographicAlgorithm.AES,
    256,
    #operation_policy_name='default',
    #name='Test_256_AES_Symmetric_Key',
    # cryptographic_usage_mask=[
    #     enums.CryptographicUsageMask.ENCRYPT,
    #     enums.CryptographicUsageMask.DECRYPT
    # ]
)

print(client.get(key_id))