From ba0af8cc20e762ef6addeefaa96f951a995bafb1 Mon Sep 17 00:00:00 2001 From: angt Date: Tue, 29 Dec 2015 18:31:23 +0100 Subject: [PATCH] Define VERSION_MAJOR and use it in handshake --- configure.ac | 1 + src/main.c | 6 ++++-- version.sh | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 4093f23..181a4e8 100644 --- a/configure.ac +++ b/configure.ac @@ -4,6 +4,7 @@ AC_INIT([glorytun], [https://github.com/angt/glorytun/issues], [glorytun], [https://github.com/angt/glorytun]) +AC_DEFINE_UNQUOTED([VERSION_MAJOR], [m4_esyscmd([./version.sh major])]) AC_CONFIG_SRCDIR([src/common.h]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/src/main.c b/src/main.c index 031ba07..2e934a3 100644 --- a/src/main.c +++ b/src/main.c @@ -651,6 +651,8 @@ static int gt_setup_secretkey (struct crypto_ctx *ctx, char *keyfile) static int gt_setup_crypto (struct crypto_ctx *ctx, int fd, int listener) { + const uint8_t gt[] = {'G', 'T', VERSION_MAJOR, 0 }; + const size_t size = 96; const size_t hash_size = 32; @@ -673,7 +675,7 @@ static int gt_setup_crypto (struct crypto_ctx *ctx, int fd, int listener) randombytes_buf(secret, sizeof(secret)); crypto_scalarmult_base(&data_w[nonce_size], secret); - byte_cpy(&data_w[size-hash_size-4], "GT\0\0", 4); + byte_cpy(&data_w[size-hash_size-sizeof(gt)], gt, sizeof(gt)); crypto_generichash(&data_w[size-hash_size], hash_size, data_w, size-hash_size, ctx->skey, sizeof(ctx->skey)); @@ -684,7 +686,7 @@ static int gt_setup_crypto (struct crypto_ctx *ctx, int fd, int listener) if (fd_read_all(fd, data_r, size)!=size) return -1; - if (memcmp(&data_r[size-hash_size-4], &data_w[size-hash_size-4], 4)) + if (memcmp(&data_r[size-hash_size-sizeof(gt)], gt, sizeof(gt))) return -2; crypto_generichash(hash, hash_size, diff --git a/version.sh b/version.sh index 1d90245..c6ae5ec 100755 --- a/version.sh +++ b/version.sh @@ -6,4 +6,6 @@ [ -z "${VERSION}" ] && VERSION=`basename \`pwd\`` \ && VERSION=${VERSION#*-} +[ "$1" = "major" ] && VERSION=${VERSION%%.*} + printf ${VERSION}