From dbaca8ba16d406004c53cb211b9eaf8028f6b6be Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Sun, 24 Jan 2021 21:28:36 -0500 Subject: [PATCH] libgit2: fix for broken SSH host callback (#39364) --- deps/Versions.make | 2 +- .../LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/md5 | 1 + .../LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/sha512 | 1 + deps/patches/libgit2-hostkey.patch | 4 ++-- stdlib/LibGit2/src/callbacks.jl | 6 +++--- stdlib/LibGit2/test/libgit2.jl | 6 +++--- 6 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/md5 create mode 100644 deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/sha512 diff --git a/deps/Versions.make b/deps/Versions.make index 22a6c4d744135..b0b2e72f63f2e 100644 --- a/deps/Versions.make +++ b/deps/Versions.make @@ -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 diff --git a/deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/md5 b/deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/md5 new file mode 100644 index 0000000000000..fc98d12c46b63 --- /dev/null +++ b/deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/md5 @@ -0,0 +1 @@ +693080c66702c9ff106b0935f01d1f96 diff --git a/deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/sha512 b/deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/sha512 new file mode 100644 index 0000000000000..bf56d1c06d292 --- /dev/null +++ b/deps/checksums/LibGit2.v1.2.2+0.x86_64-apple-darwin.tar.gz/sha512 @@ -0,0 +1 @@ +f21d5846b443188a0c604255dce77603ea861db8d4c6fc55cebd5db6da07e94ae40f0a165221c95e13db9df8777fddb05f55c865f554f45e56cd442332a95336 diff --git a/deps/patches/libgit2-hostkey.patch b/deps/patches/libgit2-hostkey.patch index 16c0f3b13f621..f07d4d1e0a116 100644 --- a/deps/patches/libgit2-hostkey.patch +++ b/deps/patches/libgit2-hostkey.patch @@ -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( @@ -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; diff --git a/stdlib/LibGit2/src/callbacks.jl b/stdlib/LibGit2/src/callbacks.jl index 8eddb8c864644..18de45a994420 100644 --- a/stdlib/LibGit2/src/callbacks.jl +++ b/stdlib/LibGit2/src/callbacks.jl @@ -440,7 +440,7 @@ 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] @@ -448,6 +448,7 @@ function ssh_knownhost_check( 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( @@ -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 diff --git a/stdlib/LibGit2/test/libgit2.jl b/stdlib/LibGit2/test/libgit2.jl index 2479deeb31b6c..93e530aee5d8e 100644 --- a/stdlib/LibGit2/test/libgit2.jl +++ b/stdlib/LibGit2/test/libgit2.jl @@ -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 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()