Skip to content

Commit

Permalink
Restore -DWITH_SSL=system support for OpenSSL versions <= 0.9.8k.
Browse files Browse the repository at this point in the history
MySQL 5.6.17 introduced support for block encryption modes and
initialization vectors for AES_ENCRYPT/AES_DECRYPT functions.  This
change broke backwards compatibility for older OpenSSL system
versions, as the ECB mode cipher there disagrees with recent OpenSSL
versions whether it need initialization vectors or not. As AES
functions directly check with OpenSSL for IV requirement and provide a
corresponding function signature, these differences result in SQL
incompatibilities.

Fixed by checking, for OpenSSL, whether ECB mode is in use whenever
OpenSSL reports required IV length > 0, and assuming IV length of zero
instead.
  • Loading branch information
laurynas-biveinis committed Apr 24, 2014
1 parent 3409bb4 commit 2a8df6d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mysys_ssl/my_aes_openssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ int my_aes_encrypt(const unsigned char *source, uint32 source_length,
unsigned char rkey[MAX_AES_KEY_LENGTH / 8];
my_aes_create_key(key, key_length, rkey, mode);

if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0 && !iv))
if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0
&& EVP_CIPHER_mode(cipher) != EVP_CIPH_ECB_MODE && !iv))
return MY_AES_BAD_DATA;

if (!EVP_EncryptInit(&ctx, cipher, rkey, iv))
Expand Down Expand Up @@ -157,7 +158,8 @@ int my_aes_decrypt(const unsigned char *source, uint32 source_length,
unsigned char rkey[MAX_AES_KEY_LENGTH / 8];

my_aes_create_key(key, key_length, rkey, mode);
if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0 && !iv))
if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0
&& EVP_CIPHER_mode(cipher) != EVP_CIPH_ECB_MODE && !iv))
return MY_AES_BAD_DATA;

EVP_CIPHER_CTX_init(&ctx);
Expand Down Expand Up @@ -212,6 +214,7 @@ my_bool my_aes_needs_iv(my_aes_opmode opmode)

iv_length= EVP_CIPHER_iv_length(cipher);
DBUG_ASSERT(iv_length == 0 || iv_length == MY_AES_IV_SIZE);
return iv_length != 0 ? TRUE : FALSE;
return iv_length != 0
? (EVP_CIPHER_mode(cipher) != EVP_CIPH_ECB_MODE) : FALSE;
}

0 comments on commit 2a8df6d

Please sign in to comment.