Add setter and getter for X509_STORE's check_policy
[openssl.git] / crypto / x509 / t_crl.c
1 /*
2  * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <stdio.h>
11 #include "internal/cryptlib.h"
12 #include <openssl/buffer.h>
13 #include <openssl/bn.h>
14 #include <openssl/objects.h>
15 #include <openssl/x509.h>
16 #include <openssl/x509v3.h>
17
18 #ifndef OPENSSL_NO_STDIO
19 int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
20 {
21     BIO *b;
22     int ret;
23
24     if ((b = BIO_new(BIO_s_file())) == NULL) {
25         X509err(X509_F_X509_CRL_PRINT_FP, ERR_R_BUF_LIB);
26         return (0);
27     }
28     BIO_set_fp(b, fp, BIO_NOCLOSE);
29     ret = X509_CRL_print(b, x);
30     BIO_free(b);
31     return (ret);
32 }
33 #endif
34
35 int X509_CRL_print(BIO *out, X509_CRL *x)
36 {
37     STACK_OF(X509_REVOKED) *rev;
38     X509_REVOKED *r;
39     X509_ALGOR *sig_alg;
40     ASN1_BIT_STRING *sig;
41     long l;
42     int i;
43     char *p;
44
45     BIO_printf(out, "Certificate Revocation List (CRL):\n");
46     l = X509_CRL_get_version(x);
47     BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l + 1, l);
48     X509_CRL_get0_signature(&sig, &sig_alg, x);
49     X509_signature_print(out, sig_alg, NULL);
50     p = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);
51     BIO_printf(out, "%8sIssuer: %s\n", "", p);
52     OPENSSL_free(p);
53     BIO_printf(out, "%8sLast Update: ", "");
54     ASN1_TIME_print(out, X509_CRL_get_lastUpdate(x));
55     BIO_printf(out, "\n%8sNext Update: ", "");
56     if (X509_CRL_get_nextUpdate(x))
57         ASN1_TIME_print(out, X509_CRL_get_nextUpdate(x));
58     else
59         BIO_printf(out, "NONE");
60     BIO_printf(out, "\n");
61
62     X509V3_extensions_print(out, "CRL extensions",
63                             X509_CRL_get0_extensions(x), 0, 8);
64
65     rev = X509_CRL_get_REVOKED(x);
66
67     if (sk_X509_REVOKED_num(rev) > 0)
68         BIO_printf(out, "Revoked Certificates:\n");
69     else
70         BIO_printf(out, "No Revoked Certificates.\n");
71
72     for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
73         r = sk_X509_REVOKED_value(rev, i);
74         BIO_printf(out, "    Serial Number: ");
75         i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r));
76         BIO_printf(out, "\n        Revocation Date: ");
77         ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r));
78         BIO_printf(out, "\n");
79         X509V3_extensions_print(out, "CRL entry extensions",
80                                 X509_REVOKED_get0_extensions(r), 0, 8);
81     }
82     X509_signature_print(out, sig_alg, sig);
83
84     return 1;
85
86 }