Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmfWM-0001CR-Eq for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Sep 2016 11:16:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bmfWM-0004FD-2J for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Sep 2016 11:16:58 +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_2) (envelope-from ) id 1bmfVh-0003Iw-6G for pgsql-bugs@postgresql.org; Wed, 21 Sep 2016 11:16:17 +0000 Received: from resqmta-ch2-01v.sys.comcast.net ([2001:558:fe21:29:69:252:207:33]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bmfVd-0007B9-HD for pgsql-bugs@postgresql.org; Wed, 21 Sep 2016 11:16:15 +0000 Received: from resomta-ch2-10v.sys.comcast.net ([69.252.207.106]) by resqmta-ch2-01v.sys.comcast.net with SMTP id mfVFb7b4nTaLwmfVbbMW7m; Wed, 21 Sep 2016 11:16:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1474456571; bh=e2ZAZ4ZM/YQUb0RpzaUmw181QrPAaI4AE3Z9PNFbe14=; h=Received:Received:Date:From:To:Message-ID:Subject:MIME-Version: Content-Type; b=eMoVphUBLiuZKVJsnAS36fuDzcftb5wk5f8xmYLfOYsF2e5NhvVlQJU/TV7qOqR4e XnBFlXYuY25bcg8q4pq3Wpj/MZUWlki+1MhnT7ugZIDlrLczWQWrBYPSkr9JnFUg5O JD6Aj/RpwV1DyC8PBtp5tFg8JpG6GOjUS9BN4S3Qj7GGJvBB7ZzznIEgJRX7F05IRA rDsv49PO5zytOE8wnrKxFZjfWrpKnrYOMj2sCWw16N5xHNvK2HZVx3AeKkoV21iZRr 9ilIeiuk8rBYFMRPWNu+ILPWZ7WZg5XeMwzPqS6HHnoqrLqZnHebS7dmyiO1vbDd1r JgJSx99fEIKhA== Received: from resmail-ch2-305v.sys.comcast.net ([162.150.49.84]) by resomta-ch2-10v.sys.comcast.net with SMTP id mfVabpfMw8W1PmfVabH3ZC; Wed, 21 Sep 2016 11:16:10 +0000 Date: Wed, 21 Sep 2016 11:16:10 +0000 (UTC) From: Lou Picciano To: Heikki Linnakangas Cc: kzuk@akamai.com, pgsql-bugs@postgresql.org Message-ID: <88224499.27838527.1474456570201.JavaMail.zimbra@comcast.net> In-Reply-To: References: <20160920101051.1355.79453@wrigleys.postgresql.org> Subject: Re: BUG #14329: libpq doesn't send complete client certificate chain on first SSL connection MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_27838526_990247307.1474456570200" X-Originating-IP: [::ffff:73.33.92.169] X-Mailer: Zimbra 8.0.7_GA_6031 (ZimbraWebClient - SAF9.1 (Mac)/8.0.7_GA_6031) Thread-Topic: BUG #14329: libpq doesn't send complete client certificate chain on first SSL connection Thread-Index: DodMvlnoiG0KFJ8oT8Rdaj0XQwHJew== X-CMAE-Envelope: MS4wfGFlz6AGK+OYzFTMcW/WdJ48LByxHvjeLfdj4vM8s4PRyJFCNGOFSDY6PQA9XEtKcyXDQdOYC4XV9OAe0bdbj1bslMPFCcpB5qCX0XjgSgtFujE3I+KR tyENOEWzM8nOBGinxX8RH7cOQWoHJBmzGawmxOrxK7AvWxJGZ5bj3o97P/ZAFxQ++MJ3y8tODq//Q3t838sVFeQv40MnV5r/V0ZYc9WZCmopEnuqECNDElTI 0GqByXYT+4rdY5tq0B+bxA== X-Pg-Spam-Score: -5.8 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------=_Part_27838526_990247307.1474456570200 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Heikki - Would also be happy to set up a test case for this.... Impacts us directly. Need a couple of days to do so, though. Please let me know your timeline. Lou Picciano ----- Original Message ----- From: "Heikki Linnakangas" To: kzuk@akamai.com, pgsql-bugs@postgresql.org Sent: Wednesday, September 21, 2016 4:06:33 AM Subject: Re: [BUGS] BUG #14329: libpq doesn't send complete client certificate chain on first SSL connection On 09/20/2016 01:10 PM, kzuk@akamai.com wrote: > My educated guess is that in fe-secure-openssl.c in initialize_SSL function > whole certificate chain is loaded into SSL_context, but only client > certificate is loaded to SSL object. SSL object is created before loading > certificate chain into SSL_context, so it doesn't see this update. Only the > next connection, with new SSL object, picks up the certificate chain from > SSL_context. It doesn't explain why it works with OpenSSL 1.0.1 though, so > that may be a false trail. Yeah, that's probably what's happening. The OpenSSL man page for SSL_CTX_use_certificate() says: > The SSL_CTX_* class of functions loads the certificates and keys into > the SSL_CTX object ctx. The information is passed to SSL objects ssl > created from ctx with SSL_new by copying, so that changes applied to > ctx do not propagate to already existing SSL objects. It says the same in both 1.0.1 and 1.0.2 versions, though. I guess we have been relying on a bug that was fixed in 1.0.2, in that the intermediate CA certs were actually propagated from the context to the existing SSL object, contrary to what the man page says. I don't immediately see any relevant change in the OpenSSL commit logs between 1.0.1 and 1.0.2, though. I think we need to rearrange the code so that we call SSL_CTX_use_certificate() first, and SSL_new() after that. I wonder if that's going to break 1.0.1, though. Setting up a test environment with the required certificates and CAs is a bit tedious. Would you be interested in adding a test case for this in the SSL test suite, in src/test/ssl, and posting a patch for that? I can take a stab at fixing this, but having a test case ready would give me a head start. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------=_Part_27838526_990247307.1474456570200 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Heikki - 

Would also be happy = to set up a test case for this.... Impacts us directly.

Need a couple of days to do so, though. Please let me know your timel= ine.

Lou Picciano


Fro= m: "Heikki Linnakangas" <hlinnaka@iki.fi>
To: kzuk@akam= ai.com, pgsql-bugs@postgresql.org
Sent: Wednesday, September 21, = 2016 4:06:33 AM
Subject: Re: [BUGS] BUG #14329: libpq doesn't sen= d complete client certificate chain on first SSL connection

On 09/20/2016 01:10 PM, kzuk@akamai.com wrote:
> My educated guess= is that in fe-secure-openssl.c in initialize_SSL function
> whole ce= rtificate chain is loaded into SSL_context, but only client
> certifi= cate is loaded to SSL object. SSL object is created before loading
> = certificate chain into SSL_context, so it doesn't see this update. Only the=
> next connection, with new SSL object, picks up the certificate cha= in from
> SSL_context. It doesn't explain why it works with OpenSSL 1= .0.1 though, so
> that may be a false trail.

Yeah, = that's probably what's happening. The OpenSSL man page for
SSL_CTX_use_= certificate() says:

> The SSL_CTX_* class of functions= loads the certificates and keys into
> the SSL_CTX object ctx. The i= nformation is passed to SSL objects ssl
> created from ctx with SSL_n= ew by copying, so that changes applied to
> ctx do not propagate to a= lready existing SSL objects.

It says the same in both 1.0= .1 and 1.0.2 versions, though. I guess we
have been relying on a bug th= at was fixed in 1.0.2, in that the
intermediate CA certs were actually = propagated from the context to the
existing SSL object, contrary to wha= t the man page says. I don't
immediately see any relevant change in the= OpenSSL commit logs between
1.0.1 and 1.0.2, though.

I think we need to rearrange the code so that we call
SSL_CTX_use_cert= ificate() first, and SSL_new() after that. I wonder if
that's going to = break 1.0.1, though.

Setting up a test environment with t= he required certificates and CAs is
a bit tedious. Would you be interes= ted in adding a test case for this in
the SSL test suite, in src/test/s= sl, and posting a patch for that? I can
take a stab at fixing this, but= having a test case ready would give me a
head start.

- Heikki



--
Sent via pgsql-bugs m= ailing list (pgsql-bugs@postgresql.org)
To make changes to your subscrip= tion:
http://www.postgresql.org/mailpref/pgsql-bugs

------=_Part_27838526_990247307.1474456570200--