|
60 | 60 | #include <openssl/err.h>
|
61 | 61 | #include <openssl/mem.h>
|
62 | 62 | #include <openssl/x509.h>
|
| 63 | +#include "internal.h" |
63 | 64 |
|
64 | 65 | int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey) {
|
65 | 66 | if ((x == NULL) || (x->spkac == NULL)) {
|
@@ -131,3 +132,47 @@ char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) {
|
131 | 132 | OPENSSL_free(der_spki);
|
132 | 133 | return b64_str;
|
133 | 134 | }
|
| 135 | + |
| 136 | +int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) { |
| 137 | + if (out == NULL || spki == NULL || spki->spkac == NULL || |
| 138 | + spki->spkac->pubkey == NULL || spki->sig_algor == NULL || |
| 139 | + spki->sig_algor->algorithm == NULL || spki->signature == NULL || |
| 140 | + spki->signature->data == NULL) { |
| 141 | + OPENSSL_PUT_ERROR(X509, ERR_R_PASSED_NULL_PARAMETER); |
| 142 | + return 0; |
| 143 | + } |
| 144 | + BIO_printf(out, "Netscape SPKI:\n"); |
| 145 | + |
| 146 | + // Print out public key algorithm and contents. |
| 147 | + ASN1_OBJECT *spkioid; |
| 148 | + X509_PUBKEY_get0_param(&spkioid, NULL, NULL, NULL, spki->spkac->pubkey); |
| 149 | + int spkioid_nid = OBJ_obj2nid(spkioid); |
| 150 | + BIO_printf(out, " Public Key Algorithm: %s\n", |
| 151 | + (spkioid_nid == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(spkioid_nid)); |
| 152 | + EVP_PKEY *pkey = X509_PUBKEY_get0(spki->spkac->pubkey); |
| 153 | + if (pkey == NULL) { |
| 154 | + BIO_printf(out, " Unable to load public key\n"); |
| 155 | + } else { |
| 156 | + EVP_PKEY_print_public(out, pkey, 4, NULL); |
| 157 | + } |
| 158 | + |
| 159 | + ASN1_IA5STRING *chal = spki->spkac->challenge; |
| 160 | + if (chal != NULL && chal->length != 0) { |
| 161 | + BIO_printf(out, " Challenge String: %.*s\n", chal->length, chal->data); |
| 162 | + } |
| 163 | + |
| 164 | + // Print out signature algorithm and contents. |
| 165 | + BIO_printf(out, " Signature Algorithm: %s", |
| 166 | + (OBJ_obj2nid(spki->sig_algor->algorithm) == NID_undef) |
| 167 | + ? "UNKNOWN" |
| 168 | + : OBJ_nid2ln(OBJ_obj2nid(spki->sig_algor->algorithm))); |
| 169 | + for (int i = 0; i < spki->signature->length; i++) { |
| 170 | + if ((i % 18) == 0) { |
| 171 | + BIO_printf(out, "\n "); |
| 172 | + } |
| 173 | + BIO_printf(out, "%02x%s", (unsigned char)spki->signature->data[i], |
| 174 | + ((i + 1) == spki->signature->length) ? "" : ":"); |
| 175 | + } |
| 176 | + BIO_write(out, "\n", 1); |
| 177 | + return 1; |
| 178 | +} |
0 commit comments