Coverage Report

Created: 2025-11-16 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/crypto/x509/v3_admis.c
Line
Count
Source
1
/*
2
 * Copyright 2017-2023 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
#include <stdio.h>
10
#include "internal/cryptlib.h"
11
#include <openssl/conf.h>
12
#include <openssl/types.h>
13
#include <openssl/asn1.h>
14
#include <openssl/asn1t.h>
15
16
#include <openssl/x509v3.h>
17
18
#include <openssl/safestack.h>
19
20
#include "v3_admis.h"
21
#include "ext_dat.h"
22
23
ASN1_SEQUENCE(NAMING_AUTHORITY) = {
24
    ASN1_OPT(NAMING_AUTHORITY, namingAuthorityId, ASN1_OBJECT),
25
    ASN1_OPT(NAMING_AUTHORITY, namingAuthorityUrl, ASN1_IA5STRING),
26
    ASN1_OPT(NAMING_AUTHORITY, namingAuthorityText, DIRECTORYSTRING),
27
140k
} ASN1_SEQUENCE_END(NAMING_AUTHORITY)
28
140k
29
140k
ASN1_SEQUENCE(PROFESSION_INFO) = {
30
140k
    ASN1_EXP_OPT(PROFESSION_INFO, namingAuthority, NAMING_AUTHORITY, 0),
31
140k
    ASN1_SEQUENCE_OF(PROFESSION_INFO, professionItems, DIRECTORYSTRING),
32
140k
    ASN1_SEQUENCE_OF_OPT(PROFESSION_INFO, professionOIDs, ASN1_OBJECT),
33
140k
    ASN1_OPT(PROFESSION_INFO, registrationNumber, ASN1_PRINTABLESTRING),
34
140k
    ASN1_OPT(PROFESSION_INFO, addProfessionInfo, ASN1_OCTET_STRING),
35
140k
} ASN1_SEQUENCE_END(PROFESSION_INFO)
36
55.1k
37
55.1k
ASN1_SEQUENCE(ADMISSIONS) = {
38
55.1k
    ASN1_EXP_OPT(ADMISSIONS, admissionAuthority, GENERAL_NAME, 0),
39
55.1k
    ASN1_EXP_OPT(ADMISSIONS, namingAuthority, NAMING_AUTHORITY, 1),
40
55.1k
    ASN1_SEQUENCE_OF(ADMISSIONS, professionInfos, PROFESSION_INFO),
41
98.0k
} ASN1_SEQUENCE_END(ADMISSIONS)
42
98.0k
43
98.0k
ASN1_SEQUENCE(ADMISSION_SYNTAX) = {
44
98.0k
    ASN1_OPT(ADMISSION_SYNTAX, admissionAuthority, GENERAL_NAME),
45
98.0k
    ASN1_SEQUENCE_OF(ADMISSION_SYNTAX, contentsOfAdmissions, ADMISSIONS),
46
98.0k
} ASN1_SEQUENCE_END(ADMISSION_SYNTAX)
47
73.7k
48
73.7k
IMPLEMENT_ASN1_FUNCTIONS(NAMING_AUTHORITY)
49
73.7k
IMPLEMENT_ASN1_FUNCTIONS(PROFESSION_INFO)
50
73.7k
IMPLEMENT_ASN1_FUNCTIONS(ADMISSIONS)
51
73.7k
IMPLEMENT_ASN1_FUNCTIONS(ADMISSION_SYNTAX)
52
73.7k
53
73.7k
static int i2r_ADMISSION_SYNTAX(const struct v3_ext_method *method, void *in,
54
73.7k
                                BIO *bp, int ind);
55
73.7k
56
73.7k
const X509V3_EXT_METHOD ossl_v3_ext_admission = {
57
73.7k
    NID_x509ExtAdmission,   /* .ext_nid = */
58
73.7k
    0,                      /* .ext_flags = */
59
73.7k
    ASN1_ITEM_ref(ADMISSION_SYNTAX), /* .it = */
60
73.7k
    NULL, NULL, NULL, NULL,
61
73.7k
    NULL,                   /* .i2s = */
62
73.7k
    NULL,                   /* .s2i = */
63
73.7k
    NULL,                   /* .i2v = */
64
73.7k
    NULL,                   /* .v2i = */
65
73.7k
    &i2r_ADMISSION_SYNTAX,  /* .i2r = */
66
73.7k
    NULL,                   /* .r2i = */
67
73.7k
    NULL                    /* extension-specific data */
68
73.7k
};
69
73.7k
70
73.7k
static int i2r_NAMING_AUTHORITY(const struct v3_ext_method *method, void *in,
71
73.7k
                                BIO *bp, int ind)
72
73.7k
{
73
2.00k
    NAMING_AUTHORITY *namingAuthority = (NAMING_AUTHORITY *) in;
74
75
2.00k
    if (namingAuthority == NULL)
76
0
        return 0;
77
78
2.00k
    if (namingAuthority->namingAuthorityId == NULL
79
1.74k
        && namingAuthority->namingAuthorityText == NULL
80
1.08k
        && namingAuthority->namingAuthorityUrl == NULL)
81
715
        return 0;
82
83
1.29k
    if (BIO_printf(bp, "%*snamingAuthority:\n", ind, "") <= 0)
84
0
        goto err;
85
86
1.29k
    if (namingAuthority->namingAuthorityId != NULL) {
87
260
        char objbuf[128];
88
260
        const char *ln = OBJ_nid2ln(OBJ_obj2nid(namingAuthority->namingAuthorityId));
89
90
260
        if (BIO_printf(bp, "%*s  namingAuthorityId: ", ind, "") <= 0)
91
0
            goto err;
92
93
260
        OBJ_obj2txt(objbuf, sizeof(objbuf), namingAuthority->namingAuthorityId, 1);
94
95
260
        if (BIO_printf(bp, "%s%s%s%s\n", ln ? ln : "",
96
260
                       ln ? " (" : "", objbuf, ln ? ")" : "") <= 0)
97
0
            goto err;
98
260
    }
99
1.29k
    if (namingAuthority->namingAuthorityText != NULL) {
100
662
        if (BIO_printf(bp, "%*s  namingAuthorityText: ", ind, "") <= 0
101
662
            || ASN1_STRING_print(bp, namingAuthority->namingAuthorityText) <= 0
102
662
            || BIO_printf(bp, "\n") <= 0)
103
0
            goto err;
104
662
    }
105
1.29k
    if (namingAuthority->namingAuthorityUrl != NULL ) {
106
369
        if (BIO_printf(bp, "%*s  namingAuthorityUrl: ", ind, "") <= 0
107
369
            || ASN1_STRING_print(bp, namingAuthority->namingAuthorityUrl) <= 0
108
369
            || BIO_printf(bp, "\n") <= 0)
109
0
            goto err;
110
369
    }
111
1.29k
    return 1;
112
113
0
err:
114
0
    return 0;
115
1.29k
}
116
117
static int i2r_ADMISSION_SYNTAX(const struct v3_ext_method *method, void *in,
118
                                BIO *bp, int ind)
119
15.7k
{
120
15.7k
    ADMISSION_SYNTAX * admission = (ADMISSION_SYNTAX *)in;
121
15.7k
    int i, j, k;
122
123
15.7k
    if (admission->admissionAuthority != NULL) {
124
6.51k
        if (BIO_printf(bp, "%*sadmissionAuthority:\n", ind, "") <= 0
125
6.51k
            || BIO_printf(bp, "%*s  ", ind, "") <= 0
126
6.51k
            || GENERAL_NAME_print(bp, admission->admissionAuthority) <= 0
127
6.51k
            || BIO_printf(bp, "\n") <= 0)
128
0
            goto err;
129
6.51k
    }
130
131
23.8k
    for (i = 0; i < sk_ADMISSIONS_num(admission->contentsOfAdmissions); i++) {
132
8.86k
        ADMISSIONS *entry = sk_ADMISSIONS_value(admission->contentsOfAdmissions, i);
133
134
8.86k
        if (BIO_printf(bp, "%*sEntry %0d:\n", ind, "", 1 + i) <= 0)
135
0
            goto err;
136
137
8.86k
        if (entry->admissionAuthority != NULL) {
138
389
            if (BIO_printf(bp, "%*s  admissionAuthority:\n", ind, "") <= 0
139
389
                || BIO_printf(bp, "%*s    ", ind, "") <= 0
140
389
                || GENERAL_NAME_print(bp, entry->admissionAuthority) <= 0
141
389
                || BIO_printf(bp, "\n") <= 0)
142
0
                goto err;
143
389
        }
144
145
8.86k
        if (entry->namingAuthority != NULL) {
146
1.00k
            if (i2r_NAMING_AUTHORITY(method, entry->namingAuthority, bp, ind + 2) <= 0)
147
389
                goto err;
148
1.00k
        }
149
150
15.6k
        for (j = 0; j < sk_PROFESSION_INFO_num(entry->professionInfos); j++) {
151
7.51k
            PROFESSION_INFO *pinfo = sk_PROFESSION_INFO_value(entry->professionInfos, j);
152
153
7.51k
            if (BIO_printf(bp, "%*s  Profession Info Entry %0d:\n", ind, "", 1 + j) <= 0)
154
0
                goto err;
155
156
7.51k
            if (pinfo->registrationNumber != NULL) {
157
1.55k
                if (BIO_printf(bp, "%*s    registrationNumber: ", ind, "") <= 0
158
1.55k
                    || ASN1_STRING_print(bp, pinfo->registrationNumber) <= 0
159
1.55k
                    || BIO_printf(bp, "\n") <= 0)
160
0
                    goto err;
161
1.55k
            }
162
163
7.51k
            if (pinfo->namingAuthority != NULL) {
164
997
                if (i2r_NAMING_AUTHORITY(method, pinfo->namingAuthority, bp, ind + 4) <= 0)
165
326
                    goto err;
166
997
            }
167
168
7.19k
            if (pinfo->professionItems != NULL) {
169
170
7.19k
                if (BIO_printf(bp, "%*s    Info Entries:\n", ind, "") <= 0)
171
0
                    goto err;
172
13.5k
                for (k = 0; k < sk_ASN1_STRING_num(pinfo->professionItems); k++) {
173
6.39k
                    ASN1_STRING *val = sk_ASN1_STRING_value(pinfo->professionItems, k);
174
175
6.39k
                    if (BIO_printf(bp, "%*s      ", ind, "") <= 0
176
6.39k
                        || ASN1_STRING_print(bp, val) <= 0
177
6.39k
                        || BIO_printf(bp, "\n") <= 0)
178
0
                        goto err;
179
6.39k
                }
180
7.19k
            }
181
182
7.19k
            if (pinfo->professionOIDs != NULL) {
183
1.86k
                if (BIO_printf(bp, "%*s    Profession OIDs:\n", ind, "") <= 0)
184
0
                    goto err;
185
4.12k
                for (k = 0; k < sk_ASN1_OBJECT_num(pinfo->professionOIDs); k++) {
186
2.26k
                    ASN1_OBJECT *obj = sk_ASN1_OBJECT_value(pinfo->professionOIDs, k);
187
2.26k
                    const char *ln = OBJ_nid2ln(OBJ_obj2nid(obj));
188
2.26k
                    char objbuf[128];
189
190
2.26k
                    OBJ_obj2txt(objbuf, sizeof(objbuf), obj, 1);
191
2.26k
                    if (BIO_printf(bp, "%*s      %s%s%s%s\n", ind, "",
192
2.26k
                                   ln ? ln : "", ln ? " (" : "",
193
2.26k
                                   objbuf, ln ? ")" : "") <= 0)
194
0
                        goto err;
195
2.26k
                }
196
1.86k
            }
197
7.19k
        }
198
8.47k
    }
199
15.0k
    return 1;
200
201
715
err:
202
715
    return 0;
203
15.7k
}
204
205
const ASN1_OBJECT *NAMING_AUTHORITY_get0_authorityId(const NAMING_AUTHORITY *n)
206
0
{
207
0
    return n->namingAuthorityId;
208
0
}
209
210
void NAMING_AUTHORITY_set0_authorityId(NAMING_AUTHORITY *n, ASN1_OBJECT *id)
211
0
{
212
0
    ASN1_OBJECT_free(n->namingAuthorityId);
213
0
    n->namingAuthorityId = id;
214
0
}
215
216
const ASN1_IA5STRING *NAMING_AUTHORITY_get0_authorityURL(const NAMING_AUTHORITY *n)
217
0
{
218
0
    return n->namingAuthorityUrl;
219
0
}
220
221
void NAMING_AUTHORITY_set0_authorityURL(NAMING_AUTHORITY *n, ASN1_IA5STRING *u)
222
0
{
223
0
    ASN1_IA5STRING_free(n->namingAuthorityUrl);
224
0
    n->namingAuthorityUrl = u;
225
0
}
226
227
const ASN1_STRING *NAMING_AUTHORITY_get0_authorityText(const NAMING_AUTHORITY *n)
228
0
{
229
0
    return n->namingAuthorityText;
230
0
}
231
232
void NAMING_AUTHORITY_set0_authorityText(NAMING_AUTHORITY *n, ASN1_STRING *t)
233
0
{
234
0
    ASN1_IA5STRING_free(n->namingAuthorityText);
235
0
    n->namingAuthorityText = t;
236
0
}
237
238
const GENERAL_NAME *ADMISSION_SYNTAX_get0_admissionAuthority(const ADMISSION_SYNTAX *as)
239
0
{
240
0
    return as->admissionAuthority;
241
0
}
242
243
void ADMISSION_SYNTAX_set0_admissionAuthority(ADMISSION_SYNTAX *as,
244
                                              GENERAL_NAME *aa)
245
0
{
246
0
    GENERAL_NAME_free(as->admissionAuthority);
247
0
    as->admissionAuthority = aa;
248
0
}
249
250
const STACK_OF(ADMISSIONS) *ADMISSION_SYNTAX_get0_contentsOfAdmissions(const ADMISSION_SYNTAX *as)
251
0
{
252
0
    return as->contentsOfAdmissions;
253
0
}
254
255
void ADMISSION_SYNTAX_set0_contentsOfAdmissions(ADMISSION_SYNTAX *as,
256
                                                STACK_OF(ADMISSIONS) *a)
257
0
{
258
0
    sk_ADMISSIONS_pop_free(as->contentsOfAdmissions, ADMISSIONS_free);
259
0
    as->contentsOfAdmissions = a;
260
0
}
261
262
const GENERAL_NAME *ADMISSIONS_get0_admissionAuthority(const ADMISSIONS *a)
263
0
{
264
0
    return a->admissionAuthority;
265
0
}
266
267
void ADMISSIONS_set0_admissionAuthority(ADMISSIONS *a, GENERAL_NAME *aa)
268
0
{
269
0
    GENERAL_NAME_free(a->admissionAuthority);
270
0
    a->admissionAuthority = aa;
271
0
}
272
273
const NAMING_AUTHORITY *ADMISSIONS_get0_namingAuthority(const ADMISSIONS *a)
274
0
{
275
0
    return a->namingAuthority;
276
0
}
277
278
void ADMISSIONS_set0_namingAuthority(ADMISSIONS *a, NAMING_AUTHORITY *na)
279
0
{
280
0
    NAMING_AUTHORITY_free(a->namingAuthority);
281
0
    a->namingAuthority = na;
282
0
}
283
284
const PROFESSION_INFOS *ADMISSIONS_get0_professionInfos(const ADMISSIONS *a)
285
0
{
286
0
    return a->professionInfos;
287
0
}
288
289
void ADMISSIONS_set0_professionInfos(ADMISSIONS *a, PROFESSION_INFOS *pi)
290
0
{
291
0
    sk_PROFESSION_INFO_pop_free(a->professionInfos, PROFESSION_INFO_free);
292
0
    a->professionInfos = pi;
293
0
}
294
295
const ASN1_OCTET_STRING *PROFESSION_INFO_get0_addProfessionInfo(const PROFESSION_INFO *pi)
296
0
{
297
0
    return pi->addProfessionInfo;
298
0
}
299
300
void PROFESSION_INFO_set0_addProfessionInfo(PROFESSION_INFO *pi,
301
                                            ASN1_OCTET_STRING *aos)
302
0
{
303
0
    ASN1_OCTET_STRING_free(pi->addProfessionInfo);
304
0
    pi->addProfessionInfo = aos;
305
0
}
306
307
const NAMING_AUTHORITY *PROFESSION_INFO_get0_namingAuthority(const PROFESSION_INFO *pi)
308
0
{
309
0
    return pi->namingAuthority;
310
0
}
311
312
void PROFESSION_INFO_set0_namingAuthority(PROFESSION_INFO *pi,
313
                                          NAMING_AUTHORITY *na)
314
0
{
315
0
    NAMING_AUTHORITY_free(pi->namingAuthority);
316
0
    pi->namingAuthority = na;
317
0
}
318
319
const STACK_OF(ASN1_STRING) *PROFESSION_INFO_get0_professionItems(const PROFESSION_INFO *pi)
320
0
{
321
0
    return pi->professionItems;
322
0
}
323
324
void PROFESSION_INFO_set0_professionItems(PROFESSION_INFO *pi,
325
                                          STACK_OF(ASN1_STRING) *as)
326
0
{
327
0
    sk_ASN1_STRING_pop_free(pi->professionItems, ASN1_STRING_free);
328
0
    pi->professionItems = as;
329
0
}
330
331
const STACK_OF(ASN1_OBJECT) *PROFESSION_INFO_get0_professionOIDs(const PROFESSION_INFO *pi)
332
0
{
333
0
    return pi->professionOIDs;
334
0
}
335
336
void PROFESSION_INFO_set0_professionOIDs(PROFESSION_INFO *pi,
337
                                         STACK_OF(ASN1_OBJECT) *po)
338
0
{
339
0
    sk_ASN1_OBJECT_pop_free(pi->professionOIDs, ASN1_OBJECT_free);
340
0
    pi->professionOIDs = po;
341
0
}
342
343
const ASN1_PRINTABLESTRING *PROFESSION_INFO_get0_registrationNumber(const PROFESSION_INFO *pi)
344
0
{
345
0
    return pi->registrationNumber;
346
0
}
347
348
void PROFESSION_INFO_set0_registrationNumber(PROFESSION_INFO *pi,
349
                                             ASN1_PRINTABLESTRING *rn)
350
0
{
351
0
    ASN1_PRINTABLESTRING_free(pi->registrationNumber);
352
0
    pi->registrationNumber = rn;
353
0
}