Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH clone fails against remotes running newer OpenSSH versions #17772

Closed
Keno opened this issue Aug 3, 2016 · 18 comments · Fixed by #17874
Closed

SSH clone fails against remotes running newer OpenSSH versions #17772

Keno opened this issue Aug 3, 2016 · 18 comments · Fixed by #17874
Assignees
Labels
packages Package management and loading
Milestone

Comments

@Keno
Copy link
Member

Keno commented Aug 3, 2016

libssh2 advertises support for diffie-hellman-group-exchange-sha256, but that kex protocol seems to be buggy or otherwise unsupported, causing Pkg clone failures if the remote has a decently up-to-date openssh. Right now GitHub does not have support for that protocol, but we should either patch libssh2 to disable this feature of figure out what's broken to avoid nasty surprises if GitHub upgrades.

@kshyatt kshyatt added the packages Package management and loading label Aug 3, 2016
@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

Seems to only be an issue with the mbedTLS backend, cc @wildart

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

@wildart
Copy link
Member

wildart commented Aug 3, 2016

I bet there is some flag that disables this protocol. Try to disable it with LIBSSH2_DH_GEX_NEW.

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

Ok, the solution is simple. The required numbers are larger than MBEDTLS_MPI_MAX_SIZE (2055 > 2048), so all random numbers are 0, and the server gets confused (and the client doesn't do error checking. We should bump MBEDTLS_MPI_MAX_SIZE (maybe to 3072). I have also started a PR to add proper error checking to libssh2 here: libssh2/libssh2#119.

@wildart
Copy link
Member

wildart commented Aug 3, 2016

make it, 4096

@wildart
Copy link
Member

wildart commented Aug 3, 2016

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

Oh, hold on, there's an even worse bug. libssh2 passes the desired number of bits, but the mbedtls api takes bytes.

@wildart
Copy link
Member

wildart commented Aug 3, 2016

That could be my fault.

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

Well, many people took a look at that code, and nobody caught it so far, so I think there's some collective blame to go around. Let's fix it in any case.

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

I wonder if fixing that would allow us to not have to patch the config file

@wildart
Copy link
Member

wildart commented Aug 3, 2016

I see. I used mbedtls_mpi_size instead of mbedtls_mpi_bitlen in gen_publickey_from_rsa in mbedtls.c.
No, I was correct.

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

No, I think that's correct.

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

The problem is in _libssh2_bn_rand

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

What we probably need to do is:

int _libssh2_bn_rand(bn, bits, top, bottom) {
    err = mbedtls_mpi_fill_random(bn, bits/8+1, mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg)
    // check err, etc
    // zero out top bits%8 bits
}

Do you want to take care of that? In that case I'll move on to something else.

@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

Hey, look we're not the only ones who were confused about that parameter: libssh2/libssh2#103

@wildart
Copy link
Member

wildart commented Aug 3, 2016

I'll fix it. Why do you need to zero out top bits%8 bits?

@wildart wildart self-assigned this Aug 3, 2016
@Keno
Copy link
Member Author

Keno commented Aug 3, 2016

Otherwise you get numbers that are too large by a couple of bits. I don't see a problem with that in the way the numbers are used by libssh2 (since g^x retains wrap-around properties), but I imagine it would be good to follow the API in any case?

@Keno Keno added this to the 0.5.0 milestone Aug 4, 2016
@wildart
Copy link
Member

wildart commented Aug 6, 2016

Indeed, problem was in incorrect byte size, so no config patch required. I'll submit libssh2-mbedtls patch ASAP.

tkelman pushed a commit that referenced this issue Aug 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages Package management and loading
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants