From 6170ae5e2ed3a64048f042ba115775f851aeb7c8 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 23 Mar 2018 12:36:25 +0200 Subject: [PATCH] net: websocket: Use system provided base64 function Instead of using mbedtls_base64, use system provided base64 encoding function. Signed-off-by: Jukka Rissanen --- samples/net/ws_console/prj.conf | 3 +-- samples/net/ws_console/sample.yaml | 2 +- samples/net/ws_echo_server/prj.conf | 3 +-- samples/net/ws_echo_server/sample.yaml | 2 +- subsys/net/lib/websocket/Kconfig | 1 + subsys/net/lib/websocket/websocket.c | 12 ++++++------ tests/net/websocket/prj.conf | 3 +-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/samples/net/ws_console/prj.conf b/samples/net/ws_console/prj.conf index 4496a6a4dc..ffee021ed6 100644 --- a/samples/net/ws_console/prj.conf +++ b/samples/net/ws_console/prj.conf @@ -39,10 +39,9 @@ CONFIG_HTTP_SERVER=y # How many URLs we are serving CONFIG_HTTP_SERVER_NUM_URLS=5 -# base64 support needed by websocket +# sha1 support needed by websocket CONFIG_MBEDTLS=y CONFIG_MBEDTLS_BUILTIN=y -CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h" # Logging CONFIG_NET_LOG=y diff --git a/samples/net/ws_console/sample.yaml b/samples/net/ws_console/sample.yaml index 7d3efa6f43..24c27daef4 100644 --- a/samples/net/ws_console/sample.yaml +++ b/samples/net/ws_console/sample.yaml @@ -3,5 +3,5 @@ sample: tests: test: build_only: true - platform_whitelist: qemu_x86 + platform_whitelist: qemu_x86 native_posix tags: net websocket diff --git a/samples/net/ws_echo_server/prj.conf b/samples/net/ws_echo_server/prj.conf index 4d9c41b355..e67363be02 100644 --- a/samples/net/ws_echo_server/prj.conf +++ b/samples/net/ws_echo_server/prj.conf @@ -38,10 +38,9 @@ CONFIG_HTTP_SERVER=y # How many URLs we are serving CONFIG_HTTP_SERVER_NUM_URLS=5 -# base64 support needed by websocket +# sha1 support needed by websocket CONFIG_MBEDTLS=y CONFIG_MBEDTLS_BUILTIN=y -CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h" # Logging CONFIG_NET_LOG=y diff --git a/samples/net/ws_echo_server/sample.yaml b/samples/net/ws_echo_server/sample.yaml index fa878166f8..db10c0d3bb 100644 --- a/samples/net/ws_echo_server/sample.yaml +++ b/samples/net/ws_echo_server/sample.yaml @@ -3,5 +3,5 @@ sample: tests: test: build_only: true - platform_whitelist: qemu_x86 qemu_cortex_m3 + platform_whitelist: qemu_x86 qemu_cortex_m3 native_posix tags: net websocket diff --git a/subsys/net/lib/websocket/Kconfig b/subsys/net/lib/websocket/Kconfig index 18b48170d2..b905d9b7dd 100644 --- a/subsys/net/lib/websocket/Kconfig +++ b/subsys/net/lib/websocket/Kconfig @@ -8,6 +8,7 @@ menuconfig WEBSOCKET default n depends on HTTP select NET_TCP + select BASE64 help This option enables the websocket library. diff --git a/subsys/net/lib/websocket/websocket.c b/subsys/net/lib/websocket/websocket.c index 32e7bc81c2..2fbccb99b6 100644 --- a/subsys/net/lib/websocket/websocket.c +++ b/subsys/net/lib/websocket/websocket.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include #define BUF_ALLOC_TIMEOUT 100 @@ -395,12 +395,12 @@ static struct net_pkt *prepare_reply(struct http_ctx *ctx, snprintk(tmp, sizeof(tmp), "Sec-WebSocket-Accept: "); - ret = mbedtls_base64_encode(tmp + sizeof("Sec-WebSocket-Accept: ") - 1, - sizeof(tmp) - - (sizeof("Sec-WebSocket-Accept: ") - 1), - &olen, accept, sizeof(accept)); + ret = base64_encode(tmp + sizeof("Sec-WebSocket-Accept: ") - 1, + sizeof(tmp) - + (sizeof("Sec-WebSocket-Accept: ") - 1), + &olen, accept, sizeof(accept)); if (ret) { - if (ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) { + if (ret == -ENOMEM) { NET_DBG("[%p] Too short buffer olen %zd", ctx, olen); } diff --git a/tests/net/websocket/prj.conf b/tests/net/websocket/prj.conf index 1da31f5561..5d321efa72 100644 --- a/tests/net/websocket/prj.conf +++ b/tests/net/websocket/prj.conf @@ -50,10 +50,9 @@ CONFIG_HTTP_SERVER=y # How many URLs we are serving CONFIG_HTTP_SERVER_NUM_URLS=5 -# base64 support needed by websocket +# sha1 support needed by websocket CONFIG_MBEDTLS=y CONFIG_MBEDTLS_BUILTIN=y -CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h" # Logging CONFIG_NET_LOG=y