Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/crypto/x509/v3_info.c
Line
Count
Source
1
/*
2
 * Copyright 1999-2021 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/conf.h>
13
#include <openssl/asn1.h>
14
#include <openssl/asn1t.h>
15
#include <openssl/x509v3.h>
16
#include "ext_dat.h"
17
18
static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
19
                                                           *method,
20
    AUTHORITY_INFO_ACCESS
21
        *ainfo,
22
    STACK_OF(CONF_VALUE)
23
        *ret);
24
static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
25
                                                            *method,
26
    X509V3_CTX *ctx,
27
    STACK_OF(CONF_VALUE)
28
        *nval);
29
30
const X509V3_EXT_METHOD ossl_v3_info = { NID_info_access, X509V3_EXT_MULTILINE,
31
    ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
32
    0, 0, 0, 0,
33
    0, 0,
34
    (X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
35
    (X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
36
    0, 0,
37
    NULL };
38
39
const X509V3_EXT_METHOD ossl_v3_sinfo = { NID_sinfo_access, X509V3_EXT_MULTILINE,
40
    ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
41
    0, 0, 0, 0,
42
    0, 0,
43
    (X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
44
    (X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
45
    0, 0,
46
    NULL };
47
48
ASN1_SEQUENCE(ACCESS_DESCRIPTION) = {
49
    ASN1_SIMPLE(ACCESS_DESCRIPTION, method, ASN1_OBJECT),
50
    ASN1_SIMPLE(ACCESS_DESCRIPTION, location, GENERAL_NAME)
51
289k
} ASN1_SEQUENCE_END(ACCESS_DESCRIPTION)
52
289k
53
289k
IMPLEMENT_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
54
289k
55
289k
ASN1_ITEM_TEMPLATE(AUTHORITY_INFO_ACCESS) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, GeneralNames, ACCESS_DESCRIPTION)
56
289k
ASN1_ITEM_TEMPLATE_END(AUTHORITY_INFO_ACCESS)
57
58
IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
59
60
static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(
61
    X509V3_EXT_METHOD *method, AUTHORITY_INFO_ACCESS *ainfo,
62
    STACK_OF(CONF_VALUE) *ret)
63
5.60k
{
64
5.60k
    ACCESS_DESCRIPTION *desc;
65
5.60k
    int i, nlen;
66
5.60k
    char objtmp[80], *ntmp;
67
5.60k
    CONF_VALUE *vtmp;
68
5.60k
    STACK_OF(CONF_VALUE) *tret = ret;
69
70
10.3k
    for (i = 0; i < sk_ACCESS_DESCRIPTION_num(ainfo); i++) {
71
6.04k
        STACK_OF(CONF_VALUE) *tmp;
72
73
6.04k
        desc = sk_ACCESS_DESCRIPTION_value(ainfo, i);
74
6.04k
        tmp = i2v_GENERAL_NAME(method, desc->location, tret);
75
6.04k
        if (tmp == NULL)
76
1.27k
            goto err;
77
4.76k
        tret = tmp;
78
4.76k
        vtmp = sk_CONF_VALUE_value(tret, i);
79
4.76k
        i2t_ASN1_OBJECT(objtmp, sizeof(objtmp), desc->method);
80
4.76k
        nlen = strlen(objtmp) + 3 + strlen(vtmp->name) + 1;
81
4.76k
        ntmp = OPENSSL_malloc(nlen);
82
4.76k
        if (ntmp == NULL)
83
0
            goto err;
84
4.76k
        BIO_snprintf(ntmp, nlen, "%s - %s", objtmp, vtmp->name);
85
4.76k
        OPENSSL_free(vtmp->name);
86
4.76k
        vtmp->name = ntmp;
87
4.76k
    }
88
4.32k
    if (ret == NULL && tret == NULL)
89
904
        return sk_CONF_VALUE_new_null();
90
91
3.42k
    return tret;
92
1.27k
err:
93
1.27k
    ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
94
1.27k
    if (ret == NULL && tret != NULL)
95
259
        sk_CONF_VALUE_pop_free(tret, X509V3_conf_free);
96
1.27k
    return NULL;
97
4.32k
}
98
99
static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
100
                                                            *method,
101
    X509V3_CTX *ctx,
102
    STACK_OF(CONF_VALUE)
103
        *nval)
104
0
{
105
0
    AUTHORITY_INFO_ACCESS *ainfo = NULL;
106
0
    CONF_VALUE *cnf, ctmp;
107
0
    ACCESS_DESCRIPTION *acc;
108
0
    int i;
109
0
    const int num = sk_CONF_VALUE_num(nval);
110
0
    char *objtmp, *ptmp;
111
112
0
    if ((ainfo = sk_ACCESS_DESCRIPTION_new_reserve(NULL, num)) == NULL) {
113
0
        ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
114
0
        return NULL;
115
0
    }
116
0
    for (i = 0; i < num; i++) {
117
0
        cnf = sk_CONF_VALUE_value(nval, i);
118
0
        if ((acc = ACCESS_DESCRIPTION_new()) == NULL) {
119
0
            ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
120
0
            goto err;
121
0
        }
122
0
        sk_ACCESS_DESCRIPTION_push(ainfo, acc); /* Cannot fail due to reserve */
123
0
        ptmp = strchr(cnf->name, ';');
124
0
        if (ptmp == NULL) {
125
0
            ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_SYNTAX);
126
0
            goto err;
127
0
        }
128
0
        ctmp.name = ptmp + 1;
129
0
        ctmp.value = cnf->value;
130
0
        if (!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0))
131
0
            goto err;
132
0
        if ((objtmp = OPENSSL_strndup(cnf->name, ptmp - cnf->name)) == NULL) {
133
0
            ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
134
0
            goto err;
135
0
        }
136
0
        acc->method = OBJ_txt2obj(objtmp, 0);
137
0
        if (!acc->method) {
138
0
            ERR_raise_data(ERR_LIB_X509V3, X509V3_R_BAD_OBJECT,
139
0
                "value=%s", objtmp);
140
0
            OPENSSL_free(objtmp);
141
0
            goto err;
142
0
        }
143
0
        OPENSSL_free(objtmp);
144
0
    }
145
0
    return ainfo;
146
0
err:
147
0
    sk_ACCESS_DESCRIPTION_pop_free(ainfo, ACCESS_DESCRIPTION_free);
148
0
    return NULL;
149
0
}
150
151
int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a)
152
0
{
153
0
    i2a_ASN1_OBJECT(bp, a->method);
154
0
    return 2;
155
0
}