Skip to content

Commit

Permalink
libgit2: fix for broken SSH host callback (#39364)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski authored Jan 25, 2021
1 parent 69d2453 commit dbaca8b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deps/Versions.make
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CURL_JLL_NAME := LibCURL
LAPACK_VER := 3.9.0

# LibGit2
LIBGIT2_JLL_VER := 1.2.1+0
LIBGIT2_JLL_VER := 1.2.2+0
LIBGIT2_JLL_NAME := LibGit2

# LibSSH2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
693080c66702c9ff106b0935f01d1f96
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f21d5846b443188a0c604255dce77603ea861db8d4c6fc55cebd5db6da07e94ae40f0a165221c95e13db9df8777fddb05f55c865f554f45e56cd442332a95336
4 changes: 2 additions & 2 deletions deps/patches/libgit2-hostkey.patch
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ index e8cd2d180..54293cd31 100644

/**
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index f4ed05bb1..049697796 100644
index f4ed05bb1..ec6366a5f 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -523,6 +523,7 @@ static int _git_ssh_setup_conn(
Expand Down Expand Up @@ -47,7 +47,7 @@ index f4ed05bb1..049697796 100644
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)) {
+ if (atoi(urldata.port) == SSH_DEFAULT_PORT) {
+ host_and_port = urldata.host;
+ } else {
+ size_t n = strlen(urldata.host) + strlen(urldata.port) + 2;
Expand Down
6 changes: 3 additions & 3 deletions stdlib/LibGit2/src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,15 @@ end
function ssh_knownhost_check(
files :: AbstractVector{<:AbstractString},
host :: AbstractString,
key :: String,
key :: Vector{UInt8},
)
if (m = match(r"^(.+):(\d+)$", host)) !== nothing
host = m.captures[1]
port = parse(Int, m.captures[2])
else
port = 22 # default SSH port
end
len = length(key)
mask = Consts.LIBSSH2_KNOWNHOST_TYPE_PLAIN |
Consts.LIBSSH2_KNOWNHOST_KEYENC_RAW
session = @ccall "libssh2".libssh2_session_init_ex(
Expand All @@ -471,13 +472,12 @@ function ssh_knownhost_check(
@ccall "libssh2".libssh2_knownhost_free(hosts::Ptr{Cvoid})::Cvoid
continue
end
size = ncodeunits(key)
check = @ccall "libssh2".libssh2_knownhost_checkp(
hosts :: Ptr{Cvoid},
host :: Cstring,
port :: Cint,
key :: Ptr{UInt8},
size :: Csize_t,
len :: Csize_t,
mask :: Cint,
C_NULL :: Ptr{Ptr{KnownHost}},
) :: Cint
Expand Down
6 changes: 3 additions & 3 deletions stdlib/LibGit2/test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2412,11 +2412,11 @@ mktempdir() do dir
CHECK_FAILURE = LibGit2.Consts.LIBSSH2_KNOWNHOST_CHECK_FAILURE

# randomly generated hashes matching no hosts
random_key = "\0\0\0\assh-rsa\0\0\0\x01#\0\0\0\x81\0¿\x95\xbe9\xfc9g\n:\xcf&\x06YA\xb5`\x97\xc13A\xbf;T+C\xc9Ut J>\xc5ҍ\xc4_S\x8a \xc1S\xeb\x15FH\xd2a\x04.D\xeeb\xac\x8f\xdb\xcc\xef\xc4l G\x9bR\xafp\x17s<=\x12\xab\x04ڳif\\A\x9ba0\xde%\xdei\x04\xc3\r\xb3\x81w\x88\xec\xc0f\x15A;AÝ\xc0r\xa1\u5fe\xd3\xf6)8\x8e\xa3\xcbc\xee\xdd\$\x04\x0f\xc1\xb4\x1f\xcc\xecK\xe0\x99"
random_key = "\0\0\0\assh-rsa\0\0\0\x01#\0\0\0\x81\0¿\x95\xbe9\xfc9g\n:\xcf&\x06YA\xb5`\x97\xc13A\xbf;T+C\xc9Ut J>\xc5ҍ\xc4_S\x8a \xc1S\xeb\x15FH\xd2a\x04.D\xeeb\xac\x8f\xdb\xcc\xef\xc4l G\x9bR\xafp\x17s<=\x12\xab\x04ڳif\\A\x9ba0\xde%\xdei\x04\xc3\r\xb3\x81w\x88\xec\xc0f\x15A;AÝ\xc0r\xa1\u5fe\xd3\xf6)8\x8e\xa3\xcbc\xee\xdd\$\x04\x0f\xc1\xb4\x1f\xcc\xecK\xe0\x99" |> codeunits |> collect
# hashes of the unique github.com fingerprint
github_key = "\0\0\0\assh-rsa\0\0\0\x01#\0\0\x01\x01\0\xab`;\x85\x11\xa6vy\xbd\xb5@\xdb;\xd2\x03K\0J\xe96\xd0k\xe3\xd7`\xf0\x8f˪\xdbN\xb4\xedóǑ\xc7\n\xae\x9at\xc9Xi\xe4wD!«\xea\x92\xe5T0_8\xb5\xfdAK2\b\xe5t\xc37\xe3 \x93e\x18F,vRɋ1\xe1n}\xa6R;\xd2\0t*dD\xd8?\xcd^\x172\xd06sǷ\x81\x15UH{U\xf0\xc4IO8)\xec\xe6\x0f\x94%Z\x95˚\xf57\xd7\xfc\x8c\x7f\xe4\x9e\xf3\x18GN\xf2\x92\t\x92\x05\"e\xb0\xa0n\xa6mJ\x16\x7f\xd9\xf3\xa4\x8a\x1aJ0~\xc1\xea\xaaQI\xa9i\xa6\xac]V\xa5\xefb~Q}\x81\xfbdO[t\\OG\x8e\xcd\b*\x94\x92\xf7D\xaa\xd3&\xf7l\x8cM\xc9\x10\vƫyF\x1d&W\xcbo\x06\xde\xc9.kd\xa6V/\xf0\xe3 \x84\xea\x06\xce\x0e\xa9\xd3ZX;\xfb\0\xbaӌ\x9d\x19p<T\x98\x92\xe5\xaaxܕ\xe2PQ@i"
github_key = "\0\0\0\assh-rsa\0\0\0\x01#\0\0\x01\x01\0\xab`;\x85\x11\xa6vy\xbd\xb5@\xdb;\xd2\x03K\0J\xe96\xd0k\xe3\xd7`\xf0\x8f˪\xdbN\xb4\xedóǑ\xc7\n\xae\x9at\xc9Xi\xe4wD!«\xea\x92\xe5T0_8\xb5\xfdAK2\b\xe5t\xc37\xe3 \x93e\x18F,vRɋ1\xe1n}\xa6R;\xd2\0t*dD\xd8?\xcd^\x172\xd06sǷ\x81\x15UH{U\xf0\xc4IO8)\xec\xe6\x0f\x94%Z\x95˚\xf57\xd7\xfc\x8c\x7f\xe4\x9e\xf3\x18GN\xf2\x92\t\x92\x05\"e\xb0\xa0n\xa6mJ\x16\x7f\xd9\xf3\xa4\x8a\x1aJ0~\xc1\xea\xaaQI\xa9i\xa6\xac]V\xa5\xefb~Q}\x81\xfbdO[t\\OG\x8e\xcd\b*\x94\x92\xf7D\xaa\xd3&\xf7l\x8cM\xc9\x10\vƫyF\x1d&W\xcbo\x06\xde\xc9.kd\xa6V/\xf0\xe3 \x84\xea\x06\xce\x0e\xa9\xd3ZX;\xfb\0\xbaӌ\x9d\x19p<T\x98\x92\xe5\xaaxܕ\xe2PQ@i" |> codeunits |> collect
# hashes of the middle github.com fingerprint
gitlab_key = "\0\0\0\vssh-ed25519\0\0\0 \a\xee\br\x95N:\xae\xc6\xfbz\bέtn\x12.\x9dA\xb6\x7f\xe79\xe1\xc7\x13\x95\x0e\xcd\x17_"
gitlab_key = "\0\0\0\vssh-ed25519\0\0\0 \a\xee\br\x95N:\xae\xc6\xfbz\bέtn\x12.\x9dA\xb6\x7f\xe79\xe1\xc7\x13\x95\x0e\xcd\x17_" |> codeunits |> collect

# various known hosts files
no_file = tempname()
Expand Down

0 comments on commit dbaca8b

Please sign in to comment.