xref: /openbsd/lib/libcrypto/asn1/t_crl.c (revision 26830284)
1*26830284Stb /* $OpenBSD: t_crl.c,v 1.26 2024/05/03 02:52:00 tb Exp $ */
2e6841c1dSdjm /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3913ec974Sbeck  * project 1999.
4913ec974Sbeck  */
5913ec974Sbeck /* ====================================================================
6913ec974Sbeck  * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
7913ec974Sbeck  *
8913ec974Sbeck  * Redistribution and use in source and binary forms, with or without
9913ec974Sbeck  * modification, are permitted provided that the following conditions
10913ec974Sbeck  * are met:
11913ec974Sbeck  *
12913ec974Sbeck  * 1. Redistributions of source code must retain the above copyright
13913ec974Sbeck  *    notice, this list of conditions and the following disclaimer.
14913ec974Sbeck  *
15913ec974Sbeck  * 2. Redistributions in binary form must reproduce the above copyright
16913ec974Sbeck  *    notice, this list of conditions and the following disclaimer in
17913ec974Sbeck  *    the documentation and/or other materials provided with the
18913ec974Sbeck  *    distribution.
19913ec974Sbeck  *
20913ec974Sbeck  * 3. All advertising materials mentioning features or use of this
21913ec974Sbeck  *    software must display the following acknowledgment:
22913ec974Sbeck  *    "This product includes software developed by the OpenSSL Project
23913ec974Sbeck  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24913ec974Sbeck  *
25913ec974Sbeck  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26913ec974Sbeck  *    endorse or promote products derived from this software without
27913ec974Sbeck  *    prior written permission. For written permission, please contact
28913ec974Sbeck  *    licensing@OpenSSL.org.
29913ec974Sbeck  *
30913ec974Sbeck  * 5. Products derived from this software may not be called "OpenSSL"
31913ec974Sbeck  *    nor may "OpenSSL" appear in their names without prior written
32913ec974Sbeck  *    permission of the OpenSSL Project.
33913ec974Sbeck  *
34913ec974Sbeck  * 6. Redistributions of any form whatsoever must retain the following
35913ec974Sbeck  *    acknowledgment:
36913ec974Sbeck  *    "This product includes software developed by the OpenSSL Project
37913ec974Sbeck  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38913ec974Sbeck  *
39913ec974Sbeck  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40913ec974Sbeck  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41913ec974Sbeck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42913ec974Sbeck  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43913ec974Sbeck  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44913ec974Sbeck  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45913ec974Sbeck  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46913ec974Sbeck  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47913ec974Sbeck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48913ec974Sbeck  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49913ec974Sbeck  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50913ec974Sbeck  * OF THE POSSIBILITY OF SUCH DAMAGE.
51913ec974Sbeck  * ====================================================================
52913ec974Sbeck  *
53913ec974Sbeck  * This product includes cryptographic software written by Eric Young
54913ec974Sbeck  * (eay@cryptsoft.com).  This product includes software written by Tim
55913ec974Sbeck  * Hudson (tjh@cryptsoft.com).
56913ec974Sbeck  *
57913ec974Sbeck  */
58913ec974Sbeck 
59913ec974Sbeck #include <stdio.h>
603c3e846bStb #include <limits.h>
61b6ab114eSjsing 
62913ec974Sbeck #include <openssl/bn.h>
63b6ab114eSjsing #include <openssl/buffer.h>
64b6ab114eSjsing #include <openssl/err.h>
65913ec974Sbeck #include <openssl/objects.h>
66913ec974Sbeck #include <openssl/x509.h>
67913ec974Sbeck #include <openssl/x509v3.h>
68913ec974Sbeck 
69c9675a23Stb #include "x509_local.h"
70838f0b6dStb 
712d55eb43Sjsing int
X509_CRL_print_fp(FILE * fp,X509_CRL * x)722d55eb43Sjsing X509_CRL_print_fp(FILE *fp, X509_CRL *x)
73913ec974Sbeck {
74913ec974Sbeck 	BIO *b;
75913ec974Sbeck 	int ret;
76913ec974Sbeck 
77cc777fd4Stedu 	if ((b = BIO_new(BIO_s_file())) == NULL) {
785067ae9fSbeck 		X509error(ERR_R_BUF_LIB);
79913ec974Sbeck 		return (0);
80913ec974Sbeck 	}
81913ec974Sbeck 	BIO_set_fp(b, fp, BIO_NOCLOSE);
82913ec974Sbeck 	ret = X509_CRL_print(b, x);
83913ec974Sbeck 	BIO_free(b);
84913ec974Sbeck 	return (ret);
85913ec974Sbeck }
86e1608179Sbeck LCRYPTO_ALIAS(X509_CRL_print_fp);
87913ec974Sbeck 
882d55eb43Sjsing int
X509_CRL_print(BIO * out,X509_CRL * x)892d55eb43Sjsing X509_CRL_print(BIO *out, X509_CRL *x)
90913ec974Sbeck {
91913ec974Sbeck 	STACK_OF(X509_REVOKED) *rev;
92913ec974Sbeck 	X509_REVOKED *r;
93913ec974Sbeck 	long l;
94c32db552Sdjm 	int i;
95767fe2ffSmarkus 	char *p;
96913ec974Sbeck 
97913ec974Sbeck 	BIO_printf(out, "Certificate Revocation List (CRL):\n");
98913ec974Sbeck 	l = X509_CRL_get_version(x);
99*26830284Stb 	if (l >= 0 && l <= 1) {
100*26830284Stb 		if (BIO_printf(out, "%8sVersion: %lu (0x%lx)\n",
101*26830284Stb 		    "", l + 1, l) <= 0)
1023c3e846bStb 			goto err;
103*26830284Stb 	} else {
104*26830284Stb 		if (BIO_printf(out, "%8sVersion: unknown (%ld)\n",
105*26830284Stb 		    "", l) <= 0)
106*26830284Stb 			goto err;
107*26830284Stb 	}
10896ab8a0eSmiod 	if (X509_signature_print(out, x->sig_alg, NULL) == 0)
10996ab8a0eSmiod 		goto err;
110767fe2ffSmarkus 	p = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);
11196ab8a0eSmiod 	if (p == NULL)
11296ab8a0eSmiod 		goto err;
113767fe2ffSmarkus 	BIO_printf(out, "%8sIssuer: %s\n", "", p);
1146f3a6cb1Sbeck 	free(p);
115913ec974Sbeck 	BIO_printf(out, "%8sLast Update: ", "");
116913ec974Sbeck 	ASN1_TIME_print(out, X509_CRL_get_lastUpdate(x));
117913ec974Sbeck 	BIO_printf(out, "\n%8sNext Update: ", "");
118913ec974Sbeck 	if (X509_CRL_get_nextUpdate(x))
119913ec974Sbeck 		ASN1_TIME_print(out, X509_CRL_get_nextUpdate(x));
1202d55eb43Sjsing 	else
1212d55eb43Sjsing 		BIO_printf(out, "NONE");
122913ec974Sbeck 	BIO_printf(out, "\n");
123913ec974Sbeck 
124da347917Sbeck 	X509V3_extensions_print(out, "CRL extensions",
125da347917Sbeck 	    x->crl->extensions, 0, 8);
126913ec974Sbeck 
127913ec974Sbeck 	rev = X509_CRL_get_REVOKED(x);
128913ec974Sbeck 
129da347917Sbeck 	if (sk_X509_REVOKED_num(rev) > 0)
130913ec974Sbeck 		BIO_printf(out, "Revoked Certificates:\n");
1312d55eb43Sjsing 	else
1322d55eb43Sjsing 		BIO_printf(out, "No Revoked Certificates.\n");
133913ec974Sbeck 
134913ec974Sbeck 	for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
135913ec974Sbeck 		r = sk_X509_REVOKED_value(rev, i);
136913ec974Sbeck 		BIO_printf(out, "    Serial Number: ");
137913ec974Sbeck 		i2a_ASN1_INTEGER(out, r->serialNumber);
1384fcf65c5Sdjm 		BIO_printf(out, "\n        Revocation Date: ");
139913ec974Sbeck 		ASN1_TIME_print(out, r->revocationDate);
140913ec974Sbeck 		BIO_printf(out, "\n");
141da347917Sbeck 		X509V3_extensions_print(out, "CRL entry extensions",
142da347917Sbeck 		    r->extensions, 0, 8);
143913ec974Sbeck 	}
14496ab8a0eSmiod 	if (X509_signature_print(out, x->sig_alg, x->signature) == 0)
14596ab8a0eSmiod 		goto err;
146913ec974Sbeck 
147913ec974Sbeck 	return 1;
148913ec974Sbeck 
14996ab8a0eSmiod  err:
15096ab8a0eSmiod 	return 0;
151913ec974Sbeck }
152e1608179Sbeck LCRYPTO_ALIAS(X509_CRL_print);
153