Skip to content

Commit

Permalink
simplify with last changes from Mina PR apache/mina-sshd#591
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy committed Oct 3, 2024
1 parent d820108 commit 750cbc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class FIPSRegistarInitPlugin extends Plugin {
public void start() throws Exception {
if(FIPS140.useCompliantAlgorithms() && Security.getProvider("BCFIPS") != null) {
LOG.info("register FIPSBouncyCastleSecurityProviderRegistar");
System.setProperty("org.apache.sshd.security.registrars", "io.jenkins.plugins.mina_sshd_api.core.bouncycastle_registar.FIPSBouncyCastleSecurityProviderRegistar");
//System.setProperty("org.apache.sshd.security.registrars", "io.jenkins.plugins.mina_sshd_api.core.bouncycastle_registar.FIPSBouncyCastleSecurityProviderRegistar");
System.setProperty("org.apache.sshd.security.fipsEnabled", "true");
System.setProperty("org.apache.sshd.security.defaultProvider", "BCFIPS");
} else {
LOG.config("not needed to register FIPSBouncyCastleSecurityProviderRegistar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -40,9 +41,14 @@ public void BCFIPSRegisteredRejectSSHkeyGen() throws Throwable {

String path = Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("id_rsa-keygen-rsa-2048")).getPath();
j.then(r -> {
Iterable<KeyPair> keyPairs = SecurityUtils.loadKeyPairIdentities(null, null,
Files.newInputStream(Path.of(path)) , FilePasswordProvider.of("theaustraliancricketteamisthebest"));
assertThat(keyPairs.iterator().next(), notNullValue());
try {
Iterable<KeyPair> keyPairs = SecurityUtils.loadKeyPairIdentities(null, null,
Files.newInputStream(Path.of(path)), FilePasswordProvider.of("theaustraliancricketteamisthebest"));
} catch (NoSuchAlgorithmException e) {
// all good
// we cannot use expected = NoSuchAlgorithmException.class
// as we get org.jvnet.hudson.test.RealJenkinsRule$StepException
}
});
}
}

0 comments on commit 750cbc6

Please sign in to comment.