summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
index 3dee31e195..4321c09c19 100644
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ b/src/lib/libcrypto/x509/x509_v3.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_v3.c,v 1.22 2024/05/16 13:19:09 tb Exp $ */ 1/* $OpenBSD: x509_v3.c,v 1.23 2024/05/23 01:40:23 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -94,7 +94,7 @@ X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk,
94 const ASN1_OBJECT *obj, int lastpos) 94 const ASN1_OBJECT *obj, int lastpos)
95{ 95{
96 int n; 96 int n;
97 X509_EXTENSION *ex; 97 X509_EXTENSION *ext;
98 98
99 if (sk == NULL) 99 if (sk == NULL)
100 return -1; 100 return -1;
@@ -103,8 +103,8 @@ X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk,
103 lastpos = 0; 103 lastpos = 0;
104 n = sk_X509_EXTENSION_num(sk); 104 n = sk_X509_EXTENSION_num(sk);
105 for (; lastpos < n; lastpos++) { 105 for (; lastpos < n; lastpos++) {
106 ex = sk_X509_EXTENSION_value(sk, lastpos); 106 ext = sk_X509_EXTENSION_value(sk, lastpos);
107 if (OBJ_cmp(ex->object, obj) == 0) 107 if (OBJ_cmp(ext->object, obj) == 0)
108 return lastpos; 108 return lastpos;
109 } 109 }
110 return -1; 110 return -1;
@@ -116,7 +116,7 @@ X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
116 int lastpos) 116 int lastpos)
117{ 117{
118 int n; 118 int n;
119 X509_EXTENSION *ex; 119 X509_EXTENSION *ext;
120 120
121 if (sk == NULL) 121 if (sk == NULL)
122 return -1; 122 return -1;
@@ -125,9 +125,9 @@ X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
125 lastpos = 0; 125 lastpos = 0;
126 n = sk_X509_EXTENSION_num(sk); 126 n = sk_X509_EXTENSION_num(sk);
127 for (; lastpos < n; lastpos++) { 127 for (; lastpos < n; lastpos++) {
128 ex = sk_X509_EXTENSION_value(sk, lastpos); 128 ext = sk_X509_EXTENSION_value(sk, lastpos);
129 if ((ex->critical > 0 && crit) || 129 if ((ext->critical > 0 && crit) ||
130 (ex->critical <= 0 && !crit)) 130 (ext->critical <= 0 && !crit))
131 return lastpos; 131 return lastpos;
132 } 132 }
133 return -1; 133 return -1;
@@ -157,9 +157,9 @@ X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc)
157LCRYPTO_ALIAS(X509v3_delete_ext); 157LCRYPTO_ALIAS(X509v3_delete_ext);
158 158
159STACK_OF(X509_EXTENSION) * 159STACK_OF(X509_EXTENSION) *
160X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc) 160X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ext, int loc)
161{ 161{
162 X509_EXTENSION *new_ex = NULL; 162 X509_EXTENSION *new_ext = NULL;
163 int n; 163 int n;
164 STACK_OF(X509_EXTENSION) *sk = NULL; 164 STACK_OF(X509_EXTENSION) *sk = NULL;
165 165
@@ -180,9 +180,9 @@ X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc)
180 else if (loc < 0) 180 else if (loc < 0)
181 loc = n; 181 loc = n;
182 182
183 if ((new_ex = X509_EXTENSION_dup(ex)) == NULL) 183 if ((new_ext = X509_EXTENSION_dup(ext)) == NULL)
184 goto err2; 184 goto err2;
185 if (!sk_X509_EXTENSION_insert(sk, new_ex, loc)) 185 if (!sk_X509_EXTENSION_insert(sk, new_ext, loc))
186 goto err; 186 goto err;
187 if (*x == NULL) 187 if (*x == NULL)
188 *x = sk; 188 *x = sk;
@@ -191,8 +191,8 @@ X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc)
191err: 191err:
192 X509error(ERR_R_MALLOC_FAILURE); 192 X509error(ERR_R_MALLOC_FAILURE);
193err2: 193err2:
194 if (new_ex != NULL) 194 if (new_ext != NULL)
195 X509_EXTENSION_free(new_ex); 195 X509_EXTENSION_free(new_ext);
196 if (sk != NULL && x != NULL && sk != *x) 196 if (sk != NULL && x != NULL && sk != *x)
197 sk_X509_EXTENSION_free(sk); 197 sk_X509_EXTENSION_free(sk);
198 return NULL; 198 return NULL;
@@ -200,7 +200,7 @@ err2:
200LCRYPTO_ALIAS(X509v3_add_ext); 200LCRYPTO_ALIAS(X509v3_add_ext);
201 201
202X509_EXTENSION * 202X509_EXTENSION *
203X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, int crit, 203X509_EXTENSION_create_by_NID(X509_EXTENSION **ext, int nid, int crit,
204 ASN1_OCTET_STRING *data) 204 ASN1_OCTET_STRING *data)
205{ 205{
206 ASN1_OBJECT *obj; 206 ASN1_OBJECT *obj;
@@ -211,7 +211,7 @@ X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, int crit,
211 X509error(X509_R_UNKNOWN_NID); 211 X509error(X509_R_UNKNOWN_NID);
212 return NULL; 212 return NULL;
213 } 213 }
214 ret = X509_EXTENSION_create_by_OBJ(ex, obj, crit, data); 214 ret = X509_EXTENSION_create_by_OBJ(ext, obj, crit, data);
215 if (ret == NULL) 215 if (ret == NULL)
216 ASN1_OBJECT_free(obj); 216 ASN1_OBJECT_free(obj);
217 return ret; 217 return ret;
@@ -219,18 +219,18 @@ X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, int crit,
219LCRYPTO_ALIAS(X509_EXTENSION_create_by_NID); 219LCRYPTO_ALIAS(X509_EXTENSION_create_by_NID);
220 220
221X509_EXTENSION * 221X509_EXTENSION *
222X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, const ASN1_OBJECT *obj, 222X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ext, const ASN1_OBJECT *obj,
223 int crit, ASN1_OCTET_STRING *data) 223 int crit, ASN1_OCTET_STRING *data)
224{ 224{
225 X509_EXTENSION *ret; 225 X509_EXTENSION *ret;
226 226
227 if (ex == NULL || *ex == NULL) { 227 if (ext == NULL || *ext == NULL) {
228 if ((ret = X509_EXTENSION_new()) == NULL) { 228 if ((ret = X509_EXTENSION_new()) == NULL) {
229 X509error(ERR_R_MALLOC_FAILURE); 229 X509error(ERR_R_MALLOC_FAILURE);
230 return NULL; 230 return NULL;
231 } 231 }
232 } else 232 } else
233 ret= *ex; 233 ret= *ext;
234 234
235 if (!X509_EXTENSION_set_object(ret, obj)) 235 if (!X509_EXTENSION_set_object(ret, obj))
236 goto err; 236 goto err;
@@ -239,46 +239,46 @@ X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, const ASN1_OBJECT *obj,
239 if (!X509_EXTENSION_set_data(ret, data)) 239 if (!X509_EXTENSION_set_data(ret, data))
240 goto err; 240 goto err;
241 241
242 if (ex != NULL && *ex == NULL) 242 if (ext != NULL && *ext == NULL)
243 *ex = ret; 243 *ext = ret;
244 return ret; 244 return ret;
245 245
246err: 246err:
247 if (ex == NULL || ret != *ex) 247 if (ext == NULL || ret != *ext)
248 X509_EXTENSION_free(ret); 248 X509_EXTENSION_free(ret);
249 return NULL; 249 return NULL;
250} 250}
251LCRYPTO_ALIAS(X509_EXTENSION_create_by_OBJ); 251LCRYPTO_ALIAS(X509_EXTENSION_create_by_OBJ);
252 252
253int 253int
254X509_EXTENSION_set_object(X509_EXTENSION *ex, const ASN1_OBJECT *obj) 254X509_EXTENSION_set_object(X509_EXTENSION *ext, const ASN1_OBJECT *obj)
255{ 255{
256 if (ex == NULL || obj == NULL) 256 if (ext == NULL || obj == NULL)
257 return 0; 257 return 0;
258 ASN1_OBJECT_free(ex->object); 258 ASN1_OBJECT_free(ext->object);
259 ex->object = OBJ_dup(obj); 259 ext->object = OBJ_dup(obj);
260 return ex->object != NULL; 260 return ext->object != NULL;
261} 261}
262LCRYPTO_ALIAS(X509_EXTENSION_set_object); 262LCRYPTO_ALIAS(X509_EXTENSION_set_object);
263 263
264int 264int
265X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit) 265X509_EXTENSION_set_critical(X509_EXTENSION *ext, int crit)
266{ 266{
267 if (ex == NULL) 267 if (ext == NULL)
268 return 0; 268 return 0;
269 ex->critical = crit ? 0xFF : -1; 269 ext->critical = crit ? 0xFF : -1;
270 return 1; 270 return 1;
271} 271}
272LCRYPTO_ALIAS(X509_EXTENSION_set_critical); 272LCRYPTO_ALIAS(X509_EXTENSION_set_critical);
273 273
274int 274int
275X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data) 275X509_EXTENSION_set_data(X509_EXTENSION *ext, ASN1_OCTET_STRING *data)
276{ 276{
277 int i; 277 int i;
278 278
279 if (ex == NULL) 279 if (ext == NULL)
280 return 0; 280 return 0;
281 i = ASN1_STRING_set(ex->value, data->data, data->length); 281 i = ASN1_STRING_set(ext->value, data->data, data->length);
282 if (!i) 282 if (!i)
283 return 0; 283 return 0;
284 return 1; 284 return 1;
@@ -286,29 +286,29 @@ X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
286LCRYPTO_ALIAS(X509_EXTENSION_set_data); 286LCRYPTO_ALIAS(X509_EXTENSION_set_data);
287 287
288ASN1_OBJECT * 288ASN1_OBJECT *
289X509_EXTENSION_get_object(X509_EXTENSION *ex) 289X509_EXTENSION_get_object(X509_EXTENSION *ext)
290{ 290{
291 if (ex == NULL) 291 if (ext == NULL)
292 return NULL; 292 return NULL;
293 return ex->object; 293 return ext->object;
294} 294}
295LCRYPTO_ALIAS(X509_EXTENSION_get_object); 295LCRYPTO_ALIAS(X509_EXTENSION_get_object);
296 296
297ASN1_OCTET_STRING * 297ASN1_OCTET_STRING *
298X509_EXTENSION_get_data(X509_EXTENSION *ex) 298X509_EXTENSION_get_data(X509_EXTENSION *ext)
299{ 299{
300 if (ex == NULL) 300 if (ext == NULL)
301 return NULL; 301 return NULL;
302 return ex->value; 302 return ext->value;
303} 303}
304LCRYPTO_ALIAS(X509_EXTENSION_get_data); 304LCRYPTO_ALIAS(X509_EXTENSION_get_data);
305 305
306int 306int
307X509_EXTENSION_get_critical(const X509_EXTENSION *ex) 307X509_EXTENSION_get_critical(const X509_EXTENSION *ext)
308{ 308{
309 if (ex == NULL) 309 if (ext == NULL)
310 return 0; 310 return 0;
311 if (ex->critical > 0) 311 if (ext->critical > 0)
312 return 1; 312 return 1;
313 return 0; 313 return 0;
314} 314}