def setUp(self):
        super(TestExtensionInformation, self).setUp()

        self.extension_name_b = ExtensionName('ACME LOCATION')
        self.extension_name_c = ExtensionName('ACME LOCATION')
        self.extension_name_d = ExtensionName('ACME ZIP CODE')

        self.extension_tag_c = ExtensionTag(5548545)
        self.extension_tag_d = ExtensionTag(5548546)

        self.extension_type_c = ExtensionType(7)
        self.extension_type_d = ExtensionType(2)

        self.encoding_a = BytearrayStream(
            b'\x42\x00\xA4\x01\x00\x00\x00\x08\x42\x00\xA5\x07\x00\x00\x00'
            b'\x00')
        self.encoding_b = BytearrayStream(
            b'\x42\x00\xA4\x01\x00\x00\x00\x18\x42\x00\xA5\x07\x00\x00\x00\x0D'
            b'\x41\x43\x4D\x45\x20\x4C\x4F\x43\x41\x54\x49\x4F\x4E\x00\x00'
            b'\x00')
        self.encoding_c = BytearrayStream(
            b'\x42\x00\xA4\x01\x00\x00\x00\x38\x42\x00\xA5\x07\x00\x00\x00\x0D'
            b'\x41\x43\x4D\x45\x20\x4C\x4F\x43\x41\x54\x49\x4F\x4E\x00\x00\x00'
            b'\x42\x00\xA6\x02\x00\x00\x00\x04\x00\x54\xAA\x01\x00\x00\x00\x00'
            b'\x42\x00\xA7\x02\x00\x00\x00\x04\x00\x00\x00\x07\x00\x00\x00'
            b'\x00')
        self.encoding_d = BytearrayStream(
            b'\x42\x00\xA4\x01\x00\x00\x00\x38\x42\x00\xA5\x07\x00\x00\x00\x0D'
            b'\x41\x43\x4D\x45\x20\x5A\x49\x50\x20\x43\x4F\x44\x45\x00\x00\x00'
            b'\x42\x00\xA6\x02\x00\x00\x00\x04\x00\x54\xAA\x02\x00\x00\x00\x00'
            b'\x42\x00\xA7\x02\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00'
            b'\x00')
Exemplo n.º 2
0
    def read(self, istream):
        super(KeyMaterialStruct, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.data = BytearrayStream(tstream.read())

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 3
0
    def setUp(self):
        super(TestServerInformation, self).setUp()

        self.data = BytearrayStream(b'\x00\x01\x02\x03')

        self.encoding_a = BytearrayStream(b'\x42\x00\x88\x01\x00\x00\x00\x00')
        self.encoding_b = BytearrayStream(
            b'\x42\x00\x88\x01\x00\x00\x00\x04\x00\x01\x02\x03')
Exemplo n.º 4
0
    def setUp(self):
        super(TestApplicationSpecificInformation, self).setUp()

        self.encoding_default = BytearrayStream((
            b'\x42\x00\x04\x01\x00\x00\x00\x10\x42\x00\x03\x07\x00\x00\x00\x00'
            b'\x42\x00\x02\x07\x00\x00\x00\x00'))
        self.encoding = BytearrayStream((
            b'\x42\x00\x04\x01\x00\x00\x00\x28\x42\x00\x03\x07\x00\x00\x00\x03'
            b'\x73\x73\x6C\x00\x00\x00\x00\x00\x42\x00\x02\x07\x00\x00\x00\x0F'
            b'\x77\x77\x77\x2E\x65\x78\x61\x6D\x70\x6C\x65\x2E\x63\x6F\x6D'
            b'\x00'))
Exemplo n.º 5
0
    def test_write(self):
        attrObj = Attribute(self.attribute_name_a, self.attribute_index_a,
                            self.attribute_value_a)
        ostream = BytearrayStream()
        attrObj.write(ostream)

        self.assertEqual(self.key_req_with_crypt_params, ostream)
Exemplo n.º 6
0
    def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        tstream = BytearrayStream()

        if self.private_key_uuid is not None:
            self.private_key_uuid.write(tstream, kmip_version=kmip_version)

        if self.offset is not None:
            self.offset.write(tstream, kmip_version=kmip_version)

        if self.common_template_attribute is not None:
            self.common_template_attribute.write(tstream,
                                                 kmip_version=kmip_version)

        if self.private_key_template_attribute is not None:
            self.private_key_template_attribute.write(
                tstream, kmip_version=kmip_version)

        if self.public_key_template_attribute is not None:
            self.public_key_template_attribute.write(tstream,
                                                     kmip_version=kmip_version)

        self.length = tstream.length()
        super(RekeyKeyPairRequestPayload,
              self).write(ostream, kmip_version=kmip_version)
        ostream.write(tstream.buffer)
Exemplo n.º 7
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        super(RekeyKeyPairRequestPayload, self).read(istream,
                                                     kmip_version=kmip_version)
        tstream = BytearrayStream(istream.read(self.length))

        if self.is_tag_next(enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER, tstream):
            self.private_key_uuid = attributes.PrivateKeyUniqueIdentifier()
            self.private_key_uuid.read(tstream, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.OFFSET, tstream):
            self.offset = misc.Offset()
            self.offset.read(tstream, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.COMMON_TEMPLATE_ATTRIBUTE, tstream):
            self.common_template_attribute = objects.CommonTemplateAttribute()
            self.common_template_attribute.read(tstream,
                                                kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
                            tstream):
            self.private_key_template_attribute = \
                objects.PrivateKeyTemplateAttribute()
            self.private_key_template_attribute.read(tstream,
                                                     kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE, tstream):
            self.public_key_template_attribute = \
                objects.PublicKeyTemplateAttribute()
            self.public_key_template_attribute.read(tstream,
                                                    kmip_version=kmip_version)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 8
0
    def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Write the data encoding the RevokeRequestPayload object to a stream.
        Args:
            ostream (Stream): A data stream in which to encode object data,
                supporting a write method; usually a BytearrayStream object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be encoded. Optional,
                defaults to KMIP 1.0.
        """
        tstream = BytearrayStream()

        # Write the contents of the request payload
        if self.unique_identifier is not None:
            self.unique_identifier.write(tstream, kmip_version=kmip_version)

        self.revocation_reason.write(tstream, kmip_version=kmip_version)

        if self.compromise_occurrence_date is not None:
            self.compromise_occurrence_date.write(tstream,
                                                  kmip_version=kmip_version)

        # Write the length and value of the request payload
        self.length = tstream.length()
        super(RevokeRequestPayload, self).write(ostream,
                                                kmip_version=kmip_version)
        ostream.write(tstream.buffer)
Exemplo n.º 9
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the RevokeRequestPayload object and decode it
        into its constituent parts.
        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 1.0.
        """
        super(RevokeRequestPayload, self).read(istream,
                                               kmip_version=kmip_version)
        tstream = BytearrayStream(istream.read(self.length))

        self.unique_identifier = attributes.UniqueIdentifier()
        self.unique_identifier.read(tstream, kmip_version=kmip_version)

        self.revocation_reason = objects.RevocationReason()
        self.revocation_reason.read(tstream, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.COMPROMISE_OCCURRENCE_DATE, tstream):
            self.compromise_occurrence_date = primitives.DateTime(
                tag=enums.Tags.COMPROMISE_OCCURRENCE_DATE)
            self.compromise_occurrence_date.read(tstream,
                                                 kmip_version=kmip_version)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 10
0
    def read(self, istream):
        super(CryptographicParameters, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        if self.is_tag_next(Tags.BLOCK_CIPHER_MODE, tstream):
            self.block_cipher_mode = CryptographicParameters.BlockCipherMode()
            self.block_cipher_mode.read(tstream)

        if self.is_tag_next(Tags.PADDING_METHOD, tstream):
            self.padding_method = CryptographicParameters.PaddingMethod()
            self.padding_method.read(tstream)

        if self.is_tag_next(Tags.HASHING_ALGORITHM, tstream):
            self.hashing_algorithm = HashingAlgorithm()
            self.hashing_algorithm.read(tstream)

        if self.is_tag_next(Tags.KEY_ROLE_TYPE, tstream):
            self.key_role_type = CryptographicParameters.KeyRoleType()
            self.key_role_type.read(tstream)

        if self.is_tag_next(Tags.DIGITAL_SIGNATURE_ALGORITHM, tstream):
            self.digital_signature_algorithm = \
                CryptographicParameters.DigitalSignatureAlgorithm()
            self.digital_signature_algorithm.read(tstream)

        if self.is_tag_next(Tags.CRYPTOGRAPHIC_ALGORITHM, tstream):
            self.cryptographic_algorithm = CryptographicAlgorithm()
            self.cryptographic_algorithm.read(tstream)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 11
0
    def read(self, istream):
        """
        Read the data encoding the ServerInformation object and decode it into
        its constituent parts.

        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
        """
        super(ServerInformation, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.data = BytearrayStream(tstream.read())

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 12
0
    def setUp(self):
        super(TestAttributeClass, self).setUp()

        name_a = 'CRYPTOGRAPHIC PARAMETERS'
        name_b = 'CRYPTOGRAPHIC ALGORITHM'

        self.attribute_name_a = Attribute.AttributeName(name_a)
        self.attribute_name_b = Attribute.AttributeName(name_b)

        self.factory = AttributeValueFactory()

        self.attribute_value_a = self.factory.create_attribute_value(
            AttributeType.CRYPTOGRAPHIC_PARAMETERS, {
                'block_cipher_mode': BlockCipherMode.CBC,
                'padding_method': PaddingMethod.PKCS5,
                'hashing_algorithm': HashingAlgorithmEnum.SHA_1,
                'key_role_type': KeyRoleType.BDK
            })

        self.attribute_value_b = self.factory.create_attribute_value(
            AttributeType.CRYPTOGRAPHIC_PARAMETERS, {
                'block_cipher_mode': BlockCipherMode.CCM,
                'padding_method': PaddingMethod.PKCS5,
                'hashing_algorithm': HashingAlgorithmEnum.SHA_1,
                'key_role_type': KeyRoleType.BDK
            })

        index_a = 2
        index_b = 3

        self.attribute_index_a = Attribute.AttributeIndex(index_a)
        self.attribute_index_b = Attribute.AttributeIndex(index_b)

        self.attributeObj_a = Attribute(attribute_name=self.attribute_name_a,
                                        attribute_value=self.attribute_value_a,
                                        attribute_index=self.attribute_index_a)

        self.attributeObj_b = Attribute(attribute_name=self.attribute_name_b,
                                        attribute_value=self.attribute_value_a,
                                        attribute_index=self.attribute_index_a)

        self.attributeObj_c = Attribute(attribute_name=self.attribute_name_a,
                                        attribute_value=self.attribute_value_b,
                                        attribute_index=self.attribute_index_a)

        self.attributeObj_d = Attribute(attribute_name=self.attribute_name_a,
                                        attribute_value=self.attribute_value_a,
                                        attribute_index=self.attribute_index_b)

        self.key_req_with_crypt_params = BytearrayStream((
            b'\x42\x00\x08\x01\x00\x00\x00\x78\x42\x00\x0a\x07\x00\x00\x00\x18'
            b'\x43\x52\x59\x50\x54\x4f\x47\x52\x41\x50\x48\x49\x43\x20\x50\x41'
            b'\x52\x41\x4d\x45\x54\x45\x52\x53'
            b'\x42\x00\x09\x02\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x00'
            b'\x42\x00\x0b\x01\x00\x00\x00\x40'
            b'\x42\x00\x11\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
            b'\x42\x00\x5f\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00'
            b'\x42\x00\x38\x05\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00'
            b'\x42\x00\x83\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
        ))
Exemplo n.º 13
0
    def read(self, istream):
        super(KeyBlock, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.key_format_type = KeyFormatType()
        self.key_format_type.read(tstream)

        if self.is_tag_next(Tags.KEY_COMPRESSION_TYPE, tstream):
            self.key_compression_type = KeyBlock.KeyCompressionType()
            self.key_compression_type.read(tstream)

        self.key_value = KeyValue()
        self.key_value.read(tstream)

        if self.is_tag_next(Tags.CRYPTOGRAPHIC_ALGORITHM, tstream):
            self.cryptographic_algorithm = attributes.CryptographicAlgorithm()
            self.cryptographic_algorithm.read(tstream)

        if self.is_tag_next(Tags.CRYPTOGRAPHIC_LENGTH, tstream):
            self.cryptographic_length = attributes.CryptographicLength()
            self.cryptographic_length.read(tstream)

        if self.is_tag_next(Tags.KEY_WRAPPING_DATA, tstream):
            self.key_wrapping_data = KeyWrappingData()
            self.key_wrapping_data.read(tstream)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 14
0
    def setUp(self):
        super(TestCryptographicParameters, self).setUp()

        self.bad_enum_code = 8535937
        self.factory = AttributeValueFactory()

        self.cp = self.factory.create_attribute_value(
            AttributeType.CRYPTOGRAPHIC_PARAMETERS, {
                'block_cipher_mode': BlockCipherMode.CBC,
                'padding_method': PaddingMethod.PKCS5,
                'hashing_algorithm': HashingAlgorithmEnum.SHA_1,
                'key_role_type': KeyRoleType.BDK
            })

        self.cp_none = self.factory.create_attribute_value(
            AttributeType.CRYPTOGRAPHIC_PARAMETERS, {})

        # Symmetric key object with Cryptographic Parameters
        # Byte stream edited to add Key Role Type parameter
        # Based on the KMIP Spec 1.1 Test Cases document
        # 11.1 page 255 on the pdf version
        self.key_req_with_crypt_params = BytearrayStream((
            b'\x42\x00\x2B\x01\x00\x00\x00\x40'
            b'\x42\x00\x11\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
            b'\x42\x00\x5F\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00'
            b'\x42\x00\x38\x05\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00'
            b'\x42\x00\x83\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
        ))
Exemplo n.º 15
0
    def setUp(self):
        super(TestProtocolVersion, self).setUp()

        self.major_default = ProtocolVersion.ProtocolVersionMajor()
        self.minor_default = ProtocolVersion.ProtocolVersionMinor()
        self.major = ProtocolVersion.ProtocolVersionMajor(1)
        self.minor = ProtocolVersion.ProtocolVersionMinor(1)

        self.encoding_default = BytearrayStream((
            b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
            b'\x00\x00\x00\x00\x00\x00\x00\x00'))
        self.encoding = BytearrayStream((
            b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
            b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
            b'\x00\x00\x00\x01\x00\x00\x00\x00'))
Exemplo n.º 16
0
    def read(self, istream):
        super(RequestBatchItem, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        # Read the batch item operation
        self.operation = contents.Operation()
        self.operation.read(tstream)

        # Read the unique batch item ID if it is present
        if self.is_tag_next(Tags.UNIQUE_BATCH_ITEM_ID, tstream):
            self.unique_batch_item_id = contents.UniqueBatchItemID()
            self.unique_batch_item_id.read(tstream)

        # Dynamically create the response payload class that belongs to the
        # operation
        self.request_payload = self.payload_factory.create(
            self.operation.value)
        self.request_payload.read(tstream)

        # Read the message extension if it is present
        if self.is_tag_next(Tags.MESSAGE_EXTENSION, tstream):
            self.message_extension = contents.MessageExtension()
            self.message_extension.read(tstream)

        self.is_oversized(tstream)
Exemplo n.º 17
0
    def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        tstream = BytearrayStream()

        # Write the contents of the batch item to the stream
        self.operation.write(tstream, kmip_version=kmip_version)

        if kmip_version >= enums.KMIPVersion.KMIP_2_0:
            if self._ephemeral:
                self._ephemeral.write(tstream, kmip_version=kmip_version)

        if self.unique_batch_item_id is not None:
            self.unique_batch_item_id.write(tstream, kmip_version=kmip_version)

        self.request_payload.write(tstream, kmip_version=kmip_version)

        if self.message_extension is not None:
            self.message_extension.write(tstream, kmip_version=kmip_version)

        # Write the length and value of the batch item
        self.length = tstream.length()
        super(RequestBatchItem, self).write(
            ostream,
            kmip_version=kmip_version
        )
        ostream.write(tstream.buffer)
Exemplo n.º 18
0
    def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        tstream = BytearrayStream()

        # Write the contents of the batch item to the stream
        if self.operation is not None:
            self.operation.write(tstream, kmip_version=kmip_version)
        if self.unique_batch_item_id is not None:
            self.unique_batch_item_id.write(tstream, kmip_version=kmip_version)

        self.result_status.write(tstream, kmip_version=kmip_version)

        if self.result_reason is not None:
            self.result_reason.write(tstream, kmip_version=kmip_version)
        if self.result_message is not None:
            self.result_message.write(tstream, kmip_version=kmip_version)
        if self.async_correlation_value is not None:
            self.async_correlation_value.write(
                tstream,
                kmip_version=kmip_version
            )
        if self.response_payload is not None:
            self.response_payload.write(tstream, kmip_version=kmip_version)
        if self.message_extension is not None:
            self.message_extension.write(tstream, kmip_version=kmip_version)

        # Write the length and value of the batch item
        self.length = tstream.length()
        super(ResponseBatchItem, self).write(
            ostream,
            kmip_version=kmip_version
        )
        ostream.write(tstream.buffer)
Exemplo n.º 19
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        super(ResponseHeader, self).read(
            istream,
            kmip_version=kmip_version
        )
        tstream = BytearrayStream(istream.read(self.length))

        self.protocol_version = contents.ProtocolVersion()
        self.protocol_version.read(tstream, kmip_version=kmip_version)

        kmip_version = contents.protocol_version_to_kmip_version(
            self.protocol_version
        )

        self.time_stamp = contents.TimeStamp()
        self.time_stamp.read(tstream, kmip_version=kmip_version)

        if kmip_version >= enums.KMIPVersion.KMIP_2_0:
            if self.is_tag_next(enums.Tags.SERVER_HASHED_PASSWORD, tstream):
                server_hashed_password = primitives.ByteString(
                    tag=enums.Tags.SERVER_HASHED_PASSWORD
                )
                server_hashed_password.read(tstream, kmip_version=kmip_version)
                self._server_hashed_password = server_hashed_password

        self.batch_count = contents.BatchCount()
        self.batch_count.read(tstream, kmip_version=kmip_version)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 20
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        super(RequestBatchItem, self).read(
            istream,
            kmip_version=kmip_version
        )
        tstream = BytearrayStream(istream.read(self.length))

        # Read the batch item operation
        self.operation = contents.Operation()
        self.operation.read(tstream, kmip_version=kmip_version)

        if kmip_version >= enums.KMIPVersion.KMIP_2_0:
            if self.is_tag_next(enums.Tags.EPHEMERAL, tstream):
                ephemeral = primitives.Boolean(tag=enums.Tags.EPHEMERAL)
                ephemeral.read(tstream, kmip_version=kmip_version)
                self._ephemeral = ephemeral

        # Read the unique batch item ID if it is present
        if self.is_tag_next(Tags.UNIQUE_BATCH_ITEM_ID, tstream):
            self.unique_batch_item_id = contents.UniqueBatchItemID()
            self.unique_batch_item_id.read(tstream, kmip_version=kmip_version)

        # Dynamically create the response payload class that belongs to the
        # operation
        self.request_payload = self.payload_factory.create(
            self.operation.value)
        self.request_payload.read(tstream, kmip_version=kmip_version)

        # Read the message extension if it is present
        if self.is_tag_next(Tags.MESSAGE_EXTENSION, tstream):
            self.message_extension = contents.MessageExtension()
            self.message_extension.read(tstream, kmip_version=kmip_version)

        self.is_oversized(tstream)
Exemplo n.º 21
0
    def read(self, istream):
        super(Attribute, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        # Read the name of the attribute
        self.attribute_name = Attribute.AttributeName()
        self.attribute_name.read(tstream)

        # Read the attribute index if it is next
        if self.is_tag_next(Tags.ATTRIBUTE_INDEX, tstream):
            self.attribute_index = Attribute.AttributeIndex()
            self.attribute_index.read(tstream)

        # Lookup the attribute class that belongs to the attribute name
        name = self.attribute_name.value
        enum_name = name.replace('.', '_').replace(' ', '_').upper()
        enum_type = None

        try:
            enum_type = AttributeType[enum_name]
        except KeyError:
            # Likely custom attribute, pass raw name string as attribute type
            enum_type = name

        value = self.value_factory.create_attribute_value(enum_type, None)
        self.attribute_value = value
        self.attribute_value.tag = Tags.ATTRIBUTE_VALUE
        self.attribute_value.read(tstream)

        self.is_oversized(tstream)
Exemplo n.º 22
0
    def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        tstream = BytearrayStream()

        # Write the contents of a request header to the stream
        self.protocol_version.write(tstream, kmip_version=kmip_version)
        if self.maximum_response_size is not None:
            self.maximum_response_size.write(
                tstream,
                kmip_version=kmip_version
            )
        if self.asynchronous_indicator is not None:
            self.asynchronous_indicator.write(
                tstream,
                kmip_version=kmip_version
            )
        if self.authentication is not None:
            self.authentication.write(tstream, kmip_version=kmip_version)
        if self.batch_error_cont_option is not None:
            self.batch_error_cont_option.write(
                tstream,
                kmip_version=kmip_version
            )
        if self.batch_order_option is not None:
            self.batch_order_option.write(tstream, kmip_version=kmip_version)
        if self.time_stamp is not None:
            self.time_stamp.write(tstream, kmip_version=kmip_version)
        self.batch_count.write(tstream, kmip_version=kmip_version)

        # Write the length and value of the request header
        self.length = tstream.length()
        super(RequestHeader, self).write(
            ostream,
            kmip_version=kmip_version
        )
        ostream.write(tstream.buffer)
Exemplo n.º 23
0
    def write(self, ostream):
        """
        Write the data encoding the QueryResponsePayload object to a stream.

        Args:
            ostream (Stream): A data stream in which to encode object data,
                supporting a write method; usually a BytearrayStream object.
        """
        tstream = BytearrayStream()

        for operation in self.operations:
            operation.write(tstream)

        for object_type in self.object_types:
            object_type.write(tstream)

        if self.vendor_identification is not None:
            self.vendor_identification.write(tstream)

        if self.server_information is not None:
            self.server_information.write(tstream)

        for application_namespace in self.application_namespaces:
            application_namespace.write(tstream)

        for extension_information in self.extension_information:
            extension_information.write(tstream)

        self.length = tstream.length()
        super(QueryResponsePayload, self).write(ostream)
        ostream.write(tstream.buffer)
Exemplo n.º 24
0
    def read(self, istream):
        super(KeyWrappingSpecification, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.wrapping_method = WrappingMethod()
        self.wrapping_method.read(tstream)

        if self.is_tag_next(Tags.ENCRYPTION_KEY_INFORMATION, tstream):
            self.encryption_key_information = EncryptionKeyInformation()
            self.encryption_key_information.read(tstream)

        if self.is_tag_next(Tags.MAC_SIGNATURE_KEY_INFORMATION, tstream):
            self.mac_signature_key_information = MACSignatureKeyInformation()
            self.mac_signature_key_information.read(tstream)

        if self.is_tag_next(Tags.ATTRIBUTE_NAME, tstream):
            self.attribute_name = KeyWrappingSpecification.AttributeName()
            self.attribute_name.read(tstream)

        if self.is_tag_next(Tags.ENCODING_OPTION, tstream):
            self.encoding_option = EncodingOption()
            self.encoding_option.read(tstream)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 25
0
    def read(self, istream):
        super(KeyWrappingData, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.wrapping_method = WrappingMethod()
        self.wrapping_method.read(tstream)

        if self.is_tag_next(Tags.ENCRYPTION_KEY_INFORMATION, tstream):
            self.encryption_key_information = EncryptionKeyInformation()
            self.encryption_key_information.read(tstream)

        if self.is_tag_next(Tags.MAC_SIGNATURE_KEY_INFORMATION, tstream):
            self.mac_signature_key_information = MACSignatureKeyInformation()
            self.mac_signature_key_information.read(tstream)

        if self.is_tag_next(Tags.MAC_SIGNATURE, tstream):
            self.mac_signature = KeyWrappingData.MACSignature()
            self.mac_signature.read(tstream)

        if self.is_tag_next(Tags.IV_COUNTER_NONCE, tstream):
            self.iv_counter_nonce = KeyWrappingData.IVCounterNonce()
            self.iv_counter_nonce.read(tstream)

        if self.is_tag_next(Tags.ENCODING_OPTION, tstream):
            self.encoding_option = EncodingOption()
            self.encoding_option.read(tstream)

        self.is_oversized(tstream)
        self.validate()
Exemplo n.º 26
0
    def write(self, ostream):
        tstream = BytearrayStream()
        tstream.write(self.data.buffer)

        self.length = tstream.length()
        super(KeyMaterialStruct, self).write(ostream)
        ostream.write(tstream.buffer)
Exemplo n.º 27
0
    def setUp(self):
        super(TestDigest, self).setUp()

        self.hashing_algorithm_a = HashingAlgorithm(
            HashingAlgorithmEnum.SHA_256)
        self.hashing_algorithm_b = HashingAlgorithm(
            HashingAlgorithmEnum.SHA_256)
        self.hashing_algorithm_c = HashingAlgorithm(
            HashingAlgorithmEnum.SHA_256)
        self.hashing_algorithm_d = HashingAlgorithm(HashingAlgorithmEnum.SHA_1)

        self.digest_value_a = DigestValue(b'')
        self.digest_value_b = DigestValue(
            b'\x6C\x06\x4F\xE0\x51\xAD\xD1\x1E\xDC\x07\x72\x7B\x59\x4E\xB4\x87'
            b'\x11\xDF\x84\x3E\x08\x44\x5B\xBA\x2C\xD7\x86\xBC\x16\xBC\x58'
            b'\xE8')
        self.digest_value_c = DigestValue(
            b'\x11\x11\x0A\x01\xED\x45\x89\xD9\x98\x7C\x9A\xD6\x03\x68\xE2\xB7'
            b'\x62\xF2\xB2\x0C\x00\x94\x6E\x19\x32\xC1\x60\x5A\x18\x17\x2F'
            b'\x55')

        self.key_format_type_a = KeyFormatType(KeyFormatTypeEnum.RAW)
        self.key_format_type_b = KeyFormatType(KeyFormatTypeEnum.RAW)
        self.key_format_type_c = KeyFormatType(KeyFormatTypeEnum.PKCS_1)

        # Encodings obtained from Section 18.1 and 18.2 of the KMIP 1.1 Test
        # Cases document.
        self.encoding_a = BytearrayStream((
            b'\x42\x00\x34\x01\x00\x00\x00\x28\x42\x00\x38\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x35\x08\x00\x00\x00\x00'
            b'\x42\x00\x42\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00'
            b'\x00'))
        self.encoding_b = BytearrayStream((
            b'\x42\x00\x34\x01\x00\x00\x00\x48\x42\x00\x38\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x35\x08\x00\x00\x00\x20'
            b'\x6C\x06\x4F\xE0\x51\xAD\xD1\x1E\xDC\x07\x72\x7B\x59\x4E\xB4\x87'
            b'\x11\xDF\x84\x3E\x08\x44\x5B\xBA\x2C\xD7\x86\xBC\x16\xBC\x58\xE8'
            b'\x42\x00\x42\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00'
            b'\x00'))
        self.encoding_c = BytearrayStream((
            b'\x42\x00\x34\x01\x00\x00\x00\x48\x42\x00\x38\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x35\x08\x00\x00\x00\x20'
            b'\x11\x11\x0A\x01\xED\x45\x89\xD9\x98\x7C\x9A\xD6\x03\x68\xE2\xB7'
            b'\x62\xF2\xB2\x0C\x00\x94\x6E\x19\x32\xC1\x60\x5A\x18\x17\x2F\x55'
            b'\x42\x00\x42\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00'
            b'\x00'))
Exemplo n.º 28
0
 def setUp(self):
     super(TestName, self).setUp()
     self.stream = BytearrayStream()
     self.badFormatName = 8675309
     self.stringName1 = 'Jenny'
     self.stringName2 = 'Johnny'
     self.enumNameType = NameType.UNINTERPRETED_TEXT_STRING
     self.enumNameTypeUri = NameType.URI
Exemplo n.º 29
0
    def write(self, ostream):
        tstream = BytearrayStream()

        for protocol_version in self.protocol_versions:
            protocol_version.write(tstream)

        self.length = tstream.length()
        super(DiscoverVersionsRequestPayload, self).write(ostream)
        ostream.write(tstream.buffer)
Exemplo n.º 30
0
    def write(self, ostream):
        tstream = BytearrayStream()

        self.unique_identifier.write(tstream)

        # Write the length and value of the request payload
        self.length = tstream.length()
        super(DestroyResponsePayload, self).write(ostream)
        ostream.write(tstream.buffer)