Statistics: Posted by JasonWan — Sun Nov 06, 2016 10:56 am
Statistics: Posted by JasonWan — Sun Nov 06, 2016 10:53 am
Code:
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;
}
Statistics: Posted by dsbaha — Sat Jan 23, 2016 2:25 pm
Statistics: Posted by ESP_Faye — Mon Jan 04, 2016 1:53 pm
Statistics: Posted by faintu — Thu Dec 31, 2015 4:37 pm
Statistics: Posted by ESP_Faye — Mon Dec 21, 2015 11:25 am
Statistics: Posted by harryzz — Sat Dec 19, 2015 6:29 pm