Skip to contentSkip to conversation

ECDH support

Openvpn-devel pietrek -- 5 participants 22 messages Feb 18, 2014 – Mar 4, 2014

lore
Share & tools
lore

pietrek --

author
#0 lore raw

Hi all,
It's my first contribution, so I could make some mistakes ;)
In attached patch I added ECDH support to openvpn with openssl.
Eliptic Curves generation is, in contrast to Diffie-Hellman very fast, so I do it on every server initialization.
Piotr Jarosz

src/openvpn/options.c +12 -2
index 9e21d5a..c8581e3 100644
@@ -578,6 +578,7 @@ static const char usage_message[] =
   "--dh file       : File containing Diffie Hellman parameters\n"
   "                  in .pem format (for --tls-server only).\n"
   "                  Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
+  "--ecdh curve    : Eliptic curve ECDH parameters\n"
   "--cert file     : Local certificate in .pem format -- must be signed\n"
   "                  by a Certificate Authority in --ca file.\n"
   "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
@@ -1607,6 +1608,7 @@ show_settings (const struct options *o)
   SHOW_STR (ca_file);
   SHOW_STR (ca_path);
   SHOW_STR (dh_file);
+  SHOW_STR (ecdh_curve);
   SHOW_STR (cert_file);
 
 #ifdef MANAGMENT_EXTERNAL_KEY
@@ -2176,7 +2178,8 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
 
   if (options->tls_server)
     {
-      notnull (options->dh_file, "DH file (--dh)");
+      if ( !options->dh_file && !options->ecdh_curve  )
+             msg(M_USAGE, "You must specify DH file (--dh) or ECDH curve name( --ecdh )");
     }
   if (options->tls_server || options->tls_client)
     {
@@ -2308,6 +2311,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
       MUST_BE_UNDEF (ca_file);
       MUST_BE_UNDEF (ca_path);
       MUST_BE_UNDEF (dh_file);
+      MUST_BE_UNDEF (ecdh_curve);
       MUST_BE_UNDEF (cert_file);
       MUST_BE_UNDEF (priv_key_file);
 #ifndef ENABLE_CRYPTO_POLARSSL
@@ -2702,7 +2706,8 @@ options_postprocess_filechecks (struct options *options)
 
   /* ** SSL/TLS/crypto related files ** */
 #ifdef ENABLE_SSL
-  errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
+  if ( options->dh_file )
+      errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->ca_file, R_OK, "--ca");
   errs |= check_file_access_chroot (options->chroot_dir, CHKACC_FILE, options->ca_path, R_OK, "--capath");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->cert_file, R_OK, "--cert");
@@ -6530,6 +6535,11 @@ add_option (struct options *options,
 	  options->dh_file_inline = p[2];
 	}
     }
+  else if (streq (p[0], "ecdh") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->ecdh_curve = p[1];
+    }
   else if (streq (p[0], "cert") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
src/openvpn/options.h +1 -0
index bf232f4..abf6971 100644
@@ -508,6 +508,7 @@ struct options
   const char *ca_file;
   const char *ca_path;
   const char *dh_file;
+  const char *ecdh_curve;
   const char *cert_file;
   const char *extra_certs_file;
   const char *priv_key_file;
src/openvpn/ssl.c +4 -1
index c61701a..3a84428 100644
@@ -474,7 +474,10 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
   if (options->tls_server)
     {
       tls_ctx_server_new(new_ctx);
-      tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+      if ( options->dh_file )
+          tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+         else
+          tls_ctx_load_ecdh_params(new_ctx, options->ecdh_curve );
     }
   else				/* if client */
     {
src/openvpn/ssl_backend.h +9 -0
index a6fc3bd..37e811a 100644
@@ -186,6 +186,15 @@ void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,
     const char *dh_file_inline);
 
 /**
+ * Generate ECDH Parameters, and load them into the library-specific
+ * TLS context.
+ *
+ * @param ctx           TLS context to use
+ * @param dh_curve      Eliptic Curve name
+ */
+void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *ecdh_curve );
+
+/**
  * Load PKCS #12 file for key, cert and (optionally) CA certs, and add to
  * library-specific TLS context.
  *
src/openvpn/ssl_openssl.c +20 -0
index f079652..4381a99 100644
@@ -329,6 +329,26 @@ tls_ctx_load_dh_params (struct tls_root_ctx *ctx, const char *dh_file,
   DH_free (dh);
 }
 
+void
+tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *ecdh_curve )
+{
+  EC_KEY *ecdh;
+  
+  int nid = OBJ_sn2nid( ecdh_curve );
+  if ( nid == NID_undef )
+      msg (M_SSLERR, "Invalid ECDH curve name '%s'", ecdh_curve );
+  
+  /* generate EC parameters */
+  ecdh = EC_KEY_new_by_curve_name( nid );
+  if ( !ecdh )
+     msg (M_SSLERR, "Cannot create ECDH params of curve %s", ecdh_curve );
+  
+  msg (D_TLS_DEBUG_LOW, "ECDH params of curve %s initialized", ecdh_curve );
+  
+  if ( !SSL_CTX_set_tmp_ecdh(ctx->ctx,ecdh) )
+      msg (M_SSLERR, "SSL_CTX_set_tmp_ecdh");
+}
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
     const char *pkcs12_file_inline,
#1 lore raw

Hi Piotr,

Quoted 1 line · pietrek --

It's my first contribution, so I could make some mistakes ;)

Thank you!

Quoted 3 lines

In attached patch I added ECDH support to openvpn with openssl. Eliptic Curves generation is, in contrast to Diffie-Hellman very fast, so I do it on every server initialization.

Nice to see someone is willing to touch the crypto parts of OpenVPN! I've been hacking on ECDH support myself too, based on a patch of Jan Just Keijser of about a your ago. I've pushed my work to a public branch on github:
https://github.com/syzzer/openvpn/commits/ecdh-squashed

I haven't sent this to the mailing list yet, because some of the ECDH/ECDSA cipher modes didn't work and I wanted to investigate further, but then life got in the way.

Right now I'm a bit in a hurry, but I'll definitely take a better look at your patches later. Let's see if we can get all the EC stuff working!

Regards,
-Steffan

#2 lore raw
In reply to pietrek --

Hiya,

Quoted 4 lines · pietrek --

It's my first contribution, so I could make some mistakes ;) In attached patch I added ECDH support to openvpn with openssl. Eliptic Curves generation is, in contrast to Diffie-Hellman very fast, so I do it on every server initialization.

Could you describe in a bit more detail what your patch does? I don't really understand the openssl innards well enough, but am curious.

*If* I understand it correctly, what it does is provide keying material (ECDH) to support EC for the TLS handshake, right? And there isn't actually anything in OpenVPN needed (besides provide keying material) as that's all "inside OpenSSL".

So how do you create the key material?

Which parts of the key handshake does it cover? Signature/Certificates, or *only* DH?

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]...
author
#3 lore raw

Hi,

Quoted 7 lines

Could you describe in a bit more detail what your patch does? I don't really understand the openssl innards well enough, but am curious.

*If* I understand it correctly, what it does is provide keying material (ECDH) to support EC for the TLS handshake, right? And there isn't actually anything in OpenVPN needed (besides provide keying material) as that's all "inside OpenSSL".

Yes, openssl does everything for us. I just added option to config.

Quoted 1 line

So how do you create the key material?

I used function EC_KEY_new_by_curve_name to generate eliptic curve parameters of type specyfied in config file.

Quoted 2 lines

Which parts of the key handshake does it cover? Signature/Certificates, or *only* DH?

Handshake only, EC certificates worked for me without doing anything. Also, DH didn't work with EC certificates( no such cipher ).

Piotr Jarosz

#4 lore raw

Hi,

Quoted 4 lines · pietrek --
Quoted 2 lines

Which parts of the key handshake does it cover? Signature/Certificates, or *only* DH?

Handshake only, EC certificates worked for me without doing anything. Also, DH didn't work with EC certificates( no such cipher ).

I see.

Seems what we need as well is a README file that explains about EC crypto, as in

- how do I generate and use an EC certificate?
- how do I use an EC curve for DH?
- how do I use EC for session keying?

because otherwise our users will be even more confused than I am.

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]...
author
#5 lore raw

Hi again,
I forget about freeing key after init.
I added a line with it to my patch.
Piotr Jarosz

src/openvpn/options.c +12 -2
index 9e21d5a..c8581e3 100644
@@ -578,6 +578,7 @@ static const char usage_message[] =
   "--dh file       : File containing Diffie Hellman parameters\n"
   "                  in .pem format (for --tls-server only).\n"
   "                  Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
+  "--ecdh curve    : Eliptic curve ECDH parameters\n"
   "--cert file     : Local certificate in .pem format -- must be signed\n"
   "                  by a Certificate Authority in --ca file.\n"
   "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
@@ -1607,6 +1608,7 @@ show_settings (const struct options *o)
   SHOW_STR (ca_file);
   SHOW_STR (ca_path);
   SHOW_STR (dh_file);
+  SHOW_STR (ecdh_curve);
   SHOW_STR (cert_file);
 
 #ifdef MANAGMENT_EXTERNAL_KEY
@@ -2176,7 +2178,8 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
 
   if (options->tls_server)
     {
-      notnull (options->dh_file, "DH file (--dh)");
+      if ( !options->dh_file && !options->ecdh_curve  )
+             msg(M_USAGE, "You must specify DH file (--dh) or ECDH curve name( --ecdh )");
     }
   if (options->tls_server || options->tls_client)
     {
@@ -2308,6 +2311,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
       MUST_BE_UNDEF (ca_file);
       MUST_BE_UNDEF (ca_path);
       MUST_BE_UNDEF (dh_file);
+      MUST_BE_UNDEF (ecdh_curve);
       MUST_BE_UNDEF (cert_file);
       MUST_BE_UNDEF (priv_key_file);
 #ifndef ENABLE_CRYPTO_POLARSSL
@@ -2702,7 +2706,8 @@ options_postprocess_filechecks (struct options *options)
 
   /* ** SSL/TLS/crypto related files ** */
 #ifdef ENABLE_SSL
-  errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
+  if ( options->dh_file )
+      errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->ca_file, R_OK, "--ca");
   errs |= check_file_access_chroot (options->chroot_dir, CHKACC_FILE, options->ca_path, R_OK, "--capath");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->cert_file, R_OK, "--cert");
@@ -6530,6 +6535,11 @@ add_option (struct options *options,
 	  options->dh_file_inline = p[2];
 	}
     }
+  else if (streq (p[0], "ecdh") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->ecdh_curve = p[1];
+    }
   else if (streq (p[0], "cert") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
src/openvpn/options.h +1 -0
index bf232f4..abf6971 100644
@@ -508,6 +508,7 @@ struct options
   const char *ca_file;
   const char *ca_path;
   const char *dh_file;
+  const char *ecdh_curve;
   const char *cert_file;
   const char *extra_certs_file;
   const char *priv_key_file;
src/openvpn/ssl.c +4 -1
index c61701a..3a84428 100644
@@ -474,7 +474,10 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
   if (options->tls_server)
     {
       tls_ctx_server_new(new_ctx);
-      tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+      if ( options->dh_file )
+          tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+         else
+          tls_ctx_load_ecdh_params(new_ctx, options->ecdh_curve );
     }
   else				/* if client */
     {
src/openvpn/ssl_backend.h +9 -0
index a6fc3bd..37e811a 100644
@@ -186,6 +186,15 @@ void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,
     const char *dh_file_inline);
 
 /**
+ * Generate ECDH Parameters, and load them into the library-specific
+ * TLS context.
+ *
+ * @param ctx           TLS context to use
+ * @param dh_curve      Eliptic Curve name
+ */
+void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *ecdh_curve );
+
+/**
  * Load PKCS #12 file for key, cert and (optionally) CA certs, and add to
  * library-specific TLS context.
  *
src/openvpn/ssl_openssl.c +22 -0
index f079652..7476430 100644
@@ -329,6 +329,28 @@ tls_ctx_load_dh_params (struct tls_root_ctx *ctx, const char *dh_file,
   DH_free (dh);
 }
 
+void
+tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *ecdh_curve )
+{
+  EC_KEY *ecdh;
+  
+  int nid = OBJ_sn2nid( ecdh_curve );
+  if ( nid == NID_undef )
+      msg (M_SSLERR, "Invalid ECDH curve name '%s'", ecdh_curve );
+  
+  /* generate EC parameters */
+  ecdh = EC_KEY_new_by_curve_name( nid );
+  if ( !ecdh )
+     msg (M_SSLERR, "Cannot create ECDH params of curve %s", ecdh_curve );
+  
+  msg (D_TLS_DEBUG_LOW, "ECDH params of curve %s initialized", ecdh_curve );
+  
+  if ( !SSL_CTX_set_tmp_ecdh(ctx->ctx,ecdh) )
+      msg (M_SSLERR, "SSL_CTX_set_tmp_ecdh");
+  
+  EC_KEY_free( ecdh );
+}
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
     const char *pkcs12_file_inline,
author
#6 lore raw
In reply to Gert Doering
Quoted 12 lines · Gert Doering

Hi,

Quoted 4 lines · pietrek --
Quoted 2 lines

Which parts of the key handshake does it cover? Signature/Certificates, or *only* DH?

Handshake only, EC certificates worked for me without doing anything. Also, DH didn't work with EC certificates( no such cipher ).

I see.

Seems what we need as well is a README file that explains about EC crypto, as in

Quoted 8 lines

- how do I generate and use an EC certificate?
- how do I use an EC curve for DH?
- how do I use EC for session keying?

because otherwise our users will be even more confused than I am.

gert

Hi Gert,
Usage of EC curves is very simple. You can use them for certificates as well as RSA, but are smaller and generate faster. Full list of curves you can get typing:
openssl ecparam -list_curves

Quoted 1 line

- how do I generate and use an EC certificate?

openssl ecparam -out ec.key -name sect571r1 -genkey
You can also extract public key:
openssl ec -in ec.key -pubout -out ec.pubkey
Now it ec.key can be used to generate certificate as well as RSA.

Quoted 1 line

- how do I use an EC curve for DH?

Simply add to openvpn server.conf line:
ecdh sect571r1
( I have created this option in my patch )

Quoted 1 line

- how do I use EC for session keying?

I've never seen eliptic curve as a key for session. We use them for key negotiation or in certificates.

Piotr Jarosz

author
#7 lore raw
In reply to Gert Doering
Quoted 12 lines · Gert Doering

Hi,

Quoted 4 lines · pietrek --
Quoted 2 lines

Which parts of the key handshake does it cover? Signature/Certificates, or *only* DH?

Handshake only, EC certificates worked for me without doing anything. Also, DH didn't work with EC certificates( no such cipher ).

I see.

Seems what we need as well is a README file that explains about EC crypto, as in

Quoted 8 lines

- how do I generate and use an EC certificate?
- how do I use an EC curve for DH?
- how do I use EC for session keying?

because otherwise our users will be even more confused than I am.

gert

Hi,
I added README.ec to my patch
Piotr Jarosz

README.ec +22 -0
index e69de29..a49a687 100644
@@ -0,0 +1,22 @@
+Now OpenVPN supports eliptic curves cryptography.
+It's advetages:
+ -very fast key generation
+ -smaller keys than using RSA
+ -wide range of curves you can use
+
+To support EC crypto OpenVPN uses openssl.
+You can get list of available curves typing:
+openssl ecparam -list_curves
+
+EC key generation is very easy:
+openssl ecparam -out ec.key -name curve_name -genkey
+You can also extract public key:
+openssl ec -in ec.key -pubout -out ec.pubkey
+You can use such key as well as RSA one in certificates generation.
+
+EC certificates don't work with DH.
+You have to use ECDH.
+Add to your OpenVPN server option:
+--ecdh curve_name
+
+
src/openvpn/options.c +12 -2
index 9e21d5a..c8581e3 100644
@@ -578,6 +578,7 @@ static const char usage_message[] =
   "--dh file       : File containing Diffie Hellman parameters\n"
   "                  in .pem format (for --tls-server only).\n"
   "                  Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
+  "--ecdh curve    : Eliptic curve ECDH parameters\n"
   "--cert file     : Local certificate in .pem format -- must be signed\n"
   "                  by a Certificate Authority in --ca file.\n"
   "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
@@ -1607,6 +1608,7 @@ show_settings (const struct options *o)
   SHOW_STR (ca_file);
   SHOW_STR (ca_path);
   SHOW_STR (dh_file);
+  SHOW_STR (ecdh_curve);
   SHOW_STR (cert_file);
 
 #ifdef MANAGMENT_EXTERNAL_KEY
@@ -2176,7 +2178,8 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
 
   if (options->tls_server)
     {
-      notnull (options->dh_file, "DH file (--dh)");
+      if ( !options->dh_file && !options->ecdh_curve  )
+             msg(M_USAGE, "You must specify DH file (--dh) or ECDH curve name( --ecdh )");
     }
   if (options->tls_server || options->tls_client)
     {
@@ -2308,6 +2311,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
       MUST_BE_UNDEF (ca_file);
       MUST_BE_UNDEF (ca_path);
       MUST_BE_UNDEF (dh_file);
+      MUST_BE_UNDEF (ecdh_curve);
       MUST_BE_UNDEF (cert_file);
       MUST_BE_UNDEF (priv_key_file);
 #ifndef ENABLE_CRYPTO_POLARSSL
@@ -2702,7 +2706,8 @@ options_postprocess_filechecks (struct options *options)
 
   /* ** SSL/TLS/crypto related files ** */
 #ifdef ENABLE_SSL
-  errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
+  if ( options->dh_file )
+      errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->ca_file, R_OK, "--ca");
   errs |= check_file_access_chroot (options->chroot_dir, CHKACC_FILE, options->ca_path, R_OK, "--capath");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->cert_file, R_OK, "--cert");
@@ -6530,6 +6535,11 @@ add_option (struct options *options,
 	  options->dh_file_inline = p[2];
 	}
     }
+  else if (streq (p[0], "ecdh") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->ecdh_curve = p[1];
+    }
   else if (streq (p[0], "cert") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
src/openvpn/options.h +1 -0
index bf232f4..abf6971 100644
@@ -508,6 +508,7 @@ struct options
   const char *ca_file;
   const char *ca_path;
   const char *dh_file;
+  const char *ecdh_curve;
   const char *cert_file;
   const char *extra_certs_file;
   const char *priv_key_file;
src/openvpn/ssl.c +4 -1
index c61701a..3a84428 100644
@@ -474,7 +474,10 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
   if (options->tls_server)
     {
       tls_ctx_server_new(new_ctx);
-      tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+      if ( options->dh_file )
+          tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+         else
+          tls_ctx_load_ecdh_params(new_ctx, options->ecdh_curve );
     }
   else				/* if client */
     {
src/openvpn/ssl_backend.h +9 -0
index a6fc3bd..37e811a 100644
@@ -186,6 +186,15 @@ void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,
     const char *dh_file_inline);
 
 /**
+ * Generate ECDH Parameters, and load them into the library-specific
+ * TLS context.
+ *
+ * @param ctx           TLS context to use
+ * @param dh_curve      Eliptic Curve name
+ */
+void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *ecdh_curve );
+
+/**
  * Load PKCS #12 file for key, cert and (optionally) CA certs, and add to
  * library-specific TLS context.
  *
src/openvpn/ssl_openssl.c +22 -0
index f079652..7476430 100644
@@ -329,6 +329,28 @@ tls_ctx_load_dh_params (struct tls_root_ctx *ctx, const char *dh_file,
   DH_free (dh);
 }
 
+void
+tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *ecdh_curve )
+{
+  EC_KEY *ecdh;
+  
+  int nid = OBJ_sn2nid( ecdh_curve );
+  if ( nid == NID_undef )
+      msg (M_SSLERR, "Invalid ECDH curve name '%s'", ecdh_curve );
+  
+  /* generate EC parameters */
+  ecdh = EC_KEY_new_by_curve_name( nid );
+  if ( !ecdh )
+     msg (M_SSLERR, "Cannot create ECDH params of curve %s", ecdh_curve );
+  
+  msg (D_TLS_DEBUG_LOW, "ECDH params of curve %s initialized", ecdh_curve );
+  
+  if ( !SSL_CTX_set_tmp_ecdh(ctx->ctx,ecdh) )
+      msg (M_SSLERR, "SSL_CTX_set_tmp_ecdh");
+  
+  EC_KEY_free( ecdh );
+}
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
     const char *pkcs12_file_inline,
#8 lore raw

Hi,

thanks for writing the patch.

I'd like to propose to add a comment to the readme regarding the use of ECDH instead of DH without using an EC certificate, because that currently is not mentioned in it.

Thanks,
M. Braun

Am 19.02.2014 14:21, schrieb pietrek --:

Quoted 42 lines · Gert Doering
Quoted 14 lines

Hi,

Quoted 5 lines · pietrek --
Quoted 3 lines

Which parts of the key handshake does it cover?
Signature/Certificates,
or *only* DH?

Handshake only, EC certificates worked for me without doing anything. Also, DH didn't work with EC certificates( no such cipher ).

I see.

Seems what we need as well is a README file that explains about EC crypto,
as in

Quoted 8 lines

- how do I generate and use an EC certificate?
- how do I use an EC curve for DH?
- how do I use EC for session keying?

because otherwise our users will be even more confused than I am.

gert

Hi,
I added README.ec to my patch
Piotr Jarosz

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

author
#9 lore raw
Quoted 55 lines · On 02/22/14 22:33, [email protected]... wrote:

Hi,

thanks for writing the patch.

I'd like to propose to add a comment to the readme regarding the use of ECDH instead of DH without using an EC certificate, because that currently is not mentioned in it.

Thanks,
M. Braun

Am 19.02.2014 14:21, schrieb pietrek --:

Quoted 37 lines · Gert Doering
Quoted 14 lines

Hi,

Quoted 5 lines · pietrek --
Quoted 3 lines

Which parts of the key handshake does it cover?
Signature/Certificates,
or *only* DH?

Handshake only, EC certificates worked for me without doing anything. Also, DH didn't work with EC certificates( no such cipher ).

I see.

Seems what we need as well is a README file that explains about EC crypto,
as in

Quoted 8 lines

- how do I generate and use an EC certificate?
- how do I use an EC curve for DH?
- how do I use EC for session keying?

because otherwise our users will be even more confused than I am.

gert

Hi,
I added README.ec to my patch
Piotr Jarosz

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk

Quoted 5 lines

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Quoted 9 lines

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Hi,
I added such a comment to the readme.
Piotr Jarosz

README.ec +24 -0
index e69de29..1ad16be 100644
@@ -0,0 +1,24 @@
+Now OpenVPN supports eliptic curves cryptography.
+It's advetages:
+ -very fast key generation
+ -smaller keys than using RSA
+ -wide range of curves you can use
+
+To support EC crypto OpenVPN uses openssl.
+You can get list of available curves typing:
+openssl ecparam -list_curves
+
+EC key generation is very easy:
+openssl ecparam -out ec.key -name curve_name -genkey
+You can also extract public key:
+openssl ec -in ec.key -pubout -out ec.pubkey
+You can use such key as well as RSA one in certificates generation.
+
+EC certificates don't work with DH.
+You have to use ECDH.
+Add to your OpenVPN server option:
+--ecdh curve_name
+
+You can also use ECDH with other types of certs.
+It's convenient because you don't have to generate any Diffie-Hellman file.
+
src/openvpn/options.c +12 -2
index 9e21d5a..c8581e3 100644
@@ -578,6 +578,7 @@ static const char usage_message[] =
   "--dh file       : File containing Diffie Hellman parameters\n"
   "                  in .pem format (for --tls-server only).\n"
   "                  Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
+  "--ecdh curve    : Eliptic curve ECDH parameters\n"
   "--cert file     : Local certificate in .pem format -- must be signed\n"
   "                  by a Certificate Authority in --ca file.\n"
   "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
@@ -1607,6 +1608,7 @@ show_settings (const struct options *o)
   SHOW_STR (ca_file);
   SHOW_STR (ca_path);
   SHOW_STR (dh_file);
+  SHOW_STR (ecdh_curve);
   SHOW_STR (cert_file);
 
 #ifdef MANAGMENT_EXTERNAL_KEY
@@ -2176,7 +2178,8 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
 
   if (options->tls_server)
     {
-      notnull (options->dh_file, "DH file (--dh)");
+      if ( !options->dh_file && !options->ecdh_curve  )
+             msg(M_USAGE, "You must specify DH file (--dh) or ECDH curve name( --ecdh )");
     }
   if (options->tls_server || options->tls_client)
     {
@@ -2308,6 +2311,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
       MUST_BE_UNDEF (ca_file);
       MUST_BE_UNDEF (ca_path);
       MUST_BE_UNDEF (dh_file);
+      MUST_BE_UNDEF (ecdh_curve);
       MUST_BE_UNDEF (cert_file);
       MUST_BE_UNDEF (priv_key_file);
 #ifndef ENABLE_CRYPTO_POLARSSL
@@ -2702,7 +2706,8 @@ options_postprocess_filechecks (struct options *options)
 
   /* ** SSL/TLS/crypto related files ** */
 #ifdef ENABLE_SSL
-  errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
+  if ( options->dh_file )
+      errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->ca_file, R_OK, "--ca");
   errs |= check_file_access_chroot (options->chroot_dir, CHKACC_FILE, options->ca_path, R_OK, "--capath");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->cert_file, R_OK, "--cert");
@@ -6530,6 +6535,11 @@ add_option (struct options *options,
 	  options->dh_file_inline = p[2];
 	}
     }
+  else if (streq (p[0], "ecdh") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->ecdh_curve = p[1];
+    }
   else if (streq (p[0], "cert") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
src/openvpn/options.h +1 -0
index bf232f4..abf6971 100644
@@ -508,6 +508,7 @@ struct options
   const char *ca_file;
   const char *ca_path;
   const char *dh_file;
+  const char *ecdh_curve;
   const char *cert_file;
   const char *extra_certs_file;
   const char *priv_key_file;
src/openvpn/ssl.c +4 -1
index c61701a..3a84428 100644
@@ -474,7 +474,10 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
   if (options->tls_server)
     {
       tls_ctx_server_new(new_ctx);
-      tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+      if ( options->dh_file )
+          tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+         else
+          tls_ctx_load_ecdh_params(new_ctx, options->ecdh_curve );
     }
   else				/* if client */
     {
src/openvpn/ssl_backend.h +9 -0
index a6fc3bd..37e811a 100644
@@ -186,6 +186,15 @@ void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,
     const char *dh_file_inline);
 
 /**
+ * Generate ECDH Parameters, and load them into the library-specific
+ * TLS context.
+ *
+ * @param ctx           TLS context to use
+ * @param dh_curve      Eliptic Curve name
+ */
+void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *ecdh_curve );
+
+/**
  * Load PKCS #12 file for key, cert and (optionally) CA certs, and add to
  * library-specific TLS context.
  *
src/openvpn/ssl_openssl.c +22 -0
index f079652..7476430 100644
@@ -329,6 +329,28 @@ tls_ctx_load_dh_params (struct tls_root_ctx *ctx, const char *dh_file,
   DH_free (dh);
 }
 
+void
+tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *ecdh_curve )
+{
+  EC_KEY *ecdh;
+  
+  int nid = OBJ_sn2nid( ecdh_curve );
+  if ( nid == NID_undef )
+      msg (M_SSLERR, "Invalid ECDH curve name '%s'", ecdh_curve );
+  
+  /* generate EC parameters */
+  ecdh = EC_KEY_new_by_curve_name( nid );
+  if ( !ecdh )
+     msg (M_SSLERR, "Cannot create ECDH params of curve %s", ecdh_curve );
+  
+  msg (D_TLS_DEBUG_LOW, "ECDH params of curve %s initialized", ecdh_curve );
+  
+  if ( !SSL_CTX_set_tmp_ecdh(ctx->ctx,ecdh) )
+      msg (M_SSLERR, "SSL_CTX_set_tmp_ecdh");
+  
+  EC_KEY_free( ecdh );
+}
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
     const char *pkcs12_file_inline,
src/openvpn/ssl_polarssl.c +6 -0
index 9dc4e87..a165fc1 100644
@@ -228,6 +228,12 @@ else
       (counter_type) 8 * mpi_size(&ctx->dhm_ctx->P));
 }
 
+void
+tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *ecdh_curve )
+{
+    msg( M_SSLERR, "ECDH is currently not suppored by polarssl" );
+}
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
     const char *pkcs12_file_inline,
#10 lore raw

Hi Piotr,

Quoted 1 line · pietrek --

I added such a comment to the readme.

First of all, thank you for writing the patch and responding to questions on the mailinglist! I've found a bit of time to look at your patch.

There are a couple things I would like to note:

1) This patch allows for not supplying a dh-file, also when no ecdh curve is specified. This makes it easier for users to end up with a less secure (TLS without (EC)DH) setup. I don't think that is a good idea.

2) When a curve is specified, the DH parameters will no longer be initialized. One could argue this is no longer needed when having ECDH, but when the other party does not support ECDH, this would cause OpenVPN to fall back to a non-DH, non-ECDH control channel; not good.

3) This implementation requires both endpoints user to specify the same curve to make it work. RFC 4492, 'ECC Cipher Suites for TLS', tells to use the same curve for ECDH as is used for ECDSA. The nice thing here is that a user does not need to specify the curve; it just works.

I wrote some code that does this already (the link I referred to in this threat earlier). As you have dug into the OpenSSL ECDH stuff too, could you please take a look at the ECDH-enabling code I wrote (also attached as patch files):
https://github.com/syzzer/openvpn/compare/OpenVPN:master...ecdh-squashed

It does the get-the-curve-from-the-private-key thing, and allows for simultaneous support of DH and ECDH. It also allows for the user-specified curve approach, and uses a sane default fallback when autodetection fails.

Once again, thank you for contributing. Your input is very welcome!

Regards,
-Steffan

From d9c2dfc272d8c9bf3a2e256655a72db19ee81cc9 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Thu, 16 Jan 2014 23:27:10 +0100
Subject: [PATCH 1/2] Add support for elliptic curve diffie-hellmann key
exchange (ECDH)

This patch is based on Jan Just Keijser's patch from Feb 7, 2012.

When OpenSSL 1.0.2 or newer is used, lets OpenSSL do the heavy lifting.

Otherwise, tries the following things (in order of preference):
* When supplied, use the ecdh curve specified by the user.
* Try to extract the curve from the private key, use the same curve.
* Fall back on secp384r1 curve.

Note that although the curve lookup succeeds, OpenSSL 1.0.0 and older do *not* support TLSv1.1 or TLSv1.2, which means no that no EC-crypto can be used.

This patch also bumps the minimum required OpenSSL version to 0.9.8, because older version do not have all the functions used and would require adding (more) #ifdefs.

---
 configure.ac               |   4 +-
 doc/openvpn.8              |  14 ++++++
 src/openvpn/init.c         |   4 +-
 src/openvpn/options.c      |  11 +++++
 src/openvpn/options.h      |   2 +
 src/openvpn/ssl.c          |   4 ++
 src/openvpn/ssl_backend.h  |  15 +++++++
 src/openvpn/ssl_openssl.c  | 105 +++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/ssl_polarssl.c |  13 ++++++
 9 files changed, 169 insertions(+), 3 deletions(-)
configure.ac +2 -2
index 380dcdb..4225343 100644
@@ -744,7 +744,7 @@ PKG_CHECK_MODULES(
 
 PKG_CHECK_MODULES(
 	[OPENSSL_CRYPTO],
-	[libcrypto >= 0.9.6],
+	[libcrypto >= 0.9.8],
 	[have_openssl_crypto="yes"],
 	[AC_CHECK_LIB(
 		[crypto],
@@ -758,7 +758,7 @@ PKG_CHECK_MODULES(
 
 PKG_CHECK_MODULES(
 	[OPENSSL_SSL],
-	[libssl >= 0.9.6],
+	[libssl >= 0.9.8],
 	[have_openssl_ssl="yes"],
 	[AC_CHECK_LIB(
 		[ssl],
doc/openvpn.8 +14 -0
index d01c935..ce8d09c 100644
@@ -4240,6 +4240,13 @@ included with the OpenVPN distribution.  Diffie Hellman parameters
 may be considered public.
 .\"*********************************************************
 .TP
+.B \-\-ecdh-curve name
+Specify the curve to use for elliptic curve Diffie Hellman. Available
+curves can be listed with
+.B \-\-show-curves
+. The specified curve will only be used for ECDH TLS-ciphers.
+.\"*********************************************************
+.TP
 .B \-\-cert file
 Local peer's signed certificate in .pem format \-\- must be signed
 by a certificate authority whose certificate is in
@@ -5021,6 +5028,13 @@ lowest.
 Show currently available hardware-based crypto acceleration
 engines supported by the OpenSSL library.
 .\"*********************************************************
+.TP
+.B \-\-show-curves
+(Standalone)
+Show all available elliptic curves to use with the
+.B \-\-ecdh-curve
+option.
+.\"*********************************************************
 .SS Generate a random key:
 Used only for non-TLS static key encryption mode.
 .\"*********************************************************
src/openvpn/init.c +3 -1
index d324166..83d631e 100644
@@ -868,7 +868,7 @@ print_openssl_info (const struct options *options)
 #ifdef ENABLE_CRYPTO
   if (options->show_ciphers || options->show_digests || options->show_engines
 #ifdef ENABLE_SSL
-      || options->show_tls_ciphers
+      || options->show_tls_ciphers || options->show_curves
 #endif
     )
     {
@@ -881,6 +881,8 @@ print_openssl_info (const struct options *options)
 #ifdef ENABLE_SSL
       if (options->show_tls_ciphers)
 	show_available_tls_ciphers (options->cipher_list);
+      if (options->show_curves)
+	show_available_curves();
 #endif
       return true;
     }
src/openvpn/options.c +11 -0
index 9e21d5a..3335946 100644
@@ -862,6 +862,7 @@ init_options (struct options *o, const bool init_gc)
   o->renegotiate_seconds = 3600;
   o->handshake_window = 60;
   o->transition_window = 3600;
+  o->ecdh_curve = NULL;
 #ifdef ENABLE_X509ALTUSERNAME
   o->x509_username_field = X509_USERNAME_FIELD_DEFAULT;
 #endif
@@ -6495,6 +6496,16 @@ add_option (struct options *options,
       VERIFY_PERMISSION (OPT_P_GENERAL);
       options->show_tls_ciphers = true;
     }
+  else if (streq (p[0], "show-curves"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->show_curves = true;
+    }
+  else if (streq (p[0], "ecdh-curve") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_CRYPTO);
+      options->ecdh_curve= p[1];
+    }
   else if (streq (p[0], "tls-server"))
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
src/openvpn/options.h +2 -0
index bf232f4..b7f4230 100644
@@ -201,6 +201,7 @@ struct options
   bool show_engines;
 #ifdef ENABLE_SSL
   bool show_tls_ciphers;
+  bool show_curves;
 #endif
   bool genkey;
 #endif
@@ -513,6 +514,7 @@ struct options
   const char *priv_key_file;
   const char *pkcs12_file;
   const char *cipher_list;
+  const char *ecdh_curve;
   const char *tls_verify;
   int verify_x509_type;
   const char *verify_x509_name;
src/openvpn/ssl.c +4 -0
index c61701a..ef5f1df 100644
@@ -542,6 +542,10 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
       tls_ctx_load_extra_certs(new_ctx, options->extra_certs_file, options->extra_certs_file_inline);
     }
 
+  /* Once keys and cert are loaded, load ECDH parameters */
+  if (options->tls_server)
+    tls_ctx_load_ecdh_params(new_ctx, options->ecdh_curve);
+
   /* Allowable ciphers */
   tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
 
src/openvpn/ssl_backend.h +15 -0
index a6fc3bd..992d370 100644
@@ -186,6 +186,16 @@ void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,
     const char *dh_file_inline);
 
 /**
+ * Load Elliptic Curve Parameters, and load them into the library-specific
+ * TLS context.
+ *
+ * @param ctx          TLS context to use
+ * @param curve_name   The name of the elliptic curve to load.
+ */
+void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name
+    );
+
+/**
  * Load PKCS #12 file for key, cert and (optionally) CA certs, and add to
  * library-specific TLS context.
  *
@@ -461,6 +471,11 @@ void print_details (struct key_state_ssl * ks_ssl, const char *prefix);
 void show_available_tls_ciphers (const char *tls_ciphers);
 
 /*
+ * Show the available elliptic curves in the crypto library
+ */
+void show_available_curves (void);
+
+/*
  * The OpenSSL library has a notion of preference in TLS ciphers.  Higher
  * preference == more secure. Return the highest preference cipher.
  */
src/openvpn/ssl_openssl.c +105 -0

123 lines not on this page · raw message

src/openvpn/ssl_polarssl.c +13 -0
index 9dc4e87..69b356b 100644
@@ -228,6 +228,13 @@ else
       (counter_type) 8 * mpi_size(&ctx->dhm_ctx->P));
 }
 
+void
+tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx, const char *curve_name
+    )
+{
+    msg(M_WARN, "Elliptic Curves not yet supported by PolarSSL");
+}
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
     const char *pkcs12_file_inline,
@@ -1068,6 +1075,12 @@ show_available_tls_ciphers (const char *cipher_list)
 }
 
 void
+show_available_curves (void)
+{
+  printf("The PolarSSL build of OpenVPN does not support elliptic curves yet");
+}
+
+void
 get_highest_preference_tls_cipher (char *buf, int size)
 {
   const char *cipher_name;
Signature · 1 line
1.8.3.2

From 960f018a69fe087513a62ad55229abfd86b9c1c5 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Sun, 19 Jan 2014 18:34:38 +0100
Subject: [PATCH 2/2] Add an elliptic curve testing cert chain to the sample
keys

---
 sample/sample-keys/README        |  6 ++--
 sample/sample-keys/ec-ca.crt     | 13 +++++++++
 sample/sample-keys/ec-ca.key     |  6 ++++
 sample/sample-keys/ec-client.crt | 61 ++++++++++++++++++++++++++++++++++++++++
 sample/sample-keys/ec-client.key |  6 ++++
 sample/sample-keys/ec-server.crt | 61 ++++++++++++++++++++++++++++++++++++++++
 sample/sample-keys/ec-server.key |  6 ++++
 7 files changed, 156 insertions(+), 3 deletions(-)
 create mode 100644 sample/sample-keys/ec-ca.crt
 create mode 100644 sample/sample-keys/ec-ca.key
 create mode 100644 sample/sample-keys/ec-client.crt
 create mode 100644 sample/sample-keys/ec-client.key
 create mode 100644 sample/sample-keys/ec-server.crt
 create mode 100644 sample/sample-keys/ec-server.key
sample/sample-keys/README +3 -3
index 1cd473a..9f4f918 100644
@@ -1,7 +1,6 @@
-Sample RSA keys.
+Sample RSA and EC keys.
 
-See the examples section of the man page
-for usage examples.
+See the examples section of the man page for usage examples.
 
 NOTE: THESE KEYS ARE FOR TESTING PURPOSES ONLY.
       DON'T USE THEM FOR ANY REAL WORK BECAUSE
@@ -12,3 +11,4 @@ client.{crt,key} -- sample client key/cert
 server.{crt,key} -- sample server key/cert (nsCertType=server)
 pass.{crt,key}   -- sample client key/cert with password-encrypted key
                     password = "password"
+ec-*.{crt,key}   -- sample elliptic curve variants of the above
sample/sample-keys/ec-ca.crt new file +13 -0
new file mode 100644
index 0000000..e190801
@@ -0,0 +1,13 @@
+-----BEGIN CERTIFICATE-----
+MIIB4jCCAWmgAwIBAgIJALGEGB2g6cAXMAoGCCqGSM49BAMCMBUxEzARBgNVBAMT
+CkVDLVRlc3QgQ0EwHhcNMTQwMTE4MTYwMTUzWhcNMjQwMTE2MTYwMTUzWjAVMRMw
+EQYDVQQDEwpFQy1UZXN0IENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE2S4AZT7j
+ZlPG/CXpT12CzCNSySyKmJt+fWyW/wzbRulVJpGHXRHpZZj2VNOUE72kqGUeshh6
+Um1o7lHGDSAkHOJpeW5FtryiKhwFc+4dsOCLTNLVFXQsEtY3gY14Uquio4GEMIGB
+MB0GA1UdDgQWBBS0mkFcuCZ8SLWZRAD/8LpBQcgGPDBFBgNVHSMEPjA8gBS0mkFc
+uCZ8SLWZRAD/8LpBQcgGPKEZpBcwFTETMBEGA1UEAxMKRUMtVGVzdCBDQYIJALGE
+GB2g6cAXMAwGA1UdEwQFMAMBAf8wCwYDVR0PBAQDAgEGMAoGCCqGSM49BAMCA2cA
+MGQCMHWlVTi0xNZstR8ZNH+7z0WlyIXyZe23ne3EXkO0thZLdv86kpxFMPW/llB+
+RMRKuQIweN97n7FQy5DTenr91U98KDFJ5Av4mDFRL1mkXiu3W1//4XD8yEYDQTRz
+/GARuOLL
+-----END CERTIFICATE-----
sample/sample-keys/ec-ca.key new file +6 -0
new file mode 100644
index 0000000..51a72e1
@@ -0,0 +1,6 @@
+-----BEGIN PRIVATE KEY-----
+MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDASU6X/mh2m2PayviL3
+teoml5soyIUcZfwZpVn6oNtnrLcAbIRsAJbM4xyGVp77G/6hZANiAATZLgBlPuNm
+U8b8JelPXYLMI1LJLIqYm359bJb/DNtG6VUmkYddEellmPZU05QTvaSoZR6yGHpS
+bWjuUcYNICQc4ml5bkW2vKIqHAVz7h2w4ItM0tUVdCwS1jeBjXhSq6I=
+-----END PRIVATE KEY-----
sample/sample-keys/ec-client.crt new file +61 -0

61 lines not on this page · raw message

sample/sample-keys/ec-client.key new file +6 -0
new file mode 100644
index 0000000..60636ed
@@ -0,0 +1,6 @@
+-----BEGIN PRIVATE KEY-----
+MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDD9Agj8nr/8sIr0XHky
+mcn1oMb3vqOh2axFBaIvmOHYmqs11SIH1tKYelkNYy9zHTChZANiAARA2bmiRBsB
+OSwU7qpwazGYKETJYby3C7VTScLACkOwCFDNgC9dpInx/30RePUMsobiWfgXdhsi
+8iNn51WQ6s4KqtoF9IUZye2ubaOtVnr2M8bPu8c5+uTTZ9/wuEqIV5g=
+-----END PRIVATE KEY-----
sample/sample-keys/ec-server.crt new file +61 -0

61 lines not on this page · raw message

sample/sample-keys/ec-server.key new file +6 -0
new file mode 100644
index 0000000..bb3cdf1
@@ -0,0 +1,6 @@
+-----BEGIN PRIVATE KEY-----
+MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDD8bQlwrFrXHPmem0bt
+cBcU6nYfaZQbPdIDAB7edOOyevvzYH0qMtbaW95iSZLMRVWhZANiAAS9jDqvLi8u
+3s/SOY25phOWgG21su6XYjuiMjh3Hvsq74ZL0J5LVeCbB/lkL2unF/1l3VA/HPr6
+Lzkul9SG5U5a0lAL9NcIYmdTRGLjJfL6NoSHHQPj6Z3ZZlHdtMTbCwU=
+-----END PRIVATE KEY-----
Signature · 1 line
1.8.3.2
author
#11 lore raw

Hi Steffan,
I modified my patch again. And thanks for your code - it helped me.
1) In such case server will set ecdh=auto.

2)That's a good idea.
I added initializing both ECDH and DH on server side if they're specified in config.

3)It works for me without specifying anything on client side.
I can also specify different curve for ECDH than used in certificates without any errors.

I added warning if DH isn't specified - old client may not support ECDH.
Autodetecting ecdh is a good idea - I made option ecdh=auto.
Most of the curves secp, prime, sect work, but some of them ( eg. wap-wsg-idm-ecid-wtls10 ) cause ssl error 'no shared cipher'.

Working curves examples:
secp192k1
secp160k1
secp224k1
secp521r1
prime192v1
prime256v1
sect233k1
sect283r1
sect409r1
sect571k1

Failing examples:
prime239v1
sect113r1
secp128r2
c2pnb304w1

I also copied from your code option --show-curves, manual entries and EC curve autodetection.

Piotr Jarosz

Quoted 48 lines · Steffan Karger

Hi Piotr,

Quoted 1 line · pietrek --

I added such a comment to the readme.

First of all, thank you for writing the patch and responding to questions on the mailinglist! I've found a bit of time to look at your patch.

There are a couple things I would like to note:

1) This patch allows for not supplying a dh-file, also when no ecdh curve is specified. This makes it easier for users to end up with a less secure (TLS without (EC)DH) setup. I don't think that is a good idea.

2) When a curve is specified, the DH parameters will no longer be initialized. One could argue this is no longer needed when having ECDH, but when the other party does not support ECDH, this would cause OpenVPN to fall back to a non-DH, non-ECDH control channel; not good.

3) This implementation requires both endpoints user to specify the same curve to make it work. RFC 4492, 'ECC Cipher Suites for TLS', tells to use the same curve for ECDH as is used for ECDSA. The nice thing here is that a user does not need to specify the curve; it just works.

I wrote some code that does this already (the link I referred to in this threat earlier). As you have dug into the OpenSSL ECDH stuff too, could you please take a look at the ECDH-enabling code I wrote (also attached as patch files):
https://github.com/syzzer/openvpn/compare/OpenVPN:master...ecdh-squashed

It does the get-the-curve-from-the-private-key thing, and allows for simultaneous support of DH and ECDH. It also allows for the user-specified curve approach, and uses a sane default fallback when autodetection fails.

Once again, thank you for contributing. Your input is very welcome!

Regards,
-Steffan

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk

Quoted 4 lines

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

README.ec +36 -0
index e69de29..c76e0bd 100644
@@ -0,0 +1,36 @@
+Now OpenVPN supports eliptic curves cryptography.
+It's advetages:
+ -very fast key generation
+ -smaller keys than using RSA
+ -wide range of curves you can use
+
+To support EC crypto OpenVPN uses openssl.
+You can get list of available curves typing:
+openssl ecparam -list_curves
+
+EC key generation is very easy:
+openssl ecparam -out ec.key -name curve_name -genkey
+You can also extract public key:
+openssl ec -in ec.key -pubout -out ec.pubkey
+You can use such key as well as RSA one in certificates generation.
+
+EC certificates don't work with DH.
+You have to use ECDH.
+Add to your OpenVPN server option:
+--ecdh curve_name
+Currently some of the curves produce SSL error 'no shared cipher' during handshake.
+Some working curves:
+secp192k1
+secp160k1
+secp224k1
+secp521r1
+prime192v1
+prime256v1
+sect233k1
+sect283r1
+sect409r1
+sect571k1
+
+You can also use ECDH with other types of certs.
+It's convenient because you don't have to generate any Diffie-Hellman file.
+
configure.ac +2 -2
index 380dcdb..4225343 100644
@@ -744,7 +744,7 @@ PKG_CHECK_MODULES(
 
 PKG_CHECK_MODULES(
 	[OPENSSL_CRYPTO],
-	[libcrypto >= 0.9.6],
+	[libcrypto >= 0.9.8],
 	[have_openssl_crypto="yes"],
 	[AC_CHECK_LIB(
 		[crypto],
@@ -758,7 +758,7 @@ PKG_CHECK_MODULES(
 
 PKG_CHECK_MODULES(
 	[OPENSSL_SSL],
-	[libssl >= 0.9.6],
+	[libssl >= 0.9.8],
 	[have_openssl_ssl="yes"],
 	[AC_CHECK_LIB(
 		[ssl],
doc/openvpn.8 +29 -0
index d01c935..78b053f 100644
@@ -4240,6 +4240,28 @@ included with the OpenVPN distribution.  Diffie Hellman parameters
 may be considered public.
 .\"*********************************************************
 .TP
+.B \-\-ecdh curve_name
+Specify the curve to use for elliptic curve Diffie Hellman. Available
+curves can be listed with
+.B \-\-show-curves
+The specified curve will only be used for ECDH TLS-ciphers.
+Currently, most of the curves work, but some of them generate ssl error: 'no shared cipher'.
+If you see this, try using another curve.
+
+.B Some examples of working curves:
+
+secp192k1,
+secp160k1,
+secp224k1,
+secp521r1,
+prime192v1,
+prime256v1,
+sect233k1,
+sect283r1,
+sect409r1,
+sect571k1
+.\"*********************************************************
+.TP
 .B \-\-cert file
 Local peer's signed certificate in .pem format \-\- must be signed
 by a certificate authority whose certificate is in
@@ -5021,6 +5043,13 @@ lowest.
 Show currently available hardware-based crypto acceleration
 engines supported by the OpenSSL library.
 .\"*********************************************************
+.TP
+.B \-\-show-curves
+(Standalone)
+Show all available elliptic curves to use with the
+.B \-\-ecdh
+option.
+.\"*********************************************************
 .SS Generate a random key:
 Used only for non-TLS static key encryption mode.
 .\"*********************************************************
src/openvpn/init.c +3 -1
index d324166..d2a7770 100644
@@ -868,7 +868,7 @@ print_openssl_info (const struct options *options)
 #ifdef ENABLE_CRYPTO
   if (options->show_ciphers || options->show_digests || options->show_engines
 #ifdef ENABLE_SSL
-      || options->show_tls_ciphers
+      || options->show_tls_ciphers || options->show_curves
 #endif
     )
     {
@@ -881,6 +881,8 @@ print_openssl_info (const struct options *options)
 #ifdef ENABLE_SSL
       if (options->show_tls_ciphers)
 	show_available_tls_ciphers (options->cipher_list);
+    if (options->show_curves)
+       show_available_curves();
 #endif
       return true;
     }
src/openvpn/options.c +18 -5
index 9e21d5a..859712d 100644
@@ -578,6 +578,9 @@ static const char usage_message[] =
   "--dh file       : File containing Diffie Hellman parameters\n"
   "                  in .pem format (for --tls-server only).\n"
   "                  Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
+  "--ecdh curve    : Eliptic curve name for ECDH \n"
+  "--show-curves   : Show all available elliptic curves to use with the\n"
+  "                  --ecdh-curve option.\n"
   "--cert file     : Local certificate in .pem format -- must be signed\n"
   "                  by a Certificate Authority in --ca file.\n"
   "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
@@ -862,6 +865,7 @@ init_options (struct options *o, const bool init_gc)
   o->renegotiate_seconds = 3600;
   o->handshake_window = 60;
   o->transition_window = 3600;
+  o->ecdh_curve = NULL;
 #ifdef ENABLE_X509ALTUSERNAME
   o->x509_username_field = X509_USERNAME_FIELD_DEFAULT;
 #endif
@@ -1607,6 +1611,7 @@ show_settings (const struct options *o)
   SHOW_STR (ca_file);
   SHOW_STR (ca_path);
   SHOW_STR (dh_file);
+  SHOW_STR (ecdh_curve);
   SHOW_STR (cert_file);
 
 #ifdef MANAGMENT_EXTERNAL_KEY
@@ -2174,10 +2179,6 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
       (options->shared_secret_file != NULL) > 1)
     msg (M_USAGE, "specify only one of --tls-server, --tls-client, or --secret");
 
-  if (options->tls_server)
-    {
-      notnull (options->dh_file, "DH file (--dh)");
-    }
   if (options->tls_server || options->tls_client)
     {
 #ifdef ENABLE_PKCS11
@@ -2308,6 +2309,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne
       MUST_BE_UNDEF (ca_file);
       MUST_BE_UNDEF (ca_path);
       MUST_BE_UNDEF (dh_file);
+      MUST_BE_UNDEF (ecdh_curve);
       MUST_BE_UNDEF (cert_file);
       MUST_BE_UNDEF (priv_key_file);
 #ifndef ENABLE_CRYPTO_POLARSSL
@@ -2702,7 +2704,8 @@ options_postprocess_filechecks (struct options *options)
 
   /* ** SSL/TLS/crypto related files ** */
 #ifdef ENABLE_SSL
-  errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
+  if ( options->dh_file )
+      errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->dh_file, R_OK, "--dh");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->ca_file, R_OK, "--ca");
   errs |= check_file_access_chroot (options->chroot_dir, CHKACC_FILE, options->ca_path, R_OK, "--capath");
   errs |= check_file_access (CHKACC_FILE|CHKACC_INLINE, options->cert_file, R_OK, "--cert");
@@ -6530,6 +6533,16 @@ add_option (struct options *options,
 	  options->dh_file_inline = p[2];
 	}
     }
+   else if (streq (p[0], "show-curves"))
+     {
+       VERIFY_PERMISSION (OPT_P_GENERAL);
+       options->show_curves = true;
+     }
+  else if (streq (p[0], "ecdh"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->ecdh_curve = p[1];
+    }
   else if (streq (p[0], "cert") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
src/openvpn/options.h +2 -0
index bf232f4..eadc758 100644
@@ -201,6 +201,7 @@ struct options
   bool show_engines;
 #ifdef ENABLE_SSL
   bool show_tls_ciphers;
+  bool show_curves;
 #endif
   bool genkey;
 #endif
@@ -508,6 +509,7 @@ struct options
   const char *ca_file;
   const char *ca_path;
   const char *dh_file;
+  const char *ecdh_curve;
   const char *cert_file;
   const char *extra_certs_file;
   const char *priv_key_file;
src/openvpn/ssl.c +24 -1
index c61701a..3ff9712 100644
@@ -474,7 +474,6 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
   if (options->tls_server)
     {
       tls_ctx_server_new(new_ctx);
-      tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
     }
   else				/* if client */
     {
@@ -541,6 +540,30 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
     {
       tls_ctx_load_extra_certs(new_ctx, options->extra_certs_file, options->extra_certs_file_inline);
     }
+  
+  if ( options->tls_server )
+    {
+        bool has_dh = false;
+        
+        if ( options->dh_file || options->dh_file_inline )
+           {
+               tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+               has_dh = true;
+           } else
+             msg(M_WARN,"You didn't specify --dh. It may cause handshake without (EC)DH in communucation with older openVPN clients.");
+        
+        if ( options->ecdh_curve )
+           {
+               tls_ctx_load_ecdh_params(new_ctx, options->ecdh_curve );
+               has_dh = true;
+           }
+        
+        if ( !has_dh )
+           {
+               msg(M_WARN, "You didn't specify any DH. ecdh=auto will be used as default.");
+               tls_ctx_load_ecdh_params(new_ctx, "auto" );
+           }
+    }
 
   /* Allowable ciphers */
   tls_ctx_restrict_ciphers(new_ctx, options->cipher_list);
src/openvpn/ssl_backend.h +14 -0
index a6fc3bd..594a402 100644
@@ -186,6 +186,15 @@ void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,
     const char *dh_file_inline);
 
 /**
+ * Generate ECDH Parameters, and load them into the library-specific
+ * TLS context.
+ *
+ * @param ctx           TLS context to use
+ * @param ecdh_curve    Eliptic Curve name
+ */
+void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *ecdh_curve );
+
+/**
  * Load PKCS #12 file for key, cert and (optionally) CA certs, and add to
  * library-specific TLS context.
  *
@@ -461,6 +470,11 @@ void print_details (struct key_state_ssl * ks_ssl, const char *prefix);
 void show_available_tls_ciphers (const char *tls_ciphers);
 
 /*
+ * Show the available elliptic curves in the crypto library
+ */
+void show_available_curves (void);
+
+/*
  * The OpenSSL library has a notion of preference in TLS ciphers.  Higher
  * preference == more secure. Return the highest preference cipher.
  */
src/openvpn/ssl_openssl.c +104 -0

122 lines not on this page · raw message

src/openvpn/ssl_openssl.h +3 -0
index fc2052c..050a065 100644
@@ -32,6 +32,9 @@
 
 #include <openssl/ssl.h>
 
+/* default eliptic curve for ecdh */
+#define ECDH_CURVE_DEFAULT NID_secp384r1
+
 /**
  * Structure that wraps the TLS context. Contents differ depending on the
  * SSL library used.
src/openvpn/ssl_polarssl.c +12 -0
index 9dc4e87..d20485d 100644
@@ -228,6 +228,12 @@ else
       (counter_type) 8 * mpi_size(&ctx->dhm_ctx->P));
 }
 
+void
+tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *ecdh_curve )
+{
+    msg( M_SSLERR, "ECDH is currently not suppored by polarssl" );
+}
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
     const char *pkcs12_file_inline,
@@ -1068,6 +1074,12 @@ show_available_tls_ciphers (const char *cipher_list)
 }
 
 void
+show_available_curves (void)
+{
+  printf("The PolarSSL build of OpenVPN does not support elliptic curves yet");
+}
+
+void
 get_highest_preference_tls_cipher (char *buf, int size)
 {
   const char *cipher_name;
#12 lore raw

Hi Piotr,

Quoted 2 lines · pietrek --

Hi Steffan,
I modified my patch again. And thanks for your code - it helped me.

Good to hear it helped you. But your new patch basically is my code now, except that it accepts a configuration without a DH-file.

Quoted 4 lines

1) In such case server will set ecdh=auto.
2)That's a good idea.
I added initializing both ECDH and DH on server side if they're specified in config.

Good.

Quoted 3 lines

3)It works for me without specifying anything on client side. I can also specify different curve for ECDH than used in certificates without any errors.

You're completely right, sorry for putting you on this side track.

Quoted 2 lines

I added warning if DH isn't specified - old client may not support ECDH. Autodetecting ecdh is a good idea - I made option ecdh=auto.

On the long run I agree that a warning should suffice, but for now I would really like to stick with forcing the DH-file to be present. Lots of people using OpenVPN do not understand the crypto or configuration options properly, but do rely on it for secure communication. As long as EC-crypto is not common, I prefer to make sure OpenVPN can always fall back on DH.

Quoted 8 lines

Most of the curves secp, prime, sect work, but some of them ( eg. wap-wsg-idm-ecid-wtls10 ) cause ssl error 'no shared cipher'.

Working curves examples:
...

Failing examples:
...

Not all curves supported by OpenSSL are available for use in SSL/TLS, wap-wsg-idm-ecid-wtls10 sounds like a perfect example of that. Furthermore, the available curves depend on you version and configuration of OpenSSL.

One of the things I do not completely grasp yet is why some cipher suites succeed (e.g. TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA works for me), but some slightly different ones do not (e.g. TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384 and TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA do not work for me), even though all the primitives for those suites are available from the version of OpenSSL I'm using. Still, the behaviour is different for various OpenSSL versions. Have you stumbled across this already?

Quoted 2 lines

I also copied from your code option --show-curves, manual entries and EC curve autodetection.

Credits for those lines go to Jan Just actually. About the copying, wouldn't it make more sense if you'd review my implementation, instead of copying it? The bulk of it is my code now anyway.

Although there is apparently more work to do to get more cipher suites working, this does give us a start on working with EC-crypto. Maybe this part can go in (once ACK'ed) as 'the start of EC-support', so more people can help improve the code. Any other opinions on this?

Regards,
-Steffan

#13 lore raw

Hi,

Quoted 9 lines · Steffan Karger
Quoted 2 lines

I added warning if DH isn't specified - old client may not support ECDH. Autodetecting ecdh is a good idea - I made option ecdh=auto.

On the long run I agree that a warning should suffice, but for now I would really like to stick with forcing the DH-file to be present. Lots of people using OpenVPN do not understand the crypto or configuration options properly, but do rely on it for secure communication. As long as EC-crypto is not common, I prefer to make sure OpenVPN can always fall back on DH.

+1

[..]

Quoted 4 lines

Although there is apparently more work to do to get more cipher suites working, this does give us a start on working with EC-crypto. Maybe this part can go in (once ACK'ed) as 'the start of EC-support', so more people can help improve the code. Any other opinions on this?

- easy to understand and a bit more detailed README
- ACK from a "trusted contributor" (read: someone who has worked on the OpenVPN crypto code before and knows the pitfalls)

then I'm fine with it

- PolarSSL...?

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]...
#14 lore raw

Hi,

Quoted 11 lines · Gert Doering
Quoted 4 lines

Although there is apparently more work to do to get more cipher suites working, this does give us a start on working with EC-crypto. Maybe this part can go in (once ACK'ed) as 'the start of EC-support', so more people can help improve the code. Any other opinions on this?

- easy to understand and a bit more detailed README
- ACK from a "trusted contributor" (read: someone who has worked on the OpenVPN crypto code before and knows the pitfalls)

then I'm fine with it

As for the README part, I can probably cook up something 'tonight' (CEST). The ACK can obviously not come from me, but I'll try to make the patch as easy as possible to review.

- PolarSSL...?

ECDH and ECDSA will work upon upgrade to PolarSSL 1.3, for which I'll send patches soon.

-Steffan

#15 lore raw

Hi Steffan,

Quoted 19 lines · Steffan Karger

Hi,

Quoted 1 line · On Tue, Feb 25, 2014 at 9:22 AM, Gert Doering <[email protected]...…

Although there is apparently more work to do to get more cipher

suites
> working, this does give us a start on working with EC-crypto. Maybe this
> part can go in (once ACK'ed) as 'the start of EC-support', so more > people can help improve the code. Any other opinions on this?

- easy to understand and a bit more detailed README
- ACK from a "trusted contributor" (read: someone who has worked on the
OpenVPN crypto code before and knows the pitfalls)

then I'm fine with it

Quoted 7 lines

As for the README part, I can probably cook up something 'tonight' (CEST). The ACK can obviously not come from me, but I'll try to make the patch as easy as possible to review.

- PolarSSL...?

ECDH and ECDSA will work upon upgrade to PolarSSL 1.3, for which I'll send patches soon.

read up on the original ticket too:
https://forums.openvpn.net/topic8404-30.html

there's some useful commands/description in there on how to generate ECDSA certificates.

HTH,

JJK

#16 lore raw

Hi,

Quoted 5 lines · Jan Just Keijser

read up on the original ticket too:
https://forums.openvpn.net/topic8404-30.html

there's some useful commands/description in there on how to generate ECDSA certificates.

Thanks. I've added support for ECDSA to EasyRSA 3 a little while ago, so that should simplify the certificate generation a lot.

-Steffan

author
#17 lore raw
In reply to Steffan Karger

Hi,

I tested what would happen if any key exchange protocol will be specified. It works as I expected: connection failed with error: 'no such cipher'. So session cannot work without ECDH and DH.
Also, if OpenSSL would accept it, it would be an invitatation for men in the middle ;)

For clients without ECDH connection will just fail.

In my opinion forcing users to specify DH key isn no longer neccessary, because this file generates long and protection against men in the middle attack is as strong as the weakest encryption algorithm so if DH will be weaker than ECDH curve, even the best curve won't improve security against such attack.

Server should not fail if user won't specify DH nor ECDH - it just could fall back into ECDH.

Piotr Jarosz

Quoted 74 lines · Steffan Karger

Hi Piotr,

Quoted 2 lines · pietrek --

Hi Steffan,
I modified my patch again. And thanks for your code - it helped me.

Good to hear it helped you. But your new patch basically is my code now, except that it accepts a configuration without a DH-file.

Quoted 4 lines

1) In such case server will set ecdh=auto.
2)That's a good idea.
I added initializing both ECDH and DH on server side if they're specified in config.

Good.

Quoted 3 lines

3)It works for me without specifying anything on client side. I can also specify different curve for ECDH than used in certificates without any errors.

You're completely right, sorry for putting you on this side track.

Quoted 2 lines

I added warning if DH isn't specified - old client may not support ECDH. Autodetecting ecdh is a good idea - I made option ecdh=auto.

On the long run I agree that a warning should suffice, but for now I would really like to stick with forcing the DH-file to be present. Lots of people using OpenVPN do not understand the crypto or configuration options properly, but do rely on it for secure communication. As long as EC-crypto is not common, I prefer to make sure OpenVPN can always fall back on DH.

Quoted 8 lines

Most of the curves secp, prime, sect work, but some of them ( eg. wap-wsg-idm-ecid-wtls10 ) cause ssl error 'no shared cipher'.

Working curves examples:
...

Failing examples:
...

Not all curves supported by OpenSSL are available for use in SSL/TLS, wap-wsg-idm-ecid-wtls10 sounds like a perfect example of that. Furthermore, the available curves depend on you version and configuration of OpenSSL.

One of the things I do not completely grasp yet is why some cipher suites succeed (e.g. TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA works for me), but some slightly different ones do not (e.g. TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384 and TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA do not work for me), even though all the primitives for those suites are available from the version of OpenSSL I'm using. Still, the behaviour is different for various OpenSSL versions. Have you stumbled across this already?

Quoted 2 lines

I also copied from your code option --show-curves, manual entries and EC curve autodetection.

Credits for those lines go to Jan Just actually. About the copying, wouldn't it make more sense if you'd review my implementation, instead of copying it? The bulk of it is my code now anyway.

Although there is apparently more work to do to get more cipher suites working, this does give us a start on working with EC-crypto. Maybe this part can go in (once ACK'ed) as 'the start of EC-support', so more people can help improve the code. Any other opinions on this?

Regards,
-Steffan

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool. Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer Customize your own dashboards, set traffic alerts and generate reports. Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#18 lore raw

Hi,

Quoted 7 lines · pietrek --

I tested what would happen if any key exchange protocol will be specified. It works as I expected: connection failed with error: 'no such cipher'. So session cannot work without ECDH and DH.
Also, if OpenSSL would accept it, it would be an invitatation for men in the middle ;)

For clients without ECDH connection will just fail.

Interesting, with the current setup and OpenSSL behaviour (at least up to OpenSSL 1.0.1) you are right. Since commit 813aa55 (last January), where ephemeral RSA support was dropped, OpenVPN knows no other way for key exchange but DH (and ECDH after the updates). Without that, OpenVPN would fall back to RSA for key exchange, which is not directly vulnerable to man-in-the-middle attacks, but it would mean falling back to less secure cipher suites.

However, we completely depend on OpenSSL being incapable of doing some sort of key exchange automatically, which I think is a bit risky. If we can make absolutely sure OpenSSL will not fall back, we might be able to remove the requirement for the DH-file from a security perspective.

Quoted 6 lines

In my opinion forcing users to specify DH key isn no longer neccessary, because this file generates
long and protection against men in the middle attack is as strong as the weakest encryption algorithm
so if DH will be weaker than ECDH curve, even the best curve won't improve security against such attack.

OpenSSL prefers ECDH over DH, so if both client and server support it, the connection would not use DH. A user who does not trust DH anymore could specifiy something like --tls-cipher DEFAULT:\!DH:\!EXP to explicitly forbid usage of DH.

I agree that the DH-file generation is not one of OpenVPN's most user-friendly features, but a server administrator has to it just once and clients are not bothered by it at all.

Furthermore, I expect that if we would make it 'too easy' to create ECDH-only servers many people would run into trouble when one of their peers has an older version of OpenVPN (of which there are a *lot*) and gets the "no shared cipher" error. An administrator diving into the crypto, specifying explicitly to not trust DH should be able to cope with that, but new users probably do not.

To conclude, I agree with you that the restriction on the DH-file should eventually disappear, I just think right now is a bit premature.

-Steffan

author
#19 lore raw

Hi,
I agree with you that admin may be confused if he won't specify --dh option and server will work but refusing some clients. He could just forget adding this option or don't know it's neccessary.
I think we could add option "--dh none" or "--no-dh". It may be specified, if user knows what he's doing. Option --no-ecdh( or --ecdh none ) could be useful if user does not want to use ECDH for some reason. Also, to avoid unexpected behaviour like fallback into RSA, we could force openssl to use DH or ECDH only.

Piotr Jarosz

Quoted 60 lines · Steffan Karger

Hi,

Quoted 7 lines · pietrek --

I tested what would happen if any key exchange protocol will be specified. It works as I expected: connection failed with error: 'no such cipher'. So session cannot work without ECDH and DH.
Also, if OpenSSL would accept it, it would be an invitatation for men in the middle ;)

For clients without ECDH connection will just fail.

Interesting, with the current setup and OpenSSL behaviour (at least up to OpenSSL 1.0.1) you are right. Since commit 813aa55 (last January), where ephemeral RSA support was dropped, OpenVPN knows no other way for key exchange but DH (and ECDH after the updates). Without that, OpenVPN would fall back to RSA for key exchange, which is not directly vulnerable to man-in-the-middle attacks, but it would mean falling back to less secure cipher suites.

However, we completely depend on OpenSSL being incapable of doing some sort of key exchange automatically, which I think is a bit risky. If we can make absolutely sure OpenSSL will not fall back, we might be able to remove the requirement for the DH-file from a security perspective.

Quoted 6 lines

In my opinion forcing users to specify DH key isn no longer neccessary, because this file generates
long and protection against men in the middle attack is as strong as the weakest encryption algorithm
so if DH will be weaker than ECDH curve, even the best curve won't improve security against such attack.

OpenSSL prefers ECDH over DH, so if both client and server support it, the connection would not use DH. A user who does not trust DH anymore could specifiy something like --tls-cipher DEFAULT:\!DH:\!EXP to explicitly forbid usage of DH.

I agree that the DH-file generation is not one of OpenVPN's most user-friendly features, but a server administrator has to it just once and clients are not bothered by it at all.

Furthermore, I expect that if we would make it 'too easy' to create ECDH-only servers many people would run into trouble when one of their peers has an older version of OpenVPN (of which there are a *lot*) and gets the "no shared cipher" error. An administrator diving into the crypto, specifying explicitly to not trust DH should be able to cope with that, but new users probably do not.

To conclude, I agree with you that the restriction on the DH-file should eventually disappear, I just think right now is a bit premature.

-Steffan

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool. Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer Customize your own dashboards, set traffic alerts and generate reports. Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#20 lore raw

Hi,

Quoted 1 line · pietrek --

[...]

I think we could add option "--dh none" or "--no-dh". It may be

Quoted 2 lines

specified, if user knows what he's doing.

I like that idea. It offers a migration path for users that really want to skip the DH-stuff. I'd vote for "--dh '[none]'", as it does not add a new option (openvpn has more then enough options ;) ), and is hard to accidentally supply as a file name.

This is more a usability thing then a crypto thing, so I'd like to hear more opinions on this.

Quoted 3 lines

Option --no-ecdh( or --ecdh none ) could be useful if user does not want to use ECDH for some reason.

I do not like this one. A user gets ECDH initialisation for free, and if a power user really wants to disable ECDH, (s)he can use --tls-cipher "DEFAULT:!EXP:!ECDH" or something like that. An explicit extra option adds code, while it is not needed for the functionality.

Quoted 3 lines

Also, to avoid unexpected behaviour like fallback into RSA, we could force openssl to use DH or ECDH only.

Do you have any idea on how to achieve this, other than setting explicit tls-cipher lists? The cipher list has a limited interface, which would result in actively maintaining a list of 'approved' ciphers within the OpenVPN codebase. I would not like to do that.

Regards,
-Steffan

#21 lore raw
Quoted 23 lines · Steffan Karger

Hi,

On Tue, Mar 4, 2014 at 10:49 PM, pietrek -- <[email protected]... <mailto:[email protected]...>> wrote:

[...]

I think we could add option "--dh none" or "--no-dh". It may be specified, if user knows what he's doing.

I like that idea. It offers a migration path for users that really want to skip the DH-stuff. I'd vote for "--dh '[none]'", as it does not add a new option (openvpn has more then enough options ;) ), and is hard to accidentally supply as a file name.

This is more a usability thing then a crypto thing, so I'd like to hear more opinions on this.

Option --no-ecdh( or --ecdh none ) could be useful if user does not want
to use ECDH for some reason.

I do not like this one. A user gets ECDH initialisation for free, and if a power user really wants to disable ECDH, (s)he can use --tls-cipher "DEFAULT:!EXP:!ECDH" or something like that. An explicit
extra option adds code, while it is not needed for the functionality.

Quoted 6 lines

Also, to avoid unexpected behaviour like fallback into RSA, we could force openssl to use DH or ECDH only.

Do you have any idea on how to achieve this, other than setting explicit tls-cipher lists? The cipher list has a limited interface, which would result in actively maintaining a list of 'approved' ciphers within the OpenVPN codebase. I would not like to do that.

According to 'man SSL_CTX_set_tmp_rsa_callback'

On OpenSSL servers ephemeral RSA key exchange is therefore
disabled by default and must be explicitly
enabled using the SSL_OP_EPHEMERAL_RSA option of
SSL_CTX_set_options(3), violating the TLS/SSL
standard. When ephemeral RSA key exchange is required for export
ciphers, it will automatically be
used without this option!

so this would suggest that ephemeral RSA keys are not used by default unless explicitly enabled (as it breaks TLS/SSL).

cheers,

JJK