Example #1
0
 def set_custom_cert_loc(self, cert_loc):
     if not os.path.isfile(cert_loc):
         logger.warning('Custom certificate file %s not found. Skipping the option ...' % cert_loc)
         return
     from sdetools.extlib import http_req
     if http_req.custom_ca_file != cert_loc:
         http_req.custom_ca_file = cert_loc
         http_req.compile_certs()
Example #2
0
        # split custom certificates and remove extra whitespace
        candidates = re.findall(cert_check, cert)
        candidates = map(lambda content: (SSL_START_MARKER + '\n' + content.strip() + '\n' + SSL_END_MARKER + '\n'), candidates)

        if not candidates:
            raise ValueError('No valid certificate(s) found')

        open(http_req.custom_ca_file, 'a').close()

        custom_bundle = open(http_req.custom_ca_file).read()

        # split present certificates and remove extra whitespace
        present_cert = re.findall(cert_check, custom_bundle)
        present_cert = map(lambda content: (SSL_START_MARKER + '\n' + content.strip() + '\n' + SSL_END_MARKER + '\n'), present_cert)

        # select only missing certificates
        import_cert = [x for x in candidates if x not in present_cert]

        validation = self.validate_pem(import_cert)

        if validation:
            raise ValueError('Invalid certificate present: \n%s' % validation)

        fp = open(http_req.custom_ca_file, 'a')
        fp.write(''.join(import_cert))
        fp.close()

        http_req.compile_certs()

        return True