Skip to contentSkip to conversation

Elliptic curve patch

Openvpn-devel Jan Just Keijser 1 participant 1 message Feb 6, 2012

lore
Share & tools
lore
#0 lore raw

hi all,

attached is my elliptic curve patch, to add support for using ECDSA curves in combination with SHA256/SHA512 signed certificates; currently you can do either ECDSA with SHA1-signed certificates, or no ECDSA but SHA256/SHA512 signed certs . The error message seen is
SSL3_CLIENT_GET_HELLO:no shared cipher
This patch overcomes this.

With the patch you should see for the control channel:
Control Channel: TLSv1, cipher TLSv1/SSLv3 ECDHE-ECDSA-AES256-SHA

Two new parameters are added to OpenVPN
--show-curves
to list the available elliptic curves, and
--ecdh <name>
to select a curve name.

TODO: this code is currently only enabled using '#ifdef USE_SSL_EC' ; I've manually added a line
#define USE_SSL_EC 1
to config.h after a './configure' step. I'm not familiar enough with autoconf and friends to turn it into an .ac script:
- you need OpenSSL 1.0+ WITH EC support enabled (RedHat , for example, disables it by default)
- PolarSSL does not support it (yet).

It would be great if somebody can help me sort the autoconf thing out.

The patch was tested on Fedora 14 64bit using a git cloned repo , but without the latest buffer.c patch.

cheers,

JJK

init.c +7 -0
diff -Naur openvpn.git/init.c openvpn.git-ecdsa/init.c
@@ -895,6 +895,9 @@
   if (options->show_ciphers || options->show_digests || options->show_engines
 #ifdef USE_SSL
       || options->show_tls_ciphers
+#ifdef USE_SSL_EC
+|| options->show_curves
+#endif
 #endif
     )
     {
@@ -907,6 +910,10 @@
 #ifdef USE_SSL
       if (options->show_tls_ciphers)
 	show_available_tls_ciphers ();
+#ifdef USE_SSL_EC
+      if (options->show_curves)
+    show_available_curves ();
+#endif
 #endif
       return true;
     }
options.c +15 -0
diff -Naur openvpn.git/options.c openvpn.git-ecdsa/options.c
@@ -836,6 +836,9 @@
 #ifdef ENABLE_X509ALTUSERNAME
   o->x509_username_field = X509_USERNAME_FIELD_DEFAULT;
 #endif
+#ifdef USE_SSL_EC
+  o->curve_name = NULL;
+#endif
 #endif /* USE_SSL */
 #endif /* USE_CRYPTO */
 #ifdef ENABLE_PKCS11
@@ -6368,6 +6371,18 @@
       VERIFY_PERMISSION (OPT_P_GENERAL);
       options->show_tls_ciphers = true;
     }
+#ifdef USE_SSL_EC
+  else if (streq (p[0], "show-curves"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->show_curves = true;
+    }
+  else if (streq (p[0], "ecdh") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_CRYPTO);
+      options->curve_name= p[1];
+    }
+#endif
   else if (streq (p[0], "tls-server"))
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
options.h +6 -0
diff -Naur openvpn.git/options.h openvpn.git-ecdsa/options.h
@@ -200,6 +200,9 @@
   bool show_engines;
 #ifdef USE_SSL
   bool show_tls_ciphers;
+#ifdef USE_SSL_EC
+  bool show_curves;
+#endif
 #endif
   bool genkey;
 #endif
@@ -533,6 +536,9 @@
   const char *priv_key_file;
   const char *pkcs12_file;
   const char *cipher_list;
+#ifdef USE_SSL_EC
+  const char *curve_name;
+#endif
   const char *tls_verify;
   const char *tls_export_cert;
   const char *tls_remote;
ssl.c +3 -0
diff -Naur openvpn.git/ssl.c openvpn.git-ecdsa/ssl.c
@@ -308,6 +308,9 @@
     {
       tls_ctx_server_new(new_ctx);
       tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline);
+#ifdef USE_SSL_EC
+      tls_ctx_load_ecdh_params(new_ctx, options->curve_name);
+#endif
     }
   else				/* if client */
     {
ssl_backend.h +10 -0
diff -Naur openvpn.git/ssl_backend.h openvpn.git-ecdsa/ssl_backend.h
@@ -145,6 +145,16 @@
     );
 
 /**
+ * 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.
  *
ssl_openssl.c +84 -0

102 lines not on this page · raw message

ssl_polarssl.c +9 -0
diff -Naur openvpn.git/ssl_polarssl.c openvpn.git-ecdsa/ssl_polarssl.c
@@ -218,6 +218,15 @@
       (counter_type) 8 * mpi_size(&ctx->dhm_ctx->P));
 }
 
+#ifdef USE_SSL_EC
+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");
+}
+#endif
+
 int
 tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
 #if ENABLE_INLINE_FILES