mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +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:
@ -268,3 +268,48 @@ a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
||||
-- check BUG #11905, problem with messages 6 less than a power of 2.
|
||||
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
|
||||
-- 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');
|
||||
|
||||
-- Routine text/binary mismatch.
|
||||
select pgp_sym_decrypt(pgp_sym_encrypt_bytea('P', 'key'), 'key', 'debug=1');
|
||||
|
||||
-- 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');
|
||||
|
||||
-- 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');
|
||||
|
Reference in New Issue
Block a user