ws-handshake: Use own base64 and SHA1 implementations
parent
923fa4a53a
commit
c4f48bc47d
|
@ -95,6 +95,7 @@ sources = [
|
||||||
'src/encoder.c',
|
'src/encoder.c',
|
||||||
'src/cursor.c',
|
'src/cursor.c',
|
||||||
'src/logging.c',
|
'src/logging.c',
|
||||||
|
'src/base64.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#include "websocket.h"
|
#include "websocket.h"
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
#include "crypto.h"
|
||||||
#include <nettle/sha1.h>
|
#include "base64.h"
|
||||||
#include <nettle/base64.h>
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -61,16 +60,16 @@ ssize_t ws_handshake(char* output, size_t output_maxlen, const char* input)
|
||||||
if (have_versions && !strstr(versions, ",13,"))
|
if (have_versions && !strstr(versions, ",13,"))
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
struct sha1_ctx ctx;
|
uint8_t hash[20];
|
||||||
sha1_init(&ctx);
|
crypto_hash_many(hash, sizeof(hash), CRYPTO_HASH_SHA1,
|
||||||
sha1_update(&ctx, strlen(challenge), (const uint8_t*)challenge);
|
(struct crypto_data_entry[]){
|
||||||
sha1_update(&ctx, strlen(magic_uuid), (const uint8_t*)magic_uuid);
|
{ (uint8_t*)challenge, strlen(challenge) },
|
||||||
|
{ (uint8_t*)magic_uuid, strlen(magic_uuid) },
|
||||||
|
{}
|
||||||
|
});
|
||||||
|
|
||||||
uint8_t hash[SHA1_DIGEST_SIZE];
|
char response[BASE64_ENCODED_SIZE(sizeof(hash))] = {};
|
||||||
sha1_digest(&ctx, sizeof(hash), hash);
|
base64_encode(response, hash, sizeof(hash));
|
||||||
|
|
||||||
char response[BASE64_ENCODE_RAW_LENGTH(SHA1_DIGEST_SIZE) + 1] = {};
|
|
||||||
base64_encode_raw(response, SHA1_DIGEST_SIZE, hash);
|
|
||||||
|
|
||||||
size_t len = snprintf(output, output_maxlen,
|
size_t len = snprintf(output, output_maxlen,
|
||||||
"HTTP/1.1 101 Switching Protocols\r\n"
|
"HTTP/1.1 101 Switching Protocols\r\n"
|
||||||
|
|
Loading…
Reference in New Issue