Add upstream patch to support mbedTLS

This commit is contained in:
Pirate Praveen 2018-05-06 17:37:29 +05:30
parent 27f4a70e4b
commit 6939eb20c6
3 changed files with 1722 additions and 123 deletions

View File

@ -1,122 +0,0 @@
Subject: Use curl for TLS
Forwarded: no
Applied-Upstream: no
From: Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
Reviewed-by: Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
Last-Update: 2018-05-02
The original Debian patchset was authored by Ximin Luo <infinity0@debian.org>
Original pull request https://github.com/libgit2/libgit2/pull/4325
---
src/CMakeLists.txt | 3 +++
src/streams/curl.c | 14 +++++++++++---
src/streams/curl.h | 2 +-
src/streams/openssl.c | 2 +-
src/streams/tls.c | 2 ++
src/transports/http.c | 2 +-
6 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b03b96a..2739fb5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -124,6 +124,9 @@ ELSE ()
IF (CURL_FOUND)
SET(GIT_CURL 1)
+ IF (USE_CURL_SSL)
+ ADD_DEFINITIONS(-DGIT_CURL_SSL)
+ ENDIF()
LIST(APPEND LIBGIT2_INCLUDES ${CURL_INCLUDE_DIRS})
LIST(APPEND LIBGIT2_LIBDIRS ${CURL_LIBRARY_DIRS})
LIST(APPEND LIBGIT2_LIBS ${CURL_LIBRARIES})
diff --git a/src/streams/curl.c b/src/streams/curl.c
index ee13be1..afb3775 100644
--- a/src/streams/curl.c
+++ b/src/streams/curl.c
@@ -314,7 +314,7 @@ static void curls_free(git_stream *stream)
git__free(s);
}
-int git_curl_stream_new(git_stream **out, const char *host, const char *port)
+int git_curl_stream_new(git_stream **out, const char *host, const char *port, int encrypted)
{
curl_stream *st;
CURL *handle;
@@ -335,7 +335,15 @@ int git_curl_stream_new(git_stream **out, const char *host, const char *port)
return error;
}
- curl_easy_setopt(handle, CURLOPT_URL, host);
+ if (encrypted) {
+ git_buf buf = GIT_BUF_INIT;
+ git_buf_printf(&buf, "https://%s", host);
+ curl_easy_setopt(handle, CURLOPT_URL, buf.ptr);
+ git_buf_free(&buf);
+ } else {
+ curl_easy_setopt(handle, CURLOPT_URL, host);
+ }
+
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, st->curl_error);
curl_easy_setopt(handle, CURLOPT_PORT, iport);
curl_easy_setopt(handle, CURLOPT_CONNECT_ONLY, 1);
@@ -347,7 +355,7 @@ int git_curl_stream_new(git_stream **out, const char *host, const char *port)
/* curl_easy_setopt(handle, CURLOPT_VERBOSE, 1); */
st->parent.version = GIT_STREAM_VERSION;
- st->parent.encrypted = 0; /* we don't encrypt ourselves */
+ st->parent.encrypted = encrypt; /* we don't encrypt ourselves */
st->parent.proxy_support = 1;
st->parent.connect = curls_connect;
st->parent.certificate = curls_certificate;
diff --git a/src/streams/curl.h b/src/streams/curl.h
index 511cd89..ac0df1c 100644
--- a/src/streams/curl.h
+++ b/src/streams/curl.h
@@ -12,6 +12,6 @@
#include "git2/sys/stream.h"
extern int git_curl_stream_global_init(void);
-extern int git_curl_stream_new(git_stream **out, const char *host, const char *port);
+extern int git_curl_stream_new(git_stream **out, const char *host, const char *port, int encrypted);
#endif
diff --git a/src/streams/openssl.c b/src/streams/openssl.c
index 9cbb274..063750f 100644
--- a/src/streams/openssl.c
+++ b/src/streams/openssl.c
@@ -607,7 +607,7 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
st->io = NULL;
#ifdef GIT_CURL
- error = git_curl_stream_new(&st->io, host, port);
+ error = git_curl_stream_new(&st->io, host, port, false);
#else
error = git_socket_stream_new(&st->io, host, port);
#endif
diff --git a/src/streams/tls.c b/src/streams/tls.c
index d6ca7d4..7279306 100644
--- a/src/streams/tls.c
+++ b/src/streams/tls.c
@@ -31,6 +31,8 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port)
return git_stransport_stream_new(out, host, port);
#elif defined(GIT_OPENSSL)
return git_openssl_stream_new(out, host, port);
+#elif defined(GIT_CURL_SSL)
+ return git_curl_stream_new(out, host, port, true);
#else
GIT_UNUSED(out);
GIT_UNUSED(host);
diff --git a/src/transports/http.c b/src/transports/http.c
index e051c8a..984be08 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -605,7 +605,7 @@ static int http_connect(http_subtransport *t)
error = git_tls_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
} else {
#ifdef GIT_CURL
- error = git_curl_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
+ error = git_curl_stream_new(&t->io, t->connection_data.host, t->connection_data.port, false);
#else
error = git_socket_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
#endif

View File

@ -1 +1 @@
Use-curl-for-TLS.patch
use-mbedtls.patch

1721
debian/patches/use-mbedtls.patch vendored Normal file

File diff suppressed because it is too large Load Diff