Spring-Boot + sharding-proxy decodes failed after encoding by AES
Bug Report
For English only, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed GitHub issues.
- Read documentation: ShardingSphere Doc.
Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.
Please answer these questions before submitting your issue. Thanks!
Which version of ShardingSphere did you use?
4.0.0-RC4-SNAPSHOT
Which project did you use? Sharding-JDBC or Sharding-Proxy?
sharding-proxy
Expected behavior
Executing select * from t_user, it will return the result.
Actual behavior
When i execute select * from t_user it can not return the result.
Reason analyze (If you can)
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
Example codes for reproduce this issue (such as a github link).
The proxy yaml config:
schemaName: encrypt_db
dataSource:
url: jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
encryptRule:
encryptors:
encryptor_aes:
type: aes
props:
aes.key.value: 123456abc
encryptor_md5:
type: md5
tables:
t_user:
columns:
user_name:
plainColumn: user_name
cipherColumn: user_name_cipher
encryptor: encryptor_aes
pwd:
plainColumn: pwd_plain
cipherColumn: pwd_cipher
encryptor: encryptor_md5
the exception:
javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.prepareInputBuffer(CipherCore.java:1005)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:848)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
at javax.crypto.Cipher.doFinal(Cipher.java:2164)
at org.apache.shardingsphere.encrypt.strategy.impl.AESEncryptor.decrypt(AESEncryptor.java:73)
at org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.getQueryData(JDBCDatabaseCommunicationEngine.java:216)
at org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.binary.execute.MySQLComStmtExecuteExecutor.getQueryData(MySQLComStmtExecuteExecutor.java:118)
at org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.binary.execute.MySQLComStmtExecuteExecutor.getQueryData(MySQLComStmtExecuteExecutor.java:57)
at org.apache.shardingsphere.shardingproxy.frontend.mysql.command.MySQLCommandExecuteEngine.writeQueryData(MySQLCommandExecuteEngine.java:83)
at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:100)
at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Hi, From @sunbufu 's investigation, it is because that we replace cipherColumn with logicColumn which has the same name with plainColumn in JDBCDatabaseCommunicationEngine.setLogicColumns(), so two same column names exist in QueryHeaders.
The root solution to solve this issue is to consider a better way from the encrypted metadata, for which more effort is required.
fixes by #4637 .
我用4.1.0版本的sharding-proxy查询加密字段还是会报错:Input length must be multiple of 16 when decrypting with padded cipher
相应的配置: schemaName: sharding_db
dataSources: ds0: url: jdbc:mysql://localhost:3306/ds_0?characterEncoding=UTF-8&serverTimezone=UTC username: root password: 3325853 connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 65 ds1: url: jdbc:mysql://localhost:3306/ds_1?characterEncoding=UTF-8&serverTimezone=UTC username: root password: 3325853 connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 65
shardingRule: defaultDataSourceName: ds0 tables: t_user_info: actualDataNodes: ds$->{0..1}.t_user_info_$->{0..1} databaseStrategy: standard: shardingColumn: one_id preciseAlgorithmClassName: com.xxx.usercenter.infra.utils.DBShardingAlgorithm tableStrategy: standard: shardingColumn: one_id preciseAlgorithmClassName: com.xxx.usercenter.infra.utils.TableShardingAlgorithm t_user_encryption_info: actualDataNodes: ds$->{0..1}.t_user_encryption_info_$->{0..1} databaseStrategy: standard: shardingColumn: one_id preciseAlgorithmClassName: com.xxx.usercenter.infra.utils.DBShardingAlgorithm tableStrategy: standard: shardingColumn: one_id preciseAlgorithmClassName: com.xxx.usercenter.infra.utils.TableShardingAlgorithm t_user_routing: actualDataNodes: ds$->{0..1}.t_user_routing_$->{0..1} databaseStrategy: standard: shardingColumn: routing_key preciseAlgorithmClassName: com.xxx.usercenter.infra.utils.DBShardingAlgorithm tableStrategy: standard: shardingColumn: routing_key preciseAlgorithmClassName: com.xxx.usercenter.infra.utils.TableShardingAlgorithm encryptRule: encryptors: aes_encryptors: type: aes props: aes.key.value: 123456 tables: t_user_encryption_info: columns: member_handler: cipherColumn: member_handler encryptor: aes_encryptors member_name: cipherColumn: member_name encryptor: aes_encryptors mobile_phone: cipherColumn: mobile_phone encryptor: aes_encryptors contact_phone: cipherColumn: contact_phone encryptor: aes_encryptors card_no: cipherColumn: card_no encryptor: aes_encryptors t_user_routing: columns: routing_key: cipherColumn: routing_key encryptor: aes_encryptors