]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/t_crl.c
Fix undefined behaviour when printing the X509 and CRL version
[thirdparty/openssl.git] / crypto / x509 / t_crl.c
CommitLineData
0f113f3e 1/*
b1322259 2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
0ca5f8b1 3 *
b1322259
RS
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
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
MC
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}
0ca5f8b1
DSH
33#endif
34
6b691a5c 35int X509_CRL_print(BIO *out, X509_CRL *x)
0ca5f8b1 36{
0f113f3e
MC
37 STACK_OF(X509_REVOKED) *rev;
38 X509_REVOKED *r;
5e6089f0
MC
39 const X509_ALGOR *sig_alg;
40 const ASN1_BIT_STRING *sig;
0f113f3e
MC
41 long l;
42 int i;
43 char *p;
0ca5f8b1 44
0f113f3e
MC
45 BIO_printf(out, "Certificate Revocation List (CRL):\n");
46 l = X509_CRL_get_version(x);
c2ce477f
KR
47 if (l >= 0 && l <= 1)
48 BIO_printf(out, "%8sVersion %ld (0x%lx)\n", "", l + 1, (unsigned long)l);
49 else
50 BIO_printf(out, "%8sVersion unknown (%ld)\n", "", l);
5e6089f0 51 X509_CRL_get0_signature(x, &sig, &sig_alg);
32f5c251 52 X509_signature_print(out, sig_alg, NULL);
0f113f3e
MC
53 p = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);
54 BIO_printf(out, "%8sIssuer: %s\n", "", p);
55 OPENSSL_free(p);
56 BIO_printf(out, "%8sLast Update: ", "");
568ce3a5 57 ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x));
0f113f3e 58 BIO_printf(out, "\n%8sNext Update: ", "");
568ce3a5
DSH
59 if (X509_CRL_get0_nextUpdate(x))
60 ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x));
0f113f3e
MC
61 else
62 BIO_printf(out, "NONE");
63 BIO_printf(out, "\n");
0ca5f8b1 64
32f5c251
DSH
65 X509V3_extensions_print(out, "CRL extensions",
66 X509_CRL_get0_extensions(x), 0, 8);
0ca5f8b1 67
0f113f3e 68 rev = X509_CRL_get_REVOKED(x);
0ca5f8b1 69
0f113f3e
MC
70 if (sk_X509_REVOKED_num(rev) > 0)
71 BIO_printf(out, "Revoked Certificates:\n");
72 else
73 BIO_printf(out, "No Revoked Certificates.\n");
0ca5f8b1 74
0f113f3e
MC
75 for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
76 r = sk_X509_REVOKED_value(rev, i);
77 BIO_printf(out, " Serial Number: ");
32f5c251 78 i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r));
0f113f3e 79 BIO_printf(out, "\n Revocation Date: ");
32f5c251 80 ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r));
0f113f3e
MC
81 BIO_printf(out, "\n");
82 X509V3_extensions_print(out, "CRL entry extensions",
32f5c251 83 X509_REVOKED_get0_extensions(r), 0, 8);
0f113f3e 84 }
32f5c251 85 X509_signature_print(out, sig_alg, sig);
0ca5f8b1 86
0f113f3e 87 return 1;
0ca5f8b1
DSH
88
89}