|
|
@ -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"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|