-
Notifications
You must be signed in to change notification settings - Fork 349
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
Add support for openssh host key certificates #119
Conversation
7bf6e9f
to
edcfd33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like solid work in general, but it lacks unit tests and most important - a real live server that we can test this code...
sshd-common/src/main/java/org/apache/sshd/common/config/keys/OpenSshCertificate.java
Outdated
Show resolved
Hide resolved
sshd-common/src/main/java/org/apache/sshd/common/config/keys/OpenSshCertificate.java
Outdated
Show resolved
Hide resolved
...-common/src/main/java/org/apache/sshd/common/keyprovider/FileHostKeyCertificateProvider.java
Outdated
Show resolved
Hide resolved
...-common/src/main/java/org/apache/sshd/common/keyprovider/FileHostKeyCertificateProvider.java
Outdated
Show resolved
Hide resolved
sshd-common/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java
Outdated
Show resolved
Hide resolved
...-common/src/main/java/org/apache/sshd/common/config/keys/impl/OpenSSHCertificateDecoder.java
Show resolved
Hide resolved
sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
Outdated
Show resolved
Hide resolved
sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
Outdated
Show resolved
Hide resolved
sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
Outdated
Show resolved
Hide resolved
...-common/src/main/java/org/apache/sshd/common/keyprovider/FileHostKeyCertificateProvider.java
Outdated
Show resolved
Hide resolved
...-common/src/main/java/org/apache/sshd/common/keyprovider/FileHostKeyCertificateProvider.java
Outdated
Show resolved
Hide resolved
...-common/src/main/java/org/apache/sshd/common/keyprovider/FileHostKeyCertificateProvider.java
Show resolved
Hide resolved
sshd-common/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java
Outdated
Show resolved
Hide resolved
...common/src/main/java/org/apache/sshd/common/util/buffer/keys/OpenSSHCertPublicKeyParser.java
Outdated
Show resolved
Hide resolved
...common/src/main/java/org/apache/sshd/common/util/buffer/keys/OpenSSHCertPublicKeyParser.java
Show resolved
Hide resolved
sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a few minor issues remain + need to figure out the lazy-load solution
...-common/src/main/java/org/apache/sshd/common/config/keys/impl/OpenSSHCertificateDecoder.java
Outdated
Show resolved
Hide resolved
...-common/src/main/java/org/apache/sshd/common/keyprovider/FileHostKeyCertificateProvider.java
Outdated
Show resolved
Hide resolved
sshd-common/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java
Show resolved
Hide resolved
sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
Outdated
Show resolved
Hide resolved
sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
Outdated
Show resolved
Hide resolved
sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
Outdated
Show resolved
Hide resolved
Just a reminder - please rebase your branch on the latest master version (I pushed some changes in the last few days) so it will be easier to merge this change. I would still love to see some jUnit test code for the following scenarios:
|
Seems in order - I am willing to merge it in as-is (provided you have re-based it) and wait for a separate PR with unit tests - let me know how you would like to proceed. |
OpenSSH actually does a fallback to the plain host key, maybe we should do the same instead of aborting the connection if the certificate is invalid. Makes especially sense if the certificate is expired, you still want to be able to connect..
I am currently on the unit tests, having some issues with RSA key mismatch exception... 512 vs 256 .. need to investigate further... |
I can live with that - just a suggestion - you can make the behavior configurable via a property that you can retrieve from the session (default can be whatever you decide).
Great - will wait for you to let me know when you feel the code is ready for more review and merging. |
…guessing it from the actual public key
…nd ignore cert per default
Please note commit a8cdbde This relates to SSHD-895, if client and server negotiated e.g. rsa-sha512 the signature verification would fail with ssh-rsa retrieved from |
Merged with acknowledgement and many thanks (see 47f779f06cb345c7cb706cb81f1214c37dab1fda). Please note that I added a commit to fix some minor styling issues as well as update the relevant documentation. Please close this PR |
Thanks a lot, but it's not only server side support but also client side (I started with client side actually and had two different commits..). |
Sorry - too late now - the important thing is that the code is in
I have reviewed the code before merging and have reached the conclusion that I can live with the change you suggested - i.e., include the certified keys by default. I have decided though not to include the |
Ok, thanks. Changelog might just be misleading. |
Do you know what is missing from this to make client certificates work? I've been hacking away for a few nights to try and figure it out, and it feels like it nearly works if you simply remove the hard-coded check that only allows decoding the host cert variant here 47f779f#diff-4067485581e7df0fec6ea6f408772edbbcd5eb7a1d9833e5ed9130a1de9015d1R74 Then things nearly "just work", but currently I'm trying to debug the publickey auth process in https://tools.ietf.org/html/rfc4252#section-7 The mina client will send the RSA-CERT in the first SSH_MSG_USERAUTH_REQUEST, and the openssh server accepts it, but the followup SSH_MSG_USERAUTH_REQUEST that includes a signature fails on the openssh server side with
It to me looks like the mina client code it doing all the right things (I think), the instructions on https://tools.ietf.org/html/rfc4252#section-7 say that "The 'public key blob' may contain certificates" and the changes in this PR for Buffer encode the client cert into the Buffer when UserAuthPublicKey invokes Quick recap:
It seems to do all the right things (I think), but something appears to be wrong with the It's worth nothing that if I compare the verbose OpenSSH server-side output when compared with a a OpenSSH client making a successful client-based RSA-CERT connection and mina client, the output is identical right up until the error from above:
All the displayed public keys and signatures and algorithms displayed in the verbose OpenSSH server-side output are identical up to here If you could provide any guidance on what docs to read or any insights on what the problem may be, that would be great Thanks, |
What about verbose client-side output? Check what ssh -vvv tells you about the signature algorithm being used on the client side, and compare against the debug logging from the Apache sshd client. I think the error "key type does not match" comes from ssh-rsa.c. |
Looking deeper into the Apache MINA sshd code, I think the problem is in
|
Hi @tomaswolf Yes this is the problem, I had debugged the native OpenSSH client code and checked the raw buffer differences to come down to that same conclusion I haven't put together a formal PR for this yet but I plan to soon, but I'm still not entirely sure what the right process is for determining the right value to put here for the algo value. I can make it work with known, contrived values ( The followup, once that's determined, will be how to properly unit test it since mina sshd server-side doesn't support client cert based auth. I haven't investigated yet if it's plausible to unit test the client behavior in isolation or if the project will want complete end-to-end testing, which may require me to implement the server-side portion of this as well (I hope not, as I don't need that functionality) |
I've researched this some more and I don't think there's any place in the current mina-sshd project that maintains a map of these signature algorithms that are utilized, at least, not aliased to the values required here. The Best I can tell, it may be necessary to create a specific map of the signature values from the original type to the value required for this part of the |
I've cleaned up an implementation that works well for all currently supported OpenSSH certificate formats on my fork (diff preview: master...alex-sherwin:master) I'm currently just using a hacky integration test that tests all valid OpenSSH client cert types against a local OpenSSH sshd daemon (which are all working from MINA ssh client now):
I'm not testing I added function It also simply removes the host key type check in the OpenSSH certificate decoding, which didn't really need to be there (other then that currently only host certs were supported for any functionality). Perhaps this explicit check should be moved into the code path for the host key usage (but it appears there's already some filtering going on to discover host keys by type, so this check seems superficial) I've love to clean up the rest of this and make a PR, but since all client unit test code I can see uses MINA-based Do you have any suggestion for that? Or will I need to implement the server-side portion of this in tandem for the PR? Thanks, |
This is definitely going in the right direction, but will need more work before it could be incorporated into the main code. As for testing: I think testing against a real OpenSSH server would be great. Testing only against an Apache MINA sshd server is better than nothing, but it's inbreeding and actually only shows that both our client and server side can talk to each other. It doesn't show that either implements the SSH protocol correctly; they might both implement their own completely different protocol. But I don't know if the containers used for the CI builds on Travis do actually have OpenSSH, nor do I know what the best way to configure, create and tear down an OpenSSH server during tests would be. We do run tests on Windows; I suspect there at least we might not have an OpenSSH server available. Perhaps @lgoldstein has an idea... Some detail comments on your code: (can't comment directly on the preview diff)
|
Afaik, we don't have any client side test that can use an SSH server other than ours. We could work on that by using |
@alex-sherwin it could be a good idea to open a different issue as this PR is actually closed. |
Sure, I didn't mean to start a whole thread here, was originally just looking to solicit info on what may be missing from this PR's original changes Since it sounds like you're receptive to this change in general I'm happy to put together an initial PR tonight. I did see that testcontainers was already in use for the SFTP performance test, looked like a one-off thing to me so I wasn't sure if it was something the project wanted to adopt or not. But I totally agree that I think it makes sense to test against OpenSSH sshd so that you're testing mina client code against a different implementation. I have a lot of experience using testcontainers so I'm more then happy to use it in some unit tests for this PR Thanks for your input so far |
@gnodet @tomaswolf I've opened a JIRA here https://issues.apache.org/jira/browse/SSHD-1161 for this work A colleague & myself should hopefully have a PR ready in the next day or two |
Hello, |
I'm not a maintainer here, but, FYI, the features have all been merged and are covered by unit tests However there has been no stable release since those PR's were merged, and best I can tell the current 2.9.0-SNAPSHOT version has not been published to maven central (looking at https://repository.apache.org/content/groups/snapshots/org/apache/sshd/sshd-core/) So you'd have to build 2.9.0-SNAPSHOT yourself to use it currently |
I believe we merged these changes into the released 2.8.0 version |
This is part of SSHD-660. Would be happy to get some feedback.