159191Skris/* t_spki.c */
2280297Sjkim/*
3280297Sjkim * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
4280297Sjkim * 1999.
559191Skris */
659191Skris/* ====================================================================
759191Skris * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
859191Skris *
959191Skris * Redistribution and use in source and binary forms, with or without
1059191Skris * modification, are permitted provided that the following conditions
1159191Skris * are met:
1259191Skris *
1359191Skris * 1. Redistributions of source code must retain the above copyright
14280297Sjkim *    notice, this list of conditions and the following disclaimer.
1559191Skris *
1659191Skris * 2. Redistributions in binary form must reproduce the above copyright
1759191Skris *    notice, this list of conditions and the following disclaimer in
1859191Skris *    the documentation and/or other materials provided with the
1959191Skris *    distribution.
2059191Skris *
2159191Skris * 3. All advertising materials mentioning features or use of this
2259191Skris *    software must display the following acknowledgment:
2359191Skris *    "This product includes software developed by the OpenSSL Project
2459191Skris *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2559191Skris *
2659191Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2759191Skris *    endorse or promote products derived from this software without
2859191Skris *    prior written permission. For written permission, please contact
2959191Skris *    licensing@OpenSSL.org.
3059191Skris *
3159191Skris * 5. Products derived from this software may not be called "OpenSSL"
3259191Skris *    nor may "OpenSSL" appear in their names without prior written
3359191Skris *    permission of the OpenSSL Project.
3459191Skris *
3559191Skris * 6. Redistributions of any form whatsoever must retain the following
3659191Skris *    acknowledgment:
3759191Skris *    "This product includes software developed by the OpenSSL Project
3859191Skris *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3959191Skris *
4059191Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
4159191Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4259191Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4359191Skris * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4459191Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4559191Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4659191Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4759191Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4859191Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4959191Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5059191Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
5159191Skris * OF THE POSSIBILITY OF SUCH DAMAGE.
5259191Skris * ====================================================================
5359191Skris *
5459191Skris * This product includes cryptographic software written by Eric Young
5559191Skris * (eay@cryptsoft.com).  This product includes software written by Tim
5659191Skris * Hudson (tjh@cryptsoft.com).
5759191Skris *
5859191Skris */
5959191Skris
6059191Skris#include <stdio.h>
6159191Skris#include "cryptlib.h"
6259191Skris#include <openssl/x509.h>
63109998Smarkm#include <openssl/asn1.h>
64160814Ssimon#ifndef OPENSSL_NO_RSA
65280297Sjkim# include <openssl/rsa.h>
66160814Ssimon#endif
67160814Ssimon#ifndef OPENSSL_NO_DSA
68280297Sjkim# include <openssl/dsa.h>
69160814Ssimon#endif
70160814Ssimon#include <openssl/bn.h>
7159191Skris
7259191Skris/* Print out an SPKI */
7359191Skris
7459191Skrisint NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
7559191Skris{
76280297Sjkim    EVP_PKEY *pkey;
77280297Sjkim    ASN1_IA5STRING *chal;
78280297Sjkim    int i, n;
79280297Sjkim    char *s;
80280297Sjkim    BIO_printf(out, "Netscape SPKI:\n");
81280297Sjkim    i = OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm);
82280297Sjkim    BIO_printf(out, "  Public Key Algorithm: %s\n",
83280297Sjkim               (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
84280297Sjkim    pkey = X509_PUBKEY_get(spki->spkac->pubkey);
85280297Sjkim    if (!pkey)
86280297Sjkim        BIO_printf(out, "  Unable to load public key\n");
87280297Sjkim    else {
88280297Sjkim        EVP_PKEY_print_public(out, pkey, 4, NULL);
89280297Sjkim        EVP_PKEY_free(pkey);
90280297Sjkim    }
91280297Sjkim    chal = spki->spkac->challenge;
92280297Sjkim    if (chal->length)
93280297Sjkim        BIO_printf(out, "  Challenge String: %s\n", chal->data);
94280297Sjkim    i = OBJ_obj2nid(spki->sig_algor->algorithm);
95280297Sjkim    BIO_printf(out, "  Signature Algorithm: %s",
96280297Sjkim               (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
9759191Skris
98280297Sjkim    n = spki->signature->length;
99280297Sjkim    s = (char *)spki->signature->data;
100280297Sjkim    for (i = 0; i < n; i++) {
101280297Sjkim        if ((i % 18) == 0)
102280297Sjkim            BIO_write(out, "\n      ", 7);
103280297Sjkim        BIO_printf(out, "%02x%s", (unsigned char)s[i],
104280297Sjkim                   ((i + 1) == n) ? "" : ":");
105280297Sjkim    }
106280297Sjkim    BIO_write(out, "\n", 1);
107280297Sjkim    return 1;
10859191Skris}
109