MCPcopy Index your code
hub / github.com/python/cpython / make_cert_key

Function make_cert_key

Lib/test/certdata/make_ssl_certs.py:122–173  ·  view source on GitHub ↗
(cmdlineargs, hostname, sign=False, extra_san='',
                  ext='req_x509_extensions_full', key='rsa:3072')

Source from the content-addressed store, hash-verified

120
121
122def 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
175TMP_CADIR = 'cadir'
176

Callers 1

make_ssl_certs.pyFile · 0.85

Calls 7

check_callFunction · 0.85
openFunction · 0.50
appendMethod · 0.45
formatMethod · 0.45
writeMethod · 0.45
readMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…