diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/t_x509.c')
-rw-r--r-- | src/lib/libcrypto/asn1/t_x509.c | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index e061f2ffad..edbb39a02f 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
@@ -72,6 +72,7 @@ | |||
72 | #include <openssl/objects.h> | 72 | #include <openssl/objects.h> |
73 | #include <openssl/x509.h> | 73 | #include <openssl/x509.h> |
74 | #include <openssl/x509v3.h> | 74 | #include <openssl/x509v3.h> |
75 | #include "asn1_locl.h" | ||
75 | 76 | ||
76 | #ifndef OPENSSL_NO_FP_API | 77 | #ifndef OPENSSL_NO_FP_API |
77 | int X509_print_fp(FILE *fp, X509 *x) | 78 | int X509_print_fp(FILE *fp, X509 *x) |
@@ -137,10 +138,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
137 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | 138 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; |
138 | 139 | ||
139 | bs=X509_get_serialNumber(x); | 140 | bs=X509_get_serialNumber(x); |
140 | if (bs->length <= 4) | 141 | if (bs->length <= (int)sizeof(long)) |
141 | { | 142 | { |
142 | l=ASN1_INTEGER_get(bs); | 143 | l=ASN1_INTEGER_get(bs); |
143 | if (l < 0) | 144 | if (bs->type == V_ASN1_NEG_INTEGER) |
144 | { | 145 | { |
145 | l= -l; | 146 | l= -l; |
146 | neg="-"; | 147 | neg="-"; |
@@ -167,12 +168,16 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
167 | 168 | ||
168 | if(!(cflag & X509_FLAG_NO_SIGNAME)) | 169 | if(!(cflag & X509_FLAG_NO_SIGNAME)) |
169 | { | 170 | { |
171 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) | ||
172 | goto err; | ||
173 | #if 0 | ||
170 | if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0) | 174 | if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0) |
171 | goto err; | 175 | goto err; |
172 | if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0) | 176 | if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0) |
173 | goto err; | 177 | goto err; |
174 | if (BIO_puts(bp, "\n") <= 0) | 178 | if (BIO_puts(bp, "\n") <= 0) |
175 | goto err; | 179 | goto err; |
180 | #endif | ||
176 | } | 181 | } |
177 | 182 | ||
178 | if(!(cflag & X509_FLAG_NO_ISSUER)) | 183 | if(!(cflag & X509_FLAG_NO_ISSUER)) |
@@ -255,7 +260,8 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
255 | goto err; | 260 | goto err; |
256 | i2d_X509_NAME(x->cert_info->subject, &dertmp); | 261 | i2d_X509_NAME(x->cert_info->subject, &dertmp); |
257 | 262 | ||
258 | EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL); | 263 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) |
264 | goto err; | ||
259 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 265 | for (i=0; i < SHA_DIGEST_LENGTH; i++) |
260 | { | 266 | { |
261 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; | 267 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; |
@@ -268,8 +274,10 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
268 | if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0) | 274 | if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0) |
269 | goto err; | 275 | goto err; |
270 | 276 | ||
271 | EVP_Digest(x->cert_info->key->public_key->data, | 277 | if (!EVP_Digest(x->cert_info->key->public_key->data, |
272 | x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL); | 278 | x->cert_info->key->public_key->length, |
279 | SHA1md, NULL, EVP_sha1(), NULL)) | ||
280 | goto err; | ||
273 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 281 | for (i=0; i < SHA_DIGEST_LENGTH; i++) |
274 | { | 282 | { |
275 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) | 283 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) |
@@ -283,23 +291,50 @@ err: | |||
283 | return(0); | 291 | return(0); |
284 | } | 292 | } |
285 | 293 | ||
286 | int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | 294 | int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) |
287 | { | 295 | { |
288 | unsigned char *s; | 296 | const unsigned char *s; |
289 | int i, n; | 297 | int i, n; |
290 | if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0; | ||
291 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; | ||
292 | 298 | ||
293 | n=sig->length; | 299 | n=sig->length; |
294 | s=sig->data; | 300 | s=sig->data; |
295 | for (i=0; i<n; i++) | 301 | for (i=0; i<n; i++) |
296 | { | 302 | { |
297 | if ((i%18) == 0) | 303 | if ((i%18) == 0) |
298 | if (BIO_write(bp,"\n ",9) <= 0) return 0; | 304 | { |
305 | if (BIO_write(bp,"\n",1) <= 0) return 0; | ||
306 | if (BIO_indent(bp, indent, indent) <= 0) return 0; | ||
307 | } | ||
299 | if (BIO_printf(bp,"%02x%s",s[i], | 308 | if (BIO_printf(bp,"%02x%s",s[i], |
300 | ((i+1) == n)?"":":") <= 0) return 0; | 309 | ((i+1) == n)?"":":") <= 0) return 0; |
301 | } | 310 | } |
302 | if (BIO_write(bp,"\n",1) != 1) return 0; | 311 | if (BIO_write(bp,"\n",1) != 1) return 0; |
312 | |||
313 | return 1; | ||
314 | } | ||
315 | |||
316 | int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | ||
317 | { | ||
318 | int sig_nid; | ||
319 | if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0; | ||
320 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; | ||
321 | |||
322 | sig_nid = OBJ_obj2nid(sigalg->algorithm); | ||
323 | if (sig_nid != NID_undef) | ||
324 | { | ||
325 | int pkey_nid, dig_nid; | ||
326 | const EVP_PKEY_ASN1_METHOD *ameth; | ||
327 | if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) | ||
328 | { | ||
329 | ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); | ||
330 | if (ameth && ameth->sig_print) | ||
331 | return ameth->sig_print(bp, sigalg, sig, 9, 0); | ||
332 | } | ||
333 | } | ||
334 | if (sig) | ||
335 | return X509_signature_dump(bp, sig, 9); | ||
336 | else if (BIO_puts(bp, "\n") <= 0) | ||
337 | return 0; | ||
303 | return 1; | 338 | return 1; |
304 | } | 339 | } |
305 | 340 | ||