t_spki.c 1.8 KB
Newer Older
1
/*
R
Rich Salz 已提交
2
 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 *
R
Rich Salz 已提交
4 5 6 7
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
8 9 10
 */

#include <stdio.h>
11
#include "internal/cryptlib.h"
12
#include <openssl/x509.h>
D
 
Dr. Stephen Henson 已提交
13
#include <openssl/asn1.h>
R
Rich Salz 已提交
14 15
#include <openssl/rsa.h>
#include <openssl/dsa.h>
16
#include <openssl/bn.h>
17 18 19 20 21

/* Print out an SPKI */

int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
{
22 23
    EVP_PKEY *pkey;
    ASN1_IA5STRING *chal;
D
Dr. Stephen Henson 已提交
24
    ASN1_OBJECT *spkioid;
25 26 27
    int i, n;
    char *s;
    BIO_printf(out, "Netscape SPKI:\n");
D
Dr. Stephen Henson 已提交
28 29
    X509_PUBKEY_get0_param(&spkioid, NULL, NULL, NULL, spki->spkac->pubkey);
    i = OBJ_obj2nid(spkioid);
30 31 32 33 34 35 36 37 38 39 40
    BIO_printf(out, "  Public Key Algorithm: %s\n",
               (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
    pkey = X509_PUBKEY_get(spki->spkac->pubkey);
    if (!pkey)
        BIO_printf(out, "  Unable to load public key\n");
    else {
        EVP_PKEY_print_public(out, pkey, 4, NULL);
        EVP_PKEY_free(pkey);
    }
    chal = spki->spkac->challenge;
    if (chal->length)
41
        BIO_printf(out, "  Challenge String: %.*s\n", chal->length, chal->data);
42
    i = OBJ_obj2nid(spki->sig_algor.algorithm);
43 44
    BIO_printf(out, "  Signature Algorithm: %s",
               (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
45

46 47 48 49 50 51 52 53 54 55
    n = spki->signature->length;
    s = (char *)spki->signature->data;
    for (i = 0; i < n; i++) {
        if ((i % 18) == 0)
            BIO_write(out, "\n      ", 7);
        BIO_printf(out, "%02x%s", (unsigned char)s[i],
                   ((i + 1) == n) ? "" : ":");
    }
    BIO_write(out, "\n", 1);
    return 1;
56
}