diff options
author | Dr. Stephen Henson <steve@openssl.org> | 1999-05-09 16:39:11 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 1999-05-09 16:39:11 +0000 |
commit | c8b41850793faed7fccf4fe4403f774266412f22 (patch) | |
tree | 13fb852b77834ea483e7d194453cee1d0dda5678 /crypto/x509v3 | |
parent | 1c10afc32a40d9bf27848790d84ec19ecc4c9768 (diff) | |
download | openssl-c8b41850793faed7fccf4fe4403f774266412f22.tar.gz |
Kill evil casts, fix PKCS#7 and add new X509V3 Function.
Diffstat (limited to 'crypto/x509v3')
-rw-r--r-- | crypto/x509v3/v3_bitst.c | 4 | ||||
-rw-r--r-- | crypto/x509v3/v3_conf.c | 46 | ||||
-rw-r--r-- | crypto/x509v3/v3_enum.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/v3err.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/x509v3.h | 5 |
5 files changed, 46 insertions, 13 deletions
diff --git a/crypto/x509v3/v3_bitst.c b/crypto/x509v3/v3_bitst.c index 29d8bd44ca..641f877c13 100644 --- a/crypto/x509v3/v3_bitst.c +++ b/crypto/x509v3/v3_bitst.c @@ -103,7 +103,7 @@ static STACK *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, ASN1_BIT_STRING *bits, STACK *ret) { BIT_STRING_BITNAME *bnam; - for(bnam =(BIT_STRING_BITNAME *)method->usr_data; bnam->lname; bnam++) { + for(bnam =method->usr_data; bnam->lname; bnam++) { if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum)) X509V3_add_value(bnam->lname, NULL, &ret); } @@ -123,7 +123,7 @@ static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, } for(i = 0; i < sk_num(nval); i++) { val = (CONF_VALUE *)sk_value(nval, i); - for(bnam = (BIT_STRING_BITNAME *)method->usr_data; bnam->lname; + for(bnam = method->usr_data; bnam->lname; bnam++) { if(!strcmp(bnam->sname, val->name) || !strcmp(bnam->lname, val->name) ) { diff --git a/crypto/x509v3/v3_conf.c b/crypto/x509v3/v3_conf.c index d63db97340..0460fbedfc 100644 --- a/crypto/x509v3/v3_conf.c +++ b/crypto/x509v3/v3_conf.c @@ -72,6 +72,8 @@ static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, in static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type); static char *conf_lhash_get_string(void *db, char *section, char *value); static STACK *conf_lhash_get_section(void *db, char *section); +static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid, + int crit, void *ext_struc); /* LHASH *conf: Config file */ /* char *name: Name */ /* char *value: Value */ @@ -111,13 +113,10 @@ X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value) { - X509_EXTENSION *ext = NULL; X509V3_EXT_METHOD *method; + X509_EXTENSION *ext; STACK *nval; - char *ext_struc; - unsigned char *ext_der, *p; - int ext_len; - ASN1_OCTET_STRING *ext_oct; + void *ext_struc; if(ext_nid == NID_undef) { X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME); return NULL; @@ -152,21 +151,50 @@ static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, return NULL; } - /* We've now got the internal representation: convert to DER */ + ext = do_ext_i2d(method, ext_nid, crit, ext_struc); + method->ext_free(ext_struc); + return ext; + +} + +static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid, + int crit, void *ext_struc) +{ + unsigned char *ext_der, *p; + int ext_len; + ASN1_OCTET_STRING *ext_oct; + X509_EXTENSION *ext; + /* Convert internal representation to DER */ ext_len = method->i2d(ext_struc, NULL); - ext_der = Malloc(ext_len); + if(!(ext_der = Malloc(ext_len))) goto merr; p = ext_der; method->i2d(ext_struc, &p); - method->ext_free(ext_struc); - ext_oct = ASN1_OCTET_STRING_new(); + if(!(ext_oct = ASN1_OCTET_STRING_new())) goto merr; ext_oct->data = ext_der; ext_oct->length = ext_len; ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct); + if(!ext) goto merr; ASN1_OCTET_STRING_free(ext_oct); return ext; + merr: + X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE); + return NULL; + +} + +/* Given an internal structure, nid and critical flag create an extension */ + +X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc) +{ + X509V3_EXT_METHOD *method; + if(!(method = X509V3_EXT_get_nid(ext_nid))) { + X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION); + return NULL; + } + return do_ext_i2d(method, ext_nid, crit, ext_struc); } /* Check the extension string for critical flag */ diff --git a/crypto/x509v3/v3_enum.c b/crypto/x509v3/v3_enum.c index e68e04f401..e76229da76 100644 --- a/crypto/x509v3/v3_enum.c +++ b/crypto/x509v3/v3_enum.c @@ -95,7 +95,7 @@ char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method, ENUMERATED_NAMES *enam; long strval; strval = ASN1_ENUMERATED_get(e); - for(enam =(ENUMERATED_NAMES *)method->usr_data; enam->lname; enam++) { + for(enam = method->usr_data; enam->lname; enam++) { if(strval == enam->bitnum) return BUF_strdup(enam->lname); } return i2s_ASN1_ENUMERATED(method, e); diff --git a/crypto/x509v3/v3err.c b/crypto/x509v3/v3err.c index b20b59c250..50efa8d99d 100644 --- a/crypto/x509v3/v3err.c +++ b/crypto/x509v3/v3err.c @@ -68,6 +68,7 @@ static ERR_STRING_DATA X509V3_str_functs[]= {ERR_PACK(0,X509V3_F_COPY_EMAIL,0), "COPY_EMAIL"}, {ERR_PACK(0,X509V3_F_COPY_ISSUER,0), "COPY_ISSUER"}, {ERR_PACK(0,X509V3_F_DO_EXT_CONF,0), "DO_EXT_CONF"}, +{ERR_PACK(0,X509V3_F_DO_EXT_I2D,0), "DO_EXT_I2D"}, {ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"}, {ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"}, {ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"}, @@ -98,6 +99,7 @@ static ERR_STRING_DATA X509V3_str_functs[]= {ERR_PACK(0,X509V3_F_X509V3_EXT_ADD,0), "X509V3_EXT_add"}, {ERR_PACK(0,X509V3_F_X509V3_EXT_ADD_ALIAS,0), "X509V3_EXT_add_alias"}, {ERR_PACK(0,X509V3_F_X509V3_EXT_CONF,0), "X509V3_EXT_conf"}, +{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"}, {ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"}, {ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"}, {0,NULL} diff --git a/crypto/x509v3/x509v3.h b/crypto/x509v3/x509v3.h index 80bb36e78e..d294a3cff1 100644 --- a/crypto/x509v3/x509v3.h +++ b/crypto/x509v3/x509v3.h @@ -104,7 +104,7 @@ X509V3_EXT_V2I v2i; X509V3_EXT_I2R i2r; X509V3_EXT_R2I r2i; -char *usr_data; /* Any extension specific data */ +void *usr_data; /* Any extension specific data */ }; typedef struct X509V3_CONF_METHOD_st { @@ -411,6 +411,7 @@ X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); int X509V3_add_standard_extensions(void); STACK *X509V3_parse_list(char *line); void *X509V3_EXT_d2i(X509_EXTENSION *ext); +X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); char *hex_to_string(unsigned char *buffer, long len); unsigned char *string_to_hex(char *str, long *len); @@ -430,6 +431,7 @@ int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); #define X509V3_F_COPY_EMAIL 122 #define X509V3_F_COPY_ISSUER 123 #define X509V3_F_DO_EXT_CONF 124 +#define X509V3_F_DO_EXT_I2D 135 #define X509V3_F_HEX_TO_STRING 111 #define X509V3_F_I2S_ASN1_ENUMERATED 121 #define X509V3_F_I2S_ASN1_INTEGER 120 @@ -460,6 +462,7 @@ int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); #define X509V3_F_X509V3_EXT_ADD 104 #define X509V3_F_X509V3_EXT_ADD_ALIAS 106 #define X509V3_F_X509V3_EXT_CONF 107 +#define X509V3_F_X509V3_EXT_I2D 136 #define X509V3_F_X509V3_GET_VALUE_BOOL 110 #define X509V3_F_X509V3_PARSE_LIST 109 |