Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion addons/websocket/nx_websocket_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ NX_PACKET *packet_ptr;
client_ptr -> nx_websocket_client_guid[i] = (UCHAR)(NX_RAND());
}

/* Set the last extra byte of the buffer to be zero, since the function _nx_utility_base64_encode will use this extra-byte for calculation */
client_ptr -> nx_websocket_client_guid[NX_WEBSOCKET_CLIENT_GUID_SIZE] = 0;

/* Encode the GUID as key. */
_nx_utility_base64_encode(client_ptr -> nx_websocket_client_guid, NX_WEBSOCKET_CLIENT_GUID_SIZE,
client_ptr -> nx_websocket_client_key, NX_WEBSOCKET_CLIENT_KEY_SIZE,
Expand Down Expand Up @@ -963,7 +966,7 @@ UCHAR *field_name;
UINT field_name_length;
UCHAR *field_value;
UINT field_value_length;
UCHAR digest[NX_WEBSOCKET_ACCEPT_DIGEST_SIZE];
UCHAR digest[NX_WEBSOCKET_ACCEPT_DIGEST_SIZE + 1];
UCHAR key[NX_WEBSOCKET_ACCEPT_KEY_SIZE + 1];
UINT key_size = 0;
UCHAR upgrade_flag = NX_FALSE;
Expand Down Expand Up @@ -1104,6 +1107,9 @@ UCHAR accept_cnt = 0;
_nx_sha1_update(&(client_ptr -> nx_websocket_client_sha1), (UCHAR*)NX_WEBSOCKET_ACCEPT_PREDEFINED_GUID, NX_WEBSOCKET_ACCEPT_PREDEFINED_GUID_SIZE);
_nx_sha1_digest_calculate(&(client_ptr -> nx_websocket_client_sha1), digest);

/* Set the last extra byte of the digest to be zero, since the function _nx_utility_base64_encode will use this byte for calculation */
digest[NX_WEBSOCKET_ACCEPT_DIGEST_SIZE] = 0;

/* Encode the hash and compare it with the field value from the server. */
_nx_utility_base64_encode(digest, NX_WEBSOCKET_ACCEPT_DIGEST_SIZE, key, (NX_WEBSOCKET_ACCEPT_KEY_SIZE + 1), &key_size);
if ((field_value_length != NX_WEBSOCKET_ACCEPT_KEY_SIZE) || (memcmp((void *)field_value, (void *)key, NX_WEBSOCKET_ACCEPT_KEY_SIZE))) /* Use case of memcpy is verified. */
Expand Down
2 changes: 1 addition & 1 deletion addons/websocket/nx_websocket_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ typedef struct NX_WEBSOCKET_CLIENT_STRUCT
NX_PACKET *nx_websocket_client_processing_packet;

/* Globally Unique Identifier. */
UCHAR nx_websocket_client_guid[NX_WEBSOCKET_CLIENT_GUID_SIZE];
UCHAR nx_websocket_client_guid[NX_WEBSOCKET_CLIENT_GUID_SIZE + 1];

/* Protocol Name and length */
UCHAR *nx_websocket_client_subprotocol;
Expand Down