/src/openssl/crypto/x509/t_crl.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (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 | 0 | { |
21 | 0 | BIO *b; |
22 | 0 | int ret; |
23 | |
|
24 | 0 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
25 | 0 | ERR_raise(ERR_LIB_X509, ERR_R_BUF_LIB); |
26 | 0 | return 0; |
27 | 0 | } |
28 | 0 | BIO_set_fp(b, fp, BIO_NOCLOSE); |
29 | 0 | ret = X509_CRL_print(b, x); |
30 | 0 | BIO_free(b); |
31 | 0 | return ret; |
32 | 0 | } |
33 | | #endif |
34 | | |
35 | | int X509_CRL_print(BIO *out, X509_CRL *x) |
36 | 28.7k | { |
37 | 28.7k | return X509_CRL_print_ex(out, x, XN_FLAG_COMPAT); |
38 | 28.7k | } |
39 | | |
40 | | int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag) |
41 | 7.50k | { |
42 | 7.50k | STACK_OF(X509_REVOKED) *rev; |
43 | 7.50k | X509_REVOKED *r; |
44 | 7.50k | const X509_ALGOR *sig_alg; |
45 | 7.50k | const ASN1_BIT_STRING *sig; |
46 | 7.50k | long l; |
47 | 7.50k | int i; |
48 | 7.50k | char mlch = ' '; |
49 | 7.50k | int nmindent = 0; |
50 | | |
51 | 7.50k | if ((nmflag & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { |
52 | 0 | mlch = '\n'; |
53 | 0 | nmindent = 8; |
54 | 0 | } |
55 | | |
56 | 7.50k | BIO_printf(out, "Certificate Revocation List (CRL):\n"); |
57 | 7.50k | l = X509_CRL_get_version(x); |
58 | 7.50k | if (l >= X509_CRL_VERSION_1 && l <= X509_CRL_VERSION_2) |
59 | 7.14k | BIO_printf(out, "%4sVersion %ld (0x%lx)\n", "", l + 1, (unsigned long)l); |
60 | 353 | else |
61 | 353 | BIO_printf(out, "%4sVersion unknown (%ld)\n", "", l); |
62 | 7.50k | X509_CRL_get0_signature(x, &sig, &sig_alg); |
63 | 7.50k | X509_signature_print(out, sig_alg, NULL); |
64 | 7.50k | BIO_printf(out, "%4sIssuer:%c", "", mlch); |
65 | 7.50k | X509_NAME_print_ex(out, X509_CRL_get_issuer(x), nmindent, nmflag); |
66 | 7.50k | BIO_puts(out, "\n"); |
67 | 7.50k | BIO_printf(out, "%4sLast Update: ", ""); |
68 | 7.50k | ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x)); |
69 | 7.50k | BIO_printf(out, "\n%4sNext Update: ", ""); |
70 | 7.50k | if (X509_CRL_get0_nextUpdate(x)) |
71 | 161 | ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x)); |
72 | 7.34k | else |
73 | 7.34k | BIO_printf(out, "NONE"); |
74 | 7.50k | BIO_printf(out, "\n"); |
75 | | |
76 | 7.50k | X509V3_extensions_print(out, "CRL extensions", |
77 | 7.50k | X509_CRL_get0_extensions(x), 0, 4); |
78 | | |
79 | 7.50k | rev = X509_CRL_get_REVOKED(x); |
80 | | |
81 | 7.50k | if (sk_X509_REVOKED_num(rev) > 0) |
82 | 344 | BIO_printf(out, "Revoked Certificates:\n"); |
83 | 7.15k | else |
84 | 7.15k | BIO_printf(out, "No Revoked Certificates.\n"); |
85 | | |
86 | 20.0k | for (i = 0; i < sk_X509_REVOKED_num(rev); i++) { |
87 | 12.5k | r = sk_X509_REVOKED_value(rev, i); |
88 | 12.5k | BIO_printf(out, " Serial Number: "); |
89 | 12.5k | i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r)); |
90 | 12.5k | BIO_printf(out, "\n Revocation Date: "); |
91 | 12.5k | ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r)); |
92 | 12.5k | BIO_printf(out, "\n"); |
93 | 12.5k | X509V3_extensions_print(out, "CRL entry extensions", |
94 | 12.5k | X509_REVOKED_get0_extensions(r), 0, 8); |
95 | 12.5k | } |
96 | 7.50k | X509_signature_print(out, sig_alg, sig); |
97 | | |
98 | 7.50k | return 1; |
99 | | |
100 | 7.50k | } |