diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libtls/tls_server.c (renamed from src/lib/libressl/ressl_server.c) | 82 |
1 files changed, 29 insertions, 53 deletions
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 | } |