2 * Copyright 2017-2020 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 DEFINE_STACK_OF(ADMISSIONS)
24 DEFINE_STACK_OF(PROFESSION_INFO)
25 DEFINE_STACK_OF(ASN1_STRING)
26 DEFINE_STACK_OF(ASN1_OBJECT)
28 ASN1_SEQUENCE(NAMING_AUTHORITY) = {
29 ASN1_OPT(NAMING_AUTHORITY, namingAuthorityId, ASN1_OBJECT),
30 ASN1_OPT(NAMING_AUTHORITY, namingAuthorityUrl, ASN1_IA5STRING),
31 ASN1_OPT(NAMING_AUTHORITY, namingAuthorityText, DIRECTORYSTRING),
32 } ASN1_SEQUENCE_END(NAMING_AUTHORITY)
34 ASN1_SEQUENCE(PROFESSION_INFO) = {
35 ASN1_EXP_OPT(PROFESSION_INFO, namingAuthority, NAMING_AUTHORITY, 0),
36 ASN1_SEQUENCE_OF(PROFESSION_INFO, professionItems, DIRECTORYSTRING),
37 ASN1_SEQUENCE_OF_OPT(PROFESSION_INFO, professionOIDs, ASN1_OBJECT),
38 ASN1_OPT(PROFESSION_INFO, registrationNumber, ASN1_PRINTABLESTRING),
39 ASN1_OPT(PROFESSION_INFO, addProfessionInfo, ASN1_OCTET_STRING),
40 } ASN1_SEQUENCE_END(PROFESSION_INFO)
42 ASN1_SEQUENCE(ADMISSIONS) = {
43 ASN1_EXP_OPT(ADMISSIONS, admissionAuthority, GENERAL_NAME, 0),
44 ASN1_EXP_OPT(ADMISSIONS, namingAuthority, NAMING_AUTHORITY, 1),
45 ASN1_SEQUENCE_OF(ADMISSIONS, professionInfos, PROFESSION_INFO),
46 } ASN1_SEQUENCE_END(ADMISSIONS)
48 ASN1_SEQUENCE(ADMISSION_SYNTAX) = {
49 ASN1_OPT(ADMISSION_SYNTAX, admissionAuthority, GENERAL_NAME),
50 ASN1_SEQUENCE_OF(ADMISSION_SYNTAX, contentsOfAdmissions, ADMISSIONS),
51 } ASN1_SEQUENCE_END(ADMISSION_SYNTAX)
53 IMPLEMENT_ASN1_FUNCTIONS(NAMING_AUTHORITY)
54 IMPLEMENT_ASN1_FUNCTIONS(PROFESSION_INFO)
55 IMPLEMENT_ASN1_FUNCTIONS(ADMISSIONS)
56 IMPLEMENT_ASN1_FUNCTIONS(ADMISSION_SYNTAX)
58 static int i2r_ADMISSION_SYNTAX(const struct v3_ext_method *method, void *in,
61 const X509V3_EXT_METHOD v3_ext_admission = {
62 NID_x509ExtAdmission, /* .ext_nid = */
64 ASN1_ITEM_ref(ADMISSION_SYNTAX), /* .it = */
65 NULL, NULL, NULL, NULL,
70 &i2r_ADMISSION_SYNTAX, /* .i2r = */
72 NULL /* extension-specific data */
76 static int i2r_NAMING_AUTHORITY(const struct v3_ext_method *method, void *in,
79 NAMING_AUTHORITY * namingAuthority = (NAMING_AUTHORITY*) in;
81 if (namingAuthority == NULL)
84 if (namingAuthority->namingAuthorityId == NULL
85 && namingAuthority->namingAuthorityText == NULL
86 && namingAuthority->namingAuthorityUrl == NULL)
89 if (BIO_printf(bp, "%*snamingAuthority: ", ind, "") <= 0)
92 if (namingAuthority->namingAuthorityId != NULL) {
94 const char *ln = OBJ_nid2ln(OBJ_obj2nid(namingAuthority->namingAuthorityId));
96 if (BIO_printf(bp, "%*s admissionAuthorityId: ", ind, "") <= 0)
99 OBJ_obj2txt(objbuf, sizeof(objbuf), namingAuthority->namingAuthorityId, 1);
101 if (BIO_printf(bp, "%s%s%s%s\n", ln ? ln : "",
102 ln ? " (" : "", objbuf, ln ? ")" : "") <= 0)
105 if (namingAuthority->namingAuthorityText != NULL) {
106 if (BIO_printf(bp, "%*s namingAuthorityText: ", ind, "") <= 0
107 || ASN1_STRING_print(bp, namingAuthority->namingAuthorityText) <= 0
108 || BIO_printf(bp, "\n") <= 0)
111 if (namingAuthority->namingAuthorityUrl != NULL ) {
112 if (BIO_printf(bp, "%*s namingAuthorityUrl: ", ind, "") <= 0
113 || ASN1_STRING_print(bp, namingAuthority->namingAuthorityUrl) <= 0
114 || BIO_printf(bp, "\n") <= 0)
123 static int i2r_ADMISSION_SYNTAX(const struct v3_ext_method *method, void *in,
126 ADMISSION_SYNTAX * admission = (ADMISSION_SYNTAX *)in;
129 if (admission->admissionAuthority != NULL) {
130 if (BIO_printf(bp, "%*sadmissionAuthority:\n", ind, "") <= 0
131 || BIO_printf(bp, "%*s ", ind, "") <= 0
132 || GENERAL_NAME_print(bp, admission->admissionAuthority) <= 0
133 || BIO_printf(bp, "\n") <= 0)
137 for (i = 0; i < sk_ADMISSIONS_num(admission->contentsOfAdmissions); i++) {
138 ADMISSIONS* entry = sk_ADMISSIONS_value(admission->contentsOfAdmissions, i);
140 if (BIO_printf(bp, "%*sEntry %0d:\n", ind, "", 1 + i) <= 0) goto err;
142 if (entry->admissionAuthority != NULL) {
143 if (BIO_printf(bp, "%*s admissionAuthority:\n", ind, "") <= 0
144 || BIO_printf(bp, "%*s ", ind, "") <= 0
145 || GENERAL_NAME_print(bp, entry->admissionAuthority) <= 0
146 || BIO_printf(bp, "\n") <= 0)
150 if (entry->namingAuthority != NULL) {
151 if (i2r_NAMING_AUTHORITY(method, entry->namingAuthority, bp, ind) <= 0)
155 for (j = 0; j < sk_PROFESSION_INFO_num(entry->professionInfos); j++) {
156 PROFESSION_INFO* pinfo = sk_PROFESSION_INFO_value(entry->professionInfos, j);
158 if (BIO_printf(bp, "%*s Profession Info Entry %0d:\n", ind, "", 1 + j) <= 0)
161 if (pinfo->registrationNumber != NULL) {
162 if (BIO_printf(bp, "%*s registrationNumber: ", ind, "") <= 0
163 || ASN1_STRING_print(bp, pinfo->registrationNumber) <= 0
164 || BIO_printf(bp, "\n") <= 0)
168 if (pinfo->namingAuthority != NULL) {
169 if (i2r_NAMING_AUTHORITY(method, pinfo->namingAuthority, bp, ind + 2) <= 0)
173 if (pinfo->professionItems != NULL) {
175 if (BIO_printf(bp, "%*s Info Entries:\n", ind, "") <= 0)
177 for (k = 0; k < sk_ASN1_STRING_num(pinfo->professionItems); k++) {
178 ASN1_STRING* val = sk_ASN1_STRING_value(pinfo->professionItems, k);
180 if (BIO_printf(bp, "%*s ", ind, "") <= 0
181 || ASN1_STRING_print(bp, val) <= 0
182 || BIO_printf(bp, "\n") <= 0)
187 if (pinfo->professionOIDs != NULL) {
188 if (BIO_printf(bp, "%*s Profession OIDs:\n", ind, "") <= 0)
190 for (k = 0; k < sk_ASN1_OBJECT_num(pinfo->professionOIDs); k++) {
191 ASN1_OBJECT* obj = sk_ASN1_OBJECT_value(pinfo->professionOIDs, k);
192 const char *ln = OBJ_nid2ln(OBJ_obj2nid(obj));
195 OBJ_obj2txt(objbuf, sizeof(objbuf), obj, 1);
196 if (BIO_printf(bp, "%*s %s%s%s%s\n", ind, "",
197 ln ? ln : "", ln ? " (" : "",
198 objbuf, ln ? ")" : "") <= 0)
210 const ASN1_OBJECT *NAMING_AUTHORITY_get0_authorityId(const NAMING_AUTHORITY *n)
212 return n->namingAuthorityId;
215 void NAMING_AUTHORITY_set0_authorityId(NAMING_AUTHORITY *n, ASN1_OBJECT* id)
217 ASN1_OBJECT_free(n->namingAuthorityId);
218 n->namingAuthorityId = id;
221 const ASN1_IA5STRING *NAMING_AUTHORITY_get0_authorityURL(
222 const NAMING_AUTHORITY *n)
224 return n->namingAuthorityUrl;
227 void NAMING_AUTHORITY_set0_authorityURL(NAMING_AUTHORITY *n, ASN1_IA5STRING* u)
229 ASN1_IA5STRING_free(n->namingAuthorityUrl);
230 n->namingAuthorityUrl = u;
233 const ASN1_STRING *NAMING_AUTHORITY_get0_authorityText(
234 const NAMING_AUTHORITY *n)
236 return n->namingAuthorityText;
239 void NAMING_AUTHORITY_set0_authorityText(NAMING_AUTHORITY *n, ASN1_STRING* t)
241 ASN1_IA5STRING_free(n->namingAuthorityText);
242 n->namingAuthorityText = t;
245 const GENERAL_NAME *ADMISSION_SYNTAX_get0_admissionAuthority(const ADMISSION_SYNTAX *as)
247 return as->admissionAuthority;
250 void ADMISSION_SYNTAX_set0_admissionAuthority(ADMISSION_SYNTAX *as,
253 GENERAL_NAME_free(as->admissionAuthority);
254 as->admissionAuthority = aa;
257 const STACK_OF(ADMISSIONS) *ADMISSION_SYNTAX_get0_contentsOfAdmissions(const ADMISSION_SYNTAX *as)
259 return as->contentsOfAdmissions;
262 void ADMISSION_SYNTAX_set0_contentsOfAdmissions(ADMISSION_SYNTAX *as,
263 STACK_OF(ADMISSIONS) *a)
265 sk_ADMISSIONS_pop_free(as->contentsOfAdmissions, ADMISSIONS_free);
266 as->contentsOfAdmissions = a;
269 const GENERAL_NAME *ADMISSIONS_get0_admissionAuthority(const ADMISSIONS *a)
271 return a->admissionAuthority;
274 void ADMISSIONS_set0_admissionAuthority(ADMISSIONS *a, GENERAL_NAME *aa)
276 GENERAL_NAME_free(a->admissionAuthority);
277 a->admissionAuthority = aa;
280 const NAMING_AUTHORITY *ADMISSIONS_get0_namingAuthority(const ADMISSIONS *a)
282 return a->namingAuthority;
285 void ADMISSIONS_set0_namingAuthority(ADMISSIONS *a, NAMING_AUTHORITY *na)
287 NAMING_AUTHORITY_free(a->namingAuthority);
288 a->namingAuthority = na;
291 const PROFESSION_INFOS *ADMISSIONS_get0_professionInfos(const ADMISSIONS *a)
293 return a->professionInfos;
296 void ADMISSIONS_set0_professionInfos(ADMISSIONS *a, PROFESSION_INFOS *pi)
298 sk_PROFESSION_INFO_pop_free(a->professionInfos, PROFESSION_INFO_free);
299 a->professionInfos = pi;
302 const ASN1_OCTET_STRING *PROFESSION_INFO_get0_addProfessionInfo(const PROFESSION_INFO *pi)
304 return pi->addProfessionInfo;
307 void PROFESSION_INFO_set0_addProfessionInfo(PROFESSION_INFO *pi,
308 ASN1_OCTET_STRING *aos)
310 ASN1_OCTET_STRING_free(pi->addProfessionInfo);
311 pi->addProfessionInfo = aos;
314 const NAMING_AUTHORITY *PROFESSION_INFO_get0_namingAuthority(const PROFESSION_INFO *pi)
316 return pi->namingAuthority;
319 void PROFESSION_INFO_set0_namingAuthority(PROFESSION_INFO *pi,
320 NAMING_AUTHORITY *na)
322 NAMING_AUTHORITY_free(pi->namingAuthority);
323 pi->namingAuthority = na;
326 const STACK_OF(ASN1_STRING) *PROFESSION_INFO_get0_professionItems(const PROFESSION_INFO *pi)
328 return pi->professionItems;
331 void PROFESSION_INFO_set0_professionItems(PROFESSION_INFO *pi,
332 STACK_OF(ASN1_STRING) *as)
334 sk_ASN1_STRING_pop_free(pi->professionItems, ASN1_STRING_free);
335 pi->professionItems = as;
338 const STACK_OF(ASN1_OBJECT) *PROFESSION_INFO_get0_professionOIDs(const PROFESSION_INFO *pi)
340 return pi->professionOIDs;
343 void PROFESSION_INFO_set0_professionOIDs(PROFESSION_INFO *pi,
344 STACK_OF(ASN1_OBJECT) *po)
346 sk_ASN1_OBJECT_pop_free(pi->professionOIDs, ASN1_OBJECT_free);
347 pi->professionOIDs = po;
350 const ASN1_PRINTABLESTRING *PROFESSION_INFO_get0_registrationNumber(const PROFESSION_INFO *pi)
352 return pi->registrationNumber;
355 void PROFESSION_INFO_set0_registrationNumber(PROFESSION_INFO *pi,
356 ASN1_PRINTABLESTRING *rn)
358 ASN1_PRINTABLESTRING_free(pi->registrationNumber);
359 pi->registrationNumber = rn;