@@ -125,6 +125,11 @@ main(int argc, const char **argv)
125
125
char * cert_file = NULL ;
126
126
char * cert_key_file = NULL ;
127
127
128
+ int ca_mode = 0644 ;
129
+ int ca_key_mode = 0600 ;
130
+ int cert_mode = 0644 ;
131
+ int cert_key_mode = 0600 ;
132
+
128
133
struct sscg_x509_cert * cacert ;
129
134
struct sscg_evp_pkey * cakey ;
130
135
struct sscg_x509_cert * svc_cert ;
@@ -135,6 +140,8 @@ main(int argc, const char **argv)
135
140
BIO * cert_out = NULL ;
136
141
BIO * cert_key_out = NULL ;
137
142
143
+ FILE * fp ;
144
+
138
145
/* Always use umask 077 for generating certificates and keys */
139
146
umask (077 );
140
147
@@ -202,21 +209,37 @@ main(int argc, const char **argv)
202
209
_ ("Path where the public CA certificate will be stored. (default: \"./ca.crt\")" ),
203
210
NULL ,
204
211
},
212
+ {"ca-mode" , '\0' , POPT_ARG_INT , & ca_mode , 0 ,
213
+ _ ("File mode of the created CA certificate. (default: 0644)" ),
214
+ _ ("0644" ),
215
+ },
205
216
{"ca-key-file" , '\0' , POPT_ARG_STRING , & ca_key_file , 0 ,
206
217
_ ("Path where the CA's private key will be stored. If unspecified, "
207
218
"the key will be destroyed rather than written to the disk." ),
208
219
NULL ,
209
220
},
221
+ {"ca-key-mode" , '\0' , POPT_ARG_INT , & ca_key_mode , 0 ,
222
+ _ ("File mode of the created CA key. (default: 0600)" ),
223
+ _ ("0600" ),
224
+ },
210
225
{"cert-file" , '\0' , POPT_ARG_STRING , & cert_file , 0 ,
211
226
_ ("Path where the public service certificate will be stored. "
212
227
"(default \"./service.pem\")" ),
213
228
NULL ,
214
229
},
230
+ {"cert-mode" , '\0' , POPT_ARG_INT , & cert_mode , 0 ,
231
+ _ ("File mode of the created certificate. (default: 0644)" ),
232
+ _ ("0644" ),
233
+ },
215
234
{"cert-key-file" , '\0' , POPT_ARG_STRING , & cert_key_file , 0 ,
216
235
_ ("Path where the service's private key will be stored. "
217
236
"(default \"service-key.pem\")" ),
218
237
NULL ,
219
238
},
239
+ {"cert-key-mode" , '\0' , POPT_ARG_INT , & cert_key_mode , 0 ,
240
+ _ ("File mode of the created certificate key. (default: 0600)" ),
241
+ _ ("0600" ),
242
+ },
220
243
POPT_TABLEEND
221
244
};
222
245
@@ -391,6 +414,8 @@ main(int argc, const char **argv)
391
414
392
415
sret = PEM_write_bio_X509 (ca_out , cacert -> certificate );
393
416
CHECK_SSL (sret , PEM_write_bio_X509 (CA ));
417
+ BIO_get_fp (ca_out , & fp );
418
+ fchmod (fileno (fp ), ca_mode );
394
419
BIO_free (ca_out ); ca_out = NULL ;
395
420
396
421
if (options -> ca_key_file ) {
@@ -408,6 +433,8 @@ main(int argc, const char **argv)
408
433
sret = PEM_write_bio_PrivateKey (ca_key_out , cakey -> evp_pkey ,
409
434
NULL , NULL , 0 , NULL , NULL );
410
435
CHECK_SSL (sret , PEM_write_bio_PrivateKey (CA ));
436
+ BIO_get_fp (ca_key_out , & fp );
437
+ fchmod (fileno (fp ), ca_key_mode );
411
438
BIO_free (ca_key_out ); ca_key_out = NULL ;
412
439
}
413
440
@@ -424,6 +451,8 @@ main(int argc, const char **argv)
424
451
425
452
sret = PEM_write_bio_X509 (cert_out , svc_cert -> certificate );
426
453
CHECK_SSL (sret , PEM_write_bio_X509 (svc ));
454
+ BIO_get_fp (cert_out , & fp );
455
+ fchmod (fileno (fp ), cert_mode );
427
456
BIO_free (cert_out ); cert_out = NULL ;
428
457
429
458
if (options -> verbosity >= SSCG_DEFAULT ) {
@@ -440,9 +469,11 @@ main(int argc, const char **argv)
440
469
sret = PEM_write_bio_PrivateKey (cert_key_out , svc_key -> evp_pkey ,
441
470
NULL , NULL , 0 , NULL , NULL );
442
471
CHECK_SSL (sret , PEM_write_bio_PrivateKey (svc ));
472
+ BIO_get_fp (cert_key_out , & fp );
473
+ fchmod (fileno (fp ), cert_key_mode );
443
474
BIO_free (cert_key_out ); cert_key_out = NULL ;
444
475
445
-
476
+ ret = EOK ;
446
477
done :
447
478
BIO_free (ca_key_out );
448
479
BIO_free (ca_out );
0 commit comments