You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2014/01/28 00:39:45 UTC
[5/7] git commit: [SSHD-279] Add test run without BouncyCastle
[SSHD-279] Add test run without BouncyCastle
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/fc91658a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/fc91658a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/fc91658a
Branch: refs/heads/master
Commit: fc91658ad938f6d6872f560849b3c7f315e115dc
Parents: 2594818
Author: Guillaume Nodet <gn...@apache.org>
Authored: Tue Jan 28 00:37:05 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Tue Jan 28 00:37:05 2014 +0100
----------------------------------------------------------------------
sshd-core/pom.xml | 12 ++++++++++++
.../apache/sshd/common/util/SecurityUtils.java | 6 ++++++
.../src/test/java/org/apache/sshd/AgentTest.java | 10 ++++++++++
.../src/test/java/org/apache/sshd/CipherTest.java | 18 +++++++++++-------
.../PEMGeneratorHostKeyProviderTest.java | 17 +++++++++++++++--
.../SimpleGeneratorHostKeyProviderTest.java | 17 +++++++++++++++--
.../src/test/java/org/apache/sshd/util/Utils.java | 4 ++--
sshd-core/src/test/resources/spring.xml | 8 +-------
8 files changed, 72 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/pom.xml
----------------------------------------------------------------------
diff --git a/sshd-core/pom.xml b/sshd-core/pom.xml
index da5c00c..f7869e0 100644
--- a/sshd-core/pom.xml
+++ b/sshd-core/pom.xml
@@ -171,6 +171,18 @@
</systemProperties>
</configuration>
</execution>
+ <execution>
+ <id>jce</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <reportsDirectory>${project.build.directory}/surefire-reports-jce</reportsDirectory>
+ <systemProperties>
+ <org.apache.sshd.registerBouncyCastle>false</org.apache.sshd.registerBouncyCastle>
+ </systemProperties>
+ </configuration>
+ </execution>
</executions>
</plugin>
</plugins>
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
index 1669cf5..2b52c5a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
@@ -84,6 +84,12 @@ public class SecurityUtils {
private static void register() {
if (!registrationDone) {
+ if (registerBouncyCastle == null) {
+ String prop = System.getProperty("org.apache.sshd.registerBouncyCastle");
+ if (prop != null) {
+ registerBouncyCastle = Boolean.parseBoolean(prop);
+ }
+ }
if (securityProvider == null && (registerBouncyCastle == null || registerBouncyCastle)) {
// Use an inner class to avoid a strong dependency from SshServer on BouncyCastle
try {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AgentTest.java b/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
index eb91c39..0e2b39e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
@@ -34,6 +34,7 @@ import org.apache.sshd.agent.unix.AgentClient;
import org.apache.sshd.agent.unix.AgentServer;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.common.KeyPairProvider;
+import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
import org.apache.sshd.util.*;
@@ -51,6 +52,11 @@ public class AgentTest {
@Test
public void testAgent() throws Exception {
+ // TODO: revisit this test to work without BC
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
AgentServer agent = new AgentServer();
String authSocket;
try {
@@ -86,6 +92,10 @@ public class AgentTest {
@Test
public void testAgentForwarding() throws Exception {
+ // TODO: revisit this test to work without BC
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
int port1 = getFreePort();
int port2 = getFreePort();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java b/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
index 50e3b63..e03be24 100644
--- a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
@@ -37,6 +37,8 @@ import org.apache.sshd.common.cipher.TripleDESCBC;
import org.apache.sshd.common.cipher.CipherNone;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.apache.sshd.common.random.BouncyCastleRandom;
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
@@ -62,17 +64,19 @@ public class CipherTest {
}
@Test
- @Ignore("AES192CBC is not always available by default")
public void testAES192CBC() throws Exception {
- setUp(new AES192CBC.Factory());
- runTest();
+ if (SecurityUtils.isBouncyCastleRegistered()) {
+ setUp(new AES192CBC.Factory());
+ runTest();
+ }
}
@Test
- @Ignore("AES256CBC is not always available by default")
public void testAES256CBC() throws Exception {
- setUp(new AES256CBC.Factory());
- runTest();
+ if (SecurityUtils.isBouncyCastleRegistered()) {
+ setUp(new AES256CBC.Factory());
+ runTest();
+ }
}
@Test
@@ -119,7 +123,7 @@ public class CipherTest {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(port);
- sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
+ sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setCipherFactories(Arrays.<NamedFactory<org.apache.sshd.common.Cipher>>asList(cipher));
sshd.setShellFactory(new EchoShellFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
index 4825a1c..13d505e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
@@ -25,6 +25,7 @@ import java.io.File;
import java.security.spec.ECGenParameterSpec;
import org.apache.sshd.common.KeyPairProvider;
+import org.apache.sshd.common.util.SecurityUtils;
import org.junit.Test;
/**
@@ -68,7 +69,7 @@ public class PEMGeneratorHostKeyProviderTest {
// Generate
PEMGeneratorHostKeyProvider provider = new PEMGeneratorHostKeyProvider();
provider.setAlgorithm("RSA");
- provider.setKeySize(32);
+ provider.setKeySize(512);
provider.setPath(path.getPath());
assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
@@ -76,7 +77,7 @@ public class PEMGeneratorHostKeyProviderTest {
// Read existing
provider = new PEMGeneratorHostKeyProvider();
provider.setAlgorithm("RSA");
- provider.setKeySize(32);
+ provider.setKeySize(512);
provider.setPath(path.getPath());
assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
@@ -84,6 +85,10 @@ public class PEMGeneratorHostKeyProviderTest {
@Test
public void testEC_NISTP256() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");
@@ -108,6 +113,10 @@ public class PEMGeneratorHostKeyProviderTest {
@Test
public void testEC_NISTP384() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");
@@ -132,6 +141,10 @@ public class PEMGeneratorHostKeyProviderTest {
@Test
public void testEC_NISTP521() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
index c61a9b6..3d7057a 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
@@ -25,6 +25,7 @@ import java.io.File;
import java.security.spec.ECGenParameterSpec;
import org.apache.sshd.common.KeyPairProvider;
+import org.apache.sshd.common.util.SecurityUtils;
import org.junit.Test;
/**
@@ -68,7 +69,7 @@ public class SimpleGeneratorHostKeyProviderTest {
// Generate
SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
provider.setAlgorithm("RSA");
- provider.setKeySize(32);
+ provider.setKeySize(512);
provider.setPath(path.getPath());
assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
@@ -76,7 +77,7 @@ public class SimpleGeneratorHostKeyProviderTest {
// Read existing
provider = new SimpleGeneratorHostKeyProvider();
provider.setAlgorithm("RSA");
- provider.setKeySize(32);
+ provider.setKeySize(512);
provider.setPath(path.getPath());
assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
@@ -84,6 +85,10 @@ public class SimpleGeneratorHostKeyProviderTest {
@Test
public void testEC_NISTP256() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");
@@ -108,6 +113,10 @@ public class SimpleGeneratorHostKeyProviderTest {
@Test
public void testEC_NISTP384() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");
@@ -132,6 +141,10 @@ public class SimpleGeneratorHostKeyProviderTest {
@Test
public void testEC_NISTP521() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/src/test/java/org/apache/sshd/util/Utils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/Utils.java b/sshd-core/src/test/java/org/apache/sshd/util/Utils.java
index 816f7ce..6314779 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/Utils.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/Utils.java
@@ -30,8 +30,8 @@ import java.net.URL;
public class Utils {
public static KeyPairProvider createTestHostKeyProvider() {
-// return new SimpleGeneratorHostKeyProvider(null, "RSA");
- return createTestKeyPairProvider("hostkey.pem");
+ return new SimpleGeneratorHostKeyProvider(null, "RSA");
+// return createTestKeyPairProvider("hostkey.pem");
}
public static FileKeyPairProvider createTestKeyPairProvider(String resource) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fc91658a/sshd-core/src/test/resources/spring.xml
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/resources/spring.xml b/sshd-core/src/test/resources/spring.xml
index cd7f86d..f00638c 100644
--- a/sshd-core/src/test/resources/spring.xml
+++ b/sshd-core/src/test/resources/spring.xml
@@ -35,13 +35,7 @@
</bean>
</property>
<property name="keyPairProvider">
- <bean class="org.apache.sshd.common.keyprovider.FileKeyPairProvider">
- <constructor-arg>
- <list>
- <value>src/test/resources/hostkey.pem</value>
- </list>
- </constructor-arg>
- </bean>
+ <bean class="org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider" />
</property>
<property name="passwordAuthenticator">
<bean class="org.apache.sshd.util.BogusPasswordAuthenticator" />