From: Steffan Karger Date: Sun, 22 Jan 2017 16:04:41 +0000 (+0100) Subject: Use SHA256 for the internal digest, instead of MD5 X-Git-Tag: v2.4.1~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cf585ce605d2328d7a2bb5cf44e82b8b196b551;p=thirdparty%2Fopenvpn.git Use SHA256 for the internal digest, instead of MD5 Our internal options digest uses MD5 hashes to store the state, instead of storing the full options string. There's nothing wrong with that, but it would still be better to use SHA256 because: * That makes it easier to make OpenVPN "FIPS-compliant" (forbids MD5) * We don't have to explain anymore that MD5 is fine too The slightly less bytes for the digest (16 instead of 32) and operations per connection setup are not worth sticking to MD5. Note that might SHA256 not be available in de crypto lib, OpenVPN will refuse to start and shout "Message hash algorithm 'SHA256' not found". Signed-off-by: Steffan Karger Acked-by: David Sommerseth Message-Id: <1485101081-9784-1-git-send-email-steffan@karger.me> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg13926.html Signed-off-by: David Sommerseth (cherry picked from commit 5b48e8c9f85442936f744c3c550d9d41fe8c7b60) --- diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 6ca0bc81b..09ff9f02f 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -132,9 +132,9 @@ #include "packet_id.h" #include "mtu.h" -/** Wrapper struct to pass around MD5 digests */ -struct md5_digest { - uint8_t digest[MD5_DIGEST_LENGTH]; +/** Wrapper struct to pass around SHA256 digests */ +struct sha256_digest { + uint8_t digest[SHA256_DIGEST_LENGTH]; }; /* diff --git a/src/openvpn/crypto_mbedtls.h b/src/openvpn/crypto_mbedtls.h index 525b256a6..da2db166a 100644 --- a/src/openvpn/crypto_mbedtls.h +++ b/src/openvpn/crypto_mbedtls.h @@ -73,6 +73,7 @@ typedef mbedtls_md_context_t hmac_ctx_t; #define MD4_DIGEST_LENGTH 16 #define MD5_DIGEST_LENGTH 16 #define SHA_DIGEST_LENGTH 20 +#define SHA256_DIGEST_LENGTH 32 #define DES_KEY_LENGTH 8 /** diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h index 56ec6e1c6..f8ddbc866 100644 --- a/src/openvpn/crypto_openssl.h +++ b/src/openvpn/crypto_openssl.h @@ -33,6 +33,7 @@ #include #include #include +#include /** Generic cipher key type %context. */ typedef EVP_CIPHER cipher_kt_t; diff --git a/src/openvpn/init.c b/src/openvpn/init.c index a540c68da..7b35cca8c 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1919,12 +1919,12 @@ tun_abort() * equal, or either one is all-zeroes. */ static bool -options_hash_changed_or_zero(const struct md5_digest *a, - const struct md5_digest *b) +options_hash_changed_or_zero(const struct sha256_digest *a, + const struct sha256_digest *b) { - const struct md5_digest zero = {{0}}; - return memcmp(a, b, sizeof(struct md5_digest)) - || !memcmp(a, &zero, sizeof(struct md5_digest)); + const struct sha256_digest zero = {{0}}; + return memcmp(a, b, sizeof(struct sha256_digest)) + || !memcmp(a, &zero, sizeof(struct sha256_digest)); } #endif /* P2MP */ diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h index 37edec4f7..893296edc 100644 --- a/src/openvpn/openvpn.h +++ b/src/openvpn/openvpn.h @@ -202,7 +202,7 @@ struct context_1 #endif /* if client mode, hash of option strings we pulled from server */ - struct md5_digest pulled_options_digest_save; + struct sha256_digest pulled_options_digest_save; /**< Hash of option strings received from the * remote OpenVPN server. Only used in * client-mode. */ @@ -471,9 +471,9 @@ struct context_2 bool did_pre_pull_restore; /* hash of pulled options, so we can compare when options change */ - bool pulled_options_md5_init_done; + bool pulled_options_digest_init_done; md_ctx_t pulled_options_state; - struct md5_digest pulled_options_digest; + struct sha256_digest pulled_options_digest; struct event_timeout scheduled_exit; int scheduled_exit_signal; diff --git a/src/openvpn/push.c b/src/openvpn/push.c index c9c04a630..8c3104ed7 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -720,10 +720,10 @@ process_incoming_push_msg(struct context *c, if (ch == ',') { struct buffer buf_orig = buf; - if (!c->c2.pulled_options_md5_init_done) + if (!c->c2.pulled_options_digest_init_done) { - md_ctx_init(&c->c2.pulled_options_state, md_kt_get("MD5")); - c->c2.pulled_options_md5_init_done = true; + md_ctx_init(&c->c2.pulled_options_state, md_kt_get("SHA256")); + c->c2.pulled_options_digest_init_done = true; } if (!c->c2.did_pre_pull_restore) { @@ -744,7 +744,7 @@ process_incoming_push_msg(struct context *c, case 1: md_ctx_final(&c->c2.pulled_options_state, c->c2.pulled_options_digest.digest); md_ctx_cleanup(&c->c2.pulled_options_state); - c->c2.pulled_options_md5_init_done = false; + c->c2.pulled_options_digest_init_done = false; ret = PUSH_MSG_REPLY; break;