Skip to content

Commit 1693261

Browse files
committed
man, str(as_pam was never going to be right
1 parent e923e4c commit 1693261

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

contrib/gen-pretend-certs.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def gen_CA(fname='ca-root', cn='ca-root', path_length=0, authority=None, pdir=DE
4949
private_key = genkey(**args)
5050
public_key = private_key.public_key()
5151

52-
with open(os.path.join(pdir, fname + '.key'), 'w') as fh:
53-
fh.write( str(as_pem(private_key)) )
52+
with open(os.path.join(pdir, fname + '.key'), 'wb') as fh:
53+
fh.write( as_pem(private_key) )
5454

55-
with open(os.path.join(pdir, fname + '.unsigned'), 'w') as fh:
56-
fh.write( str(as_pem(public_key)) )
55+
with open(os.path.join(pdir, fname + '.unsigned'), 'wb') as fh:
56+
fh.write( as_pem(public_key) )
5757

5858
ksec_100 = datetime.timedelta(0, 100e3, 0)
5959
Msec_300 = datetime.timedelta(0, 300e6, 0)
@@ -114,8 +114,8 @@ def gen_CA(fname='ca-root', cn='ca-root', path_length=0, authority=None, pdir=DE
114114

115115
certificate = builder.sign(**signing_args)
116116

117-
with open(os.path.join(pdir, fname + '.crt'), 'w') as fh:
118-
fh.write( str(as_pem(certificate)) )
117+
with open(os.path.join(pdir, fname + '.crt'), 'wb') as fh:
118+
fh.write( as_pem(certificate) )
119119

120120
return Authority(private_key, certificate)
121121

@@ -126,11 +126,11 @@ def gen_leaf(authority, fname_template='{}', cn='Certy Cert McCertFace', pdir=DE
126126
private_name = fname_template.format('private')
127127
public_name = fname_template.format('public')
128128

129-
with open(os.path.join(pdir, private_name + '.key'), 'w') as fh:
130-
fh.write( str(as_pem(private_key)) )
129+
with open(os.path.join(pdir, private_name + '.key'), 'wb') as fh:
130+
fh.write( as_pem(private_key) )
131131

132-
with open(os.path.join(pdir, public_name + '.unsigned'), 'w') as fh:
133-
fh.write( str(as_pem(public_key)) )
132+
with open(os.path.join(pdir, public_name + '.unsigned'), 'wb') as fh:
133+
fh.write( as_pem(public_key) )
134134

135135
ksec_100 = datetime.timedelta(0, 100e3, 0)
136136
Msec_300 = datetime.timedelta(0, 300e6, 0)
@@ -186,8 +186,8 @@ def gen_leaf(authority, fname_template='{}', cn='Certy Cert McCertFace', pdir=DE
186186

187187
certificate = builder.sign(**signing_args)
188188

189-
with open(os.path.join(pdir, public_name + '.crt'), 'w') as fh:
190-
fh.write( str(as_pem(certificate)) )
189+
with open(os.path.join(pdir, public_name + '.crt'), 'wb') as fh:
190+
fh.write( as_pem(certificate) )
191191

192192
return Authority(private_key, certificate)
193193

@@ -203,9 +203,9 @@ def main(root_cn, int1_cn, int2_cn, **args):
203203
lf1 = gen_leaf(cn='Certy Cert #1', fname_template='{}-1', authority=ia1, **args)
204204
lf2 = gen_leaf(cn='Certy Cert #2', fname_template='{}-2', authority=ia2, **args)
205205

206-
with open(os.path.join(args['pdir'], 'bundle.pem'), 'w') as ofh:
206+
with open(os.path.join(args['pdir'], 'bundle.pem'), 'wb') as ofh:
207207
for i in range(1,3):
208-
with open(os.path.join(args['pdir'], 'intermediate-{}.crt'.format(i)), 'r') as ifh:
208+
with open(os.path.join(args['pdir'], 'intermediate-{}.crt'.format(i)), 'rb') as ifh:
209209
ofh.write(ifh.read())
210210

211211
if __name__ == '__main__':

0 commit comments

Comments
 (0)