diff options
author | jsing <> | 2014-10-31 13:46:17 +0000 |
---|---|---|
committer | jsing <> | 2014-10-31 13:46:17 +0000 |
commit | cd85e00508e178758948e7a759609d0f1e7764df (patch) | |
tree | 44ea21a19ccf529a3e38fb107d3a2d1330f58d8e /src | |
parent | e83bdb8edcd9388f13b71372b277fdcce386a9b0 (diff) | |
download | openbsd-cd85e00508e178758948e7a759609d0f1e7764df.tar.gz openbsd-cd85e00508e178758948e7a759609d0f1e7764df.tar.bz2 openbsd-cd85e00508e178758948e7a759609d0f1e7764df.zip |
Rename libressl to libtls to avoid confusion and to make it easier to
distinguish between LibreSSL (the project) and libressl (the library).
Discussed with many.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libressl/Makefile | 56 | ||||
-rw-r--r-- | src/lib/libressl/ressl.h | 81 | ||||
-rw-r--r-- | src/lib/libtls/Makefile | 58 | ||||
-rw-r--r-- | src/lib/libtls/shlib_version (renamed from src/lib/libressl/shlib_version) | 2 | ||||
-rw-r--r-- | src/lib/libtls/tls.c (renamed from src/lib/libressl/ressl.c) | 96 | ||||
-rw-r--r-- | src/lib/libtls/tls.h | 74 | ||||
-rw-r--r-- | src/lib/libtls/tls_client.c (renamed from src/lib/libressl/ressl_client.c) | 64 | ||||
-rw-r--r-- | src/lib/libtls/tls_config.c (renamed from src/lib/libressl/ressl_config.c) | 60 | ||||
-rw-r--r-- | src/lib/libtls/tls_init.3 (renamed from src/lib/libressl/ressl_init.3) | 232 | ||||
-rw-r--r-- | src/lib/libtls/tls_internal.h (renamed from src/lib/libressl/ressl_internal.h) | 36 | ||||
-rw-r--r-- | src/lib/libtls/tls_server.c (renamed from src/lib/libressl/ressl_server.c) | 82 | ||||
-rw-r--r-- | src/lib/libtls/tls_util.c (renamed from src/lib/libressl/ressl_util.c) | 6 | ||||
-rw-r--r-- | src/lib/libtls/tls_verify.c (renamed from src/lib/libressl/ressl_verify.c) | 26 |
13 files changed, 422 insertions, 451 deletions
diff --git a/src/lib/libressl/Makefile b/src/lib/libressl/Makefile deleted file mode 100644 index f21c0474ed..0000000000 --- a/src/lib/libressl/Makefile +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2014/10/08 19:01:40 tedu Exp $ | ||
2 | |||
3 | CFLAGS+= -Wall -Werror -Wimplicit | ||
4 | CFLAGS+= -DLIBRESSL_INTERNAL | ||
5 | |||
6 | LIB= ressl | ||
7 | |||
8 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
9 | |||
10 | HDRS= ressl.h | ||
11 | |||
12 | SRCS= ressl.c \ | ||
13 | ressl_client.c \ | ||
14 | ressl_config.c \ | ||
15 | ressl_server.c \ | ||
16 | ressl_util.c \ | ||
17 | ressl_verify.c | ||
18 | |||
19 | MAN= ressl_init.3 | ||
20 | |||
21 | MLINKS+=ressl_init.3 ressl_error.3 | ||
22 | MLINKS+=ressl_init.3 ressl_config_new.3 | ||
23 | MLINKS+=ressl_init.3 ressl_config_free.3 | ||
24 | MLINKS+=ressl_init.3 ressl_set_ca_file.3 | ||
25 | MLINKS+=ressl_init.3 ressl_set_ca_path.3 | ||
26 | MLINKS+=ressl_init.3 ressl_set_cert_file.3 | ||
27 | MLINKS+=ressl_init.3 ressl_set_cert_mem.3 | ||
28 | MLINKS+=ressl_init.3 ressl_set_ciphers.3 | ||
29 | MLINKS+=ressl_init.3 ressl_set_ecdhcurve.3 | ||
30 | MLINKS+=ressl_init.3 ressl_set_key_file.3 | ||
31 | MLINKS+=ressl_init.3 ressl_set_key_mem.3 | ||
32 | MLINKS+=ressl_init.3 ressl_set_protocols.3 | ||
33 | MLINKS+=ressl_init.3 ressl_set_verify_depth.3 | ||
34 | MLINKS+=ressl_init.3 ressl_clear_keys.3 | ||
35 | MLINKS+=ressl_init.3 ressl_insecure_noverifyhost.3 | ||
36 | MLINKS+=ressl_init.3 ressl_insecure_noverifycert.3 | ||
37 | MLINKS+=ressl_init.3 ressl_verify.3 | ||
38 | MLINKS+=ressl_init.3 ressl_configure.3 | ||
39 | MLINKS+=ressl_init.3 ressl_reset.3 | ||
40 | MLINKS+=ressl_init.3 ressl_free.3 | ||
41 | MLINKS+=ressl_init.3 ressl_close.3 | ||
42 | MLINKS+=ressl_init.3 ressl_connect.3 | ||
43 | MLINKS+=ressl_init.3 ressl_connect_socket.3 | ||
44 | MLINKS+=ressl_init.3 ressl_read.3 | ||
45 | MLINKS+=ressl_init.3 ressl_write.3 | ||
46 | |||
47 | includes: | ||
48 | @cd ${.CURDIR}; for i in $(HDRS); do \ | ||
49 | j="cmp -s $$i ${DESTDIR}/usr/include/$$i || \ | ||
50 | ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 $$i\ | ||
51 | ${DESTDIR}/usr/include/"; \ | ||
52 | echo $$j; \ | ||
53 | eval "$$j"; \ | ||
54 | done; | ||
55 | |||
56 | .include <bsd.lib.mk> | ||
diff --git a/src/lib/libressl/ressl.h b/src/lib/libressl/ressl.h deleted file mode 100644 index 4ca2507f5a..0000000000 --- a/src/lib/libressl/ressl.h +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* $OpenBSD: ressl.h,v 1.21 2014/10/15 21:02:39 tedu Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Joel Sing <jsing@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 | #ifndef HEADER_RESSL_H | ||
19 | #define HEADER_RESSL_H | ||
20 | |||
21 | #define RESSL_API 20141008 | ||
22 | |||
23 | #define RESSL_PROTOCOL_TLSv1_0 (1 << 1) | ||
24 | #define RESSL_PROTOCOL_TLSv1_1 (1 << 2) | ||
25 | #define RESSL_PROTOCOL_TLSv1_2 (1 << 3) | ||
26 | #define RESSL_PROTOCOL_TLSv1 \ | ||
27 | (RESSL_PROTOCOL_TLSv1_0|RESSL_PROTOCOL_TLSv1_1|RESSL_PROTOCOL_TLSv1_2) | ||
28 | #define RESSL_PROTOCOLS_DEFAULT RESSL_PROTOCOL_TLSv1 | ||
29 | |||
30 | #define RESSL_READ_AGAIN -2 | ||
31 | #define RESSL_WRITE_AGAIN -3 | ||
32 | |||
33 | struct ressl; | ||
34 | struct ressl_config; | ||
35 | |||
36 | int ressl_init(void); | ||
37 | |||
38 | const char *ressl_error(struct ressl *ctx); | ||
39 | |||
40 | struct ressl_config *ressl_config_new(void); | ||
41 | void ressl_config_free(struct ressl_config *config); | ||
42 | |||
43 | int ressl_config_set_ca_file(struct ressl_config *config, const char *ca_file); | ||
44 | int ressl_config_set_ca_path(struct ressl_config *config, const char *ca_path); | ||
45 | int ressl_config_set_cert_file(struct ressl_config *config, | ||
46 | const char *cert_file); | ||
47 | int ressl_config_set_cert_mem(struct ressl_config *config, const uint8_t *cert, | ||
48 | size_t len); | ||
49 | int ressl_config_set_ciphers(struct ressl_config *config, const char *ciphers); | ||
50 | int ressl_config_set_ecdhcurve(struct ressl_config *config, const char *name); | ||
51 | int ressl_config_set_key_file(struct ressl_config *config, | ||
52 | const char *key_file); | ||
53 | int ressl_config_set_key_mem(struct ressl_config *config, const uint8_t *key, | ||
54 | size_t len); | ||
55 | void ressl_config_set_protocols(struct ressl_config *config, | ||
56 | uint32_t protocols); | ||
57 | void ressl_config_set_verify_depth(struct ressl_config *config, | ||
58 | int verify_depth); | ||
59 | |||
60 | void ressl_config_clear_keys(struct ressl_config *config); | ||
61 | void ressl_config_insecure_noverifyhost(struct ressl_config *config); | ||
62 | void ressl_config_insecure_noverifycert(struct ressl_config *config); | ||
63 | void ressl_config_verify(struct ressl_config *config); | ||
64 | |||
65 | struct ressl *ressl_client(void); | ||
66 | struct ressl *ressl_server(void); | ||
67 | int ressl_configure(struct ressl *ctx, struct ressl_config *config); | ||
68 | void ressl_reset(struct ressl *ctx); | ||
69 | void ressl_free(struct ressl *ctx); | ||
70 | |||
71 | int ressl_accept(struct ressl *ctx, struct ressl **cctx); | ||
72 | int ressl_accept_socket(struct ressl *ctx, struct ressl **cctx, int socket); | ||
73 | int ressl_connect(struct ressl *ctx, const char *host, const char *port); | ||
74 | int ressl_connect_socket(struct ressl *ctx, int s, const char *hostname); | ||
75 | int ressl_listen(struct ressl *ctx, const char *host, const char *port, int af); | ||
76 | int ressl_read(struct ressl *ctx, void *buf, size_t buflen, size_t *outlen); | ||
77 | int ressl_write(struct ressl *ctx, const void *buf, size_t buflen, | ||
78 | size_t *outlen); | ||
79 | int ressl_close(struct ressl *ctx); | ||
80 | |||
81 | #endif /* HEADER_RESSL_H */ | ||
diff --git a/src/lib/libtls/Makefile b/src/lib/libtls/Makefile new file mode 100644 index 0000000000..b83a6de2ce --- /dev/null +++ b/src/lib/libtls/Makefile | |||
@@ -0,0 +1,58 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2014/10/31 13:46:17 jsing Exp $ | ||
2 | |||
3 | CFLAGS+= -Wall -Werror -Wimplicit | ||
4 | CFLAGS+= -DLIBRESSL_INTERNAL | ||
5 | |||
6 | LIB= tls | ||
7 | |||
8 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
9 | |||
10 | HDRS= tls.h | ||
11 | |||
12 | SRCS= tls.c \ | ||
13 | tls_client.c \ | ||
14 | tls_config.c \ | ||
15 | tls_server.c \ | ||
16 | tls_util.c \ | ||
17 | tls_verify.c | ||
18 | |||
19 | MAN= tls_init.3 | ||
20 | |||
21 | MLINKS+=tls_init.3 tls_config_new.3 | ||
22 | MLINKS+=tls_init.3 tls_config_free.3 | ||
23 | MLINKS+=tls_init.3 tls_config_set_ca_file.3 | ||
24 | MLINKS+=tls_init.3 tls_config_set_ca_path.3 | ||
25 | MLINKS+=tls_init.3 tls_config_set_cert_file.3 | ||
26 | MLINKS+=tls_init.3 tls_config_set_cert_mem.3 | ||
27 | MLINKS+=tls_init.3 tls_config_set_ciphers.3 | ||
28 | MLINKS+=tls_init.3 tls_config_set_ecdhcurve.3 | ||
29 | MLINKS+=tls_init.3 tls_config_set_key_file.3 | ||
30 | MLINKS+=tls_init.3 tls_config_set_key_mem.3 | ||
31 | MLINKS+=tls_init.3 tls_config_set_protocols.3 | ||
32 | MLINKS+=tls_init.3 tls_config_set_verify_depth.3 | ||
33 | MLINKS+=tls_init.3 tls_config_clear_keys.3 | ||
34 | MLINKS+=tls_init.3 tls_config_insecure_noverifyhost.3 | ||
35 | MLINKS+=tls_init.3 tls_config_insecure_noverifycert.3 | ||
36 | MLINKS+=tls_init.3 tls_config_verify.3 | ||
37 | MLINKS+=tls_init.3 tls_client.3 | ||
38 | MLINKS+=tls_init.3 tls_server.3 | ||
39 | MLINKS+=tls_init.3 tls_configure.3 | ||
40 | MLINKS+=tls_init.3 tls_error.3 | ||
41 | MLINKS+=tls_init.3 tls_reset.3 | ||
42 | MLINKS+=tls_init.3 tls_free.3 | ||
43 | MLINKS+=tls_init.3 tls_close.3 | ||
44 | MLINKS+=tls_init.3 tls_connect.3 | ||
45 | MLINKS+=tls_init.3 tls_connect_socket.3 | ||
46 | MLINKS+=tls_init.3 tls_read.3 | ||
47 | MLINKS+=tls_init.3 tls_write.3 | ||
48 | |||
49 | includes: | ||
50 | @cd ${.CURDIR}; for i in $(HDRS); do \ | ||
51 | j="cmp -s $$i ${DESTDIR}/usr/include/$$i || \ | ||
52 | ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 $$i\ | ||
53 | ${DESTDIR}/usr/include/"; \ | ||
54 | echo $$j; \ | ||
55 | eval "$$j"; \ | ||
56 | done; | ||
57 | |||
58 | .include <bsd.lib.mk> | ||
diff --git a/src/lib/libressl/shlib_version b/src/lib/libtls/shlib_version index b52599a164..1edea46de9 100644 --- a/src/lib/libressl/shlib_version +++ b/src/lib/libtls/shlib_version | |||
@@ -1,2 +1,2 @@ | |||
1 | major=2 | 1 | major=1 |
2 | minor=0 | 2 | minor=0 |
diff --git a/src/lib/libressl/ressl.c b/src/lib/libtls/tls.c index 06c7d54cc2..a7f612e40b 100644 --- a/src/lib/libressl/ressl.c +++ b/src/lib/libtls/tls.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ressl.c,v 1.18 2014/10/15 21:02:39 tedu Exp $ */ | 1 | /* $OpenBSD: tls.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -26,38 +26,38 @@ | |||
26 | #include <openssl/pem.h> | 26 | #include <openssl/pem.h> |
27 | #include <openssl/x509.h> | 27 | #include <openssl/x509.h> |
28 | 28 | ||
29 | #include <ressl.h> | 29 | #include <tls.h> |
30 | #include "ressl_internal.h" | 30 | #include "tls_internal.h" |
31 | 31 | ||
32 | static struct ressl_config *ressl_config_default; | 32 | static struct tls_config *tls_config_default; |
33 | 33 | ||
34 | int | 34 | int |
35 | ressl_init(void) | 35 | tls_init(void) |
36 | { | 36 | { |
37 | static int ressl_initialised = 0; | 37 | static int tls_initialised = 0; |
38 | 38 | ||
39 | if (ressl_initialised) | 39 | if (tls_initialised) |
40 | return (0); | 40 | return (0); |
41 | 41 | ||
42 | SSL_load_error_strings(); | 42 | SSL_load_error_strings(); |
43 | SSL_library_init(); | 43 | SSL_library_init(); |
44 | 44 | ||
45 | if ((ressl_config_default = ressl_config_new()) == NULL) | 45 | if ((tls_config_default = tls_config_new()) == NULL) |
46 | return (-1); | 46 | return (-1); |
47 | 47 | ||
48 | ressl_initialised = 1; | 48 | tls_initialised = 1; |
49 | 49 | ||
50 | return (0); | 50 | return (0); |
51 | } | 51 | } |
52 | 52 | ||
53 | const char * | 53 | const char * |
54 | ressl_error(struct ressl *ctx) | 54 | tls_error(struct tls *ctx) |
55 | { | 55 | { |
56 | return ctx->errmsg; | 56 | return ctx->errmsg; |
57 | } | 57 | } |
58 | 58 | ||
59 | int | 59 | int |
60 | ressl_set_error(struct ressl *ctx, char *fmt, ...) | 60 | tls_set_error(struct tls *ctx, char *fmt, ...) |
61 | { | 61 | { |
62 | va_list ap; | 62 | va_list ap; |
63 | int rv; | 63 | int rv; |
@@ -73,37 +73,37 @@ ressl_set_error(struct ressl *ctx, char *fmt, ...) | |||
73 | return (rv); | 73 | return (rv); |
74 | } | 74 | } |
75 | 75 | ||
76 | struct ressl * | 76 | struct tls * |
77 | ressl_new(void) | 77 | tls_new(void) |
78 | { | 78 | { |
79 | struct ressl *ctx; | 79 | struct tls *ctx; |
80 | 80 | ||
81 | if ((ctx = calloc(1, sizeof(*ctx))) == NULL) | 81 | if ((ctx = calloc(1, sizeof(*ctx))) == NULL) |
82 | return (NULL); | 82 | return (NULL); |
83 | 83 | ||
84 | ctx->config = ressl_config_default; | 84 | ctx->config = tls_config_default; |
85 | 85 | ||
86 | ressl_reset(ctx); | 86 | tls_reset(ctx); |
87 | 87 | ||
88 | return (ctx); | 88 | return (ctx); |
89 | } | 89 | } |
90 | 90 | ||
91 | int | 91 | int |
92 | ressl_configure(struct ressl *ctx, struct ressl_config *config) | 92 | tls_configure(struct tls *ctx, struct tls_config *config) |
93 | { | 93 | { |
94 | if (config == NULL) | 94 | if (config == NULL) |
95 | config = ressl_config_default; | 95 | config = tls_config_default; |
96 | 96 | ||
97 | ctx->config = config; | 97 | ctx->config = config; |
98 | 98 | ||
99 | if ((ctx->flags & RESSL_SERVER) != 0) | 99 | if ((ctx->flags & TLS_SERVER) != 0) |
100 | return (ressl_configure_server(ctx)); | 100 | return (tls_configure_server(ctx)); |
101 | 101 | ||
102 | return (0); | 102 | return (0); |
103 | } | 103 | } |
104 | 104 | ||
105 | int | 105 | int |
106 | ressl_configure_keypair(struct ressl *ctx) | 106 | tls_configure_keypair(struct tls *ctx) |
107 | { | 107 | { |
108 | EVP_PKEY *pkey = NULL; | 108 | EVP_PKEY *pkey = NULL; |
109 | X509 *cert = NULL; | 109 | X509 *cert = NULL; |
@@ -112,7 +112,7 @@ ressl_configure_keypair(struct ressl *ctx) | |||
112 | if (ctx->config->cert_mem != NULL) { | 112 | if (ctx->config->cert_mem != NULL) { |
113 | if (SSL_CTX_use_certificate_chain(ctx->ssl_ctx, | 113 | if (SSL_CTX_use_certificate_chain(ctx->ssl_ctx, |
114 | ctx->config->cert_mem, ctx->config->cert_len) != 1) { | 114 | ctx->config->cert_mem, ctx->config->cert_len) != 1) { |
115 | ressl_set_error(ctx, "failed to load certificate"); | 115 | tls_set_error(ctx, "failed to load certificate"); |
116 | goto err; | 116 | goto err; |
117 | } | 117 | } |
118 | cert = NULL; | 118 | cert = NULL; |
@@ -120,16 +120,16 @@ ressl_configure_keypair(struct ressl *ctx) | |||
120 | if (ctx->config->key_mem != NULL) { | 120 | if (ctx->config->key_mem != NULL) { |
121 | if ((bio = BIO_new_mem_buf(ctx->config->key_mem, | 121 | if ((bio = BIO_new_mem_buf(ctx->config->key_mem, |
122 | ctx->config->key_len)) == NULL) { | 122 | ctx->config->key_len)) == NULL) { |
123 | ressl_set_error(ctx, "failed to create buffer"); | 123 | tls_set_error(ctx, "failed to create buffer"); |
124 | goto err; | 124 | goto err; |
125 | } | 125 | } |
126 | if ((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, | 126 | if ((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, |
127 | NULL)) == NULL) { | 127 | NULL)) == NULL) { |
128 | ressl_set_error(ctx, "failed to read private key"); | 128 | tls_set_error(ctx, "failed to read private key"); |
129 | goto err; | 129 | goto err; |
130 | } | 130 | } |
131 | if (SSL_CTX_use_PrivateKey(ctx->ssl_ctx, pkey) != 1) { | 131 | if (SSL_CTX_use_PrivateKey(ctx->ssl_ctx, pkey) != 1) { |
132 | ressl_set_error(ctx, "failed to load private key"); | 132 | tls_set_error(ctx, "failed to load private key"); |
133 | goto err; | 133 | goto err; |
134 | } | 134 | } |
135 | BIO_free(bio); | 135 | BIO_free(bio); |
@@ -141,20 +141,20 @@ ressl_configure_keypair(struct ressl *ctx) | |||
141 | if (ctx->config->cert_file != NULL) { | 141 | if (ctx->config->cert_file != NULL) { |
142 | if (SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, | 142 | if (SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, |
143 | ctx->config->cert_file) != 1) { | 143 | ctx->config->cert_file) != 1) { |
144 | ressl_set_error(ctx, "failed to load certificate file"); | 144 | tls_set_error(ctx, "failed to load certificate file"); |
145 | goto err; | 145 | goto err; |
146 | } | 146 | } |
147 | } | 147 | } |
148 | if (ctx->config->key_file != NULL) { | 148 | if (ctx->config->key_file != NULL) { |
149 | if (SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, | 149 | if (SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, |
150 | ctx->config->key_file, SSL_FILETYPE_PEM) != 1) { | 150 | ctx->config->key_file, SSL_FILETYPE_PEM) != 1) { |
151 | ressl_set_error(ctx, "failed to load private key file"); | 151 | tls_set_error(ctx, "failed to load private key file"); |
152 | goto err; | 152 | goto err; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | if (SSL_CTX_check_private_key(ctx->ssl_ctx) != 1) { | 156 | if (SSL_CTX_check_private_key(ctx->ssl_ctx) != 1) { |
157 | ressl_set_error(ctx, "private/public key mismatch"); | 157 | tls_set_error(ctx, "private/public key mismatch"); |
158 | goto err; | 158 | goto err; |
159 | } | 159 | } |
160 | 160 | ||
@@ -169,7 +169,7 @@ err: | |||
169 | } | 169 | } |
170 | 170 | ||
171 | int | 171 | int |
172 | ressl_configure_ssl(struct ressl *ctx) | 172 | tls_configure_ssl(struct tls *ctx) |
173 | { | 173 | { |
174 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_SSLv2); | 174 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_SSLv2); |
175 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_SSLv3); | 175 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_SSLv3); |
@@ -178,17 +178,17 @@ ressl_configure_ssl(struct ressl *ctx) | |||
178 | SSL_CTX_clear_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_1); | 178 | SSL_CTX_clear_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_1); |
179 | SSL_CTX_clear_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_2); | 179 | SSL_CTX_clear_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_2); |
180 | 180 | ||
181 | if ((ctx->config->protocols & RESSL_PROTOCOL_TLSv1_0) == 0) | 181 | if ((ctx->config->protocols & TLS_PROTOCOL_TLSv1_0) == 0) |
182 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1); | 182 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1); |
183 | if ((ctx->config->protocols & RESSL_PROTOCOL_TLSv1_1) == 0) | 183 | if ((ctx->config->protocols & TLS_PROTOCOL_TLSv1_1) == 0) |
184 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_1); | 184 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_1); |
185 | if ((ctx->config->protocols & RESSL_PROTOCOL_TLSv1_2) == 0) | 185 | if ((ctx->config->protocols & TLS_PROTOCOL_TLSv1_2) == 0) |
186 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_2); | 186 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_TLSv1_2); |
187 | 187 | ||
188 | if (ctx->config->ciphers != NULL) { | 188 | if (ctx->config->ciphers != NULL) { |
189 | if (SSL_CTX_set_cipher_list(ctx->ssl_ctx, | 189 | if (SSL_CTX_set_cipher_list(ctx->ssl_ctx, |
190 | ctx->config->ciphers) != 1) { | 190 | ctx->config->ciphers) != 1) { |
191 | ressl_set_error(ctx, "failed to set ciphers"); | 191 | tls_set_error(ctx, "failed to set ciphers"); |
192 | goto err; | 192 | goto err; |
193 | } | 193 | } |
194 | } | 194 | } |
@@ -200,16 +200,16 @@ err: | |||
200 | } | 200 | } |
201 | 201 | ||
202 | void | 202 | void |
203 | ressl_free(struct ressl *ctx) | 203 | tls_free(struct tls *ctx) |
204 | { | 204 | { |
205 | if (ctx == NULL) | 205 | if (ctx == NULL) |
206 | return; | 206 | return; |
207 | ressl_reset(ctx); | 207 | tls_reset(ctx); |
208 | free(ctx); | 208 | free(ctx); |
209 | } | 209 | } |
210 | 210 | ||
211 | void | 211 | void |
212 | ressl_reset(struct ressl *ctx) | 212 | tls_reset(struct tls *ctx) |
213 | { | 213 | { |
214 | SSL_CTX_free(ctx->ssl_ctx); | 214 | SSL_CTX_free(ctx->ssl_ctx); |
215 | SSL_free(ctx->ssl_conn); | 215 | SSL_free(ctx->ssl_conn); |
@@ -225,7 +225,7 @@ ressl_reset(struct ressl *ctx) | |||
225 | } | 225 | } |
226 | 226 | ||
227 | int | 227 | int |
228 | ressl_read(struct ressl *ctx, void *buf, size_t buflen, size_t *outlen) | 228 | tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen) |
229 | { | 229 | { |
230 | int ret, ssl_err; | 230 | int ret, ssl_err; |
231 | 231 | ||
@@ -238,17 +238,17 @@ ressl_read(struct ressl *ctx, void *buf, size_t buflen, size_t *outlen) | |||
238 | ssl_err = SSL_get_error(ctx->ssl_conn, ret); | 238 | ssl_err = SSL_get_error(ctx->ssl_conn, ret); |
239 | switch (ssl_err) { | 239 | switch (ssl_err) { |
240 | case SSL_ERROR_WANT_READ: | 240 | case SSL_ERROR_WANT_READ: |
241 | return (RESSL_READ_AGAIN); | 241 | return (TLS_READ_AGAIN); |
242 | case SSL_ERROR_WANT_WRITE: | 242 | case SSL_ERROR_WANT_WRITE: |
243 | return (RESSL_WRITE_AGAIN); | 243 | return (TLS_WRITE_AGAIN); |
244 | default: | 244 | default: |
245 | ressl_set_error(ctx, "read failed (%i)", ssl_err); | 245 | tls_set_error(ctx, "read failed (%i)", ssl_err); |
246 | return (-1); | 246 | return (-1); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | 249 | ||
250 | int | 250 | int |
251 | ressl_write(struct ressl *ctx, const void *buf, size_t buflen, size_t *outlen) | 251 | tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen) |
252 | { | 252 | { |
253 | int ret, ssl_err; | 253 | int ret, ssl_err; |
254 | 254 | ||
@@ -261,33 +261,33 @@ ressl_write(struct ressl *ctx, const void *buf, size_t buflen, size_t *outlen) | |||
261 | ssl_err = SSL_get_error(ctx->ssl_conn, ret); | 261 | ssl_err = SSL_get_error(ctx->ssl_conn, ret); |
262 | switch (ssl_err) { | 262 | switch (ssl_err) { |
263 | case SSL_ERROR_WANT_READ: | 263 | case SSL_ERROR_WANT_READ: |
264 | return (RESSL_READ_AGAIN); | 264 | return (TLS_READ_AGAIN); |
265 | case SSL_ERROR_WANT_WRITE: | 265 | case SSL_ERROR_WANT_WRITE: |
266 | return (RESSL_WRITE_AGAIN); | 266 | return (TLS_WRITE_AGAIN); |
267 | default: | 267 | default: |
268 | ressl_set_error(ctx, "write failed (%i)", ssl_err); | 268 | tls_set_error(ctx, "write failed (%i)", ssl_err); |
269 | return (-1); | 269 | return (-1); |
270 | } | 270 | } |
271 | } | 271 | } |
272 | 272 | ||
273 | int | 273 | int |
274 | ressl_close(struct ressl *ctx) | 274 | tls_close(struct tls *ctx) |
275 | { | 275 | { |
276 | /* XXX - handle case where multiple calls are required. */ | 276 | /* XXX - handle case where multiple calls are required. */ |
277 | if (ctx->ssl_conn != NULL) { | 277 | if (ctx->ssl_conn != NULL) { |
278 | if (SSL_shutdown(ctx->ssl_conn) == -1) { | 278 | if (SSL_shutdown(ctx->ssl_conn) == -1) { |
279 | ressl_set_error(ctx, "SSL shutdown failed"); | 279 | tls_set_error(ctx, "SSL shutdown failed"); |
280 | goto err; | 280 | goto err; |
281 | } | 281 | } |
282 | } | 282 | } |
283 | 283 | ||
284 | if (ctx->socket != -1) { | 284 | if (ctx->socket != -1) { |
285 | if (shutdown(ctx->socket, SHUT_RDWR) != 0) { | 285 | if (shutdown(ctx->socket, SHUT_RDWR) != 0) { |
286 | ressl_set_error(ctx, "shutdown"); | 286 | tls_set_error(ctx, "shutdown"); |
287 | goto err; | 287 | goto err; |
288 | } | 288 | } |
289 | if (close(ctx->socket) != 0) { | 289 | if (close(ctx->socket) != 0) { |
290 | ressl_set_error(ctx, "close"); | 290 | tls_set_error(ctx, "close"); |
291 | goto err; | 291 | goto err; |
292 | } | 292 | } |
293 | ctx->socket = -1; | 293 | ctx->socket = -1; |
diff --git a/src/lib/libtls/tls.h b/src/lib/libtls/tls.h new file mode 100644 index 0000000000..0fa776e584 --- /dev/null +++ b/src/lib/libtls/tls.h | |||
@@ -0,0 +1,74 @@ | |||
1 | /* $OpenBSD: tls.h,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Joel Sing <jsing@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 | #ifndef HEADER_TLS_H | ||
19 | #define HEADER_TLS_H | ||
20 | |||
21 | #define TLS_API 20141031 | ||
22 | |||
23 | #define TLS_PROTOCOL_TLSv1_0 (1 << 1) | ||
24 | #define TLS_PROTOCOL_TLSv1_1 (1 << 2) | ||
25 | #define TLS_PROTOCOL_TLSv1_2 (1 << 3) | ||
26 | #define TLS_PROTOCOL_TLSv1 \ | ||
27 | (TLS_PROTOCOL_TLSv1_0|TLS_PROTOCOL_TLSv1_1|TLS_PROTOCOL_TLSv1_2) | ||
28 | #define TLS_PROTOCOLS_DEFAULT TLS_PROTOCOL_TLSv1 | ||
29 | |||
30 | #define TLS_READ_AGAIN -2 | ||
31 | #define TLS_WRITE_AGAIN -3 | ||
32 | |||
33 | struct tls; | ||
34 | struct tls_config; | ||
35 | |||
36 | int tls_init(void); | ||
37 | |||
38 | const char *tls_error(struct tls *ctx); | ||
39 | |||
40 | struct tls_config *tls_config_new(void); | ||
41 | void tls_config_free(struct tls_config *config); | ||
42 | |||
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); | ||
45 | 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, | ||
47 | size_t len); | ||
48 | int tls_config_set_ciphers(struct tls_config *config, const char *ciphers); | ||
49 | int tls_config_set_ecdhcurve(struct tls_config *config, const char *name); | ||
50 | int tls_config_set_key_file(struct tls_config *config, const char *key_file); | ||
51 | int tls_config_set_key_mem(struct tls_config *config, const uint8_t *key, | ||
52 | size_t len); | ||
53 | void tls_config_set_protocols(struct tls_config *config, uint32_t protocols); | ||
54 | void tls_config_set_verify_depth(struct tls_config *config, int verify_depth); | ||
55 | |||
56 | void tls_config_clear_keys(struct tls_config *config); | ||
57 | void tls_config_insecure_noverifyhost(struct tls_config *config); | ||
58 | void tls_config_insecure_noverifycert(struct tls_config *config); | ||
59 | void tls_config_verify(struct tls_config *config); | ||
60 | |||
61 | struct tls *tls_client(void); | ||
62 | struct tls *tls_server(void); | ||
63 | int tls_configure(struct tls *ctx, struct tls_config *config); | ||
64 | void tls_reset(struct tls *ctx); | ||
65 | void tls_free(struct tls *ctx); | ||
66 | |||
67 | int tls_accept_socket(struct tls *ctx, struct tls **cctx, int socket); | ||
68 | int tls_connect(struct tls *ctx, const char *host, const char *port); | ||
69 | int tls_connect_socket(struct tls *ctx, int s, const char *hostname); | ||
70 | int tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen); | ||
71 | int tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen); | ||
72 | int tls_close(struct tls *ctx); | ||
73 | |||
74 | #endif /* HEADER_TLS_H */ | ||
diff --git a/src/lib/libressl/ressl_client.c b/src/lib/libtls/tls_client.c index 013963f3a1..853766f87b 100644 --- a/src/lib/libressl/ressl_client.c +++ b/src/lib/libtls/tls_client.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ressl_client.c,v 1.5 2014/10/03 14:14:40 tedu Exp $ */ | 1 | /* $OpenBSD: tls_client.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -26,37 +26,37 @@ | |||
26 | 26 | ||
27 | #include <openssl/x509.h> | 27 | #include <openssl/x509.h> |
28 | 28 | ||
29 | #include <ressl.h> | 29 | #include <tls.h> |
30 | #include "ressl_internal.h" | 30 | #include "tls_internal.h" |
31 | 31 | ||
32 | struct ressl * | 32 | struct tls * |
33 | ressl_client(void) | 33 | tls_client(void) |
34 | { | 34 | { |
35 | struct ressl *ctx; | 35 | struct tls *ctx; |
36 | 36 | ||
37 | if ((ctx = ressl_new()) == NULL) | 37 | if ((ctx = tls_new()) == NULL) |
38 | return (NULL); | 38 | return (NULL); |
39 | 39 | ||
40 | ctx->flags |= RESSL_CLIENT; | 40 | ctx->flags |= TLS_CLIENT; |
41 | 41 | ||
42 | return (ctx); | 42 | return (ctx); |
43 | } | 43 | } |
44 | 44 | ||
45 | int | 45 | int |
46 | ressl_connect(struct ressl *ctx, const char *host, const char *port) | 46 | tls_connect(struct tls *ctx, const char *host, const char *port) |
47 | { | 47 | { |
48 | struct addrinfo hints, *res, *res0; | 48 | struct addrinfo hints, *res, *res0; |
49 | const char *h = NULL, *p = NULL; | 49 | const char *h = NULL, *p = NULL; |
50 | char *hs = NULL, *ps = NULL; | 50 | char *hs = NULL, *ps = NULL; |
51 | int rv = -1, s = -1, ret; | 51 | int rv = -1, s = -1, ret; |
52 | 52 | ||
53 | if ((ctx->flags & RESSL_CLIENT) == 0) { | 53 | if ((ctx->flags & TLS_CLIENT) == 0) { |
54 | ressl_set_error(ctx, "not a client context"); | 54 | tls_set_error(ctx, "not a client context"); |
55 | goto err; | 55 | goto err; |
56 | } | 56 | } |
57 | 57 | ||
58 | if (host == NULL) { | 58 | if (host == NULL) { |
59 | ressl_set_error(ctx, "host not specified"); | 59 | tls_set_error(ctx, "host not specified"); |
60 | goto err; | 60 | goto err; |
61 | } | 61 | } |
62 | 62 | ||
@@ -65,9 +65,9 @@ ressl_connect(struct ressl *ctx, const char *host, const char *port) | |||
65 | * otherwise use the default. | 65 | * otherwise use the default. |
66 | */ | 66 | */ |
67 | if ((p = (char *)port) == NULL) { | 67 | if ((p = (char *)port) == NULL) { |
68 | ret = ressl_host_port(host, &hs, &ps); | 68 | ret = tls_host_port(host, &hs, &ps); |
69 | if (ret == -1) { | 69 | if (ret == -1) { |
70 | ressl_set_error(ctx, "memory allocation failure"); | 70 | tls_set_error(ctx, "memory allocation failure"); |
71 | goto err; | 71 | goto err; |
72 | } | 72 | } |
73 | if (ret != 0) | 73 | if (ret != 0) |
@@ -82,17 +82,17 @@ ressl_connect(struct ressl *ctx, const char *host, const char *port) | |||
82 | hints.ai_socktype = SOCK_STREAM; | 82 | hints.ai_socktype = SOCK_STREAM; |
83 | 83 | ||
84 | if ((ret = getaddrinfo(h, p, &hints, &res0)) != 0) { | 84 | if ((ret = getaddrinfo(h, p, &hints, &res0)) != 0) { |
85 | ressl_set_error(ctx, "%s", gai_strerror(ret)); | 85 | tls_set_error(ctx, "%s", gai_strerror(ret)); |
86 | goto err; | 86 | goto err; |
87 | } | 87 | } |
88 | for (res = res0; res; res = res->ai_next) { | 88 | for (res = res0; res; res = res->ai_next) { |
89 | s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | 89 | s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
90 | if (s == -1) { | 90 | if (s == -1) { |
91 | ressl_set_error(ctx, "socket"); | 91 | tls_set_error(ctx, "socket"); |
92 | continue; | 92 | continue; |
93 | } | 93 | } |
94 | if (connect(s, res->ai_addr, res->ai_addrlen) == -1) { | 94 | if (connect(s, res->ai_addr, res->ai_addrlen) == -1) { |
95 | ressl_set_error(ctx, "connect"); | 95 | tls_set_error(ctx, "connect"); |
96 | close(s); | 96 | close(s); |
97 | s = -1; | 97 | s = -1; |
98 | continue; | 98 | continue; |
@@ -105,7 +105,7 @@ ressl_connect(struct ressl *ctx, const char *host, const char *port) | |||
105 | if (s == -1) | 105 | if (s == -1) |
106 | goto err; | 106 | goto err; |
107 | 107 | ||
108 | if (ressl_connect_socket(ctx, s, h) != 0) { | 108 | if (tls_connect_socket(ctx, s, h) != 0) { |
109 | close(s); | 109 | close(s); |
110 | goto err; | 110 | goto err; |
111 | } | 111 | } |
@@ -121,30 +121,30 @@ err: | |||
121 | } | 121 | } |
122 | 122 | ||
123 | int | 123 | int |
124 | ressl_connect_socket(struct ressl *ctx, int socket, const char *hostname) | 124 | tls_connect_socket(struct tls *ctx, int socket, const char *hostname) |
125 | { | 125 | { |
126 | union { struct in_addr ip4; struct in6_addr ip6; } addrbuf; | 126 | union { struct in_addr ip4; struct in6_addr ip6; } addrbuf; |
127 | X509 *cert = NULL; | 127 | X509 *cert = NULL; |
128 | int ret; | 128 | int ret; |
129 | 129 | ||
130 | if ((ctx->flags & RESSL_CLIENT) == 0) { | 130 | if ((ctx->flags & TLS_CLIENT) == 0) { |
131 | ressl_set_error(ctx, "not a client context"); | 131 | tls_set_error(ctx, "not a client context"); |
132 | goto err; | 132 | goto err; |
133 | } | 133 | } |
134 | 134 | ||
135 | ctx->socket = socket; | 135 | ctx->socket = socket; |
136 | 136 | ||
137 | if ((ctx->ssl_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) { | 137 | if ((ctx->ssl_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) { |
138 | ressl_set_error(ctx, "ssl context failure"); | 138 | tls_set_error(ctx, "ssl context failure"); |
139 | goto err; | 139 | goto err; |
140 | } | 140 | } |
141 | 141 | ||
142 | if (ressl_configure_ssl(ctx) != 0) | 142 | if (tls_configure_ssl(ctx) != 0) |
143 | goto err; | 143 | goto err; |
144 | 144 | ||
145 | if (ctx->config->verify_host) { | 145 | if (ctx->config->verify_host) { |
146 | if (hostname == NULL) { | 146 | if (hostname == NULL) { |
147 | ressl_set_error(ctx, "server name not specified"); | 147 | tls_set_error(ctx, "server name not specified"); |
148 | goto err; | 148 | goto err; |
149 | } | 149 | } |
150 | } | 150 | } |
@@ -154,7 +154,7 @@ ressl_connect_socket(struct ressl *ctx, int socket, const char *hostname) | |||
154 | 154 | ||
155 | if (SSL_CTX_load_verify_locations(ctx->ssl_ctx, | 155 | if (SSL_CTX_load_verify_locations(ctx->ssl_ctx, |
156 | ctx->config->ca_file, ctx->config->ca_path) != 1) { | 156 | ctx->config->ca_file, ctx->config->ca_path) != 1) { |
157 | ressl_set_error(ctx, "ssl verify setup failure"); | 157 | tls_set_error(ctx, "ssl verify setup failure"); |
158 | goto err; | 158 | goto err; |
159 | } | 159 | } |
160 | if (ctx->config->verify_depth >= 0) | 160 | if (ctx->config->verify_depth >= 0) |
@@ -163,11 +163,11 @@ ressl_connect_socket(struct ressl *ctx, int socket, const char *hostname) | |||
163 | } | 163 | } |
164 | 164 | ||
165 | if ((ctx->ssl_conn = SSL_new(ctx->ssl_ctx)) == NULL) { | 165 | if ((ctx->ssl_conn = SSL_new(ctx->ssl_ctx)) == NULL) { |
166 | ressl_set_error(ctx, "ssl connection failure"); | 166 | tls_set_error(ctx, "ssl connection failure"); |
167 | goto err; | 167 | goto err; |
168 | } | 168 | } |
169 | if (SSL_set_fd(ctx->ssl_conn, ctx->socket) != 1) { | 169 | if (SSL_set_fd(ctx->ssl_conn, ctx->socket) != 1) { |
170 | ressl_set_error(ctx, "ssl file descriptor failure"); | 170 | tls_set_error(ctx, "ssl file descriptor failure"); |
171 | goto err; | 171 | goto err; |
172 | } | 172 | } |
173 | 173 | ||
@@ -179,13 +179,13 @@ ressl_connect_socket(struct ressl *ctx, int socket, const char *hostname) | |||
179 | inet_pton(AF_INET, hostname, &addrbuf) != 1 && | 179 | inet_pton(AF_INET, hostname, &addrbuf) != 1 && |
180 | inet_pton(AF_INET6, hostname, &addrbuf) != 1) { | 180 | inet_pton(AF_INET6, hostname, &addrbuf) != 1) { |
181 | if (SSL_set_tlsext_host_name(ctx->ssl_conn, hostname) == 0) { | 181 | if (SSL_set_tlsext_host_name(ctx->ssl_conn, hostname) == 0) { |
182 | ressl_set_error(ctx, "SNI host name failed"); | 182 | tls_set_error(ctx, "SNI host name failed"); |
183 | goto err; | 183 | goto err; |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | if ((ret = SSL_connect(ctx->ssl_conn)) != 1) { | 187 | if ((ret = SSL_connect(ctx->ssl_conn)) != 1) { |
188 | ressl_set_error(ctx, "SSL connect failed: %i", | 188 | tls_set_error(ctx, "SSL connect failed: %i", |
189 | SSL_get_error(ctx->ssl_conn, ret)); | 189 | SSL_get_error(ctx->ssl_conn, ret)); |
190 | goto err; | 190 | goto err; |
191 | } | 191 | } |
@@ -193,11 +193,11 @@ ressl_connect_socket(struct ressl *ctx, int socket, const char *hostname) | |||
193 | if (ctx->config->verify_host) { | 193 | if (ctx->config->verify_host) { |
194 | cert = SSL_get_peer_certificate(ctx->ssl_conn); | 194 | cert = SSL_get_peer_certificate(ctx->ssl_conn); |
195 | if (cert == NULL) { | 195 | if (cert == NULL) { |
196 | ressl_set_error(ctx, "no server certificate"); | 196 | tls_set_error(ctx, "no server certificate"); |
197 | goto err; | 197 | goto err; |
198 | } | 198 | } |
199 | if (ressl_check_hostname(cert, hostname) != 0) { | 199 | if (tls_check_hostname(cert, hostname) != 0) { |
200 | ressl_set_error(ctx, "host `%s' not present in" | 200 | tls_set_error(ctx, "host `%s' not present in" |
201 | " server certificate", hostname); | 201 | " server certificate", hostname); |
202 | goto err; | 202 | goto err; |
203 | } | 203 | } |
diff --git a/src/lib/libressl/ressl_config.c b/src/lib/libtls/tls_config.c index a45364c2ef..0e435f616a 100644 --- a/src/lib/libressl/ressl_config.c +++ b/src/lib/libtls/tls_config.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ressl_config.c,v 1.14 2014/10/03 14:14:40 tedu Exp $ */ | 1 | /* $OpenBSD: tls_config.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -18,8 +18,8 @@ | |||
18 | #include <errno.h> | 18 | #include <errno.h> |
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | 20 | ||
21 | #include <ressl.h> | 21 | #include <tls.h> |
22 | #include "ressl_internal.h" | 22 | #include "tls_internal.h" |
23 | 23 | ||
24 | static int | 24 | static int |
25 | set_string(const char **dest, const char *src) | 25 | set_string(const char **dest, const char *src) |
@@ -56,10 +56,10 @@ set_mem(char **dest, size_t *destlen, const void *src, size_t srclen) | |||
56 | return 0; | 56 | return 0; |
57 | } | 57 | } |
58 | 58 | ||
59 | struct ressl_config * | 59 | struct tls_config * |
60 | ressl_config_new(void) | 60 | tls_config_new(void) |
61 | { | 61 | { |
62 | struct ressl_config *config; | 62 | struct tls_config *config; |
63 | 63 | ||
64 | if ((config = calloc(1, sizeof(*config))) == NULL) | 64 | if ((config = calloc(1, sizeof(*config))) == NULL) |
65 | return (NULL); | 65 | return (NULL); |
@@ -67,26 +67,26 @@ ressl_config_new(void) | |||
67 | /* | 67 | /* |
68 | * Default configuration. | 68 | * Default configuration. |
69 | */ | 69 | */ |
70 | if (ressl_config_set_ca_file(config, _PATH_SSL_CA_FILE) != 0) { | 70 | if (tls_config_set_ca_file(config, _PATH_SSL_CA_FILE) != 0) { |
71 | ressl_config_free(config); | 71 | tls_config_free(config); |
72 | return (NULL); | 72 | return (NULL); |
73 | } | 73 | } |
74 | ressl_config_set_ecdhcurve(config, "auto"); | 74 | tls_config_set_ecdhcurve(config, "auto"); |
75 | ressl_config_set_protocols(config, RESSL_PROTOCOLS_DEFAULT); | 75 | tls_config_set_protocols(config, TLS_PROTOCOLS_DEFAULT); |
76 | ressl_config_set_verify_depth(config, 6); | 76 | tls_config_set_verify_depth(config, 6); |
77 | 77 | ||
78 | ressl_config_verify(config); | 78 | tls_config_verify(config); |
79 | 79 | ||
80 | return (config); | 80 | return (config); |
81 | } | 81 | } |
82 | 82 | ||
83 | void | 83 | void |
84 | ressl_config_free(struct ressl_config *config) | 84 | tls_config_free(struct tls_config *config) |
85 | { | 85 | { |
86 | if (config == NULL) | 86 | if (config == NULL) |
87 | return; | 87 | return; |
88 | 88 | ||
89 | ressl_config_clear_keys(config); | 89 | tls_config_clear_keys(config); |
90 | 90 | ||
91 | free((char *)config->ca_file); | 91 | free((char *)config->ca_file); |
92 | free((char *)config->ca_path); | 92 | free((char *)config->ca_path); |
@@ -100,45 +100,45 @@ ressl_config_free(struct ressl_config *config) | |||
100 | } | 100 | } |
101 | 101 | ||
102 | void | 102 | void |
103 | ressl_config_clear_keys(struct ressl_config *config) | 103 | tls_config_clear_keys(struct tls_config *config) |
104 | { | 104 | { |
105 | ressl_config_set_cert_mem(config, NULL, 0); | 105 | tls_config_set_cert_mem(config, NULL, 0); |
106 | ressl_config_set_key_mem(config, NULL, 0); | 106 | tls_config_set_key_mem(config, NULL, 0); |
107 | } | 107 | } |
108 | 108 | ||
109 | int | 109 | int |
110 | ressl_config_set_ca_file(struct ressl_config *config, const char *ca_file) | 110 | tls_config_set_ca_file(struct tls_config *config, const char *ca_file) |
111 | { | 111 | { |
112 | return set_string(&config->ca_file, ca_file); | 112 | return set_string(&config->ca_file, ca_file); |
113 | } | 113 | } |
114 | 114 | ||
115 | int | 115 | int |
116 | ressl_config_set_ca_path(struct ressl_config *config, const char *ca_path) | 116 | tls_config_set_ca_path(struct tls_config *config, const char *ca_path) |
117 | { | 117 | { |
118 | return set_string(&config->ca_path, ca_path); | 118 | return set_string(&config->ca_path, ca_path); |
119 | } | 119 | } |
120 | 120 | ||
121 | int | 121 | int |
122 | ressl_config_set_cert_file(struct ressl_config *config, const char *cert_file) | 122 | tls_config_set_cert_file(struct tls_config *config, const char *cert_file) |
123 | { | 123 | { |
124 | return set_string(&config->cert_file, cert_file); | 124 | return set_string(&config->cert_file, cert_file); |
125 | } | 125 | } |
126 | 126 | ||
127 | int | 127 | int |
128 | ressl_config_set_cert_mem(struct ressl_config *config, const uint8_t *cert, | 128 | tls_config_set_cert_mem(struct tls_config *config, const uint8_t *cert, |
129 | size_t len) | 129 | size_t len) |
130 | { | 130 | { |
131 | return set_mem(&config->cert_mem, &config->cert_len, cert, len); | 131 | return set_mem(&config->cert_mem, &config->cert_len, cert, len); |
132 | } | 132 | } |
133 | 133 | ||
134 | int | 134 | int |
135 | ressl_config_set_ciphers(struct ressl_config *config, const char *ciphers) | 135 | tls_config_set_ciphers(struct tls_config *config, const char *ciphers) |
136 | { | 136 | { |
137 | return set_string(&config->ciphers, ciphers); | 137 | return set_string(&config->ciphers, ciphers); |
138 | } | 138 | } |
139 | 139 | ||
140 | int | 140 | int |
141 | ressl_config_set_ecdhcurve(struct ressl_config *config, const char *name) | 141 | tls_config_set_ecdhcurve(struct tls_config *config, const char *name) |
142 | { | 142 | { |
143 | int nid; | 143 | int nid; |
144 | 144 | ||
@@ -155,13 +155,13 @@ ressl_config_set_ecdhcurve(struct ressl_config *config, const char *name) | |||
155 | } | 155 | } |
156 | 156 | ||
157 | int | 157 | int |
158 | ressl_config_set_key_file(struct ressl_config *config, const char *key_file) | 158 | tls_config_set_key_file(struct tls_config *config, const char *key_file) |
159 | { | 159 | { |
160 | return set_string(&config->key_file, key_file); | 160 | return set_string(&config->key_file, key_file); |
161 | } | 161 | } |
162 | 162 | ||
163 | int | 163 | int |
164 | ressl_config_set_key_mem(struct ressl_config *config, const uint8_t *key, | 164 | tls_config_set_key_mem(struct tls_config *config, const uint8_t *key, |
165 | size_t len) | 165 | size_t len) |
166 | { | 166 | { |
167 | if (config->key_mem) | 167 | if (config->key_mem) |
@@ -170,31 +170,31 @@ ressl_config_set_key_mem(struct ressl_config *config, const uint8_t *key, | |||
170 | } | 170 | } |
171 | 171 | ||
172 | void | 172 | void |
173 | ressl_config_set_protocols(struct ressl_config *config, uint32_t protocols) | 173 | tls_config_set_protocols(struct tls_config *config, uint32_t protocols) |
174 | { | 174 | { |
175 | config->protocols = protocols; | 175 | config->protocols = protocols; |
176 | } | 176 | } |
177 | 177 | ||
178 | void | 178 | void |
179 | ressl_config_set_verify_depth(struct ressl_config *config, int verify_depth) | 179 | tls_config_set_verify_depth(struct tls_config *config, int verify_depth) |
180 | { | 180 | { |
181 | config->verify_depth = verify_depth; | 181 | config->verify_depth = verify_depth; |
182 | } | 182 | } |
183 | 183 | ||
184 | void | 184 | void |
185 | ressl_config_insecure_noverifyhost(struct ressl_config *config) | 185 | tls_config_insecure_noverifyhost(struct tls_config *config) |
186 | { | 186 | { |
187 | config->verify_host = 0; | 187 | config->verify_host = 0; |
188 | } | 188 | } |
189 | 189 | ||
190 | void | 190 | void |
191 | ressl_config_insecure_noverifycert(struct ressl_config *config) | 191 | tls_config_insecure_noverifycert(struct tls_config *config) |
192 | { | 192 | { |
193 | config->verify_cert = 0; | 193 | config->verify_cert = 0; |
194 | } | 194 | } |
195 | 195 | ||
196 | void | 196 | void |
197 | ressl_config_verify(struct ressl_config *config) | 197 | tls_config_verify(struct tls_config *config) |
198 | { | 198 | { |
199 | config->verify_host = 1; | 199 | config->verify_host = 1; |
200 | config->verify_cert = 1; | 200 | config->verify_cert = 1; |
diff --git a/src/lib/libressl/ressl_init.3 b/src/lib/libtls/tls_init.3 index 81a32350ee..faa9b99539 100644 --- a/src/lib/libressl/ressl_init.3 +++ b/src/lib/libtls/tls_init.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: ressl_init.3,v 1.9 2014/10/16 12:46:35 tedu Exp $ | 1 | .\" $OpenBSD: tls_init.3,v 1.1 2014/10/31 13:46:17 jsing Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
4 | .\" | 4 | .\" |
@@ -14,167 +14,167 @@ | |||
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: October 16 2014 $ | 17 | .Dd $Mdocdate: October 31 2014 $ |
18 | .Dt RESSL 3 | 18 | .Dt TLS 3 |
19 | .Os | 19 | .Os |
20 | .Sh NAME | 20 | .Sh NAME |
21 | .Nm ressl_init , | 21 | .Nm tls_init , |
22 | .Nm ressl_error , | 22 | .Nm tls_error , |
23 | .Nm ressl_config_new , | 23 | .Nm tls_config_new , |
24 | .Nm ressl_config_free , | 24 | .Nm tls_config_free , |
25 | .Nm ressl_config_set_ca_file , | 25 | .Nm tls_config_set_ca_file , |
26 | .Nm ressl_config_set_ca_path , | 26 | .Nm tls_config_set_ca_path , |
27 | .Nm ressl_config_set_cert_file , | 27 | .Nm tls_config_set_cert_file , |
28 | .Nm ressl_config_set_cert_mem , | 28 | .Nm tls_config_set_cert_mem , |
29 | .Nm ressl_config_set_ciphers , | 29 | .Nm tls_config_set_ciphers , |
30 | .Nm ressl_config_set_ecdhcurve , | 30 | .Nm tls_config_set_ecdhcurve , |
31 | .Nm ressl_config_set_key_file , | 31 | .Nm tls_config_set_key_file , |
32 | .Nm ressl_config_set_key_mem , | 32 | .Nm tls_config_set_key_mem , |
33 | .Nm ressl_config_set_protocols , | 33 | .Nm tls_config_set_protocols , |
34 | .Nm ressl_config_set_verify_depth , | 34 | .Nm tls_config_set_verify_depth , |
35 | .Nm ressl_config_clear_keys , | 35 | .Nm tls_config_clear_keys , |
36 | .Nm ressl_config_insecure_noverifyhost , | 36 | .Nm tls_config_insecure_noverifyhost , |
37 | .Nm ressl_config_insecure_noverifycert , | 37 | .Nm tls_config_insecure_noverifycert , |
38 | .Nm ressl_config_verify , | 38 | .Nm tls_config_verify , |
39 | .Nm ressl_client , | 39 | .Nm tls_client , |
40 | .Nm ressl_server , | 40 | .Nm tls_server , |
41 | .Nm ressl_configure , | 41 | .Nm tls_configure , |
42 | .Nm ressl_reset , | 42 | .Nm tls_reset , |
43 | .Nm ressl_close , | 43 | .Nm tls_close , |
44 | .Nm ressl_free , | 44 | .Nm tls_free , |
45 | .Nm ressl_connect , | 45 | .Nm tls_connect , |
46 | .Nm ressl_connect_socket , | 46 | .Nm tls_connect_socket , |
47 | .Nm ressl_read , | 47 | .Nm tls_read , |
48 | .Nm ressl_write , | 48 | .Nm tls_write , |
49 | .Nd ressl TLS client and server API | 49 | .Nd tls TLS client and server API |
50 | .Sh SYNOPSIS | 50 | .Sh SYNOPSIS |
51 | .In ressl.h | 51 | .In tls.h |
52 | .Ft "int" | 52 | .Ft "int" |
53 | .Fn ressl_init "void" | 53 | .Fn tls_init "void" |
54 | .Ft "const char *" | 54 | .Ft "const char *" |
55 | .Fn ressl_error "struct ressl *ctx" | 55 | .Fn tls_error "struct tls *ctx" |
56 | .Ft "struct ressl_config *" | 56 | .Ft "struct tls_config *" |
57 | .Fn ressl_config_new "void" | 57 | .Fn tls_config_new "void" |
58 | .Ft "void" | 58 | .Ft "void" |
59 | .Fn ressl_config_free "struct ressl_config *config" | 59 | .Fn tls_config_free "struct tls_config *config" |
60 | .Ft "int" | 60 | .Ft "int" |
61 | .Fn ressl_config_set_ca_file "struct ressl_config *config" "const char *ca_file" | 61 | .Fn tls_config_set_ca_file "struct tls_config *config" "const char *ca_file" |
62 | .Ft "int" | 62 | .Ft "int" |
63 | .Fn ressl_config_set_ca_path "struct ressl_config *config" "const char *ca_path" | 63 | .Fn tls_config_set_ca_path "struct tls_config *config" "const char *ca_path" |
64 | .Ft "int" | 64 | .Ft "int" |
65 | .Fn ressl_config_set_cert_file "struct ressl_config *config" "const char *cert_file" | 65 | .Fn tls_config_set_cert_file "struct tls_config *config" "const char *cert_file" |
66 | .Ft "int" | 66 | .Ft "int" |
67 | .Fn ressl_config_set_cert_mem "struct ressl_config *config" "const uint8_t *cert" "size_t len" | 67 | .Fn tls_config_set_cert_mem "struct tls_config *config" "const uint8_t *cert" "size_t len" |
68 | .Ft "int" | 68 | .Ft "int" |
69 | .Fn ressl_config_set_ciphers "struct ressl_config *config" "const char *ciphers" | 69 | .Fn tls_config_set_ciphers "struct tls_config *config" "const char *ciphers" |
70 | .Ft "int" | 70 | .Ft "int" |
71 | .Fn ressl_config_set_ecdhcurve "struct ressl_config *config" "const char *name" | 71 | .Fn tls_config_set_ecdhcurve "struct tls_config *config" "const char *name" |
72 | .Ft "int" | 72 | .Ft "int" |
73 | .Fn ressl_config_set_key_file "struct ressl_config *config" "const char *key_file" | 73 | .Fn tls_config_set_key_file "struct tls_config *config" "const char *key_file" |
74 | .Ft "int" | 74 | .Ft "int" |
75 | .Fn ressl_config_set_key_mem "struct ressl_config *config" "const uint8_t *key" "size_t len" | 75 | .Fn tls_config_set_key_mem "struct tls_config *config" "const uint8_t *key" "size_t len" |
76 | .Ft "int" | 76 | .Ft "int" |
77 | .Fn ressl_config_set_protocols "struct ressl_config *config" "uint32_t protocols" | 77 | .Fn tls_config_set_protocols "struct tls_config *config" "uint32_t protocols" |
78 | .Ft "int" | 78 | .Ft "int" |
79 | .Fn ressl_config_set_verify_depth "struct ressl_config *config" "int verify_depth" | 79 | .Fn tls_config_set_verify_depth "struct tls_config *config" "int verify_depth" |
80 | .Ft "void" | 80 | .Ft "void" |
81 | .Fn ressl_config_clear_keys "struct ressl_config *config" | 81 | .Fn tls_config_clear_keys "struct tls_config *config" |
82 | .Ft "void" | 82 | .Ft "void" |
83 | .Fn ressl_config_insecure_noverifyhost "struct ressl_config *config" | 83 | .Fn tls_config_insecure_noverifyhost "struct tls_config *config" |
84 | .Ft "void" | 84 | .Ft "void" |
85 | .Fn ressl_config_insecure_noverifycert "struct ressl_config *config" | 85 | .Fn tls_config_insecure_noverifycert "struct tls_config *config" |
86 | .Ft "void" | 86 | .Ft "void" |
87 | .Fn ressl_config_verify "struct ressl_config *config" | 87 | .Fn tls_config_verify "struct tls_config *config" |
88 | .Ft "struct ressl *" | 88 | .Ft "struct tls *" |
89 | .Fn ressl_client void | 89 | .Fn tls_client void |
90 | .Ft "struct ressl *" | 90 | .Ft "struct tls *" |
91 | .Fn ressl_server void | 91 | .Fn tls_server void |
92 | .Ft "int" | 92 | .Ft "int" |
93 | .Fn ressl_configure "struct ressl *ctx" "struct ressl_config *config" | 93 | .Fn tls_configure "struct tls *ctx" "struct tls_config *config" |
94 | .Ft "void" | 94 | .Ft "void" |
95 | .Fn ressl_reset "struct ressl *ctx" | 95 | .Fn tls_reset "struct tls *ctx" |
96 | .Ft "int" | 96 | .Ft "int" |
97 | .Fn ressl_close "struct ressl *ctx" | 97 | .Fn tls_close "struct tls *ctx" |
98 | .Ft "void" | 98 | .Ft "void" |
99 | .Fn ressl_free "struct ressl *ctx" | 99 | .Fn tls_free "struct tls *ctx" |
100 | .Ft "int" | 100 | .Ft "int" |
101 | .Fn ressl_connect "struct ressl *ctx" "const char *host" "const char *port" | 101 | .Fn tls_connect "struct tls *ctx" "const char *host" "const char *port" |
102 | .Ft "int" | 102 | .Ft "int" |
103 | .Fn ressl_connect_socket "struct ressl *ctx" "int s" "const char *hostname" | 103 | .Fn tls_connect_socket "struct tls *ctx" "int s" "const char *hostname" |
104 | .Ft "int" | 104 | .Ft "int" |
105 | .Fn ressl_read "struct ressl *ctx" "void *buf" "size_t buflen" "size_t *outlen" | 105 | .Fn tls_read "struct tls *ctx" "void *buf" "size_t buflen" "size_t *outlen" |
106 | .Ft "int" | 106 | .Ft "int" |
107 | .Fn ressl_write "struct ressl *ctx" "const void *buf" "size_t buflen" | 107 | .Fn tls_write "struct tls *ctx" "const void *buf" "size_t buflen" |
108 | .Sh DESCRIPTION | 108 | .Sh DESCRIPTION |
109 | The | 109 | The |
110 | .Nm ressl | 110 | .Nm tls |
111 | family of functions establishes a secure communications channel | 111 | family of functions establishes a secure communications channel |
112 | using the TLS socket protocol. | 112 | using the TLS socket protocol. |
113 | Both clients and servers are supported. | 113 | Both clients and servers are supported. |
114 | .Pp | 114 | .Pp |
115 | The | 115 | The |
116 | .Fn ressl_init | 116 | .Fn tls_init |
117 | function should be called once before any function is used. | 117 | function should be called once before any function is used. |
118 | .Pp | 118 | .Pp |
119 | Before a connection is created, a configuration must be created. | 119 | Before a connection is created, a configuration must be created. |
120 | The | 120 | The |
121 | .Fn ressl_config_new | 121 | .Fn tls_config_new |
122 | function returns a new default configuration that can be used for future | 122 | function returns a new default configuration that can be used for future |
123 | connections. | 123 | connections. |
124 | Several functions exist to change the options of the configuration; see below. | 124 | Several functions exist to change the options of the configuration; see below. |
125 | .Pp | 125 | .Pp |
126 | A | 126 | A |
127 | .Em ressl | 127 | .Em tls |
128 | connection is represented as a | 128 | connection is represented as a |
129 | .Em context . | 129 | .Em context . |
130 | A new | 130 | A new |
131 | .Em context | 131 | .Em context |
132 | is created by either the | 132 | is created by either the |
133 | .Fn ressl_client | 133 | .Fn tls_client |
134 | or | 134 | or |
135 | .Fn ressl_server | 135 | .Fn tls_server |
136 | functions. | 136 | functions. |
137 | The context can then be configured with the function | 137 | The context can then be configured with the function |
138 | .Fn ressl_configure . | 138 | .Fn tls_configure . |
139 | The same | 139 | The same |
140 | .Em ressl_config | 140 | .Em tls_config |
141 | object can be used to configure multiple contexts. | 141 | object can be used to configure multiple contexts. |
142 | .Pp | 142 | .Pp |
143 | A client connection is initiated after configuration by calling | 143 | A client connection is initiated after configuration by calling |
144 | .Fn ressl_connect . | 144 | .Fn tls_connect . |
145 | This function will create a new socket, connect to the specified host and | 145 | This function will create a new socket, connect to the specified host and |
146 | port, and then establish a secure connection. | 146 | port, and then establish a secure connection. |
147 | An already existing socket can be upgraded to a secure connection by calling | 147 | An already existing socket can be upgraded to a secure connection by calling |
148 | .Fn ressl_connect_socket . | 148 | .Fn tls_connect_socket . |
149 | .Pp | 149 | .Pp |
150 | Two functions are provided for input and output, | 150 | Two functions are provided for input and output, |
151 | .Fn ressl_read | 151 | .Fn tls_read |
152 | and | 152 | and |
153 | .Fn ressl_write . | 153 | .Fn tls_write . |
154 | .Pp | 154 | .Pp |
155 | After use, a ressl | 155 | After use, a tls |
156 | .Em context | 156 | .Em context |
157 | should be closed with | 157 | should be closed with |
158 | .Fn ressl_close , | 158 | .Fn tls_close , |
159 | and then freed by calling | 159 | and then freed by calling |
160 | .Fn ressl_free . | 160 | .Fn tls_free . |
161 | When no more contexts are to be created, the | 161 | When no more contexts are to be created, the |
162 | .Em ressl_config | 162 | .Em tls_config |
163 | object should be freed by calling | 163 | object should be freed by calling |
164 | .Fn ressl_config_free . | 164 | .Fn tls_config_free . |
165 | .Sh FUNCTIONS | 165 | .Sh FUNCTIONS |
166 | The | 166 | The |
167 | .Fn ressl_init | 167 | .Fn tls_init |
168 | function initializes global data structures. | 168 | function initializes global data structures. |
169 | It should be called once before any other functions. | 169 | It should be called once before any other functions. |
170 | .Pp | 170 | .Pp |
171 | The following functions create and free configuration objects. | 171 | The following functions create and free configuration objects. |
172 | .Bl -bullet -offset four | 172 | .Bl -bullet -offset four |
173 | .It | 173 | .It |
174 | .Fn ressl_config_new | 174 | .Fn tls_config_new |
175 | allocates a new default configuration object. | 175 | allocates a new default configuration object. |
176 | .It | 176 | .It |
177 | .Fn ressl_config_free | 177 | .Fn tls_config_free |
178 | frees a configuration object. | 178 | frees a configuration object. |
179 | .El | 179 | .El |
180 | .Pp | 180 | .Pp |
@@ -182,68 +182,68 @@ The following functions modify a configuration by setting parameters. | |||
182 | Configuration options may apply to only clients or only servers or both. | 182 | Configuration options may apply to only clients or only servers or both. |
183 | .Bl -bullet -offset four | 183 | .Bl -bullet -offset four |
184 | .It | 184 | .It |
185 | .Fn ressl_config_set_ca_file | 185 | .Fn tls_config_set_ca_file |
186 | sets the filename used to load a file | 186 | sets the filename used to load a file |
187 | containing the root certificates. | 187 | containing the root certificates. |
188 | .Em (Client) | 188 | .Em (Client) |
189 | .It | 189 | .It |
190 | .Fn ressl_config_set_ca_path | 190 | .Fn tls_config_set_ca_path |
191 | sets the path (directory) which should be searched for root | 191 | sets the path (directory) which should be searched for root |
192 | certificates. | 192 | certificates. |
193 | .Em (Client) | 193 | .Em (Client) |
194 | .It | 194 | .It |
195 | .Fn ressl_config_set_cert_file | 195 | .Fn tls_config_set_cert_file |
196 | sets file from which the public certificate will be read. | 196 | sets file from which the public certificate will be read. |
197 | .Em (Client and server) | 197 | .Em (Client and server) |
198 | .It | 198 | .It |
199 | .Fn ressl_config_set_cert_mem | 199 | .Fn tls_config_set_cert_mem |
200 | sets the public certificate directly from memory. | 200 | sets the public certificate directly from memory. |
201 | .Em (Client and server) | 201 | .Em (Client and server) |
202 | .It | 202 | .It |
203 | .Fn ressl_config_set_ciphers | 203 | .Fn tls_config_set_ciphers |
204 | sets the list of ciphers that may be used. | 204 | sets the list of ciphers that may be used. |
205 | .Em (Client and server) | 205 | .Em (Client and server) |
206 | .It | 206 | .It |
207 | .Fn ressl_config_set_key_file | 207 | .Fn tls_config_set_key_file |
208 | sets the file from which the private key will be read. | 208 | sets the file from which the private key will be read. |
209 | .Em (Server) | 209 | .Em (Server) |
210 | .It | 210 | .It |
211 | .Fn ressl_config_set_key_mem | 211 | .Fn tls_config_set_key_mem |
212 | directly sets the private key from memory. | 212 | directly sets the private key from memory. |
213 | .Em (Server) | 213 | .Em (Server) |
214 | .It | 214 | .It |
215 | .Fn ressl_config_set_protocols | 215 | .Fn tls_config_set_protocols |
216 | sets which versions of the protocol may be used. | 216 | sets which versions of the protocol may be used. |
217 | Possible values are the bitwise OR of: | 217 | Possible values are the bitwise OR of: |
218 | .Pp | 218 | .Pp |
219 | .Bl -tag -width "RESSL_PROTOCOL_TLSv1_2" -offset indent -compact | 219 | .Bl -tag -width "TLS_PROTOCOL_TLSv1_2" -offset indent -compact |
220 | .It Dv RESSL_PROTOCOL_TLSv1_0 | 220 | .It Dv TLS_PROTOCOL_TLSv1_0 |
221 | .It Dv RESSL_PROTOCOL_TLSv1_1 | 221 | .It Dv TLS_PROTOCOL_TLSv1_1 |
222 | .It Dv RESSL_PROTOCOL_TLSv1_2 | 222 | .It Dv TLS_PROTOCOL_TLSv1_2 |
223 | .El | 223 | .El |
224 | .Pp | 224 | .Pp |
225 | Additionally, the values | 225 | Additionally, the values |
226 | .Dv RESSL_PROTOCOL_TLSv1 | 226 | .Dv TLS_PROTOCOL_TLSv1 |
227 | (all TLS versions) and | 227 | (all TLS versions) and |
228 | .Dv RESSL_PROTOCOLS_DEFAULT | 228 | .Dv TLS_PROTOCOLS_DEFAULT |
229 | (currently all TLS versions) may be used. | 229 | (currently all TLS versions) may be used. |
230 | .Em (Client and server) | 230 | .Em (Client and server) |
231 | .It | 231 | .It |
232 | .Fn ressl_config_clear_keys | 232 | .Fn tls_config_clear_keys |
233 | clears any secret keys from memory. | 233 | clears any secret keys from memory. |
234 | .Em (Server) | 234 | .Em (Server) |
235 | .It | 235 | .It |
236 | .Fn ressl_config_insecure_noverifyhost | 236 | .Fn tls_config_insecure_noverifyhost |
237 | disables hostname verification. | 237 | disables hostname verification. |
238 | Be careful when using this option. | 238 | Be careful when using this option. |
239 | .Em (Client) | 239 | .Em (Client) |
240 | .It | 240 | .It |
241 | .Fn ressl_config_insecure_noverifycert | 241 | .Fn tls_config_insecure_noverifycert |
242 | disables certificate verification. | 242 | disables certificate verification. |
243 | Be extremely careful when using this option. | 243 | Be extremely careful when using this option. |
244 | .Em (Client) | 244 | .Em (Client) |
245 | .It | 245 | .It |
246 | .Fn ressl_config_verify | 246 | .Fn tls_config_verify |
247 | reenables hostname and certificate verification. | 247 | reenables hostname and certificate verification. |
248 | .Em (Client) | 248 | .Em (Client) |
249 | .El | 249 | .El |
@@ -251,28 +251,28 @@ reenables hostname and certificate verification. | |||
251 | The following functions create, prepare, and free a connection context. | 251 | The following functions create, prepare, and free a connection context. |
252 | .Bl -bullet -offset four | 252 | .Bl -bullet -offset four |
253 | .It | 253 | .It |
254 | .Fn ressl_client | 254 | .Fn tls_client |
255 | creates a new ressl context for client connections. | 255 | creates a new tls context for client connections. |
256 | .It | 256 | .It |
257 | .Fn ressl_server | 257 | .Fn tls_server |
258 | creates a new ressl context for server connections. | 258 | creates a new tls context for server connections. |
259 | .It | 259 | .It |
260 | .Fn ressl_configure | 260 | .Fn tls_configure |
261 | readies a ressl context for use by applying the configuration | 261 | readies a tls context for use by applying the configuration |
262 | options. | 262 | options. |
263 | .It | 263 | .It |
264 | .Fn ressl_close | 264 | .Fn tls_close |
265 | closes a connection after use. | 265 | closes a connection after use. |
266 | .It | 266 | .It |
267 | .Fn ressl_free | 267 | .Fn tls_free |
268 | frees a ressl context after use. | 268 | frees a tls context after use. |
269 | .El | 269 | .El |
270 | .Pp | 270 | .Pp |
271 | The following functions initiate a connection and perform input and output | 271 | The following functions initiate a connection and perform input and output |
272 | operations. | 272 | operations. |
273 | .Bl -bullet -offset four | 273 | .Bl -bullet -offset four |
274 | .It | 274 | .It |
275 | .Fn ressl_connect | 275 | .Fn tls_connect |
276 | connects a client context to the server named by | 276 | connects a client context to the server named by |
277 | .Fa host . | 277 | .Fa host . |
278 | The | 278 | The |
@@ -280,10 +280,10 @@ The | |||
280 | may be numeric or a service name. | 280 | may be numeric or a service name. |
281 | If it is NULL then a host of the format "hostname:port" is permitted. | 281 | If it is NULL then a host of the format "hostname:port" is permitted. |
282 | .It | 282 | .It |
283 | .Fn ressl_connect_socket | 283 | .Fn tls_connect_socket |
284 | connects a client context to an already established socket connection. | 284 | connects a client context to an already established socket connection. |
285 | .It | 285 | .It |
286 | .Fn ressl_read | 286 | .Fn tls_read |
287 | reads | 287 | reads |
288 | .Fa buflen | 288 | .Fa buflen |
289 | bytes of data from the socket into | 289 | bytes of data from the socket into |
@@ -291,7 +291,7 @@ bytes of data from the socket into | |||
291 | The amount of data read is returned in | 291 | The amount of data read is returned in |
292 | .Fa outlen . | 292 | .Fa outlen . |
293 | .It | 293 | .It |
294 | .Fn ressl_write | 294 | .Fn tls_write |
295 | writes | 295 | writes |
296 | .Fa buflen | 296 | .Fa buflen |
297 | bytes of data from | 297 | bytes of data from |
@@ -309,7 +309,7 @@ Functions that return a pointer will return NULL on error. | |||
309 | .\" .Sh SEE ALSO | 309 | .\" .Sh SEE ALSO |
310 | .Sh HISTORY | 310 | .Sh HISTORY |
311 | The | 311 | The |
312 | .Nm ressl | 312 | .Nm tls |
313 | API first appeared in | 313 | API first appeared in |
314 | .Ox 5.6 | 314 | .Ox 5.6 |
315 | as a response to the unnecessary challenges other APIs present in | 315 | as a response to the unnecessary challenges other APIs present in |
diff --git a/src/lib/libressl/ressl_internal.h b/src/lib/libtls/tls_internal.h index b752b5fd88..da696e228d 100644 --- a/src/lib/libressl/ressl_internal.h +++ b/src/lib/libtls/tls_internal.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ressl_internal.h,v 1.12 2014/10/03 14:14:40 tedu Exp $ */ | 1 | /* $OpenBSD: tls_internal.h,v 1.1 2014/10/31 13:46:17 jsing 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> |
@@ -16,8 +16,8 @@ | |||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #ifndef HEADER_RESSL_INTERNAL_H | 19 | #ifndef HEADER_TLS_INTERNAL_H |
20 | #define HEADER_RESSL_INTERNAL_H | 20 | #define HEADER_TLS_INTERNAL_H |
21 | 21 | ||
22 | #include <openssl/ssl.h> | 22 | #include <openssl/ssl.h> |
23 | 23 | ||
@@ -25,7 +25,7 @@ | |||
25 | 25 | ||
26 | #define _PATH_SSL_CA_FILE "/etc/ssl/cert.pem" | 26 | #define _PATH_SSL_CA_FILE "/etc/ssl/cert.pem" |
27 | 27 | ||
28 | struct ressl_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 | const char *cert_file; | 31 | const char *cert_file; |
@@ -42,12 +42,12 @@ struct ressl_config { | |||
42 | int verify_depth; | 42 | int verify_depth; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | #define RESSL_CLIENT (1 << 0) | 45 | #define TLS_CLIENT (1 << 0) |
46 | #define RESSL_SERVER (1 << 1) | 46 | #define TLS_SERVER (1 << 1) |
47 | #define RESSL_SERVER_CONN (1 << 2) | 47 | #define TLS_SERVER_CONN (1 << 2) |
48 | 48 | ||
49 | struct ressl { | 49 | struct tls { |
50 | struct ressl_config *config; | 50 | struct tls_config *config; |
51 | uint64_t flags; | 51 | uint64_t flags; |
52 | 52 | ||
53 | int err; | 53 | int err; |
@@ -59,14 +59,14 @@ struct ressl { | |||
59 | SSL_CTX *ssl_ctx; | 59 | SSL_CTX *ssl_ctx; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | struct ressl *ressl_new(void); | 62 | struct tls *tls_new(void); |
63 | struct ressl *ressl_server_conn(struct ressl *ctx); | 63 | struct tls *tls_server_conn(struct tls *ctx); |
64 | 64 | ||
65 | int ressl_check_hostname(X509 *cert, const char *host); | 65 | int tls_check_hostname(X509 *cert, const char *host); |
66 | int ressl_configure_keypair(struct ressl *ctx); | 66 | int tls_configure_keypair(struct tls *ctx); |
67 | int ressl_configure_server(struct ressl *ctx); | 67 | int tls_configure_server(struct tls *ctx); |
68 | int ressl_configure_ssl(struct ressl *ctx); | 68 | int tls_configure_ssl(struct tls *ctx); |
69 | int ressl_host_port(const char *hostport, char **host, char **port); | 69 | int tls_host_port(const char *hostport, char **host, char **port); |
70 | int ressl_set_error(struct ressl *ctx, char *fmt, ...); | 70 | int tls_set_error(struct tls *ctx, char *fmt, ...); |
71 | 71 | ||
72 | #endif /* HEADER_RESSL_INTERNAL_H */ | 72 | #endif /* HEADER_TLS_INTERNAL_H */ |
diff --git a/src/lib/libressl/ressl_server.c b/src/lib/libtls/tls_server.c index 4783674a0b..001f19ded4 100644 --- a/src/lib/libressl/ressl_server.c +++ b/src/lib/libtls/tls_server.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ressl_server.c,v 1.11 2014/10/15 14:08:26 jsing Exp $ */ | 1 | /* $OpenBSD: tls_server.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -18,48 +18,48 @@ | |||
18 | #include <openssl/ec.h> | 18 | #include <openssl/ec.h> |
19 | #include <openssl/ssl.h> | 19 | #include <openssl/ssl.h> |
20 | 20 | ||
21 | #include <ressl.h> | 21 | #include <tls.h> |
22 | #include "ressl_internal.h" | 22 | #include "tls_internal.h" |
23 | 23 | ||
24 | struct ressl * | 24 | struct tls * |
25 | ressl_server(void) | 25 | tls_server(void) |
26 | { | 26 | { |
27 | struct ressl *ctx; | 27 | struct tls *ctx; |
28 | 28 | ||
29 | if ((ctx = ressl_new()) == NULL) | 29 | if ((ctx = tls_new()) == NULL) |
30 | return (NULL); | 30 | return (NULL); |
31 | 31 | ||
32 | ctx->flags |= RESSL_SERVER; | 32 | ctx->flags |= TLS_SERVER; |
33 | 33 | ||
34 | return (ctx); | 34 | return (ctx); |
35 | } | 35 | } |
36 | 36 | ||
37 | struct ressl * | 37 | struct tls * |
38 | ressl_server_conn(struct ressl *ctx) | 38 | tls_server_conn(struct tls *ctx) |
39 | { | 39 | { |
40 | struct ressl *conn_ctx; | 40 | struct tls *conn_ctx; |
41 | 41 | ||
42 | if ((conn_ctx = ressl_new()) == NULL) | 42 | if ((conn_ctx = tls_new()) == NULL) |
43 | return (NULL); | 43 | return (NULL); |
44 | 44 | ||
45 | conn_ctx->flags |= RESSL_SERVER_CONN; | 45 | conn_ctx->flags |= TLS_SERVER_CONN; |
46 | 46 | ||
47 | return (conn_ctx); | 47 | return (conn_ctx); |
48 | } | 48 | } |
49 | 49 | ||
50 | int | 50 | int |
51 | ressl_configure_server(struct ressl *ctx) | 51 | tls_configure_server(struct tls *ctx) |
52 | { | 52 | { |
53 | EC_KEY *ecdh_key; | 53 | EC_KEY *ecdh_key; |
54 | 54 | ||
55 | if ((ctx->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) { | 55 | if ((ctx->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) { |
56 | ressl_set_error(ctx, "ssl context failure"); | 56 | tls_set_error(ctx, "ssl context failure"); |
57 | goto err; | 57 | goto err; |
58 | } | 58 | } |
59 | 59 | ||
60 | if (ressl_configure_ssl(ctx) != 0) | 60 | if (tls_configure_ssl(ctx) != 0) |
61 | goto err; | 61 | goto err; |
62 | if (ressl_configure_keypair(ctx) != 0) | 62 | if (tls_configure_keypair(ctx) != 0) |
63 | goto err; | 63 | goto err; |
64 | 64 | ||
65 | if (ctx->config->ecdhcurve == -1) { | 65 | if (ctx->config->ecdhcurve == -1) { |
@@ -67,7 +67,7 @@ ressl_configure_server(struct ressl *ctx) | |||
67 | } else if (ctx->config->ecdhcurve != NID_undef) { | 67 | } else if (ctx->config->ecdhcurve != NID_undef) { |
68 | if ((ecdh_key = EC_KEY_new_by_curve_name( | 68 | if ((ecdh_key = EC_KEY_new_by_curve_name( |
69 | ctx->config->ecdhcurve)) == NULL) { | 69 | ctx->config->ecdhcurve)) == NULL) { |
70 | ressl_set_error(ctx, "failed to set ECDH curve"); | 70 | tls_set_error(ctx, "failed to set ECDH curve"); |
71 | goto err; | 71 | goto err; |
72 | } | 72 | } |
73 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_SINGLE_ECDH_USE); | 73 | SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_SINGLE_ECDH_USE); |
@@ -82,43 +82,19 @@ err: | |||
82 | } | 82 | } |
83 | 83 | ||
84 | int | 84 | int |
85 | ressl_listen(struct ressl *ctx, const char *host, const char *port, int af) | 85 | tls_accept_socket(struct tls *ctx, struct tls **cctx, int socket) |
86 | { | 86 | { |
87 | if ((ctx->flags & RESSL_SERVER) == 0) { | 87 | struct tls *conn_ctx = *cctx; |
88 | ressl_set_error(ctx, "not a server context"); | ||
89 | goto err; | ||
90 | } | ||
91 | |||
92 | err: | ||
93 | return (-1); | ||
94 | } | ||
95 | |||
96 | int | ||
97 | ressl_accept(struct ressl *ctx, struct ressl **cctx) | ||
98 | { | ||
99 | if ((ctx->flags & RESSL_SERVER) == 0) { | ||
100 | ressl_set_error(ctx, "not a server context"); | ||
101 | goto err; | ||
102 | } | ||
103 | |||
104 | err: | ||
105 | return (-1); | ||
106 | } | ||
107 | |||
108 | int | ||
109 | ressl_accept_socket(struct ressl *ctx, struct ressl **cctx, int socket) | ||
110 | { | ||
111 | struct ressl *conn_ctx = *cctx; | ||
112 | int ret, ssl_err; | 88 | int ret, ssl_err; |
113 | 89 | ||
114 | if ((ctx->flags & RESSL_SERVER) == 0) { | 90 | if ((ctx->flags & TLS_SERVER) == 0) { |
115 | ressl_set_error(ctx, "not a server context"); | 91 | tls_set_error(ctx, "not a server context"); |
116 | goto err; | 92 | goto err; |
117 | } | 93 | } |
118 | 94 | ||
119 | if (conn_ctx == NULL) { | 95 | if (conn_ctx == NULL) { |
120 | if ((conn_ctx = ressl_server_conn(ctx)) == NULL) { | 96 | if ((conn_ctx = tls_server_conn(ctx)) == NULL) { |
121 | ressl_set_error(ctx, "connection context failure"); | 97 | tls_set_error(ctx, "connection context failure"); |
122 | goto err; | 98 | goto err; |
123 | } | 99 | } |
124 | *cctx = conn_ctx; | 100 | *cctx = conn_ctx; |
@@ -126,12 +102,12 @@ ressl_accept_socket(struct ressl *ctx, struct ressl **cctx, int socket) | |||
126 | conn_ctx->socket = socket; | 102 | conn_ctx->socket = socket; |
127 | 103 | ||
128 | if ((conn_ctx->ssl_conn = SSL_new(ctx->ssl_ctx)) == NULL) { | 104 | if ((conn_ctx->ssl_conn = SSL_new(ctx->ssl_ctx)) == NULL) { |
129 | ressl_set_error(ctx, "ssl failure"); | 105 | tls_set_error(ctx, "ssl failure"); |
130 | goto err; | 106 | goto err; |
131 | } | 107 | } |
132 | 108 | ||
133 | if (SSL_set_fd(conn_ctx->ssl_conn, socket) != 1) { | 109 | if (SSL_set_fd(conn_ctx->ssl_conn, socket) != 1) { |
134 | ressl_set_error(ctx, "ssl set fd failure"); | 110 | tls_set_error(ctx, "ssl set fd failure"); |
135 | goto err; | 111 | goto err; |
136 | } | 112 | } |
137 | SSL_set_app_data(conn_ctx->ssl_conn, conn_ctx); | 113 | SSL_set_app_data(conn_ctx->ssl_conn, conn_ctx); |
@@ -141,11 +117,11 @@ ressl_accept_socket(struct ressl *ctx, struct ressl **cctx, int socket) | |||
141 | ssl_err = SSL_get_error(conn_ctx->ssl_conn, ret); | 117 | ssl_err = SSL_get_error(conn_ctx->ssl_conn, ret); |
142 | switch (ssl_err) { | 118 | switch (ssl_err) { |
143 | case SSL_ERROR_WANT_READ: | 119 | case SSL_ERROR_WANT_READ: |
144 | return (RESSL_READ_AGAIN); | 120 | return (TLS_READ_AGAIN); |
145 | case SSL_ERROR_WANT_WRITE: | 121 | case SSL_ERROR_WANT_WRITE: |
146 | return (RESSL_WRITE_AGAIN); | 122 | return (TLS_WRITE_AGAIN); |
147 | default: | 123 | default: |
148 | ressl_set_error(ctx, "ssl accept failure (%i)", | 124 | tls_set_error(ctx, "ssl accept failure (%i)", |
149 | ssl_err); | 125 | ssl_err); |
150 | goto err; | 126 | goto err; |
151 | } | 127 | } |
diff --git a/src/lib/libressl/ressl_util.c b/src/lib/libtls/tls_util.c index d8b8f51738..2adfb674b8 100644 --- a/src/lib/libressl/ressl_util.c +++ b/src/lib/libtls/tls_util.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ressl_util.c,v 1.2 2014/08/05 12:46:16 jsing Exp $ */ | 1 | /* $OpenBSD: tls_util.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -17,7 +17,7 @@ | |||
17 | 17 | ||
18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
19 | 19 | ||
20 | #include "ressl_internal.h" | 20 | #include "tls_internal.h" |
21 | 21 | ||
22 | /* | 22 | /* |
23 | * Extract the host and port from a colon separated value. For a literal IPv6 | 23 | * Extract the host and port from a colon separated value. For a literal IPv6 |
@@ -28,7 +28,7 @@ | |||
28 | * On memory allocation failure -1 will be returned. | 28 | * On memory allocation failure -1 will be returned. |
29 | */ | 29 | */ |
30 | int | 30 | int |
31 | ressl_host_port(const char *hostport, char **host, char **port) | 31 | tls_host_port(const char *hostport, char **host, char **port) |
32 | { | 32 | { |
33 | char *h, *p, *s; | 33 | char *h, *p, *s; |
34 | int rv = 1; | 34 | int rv = 1; |
diff --git a/src/lib/libressl/ressl_verify.c b/src/lib/libtls/tls_verify.c index 5e9f370e1c..fa0010922f 100644 --- a/src/lib/libressl/ressl_verify.c +++ b/src/lib/libtls/tls_verify.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ressl_verify.c,v 1.5 2014/10/06 11:55:48 jca Exp $ */ | 1 | /* $OpenBSD: tls_verify.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> | 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> |
4 | * | 4 | * |
@@ -24,14 +24,14 @@ | |||
24 | 24 | ||
25 | #include <openssl/x509v3.h> | 25 | #include <openssl/x509v3.h> |
26 | 26 | ||
27 | #include "ressl_internal.h" | 27 | #include "tls_internal.h" |
28 | 28 | ||
29 | int ressl_match_hostname(const char *cert_hostname, const char *hostname); | 29 | int tls_match_hostname(const char *cert_hostname, const char *hostname); |
30 | int ressl_check_subject_altname(X509 *cert, const char *host); | 30 | int tls_check_subject_altname(X509 *cert, const char *host); |
31 | int ressl_check_common_name(X509 *cert, const char *host); | 31 | int tls_check_common_name(X509 *cert, const char *host); |
32 | 32 | ||
33 | int | 33 | int |
34 | ressl_match_hostname(const char *cert_hostname, const char *hostname) | 34 | tls_match_hostname(const char *cert_hostname, const char *hostname) |
35 | { | 35 | { |
36 | const char *cert_domain, *domain, *next_dot; | 36 | const char *cert_domain, *domain, *next_dot; |
37 | 37 | ||
@@ -80,7 +80,7 @@ ressl_match_hostname(const char *cert_hostname, const char *hostname) | |||
80 | } | 80 | } |
81 | 81 | ||
82 | int | 82 | int |
83 | ressl_check_subject_altname(X509 *cert, const char *host) | 83 | tls_check_subject_altname(X509 *cert, const char *host) |
84 | { | 84 | { |
85 | STACK_OF(GENERAL_NAME) *altname_stack = NULL; | 85 | STACK_OF(GENERAL_NAME) *altname_stack = NULL; |
86 | union { struct in_addr ip4; struct in6_addr ip6; } addrbuf; | 86 | union { struct in_addr ip4; struct in6_addr ip6; } addrbuf; |
@@ -131,7 +131,7 @@ ressl_check_subject_altname(X509 *cert, const char *host) | |||
131 | break; | 131 | break; |
132 | } | 132 | } |
133 | 133 | ||
134 | if (ressl_match_hostname(data, host) == 0) { | 134 | if (tls_match_hostname(data, host) == 0) { |
135 | rv = 0; | 135 | rv = 0; |
136 | break; | 136 | break; |
137 | } | 137 | } |
@@ -160,7 +160,7 @@ ressl_check_subject_altname(X509 *cert, const char *host) | |||
160 | } | 160 | } |
161 | 161 | ||
162 | int | 162 | int |
163 | ressl_check_common_name(X509 *cert, const char *host) | 163 | tls_check_common_name(X509 *cert, const char *host) |
164 | { | 164 | { |
165 | X509_NAME *name; | 165 | X509_NAME *name; |
166 | char *common_name = NULL; | 166 | char *common_name = NULL; |
@@ -205,7 +205,7 @@ ressl_check_common_name(X509 *cert, const char *host) | |||
205 | goto out; | 205 | goto out; |
206 | } | 206 | } |
207 | 207 | ||
208 | if (ressl_match_hostname(common_name, host) == 0) | 208 | if (tls_match_hostname(common_name, host) == 0) |
209 | rv = 0; | 209 | rv = 0; |
210 | out: | 210 | out: |
211 | free(common_name); | 211 | free(common_name); |
@@ -213,13 +213,13 @@ out: | |||
213 | } | 213 | } |
214 | 214 | ||
215 | int | 215 | int |
216 | ressl_check_hostname(X509 *cert, const char *host) | 216 | tls_check_hostname(X509 *cert, const char *host) |
217 | { | 217 | { |
218 | int rv; | 218 | int rv; |
219 | 219 | ||
220 | rv = ressl_check_subject_altname(cert, host); | 220 | rv = tls_check_subject_altname(cert, host); |
221 | if (rv == 0 || rv == -2) | 221 | if (rv == 0 || rv == -2) |
222 | return rv; | 222 | return rv; |
223 | 223 | ||
224 | return ressl_check_common_name(cert, host); | 224 | return tls_check_common_name(cert, host); |
225 | } | 225 | } |