From e81dd846412e2f91cd49392b2e7b5a45baa84b52 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 8 Jan 2014 23:11:56 +0900 Subject: [PATCH] gnutls: Don't fail handshake if returned error is not fatal --- src/LibgnutlsTLSSession.cc | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/LibgnutlsTLSSession.cc b/src/LibgnutlsTLSSession.cc index 5cc78aa5..21f9549a 100644 --- a/src/LibgnutlsTLSSession.cc +++ b/src/LibgnutlsTLSSession.cc @@ -181,11 +181,15 @@ int GnuTLSSession::tlsConnect(const std::string& hostname, std::string& handshakeErr) { handshakeErr = ""; - rv_ = gnutls_handshake(sslSession_); - if(rv_ < 0) { + for(;;) { + rv_ = gnutls_handshake(sslSession_); + if(rv_ == GNUTLS_E_SUCCESS) { + break; + } if(rv_ == GNUTLS_E_AGAIN || rv_ == GNUTLS_E_INTERRUPTED) { return TLS_ERR_WOULDBLOCK; - } else { + } + if(gnutls_error_is_fatal(rv_)) { return TLS_ERR_ERROR; } } @@ -279,13 +283,17 @@ int GnuTLSSession::tlsConnect(const std::string& hostname, int GnuTLSSession::tlsAccept() { - rv_ = gnutls_handshake(sslSession_); - if(rv_ == GNUTLS_E_SUCCESS) { - return TLS_ERR_OK; - } else if(rv_ == GNUTLS_E_AGAIN || rv_ == GNUTLS_E_INTERRUPTED) { - return TLS_ERR_WOULDBLOCK; - } else { - return TLS_ERR_ERROR; + for(;;) { + rv_ = gnutls_handshake(sslSession_); + if(rv_ == GNUTLS_E_SUCCESS) { + return TLS_ERR_OK; + } + if(rv_ == GNUTLS_E_AGAIN || rv_ == GNUTLS_E_INTERRUPTED) { + return TLS_ERR_WOULDBLOCK; + } + if(gnutls_error_is_fatal(rv_)) { + return TLS_ERR_ERROR; + } } }