Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-12-07 Thread Peter Eisentraut
Committed your v2 patch (with default to on).  I added a small snippet
of documentation explaining that this setting is mainly for backward
compatibility.




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-29 Thread Peter Eisentraut
On Thu, 2013-11-14 at 11:45 +0100, Magnus Hagander wrote:
 I think the default behaviour should be the one we recommend (which
 would be to have the server one be preferred). But I do agree with the
 requirement to have a GUC to be able to  remove it

Is there a reason why you would want to turn it off?




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-29 Thread Marko Kreen
On Fri, Nov 29, 2013 at 09:25:02AM -0500, Peter Eisentraut wrote:
 On Thu, 2013-11-14 at 11:45 +0100, Magnus Hagander wrote:
  I think the default behaviour should be the one we recommend (which
  would be to have the server one be preferred). But I do agree with the
  requirement to have a GUC to be able to  remove it
 
 Is there a reason why you would want to turn it off?

GUC is there so old behaviour can be restored.

Why would anyone want that, I don't know.  In context of PostgreSQL,
I see no reason to prefer old behaviour.

-- 
marko



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-29 Thread Heikki Linnakangas

On 11/29/2013 05:43 PM, Marko Kreen wrote:

On Fri, Nov 29, 2013 at 09:25:02AM -0500, Peter Eisentraut wrote:

On Thu, 2013-11-14 at 11:45 +0100, Magnus Hagander wrote:

I think the default behaviour should be the one we recommend (which
would be to have the server one be preferred). But I do agree with the
requirement to have a GUC to be able to  remove it


Is there a reason why you would want to turn it off?


GUC is there so old behaviour can be restored.

Why would anyone want that, I don't know.  In context of PostgreSQL,
I see no reason to prefer old behaviour.


Imagine that the server is public, and anyone can connect. The server 
offers SSL protection not to protect the data in the server, since 
that's public anyway, but to protect the communication of the client. In 
that situation, it should be the client's choice what encryption to use 
(if any). This is analogous to using https on a public website.


I concur that that's pretty far-fetched. Just changing the behavior, 
with no GUC, is fine by me.


- Heikki


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-29 Thread Marko Kreen
On Fri, Nov 29, 2013 at 05:51:28PM +0200, Heikki Linnakangas wrote:
 On 11/29/2013 05:43 PM, Marko Kreen wrote:
 On Fri, Nov 29, 2013 at 09:25:02AM -0500, Peter Eisentraut wrote:
 On Thu, 2013-11-14 at 11:45 +0100, Magnus Hagander wrote:
 I think the default behaviour should be the one we recommend (which
 would be to have the server one be preferred). But I do agree with the
 requirement to have a GUC to be able to  remove it
 
 Is there a reason why you would want to turn it off?
 
 GUC is there so old behaviour can be restored.
 
 Why would anyone want that, I don't know.  In context of PostgreSQL,
 I see no reason to prefer old behaviour.
 
 Imagine that the server is public, and anyone can connect. The
 server offers SSL protection not to protect the data in the server,
 since that's public anyway, but to protect the communication of the
 client. In that situation, it should be the client's choice what
 encryption to use (if any). This is analogous to using https on a
 public website.
 
 I concur that that's pretty far-fetched. Just changing the behavior,
 with no GUC, is fine by me.

But client can control that behaviour - it just needs to specify
suites it wants and drop the rest.

So only question is that does any client have better (non-tuned?)
defaults than we can set from server.

Considering the whole HTTPS world has answered 'no' to that question
and nowadays server-controlled behaviour is preferred, I think it's
safe to change the behaviour in Postgres too.

-- 
marko



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-14 Thread Magnus Hagander
On Thursday, November 7, 2013, Marko Kreen wrote:

 On Wed, Nov 06, 2013 at 09:57:32PM -0300, Alvaro Herrera wrote:
  Marko Kreen escribió:
 
   By default OpenSSL (and SSL/TLS in general) lets client cipher
   order take priority.  This is OK for browsers where the ciphers
   were tuned, but few Postgres client libraries make cipher order
   configurable.  So it makes sense to make cipher order in
   postgresql.conf take priority over client defaults.
  
   This patch adds setting 'ssl_prefer_server_ciphers' which can be
   turned on so that server cipher order is preferred.
 
  Wouldn't it make more sense to have this enabled by default?

 Well, yes.  :)

 I would even drop the GUC setting, but hypothetically there could
 be some sort of backwards compatiblity concerns, so I added it
 to patch and kept old default.  But if noone has strong need for it,
 the setting can be removed.


I think the default behaviour should be the one we recommend (which would
be to have the server one be preferred). But I do agree with the
requirement to have a GUC to be able to  remove it - even though I don't
like the idea of more GUCs. But making it a compile time option would make
it the same as not having one...

//Magnus



-- 
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/


[HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-06 Thread Marko Kreen

By default OpenSSL (and SSL/TLS in general) lets client cipher
order take priority.  This is OK for browsers where the ciphers
were tuned, but few Postgres client libraries make cipher order
configurable.  So it makes sense to make cipher order in
postgresql.conf take priority over client defaults.

This patch adds setting 'ssl_prefer_server_ciphers' which can be
turned on so that server cipher order is preferred.

The setting SSL_OP_CIPHER_SERVER_PREFERENCE appeared in
OpenSSL 0.9.7 (31 Dec 2002), not sure if #ifdef is required
for conditional compilation.
---
 doc/src/sgml/config.sgml  | 12 
 src/backend/libpq/be-secure.c |  7 +++
 src/backend/utils/misc/guc.c  | 10 ++
 3 files changed, 29 insertions(+)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 77a9303..56bfa01 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -883,6 +883,18 @@ include 'filename'
   /listitem
  /varlistentry
 
+ varlistentry id=guc-ssl-prefer-server-ciphers xreflabel=ssl_prefer_server_ciphers
+  termvarnamessl_prefer_server_ciphers/varname (typebool/type)/term
+  indexterm
+   primaryvarnamessl_prefer_server_ciphers/ configuration parameter/primary
+  /indexterm
+  listitem
+   para
+Specifies whether to prefer client or server ciphersuite.
+   /para
+  /listitem
+ /varlistentry
+
  varlistentry id=guc-password-encryption xreflabel=password_encryption
   termvarnamepassword_encryption/varname (typeboolean/type)/term
   indexterm
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index 7f01a78..2094674 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -112,6 +112,9 @@ static bool ssl_loaded_verify_locations = false;
 /* GUC variable controlling SSL cipher list */
 char	   *SSLCipherSuites = NULL;
 
+/* GUC variable: if false, prefer client ciphers */
+bool	   SSLPreferServerCiphers;
+
 /*  */
 /*		 Hardcoded values		*/
 /*  */
@@ -845,6 +848,10 @@ initialize_SSL(void)
 	if (SSL_CTX_set_cipher_list(SSL_context, SSLCipherSuites) != 1)
 		elog(FATAL, could not set the cipher list (no valid ciphers available));
 
+	/* Let server choose order */
+	if (SSLPreferServerCiphers)
+		SSL_CTX_set_options(SSL_context, SSL_OP_CIPHER_SERVER_PREFERENCE);
+
 	/*
 	 * Load CA store, so we can verify client certificates if needed.
 	 */
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 538d027..7f1771a 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -127,6 +127,7 @@ extern char *temp_tablespaces;
 extern bool ignore_checksum_failure;
 extern bool synchronize_seqscans;
 extern char *SSLCipherSuites;
+extern bool SSLPreferServerCiphers;
 
 #ifdef TRACE_SORT
 extern bool trace_sort;
@@ -801,6 +802,15 @@ static struct config_bool ConfigureNamesBool[] =
 		check_ssl, NULL, NULL
 	},
 	{
+		{ssl_prefer_server_ciphers, PGC_POSTMASTER, CONN_AUTH_SECURITY,
+			gettext_noop(Give priority to server ciphersuite order.),
+			NULL
+		},
+		SSLPreferServerCiphers,
+		false,
+		NULL, NULL, NULL
+	},
+	{
 		{fsync, PGC_SIGHUP, WAL_SETTINGS,
 			gettext_noop(Forces synchronization of updates to disk.),
 			gettext_noop(The server will use the fsync() system call in several places to make 

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-06 Thread Alvaro Herrera
Marko Kreen escribió:

 By default OpenSSL (and SSL/TLS in general) lets client cipher
 order take priority.  This is OK for browsers where the ciphers
 were tuned, but few Postgres client libraries make cipher order
 configurable.  So it makes sense to make cipher order in
 postgresql.conf take priority over client defaults.
 
 This patch adds setting 'ssl_prefer_server_ciphers' which can be
 turned on so that server cipher order is preferred.

Wouldn't it make more sense to have this enabled by default?

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 1/2] SSL: GUC option to prefer server cipher order

2013-11-06 Thread Marko Kreen
On Wed, Nov 06, 2013 at 09:57:32PM -0300, Alvaro Herrera wrote:
 Marko Kreen escribió:
 
  By default OpenSSL (and SSL/TLS in general) lets client cipher
  order take priority.  This is OK for browsers where the ciphers
  were tuned, but few Postgres client libraries make cipher order
  configurable.  So it makes sense to make cipher order in
  postgresql.conf take priority over client defaults.
  
  This patch adds setting 'ssl_prefer_server_ciphers' which can be
  turned on so that server cipher order is preferred.
 
 Wouldn't it make more sense to have this enabled by default?

Well, yes.  :)

I would even drop the GUC setting, but hypothetically there could
be some sort of backwards compatiblity concerns, so I added it
to patch and kept old default.  But if noone has strong need for it,
the setting can be removed.

-- 
marko



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers