Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](function) fix aes_encrypt/decrypt has wrong results in view #39968

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

xy720
Copy link
Member

@xy720 xy720 commented Aug 27, 2024

Proposed changes

This commit fix 3 problems:

Before:

case 1: No matching function in view.

MySQL [test]> create view test_view as select 1,to_base64(AES_ENCRYPT('doris','doris'));
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> select * from test_view;
ERROR 1105 (HY000): errCode = 2, detailMessage = No matching function with signature: aes_encrypt(varchar(-1)).
MySQL [test]> show create table test_view;

case 2: The secret key is being shown beside '***' in result header

MySQL [test]> SELECT aes_decrypt(   from_base64("EXp7k7M9Zv1mIwPpno28Hg=="),   '17IMZrGdwWf2Piy8',   'II2HLtihr5TQpQgR'  , 'AES_128_CBC');
+---------------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '***''17IMZrGdwWf2Piy8', 'II2HLtihr5TQpQgR') |
+---------------------------------------------------------------------------------------------------+
| 17777208882                                                                                       |
+---------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)

case 3: Wrong result in view

MySQL [test]> set block_encryption_mode='AES_128_CBC';
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> CREATE VIEW client_user_test AS SELECT aes_decrypt(   from_base64('EXp7k7M9Zv1mIwPpno28Hg=='),   '17IMZrGdwWf2Piy8',   'II2HLtihr5TQpQgR'  );
Query OK, 0 rows affected (0.04 sec)

MySQL [test]> show create view client_user_test;
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View             | Create View                                                                                                                                                                                                                                                       | character_set_client | collation_connection |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| client_user_test | CREATE VIEW `client_user_test` COMMENT 'VIEW' AS SELECT aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '***''17IMZrGdwWf2Piy8', 'II2HLtihr5TQpQgR') AS `aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '***''17IMZrGdwWf2Piy8', 'II2HLtihr5TQpQgR')`; | utf8                 | utf8_general_ci      |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.01 sec)

MySQL [test]> select * from client_user_test;
+---------------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '***''17IMZrGdwWf2Piy8', 'II2HLtihr5TQpQgR') |
+---------------------------------------------------------------------------------------------------+
| NULL                                                                                              |
+---------------------------------------------------------------------------------------------------+
1 row in set (0.95 sec)

After:

case 1:

MySQL [test]> create view test_view as select 1,to_base64(AES_ENCRYPT('doris','doris'));
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> select * from test_view;
+------+------------------------------------------+
| 1    | to_base64(aes_encrypt('doris', 'doris')) |
+------+------------------------------------------+
|    1 | 4x0fdjDNBZAJxCD7qm/EHg==                 |
+------+------------------------------------------+
1 row in set (0.04 sec)

case 2:

MySQL [test]> SELECT aes_decrypt(   from_base64("EXp7k7M9Zv1mIwPpno28Hg=="),   '17IMZrGdwWf2Piy8',   'II2HLtihr5TQpQgR'  , 'AES_128_CBC');
+------------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '***', 'II2HLtihr5TQpQgR', 'AES_128_CBC') |
+------------------------------------------------------------------------------------------------+
| 17777208882                                                                                    |
+------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)

case 3:

MySQL [test]> set block_encryption_mode='AES_128_CBC';Query OK, 0 rows affected (0.01 sec)

MySQL [test]> CREATE VIEW client_user_test AS SELECT aes_decrypt(   from_base64('EXp7k7M9Zv1mIwPpno28Hg=='),   '17IMZrGdwWf2Piy8',   'II2HLtihr5TQpQgR'  );
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> show create view client_user_test;
+------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View             | Create View                                                                                                                                                                                                                                                                           | character_set_client | collation_connection |
+------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| client_user_test | CREATE VIEW `client_user_test` COMMENT 'VIEW' AS SELECT aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '17IMZrGdwWf2Piy8', 'II2HLtihr5TQpQgR', 'AES_128_CBC') AS `aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '17IMZrGdwWf2Piy8', 'II2HLtihr5TQpQgR', 'AES_128_CBC')`; | utf8                 | utf8_general_ci      |
+------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.00 sec)

MySQL [test]> select * from client_user_test;
+-------------------------------------------------------------------------------------------------------------+
| aes_decrypt(from_base64('EXp7k7M9Zv1mIwPpno28Hg=='), '17IMZrGdwWf2Piy8', 'II2HLtihr5TQpQgR', 'AES_128_CBC') |
+-------------------------------------------------------------------------------------------------------------+
| 17777208882                                                                                                 |
+-------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)

@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

@github-actions github-actions bot added the area/planner Issues or PRs related to the query planner label Aug 27, 2024
@xy720
Copy link
Member Author

xy720 commented Aug 27, 2024

run buildall

Copy link
Contributor

@cambyzju cambyzju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Aug 27, 2024
Copy link
Contributor

PR approved by at least one committer and no changes requested.

Copy link
Contributor

PR approved by anyone and no changes requested.

Copy link
Contributor

@lide-reed lide-reed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lide-reed lide-reed merged commit d8dce72 into apache:branch-1.2-lts Aug 27, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by one committer. area/planner Issues or PRs related to the query planner reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants