summaryrefslogtreecommitdiff
path: root/src/lib/libressl/ressl_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libressl/ressl_server.c')
-rw-r--r--src/lib/libressl/ressl_server.c158
1 files changed, 0 insertions, 158 deletions
diff --git a/src/lib/libressl/ressl_server.c b/src/lib/libressl/ressl_server.c
deleted file mode 100644
index 4783674a0b..0000000000
--- a/src/lib/libressl/ressl_server.c
+++ /dev/null
@@ -1,158 +0,0 @@
1/* $OpenBSD: ressl_server.c,v 1.11 2014/10/15 14:08:26 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#include <openssl/ec.h>
19#include <openssl/ssl.h>
20
21#include <ressl.h>
22#include "ressl_internal.h"
23
24struct ressl *
25ressl_server(void)
26{
27 struct ressl *ctx;
28
29 if ((ctx = ressl_new()) == NULL)
30 return (NULL);
31
32 ctx->flags |= RESSL_SERVER;
33
34 return (ctx);
35}
36
37struct ressl *
38ressl_server_conn(struct ressl *ctx)
39{
40 struct ressl *conn_ctx;
41
42 if ((conn_ctx = ressl_new()) == NULL)
43 return (NULL);
44
45 conn_ctx->flags |= RESSL_SERVER_CONN;
46
47 return (conn_ctx);
48}
49
50int
51ressl_configure_server(struct ressl *ctx)
52{
53 EC_KEY *ecdh_key;
54
55 if ((ctx->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) {
56 ressl_set_error(ctx, "ssl context failure");
57 goto err;
58 }
59
60 if (ressl_configure_ssl(ctx) != 0)
61 goto err;
62 if (ressl_configure_keypair(ctx) != 0)
63 goto err;
64
65 if (ctx->config->ecdhcurve == -1) {
66 SSL_CTX_set_ecdh_auto(ctx->ssl_ctx, 1);
67 } else if (ctx->config->ecdhcurve != NID_undef) {
68 if ((ecdh_key = EC_KEY_new_by_curve_name(
69 ctx->config->ecdhcurve)) == NULL) {
70 ressl_set_error(ctx, "failed to set ECDH curve");
71 goto err;
72 }
73 SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_SINGLE_ECDH_USE);
74 SSL_CTX_set_tmp_ecdh(ctx->ssl_ctx, ecdh_key);
75 EC_KEY_free(ecdh_key);
76 }
77
78 return (0);
79
80err:
81 return (-1);
82}
83
84int
85ressl_listen(struct ressl *ctx, const char *host, const char *port, int af)
86{
87 if ((ctx->flags & RESSL_SERVER) == 0) {
88 ressl_set_error(ctx, "not a server context");
89 goto err;
90 }
91
92err:
93 return (-1);
94}
95
96int
97ressl_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
104err:
105 return (-1);
106}
107
108int
109ressl_accept_socket(struct ressl *ctx, struct ressl **cctx, int socket)
110{
111 struct ressl *conn_ctx = *cctx;
112 int ret, ssl_err;
113
114 if ((ctx->flags & RESSL_SERVER) == 0) {
115 ressl_set_error(ctx, "not a server context");
116 goto err;
117 }
118
119 if (conn_ctx == NULL) {
120 if ((conn_ctx = ressl_server_conn(ctx)) == NULL) {
121 ressl_set_error(ctx, "connection context failure");
122 goto err;
123 }
124 *cctx = conn_ctx;
125
126 conn_ctx->socket = socket;
127
128 if ((conn_ctx->ssl_conn = SSL_new(ctx->ssl_ctx)) == NULL) {
129 ressl_set_error(ctx, "ssl failure");
130 goto err;
131 }
132
133 if (SSL_set_fd(conn_ctx->ssl_conn, socket) != 1) {
134 ressl_set_error(ctx, "ssl set fd failure");
135 goto err;
136 }
137 SSL_set_app_data(conn_ctx->ssl_conn, conn_ctx);
138 }
139
140 if ((ret = SSL_accept(conn_ctx->ssl_conn)) != 1) {
141 ssl_err = SSL_get_error(conn_ctx->ssl_conn, ret);
142 switch (ssl_err) {
143 case SSL_ERROR_WANT_READ:
144 return (RESSL_READ_AGAIN);
145 case SSL_ERROR_WANT_WRITE:
146 return (RESSL_WRITE_AGAIN);
147 default:
148 ressl_set_error(ctx, "ssl accept failure (%i)",
149 ssl_err);
150 goto err;
151 }
152 }
153
154 return (0);
155
156err:
157 return (-1);
158}