library/src/network/httpd/BP-HTTPdWebSocketRequestHandlers.cc
// This will return a variable length base64 key.  The "client_nonce_base64" value
// is the value you get from Sec-WebSocket-Key from the client request.  This process
// is specified in the websocket RFC on page 8 (as of right 2017), and documented in
// the stackoverflow answer: http://stackoverflow.com/questions/34778321/websocket-handshake-sec-websocket-accept-header-value-is-incorrect
//
// Result is bpcalloced and must be bpfree'd.
//
//
This will return a variable length base64 key.  The "client_nonce_base64" value
is the value you get from Sec-WebSocket-Key from the client request.

Result is bpcalloced and must be bpfree'd.
This will return a variable length base64 key . The " client_nonce_base64 " value is the value you get from Sec - WebSocket - Key from the client request . Result is bpcalloced and must be bpfree ' d .
char * BP_HTTPdWebsocketCalculateSecAcceptKey
(
	char *client_nonce_base64
)
{
	if(!client_nonce_base64)
		return NULL;
	if(!bpstrlen(client_nonce_base64))
		return NULL;
	if(!BP_StringIsReasonablePrintableString(client_nonce_base64, bpstrlen(client_nonce_base64), BP_FALSE, BP_FALSE))
		return NULL;
	char *joined_tmp = BP_JoinStrings
	(
		client_nonce_base64,
		"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
		NULL
	);
	if(!joined_tmp)
		return NULL;
	char * sha1_ascii = BP_GenSHA1(joined_tmp, bpstrlen(joined_tmp));
	if(!sha1_ascii)
	{
		bpfree(joined_tmp);
		return NULL;
	}
	size_t bin_len = 0;
	char *bin_str = BP_StringHexToBinaryBlob(sha1_ascii, &bin_len);
	if(!bin_str)
	{
		bpfree(joined_tmp);
		bpfree(sha1_ascii);
		return NULL;
	}
	char *calculated_key = BP_Base64Encode((unsigned char *) bin_str, bin_len);
	if(!calculated_key)
	{
		bpfree(joined_tmp);
		bpfree(sha1_ascii);
		bpfree(bin_str);
		return NULL;
	}
	return calculated_key;
}
char * BP_HTTPdWebsocketCalculateSecAcceptKey ( char * client_nonce_base64 ) { if ( ! client_nonce_base64 ) return NULL ; if ( ! bpstrlen ( client_nonce_base64 ) ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( client_nonce_base64 , bpstrlen ( client_nonce_base64 ) , BP_FALSE , BP_FALSE ) ) return NULL ; char * joined_tmp = BP_JoinStrings ( client_nonce_base64 , " " , NULL ) ; if ( ! joined_tmp ) return NULL ; char * sha1_ascii = BP_GenSHA1 ( joined_tmp , bpstrlen ( joined_tmp ) ) ; if ( ! sha1_ascii ) { bpfree ( joined_tmp ) ; return NULL ; } size_t bin_len = 0 ; char * bin_str = BP_StringHexToBinaryBlob ( sha1_ascii , & bin_len ) ; if ( ! bin_str ) { bpfree ( joined_tmp ) ; bpfree ( sha1_ascii ) ; return NULL ; } char * calculated_key = BP_Base64Encode ( ( unsigned char * ) bin_str , bin_len ) ; if ( ! calculated_key ) { bpfree ( joined_tmp ) ; bpfree ( sha1_ascii ) ; bpfree ( bin_str ) ; return NULL ; } return calculated_key ; }
This will return a variable length base64 key.
This will return a variable length base64 key .
// run basic checks // join the nonce and the rfc GUID string // ensure we joined the strings successfully // generate sha1 // create binary blob from the sha1 string // return indicating NULL