155714Skris/* t_crl.c */
2280304Sjkim/*
3280304Sjkim * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
4280304Sjkim * 1999.
555714Skris */
655714Skris/* ====================================================================
755714Skris * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
855714Skris *
955714Skris * Redistribution and use in source and binary forms, with or without
1055714Skris * modification, are permitted provided that the following conditions
1155714Skris * are met:
1255714Skris *
1355714Skris * 1. Redistributions of source code must retain the above copyright
14280304Sjkim *    notice, this list of conditions and the following disclaimer.
1555714Skris *
1655714Skris * 2. Redistributions in binary form must reproduce the above copyright
1755714Skris *    notice, this list of conditions and the following disclaimer in
1855714Skris *    the documentation and/or other materials provided with the
1955714Skris *    distribution.
2055714Skris *
2155714Skris * 3. All advertising materials mentioning features or use of this
2255714Skris *    software must display the following acknowledgment:
2355714Skris *    "This product includes software developed by the OpenSSL Project
2455714Skris *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2555714Skris *
2655714Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2755714Skris *    endorse or promote products derived from this software without
2855714Skris *    prior written permission. For written permission, please contact
2955714Skris *    licensing@OpenSSL.org.
3055714Skris *
3155714Skris * 5. Products derived from this software may not be called "OpenSSL"
3255714Skris *    nor may "OpenSSL" appear in their names without prior written
3355714Skris *    permission of the OpenSSL Project.
3455714Skris *
3555714Skris * 6. Redistributions of any form whatsoever must retain the following
3655714Skris *    acknowledgment:
3755714Skris *    "This product includes software developed by the OpenSSL Project
3855714Skris *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3955714Skris *
4055714Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
4155714Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4255714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4355714Skris * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4455714Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4555714Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4655714Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4755714Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4955714Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5055714Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
5155714Skris * OF THE POSSIBILITY OF SUCH DAMAGE.
5255714Skris * ====================================================================
5355714Skris *
5455714Skris * This product includes cryptographic software written by Eric Young
5555714Skris * (eay@cryptsoft.com).  This product includes software written by Tim
5655714Skris * Hudson (tjh@cryptsoft.com).
5755714Skris *
5855714Skris */
5955714Skris
6055714Skris#include <stdio.h>
6155714Skris#include "cryptlib.h"
6255714Skris#include <openssl/buffer.h>
6355714Skris#include <openssl/bn.h>
6455714Skris#include <openssl/objects.h>
6555714Skris#include <openssl/x509.h>
6655714Skris#include <openssl/x509v3.h>
6755714Skris
68109998Smarkm#ifndef OPENSSL_NO_FP_API
6955714Skrisint X509_CRL_print_fp(FILE *fp, X509_CRL *x)
70280304Sjkim{
71280304Sjkim    BIO *b;
72280304Sjkim    int ret;
7355714Skris
74280304Sjkim    if ((b = BIO_new(BIO_s_file())) == NULL) {
75280304Sjkim        X509err(X509_F_X509_CRL_PRINT_FP, ERR_R_BUF_LIB);
76280304Sjkim        return (0);
77280304Sjkim    }
78280304Sjkim    BIO_set_fp(b, fp, BIO_NOCLOSE);
79280304Sjkim    ret = X509_CRL_print(b, x);
80280304Sjkim    BIO_free(b);
81280304Sjkim    return (ret);
82280304Sjkim}
8355714Skris#endif
8455714Skris
8555714Skrisint X509_CRL_print(BIO *out, X509_CRL *x)
8655714Skris{
87280304Sjkim    STACK_OF(X509_REVOKED) *rev;
88280304Sjkim    X509_REVOKED *r;
89280304Sjkim    long l;
90280304Sjkim    int i;
91280304Sjkim    char *p;
9255714Skris
93280304Sjkim    BIO_printf(out, "Certificate Revocation List (CRL):\n");
94280304Sjkim    l = X509_CRL_get_version(x);
95280304Sjkim    BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l + 1, l);
96280304Sjkim    i = OBJ_obj2nid(x->sig_alg->algorithm);
97280304Sjkim    X509_signature_print(out, x->sig_alg, NULL);
98280304Sjkim    p = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);
99280304Sjkim    BIO_printf(out, "%8sIssuer: %s\n", "", p);
100280304Sjkim    OPENSSL_free(p);
101280304Sjkim    BIO_printf(out, "%8sLast Update: ", "");
102280304Sjkim    ASN1_TIME_print(out, X509_CRL_get_lastUpdate(x));
103280304Sjkim    BIO_printf(out, "\n%8sNext Update: ", "");
104280304Sjkim    if (X509_CRL_get_nextUpdate(x))
105280304Sjkim        ASN1_TIME_print(out, X509_CRL_get_nextUpdate(x));
106280304Sjkim    else
107280304Sjkim        BIO_printf(out, "NONE");
108280304Sjkim    BIO_printf(out, "\n");
10955714Skris
110280304Sjkim    X509V3_extensions_print(out, "CRL extensions", x->crl->extensions, 0, 8);
11155714Skris
112280304Sjkim    rev = X509_CRL_get_REVOKED(x);
11355714Skris
114280304Sjkim    if (sk_X509_REVOKED_num(rev) > 0)
115280304Sjkim        BIO_printf(out, "Revoked Certificates:\n");
116280304Sjkim    else
117280304Sjkim        BIO_printf(out, "No Revoked Certificates.\n");
11855714Skris
119280304Sjkim    for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
120280304Sjkim        r = sk_X509_REVOKED_value(rev, i);
121280304Sjkim        BIO_printf(out, "    Serial Number: ");
122280304Sjkim        i2a_ASN1_INTEGER(out, r->serialNumber);
123280304Sjkim        BIO_printf(out, "\n        Revocation Date: ");
124280304Sjkim        ASN1_TIME_print(out, r->revocationDate);
125280304Sjkim        BIO_printf(out, "\n");
126280304Sjkim        X509V3_extensions_print(out, "CRL entry extensions",
127280304Sjkim                                r->extensions, 0, 8);
128280304Sjkim    }
129280304Sjkim    X509_signature_print(out, x->sig_alg, x->signature);
13055714Skris
131280304Sjkim    return 1;
13255714Skris
13355714Skris}
134