Update mud and add option keygen
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
2
mud
2
mud
Submodule mud updated: 78b76437e5...91cf697fb4
54
src/main.c
54
src/main.c
@@ -51,6 +51,7 @@ static struct {
|
|||||||
int mtu_auto;
|
int mtu_auto;
|
||||||
int chacha20;
|
int chacha20;
|
||||||
int version;
|
int version;
|
||||||
|
int keygen;
|
||||||
struct {
|
struct {
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
long size;
|
long size;
|
||||||
@@ -130,7 +131,7 @@ gt_print_secretkey(struct mud *mud)
|
|||||||
char buf[2 * sizeof(key) + 1];
|
char buf[2 * sizeof(key) + 1];
|
||||||
|
|
||||||
gt_tohex(buf, sizeof(buf), key, size);
|
gt_tohex(buf, sizeof(buf), key, size);
|
||||||
gt_print("secret key: %s\n", buf);
|
gt_print("%s\n", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -195,6 +196,7 @@ gt_setup_option(int argc, char **argv)
|
|||||||
{ "mtu", >.mtu, option_long },
|
{ "mtu", >.mtu, option_long },
|
||||||
{ "mtu-auto", NULL, option_option },
|
{ "mtu-auto", NULL, option_option },
|
||||||
{ "keyfile", >.keyfile, option_str },
|
{ "keyfile", >.keyfile, option_str },
|
||||||
|
{ "keygen", NULL, option_option },
|
||||||
{ "timeout", >.timeout, option_long },
|
{ "timeout", >.timeout, option_long },
|
||||||
{ "time-tolerance", >.time_tolerance, option_long },
|
{ "time-tolerance", >.time_tolerance, option_long },
|
||||||
{ "v4only", NULL, option_option },
|
{ "v4only", NULL, option_option },
|
||||||
@@ -218,11 +220,6 @@ gt_setup_option(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gt.host && !option_is_set(opts, "keyfile")) {
|
|
||||||
gt_log("keyfile option must be set\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((int)gt.timeout <= 0) {
|
if ((int)gt.timeout <= 0) {
|
||||||
gt_log("bad timeout\n");
|
gt_log("bad timeout\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -246,6 +243,7 @@ gt_setup_option(int argc, char **argv)
|
|||||||
gt.mtu_auto = option_is_set(opts, "mtu-auto");
|
gt.mtu_auto = option_is_set(opts, "mtu-auto");
|
||||||
gt.chacha20 = option_is_set(opts, "chacha20");
|
gt.chacha20 = option_is_set(opts, "chacha20");
|
||||||
gt.version = option_is_set(opts, "version");
|
gt.version = option_is_set(opts, "version");
|
||||||
|
gt.keygen = option_is_set(opts, "keygen");
|
||||||
|
|
||||||
gt.buf.data = malloc(gt.buf.size);
|
gt.buf.data = malloc(gt.buf.size);
|
||||||
|
|
||||||
@@ -290,6 +288,36 @@ main(int argc, char **argv)
|
|||||||
gt_log("couldn't create ICMP socket\n");
|
gt_log("couldn't create ICMP socket\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct mud *mud = mud_create(gt.bind.port, gt.ipv4, gt.ipv6);
|
||||||
|
|
||||||
|
if (!mud) {
|
||||||
|
gt_log("couldn't create mud\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gt.keygen || str_empty(gt.keyfile)) {
|
||||||
|
if (mud_new_key(mud)) {
|
||||||
|
gt_log("couldn't generate a new key\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gt.keygen) {
|
||||||
|
gt_print_secretkey(mud);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gt.chacha20 && mud_set_aes(mud))
|
||||||
|
gt_log("AES is not available\n");
|
||||||
|
|
||||||
|
if (gt.timeout > 0)
|
||||||
|
mud_set_send_timeout_msec(mud, gt.timeout);
|
||||||
|
|
||||||
|
if (gt.time_tolerance > 0)
|
||||||
|
mud_set_time_tolerance_sec(mud, gt.time_tolerance);
|
||||||
|
|
||||||
|
mud_set_mtu(mud, GT_MTU(gt.mtu));
|
||||||
|
|
||||||
char *tun_name = NULL;
|
char *tun_name = NULL;
|
||||||
|
|
||||||
int tun_fd = tun_create(gt.dev, &tun_name);
|
int tun_fd = tun_create(gt.dev, &tun_name);
|
||||||
@@ -302,26 +330,14 @@ main(int argc, char **argv)
|
|||||||
if (tun_set_persist(tun_fd, 0) == -1)
|
if (tun_set_persist(tun_fd, 0) == -1)
|
||||||
perror("tun_set_persist");
|
perror("tun_set_persist");
|
||||||
|
|
||||||
struct mud *mud = mud_create(gt.bind.port, gt.ipv4, gt.ipv6,
|
|
||||||
!gt.chacha20, GT_MTU(gt.mtu));
|
|
||||||
|
|
||||||
if (!mud) {
|
|
||||||
gt_log("couldn't create mud\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str_empty(gt.keyfile)) {
|
if (str_empty(gt.keyfile)) {
|
||||||
|
gt_print("here is your new secret key:\n");
|
||||||
gt_print_secretkey(mud);
|
gt_print_secretkey(mud);
|
||||||
} else {
|
} else {
|
||||||
if (gt_setup_secretkey(mud, gt.keyfile))
|
if (gt_setup_secretkey(mud, gt.keyfile))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mud_set_send_timeout_msec(mud, gt.timeout);
|
|
||||||
|
|
||||||
if (gt.time_tolerance > 0)
|
|
||||||
mud_set_time_tolerance_sec(mud, gt.time_tolerance);
|
|
||||||
|
|
||||||
if (gt.host && gt.port) {
|
if (gt.host && gt.port) {
|
||||||
if (gt.bind.backup) {
|
if (gt.bind.backup) {
|
||||||
if (mud_peer(mud, gt.bind.backup, gt.host, gt.port, 1)) {
|
if (mud_peer(mud, gt.bind.backup, gt.host, gt.port, 1)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user