summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509v3/v3_utl.c
diff options
context:
space:
mode:
authorbeck <>2002-05-15 02:29:21 +0000
committerbeck <>2002-05-15 02:29:21 +0000
commitb64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch)
treefa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/x509v3/v3_utl.c
parente471e1ea98d673597b182ea85f29e30c97cd08b5 (diff)
downloadopenbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_utl.c')
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
index 619f161b58..283e943e46 100644
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -66,7 +66,7 @@
66 66
67static char *strip_spaces(char *name); 67static char *strip_spaces(char *name);
68static int sk_strcmp(const char * const *a, const char * const *b); 68static int sk_strcmp(const char * const *a, const char * const *b);
69static STACK *get_email(X509_NAME *name, STACK_OF(GENERAL_NAME) *gens); 69static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens);
70static void str_free(void *str); 70static void str_free(void *str);
71static int append_ia5(STACK **sk, ASN1_IA5STRING *email); 71static int append_ia5(STACK **sk, ASN1_IA5STRING *email);
72 72
@@ -154,21 +154,40 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
154{ 154{
155 BIGNUM *bn = NULL; 155 BIGNUM *bn = NULL;
156 ASN1_INTEGER *aint; 156 ASN1_INTEGER *aint;
157 int isneg, ishex;
158 int ret;
157 bn = BN_new(); 159 bn = BN_new();
158 if(!value) { 160 if (!value) {
159 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE); 161 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
160 return 0; 162 return 0;
161 } 163 }
162 if(!BN_dec2bn(&bn, value)) { 164 if (value[0] == '-') {
165 value++;
166 isneg = 1;
167 } else isneg = 0;
168
169 if (value[0] == '0' && ((value[1] == 'x') || (value[1] == 'X'))) {
170 value += 2;
171 ishex = 1;
172 } else ishex = 0;
173
174 if (ishex) ret = BN_hex2bn(&bn, value);
175 else ret = BN_dec2bn(&bn, value);
176
177 if (!ret) {
163 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR); 178 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
164 return 0; 179 return 0;
165 } 180 }
166 181
167 if(!(aint = BN_to_ASN1_INTEGER(bn, NULL))) { 182 if (isneg && BN_is_zero(bn)) isneg = 0;
183
184 aint = BN_to_ASN1_INTEGER(bn, NULL);
185 BN_free(bn);
186 if (!aint) {
168 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR); 187 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
169 return 0; 188 return 0;
170 } 189 }
171 BN_free(bn); 190 if (isneg) aint->type |= V_ASN1_NEG;
172 return aint; 191 return aint;
173} 192}
174 193
@@ -221,7 +240,7 @@ int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint)
221 240
222/*#define DEBUG*/ 241/*#define DEBUG*/
223 242
224STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line) 243STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line)
225{ 244{
226 char *p, *q, c; 245 char *p, *q, c;
227 char *ntmp, *vtmp; 246 char *ntmp, *vtmp;
@@ -250,7 +269,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line)
250 *p = 0; 269 *p = 0;
251 ntmp = strip_spaces(q); 270 ntmp = strip_spaces(q);
252 q = p + 1; 271 q = p + 1;
253#ifdef DEBUG 272#if 0
254 printf("%s\n", ntmp); 273 printf("%s\n", ntmp);
255#endif 274#endif
256 if(!ntmp) { 275 if(!ntmp) {
@@ -266,7 +285,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line)
266 state = HDR_NAME; 285 state = HDR_NAME;
267 *p = 0; 286 *p = 0;
268 vtmp = strip_spaces(q); 287 vtmp = strip_spaces(q);
269#ifdef DEBUG 288#if 0
270 printf("%s\n", ntmp); 289 printf("%s\n", ntmp);
271#endif 290#endif
272 if(!vtmp) { 291 if(!vtmp) {
@@ -283,7 +302,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line)
283 302
284 if(state == HDR_VALUE) { 303 if(state == HDR_VALUE) {
285 vtmp = strip_spaces(q); 304 vtmp = strip_spaces(q);
286#ifdef DEBUG 305#if 0
287 printf("%s=%s\n", ntmp, vtmp); 306 printf("%s=%s\n", ntmp, vtmp);
288#endif 307#endif
289 if(!vtmp) { 308 if(!vtmp) {
@@ -293,7 +312,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line)
293 X509V3_add_value(ntmp, vtmp, &values); 312 X509V3_add_value(ntmp, vtmp, &values);
294 } else { 313 } else {
295 ntmp = strip_spaces(q); 314 ntmp = strip_spaces(q);
296#ifdef DEBUG 315#if 0
297 printf("%s\n", ntmp); 316 printf("%s\n", ntmp);
298#endif 317#endif
299 if(!ntmp) { 318 if(!ntmp) {
@@ -439,7 +458,7 @@ static int sk_strcmp(const char * const *a, const char * const *b)
439 458
440STACK *X509_get1_email(X509 *x) 459STACK *X509_get1_email(X509 *x)
441{ 460{
442 STACK_OF(GENERAL_NAME) *gens; 461 GENERAL_NAMES *gens;
443 STACK *ret; 462 STACK *ret;
444 gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL); 463 gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
445 ret = get_email(X509_get_subject_name(x), gens); 464 ret = get_email(X509_get_subject_name(x), gens);
@@ -449,7 +468,7 @@ STACK *X509_get1_email(X509 *x)
449 468
450STACK *X509_REQ_get1_email(X509_REQ *x) 469STACK *X509_REQ_get1_email(X509_REQ *x)
451{ 470{
452 STACK_OF(GENERAL_NAME) *gens; 471 GENERAL_NAMES *gens;
453 STACK_OF(X509_EXTENSION) *exts; 472 STACK_OF(X509_EXTENSION) *exts;
454 STACK *ret; 473 STACK *ret;
455 exts = X509_REQ_get_extensions(x); 474 exts = X509_REQ_get_extensions(x);
@@ -461,7 +480,7 @@ STACK *X509_REQ_get1_email(X509_REQ *x)
461} 480}
462 481
463 482
464static STACK *get_email(X509_NAME *name, STACK_OF(GENERAL_NAME) *gens) 483static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
465{ 484{
466 STACK *ret = NULL; 485 STACK *ret = NULL;
467 X509_NAME_ENTRY *ne; 486 X509_NAME_ENTRY *ne;