From 213a75dbf21b8f641a9ee90cc12882fc429bb84b Mon Sep 17 00:00:00 2001 From: Ben Laurie Date: Thu, 3 Jun 1999 16:07:37 +0000 Subject: [PATCH] Make samples compile. --- CHANGES | 3 +++ crypto/pkcs7/Makefile.ssl | 14 ++++++++++ crypto/pkcs7/dec.c | 8 +++--- crypto/pkcs7/enc.c | 2 +- crypto/pkcs7/example.c | 28 ++++++++----------- crypto/pkcs7/example.h | 57 +++++++++++++++++++++++++++++++++++++++ crypto/pkcs7/sign.c | 6 ++--- crypto/pkcs7/verify.c | 22 +++++++-------- 8 files changed, 103 insertions(+), 37 deletions(-) create mode 100644 crypto/pkcs7/example.h diff --git a/CHANGES b/CHANGES index fb94adaa77..1786aefd9a 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,9 @@ Changes between 0.9.3a and 0.9.4 + *) Make S/MIME samples compile (not yet tested). + [Ben Laurie] + *) Additional typesafe stacks. [Ben Laurie] diff --git a/crypto/pkcs7/Makefile.ssl b/crypto/pkcs7/Makefile.ssl index 4951888c67..436442a7a1 100644 --- a/crypto/pkcs7/Makefile.ssl +++ b/crypto/pkcs7/Makefile.ssl @@ -39,6 +39,20 @@ test: all: lib +testapps: enc dec sign verify + +enc: enc.o lib + $(CC) $(CFLAGS) -o enc enc.o $(LIB) + +dec: dec.o lib + $(CC) $(CFLAGS) -o dec dec.o $(LIB) + +sign: sign.o lib + $(CC) $(CFLAGS) -o sign sign.o $(LIB) + +verify: verify.o example.o lib + $(CC) $(CFLAGS) -o verify verify.o example.o $(LIB) + lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) $(RANLIB) $(LIB) diff --git a/crypto/pkcs7/dec.c b/crypto/pkcs7/dec.c index c7923e9401..b3661f28d3 100644 --- a/crypto/pkcs7/dec.c +++ b/crypto/pkcs7/dec.c @@ -71,7 +71,7 @@ int main(argc,argv) int argc; char *argv[]; { - char *keyfile; + char *keyfile=NULL; BIO *in; EVP_PKEY *pkey; X509 *x509; @@ -83,7 +83,7 @@ char *argv[]; char buf[1024*4]; unsigned char *pp; int i,printit=0; - STACK *sk; + STACK_OF(PKCS7_SIGNER_INFO) *sk; SSLeay_add_all_algorithms(); bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); @@ -175,9 +175,9 @@ char *argv[]; /* Ok, first we need to, for each subject entry, * see if we can verify */ ERR_clear_error(); - for (i=0; i #include -#include #include +#include int add_signed_time(PKCS7_SIGNER_INFO *si) { @@ -18,19 +18,16 @@ int add_signed_time(PKCS7_SIGNER_INFO *si) ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si) { ASN1_TYPE *so; - ASN1_UTCTIME *ut; so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime); if (so->type == V_ASN1_UTCTIME) - { - ut=so->value.utctime; - } - return(ut); + return so->value.utctime; + return NULL; } static int signed_string_nid= -1; -int add_signed_string(PKCS7_SIGNER_INFO *si, char *str) +void add_signed_string(PKCS7_SIGNER_INFO *si, char *str) { ASN1_OCTET_STRING *os; @@ -80,7 +77,7 @@ int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2) unsigned char *p; ASN1_OCTET_STRING *os1,*os2; ASN1_STRING *seq; - char *data; + unsigned char *data; int i,total; if (signed_seq2string_nid == -1) @@ -178,19 +175,16 @@ X509_ATTRIBUTE *create_time(void) return(ret); } -ASN1_UTCTIME *sk_get_time(STACK *sk) +ASN1_UTCTIME *sk_get_time(STACK_OF(X509_ATTRIBUTE) *sk) { ASN1_TYPE *so; - ASN1_UTCTIME *ut; PKCS7_SIGNER_INFO si; si.auth_attr=sk; so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime); if (so->type == V_ASN1_UTCTIME) - { - ut=so->value.utctime; - } - return(ut); + return so->value.utctime; + return NULL; } X509_ATTRIBUTE *create_string(char *str) @@ -210,7 +204,7 @@ X509_ATTRIBUTE *create_string(char *str) return(ret); } -int sk_get_string(STACK *sk, char *buf, int len) +int sk_get_string(STACK_OF(X509_ATTRIBUTE) *sk, char *buf, int len) { ASN1_TYPE *so; ASN1_OCTET_STRING *os; @@ -247,7 +241,7 @@ X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2) ASN1_OCTET_STRING *os1,*os2; ASN1_STRING *seq; X509_ATTRIBUTE *ret; - char *data; + unsigned char *data; int i,total; if (signed_seq2string_nid == -1) @@ -280,7 +274,7 @@ X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2) } /* For this case, I will malloc the return strings */ -int sk_get_seq2string(STACK *sk, char **str1, char **str2) +int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2) { ASN1_TYPE *so; PKCS7_SIGNER_INFO si; diff --git a/crypto/pkcs7/example.h b/crypto/pkcs7/example.h new file mode 100644 index 0000000000..96167de188 --- /dev/null +++ b/crypto/pkcs7/example.h @@ -0,0 +1,57 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +int add_signed_time(PKCS7_SIGNER_INFO *si); +ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si); +int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2); diff --git a/crypto/pkcs7/sign.c b/crypto/pkcs7/sign.c index 4a1d998606..d5f1154006 100644 --- a/crypto/pkcs7/sign.c +++ b/crypto/pkcs7/sign.c @@ -59,20 +59,20 @@ #include #include #include +#include -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { X509 *x509; EVP_PKEY *pkey; PKCS7 *p7; - PKCS7 *p7_data; PKCS7_SIGNER_INFO *si; BIO *in; BIO *data,*p7bio; char buf[1024*4]; - int i,j; + int i; int nodetach=0; EVP_add_digest(EVP_md2()); diff --git a/crypto/pkcs7/verify.c b/crypto/pkcs7/verify.c index 71a67df3d4..32d9783e45 100644 --- a/crypto/pkcs7/verify.c +++ b/crypto/pkcs7/verify.c @@ -56,33 +56,31 @@ * [including the GNU Public Licence.] */ #include -#include #include +#include #include #include +#include +#include "example.h" int verify_callback(int ok, X509_STORE_CTX *ctx); BIO *bio_err=NULL; BIO *bio_out=NULL; -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { - X509 *x509,*x; 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; + char *pp; + int i,printit=0; + STACK_OF(PKCS7_SIGNER_INFO) *sk; bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); bio_out=BIO_new_fp(stdout,BIO_NOCLOSE); @@ -92,7 +90,7 @@ char *argv[]; EVP_add_digest(EVP_mdc2()); data=BIO_new(BIO_s_file()); -again: + pp=NULL; while (argc > 1) { @@ -168,12 +166,12 @@ again: } /* Ok, first we need to, for each subject entry, see if we can verify */ - for (i=0; i