- } else if (pprint == i) {
- X509_PURPOSE *ptmp;
- int j;
-
- BIO_printf(out, "Certificate purposes:\n");
- for (j = 0; j < X509_PURPOSE_get_count(); j++) {
- ptmp = X509_PURPOSE_get0(j);
- purpose_print(out, x, ptmp);
- }
- } else if (modulus == i) {
- EVP_PKEY *pkey;
-
- pkey = X509_get0_pubkey(x);
- if (pkey == NULL) {
- BIO_printf(bio_err,
- "Modulus unavailable: cannot get key\n");
- goto end;
- }
- BIO_printf(out, "Modulus=");
- if (EVP_PKEY_is_a(pkey, "RSA")) {
- BIGNUM *n;
-
- /* Every RSA key has an 'n' */
- EVP_PKEY_get_bn_param(pkey, "n", &n);
- BN_print(out, n);
- BN_free(n);
- } else if (EVP_PKEY_is_a(pkey, "DSA")) {
- BIGNUM *dsapub;
-
- /* Every DSA key has an 'pub' */
- EVP_PKEY_get_bn_param(pkey, "pub", &dsapub);
- BN_print(out, dsapub);
- BN_free(dsapub);
- } else {
- BIO_printf(out, "No modulus for this public key type");
- }
- BIO_printf(out, "\n");
- } else if (print_pubkey == i) {
- EVP_PKEY *pkey;
-
- pkey = X509_get0_pubkey(x);
- if (pkey == NULL) {
- BIO_printf(bio_err, "Error getting public key\n");
- goto end;
- }
- PEM_write_bio_PUBKEY(out, pkey);
- } else if (text == i) {
- X509_print_ex(out, x, get_nameopt(), certflag);
- } else if (startdate == i) {
- BIO_puts(out, "notBefore=");
- ASN1_TIME_print(out, X509_get0_notBefore(x));
- BIO_puts(out, "\n");
- } else if (enddate == i) {
- BIO_puts(out, "notAfter=");
- ASN1_TIME_print(out, X509_get0_notAfter(x));
- BIO_puts(out, "\n");
- } else if (fingerprint == i) {
- int j;
- unsigned int n;
- unsigned char md[EVP_MAX_MD_SIZE];
- const EVP_MD *fdig = digest;
-
- if (fdig == NULL)
- fdig = EVP_sha1();
-
- if (!X509_digest(x, fdig, md, &n)) {
- BIO_printf(bio_err, "Out of memory\n");
- goto end;
- }
- BIO_printf(out, "%s Fingerprint=",
- OBJ_nid2sn(EVP_MD_type(fdig)));
- for (j = 0; j < (int)n; j++) {
- BIO_printf(out, "%02X%c", md[j], (j + 1 == (int)n)
- ? '\n' : ':');
- }
- } else if (ocspid == i) {
- X509_ocspid_print(out, x);
- } else if (ext == i) {
- print_x509v3_exts(out, x, ext_names);
+ } else if (i == pprint) {
+ BIO_printf(out, "Certificate purposes:\n");
+ for (j = 0; j < X509_PURPOSE_get_count(); j++)
+ purpose_print(out, x, X509_PURPOSE_get0(j));
+ } else if (i == modulus) {
+ BIO_printf(out, "Modulus=");
+ if (EVP_PKEY_is_a(pkey, "RSA")) {
+ BIGNUM *n = NULL;
+
+ /* Every RSA key has an 'n' */
+ EVP_PKEY_get_bn_param(pkey, "n", &n);
+ BN_print(out, n);
+ BN_free(n);
+ } else if (EVP_PKEY_is_a(pkey, "DSA")) {
+ BIGNUM *dsapub = NULL;
+
+ /* Every DSA key has a 'pub' */
+ EVP_PKEY_get_bn_param(pkey, "pub", &dsapub);
+ BN_print(out, dsapub);
+ BN_free(dsapub);
+ } else {
+ BIO_printf(out, "No modulus for this public key type");
+ }
+ BIO_printf(out, "\n");
+ } else if (i == print_pubkey) {
+ PEM_write_bio_PUBKEY(out, pkey);
+ } else if (i == text) {
+ X509_print_ex(out, x, get_nameopt(), certflag);
+ } else if (i == startdate) {
+ BIO_puts(out, "notBefore=");
+ ASN1_TIME_print_ex(out, X509_get0_notBefore(x), dateopt);
+ BIO_puts(out, "\n");
+ } else if (i == enddate) {
+ BIO_puts(out, "notAfter=");
+ ASN1_TIME_print_ex(out, X509_get0_notAfter(x), dateopt);
+ BIO_puts(out, "\n");
+ } else if (i == fingerprint) {
+ unsigned int n;
+ unsigned char md[EVP_MAX_MD_SIZE];
+ const char *fdigname = digest;
+ EVP_MD *fdig;
+ int digres;
+
+ if (fdigname == NULL)
+ fdigname = "SHA1";
+
+ if ((fdig = EVP_MD_fetch(app_get0_libctx(), fdigname,
+ app_get0_propq())) == NULL) {
+ BIO_printf(bio_err, "Unknown digest\n");
+ goto err;
+ }
+ digres = X509_digest(x, fdig, md, &n);
+ EVP_MD_free(fdig);
+ if (!digres) {
+ BIO_printf(bio_err, "Out of memory\n");
+ goto err;