diff options
Diffstat (limited to 'main/openvpn/src/openvpn/crypto_openssl.c')
-rw-r--r-- | main/openvpn/src/openvpn/crypto_openssl.c | 162 |
1 files changed, 33 insertions, 129 deletions
diff --git a/main/openvpn/src/openvpn/crypto_openssl.c b/main/openvpn/src/openvpn/crypto_openssl.c index ef487944..0ac89a19 100644 --- a/main/openvpn/src/openvpn/crypto_openssl.c +++ b/main/openvpn/src/openvpn/crypto_openssl.c @@ -45,8 +45,6 @@ #include <openssl/objects.h> #include <openssl/evp.h> #include <openssl/des.h> -#include <openssl/ssl.h> -#include <openssl/err.h> /* * Check for key size creepage. @@ -102,14 +100,13 @@ setup_engine (const char *engine) if ((e = ENGINE_by_id (engine)) == NULL && (e = try_load_engine (engine)) == NULL) { - crypto_msg (M_FATAL, "OpenSSL error: cannot load engine '%s'", - engine); + msg (M_FATAL, "OpenSSL error: cannot load engine '%s'", engine); } if (!ENGINE_set_default (e, ENGINE_METHOD_ALL)) { - crypto_msg (M_FATAL, "OpenSSL error: ENGINE_set_default failed on " - "engine '%s'", engine); + msg (M_FATAL, "OpenSSL error: ENGINE_set_default failed on engine '%s'", + engine); } msg (M_INFO, "Initializing OpenSSL support for engine '%s'", @@ -198,26 +195,6 @@ crypto_clear_error (void) ERR_clear_error (); } -void -crypto_print_openssl_errors(const unsigned int flags) { - size_t err = 0; - - while ((err = ERR_get_error ())) - { - /* Be more clear about frequently occurring "no shared cipher" error */ - if (err == ERR_PACK(ERR_LIB_SSL,SSL_F_SSL3_GET_CLIENT_HELLO, - SSL_R_NO_SHARED_CIPHER)) - { - msg (D_CRYPT_ERRORS, "TLS error: The server has no TLS ciphersuites " - "in common with the client. Your --tls-cipher setting might be " - "too restrictive."); - } - - msg (flags, "OpenSSL: %s", ERR_error_string (err, NULL)); - } -} - - /* * * OpenSSL memory debugging. If dmalloc debugging is enabled, tell @@ -254,17 +231,17 @@ crypto_init_dmalloc (void) } #endif /* DMALLOC */ -const cipher_name_pair cipher_name_translation_table[] = { - { "AES-128-CCM", "id-aes128-CCM" }, - { "AES-192-CCM", "id-aes192-CCM" }, - { "AES-256-CCM", "id-aes256-CCM" }, - { "AES-128-GCM", "id-aes128-GCM" }, - { "AES-192-GCM", "id-aes192-GCM" }, - { "AES-256-GCM", "id-aes256-GCM" }, -}; -const size_t cipher_name_translation_table_count = - sizeof (cipher_name_translation_table) / sizeof (*cipher_name_translation_table); +const char * +translate_cipher_name_from_openvpn (const char *cipher_name) { + // OpenSSL doesn't require any translation + return cipher_name; +} +const char * +translate_cipher_name_to_openvpn (const char *cipher_name) { + // OpenSSL doesn't require any translation + return cipher_name; +} void show_available_ciphers () @@ -272,12 +249,12 @@ show_available_ciphers () int nid; #ifndef ENABLE_SMALL - printf ("The following ciphers and cipher modes are available for use\n" - "with " PACKAGE_NAME ". Each cipher shown below may be use as a\n" - "parameter to the --cipher option. The default key size is\n" - "shown as well as whether or not it can be changed with the\n" - "--keysize directive. Using a CBC or GCM mode is recommended.\n" - "In static key mode only CBC mode is allowed.\n\n"); + printf ("The following ciphers and cipher modes are available\n" + "for use with " PACKAGE_NAME ". Each cipher shown below may be\n" + "used as a parameter to the --cipher option. The default\n" + "key size is shown as well as whether or not it can be\n" + "changed with the --keysize directive. Using a CBC mode\n" + "is recommended. In static key mode only CBC mode is allowed.\n\n"); #endif for (nid = 0; nid < 10000; ++nid) /* is there a better way to get the size of the nid list? */ @@ -289,20 +266,17 @@ show_available_ciphers () #ifdef ENABLE_OFB_CFB_MODE || cipher_kt_mode_ofb_cfb(cipher) #endif -#ifdef HAVE_AEAD_CIPHER_MODES - || cipher_kt_mode_aead(cipher) -#endif ) { const char *var_key_size = (EVP_CIPHER_flags (cipher) & EVP_CIPH_VARIABLE_LENGTH) ? "variable" : "fixed"; - const char *ssl_only = cipher_kt_mode_cbc(cipher) ? - "" : " (TLS client/server mode)"; + const char *ssl_only = cipher_kt_mode_ofb_cfb(cipher) ? + " (TLS client/server mode)" : ""; - printf ("%s %d bit default key (%s)%s\n", - translate_cipher_name_to_openvpn(OBJ_nid2sn (nid)), - EVP_CIPHER_key_length (cipher) * 8, var_key_size, ssl_only); + printf ("%s %d bit default key (%s)%s\n", OBJ_nid2sn (nid), + EVP_CIPHER_key_length (cipher) * 8, var_key_size, + ssl_only); } } } @@ -412,20 +386,17 @@ key_des_check (uint8_t *key, int key_len, int ndc) DES_cblock *dc = (DES_cblock*) buf_read_alloc (&b, sizeof (DES_cblock)); if (!dc) { - msg (D_CRYPT_ERRORS, "CRYPTO INFO: check_key_DES: insufficient key " - "material"); + msg (D_CRYPT_ERRORS, "CRYPTO INFO: check_key_DES: insufficient key material"); goto err; } if (DES_is_weak_key(dc)) { - crypto_msg (D_CRYPT_ERRORS, "CRYPTO INFO: check_key_DES: weak key " - "detected"); + msg (D_CRYPT_ERRORS, "CRYPTO INFO: check_key_DES: weak key detected"); goto err; } if (!DES_check_key_parity (dc)) { - crypto_msg (D_CRYPT_ERRORS, "CRYPTO INFO: check_key_DES: bad parity " - "detected"); + msg (D_CRYPT_ERRORS, "CRYPTO INFO: check_key_DES: bad parity detected"); goto err; } } @@ -474,7 +445,7 @@ cipher_kt_get (const char *ciphername) cipher = EVP_get_cipherbyname (ciphername); if (NULL == cipher) - crypto_msg (M_FATAL, "Cipher algorithm '%s' not found", ciphername); + msg (M_SSLERR, "Cipher algorithm '%s' not found", ciphername); if (EVP_CIPHER_key_length (cipher) > MAX_CIPHER_KEY_LENGTH) msg (M_FATAL, "Cipher algorithm '%s' uses a default key size (%d bytes) which is larger than " PACKAGE_NAME "'s current maximum key size (%d bytes)", @@ -512,15 +483,6 @@ cipher_kt_block_size (const EVP_CIPHER *cipher_kt) } int -cipher_kt_tag_size (const EVP_CIPHER *cipher_kt) -{ - if (cipher_kt_mode_aead(cipher_kt)) - return OPENVPN_AEAD_TAG_LENGTH; - else - return 0; -} - -int cipher_kt_mode (const EVP_CIPHER *cipher_kt) { ASSERT(NULL != cipher_kt); @@ -550,17 +512,6 @@ cipher_kt_mode_ofb_cfb(const cipher_kt_t *cipher) ; } -bool -cipher_kt_mode_aead(const cipher_kt_t *cipher) -{ -#ifdef HAVE_AEAD_CIPHER_MODES - return (cipher_kt_mode(cipher) == OPENVPN_MODE_GCM || - cipher_kt_mode(cipher) == OPENVPN_MODE_CCM); -#else - return false; -#endif -} - /* * * Generic cipher context functions @@ -578,13 +529,13 @@ cipher_ctx_init (EVP_CIPHER_CTX *ctx, uint8_t *key, int key_len, EVP_CIPHER_CTX_init (ctx); if (!EVP_CipherInit (ctx, kt, NULL, NULL, enc)) - crypto_msg (M_FATAL, "EVP cipher init #1"); + msg (M_SSLERR, "EVP cipher init #1"); #ifdef HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH if (!EVP_CIPHER_CTX_set_key_length (ctx, key_len)) - crypto_msg (M_FATAL, "EVP set key size"); + msg (M_SSLERR, "EVP set key size"); #endif if (!EVP_CipherInit (ctx, NULL, key, NULL, enc)) - crypto_msg (M_FATAL, "EVP cipher init #2"); + msg (M_SSLERR, "EVP cipher init #2"); /* make sure we used a big enough key */ ASSERT (EVP_CIPHER_CTX_key_length (ctx) <= key_len); @@ -602,15 +553,6 @@ cipher_ctx_iv_length (const EVP_CIPHER_CTX *ctx) return EVP_CIPHER_CTX_iv_length (ctx); } -int cipher_ctx_get_tag (EVP_CIPHER_CTX *ctx, uint8_t *tag_buf, int tag_size) -{ -#ifdef HAVE_AEAD_CIPHER_MODES - return EVP_CIPHER_CTX_ctrl (ctx, EVP_CTRL_GCM_GET_TAG, tag_size, tag_buf); -#else - ASSERT (0); -#endif -} - int cipher_ctx_block_size(const EVP_CIPHER_CTX *ctx) { @@ -637,17 +579,6 @@ cipher_ctx_reset (EVP_CIPHER_CTX *ctx, uint8_t *iv_buf) } int -cipher_ctx_update_ad (EVP_CIPHER_CTX *ctx, uint8_t* src, int src_len) -{ -#ifdef HAVE_AEAD_CIPHER_MODES - int len; - return EVP_CipherUpdate (ctx, NULL, &len, src, src_len); -#else - ASSERT (0); -#endif -} - -int cipher_ctx_update (EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len, uint8_t *src, int src_len) { @@ -660,21 +591,6 @@ cipher_ctx_final (EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len) return EVP_CipherFinal (ctx, dst, dst_len); } -int -cipher_ctx_final_check_tag (EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len, - const uint8_t *tag, size_t tag_len) -{ -#ifdef HAVE_AEAD_CIPHER_MODES - /* Setting a tag does not change the tag, so casting away const... */ - if (!EVP_CIPHER_CTX_ctrl (ctx, EVP_CTRL_GCM_SET_TAG, tag_len, - (uint8_t *) tag)) - return 0; - - return cipher_ctx_final (ctx, dst, dst_len); -#else - ASSERT (0); -#endif -} void cipher_des_encrypt_ecb (const unsigned char key[DES_KEY_LENGTH], @@ -701,11 +617,9 @@ md_kt_get (const char *digest) ASSERT (digest); md = EVP_get_digestbyname (digest); if (!md) - crypto_msg (M_FATAL, "Message hash algorithm '%s' not found", digest); + msg (M_SSLERR, "Message hash algorithm '%s' not found", digest); if (EVP_MD_size (md) > MAX_HMAC_KEY_LENGTH) - crypto_msg (M_FATAL, "Message hash algorithm '%s' uses a default hash size " - "(%d bytes) which is larger than " PACKAGE_NAME "'s current maximum " - "hash size (%d bytes)", + msg (M_FATAL, "Message hash algorithm '%s' uses a default hash size (%d bytes) which is larger than " PACKAGE_NAME "'s current maximum hash size (%d bytes)", digest, EVP_MD_size (md), MAX_HMAC_KEY_LENGTH); @@ -833,14 +747,4 @@ hmac_ctx_final (HMAC_CTX *ctx, uint8_t *dst) HMAC_Final (ctx, dst, &in_hmac_len); } -bool -crypto_aead_mode (int mode) -{ -#ifdef HAVE_AEAD_CIPHER_MODES - return mode == OPENVPN_MODE_CCM || mode == OPENVPN_MODE_GCM; -#else - return false; -#endif -} - #endif /* ENABLE_CRYPTO && ENABLE_CRYPTO_OPENSSL */ |