Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B9C6E1337B5A for ; Fri, 3 Dec 2010 14:49:25 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 16359-04 for ; Fri, 3 Dec 2010 18:49:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og102.obsmtp.com (exprod7og102.obsmtp.com [64.18.2.157]) by mail.postgresql.org (Postfix) with SMTP id 5FAF71337B2F for ; Fri, 3 Dec 2010 14:49:17 -0400 (AST) Received: from source ([209.85.215.173]) by exprod7ob102.postini.com ([64.18.6.12]) with SMTP ID DSNKTPk7rKwIwKfn5IsKlpSgW2QMDKu48HU6@postini.com; Fri, 03 Dec 2010 10:49:17 PST Received: by eya25 with SMTP id 25so5202080eya.32 for ; Fri, 03 Dec 2010 10:49:15 -0800 (PST) Received: by 10.213.5.5 with SMTP id 5mr3004521ebt.84.1291402153811; Fri, 03 Dec 2010 10:49:13 -0800 (PST) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id q58sm1765444eeh.15.2010.12.03.10.49.12 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 03 Dec 2010 10:49:12 -0800 (PST) Message-ID: <4CF93BA7.5040808@enterprisedb.com> Date: Fri, 03 Dec 2010 20:49:11 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.15) Gecko/20101030 Icedove/3.0.10 MIME-Version: 1.0 To: daniel CC: pgsql-bugs@postgresql.org Subject: Re: pgcrypto bug or my brain? References: <2CFE8790-1613-4721-8001-6F37DB78F91A@zeus.bwh.harvard.edu> In-Reply-To: <2CFE8790-1613-4721-8001-6F37DB78F91A@zeus.bwh.harvard.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201012/18 X-Sequence-Number: 28824 On 03.12.2010 19:48, daniel wrote: > I have discovered either a bug in pgcrypto (postgresql-9.0.1) or at least an implementation change that is incompatible with how I've been using pgcrypto. I'm hoping a discussion here on bugs@ is an appropriate first course of discussion. > > I have a couple of databases in which I have been using pgcrypto for about 10 years (one relation has> 1.8 million records). I believe I started using pgcrypto with postgresql-7.2.x and have had absolutely no adverse issues with my data during regular upgrades through postgresql-8.4.5. I know that the raw encrypt() and decrypt() are no longer recommended when the pgp_*() can be used, but this is now a legacy issue since the pgp_*() functions did not even exist 10 years ago. Please note that the pgp_*() functions do work fine in postgresql-9.0.1. > > During testing of upgrade to 9.0.1 (I _love_ streaming replication!), my encrypted data gets mangled during import (psql -f) and, in fact, I can't even use encrypt() or decrypt() on new data in my "usual way". Here's an example that works on 7.2.x through 8.4.5 but not 9.0.1 (additional platform details are below): > > -- > -- Pull in pgcrypto functions: > -- > \i /usr/local/pgsql/share/contrib/pgcrypto.sql > > > -- > -- Create a test table: > -- > create table cryptest ( > id serial not null primary key, > plaint character varying not null, > enct bytea > ); > > > -- > -- Insert some data: > -- > insert into cryptest (plaint, enct) values > ('Testing blowfish...', encrypt('Testing blowfish...', > E'I know this is not a proper key but it _should_ work', 'bf')); > > > -- > -- Fetch the data: > -- > select > id, > plaint, > decrypt(enct, E'I know this is not a proper key but it _should_ work', 'bf') > from > cryptest; > > > Platform: > CentOS-5.5 (fully up to date with 'yum update') both i386 and x86_64 > Postgresql configured with './configure --with-openssl' > > > I'll be happy to provide any additional information necessary and do any sort of testing (if it should prove to be necessary) though my skills in this are somewhat limited. decrypt() returns a bytea, and the default representation of bytea was changed in 9.0. The result is the same but it's just displayed differently. Try "set bytea_output TO 'escape'" to get the old familiar output. The proper way to do that is to use convert_to/from to convert from text to bytea before encrypting, and from bytea to text after decrypting. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com