]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
454afd98 | 2 | * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. |
0ca5f8b1 | 3 | * |
3e4b43b9 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
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 | |
0ca5f8b1 DSH |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
b39fc560 | 11 | #include "internal/cryptlib.h" |
ec577822 BM |
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> | |
0ca5f8b1 | 17 | |
852c2ed2 RS |
18 | DEFINE_STACK_OF(X509_REVOKED) |
19 | ||
4b618848 | 20 | #ifndef OPENSSL_NO_STDIO |
6b691a5c | 21 | int X509_CRL_print_fp(FILE *fp, X509_CRL *x) |
0f113f3e MC |
22 | { |
23 | BIO *b; | |
24 | int ret; | |
0ca5f8b1 | 25 | |
0f113f3e MC |
26 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
27 | X509err(X509_F_X509_CRL_PRINT_FP, ERR_R_BUF_LIB); | |
26a7d938 | 28 | return 0; |
0f113f3e MC |
29 | } |
30 | BIO_set_fp(b, fp, BIO_NOCLOSE); | |
31 | ret = X509_CRL_print(b, x); | |
32 | BIO_free(b); | |
26a7d938 | 33 | return ret; |
0f113f3e | 34 | } |
0ca5f8b1 DSH |
35 | #endif |
36 | ||
6b691a5c | 37 | int X509_CRL_print(BIO *out, X509_CRL *x) |
b5c4209b DB |
38 | { |
39 | return X509_CRL_print_ex(out, x, XN_FLAG_COMPAT); | |
40 | } | |
41 | ||
42 | int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag) | |
0ca5f8b1 | 43 | { |
0f113f3e MC |
44 | STACK_OF(X509_REVOKED) *rev; |
45 | X509_REVOKED *r; | |
5e6089f0 MC |
46 | const X509_ALGOR *sig_alg; |
47 | const ASN1_BIT_STRING *sig; | |
0f113f3e MC |
48 | long l; |
49 | int i; | |
0ca5f8b1 | 50 | |
0f113f3e MC |
51 | BIO_printf(out, "Certificate Revocation List (CRL):\n"); |
52 | l = X509_CRL_get_version(x); | |
c2ce477f KR |
53 | if (l >= 0 && l <= 1) |
54 | BIO_printf(out, "%8sVersion %ld (0x%lx)\n", "", l + 1, (unsigned long)l); | |
55 | else | |
56 | BIO_printf(out, "%8sVersion unknown (%ld)\n", "", l); | |
5e6089f0 | 57 | X509_CRL_get0_signature(x, &sig, &sig_alg); |
be63fc12 | 58 | BIO_puts(out, " "); |
32f5c251 | 59 | X509_signature_print(out, sig_alg, NULL); |
b5c4209b DB |
60 | BIO_printf(out, "%8sIssuer: ", ""); |
61 | X509_NAME_print_ex(out, X509_CRL_get_issuer(x), 0, nmflag); | |
62 | BIO_puts(out, "\n"); | |
0f113f3e | 63 | BIO_printf(out, "%8sLast Update: ", ""); |
568ce3a5 | 64 | ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x)); |
0f113f3e | 65 | BIO_printf(out, "\n%8sNext Update: ", ""); |
568ce3a5 DSH |
66 | if (X509_CRL_get0_nextUpdate(x)) |
67 | ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x)); | |
0f113f3e MC |
68 | else |
69 | BIO_printf(out, "NONE"); | |
70 | BIO_printf(out, "\n"); | |
0ca5f8b1 | 71 | |
32f5c251 DSH |
72 | X509V3_extensions_print(out, "CRL extensions", |
73 | X509_CRL_get0_extensions(x), 0, 8); | |
0ca5f8b1 | 74 | |
0f113f3e | 75 | rev = X509_CRL_get_REVOKED(x); |
0ca5f8b1 | 76 | |
0f113f3e MC |
77 | if (sk_X509_REVOKED_num(rev) > 0) |
78 | BIO_printf(out, "Revoked Certificates:\n"); | |
79 | else | |
80 | BIO_printf(out, "No Revoked Certificates.\n"); | |
0ca5f8b1 | 81 | |
0f113f3e MC |
82 | for (i = 0; i < sk_X509_REVOKED_num(rev); i++) { |
83 | r = sk_X509_REVOKED_value(rev, i); | |
84 | BIO_printf(out, " Serial Number: "); | |
32f5c251 | 85 | i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r)); |
0f113f3e | 86 | BIO_printf(out, "\n Revocation Date: "); |
32f5c251 | 87 | ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r)); |
0f113f3e MC |
88 | BIO_printf(out, "\n"); |
89 | X509V3_extensions_print(out, "CRL entry extensions", | |
32f5c251 | 90 | X509_REVOKED_get0_extensions(r), 0, 8); |
0f113f3e | 91 | } |
32f5c251 | 92 | X509_signature_print(out, sig_alg, sig); |
0ca5f8b1 | 93 | |
0f113f3e | 94 | return 1; |
0ca5f8b1 DSH |
95 | |
96 | } |