Skip to contentSkip to conversation

Use RSA_generate_key_ex() instead of deprecated, RSA_generate_key()

PATCH In review Steffan Karger 4 participants 26 messages Dec 15, 2013 – Jan 5, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use RSA_generate_key_ex() instead of deprecated, RSA_generate_key()

Hi,

Attached a patch that should close issue #197. This patch moves from using the deprecated RSA_generate_key() to the 'new' RSA_generate_key_ex() to generate ephemeral RSA keys. This patch does not change OpenVPN's behaviour.

One note on the implementation though; the code generates one ephemeral RSA key that is used during the entire lifetime of an OpenVPN process. If OpenSSL requests a new (ephemeral) key, it will keep on returning the same (usually rather small) key. Not the best solution.

To actually run this code, I had to force usage by selecting the TLS-RSA-EXPORT-WITH-DES40-CBC-SHA tls-cipher. That generated a 512-bit ephemeral RSA key, and uses the outdated DES encryption protocol.

Using this mode could lead to a false sense of security. Then again, one should be using (Ephemeral) Diffie-Hellman anyway, and OpenVPN requires a tls-server to supply dh parameters. A user would need to deliberately choose a weak tls-cipher like TLS-RSA-EXPORT-WITH-DES40-CBC-SHA, which would be aligning a gun with his foot anyway. If one would decide this implementation is not good enough anymore, I'd suggest to just strip out support for this completely.

-Steffan

From 6d7d536ea52713fe230264f7798c509f37dd40c9 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Sun, 15 Dec 2013 17:58:04 +0100
Subject: [PATCH] Use RSA_generate_key_ex() instead of deprecated
RSA_generate_key()

Code has been tested using the TLS-RSA-EXPORT-WITH-DES40-CBC-SHA tls-cipher which uses this to create ephemeral RSA keys.

This should resolve ticket #197.

---
 src/openvpn/ssl_openssl.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
src/openvpn/ssl_openssl.c +10 -1
index f41bb71..271801d 100644
@@ -103,8 +103,17 @@ tmp_rsa_cb (SSL * s, int is_export, int keylength)
   static RSA *rsa_tmp = NULL;
   if (rsa_tmp == NULL)
     {
+      int ret = -1;
+      BIGNUM *bn = BN_new();
+      rsa_tmp = RSA_new();
+
       msg (D_HANDSHAKE, "Generating temp (%d bit) RSA key", keylength);
-      rsa_tmp = RSA_generate_key (keylength, RSA_F4, NULL, NULL);
+
+      if(!bn || !BN_set_word(bn, RSA_F4) ||
+	  !RSA_generate_key_ex(rsa_tmp, keylength, bn, NULL))
+	msg(M_SSLERR, "Failed to generate temp RSA key");
+
+      if (bn) BN_free( bn );
     }
   return (rsa_tmp);
 }
Signature · 1 line
1.8.3.2
#1 lore raw

Hi,

Quoted 8 lines · Steffan Karger

One note on the implementation though; the code generates one ephemeral RSA key that is used during the entire lifetime of an OpenVPN process. If OpenSSL requests a new (ephemeral) key, it will keep on returning the same (usually rather small) key. Not the best solution.

To actually run this code, I had to force usage by selecting the TLS-RSA-EXPORT-WITH-DES40-CBC-SHA tls-cipher. That generated a 512-bit ephemeral RSA key, and uses the outdated DES encryption protocol.

I'm not sure I understand the whole picture here. What is happening in the "normal" scenario, and why is this particular cipher calling a different code path inside OpenVPN?

Quoted 7 lines

Using this mode could lead to a false sense of security. Then again, one should be using (Ephemeral) Diffie-Hellman anyway, and OpenVPN requires a tls-server to supply dh parameters. A user would need to deliberately choose a weak tls-cipher like TLS-RSA-EXPORT-WITH-DES40-CBC-SHA, which would be aligning a gun with his foot anyway. If one would decide this implementation is not good enough anymore, I'd suggest to just strip out support for this completely.

I'm tempted to agree with this :) - single-DES (and 40 bit to that!) really isn't what we want to use.

So what would happen if we remove this code, and a user tries to use this tls-cipher?

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#2 lore raw

Hi,

Quoted 9 lines · Gert Doering

Hi,

Quoted 6 lines · Steffan Karger

One note on the implementation though; the code generates one ephemeral RSA key that is used during the entire lifetime of an OpenVPN process. If OpenSSL requests a new (ephemeral) key, it will keep on returning the same (usually rather small) key. Not the best solution.

Quoted 8 lines
Quoted 4 lines

To actually run this code, I had to force usage by selecting the TLS-RSA-EXPORT-WITH-DES40-CBC-SHA tls-cipher. That generated a 512-bit ephemeral RSA key, and uses the outdated DES encryption protocol.

I'm not sure I understand the whole picture here. What is happening in the "normal" scenario, and why is this particular cipher calling a different code path inside OpenVPN?

In the 'normal' scenario, one would use diffie-hellman for key exchange (or ephemeral diffie-hellman for forward secrecy). When using (E)DH, there is no need for ephemeral RSA keys. Some TLS ciphers (if I understand correctly, only EXPORT ciphers) use ephemeral RSA to bump their signed but restricted-length (e.g. 512-bit) key to a larger - generated - key for the connection. The OpenSSL manpage states:
"Additionally, the use of ephemeral RSA key exchange is only allowed in the TLS standard, when the RSA key can be used for signing only, that is for export ciphers."

Quoted 10 lines
Quoted 9 lines

Using this mode could lead to a false sense of security. Then again, one should be using (Ephemeral) Diffie-Hellman anyway, and OpenVPN requires a tls-server to supply dh parameters. A user would need to deliberately choose a weak tls-cipher like TLS-RSA-EXPORT-WITH-DES40-CBC-SHA, which would be aligning a gun with his foot anyway. If one would decide this implementation is not good enough anymore, I'd suggest to just strip out support for this completely.

Quoted 5 lines

I'm tempted to agree with this :) - single-DES (and 40 bit to that!) really isn't what we want to use.

So what would happen if we remove this code, and a user tries to use this tls-cipher?

OpenVPN would not be able to use the cipher and report OpenSSL's error "1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher", which makes sense if you already know what is happening: the cipher chosen is not supported by (one of) the endpoints.

I've given the stripping out a little more thought and think I'm in favour of stripping this out of 2.4, but keep support in 2.3 to not break anything for minor releases. Removing this cipher mode sounds like a feature to me ;)

-Steffan

#3 lore raw

Hi,

Quoted 4 lines · Steffan Karger

I've given the stripping out a little more thought and think I'm in favour of stripping this out of 2.4, but keep support in 2.3 to not break anything for minor releases. Removing this cipher mode sounds like a feature to me ;)

Thanks for your explanation. Yes, this sounds good to me.

As Arne also ACKed the patch, I'll merge it into 2.3 only ("soonish").

Could I ask you to provide a patch to remove this for 2.4?

thanks,

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

Quoted 1 line · Gert Doering

Could I ask you to provide a patch to remove this for 2.4?

Sure. I fixed some extra stuff along the way, I'll send a patch set in a minute.

- -Steffan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJSxHVEAAoJEJgCyj0AftKIvVMH/12ohgqRLO7K8QwImJdMfRPE rt+YIhHOyIxD+II4gRnBoDb1OlDVMLXUyPxpj9mjwq6dh0bBSfsacHCdVB5AyzTn uejpbESoCqLCoK0fnoVHZpecIf5vyiIpv9a9wBgwrpN0ZEJn2vHfvw4vILYTT9cU SXkgTQdFB3EjoKFatTXNT8om+jgapnkQpHoOZ2GMMkTXnLNWHwmV5C9mzkAYdDVY /MN6nrU52LK1b5fZ2Fk3sP7Yk6K9qY80RAw6CVZy9NsTgv8wmKvza1Zz2QewfjLP VwzvHjncrelt9J/izgQJlWFLJ5D3W8QmomttDfjpmSzgv4WPtzDaOV7zPKsYbn0= =NRPZ
-----END PGP SIGNATURE-----

#5 lore raw

[Openvpn-devel] TLS fixes, remove support for ephemeral RSA, disable export ciphers

In reply to Gert Doering

Hi,

This patch set is meant to remove ephemeral RSA support from the master branch, and disable (weak) export ciphers by default. While coding I came along some other stuff I fixed along the way:

1/6: Update two old calls to TSLv1*() functions to SSLv23*() function, matching
the TLS negotiation changes. This patch should be applied to both release/2.3 and master branches.

2/6: Update debug output to match the TLS negatiotiation changes. This patch
should be applied to both release/2.3 and master branches.

3/6: Make --show-tls parse information retrieved from --tls-cipher options, to
ease debugging and configuration. I think this one belongs in both release/2.3 and master too.

4/6: Remove the ephemeral RSA key generation callback, as discussed on the
mailinglist. This patch is for master only.

5/6: Preparation for 6/6, makes tls_ctx_restrict_ciphers accept a NULL pointer
for the cipher_list parameter, in which case it will use default settings (which for now is 'do nothing'). This one could go into release/2.3, because it doesn't really change anything, but is not really needed there as 6/6 is master-only.

6/6: Disable export ciphers for OpenSSL builds. This is to avoid confusion,
because otherwise the export ciphers that require ephemeral RSA would still be printed by --show-tls. Furthermore, export cipher are deliberately weak and much better alternatives are available. This patch is for master only.

I've tried to exhaustively comment on the changes in the commit messages, but if there are any remaining questions I'm happy to answer them.

-Steffan

#6 lore raw

PATCH 1/6 Also update TLSv1_method() calls in support code to SSLv23_method() calls.

Commit 4b67f98 changed calls to TLSv1_{sever,client}_method() to SSLv23_{client,server}_method() to enable TLS version negotiation. This commit does the same for two calls of TLSv1_method() from support code.

---
 src/openvpn/ssl_openssl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +2 -2
index f41bb71..2e5d9cd 100644
@@ -1282,7 +1282,7 @@ show_available_tls_ciphers ()
   const tls_cipher_name_pair *pair;
   int priority = 0;
 
-  ctx = SSL_CTX_new (TLSv1_method ());
+  ctx = SSL_CTX_new (SSLv23_method ());
   if (!ctx)
     msg (M_SSLERR, "Cannot create SSL_CTX object");
 
@@ -1317,7 +1317,7 @@ get_highest_preference_tls_cipher (char *buf, int size)
   SSL *ssl;
   const char *cipher_name;
 
-  ctx = SSL_CTX_new (TLSv1_method ());
+  ctx = SSL_CTX_new (SSLv23_method ());
   if (!ctx)
     msg (M_SSLERR, "Cannot create SSL_CTX object");
   ssl = SSL_new (ctx);
Signature · 1 line
1.8.3.2
#7 lore raw

[Openvpn-devel] [PATCH applied] Re: Also update TLSv1_method() calls in support code to SSLv23_method() calls.

ACK.

Patch has been applied to the master and release/2.3 branches.

commit dd3e319c1d66c7da51b8555d745a1139e0b322f2 (master) commit 191af656f84dbb83a338ded5a72e1a23427837a5 (master)

Author: Steffan Karger
Date:   Wed Jan 1 21:10:21 2014 +0100
     Also update TLSv1_method() calls in support code to SSLv23_method() calls.

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8148
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#8 lore raw

PATCH 2/6 Update TLSv1 error messages to SSLv23 to reflect changes from commit 4b67f98

In reply to Steffan Karger

Commit 4b67f98 changed call to TLSv1_{client,server}_method() to SSLv23_{client,server}_method(), this commit updates the corresponding error messages to match the changes in the code.

---
 src/openvpn/ssl_openssl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +2 -2
index 2e5d9cd..2ed95f0 100644
@@ -117,7 +117,7 @@ tls_ctx_server_new(struct tls_root_ctx *ctx)
   ctx->ctx = SSL_CTX_new (SSLv23_server_method ());
 
   if (ctx->ctx == NULL)
-    msg (M_SSLERR, "SSL_CTX_new TLSv1_server_method");
+    msg (M_SSLERR, "SSL_CTX_new SSLv23_server_method");
 
   SSL_CTX_set_tmp_rsa_callback (ctx->ctx, tmp_rsa_cb);
 }
@@ -130,7 +130,7 @@ tls_ctx_client_new(struct tls_root_ctx *ctx)
   ctx->ctx = SSL_CTX_new (SSLv23_client_method ());
 
   if (ctx->ctx == NULL)
-    msg (M_SSLERR, "SSL_CTX_new TLSv1_client_method");
+    msg (M_SSLERR, "SSL_CTX_new SSLv23_client_method");
 }
 
 void
Signature · 1 line
1.8.3.2
#9 lore raw

[Openvpn-devel] [PATCH applied] Re: Update TLSv1 error messages to SSLv23 to reflect changes from commit 4b67f98

ACK.

Your patch has been applied to the master and release/2.3 branches.

commit 441be9f4f91a16218d40b401384ead51b5aac0cc (master) commit dce118c833433cc0300cbcfe6b2d0cc3d5c34a3d (release/2.3)

Author: Steffan Karger
Date:   Wed Jan 1 21:10:22 2014 +0100
     Update TLSv1 error messages to SSLv23 to reflect changes from commit 4b67f98

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8147
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#10 lore raw

PATCH 3/6 If --tls-cipher is supplied, make --show-tls parse the list.

In reply to Steffan Karger

This allows to check the available TLS ciphers for a specific configuration by supplying both --tls-cipher and --show-tls options.

---
 src/openvpn/init.c         |  2 +-
 src/openvpn/ssl_backend.h  |  4 +++-
 src/openvpn/ssl_openssl.c  | 15 +++++++++------
 src/openvpn/ssl_polarssl.c |  8 +++++++-
 4 files changed, 20 insertions(+), 9 deletions(-)
src/openvpn/init.c +1 -1
index ae08562..1b8ee22 100644
@@ -880,7 +880,7 @@ print_openssl_info (const struct options *options)
 	show_available_engines ();
 #ifdef ENABLE_SSL
       if (options->show_tls_ciphers)
-	show_available_tls_ciphers ();
+	show_available_tls_ciphers (options->cipher_list);
 #endif
       return true;
     }
src/openvpn/ssl_backend.h +3 -1
index 07cb9ab..54383fe 100644
@@ -454,8 +454,10 @@ void print_details (struct key_state_ssl * ks_ssl, const char *prefix);
 /*
  * Show the TLS ciphers that are available for us to use in the OpenSSL
  * library.
+ *
+ * @param		- list of allowed TLS cipher, or NULL.
  */
-void show_available_tls_ciphers ();
+void show_available_tls_ciphers (const char *tls_ciphers);
 
 /*
  * The OpenSSL library has a notion of preference in TLS ciphers.  Higher
src/openvpn/ssl_openssl.c +9 -6
index 2ed95f0..1c6291f 100644
@@ -1274,22 +1274,25 @@ print_details (struct key_state_ssl * ks_ssl, const char *prefix)
 }
 
 void
-show_available_tls_ciphers ()
+show_available_tls_ciphers (const char *cipher_list)
 {
-  SSL_CTX *ctx;
+  struct tls_root_ctx tls_ctx;
   SSL *ssl;
   const char *cipher_name;
   const tls_cipher_name_pair *pair;
   int priority = 0;
 
-  ctx = SSL_CTX_new (SSLv23_method ());
-  if (!ctx)
+  tls_ctx.ctx = SSL_CTX_new (SSLv23_method ());
+  if (!tls_ctx.ctx)
     msg (M_SSLERR, "Cannot create SSL_CTX object");
 
-  ssl = SSL_new (ctx);
+  ssl = SSL_new (tls_ctx.ctx);
   if (!ssl)
     msg (M_SSLERR, "Cannot create SSL object");
 
+  if (cipher_list)
+    tls_ctx_restrict_ciphers(&tls_ctx, cipher_list);
+
   printf ("Available TLS Ciphers,\n");
   printf ("listed in order of preference:\n\n");
   while ((cipher_name = SSL_get_cipher_list (ssl, priority++)))
@@ -1307,7 +1310,7 @@ show_available_tls_ciphers ()
   printf ("\n");
 
   SSL_free (ssl);
-  SSL_CTX_free (ctx);
+  SSL_CTX_free (tls_ctx.ctx);
 }
 
 void
src/openvpn/ssl_polarssl.c +7 -1
index cdd9189..551c352 100644
@@ -1033,10 +1033,16 @@ print_details (struct key_state_ssl * ks_ssl, const char *prefix)
 }
 
 void
-show_available_tls_ciphers ()
+show_available_tls_ciphers (const char *cipher_list)
 {
+  struct tls_root_ctx tls_ctx;
   const int *ciphers = ssl_list_ciphersuites();
 
+  if (cipher_list) {
+    tls_ctx_restrict_ciphers(&tls_ctx, cipher_list);
+    ciphers = tls_ctx.allowed_ciphers;
+  }
+
 #ifndef ENABLE_SMALL
   printf ("Available TLS Ciphers,\n");
   printf ("listed in order of preference:\n\n");
Signature · 1 line
1.8.3.2
#11 lore raw

Re: [Openvpn-devel] [PATCH 3/6] If --tls-cipher is supplied, make --show-tls parse the list.

Am 01.01.14 21:10, schrieb Steffan Karger:

Quoted 4 lines

This allows to check the available TLS ciphers for a specific configuration by supplying both --tls-cipher and --show-tls options.

ACK.

Arne

#12 lore raw

[Openvpn-devel] [PATCH applied] Re: If --tls-cipher is supplied, make --show-tls parse the list.

In reply to Steffan Karger

Your patch has been applied to the master and release/2.3 branches.

commit cb03dca83e37fd65666bf776f39da902fb10acbc (master) commit 5690c525e58769a72fb5dbe63b5f6af78dff92ad (release/2.3)

Author: Steffan Karger
Date:   Wed Jan 1 21:10:23 2014 +0100
     If --tls-cipher is supplied, make --show-tls parse the list.

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8150
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#13 lore raw

PATCH 4/6 Remove OpenSSL tmp_rsa_callback. Removes support for ephemeral RSA in TLS.

In reply to Steffan Karger

This code would not really generate ephemeral keys every time it is called, but a single key that would be reused during process lifetime and returned each time the function was called; probably not what users would expect.

TLS allowes ephemeral keys to be used only when no other key exchange, such as (ephemeral) Diffie-Hellman, is performed. The end result is that it was only used by a number of (weak) export ciphers, which could give users a false sense of security.

So, instead of fixing a weak cipher mode, we'll just remove support for it completely. Plenty of better alternatives are available in TLS.

---
 src/openvpn/ssl_openssl.c | 18 ------------------
 1 file changed, 18 deletions(-)
src/openvpn/ssl_openssl.c +0 -18
index 1c6291f..08327a1 100644
@@ -93,22 +93,6 @@ tls_clear_error()
   ERR_clear_error ();
 }
 
-/*
- * OpenSSL callback to get a temporary RSA key, mostly
- * used for export ciphers.
- */
-static RSA *
-tmp_rsa_cb (SSL * s, int is_export, int keylength)
-{
-  static RSA *rsa_tmp = NULL;
-  if (rsa_tmp == NULL)
-    {
-      msg (D_HANDSHAKE, "Generating temp (%d bit) RSA key", keylength);
-      rsa_tmp = RSA_generate_key (keylength, RSA_F4, NULL, NULL);
-    }
-  return (rsa_tmp);
-}
-
 void
 tls_ctx_server_new(struct tls_root_ctx *ctx)
 {
@@ -118,8 +102,6 @@ tls_ctx_server_new(struct tls_root_ctx *ctx)
 
   if (ctx->ctx == NULL)
     msg (M_SSLERR, "SSL_CTX_new SSLv23_server_method");
-
-  SSL_CTX_set_tmp_rsa_callback (ctx->ctx, tmp_rsa_cb);
 }
 
 void
Signature · 1 line
1.8.3.2
#14 lore raw

Re: [Openvpn-devel] [PATCH 4/6] Remove OpenSSL tmp_rsa_callback. Removes support for ephemeral RSA in TLS.

Am 01.01.14 21:10, schrieb Steffan Karger:

Quoted 4 lines

This code would not really generate ephemeral keys every time it is called, but a single key that would be reused during process lifetime and returned each time the function was called; probably not what users would expect.

Quoted 8 lines

TLS allowes ephemeral keys to be used only when no other key exchange, such as (ephemeral) Diffie-Hellman, is performed. The end result is that it was only used by a number of (weak) export ciphers, which could give users a false sense of security.

So, instead of fixing a weak cipher mode, we'll just remove support for it completely. Plenty of better alternatives are available in TLS.

ACK. (reading SSL_CTX_set_tmp_rsa_callback is scary btw).

Arne

#15 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove OpenSSL tmp_rsa_callback. Removes support for ephemeral RSA in TLS.

In reply to Steffan Karger

Your patch has been applied to the master branch.

commit 813aa55754c27bdae5380dce415497a574b47e1b

Author: Steffan Karger
Date:   Wed Jan 1 21:10:24 2014 +0100
     Remove OpenSSL tmp_rsa_callback. Removes support for ephemeral RSA in TLS.

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8152
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#16 lore raw

PATCH 5/6 Make tls_ctx_restrict_ciphers accept NULL as char *cipher_list.

In reply to Steffan Karger

This diff look like a lot has changed, but this just adds some ifs to check for NULL in tls_ctx_restrict_ciphers() to prepare for disabling export ciphers by default in OpenVPN 2.4+.

---
 src/openvpn/ssl.c          |   5 +-
 src/openvpn/ssl_backend.h  |   5 +-
 src/openvpn/ssl_openssl.c  | 130 ++++++++++++++++++++++++++-------------------
 src/openvpn/ssl_polarssl.c |   7 ++-
 4 files changed, 85 insertions(+), 62 deletions(-)
src/openvpn/ssl.c +1 -4
index bd19d75..93222c4 100644
@@ -543,10 +543,7 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
     }
 
   /* Allowable ciphers */
-  if (options->cipher_list)
-    {
-      tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
-    }
+  tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
 
 #ifdef ENABLE_CRYPTO_POLARSSL
   /* Personalise the random by mixing in the certificate */
src/openvpn/ssl_backend.h +3 -2
index 54383fe..a6fc3bd 100644
@@ -167,8 +167,9 @@ void tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags);
 /**
  * Restrict the list of ciphers that can be used within the TLS context.
  *
- * @param ctx		TLS context to restrict
- * @param ciphers	String containing : delimited cipher names.
+ * @param ctx		TLS context to restrict, must be valid.
+ * @param ciphers	String containing : delimited cipher names, or NULL to use
+ *					sane defaults.
  */
 void tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers);
 
src/openvpn/ssl_openssl.c +75 -55

146 lines not on this page · raw message

src/openvpn/ssl_polarssl.c +6 -1
index 551c352..d964b91 100644
@@ -173,7 +173,12 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
   char *tmp_ciphers, *tmp_ciphers_orig, *token;
   int i, cipher_count;
-  int ciphers_len = strlen (ciphers);
+  int ciphers_len;
+
+  if (NULL == ciphers)
+    return; // Nothing to do
+
+  ciphers_len = strlen (ciphers);
 
   ASSERT (NULL != ctx);
   ASSERT (0 != ciphers_len);
Signature · 1 line
1.8.3.2
#17 lore raw

Re: [Openvpn-devel] [PATCH 5/6] Make tls_ctx_restrict_ciphers accept NULL as char *cipher_list.

Hi,

Attached a v2 of the patch below, that removes the else to make the diff a lot smaller and changes a //-style comment to /* */-style.

-Steffan

Quoted 204 lines · Steffan Karger

This diff look like a lot has changed, but this just adds some ifs to check for NULL in tls_ctx_restrict_ciphers() to prepare for disabling export ciphers by default in OpenVPN 2.4+.

---
 src/openvpn/ssl.c          |   5 +-
 src/openvpn/ssl_backend.h  |   5 +-
 src/openvpn/ssl_openssl.c  | 130 ++++++++++++++++++++++++++-------------------
 src/openvpn/ssl_polarssl.c |   7 ++-
 4 files changed, 85 insertions(+), 62 deletions(-)
src/openvpn/ssl.c +1 -4
index bd19d75..93222c4 100644
@@ -543,10 +543,7 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
     }
 
   /* Allowable ciphers */
-  if (options->cipher_list)
-    {
-      tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
-    }
+  tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
 
 #ifdef ENABLE_CRYPTO_POLARSSL
   /* Personalise the random by mixing in the certificate */
src/openvpn/ssl_backend.h +3 -2
index 54383fe..a6fc3bd 100644
@@ -167,8 +167,9 @@ void tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags);
 /**
  * Restrict the list of ciphers that can be used within the TLS context.
  *
- * @param ctx		TLS context to restrict
- * @param ciphers	String containing : delimited cipher names.
+ * @param ctx		TLS context to restrict, must be valid.
+ * @param ciphers	String containing : delimited cipher names, or NULL to use
+ *					sane defaults.
  */
 void tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers);
 
src/openvpn/ssl_openssl.c +75 -55
index 08327a1..5f6c270 100644
@@ -217,71 +217,91 @@ tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags)
 void
 tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
-  size_t begin_of_cipher, end_of_cipher;
-
-  const char *current_cipher;
-  size_t current_cipher_len;
+  if (ciphers == NULL)
+    {
+      /* Nothing to do */
+      return;
+    }
+  else
+    {
+      /* Parse supplied cipher list and pass on to OpenSSL */
+      size_t begin_of_cipher, end_of_cipher;
 
-  const tls_cipher_name_pair *cipher_pair;
+      const char *current_cipher;
+      size_t current_cipher_len;
 
-  char openssl_ciphers[4096];
-  size_t openssl_ciphers_len = 0;
-  openssl_ciphers[0] = '\0';
+      const tls_cipher_name_pair *cipher_pair;
 
-  ASSERT(NULL != ctx);
+      char openssl_ciphers[4096];
+      size_t openssl_ciphers_len = 0;
+      openssl_ciphers[0] = '\0';
 
-  // Translate IANA cipher suite names to OpenSSL names
-  begin_of_cipher = end_of_cipher = 0;
-  for (; begin_of_cipher < strlen(ciphers); begin_of_cipher = end_of_cipher) {
-      end_of_cipher += strcspn(&ciphers[begin_of_cipher], ":");
-      cipher_pair = tls_get_cipher_name_pair(&ciphers[begin_of_cipher], end_of_cipher - begin_of_cipher);
+      ASSERT(NULL != ctx);
 
-      if (NULL == cipher_pair)
+      // Translate IANA cipher suite names to OpenSSL names
+      begin_of_cipher = end_of_cipher = 0;
+      for (; begin_of_cipher < strlen(ciphers); begin_of_cipher = end_of_cipher)
         {
-          // No translation found, use original
-          current_cipher = &ciphers[begin_of_cipher];
-          current_cipher_len = end_of_cipher - begin_of_cipher;
-
-          // Issue warning on missing translation
-          // %.*s format specifier expects length of type int, so guarantee
-          // that length is small enough and cast to int.
-          msg (M_WARN, "No valid translation found for TLS cipher '%.*s'",
-                 constrain_int(current_cipher_len, 0, 256), current_cipher);
-        }
-      else
-	{
-	  // Use OpenSSL name
-          current_cipher = cipher_pair->openssl_name;
-          current_cipher_len = strlen(current_cipher);
-
-	  if (end_of_cipher - begin_of_cipher == current_cipher_len &&
-	      0 == memcmp (&ciphers[begin_of_cipher], cipher_pair->openssl_name, end_of_cipher - begin_of_cipher))
-	    {
-	      // Non-IANA name used, show warning
-	      msg (M_WARN, "Deprecated TLS cipher name '%s', please use IANA name '%s'", cipher_pair->openssl_name, cipher_pair->iana_name);
-	    }
-	}
-
-      // Make sure new cipher name fits in cipher string
-      if (((sizeof(openssl_ciphers)-1) - openssl_ciphers_len) < current_cipher_len) {
-	msg(M_SSLERR, "Failed to set restricted TLS cipher list, too long (>%d).", (int)sizeof(openssl_ciphers)-1);
-      }
+          end_of_cipher += strcspn(&ciphers[begin_of_cipher], ":");
+          cipher_pair = tls_get_cipher_name_pair(&ciphers[begin_of_cipher],
+              end_of_cipher - begin_of_cipher);
 
-      // Concatenate cipher name to OpenSSL cipher string
-      memcpy(&openssl_ciphers[openssl_ciphers_len], current_cipher, current_cipher_len);
-      openssl_ciphers_len += current_cipher_len;
-      openssl_ciphers[openssl_ciphers_len] = ':';
-      openssl_ciphers_len++;
+          if (NULL == cipher_pair)
+            {
+              // No translation found, use original
+              current_cipher = &ciphers[begin_of_cipher];
+              current_cipher_len = end_of_cipher - begin_of_cipher;
+
+              // Issue warning on missing translation
+              // %.*s format specifier expects length of type int, so guarantee
+              // that length is small enough and cast to int.
+              msg (M_WARN, "No valid translation found for TLS cipher '%.*s'",
+                     constrain_int(current_cipher_len, 0, 256), current_cipher);
+            }
+          else
+            {
+              // Use OpenSSL name
+              current_cipher = cipher_pair->openssl_name;
+              current_cipher_len = strlen(current_cipher);
+
+              if (end_of_cipher - begin_of_cipher == current_cipher_len &&
+                  0 == memcmp (&ciphers[begin_of_cipher],
+                      cipher_pair->openssl_name,
+                      end_of_cipher - begin_of_cipher))
+                {
+                  // Non-IANA name used, show warning
+                  msg (M_WARN, "Deprecated TLS cipher name '%s', "
+                      "please use IANA name '%s'", cipher_pair->openssl_name,
+                      cipher_pair->iana_name);
+                }
+            }
 
-      end_of_cipher++;
-  }
+          // Make sure new cipher name fits in cipher string
+          if (((sizeof(openssl_ciphers)-1) - openssl_ciphers_len) <
+              current_cipher_len) {
+            msg(M_SSLERR,
+                "Failed to set restricted TLS cipher list, too long (>%d).",
+                (int)sizeof(openssl_ciphers)-1);
+          }
+
+          // Concatenate cipher name to OpenSSL cipher string
+          memcpy(&openssl_ciphers[openssl_ciphers_len], current_cipher,
+              current_cipher_len);
+          openssl_ciphers_len += current_cipher_len;
+          openssl_ciphers[openssl_ciphers_len] = ':';
+          openssl_ciphers_len++;
+
+          end_of_cipher++;
+        }
 
-  if (openssl_ciphers_len > 0)
-    openssl_ciphers[openssl_ciphers_len-1] = '\0';
+      if (openssl_ciphers_len > 0)
+        openssl_ciphers[openssl_ciphers_len-1] = '\0';
 
-  // Set OpenSSL cipher list
-  if(!SSL_CTX_set_cipher_list(ctx->ctx, openssl_ciphers))
-    msg(M_SSLERR, "Failed to set restricted TLS cipher list: %s", openssl_ciphers);
+      // Set OpenSSL cipher list
+      if(!SSL_CTX_set_cipher_list(ctx->ctx, openssl_ciphers))
+        msg(M_SSLERR, "Failed to set restricted TLS cipher list: %s",
+            openssl_ciphers);
+    }
 }
 
 void
src/openvpn/ssl_polarssl.c +0 -0
index 551c352..d964b91 100644
@@ -173,7 +173,12 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
   char *tmp_ciphers, *tmp_ciphers_orig, *token;
   int i, cipher_count;

src/openvpn/ssl_polarssl.c tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers) · line 184

Quoted 10 lines
src/openvpn/ssl_polarssl.c +6 -1
-  int ciphers_len = strlen (ciphers);
+  int ciphers_len;
+
+  if (NULL == ciphers)
+    return; // Nothing to do
+
+  ciphers_len = strlen (ciphers);
 
   ASSERT (NULL != ctx);
   ASSERT (0 != ciphers_len);

From 980b26eaa90099640197438e4b8f28d0f7fd21b1 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Fri, 3 Jan 2014 21:03:02 +0100
Subject: [PATCH 1/3] Make tls_ctx_restrict_ciphers accept NULL as char
*cipher_list.

This adds some ifs to check for NULL in tls_ctx_restrict_ciphers() to prepare for disabling export ciphers by default in OpenVPN 2.4+.

---
 src/openvpn/ssl.c          | 5 +----
 src/openvpn/ssl_backend.h  | 5 +++--
 src/openvpn/ssl_openssl.c  | 7 +++++++
 src/openvpn/ssl_polarssl.c | 7 ++++++-
 4 files changed, 17 insertions(+), 7 deletions(-)
src/openvpn/ssl.c +1 -4
index bd19d75..93222c4 100644
@@ -543,10 +543,7 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
     }
 
   /* Allowable ciphers */
-  if (options->cipher_list)
-    {
-      tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
-    }
+  tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
 
 #ifdef ENABLE_CRYPTO_POLARSSL
   /* Personalise the random by mixing in the certificate */
src/openvpn/ssl_backend.h +3 -2
index 54383fe..a6fc3bd 100644
@@ -167,8 +167,9 @@ void tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags);
 /**
  * Restrict the list of ciphers that can be used within the TLS context.
  *
- * @param ctx		TLS context to restrict
- * @param ciphers	String containing : delimited cipher names.
+ * @param ctx		TLS context to restrict, must be valid.
+ * @param ciphers	String containing : delimited cipher names, or NULL to use
+ *					sane defaults.
  */
 void tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers);
 
src/openvpn/ssl_openssl.c +7 -0
index 08327a1..349c64e 100644
@@ -217,6 +217,13 @@ tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags)
 void
 tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
+  if (ciphers == NULL)
+    {
+      /* Nothing to do */
+      return;
+    }
+
+  /* Parse supplied cipher list and pass on to OpenSSL */
   size_t begin_of_cipher, end_of_cipher;
 
   const char *current_cipher;
src/openvpn/ssl_polarssl.c +6 -1
index 551c352..a517bf8 100644
@@ -173,7 +173,12 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
   char *tmp_ciphers, *tmp_ciphers_orig, *token;
   int i, cipher_count;
-  int ciphers_len = strlen (ciphers);
+  int ciphers_len;
+
+  if (NULL == ciphers)
+    return; /* Nothing to do */
+
+  ciphers_len = strlen (ciphers);
 
   ASSERT (NULL != ctx);
   ASSERT (0 != ciphers_len);
Signature · 1 line
1.8.3.2
#18 lore raw

Re: [Openvpn-devel] [PATCH 5/6] Make tls_ctx_restrict_ciphers accept NULL as char *cipher_list.

Hi,

Attached a v3 of the patch. This one also makes sure tls_ctx_restrict_ciphers is always called, to prepare for the defaults settings of 6/6 to always apply. In the previous version of the patch --show-tls would ignore the default settings.

-Steffan

Quoted 219 lines · Steffan Karger

Hi,

Attached a v2 of the patch below, that removes the else to make the diff a lot smaller and changes a //-style comment to /* */-style.

-Steffan

Quoted 211 lines · Steffan Karger

This diff look like a lot has changed, but this just adds some ifs to check for NULL in tls_ctx_restrict_ciphers() to prepare for disabling export ciphers by default in OpenVPN 2.4+.

---
 src/openvpn/ssl.c          |   5 +-
 src/openvpn/ssl_backend.h  |   5 +-
 src/openvpn/ssl_openssl.c  | 130 ++++++++++++++++++++++++++-------------------
 src/openvpn/ssl_polarssl.c |   7 ++-
 4 files changed, 85 insertions(+), 62 deletions(-)
src/openvpn/ssl.c +1 -4
index bd19d75..93222c4 100644
@@ -543,10 +543,7 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
     }
 
   /* Allowable ciphers */
-  if (options->cipher_list)
-    {
-      tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
-    }
+  tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
 
 #ifdef ENABLE_CRYPTO_POLARSSL
   /* Personalise the random by mixing in the certificate */
src/openvpn/ssl_backend.h +3 -2
index 54383fe..a6fc3bd 100644
@@ -167,8 +167,9 @@ void tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags);
 /**
  * Restrict the list of ciphers that can be used within the TLS context.
  *
- * @param ctx		TLS context to restrict
- * @param ciphers	String containing : delimited cipher names.
+ * @param ctx		TLS context to restrict, must be valid.
+ * @param ciphers	String containing : delimited cipher names, or NULL to use
+ *					sane defaults.
  */
 void tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers);
 
src/openvpn/ssl_openssl.c +75 -55
index 08327a1..5f6c270 100644
@@ -217,71 +217,91 @@ tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags)
 void
 tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
-  size_t begin_of_cipher, end_of_cipher;
-
-  const char *current_cipher;
-  size_t current_cipher_len;
+  if (ciphers == NULL)
+    {
+      /* Nothing to do */
+      return;
+    }
+  else
+    {
+      /* Parse supplied cipher list and pass on to OpenSSL */
+      size_t begin_of_cipher, end_of_cipher;
 
-  const tls_cipher_name_pair *cipher_pair;
+      const char *current_cipher;
+      size_t current_cipher_len;
 
-  char openssl_ciphers[4096];
-  size_t openssl_ciphers_len = 0;
-  openssl_ciphers[0] = '\0';
+      const tls_cipher_name_pair *cipher_pair;
 
-  ASSERT(NULL != ctx);
+      char openssl_ciphers[4096];
+      size_t openssl_ciphers_len = 0;
+      openssl_ciphers[0] = '\0';
 
-  // Translate IANA cipher suite names to OpenSSL names
-  begin_of_cipher = end_of_cipher = 0;
-  for (; begin_of_cipher < strlen(ciphers); begin_of_cipher = end_of_cipher) {
-      end_of_cipher += strcspn(&ciphers[begin_of_cipher], ":");
-      cipher_pair = tls_get_cipher_name_pair(&ciphers[begin_of_cipher], end_of_cipher - begin_of_cipher);
+      ASSERT(NULL != ctx);
 
-      if (NULL == cipher_pair)
+      // Translate IANA cipher suite names to OpenSSL names
+      begin_of_cipher = end_of_cipher = 0;
+      for (; begin_of_cipher < strlen(ciphers); begin_of_cipher = end_of_cipher)
         {
-          // No translation found, use original
-          current_cipher = &ciphers[begin_of_cipher];
-          current_cipher_len = end_of_cipher - begin_of_cipher;
-
-          // Issue warning on missing translation
-          // %.*s format specifier expects length of type int, so guarantee
-          // that length is small enough and cast to int.
-          msg (M_WARN, "No valid translation found for TLS cipher '%.*s'",
-                 constrain_int(current_cipher_len, 0, 256), current_cipher);
-        }
-      else
-	{
-	  // Use OpenSSL name
-          current_cipher = cipher_pair->openssl_name;
-          current_cipher_len = strlen(current_cipher);
-
-	  if (end_of_cipher - begin_of_cipher == current_cipher_len &&
-	      0 == memcmp (&ciphers[begin_of_cipher], cipher_pair->openssl_name, end_of_cipher - begin_of_cipher))
-	    {
-	      // Non-IANA name used, show warning
-	      msg (M_WARN, "Deprecated TLS cipher name '%s', please use IANA name '%s'", cipher_pair->openssl_name, cipher_pair->iana_name);
-	    }
-	}
-
-      // Make sure new cipher name fits in cipher string
-      if (((sizeof(openssl_ciphers)-1) - openssl_ciphers_len) < current_cipher_len) {
-	msg(M_SSLERR, "Failed to set restricted TLS cipher list, too long (>%d).", (int)sizeof(openssl_ciphers)-1);
-      }
+          end_of_cipher += strcspn(&ciphers[begin_of_cipher], ":");
+          cipher_pair = tls_get_cipher_name_pair(&ciphers[begin_of_cipher],
+              end_of_cipher - begin_of_cipher);
 
-      // Concatenate cipher name to OpenSSL cipher string
-      memcpy(&openssl_ciphers[openssl_ciphers_len], current_cipher, current_cipher_len);
-      openssl_ciphers_len += current_cipher_len;
-      openssl_ciphers[openssl_ciphers_len] = ':';
-      openssl_ciphers_len++;
+          if (NULL == cipher_pair)
+            {
+              // No translation found, use original
+              current_cipher = &ciphers[begin_of_cipher];
+              current_cipher_len = end_of_cipher - begin_of_cipher;
+
+              // Issue warning on missing translation
+              // %.*s format specifier expects length of type int, so guarantee
+              // that length is small enough and cast to int.
+              msg (M_WARN, "No valid translation found for TLS cipher '%.*s'",
+                     constrain_int(current_cipher_len, 0, 256), current_cipher);
+            }
+          else
+            {
+              // Use OpenSSL name
+              current_cipher = cipher_pair->openssl_name;
+              current_cipher_len = strlen(current_cipher);
+
+              if (end_of_cipher - begin_of_cipher == current_cipher_len &&
+                  0 == memcmp (&ciphers[begin_of_cipher],
+                      cipher_pair->openssl_name,
+                      end_of_cipher - begin_of_cipher))
+                {
+                  // Non-IANA name used, show warning
+                  msg (M_WARN, "Deprecated TLS cipher name '%s', "
+                      "please use IANA name '%s'", cipher_pair->openssl_name,
+                      cipher_pair->iana_name);
+                }
+            }
 
-      end_of_cipher++;
-  }
+          // Make sure new cipher name fits in cipher string
+          if (((sizeof(openssl_ciphers)-1) - openssl_ciphers_len) <
+              current_cipher_len) {
+            msg(M_SSLERR,
+                "Failed to set restricted TLS cipher list, too long (>%d).",
+                (int)sizeof(openssl_ciphers)-1);
+          }
+
+          // Concatenate cipher name to OpenSSL cipher string
+          memcpy(&openssl_ciphers[openssl_ciphers_len], current_cipher,
+              current_cipher_len);
+          openssl_ciphers_len += current_cipher_len;
+          openssl_ciphers[openssl_ciphers_len] = ':';
+          openssl_ciphers_len++;
+
+          end_of_cipher++;
+        }
 
-  if (openssl_ciphers_len > 0)
-    openssl_ciphers[openssl_ciphers_len-1] = '\0';
+      if (openssl_ciphers_len > 0)
+        openssl_ciphers[openssl_ciphers_len-1] = '\0';
 
-  // Set OpenSSL cipher list
-  if(!SSL_CTX_set_cipher_list(ctx->ctx, openssl_ciphers))
-    msg(M_SSLERR, "Failed to set restricted TLS cipher list: %s", openssl_ciphers);
+      // Set OpenSSL cipher list
+      if(!SSL_CTX_set_cipher_list(ctx->ctx, openssl_ciphers))
+        msg(M_SSLERR, "Failed to set restricted TLS cipher list: %s",
+            openssl_ciphers);
+    }
 }
 
 void
src/openvpn/ssl_polarssl.c +6 -1
index 551c352..d964b91 100644
@@ -173,7 +173,12 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
   char *tmp_ciphers, *tmp_ciphers_orig, *token;
   int i, cipher_count;
-  int ciphers_len = strlen (ciphers);
+  int ciphers_len;
+
+  if (NULL == ciphers)
+    return; // Nothing to do
+
+  ciphers_len = strlen (ciphers);
 
Quoted 3 lines

src/openvpn/ssl_polarssl.c tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers) · line 184

Quoted 3 lines
src/openvpn/ssl_polarssl.c +0 -0
   ASSERT (NULL != ctx);
   ASSERT (0 != ciphers_len);

From 8fe4c2668aac6f69374682af2eb1579e100f2978 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Fri, 3 Jan 2014 21:03:02 +0100
Subject: [PATCH 1/2] Make tls_ctx_restrict_ciphers accept NULL as char
*cipher_list.

This adds some ifs to check for NULL in tls_ctx_restrict_ciphers() to prepare for disabling export ciphers by default in OpenVPN 2.4+.

Also let tls_ctx_restrict_ciphers always be called, also when *cipher_list is NULL.

---
 src/openvpn/ssl.c          |  5 +----
 src/openvpn/ssl_backend.h  |  5 +++--
 src/openvpn/ssl_openssl.c  | 10 ++++++++--
 src/openvpn/ssl_polarssl.c | 16 ++++++++++++----
 4 files changed, 24 insertions(+), 12 deletions(-)
src/openvpn/ssl.c +1 -4
index bd19d75..93222c4 100644
@@ -543,10 +543,7 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
     }
 
   /* Allowable ciphers */
-  if (options->cipher_list)
-    {
-      tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
-    }
+  tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
 
 #ifdef ENABLE_CRYPTO_POLARSSL
   /* Personalise the random by mixing in the certificate */
src/openvpn/ssl_backend.h +3 -2
index 54383fe..a6fc3bd 100644
@@ -167,8 +167,9 @@ void tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags);
 /**
  * Restrict the list of ciphers that can be used within the TLS context.
  *
- * @param ctx		TLS context to restrict
- * @param ciphers	String containing : delimited cipher names.
+ * @param ctx		TLS context to restrict, must be valid.
+ * @param ciphers	String containing : delimited cipher names, or NULL to use
+ *					sane defaults.
  */
 void tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers);
 
src/openvpn/ssl_openssl.c +8 -2
index 08327a1..7ad7eab 100644
@@ -217,6 +217,13 @@ tls_ctx_set_options (struct tls_root_ctx *ctx, unsigned int ssl_flags)
 void
 tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
+  if (ciphers == NULL)
+    {
+      /* Nothing to do */
+      return;
+    }
+
+  /* Parse supplied cipher list and pass on to OpenSSL */
   size_t begin_of_cipher, end_of_cipher;
 
   const char *current_cipher;
@@ -1272,8 +1279,7 @@ show_available_tls_ciphers (const char *cipher_list)
   if (!ssl)
     msg (M_SSLERR, "Cannot create SSL object");
 
-  if (cipher_list)
-    tls_ctx_restrict_ciphers(&tls_ctx, cipher_list);
+  tls_ctx_restrict_ciphers(&tls_ctx, cipher_list);
 
   printf ("Available TLS Ciphers,\n");
   printf ("listed in order of preference:\n\n");
src/openvpn/ssl_polarssl.c +12 -4
index 551c352..47fb62a 100644
@@ -173,7 +173,12 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
   char *tmp_ciphers, *tmp_ciphers_orig, *token;
   int i, cipher_count;
-  int ciphers_len = strlen (ciphers);
+  int ciphers_len;
+
+  if (NULL == ciphers)
+    return; /* Nothing to do */
+
+  ciphers_len = strlen (ciphers);
 
   ASSERT (NULL != ctx);
   ASSERT (0 != ciphers_len);
@@ -1038,10 +1043,11 @@ show_available_tls_ciphers (const char *cipher_list)
   struct tls_root_ctx tls_ctx;
   const int *ciphers = ssl_list_ciphersuites();
 
-  if (cipher_list) {
-    tls_ctx_restrict_ciphers(&tls_ctx, cipher_list);
+  tls_ctx_server_new(&tls_ctx);
+  tls_ctx_restrict_ciphers(&tls_ctx, cipher_list);
+
+  if (tls_ctx.allowed_ciphers)
     ciphers = tls_ctx.allowed_ciphers;
-  }
 
 #ifndef ENABLE_SMALL
   printf ("Available TLS Ciphers,\n");
@@ -1054,6 +1060,8 @@ show_available_tls_ciphers (const char *cipher_list)
       ciphers++;
     }
   printf ("\n");
+
+  tls_ctx_free(&tls_ctx);
 }
 
 void
Signature · 1 line
1.8.3.2
#19 lore raw

[Openvpn-devel] [PATCH applied] Re: Make tls_ctx_restrict_ciphers accept NULL as char *cipher_list.

ACK.

Your patch has been applied to the master branch.

commit e83313a8ba92684a660c9d78c536699f67dcdf63

Author: Steffan Karger
Date:   Fri Jan 3 21:03:02 2014 +0100
     Make tls_ctx_restrict_ciphers accept NULL as char *cipher_list.

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8173
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#20 lore raw

PATCH 6/6 Disable export ciphers by default for OpenSSL builds.

In reply to Steffan Karger

Export ciphers are deliberately weak ciphers, and not fully supported by OpenVPN since ephemeral RSA support has been removed a few commits ago. This commit removes them from the default cipher list to avoid confusion.

PolarSSL does not support export ciphers, so no action required there.

---
 src/openvpn/ssl_openssl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/ssl_openssl.c +3 -1
index 5f6c270..9dced72 100644
@@ -219,7 +219,9 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
 {
   if (ciphers == NULL)
     {
-      /* Nothing to do */
+      /* Use sane default */
+      if(!SSL_CTX_set_cipher_list(ctx->ctx, "DEFAULT:!EXP"))
+        msg(M_SSLERR, "Failed to set default TLS cipher list.");
       return;
     }
   else
Signature · 1 line
1.8.3.2
#21 lore raw

Re: [Openvpn-devel] [PATCH 6/6] Disable export ciphers by default for OpenSSL builds.

Am 01.01.14 21:10, schrieb Steffan Karger:

Quoted 6 lines

Export ciphers are deliberately weak ciphers, and not fully supported by OpenVPN since ephemeral RSA support has been removed a few commits ago. This commit removes them from the default cipher list to avoid confusion.

PolarSSL does not support export ciphers, so no action required there.

ACK. But isn't is better to use good to do the !EXP just in case and for consistency for PolarSSL as well.

Arne

#22 lore raw

Re: [Openvpn-devel] [PATCH 6/6] Disable export ciphers by default for OpenSSL builds.

Quoted 2 lines · Arne Schwabe

ACK. But isn't is better to use good to do the !EXP just in case and for consistency for PolarSSL as well.

I agree that would be nice for consistency, but since PolarSSL supports neither export ciphers nor the 'DEFAULT'/'EXP'/etc cipher-suite group names that's not possible.

-Steffan

#23 lore raw

[Openvpn-devel] [PATCH applied] Re: Disable export ciphers by default for OpenSSL builds.

In reply to Steffan Karger

ACK.

Your patch has been applied to the master branch.

commit 56ab21091c0f1e07d0a6ef7815160f6ae072498d

Author: Steffan Karger
Date:   Wed Jan 1 21:10:26 2014 +0100
     Disable export ciphers by default for OpenSSL builds.

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8146
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#24 lore raw
In reply to Steffan Karger

Am 15.12.13 19:34, schrieb Steffan Karger:

Quoted 7 lines

Hi,

Attached a patch that should close issue #197. This patch moves from using the deprecated RSA_generate_key() to the 'new' RSA_generate_key_ex() to generate ephemeral RSA keys. This patch does not change OpenVPN's behaviour.

Quoted 6 lines

One note on the implementation though; the code generates one ephemeral RSA key that is used during the entire lifetime of an OpenVPN process. If OpenSSL requests a new (ephemeral) key, it will keep on returning the same (usually rather small) key. Not the best solution.

ACK from me. This is code is *very* similar to the actual RSA_generate_key key function which is also a compatbility layer around RSA_generate_key_ex. I used to include a copy of RSA_generate_key in the Android openvpn version since Android's openssl library is build without depracted interfaces.

Arne

#25 lore raw
In reply to Steffan Karger

Your patch has been applied to the release/2.3 branch.

commit 8c5c58742c72fd20febace14047fbb0f54c2c421

Author: Steffan Karger
Date:   Sun Dec 15 19:34:27 2013 +0100
     Use RSA_generate_key_ex() instead of deprecated, RSA_generate_key()

     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/8110
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering