| OLD | NEW |
| 1 /* apps/crl2p7.c */ | 1 /* apps/crl2p7.c */ |
| 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
| 6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
| 7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
| 8 * | 8 * |
| 9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
| 10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
| 57 */ | 57 */ |
| 58 | 58 |
| 59 /* This was written by Gordon Chaffee <chaffee@plateau.cs.berkeley.edu> | 59 /* This was written by Gordon Chaffee <chaffee@plateau.cs.berkeley.edu> |
| 60 * and donated 'to the cause' along with lots and lots of other fixes to | 60 * and donated 'to the cause' along with lots and lots of other fixes to |
| 61 * the library. */ | 61 * the library. */ |
| 62 | 62 |
| 63 #include <stdio.h> | 63 #include <stdio.h> |
| 64 #include <string.h> | 64 #include <string.h> |
| 65 #include <sys/types.h> | 65 #include <sys/types.h> |
| 66 #include <sys/stat.h> | |
| 67 #include "apps.h" | 66 #include "apps.h" |
| 68 #include <openssl/err.h> | 67 #include <openssl/err.h> |
| 69 #include <openssl/evp.h> | 68 #include <openssl/evp.h> |
| 70 #include <openssl/x509.h> | 69 #include <openssl/x509.h> |
| 71 #include <openssl/pkcs7.h> | 70 #include <openssl/pkcs7.h> |
| 72 #include <openssl/pem.h> | 71 #include <openssl/pem.h> |
| 73 #include <openssl/objects.h> | 72 #include <openssl/objects.h> |
| 74 | 73 |
| 75 static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile); | 74 static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile); |
| 76 #undef PROG | 75 #undef PROG |
| 77 #define PROG crl2pkcs7_main | 76 #define PROG crl2pkcs7_main |
| 78 | 77 |
| 79 /* -inform arg - input format - default PEM (DER or PEM) | 78 /* -inform arg - input format - default PEM (DER or PEM) |
| 80 * -outform arg - output format - default PEM | 79 * -outform arg - output format - default PEM |
| 81 * -in arg - input file - default stdin | 80 * -in arg - input file - default stdin |
| 82 * -out arg - output file - default stdout | 81 * -out arg - output file - default stdout |
| 83 */ | 82 */ |
| 84 | 83 |
| 85 int MAIN(int, char **); | 84 int MAIN(int, char **); |
| 86 | 85 |
| 87 int MAIN(int argc, char **argv) | 86 int MAIN(int argc, char **argv) |
| 88 { | 87 { |
| 89 int i,badops=0; | 88 int i,badops=0; |
| 90 BIO *in=NULL,*out=NULL; | 89 BIO *in=NULL,*out=NULL; |
| 91 int informat,outformat; | 90 int informat,outformat; |
| 92 char *infile,*outfile,*prog,*certfile; | 91 char *infile,*outfile,*prog,*certfile; |
| 93 PKCS7 *p7 = NULL; | 92 PKCS7 *p7 = NULL; |
| 94 PKCS7_SIGNED *p7s = NULL; | 93 PKCS7_SIGNED *p7s = NULL; |
| 95 X509_CRL *crl=NULL; | 94 X509_CRL *crl=NULL; |
| 96 » STACK *certflst=NULL; | 95 » STACK_OF(OPENSSL_STRING) *certflst=NULL; |
| 97 STACK_OF(X509_CRL) *crl_stack=NULL; | 96 STACK_OF(X509_CRL) *crl_stack=NULL; |
| 98 STACK_OF(X509) *cert_stack=NULL; | 97 STACK_OF(X509) *cert_stack=NULL; |
| 99 int ret=1,nocrl=0; | 98 int ret=1,nocrl=0; |
| 100 | 99 |
| 101 apps_startup(); | 100 apps_startup(); |
| 102 | 101 |
| 103 if (bio_err == NULL) | 102 if (bio_err == NULL) |
| 104 if ((bio_err=BIO_new(BIO_s_file())) != NULL) | 103 if ((bio_err=BIO_new(BIO_s_file())) != NULL) |
| 105 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); | 104 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); |
| 106 | 105 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 134 nocrl=1; | 133 nocrl=1; |
| 135 } | 134 } |
| 136 else if (strcmp(*argv,"-out") == 0) | 135 else if (strcmp(*argv,"-out") == 0) |
| 137 { | 136 { |
| 138 if (--argc < 1) goto bad; | 137 if (--argc < 1) goto bad; |
| 139 outfile= *(++argv); | 138 outfile= *(++argv); |
| 140 } | 139 } |
| 141 else if (strcmp(*argv,"-certfile") == 0) | 140 else if (strcmp(*argv,"-certfile") == 0) |
| 142 { | 141 { |
| 143 if (--argc < 1) goto bad; | 142 if (--argc < 1) goto bad; |
| 144 » » » if(!certflst) certflst = sk_new_null(); | 143 » » » if(!certflst) certflst = sk_OPENSSL_STRING_new_null(); |
| 145 » » » sk_push(certflst,*(++argv)); | 144 » » » sk_OPENSSL_STRING_push(certflst,*(++argv)); |
| 146 } | 145 } |
| 147 else | 146 else |
| 148 { | 147 { |
| 149 BIO_printf(bio_err,"unknown option %s\n",*argv); | 148 BIO_printf(bio_err,"unknown option %s\n",*argv); |
| 150 badops=1; | 149 badops=1; |
| 151 break; | 150 break; |
| 152 } | 151 } |
| 153 argc--; | 152 argc--; |
| 154 argv++; | 153 argv++; |
| 155 } | 154 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 p7s->crl=crl_stack; | 219 p7s->crl=crl_stack; |
| 221 if (crl != NULL) | 220 if (crl != NULL) |
| 222 { | 221 { |
| 223 sk_X509_CRL_push(crl_stack,crl); | 222 sk_X509_CRL_push(crl_stack,crl); |
| 224 crl=NULL; /* now part of p7 for OPENSSL_freeing */ | 223 crl=NULL; /* now part of p7 for OPENSSL_freeing */ |
| 225 } | 224 } |
| 226 | 225 |
| 227 if ((cert_stack=sk_X509_new_null()) == NULL) goto end; | 226 if ((cert_stack=sk_X509_new_null()) == NULL) goto end; |
| 228 p7s->cert=cert_stack; | 227 p7s->cert=cert_stack; |
| 229 | 228 |
| 230 » if(certflst) for(i = 0; i < sk_num(certflst); i++) { | 229 » if(certflst) for(i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) { |
| 231 » » certfile = sk_value(certflst, i); | 230 » » certfile = sk_OPENSSL_STRING_value(certflst, i); |
| 232 if (add_certs_from_file(cert_stack,certfile) < 0) | 231 if (add_certs_from_file(cert_stack,certfile) < 0) |
| 233 { | 232 { |
| 234 BIO_printf(bio_err, "error loading certificates\n"); | 233 BIO_printf(bio_err, "error loading certificates\n"); |
| 235 ERR_print_errors(bio_err); | 234 ERR_print_errors(bio_err); |
| 236 goto end; | 235 goto end; |
| 237 } | 236 } |
| 238 } | 237 } |
| 239 | 238 |
| 240 » sk_free(certflst); | 239 » sk_OPENSSL_STRING_free(certflst); |
| 241 | 240 |
| 242 if (outfile == NULL) | 241 if (outfile == NULL) |
| 243 { | 242 { |
| 244 BIO_set_fp(out,stdout,BIO_NOCLOSE); | 243 BIO_set_fp(out,stdout,BIO_NOCLOSE); |
| 245 #ifdef OPENSSL_SYS_VMS | 244 #ifdef OPENSSL_SYS_VMS |
| 246 { | 245 { |
| 247 BIO *tmpbio = BIO_new(BIO_f_linebuffer()); | 246 BIO *tmpbio = BIO_new(BIO_f_linebuffer()); |
| 248 out = BIO_push(tmpbio, out); | 247 out = BIO_push(tmpbio, out); |
| 249 } | 248 } |
| 250 #endif | 249 #endif |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 * int add_certs_from_file | 287 * int add_certs_from_file |
| 289 * | 288 * |
| 290 * Read a list of certificates to be checked from a file. | 289 * Read a list of certificates to be checked from a file. |
| 291 * | 290 * |
| 292 * Results: | 291 * Results: |
| 293 * number of certs added if successful, -1 if not. | 292 * number of certs added if successful, -1 if not. |
| 294 *---------------------------------------------------------------------- | 293 *---------------------------------------------------------------------- |
| 295 */ | 294 */ |
| 296 static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile) | 295 static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile) |
| 297 { | 296 { |
| 298 struct stat st; | |
| 299 BIO *in=NULL; | 297 BIO *in=NULL; |
| 300 int count=0; | 298 int count=0; |
| 301 int ret= -1; | 299 int ret= -1; |
| 302 STACK_OF(X509_INFO) *sk=NULL; | 300 STACK_OF(X509_INFO) *sk=NULL; |
| 303 X509_INFO *xi; | 301 X509_INFO *xi; |
| 304 | 302 |
| 305 if ((stat(certfile,&st) != 0)) | |
| 306 { | |
| 307 BIO_printf(bio_err,"unable to load the file, %s\n",certfile); | |
| 308 goto end; | |
| 309 } | |
| 310 | |
| 311 in=BIO_new(BIO_s_file()); | 303 in=BIO_new(BIO_s_file()); |
| 312 if ((in == NULL) || (BIO_read_filename(in,certfile) <= 0)) | 304 if ((in == NULL) || (BIO_read_filename(in,certfile) <= 0)) |
| 313 { | 305 { |
| 314 BIO_printf(bio_err,"error opening the file, %s\n",certfile); | 306 BIO_printf(bio_err,"error opening the file, %s\n",certfile); |
| 315 goto end; | 307 goto end; |
| 316 } | 308 } |
| 317 | 309 |
| 318 /* This loads from a file, a stack of x509/crl/pkey sets */ | 310 /* This loads from a file, a stack of x509/crl/pkey sets */ |
| 319 sk=PEM_X509_INFO_read_bio(in,NULL,NULL,NULL); | 311 sk=PEM_X509_INFO_read_bio(in,NULL,NULL,NULL); |
| 320 if (sk == NULL) { | 312 if (sk == NULL) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 336 } | 328 } |
| 337 | 329 |
| 338 ret=count; | 330 ret=count; |
| 339 end: | 331 end: |
| 340 /* never need to OPENSSL_free x */ | 332 /* never need to OPENSSL_free x */ |
| 341 if (in != NULL) BIO_free(in); | 333 if (in != NULL) BIO_free(in); |
| 342 if (sk != NULL) sk_X509_INFO_free(sk); | 334 if (sk != NULL) sk_X509_INFO_free(sk); |
| 343 return(ret); | 335 return(ret); |
| 344 } | 336 } |
| 345 | 337 |
| OLD | NEW |