Coverage Report

Created: 2018-08-29 13:53

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