(cmdlineargs, hostname, sign=False, extra_san='',
ext='req_x509_extensions_full', key='rsa:3072')
| 120 | |
| 121 | |
| 122 | def make_cert_key(cmdlineargs, hostname, sign=False, extra_san='', |
| 123 | ext='req_x509_extensions_full', key='rsa:3072'): |
| 124 | print("creating cert for " + hostname) |
| 125 | tempnames = [] |
| 126 | for i in range(3): |
| 127 | with tempfile.NamedTemporaryFile(delete=False) as f: |
| 128 | tempnames.append(f.name) |
| 129 | req_file, cert_file, key_file = tempnames |
| 130 | try: |
| 131 | req = req_template.format( |
| 132 | hostname=hostname, |
| 133 | extra_san=extra_san, |
| 134 | startdate=startdate, |
| 135 | enddate=cmdlineargs.enddate, |
| 136 | days=cmdlineargs.days |
| 137 | ) |
| 138 | with open(req_file, 'w') as f: |
| 139 | f.write(req) |
| 140 | args = ['req', '-new', '-nodes', '-days', cmdlineargs.days, |
| 141 | '-newkey', key, '-keyout', key_file, |
| 142 | '-config', req_file] |
| 143 | if sign: |
| 144 | with tempfile.NamedTemporaryFile(delete=False) as f: |
| 145 | tempnames.append(f.name) |
| 146 | reqfile = f.name |
| 147 | args += ['-out', reqfile ] |
| 148 | |
| 149 | else: |
| 150 | args += ['-extensions', ext, '-x509', '-out', cert_file ] |
| 151 | check_call(['openssl'] + args) |
| 152 | |
| 153 | if sign: |
| 154 | args = [ |
| 155 | 'ca', |
| 156 | '-config', req_file, |
| 157 | '-extensions', ext, |
| 158 | '-out', cert_file, |
| 159 | '-outdir', 'cadir', |
| 160 | '-policy', 'policy_anything', |
| 161 | '-batch', '-infiles', reqfile |
| 162 | ] |
| 163 | check_call(['openssl'] + args) |
| 164 | |
| 165 | |
| 166 | with open(cert_file, 'r') as f: |
| 167 | cert = f.read() |
| 168 | with open(key_file, 'r') as f: |
| 169 | key = f.read() |
| 170 | return cert, key |
| 171 | finally: |
| 172 | for name in tempnames: |
| 173 | os.remove(name) |
| 174 | |
| 175 | TMP_CADIR = 'cadir' |
| 176 |
no test coverage detected
searching dependent graphs…