Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/x509/t_crl.c

raw
1 // Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #include <assert.h>
5
6 #include <openssl/asn1.h>
7 #include <openssl/err.h>
8 #include <openssl/mem.h>
9 #include <openssl/obj.h>
10 #include <openssl/x509.h>
11
12
13 int X509_CRL_print_fp(FILE *fp, X509_CRL *x) {
14 BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);
15 if (b == NULL) {
16 OPENSSL_PUT_ERROR(X509, ERR_R_BUF_LIB);
17 return 0;
18 }
19 int ret = X509_CRL_print(b, x);
20 BIO_free(b);
21 return ret;
22 }
23
24 int X509_CRL_print(BIO *out, X509_CRL *x) {
25 long version = X509_CRL_get_version(x);
26 assert(X509_CRL_VERSION_1 <= version && version <= X509_CRL_VERSION_2);
27 const X509_ALGOR *sig_alg;
28 const ASN1_BIT_STRING *signature;
29 X509_CRL_get0_signature(x, &signature, &sig_alg);
30 if (BIO_printf(out, "Certificate Revocation List (CRL):\n") <= 0 ||
31 BIO_printf(out, "%8sVersion %ld (0x%lx)\n", "", version + 1,
32 (unsigned long)version) <= 0 ||
33 // Note this and the other |X509_signature_print| call both print the
34 // outer signature algorithm, rather than printing the inner and outer
35 // ones separately. This matches OpenSSL, though it was probably a bug.
36 !X509_signature_print(out, sig_alg, NULL)) {
37 return 0;
38 }
39
40 char *issuer = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);
41 int ok = issuer != NULL && BIO_printf(out, "%8sIssuer: %s\n", "", issuer) > 0;
42 OPENSSL_free(issuer);
43 if (!ok) {
44 return 0;
45 }
46
47 if (BIO_printf(out, "%8sLast Update: ", "") <= 0 ||
48 !ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x)) ||
49 BIO_printf(out, "\n%8sNext Update: ", "") <= 0) {
50 return 0;
51 }
52 if (X509_CRL_get0_nextUpdate(x)) {
53 if (!ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x))) {
54 return 0;
55 }
56 } else {
57 if (BIO_printf(out, "NONE") <= 0) {
58 return 0;
59 }
60 }
61
62 if (BIO_printf(out, "\n") <= 0 ||
63 !X509V3_extensions_print(out, "CRL extensions",
64 X509_CRL_get0_extensions(x), 0, 8)) {
65 return 0;
66 }
67
68 const STACK_OF(X509_REVOKED) *rev = X509_CRL_get_REVOKED(x);
69 if (sk_X509_REVOKED_num(rev) > 0) {
70 if (BIO_printf(out, "Revoked Certificates:\n") <= 0) {
71 return 0;
72 }
73 } else {
74 if (BIO_printf(out, "No Revoked Certificates.\n") <= 0) {
75 return 0;
76 }
77 }
78
79 for (size_t i = 0; i < sk_X509_REVOKED_num(rev); i++) {
80 const X509_REVOKED *r = sk_X509_REVOKED_value(rev, i);
81 if (BIO_printf(out, " Serial Number: ") <= 0 ||
82 i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r)) <= 0 ||
83 BIO_printf(out, "\n Revocation Date: ") <= 0 ||
84 !ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r)) ||
85 BIO_printf(out, "\n") <= 0 ||
86 !X509V3_extensions_print(out, "CRL entry extensions",
87 X509_REVOKED_get0_extensions(r), 0, 8)) {
88 }
89 }
90
91 return X509_signature_print(out, sig_alg, signature);
92 }