aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/tls/tls_stream.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-04-27 18:40:40 -0700
committerGarrett D'Amore <garrett@damore.org>2025-06-01 22:49:00 -0700
commit8bcb82d245a5fce1bd519e2f99250dedf11e763d (patch)
tree4d663bedbb043b9d599f061d7f2b5f9509c8f390 /src/supplemental/tls/tls_stream.c
parent08400bd437149c4fb31af9b2abece2ae44041283 (diff)
downloadnng-8bcb82d245a5fce1bd519e2f99250dedf11e763d.tar.gz
nng-8bcb82d245a5fce1bd519e2f99250dedf11e763d.tar.bz2
nng-8bcb82d245a5fce1bd519e2f99250dedf11e763d.zip
Introduce DTLS transport for NNG.
This introduces a new experimental transport for DTLS, that provides encryption over UDP. It has a simpler protocol than the current UDP SP protocol (but we intend to fix that by making the UDP transport simpler in a follow up!) There are a few other fixes in the TLS layer itself, and in the build, that were needed to accomplish this work. Also there was an endianness bug in the UDP protocol handling, which is fixed here.
Diffstat (limited to 'src/supplemental/tls/tls_stream.c')
-rw-r--r--src/supplemental/tls/tls_stream.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/supplemental/tls/tls_stream.c b/src/supplemental/tls/tls_stream.c
index 8a7f26d8..cd248686 100644
--- a/src/supplemental/tls/tls_stream.c
+++ b/src/supplemental/tls/tls_stream.c
@@ -110,9 +110,10 @@ tls_stream_recv(void *arg, nng_aio *aio)
static void
tls_stream_conn_cb(void *arg)
{
- tls_stream *ts = arg;
- nng_stream *bio;
- int rv;
+ tls_stream *ts = arg;
+ nng_stream *bio;
+ int rv;
+ nng_sockaddr sa;
if ((rv = nni_aio_result(&ts->conn_aio)) != 0) {
nni_aio_finish_error(ts->user_aio, rv);
@@ -121,8 +122,13 @@ tls_stream_conn_cb(void *arg)
}
bio = nni_aio_get_output(&ts->conn_aio, 0);
+ if ((rv = nng_stream_get_addr(bio, NNG_OPT_REMADDR, &sa)) != 0) {
+ nni_aio_finish_error(ts->user_aio, rv);
+ nni_tls_stream_free(ts);
+ return;
+ };
- if ((rv = nni_tls_start(&ts->conn, &tls_stream_bio, bio)) != 0) {
+ if ((rv = nni_tls_start(&ts->conn, &tls_stream_bio, bio, &sa)) != 0) {
// NB: if this fails, it *will* have set the bio either way.
// So nni_tls_stream_free will also free the bio.
nni_aio_finish_error(ts->user_aio, rv);
@@ -140,13 +146,12 @@ static nng_err tls_stream_get(
int
nni_tls_stream_alloc(tls_stream **tsp, nng_tls_config *cfg, nng_aio *user_aio)
{
- tls_stream *ts;
- const nng_tls_engine *eng;
- size_t size;
- int rv;
+ tls_stream *ts;
+ size_t size;
+ int rv;
- eng = cfg->engine;
- size = NNI_ALIGN_UP(sizeof(*ts)) + eng->conn_ops->size;
+ size = NNI_ALIGN_UP(sizeof(*ts)) +
+ NNI_ALIGN_UP(nni_tls_engine_conn_size());
if ((ts = nni_zalloc(size)) == NULL) {
return (NNG_ENOMEM);