2018-06-20 08:13:28 -04:00
|
|
|
/* Copyright (c) 2017-2018, The Tor Project, Inc. */
|
2017-08-13 16:56:10 +07:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
#define HS_DESCRIPTOR_PRIVATE
|
|
|
|
|
2018-07-05 16:34:59 -04:00
|
|
|
#include "core/or/or.h"
|
2018-06-20 09:35:05 -04:00
|
|
|
#include "trunnel/ed25519_cert.h" /* Trunnel interface. */
|
2018-06-21 12:47:11 -04:00
|
|
|
#include "lib/crypt_ops/crypto_ed25519.h"
|
2018-07-05 16:34:59 -04:00
|
|
|
#include "feature/hs/hs_descriptor.h"
|
2018-09-30 18:15:00 -05:00
|
|
|
#include "feature/dirparse/unparseable.h"
|
2017-08-13 16:56:10 +07:00
|
|
|
|
2018-06-20 09:35:05 -04:00
|
|
|
#include "test/fuzz/fuzzing.h"
|
2017-08-13 16:56:10 +07:00
|
|
|
|
|
|
|
static void
|
|
|
|
mock_dump_desc__nodump(const char *desc, const char *type)
|
|
|
|
{
|
|
|
|
(void)desc;
|
|
|
|
(void)type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mock_rsa_ed25519_crosscert_check(const uint8_t *crosscert,
|
|
|
|
const size_t crosscert_len,
|
|
|
|
const crypto_pk_t *rsa_id_key,
|
|
|
|
const ed25519_public_key_t *master_key,
|
|
|
|
const time_t reject_if_expired_before)
|
|
|
|
{
|
|
|
|
(void) crosscert;
|
|
|
|
(void) crosscert_len;
|
|
|
|
(void) rsa_id_key;
|
|
|
|
(void) master_key;
|
|
|
|
(void) reject_if_expired_before;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-27 14:28:02 -04:00
|
|
|
static size_t
|
|
|
|
mock_decrypt_desc_layer(const hs_descriptor_t *desc,
|
|
|
|
const uint8_t *encrypted_blob,
|
|
|
|
size_t encrypted_blob_size,
|
2018-04-19 22:44:17 +07:00
|
|
|
const uint8_t *descriptor_cookie,
|
2017-10-27 14:28:02 -04:00
|
|
|
int is_superencrypted_layer,
|
|
|
|
char **decrypted_out)
|
|
|
|
{
|
|
|
|
(void)is_superencrypted_layer;
|
|
|
|
(void)desc;
|
2018-04-19 22:44:17 +07:00
|
|
|
(void)descriptor_cookie;
|
2017-10-27 14:28:02 -04:00
|
|
|
const size_t overhead = HS_DESC_ENCRYPTED_SALT_LEN + DIGEST256_LEN;
|
|
|
|
if (encrypted_blob_size < overhead)
|
|
|
|
return 0;
|
|
|
|
*decrypted_out = tor_memdup_nulterm(
|
|
|
|
encrypted_blob + HS_DESC_ENCRYPTED_SALT_LEN,
|
|
|
|
encrypted_blob_size - overhead);
|
2017-11-05 12:21:16 -05:00
|
|
|
size_t result = strlen(*decrypted_out);
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
tor_free(*decrypted_out);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-27 14:28:02 -04:00
|
|
|
}
|
|
|
|
|
2017-08-13 16:56:10 +07:00
|
|
|
int
|
|
|
|
fuzz_init(void)
|
|
|
|
{
|
|
|
|
disable_signature_checking();
|
|
|
|
MOCK(dump_desc, mock_dump_desc__nodump);
|
|
|
|
MOCK(rsa_ed25519_crosscert_check, mock_rsa_ed25519_crosscert_check);
|
2017-10-27 14:28:02 -04:00
|
|
|
MOCK(decrypt_desc_layer, mock_decrypt_desc_layer);
|
2017-08-13 16:56:10 +07:00
|
|
|
ed25519_init();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fuzz_cleanup(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fuzz_main(const uint8_t *data, size_t sz)
|
|
|
|
{
|
|
|
|
hs_descriptor_t *desc = NULL;
|
2017-10-26 09:52:15 -04:00
|
|
|
uint8_t subcredential[DIGEST256_LEN];
|
2017-08-13 16:56:10 +07:00
|
|
|
|
|
|
|
char *fuzzing_data = tor_memdup_nulterm(data, sz);
|
2017-10-26 09:52:15 -04:00
|
|
|
memset(subcredential, 'A', sizeof(subcredential));
|
2017-08-13 16:56:10 +07:00
|
|
|
|
2018-04-19 22:44:17 +07:00
|
|
|
hs_desc_decode_descriptor(fuzzing_data, subcredential, NULL, &desc);
|
2017-08-13 16:56:10 +07:00
|
|
|
if (desc) {
|
|
|
|
log_debug(LD_GENERAL, "Decoding okay");
|
|
|
|
hs_descriptor_free(desc);
|
|
|
|
} else {
|
|
|
|
log_debug(LD_GENERAL, "Decoding failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
tor_free(fuzzing_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|