]> granicus.if.org Git - curl/commitdiff
openssl: fix SSL/TLS versions in verbose output
authorDaniel Stenberg <daniel@haxx.se>
Mon, 22 Dec 2014 13:09:46 +0000 (14:09 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 22 Dec 2014 13:21:17 +0000 (14:21 +0100)
lib/vtls/openssl.c

index b768d6fbf826a32323748b5280daccf649e08d44..4df5a7a2eb9c4d3447aff94bede01adfd9132350 100644 (file)
@@ -1381,20 +1381,43 @@ static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
   struct SessionHandle *data;
   const char *msg_name, *tls_rt_name;
   char ssl_buf[1024];
-  int  ver, msg_type, txt_len;
+  char unknown[32];
+  int msg_type, txt_len;
+  const char *verstr;
 
   if(!conn || !conn->data || !conn->data->set.fdebug ||
      (direction != 0 && direction != 1))
     return;
 
   data = conn->data;
-  ssl_ver >>= 8;
-#ifdef SSL2_VERSION_MAJOR
-  ver = (ssl_ver == SSL2_VERSION_MAJOR ? '2' :
-         ssl_ver == SSL3_VERSION_MAJOR ? '3' : '?');
-#else
-  ver = ssl_ver == SSL3_VERSION_MAJOR ? '3' : '?';
+
+  switch(ssl_ver) {
+#ifdef SSL2_VERSION_MAJOR /* removed in recent versions */
+  case SSL2_VERSION_MAJOR:
+    verstr = "SSLv2";
+    break;
 #endif
+#ifdef SSL3_VERSION
+  case SSL3_VERSION:
+    verstr = "SSLv3";
+    break;
+#endif
+  case TLS1_VERSION:
+    verstr = "TLSv1.0";
+    break;
+  case TLS1_1_VERSION:
+    verstr = "TLSv1.1";
+    break;
+  case TLS1_2_VERSION:
+    verstr = "TLSv1.2";
+    break;
+  default:
+    snprintf(unknown, sizeof(unknown), "(%x)", ssl_ver);
+    verstr = unknown;
+    break;
+  }
+
+  ssl_ver >>= 8; /* check the upper 8 bits only below */
 
   /* SSLv2 doesn't seem to have TLS record-type headers, so OpenSSL
    * always pass-up content-type as 0. But the interesting message-type
@@ -1408,8 +1431,8 @@ static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
   msg_type = *(char*)buf;
   msg_name = ssl_msg_type(ssl_ver, msg_type);
 
-  txt_len = snprintf(ssl_buf, sizeof(ssl_buf), "SSLv%c, %s%s (%d):\n",
-                     ver, tls_rt_name, msg_name, msg_type);
+  txt_len = snprintf(ssl_buf, sizeof(ssl_buf), "%s, %s%s (%d):\n",
+                     verstr, tls_rt_name, msg_name, msg_type);
   Curl_debug(data, CURLINFO_TEXT, ssl_buf, (size_t)txt_len, NULL);
 
   Curl_debug(data, (direction == 1) ? CURLINFO_SSL_DATA_OUT :