Browse code

Add better support for showing TLS 1.3 ciphersuites in --show-tls

--show-tls shows mixed TLS 1.3 and TLS 1.2 ciphers. The listed ciphers
are only valid in either --tls-cipher or --tls-ciphersuites, but it's
not clear which is which. This is confusing and not really helpful.

This patch modifies show-tls to show separate lists for TLS 1.2 and
TLS 1.3.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <20181010153624.27957-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17723.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Arne Schwabe authored on 2018/10/11 00:36:24
Showing 7 changed files
... ...
@@ -1034,6 +1034,7 @@ print_openssl_info(const struct options *options)
1034 1034
         if (options->show_tls_ciphers)
1035 1035
         {
1036 1036
             show_available_tls_ciphers(options->cipher_list,
1037
+                                       options->cipher_list_tls13,
1037 1038
                                        options->tls_cert_profile);
1038 1039
         }
1039 1040
         if (options->show_curves)
... ...
@@ -4116,6 +4116,30 @@ tls_check_ncp_cipher_list(const char *list)
4116 4116
     return 0 < strlen(list) && !unsupported_cipher_found;
4117 4117
 }
4118 4118
 
4119
+void
4120
+show_available_tls_ciphers(const char *cipher_list,
4121
+                           const char *cipher_list_tls13,
4122
+                           const char *tls_cert_profile)
4123
+{
4124
+    printf("Available TLS Ciphers, listed in order of preference:\n");
4125
+
4126
+#if (ENABLE_CRYPTO_OPENSSL && OPENSSL_VERSION_NUMBER >= 0x1010100fL)
4127
+    printf("\nFor TLS 1.3 and newer (--tls-ciphersuites):\n\n");
4128
+    show_available_tls_ciphers_list(cipher_list_tls13, tls_cert_profile, true);
4129
+#else
4130
+    (void) cipher_list_tls13;  /* Avoid unused warning */
4131
+#endif
4132
+
4133
+    printf("\nFor TLS 1.2 and older (--tls-cipher):\n\n");
4134
+    show_available_tls_ciphers_list(cipher_list, tls_cert_profile, false);
4135
+
4136
+    printf("\n"
4137
+    "Be aware that that whether a cipher suite in this list can actually work\n"
4138
+    "depends on the specific setup of both peers. See the man page entries of\n"
4139
+    "--tls-cipher and --show-tls for more details.\n\n"
4140
+    );
4141
+}
4142
+
4119 4143
 /*
4120 4144
  * Dump a human-readable rendition of an openvpn packet
4121 4145
  * into a garbage collectable string which is returned.
... ...
@@ -598,4 +598,18 @@ bool is_hard_reset(int op, int key_method);
598 598
 
599 599
 void delayed_auth_pass_purge(void);
600 600
 
601
+
602
+/*
603
+ * Show the TLS ciphers that are available for us to use in the SSL
604
+ * library with headers hinting their usage and warnings about usage.
605
+ *
606
+ * @param cipher_list       list of allowed TLS cipher, or NULL.
607
+ * @param cipher_list_tls13 list of allowed TLS 1.3+ cipher, or NULL
608
+ * @param tls_cert_profile  TLS certificate crypto profile name.
609
+ */
610
+void
611
+show_available_tls_ciphers(const char *cipher_list,
612
+                           const char *cipher_list_tls13,
613
+                           const char *tls_cert_profile);
614
+
601 615
 #endif /* ifndef OPENVPN_SSL_H */
... ...
@@ -517,15 +517,19 @@ int key_state_read_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf,
517 517
 void print_details(struct key_state_ssl *ks_ssl, const char *prefix);
518 518
 
519 519
 /*
520
- * Show the TLS ciphers that are available for us to use in the OpenSSL
521
- * library.
520
+ * Show the TLS ciphers that are available for us to use in the
521
+ * library depending on the TLS version. This function prints
522
+ * a list of ciphers without headers/footers.
522 523
  *
523 524
  * @param cipher_list       list of allowed TLS cipher, or NULL.
524 525
  * @param tls_cert_profile  TLS certificate crypto profile name.
526
+ * @param tls13             Select if <=TLS1.2 or TLS1.3+ ciphers
527
+ *                          should be shown
525 528
  */
526 529
 void
527
-show_available_tls_ciphers(const char *cipher_list,
528
-                           const char *tls_cert_profile);
530
+show_available_tls_ciphers_list(const char *cipher_list,
531
+                                const char *tls_cert_profile,
532
+                                bool tls13);
529 533
 
530 534
 /*
531 535
  * Show the available elliptic curves in the crypto library
... ...
@@ -554,10 +554,4 @@ struct tls_multi
554 554
      *   sessions with the remote peer. */
555 555
 };
556 556
 
557
-
558
-#define SHOW_TLS_CIPHER_LIST_WARNING \
559
-    "Be aware that that whether a cipher suite in this list can actually work\n" \
560
-    "depends on the specific setup of both peers. See the man page entries of\n" \
561
-    "--tls-cipher and --show-tls for more details.\n\n"
562
-
563 557
 #endif /* SSL_COMMON_H_ */
... ...
@@ -1340,9 +1340,15 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)
1340 1340
 }
1341 1341
 
1342 1342
 void
1343
-show_available_tls_ciphers(const char *cipher_list,
1344
-                           const char *tls_cert_profile)
1343
+show_available_tls_ciphers_list(const char *cipher_list,
1344
+                                const char *tls_cert_profile,
1345
+                                bool tls13)
1345 1346
 {
1347
+    if (tls13)
1348
+    {
1349
+        /* mbed TLS has no TLS 1.3 support currently */
1350
+        return;
1351
+    }
1346 1352
     struct tls_root_ctx tls_ctx;
1347 1353
     const int *ciphers = mbedtls_ssl_list_ciphersuites();
1348 1354
 
... ...
@@ -1355,18 +1361,11 @@ show_available_tls_ciphers(const char *cipher_list,
1355 1355
         ciphers = tls_ctx.allowed_ciphers;
1356 1356
     }
1357 1357
 
1358
-#ifndef ENABLE_SMALL
1359
-    printf("Available TLS Ciphers,\n");
1360
-    printf("listed in order of preference:\n\n");
1361
-#endif
1362
-
1363 1358
     while (*ciphers != 0)
1364 1359
     {
1365 1360
         printf("%s\n", mbedtls_ssl_get_ciphersuite_name(*ciphers));
1366 1361
         ciphers++;
1367 1362
     }
1368
-    printf("\n" SHOW_TLS_CIPHER_LIST_WARNING);
1369
-
1370 1363
     tls_ctx_free(&tls_ctx);
1371 1364
 }
1372 1365
 
... ...
@@ -60,6 +60,7 @@
60 60
 #include <openssl/pkcs12.h>
61 61
 #include <openssl/rsa.h>
62 62
 #include <openssl/x509.h>
63
+#include <openssl/ssl.h>
63 64
 #ifndef OPENSSL_NO_EC
64 65
 #include <openssl/ec.h>
65 66
 #endif
... ...
@@ -428,7 +429,8 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
428 428
 }
429 429
 
430 430
 void
431
-convert_tls13_list_to_openssl(char* openssl_ciphers, size_t len, const char *ciphers)
431
+convert_tls13_list_to_openssl(char *openssl_ciphers, size_t len,
432
+                              const char *ciphers)
432 433
 {
433 434
     /*
434 435
      * OpenSSL (and official IANA) cipher names have _ in them. We
... ...
@@ -1984,14 +1986,11 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)
1984 1984
 }
1985 1985
 
1986 1986
 void
1987
-show_available_tls_ciphers(const char *cipher_list,
1988
-                           const char *tls_cert_profile)
1987
+show_available_tls_ciphers_list(const char *cipher_list,
1988
+                                const char *tls_cert_profile,
1989
+                                const bool tls13)
1989 1990
 {
1990 1991
     struct tls_root_ctx tls_ctx;
1991
-    SSL *ssl;
1992
-    const char *cipher_name;
1993
-    const tls_cipher_name_pair *pair;
1994
-    int priority = 0;
1995 1992
 
1996 1993
     tls_ctx.ctx = SSL_CTX_new(SSLv23_method());
1997 1994
     if (!tls_ctx.ctx)
... ...
@@ -1999,22 +1998,45 @@ show_available_tls_ciphers(const char *cipher_list,
1999 1999
         crypto_msg(M_FATAL, "Cannot create SSL_CTX object");
2000 2000
     }
2001 2001
 
2002
-    ssl = SSL_new(tls_ctx.ctx);
2003
-    if (!ssl)
2002
+#if (OPENSSL_VERSION_NUMBER >= 0x1010100fL)
2003
+    if (tls13)
2004 2004
     {
2005
-        crypto_msg(M_FATAL, "Cannot create SSL object");
2005
+        SSL_CTX_set_min_proto_version(tls_ctx.ctx, TLS1_3_VERSION);
2006
+    }
2007
+    else
2008
+#endif
2009
+    {
2010
+        SSL_CTX_set_max_proto_version(tls_ctx.ctx, TLS1_2_VERSION);
2006 2011
     }
2007 2012
 
2008 2013
     tls_ctx_set_cert_profile(&tls_ctx, tls_cert_profile);
2009 2014
     tls_ctx_restrict_ciphers(&tls_ctx, cipher_list);
2010 2015
 
2011
-    printf("Available TLS Ciphers,\n");
2012
-    printf("listed in order of preference:\n\n");
2013
-    while ((cipher_name = SSL_get_cipher_list(ssl, priority++)))
2016
+    SSL *ssl = SSL_new(tls_ctx.ctx);
2017
+    if (!ssl)
2018
+    {
2019
+        crypto_msg(M_FATAL, "Cannot create SSL object");
2020
+    }
2021
+
2022
+#if (OPENSSL_VERSION_NUMBER < 0x1010000fL)
2023
+    STACK_OF(SSL_CIPHER) *sk = SSL_get_ciphers(ssl);
2024
+#else
2025
+    STACK_OF(SSL_CIPHER) *sk = SSL_get1_supported_ciphers(ssl);
2026
+#endif
2027
+    for (int i=0;i < sk_SSL_CIPHER_num(sk);i++)
2014 2028
     {
2015
-        pair = tls_get_cipher_name_pair(cipher_name, strlen(cipher_name));
2029
+        const SSL_CIPHER *c = sk_SSL_CIPHER_value(sk, i);
2030
+
2031
+        const char *cipher_name = SSL_CIPHER_get_name(c);
2032
+
2033
+        const tls_cipher_name_pair *pair =
2034
+            tls_get_cipher_name_pair(cipher_name, strlen(cipher_name));
2016 2035
 
2017
-        if (NULL == pair)
2036
+        if (tls13)
2037
+        {
2038
+              printf("%s\n", cipher_name);
2039
+        }
2040
+        else if (NULL == pair)
2018 2041
         {
2019 2042
             /* No translation found, print warning */
2020 2043
             printf("%s (No IANA name known to OpenVPN, use OpenSSL name.)\n", cipher_name);
... ...
@@ -2023,10 +2045,10 @@ show_available_tls_ciphers(const char *cipher_list,
2023 2023
         {
2024 2024
             printf("%s\n", pair->iana_name);
2025 2025
         }
2026
-
2027 2026
     }
2028
-    printf("\n" SHOW_TLS_CIPHER_LIST_WARNING);
2029
-
2027
+#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
2028
+    sk_SSL_CIPHER_free(sk);
2029
+#endif
2030 2030
     SSL_free(ssl);
2031 2031
     SSL_CTX_free(tls_ctx.ctx);
2032 2032
 }