diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2010-03-06 19:05:05 +0100 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2010-03-06 19:05:05 +0100 |
commit | fa1ba589f3feab2c1d8c87109d18978238a9877f (patch) | |
tree | 15c7aeba40a8354dd80c5bd83bd8f2ac3b383b89 /crypto/asn1/t_x509.c | |
parent | Fix memory leak: free up ENGINE functional reference if digest is not (diff) | |
download | openssl-fa1ba589f3feab2c1d8c87109d18978238a9877f.tar.xz openssl-fa1ba589f3feab2c1d8c87109d18978238a9877f.zip |
Add algorithm specific signature printing. An individual ASN1 method can
now print out signatures instead of the standard hex dump.
More complex signatures (e.g. PSS) can print out more meaningful information.
Sample DSA version included that prints out the signature parameters r, s.
[Note EVP_PKEY_ASN1_METHOD is an application opaque structure so adding
new fields in the middle has no compatibility issues]
Diffstat (limited to 'crypto/asn1/t_x509.c')
-rw-r--r-- | crypto/asn1/t_x509.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/crypto/asn1/t_x509.c b/crypto/asn1/t_x509.c index 01cf9e427a..22041a8fc5 100644 --- a/crypto/asn1/t_x509.c +++ b/crypto/asn1/t_x509.c @@ -72,6 +72,7 @@ #include <openssl/objects.h> #include <openssl/x509.h> #include <openssl/x509v3.h> +#include "asn1_locl.h" #ifndef OPENSSL_NO_FP_API int X509_print_fp(FILE *fp, X509 *x) @@ -286,26 +287,48 @@ err: return(0); } -int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) +int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) { - unsigned char *s; + const unsigned char *s; int i, n; - if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0; - if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; n=sig->length; s=sig->data; for (i=0; i<n; i++) { if ((i%18) == 0) - if (BIO_write(bp,"\n ",9) <= 0) return 0; + if (BIO_write(bp,"\n",1) <= 0) return 0; + if (BIO_indent(bp, indent, indent) <= 0) return 0; if (BIO_printf(bp,"%02x%s",s[i], ((i+1) == n)?"":":") <= 0) return 0; } if (BIO_write(bp,"\n",1) != 1) return 0; + return 1; } +int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) +{ + int sig_nid; + if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0; + if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; + + sig_nid = OBJ_obj2nid(sigalg->algorithm); + if (sig_nid != NID_undef) + { + int pkey_nid, dig_nid; + const EVP_PKEY_ASN1_METHOD *ameth; + if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) + { + ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); + if (ameth && ameth->sig_print) + return ameth->sig_print(bp, sigalg, sig, 9, 0); + } + } + + return X509_signature_dump(bp, sig, 9); +} + int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) { int i,n; |