Fix wssshc registration message to send password instead of request_id

- Added send_registration_message() function to websocket library
- Updated wssshc.c to use send_registration_message() instead of send_json_message()
- Registration message now sends: {"type":"register","client_id":"<id>","password":"<password>"}
- Instead of: {"type":"register","client_id":"<id>","request_id":"<password>"}
- Server can now properly authenticate clients with passwords
parent b853b506
......@@ -82,6 +82,23 @@ int send_json_message(SSL *ssl, const char *type, const char *client_id, const c
return send_websocket_frame(ssl, message);
}
int send_registration_message(SSL *ssl, const char *client_id, const char *password) {
char message[1024];
if (password && strlen(password) > 0) {
snprintf(message, sizeof(message),
"{\"type\":\"register\",\"client_id\":\"%s\",\"password\":\"%s\"}",
client_id, password);
} else {
snprintf(message, sizeof(message),
"{\"type\":\"register\",\"client_id\":\"%s\"}",
client_id);
}
// Send as WebSocket frame
return send_websocket_frame(ssl, message);
}
int send_websocket_frame(SSL *ssl, const char *data) {
char frame[BUFFER_SIZE];
frame[0] = 0x81; // FIN + text opcode
......
......@@ -25,6 +25,7 @@
// Function declarations
int websocket_handshake(SSL *ssl, const char *host, int port, const char *path);
int send_json_message(SSL *ssl, const char *type, const char *client_id, const char *request_id);
int send_registration_message(SSL *ssl, const char *client_id, const char *password);
int send_websocket_frame(SSL *ssl, const char *data);
int send_pong_frame(SSL *ssl, const char *ping_payload, int payload_len);
int parse_websocket_frame(const char *buffer, int bytes_read, char **payload, int *payload_len);
......
......@@ -265,7 +265,7 @@ int connect_to_server(const wssshc_config_t *config) {
}
// Send registration message
if (!send_json_message(ssl, "register", config->client_id, config->password)) {
if (!send_registration_message(ssl, config->client_id, config->password)) {
SSL_free(ssl);
SSL_CTX_free(ssl_ctx);
close(sock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment