diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-02-25 05:26:45 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-02-25 05:26:45 +0100 |
commit | da761883608d20798c66a2e9243240bb6142b024 (patch) | |
tree | b7a5d3cf9c724a43761ee30373cb5e617a00f8cc | |
parent | 0b6cc8b646d4824658e1534d4bbebe62d47b5695 (diff) | |
download | fastd-da761883608d20798c66a2e9243240bb6142b024.tar fastd-da761883608d20798c66a2e9243240bb6142b024.zip |
Add public keys to shell environment
-rw-r--r-- | src/fastd.h | 1 | ||||
-rw-r--r-- | src/protocol_ec25519_fhmqvc.c | 38 | ||||
-rw-r--r-- | src/shell.c | 2 |
3 files changed, 31 insertions, 10 deletions
diff --git a/src/fastd.h b/src/fastd.h index 731ee8c..ac27905 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -81,6 +81,7 @@ struct fastd_protocol { void (*generate_key)(fastd_context_t *ctx); void (*show_key)(fastd_context_t *ctx); + void (*set_shell_env)(fastd_context_t *ctx, const fastd_peer_t *peer); }; struct fastd_method { diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c index 99c5a1a..d0b6861 100644 --- a/src/protocol_ec25519_fhmqvc.c +++ b/src/protocol_ec25519_fhmqvc.c @@ -806,14 +806,17 @@ static void protocol_free_peer_state(fastd_context_t *ctx, fastd_peer_t *peer) { } } -static void hexdump(const char *desc, unsigned char d[32]) { - printf("%s", desc); - +static inline void hexdump(char out[65], unsigned char d[32]) { int i; for (i = 0; i < 32; i++) - printf("%02x", d[i]); + snprintf(out+2*i, 3, "%02x", d[i]); +} + +static inline void print_hexdump(const char *desc, unsigned char d[32]) { + char buf[65]; + hexdump(buf, d); - printf("\n"); + printf("%s%s\n", desc, buf); } static void protocol_generate_key(fastd_context_t *ctx) { @@ -831,21 +834,35 @@ static void protocol_generate_key(fastd_context_t *ctx) { ecc_25519_store_packed(&public_key, &work); if (ctx->conf->machine_readable) { - hexdump("", secret_key.p); + print_hexdump("", secret_key.p); } else { - hexdump("Secret: ", secret_key.p); - hexdump("Public: ", public_key.p); + print_hexdump("Secret: ", secret_key.p); + print_hexdump("Public: ", public_key.p); } } static void protocol_show_key(fastd_context_t *ctx) { if (ctx->conf->machine_readable) - hexdump("", ctx->conf->protocol_config->public_key.p); + print_hexdump("", ctx->conf->protocol_config->public_key.p); else - hexdump("Public: ", ctx->conf->protocol_config->public_key.p); + print_hexdump("Public: ", ctx->conf->protocol_config->public_key.p); } +static void protocol_set_shell_env(fastd_context_t *ctx, const fastd_peer_t *peer) { + char buf[65]; + + hexdump(buf, ctx->conf->protocol_config->public_key.p); + setenv("LOCAL_KEY", buf, 1); + + if (peer && peer->config && peer->config->protocol_config) { + hexdump(buf, peer->config->protocol_config->public_key.p); + setenv("PEER_KEY", buf, 1); + } + else { + unsetenv("PEER_KEY"); + } +} const fastd_protocol_t fastd_protocol_ec25519_fhmqvc = { .name = "ec25519-fhmqvc", @@ -865,4 +882,5 @@ const fastd_protocol_t fastd_protocol_ec25519_fhmqvc = { .generate_key = protocol_generate_key, .show_key = protocol_show_key, + .set_shell_env = protocol_set_shell_env, }; diff --git a/src/shell.c b/src/shell.c index c9dfab0..bcc22e1 100644 --- a/src/shell.c +++ b/src/shell.c @@ -100,6 +100,8 @@ bool fastd_shell_exec(fastd_context_t *ctx, const fastd_peer_t *peer, const char unsetenv("PEER_PORT"); } + ctx->conf->protocol->set_shell_env(ctx, peer); + result = system(command); if (ret) { |