From 146e88dc42ceb3215bc6559c4288904e3d588771 Mon Sep 17 00:00:00 2001 From: Alessandro Pilotti Date: Wed, 19 Feb 2014 19:51:23 +0200 Subject: [PATCH] Removes Windows dependencies in metadata services Removes dependencies from utils.windows.x509 in the metadata services. --- .../metadata/services/baseopenstackservice.py | 4 ++-- cloudbaseinit/metadata/services/maasservice.py | 4 ++-- cloudbaseinit/utils/windows/x509.py | 12 +++++------- cloudbaseinit/utils/x509constants.py | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 cloudbaseinit/utils/x509constants.py diff --git a/cloudbaseinit/metadata/services/baseopenstackservice.py b/cloudbaseinit/metadata/services/baseopenstackservice.py index dcad61f0..ca3a61d6 100644 --- a/cloudbaseinit/metadata/services/baseopenstackservice.py +++ b/cloudbaseinit/metadata/services/baseopenstackservice.py @@ -19,7 +19,7 @@ from oslo.config import cfg from cloudbaseinit.metadata.services import base from cloudbaseinit.openstack.common import log as logging -from cloudbaseinit.utils.windows import x509 +from cloudbaseinit.utils import x509constants opts = [ cfg.StrOpt('metadata_base_url', default='http://169.254.169.254/', @@ -104,7 +104,7 @@ class BaseOpenStackService(base.BaseMetadataService): # Look if the user_data contains a PEM certificate try: user_data = self.get_user_data() - if user_data.startswith(x509.PEM_HEADER): + if user_data.startswith(x509constants.PEM_HEADER): cert_data = user_data except base.NotExistingMetadataException: LOG.debug("user_data metadata not present") diff --git a/cloudbaseinit/metadata/services/maasservice.py b/cloudbaseinit/metadata/services/maasservice.py index f0ad8698..2a371ba1 100644 --- a/cloudbaseinit/metadata/services/maasservice.py +++ b/cloudbaseinit/metadata/services/maasservice.py @@ -21,7 +21,7 @@ from oslo.config import cfg from cloudbaseinit.metadata.services import base from cloudbaseinit.openstack.common import log as logging -from cloudbaseinit.utils.windows import x509 +from cloudbaseinit.utils import x509constants opts = [ cfg.StrOpt('maas_metadata_url', default=None, @@ -121,4 +121,4 @@ class MaaSHttpService(base.BaseMetadataService): def get_client_auth_certs(self): return self._get_list_from_text( self._get_cache_data('%s/meta-data/x509' % self._metadata_version), - "%s\n" % x509.PEM_FOOTER) + "%s\n" % x509constants.PEM_FOOTER) diff --git a/cloudbaseinit/utils/windows/x509.py b/cloudbaseinit/utils/windows/x509.py index 35468445..7b00ecd3 100644 --- a/cloudbaseinit/utils/windows/x509.py +++ b/cloudbaseinit/utils/windows/x509.py @@ -21,6 +21,7 @@ import uuid from ctypes import wintypes from cloudbaseinit.utils.windows import cryptoapi +from cloudbaseinit.utils import x509constants malloc = ctypes.cdll.msvcrt.malloc malloc.restype = ctypes.c_void_p @@ -34,9 +35,6 @@ STORE_NAME_MY = "My" STORE_NAME_ROOT = "Root" STORE_NAME_TRUSTED_PEOPLE = "TrustedPeople" -PEM_HEADER = "-----BEGIN CERTIFICATE-----" -PEM_FOOTER = "-----END CERTIFICATE-----" - class CryptoAPICertManager(object): def _get_cert_thumprint(self, cert_context_p): @@ -204,11 +202,11 @@ class CryptoAPICertManager(object): def _get_cert_base64(self, cert_data): base64_cert_data = cert_data - if base64_cert_data.startswith(PEM_HEADER): - base64_cert_data = base64_cert_data[len(PEM_HEADER):] - if base64_cert_data.endswith(PEM_FOOTER): + if base64_cert_data.startswith(x509constants.PEM_HEADER): + base64_cert_data = base64_cert_data[len(x509constants.PEM_HEADER):] + if base64_cert_data.endswith(x509constants.PEM_FOOTER): base64_cert_data = base64_cert_data[:len(base64_cert_data) - - len(PEM_FOOTER)] + len(x509constants.PEM_FOOTER)] return base64_cert_data.replace("\n", "") def import_cert(self, cert_data, machine_keyset=True, diff --git a/cloudbaseinit/utils/x509constants.py b/cloudbaseinit/utils/x509constants.py new file mode 100644 index 00000000..90ce7b20 --- /dev/null +++ b/cloudbaseinit/utils/x509constants.py @@ -0,0 +1,16 @@ +# Copyright 2014 Cloudbase Solutions Srl +# +# 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. + +PEM_HEADER = "-----BEGIN CERTIFICATE-----" +PEM_FOOTER = "-----END CERTIFICATE-----"