11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
51cb0ef41Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at
71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include <stdio.h>
111cb0ef41Sopenharmony_ci#include "internal/cryptlib.h"
121cb0ef41Sopenharmony_ci#include <openssl/x509.h>
131cb0ef41Sopenharmony_ci#include <openssl/asn1.h>
141cb0ef41Sopenharmony_ci#include <openssl/rsa.h>
151cb0ef41Sopenharmony_ci#include <openssl/dsa.h>
161cb0ef41Sopenharmony_ci#include <openssl/bn.h>
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci/* Print out an SPKI */
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciint NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
211cb0ef41Sopenharmony_ci{
221cb0ef41Sopenharmony_ci    EVP_PKEY *pkey;
231cb0ef41Sopenharmony_ci    ASN1_IA5STRING *chal;
241cb0ef41Sopenharmony_ci    ASN1_OBJECT *spkioid;
251cb0ef41Sopenharmony_ci    int i, n;
261cb0ef41Sopenharmony_ci    char *s;
271cb0ef41Sopenharmony_ci    BIO_printf(out, "Netscape SPKI:\n");
281cb0ef41Sopenharmony_ci    X509_PUBKEY_get0_param(&spkioid, NULL, NULL, NULL, spki->spkac->pubkey);
291cb0ef41Sopenharmony_ci    i = OBJ_obj2nid(spkioid);
301cb0ef41Sopenharmony_ci    BIO_printf(out, "  Public Key Algorithm: %s\n",
311cb0ef41Sopenharmony_ci               (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
321cb0ef41Sopenharmony_ci    pkey = X509_PUBKEY_get(spki->spkac->pubkey);
331cb0ef41Sopenharmony_ci    if (pkey == NULL)
341cb0ef41Sopenharmony_ci        BIO_printf(out, "  Unable to load public key\n");
351cb0ef41Sopenharmony_ci    else {
361cb0ef41Sopenharmony_ci        EVP_PKEY_print_public(out, pkey, 4, NULL);
371cb0ef41Sopenharmony_ci        EVP_PKEY_free(pkey);
381cb0ef41Sopenharmony_ci    }
391cb0ef41Sopenharmony_ci    chal = spki->spkac->challenge;
401cb0ef41Sopenharmony_ci    if (chal->length)
411cb0ef41Sopenharmony_ci        BIO_printf(out, "  Challenge String: %.*s\n", chal->length, chal->data);
421cb0ef41Sopenharmony_ci    i = OBJ_obj2nid(spki->sig_algor.algorithm);
431cb0ef41Sopenharmony_ci    BIO_printf(out, "  Signature Algorithm: %s",
441cb0ef41Sopenharmony_ci               (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci    n = spki->signature->length;
471cb0ef41Sopenharmony_ci    s = (char *)spki->signature->data;
481cb0ef41Sopenharmony_ci    for (i = 0; i < n; i++) {
491cb0ef41Sopenharmony_ci        if ((i % 18) == 0)
501cb0ef41Sopenharmony_ci            BIO_write(out, "\n      ", 7);
511cb0ef41Sopenharmony_ci        BIO_printf(out, "%02x%s", (unsigned char)s[i],
521cb0ef41Sopenharmony_ci                   ((i + 1) == n) ? "" : ":");
531cb0ef41Sopenharmony_ci    }
541cb0ef41Sopenharmony_ci    BIO_write(out, "\n", 1);
551cb0ef41Sopenharmony_ci    return 1;
561cb0ef41Sopenharmony_ci}
57