Re: [HACKERS] Possible problem with pgcrypto

2015-02-06 Thread Jan Wieck

On 02/05/2015 02:15 PM, Jan Wieck wrote:

On 02/05/2015 01:18 PM, Marko Tiikkaja wrote:



  pgcrypto bug


That doesn't look too good, but I can't reproduce it against 9.3.6 either.


Attached is an improved script and the final output from it. I ran it 
over night and it did not reproduce the pgcrypto bug message, but 
instead the expected Corrupt data plus one, that I haven't seen before 
which is Unsupported compression algorithm.



Jan

--
Jan Wieck
Senior Software Engineer
http://slony.info


pgcrypto_test2.sh
Description: application/shellscript
select * from pgp_test2 order by 1;
 id |  
vdata   
|  vkey   |  verrmsg  
+--+-+---
  1 | 
\xc30d040703027123de71fa32937175d23a01cc0377628c3b58119e4c8e51804b74cccf961c8b500b8a283db7084ed809833f9bfd7827b70cf06aa0254707e1c08b3db8419e6e2eda697637
 | key_1   | ERROR:  Wrong key or corrupt data
  2 | 
\xc30d040703027123de71fa32937175d23a01cc0377628c3b58119e4c8e51804b74cccf961c8b500b8a283db7084ed809833f9bfd7827b70cf06aa0254707e1c08b3db8419e6e2eda697637
 | key_686 | ERROR:  Not text data
  3 | 
\xc30d04070302b9688f5b4b1db6bb77d23a01ee1cad33770344503c564496fb6463d9b11a30013424fcae8b80cfbafba415ba3c7047aec7499b8e74254069b29390990c0f2a34740a7d2085
 | key_972 | ERROR:  Unsupported compression algorithm
  4 | 
\xc30d04070302c011ec7879402f4178d23a0165d2462bb4e6a7a204f8af20fc0cfadfc72f6a55902f013479697f316659bbc028ddfe624578e462aee3279b65f3e66f0993305d378ae35593
 | key_816 | ERROR:  Corrupt data
(4 rows)

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Possible problem with pgcrypto

2015-02-05 Thread Jan Wieck

Hi,

I have encountered a small instability in the behavior of pgcrypto's 
pgp_sym_decrypt() function. Attached is a script that can reproduce the 
problem. It may have to be run repeatedly because the symptom occurs 
rather seldom.


What the script does is to encode a small string with pgp_sym_encrypt() 
and then repeatedly try to decrypt it with different wrong passwords. 
The expected error message for that is of course


Wrong key or corrupt data.

Every now and then, I get a different error message. Things I've seen are:

Not text data
pgcrypto bug

This seems to be triggered by a combination of the random data included 
in the encrypted data as well as the wrong password, because for an 
instance of encrypted data only certain passwords cause this symptom.


I wonder if this may actually be a bug in pgcrypto or if this is an 
error inherent in the way, the encrypted data is encoded. I.e. that the 
decryption algorithm cannot really figure out what is wrong and just 
sometimes gets a little further in the attempt to decrypt.



Jan

--
Jan Wieck
Senior Software Engineer
http://slony.info


pgcrypto_test.sh
Description: application/shellscript

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Possible problem with pgcrypto

2015-02-05 Thread Jan Wieck

On 02/05/2015 10:58 AM, Tom Lane wrote:

Jan Wieck j...@wi3ck.info writes:

I have encountered a small instability in the behavior of pgcrypto's
pgp_sym_decrypt() function. Attached is a script that can reproduce the
problem. It may have to be run repeatedly because the symptom occurs
rather seldom.



What the script does is to encode a small string with pgp_sym_encrypt()
and then repeatedly try to decrypt it with different wrong passwords.
The expected error message for that is of course
 Wrong key or corrupt data.



Every now and then, I get a different error message. Things I've seen are:


Have you tested this with this week's releases?  We fixed some
memory-mishandling bugs in pgcrypto ...


The posted script reproduces the symptom in today's checkout of master 
as well as REL9_4_STABLE.



Jan

--
Jan Wieck
Senior Software Engineer
http://slony.info


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Possible problem with pgcrypto

2015-02-05 Thread Jan Wieck

On 02/05/2015 01:18 PM, Marko Tiikkaja wrote:

On 2/5/15 4:48 PM, Jan Wieck wrote:

What the script does is to encode a small string with pgp_sym_encrypt()
and then repeatedly try to decrypt it with different wrong passwords.
The expected error message for that is of course

  Wrong key or corrupt data.

Every now and then, I get a different error message. Things I've seen are:

  Not text data


That's not unexpected; the check for whether the data is text or not
appears to happen quite early in the process of decoding.  So it's
enough to get to that point without anything being obviously broken.


I suspected something like that.



In addition to the two errors above, it doesn't appear to be too
difficult to see PXE_MBUF_SHORT_READ, which would give you  ERROR:
Corrupt data.  I wonder why that error message is different, though.


From reading the code as far I did, I expected to see that, but haven't 
seen it yet.





  pgcrypto bug


That doesn't look too good, but I can't reproduce it against 9.3.6 either.


Let me improve the script to a point where it can run for a long time in 
the background and collect all different error cases as examples of 
encrypted data and wrong password.



Thanks so far.
Jan

--
Jan Wieck
Senior Software Engineer
http://slony.info


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers