Обсуждение: Possible problem with pgcrypto

Поиск
Список
Период
Сортировка

Possible problem with pgcrypto

От
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

Вложения

Re: Possible problem with pgcrypto

От
Tom Lane
Дата:
Jan Wieck <jan@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 ...
        regards, tom lane



Re: Possible problem with pgcrypto

От
Marko Tiikkaja
Дата:
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.

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.

>       "pgcrypto bug"

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


.m



Re: Possible problem with pgcrypto

От
Jan Wieck
Дата:
On 02/05/2015 10:58 AM, Tom Lane wrote:
> Jan Wieck <jan@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



Re: Possible problem with pgcrypto

От
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



Re: Possible problem with pgcrypto

От
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

Вложения