aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/pkcs7/dec.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>1999-05-16 17:32:32 +0000
committerDr. Stephen Henson <steve@openssl.org>1999-05-16 17:32:32 +0000
commit1b266dabf5417e228d9e970d4f2923fec92fea1e (patch)
tree5d8452e6c93ec0b81379cf23aa8a74f82c1726f9 /crypto/pkcs7/dec.c
parentf43c814917fea994234376b7c7538ad26b9c46bf (diff)
downloadopenssl-1b266dabf5417e228d9e970d4f2923fec92fea1e.tar.gz
Fix various less obvious bugs in PKCS#7 handling: such as not zeroing
the secret key before we've encrypted it and using the right NID for RC2-64. Add various arguments to the experimental programs 'dec' and 'enc' to make testing less painful. This stuff has now been tested against Netscape Messenger and it can encrypt and decrypt S/MIME messages with RC2 (128, 64 and 40 bit) DES and triple DES. Its still experimental though...
Diffstat (limited to 'crypto/pkcs7/dec.c')
-rw-r--r--crypto/pkcs7/dec.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/crypto/pkcs7/dec.c b/crypto/pkcs7/dec.c
index 7063037bb1..c7923e9401 100644
--- a/crypto/pkcs7/dec.c
+++ b/crypto/pkcs7/dec.c
@@ -56,48 +56,39 @@
* [including the GNU Public Licence.]
*/
#include <stdio.h>
-#include <openssl/asn1.h>
+#include <stdlib.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
+#include <openssl/err.h>
+#include <openssl/asn1.h>
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;
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;
+ unsigned char *pp;
+ int i,printit=0;
STACK *sk;
SSLeay_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,22 +98,34 @@ 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) goto err;
+ BIO_reset(in);
+ if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
+ BIO_free(in);
+
if (pp == NULL)
BIO_set_fp(data,stdin,BIO_NOCLOSE);
@@ -158,14 +161,14 @@ 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
{