Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZowFG-0002Ob-AL for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Oct 2015 16:28:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZowFF-000114-SA for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Oct 2015 16:28:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZowFE-0000xx-Ki for pgsql-hackers@postgresql.org; Wed, 21 Oct 2015 16:28:08 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZowFB-0007Aw-Ac for pgsql-hackers@postgresql.org; Wed, 21 Oct 2015 16:28:07 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id C0C4D811D9; Wed, 21 Oct 2015 16:28:03 +0000 (UTC) Received: from localhost (vpn-53-166.rdu2.redhat.com [10.10.53.166]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9LGS2TP025160; Wed, 21 Oct 2015 12:28:02 -0400 From: Robbie Harwood To: Michael Paquier Cc: Stephen Frost , PostgreSQL mailing lists , Andres Freund , Craig Ringer Subject: Re: [PATCH v3] GSSAPI encryption support In-Reply-To: References: <20151016133459.GL3685@tamriel.snowman.net> <20151017021105.GP3685@tamriel.snowman.net> User-Agent: Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Wed, 21 Oct 2015 12:28:29 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --=-=-= Content-Type: text/plain Michael Paquier writes: > Robbie, > > +#ifdef ENABLE_GSS > + if (pggss_encrypt(conn) < 0) > + return EOF; > +#endif > > @@ -1528,10 +1541,20 @@ socket_putmessage(char msgtype, const char *s, > size_t len) > if (internal_putbytes(s, len)) > goto fail; > PqCommBusy = false; > +#ifdef ENABLE_GSS > + /* if we're GSSAPI encrypting, s was allocated in be_gss_encrypt */ > + if (msgtype == 'g') > + pfree((char *)s); > +#endif > > Looking at this patch in more details... Why is it necessary to wrap > all the encrypted messages into a dedicated message type 'g'? Cannot > we rely on the context on client and backend that should be set up > after authentication to perform the encryption and decryption > operations? This patch is enforcing the message type in > socket_putmessage for backend and pggss_encrypt/pqPutMsgEnd for > frontend, this just feels wrong and I think that the patch could be > really simplified, this includes the crafting added in fe-protocol3.c > that should be IMO reserved only for messages received from the > backend and should not be made aware of any protocol-level logic. Well, it's not strictly necessary in the general case, but it makes debugging a *lot* easier to have it present, and it simplifies some of the handling logic. For instance, in the part quoted above, with socket_putmessage() and socket_putmessage_noblock(), we need some way to tell whether a message blob has already been encrypted. Some enforcement of message type *will need to be carried out* anyway to avoid security issues with tampering on the wire, whether that be by sanity-checking the stated message type and then handling accordingly, or trying to decrypt and detonating the connection if it fails. GSSAPI does not define a wire protocol for the transport of messages the way, e.g., TLS does, so there must be some handling of incomplete messages, multiple messages at once, etc. There is already adequate handling of these present in postgres already, so I have structured the code to take advantage of it. That said, I could absolutely reimplement them - but it would not be simpler, I'm reasonably sure. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWJ70uAAoJECUy+RdqlaRCYeoP+wUGpaWF9pLYmq+6H+aQSsaX +d1rrbGZ/WITbPRFx7uydDrn5dmJmxNZDV8uV96MH5V9jFjR5C1avcQ82qitijiP oXuQJFu726Yp9pvbLFk8YrltBx43jejNfev+u4v1uf107Twf2R3akgx7Ne0knnyt 6qZQt4ZhnsGmNfgpBwX0D/sMPzi8y4pCoREtEiJYnKhPIEs9fTyqahM6n3mcX63c xV5foq24NeHPN+mLC1zlwinddtETsyi38i5Sp4shS579p4caIlUab2MJ74zfP+K9 Yfjb/14CytVJCAm/4cWVYZpej7/07v5Ai/BPUX8D9pf3sIaecZxgA70I80R5KtKs gs3kkhfn14QSSOe2tsPmH7DD59u2dex7tEXMCn7jQMirHWC5hVWFx3HKjoo4IROm mSHRaO/jpjCMAOxmzelqYX3BnRctNTBjEeb76nXBNIZoSMtXUfXxd1qfW9Van6kA kgt4GgiWMtbe6tbgpakDTYcTX4iUS9bYmOaNRPnYhwCi1nJoLhqnaI+y4YdoXU18 Ny1oes2qkjAhymj1LK7IX3kxuwz2u31IP1YSH5qgkbrfA8RqMd+PZ3TbF5GJ8SMa MsSUPlQXc3lOPNf5Q7PrS3QK1ILyjO+SNEa5xXpx5OXb/ZcLSlzbEwlOELCc21FP F+DNDDtJgtrHvuwvIsy0 =4aOC -----END PGP SIGNATURE----- --=-=-=--