mirror of
https://github.com/OpenKMIP/PyKMIP.git
synced 2025-07-21 13:04:22 +02:00
Merge pull request #308 from OpenKMIP/feat/update-get-payloads
Update the Get request and response payloads
This commit is contained in:
commit
ba09e5dd70
@ -13,143 +13,483 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from kmip.core.factories.secrets import SecretFactory
|
import six
|
||||||
|
|
||||||
from kmip.core import attributes
|
|
||||||
from kmip.core import enums
|
from kmip.core import enums
|
||||||
from kmip.core.enums import Tags
|
from kmip.core import objects
|
||||||
|
from kmip.core import primitives
|
||||||
|
from kmip.core import secrets
|
||||||
|
from kmip.core import utils
|
||||||
|
|
||||||
from kmip.core.objects import KeyWrappingSpecification
|
from kmip.core.factories import secrets as secret_factory
|
||||||
|
|
||||||
from kmip.core.primitives import Struct
|
|
||||||
from kmip.core.primitives import Enumeration
|
|
||||||
|
|
||||||
from kmip.core.utils import BytearrayStream
|
|
||||||
|
|
||||||
|
|
||||||
# 4.11
|
class GetRequestPayload(primitives.Struct):
|
||||||
class GetRequestPayload(Struct):
|
"""
|
||||||
|
A request payload for the Get operation.
|
||||||
|
|
||||||
# 9.1.3.2.2
|
Attributes:
|
||||||
class KeyCompressionType(Enumeration):
|
unique_identifier: The unique ID of the managed object to retrieve
|
||||||
|
from the server.
|
||||||
def __init__(self, value=None):
|
key_format_type: The format of the returned object, if it is a key.
|
||||||
super(GetRequestPayload.KeyCompressionType, self).__init__(
|
key_compression_type: The compression method to be used for the
|
||||||
enums.KeyCompressionType, value, Tags.KEY_COMPRESSION_TYPE)
|
returned object, if it is an elliptic curve public key.
|
||||||
|
key_wrapping_specification: A collection of settings specifying how
|
||||||
# 9.1.3.2.3
|
the returned object should be cryptographically wrapped if it is
|
||||||
class KeyFormatType(Enumeration):
|
a key.
|
||||||
|
"""
|
||||||
def __init__(self, value=None):
|
|
||||||
super(GetRequestPayload.KeyFormatType, self).__init__(
|
|
||||||
enums.KeyFormatType, value, Tags.KEY_FORMAT_TYPE)
|
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
unique_identifier=None,
|
unique_identifier=None,
|
||||||
key_format_type=None,
|
key_format_type=None,
|
||||||
key_compression_type=None,
|
key_compression_type=None,
|
||||||
key_wrapping_specification=None):
|
key_wrapping_specification=None):
|
||||||
super(GetRequestPayload, self).__init__(tag=enums.Tags.REQUEST_PAYLOAD)
|
"""
|
||||||
|
Construct a Get request payload struct.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
unique_identifier (string): The ID of the managed object (e.g., a
|
||||||
|
symmetric key) to retrieve. Optional, defaults to None.
|
||||||
|
key_format_type (KeyFormatType): A KeyFormatType enumeration that
|
||||||
|
specifies the format in which the object should be returned.
|
||||||
|
Optional, defaults to None.
|
||||||
|
key_compression_type (KeyCompressionType): A KeyCompressionType
|
||||||
|
enumeration that specifies the compression method to be used
|
||||||
|
when returning elliptic curve public keys. Optional, defaults
|
||||||
|
to None.
|
||||||
|
key_wrapping_specification (KeyWrappingSpecification): A
|
||||||
|
KeyWrappingSpecification struct that specifies keys and other
|
||||||
|
information for wrapping the returned object. Optional,
|
||||||
|
defaults to None.
|
||||||
|
"""
|
||||||
|
super(GetRequestPayload, self).__init__(
|
||||||
|
enums.Tags.REQUEST_PAYLOAD
|
||||||
|
)
|
||||||
|
|
||||||
|
self._unique_identifier = None
|
||||||
|
self._key_format_type = None
|
||||||
|
self._key_compression_type = None
|
||||||
|
self._key_wrapping_specification = None
|
||||||
|
|
||||||
self.unique_identifier = unique_identifier
|
self.unique_identifier = unique_identifier
|
||||||
self.key_format_type = key_format_type
|
self.key_format_type = key_format_type
|
||||||
self.key_compression_type = key_compression_type
|
self.key_compression_type = key_compression_type
|
||||||
self.key_wrapping_specification = key_wrapping_specification
|
self.key_wrapping_specification = key_wrapping_specification
|
||||||
self.validate()
|
|
||||||
|
|
||||||
def read(self, istream):
|
@property
|
||||||
super(GetRequestPayload, self).read(istream)
|
def unique_identifier(self):
|
||||||
tstream = BytearrayStream(istream.read(self.length))
|
if self._unique_identifier:
|
||||||
|
return self._unique_identifier.value
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
if self.is_tag_next(Tags.UNIQUE_IDENTIFIER, tstream):
|
@unique_identifier.setter
|
||||||
self.unique_identifier = attributes.UniqueIdentifier()
|
def unique_identifier(self, value):
|
||||||
self.unique_identifier.read(tstream)
|
if value is None:
|
||||||
|
self._unique_identifier = None
|
||||||
|
elif isinstance(value, six.string_types):
|
||||||
|
self._unique_identifier = primitives.TextString(
|
||||||
|
value=value,
|
||||||
|
tag=enums.Tags.UNIQUE_IDENTIFIER
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise TypeError("Unique identifier must be a string.")
|
||||||
|
|
||||||
if self.is_tag_next(Tags.KEY_FORMAT_TYPE, tstream):
|
@property
|
||||||
self.key_format_type = GetRequestPayload.KeyFormatType()
|
def key_format_type(self):
|
||||||
self.key_format_type.read(tstream)
|
if self._key_format_type:
|
||||||
|
return self._key_format_type.value
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
if self.is_tag_next(Tags.KEY_COMPRESSION_TYPE, tstream):
|
@key_format_type.setter
|
||||||
self.key_compression_type = GetRequestPayload.KeyCompressionType()
|
def key_format_type(self, value):
|
||||||
self.key_compression_type.read(tstream)
|
if value is None:
|
||||||
|
self._key_format_type = None
|
||||||
|
elif isinstance(value, enums.KeyFormatType):
|
||||||
|
self._key_format_type = primitives.Enumeration(
|
||||||
|
enums.KeyFormatType,
|
||||||
|
value=value,
|
||||||
|
tag=enums.Tags.KEY_FORMAT_TYPE
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
"Key format type must be a KeyFormatType enumeration."
|
||||||
|
)
|
||||||
|
|
||||||
if self.is_tag_next(Tags.KEY_WRAPPING_SPECIFICATION, tstream):
|
@property
|
||||||
self.key_wrapping_specification = KeyWrappingSpecification()
|
def key_compression_type(self):
|
||||||
self.key_wrapping_specification.read(tstream)
|
if self._key_compression_type:
|
||||||
|
return self._key_compression_type.value
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
self.is_oversized(tstream)
|
@key_compression_type.setter
|
||||||
self.validate()
|
def key_compression_type(self, value):
|
||||||
|
if value is None:
|
||||||
|
self._key_compression_type = None
|
||||||
|
elif isinstance(value, enums.KeyCompressionType):
|
||||||
|
self._key_compression_type = primitives.Enumeration(
|
||||||
|
enums.KeyCompressionType,
|
||||||
|
value=value,
|
||||||
|
tag=enums.Tags.KEY_COMPRESSION_TYPE
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
"Key compression type must be a KeyCompressionType "
|
||||||
|
"enumeration."
|
||||||
|
)
|
||||||
|
|
||||||
def write(self, ostream):
|
@property
|
||||||
tstream = BytearrayStream()
|
def key_wrapping_specification(self):
|
||||||
|
return self._key_wrapping_specification
|
||||||
|
|
||||||
# Write the contents of the request payload
|
@key_wrapping_specification.setter
|
||||||
if self.unique_identifier is not None:
|
def key_wrapping_specification(self, value):
|
||||||
self.unique_identifier.write(tstream)
|
if value is None:
|
||||||
if self.key_format_type is not None:
|
self._key_wrapping_specification = None
|
||||||
self.key_format_type.write(tstream)
|
elif isinstance(value, objects.KeyWrappingSpecification):
|
||||||
if self.key_compression_type is not None:
|
self._key_wrapping_specification = value
|
||||||
self.key_compression_type.write(tstream)
|
else:
|
||||||
if self.key_wrapping_specification is not None:
|
raise TypeError(
|
||||||
self.key_wrapping_specification.write(tstream)
|
"Key wrapping specification must be a "
|
||||||
|
"KeyWrappingSpecification struct."
|
||||||
|
)
|
||||||
|
|
||||||
# Write the length and value of the request payload
|
def read(self, input_stream):
|
||||||
self.length = tstream.length()
|
"""
|
||||||
super(GetRequestPayload, self).write(ostream)
|
Read the data encoding the Get request payload and decode it into its
|
||||||
ostream.write(tstream.buffer)
|
constituent parts.
|
||||||
|
|
||||||
def validate(self):
|
Args:
|
||||||
self.__validate()
|
input_stream (stream): A data stream containing encoded object
|
||||||
|
data, supporting a read method; usually a BytearrayStream
|
||||||
|
object.
|
||||||
|
"""
|
||||||
|
super(GetRequestPayload, self).read(input_stream)
|
||||||
|
local_stream = utils.BytearrayStream(input_stream.read(self.length))
|
||||||
|
|
||||||
def __validate(self):
|
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
|
||||||
# TODO (peter-hamilton) Finish implementation
|
self._unique_identifier = primitives.TextString(
|
||||||
pass
|
tag=enums.Tags.UNIQUE_IDENTIFIER
|
||||||
|
)
|
||||||
|
self._unique_identifier.read(local_stream)
|
||||||
|
|
||||||
|
if self.is_tag_next(enums.Tags.KEY_FORMAT_TYPE, local_stream):
|
||||||
|
self._key_format_type = primitives.Enumeration(
|
||||||
|
enum=enums.KeyFormatType,
|
||||||
|
tag=enums.Tags.KEY_FORMAT_TYPE
|
||||||
|
)
|
||||||
|
self._key_format_type.read(local_stream)
|
||||||
|
|
||||||
|
if self.is_tag_next(enums.Tags.KEY_COMPRESSION_TYPE, local_stream):
|
||||||
|
self._key_compression_type = primitives.Enumeration(
|
||||||
|
enum=enums.KeyCompressionType,
|
||||||
|
tag=enums.Tags.KEY_COMPRESSION_TYPE
|
||||||
|
)
|
||||||
|
self._key_compression_type.read(local_stream)
|
||||||
|
|
||||||
|
if self.is_tag_next(
|
||||||
|
enums.Tags.KEY_WRAPPING_SPECIFICATION,
|
||||||
|
local_stream
|
||||||
|
):
|
||||||
|
self._key_wrapping_specification = \
|
||||||
|
objects.KeyWrappingSpecification()
|
||||||
|
self._key_wrapping_specification.read(local_stream)
|
||||||
|
|
||||||
|
self.is_oversized(local_stream)
|
||||||
|
|
||||||
|
def write(self, output_stream):
|
||||||
|
"""
|
||||||
|
Write the data encoding the Get request payload to a stream.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
output_stream (stream): A data stream in which to encode object
|
||||||
|
data, supporting a write method; usually a BytearrayStream
|
||||||
|
object.
|
||||||
|
"""
|
||||||
|
local_stream = utils.BytearrayStream()
|
||||||
|
|
||||||
|
if self._unique_identifier is not None:
|
||||||
|
self._unique_identifier.write(local_stream)
|
||||||
|
if self._key_format_type is not None:
|
||||||
|
self._key_format_type.write(local_stream)
|
||||||
|
if self._key_compression_type is not None:
|
||||||
|
self._key_compression_type.write(local_stream)
|
||||||
|
if self._key_wrapping_specification is not None:
|
||||||
|
self._key_wrapping_specification.write(local_stream)
|
||||||
|
|
||||||
|
self.length = local_stream.length()
|
||||||
|
super(GetRequestPayload, self).write(output_stream)
|
||||||
|
output_stream.write(local_stream.buffer)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
if isinstance(other, GetRequestPayload):
|
||||||
|
if self.unique_identifier != other.unique_identifier:
|
||||||
|
return False
|
||||||
|
elif self.key_format_type != other.key_format_type:
|
||||||
|
return False
|
||||||
|
elif self.key_compression_type != other.key_compression_type:
|
||||||
|
return False
|
||||||
|
elif self.key_wrapping_specification != \
|
||||||
|
other.key_wrapping_specification:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
if isinstance(other, GetRequestPayload):
|
||||||
|
return not (self == other)
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
args = ", ".join([
|
||||||
|
"unique_identifier='{0}'".format(self.unique_identifier),
|
||||||
|
"key_format_type={0}".format(self.key_format_type),
|
||||||
|
"key_compression_type={0}".format(self.key_compression_type),
|
||||||
|
"key_wrapping_specification={0}".format(
|
||||||
|
repr(self.key_wrapping_specification)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
return "GetRequestPayload({0})".format(args)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str({
|
||||||
|
'unique_identifier': self.unique_identifier,
|
||||||
|
'key_format_type': self.key_format_type,
|
||||||
|
'key_compression_type': self.key_compression_type,
|
||||||
|
'key_wrapping_specification': self.key_wrapping_specification
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class GetResponsePayload(Struct):
|
class GetResponsePayload(primitives.Struct):
|
||||||
|
"""
|
||||||
|
A response payload for the Get operation.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
object_type: The type of the managed object being returned.
|
||||||
|
unique_identifier: The unique ID of the managed object being returned.
|
||||||
|
secret: The managed object being returned.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
object_type=None,
|
object_type=None,
|
||||||
unique_identifier=None,
|
unique_identifier=None,
|
||||||
secret=None):
|
secret=None):
|
||||||
super(GetResponsePayload, self).__init__(tag=Tags.RESPONSE_PAYLOAD)
|
"""
|
||||||
|
Construct a Get response payload struct.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
object_type (ObjectType): An ObjectType enumeration specifying the
|
||||||
|
type of managed object being returned. Optional, defaults to
|
||||||
|
None. Required for read/write.
|
||||||
|
unique_identifier (string): The ID of the managed object (e.g., a
|
||||||
|
symmetric key) being returned. Optional, defaults to None.
|
||||||
|
Required for read/write.
|
||||||
|
secret (various): The managed object struct being returned. Must
|
||||||
|
be one of the following:
|
||||||
|
|
||||||
|
Optional, defaults to None. Required for read/write.
|
||||||
|
"""
|
||||||
|
super(GetResponsePayload, self).__init__(
|
||||||
|
tag=enums.Tags.RESPONSE_PAYLOAD
|
||||||
|
)
|
||||||
|
self._object_type = None
|
||||||
|
self._unique_identifier = None
|
||||||
|
self._secret = None
|
||||||
|
|
||||||
self.object_type = object_type
|
self.object_type = object_type
|
||||||
self.unique_identifier = unique_identifier
|
self.unique_identifier = unique_identifier
|
||||||
self.secret = secret
|
self.secret = secret
|
||||||
self.secret_factory = SecretFactory()
|
|
||||||
self.validate()
|
|
||||||
|
|
||||||
def read(self, istream):
|
self.secret_factory = secret_factory.SecretFactory()
|
||||||
super(GetResponsePayload, self).read(istream)
|
|
||||||
tstream = BytearrayStream(istream.read(self.length))
|
|
||||||
|
|
||||||
self.object_type = attributes.ObjectType()
|
@property
|
||||||
self.unique_identifier = attributes.UniqueIdentifier()
|
def object_type(self):
|
||||||
|
if self._object_type:
|
||||||
|
return self._object_type.value
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
self.object_type.read(tstream)
|
@object_type.setter
|
||||||
self.unique_identifier.read(tstream)
|
def object_type(self, value):
|
||||||
|
if value is None:
|
||||||
|
self._object_type = None
|
||||||
|
elif isinstance(value, enums.ObjectType):
|
||||||
|
self._object_type = primitives.Enumeration(
|
||||||
|
enums.ObjectType,
|
||||||
|
value=value,
|
||||||
|
tag=enums.Tags.OBJECT_TYPE
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise TypeError("Object type must be an ObjectType enumeration.")
|
||||||
|
|
||||||
secret_type = self.object_type.value
|
@property
|
||||||
self.secret = self.secret_factory.create(secret_type)
|
def unique_identifier(self):
|
||||||
self.secret.read(tstream)
|
if self._unique_identifier:
|
||||||
|
return self._unique_identifier.value
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
self.is_oversized(tstream)
|
@unique_identifier.setter
|
||||||
self.validate()
|
def unique_identifier(self, value):
|
||||||
|
if value is None:
|
||||||
|
self._unique_identifier = None
|
||||||
|
elif isinstance(value, six.string_types):
|
||||||
|
self._unique_identifier = primitives.TextString(
|
||||||
|
value=value,
|
||||||
|
tag=enums.Tags.UNIQUE_IDENTIFIER
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise TypeError("Unique identifier must be a string.")
|
||||||
|
|
||||||
def write(self, ostream):
|
@property
|
||||||
tstream = BytearrayStream()
|
def secret(self):
|
||||||
|
return self._secret
|
||||||
|
|
||||||
self.object_type.write(tstream)
|
@secret.setter
|
||||||
self.unique_identifier.write(tstream)
|
def secret(self, value):
|
||||||
self.secret.write(tstream)
|
if value is None:
|
||||||
|
self._secret = None
|
||||||
|
elif isinstance(
|
||||||
|
value,
|
||||||
|
(
|
||||||
|
secrets.Certificate,
|
||||||
|
secrets.OpaqueObject,
|
||||||
|
secrets.PrivateKey,
|
||||||
|
secrets.PublicKey,
|
||||||
|
secrets.SecretData,
|
||||||
|
secrets.SplitKey,
|
||||||
|
secrets.SymmetricKey,
|
||||||
|
secrets.Template
|
||||||
|
)
|
||||||
|
):
|
||||||
|
self._secret = value
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
"Secret must be one of the following structs: Certificate, "
|
||||||
|
"OpaqueObject, PrivateKey, PublicKey, SecretData, SplitKey, "
|
||||||
|
"SymmetricKey, Template"
|
||||||
|
)
|
||||||
|
|
||||||
# Write the length and value of the request payload
|
def read(self, input_stream):
|
||||||
self.length = tstream.length()
|
"""
|
||||||
super(GetResponsePayload, self).write(ostream)
|
Read the data encoding the Get response payload and decode it
|
||||||
ostream.write(tstream.buffer)
|
into its constituent parts.
|
||||||
|
|
||||||
def validate(self):
|
Args:
|
||||||
self.__validate()
|
input_stream (stream): A data stream containing encoded object
|
||||||
|
data, supporting a read method; usually a BytearrayStream
|
||||||
|
object.
|
||||||
|
|
||||||
def __validate(self):
|
Raises:
|
||||||
# TODO (peter-hamilton) Finish implementation.
|
ValueError: Raised if the object type, unique identifier, or
|
||||||
pass
|
secret attributes are missing from the encoded payload.
|
||||||
|
"""
|
||||||
|
super(GetResponsePayload, self).read(input_stream)
|
||||||
|
local_stream = utils.BytearrayStream(input_stream.read(self.length))
|
||||||
|
|
||||||
|
if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_stream):
|
||||||
|
self._object_type = primitives.Enumeration(
|
||||||
|
enum=enums.ObjectType,
|
||||||
|
tag=enums.Tags.OBJECT_TYPE
|
||||||
|
)
|
||||||
|
self._object_type.read(local_stream)
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
"Parsed payload encoding is missing the object type field."
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
|
||||||
|
self._unique_identifier = primitives.TextString(
|
||||||
|
tag=enums.Tags.UNIQUE_IDENTIFIER
|
||||||
|
)
|
||||||
|
self._unique_identifier.read(local_stream)
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
"Parsed payload encoding is missing the unique identifier "
|
||||||
|
"field."
|
||||||
|
)
|
||||||
|
|
||||||
|
self.secret = self.secret_factory.create(self.object_type)
|
||||||
|
if self.is_tag_next(self._secret.tag, local_stream):
|
||||||
|
self._secret.read(local_stream)
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
"Parsed payload encoding is missing the secret field."
|
||||||
|
)
|
||||||
|
|
||||||
|
self.is_oversized(local_stream)
|
||||||
|
|
||||||
|
def write(self, output_stream):
|
||||||
|
"""
|
||||||
|
Write the data encoding the Get response payload to a stream.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
output_stream (stream): A data stream in which to encode object
|
||||||
|
data, supporting a write method; usually a BytearrayStream
|
||||||
|
object.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: Raised if the object type, unique identifier, or
|
||||||
|
secret attributes are missing from the payload struct.
|
||||||
|
"""
|
||||||
|
local_stream = utils.BytearrayStream()
|
||||||
|
|
||||||
|
if self.object_type:
|
||||||
|
self._object_type.write(local_stream)
|
||||||
|
else:
|
||||||
|
raise ValueError("Payload is missing the object type field.")
|
||||||
|
|
||||||
|
if self.unique_identifier:
|
||||||
|
self._unique_identifier.write(local_stream)
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
"Payload is missing the unique identifier field."
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.secret:
|
||||||
|
self._secret.write(local_stream)
|
||||||
|
else:
|
||||||
|
raise ValueError("Payload is missing the secret field.")
|
||||||
|
|
||||||
|
self.length = local_stream.length()
|
||||||
|
super(GetResponsePayload, self).write(output_stream)
|
||||||
|
output_stream.write(local_stream.buffer)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
if isinstance(other, GetResponsePayload):
|
||||||
|
if self.object_type != other.object_type:
|
||||||
|
return False
|
||||||
|
elif self.unique_identifier != other.unique_identifier:
|
||||||
|
return False
|
||||||
|
elif self.secret != other.secret:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
if isinstance(other, GetResponsePayload):
|
||||||
|
return not (self == other)
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
args = ", ".join([
|
||||||
|
"object_type={0}".format(self.object_type),
|
||||||
|
"unique_identifier='{0}'".format(self.unique_identifier),
|
||||||
|
"secret={0}".format(repr(self.secret))
|
||||||
|
])
|
||||||
|
return "GetResponsePayload({0})".format(args)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str({
|
||||||
|
'object_type': self.object_type,
|
||||||
|
'unique_identifier': self.unique_identifier,
|
||||||
|
'secret': self.secret
|
||||||
|
})
|
||||||
|
@ -92,9 +92,9 @@ if __name__ == '__main__':
|
|||||||
if result.result_status.value == ResultStatus.SUCCESS:
|
if result.result_status.value == ResultStatus.SUCCESS:
|
||||||
logger.info('retrieved object type: {0}'.format(
|
logger.info('retrieved object type: {0}'.format(
|
||||||
result.object_type.value))
|
result.object_type.value))
|
||||||
logger.info('retrieved UUID: {0}'.format(result.uuid.value))
|
logger.info('retrieved UUID: {0}'.format(result.uuid))
|
||||||
|
|
||||||
utils.log_secret(logger, result.object_type.value, result.secret)
|
utils.log_secret(logger, result.object_type, result.secret)
|
||||||
else:
|
else:
|
||||||
logger.info('get() result reason: {0}'.format(
|
logger.info('get() result reason: {0}'.format(
|
||||||
result.result_reason.value))
|
result.result_reason.value))
|
||||||
|
@ -769,25 +769,19 @@ class KMIPProxy(KMIP):
|
|||||||
credential=None):
|
credential=None):
|
||||||
operation = Operation(OperationEnum.GET)
|
operation = Operation(OperationEnum.GET)
|
||||||
|
|
||||||
uuid = None
|
|
||||||
kft = None
|
|
||||||
kct = None
|
|
||||||
kws = None
|
kws = None
|
||||||
|
|
||||||
if unique_identifier is not None:
|
|
||||||
uuid = attr.UniqueIdentifier(unique_identifier)
|
|
||||||
if key_format_type is not None:
|
if key_format_type is not None:
|
||||||
kft = get.GetRequestPayload.KeyFormatType(key_format_type.value)
|
key_format_type = key_format_type.value
|
||||||
if key_compression_type is not None:
|
|
||||||
kct = key_compression_type
|
|
||||||
kct = get.GetRequestPayload.KeyCompressionType(kct)
|
|
||||||
if key_wrapping_specification is not None:
|
if key_wrapping_specification is not None:
|
||||||
kws = objects.KeyWrappingSpecification(key_wrapping_specification)
|
kws = objects.KeyWrappingSpecification(key_wrapping_specification)
|
||||||
|
|
||||||
req_pl = get.GetRequestPayload(unique_identifier=uuid,
|
req_pl = get.GetRequestPayload(
|
||||||
key_format_type=kft,
|
unique_identifier=unique_identifier,
|
||||||
key_compression_type=kct,
|
key_format_type=key_format_type,
|
||||||
key_wrapping_specification=kws)
|
key_compression_type=key_compression_type,
|
||||||
|
key_wrapping_specification=kws
|
||||||
|
)
|
||||||
|
|
||||||
batch_item = messages.RequestBatchItem(operation=operation,
|
batch_item = messages.RequestBatchItem(operation=operation,
|
||||||
request_payload=req_pl)
|
request_payload=req_pl)
|
||||||
|
@ -1378,11 +1378,11 @@ class KmipEngine(object):
|
|||||||
|
|
||||||
unique_identifier = self._id_placeholder
|
unique_identifier = self._id_placeholder
|
||||||
if payload.unique_identifier:
|
if payload.unique_identifier:
|
||||||
unique_identifier = payload.unique_identifier.value
|
unique_identifier = payload.unique_identifier
|
||||||
|
|
||||||
key_format_type = None
|
key_format_type = None
|
||||||
if payload.key_format_type:
|
if payload.key_format_type:
|
||||||
key_format_type = payload.key_format_type.value
|
key_format_type = payload.key_format_type
|
||||||
|
|
||||||
if payload.key_compression_type:
|
if payload.key_compression_type:
|
||||||
raise exceptions.KeyCompressionTypeNotSupported(
|
raise exceptions.KeyCompressionTypeNotSupported(
|
||||||
@ -1429,8 +1429,8 @@ class KmipEngine(object):
|
|||||||
core_secret = self._build_core_object(managed_object)
|
core_secret = self._build_core_object(managed_object)
|
||||||
|
|
||||||
response_payload = get.GetResponsePayload(
|
response_payload = get.GetResponsePayload(
|
||||||
object_type=attributes.ObjectType(managed_object._object_type),
|
object_type=managed_object._object_type,
|
||||||
unique_identifier=attributes.UniqueIdentifier(unique_identifier),
|
unique_identifier=unique_identifier,
|
||||||
secret=core_secret
|
secret=core_secret
|
||||||
)
|
)
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -480,16 +480,16 @@ class TestRequestMessage(TestCase):
|
|||||||
msg.format(get.GetRequestPayload,
|
msg.format(get.GetRequestPayload,
|
||||||
type(request_payload)))
|
type(request_payload)))
|
||||||
|
|
||||||
unique_identifier = request_payload.unique_identifier
|
# unique_identifier = request_payload.unique_identifier
|
||||||
msg = "Bad unique identifier type: expected {0}, received {1}"
|
# msg = "Bad unique identifier type: expected {0}, received {1}"
|
||||||
self.assertIsInstance(unique_identifier, attr.UniqueIdentifier,
|
# self.assertIsInstance(unique_identifier, attr.UniqueIdentifier,
|
||||||
msg.format(attr.UniqueIdentifier,
|
# msg.format(attr.UniqueIdentifier,
|
||||||
type(unique_identifier)))
|
# type(unique_identifier)))
|
||||||
msg = "Bad unique identifier value: expected {0}, received {1}"
|
# msg = "Bad unique identifier value: expected {0}, received {1}"
|
||||||
self.assertEqual('49a1ca88-6bea-4fb2-b450-7e58802c3038',
|
self.assertEqual(
|
||||||
unique_identifier.value,
|
'49a1ca88-6bea-4fb2-b450-7e58802c3038',
|
||||||
msg.format('49a1ca88-6bea-4fb2-b450-7e58802c3038',
|
request_payload.unique_identifier
|
||||||
unique_identifier.value))
|
)
|
||||||
|
|
||||||
def test_get_request_write(self):
|
def test_get_request_write(self):
|
||||||
prot_ver = contents.ProtocolVersion.create(1, 1)
|
prot_ver = contents.ProtocolVersion.create(1, 1)
|
||||||
@ -500,8 +500,10 @@ class TestRequestMessage(TestCase):
|
|||||||
|
|
||||||
operation = contents.Operation(enums.Operation.GET)
|
operation = contents.Operation(enums.Operation.GET)
|
||||||
|
|
||||||
uuid = attr.UniqueIdentifier('49a1ca88-6bea-4fb2-b450-7e58802c3038')
|
# uuid = attr.UniqueIdentifier('49a1ca88-6bea-4fb2-b450-7e58802c3038')
|
||||||
request_payload = get.GetRequestPayload(unique_identifier=uuid)
|
request_payload = get.GetRequestPayload(
|
||||||
|
unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038'
|
||||||
|
)
|
||||||
batch_item = messages.RequestBatchItem(operation=operation,
|
batch_item = messages.RequestBatchItem(operation=operation,
|
||||||
request_payload=request_payload)
|
request_payload=request_payload)
|
||||||
request_message = messages.RequestMessage(request_header=req_header,
|
request_message = messages.RequestMessage(request_header=req_header,
|
||||||
@ -1498,25 +1500,14 @@ class TestResponseMessage(TestCase):
|
|||||||
self.msg.format('response payload', 'type',
|
self.msg.format('response payload', 'type',
|
||||||
exp_type, rcv_type))
|
exp_type, rcv_type))
|
||||||
|
|
||||||
object_type = response_payload.object_type
|
self.assertEqual(
|
||||||
self.assertIsInstance(object_type, attr.ObjectType,
|
|
||||||
self.msg.format('object type', 'type',
|
|
||||||
attr.ObjectType,
|
|
||||||
type(object_type)))
|
|
||||||
self.assertEqual(enums.ObjectType.SYMMETRIC_KEY, object_type.value,
|
|
||||||
self.msg.format('object type', 'value',
|
|
||||||
enums.ObjectType.SYMMETRIC_KEY,
|
enums.ObjectType.SYMMETRIC_KEY,
|
||||||
object_type.value))
|
response_payload.object_type
|
||||||
|
)
|
||||||
unique_identifier = response_payload.unique_identifier
|
self.assertEqual(
|
||||||
value = '49a1ca88-6bea-4fb2-b450-7e58802c3038'
|
'49a1ca88-6bea-4fb2-b450-7e58802c3038',
|
||||||
self.assertIsInstance(unique_identifier, attr.UniqueIdentifier,
|
response_payload.unique_identifier
|
||||||
self.msg.format('unique identifier', 'type',
|
)
|
||||||
attr.UniqueIdentifier,
|
|
||||||
type(unique_identifier)))
|
|
||||||
self.assertEqual(value, unique_identifier.value,
|
|
||||||
self.msg.format('unique identifier', 'value',
|
|
||||||
unique_identifier.value, value))
|
|
||||||
|
|
||||||
secret = response_payload.secret
|
secret = response_payload.secret
|
||||||
self.assertIsInstance(secret, SymmetricKey,
|
self.assertIsInstance(secret, SymmetricKey,
|
||||||
@ -1619,8 +1610,8 @@ class TestResponseMessage(TestCase):
|
|||||||
|
|
||||||
secret = SymmetricKey(key_block)
|
secret = SymmetricKey(key_block)
|
||||||
|
|
||||||
resp_pl = get.GetResponsePayload(object_type=object_type,
|
resp_pl = get.GetResponsePayload(object_type=object_type.value,
|
||||||
unique_identifier=uniq_id,
|
unique_identifier=uniq_id.value,
|
||||||
secret=secret)
|
secret=secret)
|
||||||
batch_item = messages.ResponseBatchItem(operation=operation,
|
batch_item = messages.ResponseBatchItem(operation=operation,
|
||||||
result_status=result_status,
|
result_status=result_status,
|
||||||
|
@ -3679,9 +3679,7 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
id_b = str(obj_b.unique_identifier)
|
id_b = str(obj_b.unique_identifier)
|
||||||
|
|
||||||
# Test by specifying the ID of the object to get.
|
# Test by specifying the ID of the object to get.
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(unique_identifier=id_a)
|
||||||
unique_identifier=attributes.UniqueIdentifier(id_a)
|
|
||||||
)
|
|
||||||
|
|
||||||
response_payload = e._process_get(payload)
|
response_payload = e._process_get(payload)
|
||||||
e._data_session.commit()
|
e._data_session.commit()
|
||||||
@ -3692,9 +3690,9 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.ObjectType.OPAQUE_DATA,
|
enums.ObjectType.OPAQUE_DATA,
|
||||||
response_payload.object_type.value
|
response_payload.object_type
|
||||||
)
|
)
|
||||||
self.assertEqual(str(id_a), response_payload.unique_identifier.value)
|
self.assertEqual(str(id_a), response_payload.unique_identifier)
|
||||||
self.assertIsInstance(response_payload.secret, secrets.OpaqueObject)
|
self.assertIsInstance(response_payload.secret, secrets.OpaqueObject)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.OpaqueDataType.NONE,
|
enums.OpaqueDataType.NONE,
|
||||||
@ -3722,9 +3720,9 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.ObjectType.OPAQUE_DATA,
|
enums.ObjectType.OPAQUE_DATA,
|
||||||
response_payload.object_type.value
|
response_payload.object_type
|
||||||
)
|
)
|
||||||
self.assertEqual(str(id_b), response_payload.unique_identifier.value)
|
self.assertEqual(str(id_b), response_payload.unique_identifier)
|
||||||
self.assertIsInstance(response_payload.secret, secrets.OpaqueObject)
|
self.assertIsInstance(response_payload.secret, secrets.OpaqueObject)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.OpaqueDataType.NONE,
|
enums.OpaqueDataType.NONE,
|
||||||
@ -3749,11 +3747,8 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
e._logger = mock.MagicMock()
|
e._logger = mock.MagicMock()
|
||||||
|
|
||||||
# Test that specifying the key compression type generates an error.
|
# Test that specifying the key compression type generates an error.
|
||||||
payload = get.GetRequestPayload(
|
k = enums.KeyCompressionType.EC_PUBLIC_KEY_TYPE_UNCOMPRESSED
|
||||||
key_compression_type=get.GetRequestPayload.KeyCompressionType(
|
payload = get.GetRequestPayload(key_compression_type=k)
|
||||||
enums.KeyCompressionType.EC_PUBLIC_KEY_TYPE_UNCOMPRESSED
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
args = (payload, )
|
args = (payload, )
|
||||||
regex = "Key compression is not supported."
|
regex = "Key compression is not supported."
|
||||||
@ -3813,10 +3808,8 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
|
|
||||||
# Test that a key can be retrieved with the right key format.
|
# Test that a key can be retrieved with the right key format.
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(
|
||||||
unique_identifier=attributes.UniqueIdentifier(id_a),
|
unique_identifier=id_a,
|
||||||
key_format_type=get.GetRequestPayload.KeyFormatType(
|
key_format_type=enums.KeyFormatType.RAW
|
||||||
enums.KeyFormatType.RAW
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response_payload = e._process_get(payload)
|
response_payload = e._process_get(payload)
|
||||||
@ -3850,10 +3843,8 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
e._logger.reset_mock()
|
e._logger.reset_mock()
|
||||||
|
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(
|
||||||
unique_identifier=attributes.UniqueIdentifier(id_a),
|
unique_identifier=id_a,
|
||||||
key_format_type=get.GetRequestPayload.KeyFormatType(
|
key_format_type=enums.KeyFormatType.OPAQUE
|
||||||
enums.KeyFormatType.OPAQUE
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
args = (payload, )
|
args = (payload, )
|
||||||
@ -3883,10 +3874,8 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
id_b = str(obj_b.unique_identifier)
|
id_b = str(obj_b.unique_identifier)
|
||||||
|
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(
|
||||||
unique_identifier=attributes.UniqueIdentifier(id_b),
|
unique_identifier=id_b,
|
||||||
key_format_type=get.GetRequestPayload.KeyFormatType(
|
key_format_type=enums.KeyFormatType.RAW
|
||||||
enums.KeyFormatType.RAW
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
args = (payload, )
|
args = (payload, )
|
||||||
@ -3921,9 +3910,7 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
e._data_session = e._data_store_session_factory()
|
e._data_session = e._data_store_session_factory()
|
||||||
|
|
||||||
id_a = str(obj_a.unique_identifier)
|
id_a = str(obj_a.unique_identifier)
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(unique_identifier=id_a)
|
||||||
unique_identifier=attributes.UniqueIdentifier(id_a)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Test by specifying the ID of the object to get.
|
# Test by specifying the ID of the object to get.
|
||||||
args = [payload]
|
args = [payload]
|
||||||
@ -5931,9 +5918,7 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
e._logger.reset_mock()
|
e._logger.reset_mock()
|
||||||
|
|
||||||
# Retrieve the created key using Get and verify all fields set
|
# Retrieve the created key using Get and verify all fields set
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(unique_identifier=uid)
|
||||||
unique_identifier=attributes.UniqueIdentifier(uid)
|
|
||||||
)
|
|
||||||
|
|
||||||
response_payload = e._process_get(payload)
|
response_payload = e._process_get(payload)
|
||||||
e._data_session.commit()
|
e._data_session.commit()
|
||||||
@ -5944,9 +5929,9 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.ObjectType.SYMMETRIC_KEY,
|
enums.ObjectType.SYMMETRIC_KEY,
|
||||||
response_payload.object_type.value
|
response_payload.object_type
|
||||||
)
|
)
|
||||||
self.assertEqual(str(uid), response_payload.unique_identifier.value)
|
self.assertEqual(str(uid), response_payload.unique_identifier)
|
||||||
self.assertIsInstance(response_payload.secret, secrets.SymmetricKey)
|
self.assertIsInstance(response_payload.secret, secrets.SymmetricKey)
|
||||||
|
|
||||||
key_block = response_payload.secret.key_block
|
key_block = response_payload.secret.key_block
|
||||||
@ -6070,9 +6055,7 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
e._logger.reset_mock()
|
e._logger.reset_mock()
|
||||||
|
|
||||||
# Retrieve the created public key using Get and verify all fields set
|
# Retrieve the created public key using Get and verify all fields set
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(unique_identifier=public_id)
|
||||||
unique_identifier=attributes.UniqueIdentifier(public_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
response_payload = e._process_get(payload)
|
response_payload = e._process_get(payload)
|
||||||
e._data_session.commit()
|
e._data_session.commit()
|
||||||
@ -6083,12 +6066,9 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.ObjectType.PUBLIC_KEY,
|
enums.ObjectType.PUBLIC_KEY,
|
||||||
response_payload.object_type.value
|
response_payload.object_type
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(public_id),
|
|
||||||
response_payload.unique_identifier.value
|
|
||||||
)
|
)
|
||||||
|
self.assertEqual(str(public_id), response_payload.unique_identifier)
|
||||||
self.assertIsInstance(response_payload.secret, secrets.PublicKey)
|
self.assertIsInstance(response_payload.secret, secrets.PublicKey)
|
||||||
|
|
||||||
key_block = response_payload.secret.key_block
|
key_block = response_payload.secret.key_block
|
||||||
@ -6108,9 +6088,7 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
e._logger.reset_mock()
|
e._logger.reset_mock()
|
||||||
|
|
||||||
# Retrieve the created private key using Get and verify all fields set
|
# Retrieve the created private key using Get and verify all fields set
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(unique_identifier=private_id)
|
||||||
unique_identifier=attributes.UniqueIdentifier(private_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
response_payload = e._process_get(payload)
|
response_payload = e._process_get(payload)
|
||||||
e._data_session.commit()
|
e._data_session.commit()
|
||||||
@ -6121,12 +6099,9 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.ObjectType.PRIVATE_KEY,
|
enums.ObjectType.PRIVATE_KEY,
|
||||||
response_payload.object_type.value
|
response_payload.object_type
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(private_id),
|
|
||||||
response_payload.unique_identifier.value
|
|
||||||
)
|
)
|
||||||
|
self.assertEqual(str(private_id), response_payload.unique_identifier)
|
||||||
self.assertIsInstance(response_payload.secret, secrets.PrivateKey)
|
self.assertIsInstance(response_payload.secret, secrets.PrivateKey)
|
||||||
|
|
||||||
key_block = response_payload.secret.key_block
|
key_block = response_payload.secret.key_block
|
||||||
@ -6295,9 +6270,7 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
e._logger.reset_mock()
|
e._logger.reset_mock()
|
||||||
|
|
||||||
# Retrieve the registered key using Get and verify all fields set
|
# Retrieve the registered key using Get and verify all fields set
|
||||||
payload = get.GetRequestPayload(
|
payload = get.GetRequestPayload(unique_identifier=uid)
|
||||||
unique_identifier=attributes.UniqueIdentifier(uid)
|
|
||||||
)
|
|
||||||
|
|
||||||
response_payload = e._process_get(payload)
|
response_payload = e._process_get(payload)
|
||||||
e._data_session.commit()
|
e._data_session.commit()
|
||||||
@ -6308,9 +6281,9 @@ class TestKmipEngine(testtools.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
enums.ObjectType.SYMMETRIC_KEY,
|
enums.ObjectType.SYMMETRIC_KEY,
|
||||||
response_payload.object_type.value
|
response_payload.object_type
|
||||||
)
|
)
|
||||||
self.assertEqual(str(uid), response_payload.unique_identifier.value)
|
self.assertEqual(str(uid), response_payload.unique_identifier)
|
||||||
self.assertIsInstance(response_payload.secret, secrets.SymmetricKey)
|
self.assertIsInstance(response_payload.secret, secrets.SymmetricKey)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
key_bytes,
|
key_bytes,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user