summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/libtls/shlib_version2
-rw-r--r--src/lib/libtls/tls.h4
-rw-r--r--src/lib/libtls/tls_client.c17
-rw-r--r--src/lib/libtls/tls_config.c9
-rw-r--r--src/lib/libtls/tls_init.311
-rw-r--r--src/lib/libtls/tls_internal.h4
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 @@
1major=1 1major=1
2minor=0 2minor=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
43int tls_config_set_ca_file(struct tls_config *config, const char *ca_file); 43int tls_config_set_ca_file(struct tls_config *config, const char *ca_file);
44int tls_config_set_ca_path(struct tls_config *config, const char *ca_path); 44int tls_config_set_ca_path(struct tls_config *config, const char *ca_path);
45int tls_config_set_ca_mem(struct tls_config *config, const uint8_t *ca,
46 size_t len);
45int tls_config_set_cert_file(struct tls_config *config, const char *cert_file); 47int tls_config_set_cert_file(struct tls_config *config, const char *cert_file);
46int tls_config_set_cert_mem(struct tls_config *config, const uint8_t *cert, 48int 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)
102void 102void
103tls_config_clear_keys(struct tls_config *config) 103tls_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
121int 122int
123tls_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
128int
122tls_config_set_cert_file(struct tls_config *config, const char *cert_file) 129tls_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
198certificates. 201certificates.
199.Em (Client) 202.Em (Client)
200.It 203.It
204.Fn tls_config_set_ca_mem
205sets 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
202sets file from which the public certificate will be read. 209sets 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 @@
28struct tls_config { 28struct 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;