summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2024-01-10 21:11:37 +0000
committertb <>2024-01-10 21:11:37 +0000
commit43fd67915d7f16fede4a13b7fc8fc14d98aeffa2 (patch)
tree3926ede793a554fe73c638a21e2be588db6978b6 /src/lib
parent4727d280f7f2b3ef945bdccedd807691b37adf71 (diff)
downloadopenbsd-43fd67915d7f16fede4a13b7fc8fc14d98aeffa2.tar.gz
openbsd-43fd67915d7f16fede4a13b7fc8fc14d98aeffa2.tar.bz2
openbsd-43fd67915d7f16fede4a13b7fc8fc14d98aeffa2.zip
X509_TRUST: start shuffling some code around
Hoist obj_trust() to the top and move the static default_trust() next to its setter.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
index db5056dfd1..f42c34b087 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.35 2024/01/08 03:32:01 tb Exp $ */ 1/* $OpenBSD: x509_trs.c,v 1.36 2024/01/10 21:11:37 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 */
@@ -68,8 +68,34 @@ static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);
68static int trust_1oid(X509_TRUST *trust, X509 *x, int flags); 68static int trust_1oid(X509_TRUST *trust, X509 *x, int flags);
69static int trust_compat(X509_TRUST *trust, X509 *x, int flags); 69static int trust_compat(X509_TRUST *trust, X509 *x, int flags);
70 70
71static int obj_trust(int id, X509 *x, int flags); 71static int
72static int (*default_trust)(int id, X509 *x, int flags) = obj_trust; 72obj_trust(int id, X509 *x, int flags)
73{
74 ASN1_OBJECT *obj;
75 int i, nid;
76 X509_CERT_AUX *ax;
77
78 ax = x->aux;
79 if (!ax)
80 return X509_TRUST_UNTRUSTED;
81 if (ax->reject) {
82 for (i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) {
83 obj = sk_ASN1_OBJECT_value(ax->reject, i);
84 nid = OBJ_obj2nid(obj);
85 if (nid == id || nid == NID_anyExtendedKeyUsage)
86 return X509_TRUST_REJECTED;
87 }
88 }
89 if (ax->trust) {
90 for (i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) {
91 obj = sk_ASN1_OBJECT_value(ax->trust, i);
92 nid = OBJ_obj2nid(obj);
93 if (nid == id || nid == NID_anyExtendedKeyUsage)
94 return X509_TRUST_TRUSTED;
95 }
96 }
97 return X509_TRUST_UNTRUSTED;
98}
73 99
74/* WARNING: the following table should be kept in order of trust 100/* WARNING: the following table should be kept in order of trust
75 * and without any gaps so we can just subtract the minimum trust 101 * and without any gaps so we can just subtract the minimum trust
@@ -128,6 +154,8 @@ static X509_TRUST trstandard[] = {
128 154
129#define X509_TRUST_COUNT (sizeof(trstandard) / sizeof(trstandard[0])) 155#define X509_TRUST_COUNT (sizeof(trstandard) / sizeof(trstandard[0]))
130 156
157static int (*default_trust)(int id, X509 *x, int flags) = obj_trust;
158
131int 159int
132(*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int) 160(*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int)
133{ 161{
@@ -278,32 +306,3 @@ trust_compat(X509_TRUST *trust, X509 *x, int flags)
278 else 306 else
279 return X509_TRUST_UNTRUSTED; 307 return X509_TRUST_UNTRUSTED;
280} 308}
281
282static int
283obj_trust(int id, X509 *x, int flags)
284{
285 ASN1_OBJECT *obj;
286 int i, nid;
287 X509_CERT_AUX *ax;
288
289 ax = x->aux;
290 if (!ax)
291 return X509_TRUST_UNTRUSTED;
292 if (ax->reject) {
293 for (i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) {
294 obj = sk_ASN1_OBJECT_value(ax->reject, i);
295 nid = OBJ_obj2nid(obj);
296 if (nid == id || nid == NID_anyExtendedKeyUsage)
297 return X509_TRUST_REJECTED;
298 }
299 }
300 if (ax->trust) {
301 for (i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) {
302 obj = sk_ASN1_OBJECT_value(ax->trust, i);
303 nid = OBJ_obj2nid(obj);
304 if (nid == id || nid == NID_anyExtendedKeyUsage)
305 return X509_TRUST_TRUSTED;
306 }
307 }
308 return X509_TRUST_UNTRUSTED;
309}