Coverage Report

Created: 2026-07-23 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/x509/v3_usernotice.c
Line
Count
Source
1
/*
2
 * Copyright 1999-2026 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 <openssl/asn1t.h>
11
#include <openssl/x509v3.h>
12
#include "ext_dat.h"
13
14
#include <crypto/asn1.h>
15
16
ASN1_ITEM_TEMPLATE(OSSL_USER_NOTICE_SYNTAX) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_USER_NOTICE_SYNTAX, USERNOTICE)
17
22.5k
ASN1_ITEM_TEMPLATE_END(OSSL_USER_NOTICE_SYNTAX)
18
19
IMPLEMENT_ASN1_FUNCTIONS(OSSL_USER_NOTICE_SYNTAX)
20
21
static int print_notice(BIO *out, USERNOTICE *notice, int indent)
22
10.7k
{
23
10.7k
    int i;
24
10.7k
    ASN1_INTEGER *num;
25
10.7k
    char *tmp;
26
27
10.7k
    if (notice->noticeref) {
28
292
        NOTICEREF *ref;
29
292
        ref = notice->noticeref;
30
292
        if (BIO_printf(out, "%*sOrganization: %.*s\n", indent, "",
31
292
                ref->organization->length,
32
292
                ref->organization->data)
33
292
            <= 0)
34
0
            return 0;
35
292
        if (BIO_printf(out, "%*sNumber%s: ", indent, "",
36
292
                sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "")
37
292
            <= 0)
38
0
            return 0;
39
975
        for (i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
40
683
            num = sk_ASN1_INTEGER_value(ref->noticenos, i);
41
683
            if (i && BIO_puts(out, ", ") <= 0)
42
0
                return 0;
43
683
            if (num == NULL && BIO_puts(out, "(null)") <= 0)
44
0
                return 0;
45
683
            else {
46
683
                tmp = i2s_ASN1_INTEGER(NULL, num);
47
683
                if (tmp == NULL)
48
0
                    return 0;
49
683
                if (BIO_puts(out, tmp) <= 0) {
50
0
                    OPENSSL_free(tmp);
51
0
                    return 0;
52
0
                }
53
683
                OPENSSL_free(tmp);
54
683
            }
55
683
        }
56
292
        if (notice->exptext && BIO_puts(out, "\n") <= 0)
57
0
            return 0;
58
292
    }
59
10.7k
    if (notice->exptext == NULL)
60
9.42k
        return 1;
61
62
1.36k
    return BIO_printf(out, "%*sExplicit Text: %.*s", indent, "",
63
1.36k
               notice->exptext->length,
64
1.36k
               notice->exptext->data)
65
1.36k
        >= 0;
66
10.7k
}
67
68
static int i2r_USER_NOTICE_SYNTAX(X509V3_EXT_METHOD *method,
69
    OSSL_USER_NOTICE_SYNTAX *uns,
70
    BIO *out, int indent)
71
7.05k
{
72
7.05k
    int i;
73
7.05k
    USERNOTICE *unotice;
74
75
7.05k
    if (BIO_printf(out, "%*sUser Notices:\n", indent, "") <= 0)
76
0
        return 0;
77
78
17.8k
    for (i = 0; i < sk_USERNOTICE_num(uns); i++) {
79
10.7k
        unotice = sk_USERNOTICE_value(uns, i);
80
10.7k
        if (!print_notice(out, unotice, indent + 4))
81
0
            return 0;
82
10.7k
        if (BIO_puts(out, "\n\n") <= 0)
83
0
            return 0;
84
10.7k
    }
85
7.05k
    return 1;
86
7.05k
}
87
88
const X509V3_EXT_METHOD ossl_v3_user_notice = {
89
    NID_user_notice, 0,
90
    ASN1_ITEM_ref(OSSL_USER_NOTICE_SYNTAX),
91
    0, 0, 0, 0,
92
    0,
93
    0,
94
    0, 0,
95
    (X509V3_EXT_I2R)i2r_USER_NOTICE_SYNTAX,
96
    0,
97
    NULL
98
};