Coverage Report

Created: 2025-12-10 06:24

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