From bceacf938f07f84ecd2c0f2ad42b1ff90f34f93b Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Tue, 9 Feb 1999 01:29:37 +0000 Subject: [PATCH] Support for ASN1 ENUMERATED type. This copies and duplicates the ASN1_INTEGER code and adds support to ASN1_TYPE and asn1parse. --- CHANGES | 4 ++++ crypto/asn1/Makefile.ssl | 4 ++-- crypto/asn1/a_type.c | 11 +++++++++++ crypto/asn1/asn1.err | 5 +++++ crypto/asn1/asn1.h | 41 +++++++++++++++++++++++++++++++++++++++- crypto/asn1/asn1_err.c | 5 +++++ crypto/asn1/asn1_par.c | 34 +++++++++++++++++++++++++++++++++ 7 files changed, 101 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 9c33fbe2c7..156497841d 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,10 @@ Changes between 0.9.1c and 0.9.2 + *) Preliminary support for ENUMERATED type. This is largely copied from the + INTEGER code. + [Steve Henson] + *) Add new function, EVP_MD_CTX_copy() to replace frequent use of memcpy. [Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)] diff --git a/crypto/asn1/Makefile.ssl b/crypto/asn1/Makefile.ssl index 67a26df25d..1b0cfa5a78 100644 --- a/crypto/asn1/Makefile.ssl +++ b/crypto/asn1/Makefile.ssl @@ -24,7 +24,7 @@ APPS= LIB=$(TOP)/libcrypto.a LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \ a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \ - a_sign.c a_digest.c a_verify.c \ + a_enum.c a_sign.c a_digest.c a_verify.c \ x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c nsseq.c \ d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ @@ -39,7 +39,7 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \ evp_asn1.c LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \ a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \ - a_sign.o a_digest.o a_verify.o \ + a_enum.o a_sign.o a_digest.o a_verify.o \ x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o nsseq.o \ d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ diff --git a/crypto/asn1/a_type.c b/crypto/asn1/a_type.c index 63b458358a..a3cf736026 100644 --- a/crypto/asn1/a_type.c +++ b/crypto/asn1/a_type.c @@ -89,6 +89,10 @@ unsigned char **pp; case V_ASN1_NEG_INTEGER: r=i2d_ASN1_INTEGER(a->value.integer,pp); break; + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: + r=i2d_ASN1_ENUMERATED(a->value.enumerated,pp); + break; case V_ASN1_BIT_STRING: r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp); break; @@ -177,6 +181,11 @@ long length; d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL) goto err; break; + case V_ASN1_ENUMERATED: + if ((ret->value.enumerated= + d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL) + goto err; + break; case V_ASN1_BIT_STRING: if ((ret->value.bit_string= d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL) @@ -309,6 +318,8 @@ ASN1_TYPE *a; break; case V_ASN1_INTEGER: case V_ASN1_NEG_INTEGER: + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: case V_ASN1_BIT_STRING: case V_ASN1_OCTET_STRING: case V_ASN1_SEQUENCE: diff --git a/crypto/asn1/asn1.err b/crypto/asn1/asn1.err index 2aa311ff3c..a9c631bd4d 100644 --- a/crypto/asn1/asn1.err +++ b/crypto/asn1/asn1.err @@ -8,6 +8,8 @@ #define ASN1_F_ASN1_D2I_BIO 104 #define ASN1_F_ASN1_D2I_FP 105 #define ASN1_F_ASN1_DUP 106 +#define ASN1_F_ASN1_ENUMERATED_SET 232 +#define ASN1_F_ASN1_ENUMERATED_TO_BN 233 #define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222 #define ASN1_F_ASN1_GET_OBJECT 107 #define ASN1_F_ASN1_HEADER_NEW 108 @@ -25,11 +27,13 @@ #define ASN1_F_ASN1_UTCTIME_NEW 120 #define ASN1_F_ASN1_VERIFY 121 #define ASN1_F_BASIC_CONSTRAINTS_NEW 226 +#define ASN1_F_BN_TO_ASN1_ENUMERATED 234 #define ASN1_F_BN_TO_ASN1_INTEGER 122 #define ASN1_F_D2I_ASN1_BIT_STRING 123 #define ASN1_F_D2I_ASN1_BMPSTRING 124 #define ASN1_F_D2I_ASN1_BOOLEAN 125 #define ASN1_F_D2I_ASN1_BYTES 126 +#define ASN1_F_D2I_ASN1_ENUMERATED 235 #define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223 #define ASN1_F_D2I_ASN1_HEADER 127 #define ASN1_F_D2I_ASN1_INTEGER 128 @@ -148,6 +152,7 @@ #define ASN1_R_DATA_IS_WRONG 110 #define ASN1_R_DECODING_ERROR 111 #define ASN1_R_ERROR_PARSING_SET_ELEMENT 112 +#define ASN1_R_EXPECTING_AN_ENUMERATED 154 #define ASN1_R_EXPECTING_AN_INTEGER 113 #define ASN1_R_EXPECTING_AN_OBJECT 114 #define ASN1_R_EXPECTING_AN_OCTET_STRING 115 diff --git a/crypto/asn1/asn1.h b/crypto/asn1/asn1.h index c28c7b42ff..c4e3211778 100644 --- a/crypto/asn1/asn1.h +++ b/crypto/asn1/asn1.h @@ -89,7 +89,8 @@ extern "C" { #define V_ASN1_OBJECT_DESCRIPTOR 7 #define V_ASN1_EXTERNAL 8 #define V_ASN1_REAL 9 -#define V_ASN1_ENUMERATED 10 /* microsoft weirdness */ +#define V_ASN1_ENUMERATED 10 +#define V_ASN1_NEG_ENUMERATED (10+0x100) #define V_ASN1_SEQUENCE 16 #define V_ASN1_SET 17 #define V_ASN1_NUMERICSTRING 18 /**/ @@ -168,6 +169,7 @@ typedef struct asn1_string_st #ifndef DEBUG #define ASN1_INTEGER ASN1_STRING +#define ASN1_ENUMERATED ASN1_STRING #define ASN1_BIT_STRING ASN1_STRING #define ASN1_OCTET_STRING ASN1_STRING #define ASN1_PRINTABLESTRING ASN1_STRING @@ -181,6 +183,7 @@ typedef struct asn1_string_st #define ASN1_BMPSTRING ASN1_STRING #else typedef struct asn1_string_st ASN1_INTEGER; +typedef struct asn1_string_st ASN1_ENUMERATED; typedef struct asn1_string_st ASN1_BIT_STRING; typedef struct asn1_string_st ASN1_OCTET_STRING; typedef struct asn1_string_st ASN1_PRINTABLESTRING; @@ -202,6 +205,7 @@ typedef struct asn1_type_st ASN1_STRING * asn1_string; ASN1_OBJECT * object; ASN1_INTEGER * integer; + ASN1_ENUMERATED * enumerated; ASN1_BIT_STRING * bit_string; ASN1_OCTET_STRING * octet_string; ASN1_PRINTABLESTRING * printablestring; @@ -262,6 +266,17 @@ typedef struct asn1_header_st /* i2d_ASN1_INTEGER() is a function */ /* d2i_ASN1_INTEGER() is a function */ +#define ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\ + ASN1_STRING_type_new(V_ASN1_ENUMERATED) +#define ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a) +#define ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\ + (ASN1_STRING *)a,(ASN1_STRING *)b) +/* ASN1_ENUMERATED_set() is a function, also see BN_to_ASN1_ENUMERATED() */ +/* ASN1_ENUMERATED_get() is a function, also see ASN1_ENUMERATED_to_BN() */ +/* i2d_ASN1_ENUMERATED() is a function */ +/* d2i_ASN1_ENUMERATED() is a function */ + #define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ ASN1_STRING_type_new(V_ASN1_OCTET_STRING) #define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) @@ -414,6 +429,10 @@ int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp, long length); +int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp); +ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp, + long length); + int ASN1_UTCTIME_check(ASN1_UTCTIME *a); ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str); @@ -465,6 +484,8 @@ STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length, #ifdef HEADER_BIO_H int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); +int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a); +int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size); int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a); int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size); int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type); @@ -480,6 +501,11 @@ long ASN1_INTEGER_get(ASN1_INTEGER *a); ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai); BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn); +int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); +long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a); +ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai); +BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn); + /* General */ /* given a string, return the correct type, max is the maximum length */ int ASN1_PRINTABLE_type(unsigned char *s, int max); @@ -572,6 +598,8 @@ int i2d_ASN1_BOOLEAN(); int d2i_ASN1_BOOLEAN(); int i2d_ASN1_INTEGER(); ASN1_INTEGER *d2i_ASN1_INTEGER(); +int i2d_ASN1_ENUMERATED(); +ASN1_INTEGER *d2i_ASN1_ENUMERATED(); int ASN1_UTCTIME_check(); ASN1_UTCTIME *ASN1_UTCTIME_set(); int ASN1_UTCTIME_set_string(); @@ -600,6 +628,10 @@ int ASN1_INTEGER_set(); long ASN1_INTEGER_get(); ASN1_INTEGER *BN_to_ASN1_INTEGER(); BIGNUM *ASN1_INTEGER_to_BN(); +int ASN1_ENUMERATED_set(); +long ASN1_ENUMERATED_get(); +ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(); +BIGNUM *ASN1_ENUMERATED_to_BN(); int ASN1_PRINTABLE_type(); int i2d_ASN1_bytes(); ASN1_STRING *d2i_ASN1_bytes(); @@ -624,6 +656,8 @@ int ASN1_STRING_print(); int ASN1_parse(); int i2a_ASN1_INTEGER(); int a2i_ASN1_INTEGER(); +int i2a_ASN1_ENUMERATED(); +int a2i_ASN1_ENUMERATED(); int i2a_ASN1_OBJECT(); int i2t_ASN1_OBJECT(); int a2i_ASN1_STRING(); @@ -662,6 +696,8 @@ ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(); #define ASN1_F_ASN1_D2I_BIO 104 #define ASN1_F_ASN1_D2I_FP 105 #define ASN1_F_ASN1_DUP 106 +#define ASN1_F_ASN1_ENUMERATED_SET 232 +#define ASN1_F_ASN1_ENUMERATED_TO_BN 233 #define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222 #define ASN1_F_ASN1_GET_OBJECT 107 #define ASN1_F_ASN1_HEADER_NEW 108 @@ -679,11 +715,13 @@ ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(); #define ASN1_F_ASN1_UTCTIME_NEW 120 #define ASN1_F_ASN1_VERIFY 121 #define ASN1_F_BASIC_CONSTRAINTS_NEW 226 +#define ASN1_F_BN_TO_ASN1_ENUMERATED 234 #define ASN1_F_BN_TO_ASN1_INTEGER 122 #define ASN1_F_D2I_ASN1_BIT_STRING 123 #define ASN1_F_D2I_ASN1_BMPSTRING 124 #define ASN1_F_D2I_ASN1_BOOLEAN 125 #define ASN1_F_D2I_ASN1_BYTES 126 +#define ASN1_F_D2I_ASN1_ENUMERATED 235 #define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223 #define ASN1_F_D2I_ASN1_HEADER 127 #define ASN1_F_D2I_ASN1_INTEGER 128 @@ -802,6 +840,7 @@ ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(); #define ASN1_R_DATA_IS_WRONG 110 #define ASN1_R_DECODING_ERROR 111 #define ASN1_R_ERROR_PARSING_SET_ELEMENT 112 +#define ASN1_R_EXPECTING_AN_ENUMERATED 154 #define ASN1_R_EXPECTING_AN_INTEGER 113 #define ASN1_R_EXPECTING_AN_OBJECT 114 #define ASN1_R_EXPECTING_AN_OCTET_STRING 115 diff --git a/crypto/asn1/asn1_err.c b/crypto/asn1/asn1_err.c index b98b6150b0..51acca54fc 100644 --- a/crypto/asn1/asn1_err.c +++ b/crypto/asn1/asn1_err.c @@ -70,6 +70,8 @@ static ERR_STRING_DATA ASN1_str_functs[]= {ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"}, {ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"}, {ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"}, +{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"}, +{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"}, {ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_NEW"}, {ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"}, {ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"}, @@ -87,11 +89,13 @@ static ERR_STRING_DATA ASN1_str_functs[]= {ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"}, {ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_VERIFY"}, {ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_NEW"}, +{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"}, {ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_ENUMERATED,0), "d2i_ASN1_ENUMERATED"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"}, @@ -213,6 +217,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]= {ASN1_R_DATA_IS_WRONG ,"data is wrong"}, {ASN1_R_DECODING_ERROR ,"decoding error"}, {ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"}, +{ASN1_R_EXPECTING_AN_ENUMERATED ,"expecting an enumerated"}, {ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"}, {ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"}, {ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"}, diff --git a/crypto/asn1/asn1_par.c b/crypto/asn1/asn1_par.c index af71b1a85d..bde3a3b2c3 100644 --- a/crypto/asn1/asn1_par.c +++ b/crypto/asn1/asn1_par.c @@ -108,6 +108,8 @@ int indent; p="BOOLEAN"; else if (tag == V_ASN1_INTEGER) p="INTEGER"; + else if (tag == V_ASN1_ENUMERATED) + p="ENUMERATED"; else if (tag == V_ASN1_BIT_STRING) p="BIT STRING"; else if (tag == V_ASN1_OCTET_STRING) @@ -371,6 +373,38 @@ int indent; } ASN1_INTEGER_free(bs); } + else if (tag == V_ASN1_ENUMERATED) + { + ASN1_ENUMERATED *bs; + int i; + + opp=op; + bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); + if (bs != NULL) + { + if (BIO_write(bp,":",1) <= 0) goto end; + if (bs->type == V_ASN1_NEG_ENUMERATED) + if (BIO_write(bp,"-",1) <= 0) + goto end; + for (i=0; ilength; i++) + { + if (BIO_printf(bp,"%02X", + bs->data[i]) <= 0) + goto end; + } + if (bs->length == 0) + { + if (BIO_write(bp,"00",2) <= 0) + goto end; + } + } + else + { + if (BIO_write(bp,"BAD ENUMERATED",11) <= 0) + goto end; + } + ASN1_ENUMERATED_free(bs); + } if (!nl) { -- 2.25.1