Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1briE8-0003Zu-Mp for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Oct 2016 09:11:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1briE8-0007PE-7x for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Oct 2016 09:11:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1briDT-0006h2-D7 for pgsql-bugs@postgresql.org; Wed, 05 Oct 2016 09:10:19 +0000 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1briDJ-0002gK-Uo for pgsql-bugs@postgresql.org; Wed, 05 Oct 2016 09:10:18 +0000 Received: by mail-lf0-x232.google.com with SMTP id x79so10616612lff.0 for ; Wed, 05 Oct 2016 02:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to; bh=pBSHPRcYcXmV6WTmnvawpat4Mxf3wI1Yuwg51vsLakA=; b=OH+w51jszQeSxBqkjSFdLH+u2wy/zHYRCbqIVJyGOqmKcRs0f8I9otpf3PCEhOGhc2 /zI+rzoPxk3Kon3v2EVdEKnq2cCaoSMx2hxkGYCny3bDrB9YdmQU8iI5DzHrNyLjh8n0 xHFR/Udg5GEHW9kVZutP42txZO7F1//aIlgjT9PAgDzXarkxgjkZeS5OeC4WCiIdokzL xyxBLa4zCUVKFKL9wmk4etRim1pXfoJRiYVHiISWx0wy3KZKReK5XTj4GIS82//3t0v5 wkkBvBjqxxBTgo1m7rcM5WwuBkzdn5TSZN1mT/ROVoapSL11CkrudhD6dttfilGp78j6 CIjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to; bh=pBSHPRcYcXmV6WTmnvawpat4Mxf3wI1Yuwg51vsLakA=; b=LDRdAdud8qObM1g6Sb/NY0GdLuwhn9G/3xFyIrB4pHZlw1mfS+qxIEVa98IIpo0cFC JUMUPwV7WLjrjN7G2Hl3HcuC0pJNiHO4JcY7ZVzVPZibFXtvICIW6tL3fIaSYpq35Hm4 Fa4ZffPmm1Ant8H8hofIjdoHDR6nEGGJeH9ygwFsBk12Ico/65amy5eFtDd9++GiussL AWxdzbS2FIGO26In7rdTu2hANmZEU/hsDrxDxcHZtFiJcjUa43xgazt2+bhWTTbVu8pb N2W0/OulDvhfjaXJ7hxk2+fKeKIOHVFahbH9/GGOnx7HMkzLSYSXL84rNoIaZclmbQpV lMKw== X-Gm-Message-State: AA6/9RlVfnAarrYdecNDd68IuuEIAuHL86szPxbaehpfbcsqxJTRyqGt9pPyQixYf98Dzg== X-Received: by 10.46.33.230 with SMTP id h99mr3207398lji.75.1475658608395; Wed, 05 Oct 2016 02:10:08 -0700 (PDT) Received: from [192.168.1.111] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id y81sm1438860lff.29.2016.10.05.02.10.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Oct 2016 02:10:07 -0700 (PDT) Subject: Re: BUG #14329: libpq doesn't send complete client certificate chain on first SSL connection To: "Zuk, Kacper" , "pgsql-bugs@postgresql.org" References: <20160920101051.1355.79453@wrigleys.postgresql.org> From: Heikki Linnakangas Message-ID: Date: Wed, 5 Oct 2016 12:10:06 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------85BDA5975272BAF7BB52EA09" X-Pg-Spam-Score: -2.6 (--) 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 This is a multi-part message in MIME format. --------------85BDA5975272BAF7BB52EA09 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 10/04/2016 09:55 PM, Heikki Linnakangas wrote: > I'm starting to feel that using the same SSL_CTX object for multiple > connections is just too fragile. Perhaps we could share one SSL_CTX > object for all the connections with no sslcert and no sslrootcert, but > I'm not sure if even that is worth it. > > In quick testing, calling SSL_CTX_new() for each connection adds about > 3% of overhead to establishing a new connection, with the default > OpenSSL settings (seems to use ECDHE-RSA-AES256-GCM-SHA384 cipher here). > I also tested memory usage with a program that opens 10000 connections, > and it used about 15% more memory, when SSL_CTX_new() is called for each > connection. I think that's acceptable. Barring objections, I'm going to > write a patch to use a separate SSL context for every connection. I came up with the attached patch for this. As threatened, it uses a separate SSL context for each connection. That simplifies the code somewhat, and fixes the bugs. Kacper's test case is included in this. (This is for git master, stable branches will need small tweaking to make the patch apply.) Did some more testing with "pgbench -C". The overhead on establishing a connection is a bit higher than I saw initially, about 6%, when sslmode=verify-ca is used. Might be more with more complex certificate chains. I think that's still acceptable. If you have an application that establishes SSL connections so frequently that that matters, you should reconsider your design. - Heikki --------------85BDA5975272BAF7BB52EA09 Content-Type: text/x-diff; name="0001-Don-t-share-SSL_CTX-between-libpq-connections.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Don-t-share-SSL_CTX-between-libpq-connections.patch"