diff options
author | tb <> | 2022-06-28 20:40:24 +0000 |
---|---|---|
committer | tb <> | 2022-06-28 20:40:24 +0000 |
commit | 186a8ec1607c13d6266716aa9cb24fba4e86f1f0 (patch) | |
tree | 03da3cce0daceebde86bd02a2c0a4cf117bd10c9 /src | |
parent | f2a38cb44ea1980d59d2cd0db6321cfa58226032 (diff) | |
download | openbsd-186a8ec1607c13d6266716aa9cb24fba4e86f1f0.tar.gz openbsd-186a8ec1607c13d6266716aa9cb24fba4e86f1f0.tar.bz2 openbsd-186a8ec1607c13d6266716aa9cb24fba4e86f1f0.zip |
Implement the default security level callback
And here is where the fun starts. The tentacles will grow everywhere.
ok beck jsing sthen
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libssl/Makefile | 3 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 7 | ||||
-rw-r--r-- | src/lib/libssl/ssl_seclevel.c | 194 |
3 files changed, 202 insertions, 2 deletions
diff --git a/src/lib/libssl/Makefile b/src/lib/libssl/Makefile index 5a0a7bbc02..e6930b0b9f 100644 --- a/src/lib/libssl/Makefile +++ b/src/lib/libssl/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.74 2022/01/14 09:09:30 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.75 2022/06/28 20:40:24 tb Exp $ |
2 | 2 | ||
3 | .include <bsd.own.mk> | 3 | .include <bsd.own.mk> |
4 | .ifndef NOMAN | 4 | .ifndef NOMAN |
@@ -58,6 +58,7 @@ SRCS= \ | |||
58 | ssl_packet.c \ | 58 | ssl_packet.c \ |
59 | ssl_pkt.c \ | 59 | ssl_pkt.c \ |
60 | ssl_rsa.c \ | 60 | ssl_rsa.c \ |
61 | ssl_seclevel.c \ | ||
61 | ssl_sess.c \ | 62 | ssl_sess.c \ |
62 | ssl_sigalgs.c \ | 63 | ssl_sigalgs.c \ |
63 | ssl_srvr.c \ | 64 | ssl_srvr.c \ |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index 5b976bddc7..ab547ea5bc 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_locl.h,v 1.395 2022/06/28 20:31:43 tb Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.396 2022/06/28 20:40:24 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -1282,6 +1282,11 @@ int ssl_cert_set1_chain(SSL_CERT *c, STACK_OF(X509) *chain); | |||
1282 | int ssl_cert_add0_chain_cert(SSL_CERT *c, X509 *cert); | 1282 | int ssl_cert_add0_chain_cert(SSL_CERT *c, X509 *cert); |
1283 | int ssl_cert_add1_chain_cert(SSL_CERT *c, X509 *cert); | 1283 | int ssl_cert_add1_chain_cert(SSL_CERT *c, X509 *cert); |
1284 | 1284 | ||
1285 | int ssl_security_default_cb(const SSL *ssl, const SSL_CTX *ctx, int op, | ||
1286 | int bits, int nid, void *other, void *ex_data); | ||
1287 | int ssl_security_dummy_cb(const SSL *ssl, const SSL_CTX *ctx, int op, | ||
1288 | int bits, int nid, void *other, void *ex_data); | ||
1289 | |||
1285 | int ssl_get_new_session(SSL *s, int session); | 1290 | int ssl_get_new_session(SSL *s, int session); |
1286 | int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, | 1291 | int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, |
1287 | int *alert); | 1292 | int *alert); |
diff --git a/src/lib/libssl/ssl_seclevel.c b/src/lib/libssl/ssl_seclevel.c new file mode 100644 index 0000000000..3da78c65b7 --- /dev/null +++ b/src/lib/libssl/ssl_seclevel.c | |||
@@ -0,0 +1,194 @@ | |||
1 | /* $OpenBSD: ssl_seclevel.c,v 1.1 2022/06/28 20:40:24 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Theo Buehler <tb@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <stddef.h> | ||
19 | |||
20 | #include <openssl/ossl_typ.h> | ||
21 | #include <openssl/ssl.h> | ||
22 | #include <openssl/tls1.h> | ||
23 | |||
24 | #include "ssl_locl.h" | ||
25 | |||
26 | static int | ||
27 | ssl_security_normalize_level(const SSL_CTX *ctx, const SSL *ssl, int *out_level) | ||
28 | { | ||
29 | int security_level; | ||
30 | |||
31 | if (ctx != NULL) | ||
32 | security_level = SSL_CTX_get_security_level(ctx); | ||
33 | else | ||
34 | security_level = SSL_get_security_level(ssl); | ||
35 | |||
36 | if (security_level < 0) | ||
37 | security_level = 0; | ||
38 | if (security_level > 5) | ||
39 | security_level = 5; | ||
40 | |||
41 | *out_level = security_level; | ||
42 | |||
43 | return 1; | ||
44 | } | ||
45 | |||
46 | static int | ||
47 | ssl_security_level_to_minimum_bits(int security_level, int *out_minimum_bits) | ||
48 | { | ||
49 | if (security_level < 0) | ||
50 | return 0; | ||
51 | |||
52 | if (security_level == 0) | ||
53 | *out_minimum_bits = 0; | ||
54 | else if (security_level == 1) | ||
55 | *out_minimum_bits = 80; | ||
56 | else if (security_level == 2) | ||
57 | *out_minimum_bits = 112; | ||
58 | else if (security_level == 3) | ||
59 | *out_minimum_bits = 128; | ||
60 | else if (security_level == 4) | ||
61 | *out_minimum_bits = 192; | ||
62 | else if (security_level >= 5) | ||
63 | *out_minimum_bits = 256; | ||
64 | |||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | static int | ||
69 | ssl_security_level_and_minimum_bits(const SSL_CTX *ctx, const SSL *ssl, | ||
70 | int *out_level, int *out_minimum_bits) | ||
71 | { | ||
72 | int security_level = 0, minimum_bits = 0; | ||
73 | |||
74 | if (!ssl_security_normalize_level(ctx, ssl, &security_level)) | ||
75 | return 0; | ||
76 | if (!ssl_security_level_to_minimum_bits(security_level, &minimum_bits)) | ||
77 | return 0; | ||
78 | |||
79 | if (out_level != NULL) | ||
80 | *out_level = security_level; | ||
81 | if (out_minimum_bits != NULL) | ||
82 | *out_minimum_bits = minimum_bits; | ||
83 | |||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | static int | ||
88 | ssl_security_secop_cipher(const SSL_CTX *ctx, const SSL *ssl, int bits, | ||
89 | void *arg) | ||
90 | { | ||
91 | const SSL_CIPHER *cipher = arg; | ||
92 | int security_level, minimum_bits; | ||
93 | |||
94 | if (!ssl_security_level_and_minimum_bits(ctx, ssl, &security_level, | ||
95 | &minimum_bits)) | ||
96 | return 0; | ||
97 | |||
98 | if (security_level <= 0) | ||
99 | return 1; | ||
100 | |||
101 | if (bits < minimum_bits) | ||
102 | return 0; | ||
103 | |||
104 | /* No unauthenticated ciphersuites */ | ||
105 | if (cipher->algorithm_auth & SSL_aNULL) | ||
106 | return 0; | ||
107 | |||
108 | if (security_level <= 1) | ||
109 | return 1; | ||
110 | |||
111 | if (cipher->algorithm_enc == SSL_RC4) | ||
112 | return 0; | ||
113 | |||
114 | if (security_level <= 2) | ||
115 | return 1; | ||
116 | |||
117 | /* XXX TLSv1.3 */ | ||
118 | if ((cipher->algorithm_mkey & (SSL_kDHE | SSL_kECDHE)) != 0) | ||
119 | return 0; | ||
120 | |||
121 | return 1; | ||
122 | } | ||
123 | |||
124 | static int | ||
125 | ssl_security_secop_version(const SSL_CTX *ctx, const SSL *ssl, int version) | ||
126 | { | ||
127 | int min_version = TLS1_2_VERSION; | ||
128 | int security_level; | ||
129 | |||
130 | if (!ssl_security_level_and_minimum_bits(ctx, ssl, &security_level, NULL)) | ||
131 | return 0; | ||
132 | |||
133 | if (security_level < 4) | ||
134 | min_version = TLS1_1_VERSION; | ||
135 | if (security_level < 3) | ||
136 | min_version = TLS1_VERSION; | ||
137 | |||
138 | return ssl_tls_version(version) >= min_version; | ||
139 | } | ||
140 | |||
141 | static int | ||
142 | ssl_security_secop_compression(const SSL_CTX *ctx, const SSL *ssl) | ||
143 | { | ||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | static int | ||
148 | ssl_security_secop_tickets(const SSL_CTX *ctx, const SSL *ssl) | ||
149 | { | ||
150 | int security_level; | ||
151 | |||
152 | if (!ssl_security_level_and_minimum_bits(ctx, ssl, &security_level, NULL)) | ||
153 | return 0; | ||
154 | |||
155 | return security_level < 3; | ||
156 | } | ||
157 | |||
158 | static int | ||
159 | ssl_security_secop_default(const SSL_CTX *ctx, const SSL *ssl, int bits) | ||
160 | { | ||
161 | int minimum_bits; | ||
162 | |||
163 | if (!ssl_security_level_and_minimum_bits(ctx, ssl, NULL, &minimum_bits)) | ||
164 | return 0; | ||
165 | |||
166 | return bits >= minimum_bits; | ||
167 | } | ||
168 | |||
169 | int | ||
170 | ssl_security_default_cb(const SSL *ssl, const SSL_CTX *ctx, int op, int bits, | ||
171 | int version, void *cipher, void *ex_data) | ||
172 | { | ||
173 | switch (op) { | ||
174 | case SSL_SECOP_CIPHER_SUPPORTED: | ||
175 | case SSL_SECOP_CIPHER_SHARED: | ||
176 | case SSL_SECOP_CIPHER_CHECK: | ||
177 | return ssl_security_secop_cipher(ctx, ssl, bits, cipher); | ||
178 | case SSL_SECOP_VERSION: | ||
179 | return ssl_security_secop_version(ctx, ssl, version); | ||
180 | case SSL_SECOP_COMPRESSION: | ||
181 | return ssl_security_secop_compression(ctx, ssl); | ||
182 | case SSL_SECOP_TICKET: | ||
183 | return ssl_security_secop_tickets(ctx, ssl); | ||
184 | default: | ||
185 | return ssl_security_secop_default(ctx, ssl, bits); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | int | ||
190 | ssl_security_dummy_cb(const SSL *ssl, const SSL_CTX *ctx, int op, int bits, | ||
191 | int version, void *cipher, void *ex_data) | ||
192 | { | ||
193 | return 1; | ||
194 | } | ||