From 99778897f483d6882d5104123e27e95eaac26837 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 17 Jan 2018 10:04:23 -0800 Subject: fixes #209 NNG_OPT_TLS_VERIFIED is busted fixes #210 Want NNG_OPT_TLS_* options for TLS transport fixes #212 Eliminate a_endpt member of aio --- src/transport/ws/websocket.c | 65 +++++++++++++++++--------------------------- src/transport/ws/websocket.h | 4 +-- 2 files changed, 27 insertions(+), 42 deletions(-) (limited to 'src/transport/ws') diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index a06910d3..83155046 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -363,7 +363,6 @@ ws_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz) static int ws_ep_setopt_headers(ws_ep *ep, const void *v, size_t sz) { - // XXX: check that the string is well formed. char * dupstr; size_t duplen; char * name; @@ -373,6 +372,10 @@ ws_ep_setopt_headers(ws_ep *ep, const void *v, size_t sz) ws_hdr * h; int rv; + if (nni_strnlen(v, sz) >= sz) { + return (NNG_EINVAL); + } + if (ep == NULL) { return (0); } @@ -835,13 +838,11 @@ wss_ep_setopt_tlsconfig(void *arg, const void *v, size_t sz) if (ep == NULL) { return (0); } - nni_mtx_lock(&ep->mtx); if (ep->mode == NNI_EP_MODE_LISTEN) { rv = nni_ws_listener_set_tls(ep->listener, cfg); } else { rv = nni_ws_dialer_set_tls(ep->dialer, cfg); } - nni_mtx_unlock(&ep->mtx); return (rv); } @@ -852,20 +853,16 @@ wss_ep_setopt_tls_cert_key_file(void *arg, const void *v, size_t sz) int rv; nng_tls_config *tls; + if (nni_strnlen(v, sz) >= sz) { + return (NNG_EINVAL); + } if (ep == NULL) { - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } return (0); } - nni_mtx_lock(&ep->mtx); - if (((rv = wss_get_tls(ep, &tls)) != 0) || - ((rv = nng_tls_config_cert_key_file(tls, v, NULL)) != 0)) { - goto done; + if ((rv = wss_get_tls(ep, &tls)) != 0) { + return (rv); } -done: - nni_mtx_unlock(&ep->mtx); - return (rv); + return (nng_tls_config_cert_key_file(tls, v, NULL)); } static int @@ -875,20 +872,16 @@ wss_ep_setopt_tls_ca_file(void *arg, const void *v, size_t sz) int rv; nng_tls_config *tls; + if (nni_strnlen(v, sz) >= sz) { + return (NNG_EINVAL); + } if (ep == NULL) { - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } return (0); } - nni_mtx_lock(&ep->mtx); - if (((rv = wss_get_tls(ep, &tls)) != 0) || - ((rv = nng_tls_config_ca_file(tls, v)) != 0)) { - goto done; + if ((rv = wss_get_tls(ep, &tls)) != 0) { + return (rv); } -done: - nni_mtx_unlock(&ep->mtx); - return (rv); + return (nng_tls_config_ca_file(tls, v)); } static int @@ -904,14 +897,10 @@ wss_ep_setopt_tls_auth_mode(void *arg, const void *v, size_t sz) if ((rv != 0) || (ep == NULL)) { return (rv); } - nni_mtx_lock(&ep->mtx); - if (((rv = wss_get_tls(ep, &tls)) != 0) || - ((rv = nng_tls_config_auth_mode(tls, mode)) != 0)) { - goto done; + if ((rv = wss_get_tls(ep, &tls)) != 0) { + return (rv); } -done: - nni_mtx_unlock(&ep->mtx); - return (rv); + return (nng_tls_config_auth_mode(tls, mode)); } static int @@ -921,20 +910,16 @@ wss_ep_setopt_tls_server_name(void *arg, const void *v, size_t sz) int rv; nng_tls_config *tls; + if (nni_strnlen(v, sz) >= sz) { + return (NNG_EINVAL); + } if (ep == NULL) { - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } return (0); } - nni_mtx_lock(&ep->mtx); - if (((rv = wss_get_tls(ep, &tls)) != 0) || - ((rv = nng_tls_config_server_name(tls, v)) != 0)) { - goto done; + if ((rv = wss_get_tls(ep, &tls)) != 0) { + return (rv); } -done: - nni_mtx_unlock(&ep->mtx); - return (rv); + return (nng_tls_config_server_name(tls, v)); } static nni_tran_ep_option wss_ep_options[] = { diff --git a/src/transport/ws/websocket.h b/src/transport/ws/websocket.h index 76e94c3e..8179beab 100644 --- a/src/transport/ws/websocket.h +++ b/src/transport/ws/websocket.h @@ -1,6 +1,6 @@ // -// Copyright 2017 Staysail Systems, Inc. -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this -- cgit v1.2.3-70-g09d2