]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/t_crl.c
Added an explicit yield (OP_SLEEP) to QUIC testing for cooperative threading.
[thirdparty/openssl.git] / crypto / x509 / t_crl.c
CommitLineData
0f113f3e 1/*
aff636a4 2 * Copyright 1999-2021 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
4b618848 18#ifndef OPENSSL_NO_STDIO
6b691a5c 19int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
0f113f3e
MC
20{
21 BIO *b;
22 int ret;
0ca5f8b1 23
0f113f3e 24 if ((b = BIO_new(BIO_s_file())) == NULL) {
9311d0c4 25 ERR_raise(ERR_LIB_X509, ERR_R_BUF_LIB);
26a7d938 26 return 0;
0f113f3e
MC
27 }
28 BIO_set_fp(b, fp, BIO_NOCLOSE);
29 ret = X509_CRL_print(b, x);
30 BIO_free(b);
26a7d938 31 return ret;
0f113f3e 32}
0ca5f8b1
DSH
33#endif
34
6b691a5c 35int X509_CRL_print(BIO *out, X509_CRL *x)
b5c4209b
DB
36{
37 return X509_CRL_print_ex(out, x, XN_FLAG_COMPAT);
38}
39
40int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag)
0ca5f8b1 41{
0f113f3e
MC
42 STACK_OF(X509_REVOKED) *rev;
43 X509_REVOKED *r;
5e6089f0
MC
44 const X509_ALGOR *sig_alg;
45 const ASN1_BIT_STRING *sig;
0f113f3e
MC
46 long l;
47 int i;
0ca5f8b1 48
0f113f3e
MC
49 BIO_printf(out, "Certificate Revocation List (CRL):\n");
50 l = X509_CRL_get_version(x);
cdf63a37 51 if (l >= X509_CRL_VERSION_1 && l <= X509_CRL_VERSION_2)
c2ce477f
KR
52 BIO_printf(out, "%8sVersion %ld (0x%lx)\n", "", l + 1, (unsigned long)l);
53 else
54 BIO_printf(out, "%8sVersion unknown (%ld)\n", "", l);
5e6089f0 55 X509_CRL_get0_signature(x, &sig, &sig_alg);
be63fc12 56 BIO_puts(out, " ");
32f5c251 57 X509_signature_print(out, sig_alg, NULL);
b5c4209b
DB
58 BIO_printf(out, "%8sIssuer: ", "");
59 X509_NAME_print_ex(out, X509_CRL_get_issuer(x), 0, nmflag);
60 BIO_puts(out, "\n");
0f113f3e 61 BIO_printf(out, "%8sLast Update: ", "");
568ce3a5 62 ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x));
0f113f3e 63 BIO_printf(out, "\n%8sNext Update: ", "");
568ce3a5
DSH
64 if (X509_CRL_get0_nextUpdate(x))
65 ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x));
0f113f3e
MC
66 else
67 BIO_printf(out, "NONE");
68 BIO_printf(out, "\n");
0ca5f8b1 69
32f5c251
DSH
70 X509V3_extensions_print(out, "CRL extensions",
71 X509_CRL_get0_extensions(x), 0, 8);
0ca5f8b1 72
0f113f3e 73 rev = X509_CRL_get_REVOKED(x);
0ca5f8b1 74
0f113f3e
MC
75 if (sk_X509_REVOKED_num(rev) > 0)
76 BIO_printf(out, "Revoked Certificates:\n");
77 else
78 BIO_printf(out, "No Revoked Certificates.\n");
0ca5f8b1 79
0f113f3e
MC
80 for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
81 r = sk_X509_REVOKED_value(rev, i);
82 BIO_printf(out, " Serial Number: ");
32f5c251 83 i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r));
0f113f3e 84 BIO_printf(out, "\n Revocation Date: ");
32f5c251 85 ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r));
0f113f3e
MC
86 BIO_printf(out, "\n");
87 X509V3_extensions_print(out, "CRL entry extensions",
32f5c251 88 X509_REVOKED_get0_extensions(r), 0, 8);
0f113f3e 89 }
32f5c251 90 X509_signature_print(out, sig_alg, sig);
0ca5f8b1 91
0f113f3e 92 return 1;
0ca5f8b1
DSH
93
94}