Prefer TLS libraries TLS PRF function, fix OpenVPN in FIPS mode
PATCH v4 1/1 Prefer TLS libraries TLS PRF function, fix OpenVPN in FIPS mode
This moves from using our own copy of the TLS1 PRF function to using TLS library provided function where possible. This includes currently OpenSSL 1.1.0+ and mbed TLS 2.18+.
For the libraries where it is not possible to use the library's own function, we still use our own implementation. mbed TLS will continue to use our own old PRF function while for OpenSSL we will use a adapted version from OpenSSL 1.0.2t code. The version allows to be used in a FIPS enabled environment.
The old OpenSSL and mbed TLS implementation could have shared some more code but as we will eventually drop support for older TLS libraries, the separation makes it easier it remove that code invdidually.
In FIPS mode MD5 is normally forbidden, the TLS1 PRF1 function we use, makes uses of MD5, which in the past has caused OpenVPN to segfault. The new implementation for OpenSSL version of our custom implementation has added the special flags that tell OpenSSL that this specific use of MD5 is allowed in FIPS mode.
No FIPS conformitiy testing etc has been done, this is only about allowing OpenVPN on a system where FIPS mode has been enabled system wide (e.g. on RHEL derivates).
Patch v4: Handle the unlikely case that PRF generation fails. More formatting
fixes.
--- Changes.rst | 10 +- src/openvpn/crypto_backend.h | 16 ++ src/openvpn/crypto_mbedtls.c | 135 ++++++++++++++++ src/openvpn/crypto_openssl.c | 195 +++++++++++++++++++++++ src/openvpn/ssl.c | 206 ++++++------------------- tests/unit_tests/openvpn/test_crypto.c | 32 ++++ 6 files changed, 430 insertions(+), 164 deletions(-)
Changes.rst +5 -5
@@ -9,11 +9,11 @@ Keying Material Exporters (RFC 5705) based key generation the RFC5705 based key material generation to the current custom OpenVPN PRF. This feature requires OpenSSL or mbed TLS 2.18+. -Deprecated features -------------------- -``inetd`` has been removed - This was a very limited and not-well-tested way to run OpenVPN, on TCP - and TAP mode only. +Compatibility with OpenSSL in FIPS mode + OpenVPN will now work with OpenSSL in FIPS mode. Note, no effort + has been made to check or implement all the + requirements/recommendation of FIPS 140-2. This just allows OpenVPN + to be run on a system that be configured OpenSSL in FIPS mode. Overview of changes in 2.5
src/openvpn/crypto_backend.h +16 -0
@@ -699,4 +699,20 @@ const char *translate_cipher_name_from_openvpn(const char *cipher_name);*/ const char *translate_cipher_name_to_openvpn (const char *cipher_name); + +/** +* Calculates the TLS 1.0-1.1 PRF function. For the exact specification of the +* function definition see the TLS RFCs like RFC 4346. +* +* @param seed seed to use +* @param seed_len length of the seed +* @param secret secret to use +* @param secret_len length of the secret +* @param output output destination +* @param output_len length of output/number of bytes to generate +* +* @return true if successful, false on any error +*/ +bool ssl_tls1_PRF (const uint8_t *seed,int seed_len,const uint8_t *secret, +int secret_len,uint8_t *output,int output_len);#endif /* CRYPTO_BACKEND_H_ */
src/openvpn/crypto_mbedtls.c +135 -0
145 lines not on this page · raw message
src/openvpn/crypto_openssl.c +195 -0
205 lines not on this page · raw message
src/openvpn/ssl.c +47 -159
259 lines not on this page · raw message
tests/unit_tests/openvpn/test_crypto.c +32 -0
@@ -38,6 +38,7 @@#include <cmocka.h> #include "crypto.h" +#include "ssl_backend.h" #include "mock_msg.h"
@@ -136,12 +137,43 @@ crypto_translate_cipher_names(void **state)test_cipher_names ("id-aes256-GCM" ,"AES-256-GCM" ); } + +static uint8_t good_prf[32 ] = {0xd9 ,0x8c ,0x85 ,0x18 ,0xc8 ,0x5e ,0x94 ,0x69 , +0x27 ,0x91 ,0x6a ,0xcf ,0xc2 ,0xd5 ,0x92 ,0xfb , +0xb1 ,0x56 ,0x7e ,0x4b ,0x4b ,0x14 ,0x59 ,0xe6 , +0xa9 ,0x04 ,0xac ,0x2d ,0xda ,0xb7 ,0x2d ,0x67 }; +static void +crypto_test_tls_prf (void **state) +{ +const char *seedstr ="Quis aute iure reprehenderit in voluptate " +"velit esse cillum dolore" ; +const unsigned char *seed = (const unsigned char *) seedstr; +const size_t seed_len =strlen (seedstr); + + + + +const char * ipsumlorem ="Lorem ipsum dolor sit amet, consectetur " +"adipisici elit, sed eiusmod tempor incidunt ut " +"labore et dolore magna aliqua." ; + +const unsigned char *secret = (const unsigned char *) ipsumlorem; +size_t secret_len =strlen ((const char *)secret); + + +uint8_t out[32 ]; +ssl_tls1_PRF (seed, seed_len, secret, secret_len, out,sizeof (out)); + +assert_memory_equal (good_prf, out,sizeof (out)); +} +int main (void ) {const struct CMUnitTest tests[] = {cmocka_unit_test (crypto_pem_encode_decode_loopback),cmocka_unit_test (crypto_translate_cipher_names), +cmocka_unit_test (crypto_test_tls_prf) };#if defined(ENABLE_CRYPTO_OPENSSL )
Signature · 1 line
2.30.0