Update the CreateKeyPair payloads

This change updates the CreateKeyPair payloads to the current
payload format, adding properties for different payload attributes
and adding comparison and string operators. Changes are also made
to the PyKMIP clients and the surrounding testing infrastructure
to reflect the payload changes. The official unit test suite for
the CreateKeyPair payloads has been updated to also reflect these
changes.

This change prepares the CreateKeyPair payloads for future
updates to support KMIP 2.0.
This commit is contained in:
Peter Hamilton 2019-03-13 18:34:21 -04:00 committed by Peter Hamilton
parent fe3095c22b
commit 71d508019a
12 changed files with 3767 additions and 646 deletions

View File

@ -13,243 +13,590 @@
# 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 import attributes import six
from kmip.core import objects
from kmip.core import enums from kmip.core import enums
from kmip.core import exceptions
from kmip.core.primitives import Struct from kmip.core import objects
from kmip.core import primitives
from kmip.core.utils import BytearrayStream from kmip.core import utils
class CreateKeyPairRequestPayload(Struct): class CreateKeyPairRequestPayload(primitives.Struct):
"""
A request payload for the CreateKeyPair operation.
Attributes:
common_template_attribute: A group of attributes to set on the new
public and private keys.
private_key_template_attribute: A group of attributes to set on the new
private key.
public_key_template_attribute: A group of attributes to set on the new
public key.
"""
def __init__(self, def __init__(self,
common_template_attribute=None, common_template_attribute=None,
private_key_template_attribute=None, private_key_template_attribute=None,
public_key_template_attribute=None): public_key_template_attribute=None):
"""
Construct a CreateKeyPair request payload structure.
Args:
common_template_attribute (TemplateAttribute): A TemplateAttribute
structure with the CommonTemplateAttribute tag containing a set
of attributes to set on the new public and private keys.
Optional, defaults to None.
private_key_template_attribute (TemplateAttribute): A
TemplateAttribute structure with the
PrivateKeyTemplateAttribute tag containing a set of attributes
to set on the new private key. Optional, defaults to None.
public_key_template_attribute (TemplateAttribute): A
TemplateAttribute structure with the PublicKeyTemplateAttribute
tag containing a set of attributes to set on the new public
key. Optional, defaults to None.
"""
super(CreateKeyPairRequestPayload, self).__init__( super(CreateKeyPairRequestPayload, self).__init__(
enums.Tags.REQUEST_PAYLOAD enums.Tags.REQUEST_PAYLOAD
) )
self._common_template_attribute = None
self._private_key_template_attribute = None
self._public_key_template_attribute = None
self.common_template_attribute = common_template_attribute self.common_template_attribute = common_template_attribute
self.private_key_template_attribute = private_key_template_attribute self.private_key_template_attribute = private_key_template_attribute
self.public_key_template_attribute = public_key_template_attribute self.public_key_template_attribute = public_key_template_attribute
self.validate() @property
def common_template_attribute(self):
return self._common_template_attribute
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): @common_template_attribute.setter
def common_template_attribute(self, value):
if value is None:
self._common_template_attribute = None
elif isinstance(value, objects.TemplateAttribute):
if value.tag == enums.Tags.COMMON_TEMPLATE_ATTRIBUTE:
self._common_template_attribute = value
else:
raise TypeError(
"Common template attribute must be a TemplateAttribute "
"structure with a CommonTemplateAttribute tag."
)
else:
raise TypeError(
"Common template attribute must be a TemplateAttribute "
"structure."
)
@property
def private_key_template_attribute(self):
return self._private_key_template_attribute
@private_key_template_attribute.setter
def private_key_template_attribute(self, value):
if value is None:
self._private_key_template_attribute = None
elif isinstance(value, objects.TemplateAttribute):
if value.tag == enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE:
self._private_key_template_attribute = value
else:
raise TypeError(
"Private key template attribute must be a "
"TemplateAttribute structure with a "
"PrivateKeyTemplateAttribute tag."
)
else:
raise TypeError(
"Private key template attribute must be a TemplateAttribute "
"structure."
)
@property
def public_key_template_attribute(self):
return self._public_key_template_attribute
@public_key_template_attribute.setter
def public_key_template_attribute(self, value):
if value is None:
self._public_key_template_attribute = None
elif isinstance(value, objects.TemplateAttribute):
if value.tag == enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE:
self._public_key_template_attribute = value
else:
raise TypeError(
"Public key template attribute must be a "
"TemplateAttribute structure with a "
"PublicKeyTemplateAttribute tag."
)
else:
raise TypeError(
"Public key template attribute must be a TemplateAttribute "
"structure."
)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair request payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(CreateKeyPairRequestPayload, self).read( super(CreateKeyPairRequestPayload, self).read(
istream, input_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
tstream = BytearrayStream(istream.read(self.length)) local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.COMMON_TEMPLATE_ATTRIBUTE, tstream): if self.is_tag_next(
self.common_template_attribute = objects.CommonTemplateAttribute() enums.Tags.COMMON_TEMPLATE_ATTRIBUTE,
self.common_template_attribute.read( local_buffer
tstream, ):
self._common_template_attribute = objects.TemplateAttribute(
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
self._common_template_attribute.read(
local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
if self.is_tag_next(enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE, if self.is_tag_next(
tstream): enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
self.private_key_template_attribute = \ local_buffer
objects.PrivateKeyTemplateAttribute() ):
self.private_key_template_attribute.read( self._private_key_template_attribute = objects.TemplateAttribute(
tstream, tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
self._private_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
if self.is_tag_next(enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE, tstream): if self.is_tag_next(
self.public_key_template_attribute = \ enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE,
objects.PublicKeyTemplateAttribute() local_buffer
self.public_key_template_attribute.read( ):
tstream, self._public_key_template_attribute = objects.TemplateAttribute(
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
self._public_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
self.is_oversized(tstream) self.is_oversized(local_buffer)
self.validate()
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
tstream = BytearrayStream() """
Write the data encoding the CreateKeyPair request payload to a buffer.
if self.common_template_attribute is not None: Args:
self.common_template_attribute.write( output_buffer (stream): A data buffer in which to encode object
tstream, data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if self._common_template_attribute is not None:
self._common_template_attribute.write(
local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
if self.private_key_template_attribute is not None: if self._private_key_template_attribute is not None:
self.private_key_template_attribute.write( self._private_key_template_attribute.write(
tstream, local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
if self.public_key_template_attribute is not None: if self._public_key_template_attribute is not None:
self.public_key_template_attribute.write( self._public_key_template_attribute.write(
tstream, local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
self.length = tstream.length() self.length = local_buffer.length()
super(CreateKeyPairRequestPayload, self).write( super(CreateKeyPairRequestPayload, self).write(
ostream, output_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
ostream.write(tstream.buffer) output_buffer.write(local_buffer.buffer)
def validate(self): def __eq__(self, other):
self.__validate() if isinstance(other, CreateKeyPairRequestPayload):
if self.common_template_attribute != \
other.common_template_attribute:
return False
elif self.private_key_template_attribute != \
other.private_key_template_attribute:
return False
elif self.public_key_template_attribute != \
other.public_key_template_attribute:
return False
else:
return True
else:
return NotImplemented
def __validate(self): def __ne__(self, other):
if self.common_template_attribute is not None: if isinstance(other, CreateKeyPairRequestPayload):
if not isinstance(self.common_template_attribute, return not (self == other)
objects.CommonTemplateAttribute): else:
msg = "invalid common template attribute" return NotImplemented
msg += "; expected {0}, received {1}".format(
objects.CommonTemplateAttribute,
self.common_template_attribute)
raise TypeError(msg)
if self.private_key_template_attribute is not None: def __repr__(self):
if not isinstance(self.private_key_template_attribute, args = ", ".join([
objects.PrivateKeyTemplateAttribute): "common_template_attribute={}".format(
msg = "invalid private key template attribute" self.common_template_attribute
msg += "; expected {0}, received {1}".format( ),
objects.PrivateKeyTemplateAttribute, "private_key_template_attribute={}".format(
self.private_key_template_attribute) self.private_key_template_attribute
raise TypeError(msg) ),
"public_key_template_attribute={}".format(
self.public_key_template_attribute
)
])
return "CreateKeyPairRequestPayload({})".format(args)
if self.public_key_template_attribute is not None: def __str__(self):
if not isinstance(self.public_key_template_attribute, value = ", ".join(
objects.PublicKeyTemplateAttribute): [
msg = "invalid public key template attribute" '"common_template_attribute": {}'.format(
msg += "; expected {0}, received {1}".format( self.common_template_attribute
objects.PublicKeyTemplateAttribute, ),
self.public_key_template_attribute) '"private_key_template_attribute": {}'.format(
raise TypeError(msg) self.private_key_template_attribute
),
'"public_key_template_attribute": {}'.format(
self.public_key_template_attribute
)
]
)
return '{' + value + '}'
class CreateKeyPairResponsePayload(Struct): class CreateKeyPairResponsePayload(primitives.Struct):
"""
A response payload for the CreateKeyPair operation.
Attributes:
private_key_unique_identifier: The ID of the new private key.
public_key_unique_identifier: The ID of the new public key.
private_key_template_attribute: A group of attributes to set on the new
private key.
public_key_template_attribute: A group of attributes to set on the new
public key.
"""
def __init__(self, def __init__(self,
private_key_uuid=None, private_key_unique_identifier=None,
public_key_uuid=None, public_key_unique_identifier=None,
private_key_template_attribute=None, private_key_template_attribute=None,
public_key_template_attribute=None): public_key_template_attribute=None):
super(CreateKeyPairResponsePayload, self).__init__( super(CreateKeyPairResponsePayload, self).__init__(
enums.Tags.RESPONSE_PAYLOAD enums.Tags.RESPONSE_PAYLOAD
) )
# Private and public UUIDs are required so make defaults as backup self._private_key_unique_identifier = None
if private_key_uuid is None: self._public_key_unique_identifier = None
self.private_key_uuid = attributes.PrivateKeyUniqueIdentifier('') self._private_key_template_attribute = None
else: self._public_key_template_attribute = None
self.private_key_uuid = private_key_uuid
if public_key_uuid is None:
self.public_key_uuid = attributes.PublicKeyUniqueIdentifier('')
else:
self.public_key_uuid = public_key_uuid
self.private_key_unique_identifier = private_key_unique_identifier
self.public_key_unique_identifier = public_key_unique_identifier
self.private_key_template_attribute = private_key_template_attribute self.private_key_template_attribute = private_key_template_attribute
self.public_key_template_attribute = public_key_template_attribute self.public_key_template_attribute = public_key_template_attribute
self.validate() @property
def private_key_unique_identifier(self):
if self._private_key_unique_identifier:
return self._private_key_unique_identifier.value
else:
return None
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): @private_key_unique_identifier.setter
def private_key_unique_identifier(self, value):
if value is None:
self._private_key_unique_identifier = None
elif isinstance(value, six.string_types):
self._private_key_unique_identifier = primitives.TextString(
value=value,
tag=enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER
)
else:
raise TypeError("Private key unique identifier must be a string.")
@property
def public_key_unique_identifier(self):
if self._public_key_unique_identifier:
return self._public_key_unique_identifier.value
else:
return None
@public_key_unique_identifier.setter
def public_key_unique_identifier(self, value):
if value is None:
self._public_key_unique_identifier = None
elif isinstance(value, six.string_types):
self._public_key_unique_identifier = primitives.TextString(
value=value,
tag=enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER
)
else:
raise TypeError("Public key unique identifier must be a string.")
@property
def private_key_template_attribute(self):
return self._private_key_template_attribute
@private_key_template_attribute.setter
def private_key_template_attribute(self, value):
if value is None:
self._private_key_template_attribute = None
elif isinstance(value, objects.TemplateAttribute):
if value.tag == enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE:
self._private_key_template_attribute = value
else:
raise TypeError(
"Private key template attribute must be a "
"TemplateAttribute structure with a "
"PrivateKeyTemplateAttribute tag."
)
else:
raise TypeError(
"Private key template attribute must be a TemplateAttribute "
"structure."
)
@property
def public_key_template_attribute(self):
return self._public_key_template_attribute
@public_key_template_attribute.setter
def public_key_template_attribute(self, value):
if value is None:
self._public_key_template_attribute = None
elif isinstance(value, objects.TemplateAttribute):
if value.tag == enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE:
self._public_key_template_attribute = value
else:
raise TypeError(
"Public key template attribute must be a "
"TemplateAttribute structure with a "
"PublicKeyTemplateAttribute tag."
)
else:
raise TypeError(
"Public key template attribute must be a TemplateAttribute "
"structure."
)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair response payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the private key unique identifier or
the public key unique identifier is missing from the encoded
payload.
"""
super(CreateKeyPairResponsePayload, self).read( super(CreateKeyPairResponsePayload, self).read(
istream, input_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
tstream = BytearrayStream(istream.read(self.length)) local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
self.private_key_uuid.read(tstream, kmip_version=kmip_version) if self.is_tag_next(
self.public_key_uuid.read(tstream, kmip_version=kmip_version) enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER,
local_buffer
):
self._private_key_unique_identifier = primitives.TextString(
tag=enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER
)
self._private_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The CreateKeyPair response payload encoding is missing the "
"private key unique identifier."
)
if self.is_tag_next(enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE, if self.is_tag_next(
tstream): enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER,
self.private_key_template_attribute = \ local_buffer
objects.PrivateKeyTemplateAttribute() ):
self.private_key_template_attribute.read( self._public_key_unique_identifier = primitives.TextString(
tstream, tag=enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER
)
self._public_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The CreateKeyPair response payload encoding is missing the "
"public key unique identifier."
)
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._private_key_template_attribute = objects.TemplateAttribute(
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
self._private_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
if self.is_tag_next(enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE, if self.is_tag_next(
tstream): enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE,
self.public_key_template_attribute = \ local_buffer
objects.PublicKeyTemplateAttribute() ):
self.public_key_template_attribute.read( self._public_key_template_attribute = objects.TemplateAttribute(
tstream, tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
self._public_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
self.is_oversized(tstream) self.is_oversized(local_buffer)
self.validate()
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
tstream = BytearrayStream() """
Write the data encoding the CreateKeyPair response payload to a buffer.
self.private_key_uuid.write(tstream, kmip_version=kmip_version) Args:
self.public_key_uuid.write(tstream, kmip_version=kmip_version) output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
if self.private_key_template_attribute is not None: Raises:
self.private_key_template_attribute.write( InvalidField: Raised if the private key unique identifier or the
tstream, public key unique identifier is not defined.
"""
local_buffer = utils.BytearrayStream()
if self._private_key_unique_identifier:
self._private_key_unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The CreateKeyPair response payload is missing the private "
"key unique identifier field."
)
if self._public_key_unique_identifier:
self._public_key_unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The CreateKeyPair response payload is missing the public "
"key unique identifier field."
)
if self._private_key_template_attribute:
self._private_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
if self.public_key_template_attribute is not None: if self._public_key_template_attribute:
self.public_key_template_attribute.write( self._public_key_template_attribute.write(
tstream, local_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
self.length = tstream.length() self.length = local_buffer.length()
super(CreateKeyPairResponsePayload, self).write( super(CreateKeyPairResponsePayload, self).write(
ostream, output_buffer,
kmip_version=kmip_version kmip_version=kmip_version
) )
ostream.write(tstream.buffer) output_buffer.write(local_buffer.buffer)
def validate(self): def __eq__(self, other):
self.__validate() if isinstance(other, CreateKeyPairResponsePayload):
if self.private_key_unique_identifier != \
other.private_key_unique_identifier:
return False
elif self.public_key_unique_identifier != \
other.public_key_unique_identifier:
return False
elif self.private_key_template_attribute != \
other.private_key_template_attribute:
return False
elif self.public_key_template_attribute != \
other.public_key_template_attribute:
return False
else:
return True
else:
return NotImplemented
def __validate(self): def __ne__(self, other):
if not isinstance(self.private_key_uuid, if isinstance(other, CreateKeyPairResponsePayload):
attributes.PrivateKeyUniqueIdentifier): return not (self == other)
msg = "invalid private key unique identifier" else:
msg += "; expected {0}, received {1}".format( return NotImplemented
attributes.PrivateKeyUniqueIdentifier,
self.private_key_uuid)
raise TypeError(msg)
if not isinstance(self.public_key_uuid, def __repr__(self):
attributes.PublicKeyUniqueIdentifier): args = ", ".join([
msg = "invalid public key unique identifier" "private_key_unique_identifier='{}'".format(
msg += "; expected {0}, received {1}".format( self.private_key_unique_identifier
attributes.PublicKeyUniqueIdentifier, ),
self.public_key_uuid) "public_key_unique_identifier='{}'".format(
raise TypeError(msg) self.public_key_unique_identifier
),
"private_key_template_attribute={}".format(
self.private_key_template_attribute
),
"public_key_template_attribute={}".format(
self.public_key_template_attribute
)
])
return "CreateKeyPairResponsePayload({})".format(args)
if self.private_key_template_attribute is not None: def __str__(self):
if not isinstance(self.private_key_template_attribute, value = ", ".join(
objects.PrivateKeyTemplateAttribute): [
msg = "invalid private key template attribute" '"private_key_unique_identifier": "{}"'.format(
msg += "; expected {0}, received {1}".format( self.private_key_unique_identifier
objects.PrivateKeyTemplateAttribute, ),
self.private_key_template_attribute) '"public_key_unique_identifier": "{}"'.format(
raise TypeError(msg) self.public_key_unique_identifier
),
if self.public_key_template_attribute is not None: '"private_key_template_attribute": {}'.format(
if not isinstance(self.public_key_template_attribute, self.private_key_template_attribute
objects.PublicKeyTemplateAttribute): ),
msg = "invalid public key template attribute" '"public_key_template_attribute": {}'.format(
msg += "; expected {0}, received {1}".format( self.public_key_template_attribute
objects.PublicKeyTemplateAttribute, )
self.public_key_template_attribute) ]
raise TypeError(msg) )
return '{' + value + '}'

View File

@ -168,6 +168,7 @@ class RekeyKeyPairRequestPayload(Struct):
raise TypeError(msg) raise TypeError(msg)
# TODO (ph) Remove the dependency on the CreateKeyPairResponsePayload
class RekeyKeyPairResponsePayload(CreateKeyPairResponsePayload): class RekeyKeyPairResponsePayload(CreateKeyPairResponsePayload):
def __init__(self, def __init__(self,

View File

@ -51,7 +51,9 @@ if __name__ == '__main__':
public_uid, private_uid = client.create_key_pair( public_uid, private_uid = client.create_key_pair(
algorithm, algorithm,
length, length,
operation_policy_name=opts.operation_policy_name operation_policy_name=opts.operation_policy_name,
public_usage_mask=[enums.CryptographicUsageMask.VERIFY],
private_usage_mask=[enums.CryptographicUsageMask.SIGN]
) )
logger.info("Successfully created public key with ID: {0}".format( logger.info("Successfully created public key with ID: {0}".format(
public_uid)) public_uid))

View File

@ -30,9 +30,7 @@ from kmip.core.factories.credentials import CredentialFactory
from kmip.core.attributes import Name from kmip.core.attributes import Name
from kmip.core.attributes import CryptographicUsageMask from kmip.core.attributes import CryptographicUsageMask
from kmip.core.objects import CommonTemplateAttribute from kmip.core.objects import TemplateAttribute
from kmip.core.objects import PrivateKeyTemplateAttribute
from kmip.core.objects import PublicKeyTemplateAttribute
from kmip.core.objects import Attribute from kmip.core.objects import Attribute
from kmip.services.kmip_client import KMIPProxy from kmip.services.kmip_client import KMIPProxy
@ -117,14 +115,25 @@ if __name__ == '__main__':
) )
attributes.append(opn) attributes.append(opn)
common = CommonTemplateAttribute(attributes=attributes) common = TemplateAttribute(
private = PrivateKeyTemplateAttribute(attributes=attributes) attributes=attributes,
public = PublicKeyTemplateAttribute(attributes=attributes) tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
private = TemplateAttribute(
attributes=attributes,
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
public = TemplateAttribute(
attributes=attributes,
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
# Create the SYMMETRIC_KEY object # Create the SYMMETRIC_KEY object
result = client.create_key_pair(common_template_attribute=common, result = client.create_key_pair(
private_key_template_attribute=private, common_template_attribute=common,
public_key_template_attribute=public) private_key_template_attribute=private,
public_key_template_attribute=public
)
client.close() client.close()
# Display operation results # Display operation results

View File

@ -313,8 +313,9 @@ class ProxyKmipClient(object):
) )
common_attributes.extend([algorithm_attribute, length_attribute]) common_attributes.extend([algorithm_attribute, length_attribute])
template = cobjects.CommonTemplateAttribute( template = cobjects.TemplateAttribute(
attributes=common_attributes attributes=common_attributes,
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
# Create public / private specific attributes # Create public / private specific attributes
@ -331,9 +332,10 @@ class ProxyKmipClient(object):
) )
] ]
if names or attrs: if names or attrs:
public_template = cobjects.PublicKeyTemplateAttribute( public_template = cobjects.TemplateAttribute(
names=names, names=names,
attributes=attrs attributes=attrs,
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = None private_template = None
@ -349,9 +351,10 @@ class ProxyKmipClient(object):
) )
] ]
if names or attrs: if names or attrs:
private_template = cobjects.PrivateKeyTemplateAttribute( private_template = cobjects.TemplateAttribute(
names=names, names=names,
attributes=attrs attributes=attrs,
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
# Create the asymmetric key pair and handle the results # Create the asymmetric key pair and handle the results
@ -362,8 +365,8 @@ class ProxyKmipClient(object):
status = result.result_status.value status = result.result_status.value
if status == enums.ResultStatus.SUCCESS: if status == enums.ResultStatus.SUCCESS:
public_uid = result.public_key_uuid.value public_uid = result.public_key_uuid
private_uid = result.private_key_uuid.value private_uid = result.private_key_uuid
return public_uid, private_uid return public_uid, private_uid
else: else:
reason = result.result_reason.value reason = result.result_reason.value

View File

@ -1222,8 +1222,8 @@ class KMIPProxy(object):
payload_public_key_template_attribute = None payload_public_key_template_attribute = None
if payload is not None: if payload is not None:
payload_private_key_uuid = payload.private_key_uuid payload_private_key_uuid = payload.private_key_unique_identifier
payload_public_key_uuid = payload.public_key_uuid payload_public_key_uuid = payload.public_key_unique_identifier
payload_private_key_template_attribute = \ payload_private_key_template_attribute = \
payload.private_key_template_attribute payload.private_key_template_attribute
payload_public_key_template_attribute = \ payload_public_key_template_attribute = \

View File

@ -1270,12 +1270,8 @@ class KmipEngine(object):
) )
response_payload = payloads.CreateKeyPairResponsePayload( response_payload = payloads.CreateKeyPairResponsePayload(
private_key_uuid=attributes.PrivateKeyUniqueIdentifier( private_key_unique_identifier=str(private_key.unique_identifier),
str(private_key.unique_identifier) public_key_unique_identifier=str(public_key.unique_identifier)
),
public_key_uuid=attributes.PublicKeyUniqueIdentifier(
str(public_key.unique_identifier)
)
) )
self._id_placeholder = str(private_key.unique_identifier) self._id_placeholder = str(private_key.unique_identifier)

View File

@ -20,6 +20,7 @@ from kmip.core.attributes import CryptographicAlgorithm
from kmip.core.attributes import CryptographicLength from kmip.core.attributes import CryptographicLength
from kmip.core.attributes import Name from kmip.core.attributes import Name
from kmip.core import enums
from kmip.core.enums import AttributeType from kmip.core.enums import AttributeType
from kmip.core.enums import CryptographicAlgorithm as CryptoAlgorithmEnum from kmip.core.enums import CryptographicAlgorithm as CryptoAlgorithmEnum
from kmip.core.enums import CryptographicUsageMask from kmip.core.enums import CryptographicUsageMask
@ -44,9 +45,6 @@ from kmip.core.objects import KeyBlock
from kmip.core.objects import KeyMaterial from kmip.core.objects import KeyMaterial
from kmip.core.objects import KeyValue from kmip.core.objects import KeyValue
from kmip.core.objects import TemplateAttribute from kmip.core.objects import TemplateAttribute
from kmip.core.objects import PrivateKeyTemplateAttribute
from kmip.core.objects import PublicKeyTemplateAttribute
from kmip.core.objects import CommonTemplateAttribute
from kmip.core.misc import QueryFunction from kmip.core.misc import QueryFunction
@ -149,11 +147,18 @@ class TestIntegration(TestCase):
private_key_attributes = [priv_name] private_key_attributes = [priv_name]
public_key_attributes = [pub_name] public_key_attributes = [pub_name]
common = CommonTemplateAttribute(attributes=common_attributes) common = TemplateAttribute(
priv_templ_attr = PrivateKeyTemplateAttribute( attributes=common_attributes,
attributes=private_key_attributes) tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
pub_templ_attr = PublicKeyTemplateAttribute( )
attributes=public_key_attributes) priv_templ_attr = TemplateAttribute(
attributes=private_key_attributes,
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
pub_templ_attr = TemplateAttribute(
attributes=public_key_attributes,
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
return self.client.\ return self.client.\
create_key_pair(common_template_attribute=common, create_key_pair(common_template_attribute=common,
@ -488,12 +493,12 @@ class TestIntegration(TestCase):
self._check_result_status(result, ResultStatus, ResultStatus.SUCCESS) self._check_result_status(result, ResultStatus, ResultStatus.SUCCESS)
# Check UUID value for Private key # Check UUID value for Private key
self._check_uuid(result.private_key_uuid.value, str) self._check_uuid(result.private_key_uuid, str)
# Check UUID value for Public key # Check UUID value for Public key
self._check_uuid(result.public_key_uuid.value, str) self._check_uuid(result.public_key_uuid, str)
priv_key_uuid = result.private_key_uuid.value priv_key_uuid = result.private_key_uuid
pub_key_uuid = result.public_key_uuid.value pub_key_uuid = result.public_key_uuid
priv_key_result = self.client.get(uuid=priv_key_uuid, credential=None) priv_key_result = self.client.get(uuid=priv_key_uuid, credential=None)
pub_key_result = self.client.get(uuid=pub_key_uuid, credential=None) pub_key_result = self.client.get(uuid=pub_key_uuid, credential=None)
@ -522,17 +527,17 @@ class TestIntegration(TestCase):
self.assertIsInstance(pub_secret, pub_expected) self.assertIsInstance(pub_secret, pub_expected)
self.logger.debug('Destroying key: ' + key_name + ' Private' + self.logger.debug('Destroying key: ' + key_name + ' Private' +
'\n With UUID: ' + result.private_key_uuid.value) '\n With UUID: ' + result.private_key_uuid)
destroy_priv_key_result = self.client.destroy( destroy_priv_key_result = self.client.destroy(
result.private_key_uuid.value) result.private_key_uuid)
self._check_result_status(destroy_priv_key_result, ResultStatus, self._check_result_status(destroy_priv_key_result, ResultStatus,
ResultStatus.SUCCESS) ResultStatus.SUCCESS)
self.logger.debug('Destroying key: ' + key_name + ' Public' + self.logger.debug('Destroying key: ' + key_name + ' Public' +
'\n With UUID: ' + result.public_key_uuid.value) '\n With UUID: ' + result.public_key_uuid)
destroy_pub_key_result = self.client.destroy( destroy_pub_key_result = self.client.destroy(
result.public_key_uuid.value) result.public_key_uuid)
self._check_result_status(destroy_pub_key_result, ResultStatus, self._check_result_status(destroy_pub_key_result, ResultStatus,
ResultStatus.SUCCESS) ResultStatus.SUCCESS)

File diff suppressed because it is too large Load Diff

View File

@ -187,24 +187,12 @@ class TestRekeyKeyPairRequestPayload(TestCase):
self._test_write(stream, payload, self.encoding_full) self._test_write(stream, payload, self.encoding_full)
# TODO (ph) Replicate CreateKeyPairResponsePayload test suite here
class TestRekeyKeyPairResponsePayload(TestCase): class TestRekeyKeyPairResponsePayload(TestCase):
def setUp(self): def setUp(self):
super(TestRekeyKeyPairResponsePayload, self).setUp() super(TestRekeyKeyPairResponsePayload, self).setUp()
self.uuid = '00000000-0000-0000-0000-000000000000'
self.private_key_uuid = attributes.PrivateKeyUniqueIdentifier(
self.uuid)
self.public_key_uuid = attributes.PublicKeyUniqueIdentifier(
self.uuid)
self.empty_private_key_uuid = attributes.PrivateKeyUniqueIdentifier('')
self.empty_public_key_uuid = attributes.PublicKeyUniqueIdentifier('')
self.private_key_template_attribute = \
objects.PrivateKeyTemplateAttribute()
self.public_key_template_attribute = \
objects.PublicKeyTemplateAttribute()
self.encoding_empty = utils.BytearrayStream(( self.encoding_empty = utils.BytearrayStream((
b'\x42\x00\x7C\x01\x00\x00\x00\x10\x42\x00\x66\x07\x00\x00\x00\x00' b'\x42\x00\x7C\x01\x00\x00\x00\x10\x42\x00\x66\x07\x00\x00\x00\x00'
b'\x42\x00\x6F\x07\x00\x00\x00\x00')) b'\x42\x00\x6F\x07\x00\x00\x00\x00'))
@ -220,127 +208,3 @@ class TestRekeyKeyPairResponsePayload(TestCase):
def tearDown(self): def tearDown(self):
super(TestRekeyKeyPairResponsePayload, self).tearDown() super(TestRekeyKeyPairResponsePayload, self).tearDown()
def test_init_with_none(self):
payloads.RekeyKeyPairResponsePayload()
def test_init_with_args(self):
payloads.RekeyKeyPairResponsePayload(
self.private_key_uuid, self.public_key_uuid,
self.private_key_template_attribute,
self.public_key_template_attribute)
def test_validate_with_invalid_private_key_unique_identifier(self):
kwargs = {'private_key_uuid': 'invalid',
'public_key_uuid': None,
'private_key_template_attribute': None,
'public_key_template_attribute': None}
self.assertRaisesRegex(
TypeError, "invalid private key unique identifier",
payloads.RekeyKeyPairResponsePayload, **kwargs)
def test_validate_with_invalid_public_key_unique_identifier(self):
kwargs = {'private_key_uuid': None,
'public_key_uuid': 'invalid',
'private_key_template_attribute': None,
'public_key_template_attribute': None}
self.assertRaisesRegex(
TypeError, "invalid public key unique identifier",
payloads.RekeyKeyPairResponsePayload, **kwargs)
def test_validate_with_invalid_private_key_template_attribute(self):
kwargs = {'private_key_uuid': None,
'public_key_uuid': None,
'private_key_template_attribute': 'invalid',
'public_key_template_attribute': None}
self.assertRaisesRegex(
TypeError, "invalid private key template attribute",
payloads.RekeyKeyPairResponsePayload, **kwargs)
def test_validate_with_invalid_public_key_template_attribute(self):
kwargs = {'private_key_uuid': None,
'public_key_uuid': None,
'private_key_template_attribute': None,
'public_key_template_attribute': 'invalid'}
self.assertRaisesRegex(
TypeError, "invalid public key template attribute",
payloads.RekeyKeyPairResponsePayload, **kwargs)
def _test_read(self, stream, payload, private_key_uuid, public_key_uuid,
private_key_template_attribute,
public_key_template_attribute):
payload.read(stream)
msg = "private_key_uuid decoding mismatch"
msg += "; expected {0}, received {1}".format(
private_key_uuid, payload.private_key_uuid)
self.assertEqual(private_key_uuid, payload.private_key_uuid, msg)
msg = "public_key_uuid decoding mismatch"
msg += "; expected {0}, received {1}".format(
public_key_uuid, payload.public_key_uuid)
self.assertEqual(public_key_uuid, payload.public_key_uuid, msg)
msg = "private_key_template_attribute decoding mismatch"
msg += "; expected {0}, received {1}".format(
private_key_template_attribute,
payload.private_key_template_attribute)
self.assertEqual(private_key_template_attribute,
payload.private_key_template_attribute, msg)
msg = "public_key_template_attribute decoding mismatch"
msg += "; expected {0}, received {1}".format(
public_key_template_attribute,
payload.public_key_template_attribute)
self.assertEqual(public_key_template_attribute,
payload.public_key_template_attribute, msg)
def test_read_with_none(self):
stream = self.encoding_empty
payload = payloads.RekeyKeyPairResponsePayload()
self._test_read(stream, payload, self.empty_private_key_uuid,
self.empty_public_key_uuid, None, None)
def test_read_with_args(self):
stream = self.encoding_full
payload = payloads.RekeyKeyPairResponsePayload(
self.private_key_uuid, self.public_key_uuid,
self.private_key_template_attribute,
self.public_key_template_attribute)
self._test_read(stream, payload, self.private_key_uuid,
self.public_key_uuid,
self.private_key_template_attribute,
self.public_key_template_attribute)
def _test_write(self, stream, payload, expected):
payload.write(stream)
length_expected = len(expected)
length_received = len(stream)
msg = "encoding lengths not equal"
msg += "; expected {0}, received {1}".format(
length_expected, length_received)
self.assertEqual(length_expected, length_received, msg)
msg = "encoding mismatch"
msg += ";\nexpected:\n{0}\nreceived:\n{1}".format(expected, stream)
self.assertEqual(expected, stream, msg)
def test_write_with_none(self):
stream = utils.BytearrayStream()
payload = payloads.RekeyKeyPairResponsePayload()
self._test_write(stream, payload, self.encoding_empty)
def test_write_with_args(self):
stream = utils.BytearrayStream()
payload = payloads.RekeyKeyPairResponsePayload(
self.private_key_uuid, self.public_key_uuid,
self.private_key_template_attribute,
self.public_key_template_attribute)
self._test_write(stream, payload, self.encoding_full)

View File

@ -483,15 +483,17 @@ class TestProxyKmipClient(testtools.TestCase):
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, length) enums.AttributeType.CRYPTOGRAPHIC_LENGTH, length)
attributes = [algorithm_attribute, length_attribute] attributes = [algorithm_attribute, length_attribute]
template = obj.CommonTemplateAttribute(attributes=attributes) template = obj.TemplateAttribute(
attributes=attributes,
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
status = enums.ResultStatus.SUCCESS status = enums.ResultStatus.SUCCESS
result = results.CreateKeyPairResult( result = results.CreateKeyPairResult(
contents.ResultStatus(status), contents.ResultStatus(status),
public_key_uuid=attr.PublicKeyUniqueIdentifier( public_key_uuid="aaaaaaaa-1111-2222-3333-ffffffffffff",
'aaaaaaaa-1111-2222-3333-ffffffffffff'), private_key_uuid="ffffffff-3333-2222-1111-aaaaaaaaaaaa"
private_key_uuid=attr.PrivateKeyUniqueIdentifier( )
'ffffffff-3333-2222-1111-aaaaaaaaaaaa'))
with ProxyKmipClient() as client: with ProxyKmipClient() as client:
client.proxy.create_key_pair.return_value = result client.proxy.create_key_pair.return_value = result
@ -501,9 +503,11 @@ class TestProxyKmipClient(testtools.TestCase):
2048 2048
) )
kwargs = {'common_template_attribute': template, kwargs = {
'private_key_template_attribute': None, "common_template_attribute": template,
'public_key_template_attribute': None} "private_key_template_attribute": None,
"public_key_template_attribute": None
}
client.proxy.create_key_pair.assert_called_with(**kwargs) client.proxy.create_key_pair.assert_called_with(**kwargs)
self.assertIsInstance(public_uid, six.string_types) self.assertIsInstance(public_uid, six.string_types)
self.assertIsInstance(private_uid, six.string_types) self.assertIsInstance(private_uid, six.string_types)
@ -533,15 +537,17 @@ class TestProxyKmipClient(testtools.TestCase):
algorithm_attribute, algorithm_attribute,
length_attribute length_attribute
] ]
template = obj.CommonTemplateAttribute(attributes=pair_attributes) template = obj.TemplateAttribute(
attributes=pair_attributes,
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
status = enums.ResultStatus.SUCCESS status = enums.ResultStatus.SUCCESS
result = results.CreateKeyPairResult( result = results.CreateKeyPairResult(
contents.ResultStatus(status), contents.ResultStatus(status),
public_key_uuid=attr.PublicKeyUniqueIdentifier( public_key_uuid="aaaaaaaa-1111-2222-3333-ffffffffffff",
'aaaaaaaa-1111-2222-3333-ffffffffffff'), private_key_uuid="ffffffff-3333-2222-1111-aaaaaaaaaaaa"
private_key_uuid=attr.PrivateKeyUniqueIdentifier( )
'ffffffff-3333-2222-1111-aaaaaaaaaaaa'))
with ProxyKmipClient() as client: with ProxyKmipClient() as client:
client.proxy.create_key_pair.return_value = result client.proxy.create_key_pair.return_value = result
@ -552,9 +558,11 @@ class TestProxyKmipClient(testtools.TestCase):
operation_policy_name='test' operation_policy_name='test'
) )
kwargs = {'common_template_attribute': template, kwargs = {
'private_key_template_attribute': None, "common_template_attribute": template,
'public_key_template_attribute': None} "private_key_template_attribute": None,
"public_key_template_attribute": None
}
client.proxy.create_key_pair.assert_called_with(**kwargs) client.proxy.create_key_pair.assert_called_with(**kwargs)
@mock.patch('kmip.pie.client.KMIPProxy', @mock.patch('kmip.pie.client.KMIPProxy',
@ -583,19 +591,25 @@ class TestProxyKmipClient(testtools.TestCase):
length_attribute length_attribute
] ]
template = obj.CommonTemplateAttribute(attributes=pair_attributes) template = obj.TemplateAttribute(
private_template = obj.PrivateKeyTemplateAttribute( attributes=pair_attributes,
names=[private_name_attribute]) tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
public_template = obj.PublicKeyTemplateAttribute( )
names=[public_name_attribute]) private_template = obj.TemplateAttribute(
names=[private_name_attribute],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
public_template = obj.TemplateAttribute(
names=[public_name_attribute],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
status = enums.ResultStatus.SUCCESS status = enums.ResultStatus.SUCCESS
result = results.CreateKeyPairResult( result = results.CreateKeyPairResult(
contents.ResultStatus(status), contents.ResultStatus(status),
public_key_uuid=attr.PublicKeyUniqueIdentifier( public_key_uuid="aaaaaaaa-1111-2222-3333-ffffffffffff",
'aaaaaaaa-1111-2222-3333-ffffffffffff'), private_key_uuid="ffffffff-3333-2222-1111-aaaaaaaaaaaa"
private_key_uuid=attr.PrivateKeyUniqueIdentifier( )
'ffffffff-3333-2222-1111-aaaaaaaaaaaa'))
with ProxyKmipClient() as client: with ProxyKmipClient() as client:
client.proxy.create_key_pair.return_value = result client.proxy.create_key_pair.return_value = result
@ -607,9 +621,11 @@ class TestProxyKmipClient(testtools.TestCase):
private_name="private" private_name="private"
) )
kwargs = {'common_template_attribute': template, kwargs = {
'private_key_template_attribute': private_template, "common_template_attribute": template,
'public_key_template_attribute': public_template} "private_key_template_attribute": private_template,
"public_key_template_attribute": public_template
}
client.proxy.create_key_pair.assert_called_with(**kwargs) client.proxy.create_key_pair.assert_called_with(**kwargs)
@mock.patch('kmip.pie.client.KMIPProxy', @mock.patch('kmip.pie.client.KMIPProxy',
@ -642,19 +658,25 @@ class TestProxyKmipClient(testtools.TestCase):
length_attribute length_attribute
] ]
template = obj.CommonTemplateAttribute(attributes=pair_attributes) template = obj.TemplateAttribute(
private_template = obj.PrivateKeyTemplateAttribute( attributes=pair_attributes,
attributes=[private_usage_mask]) tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
public_template = obj.PublicKeyTemplateAttribute( )
attributes=[public_usage_mask]) private_template = obj.TemplateAttribute(
attributes=[private_usage_mask],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
public_template = obj.TemplateAttribute(
attributes=[public_usage_mask],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
status = enums.ResultStatus.SUCCESS status = enums.ResultStatus.SUCCESS
result = results.CreateKeyPairResult( result = results.CreateKeyPairResult(
contents.ResultStatus(status), contents.ResultStatus(status),
public_key_uuid=attr.PublicKeyUniqueIdentifier( public_key_uuid="aaaaaaaa-1111-2222-3333-ffffffffffff",
'aaaaaaaa-1111-2222-3333-ffffffffffff'), private_key_uuid="ffffffff-3333-2222-1111-aaaaaaaaaaaa"
private_key_uuid=attr.PrivateKeyUniqueIdentifier( )
'ffffffff-3333-2222-1111-aaaaaaaaaaaa'))
with ProxyKmipClient() as client: with ProxyKmipClient() as client:
client.proxy.create_key_pair.return_value = result client.proxy.create_key_pair.return_value = result
@ -666,9 +688,11 @@ class TestProxyKmipClient(testtools.TestCase):
private_usage_mask=[enums.CryptographicUsageMask.SIGN] private_usage_mask=[enums.CryptographicUsageMask.SIGN]
) )
kwargs = {'common_template_attribute': template, kwargs = {
'private_key_template_attribute': private_template, "common_template_attribute": template,
'public_key_template_attribute': public_template} "private_key_template_attribute": private_template,
"public_key_template_attribute": public_template
}
client.proxy.create_key_pair.assert_called_with(**kwargs) client.proxy.create_key_pair.assert_called_with(**kwargs)
@mock.patch('kmip.pie.client.KMIPProxy', @mock.patch('kmip.pie.client.KMIPProxy',

View File

@ -2666,7 +2666,7 @@ class TestKmipEngine(testtools.TestCase):
attribute_factory = factory.AttributeFactory() attribute_factory = factory.AttributeFactory()
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -2683,9 +2683,10 @@ class TestKmipEngine(testtools.TestCase):
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
2048 2048
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK, enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK,
@ -2693,9 +2694,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK, enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK,
@ -2703,7 +2705,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -2719,9 +2722,9 @@ class TestKmipEngine(testtools.TestCase):
"Processing operation: CreateKeyPair" "Processing operation: CreateKeyPair"
) )
public_id = response_payload.public_key_uuid.value public_id = response_payload.public_key_unique_identifier
self.assertEqual('1', public_id) self.assertEqual('1', public_id)
private_id = response_payload.private_key_uuid.value private_id = response_payload.private_key_unique_identifier
self.assertEqual('2', private_id) self.assertEqual('2', private_id)
# Retrieve the stored public key and verify all attributes were set # Retrieve the stored public key and verify all attributes were set
@ -2794,7 +2797,7 @@ class TestKmipEngine(testtools.TestCase):
attribute_factory = factory.AttributeFactory() attribute_factory = factory.AttributeFactory()
# Test that a missing PublicKey CryptographicAlgorithm raises an error # Test that a missing PublicKey CryptographicAlgorithm raises an error
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -2803,9 +2806,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
@ -2817,9 +2821,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -2835,7 +2840,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -2861,7 +2867,7 @@ class TestKmipEngine(testtools.TestCase):
e._logger.reset_mock() e._logger.reset_mock()
# Test that a missing PrivateKey CryptographicAlgorithm raises an error # Test that a missing PrivateKey CryptographicAlgorithm raises an error
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -2870,9 +2876,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -2888,9 +2895,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
@ -2902,7 +2910,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -2928,7 +2937,7 @@ class TestKmipEngine(testtools.TestCase):
e._logger.reset_mock() e._logger.reset_mock()
# Test that a missing PublicKey CryptographicLength raises an error # Test that a missing PublicKey CryptographicLength raises an error
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -2937,9 +2946,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -2951,9 +2961,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -2969,7 +2980,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -2995,7 +3007,7 @@ class TestKmipEngine(testtools.TestCase):
e._logger.reset_mock() e._logger.reset_mock()
# Test that a missing PrivateKey CryptographicLength raises an error # Test that a missing PrivateKey CryptographicLength raises an error
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -3004,9 +3016,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3022,9 +3035,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3036,7 +3050,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -3062,7 +3077,7 @@ class TestKmipEngine(testtools.TestCase):
e._logger.reset_mock() e._logger.reset_mock()
# Test that a missing PublicKey CryptographicUsageMask raises an error # Test that a missing PublicKey CryptographicUsageMask raises an error
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -3071,9 +3086,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3083,9 +3099,10 @@ class TestKmipEngine(testtools.TestCase):
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
2048 2048
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3101,7 +3118,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -3127,7 +3145,7 @@ class TestKmipEngine(testtools.TestCase):
e._logger.reset_mock() e._logger.reset_mock()
# Test that a missing PrivateKey CryptographicUsageMask raises an error # Test that a missing PrivateKey CryptographicUsageMask raises an error
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -3136,9 +3154,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3154,9 +3173,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3166,7 +3186,8 @@ class TestKmipEngine(testtools.TestCase):
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
2048 2048
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -3205,7 +3226,7 @@ class TestKmipEngine(testtools.TestCase):
attribute_factory = factory.AttributeFactory() attribute_factory = factory.AttributeFactory()
# Test that mismatched CryptographicAlgorithms raise an error. # Test that mismatched CryptographicAlgorithms raise an error.
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -3214,9 +3235,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3232,9 +3254,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3250,7 +3273,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -3275,7 +3299,7 @@ class TestKmipEngine(testtools.TestCase):
e._logger.reset_mock() e._logger.reset_mock()
# Test that mismatched CryptographicAlgorithms raise an error. # Test that mismatched CryptographicAlgorithms raise an error.
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -3284,9 +3308,10 @@ class TestKmipEngine(testtools.TestCase):
enums.NameType.UNINTERPRETED_TEXT_STRING enums.NameType.UNINTERPRETED_TEXT_STRING
) )
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3302,9 +3327,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
@ -3320,7 +3346,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -8125,7 +8152,7 @@ class TestKmipEngine(testtools.TestCase):
attribute_factory = factory.AttributeFactory() attribute_factory = factory.AttributeFactory()
common_template = objects.CommonTemplateAttribute( common_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.NAME, enums.AttributeType.NAME,
@ -8142,9 +8169,10 @@ class TestKmipEngine(testtools.TestCase):
enums.AttributeType.CRYPTOGRAPHIC_LENGTH, enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
2048 2048
) )
] ],
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
) )
public_template = objects.PublicKeyTemplateAttribute( public_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK, enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK,
@ -8152,9 +8180,10 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.ENCRYPT enums.CryptographicUsageMask.ENCRYPT
] ]
) )
] ],
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
) )
private_template = objects.PrivateKeyTemplateAttribute( private_template = objects.TemplateAttribute(
attributes=[ attributes=[
attribute_factory.create_attribute( attribute_factory.create_attribute(
enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK, enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK,
@ -8162,7 +8191,8 @@ class TestKmipEngine(testtools.TestCase):
enums.CryptographicUsageMask.DECRYPT enums.CryptographicUsageMask.DECRYPT
] ]
) )
] ],
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
) )
payload = payloads.CreateKeyPairRequestPayload( payload = payloads.CreateKeyPairRequestPayload(
common_template, common_template,
@ -8178,9 +8208,9 @@ class TestKmipEngine(testtools.TestCase):
"Processing operation: CreateKeyPair" "Processing operation: CreateKeyPair"
) )
public_id = response_payload.public_key_uuid.value public_id = response_payload.public_key_unique_identifier
self.assertEqual('1', public_id) self.assertEqual('1', public_id)
private_id = response_payload.private_key_uuid.value private_id = response_payload.private_key_unique_identifier
self.assertEqual('2', private_id) self.assertEqual('2', private_id)
e._logger.reset_mock() e._logger.reset_mock()