Coverage Report

Created: 2025-06-13 06:58

/src/openssl30/crypto/ts/ts_lib.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2006-2018 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/objects.h>
13
#include <openssl/bn.h>
14
#include <openssl/x509.h>
15
#include <openssl/x509v3.h>
16
#include <openssl/ts.h>
17
#include "ts_local.h"
18
19
int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num)
20
1.10k
{
21
1.10k
    BIGNUM *num_bn;
22
1.10k
    int result = 0;
23
1.10k
    char *hex;
24
25
1.10k
    num_bn = ASN1_INTEGER_to_BN(num, NULL);
26
1.10k
    if (num_bn == NULL)
27
0
        return -1;
28
1.10k
    if ((hex = BN_bn2hex(num_bn))) {
29
1.10k
        result = BIO_write(bio, "0x", 2) > 0;
30
1.10k
        result = result && BIO_write(bio, hex, strlen(hex)) > 0;
31
1.10k
        OPENSSL_free(hex);
32
1.10k
    }
33
1.10k
    BN_free(num_bn);
34
35
1.10k
    return result;
36
1.10k
}
37
38
int TS_OBJ_print_bio(BIO *bio, const ASN1_OBJECT *obj)
39
44
{
40
44
    char obj_txt[128];
41
42
44
    OBJ_obj2txt(obj_txt, sizeof(obj_txt), obj, 0);
43
44
    BIO_printf(bio, "%s\n", obj_txt);
44
45
44
    return 1;
46
44
}
47
48
int TS_ext_print_bio(BIO *bio, const STACK_OF(X509_EXTENSION) *extensions)
49
4.03k
{
50
4.03k
    int i, critical, n;
51
4.03k
    X509_EXTENSION *ex;
52
4.03k
    ASN1_OBJECT *obj;
53
54
4.03k
    BIO_printf(bio, "Extensions:\n");
55
4.03k
    n = X509v3_get_ext_count(extensions);
56
125k
    for (i = 0; i < n; i++) {
57
121k
        ex = X509v3_get_ext(extensions, i);
58
121k
        obj = X509_EXTENSION_get_object(ex);
59
121k
        if (i2a_ASN1_OBJECT(bio, obj) < 0)
60
0
            return 0;
61
121k
        critical = X509_EXTENSION_get_critical(ex);
62
121k
        BIO_printf(bio, ":%s\n", critical ? " critical" : "");
63
121k
        if (!X509V3_EXT_print(bio, ex, 0, 4)) {
64
71.5k
            BIO_printf(bio, "%4s", "");
65
71.5k
            ASN1_STRING_print(bio, X509_EXTENSION_get_data(ex));
66
71.5k
        }
67
121k
        BIO_write(bio, "\n", 1);
68
121k
    }
69
70
4.03k
    return 1;
71
4.03k
}
72
73
int TS_X509_ALGOR_print_bio(BIO *bio, const X509_ALGOR *alg)
74
4.07k
{
75
4.07k
    int i = OBJ_obj2nid(alg->algorithm);
76
4.07k
    return BIO_printf(bio, "Hash Algorithm: %s\n",
77
4.07k
                      (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
78
4.07k
}
79
80
int TS_MSG_IMPRINT_print_bio(BIO *bio, TS_MSG_IMPRINT *a)
81
4.07k
{
82
4.07k
    ASN1_OCTET_STRING *msg;
83
84
4.07k
    TS_X509_ALGOR_print_bio(bio, a->hash_algo);
85
86
4.07k
    BIO_printf(bio, "Message data:\n");
87
4.07k
    msg = a->hashed_msg;
88
4.07k
    BIO_dump_indent(bio, (const char *)ASN1_STRING_get0_data(msg),
89
4.07k
                    ASN1_STRING_length(msg), 4);
90
91
4.07k
    return 1;
92
4.07k
}