From d500de16725216503786dba48db519d3031614e7 Mon Sep 17 00:00:00 2001 From: Ben Laurie Date: Sat, 1 May 1999 18:08:44 +0000 Subject: [PATCH] Another stack. --- apps/req.c | 12 +++++++----- crypto/asn1/asn1_mac.h | 21 +++++++++++++++++++++ crypto/asn1/t_req.c | 8 ++++---- crypto/asn1/x_req.c | 20 ++++++++++++-------- crypto/x509/x509.h | 31 ++++++++++++++++--------------- crypto/x509/x509_r2x.c | 2 +- crypto/x509/x509_vfy.c | 3 +++ 7 files changed, 64 insertions(+), 33 deletions(-) diff --git a/apps/req.c b/apps/req.c index b7342f071d..c3f6a1a0ca 100644 --- a/apps/req.c +++ b/apps/req.c @@ -108,8 +108,9 @@ */ static int make_REQ(X509_REQ *req,EVP_PKEY *pkey,int attribs); -static int add_attribute_object(STACK *n, char *text, char *def, - char *value, int nid,int min,int max); +static int add_attribute_object(STACK_OF(X509_ATTRIBUTE) *n, char *text, + char *def, char *value, int nid, int min, + int max); static int add_DN_object(X509_NAME *n, char *text, char *def, char *value, int nid,int min,int max); static void MS_CALLBACK req_cb(int p,int n,char *arg); @@ -1022,8 +1023,9 @@ err: return(ret); } -static int add_attribute_object(STACK *n, char *text, char *def, char *value, - int nid, int min, int max) +static int add_attribute_object(STACK_OF(X509_ATTRIBUTE) *n, char *text, + char *def, char *value, int nid, int min, + int max) { int i,z; X509_ATTRIBUTE *xa=NULL; @@ -1098,7 +1100,7 @@ start: at=NULL; /* only one item per attribute */ - if (!sk_push(n,(char *)xa)) goto err; + if (!sk_X509_ATTRIBUTE_push(n,xa)) goto err; return(1); err: if (xa != NULL) X509_ATTRIBUTE_free(xa); diff --git a/crypto/asn1/asn1_mac.h b/crypto/asn1/asn1_mac.h index f0ab1e9069..2689f22e48 100644 --- a/crypto/asn1/asn1_mac.h +++ b/crypto/asn1/asn1_mac.h @@ -210,6 +210,10 @@ err:\ M_ASN1_D2I_get_imp_set(r,func,free_func,\ x,V_ASN1_CONTEXT_SPECIFIC); +#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ + M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ + x,V_ASN1_CONTEXT_SPECIFIC); + #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ c.q=c.p; \ if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ @@ -328,11 +332,20 @@ err:\ #define M_ASN1_I2D_len_IMP_SET(a,f,x) \ ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); +#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC,IS_SET); + #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ if ((a != NULL) && (sk_num(a) != 0)) \ ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ IS_SET); +#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC,IS_SET); + #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ IS_SEQUENCE); @@ -385,6 +398,8 @@ err:\ V_ASN1_UNIVERSAL,IS_SET) #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ V_ASN1_CONTEXT_SPECIFIC,IS_SET) +#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ + i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) @@ -404,6 +419,12 @@ err:\ { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ IS_SET); } +#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ + V_ASN1_CONTEXT_SPECIFIC, \ + IS_SET); } + #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ if ((a != NULL) && (sk_num(a) != 0)) \ { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ diff --git a/crypto/asn1/t_req.c b/crypto/asn1/t_req.c index 6e04b0861c..b83684416d 100644 --- a/crypto/asn1/t_req.c +++ b/crypto/asn1/t_req.c @@ -89,7 +89,7 @@ int X509_REQ_print(BIO *bp, X509_REQ *x) const char *neg; X509_REQ_INFO *ri; EVP_PKEY *pkey; - STACK *sk; + STACK_OF(X509_ATTRIBUTE) *sk; char str[128]; ri=x->req_info; @@ -142,7 +142,7 @@ int X509_REQ_print(BIO *bp, X509_REQ *x) if (BIO_puts(bp,str) <= 0) goto err; sk=x->req_info->attributes; - if ((sk == NULL) || (sk_num(sk) == 0)) + if ((sk == NULL) || (sk_X509_ATTRIBUTE_num(sk) == 0)) { if (!x->req_info->req_kludge) { @@ -152,7 +152,7 @@ int X509_REQ_print(BIO *bp, X509_REQ *x) } else { - for (i=0; iobject)) > 0) diff --git a/crypto/asn1/x_req.c b/crypto/asn1/x_req.c index 0f14e307e1..9b1d6abe64 100644 --- a/crypto/asn1/x_req.c +++ b/crypto/asn1/x_req.c @@ -78,11 +78,12 @@ int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp) */ if (a->req_kludge) { - M_ASN1_I2D_len_IMP_SET_opt(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,i2d_X509_ATTRIBUTE,0); } else { - M_ASN1_I2D_len_IMP_SET(a->attributes, i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET_type(X509_ATTRIBUTE,a->attributes, + i2d_X509_ATTRIBUTE,0); } M_ASN1_I2D_seq_total(); @@ -98,11 +99,13 @@ int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp) */ if (a->req_kludge) { - M_ASN1_I2D_put_IMP_SET_opt(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes, + i2d_X509_ATTRIBUTE,0); } else { - M_ASN1_I2D_put_IMP_SET(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET_type(X509_ATTRIBUTE,a->attributes, + i2d_X509_ATTRIBUTE,0); } M_ASN1_I2D_finish(); @@ -130,8 +133,9 @@ X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, unsigned char **pp, ret->req_kludge=1; else { - M_ASN1_D2I_get_IMP_set(ret->attributes,d2i_X509_ATTRIBUTE, - X509_ATTRIBUTE_free,0); + M_ASN1_D2I_get_IMP_set_type(X509_ATTRIBUTE,ret->attributes, + d2i_X509_ATTRIBUTE, + X509_ATTRIBUTE_free,0); } M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO); @@ -146,7 +150,7 @@ X509_REQ_INFO *X509_REQ_INFO_new(void) M_ASN1_New(ret->version,ASN1_INTEGER_new); M_ASN1_New(ret->subject,X509_NAME_new); M_ASN1_New(ret->pubkey,X509_PUBKEY_new); - M_ASN1_New(ret->attributes,sk_new_null); + M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null); ret->req_kludge=0; return(ret); M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW); @@ -158,7 +162,7 @@ void X509_REQ_INFO_free(X509_REQ_INFO *a) ASN1_INTEGER_free(a->version); X509_NAME_free(a->subject); X509_PUBKEY_free(a->pubkey); - sk_pop_free(a->attributes,X509_ATTRIBUTE_free); + sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free); Free((char *)a); } diff --git a/crypto/x509/x509.h b/crypto/x509/x509.h index df04cfed01..5c2894ba73 100644 --- a/crypto/x509/x509.h +++ b/crypto/x509/x509.h @@ -167,13 +167,28 @@ typedef struct X509_extension_st void (*ex_free)(); /* clear argp stuff */ } X509_EXTENSION; +/* a sequence of these are used */ +typedef struct x509_attributes_st + { + ASN1_OBJECT *object; + int set; /* 1 for a set, 0 for a single item (which is wrong) */ + union { + char *ptr; +/* 1 */ STACK /* ASN1_TYPE */ *set; +/* 0 */ ASN1_TYPE *single; + } value; + } X509_ATTRIBUTE; + +DECLARE_STACK_OF(X509_ATTRIBUTE) +DECLARE_ASN1_SET_OF(X509_ATTRIBUTE) + typedef struct X509_req_info_st { ASN1_INTEGER *version; X509_NAME *subject; X509_PUBKEY *pubkey; /* d=2 hl=2 l= 0 cons: cont: 00 */ - STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ + STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ int req_kludge; } X509_REQ_INFO; @@ -240,20 +255,6 @@ typedef struct X509_crl_st int references; } X509_CRL; -/* a sequence of these are used */ -typedef struct x509_attributes_st - { - ASN1_OBJECT *object; - int set; /* 1 for a set, 0 for a single item (which is wrong) */ - union { - char *ptr; -/* 1 */ STACK /* ASN1_TYPE */ *set; -/* 0 */ ASN1_TYPE *single; - } value; - } X509_ATTRIBUTE; - -DECLARE_STACK_OF(X509_ATTRIBUTE) - typedef struct private_key_st { int version; diff --git a/crypto/x509/x509_r2x.c b/crypto/x509/x509_r2x.c index ec92d2f8a8..bb4697ae60 100644 --- a/crypto/x509/x509_r2x.c +++ b/crypto/x509/x509_r2x.c @@ -80,7 +80,7 @@ X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) /* duplicate the request */ xi=ret->cert_info; - if (sk_num(r->req_info->attributes) != 0) + if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0) { if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err; if (!ASN1_INTEGER_set(xi->version,2)) goto err; diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index 16fef853dd..7bee6158a4 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -628,5 +628,8 @@ void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) IMPLEMENT_STACK_OF(X509) IMPLEMENT_ASN1_SET_OF(X509) + IMPLEMENT_STACK_OF(X509_NAME) + IMPLEMENT_STACK_OF(X509_ATTRIBUTE) +IMPLEMENT_ASN1_SET_OF(X509_ATTRIBUTE) -- 2.34.1