New function X509V3_extensions_print() this removes extension duplication
[openssl.git] / crypto / ocsp / ocsp_prn.c
1 /* ocsp_cid.c */
2 /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3  * project. */
4
5 /* History:
6    This file was originally part of ocsp.c and was transfered to Richard
7    Levitte from CertCo by Kathy Weinhold in mid-spring 2000 to be included
8    in OpenSSL or released as a patch kit. */
9
10 /* ====================================================================
11  * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  *
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer. 
19  *
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in
22  *    the documentation and/or other materials provided with the
23  *    distribution.
24  *
25  * 3. All advertising materials mentioning features or use of this
26  *    software must display the following acknowledgment:
27  *    "This product includes software developed by the OpenSSL Project
28  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29  *
30  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31  *    endorse or promote products derived from this software without
32  *    prior written permission. For written permission, please contact
33  *    openssl-core@openssl.org.
34  *
35  * 5. Products derived from this software may not be called "OpenSSL"
36  *    nor may "OpenSSL" appear in their names without prior written
37  *    permission of the OpenSSL Project.
38  *
39  * 6. Redistributions of any form whatsoever must retain the following
40  *    acknowledgment:
41  *    "This product includes software developed by the OpenSSL Project
42  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43  *
44  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
48  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55  * OF THE POSSIBILITY OF SUCH DAMAGE.
56  * ====================================================================
57  *
58  * This product includes cryptographic software written by Eric Young
59  * (eay@cryptsoft.com).  This product includes software written by Tim
60  * Hudson (tjh@cryptsoft.com).
61  *
62  */
63
64 #include <openssl/bio.h>
65 #include <openssl/err.h>
66 #include <openssl/ocsp.h>
67 #include <openssl/x509.h>
68
69 int OCSP_CERTID_print(BIO *bp, OCSP_CERTID* a, int indent)
70         {
71         BIO_printf(bp, "%*sCertificate ID:\n", indent, "");
72         indent += 2;
73         BIO_printf(bp, "%*sHash Algorithm: ", indent, "");
74         i2a_ASN1_OBJECT(bp, a->hashAlgorithm->algorithm);
75         BIO_printf(bp, "\n%*sIssuer Name Hash: ", indent, "");
76         i2a_ASN1_STRING(bp, a->issuerNameHash, V_ASN1_OCTET_STRING);
77         BIO_printf(bp, "\n%*sIssuer Key Hash: ", indent, "");
78         i2a_ASN1_STRING(bp, a->issuerKeyHash, V_ASN1_OCTET_STRING);
79         BIO_printf(bp, "\n%*sSerial Number: ", indent, "");
80         i2a_ASN1_INTEGER(bp, a->serialNumber);
81         BIO_printf(bp, "\n");
82         return 1;
83         }
84
85 int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags)
86         {
87         int i;
88         long l;
89         OCSP_CERTID* cid = NULL;
90         OCSP_ONEREQ *one = NULL;
91         OCSP_REQINFO *inf = o->tbsRequest;
92         OCSP_SIGNATURE *sig = o->optionalSignature;
93
94         if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err;
95         l=ASN1_INTEGER_get(inf->version);
96         if (BIO_printf(bp,"%4sVersion: %lu (0x%lx)","",l+1,l) <= 0) goto err;
97         if (inf->requestorName != NULL)
98                 {
99                 if (BIO_write(bp,"\n    Requestor Name: ",21) <= 0) 
100                         goto err;
101                 GENERAL_NAME_print(bp, inf->requestorName);
102                 }
103         if (BIO_write(bp,"\n    Requestor List:\n",21) <= 0) goto err;
104         for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++)
105                 {
106                 if (!sk_OCSP_ONEREQ_value(inf->requestList, i)) continue;
107                 one = sk_OCSP_ONEREQ_value(inf->requestList, i);
108                 cid = one->reqCert;
109                 OCSP_CERTID_print(bp, cid, 8);
110                 if (!X509V3_extensions_print(bp,
111                                         "OCSP Request Single Extensions",
112                                         one->singleRequestExtensions, flags, 4))
113                                                         goto err;
114                 }
115         if (!X509V3_extensions_print(bp, "OCSP Request Extensions",
116                         inf->requestExtensions, flags, 4))
117                                                         goto err;
118         if (sig)
119                 {
120                 X509_signature_print(bp, sig->signatureAlgorithm, sig->signature);
121                 }
122         return 1;
123 err:
124         return 0;
125         }