v3_pci.c
Go to the documentation of this file.
1 /* v3_pci.c -*- mode:C; c-file-style: "eay" -*- */
2 /*
3  * Contributed to the OpenSSL Project 2004 by Richard Levitte
4  * (richard@levitte.org)
5  */
6 /* Copyright (c) 2004 Kungliga Tekniska Högskolan
7  * (Royal Institute of Technology, Stockholm, Sweden).
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  *
21  * 3. Neither the name of the Institute nor the names of its contributors
22  * may be used to endorse or promote products derived from this software
23  * without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  */
37 
38 #include <string.h>
39 
40 #include <openssl/conf.h>
41 #include <openssl/err.h>
42 #include <openssl/mem.h>
43 #include <openssl/obj.h>
44 #include <openssl/x509v3.h>
45 
46 #include "../internal.h"
47 #include "internal.h"
48 
49 
51  BIO *out, int indent);
53  X509V3_CTX *ctx, char *str);
54 
57  0, 0, 0, 0,
58  0, 0,
59  NULL, NULL,
62  NULL,
63 };
64 
66  BIO *out, int indent)
67 {
68  BIO_printf(out, "%*sPath Length Constraint: ", indent, "");
69  if (pci->pcPathLengthConstraint)
71  else
72  BIO_printf(out, "infinite");
73  BIO_puts(out, "\n");
74  BIO_printf(out, "%*sPolicy Language: ", indent, "");
76  BIO_puts(out, "\n");
77  if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data)
78  BIO_printf(out, "%*sPolicy Text: %.*s\n", indent, "",
79  pci->proxyPolicy->policy->length,
80  pci->proxyPolicy->policy->data);
81  return 1;
82 }
83 
84 static int process_pci_value(CONF_VALUE *val,
85  ASN1_OBJECT **language, ASN1_INTEGER **pathlen,
86  ASN1_OCTET_STRING **policy)
87 {
88  int free_policy = 0;
89 
90  if (strcmp(val->name, "language") == 0) {
91  if (*language) {
92  OPENSSL_PUT_ERROR(X509V3,
94  X509V3_conf_err(val);
95  return 0;
96  }
97  if (!(*language = OBJ_txt2obj(val->value, 0))) {
99  X509V3_conf_err(val);
100  return 0;
101  }
102  } else if (strcmp(val->name, "pathlen") == 0) {
103  if (*pathlen) {
104  OPENSSL_PUT_ERROR(X509V3,
106  X509V3_conf_err(val);
107  return 0;
108  }
109  if (!X509V3_get_value_int(val, pathlen)) {
111  X509V3_conf_err(val);
112  return 0;
113  }
114  } else if (strcmp(val->name, "policy") == 0) {
115  unsigned char *tmp_data = NULL;
116  long val_len;
117  if (!*policy) {
118  *policy = ASN1_OCTET_STRING_new();
119  if (!*policy) {
121  X509V3_conf_err(val);
122  return 0;
123  }
124  free_policy = 1;
125  }
126  if (strncmp(val->value, "hex:", 4) == 0) {
127  unsigned char *tmp_data2 =
128  x509v3_hex_to_bytes(val->value + 4, &val_len);
129 
130  if (!tmp_data2) {
132  X509V3_conf_err(val);
133  goto err;
134  }
135 
136  tmp_data = OPENSSL_realloc((*policy)->data,
137  (*policy)->length + val_len + 1);
138  if (tmp_data) {
139  (*policy)->data = tmp_data;
140  OPENSSL_memcpy(&(*policy)->data[(*policy)->length],
141  tmp_data2, val_len);
142  (*policy)->length += val_len;
143  (*policy)->data[(*policy)->length] = '\0';
144  } else {
145  OPENSSL_free(tmp_data2);
146  /*
147  * realloc failure implies the original data space is b0rked
148  * too!
149  */
150  (*policy)->data = NULL;
151  (*policy)->length = 0;
153  X509V3_conf_err(val);
154  goto err;
155  }
156  OPENSSL_free(tmp_data2);
157  } else if (strncmp(val->value, "text:", 5) == 0) {
158  val_len = strlen(val->value + 5);
159  tmp_data = OPENSSL_realloc((*policy)->data,
160  (*policy)->length + val_len + 1);
161  if (tmp_data) {
162  (*policy)->data = tmp_data;
163  OPENSSL_memcpy(&(*policy)->data[(*policy)->length],
164  val->value + 5, val_len);
165  (*policy)->length += val_len;
166  (*policy)->data[(*policy)->length] = '\0';
167  } else {
168  /*
169  * realloc failure implies the original data space is b0rked
170  * too!
171  */
172  (*policy)->data = NULL;
173  (*policy)->length = 0;
175  X509V3_conf_err(val);
176  goto err;
177  }
178  } else {
180  X509V3_conf_err(val);
181  goto err;
182  }
183  if (!tmp_data) {
185  X509V3_conf_err(val);
186  goto err;
187  }
188  }
189  return 1;
190  err:
191  if (free_policy) {
192  ASN1_OCTET_STRING_free(*policy);
193  *policy = NULL;
194  }
195  return 0;
196 }
197 
199  X509V3_CTX *ctx, char *value)
200 {
201  PROXY_CERT_INFO_EXTENSION *pci = NULL;
203  ASN1_OBJECT *language = NULL;
204  ASN1_INTEGER *pathlen = NULL;
205  ASN1_OCTET_STRING *policy = NULL;
206  size_t i, j;
207  int nid;
208 
210  for (i = 0; i < sk_CONF_VALUE_num(vals); i++) {
211  CONF_VALUE *cnf = sk_CONF_VALUE_value(vals, i);
212  if (!cnf->name || (*cnf->name != '@' && !cnf->value)) {
214  X509V3_conf_err(cnf);
215  goto err;
216  }
217  if (*cnf->name == '@') {
218  STACK_OF(CONF_VALUE) *sect;
219  int success_p = 1;
220 
221  sect = X509V3_get_section(ctx, cnf->name + 1);
222  if (!sect) {
224  X509V3_conf_err(cnf);
225  goto err;
226  }
227  for (j = 0; success_p && j < sk_CONF_VALUE_num(sect); j++) {
228  success_p =
229  process_pci_value(sk_CONF_VALUE_value(sect, j),
230  &language, &pathlen, &policy);
231  }
232  X509V3_section_free(ctx, sect);
233  if (!success_p)
234  goto err;
235  } else {
236  if (!process_pci_value(cnf, &language, &pathlen, &policy)) {
237  X509V3_conf_err(cnf);
238  goto err;
239  }
240  }
241  }
242 
243  /* Language is mandatory */
244  if (!language) {
245  OPENSSL_PUT_ERROR(X509V3,
247  goto err;
248  }
250  if ((nid == NID_Independent || nid == NID_id_ppl_inheritAll) && policy) {
251  OPENSSL_PUT_ERROR(X509V3,
253  goto err;
254  }
255 
257  if (!pci) {
259  goto err;
260  }
261 
263  language = NULL;
264  pci->proxyPolicy->policy = policy;
265  policy = NULL;
266  pci->pcPathLengthConstraint = pathlen;
267  pathlen = NULL;
268  goto end;
269  err:
270  if (language) {
272  language = NULL;
273  }
274  if (pathlen) {
275  ASN1_INTEGER_free(pathlen);
276  pathlen = NULL;
277  }
278  if (policy) {
279  ASN1_OCTET_STRING_free(policy);
280  policy = NULL;
281  }
282  if (pci) {
284  pci = NULL;
285  }
286  end:
287  sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
288  return pci;
289 }
PROXY_POLICY_st::policy
ASN1_OCTET_STRING * policy
Definition: x509v3.h:323
xds_interop_client.str
str
Definition: xds_interop_client.py:487
v3_pci
const X509V3_EXT_METHOD v3_pci
Definition: v3_pci.c:55
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
PROXY_CERT_INFO_EXTENSION_st::pcPathLengthConstraint
ASN1_INTEGER * pcPathLengthConstraint
Definition: x509v3.h:327
i2r_pci
static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *ext, BIO *out, int indent)
Definition: v3_pci.c:65
ctx
Definition: benchmark-async.c:30
v3_ext_ctx
Definition: x509v3.h:136
bio_st
Definition: bio.h:822
X509V3_EXT_I2R
int(* X509V3_EXT_I2R)(const struct v3_ext_method *method, void *ext, BIO *out, int indent)
Definition: x509v3.h:95
X509V3_R_INVALID_PROXY_POLICY_SETTING
#define X509V3_R_INVALID_PROXY_POLICY_SETTING
Definition: x509v3.h:986
PROXY_CERT_INFO_EXTENSION_new
#define PROXY_CERT_INFO_EXTENSION_new
Definition: boringssl_prefix_symbols.h:2053
X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED
#define X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED
Definition: x509v3.h:1005
X509V3_EXT_R2I
void *(* X509V3_EXT_R2I)(const struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str)
Definition: x509v3.h:97
OPENSSL_PUT_ERROR
#define OPENSSL_PUT_ERROR(library, reason)
Definition: err.h:423
internal.h
ext
void * ext
Definition: x509v3.h:87
string.h
OPENSSL_realloc
#define OPENSSL_realloc
Definition: boringssl_prefix_symbols.h:1889
x509v3_hex_to_bytes
#define x509v3_hex_to_bytes
Definition: boringssl_prefix_symbols.h:3460
r2i_pci
static PROXY_CERT_INFO_EXTENSION * r2i_pci(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
Definition: v3_pci.c:198
error_ref_leak.err
err
Definition: error_ref_leak.py:35
PROXY_CERT_INFO_EXTENSION_free
#define PROXY_CERT_INFO_EXTENSION_free
Definition: boringssl_prefix_symbols.h:2051
x509v3.h
X509V3_get_section
#define X509V3_get_section
Definition: boringssl_prefix_symbols.h:2241
ASN1_ITEM_ref
#define ASN1_ITEM_ref(name)
Definition: asn1.h:312
X509V3_conf_err
#define X509V3_conf_err(val)
Definition: x509v3.h:359
gen_header_frame.vals
list vals
Definition: gen_header_frame.py:73
python_utils.upload_rbe_results.indent
indent
Definition: upload_rbe_results.py:183
asn1_string_st::data
unsigned char * data
Definition: asn1.h:546
BIO_printf
#define BIO_printf
Definition: boringssl_prefix_symbols.h:827
ASN1_OCTET_STRING_new
OPENSSL_EXPORT ASN1_OCTET_STRING * ASN1_OCTET_STRING_new(void)
asn1_object_st
Definition: third_party/boringssl-with-bazel/src/crypto/asn1/internal.h:102
i2a_ASN1_INTEGER
#define i2a_ASN1_INTEGER
Definition: boringssl_prefix_symbols.h:3171
OBJ_obj2nid
#define OBJ_obj2nid
Definition: boringssl_prefix_symbols.h:1857
conf.language
string language
Definition: doc/python/sphinx/conf.py:48
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
STACK_OF
#define STACK_OF(type)
Definition: stack.h:125
conf_value_st::value
char * value
Definition: conf.h:85
NID_id_ppl_inheritAll
#define NID_id_ppl_inheritAll
Definition: nid.h:2958
asn1_string_st::length
int length
Definition: asn1.h:544
X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED
#define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED
Definition: x509v3.h:997
PROXY_CERT_INFO_EXTENSION_st::proxyPolicy
PROXY_POLICY * proxyPolicy
Definition: x509v3.h:328
process_pci_value
static int process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language, ASN1_INTEGER **pathlen, ASN1_OCTET_STRING **policy)
Definition: v3_pci.c:84
OBJ_txt2obj
#define OBJ_txt2obj
Definition: boringssl_prefix_symbols.h:1861
X509V3_section_free
#define X509V3_section_free
Definition: boringssl_prefix_symbols.h:2246
X509V3_conf_free
#define X509V3_conf_free
Definition: boringssl_prefix_symbols.h:2238
OPENSSL_memcpy
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:819
err.h
X509V3_R_INVALID_OBJECT_IDENTIFIER
#define X509V3_R_INVALID_OBJECT_IDENTIFIER
Definition: x509v3.h:983
ASN1_OBJECT_free
#define ASN1_OBJECT_free
Definition: boringssl_prefix_symbols.h:655
ASN1_INTEGER_free
OPENSSL_EXPORT void ASN1_INTEGER_free(ASN1_INTEGER *str)
conf.h
PROXY_CERT_INFO_EXTENSION_st
Definition: x509v3.h:326
nid
int nid
Definition: cipher_extra.c:71
value
const char * value
Definition: hpack_parser_table.cc:165
X509V3_R_ILLEGAL_HEX_DIGIT
#define X509V3_R_ILLEGAL_HEX_DIGIT
Definition: x509v3.h:972
X509V3_parse_list
#define X509V3_parse_list
Definition: boringssl_prefix_symbols.h:2245
i2a_ASN1_OBJECT
#define i2a_ASN1_OBJECT
Definition: boringssl_prefix_symbols.h:3172
X509V3_R_POLICY_PATH_LENGTH
#define X509V3_R_POLICY_PATH_LENGTH
Definition: x509v3.h:1004
BIO_puts
#define BIO_puts
Definition: boringssl_prefix_symbols.h:830
NID_Independent
#define NID_Independent
Definition: nid.h:2968
X509V3_R_INVALID_SECTION
#define X509V3_R_INVALID_SECTION
Definition: x509v3.h:988
X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED
#define X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED
Definition: x509v3.h:1003
obj.h
X509V3_R_INCORRECT_POLICY_SYNTAX_TAG
#define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG
Definition: x509v3.h:973
NID_proxyCertInfo
#define NID_proxyCertInfo
Definition: nid.h:2948
v3_ext_method
Definition: x509v3.h:102
mem.h
method
NSString * method
Definition: ProtoMethod.h:28
X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY
#define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY
Definition: x509v3.h:1006
OPENSSL_free
#define OPENSSL_free
Definition: boringssl_prefix_symbols.h:1869
asn1_string_st
Definition: asn1.h:543
ASN1_OCTET_STRING_free
OPENSSL_EXPORT void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *str)
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
ERR_R_MALLOC_FAILURE
#define ERR_R_MALLOC_FAILURE
Definition: err.h:371
X509V3_get_value_int
#define X509V3_get_value_int
Definition: boringssl_prefix_symbols.h:2244
PROXY_POLICY_st::policyLanguage
ASN1_OBJECT * policyLanguage
Definition: x509v3.h:322
conf_value_st
Definition: conf.h:82
conf_value_st::name
char * name
Definition: conf.h:84


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:50