diff options
author | Dr. Stephen Henson <steve@openssl.org> | 1999-01-24 00:50:01 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 1999-01-24 00:50:01 +0000 |
commit | 9aeaf1b4a7924cabf829bf57d0ca87d311cd2dfe (patch) | |
tree | 2fcca9cb74c2bf745deb7d6977f3da826347bff7 | |
parent | 69d1dfba24c9200a2cd307bf0b1949f6bb6291ea (diff) |
Initial addition of new X509 V3 files, tidy of old files.
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | crypto/x509v3/Makefile.ssl | 88 | ||||
-rw-r--r-- | crypto/x509v3/README | 4 | ||||
-rw-r--r-- | crypto/x509v3/old-v3/format (renamed from crypto/x509v3/format) | 0 | ||||
-rw-r--r-- | crypto/x509v3/old-v3/header (renamed from crypto/x509v3/header) | 0 | ||||
-rw-r--r-- | crypto/x509v3/old-v3/v3_ku.c | 318 | ||||
-rw-r--r-- | crypto/x509v3/old-v3/x509v3.h | 87 | ||||
-rw-r--r-- | crypto/x509v3/v3_bcons.c | 187 | ||||
-rw-r--r-- | crypto/x509v3/v3_bitstr.c | 159 | ||||
-rw-r--r-- | crypto/x509v3/v3_conf.c | 165 | ||||
-rw-r--r-- | crypto/x509v3/v3_extku.c | 165 | ||||
-rw-r--r-- | crypto/x509v3/v3_ia5.c | 127 | ||||
-rw-r--r-- | crypto/x509v3/v3_lib.c | 158 | ||||
-rw-r--r-- | crypto/x509v3/v3_prn.c | 134 | ||||
-rw-r--r-- | crypto/x509v3/v3_utl.c | 312 | ||||
-rw-r--r-- | crypto/x509v3/v3conf.c | 127 | ||||
-rw-r--r-- | crypto/x509v3/v3err.c | 112 | ||||
-rw-r--r-- | crypto/x509v3/v3prin.c | 97 | ||||
-rw-r--r-- | crypto/x509v3/x509v3.h | 344 |
19 files changed, 2508 insertions, 81 deletions
@@ -5,6 +5,11 @@ Changes between 0.9.1c and 0.9.2 + *) Takes a deep breath and start addding X509 V3 extension support code. Add + files in crypto/x509v3. Move original stuff to crypto/x509v3/old. All this + stuff is currently isolated and isn't even compiled yet. + [Steve Henson] + *) Continuing patches for GeneralizedTime. Fix up certificate and CRL ASN1 to use ASN1_TIME and modify print routines to use ASN1_TIME_print. Removed the versions check from X509 routines when loading extensions: diff --git a/crypto/x509v3/Makefile.ssl b/crypto/x509v3/Makefile.ssl new file mode 100644 index 0000000000..3cc99ea296 --- /dev/null +++ b/crypto/x509v3/Makefile.ssl @@ -0,0 +1,88 @@ +# +# SSLeay/crypto/x509v3/Makefile +# + +DIR= x509v3 +TOP= ../.. +CC= cc +INCLUDES= -I.. -I../../include +CFLAG=-g +INSTALLTOP=/usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) +MAKEFILE= Makefile.ssl +AR= ar r + +CFLAGS= $(INCLUDES) $(CFLAG) + +ERR=x509v3 +ERRC=v3err +GENERAL=Makefile README +TEST= +APPS= + +LIB=$(TOP)/libcrypto.a +LIBSRC= v3_bcons.c v3_bitstr.c v3_conf.c v3_extku.c v3_ia5.c \ +v3_lib.c v3_prn.c v3_utl.c v3err.c +LIBOBJ= v3_bcons.o v3_bitstr.o v3_conf.o v3_extku.o v3_ia5.o v3_lib.o \ +v3_prn.o v3_utl.o v3err.o + +SRC= $(LIBSRC) + +EXHEADER= x509v3.h +HEADER= $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) + +all: lib + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + sh $(TOP)/util/ranlib.sh $(LIB) + @touch lib + +files: + perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +links: + /bin/rm -f Makefile + $(TOP)/util/point.sh Makefile.ssl Makefile ; + $(TOP)/util/mklink.sh ../../include $(EXHEADER) + $(TOP)/util/mklink.sh ../../test $(TEST) + $(TOP)/util/mklink.sh ../../apps $(APPS) + +install: + @for i in $(EXHEADER) ; \ + do \ + (cp $$i $(INSTALLTOP)/include/$$i; \ + chmod 644 $(INSTALLTOP)/include/$$i ); \ + done; + +tags: + ctags $(SRC) + +tests: + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + +dclean: + perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +errors: $(ERRC).c + +$(ERRC).c: $(ERR).err + perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h + perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + +# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/crypto/x509v3/README b/crypto/x509v3/README new file mode 100644 index 0000000000..3b2cc047be --- /dev/null +++ b/crypto/x509v3/README @@ -0,0 +1,4 @@ +WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING + +This is ***VERY*** new experimental code and is likely to change +considerably or vanish altogether. diff --git a/crypto/x509v3/format b/crypto/x509v3/old-v3/format index 3307978121..3307978121 100644 --- a/crypto/x509v3/format +++ b/crypto/x509v3/old-v3/format diff --git a/crypto/x509v3/header b/crypto/x509v3/old-v3/header index 3d791ca3dd..3d791ca3dd 100644 --- a/crypto/x509v3/header +++ b/crypto/x509v3/old-v3/header diff --git a/crypto/x509v3/old-v3/v3_ku.c b/crypto/x509v3/old-v3/v3_ku.c new file mode 100644 index 0000000000..87c7402f43 --- /dev/null +++ b/crypto/x509v3/old-v3/v3_ku.c @@ -0,0 +1,318 @@ +/* crypto/x509v3/v3_ku.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 <ctype.h> +#include "stack.h" +#include "cryptlib.h" +#include "bio.h" +#include "asn1.h" +#include "objects.h" +#include "x509.h" + +X509_EXTENSION_METHOD X509v3_key_usage_method= + { + NID_key_usage, + ku_clear, + ex_get_bool, + ex_set_bool, + NULL, + NULL, + NULL, + NULL, + ku_a2i, + ku_i2a, + }; + +static void ku_clear(a) +X509_EXTENSION *a; + { + } + +static int ku_expand(a) +X509_EXTENSION *a; + { + ASN1_BIT_STRING *bs; + + if (a->argp == NULL) + { + bs=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING,value); + if (bs == NULL) return(0); + a->argp=(char *)bs; + a->ex_free=ASN1_STRING_free; + } + return(1); + } + +static int ku_get_bool(a,num) +X509_EXTENSION *a; +int num; + { + int ret; + ASN1_BIT_STRING *bs; + + if ((a->argp == NULL) && !ku_expand(a)) + return(-1); + bs=(ASN1_BIT_STRING *)a->argp; + ret=ASN1_BIT_STRING_get_bit(bs,num); + return(ret); + } + +static int ku_set_bool(a,num,value) +X509_EXTENSION *a; +int num; +int value; + { + ASN1_BIT_STRING *a; + + if ((a->argp == NULL) && !ku_expand(a)) + return(0); + bs=(ASN1_BIT_STRING *)a->argp; + ret=ASN1_BIT_STRING_set_bit(bs,num,value); + } + +static int ku_a2i(bio,a,buf,len) +BIO *bio; +X509_EXTENSION *a; +char *buf; +int len; + { + get token + } + +static char ku_names[X509v3_N_KU_NUM]={ + X509v3_S_KU_digitalSignature, + X509v3_S_KU_nonRepudiation, + X509v3_S_KU_keyEncipherment, + X509v3_S_KU_dataEncipherment, + X509v3_S_KU_keyAgreement, + X509v3_S_KU_keyCertSign, + X509v3_S_KU_cRLSign, + X509v3_S_KU_encipherOnly, + X509v3_S_KU_decipherOnly, + }; + +static int ku_i2a(bio,a); +BIO *bio; +X509_EXTENSION *a; + { + int i,first=1; + char *c; + + for (i=0; i<X509v3_N_KU_NUM; i++) + { + if (ku_get_bool(a,i) > 0) + { + BIO_printf(bio,"%s%s",((first)?"":" "),ku_names[i]); + first=0; + } + } + } + +/***********************/ + +int X509v3_get_key_usage(x,ret) +STACK *x; +unsigned long *ret; + { + X509_EXTENSION *ext; + ASN1_STRING *st; + char *p; + int i; + + i=X509_get_ext_by_NID(x,NID_key_usage,-1); + if (i < 0) return(X509v3_KU_UNDEF); + ext=X509_get_ext(x,i); + st=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING, + X509_EXTENSION_get_data(X509_get_ext(x,i))); + + p=ASN1_STRING_data(st); + if (ASN1_STRING_length(st) == 1) + i=p[0]; + else if (ASN1_STRING_length(st) == 2) + i=p[0]|(p[1]<<8); + else + i=0; + return(i); + } + +static struct + { + char *name; + unsigned int value; + } key_usage_data[] ={ + {"digitalSignature", X509v3_KU_DIGITAL_SIGNATURE}, + {"nonRepudiation", X509v3_KU_NON_REPUDIATION}, + {"keyEncipherment", X509v3_KU_KEY_ENCIPHERMENT}, + {"dataEncipherment", X509v3_KU_DATA_ENCIPHERMENT}, + {"keyAgreement", X509v3_KU_KEY_AGREEMENT}, + {"keyCertSign", X509v3_KU_KEY_CERT_SIGN}, + {"cRLSign", X509v3_KU_CRL_SIGN}, + {"encipherOnly", X509v3_KU_ENCIPHER_ONLY}, + {"decipherOnly", X509v3_KU_DECIPHER_ONLY}, + {NULL,0}, + }; + +#if 0 +static int a2i_key_usage(x,str,len) +X509 *x; +char *str; +int len; + { + return(X509v3_set_key_usage(x,a2i_X509v3_key_usage(str))); + } + +static int i2a_key_usage(bp,x) +BIO *bp; +X509 *x; + { + return(i2a_X509v3_key_usage(bp,X509v3_get_key_usage(x))); + } +#endif + +int i2a_X509v3_key_usage(bp,use) +BIO *bp; +unsigned int use; + { + int i=0,first=1; + + for (;;) + { + if (use | key_usage_data[i].value) + { + BIO_printf(bp,"%s%s",((first)?"":" "), + key_usage_data[i].name); + first=0; + } + } + return(1); + } + +unsigned int a2i_X509v3_key_usage(p) +char *p; + { + unsigned int ret=0; + char *q,*s; + int i,n; + + q=p; + for (;;) + { + while ((*q != '\0') && isalnum(*q)) + q++; + if (*q == '\0') break; + s=q++; + while (isalnum(*q)) + q++; + n=q-s; + i=0; + for (;;) + { + if (strncmp(key_usage_data[i].name,s,n) == 0) + { + ret|=key_usage_data[i].value; + break; + } + i++; + if (key_usage_data[i].name == NULL) + return(X509v3_KU_UNDEF); + } + } + return(ret); + } + +int X509v3_set_key_usage(x,use) +X509 *x; +unsigned int use; + { + ASN1_OCTET_STRING *os; + X509_EXTENSION *ext; + int i; + unsigned char data[4]; + + i=X509_get_ext_by_NID(x,NID_key_usage,-1); + if (i < 0) + { + i=X509_get_ext_count(x)+1; + if ((ext=X509_EXTENSION_new()) == NULL) return(0); + if (!X509_add_ext(x,ext,i)) + { + X509_EXTENSION_free(ext); + return(0); + } + } + else + ext=X509_get_ext(x,i); + + /* fill in 'ext' */ + os=X509_EXTENSION_get_data(ext); + + i=0; + if (use > 0) + { + i=1; + data[0]=use&0xff; + } + if (use > 0xff) + { + i=2; + data[1]=(use>>8)&0xff; + } + return((X509v3_pack_string(&os,V_ASN1_BIT_STRING,data,i) == NULL)?0:1); + } + diff --git a/crypto/x509v3/old-v3/x509v3.h b/crypto/x509v3/old-v3/x509v3.h new file mode 100644 index 0000000000..d7945bc9cd --- /dev/null +++ b/crypto/x509v3/old-v3/x509v3.h @@ -0,0 +1,87 @@ +/* crypto/x509v3/x509v3.h */ +/* 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.] + */ +#define X509v3_N_KU_digitalSignature 0 +#define X509v3_N_KU_nonRepudiation 1 +#define X509v3_N_KU_keyEncipherment 2 +#define X509v3_N_KU_dataEncipherment 3 +#define X509v3_N_KU_keyAgreement 4 +#define X509v3_N_KU_keyCertSign 5 +#define X509v3_N_KU_cRLSign 6 +#define X509v3_N_KU_encipherOnly 7 +#define X509v3_N_KU_decipherOnly 8 +#define X509v3_N_KU_NUM 9 +#define X509v3_S_KU_digitalSignature "digitalSignature" +#define X509v3_S_KU_nonRepudiation "nonRepudiation" +#define X509v3_S_KU_keyEncipherment "keyEncipherment" +#define X509v3_S_KU_dataEncipherment "dataEncipherment" +#define X509v3_S_KU_keyAgreement "keyAgreement" +#define X509v3_S_KU_keyCertSign "keyCertSign" +#define X509v3_S_KU_cRLSign "cRLSign" +#define X509v3_S_KU_encipherOnly "encipherOnly" +#define X509v3_S_KU_decipherOnly "decipherOnly" + + +void X509_ex_clear(X509_EXTENSION *a); +int X509_ex_get_bool(X509_EXTENSION *a,int num); +int X509_ex_set_bool(X509_EXTENSION *a,int num,int value); +int X509_ex_get_str(X509_EXTENSION *a,int index,char **p,int *len); +int X509_ex_set_str(X509_EXTENSION *a,int oid,int index,char *p,int len); +char *X509_ex_get_struct(X509_EXTENSION *a,int oid,int index,char **p); +int X509_ex_set_struct(X509_EXTENSION *a,int index,char *p); +int a2i_X509_EXTENSION(BIO *bp,X509_EXTENSION *a,char *buf,int len); +int i2a_X509_EXTENSION(BIO *bp,X509_EXTENSION *a); diff --git a/crypto/x509v3/v3_bcons.c b/crypto/x509v3/v3_bcons.c new file mode 100644 index 0000000000..f7ad3e884c --- /dev/null +++ b/crypto/x509v3/v3_bcons.c @@ -0,0 +1,187 @@ +/* v3_bcons.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * 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 + * licensing@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). + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <pem.h> +#include <asn1_mac.h> +#include <err.h> +#include <objects.h> +#include <conf.h> +#include "x509v3.h" + +#ifndef NOPROTO +static STACK *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons); +static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK *values); + +#else + +static STACK *i2v_BASIC_CONSTRAINTS(); +static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(); + +#endif + +X509V3_EXT_METHOD v3_bcons = { +NID_basic_constraints, 0, +(X509V3_EXT_NEW)BASIC_CONSTRAINTS_new, +BASIC_CONSTRAINTS_free, +(X509V3_EXT_D2I)d2i_BASIC_CONSTRAINTS, +i2d_BASIC_CONSTRAINTS, +NULL, NULL, +(X509V3_EXT_I2V)i2v_BASIC_CONSTRAINTS, +(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS, +NULL, +NULL +}; + + +/* + * ASN1err(ASN1_F_BASIC_CONSTRAINTS_NEW,ERR_R_MALLOC_FAILURE); + * ASN1err(ASN1_F_D2I_BASIC_CONSTRAINTS,ERR_R_MALLOC_FAILURE); + */ + +int i2d_BASIC_CONSTRAINTS(a,pp) +BASIC_CONSTRAINTS *a; +unsigned char **pp; +{ + M_ASN1_I2D_vars(a); + if(a->ca) M_ASN1_I2D_len (a->ca, i2d_ASN1_BOOLEAN); + M_ASN1_I2D_len (a->pathlen, i2d_ASN1_INTEGER); + + M_ASN1_I2D_seq_total(); + + if (a->ca) M_ASN1_I2D_put (a->ca, i2d_ASN1_BOOLEAN); + M_ASN1_I2D_put (a->pathlen, i2d_ASN1_INTEGER); + M_ASN1_I2D_finish(); +} + +BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new() +{ + BASIC_CONSTRAINTS *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, BASIC_CONSTRAINTS); + ret->ca = 0; + ret->pathlen = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_BASIC_CONSTRAINTS_NEW); +} + +BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(a,pp,length) +BASIC_CONSTRAINTS **a; +unsigned char **pp; +long length; +{ + M_ASN1_D2I_vars(a,BASIC_CONSTRAINTS *,BASIC_CONSTRAINTS_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + if((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == + (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN) ) { + M_ASN1_D2I_get_int (ret->ca, d2i_ASN1_BOOLEAN); + } + M_ASN1_D2I_get_opt (ret->pathlen, d2i_ASN1_INTEGER, V_ASN1_INTEGER); + M_ASN1_D2I_Finish(a, BASIC_CONSTRAINTS_free, ASN1_F_D2I_BASIC_CONSTRAINTS); +} + +void BASIC_CONSTRAINTS_free(a) +BASIC_CONSTRAINTS *a; +{ + if (a == NULL) return; + ASN1_INTEGER_free (a->pathlen); + Free ((char *)a); +} + +static STACK *i2v_BASIC_CONSTRAINTS(method, bcons) +X509V3_EXT_METHOD *method; +BASIC_CONSTRAINTS *bcons; +{ + STACK *extlist = NULL; + X509V3_add_value_bool("CA", bcons->ca, &extlist); + X509V3_add_value_int("pathlen", bcons->pathlen, &extlist); + return extlist; +} + +static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(method, ctx, values) +X509V3_EXT_METHOD *method; +X509V3_CTX *ctx; +STACK *values; +{ + BASIC_CONSTRAINTS *bcons=NULL; + CONF_VALUE *val; + int i; + if(!(bcons = BASIC_CONSTRAINTS_new())) { + X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE); + return NULL; + } + for(i = 0; i < sk_num(values); i++) { + val = (CONF_VALUE *)sk_value(values, i); + if(!strcmp(val->name, "CA")) { + if(!X509V3_get_value_bool(val, &bcons->ca)) goto err; + } else if(!strcmp(val->name, "pathlen")) { + if(!X509V3_get_value_int(val, &bcons->pathlen)) goto err; + } else { + X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME); + X509V3_conf_err(val); + goto err; + } + } + return bcons; + err: + BASIC_CONSTRAINTS_free(bcons); + return NULL; +} + diff --git a/crypto/x509v3/v3_bitstr.c b/crypto/x509v3/v3_bitstr.c new file mode 100644 index 0000000000..46d8836cd6 --- /dev/null +++ b/crypto/x509v3/v3_bitstr.c @@ -0,0 +1,159 @@ +/* v3_bitstr.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * 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 + * licensing@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). + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <pem.h> +#include <asn1_mac.h> +#include <err.h> +#include <objects.h> +#include <conf.h> +#include "x509v3.h" + +#ifndef NOPROTO +static ASN1_BIT_STRING *asn1_bit_string_new(void); +static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK *nval); +static STACK *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, ASN1_BIT_STRING *bits); +#else +static ASN1_BIT_STRING *asn1_bit_string_new(); +static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(); +static STACK *i2v_ASN1_BIT_STRING(); +#endif + +static BIT_STRING_BITNAME ns_cert_type_table[] = { +{0, "SSL Client", "client"}, +{1, "SSL Server", "server"}, +{2, "S/MIME", "email"}, +{3, "Object Signing", "objsign"}, +{4, "Unused", "reserved"}, +{5, "SSL CA", "sslCA"}, +{6, "S/MIME CA", "emailCA"}, +{7, "Object Signing CA", "objCA"}, +{-1, NULL, NULL} +}; + +static BIT_STRING_BITNAME key_usage_type_table[] = { +{0, "Digital Signature", "digitalSignature"}, +{1, "Non Repudiation", "nonRepudiation"}, +{2, "Key Encipherment", "keyEncipherment"}, +{3, "Data Encipherment", "dataEncipherment"}, +{4, "Key Agreement", "keyAgreement"}, +{5, "Certificate Sign", "keyCertSign"}, +{6, "CRL Sign", "cRLCertSign"}, +{7, "Encipher Only", "encipherOnly"}, +{8, "Decipher Only", "decipherOnly"}, +{-1, NULL, NULL} +}; + + + +X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table); +X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table); + +static ASN1_BIT_STRING *asn1_bit_string_new() +{ + return ASN1_BIT_STRING_new(); +} + +static STACK *i2v_ASN1_BIT_STRING(method, bits) +X509V3_EXT_METHOD *method; +ASN1_BIT_STRING *bits; +{ + BIT_STRING_BITNAME *bnam; + STACK *ret = NULL; + for(bnam =(BIT_STRING_BITNAME *)method->usr_data; bnam->lname; bnam++) { + if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum)) + X509V3_add_value(bnam->lname, NULL, &ret); + } + return ret; +} + +static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(method, ctx, nval) +X509V3_EXT_METHOD *method; +X509V3_CTX *ctx; +STACK *nval; +{ + CONF_VALUE *val; + ASN1_BIT_STRING *bs; + int i; + BIT_STRING_BITNAME *bnam; + if(!(bs = ASN1_BIT_STRING_new())) { + X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE); + return NULL; + } + for(i = 0; i < sk_num(nval); i++) { + val = (CONF_VALUE *)sk_value(nval, i); + for(bnam = (BIT_STRING_BITNAME *)method->usr_data; bnam->lname; + bnam++) { + if(!strcmp(bnam->sname, val->name) || + !strcmp(bnam->lname, val->name) ) { + ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1); + break; + } + } + if(!bnam->lname) { + X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT); + X509V3_conf_err(val); + ASN1_BIT_STRING_free(bs); + return NULL; + } + } + return bs; +} + + diff --git a/crypto/x509v3/v3_conf.c b/crypto/x509v3/v3_conf.c new file mode 100644 index 0000000000..afe2ae249e --- /dev/null +++ b/crypto/x509v3/v3_conf.c @@ -0,0 +1,165 @@ +/* v3_conf.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1 |