diff options
author | Rob Austein <sra@hactrn.net> | 2012-11-15 22:13:53 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2012-11-15 22:13:53 +0000 |
commit | 756fdbe0d7eda1e98663c62bb3e57f2c18e88ee1 (patch) | |
tree | c0af81a5987e9859d12a0323d0d240f58d8b2f36 /utils/uri/uri.c | |
parent | 713507be1695d8f2f278ab925d58defc58eff2aa (diff) | |
parent | 11f3b8df179a16ebe1446dab620522ac97e3c327 (diff) |
Merge tk274 performance work back to trunk. Closes #274.
svn path=/trunk/; revision=4878
Diffstat (limited to 'utils/uri/uri.c')
-rw-r--r-- | utils/uri/uri.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/utils/uri/uri.c b/utils/uri/uri.c index 2b1b2d24..e741de5c 100644 --- a/utils/uri/uri.c +++ b/utils/uri/uri.c @@ -30,6 +30,7 @@ #include <openssl/bio.h> #include <openssl/pem.h> #include <openssl/err.h> +#include <openssl/cms.h> #include <openssl/x509.h> #include <openssl/x509v3.h> #include <openssl/safestack.h> @@ -42,23 +43,44 @@ static const unsigned char id_ad_signedObject[] = {0x2b, 0x6, 0x1, 0x5 static X509 *read_cert(const char *filename, int format, int verbose) { + BIO *b = BIO_new_file(filename, "r"); + STACK_OF(X509) *certs = NULL; + CMS_ContentInfo *cms = NULL; X509 *x = NULL; - BIO *b; - if ((b = BIO_new_file(filename, "r")) != NULL) { + if (b == NULL) + return NULL; + + switch (format) { + case 'p': + x = PEM_read_bio_X509(b, NULL, NULL, NULL); + break; + case 'd': + x = d2i_X509_bio(b, NULL); + break; + } + + if (x == NULL) { + BIO_reset(b); switch (format) { case 'p': - x = PEM_read_bio_X509_AUX(b, NULL, NULL, NULL); + cms = PEM_read_bio_CMS(b, NULL, NULL, NULL); break; case 'd': - x = d2i_X509_bio(b, NULL); + cms = d2i_CMS_bio(b, NULL); break; } - if (verbose && x != NULL) { - X509_print_fp(stdout, x); - printf("\n"); - } + if (cms != NULL && (certs = CMS_get1_certs(cms)) != NULL) + x = sk_X509_shift(certs); + } + + if (x != NULL && verbose) { + X509_print_fp(stdout, x); + printf("\n"); } + + sk_X509_pop_free(certs, X509_free); + CMS_ContentInfo_free(cms); BIO_free(b); return x; } |