Commit 5c213e29df614391064aa3c590e329620cc91e49

Edward Thomson 2018-11-18T22:59:03

Merge pull request #4875 from tiennou/fix/openssl-errors Some OpenSSL issues

diff --git a/src/streams/openssl.c b/src/streams/openssl.c
index 7fd810a..a68f9a9 100644
--- a/src/streams/openssl.c
+++ b/src/streams/openssl.c
@@ -373,10 +373,10 @@ static int ssl_set_error(SSL *ssl, int error)
 	switch (err) {
 	case SSL_ERROR_WANT_CONNECT:
 	case SSL_ERROR_WANT_ACCEPT:
-		giterr_set(GITERR_NET, "SSL error: connection failure");
+		giterr_set(GITERR_SSL, "SSL error: connection failure");
 		break;
 	case SSL_ERROR_WANT_X509_LOOKUP:
-		giterr_set(GITERR_NET, "SSL error: x509 error");
+		giterr_set(GITERR_SSL, "SSL error: x509 error");
 		break;
 	case SSL_ERROR_SYSCALL:
 		e = ERR_get_error();
@@ -389,7 +389,7 @@ static int ssl_set_error(SSL *ssl, int error)
 			giterr_set(GITERR_OS, "SSL error: syscall failure");
 			break;
 		}
-		giterr_set(GITERR_NET, "SSL error: received early EOF");
+		giterr_set(GITERR_SSL, "SSL error: received early EOF");
 		return GIT_EEOF;
 		break;
 	case SSL_ERROR_SSL:
@@ -397,13 +397,13 @@ static int ssl_set_error(SSL *ssl, int error)
 		char errmsg[256];
 		e = ERR_get_error();
 		ERR_error_string_n(e, errmsg, sizeof(errmsg));
-		giterr_set(GITERR_NET, "SSL error: %s", errmsg);
+		giterr_set(GITERR_SSL, "SSL error: %s", errmsg);
 		break;
 	}
 	case SSL_ERROR_NONE:
 	case SSL_ERROR_ZERO_RETURN:
 	default:
-		giterr_set(GITERR_NET, "SSL error: unknown error");
+		giterr_set(GITERR_SSL, "SSL error: unknown error");
 		break;
 	}
 	return -1;
@@ -586,8 +586,6 @@ int openssl_connect(git_stream *stream)
 	if ((ret = git_stream_connect(st->io)) < 0)
 		return ret;
 
-	st->connected = true;
-
 	bio = BIO_new(git_stream_bio_method);
 	GITERR_CHECK_ALLOC(bio);
 
@@ -602,6 +600,8 @@ int openssl_connect(git_stream *stream)
 	if ((ret = SSL_connect(st->ssl)) <= 0)
 		return ssl_set_error(st->ssl, ret);
 
+	st->connected = true;
+
 	return verify_server_cert(st->ssl, st->host);
 }