Add support for the noCheck OCSP extension. This is
[openssl.git] / crypto / x509v3 / v3_crld.c
index c0b63ee23cdf1dc60d7e83f53604e6987ff77f82..4f53dcf6dfddcb97b3acfeeb64c5593a43b0b1b0 100644 (file)
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "conf.h"
-#include "asn1.h"
-#include "asn1_mac.h"
-#include "x509v3.h"
+#include <openssl/conf.h>
+#include <openssl/asn1.h>
+#include <openssl/asn1t.h>
+#include <openssl/x509v3.h>
 
-static STACK *i2v_crld(X509V3_EXT_METHOD *method, STACK_OF(DIST_POINT) *crld,
-                                                        STACK *extlist);
+static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
+               STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist);
 static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
-                                                X509V3_CTX *ctx, STACK *nval);
+                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
 
 X509V3_EXT_METHOD v3_crld = {
-NID_crl_distribution_points, X509V3_EXT_MULTILINE,
-(X509V3_EXT_NEW)CRL_DIST_POINTS_new,
-CRL_DIST_POINTS_free,
-(X509V3_EXT_D2I)d2i_CRL_DIST_POINTS,
-i2d_CRL_DIST_POINTS,
-NULL, NULL,
+NID_crl_distribution_points, X509V3_EXT_MULTILINE, &CRL_DIST_POINTS_it,
+0,0,0,0,
+0,0,
 (X509V3_EXT_I2V)i2v_crld,
 (X509V3_EXT_V2I)v2i_crld,
-NULL, NULL, NULL
+0,0,
+NULL
 };
 
-/*
- * ASN1err(ASN1_F_DIST_POINT_NEW,ERR_R_MALLOC_FAILURE);
- * ASN1err(ASN1_F_D2I_DIST_POINT,ERR_R_MALLOC_FAILURE);
- * ASN1err(ASN1_F_DIST_POINT_NAME_NEW,ERR_R_MALLOC_FAILURE);
- * ASN1err(ASN1_F_D2I_DIST_POINT_NAME,ERR_R_MALLOC_FAILURE);
- */
-
-static STACK *i2v_crld(X509V3_EXT_METHOD *method, STACK_OF(DIST_POINT) *crld,
-                                                                STACK *exts)
+static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
+                       STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
 {
        DIST_POINT *point;
        int i;
        for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
                point = sk_DIST_POINT_value(crld, i);
-               if(point->distpoint->fullname) {
-                       exts = i2v_GENERAL_NAMES(NULL,
-                                        point->distpoint->fullname, exts);
+               if(point->distpoint) {
+                       if(point->distpoint->type == 0)
+                               exts = i2v_GENERAL_NAMES(NULL,
+                                        point->distpoint->name.fullname, exts);
+                       else X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
                }
                if(point->reasons) 
                        X509V3_add_value("reasons","<UNSUPPORTED>", &exts);
                if(point->CRLissuer)
                        X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts);
-               if(point->distpoint->relativename)
-                       X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
        }
        return exts;
 }
 
 static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
-                                                X509V3_CTX *ctx, STACK *nval)
+                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
 {
        STACK_OF(DIST_POINT) *crld = NULL;
-       STACK_OF(GENERAL_NAME) *gens = NULL;
+       GENERAL_NAMES *gens = NULL;
        GENERAL_NAME *gen = NULL;
        CONF_VALUE *cnf;
        int i;
-       if(!(crld = sk_DIST_POINT_new(NULL))) goto merr;
-       for(i = 0; i < sk_num(nval); i++) {
+       if(!(crld = sk_DIST_POINT_new_null())) goto merr;
+       for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
                DIST_POINT *point;
-               cnf = (CONF_VALUE *)sk_value(nval, i);
+               cnf = sk_CONF_VALUE_value(nval, i);
                if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err; 
                if(!(gens = GENERAL_NAMES_new())) goto merr;
                if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
@@ -130,7 +121,8 @@ static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
                        goto merr;
                }
                if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr;
-               point->distpoint->fullname = gens;
+               point->distpoint->name.fullname = gens;
+               point->distpoint->type = 0;
                gens = NULL;
        }
        return crld;
@@ -144,147 +136,27 @@ static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
        return NULL;
 }
 
-int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp)
-{
-
-return i2d_ASN1_SET_OF_DIST_POINT(a, pp, i2d_DIST_POINT, V_ASN1_SEQUENCE,
-                                                 V_ASN1_UNIVERSAL, IS_SEQUENCE);}
-
-STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void)
-{
-       return sk_DIST_POINT_new_null();
-}
-
-void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a)
-{
-       sk_DIST_POINT_pop_free(a, DIST_POINT_free);
-}
-
-STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a,
-               unsigned char **pp,long length)
-{
-return d2i_ASN1_SET_OF_DIST_POINT(a, pp, length, d2i_DIST_POINT,
-                         DIST_POINT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
-
-}
-
 IMPLEMENT_STACK_OF(DIST_POINT)
 IMPLEMENT_ASN1_SET_OF(DIST_POINT)
 
-int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp)
-{
-       int v = 0;
-       M_ASN1_I2D_vars(a);
-       /* NB: underlying type is a CHOICE so need EXPLICIT tagging */
-       M_ASN1_I2D_len_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
-       M_ASN1_I2D_len_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING);
-       M_ASN1_I2D_len_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES);
 
-       M_ASN1_I2D_seq_total();
+ASN1_CHOICE(DIST_POINT_NAME) = {
+       ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0),
+       ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1)
+} ASN1_CHOICE_END(DIST_POINT_NAME);
 
-       M_ASN1_I2D_put_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
-       M_ASN1_I2D_put_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING, 1);
-       M_ASN1_I2D_put_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES, 2);
+IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME)
 
-       M_ASN1_I2D_finish();
-}
+ASN1_SEQUENCE(DIST_POINT) = {
+       ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0),
+       ASN1_IMP_OPT(DIST_POINT, reasons, ASN1_BIT_STRING, 1),
+       ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, distpoint, GENERAL_NAME, 2)
+} ASN1_SEQUENCE_END(DIST_POINT);
 
-DIST_POINT *DIST_POINT_new(void)
-{
-       DIST_POINT *ret=NULL;
-       ASN1_CTX c;
-       M_ASN1_New_Malloc(ret, DIST_POINT);
-       ret->distpoint = NULL;
-       ret->reasons = NULL;
-       ret->CRLissuer = NULL;
-       return (ret);
-       M_ASN1_New_Error(ASN1_F_DIST_POINT_NEW);
-}
+IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT)
 
-DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length)
-{
-       M_ASN1_D2I_vars(a,DIST_POINT *,DIST_POINT_new);
-       M_ASN1_D2I_Init();
-       M_ASN1_D2I_start_sequence();
-       M_ASN1_D2I_get_EXP_opt (ret->distpoint, d2i_DIST_POINT_NAME, 0);
-       M_ASN1_D2I_get_IMP_opt (ret->reasons, d2i_ASN1_BIT_STRING, 1,
-                                                       V_ASN1_BIT_STRING);
-       M_ASN1_D2I_get_IMP_opt (ret->CRLissuer, d2i_GENERAL_NAMES, 2,
-                                                       V_ASN1_SEQUENCE);
-       M_ASN1_D2I_Finish(a, DIST_POINT_free, ASN1_F_D2I_DIST_POINT);
-}
+ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) = 
+       ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, DIST_POINT, DIST_POINT)
+ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS);
 
-void DIST_POINT_free(DIST_POINT *a)
-{
-       if (a == NULL) return;
-       DIST_POINT_NAME_free(a->distpoint);
-       ASN1_BIT_STRING_free(a->reasons);
-       sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free);
-       Free ((char *)a);
-}
-
-int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
-{
-       int v = 0;
-       M_ASN1_I2D_vars(a);
-
-       if(a->fullname) {
-               M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES);
-       } else {
-               M_ASN1_I2D_len_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
-       }
-
-       /* Don't want a SEQUENCE so... */
-       if(pp == NULL) return ret;
-       p = *pp;
-
-       if(a->fullname) {
-               M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0);
-       } else {
-               M_ASN1_I2D_put_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
-       }
-       M_ASN1_I2D_finish();
-}
-
-DIST_POINT_NAME *DIST_POINT_NAME_new(void)
-{
-       DIST_POINT_NAME *ret=NULL;
-       ASN1_CTX c;
-       M_ASN1_New_Malloc(ret, DIST_POINT_NAME);
-       ret->fullname = NULL;
-       ret->relativename = NULL;
-       return (ret);
-       M_ASN1_New_Error(ASN1_F_DIST_POINT_NAME_NEW);
-}
-
-void DIST_POINT_NAME_free(DIST_POINT_NAME *a)
-{
-       if (a == NULL) return;
-       X509_NAME_free(a->relativename);
-       sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free);
-       Free ((char *)a);
-}
-
-DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
-            long length)
-{
-        unsigned char _tmp, tag;
-        M_ASN1_D2I_vars(a,DIST_POINT_NAME *,DIST_POINT_NAME_new);
-        M_ASN1_D2I_Init();
-        c.slen = length;
-
-        _tmp = M_ASN1_next;
-        tag = _tmp & ~V_ASN1_CONSTRUCTED;
-       
-       if(tag == (0|V_ASN1_CONTEXT_SPECIFIC)) {
-               M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES,
-                                                       V_ASN1_SEQUENCE);
-       } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) {
-               M_ASN1_D2I_get_EXP_opt (ret->relativename, d2i_X509_NAME, 1);
-       } else {
-               c.error = ASN1_R_BAD_TAG;
-               goto err;
-       }
-
-       M_ASN1_D2I_Finish(a, DIST_POINT_NAME_free, ASN1_F_D2I_DIST_POINT_NAME);
-}
+IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS)