Coverage Report

Created: 2026-08-31 06:56

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
0
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
0
{
23
0
    int i;
24
0
    ASN1_INTEGER *num;
25
0
    char *tmp;
26
27
0
    if (notice->noticeref) {
28
0
        NOTICEREF *ref;
29
0
        ref = notice->noticeref;
30
0
        if (BIO_printf(out, "%*sOrganization: %.*s\n", indent, "",
31
0
                ref->organization->length,
32
0
                ref->organization->length
33
0
                    ? ref->organization->data
34
0
                    : (const unsigned char *)"")
35
0
            <= 0)
36
0
            return 0;
37
0
        if (BIO_printf(out, "%*sNumber%s: ", indent, "",
38
0
                sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "")
39
0
            <= 0)
40
0
            return 0;
41
0
        for (i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
42
0
            num = sk_ASN1_INTEGER_value(ref->noticenos, i);
43
0
            if (i && BIO_puts(out, ", ") <= 0)
44
0
                return 0;
45
0
            if (num == NULL && BIO_puts(out, "(null)") <= 0)
46
0
                return 0;
47
0
            else {
48
0
                tmp = i2s_ASN1_INTEGER(NULL, num);
49
0
                if (tmp == NULL)
50
0
                    return 0;
51
0
                if (BIO_puts(out, tmp) <= 0) {
52
0
                    OPENSSL_free(tmp);
53
0
                    return 0;
54
0
                }
55
0
                OPENSSL_free(tmp);
56
0
            }
57
0
        }
58
0
        if (notice->exptext && BIO_puts(out, "\n") <= 0)
59
0
            return 0;
60
0
    }
61
0
    if (notice->exptext == NULL)
62
0
        return 1;
63
64
0
    return BIO_printf(out, "%*sExplicit Text: %.*s", indent, "",
65
0
               notice->exptext->length,
66
0
               notice->exptext->length
67
0
                   ? notice->exptext->data
68
0
                   : (const unsigned char *)"")
69
0
        >= 0;
70
0
}
71
72
static int i2r_USER_NOTICE_SYNTAX(X509V3_EXT_METHOD *method,
73
    OSSL_USER_NOTICE_SYNTAX *uns,
74
    BIO *out, int indent)
75
0
{
76
0
    int i;
77
0
    USERNOTICE *unotice;
78
79
0
    if (BIO_printf(out, "%*sUser Notices:\n", indent, "") <= 0)
80
0
        return 0;
81
82
0
    for (i = 0; i < sk_USERNOTICE_num(uns); i++) {
83
0
        unotice = sk_USERNOTICE_value(uns, i);
84
0
        if (!print_notice(out, unotice, indent + 4))
85
0
            return 0;
86
0
        if (BIO_puts(out, "\n\n") <= 0)
87
0
            return 0;
88
0
    }
89
0
    return 1;
90
0
}
91
92
const X509V3_EXT_METHOD ossl_v3_user_notice = {
93
    NID_user_notice, 0,
94
    ASN1_ITEM_ref(OSSL_USER_NOTICE_SYNTAX),
95
    0, 0, 0, 0,
96
    0,
97
    0,
98
    0, 0,
99
    (X509V3_EXT_I2R)i2r_USER_NOTICE_SYNTAX,
100
    0,
101
    NULL
102
};