shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Encrypt jdbc bug occur when cipher column value is not from method parameter.

Open HongJinFeng opened this issue 7 years ago • 10 comments

1.Below cases work normally.

UPDATE t_demo SET username = CONCAT('xxx','xxxx') WHERE id in (#{id1},#{id2},#{id3})
UPDATE t_demo SET username = ‘xxx’ WHERE id in (#{id1},#{id2},#{id3})
UPDATE t_demo SET username = #{username} WHERE id in (#{id1},#{id2},#{id3})

2.But in these cases, exception occurs. Using encrypt-jdbc, and username is one of encrypt column.

create t_demo{
   id int,
    username varchar(20),
    username_encrypt(64)
};

UPDATE t_demo SET username = CONCAT(username,'xxx') WHERE id in (#{id1},#{id2},#{id3})
UPDATE t_demo SET username = CONCAT(username,'xxx',UNIX_TIMESTAMP()) WHERE id in (#{id1},#{id2},#{id3})
UPDATE t_demo SET username = CONCAT(username,UNIX_TIMESTAMP()) WHERE id in (#{id1},#{id2},#{id3})
UPDATE t_demo SET username = username WHERE id in (#{id1},#{id2},#{id3})

encrypt rule configuration: spring.shardingsphere.datasource.name = ds spring.shardingsphere.datasource.ds.type = com.alibaba.druid.pool.DruidDataSource spring.shardingsphere.datasource.ds.driver-class-name = com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds.url = xxx spring.shardingsphere.datasource.ds.username = xxx spring.shardingsphere.datasource.ds.password = xxx spring.shardingsphere.encrypt.encryptors.encryptor_aes.type = AES spring.shardingsphere.encrypt.encryptors.encryptor_aes.props.aes.key.value = spring.shardingsphere.encrypt.tables.t_demo.columns.username.plainColumn = username spring.shardingsphere.encrypt.tables.t_demo.columns.username.cipherColumn = username_encrypt spring.shardingsphere.encrypt.tables.t_demo.columns.username.encryptor = encryptor_aes

All Update SQL throw exception.

3.Here is one of the rewrite SQL:

update t_demo set username = ?, username_encrypt = ? where resourceid in (?,?,?) 

image

4.Version sharding-sphere 4.0.0-RC2

5.Personal view The exception throw might because the plain column's value is from MySQL but not method parameters, and encrypt jdbc can not get the cipher column value in core. It may cause this exception. In my opinion, encrypt jdbc can just omit this cipher column, but not throws an exception, or It is maybe exist a better way to handle with it.

HongJinFeng avatar Nov 12 '19 10:11 HongJinFeng

Can you describe the summary in title for search friendly?

terrymanu avatar Nov 13 '19 04:11 terrymanu

What' mean of core parameter? I saw your SQL

update seewo_sys_users set username = ?, username_encrypt = ? where resourceid in (?,?,?)

what is the table seewo_sys_users, what is different with previous table t_demo?

terrymanu avatar Nov 14 '19 08:11 terrymanu

Will close soon if no response anymore

terrymanu avatar Nov 19 '19 15:11 terrymanu

  1. It is method parameter.
  2. Not seewo_sys_users,It is t_demo.

HongJinFeng avatar Nov 20 '19 01:11 HongJinFeng

What is your encrypt rule configuration?

terrymanu avatar Nov 20 '19 09:11 terrymanu

Can you fix the title about core parameter?

terrymanu avatar Nov 20 '19 09:11 terrymanu

Hi, will close soon if no response anymore

terrymanu avatar Nov 25 '19 03:11 terrymanu

Hi, maybe you can try my sql. But note to this: image

HongJinFeng avatar Nov 25 '19 03:11 HongJinFeng

I have 2 suggestions, maybe you can have try:

  1. Version 4.0.0-RC3 is released, some of encrypt bugs are fixed, you can try to this version
  2. If the issue still existed, please provide the log of sql.show.

Another suggestion is could you use code to instead of screenshot? Screenshot cannot search by other people.

terrymanu avatar Nov 25 '19 07:11 terrymanu

The new Version fixed this bugs.

HongJinFeng avatar Nov 28 '19 02:11 HongJinFeng