From 1bc568c1757f6b73864bdf669c2881af81e579e0 Mon Sep 17 00:00:00 2001 From: Peter Hamilton Date: Thu, 4 Jun 2015 09:29:58 -0400 Subject: [PATCH] Removing old and out-of-date demo scripts This change removes the original top-level set of demo scripts in kmip/demos in favor of the functioning and up-to-date unit demo scripts located in kmip/demos/units. --- kmip/demos/create.py | 79 ------------------------------------- kmip/demos/destroy.py | 70 --------------------------------- kmip/demos/get.py | 69 -------------------------------- kmip/demos/locate.py | 80 ------------------------------------- kmip/demos/register.py | 84 --------------------------------------- kmip/demos/server.py | 89 ------------------------------------------ 6 files changed, 471 deletions(-) delete mode 100644 kmip/demos/create.py delete mode 100644 kmip/demos/destroy.py delete mode 100644 kmip/demos/get.py delete mode 100644 kmip/demos/locate.py delete mode 100644 kmip/demos/register.py delete mode 100644 kmip/demos/server.py diff --git a/kmip/demos/create.py b/kmip/demos/create.py deleted file mode 100644 index e4ef10f..0000000 --- a/kmip/demos/create.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from kmip.core.enums import AttributeType -from kmip.core.enums import CredentialType -from kmip.core.enums import ObjectType -from kmip.core.enums import ResultStatus -from kmip.core.enums import CryptographicAlgorithm -from kmip.core.enums import CryptographicUsageMask - -from kmip.core.factories.attributes import AttributeFactory -from kmip.core.factories.credentials import CredentialFactory - -from kmip.core.objects import TemplateAttribute - -from kmip.services.kmip_client import KMIPProxy - -import logging -import os - -if __name__ == '__main__': - f_log = os.path.join(os.path.dirname(__file__), '..', 'logconfig.ini') - logging.config.fileConfig(f_log) - logger = logging.getLogger(__name__) - attribute_factory = AttributeFactory() - credential_factory = CredentialFactory() - - credential_type = CredentialType.USERNAME_AND_PASSWORD - credential_value = {'Username': 'user', 'Password': 'abc123'} - credential = credential_factory.create_credential(credential_type, - credential_value) - - client = KMIPProxy() - client.open() - - object_type = ObjectType.SYMMETRIC_KEY - attribute_type = AttributeType.CRYPTOGRAPHIC_ALGORITHM - algorithm = attribute_factory.create_attribute(attribute_type, - CryptographicAlgorithm.AES) - mask_flags = [CryptographicUsageMask.ENCRYPT, - CryptographicUsageMask.DECRYPT] - attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK - usage_mask = attribute_factory.create_attribute(attribute_type, - mask_flags) - attribute_type = AttributeType.CRYPTOGRAPHIC_LENGTH - length = attribute_factory.create_attribute(attribute_type, - 128) - attributes = [algorithm, usage_mask, length] - template_attribute = TemplateAttribute(attributes=attributes) - - result = client.create(object_type, template_attribute, - credential) - client.close() - - logger.debug('create() result status: {0}'.format( - result.result_status.enum)) - if result.result_status.enum == ResultStatus.SUCCESS: - logger.debug('created object type: {0}'.format( - result.object_type.enum)) - logger.debug('created UUID: {0}'.format(result.uuid.value)) - logger.debug('created template attribute: {0}'. - format(result.template_attribute)) - else: - logger.debug('create() result reason: {0}'.format( - result.result_reason.enum)) - logger.debug('create() result message: {0}'.format( - result.result_message.value)) diff --git a/kmip/demos/destroy.py b/kmip/demos/destroy.py deleted file mode 100644 index 1e1b084..0000000 --- a/kmip/demos/destroy.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from kmip.core.enums import AttributeType -from kmip.core.enums import CredentialType -from kmip.core.enums import ObjectType -from kmip.core.enums import CryptographicAlgorithm -from kmip.core.enums import CryptographicUsageMask - -from kmip.core.factories.attributes import AttributeFactory -from kmip.core.factories.credentials import CredentialFactory - -from kmip.core.objects import TemplateAttribute - -from kmip.services.kmip_client import KMIPProxy - -import logging -import os - -if __name__ == '__main__': - f_log = os.path.join(os.path.dirname(__file__), '..', 'logconfig.ini') - logging.config.fileConfig(f_log) - logger = logging.getLogger(__name__) - - attribute_factory = AttributeFactory() - credential_factory = CredentialFactory() - - credential_type = CredentialType.USERNAME_AND_PASSWORD - credential_value = {'Username': 'Peter', 'Password': 'abc123'} - credential = credential_factory.create_credential(credential_type, - credential_value) - client = KMIPProxy() - client.open() - - # Create a SYMMETRIC_KEY object - object_type = ObjectType.SYMMETRIC_KEY - attribute_type = AttributeType.CRYPTOGRAPHIC_ALGORITHM - algorithm = attribute_factory.create_attribute(attribute_type, - CryptographicAlgorithm.AES) - mask_flags = [CryptographicUsageMask.ENCRYPT, - CryptographicUsageMask.DECRYPT] - attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK - usage_mask = attribute_factory.create_attribute(attribute_type, - mask_flags) - attributes = [algorithm, usage_mask] - template_attribute = TemplateAttribute(attributes=attributes) - - result = client.create(object_type, template_attribute, - credential) - uuid = result.uuid.value - - # Destroy the SYMMETRIC_KEY object - result = client.destroy(uuid, credential) - client.close() - - logger.debug('destroy() result status: {0}'.format( - result.result_status.enum)) - logger.debug('destroyed UUID: {0}'.format(result.uuid.value)) diff --git a/kmip/demos/get.py b/kmip/demos/get.py deleted file mode 100644 index a3c02e7..0000000 --- a/kmip/demos/get.py +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from kmip.core.enums import AttributeType -from kmip.core.enums import CredentialType -from kmip.core.enums import ObjectType -from kmip.core.enums import CryptographicAlgorithm -from kmip.core.enums import CryptographicUsageMask - -from kmip.core.factories.attributes import AttributeFactory -from kmip.core.factories.credentials import CredentialFactory - -from kmip.core.objects import TemplateAttribute - -from kmip.services.kmip_client import KMIPProxy - -import logging -import os - -if __name__ == '__main__': - f_log = os.path.join(os.path.dirname(__file__), '..', 'logconfig.ini') - logging.config.fileConfig(f_log) - logger = logging.getLogger(__name__) - - attribute_factory = AttributeFactory() - credential_factory = CredentialFactory() - - credential_type = CredentialType.USERNAME_AND_PASSWORD - credential_value = {'Username': 'Peter', 'Password': 'abc123'} - credential = credential_factory.create_credential(credential_type, - credential_value) - client = KMIPProxy() - client.open() - - object_type = ObjectType.SYMMETRIC_KEY - attribute_type = AttributeType.CRYPTOGRAPHIC_ALGORITHM - algorithm = attribute_factory.create_attribute(attribute_type, - CryptographicAlgorithm.AES) - mask_flags = [CryptographicUsageMask.ENCRYPT, - CryptographicUsageMask.DECRYPT] - attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK - usage_mask = attribute_factory.create_attribute(attribute_type, - mask_flags) - attributes = [algorithm, usage_mask] - template_attribute = TemplateAttribute(attributes=attributes) - - result = client.create(object_type, template_attribute, - credential) - uuid = result.uuid.value - - result = client.get(uuid=uuid, credential=credential) - client.close() - - logger.debug('get() result status: {0}'.format(result.result_status.enum)) - logger.debug('retrieved object type: {0}'.format(result.object_type.enum)) - logger.debug('retrieved UUID: {0}'.format(result.uuid.value)) - logger.debug('retrieved secret: {0}'.format(result.secret)) diff --git a/kmip/demos/locate.py b/kmip/demos/locate.py deleted file mode 100644 index f982a2f..0000000 --- a/kmip/demos/locate.py +++ /dev/null @@ -1,80 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from kmip.core.enums import AttributeType -from kmip.core.enums import CredentialType -from kmip.core.enums import ObjectType -from kmip.core.enums import ResultStatus -from kmip.core.enums import CryptographicAlgorithm -from kmip.core.enums import CryptographicUsageMask -from kmip.core.enums import NameType - -from kmip.core.attributes import Name - -from kmip.core.factories.attributes import AttributeFactory -from kmip.core.factories.credentials import CredentialFactory - -from kmip.core.objects import TemplateAttribute, Attribute - -from kmip.services.kmip_client import KMIPProxy - -import logging -import os - -if __name__ == '__main__': - f_log = os.path.join(os.path.dirname(__file__), '..', 'logconfig.ini') - logging.config.fileConfig(f_log) - logger = logging.getLogger(__name__) - - attribute_factory = AttributeFactory() - credential_factory = CredentialFactory() - - credential_type = CredentialType.USERNAME_AND_PASSWORD - credential_value = {'Username': 'Peter', 'Password': 'abc123'} - credential = credential_factory.create_credential(credential_type, - credential_value) - client = KMIPProxy() - client.open() - - object_type = ObjectType.SYMMETRIC_KEY - attribute_type = AttributeType.CRYPTOGRAPHIC_ALGORITHM - algorithm = attribute_factory.create_attribute(attribute_type, - CryptographicAlgorithm.AES) - mask_flags = [CryptographicUsageMask.ENCRYPT, - CryptographicUsageMask.DECRYPT] - attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK - usage_mask = attribute_factory.create_attribute(attribute_type, - mask_flags) - name = Attribute.AttributeName('Name') - name_value = Name.NameValue('FOOBAR') - name_type = Name.NameType(NameType.UNINTERPRETED_TEXT_STRING) - value = Name(name_value=name_value, name_type=name_type) - nameattr = Attribute(attribute_name=name, attribute_value=value) - - attributes = [algorithm, usage_mask, nameattr] - - template_attribute = TemplateAttribute(attributes=attributes) - - result = client.create(object_type, template_attribute, - credential) - - attrs = [nameattr] - result = client.locate(attributes=attrs, credential=credential) - client.close() - - logger.debug('locate() result status: {0}'. - format(result.result_status.enum)) - if result.result_status.enum == ResultStatus.SUCCESS: - logger.debug('retrieved object type: {0}'. - format(result.object_type.enum)) - logger.debug('Located UUIDs: {0}'.format(','.join([u.value for u in - result.uuids]))) diff --git a/kmip/demos/register.py b/kmip/demos/register.py deleted file mode 100644 index 18ffa3b..0000000 --- a/kmip/demos/register.py +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from kmip.core.enums import AttributeType -from kmip.core.enums import CredentialType -from kmip.core.enums import CryptographicAlgorithm -from kmip.core.enums import CryptographicUsageMask -from kmip.core.enums import KeyFormatType -from kmip.core.enums import ObjectType - -from kmip.core.factories.attributes import AttributeFactory -from kmip.core.factories.credentials import CredentialFactory -from kmip.core.factories.secrets import SecretFactory - -from kmip.core.objects import TemplateAttribute - -from kmip.services.kmip_client import KMIPProxy - -import logging -import os - -if __name__ == '__main__': - f_log = os.path.join(os.path.dirname(__file__), '..', 'logconfig.ini') - logging.config.fileConfig(f_log) - logger = logging.getLogger(__name__) - - attribute_factory = AttributeFactory() - credential_factory = CredentialFactory() - secret_factory = SecretFactory() - - credential_type = CredentialType.USERNAME_AND_PASSWORD - credential_value = {'Username': 'Peter', 'Password': 'abc123'} - credential = credential_factory.create_credential(credential_type, - credential_value) - client = KMIPProxy() - client.open() - - object_type = ObjectType.SYMMETRIC_KEY - algorithm_value = CryptographicAlgorithm.AES - - mask_flags = [CryptographicUsageMask.ENCRYPT, - CryptographicUsageMask.DECRYPT] - attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK - usage_mask = attribute_factory.create_attribute(attribute_type, - mask_flags) - attributes = [usage_mask] - template_attribute = TemplateAttribute(attributes=attributes) - - secret_features = {} - - key_format_type = KeyFormatType.RAW - secret_features.update([('key_format_type', key_format_type)]) - - # TODO (peter-hamilton) Replace with calls to crypto libraries - key_data = {'bytes': bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00')} - - secret_features.update([('key_value', key_data)]) - secret_features.update([('cryptographic_algorithm', algorithm_value)]) - secret_features.update([('cryptographic_length', 128)]) - - secret = secret_factory.create(object_type, secret_features) - - result = client.register(object_type, template_attribute, secret, - credential) - client.close() - - logger.debug('register() result status: {0}'.format( - result.result_status.enum)) - logger.debug('registered UUID: {0}'.format(result.uuid.value)) - logger.debug('registered template attribute: {0}'. - format(result.template_attribute)) diff --git a/kmip/demos/server.py b/kmip/demos/server.py deleted file mode 100644 index e46b01d..0000000 --- a/kmip/demos/server.py +++ /dev/null @@ -1,89 +0,0 @@ -# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import logging -import optparse -import os -import sys - -from kmip.services.kmip_server import KMIPServer - -FILE_PATH = os.path.dirname(os.path.abspath(__file__)) - - -def run_server(host, port, keyfile, certfile, cert_reqs, ssl_version, - ca_certs, do_handshake_on_connect, suppress_ragged_eofs): - logger = logging.getLogger(__name__) - - server = KMIPServer(host=host, port=port, certfile=certfile, - keyfile=keyfile, cert_reqs=cert_reqs, - ssl_version=ssl_version, ca_certs=ca_certs, - do_handshake_on_connect=do_handshake_on_connect, - suppress_ragged_eofs=suppress_ragged_eofs) - - logger.info('Starting the KMIP server') - - try: - server.serve() - except KeyboardInterrupt: - logger.info('KeyboardInterrupt received while serving') - except Exception as e: - logger.info('Exception received while serving: {0}'.format(e)) - finally: - server.close() - - logger.info('Shutting down KMIP server') - - -def build_cli_parser(): - parser = optparse.OptionParser(usage="%prog [options]", - description="Run KMIP Server") - parser.add_option("-n", "--host", action="store", default=None, - dest="host", - help="Hostname/IP address of platform running the KMIP " - "server (e.g., localhost, 127.0.0.1)") - parser.add_option("-p", "--port", action="store", default=None, - dest="port", help="Port number for KMIP services") - parser.add_option("-c", "--certfile", action="store", default=None, - dest="certfile") - parser.add_option("-k", "--keyfile", action="store", default=None, - dest="keyfile") - parser.add_option("-r", "--cert_reqs", action="store", default=None, - dest="cert_reqs") - parser.add_option("-s", "--ssl_version", action="store", default=None, - dest="ssl_version") - parser.add_option("-a", "--ca_certs", action="store", default=None, - dest="ca_certs") - parser.add_option("-d", "--do_handshake_on_connect", action="store", - default=None, dest="do_handshake_on_connect") - parser.add_option("-e", "--suppress_ragged_eofs", action="store", - default=None, dest="suppress_ragged_eofs") - return parser - - -if __name__ == '__main__': - parser = build_cli_parser() - - opts, args = parser.parse_args(sys.argv[1:]) - - run_server(host=opts.host, - port=opts.port, - certfile=opts.certfile, - keyfile=opts.keyfile, - cert_reqs=opts.cert_reqs, - ssl_version=opts.ssl_version, - ca_certs=opts.ca_certs, - do_handshake_on_connect=opts.do_handshake_on_connect, - suppress_ragged_eofs=opts.suppress_ragged_eofs)