From: Nikos Mavrogiannopoulos Date: Sun, 5 Aug 2001 09:38:22 +0000 (+0000) Subject: renamed cert_* to x509_* X-Git-Tag: gnutls_0_2_0~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb3a0595d557f00e3956e75ea0abc268f9bc4533;p=thirdparty%2Fgnutls.git renamed cert_* to x509_* --- diff --git a/lib/Makefile.am b/lib/Makefile.am index a5ab36780a..d8f18797fc 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -11,25 +11,26 @@ EXTRA_DIST = debug.h gnutls_compress.h defines.h pkcs1.asn pkix.asn \ gnutls_compress_int.h gnutls_session.h gnutls_priority.h gnutls_auth.h \ auth_anon.h auth_dhe_dss.h gnutls_extensions.h ext_srp.h \ gnutls_auth_int.h crypt_bcrypt.h gnutls_random.h crypt_srpsha1.h \ - cert_b64.h gnutls_srp.h auth_srp.h auth_srp_passwd.h gnutls_v2_compat.h \ + x509_b64.h gnutls_srp.h auth_srp.h auth_srp_passwd.h gnutls_v2_compat.h \ crypt.h libgnutls-config.in libgnutls.m4 gnutls.h.in gnutls_errors_int.h \ - cert_asn1.h cert_der.h gnutls_datum.h auth_x509.h gnutls_gcry.h \ + x509_asn1.h x509_der.h gnutls_datum.h auth_x509.h gnutls_gcry.h \ ext_dnsname.h gnutls_pk.h gnutls_record.h gnutls_cert.h \ - gnutls_privkey.h gnutls_constate.h gnutls_global.h cert_verify.h \ - gnutls_sig.h gnutls_mem.h + gnutls_privkey.h gnutls_constate.h gnutls_global.h x509_verify.h \ + gnutls_sig.h gnutls_mem.h x509_extensions.h lib_LTLIBRARIES = libgnutls.la libgnutls_la_SOURCES = gnutls_record.c gnutls_compress.c debug.c \ gnutls_cipher.c gnutls_buffers.c gnutls_handshake.c gnutls_num.c \ gnutls_errors.c gnutls_algorithms.c gnutls_dh.c gnutls_kx.c \ gnutls_priority.c gnutls_hash_int.c gnutls_cipher_int.c \ - gnutls_compress_int.c gnutls_session.c gnutls_db.c cert_b64.c \ + gnutls_compress_int.c gnutls_session.c gnutls_db.c x509_b64.c \ auth_anon.c auth_dhe_dss.c gnutls_extensions.c ext_srp.c gnutls_auth.c \ crypt_bcrypt.c crypt.c gnutls_random.c crypt_srpsha1.c gnutls_srp.c \ auth_srp.c auth_srp_passwd.c gnutls_v2_compat.c auth_srp_sb64.c \ - cert_ASN.y cert_asn1.c cert_der.c gnutls_datum.c auth_rsa.c \ - gnutls_gcry.c ext_dnsname.c gnutls_pk.c gnutls_cert.c cert_verify.c\ + x509_ASN.y x509_asn1.c x509_der.c gnutls_datum.c auth_rsa.c \ + gnutls_gcry.c ext_dnsname.c gnutls_pk.c gnutls_cert.c x509_verify.c\ gnutls_global.c gnutls_privkey.c gnutls_constate.c gnutls_anon_cred.c \ - gnutls_sig_check.c pkix_asn1_tab.c pkcs1_asn1_tab.c gnutls_mem.c + gnutls_sig_check.c pkix_asn1_tab.c pkcs1_asn1_tab.c gnutls_mem.c \ + x509_extensions.c libgnutls_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) diff --git a/lib/auth_rsa.c b/lib/auth_rsa.c index 863b2eddce..dd12b4f8e5 100644 --- a/lib/auth_rsa.c +++ b/lib/auth_rsa.c @@ -23,15 +23,15 @@ #include "gnutls_errors.h" #include "gnutls_dh.h" #include "gnutls_num.h" -#include "cert_asn1.h" -#include "cert_der.h" +#include "x509_asn1.h" +#include "x509_der.h" #include "gnutls_datum.h" #include "auth_x509.h" #include #include #include #include -#include +#include #include "debug.h" int gen_rsa_certificate(GNUTLS_KEY, opaque **); diff --git a/lib/auth_srp_passwd.c b/lib/auth_srp_passwd.c index 358ee1c96d..3f4726ce1b 100644 --- a/lib/auth_srp_passwd.c +++ b/lib/auth_srp_passwd.c @@ -21,7 +21,7 @@ /* Functions for operating in an SRP passwd file are included here */ #include "gnutls_int.h" -#include "cert_b64.h" +#include "x509_b64.h" #include "gnutls_errors.h" #include "auth_srp_passwd.h" #include "auth_srp.h" diff --git a/lib/gnutls_cert.c b/lib/gnutls_cert.c index ed07b777c9..43912d5caa 100644 --- a/lib/gnutls_cert.c +++ b/lib/gnutls_cert.c @@ -20,17 +20,17 @@ #include #include -#include +#include #include #include -#include -#include +#include +#include #include #include #include #include -#include -#include +#include +#include /* KX mappings to PK algorithms */ typedef struct { @@ -500,7 +500,6 @@ static int _read_rsa_params(opaque * der, int dersize, MPI ** params) /* this function will convert up to 3 digit * numbers to characters. */ -#define MAX_INT_DIGITS 4 void _gnutls_int2str(int k, char* data) { if (k > 999) data[0] = 0; else sprintf( data, "%d", k); @@ -590,222 +589,6 @@ static int _get_Name_type( node_asn *rasn, char *root, gnutls_DN * dn) return GNUTLS_E_ASN1_PARSING_ERROR; } -/* Here we only read subjectAltName, in case of - * dnsName. Otherwise we read nothing. - */ -static int _extract_subjectAltName( char* subjectAltName, opaque* extnValue, int extnValueLen) { -node_asn* ext; -char counter[MAX_INT_DIGITS]; -char name[1024]; -char str[1024]; -int len, k, result; - - subjectAltName[0] = 0; - - if (asn1_create_structure - ( _gnutls_get_pkix(), "PKIX1Implicit88.GeneralNames", &ext, - "san") != ASN_OK) { - gnutls_assert(); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - result = asn1_get_der ( ext, extnValue, extnValueLen); - - if (result != ASN_OK) { - gnutls_assert(); - asn1_delete_structure(ext); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - k = 1; - for (;;) { - strcpy(name, "san.?"); - _gnutls_int2str(k, counter); - strcat(name, counter); - - len = sizeof(str) - 1; - result = asn1_read_value(ext, name, str, &len); - if (result == ASN_ELEMENT_NOT_FOUND) break; - - if (strcmp( str, "dNSName") == 0) { - strcat( name, "dNSName"); - len = sizeof( str) -1; - result = asn1_read_value(ext, name, str, &len); - - if (result != ASN_OK) { - gnutls_assert(); - asn1_delete_structure(ext); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - strncpy( subjectAltName, str, GMIN( len, X509_CN_SIZE-1)); - subjectAltName[X509_CN_SIZE-1] = 0; - - break; - } - k++; - } - - asn1_delete_structure(ext); - return 0; -} - -/* Here we only extract the KeyUsage field - */ -static int _extract_keyUsage( char* keyUsage, opaque* extnValue, int extnValueLen) { -node_asn* ext; -char str[128]; -int len, result; - - - if (asn1_create_structure - ( _gnutls_get_pkix(), "PKIX1Implicit88.KeyUsage", &ext, - "ku") != ASN_OK) { - gnutls_assert(); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - result = asn1_get_der ( ext, extnValue, extnValueLen); - - if (result != ASN_OK) { - gnutls_assert(); - asn1_delete_structure(ext); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - len = sizeof(str) - 1; - result = asn1_read_value(ext, "ku", str, &len); - if (result != ASN_OK) { - gnutls_assert(); - asn1_delete_structure(ext); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - keyUsage[0] = str[0]; - - asn1_delete_structure(ext); - - return 0; -} - - -static int _parse_extension( gnutls_cert* cert, char* extnID, char* critical, char* extnValue, int extnValueLen) { - - if (strcmp( extnID, "2 5 29 14")==0) { /* subject Key ID */ - /* we don't use it */ - return 0; - } - - if (strcmp( extnID, "2 5 29 15")==0) { /* Key Usage */ - return _extract_keyUsage( &cert->keyUsage, extnValue, extnValueLen); - } - - if (strcmp( extnID, "2 5 29 19")==0) { /* Basic Constraints */ - /* we don't use it */ - return 0; - } - - if (strcmp( extnID, "2 5 29 17")==0) { /* subjectAltName */ - return _extract_subjectAltName( cert->subjectAltName, extnValue, extnValueLen); - } - -#ifdef DEBUG - _gnutls_log("CERT[%s]: Unsupported Extension: %s, %s\n", cert->cert_info.common_name, extnID, critical); -#endif - - if (strcmp( critical, "TRUE")==0) { - gnutls_assert(); - return GNUTLS_E_X509_UNSUPPORTED_CRITICAL_EXTENSION; - } - return 0; - -} - -/* This function will attempt to parse Extensions in - * an X509v3 certificate - */ -static int _get_Ext_type( node_asn *rasn, char *root, gnutls_cert *cert) -{ - int k, result, len; - char name[128], name2[128], counter[MAX_INT_DIGITS]; - char str[1024]; - char critical[10]; - char extnID[128]; - char extnValue[128]; - - k = 0; - do { - k++; - - strcpy(name, root); - strcat(name, ".?"); - _gnutls_int2str(k, counter); - strcat(name, counter); - - len = sizeof(str) - 1; - result = asn1_read_value( rasn, name, str, &len); - - /* move to next - */ - - if (result==ASN_ELEMENT_NOT_FOUND) break; - - do { - - strcpy(name2, name); - strcat(name2, ".extnID"); - - len = sizeof(extnID) - 1; - result = asn1_read_value( rasn, name2, extnID, &len); - - if (result==ASN_ELEMENT_NOT_FOUND) break; - else - if (result != ASN_OK) { - gnutls_assert(); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - strcpy(name2, name); - strcat(name2, ".critical"); - - len = sizeof(critical) - 1; - result = asn1_read_value( rasn, name2, critical, &len); - - if (result==ASN_ELEMENT_NOT_FOUND) break; - else - if (result != ASN_OK) { - gnutls_assert(); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - strcpy(name2, name); - strcat(name2, ".extnValue"); - - len = sizeof( extnValue) - 1; - result = asn1_read_value( rasn, name2, extnValue, &len); - - if (result==ASN_ELEMENT_NOT_FOUND) break; - else - if (result != ASN_OK) { - gnutls_assert(); - return GNUTLS_E_ASN1_PARSING_ERROR; - } - - /* Handle Extension */ - if ( (result=_parse_extension( cert, extnID, critical, extnValue, len)) < 0) { - gnutls_assert(); - return result; - } - - - } while (0); - } while (1); - - if (result==ASN_ELEMENT_NOT_FOUND) - return 0; - else - return GNUTLS_E_ASN1_PARSING_ERROR; -} #define MAX_TIME 1024 @@ -976,7 +759,7 @@ return GNUTLS_E_UNIMPLEMENTED_FEATURE; } if ((result = - _get_Ext_type( c2, "certificate2.tbsCertificate.extensions", gCert)) < 0) { + _gnutls_get_ext_type( c2, "certificate2.tbsCertificate.extensions", gCert)) < 0) { gnutls_assert(); asn1_delete_structure(c2); return result; diff --git a/lib/gnutls_cert.h b/lib/gnutls_cert.h index 362458ff14..d3a30b0ef8 100644 --- a/lib/gnutls_cert.h +++ b/lib/gnutls_cert.h @@ -48,6 +48,10 @@ typedef struct { int valid; /* 0 if the certificate looks good. */ + + int CA; /* 0 if the certificate does not belong to + * a certificate authority. 1 otherwise. + */ gnutls_datum raw; /* the raw certificate */ } gnutls_cert; @@ -66,4 +70,7 @@ PKAlgorithm _gnutls_map_pk_get_pk(KXAlgorithm kx_algorithm); int _gnutls_cert2gnutlsCert(gnutls_cert * gCert, gnutls_datum derCert); gnutls_cert* _gnutls_find_cert( gnutls_cert** cert_list, int cert_list_length, char* name); +#define MAX_INT_DIGITS 4 +void _gnutls_int2str(int k, char* data); + #endif diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c index 4bd10e3237..b545912c75 100644 --- a/lib/gnutls_global.c +++ b/lib/gnutls_global.c @@ -20,7 +20,7 @@ #include #include -#include +#include #ifdef HAVE_SIGNAL_H # include #endif diff --git a/lib/gnutls_global.h b/lib/gnutls_global.h index ba00f573f9..dcb012ec32 100644 --- a/lib/gnutls_global.h +++ b/lib/gnutls_global.h @@ -1,5 +1,10 @@ -#include +#ifndef GNUTLS_GLOBAL_H +# define GNUTLS_GLOBAL_H + +#include int gnutls_is_secure_memory(const void* mem); node_asn* _gnutls_get_pkcs(); node_asn* _gnutls_get_pkix(); + +#endif diff --git a/lib/gnutls_privkey.c b/lib/gnutls_privkey.c index 406fce64ef..b26d9432c0 100644 --- a/lib/gnutls_privkey.c +++ b/lib/gnutls_privkey.c @@ -21,11 +21,11 @@ #include #include -#include +#include #include #include -#include -#include +#include +#include #include #include #include diff --git a/lib/gnutls_sig_check.c b/lib/gnutls_sig_check.c index fe30bba45c..9b3273624d 100644 --- a/lib/gnutls_sig_check.c +++ b/lib/gnutls_sig_check.c @@ -20,11 +20,11 @@ #include #include -#include +#include #include #include -#include -#include +#include +#include #include #include #include diff --git a/lib/pkcs1_asn1_tab.c b/lib/pkcs1_asn1_tab.c index 2fe359872d..3e1d2b1208 100644 --- a/lib/pkcs1_asn1_tab.c +++ b/lib/pkcs1_asn1_tab.c @@ -1,5 +1,5 @@ -#include "cert_asn1.h" +#include "x509_asn1.h" const static_asn pkcs1_asn1_tab[]={ {"PKCS-1",536872976,0}, diff --git a/lib/pkix_asn1_tab.c b/lib/pkix_asn1_tab.c index d03905e5e8..727a980f4c 100644 --- a/lib/pkix_asn1_tab.c +++ b/lib/pkix_asn1_tab.c @@ -1,5 +1,5 @@ -#include "cert_asn1.h" +#include "x509_asn1.h" const static_asn pkix_asn1_tab[]={ {"PKIX1Implicit88",536875024,0}, diff --git a/lib/cert_ASN.y b/lib/x509_ASN.y similarity index 99% rename from lib/cert_ASN.y rename to lib/x509_ASN.y index 407b342a87..52d240d6fc 100755 --- a/lib/cert_ASN.y +++ b/lib/x509_ASN.y @@ -20,7 +20,7 @@ /*****************************************************/ -/* File: cert_ASN.y */ +/* File: x509_ASN.y */ /* Description: input file for 'bison' program. */ /* The output file is a parser (in C language) for */ /* ASN.1 syntax */ @@ -29,7 +29,7 @@ %{ #include -#include "cert_asn1.h" +#include "x509_asn1.h" FILE *file_asn1; /* Pointer to file to parse */ extern int parse_mode; diff --git a/lib/cert_asn1.c b/lib/x509_asn1.c similarity index 99% rename from lib/cert_asn1.c rename to lib/x509_asn1.c index 857c71a058..1a9f36be12 100755 --- a/lib/cert_asn1.c +++ b/lib/x509_asn1.c @@ -20,15 +20,15 @@ /*****************************************************/ -/* File: cert_asn1.c */ +/* File: x509_asn1.c */ /* Description: Functions to manage ASN.1 DEFINITIONS*/ /*****************************************************/ #include -#include "cert_asn1.h" -#include "cert_der.h" +#include "x509_asn1.h" +#include "x509_der.h" #define UP 1 @@ -407,7 +407,7 @@ _asn1_create_static_structure(node_asn *pointer,char *file_name, char* out_name) if(file==NULL) return ASN_FILE_NOT_FOUND; - fprintf(file,"\n#include \"cert_asn1.h\"\n\n"); + fprintf(file,"\n#include \"x509_asn1.h\"\n\n"); fprintf(file,"const static_asn %s[]={\n",structure_name); p=pointer; diff --git a/lib/cert_asn1.h b/lib/x509_asn1.h similarity index 100% rename from lib/cert_asn1.h rename to lib/x509_asn1.h diff --git a/lib/cert_b64.c b/lib/x509_b64.c similarity index 100% rename from lib/cert_b64.c rename to lib/x509_b64.c diff --git a/lib/cert_b64.h b/lib/x509_b64.h similarity index 100% rename from lib/cert_b64.h rename to lib/x509_b64.h diff --git a/lib/cert_der.c b/lib/x509_der.c similarity index 99% rename from lib/cert_der.c rename to lib/x509_der.c index 95bb8cb4d4..26260faccd 100644 --- a/lib/cert_der.c +++ b/lib/x509_der.c @@ -20,14 +20,14 @@ /*****************************************************/ -/* File: cert_der.c */ +/* File: x509_der.c */ /* Description: Functions to manage DER encoding */ /*****************************************************/ #include /* for memory debugging - and types */ -#include "cert_der.h" -#include "cert_asn1.h" +#include "x509_der.h" +#include "x509_asn1.h" #define TAG_BOOLEAN 0x01 diff --git a/lib/cert_der.h b/lib/x509_der.h similarity index 97% rename from lib/cert_der.h rename to lib/x509_der.h index e1f6305c61..bc2f3c77cd 100644 --- a/lib/cert_der.h +++ b/lib/x509_der.h @@ -7,7 +7,7 @@ #ifndef _GNUTLS_DER_H #define _GNUTLS_DER_H -#include "cert_asn1.h" +#include "x509_asn1.h" #define UNIVERSAL 0x00 #define APPLICATION 0x40 diff --git a/lib/x509_extensions.c b/lib/x509_extensions.c new file mode 100644 index 0000000000..d4d09eb6a3 --- /dev/null +++ b/lib/x509_extensions.c @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2001 Nikos Mavroyanopoulos + * + * This file is part of GNUTLS. + * + * GNUTLS is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GNUTLS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Here we only read subjectAltName, in case of + * dnsName. Otherwise we read nothing. + */ +static int _extract_subjectAltName( char* subjectAltName, opaque* extnValue, int extnValueLen) { +node_asn* ext; +char counter[MAX_INT_DIGITS]; +char name[1024]; +char str[1024]; +int len, k, result; + + subjectAltName[0] = 0; + + if (asn1_create_structure + ( _gnutls_get_pkix(), "PKIX1Implicit88.GeneralNames", &ext, + "san") != ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + result = asn1_get_der ( ext, extnValue, extnValueLen); + + if (result != ASN_OK) { + gnutls_assert(); + asn1_delete_structure(ext); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + k = 1; + for (;;) { + strcpy(name, "san.?"); + _gnutls_int2str(k, counter); + strcat(name, counter); + + len = sizeof(str) - 1; + result = asn1_read_value(ext, name, str, &len); + if (result == ASN_ELEMENT_NOT_FOUND) break; + + if (strcmp( str, "dNSName") == 0) { + strcat( name, "dNSName"); + len = sizeof( str) -1; + result = asn1_read_value(ext, name, str, &len); + + if (result != ASN_OK) { + gnutls_assert(); + asn1_delete_structure(ext); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + strncpy( subjectAltName, str, GMIN( len, X509_CN_SIZE-1)); + subjectAltName[X509_CN_SIZE-1] = 0; + + break; + } + k++; + } + + asn1_delete_structure(ext); + return 0; +} + +/* Here we only extract the KeyUsage field + */ +static int _extract_keyUsage( char* keyUsage, opaque* extnValue, int extnValueLen) { +node_asn* ext; +char str[128]; +int len, result; + + + if (asn1_create_structure + ( _gnutls_get_pkix(), "PKIX1Implicit88.KeyUsage", &ext, + "ku") != ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + result = asn1_get_der ( ext, extnValue, extnValueLen); + + if (result != ASN_OK) { + gnutls_assert(); + asn1_delete_structure(ext); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + len = sizeof(str) - 1; + result = asn1_read_value(ext, "ku", str, &len); + if (result != ASN_OK) { + gnutls_assert(); + asn1_delete_structure(ext); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + keyUsage[0] = str[0]; + + asn1_delete_structure(ext); + + return 0; +} + +static int _extract_basicConstraints( int* CA, opaque* extnValue, int extnValueLen) { +node_asn* ext; +char str[128]; +int len, result; + + + if (asn1_create_structure + ( _gnutls_get_pkix(), "PKIX1Implicit88.BasicConstraints", &ext, + "bc") != ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + result = asn1_get_der ( ext, extnValue, extnValueLen); + + if (result != ASN_OK) { + gnutls_assert(); + asn1_delete_structure(ext); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + len = sizeof(str) - 1; + result = asn1_read_value(ext, "bc.cA", str, &len); + if (result != ASN_OK) { + gnutls_assert(); + asn1_delete_structure(ext); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + asn1_delete_structure(ext); + + if ( strcmp(str, "TRUE")==0) *CA = 1; + else *CA = 0; + + + return 0; +} + + +static int _parse_extension( gnutls_cert* cert, char* extnID, char* critical, char* extnValue, int extnValueLen) { + + if (strcmp( extnID, "2 5 29 14")==0) { /* subject Key ID */ + /* we don't use it */ + return 0; + } + + if (strcmp( extnID, "2 5 29 15")==0) { /* Key Usage */ + return _extract_keyUsage( &cert->keyUsage, extnValue, extnValueLen); + } + + if (strcmp( extnID, "2 5 29 19")==0) { /* Basic Constraints */ + /* actually checks if a certificate belongs to + * a Certificate Authority. + */ + return _extract_basicConstraints( &cert->CA, extnValue, extnValueLen); + } + + if (strcmp( extnID, "2 5 29 17")==0) { /* subjectAltName */ + return _extract_subjectAltName( cert->subjectAltName, extnValue, extnValueLen); + } + +#ifdef DEBUG + _gnutls_log("CERT[%s]: Unsupported Extension: %s, %s\n", cert->cert_info.common_name, extnID, critical); +#endif + + if (strcmp( critical, "TRUE")==0) { + gnutls_assert(); + return GNUTLS_E_X509_UNSUPPORTED_CRITICAL_EXTENSION; + } + return 0; + +} + +/* This function will attempt to parse Extensions in + * an X509v3 certificate + */ +int _gnutls_get_ext_type( node_asn *rasn, char *root, gnutls_cert *cert) +{ + int k, result, len; + char name[128], name2[128], counter[MAX_INT_DIGITS]; + char str[1024]; + char critical[10]; + char extnID[128]; + char extnValue[128]; + + k = 0; + do { + k++; + + strcpy(name, root); + strcat(name, ".?"); + _gnutls_int2str(k, counter); + strcat(name, counter); + + len = sizeof(str) - 1; + result = asn1_read_value( rasn, name, str, &len); + + /* move to next + */ + + if (result==ASN_ELEMENT_NOT_FOUND) break; + + do { + + strcpy(name2, name); + strcat(name2, ".extnID"); + + len = sizeof(extnID) - 1; + result = asn1_read_value( rasn, name2, extnID, &len); + + if (result==ASN_ELEMENT_NOT_FOUND) break; + else + if (result != ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + strcpy(name2, name); + strcat(name2, ".critical"); + + len = sizeof(critical) - 1; + result = asn1_read_value( rasn, name2, critical, &len); + + if (result==ASN_ELEMENT_NOT_FOUND) break; + else + if (result != ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + strcpy(name2, name); + strcat(name2, ".extnValue"); + + len = sizeof( extnValue) - 1; + result = asn1_read_value( rasn, name2, extnValue, &len); + + if (result==ASN_ELEMENT_NOT_FOUND) break; + else + if (result != ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + /* Handle Extension */ + if ( (result=_parse_extension( cert, extnID, critical, extnValue, len)) < 0) { + gnutls_assert(); + return result; + } + + + } while (0); + } while (1); + + if (result==ASN_ELEMENT_NOT_FOUND) + return 0; + else + return GNUTLS_E_ASN1_PARSING_ERROR; +} diff --git a/lib/x509_extensions.h b/lib/x509_extensions.h new file mode 100644 index 0000000000..8935071025 --- /dev/null +++ b/lib/x509_extensions.h @@ -0,0 +1 @@ +int _gnutls_get_ext_type( node_asn *rasn, char *root, gnutls_cert *cert); diff --git a/lib/cert_verify.c b/lib/x509_verify.c similarity index 99% rename from lib/cert_verify.c rename to lib/x509_verify.c index b58cbf74fb..aa5a61c9c1 100644 --- a/lib/cert_verify.c +++ b/lib/x509_verify.c @@ -21,8 +21,8 @@ #include "gnutls_int.h" #include "gnutls_errors.h" #include "gnutls_cert.h" -#include "cert_asn1.h" -#include "cert_der.h" +#include "x509_asn1.h" +#include "x509_der.h" #include "gnutls_global.h" #include "gnutls_num.h" /* GMAX */ #include diff --git a/lib/cert_verify.h b/lib/x509_verify.h similarity index 100% rename from lib/cert_verify.h rename to lib/x509_verify.h