src/modules/client/image.py
changeset 3321 52e8eec3014c
parent 3318 864be9e4db61
child 3325 18a3d7b0d618
equal deleted inserted replaced
3320:f727edff50bd 3321:52e8eec3014c
    22 
    22 
    23 #
    23 #
    24 # Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
    24 # Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
    25 #
    25 #
    26 
    26 
    27 import M2Crypto as m2
       
    28 import atexit
    27 import atexit
    29 import calendar
    28 import calendar
    30 import collections
    29 import collections
    31 import copy
    30 import copy
    32 import datetime
    31 import datetime
    41 import sys
    40 import sys
    42 import tempfile
    41 import tempfile
    43 import time
    42 import time
    44 
    43 
    45 from contextlib import contextmanager
    44 from contextlib import contextmanager
       
    45 from cryptography import x509
       
    46 from cryptography.hazmat.backends import default_backend
    46 from six.moves.urllib.parse import quote, unquote
    47 from six.moves.urllib.parse import quote, unquote
    47 
    48 
    48 import pkg.actions
    49 import pkg.actions
    49 import pkg.catalog
    50 import pkg.catalog
    50 import pkg.client.api_errors            as apx
    51 import pkg.client.api_errors            as apx
   338                         for fn in os.listdir(trust_anchor_loc):
   339                         for fn in os.listdir(trust_anchor_loc):
   339                                 pth = os.path.join(trust_anchor_loc, fn)
   340                                 pth = os.path.join(trust_anchor_loc, fn)
   340                                 if os.path.islink(pth):
   341                                 if os.path.islink(pth):
   341                                         continue
   342                                         continue
   342                                 try:
   343                                 try:
   343                                         trusted_ca = m2.X509.load_cert(pth)
   344                                         with open(pth, "rb") as f:
   344                                 except m2.X509.X509Error as e:
   345                                                 raw = f.read()
       
   346                                         trusted_ca = \
       
   347                                             x509.load_pem_x509_certificate(
       
   348                                             raw, default_backend())
       
   349                                 except (ValueError, IOError) as e:
   345                                         self.__bad_trust_anchors.append(
   350                                         self.__bad_trust_anchors.append(
   346                                             (pth, str(e)))
   351                                             (pth, str(e)))
   347                                 else:
   352                                 else:
   348                                         # M2Crypto's subject hash doesn't match
   353                                         # We store certificates internally by
   349                                         # openssl's subject hash so recompute it
   354                                         # the SHA-1 hash of its subject.
   350                                         # so all hashes are in the same
   355                                         s = hashlib.sha1(misc.force_bytes(
   351                                         # universe.
   356                                             trusted_ca.subject)).hexdigest()
   352                                         s = trusted_ca.get_subject().as_hash()
       
   353                                         self.__trust_anchors.setdefault(s, [])
   357                                         self.__trust_anchors.setdefault(s, [])
   354                                         self.__trust_anchors[s].append(
   358                                         self.__trust_anchors[s].append(
   355                                             trusted_ca)
   359                                             trusted_ca)
   356                 for s in pkg_trust_anchors:
   360                 for s in pkg_trust_anchors:
   357                         if s not in self.__trust_anchors:
   361                         if s not in self.__trust_anchors: