summaryrefslogtreecommitdiff
path: root/src/lib/libtls/tls_client.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libtls/tls_client.c (renamed from src/lib/libressl/ressl_client.c)64
1 files changed, 32 insertions, 32 deletions
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
32struct ressl * 32struct tls *
33ressl_client(void) 33tls_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
45int 45int
46ressl_connect(struct ressl *ctx, const char *host, const char *port) 46tls_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
123int 123int
124ressl_connect_socket(struct ressl *ctx, int socket, const char *hostname) 124tls_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 }