Add EX_DATA support to X509.
authorDr. Stephen Henson <steve@openssl.org>
Mon, 11 Oct 1999 01:30:04 +0000 (01:30 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 11 Oct 1999 01:30:04 +0000 (01:30 +0000)
Fix a bug in the X509_get_d2i() functions which didn't check if crit was NULL.

CHANGES
crypto/asn1/x_x509.c
crypto/x509/x509.h
crypto/x509v3/v3_lib.c

diff --git a/CHANGES b/CHANGES
index 7cbe4ded329eb8559451e1b6d408341e40fe7526..12abb958400feb10fec50a57e9f3e6637078dc13 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,10 @@
 
  Changes between 0.9.4 and 0.9.5  [xx XXX 1999]
 
+  *) Add a CRYPTO_EX_DATA to X509 certificate structure and associated
+     functions.
+     [Steve Henson]
+
   *) New X509V3_{X509,CRL,REVOKED}_get_d2i() functions. These will search
      for, obtain and decode and extension and obtain its critical flag.
      This allows all the necessary extension code to be handled in a
index 7abf6b2a6babfa626a406c4f581c9bd588b6a9be..c428997c007b45c315113d509053f298bd07c99f 100644 (file)
@@ -62,6 +62,9 @@
 #include <openssl/asn1_mac.h>
 #include <openssl/x509.h>
 
+static int x509_meth_num = 0;
+static STACK *x509_meth = NULL;
+
 static ASN1_METHOD meth={
        (int (*)())  i2d_X509,
        (char *(*)())d2i_X509,
@@ -117,6 +120,7 @@ X509 *X509_new(void)
        M_ASN1_New(ret->cert_info,X509_CINF_new);
        M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
        M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
+       CRYPTO_new_ex_data(x509_meth, (char *)ret, &ret->ex_data);
        return(ret);
        M_ASN1_New_Error(ASN1_F_X509_NEW);
        }
@@ -140,7 +144,7 @@ void X509_free(X509 *a)
                }
 #endif
 
-       /* CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); */
+       CRYPTO_free_ex_data(x509_meth,(char *)a,&a->ex_data);
        X509_CINF_free(a->cert_info);
        X509_ALGOR_free(a->sig_alg);
        ASN1_BIT_STRING_free(a->signature);
@@ -149,3 +153,21 @@ void X509_free(X509 *a)
        Free((char *)a);
        }
 
+int X509_get_ex_new_index(long argl, char *argp, int (*new_func)(),
+            int (*dup_func)(), void (*free_func)())
+        {
+       x509_meth_num++;
+       return(CRYPTO_get_ex_new_index(x509_meth_num-1,
+               &x509_meth,argl,argp,new_func,dup_func,free_func));
+        }
+
+int X509_set_ex_data(X509 *r, int idx, char *arg)
+       {
+       return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
+       }
+
+char *X509_get_ex_data(X509 *r, int idx)
+       {
+       return(CRYPTO_get_ex_data(&r->ex_data,idx));
+       }
+
index 17319fee11ec3d72e40d05642cf767e3135866a7..36772b57ea286b2524f61503897db523193e0947 100644 (file)
@@ -238,6 +238,7 @@ typedef struct x509_st
        int valid;
        int references;
        char *name;
+       CRYPTO_EX_DATA ex_data;
        } X509;
 
 DECLARE_STACK_OF(X509)
@@ -724,6 +725,10 @@ X509 *             X509_new(void);
 void           X509_free(X509 *a);
 int            i2d_X509(X509 *a,unsigned char **pp);
 X509 *         d2i_X509(X509 **a,unsigned char **pp,long length);
+int X509_get_ex_new_index(long argl, char *argp, int (*new_func)(),
+            int (*dup_func)(), void (*free_func)());
+int X509_set_ex_data(X509 *r, int idx, char *arg);
+char *X509_get_ex_data(X509 *r, int idx);
 
 X509_REVOKED * X509_REVOKED_new(void);
 void           X509_REVOKED_free(X509_REVOKED *a);
index 06def2a659c67174626184bda3d5f285e6b7fb0f..6219d27883e568365d538970658d0a13605a1395 100644 (file)
@@ -219,7 +219,7 @@ void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
        }
        if(found_ex) {
                /* Found it */
-               *crit = found_ex->critical;
+               if(crit) *crit = found_ex->critical;
                return X509V3_EXT_d2i(found_ex);
        }