mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
pgcrypto: Report errant decryption as "Wrong key or corrupt data".
This has been the predominant outcome. When the output of decrypting with a wrong key coincidentally resembled an OpenPGP packet header, pgcrypto could instead report "Corrupt data", "Not text data" or "Unsupported compression algorithm". The distinct "Corrupt data" message added no value. The latter two error messages misled when the decrypted payload also exhibited fundamental integrity problems. Worse, error message variance in other systems has enabled cryptologic attacks; see RFC 4880 section "14. Security Considerations". Whether these pgcrypto behaviors are likewise exploitable is unknown. In passing, document that pgcrypto does not resist side-channel attacks. Back-patch to 9.0 (all supported versions). Security: CVE-2015-3167
This commit is contained in:
@ -372,3 +372,54 @@ select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',
|
||||
(1 row)
|
||||
|
||||
-- expected: true
|
||||
-- Negative tests
|
||||
-- Decryption with a certain incorrect key yields an apparent Literal Data
|
||||
-- packet reporting its content to be binary data. Ciphertext source:
|
||||
-- iterative pgp_sym_encrypt('secret', 'key') until the random prefix gave
|
||||
-- rise to that property.
|
||||
select pgp_sym_decrypt(dearmor('
|
||||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
ww0EBwMCxf8PTrQBmJdl0jcB6y2joE7GSLKRv7trbNsF5Z8ou5NISLUg31llVH/S0B2wl4bvzZjV
|
||||
VsxxqLSPzNLAeIspJk5G
|
||||
=mSd/
|
||||
-----END PGP MESSAGE-----
|
||||
'), 'wrong-key', 'debug=1');
|
||||
NOTICE: dbg: prefix_init: corrupt prefix
|
||||
NOTICE: dbg: parse_literal_data: data type=b
|
||||
NOTICE: dbg: mdcbuf_finish: bad MDC pkt hdr
|
||||
ERROR: Wrong key or corrupt data
|
||||
-- Routine text/binary mismatch.
|
||||
select pgp_sym_decrypt(pgp_sym_encrypt_bytea('P', 'key'), 'key', 'debug=1');
|
||||
NOTICE: dbg: parse_literal_data: data type=b
|
||||
ERROR: Not text data
|
||||
-- Decryption with a certain incorrect key yields an apparent BZip2-compressed
|
||||
-- plaintext. Ciphertext source: iterative pgp_sym_encrypt('secret', 'key')
|
||||
-- until the random prefix gave rise to that property.
|
||||
select pgp_sym_decrypt(dearmor('
|
||||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
ww0EBwMC9rK/dMkF5Zlt0jcBlzAQ1mQY2qYbKYbw8h3EZ5Jk0K2IiY92R82TRhWzBIF/8cmXDPtP
|
||||
GXsd65oYJZp3Khz0qfyn
|
||||
=Nmpq
|
||||
-----END PGP MESSAGE-----
|
||||
'), 'wrong-key', 'debug=1');
|
||||
NOTICE: dbg: prefix_init: corrupt prefix
|
||||
NOTICE: dbg: parse_compressed_data: bzip2 unsupported
|
||||
NOTICE: dbg: mdcbuf_finish: bad MDC pkt hdr
|
||||
ERROR: Wrong key or corrupt data
|
||||
-- Routine use of BZip2 compression. Ciphertext source:
|
||||
-- echo x | gpg --homedir /nonexistent --personal-compress-preferences bzip2 \
|
||||
-- --personal-cipher-preferences aes --no-emit-version --batch \
|
||||
-- --symmetric --passphrase key --armor
|
||||
select pgp_sym_decrypt(dearmor('
|
||||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
jA0EBwMCRhFrAKNcLVJg0mMBLJG1cCASNk/x/3dt1zJ+2eo7jHfjgg3N6wpB3XIe
|
||||
QCwkWJwlBG5pzbO5gu7xuPQN+TbPJ7aQ2sLx3bAHhtYb0i3vV9RO10Gw++yUyd4R
|
||||
UCAAw2JRIISttRHMfDpDuZJpvYo=
|
||||
=AZ9M
|
||||
-----END PGP MESSAGE-----
|
||||
'), 'key', 'debug=1');
|
||||
NOTICE: dbg: parse_compressed_data: bzip2 unsupported
|
||||
ERROR: Unsupported compression algorithm
|
||||
|
@ -625,7 +625,7 @@ ERROR: No encryption key found
|
||||
-- rsa: password-protected secret key, wrong password
|
||||
select pgp_pub_decrypt(dearmor(data), dearmor(seckey), '123')
|
||||
from keytbl, encdata where keytbl.id=7 and encdata.id=4;
|
||||
ERROR: Corrupt data
|
||||
ERROR: Wrong key or corrupt data
|
||||
-- rsa: password-protected secret key, right password
|
||||
select pgp_pub_decrypt(dearmor(data), dearmor(seckey), 'parool')
|
||||
from keytbl, encdata where keytbl.id=7 and encdata.id=4;
|
||||
@ -641,7 +641,7 @@ ERROR: Need password for secret key
|
||||
-- password-protected secret key, wrong password
|
||||
select pgp_pub_decrypt(dearmor(data), dearmor(seckey), 'foo')
|
||||
from keytbl, encdata where keytbl.id=5 and encdata.id=1;
|
||||
ERROR: Corrupt data
|
||||
ERROR: Wrong key or corrupt data
|
||||
-- password-protected secret key, right password
|
||||
select pgp_pub_decrypt(dearmor(data), dearmor(seckey), 'parool')
|
||||
from keytbl, encdata where keytbl.id=5 and encdata.id=1;
|
||||
|
Reference in New Issue
Block a user