diff options
author | markus <> | 2002-09-05 12:51:50 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 12:51:50 +0000 |
commit | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch) | |
tree | bf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/x509/x509_trs.c | |
parent | 027351f729b9e837200dae6e1520cda6577ab930 (diff) | |
download | openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2 openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/x509/x509_trs.c')
-rw-r--r-- | src/lib/libcrypto/x509/x509_trs.c | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c index 9f7d67952d..17d69ac005 100644 --- a/src/lib/libcrypto/x509/x509_trs.c +++ b/src/lib/libcrypto/x509/x509_trs.c | |||
@@ -61,11 +61,13 @@ | |||
61 | #include <openssl/x509v3.h> | 61 | #include <openssl/x509v3.h> |
62 | 62 | ||
63 | 63 | ||
64 | static int tr_cmp(X509_TRUST **a, X509_TRUST **b); | 64 | static int tr_cmp(const X509_TRUST * const *a, |
65 | const X509_TRUST * const *b); | ||
65 | static void trtable_free(X509_TRUST *p); | 66 | static void trtable_free(X509_TRUST *p); |
66 | 67 | ||
67 | static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags); | 68 | static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags); |
68 | static int trust_any(X509_TRUST *trust, X509 *x, int flags); | 69 | static int trust_1oid(X509_TRUST *trust, X509 *x, int flags); |
70 | static int trust_compat(X509_TRUST *trust, X509 *x, int flags); | ||
69 | 71 | ||
70 | static int obj_trust(int id, X509 *x, int flags); | 72 | static int obj_trust(int id, X509 *x, int flags); |
71 | static int (*default_trust)(int id, X509 *x, int flags) = obj_trust; | 73 | static int (*default_trust)(int id, X509 *x, int flags) = obj_trust; |
@@ -76,10 +78,12 @@ static int (*default_trust)(int id, X509 *x, int flags) = obj_trust; | |||
76 | */ | 78 | */ |
77 | 79 | ||
78 | static X509_TRUST trstandard[] = { | 80 | static X509_TRUST trstandard[] = { |
79 | {X509_TRUST_ANY, 0, trust_any, "Any", 0, NULL}, | 81 | {X509_TRUST_COMPAT, 0, trust_compat, "compatible", 0, NULL}, |
80 | {X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL}, | 82 | {X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL}, |
81 | {X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Client", NID_server_auth, NULL}, | 83 | {X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Server", NID_server_auth, NULL}, |
82 | {X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL}, | 84 | {X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL}, |
85 | {X509_TRUST_OCSP_SIGN, 0, trust_1oid, "OCSP responder", NID_OCSP_sign, NULL}, | ||
86 | {X509_TRUST_OCSP_REQUEST, 0, trust_1oid, "OCSP request", NID_ad_OCSP, NULL} | ||
83 | }; | 87 | }; |
84 | 88 | ||
85 | #define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST)) | 89 | #define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST)) |
@@ -88,17 +92,18 @@ IMPLEMENT_STACK_OF(X509_TRUST) | |||
88 | 92 | ||
89 | static STACK_OF(X509_TRUST) *trtable = NULL; | 93 | static STACK_OF(X509_TRUST) *trtable = NULL; |
90 | 94 | ||
91 | static int tr_cmp(X509_TRUST **a, X509_TRUST **b) | 95 | static int tr_cmp(const X509_TRUST * const *a, |
96 | const X509_TRUST * const *b) | ||
92 | { | 97 | { |
93 | return (*a)->trust - (*b)->trust; | 98 | return (*a)->trust - (*b)->trust; |
94 | } | 99 | } |
95 | 100 | ||
96 | int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int) | 101 | int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int) |
97 | { | 102 | { |
98 | int (*oldtrust)(int , X509 *, int); | 103 | int (*oldtrust)(int , X509 *, int); |
99 | oldtrust = default_trust; | 104 | oldtrust = default_trust; |
100 | default_trust = trust; | 105 | default_trust = trust; |
101 | return oldtrust; | 106 | return oldtrust; |
102 | } | 107 | } |
103 | 108 | ||
104 | 109 | ||
@@ -107,8 +112,8 @@ int X509_check_trust(X509 *x, int id, int flags) | |||
107 | X509_TRUST *pt; | 112 | X509_TRUST *pt; |
108 | int idx; | 113 | int idx; |
109 | if(id == -1) return 1; | 114 | if(id == -1) return 1; |
110 | if(!(idx = X509_TRUST_get_by_id(id))) | 115 | idx = X509_TRUST_get_by_id(id); |
111 | return default_trust(id, x, flags); | 116 | if(idx == -1) return default_trust(id, x, flags); |
112 | pt = X509_TRUST_get0(idx); | 117 | pt = X509_TRUST_get0(idx); |
113 | return pt->check_trust(pt, x, flags); | 118 | return pt->check_trust(pt, x, flags); |
114 | } | 119 | } |
@@ -139,6 +144,16 @@ int X509_TRUST_get_by_id(int id) | |||
139 | return idx + X509_TRUST_COUNT; | 144 | return idx + X509_TRUST_COUNT; |
140 | } | 145 | } |
141 | 146 | ||
147 | int X509_TRUST_set(int *t, int trust) | ||
148 | { | ||
149 | if(X509_TRUST_get_by_id(trust) == -1) { | ||
150 | X509err(X509_F_X509_TRUST_SET, X509_R_INVALID_TRUST); | ||
151 | return 0; | ||
152 | } | ||
153 | *t = trust; | ||
154 | return 1; | ||
155 | } | ||
156 | |||
142 | int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), | 157 | int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), |
143 | char *name, int arg1, void *arg2) | 158 | char *name, int arg1, void *arg2) |
144 | { | 159 | { |
@@ -152,15 +167,15 @@ int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), | |||
152 | idx = X509_TRUST_get_by_id(id); | 167 | idx = X509_TRUST_get_by_id(id); |
153 | /* Need a new entry */ | 168 | /* Need a new entry */ |
154 | if(idx == -1) { | 169 | if(idx == -1) { |
155 | if(!(trtmp = Malloc(sizeof(X509_TRUST)))) { | 170 | if(!(trtmp = OPENSSL_malloc(sizeof(X509_TRUST)))) { |
156 | X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE); | 171 | X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE); |
157 | return 0; | 172 | return 0; |
158 | } | 173 | } |
159 | trtmp->flags = X509_TRUST_DYNAMIC; | 174 | trtmp->flags = X509_TRUST_DYNAMIC; |
160 | } else trtmp = X509_TRUST_get0(idx); | 175 | } else trtmp = X509_TRUST_get0(idx); |
161 | 176 | ||
162 | /* Free existing name if dynamic */ | 177 | /* OPENSSL_free existing name if dynamic */ |
163 | if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) Free(trtmp->name); | 178 | if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name); |
164 | /* dup supplied name */ | 179 | /* dup supplied name */ |
165 | if(!(trtmp->name = BUF_strdup(name))) { | 180 | if(!(trtmp->name = BUF_strdup(name))) { |
166 | X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE); | 181 | X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE); |
@@ -196,8 +211,8 @@ static void trtable_free(X509_TRUST *p) | |||
196 | if (p->flags & X509_TRUST_DYNAMIC) | 211 | if (p->flags & X509_TRUST_DYNAMIC) |
197 | { | 212 | { |
198 | if (p->flags & X509_TRUST_DYNAMIC_NAME) | 213 | if (p->flags & X509_TRUST_DYNAMIC_NAME) |
199 | Free(p->name); | 214 | OPENSSL_free(p->name); |
200 | Free(p); | 215 | OPENSSL_free(p); |
201 | } | 216 | } |
202 | } | 217 | } |
203 | 218 | ||
@@ -226,10 +241,22 @@ int X509_TRUST_get_trust(X509_TRUST *xp) | |||
226 | 241 | ||
227 | static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags) | 242 | static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags) |
228 | { | 243 | { |
229 | if(x->aux) return obj_trust(trust->arg1, x, flags); | 244 | if(x->aux && (x->aux->trust || x->aux->reject)) |
245 | return obj_trust(trust->arg1, x, flags); | ||
230 | /* we don't have any trust settings: for compatibility | 246 | /* we don't have any trust settings: for compatibility |
231 | * we return trusted if it is self signed | 247 | * we return trusted if it is self signed |
232 | */ | 248 | */ |
249 | return trust_compat(trust, x, flags); | ||
250 | } | ||
251 | |||
252 | static int trust_1oid(X509_TRUST *trust, X509 *x, int flags) | ||
253 | { | ||
254 | if(x->aux) return obj_trust(trust->arg1, x, flags); | ||
255 | return X509_TRUST_UNTRUSTED; | ||
256 | } | ||
257 | |||
258 | static int trust_compat(X509_TRUST *trust, X509 *x, int flags) | ||
259 | { | ||
233 | X509_check_purpose(x, -1, 0); | 260 | X509_check_purpose(x, -1, 0); |
234 | if(x->ex_flags & EXFLAG_SS) return X509_TRUST_TRUSTED; | 261 | if(x->ex_flags & EXFLAG_SS) return X509_TRUST_TRUSTED; |
235 | else return X509_TRUST_UNTRUSTED; | 262 | else return X509_TRUST_UNTRUSTED; |
@@ -257,7 +284,3 @@ static int obj_trust(int id, X509 *x, int flags) | |||
257 | return X509_TRUST_UNTRUSTED; | 284 | return X509_TRUST_UNTRUSTED; |
258 | } | 285 | } |
259 | 286 | ||
260 | static int trust_any(X509_TRUST *trust, X509 *x, int flags) | ||
261 | { | ||
262 | return X509_TRUST_TRUSTED; | ||
263 | } | ||