]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
renamed cert_* to x509_*
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 5 Aug 2001 09:38:22 +0000 (09:38 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 5 Aug 2001 09:38:22 +0000 (09:38 +0000)
22 files changed:
lib/Makefile.am
lib/auth_rsa.c
lib/auth_srp_passwd.c
lib/gnutls_cert.c
lib/gnutls_cert.h
lib/gnutls_global.c
lib/gnutls_global.h
lib/gnutls_privkey.c
lib/gnutls_sig_check.c
lib/pkcs1_asn1_tab.c
lib/pkix_asn1_tab.c
lib/x509_ASN.y [moved from lib/cert_ASN.y with 99% similarity]
lib/x509_asn1.c [moved from lib/cert_asn1.c with 99% similarity]
lib/x509_asn1.h [moved from lib/cert_asn1.h with 100% similarity]
lib/x509_b64.c [moved from lib/cert_b64.c with 100% similarity]
lib/x509_b64.h [moved from lib/cert_b64.h with 100% similarity]
lib/x509_der.c [moved from lib/cert_der.c with 99% similarity]
lib/x509_der.h [moved from lib/cert_der.h with 97% similarity]
lib/x509_extensions.c [new file with mode: 0644]
lib/x509_extensions.h [new file with mode: 0644]
lib/x509_verify.c [moved from lib/cert_verify.c with 99% similarity]
lib/x509_verify.h [moved from lib/cert_verify.h with 100% similarity]

index a5ab36780ae78491b8efb780bdfbaaab6c044f2e..d8f18797fc7916dc526a3f77e94a7d7ef545a7d6 100644 (file)
@@ -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)
 
index 863b2eddceaa5320532ebf1e273a648e70a5e19b..dd12b4f8e585c4519d4d36fdf69ae0918f89035e 100644 (file)
 #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 <gnutls_random.h>
 #include <gnutls_pk.h>
 #include <gnutls_algorithms.h>
 #include <gnutls_global.h>
-#include <cert_verify.h>
+#include <x509_verify.h>
 #include "debug.h"
 
 int gen_rsa_certificate(GNUTLS_KEY, opaque **);
index 358ee1c96d1e3bb31e3132f2d1f44c137472bc37..3f4726ce1bcffe212388180fbf40ec7e6b622458 100644 (file)
@@ -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"
index ed07b777c97c0997aeaa8e40fd9a57b7eaad02f3..43912d5caac5c5d204e51755964067fcd43828a6 100644 (file)
 
 #include <gnutls_int.h>
 #include <gnutls_errors.h>
-#include <cert_b64.h>
+#include <x509_b64.h>
 #include <auth_x509.h>
 #include <gnutls_cert.h>
-#include <cert_asn1.h>
-#include <cert_der.h>
+#include <x509_asn1.h>
+#include <x509_der.h>
 #include <gnutls_datum.h>
 #include <gnutls_gcry.h>
 #include <gnutls_privkey.h>
 #include <gnutls_global.h>
-#include <cert_verify.h>
-#include <gnutls_num.h>
+#include <x509_verify.h>
+#include <x509_extensions.h>
 
 /* 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;
index 362458ff14d044e6d40ae76b6f8b6763c7cac90d..d3a30b0ef81cd225b38e3c01e85e3ff1ee8b873d 100644 (file)
@@ -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
index 4bd10e32377484a2f3f7c3babcd9b68717929934..b545912c75ee248bb64d216df017cd3b15a12414 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <gnutls_int.h>
 #include <gnutls_errors.h>
-#include <cert_asn1.h>
+#include <x509_asn1.h>
 #ifdef HAVE_SIGNAL_H
 # include <signal.h>
 #endif
index ba00f573f96ec4702e8576ac2e5237eee987eb36..dcb012ec32b34c1fc370e7171b8b69dab8b27a69 100644 (file)
@@ -1,5 +1,10 @@
-#include <cert_asn1.h>
+#ifndef GNUTLS_GLOBAL_H
+# define GNUTLS_GLOBAL_H
+
+#include <x509_asn1.h>
 
 int gnutls_is_secure_memory(const void* mem);
 node_asn* _gnutls_get_pkcs();
 node_asn* _gnutls_get_pkix();
+
+#endif
index 406fce64efeb17cbbe9cfef23bc28bdc3045084f..b26d9432c0ca830bd05761737261d14d4774e9e3 100644 (file)
 
 #include <gnutls_int.h>
 #include <gnutls_errors.h>
-#include <cert_b64.h>
+#include <x509_b64.h>
 #include <auth_x509.h>
 #include <gnutls_cert.h>
-#include <cert_asn1.h>
-#include <cert_der.h>
+#include <x509_asn1.h>
+#include <x509_der.h>
 #include <gnutls_datum.h>
 #include <gnutls_gcry.h>
 #include <gnutls_global.h>
index fe30bba45c203681f76f2926764bbd9cd800ee2a..9b3273624dceef40739264df039c4de8f9c6d463 100644 (file)
 
 #include <gnutls_int.h>
 #include <gnutls_errors.h>
-#include <cert_b64.h>
+#include <x509_b64.h>
 #include <auth_x509.h>
 #include <gnutls_cert.h>
-#include <cert_asn1.h>
-#include <cert_der.h>
+#include <x509_asn1.h>
+#include <x509_der.h>
 #include <gnutls_datum.h>
 #include <gnutls_gcry.h>
 #include <gnutls_privkey.h>
index 2fe359872d81b74e18ea470fab16364104fd81e6..3e1d2b1208a686d612d5c3d7c62aad81b3f5e3d1 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "cert_asn1.h"
+#include "x509_asn1.h"
 
 const static_asn pkcs1_asn1_tab[]={
   {"PKCS-1",536872976,0},
index d03905e5e80569bf29ba9d8c8c2c9a37057e6968..727a980f4c900c7d30c34bf6f1e42d81fb78959f 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "cert_asn1.h"
+#include "x509_asn1.h"
 
 const static_asn pkix_asn1_tab[]={
   {"PKIX1Implicit88",536875024,0},
similarity index 99%
rename from lib/cert_ASN.y
rename to lib/x509_ASN.y
index 407b342a87dab2667fa509dcef29924165ad900f..52d240d6fc6c3d9387b37f96085787ca5141c49c 100755 (executable)
@@ -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 <gnutls_int.h>
-#include "cert_asn1.h"
+#include "x509_asn1.h"
 
 FILE *file_asn1;  /* Pointer to file to parse */
 extern int parse_mode;
similarity index 99%
rename from lib/cert_asn1.c
rename to lib/x509_asn1.c
index 857c71a0587f1d5ca9b0f28c8683bf0211b46bc2..1a9f36be12216efcae0fa8840074cbd2b6535629 100755 (executable)
 
 
 /*****************************************************/
-/* File: cert_asn1.c                                 */
+/* File: x509_asn1.c                                 */
 /* Description: Functions to manage ASN.1 DEFINITIONS*/
 /*****************************************************/
 
 
 #include <gnutls_int.h> 
 
-#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;
similarity index 100%
rename from lib/cert_asn1.h
rename to lib/x509_asn1.h
similarity index 100%
rename from lib/cert_b64.c
rename to lib/x509_b64.c
similarity index 100%
rename from lib/cert_b64.h
rename to lib/x509_b64.h
similarity index 99%
rename from lib/cert_der.c
rename to lib/x509_der.c
index 95bb8cb4d4b82b8390e5e807904b754fd3a8526f..26260faccdd137bef911c61a92ef171f8e5bae60 100644 (file)
 
 
 /*****************************************************/
-/* File: cert_der.c                                  */
+/* File: x509_der.c                                  */
 /* Description: Functions to manage DER encoding     */
 /*****************************************************/
  
 #include <gnutls_int.h> /* 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
similarity index 97%
rename from lib/cert_der.h
rename to lib/x509_der.h
index e1f6305c61009830e31316a5c78476e5dfb859c1..bc2f3c77cd60b0e4573750718904abd0c9f6ec55 100644 (file)
@@ -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 (file)
index 0000000..d4d09eb
--- /dev/null
@@ -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 <gnutls_int.h>
+#include <x509_asn1.h>
+#include <x509_der.h>
+#include <gnutls_num.h>
+#include <gnutls_cert.h>
+#include <gnutls_errors.h>
+#include <gnutls_global.h>
+
+/* 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 (file)
index 0000000..8935071
--- /dev/null
@@ -0,0 +1 @@
+int _gnutls_get_ext_type( node_asn *rasn, char *root, gnutls_cert *cert);
similarity index 99%
rename from lib/cert_verify.c
rename to lib/x509_verify.c
index b58cbf74fb9060ef5d61829e2e1e7ccf1db8ec06..aa5a61c9c1774547298360766b319527627aeaf7 100644 (file)
@@ -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 <gnutls_sig.h>
similarity index 100%
rename from lib/cert_verify.h
rename to lib/x509_verify.h