summaryrefslogtreecommitdiffstats
path: root/apps/smime.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2000-07-10 18:33:05 +0000
committerDr. Stephen Henson <steve@openssl.org>2000-07-10 18:33:05 +0000
commit094fe66d9fdb70bb424de822bbed1eddb8f0194a (patch)
tree619eb1632041ad37336b07e9916a0430028763f8 /apps/smime.c
parent27d7260075ba525c69e5b8e8ccb1b98010b56dd3 (diff)
Fix some typose in the i2d/d2i functions that
call the i2c/c2i (they were not using the content length for the headers). Fix ASN1 long form tag encoding. This never worked but it was never tested since it is only used for tags > 30. New options to smime program to allow the PKCS#7 format to be specified and the content supplied externally.
Diffstat (limited to 'apps/smime.c')
-rw-r--r--apps/smime.c58
1 files changed, 52 insertions, 6 deletions
diff --git a/apps/smime.c b/apps/smime.c
index bb8ecd7cf0..ebc0eb6af4 100644
--- a/apps/smime.c
+++ b/apps/smime.c
@@ -87,7 +87,7 @@ int MAIN(int argc, char **argv)
char *inmode = "r", *outmode = "w";
char *infile = NULL, *outfile = NULL;
char *signerfile = NULL, *recipfile = NULL;
- char *certfile = NULL, *keyfile = NULL;
+ char *certfile = NULL, *keyfile = NULL, *contfile=NULL;
EVP_CIPHER *cipher = NULL;
PKCS7 *p7 = NULL;
X509_STORE *store = NULL;
@@ -102,6 +102,7 @@ int MAIN(int argc, char **argv)
char *passargin = NULL, *passin = NULL;
char *inrand = NULL;
int need_rand = 0;
+ int informat = FORMAT_SMIME, outformat = FORMAT_SMIME;
args = argv + 1;
ret = 1;
@@ -205,11 +206,26 @@ int MAIN(int argc, char **argv)
args++;
infile = *args;
} else badarg = 1;
+ } else if (!strcmp (*args, "-inform")) {
+ if (args[1]) {
+ args++;
+ informat = str2fmt(*args);
+ } else badarg = 1;
+ } else if (!strcmp (*args, "-outform")) {
+ if (args[1]) {
+ args++;
+ outformat = str2fmt(*args);
+ } else badarg = 1;
} else if (!strcmp (*args, "-out")) {
if (args[1]) {
args++;
outfile = *args;
} else badarg = 1;
+ } else if (!strcmp (*args, "-content")) {
+ if (args[1]) {
+ args++;
+ contfile = *args;
+ } else badarg = 1;
} else badarg = 1;
args++;
}
@@ -292,9 +308,12 @@ int MAIN(int argc, char **argv)
if(operation != SMIME_SIGN) flags &= ~PKCS7_DETACHED;
- if(flags & PKCS7_BINARY) {
- if(operation & SMIME_OP) inmode = "rb";
- else outmode = "rb";
+ if(operation & SMIME_OP) {
+ if(flags & PKCS7_BINARY) inmode = "rb";
+ if(outformat == FORMAT_ASN1) outmode = "wb";
+ } else {
+ if(flags & PKCS7_BINARY) outmode = "wb";
+ if(informat == FORMAT_ASN1) inmode = "rb";
}
if(operation == SMIME_ENCRYPT) {
@@ -383,10 +402,28 @@ int MAIN(int argc, char **argv)
p7 = PKCS7_sign(signer, key, other, in, flags);
BIO_reset(in);
} else {
- if(!(p7 = SMIME_read_PKCS7(in, &indata))) {
+ if(informat == FORMAT_SMIME)
+ p7 = SMIME_read_PKCS7(in, &indata);
+ else if(informat == FORMAT_PEM)
+ p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
+ else if(informat == FORMAT_ASN1)
+ p7 = d2i_PKCS7_bio(in, NULL);
+ else {
+ BIO_printf(bio_err, "Bad input format for PKCS#7 file\n");
+ goto end;
+ }
+
+ if(!p7) {
BIO_printf(bio_err, "Error reading S/MIME message\n");
goto end;
}
+ if(contfile) {
+ BIO_free(indata);
+ if(!(indata = BIO_new_file(contfile, "rb"))) {
+ BIO_printf(bio_err, "Can't read content file %s\n", contfile);
+ goto end;
+ }
+ }
}
if(!p7) {
@@ -422,7 +459,16 @@ int MAIN(int argc, char **argv)
if(to) BIO_printf(out, "To: %s\n", to);
if(from) BIO_printf(out, "From: %s\n", from);
if(subject) BIO_printf(out, "Subject: %s\n", subject);
- SMIME_write_PKCS7(out, p7, in, flags);
+ if(outformat == FORMAT_SMIME)
+ SMIME_write_PKCS7(out, p7, in, flags);
+ else if(outformat == FORMAT_PEM)
+ PEM_write_bio_PKCS7(out,p7);
+ else if(outformat == FORMAT_ASN1)
+ i2d_PKCS7_bio(out,p7);
+ else {
+ BIO_printf(bio_err, "Bad output format for PKCS#7 file\n");
+ goto end;
+ }
}
ret = 0;
end: