Re: pgcrypto: is an IV needed with pgp_sym_encrypt()?

From: Bill Moseley <moseley(at)hank(dot)org>
To: Marko Kreen <markokr(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pgcrypto: is an IV needed with pgp_sym_encrypt()?
Date: 2007-09-18 18:34:04
Message-ID: 20070918183404.GA29512@hank.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Sep 18, 2007 at 11:26:17AM +0300, Marko Kreen wrote:
> Few bytes being same is normal. Those are PGP packet header,
> telling "this is symmetrically encrypted session key packet,
> with length X" plus some more details.

I see. So, you are saying no need to generate my own IV to prepend to
the plain text before encrypting.

> If more that few bytes are same, and if the salt is not randomised
> it _could_ be a sign of problem. Either pgcrypto bug or failure
> to initialize random generator. If you suspect a problem, please
> send me few example encryptions with keys and your setup details
> (postgres version, openssl or not, os version)

No, it was only a few bytes that were similar, so the headers explain
that.

> > Besides following the PCI DSS and external audit procedures, the plan
> > is to use pgcrypto (pgp_sym_encrypt() with AES-256) as part of a
> > credit card storage server. The server and db are SSL only and the
> > key is passed from the application and never stored anyplace (except
> > in memcached on other servers during the session). The key is a
> > user's plain text password plus an application-specific secret. So,
> > each row has its own key. Passwords must be changed periodically,
> > etc.
>
> I don't know details of your setup, but I strongly suggest you
> look into using public-key crypto. That allow you separate keys
> for encryption and decryption. So in webserver where users only
> input credit cards, you keep only public keys, so anybody cracking
> that won't be able to decrypt data.

I need to look at that more. But I've seen that suggested where one
needs to decrypt the data at a later time. We don't have that need.

Our plan was to never store any keys. Every user must log in to the
application with a password. Their account passwords are only stored
hashed on disk, so we don't know their passwords.

The plan is to encrypt their plain-text password with a secret known
by the application only and stored into memcached. It's this
plain-text password that will be sent to a separate server to encrypt
and (and decrypt) their credit card data when the user make a
transaction.

We only need to store the credit card data to allow subsequent charges
to their "card on file" -- and that only happens when a user logs in
and processes a transaction. We don't have any way to decrypt the
data without this password stored in the session.

If someone hacks an application server they could pluck active user's
passwords from memcached and also find the application's secret word.

Then if they also hacked the credit card server they could then
decrypt the data using passwords they were able to sniff.

See any glaring holes?

Thanks for the help!

--
Bill Moseley
moseley(at)hank(dot)org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Williamson 2007-09-18 19:00:44 Re: For index bloat: VACUUM ANALYZE vs REINDEX/CLUSTER
Previous Message John D. Burger 2007-09-18 18:31:23 Re: Performance Issues (was: "like" vs "substring" again)