diff options
Diffstat (limited to 'crypto/asn1')
59 files changed, 1088 insertions, 390 deletions
diff --git a/crypto/asn1/Makefile.ssl b/crypto/asn1/Makefile.ssl index 30751bd156..1e9951fc56 100644 --- a/crypto/asn1/Makefile.ssl +++ b/crypto/asn1/Makefile.ssl @@ -23,7 +23,7 @@ APPS= LIB=$(TOP)/libcrypto.a LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ - a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \ + a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \ a_sign.c a_digest.c a_verify.c \ x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c \ @@ -38,7 +38,7 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \ evp_asn1.c LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ - a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ + a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \ a_sign.o a_digest.o a_verify.o \ x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o \ diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c index 2c10120651..275de43eb6 100644 --- a/crypto/asn1/a_bitstr.c +++ b/crypto/asn1/a_bitstr.c @@ -68,27 +68,50 @@ int i2d_ASN1_BIT_STRING(a,pp) ASN1_BIT_STRING *a; unsigned char **pp; { - int ret,j,r,bits; + int ret,j,r,bits,len; unsigned char *p,*d; if (a == NULL) return(0); - /* our bit strings are always a multiple of 8 :-) */ - bits=0; - ret=1+a->length; + len=a->length; + + if (len > 0) + { + if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) + { + bits=(int)a->flags&0x07; + } + else + { + for ( ; len > 0; len--) + { + if (a->data[len-1]) break; + } + j=a->data[len-1]; + if (j & 0x01) bits=0; + else if (j & 0x02) bits=1; + else if (j & 0x04) bits=2; + else if (j & 0x08) bits=3; + else if (j & 0x10) bits=4; + else if (j & 0x20) bits=5; + else if (j & 0x40) bits=6; + else if (j & 0x80) bits=7; + else bits=0; /* should not happen */ + } + } + else + bits=0; + ret=1+len; r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING); if (pp == NULL) return(r); p= *pp; ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL); - if (bits == 0) - j=0; - else j=8-bits; - *(p++)=(unsigned char)j; + *(p++)=(unsigned char)bits; d=a->data; - memcpy(p,d,a->length); - p+=a->length; - if (a->length > 0) p[-1]&=(0xff<<j); + memcpy(p,d,len); + p+=len; + if (len > 0) p[-1]&=(0xff<<bits); *pp=p; return(r); } @@ -127,6 +150,12 @@ long length; if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; } i= *(p++); + /* We do this to preserve the settings. If we modify + * the settings, via the _set_bit function, we will recalculate + * on output */ + ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */ + ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ + if (len-- > 1) /* using one because of the bits left byte */ { s=(unsigned char *)Malloc((int)len); @@ -170,6 +199,8 @@ int value; v=1<<(7-(n&0x07)); iv= ~v; + a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ + if (a == NULL) return(0); if ((a->length < (w+1)) || (a->data == NULL)) { diff --git a/crypto/asn1/a_bitstr.orig.c b/crypto/asn1/a_bitstr.orig.c new file mode 100644 index 0000000000..871e0575d9 --- /dev/null +++ b/crypto/asn1/a_bitstr.orig.c @@ -0,0 +1,236 @@ +/* crypto/asn1/a_bitstr.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * 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 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 acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS 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 AUTHOR OR 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. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +#include "cryptlib.h" +#include "asn1.h" + +/* ASN1err(ASN1_F_ASN1_STRING_NEW,ASN1_R_STRING_TOO_SHORT); + * ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,ASN1_R_EXPECTING_A_BIT_STRING); + */ + +int i2d_ASN1_BIT_STRING(a,pp) +ASN1_BIT_STRING *a; +unsigned char **pp; + { + int ret,i,j,r,bits,len; + unsigned char *p,*d; + + if (a == NULL) return(0); + + len=a->length; + + if ((len > 0) + { + if (a->flags & ASN1_FG_BITS_LEFT)) + { + bits=a->flags&0x07; + } + else + { + for ( ; len > 0; len--) + { + if (a->data[len-1]) break; + } + j=a->data[len-1]; + if (j & 0x80) bits=1; + else if (j & 0x40) bits=2; + else if (j & 0x20) bits=3; + else if (j & 0x10) bits=4; + else if (j & 0x08) bits=5; + else if (j & 0x04) bits=6; + else if (j & 0x02) bits=7; + else if (j & 0x01) bits=8; + else bits=0; + } + } + else + bits=0; + ret=1+len; + r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING); + if (pp == NULL) return(r); + p= *pp; + + ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL); + if (bits == 0) + j=0; + else j=8-bits; + *(p++)=(unsigned char)j; + d=a->data; + memcpy(p,d,len); + p+=len; + if (len > 0) p[-1]&=(0xff<<j); + *pp=p; + return(r); + } + +ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(a, pp, length) +ASN1_BIT_STRING **a; +unsigned char **pp; +long length; + { + ASN1_BIT_STRING *ret=NULL; + unsigned char *p,*s; + long len; + int inf,tag,xclass; + int i; + + if ((a == NULL) || ((*a) == NULL)) + { + if ((ret=ASN1_BIT_STRING_new()) == NULL) return(NULL); + } + else + ret=(*a); + + p= *pp; + inf=ASN1_get_object(&p,&len,&tag,&xclass,length); + if (inf & 0x80) + { + i=ASN1_R_BAD_OBJECT_HEADER; + goto err; + } + + if (tag != V_ASN1_BIT_STRING) + { + i=ASN1_R_EXPECTING_A_BIT_STRING; + goto err; + } + if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; } + + i= *(p++); + ret->flag&= ~(ASN1_FG_BITS_LEFT|0x07); /* clear */ + if (i > 0) + ret->flag|=(ASN1_FG_BITS_LEFT|(i&0x07)); /* set */ + + if (len-- > 1) /* using one because of the bits left byte */ + { + s=(unsigned char *)Malloc((int)len); + if (s == NULL) + { + i=ERR_R_MALLOC_FAILURE; + goto err; + } + memcpy(s,p,(int)len); + s[len-1]&=(0xff<<i); + p+=len; + } + else + s=NULL; + + ret->length=(int)len; + if (ret->data != NULL) Free((char *)ret->data); + ret->data=s; + ret->type=V_ASN1_BIT_STRING; + if (a != NULL) (*a)=ret; + *pp=p; + return(ret); +err: + ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) + ASN1_BIT_STRING_free(ret); + return(NULL); + } + +/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> + */ +int ASN1_BIT_STRING_set_bit(a,n,value) +ASN1_BIT_STRING *a; +int n; +int value; + { + int w,v,iv; + unsigned char *c; + + w=n/8; + v=1<<(7-(n&0x07)); + iv= ~v; + + a->flag&= ~(ASN1_FG_BITS_LEFT|0x07); /* clear, set on write */ + + if (a == NULL) return(0); + if ((a->length < (w+1)) || (a->data == NULL)) + { + if (!value) return(1); /* Don't need to set */ + if (a->data == NULL) + c=(unsigned char *)Malloc(w+1); + else + c=(unsigned char *)Realloc(a->data,w+1); + if (c == NULL) return(0); + a->data=c; + a->length=w+1; + c[w]=0; + } + a->data[w]=((a->data[w])&iv)|v; + while ((a->length > 0) && (a->data[a->length-1] == 0)) + a->length--; + return(1); + } + +int ASN1_BIT_STRING_get_bit(a,n) +ASN1_BIT_STRING *a; +int n; + { + int w,v; + + w=n/8; + v=1<<(7-(n&0x07)); + if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL)) + return(0); + return((a->data[w]&v) != 0); + } + diff --git a/crypto/asn1/a_bmp.c b/crypto/asn1/a_bmp.c index 774502b1fc..76a6f1cd66 100644 --- a/crypto/asn1/a_bmp.c +++ b/crypto/asn1/a_bmp.c @@ -79,10 +79,10 @@ long length; ASN1_BMPSTRING *ret=NULL; ret=(ASN1_BMPSTRING *)d2i_ASN1_bytes((ASN1_STRING **)a, - pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); + pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); if (ret == NULL) { - ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ERR_R_NESTED_ASN1_ERROR); return(NULL); } return(ret); diff --git a/crypto/asn1/a_bytes.c b/crypto/asn1/a_bytes.c index 14168d61ad..6bfa983349 100644 --- a/crypto/asn1/a_bytes.c +++ b/crypto/asn1/a_bytes.c @@ -60,9 +60,7 @@ #include "cryptlib.h" #include "asn1_mac.h" -/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE); +/* ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE); * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG); */ diff --git a/crypto/asn1/a_hdr.c b/crypto/asn1/a_hdr.c index 4fb7a5fa75..e9de2838d0 100644 --- a/crypto/asn1/a_hdr.c +++ b/crypto/asn1/a_hdr.c @@ -62,10 +62,10 @@ #include "asn1.h" /* - * ASN1err(ASN1_F_D2I_ASN1_HEADER,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT); - * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT); - * ASN1err(ASN1_F_ASN1_HEADER_NEW,ASN1_R_BAD_GET_OBJECT); + * ASN1err(ASN1_F_D2I_ASN1_HEADER,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_ASN1_HEADER,ERR_R_BAD_GET_ASN1_OBJECT_CALL); + * ASN1err(ASN1_F_I2D_ASN1_HEADER,ERR_R_BAD_GET_ASN1_OBJECT_CALL); + * ASN1err(ASN1_F_ASN1_HEADER_NEW,ERR_R_BAD_GET_ASN1_OBJECT_CALL); */ int i2d_ASN1_HEADER(a,pp) @@ -110,6 +110,7 @@ long length; ASN1_HEADER *ASN1_HEADER_new() { ASN1_HEADER *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,ASN1_HEADER); M_ASN1_New(ret->header,ASN1_OCTET_STRING_new); diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c index df79cf99bb..e847efee85 100644 --- a/crypto/asn1/a_int.c +++ b/crypto/asn1/a_int.c @@ -279,7 +279,7 @@ ASN1_INTEGER *ai; ret=ai; if (ret == NULL) { - ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); goto err; } ret->type=V_ASN1_INTEGER; diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c index 5a7eeef8d8..a476960d9a 100644 --- a/crypto/asn1/a_object.c +++ b/crypto/asn1/a_object.c @@ -382,8 +382,8 @@ char *sn,*ln; o.data=data; o.nid=nid; o.length=len; - o.flags=ASN1_OBJECT_FLAG_DYNAMIC| - ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA; + o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| + ASN1_OBJECT_FLAG_DYNAMIC_DATA; return(OBJ_dup(&o)); } diff --git a/crypto/asn1/a_octet.c b/crypto/asn1/a_octet.c index be3f172a8c..5954c7bee0 100644 --- a/crypto/asn1/a_octet.c +++ b/crypto/asn1/a_octet.c @@ -82,7 +82,7 @@ long length; pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL); if (ret == NULL) { - ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ERR_R_NESTED_ASN1_ERROR); return(NULL); } return(ret); diff --git a/crypto/asn1/a_set.c b/crypto/asn1/a_set.c index 17c49946cf..7fd4807e52 100644 --- a/crypto/asn1/a_set.c +++ b/crypto/asn1/a_set.c @@ -89,11 +89,12 @@ int ex_class; return(r); } -STACK *d2i_ASN1_SET(a,pp,length,func,ex_tag,ex_class) +STACK *d2i_ASN1_SET(a,pp,length,func,free_func,ex_tag,ex_class) STACK **a; unsigned char **pp; long length; char *(*func)(); +void (*free_func)(); int ex_tag; int ex_class; { @@ -136,14 +137,25 @@ int ex_class; char *s; if (M_ASN1_D2I_end_sequence()) break; - if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) goto err; + if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) + { + ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT); + asn1_add_error(*pp,(int)(c.q- *pp)); + goto err; + } if (!sk_push(ret,s)) goto err; } if (a != NULL) (*a)=ret; *pp=c.p; return(ret); err: - if ((ret != NULL) && ((a == NULL) || (*a != ret))) sk_free(ret); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) + { + if (free_func != NULL) + sk_pop_free(ret,free_func); + else + sk_free(ret); + } return(NULL); } diff --git a/crypto/asn1/a_sign.c b/crypto/asn1/a_sign.c index 02188e68c4..c2ff9783ac 100644 --- a/crypto/asn1/a_sign.c +++ b/crypto/asn1/a_sign.c @@ -136,7 +136,11 @@ EVP_MD *type; signature->data=buf_out; buf_out=NULL; signature->length=outl; - + /* In the interests of compatability, I'll make sure that + * the bit string has a 'not-used bits' value of 0 + */ + signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); + signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; err: memset(&ctx,0,sizeof(ctx)); if (buf_in != NULL) diff --git a/crypto/asn1/a_type.c b/crypto/asn1/a_type.c index 7c0004084c..7ddf5f9917 100644 --- a/crypto/asn1/a_type.c +++ b/crypto/asn1/a_type.c @@ -60,9 +60,7 @@ #include "cryptlib.h" #include "asn1_mac.h" -/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_WRONG_TAG); +/* ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_WRONG_TAG); * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG); */ @@ -252,6 +250,7 @@ err: ASN1_TYPE *ASN1_TYPE_new() { ASN1_TYPE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,ASN1_TYPE); ret->type= -1; @@ -304,14 +303,20 @@ ASN1_TYPE *a; case V_ASN1_NEG_INTEGER: case V_ASN1_BIT_STRING: case V_ASN1_OCTET_STRING: + case V_ASN1_SEQUENCE: + case V_ASN1_SET: + case V_ASN1_NUMERICSTRING: case V_ASN1_PRINTABLESTRING: case V_ASN1_T61STRING: + case V_ASN1_VIDEOTEXSTRING: case V_ASN1_IA5STRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_GENERALSTRING: case V_ASN1_UTCTIME: - case V_ASN1_SET: - case V_ASN1_SEQUENCE: + case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GRAPHICSTRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_BMPSTRING: ASN1_STRING_free((ASN1_STRING *)a->value.ptr); break; default: diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c index 17a7abbb67..ddd1a4016b 100644 --- a/crypto/asn1/a_utctm.c +++ b/crypto/asn1/a_utctm.c @@ -85,7 +85,7 @@ long length; V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); if (ret == NULL) { - ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); return(NULL); } if (!ASN1_UTCTIME_check(ret)) @@ -180,7 +180,7 @@ time_t t; { char *p; struct tm *ts; -#if defined(THREADS) +#if defined(THREADS) && !defined(WIN32) struct tm data; #endif @@ -189,7 +189,7 @@ time_t t; if (s == NULL) return(NULL); -#if defined(THREADS) +#if defined(THREADS) && !defined(WIN32) ts=(struct tm *)gmtime_r(&t,&data); #else ts=(struct tm *)gmtime(&t); diff --git a/crypto/asn1/asn1.err b/crypto/asn1/asn1.err index c8b7011488..1f5af96941 100644 --- a/crypto/asn1/asn1.err +++ b/crypto/asn1/asn1.err @@ -126,57 +126,53 @@ /* Reason codes. */ #define ASN1_R_BAD_CLASS 100 -#define ASN1_R_BAD_GET_OBJECT 101 -#define ASN1_R_BAD_OBJECT_HEADER 102 -#define ASN1_R_BAD_PASSWORD_READ 103 -#define ASN1_R_BAD_PKCS7_CONTENT 104 -#define ASN1_R_BAD_PKCS7_TYPE 105 -#define ASN1_R_BAD_TAG 106 -#define ASN1_R_BAD_TYPE 107 -#define ASN1_R_BN_LIB 108 -#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 -#define ASN1_R_BUFFER_TOO_SMALL 110 -#define ASN1_R_DATA_IS_WRONG 111 -#define ASN1_R_DECODING_ERROR 112 -#define ASN1_R_ERROR_STACK 113 -#define ASN1_R_EXPECTING_AN_INTEGER 114 -#define ASN1_R_EXPECTING_AN_OBJECT 115 -#define ASN1_R_EXPECTING_AN_OCTET_STRING 116 -#define ASN1_R_EXPECTING_A_BIT_STRING 117 -#define ASN1_R_EXPECTING_A_BOOLEAN 118 -#define ASN1_R_EXPECTING_A_SEQUENCE 119 -#define ASN1_R_EXPECTING_A_UTCTIME 120 -#define ASN1_R_FIRST_NUM_TOO_LARGE 121 -#define ASN1_R_HEADER_TOO_LONG 122 -#define ASN1_R_INVALID_DIGIT 123 -#define ASN1_R_INVALID_SEPARATOR 124 -#define ASN1_R_INVALID_TIME_FORMAT 125 -#define ASN1_R_IV_TOO_LARGE 126 -#define ASN1_R_LENGTH_ERROR 127 -#define ASN1_R_LENGTH_MISMATCH 128 -#define ASN1_R_MISSING_EOS 129 -#define ASN1_R_MISSING_SECOND_NUMBER 130 -#define ASN1_R_NON_HEX_CHARACTERS 131 -#define ASN1_R_NOT_ENOUGH_DATA 132 -#define ASN1_R_ODD_NUMBER_OF_CHARS 133 -#define ASN1_R_PARSING 134 -#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 -#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 -#define ASN1_R_SHORT_LINE 137 -#define ASN1_R_STRING_TOO_SHORT 138 -#define ASN1_R_TAG_VALUE_TOO_HIGH 139 -#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 -#define ASN1_R_TOO_LONG 141 -#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 -#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 -#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 -#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 -#define ASN1_R_UNKNOWN_OBJECT_TYPE 146 -#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 -#define ASN1_R_UNSUPPORTED_CIPHER 148 -#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 -#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 -#define ASN1_R_UTCTIME_TOO_LONG 151 -#define ASN1_R_WRONG_PRINTABLE_TYPE 152 -#define ASN1_R_WRONG_TAG 153 -#define ASN1_R_WRONG_TYPE 154 +#define ASN1_R_BAD_OBJECT_HEADER 101 +#define ASN1_R_BAD_PASSWORD_READ 102 +#define ASN1_R_BAD_PKCS7_CONTENT 103 +#define ASN1_R_BAD_PKCS7_TYPE 104 +#define ASN1_R_BAD_TAG 105 +#define ASN1_R_BAD_TYPE 106 +#define ASN1_R_BN_LIB 107 +#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108 +#define ASN1_R_BUFFER_TOO_SMALL 109 +#define ASN1_R_DATA_IS_WRONG 110 +#define ASN1_R_DECODING_ERROR 111 +#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112 +#define ASN1_R_EXPECTING_AN_INTEGER 113 +#define ASN1_R_EXPECTING_AN_OBJECT 114 +#define ASN1_R_EXPECTING_AN_OCTET_STRING 115 +#define ASN1_R_EXPECTING_A_BIT_STRING 116 +#define ASN1_R_EXPECTING_A_BOOLEAN 117 +#define ASN1_R_EXPECTING_A_UTCTIME 118 +#define ASN1_R_FIRST_NUM_TOO_LARGE 119 +#define ASN1_R_HEADER_TOO_LONG 120 +#define ASN1_R_INVALID_DIGIT 121 +#define ASN1_R_INVALID_SEPARATOR 122 +#define ASN1_R_INVALID_TIME_FORMAT 123 +#define ASN1_R_IV_TOO_LARGE 124 +#define ASN1_R_LENGTH_ERROR 125 +#define ASN1_R_MISSING_SECOND_NUMBER 126 +#define ASN1_R_NON_HEX_CHARACTERS 127 +#define ASN1_R_NOT_ENOUGH_DATA 128 +#define ASN1_R_ODD_NUMBER_OF_CHARS 129 +#define ASN1_R_PARSING 130 +#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131 +#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132 +#define ASN1_R_SHORT_LINE 133 +#define ASN1_R_STRING_TOO_SHORT 134 +#define ASN1_R_TAG_VALUE_TOO_HIGH 135 +#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136 +#define ASN1_R_TOO_LONG 137 +#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138 +#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139 +#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140 +#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141 +#define ASN1_R_UNKNOWN_OBJECT_TYPE 142 +#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143 +#define ASN1_R_UNSUPPORTED_CIPHER 144 +#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145 +#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146 +#define ASN1_R_UTCTIME_TOO_LONG 147 +#define ASN1_R_WRONG_PRINTABLE_TYPE 148 +#define ASN1_R_WRONG_TAG 149 +#define ASN1_R_WRONG_TYPE 150 diff --git a/crypto/asn1/asn1.h b/crypto/asn1/asn1.h index 9793db365d..0aa1ca043d 100644 --- a/crypto/asn1/asn1.h +++ b/crypto/asn1/asn1.h @@ -122,101 +122,6 @@ extern "C" { #define B_ASN1_BMPSTRING 0x0800 #define B_ASN1_UNKNOWN 0x1000 -#ifndef DEBUG - -#define ASN1_INTEGER ASN1_STRING -#define ASN1_BIT_STRING ASN1_STRING -#define ASN1_OCTET_STRING ASN1_STRING -#define ASN1_PRINTABLESTRING ASN1_STRING -#define ASN1_T61STRING ASN1_STRING -#define ASN1_IA5STRING ASN1_STRING -#define ASN1_UTCTIME ASN1_STRING -#define ASN1_GENERALIZEDTIME ASN1_STRING -#define ASN1_GENERALSTRING ASN1_STRING -#define ASN1_UNIVERSALSTRING ASN1_STRING -#define ASN1_BMPSTRING ASN1_STRING - -#else - -typedef struct asn1_integer_st - { - int length; - int type; - unsigned char *data; - } ASN1_INTEGER; - -typedef struct asn1_bit_string_st - { - int length; - int type; - unsigned char *data; - } ASN1_BIT_STRING; - -typedef struct asn1_octet_string_st - { - int length; - int type; - unsigned char *data; - } ASN1_OCTET_STRING; - -typedef struct asn1_printablestring_st - { - int length; - int type; - unsigned char *data; - } ASN1_PRINTABLESTRING; - -typedef struct asn1_t61string_st - { - int length; - int type; - unsigned char *data; - } ASN1_T61STRING; - -typedef struct asn1_ia5string_st - { - int length; - int type; - unsigned char *data; - } ASN1_IA5STRING; - -typedef struct asn1_generalstring_st - { - int length; - int type; - unsigned char *data; - } ASN1_GENERALSTRING; - -typedef struct asn1_universalstring_st - { - int length; - int type; - unsigned char *data; - } ASN1_UNIVERSALSTRING; - -typedef struct asn1_bmpstring_st - { - int length; - int type; - unsigned char *data; - } ASN1_BMPSTRING; - -typedef struct asn1_utctime_st - { - int length; - int type; - unsigned char *data; - } ASN1_UTCTIME; - -typedef struct asn1_generalizedtime_st - { - int length; - int type; - unsigned char *data; - } ASN1_GENERALIZEDTIME; - -#endif - typedef struct asn1_ctx_st { unsigned char *p;/* work char pointer */ @@ -229,6 +134,7 @@ typedef struct asn1_ctx_st unsigned char *max; /* largest value of p alowed */ unsigned char *q;/* temporary variable */ unsigned char **pp;/* variable */ + int line; /* used in error processing */ } ASN1_CTX; /* These are used internally in the ASN1_OBJECT to keep track of @@ -246,14 +152,46 @@ typedef struct asn1_object_st int flags; /* Should we free this one */ } ASN1_OBJECT; +#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ /* This is the base type that holds just about everything :-) */ typedef struct asn1_string_st { int length; int type; unsigned char *data; + /* The value of the following field depends on the type being + * held. It is mostly being used for BIT_STRING so if the + * input data has a non-zero 'unused bits' value, it will be + * handled correctly */ + long flags; } ASN1_STRING; +#ifndef DEBUG +#define ASN1_INTEGER ASN1_STRING +#define ASN1_BIT_STRING ASN1_STRING +#define ASN1_OCTET_STRING ASN1_STRING +#define ASN1_PRINTABLESTRING ASN1_STRING +#define ASN1_T61STRING ASN1_STRING +#define ASN1_IA5STRING ASN1_STRING +#define ASN1_UTCTIME ASN1_STRING +#define ASN1_GENERALIZEDTIME ASN1_STRING +#define ASN1_GENERALSTRING ASN1_STRING +#define ASN1_UNIVERSALSTRING ASN1_STRING +#define ASN1_BMPSTRING ASN1_STRING +#else +typedef struct asn1_string_st ASN1_INTEGER; +typedef struct asn1_string_st ASN1_BIT_STRING; +typedef struct asn1_string_st ASN1_OCTET_STRING; +typedef struct asn1_string_st ASN1_PRINTABLESTRING; +typedef struct asn1_string_st ASN1_T61STRING; +typedef struct asn1_string_st ASN1_IA5STRING; +typedef struct asn1_string_st ASN1_GENERALSTRING; +typedef struct asn1_string_st ASN1_UNIVERSALSTRING; +typedef struct asn1_string_st ASN1_BMPSTRING; +typedef struct asn1_string_st ASN1_UTCTIME; +typedef struct asn1_string_st ASN1_GENERALIZEDTIME; +#endif + typedef struct asn1_type_st { int type; @@ -472,6 +410,10 @@ int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp); ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, unsigned char **pp,long length); +int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp); +ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp, + long length); + int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp); ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, unsigned char **pp, long l); @@ -491,7 +433,8 @@ ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp, int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag, int ex_class); STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length, - char *(*func)(), int ex_tag, int ex_class); + char *(*func)(), void (*free_func)(), + int ex_tag, int ex_class); #ifdef HEADER_BIO_H int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); @@ -666,6 +609,9 @@ int ASN1_TYPE_get_octetstring(); int ASN1_TYPE_set_int_octetstring(); int ASN1_TYPE_get_int_octetstring(); +int i2d_ASN1_BMPSTRING(); +ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(); + #endif /* BEGIN ERROR CODES */ @@ -797,60 +743,56 @@ int ASN1_TYPE_get_int_octetstring(); /* Reason codes. */ #define ASN1_R_BAD_CLASS 100 -#define ASN1_R_BAD_GET_OBJECT 101 -#define ASN1_R_BAD_OBJECT_HEADER 102 -#define ASN1_R_BAD_PASSWORD_READ 103 -#define ASN1_R_BAD_PKCS7_CONTENT 104 -#define ASN1_R_BAD_PKCS7_TYPE 105 -#define ASN1_R_BAD_TAG 106 -#define ASN1_R_BAD_TYPE 107 -#define ASN1_R_BN_LIB 108 -#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 -#define ASN1_R_BUFFER_TOO_SMALL 110 -#define ASN1_R_DATA_IS_WRONG 111 -#define ASN1_R_DECODING_ERROR 112 -#define ASN1_R_ERROR_STACK 113 -#define ASN1_R_EXPECTING_AN_INTEGER 114 -#define ASN1_R_EXPECTING_AN_OBJECT 115 -#define ASN1_R_EXPECTING_AN_OCTET_STRING 116 -#define ASN1_R_EXPECTING_A_BIT_STRING 117 -#define ASN1_R_EXPECTING_A_BOOLEAN 118 -#define ASN1_R_EXPECTING_A_SEQUENCE 119 -#define ASN1_R_EXPECTING_A_UTCTIME 120 -#define ASN1_R_FIRST_NUM_TOO_LARGE 121 -#define ASN1_R_HEADER_TOO_LONG 122 -#define ASN1_R_INVALID_DIGIT 123 -#define ASN1_R_INVALID_SEPARATOR 124 -#define ASN1_R_INVALID_TIME_FORMAT 125 -#define ASN1_R_IV_TOO_LARGE 126 -#define ASN1_R_LENGTH_ERROR 127 -#define ASN1_R_LENGTH_MISMATCH 128 -#define ASN1_R_MISSING_EOS 129 -#define ASN1_R_MISSING_SECOND_NUMBER 130 -#define ASN1_R_NON_HEX_CHARACTERS 131 -#define ASN1_R_NOT_ENOUGH_DATA 132 -#define ASN1_R_ODD_NUMBER_OF_CHARS 133 -#define ASN1_R_PARSING 134 -#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 -#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 -#define ASN1_R_SHORT_LINE 137 -#define ASN1_R_STRING_TOO_SHORT 138 -#define ASN1_R_TAG_VALUE_TOO_HIGH 139 -#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 -#define ASN1_R_TOO_LONG 141 -#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 -#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 -#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 -#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 -#define ASN1_R_UNKNOWN_OBJECT_TYPE 146 -#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 -#define ASN1_R_UNSUPPORTED_CIPHER 148 -#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 -#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 -#define ASN1_R_UTCTIME_TOO_LONG 151 -#define ASN1_R_WRONG_PRINTABLE_TYPE 152 -#define ASN1_R_WRONG_TAG 153 -#define ASN1_R_WRONG_TYPE 154 +#define ASN1_R_BAD_OBJECT_HEADER 101 +#define ASN1_R_BAD_PASSWORD_READ 102 +#define ASN1_R_BAD_PKCS7_CONTENT 103 +#define ASN1_R_BAD_PKCS7_TYPE 104 +#define ASN1_R_BAD_TAG 105 +#define ASN1_R_BAD_TYPE 106 +#define ASN1_R_BN_LIB 107 +#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108 +#define ASN1_R_BUFFER_TOO_SMALL 109 +#define ASN1_R_DATA_IS_WRONG 110 +#define ASN1_R_DECODING_ERROR 111 +#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112 +#define ASN1_R_EXPECTING_AN_INTEGER 113 +#define ASN1_R_EXPECTING_AN_OBJECT 114 +#define ASN1_R_EXPECTING_AN_OCTET_STRING 115 +#define ASN1_R_EXPECTING_A_BIT_STRING 116 +#define ASN1_R_EXPECTING_A_BOOLEAN 117 +#define ASN1_R_EXPECTING_A_UTCTIME 118 +#define ASN1_R_FIRST_NUM_TOO_LARGE 119 +#define ASN1_R_HEADER_TOO_LONG 120 +#define ASN1_R_INVALID_DIGIT 121 +#define ASN1_R_INVALID_SEPARATOR 122 +#define ASN1_R_INVALID_TIME_FORMAT 123 +#define ASN1_R_IV_TOO_LARGE 124 +#define ASN1_R_LENGTH_ERROR 125 +#define ASN1_R_MISSING_SECOND_NUMBER 126 +#define ASN1_R_NON_HEX_CHARACTERS 127 +#define ASN1_R_NOT_ENOUGH_DATA 128 +#define ASN1_R_ODD_NUMBER_OF_CHARS 129 +#define ASN1_R_PARSING 130 +#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131 +#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132 +#define ASN1_R_SHORT_LINE 133 +#define ASN1_R_STRING_TOO_SHORT 134 +#define ASN1_R_TAG_VALUE_TOO_HIGH 135 +#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136 +#define ASN1_R_TOO_LONG 137 +#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138 +#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139 +#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140 +#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141 +#define ASN1_R_UNKNOWN_OBJECT_TYPE 142 +#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143 +#define ASN1_R_UNSUPPORTED_CIPHER 144 +#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145 +#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146 +#define ASN1_R_UTCTIME_TOO_LONG 147 +#define ASN1_R_WRONG_PRINTABLE_TYPE 148 +#define ASN1_R_WRONG_TAG 149 +#define ASN1_R_WRONG_TYPE 150 #ifdef __cplusplus } diff --git a/crypto/asn1/asn1_err.c b/crypto/asn1/asn1_err.c index 03c2858e7d..b7818f8477 100644 --- a/crypto/asn1/asn1_err.c +++ b/crypto/asn1/asn1_err.c @@ -87,7 +87,7 @@ static ERR_STRING_DATA ASN1_str_functs[]= {ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_VERIFY"}, {ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"}, -{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "D2I_ASN1_BMPSTRING"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"}, @@ -191,7 +191,6 @@ static ERR_STRING_DATA ASN1_str_functs[]= static ERR_STRING_DATA ASN1_str_reasons[]= { {ASN1_R_BAD_CLASS ,"bad class"}, -{ASN1_R_BAD_GET_OBJECT ,"bad get object"}, {ASN1_R_BAD_OBJECT_HEADER ,"bad object header"}, {ASN1_R_BAD_PASSWORD_READ ,"bad password read"}, {ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"}, @@ -203,13 +202,12 @@ static ERR_STRING_DATA ASN1_str_reasons[]= {ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"}, {ASN1_R_DATA_IS_WRONG ,"data is wrong"}, {ASN1_R_DECODING_ERROR ,"decoding error"}, -{ASN1_R_ERROR_STACK ,"error stack"}, +{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"}, {ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"}, {ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"}, {ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"}, {ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"}, {ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"}, -{ASN1_R_EXPECTING_A_SEQUENCE ,"expecting a sequence"}, {ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"}, {ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"}, {ASN1_R_HEADER_TOO_LONG ,"header too long"}, @@ -218,8 +216,6 @@ static ERR_STRING_DATA ASN1_str_reasons[]= {ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"}, {ASN1_R_IV_TOO_LARGE ,"iv too large"}, {ASN1_R_LENGTH_ERROR ,"length error"}, -{ASN1_R_LENGTH_MISMATCH ,"length mismatch"}, -{ASN1_R_MISSING_EOS ,"missing eos"}, {ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"}, {ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"}, {ASN1_R_NOT_ENOUGH_DATA ,"not enough data"}, @@ -254,8 +250,8 @@ void ERR_load_ASN1_strings() { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs); diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index ff30b25836..bc34cc4fe0 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -69,7 +69,7 @@ static int asn1_get_length(); static void asn1_put_length(); #endif -char *ASN1_version="ASN1 part of SSLeay 0.9.0b 29-Jun-1998"; +char *ASN1_version="ASN1 part of SSLeay 0.9.1a 06-Jul-1998"; int ASN1_check_infinite_end(p,len) unsigned char **p; @@ -130,11 +130,13 @@ long omax; *pclass=xclass; if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; -#ifdef undef - fprintf(stderr,"p=%d + *plength=%d > omax=%d + *pp=%d (%d > %d)\n", - p,*plength,omax,*pp,(p+ *plength),omax+ *pp); +#if 0 + fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", + (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), + (int)(omax+ *pp)); #endif +#if 0 if ((p+ *plength) > (omax+ *pp)) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); @@ -142,8 +144,9 @@ long omax; * the values are set correctly */ ret|=0x80; } +#endif *pp=p; - return(ret+inf); + return(ret|inf); err: ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); return(0x80); @@ -284,14 +287,14 @@ ASN1_CTX *c; { if (!ASN1_check_infinite_end(&c->p,c->slen)) { - c->error=ASN1_R_MISSING_EOS; + c->error=ERR_R_MISSING_ASN1_EOS; return(0); } } if ( ((c->slen != 0) && !(c->inf & 1)) || ((c->slen < 0) && (c->inf & 1))) { - c->error=ASN1_R_LENGTH_MISMATCH; + c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } return(1); @@ -308,18 +311,18 @@ long *length; *length); if (c->inf & 0x80) { - c->error=ASN1_R_BAD_GET_OBJECT; + c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; return(0); } if (c->tag != V_ASN1_SEQUENCE) { - c->error=ASN1_R_EXPECTING_A_SEQUENCE; + c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; return(0); } (*length)-=(c->p-q); if (c->max && (*length < 0)) { - c->error=ASN1_R_LENGTH_MISMATCH; + c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } if (c->inf == (1|V_ASN1_CONSTRUCTED)) @@ -402,6 +405,7 @@ int type; ret->length=0; ret->type=type; ret->data=NULL; + ret->flags=0; return(ret); } diff --git a/crypto/asn1/asn1_mac.h b/crypto/asn1/asn1_mac.h index 4fba70e4bb..4e6115224c 100644 --- a/crypto/asn1/asn1_mac.h +++ b/crypto/asn1/asn1_mac.h @@ -67,14 +67,23 @@ extern "C" { #include "x509.h" #include "pkcs7.h" +#ifndef ASN1_MAC_ERR_LIB +#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 +#endif + +#define ASN1_MAC_H_err(f,r,line) \ + ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),ERR_file_name,(line)) + #define M_ASN1_D2I_vars(a,type,func) \ ASN1_CTX c; \ type ret=NULL; \ \ c.pp=pp; \ - c.error=ASN1_R_ERROR_STACK; \ + c.q= *pp; \ + c.error=ERR_R_NESTED_ASN1_ERROR; \ if ((a == NULL) || ((*a) == NULL)) \ - { if ((ret=(type)func()) == NULL) goto err; } \ + { if ((ret=(type)func()) == NULL) \ + { c.line=__LINE__; goto err; } } \ else ret=(*a); #define M_ASN1_D2I_Init() \ @@ -82,7 +91,8 @@ extern "C" { c.max=(length == 0)?0:(c.p+length); #define M_ASN1_D2I_Finish_2(a) \ - if (!asn1_Finish(&c)) goto err; \ + if (!asn1_Finish(&c)) \ + { c.line=__LINE__; goto err; } \ *pp=c.p; \ if (a != NULL) (*a)=ret; \ return(ret); @@ -90,21 +100,31 @@ extern "C" { #define M_ASN1_D2I_Finish(a,func,e) \ M_ASN1_D2I_Finish_2(a); \ err:\ - ASN1err((e),c.error); \ + ASN1_MAC_H_err((e),c.error,c.line); \ asn1_add_error(*pp,(int)(c.q- *pp)); \ if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ return(NULL) #define M_ASN1_D2I_start_sequence() \ - if (!asn1_GetSequence(&c,&length)) goto err; + if (!asn1_GetSequence(&c,&length)) \ + { c.line=__LINE__; goto err; } #define M_ASN1_D2I_end_sequence() \ (((c.inf&1) == 0)?(c.slen <= 0): \ (c.eos=ASN1_check_infinite_end(&c.p,c.slen))) +/* Don't use this with d2i_ASN1_BOOLEAN() */ #define M_ASN1_D2I_get(b,func) \ c.q=c.p; \ - if (func(&(b),&c.p,c.slen) == NULL) goto err; \ + if (func(&(b),&c.p,c.slen) == NULL) \ + {c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +/* use this instead () */ +#define M_ASN1_D2I_get_int(b,func) \ + c.q=c.p; \ + if (func(&(b),&c.p,c.slen) < 0) \ + {c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); #define M_ASN1_D2I_get_opt(b,func,type) \ @@ -125,38 +145,56 @@ err:\ M_ASN1_next_prev=tmp; \ } -#define M_ASN1_D2I_get_set(r,func) \ - M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SET,V_ASN1_UNIVERSAL); +#define M_ASN1_D2I_get_set(r,func,free_func) \ + M_ASN1_D2I_get_imp_set(r,func,free_func, \ + V_ASN1_SET,V_ASN1_UNIVERSAL); + +#define M_ASN1_D2I_get_set_opt(r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ + { M_ASN1_D2I_get_set(r,func,free_func); } + +#define M_ASN1_I2D_len_SET_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_len_SET(a,f); + +#define M_ASN1_I2D_put_SET_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_put_SET(a,f); -#define M_ASN1_D2I_get_IMP_set_opt(b,func,tag) \ +#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \ if ((c.slen != 0) && \ (M_ASN1_next == \ (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ { \ - M_ASN1_D2I_get_imp_set(b,func,tag,V_ASN1_CONTEXT_SPECIFIC); \ + M_ASN1_D2I_get_imp_set(b,func,free_func,\ + tag,V_ASN1_CONTEXT_SPECIFIC); \ } -#define M_ASN1_D2I_get_seq(r,func) \ - M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); +#define M_ASN1_D2I_get_seq(r,func,free_func) \ + M_ASN1_D2I_get_imp_set(r,func,free_func,\ + V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); -#define M_ASN1_D2I_get_seq_opt(r,func) \ +#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ - { M_ASN1_D2I_get_seq(r,func); } + { M_ASN1_D2I_get_seq(r,func,free_func); } -#define M_ASN1_D2I_get_IMP_set(r,func,x) \ - M_ASN1_D2I_get_imp_set(r,func,x,V_ASN1_CONTEXT_SPECIFIC); +#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ + M_ASN1_D2I_get_imp_set(r,func,free_func,\ + x,V_ASN1_CONTEXT_SPECIFIC); -#define M_ASN1_D2I_get_imp_set(r,func,a,b) \ +#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ c.q=c.p; \ - if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,a,b) == NULL) \ - goto err; \ + if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ + (void (*)())free_func,a,b) == NULL) \ + { c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); #define M_ASN1_D2I_get_set_strings(r,func,a,b) \ c.q=c.p; \ if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ - goto err; \ + { c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ @@ -169,13 +207,14 @@ err:\ c.q=c.p; \ Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ if (Tinf & 0x80) \ - { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ if (func(&(r),&c.p,Tlen) == NULL) \ - goto err; \ + { c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); \ } -#define M_ASN1_D2I_get_EXP_set_opt(r,func,tag,b) \ +#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ if ((c.slen != 0) && (M_ASN1_next == \ (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ { \ @@ -185,24 +224,27 @@ err:\ c.q=c.p; \ Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ if (Tinf & 0x80) \ - { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ + (void (*)())free_func, \ b,V_ASN1_UNIVERSAL) == NULL) \ - goto err; \ + { c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); \ } /* New macros */ #define M_ASN1_New_Malloc(ret,type) \ - if ((ret=(type *)Malloc(sizeof(type))) == NULL) goto err2; + if ((ret=(type *)Malloc(sizeof(type))) == NULL) \ + { c.line=__LINE__; goto err2; } #define M_ASN1_New(arg,func) \ if (((arg)=func()) == NULL) return(NULL) #define M_ASN1_New_Error(a) \ -/* err: ASN1err((a),ASN1_R_ERROR_STACK); \ +/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ return(NULL);*/ \ - err2: ASN1err((a),ERR_R_MALLOC_FAILURE); \ + err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ return(NULL) diff --git a/crypto/asn1/asn1_par.c b/crypto/asn1/asn1_par.c index 3906227d21..af71b1a85d 100644 --- a/crypto/asn1/asn1_par.c +++ b/crypto/asn1/asn1_par.c @@ -266,7 +266,8 @@ int indent; if ( (tag == V_ASN1_PRINTABLESTRING) || (tag == V_ASN1_T61STRING) || (tag == V_ASN1_IA5STRING) || - (tag == V_ASN1_UTCTIME)) + (tag == V_ASN1_UTCTIME) || + (tag == V_ASN1_GENERALIZEDTIME)) { if (BIO_write(bp,":",1) <= 0) goto end; if ((len > 0) && diff --git a/crypto/asn1/d2i_dhp.c b/crypto/asn1/d2i_dhp.c index 616a308100..f2236fc2e2 100644 --- a/crypto/asn1/d2i_dhp.c +++ b/crypto/asn1/d2i_dhp.c @@ -64,7 +64,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_DHPARAMS,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_DHPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ @@ -73,7 +73,7 @@ DH **a; unsigned char **pp; long length; { - int i=ASN1_R_ERROR_STACK; + int i=ERR_R_NESTED_ASN1_ERROR; ASN1_INTEGER *bs=NULL; long v=0; M_ASN1_D2I_vars(a,DH *,DH_new); diff --git a/crypto/asn1/d2i_dsap.c b/crypto/asn1/d2i_dsap.c index 2c8ac7bbcf..fc2961b3a4 100644 --- a/crypto/asn1/d2i_dsap.c +++ b/crypto/asn1/d2i_dsap.c @@ -64,7 +64,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_DSAPARAMS,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_DSAPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ @@ -73,7 +73,7 @@ DSA **a; unsigned char **pp; long length; { - int i=ASN1_R_ERROR_STACK; + int i=ERR_R_NESTED_ASN1_ERROR; ASN1_INTEGER *bs=NULL; M_ASN1_D2I_vars(a,DSA *,DSA_new); diff --git a/crypto/asn1/d2i_pr.c b/crypto/asn1/d2i_pr.c index b9eaa9629b..677403564b 100644 --- a/crypto/asn1/d2i_pr.c +++ b/crypto/asn1/d2i_pr.c @@ -106,7 +106,7 @@ long length; default: ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); goto err; - break; + /* break; */ } if (a != NULL) (*a)=ret; return(ret); diff --git a/crypto/asn1/d2i_pu.c b/crypto/asn1/d2i_pu.c index 5d6192f1e5..eb572acb0f 100644 --- a/crypto/asn1/d2i_pu.c +++ b/crypto/asn1/d2i_pu.c @@ -106,7 +106,7 @@ long length; default: ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); goto err; - break; + /* break; */ } if (a != NULL) (*a)=ret; return(ret); diff --git a/crypto/asn1/d2i_r_pr.c b/crypto/asn1/d2i_r_pr.c index 0c53aa94bf..a276a1d4c5 100644 --- a/crypto/asn1/d2i_r_pr.c +++ b/crypto/asn1/d2i_r_pr.c @@ -64,7 +64,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_PARSING); */ diff --git a/crypto/asn1/d2i_r_pu.c b/crypto/asn1/d2i_r_pu.c index 778b792b1e..a4e2c22f36 100644 --- a/crypto/asn1/d2i_r_pu.c +++ b/crypto/asn1/d2i_r_pu.c @@ -64,7 +64,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ diff --git a/crypto/asn1/d2i_s_pr.c b/crypto/asn1/d2i_s_pr.c index 32ff8ba4b3..8499702c9c 100644 --- a/crypto/asn1/d2i_s_pr.c +++ b/crypto/asn1/d2i_s_pr.c @@ -66,7 +66,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_PARSING); */ diff --git a/crypto/asn1/d2i_s_pu.c b/crypto/asn1/d2i_s_pu.c index 1002f41cd8..ecf6407eab 100644 --- a/crypto/asn1/d2i_s_pu.c +++ b/crypto/asn1/d2i_s_pu.c @@ -66,7 +66,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_DSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_DSAPUBLICKEY,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ diff --git a/crypto/asn1/evp_asn1.c b/crypto/asn1/evp_asn1.c index ebe34a3362..4153d1b57f 100644 --- a/crypto/asn1/evp_asn1.c +++ b/crypto/asn1/evp_asn1.c @@ -135,7 +135,8 @@ int len; return(1); } -/* we return the actual length... */ +/* we return the actual length..., num may be missing, in which + * case, set it to zero */ int ASN1_TYPE_get_int_octetstring(a,num,data,max_len) ASN1_TYPE *a; long *num; diff --git a/crypto/asn1/i2d_dhp.c b/crypto/asn1/i2d_dhp.c index a454025ce3..a1afa46c86 100644 --- a/crypto/asn1/i2d_dhp.c +++ b/crypto/asn1/i2d_dhp.c @@ -63,8 +63,8 @@ #include "dh.h" /* - * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_DHPARAMS_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_DHPARAMS,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_DHPARAMS_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_DHparams(a,pp) diff --git a/crypto/asn1/i2d_dsap.c b/crypto/asn1/i2d_dsap.c index 94ecff1525..0b7d5543f3 100644 --- a/crypto/asn1/i2d_dsap.c +++ b/crypto/asn1/i2d_dsap.c @@ -63,7 +63,7 @@ #include "dsa.h" /* - * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_DSAPARAMS,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_DSAparams(a,pp) diff --git a/crypto/asn1/i2d_r_pr.c b/crypto/asn1/i2d_r_pr.c index aadbb92d8e..78312dbf2f 100644 --- a/crypto/asn1/i2d_r_pr.c +++ b/crypto/asn1/i2d_r_pr.c @@ -64,7 +64,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ diff --git a/crypto/asn1/i2d_r_pu.c b/crypto/asn1/i2d_r_pu.c index 3c54f6709d..4bcebaa1ba 100644 --- a/crypto/asn1/i2d_r_pu.c +++ b/crypto/asn1/i2d_r_pu.c @@ -64,7 +64,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ diff --git a/crypto/asn1/n_pkey.c b/crypto/asn1/n_pkey.c index 5110c91bec..9649847866 100644 --- a/crypto/asn1/n_pkey.c +++ b/crypto/asn1/n_pkey.c @@ -75,7 +75,7 @@ typedef struct netscape_pkey_st } NETSCAPE_PKEY; /* - * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR); * ASN1err(ASN1_F_D2I_NETSCAPE_PKEY,ASN1_R_DECODING_ERROR); * ASN1err(ASN1_F_NETSCAPE_PKEY_NEW,ASN1_R_DECODING_ERROR); @@ -249,7 +249,7 @@ int (*cb)(); ASN1_OCTET_STRING *os=NULL; ASN1_CTX c; - c.error=ASN1_R_ERROR_STACK; + c.error=ERR_R_NESTED_ASN1_ERROR; c.pp=pp; M_ASN1_D2I_Init(); @@ -342,6 +342,7 @@ long length; static NETSCAPE_PKEY *NETSCAPE_PKEY_new() { NETSCAPE_PKEY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,NETSCAPE_PKEY); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/p7_dgst.c b/crypto/asn1/p7_dgst.c index f71ed8eb1d..bf7b8e2f43 100644 --- a/crypto/asn1/p7_dgst.c +++ b/crypto/asn1/p7_dgst.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_DIGEST_NEW,ASN1_R_MISSING_EOS); - * ASN1err(ASN1_F_D2I_PKCS7_DIGEST,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_DIGEST_NEW,ERR_R_MISSING_ASN1_EOS); + * ASN1err(ASN1_F_D2I_PKCS7_DIGEST,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_DIGEST(a,pp) @@ -107,6 +107,7 @@ long length; PKCS7_DIGEST *PKCS7_DIGEST_new() { PKCS7_DIGEST *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_DIGEST); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/p7_enc.c b/crypto/asn1/p7_enc.c index 874dd78389..56e27fa112 100644 --- a/crypto/asn1/p7_enc.c +++ b/crypto/asn1/p7_enc.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_ENCRYPT_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ENCRYPT,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_ENCRYPT_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ENCRYPT,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_ENCRYPT(a,pp) @@ -101,6 +101,7 @@ long length; PKCS7_ENCRYPT *PKCS7_ENCRYPT_new() { PKCS7_ENCRYPT *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/p7_enc_c.c b/crypto/asn1/p7_enc_c.c index 2860d3e925..f98afb51b8 100644 --- a/crypto/asn1/p7_enc_c.c +++ b/crypto/asn1/p7_enc_c.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_ENC_CONTENT_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ENC_CONTENT,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_ENC_CONTENT_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ENC_CONTENT,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_ENC_CONTENT(a,pp) @@ -106,9 +106,11 @@ long length; PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new() { PKCS7_ENC_CONTENT *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT); - M_ASN1_New(ret->content_type,ASN1_OBJECT_new); + /* M_ASN1_New(ret->content_type,ASN1_OBJECT_new); */ + ret->content_type=OBJ_nid2obj(NID_pkcs7_encrypted); M_ASN1_New(ret->algorithm,X509_ALGOR_new); ret->enc_data=NULL; return(ret); diff --git a/crypto/asn1/p7_evp.c b/crypto/asn1/p7_evp.c index 4db0a7fe62..7879a66848 100644 --- a/crypto/asn1/p7_evp.c +++ b/crypto/asn1/p7_evp.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ENVELOPE,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_ENVELOPE_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ENVELOPE,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_ENVELOPE(a,pp) @@ -95,7 +95,8 @@ long length; M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); - M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); + M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO, + PKCS7_RECIP_INFO_free); M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); M_ASN1_D2I_Finish(a,PKCS7_ENVELOPE_free,ASN1_F_D2I_PKCS7_ENVELOPE); @@ -104,6 +105,7 @@ long length; PKCS7_ENVELOPE *PKCS7_ENVELOPE_new() { PKCS7_ENVELOPE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/p7_i_s.c b/crypto/asn1/p7_i_s.c index 9b00c556d9..9bae647feb 100644 --- a/crypto/asn1/p7_i_s.c +++ b/crypto/asn1/p7_i_s.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_ISSUER_AND_SERIAL(a,pp) @@ -101,6 +101,7 @@ long length; PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new() { PKCS7_ISSUER_AND_SERIAL *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL); M_ASN1_New(ret->issuer,X509_NAME_new); diff --git a/crypto/asn1/p7_lib.c b/crypto/asn1/p7_lib.c index 2134e0974a..06e1da4a74 100644 --- a/crypto/asn1/p7_lib.c +++ b/crypto/asn1/p7_lib.c @@ -179,6 +179,7 @@ long length; V_ASN1_CONTEXT_SPECIFIC|0)) { c.error=ASN1_R_BAD_PKCS7_CONTENT; + c.line=__LINE__; goto err; } @@ -187,7 +188,7 @@ long length; c.q=c.p; Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass, (c.inf & 1)?(length+ *pp-c.q):c.slen); - if (Tinf & 0x80) goto err; + if (Tinf & 0x80) { c.line=__LINE__; goto err; } c.slen-=(c.p-c.q); switch (OBJ_obj2nid(ret->type)) @@ -215,14 +216,16 @@ long length; break; default: c.error=ASN1_R_BAD_PKCS7_TYPE; + c.line=__LINE__; goto err; - break; + /* break; */ } if (Tinf == (1|V_ASN1_CONSTRUCTED)) { if (!ASN1_check_infinite_end(&c.p,c.slen)) { - c.error=ASN1_R_MISSING_EOS; + c.error=ERR_R_MISSING_ASN1_EOS; + c.line=__LINE__; goto err; } } @@ -236,9 +239,10 @@ long length; PKCS7 *PKCS7_new() { PKCS7 *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7); - ret->type=ASN1_OBJECT_new(); + ret->type=OBJ_nid2obj(NID_undef); ret->asn1=NULL; ret->length=0; ret->detached=0; diff --git a/crypto/asn1/p7_recip.c b/crypto/asn1/p7_recip.c index f02233f5a8..2516d7b193 100644 --- a/crypto/asn1/p7_recip.c +++ b/crypto/asn1/p7_recip.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_RECIP_INFO_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_RECIP_INFO,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_RECIP_INFO_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_RECIP_INFO,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_RECIP_INFO(a,pp) @@ -107,6 +107,7 @@ long length; PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new() { PKCS7_RECIP_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/p7_s_e.c b/crypto/asn1/p7_s_e.c index d344211456..0368bcbbcd 100644 --- a/crypto/asn1/p7_s_e.c +++ b/crypto/asn1/p7_s_e.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_SIGN_ENVELOPE(a,pp) @@ -103,12 +103,14 @@ long length; M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); - M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); - M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); + M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO, + PKCS7_RECIP_INFO_free); + M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR,X509_ALGOR_free); M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); - M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); - M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); - M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); + M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,X509_free,0); + M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,X509_CRL_free,1); + M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO, + PKCS7_SIGNER_INFO_free); M_ASN1_D2I_Finish(a,PKCS7_SIGN_ENVELOPE_free, ASN1_F_D2I_PKCS7_SIGN_ENVELOPE); @@ -117,6 +119,7 @@ long length; PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new() { PKCS7_SIGN_ENVELOPE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/p7_signd.c b/crypto/asn1/p7_signd.c index 40f9a44fa8..830617cbf8 100644 --- a/crypto/asn1/p7_signd.c +++ b/crypto/asn1/p7_signd.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_SIGNED_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_SIGNED,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_SIGNED_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_SIGNED,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_SIGNED(a,pp) @@ -101,11 +101,12 @@ long length; M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); - M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); + M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR,X509_ALGOR_free); M_ASN1_D2I_get(ret->contents,d2i_PKCS7); - M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); - M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); - M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); + M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,X509_free,0); + M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,X509_CRL_free,1); + M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO, + PKCS7_SIGNER_INFO_free); M_ASN1_D2I_Finish(a,PKCS7_SIGNED_free,ASN1_F_D2I_PKCS7_SIGNED); } @@ -113,6 +114,7 @@ long length; PKCS7_SIGNED *PKCS7_SIGNED_new() { PKCS7_SIGNED *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_SIGNED); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/p7_signi.c b/crypto/asn1/p7_signi.c index 0da92169fc..4bc415d572 100644 --- a/crypto/asn1/p7_signi.c +++ b/crypto/asn1/p7_signi.c @@ -62,8 +62,8 @@ #include "x509.h" /* - * ASN1err(ASN1_F_PKCS7_SIGNER_INFO_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_SIGNER_INFO,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_PKCS7_SIGNER_INFO_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_SIGNER_INFO,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_PKCS7_SIGNER_INFO(a,pp) @@ -105,10 +105,12 @@ long length; M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL); M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR); - M_ASN1_D2I_get_IMP_set_opt(ret->auth_attr,d2i_X509_ATTRIBUTE,0); + M_ASN1_D2I_get_IMP_set_opt(ret->auth_attr,d2i_X509_ATTRIBUTE, + X509_ATTRIBUTE_free,0); M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR); M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING); - M_ASN1_D2I_get_IMP_set_opt(ret->unauth_attr,d2i_X509_ATTRIBUTE,1); + M_ASN1_D2I_get_IMP_set_opt(ret->unauth_attr,d2i_X509_ATTRIBUTE, + X509_ATTRIBUTE_free,1); M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free, ASN1_F_D2I_PKCS7_SIGNER_INFO); @@ -117,6 +119,7 @@ long length; PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new() { PKCS7_SIGNER_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO); M_ASN1_New(ret->version,ASN1_INTEGER_new); diff --git a/crypto/asn1/pkcs8.c b/crypto/asn1/pkcs8.c index 03fdadd51a..d2bc9ce134 100644 --- a/crypto/asn1/pkcs8.c +++ b/crypto/asn1/pkcs8.c @@ -62,8 +62,8 @@ #include "objects.h" /* - * ASN1err(ASN1_F_D2I_X509_KEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_KEY_NEW,ASN1_R_BAD_GET_OBJECT); + * ASN1err(ASN1_F_D2I_X509_KEY,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_KEY_NEW,ERR_R_BAD_GET_ASN1_OBJECT_CALL); */ int i2d_X509_KEY(a,pp) diff --git a/crypto/asn1/t_x509.c b/crypto/asn1/t_x509.c index b10fbbb992..9a8c8bf0ca 100644 --- a/crypto/asn1/t_x509.c +++ b/crypto/asn1/t_x509.c @@ -158,6 +158,11 @@ X509 *x; (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err; pkey=X509_get_pubkey(x); + if (pkey == NULL) + { + BIO_printf(bp,"%12sUnable to load Public Key\n",""); + } + else #ifndef NO_RSA if (pkey->type == EVP_PKEY_RSA) { @@ -175,7 +180,7 @@ X509 *x; } else #endif - BIO_printf(bp,"%12sDSA Public Key:\n",""); + BIO_printf(bp,"%12sUnknown Public Key:\n",""); n=X509_get_ext_count(x); if (n > 0) diff --git a/crypto/asn1/x b/crypto/asn1/x new file mode 100644 index 0000000000..13acdab427 --- /dev/null +++ b/crypto/asn1/x @@ -0,0 +1,353 @@ +/* crypto/asn1/x_crl.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * 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 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 acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS 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 AUTHOR OR 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. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_D2I_X509_CRL,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_CRL_INFO,ASN1_R_EXPECTING_A_SEQUENCE); + * ASN1err(ASN1_F_D2I_X509_REVOKED,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_CRL_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_CRL_INFO_NEW,ASN1_R_EXPECTING_A_SEQUENCE); + * ASN1err(ASN1_F_X509_REVOKED_NEW,ASN1_R_LENGTH_MISMATCH); + */ + +#ifndef NOPROTO +static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b); +static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b); +#else +static int X509_REVOKED_cmp(); +static int X509_REVOKED_seq_cmp(); +#endif + +int i2d_X509_REVOKED(a,pp) +X509_REVOKED *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER); + M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_UTCTIME); + M_ASN1_I2D_len_SEQ_opt(a->extensions,i2d_X509_EXTENSION); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER); + M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_UTCTIME); + M_ASN1_I2D_put_SEQ_opt(a->extensions,i2d_X509_EXTENSION); + + M_ASN1_I2D_finish(); + } + +X509_REVOKED *d2i_X509_REVOKED(a,pp,length) +X509_REVOKED **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); + M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_UTCTIME); + M_ASN1_D2I_get_seq_opt(ret->extensions,d2i_X509_EXTENSION); + M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED); + } + +int i2d_X509_CRL_INFO(a,pp) +X509_CRL_INFO *a; +unsigned char **pp; + { + int v1=0; + long l=0; + M_ASN1_I2D_vars(a); + + if (sk_num(a->revoked) != 0) + qsort((char *)a->revoked->data,sk_num(a->revoked), + sizeof(X509_REVOKED *),(int (*)(P_CC_CC))X509_REVOKED_seq_cmp); + if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0)) + { + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + } + M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR); + M_ASN1_I2D_len(a->issuer,i2d_X509_NAME); + M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_UTCTIME); + if (a->nextUpdate != NULL) + { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_UTCTIME); } + M_ASN1_I2D_len_SEQ_opt(a->revoked,i2d_X509_REVOKED); + M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, + V_ASN1_SEQUENCE,v1); + + M_ASN1_I2D_seq_total(); + + if ((a->version != NULL) && (l != 0)) + { + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + } + M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR); + M_ASN1_I2D_put(a->issuer,i2d_X509_NAME); + M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME); + if (a->nextUpdate != NULL) + { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); } + M_ASN1_I2D_put_SEQ_opt(a->revoked,i2d_X509_REVOKED); + M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, + V_ASN1_SEQUENCE,v1); + + M_ASN1_I2D_finish(); + } + +X509_CRL_INFO *d2i_X509_CRL_INFO(a,pp,length) +X509_CRL_INFO **a; +unsigned char **pp; +long length; + { + int i,ver=0; + M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new); + + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get_opt(ret->version,d2i_ASN1_INTEGER,V_ASN1_INTEGER); + if (ret->version != NULL) + ver=ret->version->data[0]; + + if ((ver == 0) && (ret->version != NULL)) + { + ASN1_INTEGER_free(ret->version); + ret->version=NULL; + } + M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); + M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_UTCTIME); + M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME,V_ASN1_UTCTIME); + if (ret->revoked != NULL) + { + while (sk_num(ret->revoked)) + X509_REVOKED_free((X509_REVOKED *)sk_pop(ret->revoked)); + } + M_ASN1_D2I_get_seq_opt(ret->revoked,d2i_X509_REVOKED); + + if (ret->revoked != NULL) + { + for (i=0; i<sk_num(ret->revoked); i++) + { + ((X509_REVOKED *)sk_value(ret->revoked,i))->sequence=i; + } + } + + if (ver >= 1) + { + if (ret->extensions != NULL) + { + while (sk_num(ret->extensions)) + X509_EXTENSION_free((X509_EXTENSION *) + sk_pop(ret->extensions)); + } + + M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION, + 0,V_ASN1_SEQUENCE); + } + + M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO); + } + +int i2d_X509_CRL(a,pp) +X509_CRL *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->crl,i2d_X509_CRL_INFO); + M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR); + M_ASN1_I2D_len(a->signature,i2d_ASN1_BIT_STRING); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->crl,i2d_X509_CRL_INFO); + M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR); + M_ASN1_I2D_put(a->signature,i2d_ASN1_BIT_STRING); + + M_ASN1_I2D_finish(); + } + +X509_CRL *d2i_X509_CRL(a,pp,length) +X509_CRL **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->crl,d2i_X509_CRL_INFO); + M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); + + M_ASN1_D2I_Finish(a,X509_CRL_free,ASN1_F_D2I_X509_CRL); + } + + +X509_REVOKED *X509_REVOKED_new() + { + X509_REVOKED *ret=NULL; + + M_ASN1_New_Malloc(ret,X509_REVOKED); + M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); + M_ASN1_New(ret->revocationDate,ASN1_UTCTIME_new); + ret->extensions=NULL; + return(ret); + M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW); + } + +X509_CRL_INFO *X509_CRL_INFO_new() + { + X509_CRL_INFO *ret=NULL; + + M_ASN1_New_Malloc(ret,X509_CRL_INFO); + ret->version=NULL; + M_ASN1_New(ret->sig_alg,X509_ALGOR_new); + M_ASN1_New(ret->issuer,X509_NAME_new); + M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new); + ret->nextUpdate=NULL; + M_ASN1_New(ret->revoked,sk_new_null); + M_ASN1_New(ret->extensions,sk_new_null); + ret->revoked->comp=(int (*)())X509_REVOKED_cmp; + return(ret); + M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW); + } + +X509_CRL *X509_CRL_new() + { + X509_CRL *ret=NULL; + + M_ASN1_New_Malloc(ret,X509_CRL); + ret->references=1; + M_ASN1_New(ret->crl,X509_CRL_INFO_new); + M_ASN1_New(ret->sig_alg,X509_ALGOR_new); + M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); + return(ret); + M_ASN1_New_Error(ASN1_F_X509_CRL_NEW); + } + +void X509_REVOKED_free(a) +X509_REVOKED *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->serialNumber); + ASN1_UTCTIME_free(a->revocationDate); + sk_pop_free(a->extensions,X509_EXTENSION_free); + Free((char *)a); + } + +void X509_CRL_INFO_free(a) +X509_CRL_INFO *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + X509_ALGOR_free(a->sig_alg); + X509_NAME_free(a->issuer); + ASN1_UTCTIME_free(a->lastUpdate); + if (a->nextUpdate) + ASN1_UTCTIME_free(a->nextUpdate); + sk_pop_free(a->revoked,X509_REVOKED_free); + sk_pop_free(a->extensions,X509_EXTENSION_free); + Free((char *)a); + } + +void X509_CRL_free(a) +X509_CRL *a; + { + int i; + + if (a == NULL) return; + + i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_CRL); +#ifdef REF_PRINT + REF_PRINT("X509_CRL",a); +#endif + if (i > 0) return; +#ifdef REF_CHECK + if (i < 0) + { + fprintf(stderr,"X509_CRL_free, bad reference count\n"); + abort(); + } +#endif + + X509_CRL_INFO_free(a->crl); + X509_ALGOR_free(a->sig_alg); + ASN1_BIT_STRING_free(a->signature); + Free((char *)a); + } + +static int X509_REVOKED_cmp(a,b) +X509_REVOKED **a,**b; + { + return(ASN1_STRING_cmp( + (ASN1_STRING *)(*a)->serialNumber, + (ASN1_STRING *)(*b)->serialNumber)); + } + +static int X509_REVOKED_seq_cmp(a,b) +X509_REVOKED **a,**b; + { + return((*a)->sequence-(*b)->sequence); + } diff --git a/crypto/asn1/x_algor.c b/crypto/asn1/x_algor.c index 0ed2c87b64..01aa0cb6fc 100644 --- a/crypto/asn1/x_algor.c +++ b/crypto/asn1/x_algor.c @@ -61,9 +61,9 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_ALGOR_NEW,ASN1_R_EXPECTING_A_SEQUENCE); - * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_ALGOR,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_ALGOR_NEW,ERR_R_EXPECTING_AN_ASN1_SEQUENCE); + * ASN1err(ASN1_F_D2I_X509_ALGOR,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_X509_ALGOR(a,pp) @@ -107,9 +107,10 @@ long length; X509_ALGOR *X509_ALGOR_new() { X509_ALGOR *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_ALGOR); - M_ASN1_New(ret->algorithm,ASN1_OBJECT_new); + ret->algorithm=OBJ_nid2obj(NID_undef); ret->parameter=NULL; return(ret); M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW); diff --git a/crypto/asn1/x_attrib.c b/crypto/asn1/x_attrib.c index e52ced8627..d9faf141d3 100644 --- a/crypto/asn1/x_attrib.c +++ b/crypto/asn1/x_attrib.c @@ -62,7 +62,7 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509_ATTRIBUTE,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_ATTRIBUTE,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_X509_ATTRIBUTE_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); * ASN1err(ASN1_F_I2D_X509_ATTRIBUTE,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ @@ -115,7 +115,7 @@ long length; (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET))) { ret->set=1; - M_ASN1_D2I_get_set(ret->value.set,d2i_ASN1_TYPE); + M_ASN1_D2I_get_set(ret->value.set,d2i_ASN1_TYPE,ASN1_TYPE_free); } else { @@ -126,12 +126,37 @@ long length; M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE); } +X509_ATTRIBUTE *X509_ATTRIBUTE_create(nid,atrtype,value) +int nid; +int atrtype; +char *value; + { + X509_ATTRIBUTE *ret=NULL; + ASN1_TYPE *val=NULL; + + if ((ret=X509_ATTRIBUTE_new()) == NULL) + return(NULL); + ret->object=OBJ_nid2obj(nid); + ret->set=1; + if ((ret->value.set=sk_new_null()) == NULL) goto err; + if ((val=ASN1_TYPE_new()) == NULL) goto err; + if (!sk_push(ret->value.set,(char *)val)) goto err; + + ASN1_TYPE_set(val,atrtype,value); + return(ret); +err: + if (ret != NULL) X509_ATTRIBUTE_free(ret); + if (val != NULL) ASN1_TYPE_free(val); + return(NULL); + } + X509_ATTRIBUTE *X509_ATTRIBUTE_new() { X509_ATTRIBUTE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_ATTRIBUTE); - M_ASN1_New(ret->object,ASN1_OBJECT_new); + ret->object=OBJ_nid2obj(NID_undef); ret->set=0; ret->value.ptr=NULL; return(ret); diff --git a/crypto/asn1/x_cinf.c b/crypto/asn1/x_cinf.c index 4fc2cc9f6e..27aad14c52 100644 --- a/crypto/asn1/x_cinf.c +++ b/crypto/asn1/x_cinf.c @@ -61,8 +61,8 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509_CINF,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_CINF_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_CINF,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_CINF_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_X509_CINF(a,pp) @@ -140,7 +140,7 @@ long length; if (ret->subjectUID != NULL) { ASN1_BIT_STRING_free(ret->subjectUID); - ret->issuerUID=NULL; + ret->subjectUID=NULL; } M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1, V_ASN1_BIT_STRING); @@ -153,8 +153,8 @@ long length; while (sk_num(ret->extensions)) X509_EXTENSION_free((X509_EXTENSION *) sk_pop(ret->extensions)); - M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION,3, - V_ASN1_SEQUENCE); + M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION, + X509_EXTENSION_free,3,V_ASN1_SEQUENCE); } M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF); } @@ -162,6 +162,7 @@ long length; X509_CINF *X509_CINF_new() { X509_CINF *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_CINF); ret->version=NULL; diff --git a/crypto/asn1/x_crl.c b/crypto/asn1/x_crl.c index 13acdab427..fe7b5f175b 100644 --- a/crypto/asn1/x_crl.c +++ b/crypto/asn1/x_crl.c @@ -62,12 +62,12 @@ #include "x509.h" /* - * ASN1err(ASN1_F_D2I_X509_CRL,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_X509_CRL_INFO,ASN1_R_EXPECTING_A_SEQUENCE); - * ASN1err(ASN1_F_D2I_X509_REVOKED,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_CRL_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_CRL_INFO_NEW,ASN1_R_EXPECTING_A_SEQUENCE); - * ASN1err(ASN1_F_X509_REVOKED_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_CRL,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_CRL_INFO,ERR_R_EXPECTING_AN_ASN1_SEQUENCE); + * ASN1err(ASN1_F_D2I_X509_REVOKED,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_CRL_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_CRL_INFO_NEW,ERR_R_EXPECTING_AN_ASN1_SEQUENCE); + * ASN1err(ASN1_F_X509_REVOKED_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ #ifndef NOPROTO @@ -108,7 +108,8 @@ long length; M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_UTCTIME); - M_ASN1_D2I_get_seq_opt(ret->extensions,d2i_X509_EXTENSION); + M_ASN1_D2I_get_seq_opt(ret->extensions,d2i_X509_EXTENSION, + X509_EXTENSION_free); M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED); } @@ -183,7 +184,7 @@ long length; while (sk_num(ret->revoked)) X509_REVOKED_free((X509_REVOKED *)sk_pop(ret->revoked)); } - M_ASN1_D2I_get_seq_opt(ret->revoked,d2i_X509_REVOKED); + M_ASN1_D2I_get_seq_opt(ret->revoked,d2i_X509_REVOKED,X509_REVOKED_free); if (ret->revoked != NULL) { @@ -203,7 +204,7 @@ long length; } M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION, - 0,V_ASN1_SEQUENCE); + X509_EXTENSION_free,0,V_ASN1_SEQUENCE); } M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO); @@ -248,6 +249,7 @@ long length; X509_REVOKED *X509_REVOKED_new() { X509_REVOKED *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_REVOKED); M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); @@ -260,6 +262,7 @@ X509_REVOKED *X509_REVOKED_new() X509_CRL_INFO *X509_CRL_INFO_new() { X509_CRL_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_CRL_INFO); ret->version=NULL; @@ -277,6 +280,7 @@ X509_CRL_INFO *X509_CRL_INFO_new() X509_CRL *X509_CRL_new() { X509_CRL *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_CRL); ret->references=1; diff --git a/crypto/asn1/x_exten.c b/crypto/asn1/x_exten.c index 54ffe2f00b..f5e3ece226 100644 --- a/crypto/asn1/x_exten.c +++ b/crypto/asn1/x_exten.c @@ -62,8 +62,8 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509_EXTENSION,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_EXTENSION_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_EXTENSION,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_EXTENSION_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_X509_EXTENSION(a,pp) @@ -130,9 +130,10 @@ long length; X509_EXTENSION *X509_EXTENSION_new() { X509_EXTENSION *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_EXTENSION); - M_ASN1_New(ret->object,ASN1_OBJECT_new); + ret->object=OBJ_nid2obj(NID_undef); M_ASN1_New(ret->value,ASN1_OCTET_STRING_new); ret->critical=0; ret->netscape_hack=0; diff --git a/crypto/asn1/x_name.c b/crypto/asn1/x_name.c index 28b9c34b58..3b8bc5191f 100644 --- a/crypto/asn1/x_name.c +++ b/crypto/asn1/x_name.c @@ -62,9 +62,9 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509_NAME,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_NAME,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_X509_NAME_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - * ASN1err(ASN1_F_D2I_X509_NAME_ENTRY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_NAME_ENTRY,ERR_R_ASN1_LENGTH_MISMATCH); * ASN1err(ASN1_F_X509_NAME_ENTRY_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); */ @@ -213,7 +213,8 @@ long length; for (;;) { if (M_ASN1_D2I_end_sequence()) break; - M_ASN1_D2I_get_set(ret->entries,d2i_X509_NAME_ENTRY); + M_ASN1_D2I_get_set(ret->entries,d2i_X509_NAME_ENTRY, + X509_NAME_ENTRY_free); for (; idx < sk_num(ret->entries); idx++) { ((X509_NAME_ENTRY *)sk_value(ret->entries,idx))->set= @@ -234,9 +235,11 @@ long length; X509_NAME *X509_NAME_new() { X509_NAME *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_NAME); - if ((ret->entries=sk_new(NULL)) == NULL) goto err2; + if ((ret->entries=sk_new(NULL)) == NULL) + { c.line=__LINE__; goto err2; } M_ASN1_New(ret->bytes,BUF_MEM_new); ret->modified=1; return(ret); @@ -246,6 +249,7 @@ X509_NAME *X509_NAME_new() X509_NAME_ENTRY *X509_NAME_ENTRY_new() { X509_NAME_ENTRY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_NAME_ENTRY); /* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/ diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c index 1d4d926129..3a359cce9e 100644 --- a/crypto/asn1/x_pkey.c +++ b/crypto/asn1/x_pkey.c @@ -91,6 +91,7 @@ long length; if (ret->cipher.cipher == NULL) { c.error=ASN1_R_UNSUPPORTED_CIPHER; + c.line=__LINE__; goto err; } if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) @@ -99,6 +100,7 @@ long length; if (i > EVP_MAX_IV_LENGTH) { c.error=ASN1_R_IV_TOO_LARGE; + c.line=__LINE__; goto err; } memcpy(ret->cipher.iv, @@ -112,6 +114,7 @@ long length; X509_PKEY *X509_PKEY_new() { X509_PKEY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_PKEY); ret->version=0; diff --git a/crypto/asn1/x_pubkey.c b/crypto/asn1/x_pubkey.c index a309cf74a7..b8e6d0e00e 100644 --- a/crypto/asn1/x_pubkey.c +++ b/crypto/asn1/x_pubkey.c @@ -61,8 +61,8 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509_PUBKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_PUBKEY_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_PUBKEY,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_PUBKEY_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_X509_PUBKEY(a,pp) @@ -104,6 +104,7 @@ long length; X509_PUBKEY *X509_PUBKEY_new() { X509_PUBKEY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_PUBKEY); M_ASN1_New(ret->algor,X509_ALGOR_new); diff --git a/crypto/asn1/x_req.c b/crypto/asn1/x_req.c index ff0be13d37..a0df9982dc 100644 --- a/crypto/asn1/x_req.c +++ b/crypto/asn1/x_req.c @@ -62,10 +62,10 @@ #include "x509.h" /* - * ASN1err(ASN1_F_D2I_X509_REQ,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_X509_REQ_INFO,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_REQ_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_REQ_INFO_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_REQ,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_REQ_INFO,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_REQ_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_REQ_INFO_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_X509_REQ_INFO(a,pp) @@ -141,7 +141,8 @@ long length; ret->req_kludge=1; else { - M_ASN1_D2I_get_IMP_set(ret->attributes,d2i_X509_ATTRIBUTE,0); + M_ASN1_D2I_get_IMP_set(ret->attributes,d2i_X509_ATTRIBUTE, + X509_ATTRIBUTE_free,0); } M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO); @@ -150,6 +151,7 @@ long length; X509_REQ_INFO *X509_REQ_INFO_new() { X509_REQ_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_REQ_INFO); M_ASN1_New(ret->version,ASN1_INTEGER_new); @@ -208,6 +210,7 @@ long length; X509_REQ *X509_REQ_new() { X509_REQ *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_REQ); ret->references=1; diff --git a/crypto/asn1/x_sig.c b/crypto/asn1/x_sig.c index f0a2e4c27a..245a76b0f0 100644 --- a/crypto/asn1/x_sig.c +++ b/crypto/asn1/x_sig.c @@ -61,8 +61,8 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509_SIG,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_SIG_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_X509_SIG,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_SIG_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_X509_SIG(a,pp) @@ -99,6 +99,7 @@ long length; X509_SIG *X509_SIG_new() { X509_SIG *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_SIG); M_ASN1_New(ret->algor,X509_ALGOR_new); diff --git a/crypto/asn1/x_spki.c b/crypto/asn1/x_spki.c index 4a80df44b8..5600d305a3 100644 --- a/crypto/asn1/x_spki.c +++ b/crypto/asn1/x_spki.c @@ -66,10 +66,10 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_NETSCAPE_SPKAC,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_NETSCAPE_SPKAC_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_NETSCAPE_SPKI,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_NETSCAPE_SPKI_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_NETSCAPE_SPKAC,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_NETSCAPE_SPKAC_NEW,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_NETSCAPE_SPKI,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_NETSCAPE_SPKI_NEW,ERR_R_ASN1_LENGTH_MISMATCH); */ int i2d_NETSCAPE_SPKAC(a,pp) @@ -106,6 +106,7 @@ long length; NETSCAPE_SPKAC *NETSCAPE_SPKAC_new() { NETSCAPE_SPKAC *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC); M_ASN1_New(ret->pubkey,X509_PUBKEY_new); @@ -160,6 +161,7 @@ long length; NETSCAPE_SPKI *NETSCAPE_SPKI_new() { NETSCAPE_SPKI *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,NETSCAPE_SPKI); M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new); diff --git a/crypto/asn1/x_val.c b/crypto/asn1/x_val.c index a9c390f88c..8d996e9950 100644 --- a/crypto/asn1/x_val.c +++ b/crypto/asn1/x_val.c @@ -99,6 +99,7 @@ long length; X509_VAL *X509_VAL_new() { X509_VAL *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_VAL); M_ASN1_New(ret->notBefore,ASN1_UTCTIME_new); diff --git a/crypto/asn1/x_x509.c b/crypto/asn1/x_x509.c index bc466ce0f6..e235abb231 100644 --- a/crypto/asn1/x_x509.c +++ b/crypto/asn1/x_x509.c @@ -62,8 +62,8 @@ #include "asn1_mac.h" /* - * ASN1err(ASN1_F_D2I_X509,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_NEW,ASN1_R_BAD_GET_OBJECT); + * ASN1err(ASN1_F_D2I_X509,ERR_R_ASN1_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_NEW,ERR_R_BAD_GET_ASN1_OBJECT_CALL); */ static ASN1_METHOD meth={ @@ -117,6 +117,7 @@ ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); X509 *X509_new() { X509 *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509); ret->references=1; @@ -149,9 +150,11 @@ X509 *a; } #endif + /* CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); */ X509_CINF_free(a->cert_info); X509_ALGOR_free(a->sig_alg); ASN1_BIT_STRING_free(a->signature); + if (a->name != NULL) Free(a->name); Free((char *)a); } |