def _create_key_pair(self, key_name=None): """ Helper function for creating private and public keys. Used any time a key pair needs to be created. :param key_name: name of the key to be created :return: returns the result of the "create key" operation as provided by the KMIP appliance """ attribute_type = AttributeType.CRYPTOGRAPHIC_ALGORITHM algorithm = self.attr_factory.create_attribute(attribute_type, CryptoAlgorithmEnum.RSA) mask_flags = [ CryptographicUsageMask.ENCRYPT, CryptographicUsageMask.DECRYPT ] attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK usage_mask = self.attr_factory.create_attribute( attribute_type, mask_flags) key_length = 2048 attribute_type = AttributeType.CRYPTOGRAPHIC_LENGTH key_length_obj = self.attr_factory.create_attribute( attribute_type, key_length) name = Attribute.AttributeName('Name') if key_name is None: key_name = 'Integration Test - Key' priv_name_value = Name.NameValue(key_name + " Private") pub_name_value = Name.NameValue(key_name + " Public") name_type = Name.NameType(NameType.UNINTERPRETED_TEXT_STRING) priv_value = Name(name_value=priv_name_value, name_type=name_type) pub_value = Name(name_value=pub_name_value, name_type=name_type) priv_name = Attribute(attribute_name=name, attribute_value=priv_value) pub_name = Attribute(attribute_name=name, attribute_value=pub_value) common_attributes = [algorithm, usage_mask, key_length_obj] private_key_attributes = [priv_name] public_key_attributes = [pub_name] common = CommonTemplateAttribute(attributes=common_attributes) priv_templ_attr = PrivateKeyTemplateAttribute( attributes=private_key_attributes) pub_templ_attr = PublicKeyTemplateAttribute( attributes=public_key_attributes) return self.client.\ create_key_pair(common_template_attribute=common, private_key_template_attribute=priv_templ_attr, public_key_template_attribute=pub_templ_attr)
def test_build_rekey_key_pair_batch_item_with_input(self): self._test_build_rekey_key_pair_batch_item( PrivateKeyUniqueIdentifier(), Offset(), CommonTemplateAttribute(), PrivateKeyTemplateAttribute(), PublicKeyTemplateAttribute())
name_type = Name.NameType(NameType.UNINTERPRETED_TEXT_STRING) value = Name(name_value=name_value, name_type=name_type) name = Attribute(attribute_name=name, attribute_value=value) name = Attribute.AttributeName('Cryptographic Usage Mask') value = CryptographicUsageMask(UsageMaskEnum.ENCRYPT.value | UsageMaskEnum.DECRYPT.value) usage_mask = Attribute(attribute_name=name, attribute_value=value) attribute_type = AttributeType.CRYPTOGRAPHIC_LENGTH length_obj = attribute_factory.create_attribute(attribute_type, length) attributes = [algorithm_obj, length_obj, name, usage_mask] common = CommonTemplateAttribute(attributes=attributes) private = PrivateKeyTemplateAttribute(attributes=attributes) public = PublicKeyTemplateAttribute(attributes=attributes) # Create the SYMMETRIC_KEY object result = client.create_key_pair(common_template_attribute=common, private_key_template_attribute=private, public_key_template_attribute=public) client.close() # Display operation results logger.info('create_key_pair() result status: {0}'.format( result.result_status.value)) if result.result_status.value == ResultStatus.SUCCESS: logger.info('created private key UUID: {0}'.format( result.private_key_uuid)) logger.info('created public key UUID: {0}'.format(
def test_build_create_key_pair_batch_item_with_input(self): self._test_build_create_key_pair_batch_item( CommonTemplateAttribute(), PrivateKeyTemplateAttribute(), PublicKeyTemplateAttribute())