pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Stefan Kaltenbrunner <stefan@kaltenbrunner.cc>
Cc: Postgres-Bugs <pgsql-bugs@postgresql.org>
Cc: Marko Kreen <markokr@gmail.com>
Subject: Re: pgcrypto decrypt_iv() issue
Date: Fri, 27 Jan 2012 01:37:11 -0500
Message-ID: <23889.1327646231@sss.pgh.pa.us> (raw)
In-Reply-To: <4F1F23E8.80100@kaltenbrunner.cc>
References: <4F1DB7BF.60304@kaltenbrunner.cc>
	<4F1F23E8.80100@kaltenbrunner.cc>

Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> writes:
> from some looking at the code in pgcrypto.c it seems to me that the
> coding pattern in most functions there only checks for errors from the
> corresponding initialization function, in the case of say decrypt_iv()
> that means only the IV and the key are actually "validated" because that
> is what the init function sees(it never sees that data!), if the actual
> decrypt call fails (because the data is maybe a bit weird^broken) it
> will happily ignore that and return random data.

Yeah.  In pg_decrypt() we have

    err = px_combo_init(c, (uint8 *) VARDATA(key), klen, NULL, 0);
    if (!err)
        err = px_combo_decrypt(c, (uint8 *) VARDATA(data), dlen,
                               (uint8 *) VARDATA(res), &rlen);

but in pg_decrypt_iv() it's just

    err = px_combo_init(c, (uint8 *) VARDATA(key), klen,
                        (uint8 *) VARDATA(iv), ivlen);
    if (!err)
        px_combo_decrypt(c, (uint8 *) VARDATA(data), dlen,
                         (uint8 *) VARDATA(res), &rlen);

It looks to me like the result of px_combo_decrypt should be assigned to
"err" here.  If I make that change, the test case you provide is
rejected:

ERROR:  decrypt_iv error: Data not a multiple of block size

but the module's regression tests all still pass, indicating that this
sort of case isn't tested.

pg_encrypt_iv() has the identical usage error with respect to
px_combo_encrypt.

Marko, does this look right to you?

			regards, tom lane



view thread (13+ messages)  latest in thread

Message-ID: <23889.1327646231@sss.pgh.pa.us>
Permalink:  ../23889.1327646231@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23889.1327646231@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, stefan@kaltenbrunner.cc, markokr@gmail.com
  Subject: Re: pgcrypto decrypt_iv() issue
  In-Reply-To: <23889.1327646231@sss.pgh.pa.us>
  References: <4F1DB7BF.60304@kaltenbrunner.cc> <4F1F23E8.80100@kaltenbrunner.cc> <23889.1327646231@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox