On 10/24, Alessandro Ghedini wrote:
> Attached is the patch that implements the second solution. I am testing it 
> right
> now to see if it works, so do not merge this yet.

I've rewritten the patch to fix the original broken logic, so that it now still
prints "gnutls_handshake() warning: ..." and has the correct behaviour (i.e.
doesn't break git).

The problem is that the original test case still fails a few steps afterwards
with "GnuTLS recv error (-15): An unexpected TLS packet was received" and I
don't know why. When manually sending the HTTP request using gnutls-cli it
works fine.

The second patch attached is for printing the actual content of the received
TLS alert, so that libcurl prints the more useful:

  gnutls_handshake() warning: The server name sent was not recognized

instead of:

  gnutls_handshake() warning: A TLS warning alert has been received.

Comments?

Cheers

-- 
perl -E '$_=q;$/= @{[@_]};and s;\S+;<inidehG ordnasselA>;eg;say~~reverse'
From 80907d7dc770b2e673d51308fb2b28a68783734d Mon Sep 17 00:00:00 2001
From: Alessandro Ghedini <[email protected]>
Date: Wed, 24 Oct 2012 11:47:32 +0200
Subject: [PATCH 1/2] gnutls: fix the error_is_fatal logic

---
 lib/gtls.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/gtls.c b/lib/gtls.c
index f5f95ae..dbf568c 100644
--- a/lib/gtls.c
+++ b/lib/gtls.c
@@ -299,21 +299,21 @@ static CURLcode handshake(struct connectdata *conn,
       connssl->connecting_state =
         gnutls_record_get_direction(session)?
         ssl_connect_2_writing:ssl_connect_2_reading;
+      continue;
       if(nonblocking)
         return CURLE_OK;
     }
-    else if((rc < 0) && gnutls_error_is_fatal(rc)) {
+    else if((rc < 0) && !gnutls_error_is_fatal(rc)) {
       failf(data, "gnutls_handshake() warning: %s", gnutls_strerror(rc));
     }
     else if(rc < 0) {
       failf(data, "gnutls_handshake() failed: %s", gnutls_strerror(rc));
       return CURLE_SSL_CONNECT_ERROR;
     }
-    else {
-      /* Reset our connect state machine */
-      connssl->connecting_state = ssl_connect_1;
-      return CURLE_OK;
-    }
+
+    /* Reset our connect state machine */
+    connssl->connecting_state = ssl_connect_1;
+    return CURLE_OK;
   }
 }
 
-- 
1.7.10.4

From 956fc9a1b1d4be8f33b77e1fca91519de24476de Mon Sep 17 00:00:00 2001
From: Alessandro Ghedini <[email protected]>
Date: Wed, 24 Oct 2012 14:34:00 +0200
Subject: [PATCH 2/2] gnutls: print alerts during handshake

---
 lib/gtls.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/gtls.c b/lib/gtls.c
index dbf568c..d8e88e2 100644
--- a/lib/gtls.c
+++ b/lib/gtls.c
@@ -304,10 +304,30 @@ static CURLcode handshake(struct connectdata *conn,
         return CURLE_OK;
     }
     else if((rc < 0) && !gnutls_error_is_fatal(rc)) {
-      failf(data, "gnutls_handshake() warning: %s", gnutls_strerror(rc));
+      char *strerr = NULL;
+
+      if(rc == GNUTLS_E_WARNING_ALERT_RECEIVED) {
+        int alert = gnutls_alert_get(session);
+        strerr = gnutls_alert_get_name(alert);
+      }
+
+      if(strerr == NULL)
+        strerr = gnutls_strerror(rc);
+
+      failf(data, "gnutls_handshake() warning: %s", strerr);
     }
     else if(rc < 0) {
-      failf(data, "gnutls_handshake() failed: %s", gnutls_strerror(rc));
+      char *strerr = NULL;
+
+      if(rc == GNUTLS_E_FATAL_ALERT_RECEIVED) {
+        int alert = gnutls_alert_get(session);
+        strerr = gnutls_alert_get_name(alert);
+      }
+
+      if(strerr == NULL)
+        strerr = gnutls_strerror(rc);
+
+      failf(data, "gnutls_handshake() failed: %s", strerr);
       return CURLE_SSL_CONNECT_ERROR;
     }
 
-- 
1.7.10.4

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to