diff options
| author | tb <> | 2024-01-07 14:50:45 +0000 |
|---|---|---|
| committer | tb <> | 2024-01-07 14:50:45 +0000 |
| commit | 0da1b1b923de1d17a643b83aba8a331fdb974595 (patch) | |
| tree | 1abee0aa041f41d174e7143e6181aef23d52ecf3 /src | |
| parent | bf376912db7e8fbe9b235538e3c4842921bc30bb (diff) | |
| download | openbsd-0da1b1b923de1d17a643b83aba8a331fdb974595.tar.gz openbsd-0da1b1b923de1d17a643b83aba8a331fdb974595.tar.bz2 openbsd-0da1b1b923de1d17a643b83aba8a331fdb974595.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.c | 112 |
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 | ||
| 67 | static int tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b); | ||
| 68 | static void trtable_free(X509_TRUST *p); | ||
| 69 | |||
| 70 | static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags); | 67 | static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags); |
| 71 | static int trust_1oid(X509_TRUST *trust, X509 *x, int flags); | 68 | static int trust_1oid(X509_TRUST *trust, X509 *x, int flags); |
| 72 | static int trust_compat(X509_TRUST *trust, X509 *x, int flags); | 69 | static 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 | ||
| 134 | static STACK_OF(X509_TRUST) *trtable = NULL; | ||
| 135 | |||
| 136 | static int | ||
| 137 | tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b) | ||
| 138 | { | ||
| 139 | return (*a)->trust - (*b)->trust; | ||
| 140 | } | ||
| 141 | |||
| 142 | int | 131 | int |
| 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); | |||
| 185 | int | 174 | int |
| 186 | X509_TRUST_get_count(void) | 175 | X509_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 | } |
| 192 | LCRYPTO_ALIAS(X509_TRUST_get_count); | 179 | LCRYPTO_ALIAS(X509_TRUST_get_count); |
| 193 | 180 | ||
| 194 | X509_TRUST * | 181 | X509_TRUST * |
| 195 | X509_TRUST_get0(int idx) | 182 | X509_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 | } |
| 203 | LCRYPTO_ALIAS(X509_TRUST_get0); | 189 | LCRYPTO_ALIAS(X509_TRUST_get0); |
| 204 | 190 | ||
| 205 | int | 191 | int |
| 206 | X509_TRUST_get_by_id(int id) | 192 | X509_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 | } |
| 221 | LCRYPTO_ALIAS(X509_TRUST_get_by_id); | 200 | LCRYPTO_ALIAS(X509_TRUST_get_by_id); |
| 222 | 201 | ||
| @@ -236,85 +215,14 @@ int | |||
| 236 | X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), | 215 | X509_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 | |||
| 292 | err: | ||
| 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 | } |
| 299 | LCRYPTO_ALIAS(X509_TRUST_add); | 221 | LCRYPTO_ALIAS(X509_TRUST_add); |
| 300 | 222 | ||
| 301 | static void | ||
| 302 | trtable_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 | |||
| 313 | void | 223 | void |
| 314 | X509_TRUST_cleanup(void) | 224 | X509_TRUST_cleanup(void) |
| 315 | { | 225 | { |
| 316 | sk_X509_TRUST_pop_free(trtable, trtable_free); | ||
| 317 | trtable = NULL; | ||
| 318 | } | 226 | } |
| 319 | LCRYPTO_ALIAS(X509_TRUST_cleanup); | 227 | LCRYPTO_ALIAS(X509_TRUST_cleanup); |
| 320 | 228 | ||
