diff options
| author | cvs2svn <admin@example.com> | 1998-10-19 21:47:12 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 1998-10-19 21:47:12 +0000 |
| commit | 5170039cf1df2194faa85741f0733977525cd5c0 (patch) | |
| tree | c667406046ddb1efca5ed4316b02e43494241660 /src/lib/libcrypto/x509 | |
| parent | 536c76cbb863bab152f19842ab88772c01e922c7 (diff) | |
| download | openbsd-OPENBSD_2_4_BASE.tar.gz openbsd-OPENBSD_2_4_BASE.tar.bz2 openbsd-OPENBSD_2_4_BASE.zip | |
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_4_BASE'.OPENBSD_2_4_BASE
Diffstat (limited to 'src/lib/libcrypto/x509')
| -rw-r--r-- | src/lib/libcrypto/x509/Makefile.ssl | 96 | ||||
| -rw-r--r-- | src/lib/libcrypto/x509/attrib | 38 | ||||
| -rw-r--r-- | src/lib/libcrypto/x509/v3_net.c | 87 | ||||
| -rw-r--r-- | src/lib/libcrypto/x509/v3_x509.c | 253 | ||||
| -rw-r--r-- | src/lib/libcrypto/x509/x509.doc | 27 | ||||
| -rw-r--r-- | src/lib/libcrypto/x509/x509.err | 46 | ||||
| -rw-r--r-- | src/lib/libcrypto/x509/x509pack.c | 157 | ||||
| -rw-r--r-- | src/lib/libcrypto/x509/x509v3.doc | 24 |
8 files changed, 728 insertions, 0 deletions
diff --git a/src/lib/libcrypto/x509/Makefile.ssl b/src/lib/libcrypto/x509/Makefile.ssl new file mode 100644 index 0000000000..1c1ca2ffa0 --- /dev/null +++ b/src/lib/libcrypto/x509/Makefile.ssl | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | # | ||
| 2 | # SSLeay/crypto/x509/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= x509 | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I../../include | ||
| 9 | CFLAG=-g | ||
| 10 | INSTALLTOP=/usr/local/ssl | ||
| 11 | MAKE= make -f Makefile.ssl | ||
| 12 | MAKEDEPEND= makedepend -f Makefile.ssl | ||
| 13 | MAKEFILE= Makefile.ssl | ||
| 14 | AR= ar r | ||
| 15 | |||
| 16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 17 | |||
| 18 | ERR=x509 | ||
| 19 | ERRC=x509_err | ||
| 20 | GENERAL=Makefile README | ||
| 21 | TEST= | ||
| 22 | APPS= | ||
| 23 | |||
| 24 | LIB=$(TOP)/libcrypto.a | ||
| 25 | LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \ | ||
| 26 | x509_obj.c x509_req.c x509_vfy.c \ | ||
| 27 | x509_set.c x509rset.c $(ERRC).c \ | ||
| 28 | x509name.c x509_v3.c x509_ext.c x509pack.c \ | ||
| 29 | x509type.c x509_lu.c x_all.c x509_txt.c \ | ||
| 30 | by_file.c by_dir.c \ | ||
| 31 | v3_net.c v3_x509.c | ||
| 32 | LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \ | ||
| 33 | x509_obj.o x509_req.o x509_vfy.o \ | ||
| 34 | x509_set.o x509rset.o $(ERRC).o \ | ||
| 35 | x509name.o x509_v3.o x509_ext.o x509pack.o \ | ||
| 36 | x509type.o x509_lu.o x_all.o x509_txt.o \ | ||
| 37 | by_file.o by_dir.o \ | ||
| 38 | v3_net.o v3_x509.o | ||
| 39 | |||
| 40 | SRC= $(LIBSRC) | ||
| 41 | |||
| 42 | EXHEADER= x509.h x509_vfy.h | ||
| 43 | HEADER= $(EXHEADER) | ||
| 44 | |||
| 45 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 46 | |||
| 47 | top: | ||
| 48 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 49 | |||
| 50 | all: lib | ||
| 51 | |||
| 52 | lib: $(LIBOBJ) | ||
| 53 | $(AR) $(LIB) $(LIBOBJ) | ||
| 54 | sh $(TOP)/util/ranlib.sh $(LIB) | ||
| 55 | @touch lib | ||
| 56 | |||
| 57 | files: | ||
| 58 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
| 59 | |||
| 60 | links: | ||
| 61 | /bin/rm -f Makefile | ||
| 62 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | ||
| 63 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | ||
| 64 | $(TOP)/util/mklink.sh ../../test $(TEST) | ||
| 65 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
| 66 | |||
| 67 | install: | ||
| 68 | @for i in $(EXHEADER) ; \ | ||
| 69 | do \ | ||
| 70 | (cp $$i $(INSTALLTOP)/include/$$i; \ | ||
| 71 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | ||
| 72 | done; | ||
| 73 | |||
| 74 | tags: | ||
| 75 | ctags $(SRC) | ||
| 76 | |||
| 77 | tests: | ||
| 78 | |||
| 79 | lint: | ||
| 80 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 81 | |||
| 82 | depend: | ||
| 83 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | ||
| 84 | |||
| 85 | dclean: | ||
| 86 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 87 | mv -f Makefile.new $(MAKEFILE) | ||
| 88 | |||
| 89 | clean: | ||
| 90 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 91 | |||
| 92 | errors: | ||
| 93 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
| 94 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
| 95 | |||
| 96 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
diff --git a/src/lib/libcrypto/x509/attrib b/src/lib/libcrypto/x509/attrib new file mode 100644 index 0000000000..37f6cd755f --- /dev/null +++ b/src/lib/libcrypto/x509/attrib | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | |||
| 2 | PKCS7 | ||
| 3 | STACK of X509_ATTRIBUTES | ||
| 4 | ASN1_OBJECT | ||
| 5 | STACK of ASN1_TYPE | ||
| 6 | |||
| 7 | So it is | ||
| 8 | |||
| 9 | p7.xa[].obj | ||
| 10 | p7.xa[].data[] | ||
| 11 | |||
| 12 | get_obj_by_nid(STACK , nid) | ||
| 13 | get_num_by_nid(STACK , nid) | ||
| 14 | get_data_by_nid(STACK , nid, index) | ||
| 15 | |||
| 16 | X509_ATTRIBUTE *X509_ATTRIBUTE_new(void ); | ||
| 17 | void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a); | ||
| 18 | |||
| 19 | X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **ex, | ||
| 20 | int nid, STACK *value); | ||
| 21 | |||
| 22 | X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **ex, | ||
| 23 | int nid, STACK *value); | ||
| 24 | |||
| 25 | int X509_ATTRIBUTE_set_object(X509_ATTRIBUTE *ex,ASN1_OBJECT *obj); | ||
| 26 | int X509_ATTRIBUTE_add_data(X509_ATTRIBUTE *ex, int index, | ||
| 27 | ASN1_TYPE *value); | ||
| 28 | |||
| 29 | ASN1_OBJECT * X509_ATTRIBUTE_get_object(X509_ATTRIBUTE *ex); | ||
| 30 | int X509_ATTRIBUTE_get_num(X509_ATTRIBUTE *ne); | ||
| 31 | ASN1_TYPE * X509_ATTRIBUTE_get_data(X509_ATTRIBUTE *ne,int index); | ||
| 32 | |||
| 33 | ASN1_TYPE * X509_ATTRIBUTE_get_data_by_NID(X509_ATTRIBUTE *ne, | ||
| 34 | ASN1_OBJECT *obj); | ||
| 35 | |||
| 36 | X509_ATTRUBUTE *PKCS7_get_s_att_by_NID(PKCS7 *p7,int nid); | ||
| 37 | X509_ATTRUBUTE *PKCS7_get_u_att_by_NID(PKCS7 *p7,int nid); | ||
| 38 | |||
diff --git a/src/lib/libcrypto/x509/v3_net.c b/src/lib/libcrypto/x509/v3_net.c new file mode 100644 index 0000000000..0c2d276d13 --- /dev/null +++ b/src/lib/libcrypto/x509/v3_net.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* crypto/x509/v3_net.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "stack.h" | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "asn1.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | #define NETSCAPE_X509_EXT_NUM 8 | ||
| 67 | |||
| 68 | static X509_EXTENSION_METHOD netscape_x509_ext[NETSCAPE_X509_EXT_NUM]={ | ||
| 69 | {NID_netscape_ca_policy_url, V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, | ||
| 70 | {NID_netscape_ssl_server_name, V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, | ||
| 71 | {NID_netscape_revocation_url, V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, | ||
| 72 | {NID_netscape_base_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, | ||
| 73 | {NID_netscape_cert_type,V_ASN1_BIT_STRING,X509_EXT_PACK_STRING}, | ||
| 74 | {NID_netscape_ca_revocation_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, | ||
| 75 | {NID_netscape_renewal_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, | ||
| 76 | {NID_netscape_comment,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, | ||
| 77 | }; | ||
| 78 | |||
| 79 | int X509v3_add_netscape_extensions() | ||
| 80 | { | ||
| 81 | int i; | ||
| 82 | |||
| 83 | for (i=0; i<NETSCAPE_X509_EXT_NUM; i++) | ||
| 84 | if (!X509v3_add_extension(&(netscape_x509_ext[i]))) | ||
| 85 | return(0); | ||
| 86 | return(1); | ||
| 87 | } | ||
diff --git a/src/lib/libcrypto/x509/v3_x509.c b/src/lib/libcrypto/x509/v3_x509.c new file mode 100644 index 0000000000..f685aa4c71 --- /dev/null +++ b/src/lib/libcrypto/x509/v3_x509.c | |||
| @@ -0,0 +1,253 @@ | |||
| 1 | /* crypto/x509/v3_x509.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <ctype.h> | ||
| 61 | #include "stack.h" | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "bio.h" | ||
| 64 | #include "asn1.h" | ||
| 65 | #include "objects.h" | ||
| 66 | #include "x509.h" | ||
| 67 | |||
| 68 | #if 0 | ||
| 69 | static int i2a_key_usage(BIO *bp, X509 *x); | ||
| 70 | static int a2i_key_usage(X509 *x, char *str, int len); | ||
| 71 | #endif | ||
| 72 | |||
| 73 | int X509v3_get_key_usage(X509 *x); | ||
| 74 | int X509v3_set_key_usage(X509 *x,unsigned int use); | ||
| 75 | int i2a_X509v3_key_usage(BIO *bp, unsigned int use); | ||
| 76 | unsigned int a2i_X509v3_key_usage(char *p); | ||
| 77 | |||
| 78 | #define STD_X509_EXT_NUM 9 | ||
| 79 | |||
| 80 | #if 0 | ||
| 81 | static X509_OBJECTS std_x509_ext[STD_X509_EXT_NUM]={ | ||
| 82 | {NID_subject_key_identifier, NULL,NULL}, | ||
| 83 | {NID_key_usage, a2i_key_usage,i2a_key_usage}, /**/ | ||
| 84 | {NID_private_key_usage_period, NULL,NULL}, | ||
| 85 | {NID_subject_alt_name, NULL,NULL}, | ||
| 86 | {NID_issuer_alt_name, NULL,NULL}, | ||
| 87 | {NID_basic_constraints, NULL,NULL}, | ||
| 88 | {NID_crl_number, NULL,NULL}, | ||
| 89 | {NID_certificate_policies, NULL,NULL}, | ||
| 90 | {NID_authority_key_identifier, NULL,NULL}, | ||
| 91 | }; | ||
| 92 | #endif | ||
| 93 | |||
| 94 | int X509v3_add_standard_extensions() | ||
| 95 | { | ||
| 96 | |||
| 97 | #if 0 | ||
| 98 | for (i=0; i<STD_X509_EXT_NUM; i++) | ||
| 99 | if (!X509v3_add_extension(&(std_x509_ext[i]))) | ||
| 100 | return(0); | ||
| 101 | #endif | ||
| 102 | return(1); | ||
| 103 | } | ||
| 104 | |||
| 105 | int X509v3_get_key_usage(x) | ||
| 106 | X509 *x; | ||
| 107 | { | ||
| 108 | X509_EXTENSION *ext; | ||
| 109 | ASN1_STRING *st; | ||
| 110 | char *p; | ||
| 111 | int i; | ||
| 112 | |||
| 113 | i=X509_get_ext_by_NID(x,NID_key_usage,-1); | ||
| 114 | if (i < 0) return(X509v3_KU_UNDEF); | ||
| 115 | ext=X509_get_ext(x,i); | ||
| 116 | st=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING, | ||
| 117 | X509_EXTENSION_get_data(X509_get_ext(x,i))); | ||
| 118 | |||
| 119 | p=(char *)ASN1_STRING_data(st); | ||
| 120 | if (ASN1_STRING_length(st) == 1) | ||
| 121 | i=p[0]; | ||
| 122 | else if (ASN1_STRING_length(st) == 2) | ||
| 123 | i=p[0]|(p[1]<<8); | ||
| 124 | else | ||
| 125 | i=0; | ||
| 126 | return(i); | ||
| 127 | } | ||
| 128 | |||
| 129 | static struct | ||
| 130 | { | ||
| 131 | char *name; | ||
| 132 | unsigned int value; | ||
| 133 | } key_usage_data[] ={ | ||
| 134 | {"digitalSignature", X509v3_KU_DIGITAL_SIGNATURE}, | ||
| 135 | {"nonRepudiation", X509v3_KU_NON_REPUDIATION}, | ||
| 136 | {"keyEncipherment", X509v3_KU_KEY_ENCIPHERMENT}, | ||
| 137 | {"dataEncipherment", X509v3_KU_DATA_ENCIPHERMENT}, | ||
| 138 | {"keyAgreement", X509v3_KU_KEY_AGREEMENT}, | ||
| 139 | {"keyCertSign", X509v3_KU_KEY_CERT_SIGN}, | ||
| 140 | {"cRLSign", X509v3_KU_CRL_SIGN}, | ||
| 141 | {"encipherOnly", X509v3_KU_ENCIPHER_ONLY}, | ||
| 142 | {"decipherOnly", X509v3_KU_DECIPHER_ONLY}, | ||
| 143 | {NULL,0}, | ||
| 144 | }; | ||
| 145 | |||
| 146 | #if 0 | ||
| 147 | static int a2i_key_usage(x,str,len) | ||
| 148 | X509 *x; | ||
| 149 | char *str; | ||
| 150 | int len; | ||
| 151 | { | ||
| 152 | return(X509v3_set_key_usage(x,a2i_X509v3_key_usage(str))); | ||
| 153 | } | ||
| 154 | |||
| 155 | static int i2a_key_usage(bp,x) | ||
| 156 | BIO *bp; | ||
| 157 | X509 *x; | ||
| 158 | { | ||
| 159 | return(i2a_X509v3_key_usage(bp,X509v3_get_key_usage(x))); | ||
| 160 | } | ||
| 161 | #endif | ||
| 162 | |||
| 163 | int i2a_X509v3_key_usage(bp,use) | ||
| 164 | BIO *bp; | ||
| 165 | unsigned int use; | ||
| 166 | { | ||
| 167 | int i=0,first=1; | ||
| 168 | |||
| 169 | for (;;) | ||
| 170 | { | ||
| 171 | if (use | key_usage_data[i].value) | ||
| 172 | { | ||
| 173 | BIO_printf(bp,"%s%s",((first)?"":" "), | ||
| 174 | key_usage_data[i].name); | ||
| 175 | first=0; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | return(1); | ||
| 179 | } | ||
| 180 | |||
| 181 | unsigned int a2i_X509v3_key_usage(p) | ||
| 182 | char *p; | ||
| 183 | { | ||
| 184 | unsigned int ret=0; | ||
| 185 | char *q,*s; | ||
| 186 | int i,n; | ||
| 187 | |||
| 188 | q=p; | ||
| 189 | for (;;) | ||
| 190 | { | ||
| 191 | while ((*q != '\0') && isalnum(*q)) | ||
| 192 | q++; | ||
| 193 | if (*q == '\0') break; | ||
| 194 | s=q++; | ||
| 195 | while (isalnum(*q)) | ||
| 196 | q++; | ||
| 197 | n=q-s; | ||
| 198 | i=0; | ||
| 199 | for (;;) | ||
| 200 | { | ||
| 201 | if (strncmp(key_usage_data[i].name,s,n) == 0) | ||
| 202 | { | ||
| 203 | ret|=key_usage_data[i].value; | ||
| 204 | break; | ||
| 205 | } | ||
| 206 | i++; | ||
| 207 | if (key_usage_data[i].name == NULL) | ||
| 208 | return(X509v3_KU_UNDEF); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | return(ret); | ||
| 212 | } | ||
| 213 | |||
| 214 | int X509v3_set_key_usage(x,use) | ||
| 215 | X509 *x; | ||
| 216 | unsigned int use; | ||
| 217 | { | ||
| 218 | ASN1_OCTET_STRING *os; | ||
| 219 | X509_EXTENSION *ext; | ||
| 220 | int i; | ||
| 221 | unsigned char data[4]; | ||
| 222 | |||
| 223 | i=X509_get_ext_by_NID(x,NID_key_usage,-1); | ||
| 224 | if (i < 0) | ||
| 225 | { | ||
| 226 | i=X509_get_ext_count(x)+1; | ||
| 227 | if ((ext=X509_EXTENSION_new()) == NULL) return(0); | ||
| 228 | if (!X509_add_ext(x,ext,i)) | ||
| 229 | { | ||
| 230 | X509_EXTENSION_free(ext); | ||
| 231 | return(0); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | else | ||
| 235 | ext=X509_get_ext(x,i); | ||
| 236 | |||
| 237 | /* fill in 'ext' */ | ||
| 238 | os=X509_EXTENSION_get_data(ext); | ||
| 239 | |||
| 240 | i=0; | ||
| 241 | if (use > 0) | ||
| 242 | { | ||
| 243 | i=1; | ||
| 244 | data[0]=use&0xff; | ||
| 245 | } | ||
| 246 | if (use > 0xff) | ||
| 247 | { | ||
| 248 | i=2; | ||
| 249 | data[1]=(use>>8)&0xff; | ||
| 250 | } | ||
| 251 | return((X509v3_pack_string(&os,V_ASN1_BIT_STRING,data,i) == NULL)?0:1); | ||
| 252 | } | ||
| 253 | |||
diff --git a/src/lib/libcrypto/x509/x509.doc b/src/lib/libcrypto/x509/x509.doc new file mode 100644 index 0000000000..73cfc9f034 --- /dev/null +++ b/src/lib/libcrypto/x509/x509.doc | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | X509_verify() | ||
| 2 | X509_sign() | ||
| 3 | |||
| 4 | X509_get_version() | ||
| 5 | X509_get_serialNumber() | ||
| 6 | X509_get_issuer() | ||
| 7 | X509_get_subject() | ||
| 8 | X509_get_notBefore() | ||
| 9 | X509_get_notAfter() | ||
| 10 | X509_get_pubkey() | ||
| 11 | |||
| 12 | X509_set_version() | ||
| 13 | X509_set_serialNumber() | ||
| 14 | X509_set_issuer() | ||
| 15 | X509_set_subject() | ||
| 16 | X509_set_notBefore() | ||
| 17 | X509_set_notAfter() | ||
| 18 | X509_set_pubkey() | ||
| 19 | |||
| 20 | X509_get_extensions() | ||
| 21 | X509_set_extensions() | ||
| 22 | |||
| 23 | X509_EXTENSIONS_clear() | ||
| 24 | X509_EXTENSIONS_retrieve() | ||
| 25 | X509_EXTENSIONS_add() | ||
| 26 | X509_EXTENSIONS_delete() | ||
| 27 | |||
diff --git a/src/lib/libcrypto/x509/x509.err b/src/lib/libcrypto/x509/x509.err new file mode 100644 index 0000000000..8d0862d7d1 --- /dev/null +++ b/src/lib/libcrypto/x509/x509.err | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /* Error codes for the X509 functions. */ | ||
| 2 | |||
| 3 | /* Function codes. */ | ||
| 4 | #define X509_F_ADD_CERT_DIR 100 | ||
| 5 | #define X509_F_BY_FILE_CTRL 101 | ||
| 6 | #define X509_F_DIR_CTRL 102 | ||
| 7 | #define X509_F_GET_CERT_BY_SUBJECT 103 | ||
| 8 | #define X509_F_X509V3_ADD_EXT 104 | ||
| 9 | #define X509_F_X509V3_ADD_EXTENSION 105 | ||
| 10 | #define X509_F_X509V3_PACK_STRING 106 | ||
| 11 | #define X509_F_X509V3_UNPACK_STRING 107 | ||
| 12 | #define X509_F_X509_EXTENSION_CREATE_BY_NID 108 | ||
| 13 | #define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 | ||
| 14 | #define X509_F_X509_GET_PUBKEY_PARAMETERS 110 | ||
| 15 | #define X509_F_X509_LOAD_CERT_FILE 111 | ||
| 16 | #define X509_F_X509_LOAD_CRL_FILE 112 | ||
| 17 | #define X509_F_X509_NAME_ADD_ENTRY 113 | ||
| 18 | #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 | ||
| 19 | #define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 | ||
| 20 | #define X509_F_X509_NAME_ONELINE 116 | ||
| 21 | #define X509_F_X509_NAME_PRINT 117 | ||
| 22 | #define X509_F_X509_PRINT_FP 118 | ||
| 23 | #define X509_F_X509_PUBKEY_GET 119 | ||
| 24 | #define X509_F_X509_PUBKEY_SET 120 | ||
| 25 | #define X509_F_X509_REQ_PRINT 121 | ||
| 26 | #define X509_F_X509_REQ_PRINT_FP 122 | ||
| 27 | #define X509_F_X509_REQ_TO_X509 123 | ||
| 28 | #define X509_F_X509_STORE_ADD_CERT 124 | ||
| 29 | #define X509_F_X509_STORE_ADD_CRL 125 | ||
| 30 | #define X509_F_X509_TO_X509_REQ 126 | ||
| 31 | #define X509_F_X509_VERIFY_CERT 127 | ||
| 32 | |||
| 33 | /* Reason codes. */ | ||
| 34 | #define X509_R_BAD_X509_FILETYPE 100 | ||
| 35 | #define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 | ||
| 36 | #define X509_R_ERR_ASN1_LIB 102 | ||
| 37 | #define X509_R_LOADING_CERT_DIR 103 | ||
| 38 | #define X509_R_LOADING_DEFAULTS 104 | ||
| 39 | #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 | ||
| 40 | #define X509_R_SHOULD_RETRY 106 | ||
| 41 | #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 | ||
| 42 | #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 | ||
| 43 | #define X509_R_UNKNOWN_NID 109 | ||
| 44 | #define X509_R_UNKNOWN_STRING_TYPE 110 | ||
| 45 | #define X509_R_UNSUPPORTED_ALGORITHM 111 | ||
| 46 | #define X509_R_WRONG_LOOKUP_TYPE 112 | ||
diff --git a/src/lib/libcrypto/x509/x509pack.c b/src/lib/libcrypto/x509/x509pack.c new file mode 100644 index 0000000000..846f125859 --- /dev/null +++ b/src/lib/libcrypto/x509/x509pack.c | |||
| @@ -0,0 +1,157 @@ | |||
| 1 | /* crypto/x509/x509pack.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "stack.h" | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "asn1.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "evp.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | ASN1_OCTET_STRING *X509v3_pack_string(ex,type,bytes,len) | ||
| 68 | ASN1_OCTET_STRING **ex; | ||
| 69 | int type; | ||
| 70 | unsigned char *bytes; | ||
| 71 | int len; | ||
| 72 | { | ||
| 73 | ASN1_OCTET_STRING *os; | ||
| 74 | ASN1_STRING str; | ||
| 75 | unsigned char *p; | ||
| 76 | int i; | ||
| 77 | |||
| 78 | if ((ex == NULL) || (*ex == NULL)) | ||
| 79 | os=ASN1_OCTET_STRING_new(); | ||
| 80 | else | ||
| 81 | os= *ex; | ||
| 82 | |||
| 83 | if (len < 0) len=strlen((char *)bytes); | ||
| 84 | str.length=len; | ||
| 85 | str.type=type; | ||
| 86 | str.data=bytes; | ||
| 87 | |||
| 88 | /* str now holds the data, we just have to copy it into ->value */ | ||
| 89 | |||
| 90 | switch (type) | ||
| 91 | { | ||
| 92 | case V_ASN1_BIT_STRING: | ||
| 93 | i=i2d_ASN1_BIT_STRING((ASN1_BIT_STRING *)&str,NULL); | ||
| 94 | if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i)) | ||
| 95 | goto err; | ||
| 96 | p=(unsigned char *)os->data; | ||
| 97 | i2d_ASN1_BIT_STRING((ASN1_BIT_STRING *)&str,&p); | ||
| 98 | break; | ||
| 99 | case V_ASN1_OCTET_STRING: | ||
| 100 | i=i2d_ASN1_OCTET_STRING((ASN1_OCTET_STRING *)&str,NULL); | ||
| 101 | if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i)) | ||
| 102 | goto err; | ||
| 103 | p=(unsigned char *)os->data; | ||
| 104 | i2d_ASN1_OCTET_STRING((ASN1_OCTET_STRING *)&str,&p); | ||
| 105 | break; | ||
| 106 | case V_ASN1_IA5STRING: | ||
| 107 | case V_ASN1_PRINTABLESTRING: | ||
| 108 | case V_ASN1_T61STRING: | ||
| 109 | i=i2d_ASN1_bytes(&str,NULL,type,V_ASN1_UNIVERSAL); | ||
| 110 | if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i)) | ||
| 111 | goto err; | ||
| 112 | p=(unsigned char *)os->data; | ||
| 113 | i=i2d_ASN1_bytes(&str,&p,type,V_ASN1_UNIVERSAL); | ||
| 114 | break; | ||
| 115 | default: | ||
| 116 | X509err(X509_F_X509V3_PACK_STRING,X509_R_UNKNOWN_STRING_TYPE); | ||
| 117 | goto err; | ||
| 118 | } | ||
| 119 | os->length=i; | ||
| 120 | |||
| 121 | if ((ex != NULL) && (os != *ex)) | ||
| 122 | *ex=os; | ||
| 123 | return(os); | ||
| 124 | err: | ||
| 125 | return(NULL); | ||
| 126 | } | ||
| 127 | |||
| 128 | ASN1_STRING *X509v3_unpack_string(ex,type,os) | ||
| 129 | ASN1_STRING **ex; | ||
| 130 | int type; | ||
| 131 | ASN1_OCTET_STRING *os; | ||
| 132 | { | ||
| 133 | unsigned char *p; | ||
| 134 | ASN1_STRING *ret=NULL; | ||
| 135 | |||
| 136 | p=os->data; | ||
| 137 | switch (type) | ||
| 138 | { | ||
| 139 | case V_ASN1_BIT_STRING: | ||
| 140 | ret=(ASN1_STRING *)d2i_ASN1_BIT_STRING( | ||
| 141 | (ASN1_BIT_STRING **)ex,&p,os->length); | ||
| 142 | break; | ||
| 143 | case V_ASN1_OCTET_STRING: | ||
| 144 | ret=(ASN1_STRING *)d2i_ASN1_OCTET_STRING( | ||
| 145 | (ASN1_BIT_STRING **)ex,&p,os->length); | ||
| 146 | break; | ||
| 147 | case V_ASN1_IA5STRING: | ||
| 148 | case V_ASN1_PRINTABLESTRING: | ||
| 149 | case V_ASN1_T61STRING: | ||
| 150 | ret=(ASN1_STRING *)d2i_ASN1_PRINTABLE(ex,&p,os->length); | ||
| 151 | break; | ||
| 152 | default: | ||
| 153 | X509err(X509_F_X509V3_UNPACK_STRING,X509_R_UNKNOWN_STRING_TYPE); | ||
| 154 | } | ||
| 155 | return(ret); | ||
| 156 | } | ||
| 157 | |||
diff --git a/src/lib/libcrypto/x509/x509v3.doc b/src/lib/libcrypto/x509/x509v3.doc new file mode 100644 index 0000000000..1e760a9469 --- /dev/null +++ b/src/lib/libcrypto/x509/x509v3.doc | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | The 'new' system. | ||
| 2 | |||
| 3 | The X509_EXTENSION_METHOD includes extensions and attributes and/or names. | ||
| 4 | Basically everthing that can be added to an X509 with an OID identifying it. | ||
| 5 | |||
| 6 | It operates via 2 methods per object id. | ||
| 7 | int a2i_XXX(X509 *x,char *str,int len); | ||
| 8 | int i2a_XXX(BIO *bp,X509 *x); | ||
| 9 | |||
| 10 | The a2i_XXX function will add the object with a value converted from the | ||
| 11 | string into the X509. Len can be -1 in which case the length is calculated | ||
| 12 | via strlen(str). Applications can always use direct knowledge to load and | ||
| 13 | unload the relevent objects themselves. | ||
| 14 | |||
| 15 | i2a_XXX will print to the passed BIO, a text representation of the | ||
| 16 | relevet object. Use a memory BIO if you want it printed to a buffer :-). | ||
| 17 | |||
| 18 | X509_add_by_NID(X509 *x,int nid,char *str,int len); | ||
| 19 | X509_add_by_OBJ(X509 *x,ASN1_OBJECT *obj,char *str,int len); | ||
| 20 | |||
| 21 | X509_print_by_name(BIO *bp,X509 *x); | ||
| 22 | X509_print_by_NID(BIO *bp,X509 *x); | ||
| 23 | X509_print_by_OBJ(BIO *bp,X509 *x); | ||
| 24 | |||
