-
Notifications
You must be signed in to change notification settings - Fork 361
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
GH-590: Be more careful with Bouncy Castle in FIPS environment #591
Conversation
Thanks for the PR but hardcoded "BC" gives me this:
|
as long as there is this check still using the hardcoded mina-sshd/sshd-common/src/main/java/org/apache/sshd/common/util/security/SecurityUtils.java Line 396 in 40a08a4
|
There is a test for this with this PR jenkinsci/mina-sshd-api-plugin#114 |
The exception you show above shows that you are trying to load an encrypted PEM key. (Starts with "-----BEGIN ENCRYPTED PRIVATE KEY-----"). AFAIK that is not possible in a FIPS environments as FIPS has no PBE/PBES2. So the exception is totally correct. |
Ah. Do you have any link for this? |
TBI have been always thinking this |
Hm. Actually, I had a link, but can't find it anymore. Anyway, it said bc-fips had no pbe... (not that FIPS didn't have it). Might be technically true since I don't see any such code in bundle bc-fips, but there's also bundle bcpkix-fips which seems to have the classes I was missing. I'll keep trying. |
that's failing my tests here jenkinsci/mina-sshd-api-plugin#114 |
@olamy: All right. The original idea was sound after all. With this PR at commit 9518312 and the following patch applied to your test jenkinsci/mina-sshd-api-plugin#114 that test succeeds. Patch:
Test run succeeds:
Note that I did not include the customizeable RandomFactory. Not sure it's needed; it'll use Two observations:
Your use case seems to be in Jenkins and apparently both libraries (BC and BCFIPS) may be present. That use case may still need its special-purpose registrar. Also you mentioned you'd not want to use the SunJCE AES, so a system property to disable the SunJCEWrapper registrar would be needed anyway if you don't override the registrars. (If you do -- as is currently the case -- that SunJCEWrapper won't be registered at all.) |
And in
|
@tomaswolf Thanks a lot!!
Right so it's not needed anymore.
Haha good catch. I was checking if String constants in System.setProperty were right but the problem was something else. Uhm I need some new glasses...
No we don't. If Jenkins is running in FIPS mode, the classic BC is not registered (not easy to figure when looking at the poms only but it's here https://github.com/jenkinsci/bouncycastle-api-plugin/blob/e27176eb46cbe94c1d1de6a9f318e3d538c34a4a/src/main/java/jenkins/bouncycastle/api/BouncyCastlePlugin.java#L27) |
this one ^ is still needed because we want to use BCFIPS.
Running few tests and this is looking really great. Thanks for your help. |
Right. However, for FIPS mode I think we may have another problem: we use our own ChaCha20-Poly1305 implementation, and we use the bcyrypt KDF for encrypted OpenSSH "new format" keys. Probably we should have a way to disable those if you want to run in FIPS mode? |
right as far as I understand Regarding
|
Yes: https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key I also think neither ChaCha20-Poly1305 nor bcrypt are covered by FIPS. For ChaCha20-Poly1305 we have two options: either we say it's the user's responsibility to configure the SshClient appropriately by removing the cipher via configuration ( The bcrypt thing is less critical. I don't know which KDF's are FIPS-approved, but I'd be surprised if bcrypt was. If not, anyone using this OpenSSH format for stored keys would deviate from FIPS anyway, so we could say it's entirely the user's responsibility. (As is using only PEM keys with FIPS-approved encryptions and KDFs.) Or we could use the aforementioned flag to also disable bcrypt (with the effect that such keys cannot be read or written in FIPS mode). Or we might only disable writing such files, while still allowing to read them. |
for BouncyCastle FIPS see section 6 of https://downloads.bouncycastle.org/fips-java/docs/BC-FJA-UserGuide-1.0.2.pdf Key Agreements are in Section 5 of the same document. |
LGTM
what about something such a general flag |
56571c6
to
31234de
Compare
So here's another commit on top of this PR for this single flag. See the commit message. With this, I think you don't need the
If the flag is set, a number of non-FIPS-approved crypto-algorithms get disabled (ed25519, curve25519, curve448, sntrup761, bcrypt, chacha20-poly1305). Disabling sntrup761 and curve25519 means that this FIPS mode is left without any post-quantum key exchange method. Can you test that this works for your use case in Jenkins? |
@tomaswolf Thanks a lot. I will test this. |
Signed-off-by: Olivier Lamy <olamy@apache.org>
@tomaswolf I did some successful testing.
|
That's strange. I did test this with your change, and it worked like a charm. I see the bug: at Line 310 in 890f93a
we must use |
Yes, correct. |
Edited my comments. There is indeed a bug; I missed one place where getName() must be replaced by getProviderName(). |
ah so I need to test again because I'm confused :) |
I'll push an update this evening. |
Thanks. |
Decouple the registrar name from the security provider name. In the BouncyCastleSecurityRegistrar, check also for BCFIPS if regular BC cannot be found. Also check whether the BC RandomGenerator exists at all; in BCFIPS, it doesn't.
Fall back to new SecureRandom() if we get a NoSuchAlgorithmException, which should never occur unless the JVM is wrongly configured. Every JVM must support at least one strong PRNG.
Done. The bug fix is https://github.com/apache/mina-sshd/compare/31234defad60f723ba5f3de4d2a7527784e46e49..8092f28b9f379e3652907a8cad3916e1163bc646#diff-b775cafcbee766e042f74d6790cbaa143b5f175756db29140865a41222e7b94aR310 . Hope I didn't miss anything else. |
@tomaswolf All is working fine. |
Thanks for testing. I'll finish this this evening (documentation needs some updates still), then merge.
I have a few other things to fix or clean-up first. But after that I'll ask our release manager if we could do a release. |
Add a flag in SecurityUtils to enable FIPS mode. In FIPS mode, algorithms known to be not FIPS-compliant are had disabled and not available. The BouncyCastleSecurityRegistrar only considers bc-fips, and the SunJCESecurityRegistrar and the EdDSASecurityRegistrar are disabled. The ChaCha20-Poly1305 cipher is disabled, ed25519 signatures are disabled, the bcrypt KDF used in OpenSSH-format encrypted private keys[1] is disabled, and the curve25519 and curve448 key exchange methods are disabled. Also disabled is the post-quantum sntrup761x25519-sha512 key exchange method. These disabled algorithms are not approved in FIPS 140. The flag can be set via a system property or by calling SecurityUtils.setFipsMode(). The system property is "org.apache.sshd.security.fipsEnabled" and takes the boolean value "true". Any other value does not enable FIPS mode. [1] https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key
Signed-off-by: Olivier Lamy <olamy@apache.org>
Decouple the registrar name from the security provider name. Also check whether the BC RandomGenerator exists at all; in BC-FIPS, it doesn't.