|
| 1 | +# Tests of the AES KDF functionality |
| 2 | +#### AES_ENCRYPT return type |
| 3 | +# must work and return a string |
| 4 | +SELECT TO_BASE64(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac')); |
| 5 | +TO_BASE64(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac')) |
| 6 | +44uRAyA9td7Ih/8XyI4paA== |
| 7 | +# must return 16 |
| 8 | +SELECT LENGTH(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac')); |
| 9 | +LENGTH(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac')) |
| 10 | +16 |
| 11 | +# must return binary |
| 12 | +SELECT CHARSET(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac')); |
| 13 | +CHARSET(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac')) |
| 14 | +binary |
| 15 | +# must be equal |
| 16 | +SELECT AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac') = AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac'); |
| 17 | +AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac') = AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac') |
| 18 | +1 |
| 19 | +#### AES_ENCRYPT KDF pbkdf2_hmac parameters |
| 20 | +select TO_BASE64(AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac')); |
| 21 | +TO_BASE64(AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac')) |
| 22 | +44uRAyA9td7Ih/8XyI4paA== |
| 23 | +select TO_BASE64(AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac', 'salt')); |
| 24 | +TO_BASE64(AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac', 'salt')) |
| 25 | +gmnbJutgker3Oftr8Bwejg== |
| 26 | +select TO_BASE64(AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac', 'salt', '10001')); |
| 27 | +TO_BASE64(AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac', 'salt', '10001')) |
| 28 | +XoWbOI01+edhv7XX2+BKew== |
| 29 | +SELECT 'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac'), 'my_key_string', '', 'pbkdf2_hmac'); |
| 30 | +'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac'), 'my_key_string', '', 'pbkdf2_hmac') |
| 31 | +1 |
| 32 | +# Tests of AES strong key generation |
| 33 | +# Weak key generation without KDF, should be equal output |
| 34 | +SELECT AES_ENCRYPT('my_text', repeat("x",32), '') = AES_ENCRYPT('my_text', repeat("y",32), ''); |
| 35 | +AES_ENCRYPT('my_text', repeat("x",32), '') = AES_ENCRYPT('my_text', repeat("y",32), '') |
| 36 | +1 |
| 37 | +Warnings: |
| 38 | +Warning 1618 <IV> option ignored |
| 39 | +Warning 3237 AES key size should be 16 bytes length or secure KDF methods hkdf or pbkdf2_hmac should be used, please provide exact AES key size or use KDF methods for better security. |
| 40 | +Warning 1618 <IV> option ignored |
| 41 | +Warning 3237 AES key size should be 16 bytes length or secure KDF methods hkdf or pbkdf2_hmac should be used, please provide exact AES key size or use KDF methods for better security. |
| 42 | +# Strong key generation with KDF, should not be equal output |
| 43 | +SELECT AES_ENCRYPT('my_text', repeat("x",32), '', 'pbkdf2_hmac') = AES_ENCRYPT('my_text', repeat("y",32), '', 'pbkdf2_hmac'); |
| 44 | +AES_ENCRYPT('my_text', repeat("x",32), '', 'pbkdf2_hmac') = AES_ENCRYPT('my_text', repeat("y",32), '', 'pbkdf2_hmac') |
| 45 | +0 |
| 46 | +# Strong key generation with KDF, should not be equal output |
| 47 | +SELECT AES_ENCRYPT('my_text', repeat("x",32), '', 'pbkdf2_hmac') = AES_ENCRYPT('my_text', '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', '', 'pbkdf2_hmac'); |
| 48 | +AES_ENCRYPT('my_text', repeat("x",32), '', 'pbkdf2_hmac') = AES_ENCRYPT('my_text', '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', '', 'pbkdf2_hmac') |
| 49 | +0 |
| 50 | +#### AES_ENCRYPT KDF pbkdf2_hmac parameters with incorrect data types |
| 51 | +SELECT 'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac', 4000, '10001'), 'my_key_string', '', 'pbkdf2_hmac',4000, '10001'); |
| 52 | +'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac', 4000, '10001'), 'my_key_string', '', 'pbkdf2_hmac',4000, '10001') |
| 53 | +1 |
| 54 | +SELECT 'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac', 4000, 10001), 'my_key_string', '', 'pbkdf2_hmac',4000, 10001); |
| 55 | +'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', '', 'pbkdf2_hmac', 4000, 10001), 'my_key_string', '', 'pbkdf2_hmac',4000, 10001) |
| 56 | +1 |
| 57 | +#### AES_ENCRYPT KDF error conditions |
| 58 | +# Invalid KDF method |
| 59 | +select AES_ENCRYPT('my_text','my_key_string', '', 'invalid'); |
| 60 | +ERROR HY000: KDF method name is not valid. Please use hkdf or pbkdf2_hmac method name |
| 61 | +# Warning for big AES key and empty KDF method |
| 62 | +select AES_ENCRYPT('my_text', repeat("x",32)); |
| 63 | +AES_ENCRYPT('my_text', repeat("x",32)) |
| 64 | +�'���lD5H����� |
| 65 | +Warnings: |
| 66 | +Warning 3237 AES key size should be 16 bytes length or secure KDF methods hkdf or pbkdf2_hmac should be used, please provide exact AES key size or use KDF methods for better security. |
| 67 | +# No warning for smaller key |
| 68 | +select AES_ENCRYPT('my_text', 'my_key'); |
| 69 | +AES_ENCRYPT('my_text', 'my_key') |
| 70 | +~�Zk,Za���=Z� |
| 71 | +# KDF pbkdf2_hmac iterations less then 1000 error. |
| 72 | +select AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac', 'salt', '100'); |
| 73 | +ERROR HY000: For KDF method pbkdf2_hmac iterations value less than 1000 or more than 65535 is not allowed due to security reasons. Please provide iterations >= 1000 and iterations < 65535 |
| 74 | +# KDF pbkdf2_hmac iterations as text |
| 75 | +select AES_ENCRYPT('my_text','my_key_string', '', 'pbkdf2_hmac', 'salt', 'aa'); |
| 76 | +ERROR HY000: For KDF method pbkdf2_hmac iterations value less than 1000 or more than 65535 is not allowed due to security reasons. Please provide iterations >= 1000 and iterations < 65535 |
| 77 | +# KDF function name very large. |
| 78 | +select aes_encrypt("foo",repeat("x",16),NULL,repeat("1",10000000000)); |
| 79 | +ERROR HY000: KDF option size is invalid, please provide valid size < 256 bytes and not NULL |
| 80 | +# KDF function name large |
| 81 | +select aes_encrypt("foo",repeat("x",16),NULL,repeat("1",300)); |
| 82 | +ERROR HY000: KDF option size is invalid, please provide valid size < 256 bytes and not NULL |
| 83 | +# KDF function name different case. |
| 84 | +select aes_encrypt("foo",repeat("x",16),NULL,'pbkdf2_HMac'); |
| 85 | +ERROR HY000: KDF method name is not valid. Please use hkdf or pbkdf2_hmac method name |
| 86 | +# Extra IV |
| 87 | +select aes_encrypt("foo",repeat("x",16),NULL,'pbkdf2_HMac'); |
| 88 | +ERROR HY000: KDF method name is not valid. Please use hkdf or pbkdf2_hmac method name |
| 89 | +#### AES_ENCRYPT KDF pbkdf2_hmac parameters with initialization vector |
| 90 | +SET @IV=REPEAT('a', 16); |
| 91 | +#### aes-128-cbc |
| 92 | +SELECT @@session.block_encryption_mode INTO @save_block_encryption_mode; |
| 93 | +SET SESSION block_encryption_mode="aes-128-cbc"; |
| 94 | +SELECT 'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', @IV, 'pbkdf2_hmac'), 'my_key_string', @IV, 'pbkdf2_hmac'); |
| 95 | +'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', @IV, 'pbkdf2_hmac'), 'my_key_string', @IV, 'pbkdf2_hmac') |
| 96 | +1 |
| 97 | +SELECT 'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', @IV, 'pbkdf2_hmac', 'salt'), 'my_key_string', @IV, 'pbkdf2_hmac', 'salt'); |
| 98 | +'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', @IV, 'pbkdf2_hmac', 'salt'), 'my_key_string', @IV, 'pbkdf2_hmac', 'salt') |
| 99 | +1 |
| 100 | +SELECT 'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', @IV, 'pbkdf2_hmac', 'salt', '10001'), 'my_key_string', @IV, 'pbkdf2_hmac', 'salt', '10001'); |
| 101 | +'my_text' = AES_DECRYPT(AES_ENCRYPT('my_text', 'my_key_string', @IV, 'pbkdf2_hmac', 'salt', '10001'), 'my_key_string', @IV, 'pbkdf2_hmac', 'salt', '10001') |
| 102 | +1 |
| 103 | +SET SESSION block_encryption_mode=@save_block_encryption_mode; |
0 commit comments