Coverage Report

Created: 2023-06-08 06:40

/src/openssl111/crypto/x509/t_crl.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 *
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
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
        X509err(X509_F_X509_CRL_PRINT_FP, 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
6.74k
{
37
6.74k
  return X509_CRL_print_ex(out, x, XN_FLAG_COMPAT);
38
6.74k
}
39
40
int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag)
41
6.74k
{
42
6.74k
    STACK_OF(X509_REVOKED) *rev;
43
6.74k
    X509_REVOKED *r;
44
6.74k
    const X509_ALGOR *sig_alg;
45
6.74k
    const ASN1_BIT_STRING *sig;
46
6.74k
    long l;
47
6.74k
    int i;
48
49
6.74k
    BIO_printf(out, "Certificate Revocation List (CRL):\n");
50
6.74k
    l = X509_CRL_get_version(x);
51
6.74k
    if (l >= 0 && l <= 1)
52
6.35k
        BIO_printf(out, "%8sVersion %ld (0x%lx)\n", "", l + 1, (unsigned long)l);
53
399
    else
54
399
        BIO_printf(out, "%8sVersion unknown (%ld)\n", "", l);
55
6.74k
    X509_CRL_get0_signature(x, &sig, &sig_alg);
56
6.74k
    BIO_puts(out, "    ");
57
6.74k
    X509_signature_print(out, sig_alg, NULL);
58
6.74k
    BIO_printf(out, "%8sIssuer: ", "");
59
6.74k
    X509_NAME_print_ex(out, X509_CRL_get_issuer(x), 0, nmflag);
60
6.74k
    BIO_puts(out, "\n");
61
6.74k
    BIO_printf(out, "%8sLast Update: ", "");
62
6.74k
    ASN1_TIME_print(out, X509_CRL_get0_lastUpdate(x));
63
6.74k
    BIO_printf(out, "\n%8sNext Update: ", "");
64
6.74k
    if (X509_CRL_get0_nextUpdate(x))
65
140
        ASN1_TIME_print(out, X509_CRL_get0_nextUpdate(x));
66
6.60k
    else
67
6.60k
        BIO_printf(out, "NONE");
68
6.74k
    BIO_printf(out, "\n");
69
70
6.74k
    X509V3_extensions_print(out, "CRL extensions",
71
6.74k
                            X509_CRL_get0_extensions(x), 0, 8);
72
73
6.74k
    rev = X509_CRL_get_REVOKED(x);
74
75
6.74k
    if (sk_X509_REVOKED_num(rev) > 0)
76
535
        BIO_printf(out, "Revoked Certificates:\n");
77
6.21k
    else
78
6.21k
        BIO_printf(out, "No Revoked Certificates.\n");
79
80
22.9k
    for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
81
16.1k
        r = sk_X509_REVOKED_value(rev, i);
82
16.1k
        BIO_printf(out, "    Serial Number: ");
83
16.1k
        i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r));
84
16.1k
        BIO_printf(out, "\n        Revocation Date: ");
85
16.1k
        ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r));
86
16.1k
        BIO_printf(out, "\n");
87
16.1k
        X509V3_extensions_print(out, "CRL entry extensions",
88
16.1k
                                X509_REVOKED_get0_extensions(r), 0, 8);
89
16.1k
    }
90
6.74k
    X509_signature_print(out, sig_alg, sig);
91
92
6.74k
    return 1;
93
94
6.74k
}