X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fpkcs7%2Fdec.c;h=6752ec568a91ecc2a435685d84e562635271a984;hp=2622cbd696d29926ac28ffafa4bf756d673d186d;hb=980aea7860004ca348abafce6c7d08694f6e98eb;hpb=dfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c diff --git a/crypto/pkcs7/dec.c b/crypto/pkcs7/dec.c index 2622cbd696..6752ec568a 100644 --- a/crypto/pkcs7/dec.c +++ b/crypto/pkcs7/dec.c @@ -56,48 +56,40 @@ * [including the GNU Public Licence.] */ #include -#include "asn1.h" -#include "bio.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include +#include +#include +#include int verify_callback(int ok, X509_STORE_CTX *ctx); BIO *bio_err=NULL; -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { + char *keyfile=NULL; BIO *in; - X509 *x509,*x; EVP_PKEY *pkey; + X509 *x509; PKCS7 *p7; - PKCS7_SIGNED *s; PKCS7_SIGNER_INFO *si; - PKCS7_ISSUER_AND_SERIAL *ias; X509_STORE_CTX cert_ctx; X509_STORE *cert_store=NULL; - X509_LOOKUP *lookup=NULL; BIO *data,*detached=NULL,*p7bio=NULL; char buf[1024*4]; - unsigned char *p,*pp; - int i,j,printit=0; - STACK *sk; + unsigned char *pp; + int i,printit=0; + STACK_OF(PKCS7_SIGNER_INFO) *sk; - SSLeay_add_all_algorithms(); + OpenSSL_add_all_algorithms(); bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); - EVP_add_digest(EVP_sha1()); - EVP_add_cipher(EVP_des_ede3_cbc()); - - if ((in=BIO_new_file("server.pem","r")) == NULL) goto err; - if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; - BIO_reset(in); - if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; - BIO_free(in); data=BIO_new(BIO_s_file()); -again: pp=NULL; while (argc > 1) { @@ -107,28 +99,41 @@ again: { printit=1; } - else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2)) + else if ((strcmp(argv[0],"-k") == 0) && (argc >= 2)) { + keyfile = argv[1]; + argc-=1; + argv+=1; + } else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2)) { detached=BIO_new(BIO_s_file()); if (!BIO_read_filename(detached,argv[1])) goto err; - argc--; - argv++; - } - else - { - pp=argv[0]; - if (!BIO_read_filename(data,argv[0])) - goto err; + argc-=1; + argv+=1; } + else break; } + if (!BIO_read_filename(data,argv[0])) goto err; + + if(!keyfile) { + fprintf(stderr, "No private key file specified\n"); + goto err; + } + + if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err; + if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err; + BIO_reset(in); + if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL) + goto err; + BIO_free(in); + if (pp == NULL) BIO_set_fp(data,stdin,BIO_NOCLOSE); /* Load the PKCS7 object from a file */ - if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err; + if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL,NULL)) == NULL) goto err; @@ -144,8 +149,8 @@ again: /* We need to process the data */ /* We cannot support detached encryption */ - p7bio=PKCS7_dataDecode(p7,pkey,detached,cert_store); - + p7bio=PKCS7_dataDecode(p7,pkey,detached,x509); + if (p7bio == NULL) { printf("problems decoding\n"); @@ -158,23 +163,23 @@ again: i=BIO_read(p7bio,buf,sizeof(buf)); /* print it? */ if (i <= 0) break; - write(fileno(stdout),buf,i); + fwrite(buf,1, i, stdout); } /* We can now verify signatures */ sk=PKCS7_get_signer_info(p7); if (sk == NULL) { - printf("there are no signatures on this data\n"); + fprintf(stderr, "there are no signatures on this data\n"); } else { /* Ok, first we need to, for each subject entry, * see if we can verify */ ERR_clear_error(); - for (i=0; i