From 701fcc7c7e353def78d89d9ee0ca52d32fb894b9 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 14 Apr 2012 13:06:11 +0200 Subject: Separate handshake from encryption method --- src/config.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index 8c63b4e..e7c8640 100644 --- a/src/config.c +++ b/src/config.c @@ -41,10 +41,12 @@ #include -extern const fastd_protocol fastd_protocol_null; +extern const fastd_protocol fastd_protocol_ec25519_fhmqvc; -#ifdef WITH_PROTOCOL_ECFXP -extern const fastd_protocol fastd_protocol_ec25519_fhmqvc_xsalsa20_poly1305; +extern const fastd_method fastd_method_null; + +#ifdef WITH_METHOD_XSALSA20_POLY1305 +extern const fastd_method fastd_method_xsalsa20_poly1305; #endif @@ -66,7 +68,8 @@ static void default_config(fastd_config *conf) { conf->peer_to_peer = false; - conf->protocol = &fastd_protocol_null; + conf->protocol = &fastd_protocol_ec25519_fhmqvc; + conf->method = &fastd_method_null; conf->secret = NULL; conf->key_valid = 3600; /* 60 minutes */ conf->key_refresh = 3300; /* 55 minutes */ @@ -107,6 +110,28 @@ static bool config_match(const char *opt, ...) { return match; } +bool fastd_config_protocol(fastd_context *ctx, fastd_config *conf, const char *name) { + if (!strcmp(name, "ec25519-fhmqvc")) + conf->protocol = &fastd_protocol_ec25519_fhmqvc; + else + return false; + + return true; +} + +bool fastd_config_method(fastd_context *ctx, fastd_config *conf, const char *name) { + if (!strcmp(name, "null")) + conf->method = &fastd_method_null; +#ifdef WITH_METHOD_XSALSA20_POLY1305 + else if (!strcmp(name, "xsalsa20-poly1305")) + conf->method = &fastd_method_xsalsa20_poly1305; +#endif + else + return false; + + return true; +} + static void read_peer_dir(fastd_context *ctx, fastd_config *conf, const char *dir) { DIR *dirh = opendir("."); @@ -436,17 +461,17 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con IF_OPTION_ARG("-P", "--protocol") { - if (!strcmp(arg, "null")) - conf->protocol = &fastd_protocol_null; -#ifdef WITH_PROTOCOL_ECFXP - else if (!strcmp(arg, "ecfxp")) - conf->protocol = &fastd_protocol_ec25519_fhmqvc_xsalsa20_poly1305; -#endif - else + if (!fastd_config_protocol(ctx, conf, arg)) exit_error(ctx, "invalid protocol `%s'", arg); continue; } + IF_OPTION_ARG("--method") { + if (!fastd_config_method(ctx, conf, arg)) + exit_error(ctx, "invalid method `%s'", arg); + continue; + } + IF_OPTION_ARG("-p", "--peer") { peer = fastd_peer_config_new(ctx, conf); -- cgit v1.2.3