RTOS problem with nopoll websockets
RTOS problem with nopoll websockets
Postby harryzz » Sat Dec 19, 2015 6:29 pm
Hello
someone tested nopoll lib. I can't establish connection with nopoll_conn_new() - every time i get error.
For example
conn = nopoll_conn_new(ctx, "echo.websocket.org", "80", "echo.websocket.org:80", "ws://echo.websocket.org:80/", NULL, "null");
this work without problem with nopoll lib under windows. but on ESP with latest RTOS not. And the example included also not work.
br
harry
someone tested nopoll lib. I can't establish connection with nopoll_conn_new() - every time i get error.
For example
conn = nopoll_conn_new(ctx, "echo.websocket.org", "80", "echo.websocket.org:80", "ws://echo.websocket.org:80/", NULL, "null");
this work without problem with nopoll lib under windows. but on ESP with latest RTOS not. And the example included also not work.
br
harry
Re: RTOS problem with nopoll websockets
Postby faintu » Thu Dec 31, 2015 4:37 pm
The included websocket demo causes system crash -- of course it will cause crash, as it declares 512 bytes stack space, and then it immediately declares a 1024 byte local array in function test_04a. Are all the examples coming along with the RTOS sdk ever built and run????
also, the libnopoll will not work, because it won't generate the handshake key correctly. Why do I know this, simply build and run the following code:
extern char * nopoll_conn_produce_accept_key(noPollCtx * ctx, const char * websocket_key);
char* key = nopoll_conn_produce_accept_key(ctx, "3WazH0uwf9nfcy5VNmasrw==");
printf("KEY:%s\n", key);
nopoll_free(key);
The expected result response key should be "yKyGAgJvgbG9GY8gjdicbpl3HWs=", but it actually returns "udQnQPAff9nfcy5VNmasrw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11". Why is that? Because the libnopoll.a is compiled with wrong SHA1 result buffer size, which is defined as "ESP_EVP_MAX_MD_SIZE 6". It should be at least 20.
Since I don't have access to the code,I don't know if there is any other errors, but please, when you release an "SDK" with examples, build and run them!
this is totally a waste of time!
also, the libnopoll will not work, because it won't generate the handshake key correctly. Why do I know this, simply build and run the following code:
extern char * nopoll_conn_produce_accept_key(noPollCtx * ctx, const char * websocket_key);
char* key = nopoll_conn_produce_accept_key(ctx, "3WazH0uwf9nfcy5VNmasrw==");
printf("KEY:%s\n", key);
nopoll_free(key);
The expected result response key should be "yKyGAgJvgbG9GY8gjdicbpl3HWs=", but it actually returns "udQnQPAff9nfcy5VNmasrw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11". Why is that? Because the libnopoll.a is compiled with wrong SHA1 result buffer size, which is defined as "ESP_EVP_MAX_MD_SIZE 6". It should be at least 20.
Since I don't have access to the code,I don't know if there is any other errors, but please, when you release an "SDK" with examples, build and run them!
this is totally a waste of time!
Re: RTOS problem with nopoll websockets
Postby ESP_Faye » Mon Jan 04, 2016 1:53 pm
Hi,
Sorry for the inconvenience.
Please have a try with this new demo as the attachment.
Sorry for the inconvenience.
Please have a try with this new demo as the attachment.
- Attachments
-
- websocket_demo.zip
- (425.51 KiB) Downloaded 723 times
Re: RTOS problem with nopoll websockets
Postby dsbaha » Fri Jan 22, 2016 3:23 pm
I, too, have wasted countless amount of hours trying to get this to work to only get a "Sec-Websocket-Accept" mismatch error due to the invalid SHA1 calculation of the key. When will a patched version of libnopoll.a be released? I don't see anything special/different in the "websocket_demo.zip" file either.
Re: RTOS problem with nopoll websockets
Postby dsbaha » Sat Jan 23, 2016 2:25 pm
Hi, instead of waiting for a patched libnopoll, I just made my own patch.
execute xtensa-lx106-elf-objcopy -W nopoll_conn_produce_accept_key libnopoll.a libnopoll2.a
Edit makefile to link libnopoll2.a (instead of the default one).
Put the following in your source code (or just a new .c file);
works great!!
execute xtensa-lx106-elf-objcopy -W nopoll_conn_produce_accept_key libnopoll.a libnopoll2.a
Edit makefile to link libnopoll2.a (instead of the default one).
Put the following in your source code (or just a new .c file);
Code: Select all
include <nopoll/nopoll.h>
#include "ssl_compat-1.0.h"
#include "esp_common.h"
char ICACHE_FLASH_ATTR * nopoll_conn_produce_accept_key(noPollCtx * ctx, const char * websocket_key)
{
if(websocket_key == NULL) return;
const char * static_guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
char * accept_key = NULL;
int accept_key_size, key_length;
key_length = strlen(websocket_key);
unsigned char buffer[SHA1_SIZE];
SHA1_CTX mdctx;
unsigned int md_len = SHA1_SIZE;
accept_key_size = key_length + 36 + 1;
accept_key = nopoll_new(char, accept_key_size);
memcpy(accept_key, websocket_key, key_length);
memcpy(accept_key + key_length, static_guid, 36);
SHA1_Init(&mdctx);
SHA1_Update(&mdctx, accept_key, strlen(accept_key));
SHA1_Final(buffer, &mdctx);
nopoll_base64_encode((const char *)buffer, md_len, (char *)accept_key, &accept_key_size);
return accept_key;
}
bool ICACHE_FLASH_ATTR check_websocket_auth_response(bool print)
{
bool result = FALSE;
char * expected_result = "HSmrc0sMlYUkAGmm5OPpG2HaGWk="; //Wikipedia Sample Response
char * websocket_key_test = nopoll_conn_produce_accept_key(NULL, "x3JJHMbDL1EzLkh9GBhXDw=="); //Wikipedia Sample
if(memcmp(expected_result, websocket_key_test, 28) == 0) result = TRUE;
if(print) printf("Websocket Auth Response %s\nExpected: %s\nReturned: %s\n", result ? "Passed" : "Failed", expected_result, websocket_key_test);
nopoll_free(websocket_key_test);
return result;
}
works great!!
Who is online
Users browsing this forum: No registered users and 318 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.