2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include <openssl/conf.h>
13 #include <openssl/asn1.h>
14 #include <openssl/asn1t.h>
15 #include <openssl/x509v3.h>
18 static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
19 *method, AUTHORITY_INFO_ACCESS
20 *ainfo, STACK_OF(CONF_VALUE)
22 static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
28 const X509V3_EXT_METHOD v3_info = { NID_info_access, X509V3_EXT_MULTILINE,
29 ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
32 (X509V3_EXT_I2V) i2v_AUTHORITY_INFO_ACCESS,
33 (X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
38 const X509V3_EXT_METHOD v3_sinfo = { NID_sinfo_access, X509V3_EXT_MULTILINE,
39 ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
42 (X509V3_EXT_I2V) i2v_AUTHORITY_INFO_ACCESS,
43 (X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
48 ASN1_SEQUENCE(ACCESS_DESCRIPTION) = {
49 ASN1_SIMPLE(ACCESS_DESCRIPTION, method, ASN1_OBJECT),
50 ASN1_SIMPLE(ACCESS_DESCRIPTION, location, GENERAL_NAME)
51 } ASN1_SEQUENCE_END(ACCESS_DESCRIPTION)
53 IMPLEMENT_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
55 ASN1_ITEM_TEMPLATE(AUTHORITY_INFO_ACCESS) =
56 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, GeneralNames, ACCESS_DESCRIPTION)
57 ASN1_ITEM_TEMPLATE_END(AUTHORITY_INFO_ACCESS)
59 IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
61 static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
62 *method, AUTHORITY_INFO_ACCESS
63 *ainfo, STACK_OF(CONF_VALUE)
66 ACCESS_DESCRIPTION *desc;
68 char objtmp[80], *ntmp;
70 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(ainfo); i++) {
71 desc = sk_ACCESS_DESCRIPTION_value(ainfo, i);
72 ret = i2v_GENERAL_NAME(method, desc->location, ret);
75 vtmp = sk_CONF_VALUE_value(ret, i);
76 i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method);
77 nlen = strlen(objtmp) + strlen(vtmp->name) + 5;
78 ntmp = OPENSSL_malloc(nlen);
80 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS,
81 ERR_R_MALLOC_FAILURE);
84 OPENSSL_strlcpy(ntmp, objtmp, nlen);
85 OPENSSL_strlcat(ntmp, " - ", nlen);
86 OPENSSL_strlcat(ntmp, vtmp->name, nlen);
87 OPENSSL_free(vtmp->name);
92 return sk_CONF_VALUE_new_null();
96 static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD
102 AUTHORITY_INFO_ACCESS *ainfo = NULL;
103 CONF_VALUE *cnf, ctmp;
104 ACCESS_DESCRIPTION *acc;
108 if ((ainfo = sk_ACCESS_DESCRIPTION_new_null()) == NULL) {
109 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, ERR_R_MALLOC_FAILURE);
112 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
113 cnf = sk_CONF_VALUE_value(nval, i);
114 if ((acc = ACCESS_DESCRIPTION_new()) == NULL
115 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
116 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,
117 ERR_R_MALLOC_FAILURE);
120 ptmp = strchr(cnf->name, ';');
122 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,
123 X509V3_R_INVALID_SYNTAX);
126 objlen = ptmp - cnf->name;
127 ctmp.name = ptmp + 1;
128 ctmp.value = cnf->value;
129 if (!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0))
131 if ((objtmp = OPENSSL_strndup(cnf->name, objlen)) == NULL) {
132 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,
133 ERR_R_MALLOC_FAILURE);
136 acc->method = OBJ_txt2obj(objtmp, 0);
138 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,
139 X509V3_R_BAD_OBJECT);
140 ERR_add_error_data(2, "value=", objtmp);
141 OPENSSL_free(objtmp);
144 OPENSSL_free(objtmp);
149 sk_ACCESS_DESCRIPTION_pop_free(ainfo, ACCESS_DESCRIPTION_free);
153 int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a)
155 i2a_ASN1_OBJECT(bp, a->method);