@@ -49,11 +49,11 @@ def gen_CA(fname='ca-root', cn='ca-root', path_length=0, authority=None, pdir=DE
49
49
private_key = genkey (** args )
50
50
public_key = private_key .public_key ()
51
51
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 ) )
54
54
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 ) )
57
57
58
58
ksec_100 = datetime .timedelta (0 , 100e3 , 0 )
59
59
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
114
114
115
115
certificate = builder .sign (** signing_args )
116
116
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 ) )
119
119
120
120
return Authority (private_key , certificate )
121
121
@@ -126,11 +126,11 @@ def gen_leaf(authority, fname_template='{}', cn='Certy Cert McCertFace', pdir=DE
126
126
private_name = fname_template .format ('private' )
127
127
public_name = fname_template .format ('public' )
128
128
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 ) )
131
131
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 ) )
134
134
135
135
ksec_100 = datetime .timedelta (0 , 100e3 , 0 )
136
136
Msec_300 = datetime .timedelta (0 , 300e6 , 0 )
@@ -186,8 +186,8 @@ def gen_leaf(authority, fname_template='{}', cn='Certy Cert McCertFace', pdir=DE
186
186
187
187
certificate = builder .sign (** signing_args )
188
188
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 ) )
191
191
192
192
return Authority (private_key , certificate )
193
193
@@ -203,9 +203,9 @@ def main(root_cn, int1_cn, int2_cn, **args):
203
203
lf1 = gen_leaf (cn = 'Certy Cert #1' , fname_template = '{}-1' , authority = ia1 , ** args )
204
204
lf2 = gen_leaf (cn = 'Certy Cert #2' , fname_template = '{}-2' , authority = ia2 , ** args )
205
205
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 :
207
207
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 :
209
209
ofh .write (ifh .read ())
210
210
211
211
if __name__ == '__main__' :
0 commit comments