diff options
author | beck <> | 2024-07-12 18:15:10 +0000 |
---|---|---|
committer | beck <> | 2024-07-12 18:15:10 +0000 |
commit | d694a3319273a6e59cc84d958713e0342bfc206d (patch) | |
tree | caf914a4a8067bbc8e5b4712e3e4fbf8ffc4c380 /src/lib/libcrypto/x509/x509_trs.c | |
parent | a41114b964f05026c5489e35fb584a9f78de8fce (diff) | |
download | openbsd-d694a3319273a6e59cc84d958713e0342bfc206d.tar.gz openbsd-d694a3319273a6e59cc84d958713e0342bfc206d.tar.bz2 openbsd-d694a3319273a6e59cc84d958713e0342bfc206d.zip |
Fix the horrible and undocumented behaviour of X509_check_trust
Of allowing you to pass in a NID directly, instead of a trust_id,
and have it work, as long as the trust_id's and the NID's did not
overlap.
This screwball behaviour was depended upon by the OCSP code that
called X509_check_trust with the NID, instead of the trust id, so
let's fix that.
We also rename the confusingly named X509_TRUST_DEFAULT to
X509_TRUST_ACCEPT_ALL which makes a lot more sense, and rototill
this to remove the confusingly named static functions.
This will shortly be follwed up by making this function private,
so we have not bothered to fix the amazingly obtuse man page
as it will be taken behind the barn at that time.
ok tb@
Diffstat (limited to 'src/lib/libcrypto/x509/x509_trs.c')
-rw-r--r-- | src/lib/libcrypto/x509/x509_trs.c | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c index 78eb29555e..9ba8194ee0 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.56 2024/07/12 15:53:51 beck Exp $ */ | 1 | /* $OpenBSD: x509_trs.c,v 1.57 2024/07/12 18:15:10 beck 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 | */ |
@@ -67,6 +67,23 @@ | |||
67 | #include "x509_local.h" | 67 | #include "x509_local.h" |
68 | 68 | ||
69 | static int | 69 | static int |
70 | trust_if_self_signed(const X509 *x) | ||
71 | { | ||
72 | /* Extensions already cached in X509_check_trust(). */ | ||
73 | if ((x->ex_flags & EXFLAG_SS) != 0) | ||
74 | return X509_TRUST_TRUSTED; | ||
75 | |||
76 | return X509_TRUST_UNTRUSTED; | ||
77 | } | ||
78 | |||
79 | static int | ||
80 | trust_was_set(const X509 *x) | ||
81 | { | ||
82 | return x->aux != NULL && (x->aux->trust != NULL || | ||
83 | x->aux->reject != NULL); | ||
84 | } | ||
85 | |||
86 | static int | ||
70 | obj_trust(int id, const X509 *x) | 87 | obj_trust(int id, const X509 *x) |
71 | { | 88 | { |
72 | const X509_CERT_AUX *aux; | 89 | const X509_CERT_AUX *aux; |
@@ -94,33 +111,31 @@ obj_trust(int id, const X509 *x) | |||
94 | } | 111 | } |
95 | 112 | ||
96 | static int | 113 | static int |
97 | trust_if_self_signed(const X509 *x) | 114 | nid_from_trust_id(int trust_id) |
98 | { | ||
99 | /* Extensions already cached in X509_check_trust(). */ | ||
100 | if ((x->ex_flags & EXFLAG_SS) != 0) | ||
101 | return X509_TRUST_TRUSTED; | ||
102 | |||
103 | return X509_TRUST_UNTRUSTED; | ||
104 | } | ||
105 | |||
106 | static int | ||
107 | trust_1oidany(int nid, const X509 *x) | ||
108 | { | 115 | { |
109 | /* Inspect the certificate's trust settings if there are any. */ | 116 | OPENSSL_assert(trust_id == 0 || |
110 | if (x->aux != NULL && (x->aux->trust != NULL || x->aux->reject != NULL)) | 117 | (trust_id >= X509_TRUST_MIN && trust_id <= X509_TRUST_MAX)); |
111 | return obj_trust(nid, x); | ||
112 | |||
113 | /* For compatibility we return trusted if the cert is self signed. */ | ||
114 | return trust_if_self_signed(x); | ||
115 | } | ||
116 | 118 | ||
117 | static int | 119 | switch (trust_id) { |
118 | trust_1oid(int nid, const X509 *x) | 120 | case X509_TRUST_COMPAT: |
119 | { | 121 | return NID_undef; |
120 | if (x->aux != NULL) | 122 | case X509_TRUST_SSL_CLIENT: |
121 | return obj_trust(nid, x); | 123 | return NID_client_auth; |
122 | 124 | case X509_TRUST_SSL_SERVER: | |
123 | return X509_TRUST_UNTRUSTED; | 125 | return NID_server_auth; |
126 | case X509_TRUST_EMAIL: | ||
127 | return NID_email_protect; | ||
128 | case X509_TRUST_OBJECT_SIGN: | ||
129 | return NID_code_sign; | ||
130 | case X509_TRUST_OCSP_SIGN: | ||
131 | return NID_OCSP_sign; | ||
132 | case X509_TRUST_OCSP_REQUEST: | ||
133 | return NID_ad_OCSP; | ||
134 | case X509_TRUST_TSA: | ||
135 | return NID_time_stamp; | ||
136 | default: | ||
137 | return NID_undef; | ||
138 | } | ||
124 | } | 139 | } |
125 | 140 | ||
126 | int | 141 | int |
@@ -128,40 +143,36 @@ X509_check_trust(X509 *x, int trust_id, int flags) | |||
128 | { | 143 | { |
129 | int rv; | 144 | int rv; |
130 | 145 | ||
131 | if (trust_id == -1) | ||
132 | return 1; | ||
133 | |||
134 | /* Call early so the trust handlers don't need to modify the certs. */ | 146 | /* Call early so the trust handlers don't need to modify the certs. */ |
135 | if (!x509v3_cache_extensions(x)) | 147 | if (!x509v3_cache_extensions(x)) |
136 | return X509_TRUST_UNTRUSTED; | 148 | return X509_TRUST_UNTRUSTED; |
137 | 149 | ||
150 | /* | ||
151 | * XXX make X509_TRUST_ACCEPT_ALL a real boy once it does not | ||
152 | * need to have the same -1 value as X509_TRUST_DEFAULT | ||
153 | */ | ||
154 | if (trust_id == X509_TRUST_ACCEPT_ALL) | ||
155 | return 1; | ||
156 | |||
138 | switch (trust_id) { | 157 | switch (trust_id) { |
139 | case 0: /* | ||
140 | * The default behaviour: If the certificate has EKU any, or it | ||
141 | * is self-signed, it is trusted. Otherwise it is untrusted. | ||
142 | */ | ||
143 | rv = obj_trust(NID_anyExtendedKeyUsage, x); | ||
144 | if (rv != X509_TRUST_UNTRUSTED) | ||
145 | return rv; | ||
146 | return trust_if_self_signed(x); | ||
147 | case X509_TRUST_COMPAT: | 158 | case X509_TRUST_COMPAT: |
148 | return trust_if_self_signed(x); | 159 | return trust_if_self_signed(x); |
149 | case X509_TRUST_SSL_CLIENT: | ||
150 | return trust_1oidany(NID_client_auth, x); | ||
151 | case X509_TRUST_SSL_SERVER: | ||
152 | return trust_1oidany(NID_server_auth, x); | ||
153 | case X509_TRUST_EMAIL: | 160 | case X509_TRUST_EMAIL: |
154 | return trust_1oidany(NID_email_protect, x); | ||
155 | case X509_TRUST_OBJECT_SIGN: | 161 | case X509_TRUST_OBJECT_SIGN: |
156 | return trust_1oidany(NID_code_sign, x); | 162 | case X509_TRUST_SSL_SERVER: |
163 | case X509_TRUST_SSL_CLIENT: | ||
164 | case X509_TRUST_TSA: | ||
165 | if (trust_was_set(x)) | ||
166 | return obj_trust(nid_from_trust_id(trust_id), x); | ||
167 | return trust_if_self_signed(x); | ||
157 | case X509_TRUST_OCSP_SIGN: | 168 | case X509_TRUST_OCSP_SIGN: |
158 | return trust_1oid(NID_OCSP_sign, x); | ||
159 | case X509_TRUST_OCSP_REQUEST: | 169 | case X509_TRUST_OCSP_REQUEST: |
160 | return trust_1oid(NID_ad_OCSP, x); | 170 | return obj_trust(nid_from_trust_id(trust_id), x); |
161 | case X509_TRUST_TSA: | ||
162 | return trust_1oidany(NID_time_stamp, x); | ||
163 | default: | 171 | default: |
164 | return obj_trust(trust_id, x); | 172 | rv = obj_trust(NID_anyExtendedKeyUsage, x); |
173 | if (rv != X509_TRUST_UNTRUSTED) | ||
174 | return rv; | ||
175 | return trust_if_self_signed(x); | ||
165 | } | 176 | } |
166 | } | 177 | } |
167 | LCRYPTO_ALIAS(X509_check_trust); | 178 | LCRYPTO_ALIAS(X509_check_trust); |