Repository navigation
Conversation
|
Hi libssh2 :) For what it's worth, this would be super helpful for Julia users with private GitHub repos as discussed in the issue @wildart referenced above. Cheers |
|
@EricForgy, is that an "independent" claim that the patch works as intended? |
|
Hi @bagder, not an independent claim (I'm not qualified). Just morale support :) If it helps, I'll see if someone in that Julia issue can help with an independent verification. @wildart, is there some simple thing I can do to help? It was a challenge for me just to get SSH working with GitHub in the first place, so I'm just hoping Julia gets fixed. |
09f7c8d to
8754165
Compare
|
I changed travis configuration to include to mbedtls support. |
| NAMES mbedtls libmbedtls libmbedx509 | ||
| PATHS | ||
| ${MBEDTLS_ROOT_DIR}/library | ||
| ${MBEDTLS_ROOT_DIR}/build/library |
There was a problem hiding this comment.
these should probably refer to an install tree, not a build tree (which certainly isn't guaranteed to be called "build")
|
What's the status of this? What's needed to move this forward? |
|
Just another friendly ping. I'd be happy to help out with whatever is needed here. |
|
@Keno did you try it out? |
| # download mbedtls sources | ||
| cd mbedtls | ||
| wget https://github.com/ARMmbed/mbedtls/archive/$MBEDTLS_SRC_ARCH.tar.gz | ||
| tar -xzf $MBEDTLS_SRC_ARCH.tar.gz |
There was a problem hiding this comment.
I realize that this file mainly exists to set up testing on TravisCI, but this doesn't work on macOS because wget is not available by default. You could conditionally substitute wget with curl -O -L. Alternatively, you could replace this file with something in the top-level CMakeLists.txt with the ExternalProject_Add command. I'm winging this, but it would be something like:
SET(MBEDTLS_SRC_ARCH mbedtls-2.2.1)
ExternalProject_Add(
URL https://github.com/ARMmbed/mbedtls/archive/${MBEDTLS_SRC_ARC}.tar.gz
PATCH patch -p0 < ../mbedtls.patch
CMAKE_ARGS -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_SHARED_MBEDTLS_LIBRARY=ON
BUILD_COMMAND make
INSTALL_COMMAND make install
)There was a problem hiding this comment.
ExternalProject is executed during the build time, however mbedtls installation is needed before the configuration step.
|
I finally got around to trying this out and it worked for me on all platforms that I tried (Linux, Mac, Windows). |
|
I was also able to get this to pass the tests on x86_64 ubuntu 14.04 via git clone https://github.com/ARMmbed/mbedtls -b mbedtls-2.2.1
git clone https://github.com/wildart/libssh2 -b mbedtls
mkdir -p mbedtls/build
mkdir -p libssh2/build
cd mbedtls
patch -p0 < ../libssh2/mbedtls/mbedtls.patch
cd build
cmake .. -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX=$PWD/../../usr
make -j`nproc` install
cd ../../libssh2/build
cmake .. -DCRYPTO_BACKEND=mbedTLS -DCMAKE_INSTALL_PREFIX=$PWD/../../usr
make -j`nproc` install
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/../../usr/lib ctest . |
| if(!ret) | ||
| ret = mbedtls_cipher_finish(ctx, output + olen, &finish_olen); | ||
|
|
||
| olen += finish_olen; |
There was a problem hiding this comment.
If mbedtls_ciper_reset() fails, olen and finish_olen will still be uninitialized. Adding them and using them in the _libssh2_mbedtls_safe_free() below will have unwanted behaviour.
There was a problem hiding this comment.
if any of the mbedtls_ calls fail then memcpy will not be executed with olen as parameter.
BTW, _libssh2_mbedtls_safe_free is called with osize not olen.
|
Did a quick pass over the PR.. As I'm not that familiar with the libssh2 internals, I cannot comment too much on correctness. I flagged things that seemed worth a second look. |
| return -1; /* failure */ | ||
|
|
||
| ret = mbedtls_rsa_pkcs1_verify(rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, | ||
| MBEDTLS_MD_SHA1, sig_len, hash, sig); |
There was a problem hiding this comment.
The length parameter here is the length of the hash, not the length of the signature, which is assumed to be rsa->len. That assumption should be verified, and SHA_DIGEST_LENGTH should be passed here.
| return -1; | ||
| } | ||
|
|
||
| mbedtls_rsa_context *pk_rsa = mbedtls_pk_rsa(pkey); |
There was a problem hiding this comment.
Verify that this is actually an RSA context first?
| /* Zero unsued bits above the most significant bit and if `top` is -1, | ||
| the most significant bit of the random number can be zero. */ | ||
| msb = bits; | ||
| if (top == -1) |
There was a problem hiding this comment.
I don't think this is correct. "Can be zero" just means that it's not forced to 1 as the other values of top do.
| to 1, so that the product of two such random numbers will always have 2*bits length. | ||
| */ | ||
| for(i=0;i<=top;++i) { | ||
| err = mbedtls_mpi_set_bit(bn, bits-i, 1); |
There was a problem hiding this comment.
bits - i - 1? It seems to me that the most significant bit is bits - 1, no?
There was a problem hiding this comment.
I thought bits is index of the most significant bit. because from kex.c _libssh2_bn_rand is called with following parameters
_libssh2_bn_rand(exchange_state->x, group_order * 8 - 1, 0, -1);
Why subtract 1, other then adjusting to 0-based bit index.
There was a problem hiding this comment.
Well, bits is definitely the number of bits of randomness, and we know bits are zero indexed, so say we want one bit of randomness, then 0 is the MSB which is bits-1, no?
|
I believe @wildart has addressed all the review comments I had. This is good to go from my perspective. |
|
Can any of the libssh2 maintainers review this please? Julia has been carrying this patch for a month or two and it's been working for our purposes. We want to get this PR upstreamed some day. What do you need us to do to get this moving in that direction, even slowly? |
|
Can you then please squash the patch series properly? Reviewing a patch series with some of the patches fixing mistakes in some of the earlier patches isn't very effective. Squash those that fix mistakes so that you only have distinct commits that each makes a logical change. |
|
@Keno do you have collaborator access to @wildart's fork to do that? Can also look at https://github.com/libssh2/libssh2/pull/106/files which just shows the end result. |
|
If the end result is the only thing to review, then the PR should be made as a single commit. Any considerations on fixing the autotools build script to support mbedTLS? Shouldn't we have some docs somewhere that describes this support and perhaps how you build libssh2 to use it? |
|
Yes, docs are an obvious omission. @wildart has been mia for a while so we'll have to either find someone with commit access to the fork (@Keno? hopefully he'll respond, maybe during the week) or open a new revised copy of the pr. mbedtls does not have an autotools build system itself. It has a simple makefile but I don't know if it's enough for our purposes. |
|
Yes, I should have access to wildart's fork. I'll squash this. |
|
Turns out I don't. Opening a new PR. |
|
continued in #132 |
This is mbedTLS crypto backend (libmbedcrypto) for libssh2 cryptography.