summaryrefslogtreecommitdiff
path: root/src/lib/libssl/tls13_lib.c
diff options
context:
space:
mode:
authorjsing <>2019-01-21 13:45:57 +0000
committerjsing <>2019-01-21 13:45:57 +0000
commitc06f6f3e478fe1e9e0a1f1601f983e3d55479ed3 (patch)
tree14969b4304a48b9fdbf41d756aec5076c5ac5d69 /src/lib/libssl/tls13_lib.c
parentbde3ac13e78ee3960e9e0340d4af51a79ada0aa6 (diff)
downloadopenbsd-c06f6f3e478fe1e9e0a1f1601f983e3d55479ed3.tar.gz
openbsd-c06f6f3e478fe1e9e0a1f1601f983e3d55479ed3.tar.bz2
openbsd-c06f6f3e478fe1e9e0a1f1601f983e3d55479ed3.zip
Provide the initial TLSv1.3 client implementation.
Move tls13_connect() to a new tls13_client.c file and provide a legacy wrapper to it, which allocates a struct tls_ctx if necessary. Also move tls13_client_hello_send() to tls13_client.c and actual implement the building of a client hello. ok tb@
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/tls13_lib.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/lib/libssl/tls13_lib.c b/src/lib/libssl/tls13_lib.c
index c4cce26ca5..3860ddefef 100644
--- a/src/lib/libssl/tls13_lib.c
+++ b/src/lib/libssl/tls13_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_lib.c,v 1.2 2019/01/21 10:24:25 jsing Exp $ */ 1/* $OpenBSD: tls13_lib.c,v 1.3 2019/01/21 13:45:57 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -61,6 +61,39 @@ tls13_cipher_hash(const SSL_CIPHER *cipher)
61 return NULL; 61 return NULL;
62} 62}
63 63
64struct tls13_ctx *
65tls13_ctx_new(int mode)
66{
67 struct tls13_ctx *ctx = NULL;
68
69 if ((ctx = calloc(sizeof(struct tls13_ctx), 1)) == NULL)
70 goto err;
71
72 ctx->mode = mode;
73
74 if ((ctx->rl = tls13_record_layer_new(tls13_legacy_wire_read_cb,
75 tls13_legacy_wire_write_cb, NULL, NULL, ctx)) == NULL)
76 goto err;
77
78 return ctx;
79
80 err:
81 tls13_ctx_free(ctx);
82
83 return NULL;
84}
85
86void
87tls13_ctx_free(struct tls13_ctx *ctx)
88{
89 if (ctx == NULL)
90 return;
91
92 tls13_record_layer_free(ctx->rl);
93
94 freezero(ctx, sizeof(struct tls13_ctx));
95}
96
64static ssize_t 97static ssize_t
65tls13_legacy_wire_read(SSL *ssl, uint8_t *buf, size_t len) 98tls13_legacy_wire_read(SSL *ssl, uint8_t *buf, size_t len)
66{ 99{
@@ -131,7 +164,7 @@ tls13_legacy_wire_write_cb(const void *buf, size_t n, void *arg)
131 return tls13_legacy_wire_write(ctx->ssl, buf, n); 164 return tls13_legacy_wire_write(ctx->ssl, buf, n);
132} 165}
133 166
134static int 167int
135tls13_legacy_return_code(SSL *ssl, ssize_t ret) 168tls13_legacy_return_code(SSL *ssl, ssize_t ret)
136{ 169{
137 if (ret > INT_MAX) { 170 if (ret > INT_MAX) {
@@ -139,7 +172,7 @@ tls13_legacy_return_code(SSL *ssl, ssize_t ret)
139 return -1; 172 return -1;
140 } 173 }
141 174
142 /* A successful read or write. */ 175 /* A successful read, write or other operation. */
143 if (ret > 0) 176 if (ret > 0)
144 return ret; 177 return ret;
145 178