diff options
author | reyk <> | 2015-01-22 09:16:24 +0000 |
---|---|---|
committer | reyk <> | 2015-01-22 09:16:24 +0000 |
commit | 138944aeef27fb00df60db6f46ef653726b4ca5a (patch) | |
tree | 0cd70582ac032f525e31a6921611469898b556c3 /src | |
parent | d0ef2b563d4291f81a8f9ed7cd02bdfbaa8cc5f4 (diff) | |
download | openbsd-138944aeef27fb00df60db6f46ef653726b4ca5a.tar.gz openbsd-138944aeef27fb00df60db6f46ef653726b4ca5a.tar.bz2 openbsd-138944aeef27fb00df60db6f46ef653726b4ca5a.zip |
Allow to to load the CA chain directly from memory instead of
specifying a file. This enables CA verification in privsep'ed
processes that are running chroot'ed without direct access to the
certificate files.
With feedback, tests, and OK from bluhm@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libtls/shlib_version | 2 | ||||
-rw-r--r-- | src/lib/libtls/tls.h | 4 | ||||
-rw-r--r-- | src/lib/libtls/tls_client.c | 17 | ||||
-rw-r--r-- | src/lib/libtls/tls_config.c | 9 | ||||
-rw-r--r-- | src/lib/libtls/tls_init.3 | 11 | ||||
-rw-r--r-- | src/lib/libtls/tls_internal.h | 4 |
6 files changed, 39 insertions, 8 deletions
diff --git a/src/lib/libtls/shlib_version b/src/lib/libtls/shlib_version index 1edea46de9..893819d18f 100644 --- a/src/lib/libtls/shlib_version +++ b/src/lib/libtls/shlib_version | |||
@@ -1,2 +1,2 @@ | |||
1 | major=1 | 1 | major=1 |
2 | minor=0 | 2 | minor=1 |
diff --git a/src/lib/libtls/tls.h b/src/lib/libtls/tls.h index 21e1d74b35..8dcf125765 100644 --- a/src/lib/libtls/tls.h +++ b/src/lib/libtls/tls.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls.h,v 1.2 2014/11/02 14:45:05 jsing Exp $ */ | 1 | /* $OpenBSD: tls.h,v 1.3 2015/01/22 09:16:24 reyk Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -42,6 +42,8 @@ void tls_config_free(struct tls_config *config); | |||
42 | 42 | ||
43 | int tls_config_set_ca_file(struct tls_config *config, const char *ca_file); | 43 | int tls_config_set_ca_file(struct tls_config *config, const char *ca_file); |
44 | int tls_config_set_ca_path(struct tls_config *config, const char *ca_path); | 44 | int tls_config_set_ca_path(struct tls_config *config, const char *ca_path); |
45 | int tls_config_set_ca_mem(struct tls_config *config, const uint8_t *ca, | ||
46 | size_t len); | ||
45 | int tls_config_set_cert_file(struct tls_config *config, const char *cert_file); | 47 | int tls_config_set_cert_file(struct tls_config *config, const char *cert_file); |
46 | int tls_config_set_cert_mem(struct tls_config *config, const uint8_t *cert, | 48 | int tls_config_set_cert_mem(struct tls_config *config, const uint8_t *cert, |
47 | size_t len); | 49 | size_t len); |
diff --git a/src/lib/libtls/tls_client.c b/src/lib/libtls/tls_client.c index c6117c3292..4a9a4c976d 100644 --- a/src/lib/libtls/tls_client.c +++ b/src/lib/libtls/tls_client.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_client.c,v 1.8 2015/01/13 17:35:35 bluhm Exp $ */ | 1 | /* $OpenBSD: tls_client.c,v 1.9 2015/01/22 09:16:24 reyk Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -21,6 +21,7 @@ | |||
21 | #include <arpa/inet.h> | 21 | #include <arpa/inet.h> |
22 | #include <netinet/in.h> | 22 | #include <netinet/in.h> |
23 | 23 | ||
24 | #include <limits.h> | ||
24 | #include <netdb.h> | 25 | #include <netdb.h> |
25 | #include <stdlib.h> | 26 | #include <stdlib.h> |
26 | #include <unistd.h> | 27 | #include <unistd.h> |
@@ -168,7 +169,19 @@ tls_connect_fds(struct tls *ctx, int fd_read, int fd_write, | |||
168 | if (ctx->config->verify_cert) { | 169 | if (ctx->config->verify_cert) { |
169 | SSL_CTX_set_verify(ctx->ssl_ctx, SSL_VERIFY_PEER, NULL); | 170 | SSL_CTX_set_verify(ctx->ssl_ctx, SSL_VERIFY_PEER, NULL); |
170 | 171 | ||
171 | if (SSL_CTX_load_verify_locations(ctx->ssl_ctx, | 172 | if (ctx->config->ca_mem != NULL) { |
173 | if (ctx->config->ca_len > INT_MAX) { | ||
174 | tls_set_error(ctx, "ca too long"); | ||
175 | goto err; | ||
176 | } | ||
177 | |||
178 | if (SSL_CTX_load_verify_mem(ctx->ssl_ctx, | ||
179 | ctx->config->ca_mem, ctx->config->ca_len) != 1) { | ||
180 | tls_set_error(ctx, | ||
181 | "ssl verify memory setup failure"); | ||
182 | goto err; | ||
183 | } | ||
184 | } else if (SSL_CTX_load_verify_locations(ctx->ssl_ctx, | ||
172 | ctx->config->ca_file, ctx->config->ca_path) != 1) { | 185 | ctx->config->ca_file, ctx->config->ca_path) != 1) { |
173 | tls_set_error(ctx, "ssl verify setup failure"); | 186 | tls_set_error(ctx, "ssl verify setup failure"); |
174 | goto err; | 187 | goto err; |
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c index 0e435f616a..16120c5e4e 100644 --- a/src/lib/libtls/tls_config.c +++ b/src/lib/libtls/tls_config.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_config.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ | 1 | /* $OpenBSD: tls_config.c,v 1.2 2015/01/22 09:16:24 reyk Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -102,6 +102,7 @@ tls_config_free(struct tls_config *config) | |||
102 | void | 102 | void |
103 | tls_config_clear_keys(struct tls_config *config) | 103 | tls_config_clear_keys(struct tls_config *config) |
104 | { | 104 | { |
105 | tls_config_set_ca_mem(config, NULL, 0); | ||
105 | tls_config_set_cert_mem(config, NULL, 0); | 106 | tls_config_set_cert_mem(config, NULL, 0); |
106 | tls_config_set_key_mem(config, NULL, 0); | 107 | tls_config_set_key_mem(config, NULL, 0); |
107 | } | 108 | } |
@@ -119,6 +120,12 @@ tls_config_set_ca_path(struct tls_config *config, const char *ca_path) | |||
119 | } | 120 | } |
120 | 121 | ||
121 | int | 122 | int |
123 | tls_config_set_ca_mem(struct tls_config *config, const uint8_t *ca, size_t len) | ||
124 | { | ||
125 | return set_mem(&config->ca_mem, &config->ca_len, ca, len); | ||
126 | } | ||
127 | |||
128 | int | ||
122 | tls_config_set_cert_file(struct tls_config *config, const char *cert_file) | 129 | tls_config_set_cert_file(struct tls_config *config, const char *cert_file) |
123 | { | 130 | { |
124 | return set_string(&config->cert_file, cert_file); | 131 | return set_string(&config->cert_file, cert_file); |
diff --git a/src/lib/libtls/tls_init.3 b/src/lib/libtls/tls_init.3 index e870078225..df2dfc8a41 100644 --- a/src/lib/libtls/tls_init.3 +++ b/src/lib/libtls/tls_init.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: tls_init.3,v 1.6 2015/01/01 13:30:52 schwarze Exp $ | 1 | .\" $OpenBSD: tls_init.3,v 1.7 2015/01/22 09:16:24 reyk Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
4 | .\" | 4 | .\" |
@@ -14,7 +14,7 @@ | |||
14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | .\" | 16 | .\" |
17 | .Dd $Mdocdate: January 1 2015 $ | 17 | .Dd $Mdocdate: January 22 2015 $ |
18 | .Dt TLS 3 | 18 | .Dt TLS 3 |
19 | .Os | 19 | .Os |
20 | .Sh NAME | 20 | .Sh NAME |
@@ -24,6 +24,7 @@ | |||
24 | .Nm tls_config_free , | 24 | .Nm tls_config_free , |
25 | .Nm tls_config_set_ca_file , | 25 | .Nm tls_config_set_ca_file , |
26 | .Nm tls_config_set_ca_path , | 26 | .Nm tls_config_set_ca_path , |
27 | .Nm tls_config_set_ca_mem , | ||
27 | .Nm tls_config_set_cert_file , | 28 | .Nm tls_config_set_cert_file , |
28 | .Nm tls_config_set_cert_mem , | 29 | .Nm tls_config_set_cert_mem , |
29 | .Nm tls_config_set_ciphers , | 30 | .Nm tls_config_set_ciphers , |
@@ -63,6 +64,8 @@ | |||
63 | .Ft "int" | 64 | .Ft "int" |
64 | .Fn tls_config_set_ca_path "struct tls_config *config" "const char *ca_path" | 65 | .Fn tls_config_set_ca_path "struct tls_config *config" "const char *ca_path" |
65 | .Ft "int" | 66 | .Ft "int" |
67 | .Fn tls_config_set_ca_mem "struct tls_config *config" "const uint8_t *cert" "size_t len" | ||
68 | .Ft "int" | ||
66 | .Fn tls_config_set_cert_file "struct tls_config *config" "const char *cert_file" | 69 | .Fn tls_config_set_cert_file "struct tls_config *config" "const char *cert_file" |
67 | .Ft "int" | 70 | .Ft "int" |
68 | .Fn tls_config_set_cert_mem "struct tls_config *config" "const uint8_t *cert" "size_t len" | 71 | .Fn tls_config_set_cert_mem "struct tls_config *config" "const uint8_t *cert" "size_t len" |
@@ -198,6 +201,10 @@ sets the path (directory) which should be searched for root | |||
198 | certificates. | 201 | certificates. |
199 | .Em (Client) | 202 | .Em (Client) |
200 | .It | 203 | .It |
204 | .Fn tls_config_set_ca_mem | ||
205 | sets the root certificates directly from memory. | ||
206 | .Em (Client) | ||
207 | .It | ||
201 | .Fn tls_config_set_cert_file | 208 | .Fn tls_config_set_cert_file |
202 | sets file from which the public certificate will be read. | 209 | sets file from which the public certificate will be read. |
203 | .Em (Client and server) | 210 | .Em (Client and server) |
diff --git a/src/lib/libtls/tls_internal.h b/src/lib/libtls/tls_internal.h index 1a2bd388b7..9a1a180e0b 100644 --- a/src/lib/libtls/tls_internal.h +++ b/src/lib/libtls/tls_internal.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_internal.h,v 1.6 2015/01/13 17:35:35 bluhm Exp $ */ | 1 | /* $OpenBSD: tls_internal.h,v 1.7 2015/01/22 09:16:24 reyk Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> | 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> |
4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
@@ -28,6 +28,8 @@ | |||
28 | struct tls_config { | 28 | struct tls_config { |
29 | const char *ca_file; | 29 | const char *ca_file; |
30 | const char *ca_path; | 30 | const char *ca_path; |
31 | char *ca_mem; | ||
32 | size_t ca_len; | ||
31 | const char *cert_file; | 33 | const char *cert_file; |
32 | char *cert_mem; | 34 | char *cert_mem; |
33 | size_t cert_len; | 35 | size_t cert_len; |