Example #1
0
 def build_req_config(self, entry, metadata):
     """
     generates a temporary openssl configuration file that is
     used to generate the required certificate request
     """
     # create temp request config file
     conffile = open(tempfile.mkstemp()[1], 'w')
     cp = ConfigParser({})
     cp.optionxform = str
     defaults = {
         'req': {
             'default_md': 'sha1',
             'distinguished_name': 'req_distinguished_name',
             'req_extensions': 'v3_req',
             'x509_extensions': 'v3_req',
             'prompt': 'no'
         },
         'req_distinguished_name': {},
         'v3_req': {
             'subjectAltName': '@alt_names'
         },
         'alt_names': {}
     }
     for section in list(defaults.keys()):
         cp.add_section(section)
         for key in defaults[section]:
             cp.set(section, key, defaults[section][key])
     x = 1
     altnames = list(metadata.aliases)
     altnames.append(metadata.hostname)
     for altname in altnames:
         cp.set('alt_names', 'DNS.' + str(x), altname)
         x += 1
     for item in ['C', 'L', 'ST', 'O', 'OU', 'emailAddress']:
         if self.cert_specs[entry.get('name')][item]:
             cp.set('req_distinguished_name', item, self.cert_specs[entry.get('name')][item])
     cp.set('req_distinguished_name', 'CN', metadata.hostname)
     cp.write(conffile)
     conffile.close()
     return conffile.name
Example #2
0
 def build_req_config(self, entry, metadata):
     """
     generates a temporary openssl configuration file that is
     used to generate the required certificate request
     """
     # create temp request config file
     conffile = open(tempfile.mkstemp()[1], "w")
     cp = ConfigParser({})
     cp.optionxform = str
     defaults = {
         "req": {
             "default_md": "sha1",
             "distinguished_name": "req_distinguished_name",
             "req_extensions": "v3_req",
             "x509_extensions": "v3_req",
             "prompt": "no",
         },
         "req_distinguished_name": {},
         "v3_req": {"subjectAltName": "@alt_names"},
         "alt_names": {},
     }
     for section in list(defaults.keys()):
         cp.add_section(section)
         for key in defaults[section]:
             cp.set(section, key, defaults[section][key])
     x = 1
     altnames = list(metadata.aliases)
     altnames.append(metadata.hostname)
     for altname in altnames:
         cp.set("alt_names", "DNS." + str(x), altname)
         x += 1
     for item in ["C", "L", "ST", "O", "OU", "emailAddress"]:
         if self.cert_specs[entry.get("name")][item]:
             cp.set("req_distinguished_name", item, self.cert_specs[entry.get("name")][item])
     cp.set("req_distinguished_name", "CN", metadata.hostname)
     cp.write(conffile)
     conffile.close()
     return conffile.name