diff options
-rw-r--r-- | src/lib/libcrypto/x509v3/v3_utl.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c index 4f8d16fd00..75f7662e7e 100644 --- a/src/lib/libcrypto/x509v3/v3_utl.c +++ b/src/lib/libcrypto/x509v3/v3_utl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: v3_utl.c,v 1.31 2018/05/19 10:50:08 tb Exp $ */ | 1 | /* $OpenBSD: v3_utl.c,v 1.32 2019/04/13 18:42:23 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -66,6 +66,7 @@ | |||
66 | #include <openssl/err.h> | 66 | #include <openssl/err.h> |
67 | #include <openssl/x509v3.h> | 67 | #include <openssl/x509v3.h> |
68 | 68 | ||
69 | char *bnstr(const BIGNUM *bn); | ||
69 | static char *strip_spaces(char *name); | 70 | static char *strip_spaces(char *name); |
70 | static int sk_strcmp(const char * const *a, const char * const *b); | 71 | static int sk_strcmp(const char * const *a, const char * const *b); |
71 | static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, | 72 | static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, |
@@ -148,17 +149,43 @@ X509V3_add_value_bool_nf(const char *name, int asn1_bool, | |||
148 | return 1; | 149 | return 1; |
149 | } | 150 | } |
150 | 151 | ||
152 | char * | ||
153 | bn_to_string(const BIGNUM *bn) | ||
154 | { | ||
155 | const char *sign = ""; | ||
156 | char *bnstr, *hex; | ||
157 | char *ret = NULL; | ||
158 | |||
159 | /* Only display small numbers in decimal, as conversion is quadratic. */ | ||
160 | if (BN_num_bits(bn) < 128) | ||
161 | return BN_bn2dec(bn); | ||
162 | |||
163 | if ((hex = bnstr = BN_bn2hex(bn)) == NULL) | ||
164 | goto err; | ||
165 | |||
166 | if (BN_is_negative(bn)) { | ||
167 | sign = "-"; | ||
168 | hex++; | ||
169 | } | ||
170 | |||
171 | if (asprintf(&ret, "%s0x%s", sign, hex) == -1) | ||
172 | ret = NULL; | ||
173 | |||
174 | err: | ||
175 | free(bnstr); | ||
176 | return ret; | ||
177 | } | ||
151 | 178 | ||
152 | char * | 179 | char * |
153 | i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, const ASN1_ENUMERATED *a) | 180 | i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, const ASN1_ENUMERATED *a) |
154 | { | 181 | { |
155 | BIGNUM *bntmp = NULL; | 182 | BIGNUM *bntmp; |
156 | char *strtmp = NULL; | 183 | char *strtmp = NULL; |
157 | 184 | ||
158 | if (!a) | 185 | if (a == NULL) |
159 | return NULL; | 186 | return NULL; |
160 | if (!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) || | 187 | if ((bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) == NULL || |
161 | !(strtmp = BN_bn2dec(bntmp))) | 188 | (strtmp = bn_to_string(bntmp)) == NULL) |
162 | X509V3error(ERR_R_MALLOC_FAILURE); | 189 | X509V3error(ERR_R_MALLOC_FAILURE); |
163 | BN_free(bntmp); | 190 | BN_free(bntmp); |
164 | return strtmp; | 191 | return strtmp; |
@@ -167,13 +194,13 @@ i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, const ASN1_ENUMERATED *a) | |||
167 | char * | 194 | char * |
168 | i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, const ASN1_INTEGER *a) | 195 | i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, const ASN1_INTEGER *a) |
169 | { | 196 | { |
170 | BIGNUM *bntmp = NULL; | 197 | BIGNUM *bntmp; |
171 | char *strtmp = NULL; | 198 | char *strtmp = NULL; |
172 | 199 | ||
173 | if (!a) | 200 | if (a == NULL) |
174 | return NULL; | 201 | return NULL; |
175 | if (!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) || | 202 | if ((bntmp = ASN1_INTEGER_to_BN(a, NULL)) == NULL || |
176 | !(strtmp = BN_bn2dec(bntmp))) | 203 | (strtmp = bn_to_string(bntmp)) == NULL) |
177 | X509V3error(ERR_R_MALLOC_FAILURE); | 204 | X509V3error(ERR_R_MALLOC_FAILURE); |
178 | BN_free(bntmp); | 205 | BN_free(bntmp); |
179 | return strtmp; | 206 | return strtmp; |