为了跟踪调查,我构建了一个包含较少列的表的副本。并尝试了相同的密码视觉检查:
perso=# select quoi,login,pgp_sym_decrypt(password::bytea,'someKEY') from tempo where quoi ilike '%somesite%' ;
quoi | login | pgp_sym_decrypt
--------------+-----------------------+-----------------
somesite.com | somename@somewhere.fr | foobar
(1 row)
perso=# select quoi,login,pgp_sym_decrypt(password,'someKEY') from tempo where quoi ilike '%somesite%' ;
quoi | login | pgp_sym_decrypt
--------------+-----------------------+-----------------
somesite.com | somename@somewhere.fr | foobar
(1 row)
perso=# \d+ tempo
Table "public.tempo"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+---------+----------+--------------+-------------
ref | integer | | | | plain | |
quoi | text | | | | extended | |
login | text | | | | extended | |
password | bytea | | | | extended | |
这里没有更多问题,因此表或数据存储模式存在问题。
perso=# \d+ passwd
Table "public.passwd"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+-------------------------------------+----------+--------------+-------------
ref | integer | | not null | nextval('passwd_ref_seq'::regclass) | plain | |
quoi | text | | not null | | extended | |
login | text | | not null | | extended | |
password | text | | not null | | extended | |
Indexes:
"passwd_pkey" PRIMARY KEY, btree (ref)
"passwd_password_key" UNIQUE CONSTRAINT, btree (password)
perso=#
perso=# select quoi,login,pgp_sym_decrypt(password,'someKEY') from passwd where quoi ilike '%somesite%' ;
ERROR: function pgp_sym_decrypt(text, unknown) does not exist
LINE 1: select quoi,login,pgp_sym_decrypt(password,'someKEY') fr...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
perso=#
text
在这里,我们在密码列上有返回错误和检测。所以测试:
- alter table => BIG FAIL 它第二次重新编码所有数据..
- 跌落测试表 passwd
- 恢复测试表密码
- 在速度表中复制数据
- 删除密码表中的数据
- 更改密码表
- 将数据复制回 passwd 表中
作为我的测试程序。
所以我做了 :
perso=#
perso=# delete from passwd ;
DELETE 106
perso=# alter table passwd alter column password type bytea using PGP_SYM_ENCRYPT(password::text,'someKEY');
ALTER TABLE
perso=# \d+ passwd
Table "public.passwd"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+-------------------------------------+----------+--------------+-------------
ref | integer | | not null | nextval('passwd_ref_seq'::regclass) | plain | |
quoi | text | | not null | | extended | |
login | text | | not null | | extended | |
password | bytea | | not null | | extended | |
Indexes:
"passwd_pkey" PRIMARY KEY, btree (ref)
"passwd_password_key" UNIQUE CONSTRAINT, btree (password)
perso=# insert into passwd (ref,quoi,login,password) select ref,quoi,login,password::bytea from tempo ;
INSERT 0 106
perso=#
perso=#
perso=# select quoi,login,pgp_sym_decrypt(password,'someKEY') from passwd where quoi ilike '%somesite%' ;
quoi | login | pgp_sym_decrypt
--------------+-----------------------+-----------------
somesite.com | somename@somewhere.fr | foobar
(1 row)
perso=#
然后我备份数据库;并应用类似的程序来成功解决问题。这可能是一个更好的方法,但这样我就理解了这个过程。
两个解决方案都在那里:
- 使用带有 column:bytea 语法的查询
- 将列类型修复为:bytea