forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibGit2: patch to pass hostkey & port to host verify callback (JuliaL…
…ang#39324) It seems that no one actually verifies SSH host identity with libgit2 because the callback doesn't give enough information do so correctly: - It doesn't give the actual host key fingerprint, but rather three different hashes thereof. This means we cannot distinguish a known hosts entry that has a different type (`ssh-rsa`, `ssh-dsa`, etc.) from an entry with a matching type and a fingerprint mismatch: the former should be treated as an unknown host whereas the latter is a host key mismatch; they cannot be distinguished without this patch. - If the user connects on a non-default port (i.e. not 22), this is not passed to the callback in any way. Since there can be different known host entries for different ports and they should be treated as distinct, this also means the current API cannot be used to verify hosts serving SSH on non-standard ports. This patch passes the port. I will try to upstream some version of this patch to libgit2. The same patch has already been applied to the LibGit2 JLL. Fixes JuliaLang#38777. Might fix JuliaLang/Pkg.jl#2334.
- Loading branch information
1 parent
3fa2fb5
commit cae6726
Showing
8 changed files
with
158 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
48b3eb5811566f1cc70a9581b8f702f4 |
1 change: 1 addition & 0 deletions
1
deps/checksums/LibGit2.v1.2.1+0.x86_64-apple-darwin.tar.gz/sha512
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
46af2fbe9c96a18a97531aefc79e710abd8e12eca64ddcb2a0ddc8bc675dbaed0723ddbd4401d870eddcae04d99c4306cc6bdaa54b063de36d7fc0981ba86587 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
diff --git a/include/git2/cert.h b/include/git2/cert.h | ||
index e8cd2d180..54293cd31 100644 | ||
--- a/include/git2/cert.h | ||
+++ b/include/git2/cert.h | ||
@@ -111,6 +111,14 @@ typedef struct { | ||
* have the SHA-256 hash of the hostkey. | ||
*/ | ||
unsigned char hash_sha256[32]; | ||
+ | ||
+ /** | ||
+ * Hostkey itself. | ||
+ */ | ||
+ int hostkey_type; | ||
+ size_t hostkey_len; | ||
+ unsigned char hostkey[1024]; | ||
+ | ||
} git_cert_hostkey; | ||
|
||
/** | ||
diff --git a/src/transports/ssh.c b/src/transports/ssh.c | ||
index f4ed05bb1..049697796 100644 | ||
--- a/src/transports/ssh.c | ||
+++ b/src/transports/ssh.c | ||
@@ -523,6 +523,7 @@ static int _git_ssh_setup_conn( | ||
git_credential *cred = NULL; | ||
LIBSSH2_SESSION* session=NULL; | ||
LIBSSH2_CHANNEL* channel=NULL; | ||
+ char *host_and_port; | ||
|
||
t->current_stream = NULL; | ||
|
||
@@ -566,6 +567,12 @@ post_extract: | ||
|
||
cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2; | ||
|
||
+ key = libssh2_session_hostkey(session, &cert.hostkey_len, &cert.hostkey_type); | ||
+ bzero(&cert.hostkey, sizeof(cert.hostkey)); | ||
+ if (cert.hostkey_len > sizeof(cert.hostkey)) | ||
+ cert.hostkey_len = sizeof(cert.hostkey); | ||
+ memcpy(&cert.hostkey, key, cert.hostkey_len); | ||
+ | ||
#ifdef LIBSSH2_HOSTKEY_HASH_SHA256 | ||
key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256); | ||
if (key != NULL) { | ||
@@ -597,7 +604,15 @@ post_extract: | ||
|
||
cert_ptr = &cert; | ||
|
||
- error = t->owner->certificate_check_cb((git_cert *) cert_ptr, 0, urldata.host, t->owner->message_cb_payload); | ||
+ if (git_net_url_is_default_port(&urldata)) { | ||
+ host_and_port = urldata.host; | ||
+ } else { | ||
+ size_t n = strlen(urldata.host) + strlen(urldata.port) + 2; | ||
+ host_and_port = alloca(n); | ||
+ sprintf(host_and_port, "%s:%s", urldata.host, urldata.port); | ||
+ } | ||
+ | ||
+ error = t->owner->certificate_check_cb((git_cert *) cert_ptr, 0, host_and_port, t->owner->message_cb_payload); | ||
|
||
if (error < 0 && error != GIT_PASSTHROUGH) { | ||
if (!git_error_last()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.