/src/openssl111/ssl/ssl_cert.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved |
4 | | * |
5 | | * Licensed under the OpenSSL license (the "License"). You may not use |
6 | | * this file except in compliance with the License. You can obtain a copy |
7 | | * in the file LICENSE in the source distribution or at |
8 | | * https://www.openssl.org/source/license.html |
9 | | */ |
10 | | |
11 | | #include <stdio.h> |
12 | | #include <sys/types.h> |
13 | | |
14 | | #include "internal/nelem.h" |
15 | | #include "internal/o_dir.h" |
16 | | #include <openssl/bio.h> |
17 | | #include <openssl/pem.h> |
18 | | #include <openssl/x509v3.h> |
19 | | #include <openssl/dh.h> |
20 | | #include <openssl/bn.h> |
21 | | #include <openssl/crypto.h> |
22 | | #include "internal/refcount.h" |
23 | | #include "ssl_local.h" |
24 | | #include "ssl_cert_table.h" |
25 | | #include "internal/thread_once.h" |
26 | | |
27 | | static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, |
28 | | int op, int bits, int nid, void *other, |
29 | | void *ex); |
30 | | |
31 | | static CRYPTO_ONCE ssl_x509_store_ctx_once = CRYPTO_ONCE_STATIC_INIT; |
32 | | static volatile int ssl_x509_store_ctx_idx = -1; |
33 | | |
34 | | DEFINE_RUN_ONCE_STATIC(ssl_x509_store_ctx_init) |
35 | 2 | { |
36 | 2 | ssl_x509_store_ctx_idx = X509_STORE_CTX_get_ex_new_index(0, |
37 | 2 | "SSL for verify callback", |
38 | 2 | NULL, NULL, NULL); |
39 | 2 | return ssl_x509_store_ctx_idx >= 0; |
40 | 2 | } |
41 | | |
42 | | int SSL_get_ex_data_X509_STORE_CTX_idx(void) |
43 | 10.2k | { |
44 | | |
45 | 10.2k | if (!RUN_ONCE(&ssl_x509_store_ctx_once, ssl_x509_store_ctx_init)) |
46 | 0 | return -1; |
47 | 10.2k | return ssl_x509_store_ctx_idx; |
48 | 10.2k | } |
49 | | |
50 | | CERT *ssl_cert_new(void) |
51 | 7.76k | { |
52 | 7.76k | CERT *ret = OPENSSL_zalloc(sizeof(*ret)); |
53 | | |
54 | 7.76k | if (ret == NULL) { |
55 | 0 | SSLerr(SSL_F_SSL_CERT_NEW, ERR_R_MALLOC_FAILURE); |
56 | 0 | return NULL; |
57 | 0 | } |
58 | | |
59 | 7.76k | ret->key = &(ret->pkeys[SSL_PKEY_RSA]); |
60 | 7.76k | ret->references = 1; |
61 | 7.76k | ret->sec_cb = ssl_security_default_callback; |
62 | 7.76k | ret->sec_level = OPENSSL_TLS_SECURITY_LEVEL; |
63 | 7.76k | ret->sec_ex = NULL; |
64 | 7.76k | ret->lock = CRYPTO_THREAD_lock_new(); |
65 | 7.76k | if (ret->lock == NULL) { |
66 | 0 | SSLerr(SSL_F_SSL_CERT_NEW, ERR_R_MALLOC_FAILURE); |
67 | 0 | OPENSSL_free(ret); |
68 | 0 | return NULL; |
69 | 0 | } |
70 | | |
71 | 7.76k | return ret; |
72 | 7.76k | } |
73 | | |
74 | | CERT *ssl_cert_dup(CERT *cert) |
75 | 7.76k | { |
76 | 7.76k | CERT *ret = OPENSSL_zalloc(sizeof(*ret)); |
77 | 7.76k | int i; |
78 | | |
79 | 7.76k | if (ret == NULL) { |
80 | 0 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE); |
81 | 0 | return NULL; |
82 | 0 | } |
83 | | |
84 | 7.76k | ret->references = 1; |
85 | 7.76k | ret->key = &ret->pkeys[cert->key - cert->pkeys]; |
86 | 7.76k | ret->lock = CRYPTO_THREAD_lock_new(); |
87 | 7.76k | if (ret->lock == NULL) { |
88 | 0 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE); |
89 | 0 | OPENSSL_free(ret); |
90 | 0 | return NULL; |
91 | 0 | } |
92 | 7.76k | #ifndef OPENSSL_NO_DH |
93 | 7.76k | if (cert->dh_tmp != NULL) { |
94 | 0 | ret->dh_tmp = cert->dh_tmp; |
95 | 0 | EVP_PKEY_up_ref(ret->dh_tmp); |
96 | 0 | } |
97 | 7.76k | ret->dh_tmp_cb = cert->dh_tmp_cb; |
98 | 7.76k | ret->dh_tmp_auto = cert->dh_tmp_auto; |
99 | 7.76k | #endif |
100 | | |
101 | 77.6k | for (i = 0; i < SSL_PKEY_NUM; i++) { |
102 | 69.8k | CERT_PKEY *cpk = cert->pkeys + i; |
103 | 69.8k | CERT_PKEY *rpk = ret->pkeys + i; |
104 | 69.8k | if (cpk->x509 != NULL) { |
105 | 0 | rpk->x509 = cpk->x509; |
106 | 0 | X509_up_ref(rpk->x509); |
107 | 0 | } |
108 | | |
109 | 69.8k | if (cpk->privatekey != NULL) { |
110 | 0 | rpk->privatekey = cpk->privatekey; |
111 | 0 | EVP_PKEY_up_ref(cpk->privatekey); |
112 | 0 | } |
113 | | |
114 | 69.8k | if (cpk->chain) { |
115 | 0 | rpk->chain = X509_chain_up_ref(cpk->chain); |
116 | 0 | if (!rpk->chain) { |
117 | 0 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE); |
118 | 0 | goto err; |
119 | 0 | } |
120 | 0 | } |
121 | 69.8k | if (cert->pkeys[i].serverinfo != NULL) { |
122 | | /* Just copy everything. */ |
123 | 0 | ret->pkeys[i].serverinfo = |
124 | 0 | OPENSSL_malloc(cert->pkeys[i].serverinfo_length); |
125 | 0 | if (ret->pkeys[i].serverinfo == NULL) { |
126 | 0 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE); |
127 | 0 | goto err; |
128 | 0 | } |
129 | 0 | ret->pkeys[i].serverinfo_length = cert->pkeys[i].serverinfo_length; |
130 | 0 | memcpy(ret->pkeys[i].serverinfo, |
131 | 0 | cert->pkeys[i].serverinfo, cert->pkeys[i].serverinfo_length); |
132 | 0 | } |
133 | 69.8k | } |
134 | | |
135 | | /* Configured sigalgs copied across */ |
136 | 7.76k | if (cert->conf_sigalgs) { |
137 | 0 | ret->conf_sigalgs = OPENSSL_malloc(cert->conf_sigalgslen |
138 | 0 | * sizeof(*cert->conf_sigalgs)); |
139 | 0 | if (ret->conf_sigalgs == NULL) |
140 | 0 | goto err; |
141 | 0 | memcpy(ret->conf_sigalgs, cert->conf_sigalgs, |
142 | 0 | cert->conf_sigalgslen * sizeof(*cert->conf_sigalgs)); |
143 | 0 | ret->conf_sigalgslen = cert->conf_sigalgslen; |
144 | 0 | } else |
145 | 7.76k | ret->conf_sigalgs = NULL; |
146 | | |
147 | 7.76k | if (cert->client_sigalgs) { |
148 | 0 | ret->client_sigalgs = OPENSSL_malloc(cert->client_sigalgslen |
149 | 0 | * sizeof(*cert->client_sigalgs)); |
150 | 0 | if (ret->client_sigalgs == NULL) |
151 | 0 | goto err; |
152 | 0 | memcpy(ret->client_sigalgs, cert->client_sigalgs, |
153 | 0 | cert->client_sigalgslen * sizeof(*cert->client_sigalgs)); |
154 | 0 | ret->client_sigalgslen = cert->client_sigalgslen; |
155 | 0 | } else |
156 | 7.76k | ret->client_sigalgs = NULL; |
157 | | /* Copy any custom client certificate types */ |
158 | 7.76k | if (cert->ctype) { |
159 | 0 | ret->ctype = OPENSSL_memdup(cert->ctype, cert->ctype_len); |
160 | 0 | if (ret->ctype == NULL) |
161 | 0 | goto err; |
162 | 0 | ret->ctype_len = cert->ctype_len; |
163 | 0 | } |
164 | | |
165 | 7.76k | ret->cert_flags = cert->cert_flags; |
166 | | |
167 | 7.76k | ret->cert_cb = cert->cert_cb; |
168 | 7.76k | ret->cert_cb_arg = cert->cert_cb_arg; |
169 | | |
170 | 7.76k | if (cert->verify_store) { |
171 | 0 | X509_STORE_up_ref(cert->verify_store); |
172 | 0 | ret->verify_store = cert->verify_store; |
173 | 0 | } |
174 | | |
175 | 7.76k | if (cert->chain_store) { |
176 | 0 | X509_STORE_up_ref(cert->chain_store); |
177 | 0 | ret->chain_store = cert->chain_store; |
178 | 0 | } |
179 | | |
180 | 7.76k | ret->sec_cb = cert->sec_cb; |
181 | 7.76k | ret->sec_level = cert->sec_level; |
182 | 7.76k | ret->sec_ex = cert->sec_ex; |
183 | | |
184 | 7.76k | if (!custom_exts_copy(&ret->custext, &cert->custext)) |
185 | 0 | goto err; |
186 | 7.76k | #ifndef OPENSSL_NO_PSK |
187 | 7.76k | if (cert->psk_identity_hint) { |
188 | 0 | ret->psk_identity_hint = OPENSSL_strdup(cert->psk_identity_hint); |
189 | 0 | if (ret->psk_identity_hint == NULL) |
190 | 0 | goto err; |
191 | 0 | } |
192 | 7.76k | #endif |
193 | 7.76k | return ret; |
194 | | |
195 | 0 | err: |
196 | 0 | ssl_cert_free(ret); |
197 | |
|
198 | 0 | return NULL; |
199 | 7.76k | } |
200 | | |
201 | | /* Free up and clear all certificates and chains */ |
202 | | |
203 | | void ssl_cert_clear_certs(CERT *c) |
204 | 15.5k | { |
205 | 15.5k | int i; |
206 | 15.5k | if (c == NULL) |
207 | 0 | return; |
208 | 155k | for (i = 0; i < SSL_PKEY_NUM; i++) { |
209 | 139k | CERT_PKEY *cpk = c->pkeys + i; |
210 | 139k | X509_free(cpk->x509); |
211 | 139k | cpk->x509 = NULL; |
212 | 139k | EVP_PKEY_free(cpk->privatekey); |
213 | 139k | cpk->privatekey = NULL; |
214 | 139k | sk_X509_pop_free(cpk->chain, X509_free); |
215 | 139k | cpk->chain = NULL; |
216 | 139k | OPENSSL_free(cpk->serverinfo); |
217 | 139k | cpk->serverinfo = NULL; |
218 | 139k | cpk->serverinfo_length = 0; |
219 | 139k | } |
220 | 15.5k | } |
221 | | |
222 | | void ssl_cert_free(CERT *c) |
223 | 15.5k | { |
224 | 15.5k | int i; |
225 | | |
226 | 15.5k | if (c == NULL) |
227 | 0 | return; |
228 | 15.5k | CRYPTO_DOWN_REF(&c->references, &i, c->lock); |
229 | 15.5k | REF_PRINT_COUNT("CERT", c); |
230 | 15.5k | if (i > 0) |
231 | 0 | return; |
232 | 15.5k | REF_ASSERT_ISNT(i < 0); |
233 | | |
234 | 15.5k | #ifndef OPENSSL_NO_DH |
235 | 15.5k | EVP_PKEY_free(c->dh_tmp); |
236 | 15.5k | #endif |
237 | | |
238 | 15.5k | ssl_cert_clear_certs(c); |
239 | 15.5k | OPENSSL_free(c->conf_sigalgs); |
240 | 15.5k | OPENSSL_free(c->client_sigalgs); |
241 | 15.5k | OPENSSL_free(c->ctype); |
242 | 15.5k | X509_STORE_free(c->verify_store); |
243 | 15.5k | X509_STORE_free(c->chain_store); |
244 | 15.5k | custom_exts_free(&c->custext); |
245 | 15.5k | #ifndef OPENSSL_NO_PSK |
246 | 15.5k | OPENSSL_free(c->psk_identity_hint); |
247 | 15.5k | #endif |
248 | 15.5k | CRYPTO_THREAD_lock_free(c->lock); |
249 | 15.5k | OPENSSL_free(c); |
250 | 15.5k | } |
251 | | |
252 | | int ssl_cert_set0_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain) |
253 | 0 | { |
254 | 0 | int i, r; |
255 | 0 | CERT_PKEY *cpk = s ? s->cert->key : ctx->cert->key; |
256 | 0 | if (!cpk) |
257 | 0 | return 0; |
258 | 0 | for (i = 0; i < sk_X509_num(chain); i++) { |
259 | 0 | r = ssl_security_cert(s, ctx, sk_X509_value(chain, i), 0, 0); |
260 | 0 | if (r != 1) { |
261 | 0 | SSLerr(SSL_F_SSL_CERT_SET0_CHAIN, r); |
262 | 0 | return 0; |
263 | 0 | } |
264 | 0 | } |
265 | 0 | sk_X509_pop_free(cpk->chain, X509_free); |
266 | 0 | cpk->chain = chain; |
267 | 0 | return 1; |
268 | 0 | } |
269 | | |
270 | | int ssl_cert_set1_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain) |
271 | 0 | { |
272 | 0 | STACK_OF(X509) *dchain; |
273 | 0 | if (!chain) |
274 | 0 | return ssl_cert_set0_chain(s, ctx, NULL); |
275 | 0 | dchain = X509_chain_up_ref(chain); |
276 | 0 | if (!dchain) |
277 | 0 | return 0; |
278 | 0 | if (!ssl_cert_set0_chain(s, ctx, dchain)) { |
279 | 0 | sk_X509_pop_free(dchain, X509_free); |
280 | 0 | return 0; |
281 | 0 | } |
282 | 0 | return 1; |
283 | 0 | } |
284 | | |
285 | | int ssl_cert_add0_chain_cert(SSL *s, SSL_CTX *ctx, X509 *x) |
286 | 0 | { |
287 | 0 | int r; |
288 | 0 | CERT_PKEY *cpk = s ? s->cert->key : ctx->cert->key; |
289 | 0 | if (!cpk) |
290 | 0 | return 0; |
291 | 0 | r = ssl_security_cert(s, ctx, x, 0, 0); |
292 | 0 | if (r != 1) { |
293 | 0 | SSLerr(SSL_F_SSL_CERT_ADD0_CHAIN_CERT, r); |
294 | 0 | return 0; |
295 | 0 | } |
296 | 0 | if (!cpk->chain) |
297 | 0 | cpk->chain = sk_X509_new_null(); |
298 | 0 | if (!cpk->chain || !sk_X509_push(cpk->chain, x)) |
299 | 0 | return 0; |
300 | 0 | return 1; |
301 | 0 | } |
302 | | |
303 | | int ssl_cert_add1_chain_cert(SSL *s, SSL_CTX *ctx, X509 *x) |
304 | 0 | { |
305 | 0 | if (!ssl_cert_add0_chain_cert(s, ctx, x)) |
306 | 0 | return 0; |
307 | 0 | X509_up_ref(x); |
308 | 0 | return 1; |
309 | 0 | } |
310 | | |
311 | | int ssl_cert_select_current(CERT *c, X509 *x) |
312 | 0 | { |
313 | 0 | int i; |
314 | 0 | if (x == NULL) |
315 | 0 | return 0; |
316 | 0 | for (i = 0; i < SSL_PKEY_NUM; i++) { |
317 | 0 | CERT_PKEY *cpk = c->pkeys + i; |
318 | 0 | if (cpk->x509 == x && cpk->privatekey) { |
319 | 0 | c->key = cpk; |
320 | 0 | return 1; |
321 | 0 | } |
322 | 0 | } |
323 | | |
324 | 0 | for (i = 0; i < SSL_PKEY_NUM; i++) { |
325 | 0 | CERT_PKEY *cpk = c->pkeys + i; |
326 | 0 | if (cpk->privatekey && cpk->x509 && !X509_cmp(cpk->x509, x)) { |
327 | 0 | c->key = cpk; |
328 | 0 | return 1; |
329 | 0 | } |
330 | 0 | } |
331 | 0 | return 0; |
332 | 0 | } |
333 | | |
334 | | int ssl_cert_set_current(CERT *c, long op) |
335 | 0 | { |
336 | 0 | int i, idx; |
337 | 0 | if (!c) |
338 | 0 | return 0; |
339 | 0 | if (op == SSL_CERT_SET_FIRST) |
340 | 0 | idx = 0; |
341 | 0 | else if (op == SSL_CERT_SET_NEXT) { |
342 | 0 | idx = (int)(c->key - c->pkeys + 1); |
343 | 0 | if (idx >= SSL_PKEY_NUM) |
344 | 0 | return 0; |
345 | 0 | } else |
346 | 0 | return 0; |
347 | 0 | for (i = idx; i < SSL_PKEY_NUM; i++) { |
348 | 0 | CERT_PKEY *cpk = c->pkeys + i; |
349 | 0 | if (cpk->x509 && cpk->privatekey) { |
350 | 0 | c->key = cpk; |
351 | 0 | return 1; |
352 | 0 | } |
353 | 0 | } |
354 | 0 | return 0; |
355 | 0 | } |
356 | | |
357 | | void ssl_cert_set_cert_cb(CERT *c, int (*cb) (SSL *ssl, void *arg), void *arg) |
358 | 0 | { |
359 | 0 | c->cert_cb = cb; |
360 | 0 | c->cert_cb_arg = arg; |
361 | 0 | } |
362 | | |
363 | | int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk) |
364 | 2.51k | { |
365 | 2.51k | X509 *x; |
366 | 2.51k | int i = 0; |
367 | 2.51k | X509_STORE *verify_store; |
368 | 2.51k | X509_STORE_CTX *ctx = NULL; |
369 | 2.51k | X509_VERIFY_PARAM *param; |
370 | | |
371 | 2.51k | if ((sk == NULL) || (sk_X509_num(sk) == 0)) |
372 | 0 | return 0; |
373 | | |
374 | 2.51k | if (s->cert->verify_store) |
375 | 0 | verify_store = s->cert->verify_store; |
376 | 2.51k | else |
377 | 2.51k | verify_store = s->ctx->cert_store; |
378 | | |
379 | 2.51k | ctx = X509_STORE_CTX_new(); |
380 | 2.51k | if (ctx == NULL) { |
381 | 0 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN, ERR_R_MALLOC_FAILURE); |
382 | 0 | return 0; |
383 | 0 | } |
384 | | |
385 | 2.51k | x = sk_X509_value(sk, 0); |
386 | 2.51k | if (!X509_STORE_CTX_init(ctx, verify_store, x, sk)) { |
387 | 0 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN, ERR_R_X509_LIB); |
388 | 0 | goto end; |
389 | 0 | } |
390 | 2.51k | param = X509_STORE_CTX_get0_param(ctx); |
391 | | /* |
392 | | * XXX: Separate @AUTHSECLEVEL and @TLSSECLEVEL would be useful at some |
393 | | * point, for now a single @SECLEVEL sets the same policy for TLS crypto |
394 | | * and PKI authentication. |
395 | | */ |
396 | 2.51k | X509_VERIFY_PARAM_set_auth_level(param, SSL_get_security_level(s)); |
397 | | |
398 | | /* Set suite B flags if needed */ |
399 | 2.51k | X509_STORE_CTX_set_flags(ctx, tls1_suiteb(s)); |
400 | 2.51k | if (!X509_STORE_CTX_set_ex_data |
401 | 2.51k | (ctx, SSL_get_ex_data_X509_STORE_CTX_idx(), s)) { |
402 | 0 | goto end; |
403 | 0 | } |
404 | | |
405 | | /* Verify via DANE if enabled */ |
406 | 2.51k | if (DANETLS_ENABLED(&s->dane)) |
407 | 0 | X509_STORE_CTX_set0_dane(ctx, &s->dane); |
408 | | |
409 | | /* |
410 | | * We need to inherit the verify parameters. These can be determined by |
411 | | * the context: if its a server it will verify SSL client certificates or |
412 | | * vice versa. |
413 | | */ |
414 | | |
415 | 2.51k | X509_STORE_CTX_set_default(ctx, s->server ? "ssl_client" : "ssl_server"); |
416 | | /* |
417 | | * Anything non-default in "s->param" should overwrite anything in the ctx. |
418 | | */ |
419 | 2.51k | X509_VERIFY_PARAM_set1(param, s->param); |
420 | | |
421 | 2.51k | if (s->verify_callback) |
422 | 0 | X509_STORE_CTX_set_verify_cb(ctx, s->verify_callback); |
423 | | |
424 | 2.51k | if (s->ctx->app_verify_callback != NULL) |
425 | 0 | i = s->ctx->app_verify_callback(ctx, s->ctx->app_verify_arg); |
426 | 2.51k | else |
427 | 2.51k | i = X509_verify_cert(ctx); |
428 | | |
429 | 2.51k | s->verify_result = X509_STORE_CTX_get_error(ctx); |
430 | 2.51k | sk_X509_pop_free(s->verified_chain, X509_free); |
431 | 2.51k | s->verified_chain = NULL; |
432 | 2.51k | if (X509_STORE_CTX_get0_chain(ctx) != NULL) { |
433 | 2.51k | s->verified_chain = X509_STORE_CTX_get1_chain(ctx); |
434 | 2.51k | if (s->verified_chain == NULL) { |
435 | 0 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN, ERR_R_MALLOC_FAILURE); |
436 | 0 | i = 0; |
437 | 0 | } |
438 | 2.51k | } |
439 | | |
440 | | /* Move peername from the store context params to the SSL handle's */ |
441 | 2.51k | X509_VERIFY_PARAM_move_peername(s->param, param); |
442 | | |
443 | 2.51k | end: |
444 | 2.51k | X509_STORE_CTX_free(ctx); |
445 | 2.51k | return i; |
446 | 2.51k | } |
447 | | |
448 | | static void set0_CA_list(STACK_OF(X509_NAME) **ca_list, |
449 | | STACK_OF(X509_NAME) *name_list) |
450 | 0 | { |
451 | 0 | sk_X509_NAME_pop_free(*ca_list, X509_NAME_free); |
452 | 0 | *ca_list = name_list; |
453 | 0 | } |
454 | | |
455 | | STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk) |
456 | 0 | { |
457 | 0 | int i; |
458 | 0 | const int num = sk_X509_NAME_num(sk); |
459 | 0 | STACK_OF(X509_NAME) *ret; |
460 | 0 | X509_NAME *name; |
461 | |
|
462 | 0 | ret = sk_X509_NAME_new_reserve(NULL, num); |
463 | 0 | if (ret == NULL) { |
464 | 0 | SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE); |
465 | 0 | return NULL; |
466 | 0 | } |
467 | 0 | for (i = 0; i < num; i++) { |
468 | 0 | name = X509_NAME_dup(sk_X509_NAME_value(sk, i)); |
469 | 0 | if (name == NULL) { |
470 | 0 | SSLerr(SSL_F_SSL_DUP_CA_LIST, ERR_R_MALLOC_FAILURE); |
471 | 0 | sk_X509_NAME_pop_free(ret, X509_NAME_free); |
472 | 0 | return NULL; |
473 | 0 | } |
474 | 0 | sk_X509_NAME_push(ret, name); /* Cannot fail after reserve call */ |
475 | 0 | } |
476 | 0 | return ret; |
477 | 0 | } |
478 | | |
479 | | void SSL_set0_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list) |
480 | 0 | { |
481 | 0 | set0_CA_list(&s->ca_names, name_list); |
482 | 0 | } |
483 | | |
484 | | void SSL_CTX_set0_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list) |
485 | 0 | { |
486 | 0 | set0_CA_list(&ctx->ca_names, name_list); |
487 | 0 | } |
488 | | |
489 | | const STACK_OF(X509_NAME) *SSL_CTX_get0_CA_list(const SSL_CTX *ctx) |
490 | 0 | { |
491 | 0 | return ctx->ca_names; |
492 | 0 | } |
493 | | |
494 | | const STACK_OF(X509_NAME) *SSL_get0_CA_list(const SSL *s) |
495 | 7.82k | { |
496 | 7.82k | return s->ca_names != NULL ? s->ca_names : s->ctx->ca_names; |
497 | 7.82k | } |
498 | | |
499 | | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list) |
500 | 0 | { |
501 | 0 | set0_CA_list(&ctx->client_ca_names, name_list); |
502 | 0 | } |
503 | | |
504 | | STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx) |
505 | 0 | { |
506 | 0 | return ctx->client_ca_names; |
507 | 0 | } |
508 | | |
509 | | void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list) |
510 | 0 | { |
511 | 0 | set0_CA_list(&s->client_ca_names, name_list); |
512 | 0 | } |
513 | | |
514 | | const STACK_OF(X509_NAME) *SSL_get0_peer_CA_list(const SSL *s) |
515 | 0 | { |
516 | 0 | return s->s3 != NULL ? s->s3->tmp.peer_ca_names : NULL; |
517 | 0 | } |
518 | | |
519 | | STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s) |
520 | 0 | { |
521 | 0 | if (!s->server) |
522 | 0 | return s->s3 != NULL ? s->s3->tmp.peer_ca_names : NULL; |
523 | 0 | return s->client_ca_names != NULL ? s->client_ca_names |
524 | 0 | : s->ctx->client_ca_names; |
525 | 0 | } |
526 | | |
527 | | static int add_ca_name(STACK_OF(X509_NAME) **sk, const X509 *x) |
528 | 0 | { |
529 | 0 | X509_NAME *name; |
530 | |
|
531 | 0 | if (x == NULL) |
532 | 0 | return 0; |
533 | 0 | if (*sk == NULL && ((*sk = sk_X509_NAME_new_null()) == NULL)) |
534 | 0 | return 0; |
535 | | |
536 | 0 | if ((name = X509_NAME_dup(X509_get_subject_name(x))) == NULL) |
537 | 0 | return 0; |
538 | | |
539 | 0 | if (!sk_X509_NAME_push(*sk, name)) { |
540 | 0 | X509_NAME_free(name); |
541 | 0 | return 0; |
542 | 0 | } |
543 | 0 | return 1; |
544 | 0 | } |
545 | | |
546 | | int SSL_add1_to_CA_list(SSL *ssl, const X509 *x) |
547 | 0 | { |
548 | 0 | return add_ca_name(&ssl->ca_names, x); |
549 | 0 | } |
550 | | |
551 | | int SSL_CTX_add1_to_CA_list(SSL_CTX *ctx, const X509 *x) |
552 | 0 | { |
553 | 0 | return add_ca_name(&ctx->ca_names, x); |
554 | 0 | } |
555 | | |
556 | | /* |
557 | | * The following two are older names are to be replaced with |
558 | | * SSL(_CTX)_add1_to_CA_list |
559 | | */ |
560 | | int SSL_add_client_CA(SSL *ssl, X509 *x) |
561 | 0 | { |
562 | 0 | return add_ca_name(&ssl->client_ca_names, x); |
563 | 0 | } |
564 | | |
565 | | int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x) |
566 | 0 | { |
567 | 0 | return add_ca_name(&ctx->client_ca_names, x); |
568 | 0 | } |
569 | | |
570 | | static int xname_cmp(const X509_NAME *a, const X509_NAME *b) |
571 | 0 | { |
572 | 0 | unsigned char *abuf = NULL, *bbuf = NULL; |
573 | 0 | int alen, blen, ret; |
574 | | |
575 | | /* X509_NAME_cmp() itself casts away constness in this way, so |
576 | | * assume it's safe: |
577 | | */ |
578 | 0 | alen = i2d_X509_NAME((X509_NAME *)a, &abuf); |
579 | 0 | blen = i2d_X509_NAME((X509_NAME *)b, &bbuf); |
580 | |
|
581 | 0 | if (alen < 0 || blen < 0) |
582 | 0 | ret = -2; |
583 | 0 | else if (alen != blen) |
584 | 0 | ret = alen - blen; |
585 | 0 | else /* alen == blen */ |
586 | 0 | ret = memcmp(abuf, bbuf, alen); |
587 | |
|
588 | 0 | OPENSSL_free(abuf); |
589 | 0 | OPENSSL_free(bbuf); |
590 | |
|
591 | 0 | return ret; |
592 | 0 | } |
593 | | |
594 | | static int xname_sk_cmp(const X509_NAME *const *a, const X509_NAME *const *b) |
595 | 0 | { |
596 | 0 | return xname_cmp(*a, *b); |
597 | 0 | } |
598 | | |
599 | | static unsigned long xname_hash(const X509_NAME *a) |
600 | 0 | { |
601 | 0 | return X509_NAME_hash((X509_NAME *)a); |
602 | 0 | } |
603 | | |
604 | | STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) |
605 | 0 | { |
606 | 0 | BIO *in = BIO_new(BIO_s_file()); |
607 | 0 | X509 *x = NULL; |
608 | 0 | X509_NAME *xn = NULL; |
609 | 0 | STACK_OF(X509_NAME) *ret = NULL; |
610 | 0 | LHASH_OF(X509_NAME) *name_hash = lh_X509_NAME_new(xname_hash, xname_cmp); |
611 | |
|
612 | 0 | if ((name_hash == NULL) || (in == NULL)) { |
613 | 0 | SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE, ERR_R_MALLOC_FAILURE); |
614 | 0 | goto err; |
615 | 0 | } |
616 | | |
617 | 0 | if (!BIO_read_filename(in, file)) |
618 | 0 | goto err; |
619 | | |
620 | 0 | for (;;) { |
621 | 0 | if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL) |
622 | 0 | break; |
623 | 0 | if (ret == NULL) { |
624 | 0 | ret = sk_X509_NAME_new_null(); |
625 | 0 | if (ret == NULL) { |
626 | 0 | SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE, ERR_R_MALLOC_FAILURE); |
627 | 0 | goto err; |
628 | 0 | } |
629 | 0 | } |
630 | 0 | if ((xn = X509_get_subject_name(x)) == NULL) |
631 | 0 | goto err; |
632 | | /* check for duplicates */ |
633 | 0 | xn = X509_NAME_dup(xn); |
634 | 0 | if (xn == NULL) |
635 | 0 | goto err; |
636 | 0 | if (lh_X509_NAME_retrieve(name_hash, xn) != NULL) { |
637 | | /* Duplicate. */ |
638 | 0 | X509_NAME_free(xn); |
639 | 0 | xn = NULL; |
640 | 0 | } else { |
641 | 0 | lh_X509_NAME_insert(name_hash, xn); |
642 | 0 | if (!sk_X509_NAME_push(ret, xn)) |
643 | 0 | goto err; |
644 | 0 | } |
645 | 0 | } |
646 | 0 | goto done; |
647 | | |
648 | 0 | err: |
649 | 0 | X509_NAME_free(xn); |
650 | 0 | sk_X509_NAME_pop_free(ret, X509_NAME_free); |
651 | 0 | ret = NULL; |
652 | 0 | done: |
653 | 0 | BIO_free(in); |
654 | 0 | X509_free(x); |
655 | 0 | lh_X509_NAME_free(name_hash); |
656 | 0 | if (ret != NULL) |
657 | 0 | ERR_clear_error(); |
658 | 0 | return ret; |
659 | 0 | } |
660 | | |
661 | | int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, |
662 | | const char *file) |
663 | 0 | { |
664 | 0 | BIO *in; |
665 | 0 | X509 *x = NULL; |
666 | 0 | X509_NAME *xn = NULL; |
667 | 0 | int ret = 1; |
668 | 0 | int (*oldcmp) (const X509_NAME *const *a, const X509_NAME *const *b); |
669 | |
|
670 | 0 | oldcmp = sk_X509_NAME_set_cmp_func(stack, xname_sk_cmp); |
671 | |
|
672 | 0 | in = BIO_new(BIO_s_file()); |
673 | |
|
674 | 0 | if (in == NULL) { |
675 | 0 | SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK, ERR_R_MALLOC_FAILURE); |
676 | 0 | goto err; |
677 | 0 | } |
678 | | |
679 | 0 | if (!BIO_read_filename(in, file)) |
680 | 0 | goto err; |
681 | | |
682 | 0 | for (;;) { |
683 | 0 | if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL) |
684 | 0 | break; |
685 | 0 | if ((xn = X509_get_subject_name(x)) == NULL) |
686 | 0 | goto err; |
687 | 0 | xn = X509_NAME_dup(xn); |
688 | 0 | if (xn == NULL) |
689 | 0 | goto err; |
690 | 0 | if (sk_X509_NAME_find(stack, xn) >= 0) { |
691 | | /* Duplicate. */ |
692 | 0 | X509_NAME_free(xn); |
693 | 0 | } else if (!sk_X509_NAME_push(stack, xn)) { |
694 | 0 | X509_NAME_free(xn); |
695 | 0 | goto err; |
696 | 0 | } |
697 | 0 | } |
698 | | |
699 | 0 | ERR_clear_error(); |
700 | 0 | goto done; |
701 | | |
702 | 0 | err: |
703 | 0 | ret = 0; |
704 | 0 | done: |
705 | 0 | BIO_free(in); |
706 | 0 | X509_free(x); |
707 | 0 | (void)sk_X509_NAME_set_cmp_func(stack, oldcmp); |
708 | 0 | return ret; |
709 | 0 | } |
710 | | |
711 | | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, |
712 | | const char *dir) |
713 | 0 | { |
714 | 0 | OPENSSL_DIR_CTX *d = NULL; |
715 | 0 | const char *filename; |
716 | 0 | int ret = 0; |
717 | | |
718 | | /* Note that a side effect is that the CAs will be sorted by name */ |
719 | |
|
720 | 0 | while ((filename = OPENSSL_DIR_read(&d, dir))) { |
721 | 0 | char buf[1024]; |
722 | 0 | int r; |
723 | |
|
724 | 0 | if (strlen(dir) + strlen(filename) + 2 > sizeof(buf)) { |
725 | 0 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, |
726 | 0 | SSL_R_PATH_TOO_LONG); |
727 | 0 | goto err; |
728 | 0 | } |
729 | | #ifdef OPENSSL_SYS_VMS |
730 | | r = BIO_snprintf(buf, sizeof(buf), "%s%s", dir, filename); |
731 | | #else |
732 | 0 | r = BIO_snprintf(buf, sizeof(buf), "%s/%s", dir, filename); |
733 | 0 | #endif |
734 | 0 | if (r <= 0 || r >= (int)sizeof(buf)) |
735 | 0 | goto err; |
736 | 0 | if (!SSL_add_file_cert_subjects_to_stack(stack, buf)) |
737 | 0 | goto err; |
738 | 0 | } |
739 | | |
740 | 0 | if (errno) { |
741 | 0 | SYSerr(SYS_F_OPENDIR, get_last_sys_error()); |
742 | 0 | ERR_add_error_data(3, "OPENSSL_DIR_read(&ctx, '", dir, "')"); |
743 | 0 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); |
744 | 0 | goto err; |
745 | 0 | } |
746 | | |
747 | 0 | ret = 1; |
748 | |
|
749 | 0 | err: |
750 | 0 | if (d) |
751 | 0 | OPENSSL_DIR_end(&d); |
752 | |
|
753 | 0 | return ret; |
754 | 0 | } |
755 | | |
756 | | /* Build a certificate chain for current certificate */ |
757 | | int ssl_build_cert_chain(SSL *s, SSL_CTX *ctx, int flags) |
758 | 0 | { |
759 | 0 | CERT *c = s ? s->cert : ctx->cert; |
760 | 0 | CERT_PKEY *cpk = c->key; |
761 | 0 | X509_STORE *chain_store = NULL; |
762 | 0 | X509_STORE_CTX *xs_ctx = NULL; |
763 | 0 | STACK_OF(X509) *chain = NULL, *untrusted = NULL; |
764 | 0 | X509 *x; |
765 | 0 | int i, rv = 0; |
766 | |
|
767 | 0 | if (!cpk->x509) { |
768 | 0 | SSLerr(SSL_F_SSL_BUILD_CERT_CHAIN, SSL_R_NO_CERTIFICATE_SET); |
769 | 0 | goto err; |
770 | 0 | } |
771 | | /* Rearranging and check the chain: add everything to a store */ |
772 | 0 | if (flags & SSL_BUILD_CHAIN_FLAG_CHECK) { |
773 | 0 | chain_store = X509_STORE_new(); |
774 | 0 | if (chain_store == NULL) |
775 | 0 | goto err; |
776 | 0 | for (i = 0; i < sk_X509_num(cpk->chain); i++) { |
777 | 0 | x = sk_X509_value(cpk->chain, i); |
778 | 0 | if (!X509_STORE_add_cert(chain_store, x)) |
779 | 0 | goto err; |
780 | 0 | } |
781 | | /* Add EE cert too: it might be self signed */ |
782 | 0 | if (!X509_STORE_add_cert(chain_store, cpk->x509)) |
783 | 0 | goto err; |
784 | 0 | } else { |
785 | 0 | if (c->chain_store) |
786 | 0 | chain_store = c->chain_store; |
787 | 0 | else if (s) |
788 | 0 | chain_store = s->ctx->cert_store; |
789 | 0 | else |
790 | 0 | chain_store = ctx->cert_store; |
791 | |
|
792 | 0 | if (flags & SSL_BUILD_CHAIN_FLAG_UNTRUSTED) |
793 | 0 | untrusted = cpk->chain; |
794 | 0 | } |
795 | | |
796 | 0 | xs_ctx = X509_STORE_CTX_new(); |
797 | 0 | if (xs_ctx == NULL) { |
798 | 0 | SSLerr(SSL_F_SSL_BUILD_CERT_CHAIN, ERR_R_MALLOC_FAILURE); |
799 | 0 | goto err; |
800 | 0 | } |
801 | 0 | if (!X509_STORE_CTX_init(xs_ctx, chain_store, cpk->x509, untrusted)) { |
802 | 0 | SSLerr(SSL_F_SSL_BUILD_CERT_CHAIN, ERR_R_X509_LIB); |
803 | 0 | goto err; |
804 | 0 | } |
805 | | /* Set suite B flags if needed */ |
806 | 0 | X509_STORE_CTX_set_flags(xs_ctx, |
807 | 0 | c->cert_flags & SSL_CERT_FLAG_SUITEB_128_LOS); |
808 | |
|
809 | 0 | i = X509_verify_cert(xs_ctx); |
810 | 0 | if (i <= 0 && flags & SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR) { |
811 | 0 | if (flags & SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR) |
812 | 0 | ERR_clear_error(); |
813 | 0 | i = 1; |
814 | 0 | rv = 2; |
815 | 0 | } |
816 | 0 | if (i > 0) |
817 | 0 | chain = X509_STORE_CTX_get1_chain(xs_ctx); |
818 | 0 | if (i <= 0) { |
819 | 0 | SSLerr(SSL_F_SSL_BUILD_CERT_CHAIN, SSL_R_CERTIFICATE_VERIFY_FAILED); |
820 | 0 | i = X509_STORE_CTX_get_error(xs_ctx); |
821 | 0 | ERR_add_error_data(2, "Verify error:", |
822 | 0 | X509_verify_cert_error_string(i)); |
823 | |
|
824 | 0 | goto err; |
825 | 0 | } |
826 | | /* Remove EE certificate from chain */ |
827 | 0 | x = sk_X509_shift(chain); |
828 | 0 | X509_free(x); |
829 | 0 | if (flags & SSL_BUILD_CHAIN_FLAG_NO_ROOT) { |
830 | 0 | if (sk_X509_num(chain) > 0) { |
831 | | /* See if last cert is self signed */ |
832 | 0 | x = sk_X509_value(chain, sk_X509_num(chain) - 1); |
833 | 0 | if (X509_get_extension_flags(x) & EXFLAG_SS) { |
834 | 0 | x = sk_X509_pop(chain); |
835 | 0 | X509_free(x); |
836 | 0 | } |
837 | 0 | } |
838 | 0 | } |
839 | | /* |
840 | | * Check security level of all CA certificates: EE will have been checked |
841 | | * already. |
842 | | */ |
843 | 0 | for (i = 0; i < sk_X509_num(chain); i++) { |
844 | 0 | x = sk_X509_value(chain, i); |
845 | 0 | rv = ssl_security_cert(s, ctx, x, 0, 0); |
846 | 0 | if (rv != 1) { |
847 | 0 | SSLerr(SSL_F_SSL_BUILD_CERT_CHAIN, rv); |
848 | 0 | sk_X509_pop_free(chain, X509_free); |
849 | 0 | rv = 0; |
850 | 0 | goto err; |
851 | 0 | } |
852 | 0 | } |
853 | 0 | sk_X509_pop_free(cpk->chain, X509_free); |
854 | 0 | cpk->chain = chain; |
855 | 0 | if (rv == 0) |
856 | 0 | rv = 1; |
857 | 0 | err: |
858 | 0 | if (flags & SSL_BUILD_CHAIN_FLAG_CHECK) |
859 | 0 | X509_STORE_free(chain_store); |
860 | 0 | X509_STORE_CTX_free(xs_ctx); |
861 | |
|
862 | 0 | return rv; |
863 | 0 | } |
864 | | |
865 | | int ssl_cert_set_cert_store(CERT *c, X509_STORE *store, int chain, int ref) |
866 | 0 | { |
867 | 0 | X509_STORE **pstore; |
868 | 0 | if (chain) |
869 | 0 | pstore = &c->chain_store; |
870 | 0 | else |
871 | 0 | pstore = &c->verify_store; |
872 | 0 | X509_STORE_free(*pstore); |
873 | 0 | *pstore = store; |
874 | 0 | if (ref && store) |
875 | 0 | X509_STORE_up_ref(store); |
876 | 0 | return 1; |
877 | 0 | } |
878 | | |
879 | | int ssl_cert_get_cert_store(CERT *c, X509_STORE **pstore, int chain) |
880 | 0 | { |
881 | 0 | *pstore = (chain ? c->chain_store : c->verify_store); |
882 | 0 | return 1; |
883 | 0 | } |
884 | | |
885 | | int ssl_get_security_level_bits(const SSL *s, const SSL_CTX *ctx, int *levelp) |
886 | 3.19M | { |
887 | 3.19M | int level; |
888 | 3.19M | static const int minbits_table[5 + 1] = { 0, 80, 112, 128, 192, 256 }; |
889 | | |
890 | 3.19M | if (ctx != NULL) |
891 | 0 | level = SSL_CTX_get_security_level(ctx); |
892 | 3.19M | else |
893 | 3.19M | level = SSL_get_security_level(s); |
894 | | |
895 | 3.19M | if (level > 5) |
896 | 0 | level = 5; |
897 | 3.19M | else if (level < 0) |
898 | 0 | level = 0; |
899 | | |
900 | 3.19M | if (levelp != NULL) |
901 | 3.19M | *levelp = level; |
902 | | |
903 | 3.19M | return minbits_table[level]; |
904 | 3.19M | } |
905 | | |
906 | | static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, |
907 | | int op, int bits, int nid, void *other, |
908 | | void *ex) |
909 | 3.19M | { |
910 | 3.19M | int level, minbits, pfs_mask; |
911 | | |
912 | 3.19M | minbits = ssl_get_security_level_bits(s, ctx, &level); |
913 | | |
914 | 3.19M | if (level == 0) { |
915 | | /* |
916 | | * No EDH keys weaker than 1024-bits even at level 0, otherwise, |
917 | | * anything goes. |
918 | | */ |
919 | 3.19M | if (op == SSL_SECOP_TMP_DH && bits < 80) |
920 | 169 | return 0; |
921 | 3.19M | return 1; |
922 | 3.19M | } |
923 | 0 | switch (op) { |
924 | 0 | case SSL_SECOP_CIPHER_SUPPORTED: |
925 | 0 | case SSL_SECOP_CIPHER_SHARED: |
926 | 0 | case SSL_SECOP_CIPHER_CHECK: |
927 | 0 | { |
928 | 0 | const SSL_CIPHER *c = other; |
929 | | /* No ciphers below security level */ |
930 | 0 | if (bits < minbits) |
931 | 0 | return 0; |
932 | | /* No unauthenticated ciphersuites */ |
933 | 0 | if (c->algorithm_auth & SSL_aNULL) |
934 | 0 | return 0; |
935 | | /* No MD5 mac ciphersuites */ |
936 | 0 | if (c->algorithm_mac & SSL_MD5) |
937 | 0 | return 0; |
938 | | /* SHA1 HMAC is 160 bits of security */ |
939 | 0 | if (minbits > 160 && c->algorithm_mac & SSL_SHA1) |
940 | 0 | return 0; |
941 | | /* Level 2: no RC4 */ |
942 | 0 | if (level >= 2 && c->algorithm_enc == SSL_RC4) |
943 | 0 | return 0; |
944 | | /* Level 3: forward secure ciphersuites only */ |
945 | 0 | pfs_mask = SSL_kDHE | SSL_kECDHE | SSL_kDHEPSK | SSL_kECDHEPSK; |
946 | 0 | if (level >= 3 && c->min_tls != TLS1_3_VERSION && |
947 | 0 | !(c->algorithm_mkey & pfs_mask)) |
948 | 0 | return 0; |
949 | 0 | break; |
950 | 0 | } |
951 | 0 | case SSL_SECOP_VERSION: |
952 | 0 | if (!SSL_IS_DTLS(s)) { |
953 | | /* SSLv3 not allowed at level 2 */ |
954 | 0 | if (nid <= SSL3_VERSION && level >= 2) |
955 | 0 | return 0; |
956 | | /* TLS v1.1 and above only for level 3 */ |
957 | 0 | if (nid <= TLS1_VERSION && level >= 3) |
958 | 0 | return 0; |
959 | | /* TLS v1.2 only for level 4 and above */ |
960 | 0 | if (nid <= TLS1_1_VERSION && level >= 4) |
961 | 0 | return 0; |
962 | 0 | } else { |
963 | | /* DTLS v1.2 only for level 4 and above */ |
964 | 0 | if (DTLS_VERSION_LT(nid, DTLS1_2_VERSION) && level >= 4) |
965 | 0 | return 0; |
966 | 0 | } |
967 | 0 | break; |
968 | | |
969 | 0 | case SSL_SECOP_COMPRESSION: |
970 | 0 | if (level >= 2) |
971 | 0 | return 0; |
972 | 0 | break; |
973 | 0 | case SSL_SECOP_TICKET: |
974 | 0 | if (level >= 3) |
975 | 0 | return 0; |
976 | 0 | break; |
977 | 0 | default: |
978 | 0 | if (bits < minbits) |
979 | 0 | return 0; |
980 | 0 | } |
981 | 0 | return 1; |
982 | 0 | } |
983 | | |
984 | | int ssl_security(const SSL *s, int op, int bits, int nid, void *other) |
985 | 3.19M | { |
986 | 3.19M | return s->cert->sec_cb(s, NULL, op, bits, nid, other, s->cert->sec_ex); |
987 | 3.19M | } |
988 | | |
989 | | int ssl_ctx_security(const SSL_CTX *ctx, int op, int bits, int nid, void *other) |
990 | 0 | { |
991 | 0 | return ctx->cert->sec_cb(NULL, ctx, op, bits, nid, other, |
992 | 0 | ctx->cert->sec_ex); |
993 | 0 | } |
994 | | |
995 | | int ssl_cert_lookup_by_nid(int nid, size_t *pidx) |
996 | 3.53k | { |
997 | 3.53k | size_t i; |
998 | | |
999 | 6.82k | for (i = 0; i < OSSL_NELEM(ssl_cert_info); i++) { |
1000 | 6.82k | if (ssl_cert_info[i].nid == nid) { |
1001 | 3.53k | *pidx = i; |
1002 | 3.53k | return 1; |
1003 | 3.53k | } |
1004 | 6.82k | } |
1005 | | |
1006 | 5 | return 0; |
1007 | 3.53k | } |
1008 | | |
1009 | | const SSL_CERT_LOOKUP *ssl_cert_lookup_by_pkey(const EVP_PKEY *pk, size_t *pidx) |
1010 | 3.15k | { |
1011 | 3.15k | int nid = EVP_PKEY_id(pk); |
1012 | 3.15k | size_t tmpidx; |
1013 | | |
1014 | 3.15k | if (nid == NID_undef) |
1015 | 0 | return NULL; |
1016 | | |
1017 | 3.15k | if (!ssl_cert_lookup_by_nid(nid, &tmpidx)) |
1018 | 5 | return NULL; |
1019 | | |
1020 | 3.14k | if (pidx != NULL) |
1021 | 3.14k | *pidx = tmpidx; |
1022 | | |
1023 | 3.14k | return &ssl_cert_info[tmpidx]; |
1024 | 3.15k | } |
1025 | | |
1026 | | const SSL_CERT_LOOKUP *ssl_cert_lookup_by_idx(size_t idx) |
1027 | 866k | { |
1028 | 866k | if (idx >= OSSL_NELEM(ssl_cert_info)) |
1029 | 0 | return NULL; |
1030 | 866k | return &ssl_cert_info[idx]; |
1031 | 866k | } |