Browse Source

renamed variables, parameters, constants, fields and files that contain or are about the user supplied seed to random_seeed.

pull/1/head
Maximilian Münchow 8 years ago
parent
commit
75c9fd8642
  1. 2
      src/libxt_TS3INIT_MORPH_TO_GET_COOKIE.c
  2. 2
      src/libxt_TS3INIT_RESET.c
  3. 68
      src/libxt_TS3INIT_SET_COOKIE.c
  4. 2
      src/libxt_ts3init_get_cookie.c
  5. 60
      src/libxt_ts3init_get_puzzle.c
  6. 8
      src/ts3init_cache.c
  7. 8
      src/ts3init_cache.h
  8. 12
      src/ts3init_cookie.c
  9. 4
      src/ts3init_cookie.h
  10. 4
      src/ts3init_match.c
  11. 12
      src/ts3init_match.h
  12. 18
      src/ts3init_random_seed.h
  13. 6
      src/ts3init_target.c
  14. 12
      src/ts3init_target.h

2
src/libxt_TS3INIT_MORPH_TO_GET_COOKIE.c

@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_target.h" #include "ts3init_target.h"
static void ts3init_morph_to_get_cookie_help(void) static void ts3init_morph_to_get_cookie_help(void)

2
src/libxt_TS3INIT_RESET.c

@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_target.h" #include "ts3init_target.h"
static void ts3init_reset_help(void) static void ts3init_reset_help(void)

68
src/libxt_TS3INIT_SET_COOKIE.c

@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_target.h" #include "ts3init_target.h"
#define param_act(t, s, f) xtables_param_act((t), "ts3init_set_cookie", (s), (f)) #define param_act(t, s, f) xtables_param_act((t), "ts3init_set_cookie", (s), (f))
@ -27,20 +27,20 @@ static void ts3init_set_cookie_tg_help(void)
printf( printf(
"TS3INIT_SET_COOKIE target options:\n" "TS3INIT_SET_COOKIE target options:\n"
" --zero-random-sequence Always return 0 as random sequence.\n" " --zero-random-sequence Always return 0 as random sequence.\n"
" --seed <seed> Seed is a %i byte lowercase hex number in.\n" " --random-seed <seed> Seed is a %i byte lowercase hex number in.\n"
" A source could be /dev/random.\n" " A source could be /dev/random.\n"
" --seed-file <file> Read the seed from a file.\n", " --random-seed-file <file> Read the seed from a file.\n",
COOKIE_SEED_LEN); RANDOM_SEED_LEN);
} }
static const struct option ts3init_set_cookie_tg_opts[] = { static const struct option ts3init_set_cookie_tg_opts[] = {
{.name = "zero-random-sequence", .has_arg = false, .val = '1'}, {.name = "zero-random-sequence", .has_arg = false, .val = '1'},
{.name = "seed", .has_arg = true, .val = '2'}, {.name = "random-seed", .has_arg = true, .val = '2'},
{.name = "seed-file", .has_arg = true, .val = '3'}, {.name = "random-seed-file", .has_arg = true, .val = '3'},
{NULL}, {NULL},
}; };
static int ts3init_set_cookie_tg_parse(int c, char **argv, static int ts3init_set_cookie_tg_parse(int c, char **argv,
int invert, unsigned int *flags, const void *entry, int invert, unsigned int *flags, const void *entry,
struct xt_entry_target **target) struct xt_entry_target **target)
{ {
@ -52,26 +52,26 @@ static int ts3init_set_cookie_tg_parse(int c, char **argv,
info->specific_options |= TARGET_SET_COOKIE_ZERO_RANDOM_SEQUENCE; info->specific_options |= TARGET_SET_COOKIE_ZERO_RANDOM_SEQUENCE;
return true; return true;
case '2': case '2':
param_act(XTF_ONLY_ONCE, "--seed", *flags & TARGET_SET_COOKIE_SEED_FROM_ARGUMENT); param_act(XTF_ONLY_ONCE, "--random-seed", *flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT);
param_act(XTF_NO_INVERT, "--seed", invert); param_act(XTF_NO_INVERT, "--random-seed", invert);
if (strlen(optarg) != (COOKIE_SEED_LEN * 2)) if (strlen(optarg) != (RANDOM_SEED_LEN * 2))
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"TS3INIT_SET_COOKIE: invalid seed length"); "TS3INIT_SET_COOKIE: invalid random seed length");
if (!hex2int_seed(optarg, info->cookie_seed)) if (!parse_random_seed(optarg, info->random_seed))
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"TS3INIT_SET_COOKIE: invalid seed. (not lowercase hex)"); "TS3INIT_SET_COOKIE: invalid random seed. (not lowercase hex)");
info->specific_options |= TARGET_SET_COOKIE_SEED_FROM_ARGUMENT; info->specific_options |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT;
*flags |= TARGET_SET_COOKIE_SEED_FROM_ARGUMENT; *flags |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT;
return true; return true;
case '3': case '3':
param_act(XTF_ONLY_ONCE, "--seed-file", *flags & TARGET_SET_COOKIE_SEED_FROM_FILE); param_act(XTF_ONLY_ONCE, "--random-seed-file", *flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE);
param_act(XTF_NO_INVERT, "--seed-file", invert); param_act(XTF_NO_INVERT, "--random-seed-file", invert);
if (read_cookie_seed_from_file("TS3INIT_SET_COOKIE", optarg, info->cookie_seed)) if (read_random_seed_from_file("TS3INIT_SET_COOKIE", optarg, info->random_seed))
memcpy(info->cookie_seed_path, optarg, strlen(optarg) + 1); memcpy(info->random_seed_path, optarg, strlen(optarg) + 1);
info->specific_options |= TARGET_SET_COOKIE_SEED_FROM_FILE; info->specific_options |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE;
*flags |= TARGET_SET_COOKIE_SEED_FROM_FILE; *flags |= TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE;
return true; return true;
default: default:
@ -86,18 +86,18 @@ static void ts3init_set_cookie_tg_save(const void *ip, const struct xt_entry_tar
{ {
printf("--zero-random-sequence "); printf("--zero-random-sequence ");
} }
if (info->specific_options & TARGET_SET_COOKIE_SEED_FROM_ARGUMENT) if (info->specific_options & TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT)
{ {
printf("--seed "); printf("--random-seed ");
for (int i = 0; i < COOKIE_SEED_LEN; i++) for (int i = 0; i < RANDOM_SEED_LEN; i++)
{ {
printf("%02X", info->cookie_seed[i]); printf("%02X", info->random_seed[i]);
} }
printf(" "); printf(" ");
} }
if (info->specific_options & TARGET_SET_COOKIE_SEED_FROM_FILE) if (info->specific_options & TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE)
{ {
printf("--seed-file \"%s\" ", info->cookie_seed_path); printf("--random-seed-file \"%s\" ", info->random_seed_path);
} }
} }
@ -110,18 +110,18 @@ static void ts3init_set_cookie_tg_print(const void *ip, const struct xt_entry_ta
static void ts3init_set_cookie_tg_check(unsigned int flags) static void ts3init_set_cookie_tg_check(unsigned int flags)
{ {
bool seed_from_argument = flags & TARGET_SET_COOKIE_SEED_FROM_ARGUMENT; bool random_seed_from_argument = flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT;
bool seed_from_file = flags & TARGET_SET_COOKIE_SEED_FROM_FILE; bool random_seed_from_file = flags & TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE;
if (seed_from_argument && seed_from_file) if (random_seed_from_argument && random_seed_from_file)
{ {
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"TS3INIT_SET_COOKIE: --seed and --seed-file " "TS3INIT_SET_COOKIE: --random-seed and --random-seed-file "
"can not be specified at the same time"); "can not be specified at the same time");
} }
if (!seed_from_argument && !seed_from_file) if (!random_seed_from_argument && !random_seed_from_file)
{ {
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"TS3INIT_SET_COOKIE: either --seed or --seed-file " "TS3INIT_SET_COOKIE: either --random-seed or --random-seed-file "
"must be specified"); "must be specified");
} }
} }

2
src/libxt_ts3init_get_cookie.c

@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_match.h" #include "ts3init_match.h"
#define param_act(t, s, f) xtables_param_act((t), "ts3init_get_cookie", (s), (f)) #define param_act(t, s, f) xtables_param_act((t), "ts3init_get_cookie", (s), (f))

60
src/libxt_ts3init_get_puzzle.c

@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_match.h" #include "ts3init_match.h"
#define param_act(t, s, f) xtables_param_act((t), "ts3init_get_puzzle", (s), (f)) #define param_act(t, s, f) xtables_param_act((t), "ts3init_get_puzzle", (s), (f))
@ -29,18 +29,18 @@ static void ts3init_get_puzzle_help(void)
"ts3init_get_puzzle match options:\n" "ts3init_get_puzzle match options:\n"
" --min-client n The sending client needs to be at least version.\n" " --min-client n The sending client needs to be at least version.\n"
" --check-cookie Check that the cookie was generated by same seed.\n" " --check-cookie Check that the cookie was generated by same seed.\n"
" --seed <seed> Seed is a %i byte lowercase hex number in.\n" " --random-seed <seed> Seed is a %i byte lowercase hex number in.\n"
" A source could be /dev/random.\n" " A source could be /dev/random.\n"
" --seed-file <file> Read the seed from a file.\n", " --random-seed-file <file> Read the seed from a file.\n",
COOKIE_SEED_LEN RANDOM_SEED_LEN
); );
} }
static const struct option ts3init_get_puzzle_opts[] = { static const struct option ts3init_get_puzzle_opts[] = {
{.name = "min-client", .has_arg = true, .val = '1'}, {.name = "min-client", .has_arg = true, .val = '1'},
{.name = "check-cookie", .has_arg = false, .val = '2'}, {.name = "check-cookie", .has_arg = false, .val = '2'},
{.name = "seed", .has_arg = true, .val = '3'}, {.name = "random-seed", .has_arg = true, .val = '3'},
{.name = "seed-file", .has_arg = true, .val = '4'}, {.name = "random-seed-file", .has_arg = true, .val = '4'},
{NULL}, {NULL},
}; };
@ -70,26 +70,26 @@ static int ts3init_get_puzzle_parse(int c, char **argv, int invert, unsigned int
return true; return true;
case '3': case '3':
param_act(XTF_ONLY_ONCE, "--seed", info->specific_options & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT); param_act(XTF_ONLY_ONCE, "--random-seed", info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT);
param_act(XTF_NO_INVERT, "--seed", invert); param_act(XTF_NO_INVERT, "--random-seed", invert);
if (strlen(optarg) != (COOKIE_SEED_LEN * 2)) if (strlen(optarg) != (RANDOM_SEED_LEN * 2))
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"ts3init_get_puzzle: invalid seed length"); "ts3init_get_puzzle: invalid random seed length");
if (!hex2int_seed(optarg, info->cookie_seed)) if (!parse_random_seed(optarg, info->random_seed))
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"ts3init_get_puzzle: invalid seed. (not lowercase hex)"); "ts3init_get_puzzle: invalid random seed. (not lowercase hex)");
info->specific_options |= CHK_GET_PUZZLE_SEED_FROM_ARGUMENT; info->specific_options |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT;
*flags |= CHK_GET_PUZZLE_SEED_FROM_ARGUMENT; *flags |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT;
return true; return true;
case '4': case '4':
param_act(XTF_ONLY_ONCE, "--seed-file", info->specific_options & CHK_GET_PUZZLE_SEED_FROM_FILE); param_act(XTF_ONLY_ONCE, "--random-seed-file", info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE);
param_act(XTF_NO_INVERT, "--seed-file", invert); param_act(XTF_NO_INVERT, "--random-seed-file", invert);
if (read_cookie_seed_from_file("ts3init_get_puzzle", optarg, info->cookie_seed)) if (read_random_seed_from_file("ts3init_get_puzzle", optarg, info->random_seed))
memcpy(info->cookie_seed_path, optarg, strlen(optarg) + 1); memcpy(info->random_seed_path, optarg, strlen(optarg) + 1);
info->specific_options |= CHK_GET_PUZZLE_SEED_FROM_FILE; info->specific_options |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE;
*flags |= CHK_GET_PUZZLE_SEED_FROM_FILE; *flags |= CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE;
return true; return true;
default: default:
@ -108,18 +108,18 @@ static void ts3init_get_puzzle_save(const void *ip, const struct xt_entry_match
{ {
printf("--check-cookie "); printf("--check-cookie ");
} }
if (info->specific_options & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT) if (info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT)
{ {
printf("--seed "); printf("--random-seed ");
for (int i = 0; i < COOKIE_SEED_LEN; i++) for (int i = 0; i < RANDOM_SEED_LEN; i++)
{ {
printf("%02X", info->cookie_seed[i]); printf("%02X", info->random_seed[i]);
} }
printf(" "); printf(" ");
} }
if (info->specific_options & CHK_GET_PUZZLE_SEED_FROM_FILE) if (info->specific_options & CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE)
{ {
printf("--seed-file \"%s\" ", info->cookie_seed_path); printf("--random-seed-file \"%s\" ", info->random_seed_path);
} }
} }
@ -132,12 +132,12 @@ static void ts3init_get_puzzle_print(const void *ip, const struct xt_entry_match
static void ts3init_get_puzzle_check(unsigned int flags) static void ts3init_get_puzzle_check(unsigned int flags)
{ {
bool seed_from_argument = flags & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT; bool seed_from_argument = flags & CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT;
bool seed_from_file = flags & CHK_GET_PUZZLE_SEED_FROM_FILE; bool seed_from_file = flags & CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE;
if (seed_from_argument && seed_from_file) if (seed_from_argument && seed_from_file)
{ {
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"ts3init_get_puzzle: --seed and --seed-file " "ts3init_get_puzzle: --random-seed and --random-seed-file "
"can not be specified at the same time"); "can not be specified at the same time");
} }
if (flags & CHK_GET_PUZZLE_CHECK_COOKIE) if (flags & CHK_GET_PUZZLE_CHECK_COOKIE)
@ -146,7 +146,7 @@ static void ts3init_get_puzzle_check(unsigned int flags)
{ {
xtables_error(PARAMETER_PROBLEM, xtables_error(PARAMETER_PROBLEM,
"ts3init_get_puzzle: --check-cookie requires either " "ts3init_get_puzzle: --check-cookie requires either "
"--seed or --seed-file"); "--random-seed or --random-seed-file");
} }
} }
} }

8
src/ts3init_cache.c

@ -65,7 +65,7 @@ time_t ts3init_get_cached_unix_time(void)
return current_unix_time; return current_unix_time;
} }
bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (*cookie)[2]) bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* random_seed, u64 (*cookie)[2])
{ {
struct ts3init_cache_t* cache; struct ts3init_cache_t* cache;
u64* result; u64* result;
@ -80,7 +80,7 @@ bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (*
current_unix_time = cache->unix_time; current_unix_time = cache->unix_time;
result = ts3init_get_cookie_seed(current_unix_time, result = ts3init_get_cookie_seed(current_unix_time,
packet_index, &cache->cookie_cache, seed); packet_index, &cache->cookie_cache, random_seed);
if (result) if (result)
{ {
@ -91,7 +91,7 @@ bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (*
return result; return result;
} }
bool ts3init_get_current_cookie(const u8* seed, u64 (*cookie)[2], u8 *packet_index) bool ts3init_get_current_cookie(const u8* random_seed, u64 (*cookie)[2], u8 *packet_index)
{ {
struct ts3init_cache_t* cache; struct ts3init_cache_t* cache;
u64* result; u64* result;
@ -108,7 +108,7 @@ bool ts3init_get_current_cookie(const u8* seed, u64 (*cookie)[2], u8 *packet_ind
*packet_index = current_unix_time % 8; *packet_index = current_unix_time % 8;
result = ts3init_get_cookie_seed(current_unix_time, result = ts3init_get_cookie_seed(current_unix_time,
*packet_index, &cache->cookie_cache, seed); *packet_index, &cache->cookie_cache, random_seed);
if (result) if (result)
{ {

8
src/ts3init_cache.h

@ -9,14 +9,14 @@ time_t ts3init_get_cached_unix_time(void);
/* /*
* Returns the cookie for a packet_index. * Returns the cookie for a packet_index.
* If the cookie is not in the cache, it will be generated using the seed. * If the cookie is not in the cache, it will be generated using the random seed.
*/ */
bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* seed, u64 (*cookie)[2]); bool ts3init_get_cookie_for_packet_index(u8 packet_index, const u8* random_seed, u64 (*cookie)[2]);
/* /*
* Returns the current cookie and packet_index. * Returns the current cookie and packet_index.
* If the cookie is not in the cache, it will be generated using the seed. * If the cookie is not in the cache, it will be generated using the random seed.
*/ */
bool ts3init_get_current_cookie(const u8* seed, u64 (*cookie)[2], u8 *packet_index); bool ts3init_get_current_cookie(const u8* random_seed, u64 (*cookie)[2], u8 *packet_index);
#endif /* _TS3INIT_CACHE_H */ #endif /* _TS3INIT_CACHE_H */

12
src/ts3init_cookie.c

@ -21,12 +21,12 @@
#include <linux/ipv6.h> #include <linux/ipv6.h>
#include <linux/udp.h> #include <linux/udp.h>
#include "siphash24.h" #include "siphash24.h"
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_cookie.h" #include "ts3init_cookie.h"
static void check_update_seed_cache(time_t time, __u8 index, static void check_update_seed_cache(time_t time, __u8 index,
struct xt_ts3init_cookie_cache* cache, struct xt_ts3init_cookie_cache* cache,
const __u8* cookie_seed) const __u8* random_seed)
{ {
struct hash_desc desc; struct hash_desc desc;
struct scatterlist sg[2]; struct scatterlist sg[2];
@ -36,10 +36,10 @@ static void check_update_seed_cache(time_t time, __u8 index,
if (time == cache->time[index]) return; if (time == cache->time[index]) return;
/* We need to update the cache. */ /* We need to update the cache. */
/* seed = sha512(cookie_seed[COOKIE_SEED_LEN] + __le32 time) */ /* seed = sha512(random_seed[RANDOM_SEED_LEN] + __le32 time) */
seed_hash_time = cpu_to_le32( (__u32)time); seed_hash_time = cpu_to_le32( (__u32)time);
sg_init_table(sg, ARRAY_SIZE(sg)); sg_init_table(sg, ARRAY_SIZE(sg));
sg_set_buf(&sg[0], cookie_seed, COOKIE_SEED_LEN); sg_set_buf(&sg[0], random_seed, RANDOM_SEED_LEN);
sg_set_buf(&sg[1], &seed_hash_time, 4); sg_set_buf(&sg[1], &seed_hash_time, 4);
desc.tfm = crypto_alloc_hash("sha512", 0, 0); desc.tfm = crypto_alloc_hash("sha512", 0, 0);
@ -70,7 +70,7 @@ static void check_update_seed_cache(time_t time, __u8 index,
__u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index, __u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index,
struct xt_ts3init_cookie_cache* cache, struct xt_ts3init_cookie_cache* cache,
const __u8* cookie_seed) const __u8* random_seed)
{ {
__u8 current_cache_index; __u8 current_cache_index;
@ -90,7 +90,7 @@ __u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index,
/* make sure the cache is up-to-date */ /* make sure the cache is up-to-date */
check_update_seed_cache(packet_cache_time, packet_cache_index, cache, check_update_seed_cache(packet_cache_time, packet_cache_index, cache,
cookie_seed); random_seed);
/* return the proper seed */ /* return the proper seed */
return cache->seed64 + ((SIP_KEY_SIZE/sizeof(__u64)) * packet_index ); return cache->seed64 + ((SIP_KEY_SIZE/sizeof(__u64)) * packet_index );

4
src/ts3init_cookie.h

@ -19,11 +19,11 @@ struct xt_ts3init_cookie_cache
/* /*
* Returns the cookie that fits current_time and packet_index. * Returns the cookie that fits current_time and packet_index.
* If the cookie is missing in cache it will be generated using * If the cookie is missing in cache it will be generated using
* cookie_seed and current_time * random_seed and current_time
*/ */
__u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index, __u64* ts3init_get_cookie_seed(time_t current_time, __u8 packet_index,
struct xt_ts3init_cookie_cache* cache, struct xt_ts3init_cookie_cache* cache,
const __u8* cookie_seed); const __u8* random_seed);
/* /*
* Returns the hash of cookie and source/destination address/port. * Returns the hash of cookie and source/destination address/port.

4
src/ts3init_match.c

@ -20,7 +20,7 @@
#include <linux/udp.h> #include <linux/udp.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_cookie.h" #include "ts3init_cookie.h"
#include "ts3init_match.h" #include "ts3init_match.h"
#include "ts3init_header.h" #include "ts3init_header.h"
@ -217,7 +217,7 @@ static bool ts3init_get_puzzle_mt(const struct sk_buff *skb, struct xt_action_pa
__u64 cookie_seed[2]; __u64 cookie_seed[2];
__u64 cookie, packet_cookie; __u64 cookie, packet_cookie;
if (ts3init_get_cookie_for_packet_index(ts3_header->payload[8], info->cookie_seed, &cookie_seed) == false) if (ts3init_get_cookie_for_packet_index(ts3_header->payload[8], info->random_seed, &cookie_seed) == false)
return false; return false;
/* use cookie_seed and ipaddress and port to create a hash /* use cookie_seed and ipaddress and port to create a hash

12
src/ts3init_match.h

@ -30,10 +30,10 @@ struct xt_ts3init_get_cookie_mtinfo
/* Enums and structs for get_puzzle */ /* Enums and structs for get_puzzle */
enum enum
{ {
CHK_GET_PUZZLE_CHECK_COOKIE = 1 << 0, CHK_GET_PUZZLE_CHECK_COOKIE = 1 << 0,
CHK_GET_PUZZLE_SEED_FROM_ARGUMENT = 1 << 1, CHK_GET_PUZZLE_RANDOM_SEED_FROM_ARGUMENT = 1 << 1,
CHK_GET_PUZZLE_SEED_FROM_FILE = 1 << 2, CHK_GET_PUZZLE_RANDOM_SEED_FROM_FILE = 1 << 2,
CHK_GET_PUZZLE_VALID_MASK = (1 << 3) - 1, CHK_GET_PUZZLE_VALID_MASK = (1 << 3) - 1,
}; };
struct xt_ts3init_get_puzzle_mtinfo struct xt_ts3init_get_puzzle_mtinfo
@ -42,8 +42,8 @@ struct xt_ts3init_get_puzzle_mtinfo
__u8 specific_options; __u8 specific_options;
__u16 reserved1; __u16 reserved1;
__u32 min_client_version; __u32 min_client_version;
__u8 cookie_seed[COOKIE_SEED_LEN]; __u8 random_seed[RANDOM_SEED_LEN];
char cookie_seed_path[COOKIE_PATH_MAX]; char random_seed_path[RANDOM_SEED_PATH_MAX];
}; };
#endif /* _TS3INIT_MATCH_H */ #endif /* _TS3INIT_MATCH_H */

18
src/ts3init_cookie_seed.h → src/ts3init_random_seed.h

@ -2,18 +2,18 @@
#define _TS3INIT_COOKIE_SEED_H #define _TS3INIT_COOKIE_SEED_H
enum { enum {
COOKIE_SEED_LEN = 60, RANDOM_SEED_LEN = 60,
COOKIE_PATH_MAX = 256, RANDOM_SEED_PATH_MAX = 256,
}; };
/* /*
* Parses a hexstring into dest. * Parses a hexstring into dest.
* It is assumed that COOKIE_SEED_LEN bytes are to be parsed. * It is assumed that RANDOM_SEED_LEN bytes are to be parsed.
*/ */
static inline bool hex2int_seed(const char *src, __u8* dst) static inline bool parse_random_seed(const char *src, __u8* dst)
{ {
int i, j; int i, j;
for (i = 0; i < COOKIE_SEED_LEN; ++i) for (i = 0; i < RANDOM_SEED_LEN; ++i)
{ {
int v = 0; int v = 0;
for ( j = 0; j < 2; ++j) for ( j = 0; j < 2; ++j)
@ -35,11 +35,11 @@ static inline bool hex2int_seed(const char *src, __u8* dst)
/* /*
* Reads a cookie seed from a file. * Reads a cookie seed from a file.
*/ */
static inline bool read_cookie_seed_from_file(const char *module_name, const char *path, __u8* dst) static inline bool read_random_seed_from_file(const char *module_name, const char *path, __u8* dst)
{ {
int n, fd; int n, fd;
char text[COOKIE_SEED_LEN * 2], error_message[256]; char text[RANDOM_SEED_LEN * 2], error_message[256];
if (strlen(path) > COOKIE_PATH_MAX) if (strlen(path) > RANDOM_SEED_PATH_MAX)
{ {
xtables_error(PARAMETER_PROBLEM, "%s: path is too long.", module_name); xtables_error(PARAMETER_PROBLEM, "%s: path is too long.", module_name);
return false; return false;
@ -56,7 +56,7 @@ static inline bool read_cookie_seed_from_file(const char *module_name, const cha
n = read(fd, text, sizeof(text)); n = read(fd, text, sizeof(text));
if (n == -1) goto io_error; if (n == -1) goto io_error;
else if (n != sizeof(text) || hex2int_seed(text, dst) == false) else if (n != sizeof(text) || parse_random_seed(text, dst) == false)
{ {
xtables_error(PARAMETER_PROBLEM, "%s: %s must contain exactly %lu lowercase hex characters", module_name, path, sizeof(text)); xtables_error(PARAMETER_PROBLEM, "%s: %s must contain exactly %lu lowercase hex characters", module_name, path, sizeof(text));
return false; return false;

6
src/ts3init_target.c

@ -26,7 +26,7 @@
#include <net/ip6_route.h> #include <net/ip6_route.h>
#include <net/route.h> #include <net/route.h>
#include "compat_xtables.h" #include "compat_xtables.h"
#include "ts3init_cookie_seed.h" #include "ts3init_random_seed.h"
#include "ts3init_cookie.h" #include "ts3init_cookie.h"
#include "ts3init_target.h" #include "ts3init_target.h"
#include "ts3init_header.h" #include "ts3init_header.h"
@ -231,7 +231,7 @@ ts3init_generate_cookie_ipv4(const struct xt_action_param *par,
const struct xt_ts3init_set_cookie_tginfo *info = par->targinfo; const struct xt_ts3init_set_cookie_tginfo *info = par->targinfo;
__u64 cookie[2]; __u64 cookie[2];
if (ts3init_get_current_cookie(info->cookie_seed, &cookie, packet_index) == false) if (ts3init_get_current_cookie(info->random_seed, &cookie, packet_index) == false)
return false; return false;
if (ts3init_calculate_cookie_ipv4(ip, udp, cookie[0], cookie[1], cookie_hash)) if (ts3init_calculate_cookie_ipv4(ip, udp, cookie[0], cookie[1], cookie_hash))
return false; return false;
@ -250,7 +250,7 @@ ts3init_generate_cookie_ipv6(const struct xt_action_param *par,
const struct xt_ts3init_set_cookie_tginfo *info = par->targinfo; const struct xt_ts3init_set_cookie_tginfo *info = par->targinfo;
__u64 cookie[2]; __u64 cookie[2];
if (ts3init_get_current_cookie(info->cookie_seed, &cookie, packet_index) == false) if (ts3init_get_current_cookie(info->random_seed, &cookie, packet_index) == false)
return false; return false;
if (ts3init_calculate_cookie_ipv6(ip, udp, cookie[0], cookie[1], cookie_hash)) if (ts3init_calculate_cookie_ipv6(ip, udp, cookie[0], cookie[1], cookie_hash))
return false; return false;

12
src/ts3init_target.h

@ -10,10 +10,10 @@ enum
/* Enums and structs for set_cookie */ /* Enums and structs for set_cookie */
enum enum
{ {
TARGET_SET_COOKIE_ZERO_RANDOM_SEQUENCE = 1 << 0, TARGET_SET_COOKIE_ZERO_RANDOM_SEQUENCE = 1 << 0,
TARGET_SET_COOKIE_SEED_FROM_ARGUMENT = 1 << 1, TARGET_SET_COOKIE_RANDOM_SEED_FROM_ARGUMENT = 1 << 1,
TARGET_SET_COOKIE_SEED_FROM_FILE = 1 << 2, TARGET_SET_COOKIE_RANDOM_SEED_FROM_FILE = 1 << 2,
TARGET_SET_COOKIE_VALID_MASK = (1 << 3) - 1 TARGET_SET_COOKIE_VALID_MASK = (1 << 3) - 1
}; };
@ -22,8 +22,8 @@ struct xt_ts3init_set_cookie_tginfo
__u8 common_options; __u8 common_options;
__u8 specific_options; __u8 specific_options;
__u16 reserved1; __u16 reserved1;
__u8 cookie_seed[COOKIE_SEED_LEN]; __u8 random_seed[RANDOM_SEED_LEN];
char cookie_seed_path[COOKIE_PATH_MAX]; char random_seed_path[RANDOM_SEED_PATH_MAX];
}; };
#endif /* _TS3INIT_TARGET_H */ #endif /* _TS3INIT_TARGET_H */

Loading…
Cancel
Save