summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-01-07 14:50:45 +0000
committertb <>2024-01-07 14:50:45 +0000
commite76a414f8808d66dcbcfa39c77bedc8c8f469d5b (patch)
tree1abee0aa041f41d174e7143e6181aef23d52ecf3 /src
parentbf702ad7405cf38ecfa682f20ce867b97a100239 (diff)
downloadopenbsd-e76a414f8808d66dcbcfa39c77bedc8c8f469d5b.tar.gz
openbsd-e76a414f8808d66dcbcfa39c77bedc8c8f469d5b.tar.bz2
openbsd-e76a414f8808d66dcbcfa39c77bedc8c8f469d5b.zip
Remove X509_TRUST extensibility
This is pretty much identical to the X509_PURPOSE case: remove the stack used for extending and overriding the trust table and make X509_TRUST_add() always fail. Simplify some other bits accordingly. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c112
1 files changed, 10 insertions, 102 deletions
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
index 6b935f8bee..e3a20e22b0 100644
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_trs.c,v 1.32 2023/07/02 17:12:17 tb Exp $ */ 1/* $OpenBSD: x509_trs.c,v 1.33 2024/01/07 14:50:45 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -64,9 +64,6 @@
64 64
65#include "x509_local.h" 65#include "x509_local.h"
66 66
67static int tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b);
68static void trtable_free(X509_TRUST *p);
69
70static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags); 67static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);
71static int trust_1oid(X509_TRUST *trust, X509 *x, int flags); 68static int trust_1oid(X509_TRUST *trust, X509 *x, int flags);
72static int trust_compat(X509_TRUST *trust, X509 *x, int flags); 69static int trust_compat(X509_TRUST *trust, X509 *x, int flags);
@@ -131,14 +128,6 @@ static X509_TRUST trstandard[] = {
131 128
132#define X509_TRUST_COUNT (sizeof(trstandard) / sizeof(trstandard[0])) 129#define X509_TRUST_COUNT (sizeof(trstandard) / sizeof(trstandard[0]))
133 130
134static STACK_OF(X509_TRUST) *trtable = NULL;
135
136static int
137tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b)
138{
139 return (*a)->trust - (*b)->trust;
140}
141
142int 131int
143(*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int) 132(*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int)
144{ 133{
@@ -185,38 +174,28 @@ LCRYPTO_ALIAS(X509_check_trust);
185int 174int
186X509_TRUST_get_count(void) 175X509_TRUST_get_count(void)
187{ 176{
188 if (!trtable) 177 return X509_TRUST_COUNT;
189 return X509_TRUST_COUNT;
190 return sk_X509_TRUST_num(trtable) + X509_TRUST_COUNT;
191} 178}
192LCRYPTO_ALIAS(X509_TRUST_get_count); 179LCRYPTO_ALIAS(X509_TRUST_get_count);
193 180
194X509_TRUST * 181X509_TRUST *
195X509_TRUST_get0(int idx) 182X509_TRUST_get0(int idx)
196{ 183{
197 if (idx < 0) 184 if (idx < 0 || (size_t)idx >= X509_TRUST_COUNT)
198 return NULL; 185 return NULL;
199 if (idx < (int)X509_TRUST_COUNT) 186
200 return trstandard + idx; 187 return &trstandard[idx];
201 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
202} 188}
203LCRYPTO_ALIAS(X509_TRUST_get0); 189LCRYPTO_ALIAS(X509_TRUST_get0);
204 190
205int 191int
206X509_TRUST_get_by_id(int id) 192X509_TRUST_get_by_id(int id)
207{ 193{
208 X509_TRUST tmp; 194 /* X509_TRUST_MIN == 1, so the bounds are correct. */
209 int idx; 195 if (id < X509_TRUST_MIN && id > X509_TRUST_MAX)
210
211 if ((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
212 return id - X509_TRUST_MIN;
213 tmp.trust = id;
214 if (!trtable)
215 return -1;
216 idx = sk_X509_TRUST_find(trtable, &tmp);
217 if (idx == -1)
218 return -1; 196 return -1;
219 return idx + X509_TRUST_COUNT; 197
198 return id - X509_TRUST_MIN;
220} 199}
221LCRYPTO_ALIAS(X509_TRUST_get_by_id); 200LCRYPTO_ALIAS(X509_TRUST_get_by_id);
222 201
@@ -236,85 +215,14 @@ int
236X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), 215X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
237 const char *name, int arg1, void *arg2) 216 const char *name, int arg1, void *arg2)
238{ 217{
239 int idx; 218 X509error(ERR_R_DISABLED);
240 X509_TRUST *trtmp;
241 char *name_dup;
242
243 /* This is set according to what we change: application can't set it */
244 flags &= ~X509_TRUST_DYNAMIC;
245 /* This will always be set for application modified trust entries */
246 flags |= X509_TRUST_DYNAMIC_NAME;
247 /* Get existing entry if any */
248 idx = X509_TRUST_get_by_id(id);
249 /* Need a new entry */
250 if (idx == -1) {
251 if (!(trtmp = malloc(sizeof(X509_TRUST)))) {
252 X509error(ERR_R_MALLOC_FAILURE);
253 return 0;
254 }
255 trtmp->flags = X509_TRUST_DYNAMIC;
256 } else {
257 trtmp = X509_TRUST_get0(idx);
258 if (trtmp == NULL) {
259 X509error(X509_R_INVALID_TRUST);
260 return 0;
261 }
262 }
263
264 if ((name_dup = strdup(name)) == NULL)
265 goto err;
266
267 /* free existing name if dynamic */
268 if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)
269 free(trtmp->name);
270 /* dup supplied name */
271 trtmp->name = name_dup;
272 /* Keep the dynamic flag of existing entry */
273 trtmp->flags &= X509_TRUST_DYNAMIC;
274 /* Set all other flags */
275 trtmp->flags |= flags;
276
277 trtmp->trust = id;
278 trtmp->check_trust = ck;
279 trtmp->arg1 = arg1;
280 trtmp->arg2 = arg2;
281
282 /* If it's a new entry, manage the dynamic table */
283 if (idx == -1) {
284 if (trtable == NULL &&
285 (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL)
286 goto err;
287 if (sk_X509_TRUST_push(trtable, trtmp) == 0)
288 goto err;
289 }
290 return 1;
291
292err:
293 free(name_dup);
294 if (idx == -1)
295 free(trtmp);
296 X509error(ERR_R_MALLOC_FAILURE);
297 return 0; 219 return 0;
298} 220}
299LCRYPTO_ALIAS(X509_TRUST_add); 221LCRYPTO_ALIAS(X509_TRUST_add);
300 222
301static void
302trtable_free(X509_TRUST *p)
303{
304 if (!p)
305 return;
306 if (p->flags & X509_TRUST_DYNAMIC) {
307 if (p->flags & X509_TRUST_DYNAMIC_NAME)
308 free(p->name);
309 free(p);
310 }
311}
312
313void 223void
314X509_TRUST_cleanup(void) 224X509_TRUST_cleanup(void)
315{ 225{
316 sk_X509_TRUST_pop_free(trtable, trtable_free);
317 trtable = NULL;
318} 226}
319LCRYPTO_ALIAS(X509_TRUST_cleanup); 227LCRYPTO_ALIAS(X509_TRUST_cleanup);
320 228