Enable 'curve25519-sha256@libssh.org' in DefaultConfig (Fixes #464)

This commit is contained in:
Jeroen van Erp
2018-11-16 11:48:15 +01:00
parent f71d34e106
commit 0301d4537f
4 changed files with 19 additions and 8 deletions

View File

@@ -109,6 +109,7 @@ public class DefaultConfig
if (bouncyCastleRegistered) { if (bouncyCastleRegistered) {
setKeyExchangeFactories( setKeyExchangeFactories(
new Curve25519SHA256.Factory(), new Curve25519SHA256.Factory(),
new Curve25519SHA256.FactoryLibSsh(),
new DHGexSHA256.Factory(), new DHGexSHA256.Factory(),
new ECDHNistP.Factory521(), new ECDHNistP.Factory521(),
new ECDHNistP.Factory384(), new ECDHNistP.Factory384(),

View File

@@ -61,7 +61,6 @@ import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.PublicKey;
import java.util.*; import java.util.*;
/** /**
@@ -360,8 +359,7 @@ public class SSHClient
* @throws TransportException if there was a transport-layer error * @throws TransportException if there was a transport-layer error
*/ */
public void authPublickey(String username, KeyProvider... keyProviders) public void authPublickey(String username, KeyProvider... keyProviders)
throws UserAuthException, throws UserAuthException, TransportException {
TransportException {
authPublickey(username, Arrays.<KeyProvider>asList(keyProviders)); authPublickey(username, Arrays.<KeyProvider>asList(keyProviders));
} }

View File

@@ -18,6 +18,8 @@ package com.hierynomus.sshj.test;
import net.schmizz.sshj.Config; import net.schmizz.sshj.Config;
import net.schmizz.sshj.DefaultConfig; import net.schmizz.sshj.DefaultConfig;
import net.schmizz.sshj.SSHClient; import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.transport.random.JCERandom;
import net.schmizz.sshj.transport.random.SingletonRandomFactory;
import org.apache.sshd.server.SshServer; import org.apache.sshd.server.SshServer;
import org.junit.After; import org.junit.After;
import org.junit.Rule; import org.junit.Rule;
@@ -32,6 +34,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
public abstract class BaseAlgorithmTest { public abstract class BaseAlgorithmTest {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());
private SingletonRandomFactory randomFactory = new SingletonRandomFactory(new JCERandom.Factory());
private DefaultConfig config = new DefaultConfig();
@Rule @Rule
public SshFixture fixture = new SshFixture(false); public SshFixture fixture = new SshFixture(false);
@@ -42,11 +46,12 @@ public abstract class BaseAlgorithmTest {
@Test @Test
public void shouldVerifyAlgorithm() throws IOException { public void shouldVerifyAlgorithm() throws IOException {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 10; i++) {
logger.info("--> Attempt {}", i); logger.info("--> Attempt {}", i);
configureServer(fixture.getServer()); configureServer(fixture.getServer());
fixture.start(); fixture.start();
Config config = getClientConfig(new DefaultConfig()); config.setRandomFactory(randomFactory);
Config config = getClientConfig(this.config);
SSHClient sshClient = fixture.connectClient(fixture.setupClient(config)); SSHClient sshClient = fixture.connectClient(fixture.setupClient(config));
assertThat("should be connected", sshClient.isConnected()); assertThat("should be connected", sshClient.isConnected());
sshClient.disconnect(); sshClient.disconnect();

View File

@@ -19,6 +19,7 @@ import com.hierynomus.sshj.test.BaseAlgorithmTest;
import net.schmizz.sshj.Config; import net.schmizz.sshj.Config;
import net.schmizz.sshj.DefaultConfig; import net.schmizz.sshj.DefaultConfig;
import net.schmizz.sshj.common.Factory; import net.schmizz.sshj.common.Factory;
import net.schmizz.sshj.transport.kex.Curve25519SHA256;
import net.schmizz.sshj.transport.kex.DHGexSHA1; import net.schmizz.sshj.transport.kex.DHGexSHA1;
import net.schmizz.sshj.transport.kex.DHGexSHA256; import net.schmizz.sshj.transport.kex.DHGexSHA256;
import net.schmizz.sshj.transport.kex.ECDHNistP; import net.schmizz.sshj.transport.kex.ECDHNistP;
@@ -38,15 +39,21 @@ import java.util.Collections;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class KeyExchangeTest extends BaseAlgorithmTest { public class KeyExchangeTest extends BaseAlgorithmTest {
@Parameterized.Parameters @Parameterized.Parameters(name = "algorithm={0}")
public static Collection<Object[]> getParameters() { public static Collection<Object[]> getParameters() {
return Arrays.asList(new Object[][]{ return Arrays.asList(new Object[][]{
{DHGEXServer.newFactory(BuiltinDHFactories.dhgex), new DHGexSHA1.Factory()}, {DHGEXServer.newFactory(BuiltinDHFactories.dhgex), new DHGexSHA1.Factory()},
{DHGEXServer.newFactory(BuiltinDHFactories.dhgex256), new DHGexSHA256.Factory()}, {DHGEXServer.newFactory(BuiltinDHFactories.dhgex256), new DHGexSHA256.Factory()},
{DHGServer.newFactory(BuiltinDHFactories.ecdhp256), new ECDHNistP.Factory256()}, {DHGServer.newFactory(BuiltinDHFactories.ecdhp256), new ECDHNistP.Factory256()},
{DHGServer.newFactory(BuiltinDHFactories.ecdhp384), new ECDHNistP.Factory384()}, {DHGServer.newFactory(BuiltinDHFactories.ecdhp384), new ECDHNistP.Factory384()},
{DHGServer.newFactory(BuiltinDHFactories.ecdhp521), new ECDHNistP.Factory521()} {DHGServer.newFactory(BuiltinDHFactories.ecdhp521), new ECDHNistP.Factory521()},
// Not supported yet by MINA {null, new Curve25519SHA256.Factory()} {DHGServer.newFactory(BuiltinDHFactories.dhg1), DHGroups.Group1SHA1()},
{DHGServer.newFactory(BuiltinDHFactories.dhg14), DHGroups.Group14SHA1()},
{DHGServer.newFactory(BuiltinDHFactories.dhg14_256), DHGroups.Group14SHA256()},
{DHGServer.newFactory(BuiltinDHFactories.dhg15_512), DHGroups.Group15SHA512()},
{DHGServer.newFactory(BuiltinDHFactories.dhg16_512), DHGroups.Group16SHA512()},
{DHGServer.newFactory(BuiltinDHFactories.dhg17_512), DHGroups.Group17SHA512()},
{DHGServer.newFactory(BuiltinDHFactories.dhg18_512), DHGroups.Group18SHA512()},
}); });
} }