155714Skris/* t_crl.c */
2194206Ssimon/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
355714Skris * project 1999.
455714Skris */
555714Skris/* ====================================================================
655714Skris * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
755714Skris *
855714Skris * Redistribution and use in source and binary forms, with or without
955714Skris * modification, are permitted provided that the following conditions
1055714Skris * are met:
1155714Skris *
1255714Skris * 1. Redistributions of source code must retain the above copyright
1355714Skris *    notice, this list of conditions and the following disclaimer.
1455714Skris *
1555714Skris * 2. Redistributions in binary form must reproduce the above copyright
1655714Skris *    notice, this list of conditions and the following disclaimer in
1755714Skris *    the documentation and/or other materials provided with the
1855714Skris *    distribution.
1955714Skris *
2055714Skris * 3. All advertising materials mentioning features or use of this
2155714Skris *    software must display the following acknowledgment:
2255714Skris *    "This product includes software developed by the OpenSSL Project
2355714Skris *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2455714Skris *
2555714Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2655714Skris *    endorse or promote products derived from this software without
2755714Skris *    prior written permission. For written permission, please contact
2855714Skris *    licensing@OpenSSL.org.
2955714Skris *
3055714Skris * 5. Products derived from this software may not be called "OpenSSL"
3155714Skris *    nor may "OpenSSL" appear in their names without prior written
3255714Skris *    permission of the OpenSSL Project.
3355714Skris *
3455714Skris * 6. Redistributions of any form whatsoever must retain the following
3555714Skris *    acknowledgment:
3655714Skris *    "This product includes software developed by the OpenSSL Project
3755714Skris *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3855714Skris *
3955714Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
4055714Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4155714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4255714Skris * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4355714Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4455714Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4555714Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4655714Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4755714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4855714Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4955714Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
5055714Skris * OF THE POSSIBILITY OF SUCH DAMAGE.
5155714Skris * ====================================================================
5255714Skris *
5355714Skris * This product includes cryptographic software written by Eric Young
5455714Skris * (eay@cryptsoft.com).  This product includes software written by Tim
5555714Skris * Hudson (tjh@cryptsoft.com).
5655714Skris *
5755714Skris */
5855714Skris
5955714Skris#include <stdio.h>
6055714Skris#include "cryptlib.h"
6155714Skris#include <openssl/buffer.h>
6255714Skris#include <openssl/bn.h>
6355714Skris#include <openssl/objects.h>
6455714Skris#include <openssl/x509.h>
6555714Skris#include <openssl/x509v3.h>
6655714Skris
67109998Smarkm#ifndef OPENSSL_NO_FP_API
6855714Skrisint X509_CRL_print_fp(FILE *fp, X509_CRL *x)
6955714Skris        {
7055714Skris        BIO *b;
7155714Skris        int ret;
7255714Skris
7355714Skris        if ((b=BIO_new(BIO_s_file())) == NULL)
7455714Skris		{
75160814Ssimon		X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB);
7655714Skris                return(0);
7755714Skris		}
7855714Skris        BIO_set_fp(b,fp,BIO_NOCLOSE);
7955714Skris        ret=X509_CRL_print(b, x);
8055714Skris        BIO_free(b);
8155714Skris        return(ret);
8255714Skris        }
8355714Skris#endif
8455714Skris
8555714Skrisint X509_CRL_print(BIO *out, X509_CRL *x)
8655714Skris{
8755714Skris	STACK_OF(X509_REVOKED) *rev;
8855714Skris	X509_REVOKED *r;
8955714Skris	long l;
90215697Ssimon	int i;
91109998Smarkm	char *p;
9255714Skris
9355714Skris	BIO_printf(out, "Certificate Revocation List (CRL):\n");
9455714Skris	l = X509_CRL_get_version(x);
9555714Skris	BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
9655714Skris	i = OBJ_obj2nid(x->sig_alg->algorithm);
97238405Sjkim	X509_signature_print(out, x->sig_alg, NULL);
98109998Smarkm	p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0);
99109998Smarkm	BIO_printf(out,"%8sIssuer: %s\n","",p);
100109998Smarkm	OPENSSL_free(p);
10155714Skris	BIO_printf(out,"%8sLast Update: ","");
10255714Skris	ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
10355714Skris	BIO_printf(out,"\n%8sNext Update: ","");
10455714Skris	if (X509_CRL_get_nextUpdate(x))
10555714Skris		 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
10655714Skris	else BIO_printf(out,"NONE");
10755714Skris	BIO_printf(out,"\n");
10855714Skris
109109998Smarkm	X509V3_extensions_print(out, "CRL extensions",
110109998Smarkm						x->crl->extensions, 0, 8);
11155714Skris
11255714Skris	rev = X509_CRL_get_REVOKED(x);
11355714Skris
114109998Smarkm	if(sk_X509_REVOKED_num(rev) > 0)
11555714Skris	    BIO_printf(out, "Revoked Certificates:\n");
11655714Skris	else BIO_printf(out, "No Revoked Certificates.\n");
11755714Skris
11855714Skris	for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
11955714Skris		r = sk_X509_REVOKED_value(rev, i);
12055714Skris		BIO_printf(out,"    Serial Number: ");
12155714Skris		i2a_ASN1_INTEGER(out,r->serialNumber);
122160814Ssimon		BIO_printf(out,"\n        Revocation Date: ");
12355714Skris		ASN1_TIME_print(out,r->revocationDate);
12455714Skris		BIO_printf(out,"\n");
125109998Smarkm		X509V3_extensions_print(out, "CRL entry extensions",
126109998Smarkm						r->extensions, 0, 8);
12755714Skris	}
128109998Smarkm	X509_signature_print(out, x->sig_alg, x->signature);
12955714Skris
13055714Skris	return 1;
13155714Skris
13255714Skris}
133