2 * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
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
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>
16 #include <openssl/x509v3.h>
18 #include <openssl/safestack.h>
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 } ASN1_SEQUENCE_END(NAMING_AUTHORITY
)
29 ASN1_SEQUENCE(PROFESSION_INFO
) = {
30 ASN1_EXP_OPT(PROFESSION_INFO
, namingAuthority
, NAMING_AUTHORITY
, 0),
31 ASN1_SEQUENCE_OF(PROFESSION_INFO
, professionItems
, DIRECTORYSTRING
),
32 ASN1_SEQUENCE_OF_OPT(PROFESSION_INFO
, professionOIDs
, ASN1_OBJECT
),
33 ASN1_OPT(PROFESSION_INFO
, registrationNumber
, ASN1_PRINTABLESTRING
),
34 ASN1_OPT(PROFESSION_INFO
, addProfessionInfo
, ASN1_OCTET_STRING
),
35 } ASN1_SEQUENCE_END(PROFESSION_INFO
)
37 ASN1_SEQUENCE(ADMISSIONS
) = {
38 ASN1_EXP_OPT(ADMISSIONS
, admissionAuthority
, GENERAL_NAME
, 0),
39 ASN1_EXP_OPT(ADMISSIONS
, namingAuthority
, NAMING_AUTHORITY
, 1),
40 ASN1_SEQUENCE_OF(ADMISSIONS
, professionInfos
, PROFESSION_INFO
),
41 } ASN1_SEQUENCE_END(ADMISSIONS
)
43 ASN1_SEQUENCE(ADMISSION_SYNTAX
) = {
44 ASN1_OPT(ADMISSION_SYNTAX
, admissionAuthority
, GENERAL_NAME
),
45 ASN1_SEQUENCE_OF(ADMISSION_SYNTAX
, contentsOfAdmissions
, ADMISSIONS
),
46 } ASN1_SEQUENCE_END(ADMISSION_SYNTAX
)
48 IMPLEMENT_ASN1_FUNCTIONS(NAMING_AUTHORITY
)
49 IMPLEMENT_ASN1_FUNCTIONS(PROFESSION_INFO
)
50 IMPLEMENT_ASN1_FUNCTIONS(ADMISSIONS
)
51 IMPLEMENT_ASN1_FUNCTIONS(ADMISSION_SYNTAX
)
53 static int i2r_ADMISSION_SYNTAX(const struct v3_ext_method
*method
, void *in
,
56 const X509V3_EXT_METHOD ossl_v3_ext_admission
= {
57 NID_x509ExtAdmission
, /* .ext_nid = */
59 ASN1_ITEM_ref(ADMISSION_SYNTAX
), /* .it = */
60 NULL
, NULL
, NULL
, NULL
,
65 &i2r_ADMISSION_SYNTAX
, /* .i2r = */
67 NULL
/* extension-specific data */
71 static int i2r_NAMING_AUTHORITY(const struct v3_ext_method
*method
, void *in
,
74 NAMING_AUTHORITY
* namingAuthority
= (NAMING_AUTHORITY
*) in
;
76 if (namingAuthority
== NULL
)
79 if (namingAuthority
->namingAuthorityId
== NULL
80 && namingAuthority
->namingAuthorityText
== NULL
81 && namingAuthority
->namingAuthorityUrl
== NULL
)
84 if (BIO_printf(bp
, "%*snamingAuthority: ", ind
, "") <= 0)
87 if (namingAuthority
->namingAuthorityId
!= NULL
) {
89 const char *ln
= OBJ_nid2ln(OBJ_obj2nid(namingAuthority
->namingAuthorityId
));
91 if (BIO_printf(bp
, "%*s admissionAuthorityId: ", ind
, "") <= 0)
94 OBJ_obj2txt(objbuf
, sizeof(objbuf
), namingAuthority
->namingAuthorityId
, 1);
96 if (BIO_printf(bp
, "%s%s%s%s\n", ln
? ln
: "",
97 ln
? " (" : "", objbuf
, ln
? ")" : "") <= 0)
100 if (namingAuthority
->namingAuthorityText
!= NULL
) {
101 if (BIO_printf(bp
, "%*s namingAuthorityText: ", ind
, "") <= 0
102 || ASN1_STRING_print(bp
, namingAuthority
->namingAuthorityText
) <= 0
103 || BIO_printf(bp
, "\n") <= 0)
106 if (namingAuthority
->namingAuthorityUrl
!= NULL
) {
107 if (BIO_printf(bp
, "%*s namingAuthorityUrl: ", ind
, "") <= 0
108 || ASN1_STRING_print(bp
, namingAuthority
->namingAuthorityUrl
) <= 0
109 || BIO_printf(bp
, "\n") <= 0)
118 static int i2r_ADMISSION_SYNTAX(const struct v3_ext_method
*method
, void *in
,
121 ADMISSION_SYNTAX
* admission
= (ADMISSION_SYNTAX
*)in
;
124 if (admission
->admissionAuthority
!= NULL
) {
125 if (BIO_printf(bp
, "%*sadmissionAuthority:\n", ind
, "") <= 0
126 || BIO_printf(bp
, "%*s ", ind
, "") <= 0
127 || GENERAL_NAME_print(bp
, admission
->admissionAuthority
) <= 0
128 || BIO_printf(bp
, "\n") <= 0)
132 for (i
= 0; i
< sk_ADMISSIONS_num(admission
->contentsOfAdmissions
); i
++) {
133 ADMISSIONS
* entry
= sk_ADMISSIONS_value(admission
->contentsOfAdmissions
, i
);
135 if (BIO_printf(bp
, "%*sEntry %0d:\n", ind
, "", 1 + i
) <= 0) goto err
;
137 if (entry
->admissionAuthority
!= NULL
) {
138 if (BIO_printf(bp
, "%*s admissionAuthority:\n", ind
, "") <= 0
139 || BIO_printf(bp
, "%*s ", ind
, "") <= 0
140 || GENERAL_NAME_print(bp
, entry
->admissionAuthority
) <= 0
141 || BIO_printf(bp
, "\n") <= 0)
145 if (entry
->namingAuthority
!= NULL
) {
146 if (i2r_NAMING_AUTHORITY(method
, entry
->namingAuthority
, bp
, ind
) <= 0)
150 for (j
= 0; j
< sk_PROFESSION_INFO_num(entry
->professionInfos
); j
++) {
151 PROFESSION_INFO
* pinfo
= sk_PROFESSION_INFO_value(entry
->professionInfos
, j
);
153 if (BIO_printf(bp
, "%*s Profession Info Entry %0d:\n", ind
, "", 1 + j
) <= 0)
156 if (pinfo
->registrationNumber
!= NULL
) {
157 if (BIO_printf(bp
, "%*s registrationNumber: ", ind
, "") <= 0
158 || ASN1_STRING_print(bp
, pinfo
->registrationNumber
) <= 0
159 || BIO_printf(bp
, "\n") <= 0)
163 if (pinfo
->namingAuthority
!= NULL
) {
164 if (i2r_NAMING_AUTHORITY(method
, pinfo
->namingAuthority
, bp
, ind
+ 2) <= 0)
168 if (pinfo
->professionItems
!= NULL
) {
170 if (BIO_printf(bp
, "%*s Info Entries:\n", ind
, "") <= 0)
172 for (k
= 0; k
< sk_ASN1_STRING_num(pinfo
->professionItems
); k
++) {
173 ASN1_STRING
* val
= sk_ASN1_STRING_value(pinfo
->professionItems
, k
);
175 if (BIO_printf(bp
, "%*s ", ind
, "") <= 0
176 || ASN1_STRING_print(bp
, val
) <= 0
177 || BIO_printf(bp
, "\n") <= 0)
182 if (pinfo
->professionOIDs
!= NULL
) {
183 if (BIO_printf(bp
, "%*s Profession OIDs:\n", ind
, "") <= 0)
185 for (k
= 0; k
< sk_ASN1_OBJECT_num(pinfo
->professionOIDs
); k
++) {
186 ASN1_OBJECT
* obj
= sk_ASN1_OBJECT_value(pinfo
->professionOIDs
, k
);
187 const char *ln
= OBJ_nid2ln(OBJ_obj2nid(obj
));
190 OBJ_obj2txt(objbuf
, sizeof(objbuf
), obj
, 1);
191 if (BIO_printf(bp
, "%*s %s%s%s%s\n", ind
, "",
192 ln
? ln
: "", ln
? " (" : "",
193 objbuf
, ln
? ")" : "") <= 0)
205 const ASN1_OBJECT
*NAMING_AUTHORITY_get0_authorityId(const NAMING_AUTHORITY
*n
)
207 return n
->namingAuthorityId
;
210 void NAMING_AUTHORITY_set0_authorityId(NAMING_AUTHORITY
*n
, ASN1_OBJECT
* id
)
212 ASN1_OBJECT_free(n
->namingAuthorityId
);
213 n
->namingAuthorityId
= id
;
216 const ASN1_IA5STRING
*NAMING_AUTHORITY_get0_authorityURL(
217 const NAMING_AUTHORITY
*n
)
219 return n
->namingAuthorityUrl
;
222 void NAMING_AUTHORITY_set0_authorityURL(NAMING_AUTHORITY
*n
, ASN1_IA5STRING
* u
)
224 ASN1_IA5STRING_free(n
->namingAuthorityUrl
);
225 n
->namingAuthorityUrl
= u
;
228 const ASN1_STRING
*NAMING_AUTHORITY_get0_authorityText(
229 const NAMING_AUTHORITY
*n
)
231 return n
->namingAuthorityText
;
234 void NAMING_AUTHORITY_set0_authorityText(NAMING_AUTHORITY
*n
, ASN1_STRING
* t
)
236 ASN1_IA5STRING_free(n
->namingAuthorityText
);
237 n
->namingAuthorityText
= t
;
240 const GENERAL_NAME
*ADMISSION_SYNTAX_get0_admissionAuthority(const ADMISSION_SYNTAX
*as
)
242 return as
->admissionAuthority
;
245 void ADMISSION_SYNTAX_set0_admissionAuthority(ADMISSION_SYNTAX
*as
,
248 GENERAL_NAME_free(as
->admissionAuthority
);
249 as
->admissionAuthority
= aa
;
252 const STACK_OF(ADMISSIONS
) *ADMISSION_SYNTAX_get0_contentsOfAdmissions(const ADMISSION_SYNTAX
*as
)
254 return as
->contentsOfAdmissions
;
257 void ADMISSION_SYNTAX_set0_contentsOfAdmissions(ADMISSION_SYNTAX
*as
,
258 STACK_OF(ADMISSIONS
) *a
)
260 sk_ADMISSIONS_pop_free(as
->contentsOfAdmissions
, ADMISSIONS_free
);
261 as
->contentsOfAdmissions
= a
;
264 const GENERAL_NAME
*ADMISSIONS_get0_admissionAuthority(const ADMISSIONS
*a
)
266 return a
->admissionAuthority
;
269 void ADMISSIONS_set0_admissionAuthority(ADMISSIONS
*a
, GENERAL_NAME
*aa
)
271 GENERAL_NAME_free(a
->admissionAuthority
);
272 a
->admissionAuthority
= aa
;
275 const NAMING_AUTHORITY
*ADMISSIONS_get0_namingAuthority(const ADMISSIONS
*a
)
277 return a
->namingAuthority
;
280 void ADMISSIONS_set0_namingAuthority(ADMISSIONS
*a
, NAMING_AUTHORITY
*na
)
282 NAMING_AUTHORITY_free(a
->namingAuthority
);
283 a
->namingAuthority
= na
;
286 const PROFESSION_INFOS
*ADMISSIONS_get0_professionInfos(const ADMISSIONS
*a
)
288 return a
->professionInfos
;
291 void ADMISSIONS_set0_professionInfos(ADMISSIONS
*a
, PROFESSION_INFOS
*pi
)
293 sk_PROFESSION_INFO_pop_free(a
->professionInfos
, PROFESSION_INFO_free
);
294 a
->professionInfos
= pi
;
297 const ASN1_OCTET_STRING
*PROFESSION_INFO_get0_addProfessionInfo(const PROFESSION_INFO
*pi
)
299 return pi
->addProfessionInfo
;
302 void PROFESSION_INFO_set0_addProfessionInfo(PROFESSION_INFO
*pi
,
303 ASN1_OCTET_STRING
*aos
)
305 ASN1_OCTET_STRING_free(pi
->addProfessionInfo
);
306 pi
->addProfessionInfo
= aos
;
309 const NAMING_AUTHORITY
*PROFESSION_INFO_get0_namingAuthority(const PROFESSION_INFO
*pi
)
311 return pi
->namingAuthority
;
314 void PROFESSION_INFO_set0_namingAuthority(PROFESSION_INFO
*pi
,
315 NAMING_AUTHORITY
*na
)
317 NAMING_AUTHORITY_free(pi
->namingAuthority
);
318 pi
->namingAuthority
= na
;
321 const STACK_OF(ASN1_STRING
) *PROFESSION_INFO_get0_professionItems(const PROFESSION_INFO
*pi
)
323 return pi
->professionItems
;
326 void PROFESSION_INFO_set0_professionItems(PROFESSION_INFO
*pi
,
327 STACK_OF(ASN1_STRING
) *as
)
329 sk_ASN1_STRING_pop_free(pi
->professionItems
, ASN1_STRING_free
);
330 pi
->professionItems
= as
;
333 const STACK_OF(ASN1_OBJECT
) *PROFESSION_INFO_get0_professionOIDs(const PROFESSION_INFO
*pi
)
335 return pi
->professionOIDs
;
338 void PROFESSION_INFO_set0_professionOIDs(PROFESSION_INFO
*pi
,
339 STACK_OF(ASN1_OBJECT
) *po
)
341 sk_ASN1_OBJECT_pop_free(pi
->professionOIDs
, ASN1_OBJECT_free
);
342 pi
->professionOIDs
= po
;
345 const ASN1_PRINTABLESTRING
*PROFESSION_INFO_get0_registrationNumber(const PROFESSION_INFO
*pi
)
347 return pi
->registrationNumber
;
350 void PROFESSION_INFO_set0_registrationNumber(PROFESSION_INFO
*pi
,
351 ASN1_PRINTABLESTRING
*rn
)
353 ASN1_PRINTABLESTRING_free(pi
->registrationNumber
);
354 pi
->registrationNumber
= rn
;