http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java deleted file mode 100644 index 7df1c64..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.cipher; - -import java.util.EnumSet; -import java.util.Set; - -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class ECCurvesTest extends BaseTestSupport { - public ECCurvesTest() { - super(); - } - - @Test - public void testFromName() { - for (ECCurves expected : ECCurves.VALUES) { - String name = expected.getName(); - for (int index = 0; index < name.length(); index++) { - ECCurves actual = ECCurves.fromCurveName(name); - assertSame(name, expected, actual); - name = shuffleCase(name); - } - } - } - - @Test - public void testAllNamesListed() { - Set<ECCurves> listed = EnumSet.noneOf(ECCurves.class); - for (String name : ECCurves.NAMES) { - ECCurves c = ECCurves.fromCurveName(name); - assertNotNull("No curve for listed name=" + name, c); - assertTrue("Duplicated listed name: " + name, listed.add(c)); - } - - assertEquals("Mismatched listed vs. values", ECCurves.VALUES, listed); - } - - @Test - public void testFromKeySize() { - for (ECCurves expected : ECCurves.VALUES) { - String name = expected.getName(); - ECCurves actual = ECCurves.fromCurveSize(expected.getKeySize()); - assertSame(name, expected, actual); - } - } - - @Test - public void testFromCurveParameters() { - for (ECCurves expected : ECCurves.VALUES) { - String name = expected.getName(); - ECCurves actual = ECCurves.fromCurveParameters(expected.getParameters()); - assertSame(name, expected, actual); - } - } - - @Test - public void testFromKeyType() { - for (ECCurves expected : ECCurves.VALUES) { - String keyType = expected.getKeyType(); - for (int index = 0; index < keyType.length(); index++) { - ECCurves actual = ECCurves.fromKeyType(keyType); - assertSame(keyType, expected, actual); - keyType = shuffleCase(keyType); - } - } - } - - @Test - public void testAllKeyTypesListed() { - Set<ECCurves> listed = EnumSet.noneOf(ECCurves.class); - for (String name : ECCurves.KEY_TYPES) { - ECCurves c = ECCurves.fromKeyType(name); - assertNotNull("No curve for listed key type=" + name, c); - assertTrue("Duplicated listed key type: " + name, listed.add(c)); - } - - assertEquals("Mismatched listed vs. values", ECCurves.VALUES, listed); - } -}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java deleted file mode 100644 index 0daeb23..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.compression; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.List; -import java.util.Random; -import java.util.Set; - -import org.apache.sshd.common.NamedFactory; -import org.apache.sshd.common.NamedResource; -import org.apache.sshd.common.compression.BuiltinCompressions.ParseResult; -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; -import org.mockito.Mockito; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class BuiltinCompressionsTest extends BaseTestSupport { - public BuiltinCompressionsTest() { - super(); - } - - @Test - public void testFromFactoryName() { - for (BuiltinCompressions expected : BuiltinCompressions.VALUES) { - String name = expected.getName(); - - for (int index = 0; index < name.length(); index++) { - BuiltinCompressions actual = BuiltinCompressions.fromFactoryName(name); - assertSame(name, expected, actual); - name = shuffleCase(name); - } - } - } - - @Test - public void testAllConstantsCovered() throws Exception { - Set<BuiltinCompressions> avail = EnumSet.noneOf(BuiltinCompressions.class); - Field[] fields = BuiltinCompressions.Constants.class.getFields(); - for (Field f : fields) { - String name = (String) f.get(null); - BuiltinCompressions value = BuiltinCompressions.fromFactoryName(name); - assertNotNull("No match found for " + name, value); - assertTrue(name + " re-specified", avail.add(value)); - } - - assertEquals("Incomplete coverage", BuiltinCompressions.VALUES, avail); - } - - @Test - public void testParseCompressionsList() { - List<String> builtin = NamedResource.getNameList(BuiltinCompressions.VALUES); - List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName()); - Random rnd = new Random(); - for (int index = 0; index < (builtin.size() + unknown.size()); index++) { - Collections.shuffle(builtin, rnd); - Collections.shuffle(unknown, rnd); - - List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size()); - for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) { - boolean useBuiltin = false; - if (bIndex < builtin.size()) { - useBuiltin = uIndex >= unknown.size() || rnd.nextBoolean(); - } - - if (useBuiltin) { - weavedList.add(builtin.get(bIndex)); - bIndex++; - } else if (uIndex < unknown.size()) { - weavedList.add(unknown.get(uIndex)); - uIndex++; - } - } - - String fullList = GenericUtils.join(weavedList, ','); - ParseResult result = BuiltinCompressions.parseCompressionsList(fullList); - List<String> parsed = NamedResource.getNameList(result.getParsedFactories()); - List<String> missing = result.getUnsupportedFactories(); - - // makes sure not only that the contents are the same but also the order - assertListEquals(fullList + "[parsed]", builtin, parsed); - assertListEquals(fullList + "[unsupported]", unknown, missing); - } - } - - @Test - public void testResolveFactoryOnBuiltinValues() { - for (NamedFactory<Compression> expected : BuiltinCompressions.VALUES) { - String name = expected.getName(); - NamedFactory<Compression> actual = BuiltinCompressions.resolveFactory(name); - assertSame(name, expected, actual); - } - } - - @Test - public void testNotAllowedToRegisterBuiltinFactories() { - for (CompressionFactory expected : BuiltinCompressions.VALUES) { - try { - BuiltinCompressions.registerExtension(expected); - fail("Unexpected success for " + expected.getName()); - } catch (IllegalArgumentException e) { - // expected - ignored - } - } - } - - @Test(expected = IllegalArgumentException.class) - public void testNotAllowedToOverrideRegisteredFactories() { - CompressionFactory expected = Mockito.mock(CompressionFactory.class); - Mockito.when(expected.getName()).thenReturn(getCurrentTestName()); - - String name = expected.getName(); - try { - for (int index = 1; index <= Byte.SIZE; index++) { - BuiltinCompressions.registerExtension(expected); - assertEquals("Unexpected success at attempt #" + index, 1, index); - } - } finally { - BuiltinCompressions.unregisterExtension(name); - } - } - - @Test - public void testResolveFactoryOnRegisteredExtension() { - CompressionFactory expected = Mockito.mock(CompressionFactory.class); - Mockito.when(expected.getName()).thenReturn(getCurrentTestName()); - - String name = expected.getName(); - try { - assertNull("Extension already registered", BuiltinCompressions.resolveFactory(name)); - BuiltinCompressions.registerExtension(expected); - - NamedFactory<Compression> actual = BuiltinCompressions.resolveFactory(name); - assertSame("Mismatched resolved instance", expected, actual); - } finally { - NamedFactory<Compression> actual = BuiltinCompressions.unregisterExtension(name); - assertSame("Mismatched unregistered instance", expected, actual); - assertNull("Extension not un-registered", BuiltinCompressions.resolveFactory(name)); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java index a8132fb..b18c273 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java @@ -33,10 +33,11 @@ import org.apache.sshd.common.session.Session; import org.apache.sshd.common.session.SessionListener; import org.apache.sshd.server.SshServer; import org.apache.sshd.util.test.BaseTestSupport; +import org.apache.sshd.util.test.CommonTestSupportUtils; +import org.apache.sshd.util.test.CoreTestSupportUtils; import org.apache.sshd.util.test.JSchLogger; import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; import org.apache.sshd.util.test.SimpleUserInfo; -import org.apache.sshd.util.test.Utils; import org.junit.After; import org.junit.AfterClass; import org.junit.Assume; @@ -96,8 +97,8 @@ public class CompressionTest extends BaseTestSupport { public static void setupClientAndServer() throws Exception { JSchLogger.init(); - sshd = Utils.setupTestServer(MacTest.class); - sshd.setKeyPairProvider(Utils.createTestHostKeyProvider(MacTest.class)); + sshd = CoreTestSupportUtils.setupTestServer(MacTest.class); + sshd.setKeyPairProvider(CommonTestSupportUtils.createTestHostKeyProvider(MacTest.class)); sshd.start(); port = sshd.getPort(); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java index f9de9b1..94ce291 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java @@ -71,7 +71,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { URL url = getClass().getResource("sshd_config"); assertNotNull("Cannot locate test file", url); - Properties props = SshConfigFileReader.readConfigFile(url); + Properties props = ConfigFileReaderSupport.readConfigFile(url); assertFalse("No properties read", props.isEmpty()); assertTrue("Unexpected commented property data", GenericUtils.isEmpty(props.getProperty("ListenAddress"))); assertTrue("Unexpected non-existing property data", GenericUtils.isEmpty(props.getProperty(getCurrentTestName()))); @@ -86,55 +86,55 @@ public class SshConfigFileReaderTest extends BaseTestSupport { @Test public void testParseCiphersList() { List<? extends NamedResource> expected = BaseBuilder.DEFAULT_CIPHERS_PREFERENCE; - Properties props = initNamedResourceProperties(SshConfigFileReader.CIPHERS_CONFIG_PROP, expected); + Properties props = initNamedResourceProperties(ConfigFileReaderSupport.CIPHERS_CONFIG_PROP, expected); BuiltinCiphers.ParseResult result = SshConfigFileReader.getCiphers(PropertyResolverUtils.toPropertyResolver(props)); testParsedFactoriesList(expected, result.getParsedFactories(), result.getUnsupportedFactories()); } @Test public void testKnownDefaultCipherFactoriesList() { - testKnownDefaultFactoriesList(SshConfigFileReader.DEFAULT_CIPHERS, BuiltinCiphers::fromFactoryName, + testKnownDefaultFactoriesList(ConfigFileReaderSupport.DEFAULT_CIPHERS, BuiltinCiphers::fromFactoryName, GenericUtils.asSortedSet(String.CASE_INSENSITIVE_ORDER, "cast128-cbc", "arcfour")); } @Test public void testParseMacsList() { List<? extends NamedResource> expected = BaseBuilder.DEFAULT_MAC_PREFERENCE; - Properties props = initNamedResourceProperties(SshConfigFileReader.MACS_CONFIG_PROP, expected); + Properties props = initNamedResourceProperties(ConfigFileReaderSupport.MACS_CONFIG_PROP, expected); BuiltinMacs.ParseResult result = SshConfigFileReader.getMacs(PropertyResolverUtils.toPropertyResolver(props)); testParsedFactoriesList(expected, result.getParsedFactories(), result.getUnsupportedFactories()); } @Test public void testKnownDefaultMacFactoriesList() { - testKnownDefaultFactoriesList(SshConfigFileReader.DEFAULT_MACS, BuiltinMacs::fromFactoryName, + testKnownDefaultFactoriesList(ConfigFileReaderSupport.DEFAULT_MACS, BuiltinMacs::fromFactoryName, GenericUtils.asSortedSet(String.CASE_INSENSITIVE_ORDER, "[email protected]", "hmac-ripemd160", "hmac-sha2-256-96", "hmac-sha2-512-96")); } @Test public void testParseSignaturesList() { List<? extends NamedResource> expected = BaseBuilder.DEFAULT_SIGNATURE_PREFERENCE; - Properties props = initNamedResourceProperties(SshConfigFileReader.HOST_KEY_ALGORITHMS_CONFIG_PROP, expected); + Properties props = initNamedResourceProperties(ConfigFileReaderSupport.HOST_KEY_ALGORITHMS_CONFIG_PROP, expected); BuiltinSignatures.ParseResult result = SshConfigFileReader.getSignatures(PropertyResolverUtils.toPropertyResolver(props)); testParsedFactoriesList(expected, result.getParsedFactories(), result.getUnsupportedFactories()); } @Test public void testKnownDefaultSignatureFactoriesList() { - testKnownDefaultFactoriesList(SshConfigFileReader.DEFAULT_HOST_KEY_ALGORITHMS, BuiltinSignatures::fromFactoryName); + testKnownDefaultFactoriesList(ConfigFileReaderSupport.DEFAULT_HOST_KEY_ALGORITHMS, BuiltinSignatures::fromFactoryName); } @Test public void testParseKexFactoriesList() { List<? extends NamedResource> expected = BaseBuilder.DEFAULT_KEX_PREFERENCE; - Properties props = initNamedResourceProperties(SshConfigFileReader.KEX_ALGORITHMS_CONFIG_PROP, expected); + Properties props = initNamedResourceProperties(ConfigFileReaderSupport.KEX_ALGORITHMS_CONFIG_PROP, expected); BuiltinDHFactories.ParseResult result = SshConfigFileReader.getKexFactories(PropertyResolverUtils.toPropertyResolver(props)); testParsedFactoriesList(expected, result.getParsedFactories(), result.getUnsupportedFactories()); } @Test public void testKnownDefaultKexFactoriesList() { - testKnownDefaultFactoriesList(SshConfigFileReader.DEFAULT_KEX_ALGORITHMS, BuiltinDHFactories::fromFactoryName); + testKnownDefaultFactoriesList(ConfigFileReaderSupport.DEFAULT_KEX_ALGORITHMS, BuiltinDHFactories::fromFactoryName); } private static void testKnownDefaultFactoriesList(String factories, Function<? super String, ? extends NamedResource> resolver) { @@ -159,7 +159,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { public void testGetCompression() { Properties props = new Properties(); for (CompressionConfigValue expected : CompressionConfigValue.VALUES) { - props.setProperty(SshConfigFileReader.COMPRESSION_PROP, expected.name().toLowerCase()); + props.setProperty(ConfigFileReaderSupport.COMPRESSION_PROP, expected.name().toLowerCase()); NamedResource actual = SshConfigFileReader.getCompression(PropertyResolverUtils.toPropertyResolver(props)); assertNotNull("No match for " + expected.name(), actual); @@ -177,7 +177,8 @@ public class SshConfigFileReaderTest extends BaseTestSupport { } }; // must be lenient since we do not cover the full default spectrum - AbstractFactoryManager actual = SshConfigFileReader.configure(expected, PropertyResolverUtils.toPropertyResolver(props), true, true); + AbstractFactoryManager actual = SshConfigFileReader.configure( + expected, PropertyResolverUtils.toPropertyResolver(props), true, true); assertSame("Mismatched configured result", expected, actual); validateAbstractFactoryManagerConfiguration(expected, props, true); } @@ -237,7 +238,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { public void testInvalidDelimiter() throws IOException { String line = getClass().getSimpleName() + "+" + getCurrentTestName(); try (Reader rdr = new StringReader(line)) { - Properties props = SshConfigFileReader.readConfigFile(rdr, true); + Properties props = ConfigFileReaderSupport.readConfigFile(rdr, true); fail("Unexpected success: " + props); } } @@ -248,7 +249,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { String expected = getCurrentTestName(); Properties props; try (Reader rdr = new StringReader(name + "\t" + expected)) { - props = SshConfigFileReader.readConfigFile(rdr, true); + props = ConfigFileReaderSupport.readConfigFile(rdr, true); } String actual = props.getProperty(name); @@ -285,7 +286,8 @@ public class SshConfigFileReaderTest extends BaseTestSupport { } private static <M extends FactoryManager> M validateFactoryManagerCiphers(M manager, Properties props) { - return validateFactoryManagerCiphers(manager, props.getProperty(SshConfigFileReader.CIPHERS_CONFIG_PROP, SshConfigFileReader.DEFAULT_CIPHERS)); + return validateFactoryManagerCiphers(manager, + props.getProperty(ConfigFileReaderSupport.CIPHERS_CONFIG_PROP, ConfigFileReaderSupport.DEFAULT_CIPHERS)); } private static <M extends FactoryManager> M validateFactoryManagerCiphers(M manager, String value) { @@ -295,7 +297,8 @@ public class SshConfigFileReaderTest extends BaseTestSupport { } private static <M extends FactoryManager> M validateFactoryManagerSignatures(M manager, Properties props) { - return validateFactoryManagerSignatures(manager, props.getProperty(SshConfigFileReader.HOST_KEY_ALGORITHMS_CONFIG_PROP, SshConfigFileReader.DEFAULT_HOST_KEY_ALGORITHMS)); + return validateFactoryManagerSignatures(manager, + props.getProperty(ConfigFileReaderSupport.HOST_KEY_ALGORITHMS_CONFIG_PROP, ConfigFileReaderSupport.DEFAULT_HOST_KEY_ALGORITHMS)); } private static <M extends FactoryManager> M validateFactoryManagerSignatures(M manager, String value) { @@ -305,7 +308,8 @@ public class SshConfigFileReaderTest extends BaseTestSupport { } private static <M extends FactoryManager> M validateFactoryManagerMacs(M manager, Properties props) { - return validateFactoryManagerMacs(manager, props.getProperty(SshConfigFileReader.MACS_CONFIG_PROP, SshConfigFileReader.DEFAULT_MACS)); + return validateFactoryManagerMacs(manager, + props.getProperty(ConfigFileReaderSupport.MACS_CONFIG_PROP, ConfigFileReaderSupport.DEFAULT_MACS)); } private static <M extends FactoryManager> M validateFactoryManagerMacs(M manager, String value) { @@ -315,7 +319,8 @@ public class SshConfigFileReaderTest extends BaseTestSupport { } private static <M extends FactoryManager> M validateFactoryManagerCompressions(M manager, Properties props, boolean lenient) { - return validateFactoryManagerCompressions(manager, props.getProperty(SshConfigFileReader.COMPRESSION_PROP, SshConfigFileReader.DEFAULT_COMPRESSION), lenient); + return validateFactoryManagerCompressions(manager, + props.getProperty(ConfigFileReaderSupport.COMPRESSION_PROP, ConfigFileReaderSupport.DEFAULT_COMPRESSION), lenient); } private static <M extends FactoryManager> M validateFactoryManagerCompressions(M manager, String value, boolean lenient) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java deleted file mode 100644 index e9acf4d..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config; - -import java.util.concurrent.TimeUnit; - -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class TimeValueConfigTest extends BaseTestSupport { - public TimeValueConfigTest() { - super(); - } - - @Test - public void testDurationOf() { - Object[] values = { - "600", TimeUnit.SECONDS.toMillis(600L), - "10m", TimeUnit.MINUTES.toMillis(10L), - "1h30m", TimeUnit.MINUTES.toMillis(90L), - "2d", TimeUnit.DAYS.toMillis(2L), - "3w", TimeUnit.DAYS.toMillis(3L * 7L) - }; - for (int index = 0; index < values.length; index += 2) { - String s = (String) values[index]; - Number expected = (Number) values[index + 1]; - long actual = TimeValueConfig.durationOf(s); - assertEquals(s, expected.longValue(), actual); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java deleted file mode 100644 index 5588622..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sshd.common.config.keys; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -public class AuthorizedKeyEntryLoginOptionsParseTest extends BaseTestSupport { - private final String value; - private final String loginPart; - private final String keyPart; - private final Map<String, String> options; - - public AuthorizedKeyEntryLoginOptionsParseTest(String value, String loginPart, String keyPart, Map<String, String> options) { - this.value = value; - this.loginPart = loginPart; - this.keyPart = keyPart; - this.options = options; - } - - @Parameters(name = "{0}") - public static List<Object[]> parameters() { - List<Object[]> params = new ArrayList<>(); - addData(params, "ssh-rsa AAAAB2...19Q==", "[email protected]", "from=\"*.sales.example.net,!pc.sales.example.net\""); - addData(params, "ssh-dss AAAAC3...51R==", "example.net", "command=\"dump /home\"", "no-pty", "no-port-forwarding"); - addData(params, "ssh-dss AAAAB5...21S==", "", "permitopen=\"192.0.2.1:80\"", "permitopen=\"192.0.2.2:25\""); - addData(params, "ssh-rsa AAAA...==", "[email protected]", "tunnel=\"0\"", "command=\"sh /etc/netstart tun0\""); - addData(params, "ssh-rsa AAAA1C8...32Tv==", "[email protected]", "!restrict", "command=\"uptime\""); - addData(params, "ssh-rsa AAAA1f8...IrrC5==", "[email protected]", "restrict", "!pty", "command=\"nethack\""); - return params; - } - - private static void addData(List<Object[]> params, String keyData, String comment, String... comps) { - StringBuilder sb = new StringBuilder(); - - Map<String, String> optionsMap = new HashMap<>(); - for (String c : comps) { - if (sb.length() > 0) { - sb.append(','); - } - sb.append(c); - - int pos = c.indexOf('='); - if (pos > 0) { - String name = c.substring(0, pos); - String value = GenericUtils.stripQuotes(c.substring(pos + 1)).toString(); - String prev = optionsMap.put(name, value); - if (prev != null) { - optionsMap.put(name, prev + "," + value); - } - } else { - optionsMap.put(c, Boolean.toString(c.charAt(0) != AuthorizedKeyEntry.BOOLEAN_OPTION_NEGATION_INDICATOR)); - } - } - - int pos = sb.length(); - - sb.append(' ').append(keyData); - if (GenericUtils.isNotEmpty(comment)) { - sb.append(' ').append(comment); - } - - String value = sb.toString(); - params.add(new Object[] {value, value.substring(0, pos), value.substring(pos + 1), optionsMap}); - } - - @Test - public void testResolveEntryComponents() { - Map.Entry<String, String> actual = AuthorizedKeyEntry.resolveEntryComponents(value); - assertNotNull(value, actual); - assertEquals("login(" + value + ")", loginPart, actual.getKey()); - assertEquals("remainder(" + value + ")", keyPart, actual.getValue()); - } - - @Test - public void testParseLoginOptions() { - Map<String, String> parsed = AuthorizedKeyEntry.parseLoginOptions(loginPart); - options.forEach((key, expected) -> { - String actual = parsed.get(key); - assertEquals(key, expected, actual); - }); - assertEquals("Mismatched size", options.size(), parsed.size()); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "[" + value + "]"; - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java index d28e3df..2b0dec4 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java @@ -123,8 +123,10 @@ public class AuthorizedKeyEntryTest extends AuthorizedKeysTestSupport { } private PublickeyAuthenticator testAuthorizedKeysAuth(Collection<AuthorizedKeyEntry> entries) throws Exception { - Collection<PublicKey> keySet = AuthorizedKeyEntry.resolveAuthorizedKeys(PublicKeyEntryResolver.FAILING, entries); - PublickeyAuthenticator auth = AuthorizedKeyEntry.fromAuthorizedEntries(PublicKeyEntryResolver.FAILING, entries); + Collection<PublicKey> keySet = + AuthorizedKeyEntry.resolveAuthorizedKeys(PublicKeyEntryResolver.FAILING, entries); + PublickeyAuthenticator auth = + PublickeyAuthenticator.fromAuthorizedEntries(PublicKeyEntryResolver.FAILING, entries); for (PublicKey key : keySet) { assertTrue("Failed to authenticate with key=" + key.getAlgorithm(), auth.authenticate(getCurrentTestName(), key, null)); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java deleted file mode 100644 index acc349a..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config.keys; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.security.GeneralSecurityException; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.util.List; - -import org.apache.sshd.common.util.security.SecurityUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@Category({ NoIoTestCase.class }) -public class BuiltinIdentitiesTest extends BaseTestSupport { - private final BuiltinIdentities expected; - - public BuiltinIdentitiesTest(BuiltinIdentities expected) { - this.expected = expected; - } - - @Parameters(name = "{0}") - public static List<Object[]> parameters() { - return parameterize(BuiltinIdentities.VALUES); - } - - @BeforeClass // Dirty hack around the parameterized run - public static void testAllConstantsCovered() throws Exception { - Field[] fields = BuiltinIdentities.Constants.class.getFields(); - for (Field f : fields) { - int mods = f.getModifiers(); - if (!Modifier.isStatic(mods)) { - continue; - } - - if (!Modifier.isFinal(mods)) { - continue; - } - - Class<?> type = f.getType(); - if (!String.class.isAssignableFrom(type)) { - continue; - } - - String name = f.getName(); - String value = (String) f.get(null); - BuiltinIdentities id = BuiltinIdentities.fromName(value); - assertNotNull("No match found for field " + name + "=" + value, id); - } - } - - @Test - public void testFromName() { - String name = expected.getName(); - for (int index = 0, count = name.length(); index < count; index++) { - assertSame(name, expected, BuiltinIdentities.fromName(name)); - name = shuffleCase(name); - } - } - - @Test - public void testFromAlgorithm() { - String algorithm = expected.getAlgorithm(); - for (int index = 0, count = algorithm.length(); index < count; index++) { - assertSame(algorithm, expected, BuiltinIdentities.fromAlgorithm(algorithm)); - algorithm = shuffleCase(algorithm); - } - } - - @Test - public void testFromKey() throws GeneralSecurityException { - Assume.assumeTrue("Unsupported built-in identity", expected.isSupported()); - KeyPairGenerator gen = SecurityUtils.getKeyPairGenerator(expected.getAlgorithm()); - KeyPair kp = gen.generateKeyPair(); - outputDebugMessage("Checking built-in identity: %s", expected); - assertSame(expected + "[pair]", expected, BuiltinIdentities.fromKeyPair(kp)); - assertSame(expected + "[public]", expected, BuiltinIdentities.fromKey(kp.getPublic())); - assertSame(expected + "[private]", expected, BuiltinIdentities.fromKey(kp.getPrivate())); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java deleted file mode 100644 index 4c74ef5..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config.keys; - -import java.security.KeyPair; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import org.apache.sshd.common.cipher.ECCurves; -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.common.util.security.SecurityUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.apache.sshd.util.test.Utils; -import org.junit.AfterClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@Category({ NoIoTestCase.class }) -public class KeyRandomArtTest extends BaseTestSupport { - private static final Collection<KeyPair> KEYS = new LinkedList<>(); - - private final String algorithm; - private final int keySize; - private final KeyPair keyPair; - - public KeyRandomArtTest(String algorithm, int keySize) throws Exception { - this.algorithm = algorithm; - this.keySize = keySize; - this.keyPair = Utils.generateKeyPair(algorithm, keySize); - KEYS.add(this.keyPair); - } - - @Parameters(name = "algorithm={0}, key-size={1}") - public static List<Object[]> parameters() { - List<Object[]> params = new ArrayList<>(); - for (int keySize : RSA_SIZES) { - params.add(new Object[]{KeyUtils.RSA_ALGORITHM, keySize}); - } - - for (int keySize : DSS_SIZES) { - params.add(new Object[]{KeyUtils.DSS_ALGORITHM, keySize}); - } - - if (SecurityUtils.isECCSupported()) { - for (ECCurves curve : ECCurves.VALUES) { - params.add(new Object[]{KeyUtils.EC_ALGORITHM, curve.getKeySize()}); - } - } - - if (SecurityUtils.isEDDSACurveSupported()) { - for (int keySize : ED25519_SIZES) { - params.add(new Object[]{SecurityUtils.EDDSA, keySize}); - } - } - return params; - } - - @AfterClass - public static void dumpAllArts() throws Exception { - KeyRandomArt.combine(System.out, ' ', () -> KEYS); - } - - @Test - public void testRandomArtString() throws Exception { - KeyRandomArt art = new KeyRandomArt(keyPair.getPublic()); - assertEquals("Mismatched algorithm", algorithm, art.getAlgorithm()); - assertEquals("Mismatched key size", keySize, art.getKeySize()); - - String s = art.toString(); - String[] lines = GenericUtils.split(s, '\n'); - assertEquals("Mismatched lines count", KeyRandomArt.FLDSIZE_Y + 2, lines.length); - - for (int index = 0; index < lines.length; index++) { - String l = lines[index]; - if ((l.length() > 0) && (l.charAt(l.length() - 1) == '\r')) { - l = l.substring(0, l.length() - 1); - lines[index] = l; - } - System.out.append('\t').println(l); - - assertTrue("Mismatched line length #" + (index + 1) + ": " + l.length(), l.length() >= (KeyRandomArt.FLDSIZE_X + 2)); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsCloneTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsCloneTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsCloneTest.java deleted file mode 100644 index cb23591..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsCloneTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config.keys; - -import java.security.GeneralSecurityException; -import java.security.KeyPair; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.sshd.common.cipher.ECCurves; -import org.apache.sshd.common.keyprovider.KeyPairProvider; -import org.apache.sshd.common.util.ValidateUtils; -import org.apache.sshd.common.util.security.SecurityUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@Category({ NoIoTestCase.class }) -public class KeyUtilsCloneTest extends BaseTestSupport { - private final String keyType; - private final int keySize; - - public KeyUtilsCloneTest(String keyType, int keySize) { - this.keyType = ValidateUtils.checkNotNullAndNotEmpty(keyType, "No key type specified"); - this.keySize = keySize; - } - - @Parameters(name = "type={0}, size={1}") - public static List<Object[]> parameters() { - List<Object[]> list = new ArrayList<>(); - addTests(list, KeyPairProvider.SSH_DSS, DSS_SIZES); - addTests(list, KeyPairProvider.SSH_RSA, RSA_SIZES); - if (SecurityUtils.isECCSupported()) { - for (ECCurves curve : ECCurves.VALUES) { - if (!curve.isSupported()) { - continue; - } - addTests(list, curve.getKeyType(), Collections.singletonList(curve.getKeySize())); - } - } - if (SecurityUtils.isEDDSACurveSupported()) { - addTests(list, KeyPairProvider.SSH_ED25519, ED25519_SIZES); - } - return Collections.unmodifiableList(list); - } - - private static void addTests(List<Object[]> list, String keyType, Collection<Integer> sizes) { - for (Integer keySize : sizes) { - list.add(new Object[]{keyType, keySize}); - } - } - - @Test - @SuppressWarnings("checkstyle:avoidnestedblocks") - public void testKeyPairCloning() throws GeneralSecurityException { - outputDebugMessage("generateKeyPair(%s)[%d]", keyType, keySize); - KeyPair original = KeyUtils.generateKeyPair(keyType, keySize); - - outputDebugMessage("cloneKeyPair(%s)[%d]", keyType, keySize); - KeyPair cloned = KeyUtils.cloneKeyPair(keyType, original); - - String prefix = keyType + "[" + keySize + "]"; - assertNotSame(prefix + ": Key pair not cloned", original, cloned); - assertTrue(prefix + ": Cloned pair not equals", KeyUtils.compareKeyPairs(original, cloned)); - - { - PublicKey k1 = original.getPublic(); - PublicKey k2 = cloned.getPublic(); - assertNotSame(prefix + ": Public key not cloned", k1, k2); - assertTrue(prefix + ": Cloned public key not equals", KeyUtils.compareKeys(k1, k2)); - - String f1 = KeyUtils.getFingerPrint(k1); - String f2 = KeyUtils.getFingerPrint(k2); - assertEquals(prefix + ": Mismatched fingerprints", f1, f2); - } - - { - PrivateKey k1 = original.getPrivate(); - PrivateKey k2 = cloned.getPrivate(); - assertNotSame(prefix + ": Private key not cloned", k1, k2); - assertTrue(prefix + ": Cloned private key not equals", KeyUtils.compareKeys(k1, k2)); - } - } - -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java deleted file mode 100644 index c9457fa..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config.keys; - -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.security.PublicKey; -import java.util.AbstractMap.SimpleImmutableEntry; -import java.util.Arrays; -import java.util.Collection; - -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@Category({ NoIoTestCase.class }) -public class KeyUtilsFingerprintCaseSensitivityTest extends BaseTestSupport { - - // CHECKSTYLE:OFF - private static final String KEY_STRING = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7"; - // CHECKSTYLE:ON - private static final String MD5_PREFIX = "MD5:"; - private static final String MD5 = "24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e"; - private static final String MD5_FULL = MD5_PREFIX + MD5; - private static final String SHA1_PREFIX = "SHA1:"; - private static final String SHA1 = "ZNLzC6u+F37oq8BpEAwP69EQtoA"; - private static final String SHA1_FULL = SHA1_PREFIX + SHA1; - - private static PublicKey key; - - private String expected; - private String test; - - public KeyUtilsFingerprintCaseSensitivityTest(String expected, String test) { - this.expected = expected; - this.test = test; - } - - @BeforeClass - public static void beforeClass() throws GeneralSecurityException, IOException { - key = PublicKeyEntry.parsePublicKeyEntry(KEY_STRING).resolvePublicKey(PublicKeyEntryResolver.FAILING); - } - - @Parameters(name = "expected={0}, test={1}") - public static Collection<Object[]> parameters() { - return Arrays.asList( - new Object[] {MD5_FULL, MD5_FULL}, - new Object[] {MD5_FULL, MD5_FULL.toUpperCase()}, - new Object[] {MD5_FULL, MD5_FULL.toLowerCase()}, - new Object[] {MD5_FULL, MD5_PREFIX.toUpperCase() + MD5}, - new Object[] {MD5_FULL, MD5_PREFIX.toLowerCase() + MD5}, - new Object[] {MD5_FULL, MD5.toLowerCase()}, - new Object[] {MD5_FULL, MD5.toUpperCase()}, - new Object[] {SHA1_FULL, SHA1_FULL}, - new Object[] {SHA1_FULL, SHA1_PREFIX.toUpperCase() + SHA1}, - new Object[] {SHA1_FULL, SHA1_PREFIX.toLowerCase() + SHA1} - ); - } - - @Test - public void testCase() throws Exception { - assertEquals("Check failed", new SimpleImmutableEntry<>(true, expected), KeyUtils.checkFingerPrint(test, key)); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java deleted file mode 100644 index e78eaeb..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config.keys; - -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.security.PublicKey; -import java.security.spec.InvalidKeySpecException; -import java.util.AbstractMap.SimpleImmutableEntry; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.apache.sshd.common.digest.BuiltinDigests; -import org.apache.sshd.common.digest.DigestFactory; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@Category({ NoIoTestCase.class }) -public class KeyUtilsFingerprintGenerationTest extends BaseTestSupport { - private final PublicKey key; - private final DigestFactory digestFactory; - private final String expected; - - public KeyUtilsFingerprintGenerationTest(PublicKey key, DigestFactory digestFactory, String expected) { - this.key = key; - this.digestFactory = digestFactory; - this.expected = expected; - } - - @Parameters(name = "key={0}, digestFactory={1}, expected={2}") - public static Collection<Object[]> parameters() throws IOException, GeneralSecurityException { - List<? extends Map.Entry<String, List<? extends Map.Entry<DigestFactory, String>>>> keyEntries = - Collections.unmodifiableList(Arrays.asList( - new SimpleImmutableEntry<>( - // CHECKSTYLE:OFF - "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7", - // CHECKSTYLE:ON - Arrays.asList( - new SimpleImmutableEntry<>( - BuiltinDigests.md5, - "MD5:24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e" - ), - new SimpleImmutableEntry<>( - BuiltinDigests.sha256, - "SHA256:1wNOZO+/XgNGJMx8UUJst33V+bBMTz5EcL0B6y2iRv0" - ) - ) - ), - new SimpleImmutableEntry<>( - // CHECKSTYLE:OFF - "ssh-dss AAAAB3NzaC1kc3MAAACBAMg/IxsG5BxnF5gM7IKqqR0rftxZC+n5GlbO+J4H+iIb/KR8NBehkxG3CrBZMF96M2K1sEGYLob+3k4r71oWaPul8n5rt9kpd+JSq4iD2ygOyg6Kd1/YDBHoxneizy6I/bGsLwhAAKWcRNrXmYVKGzhrhvZWN12AJDq2mGdj3szLAAAAFQD7a2MltdUSF7FU3//SpW4WGjZbeQAAAIBf0nNsfKQL/TEMo7IpTrEMg5V0RnSigCX0+yUERS42GW/ZeCZBJw7oL2XZbuBtu63vMjDgVpnb92BdrcPgjJ7EFW6DlcyeuywStmg1ygXmDR2AQCxv0eX2CQgrdUczmRa155SDVUTvTQlO1IyKx0vwKAh1H7E3yJUfkTAJstbGYQAAAIEAtv+cdRfNevYFkp55jVqazc8zRLvfb64jzgc5oSJVc64kFs4yx+abYpGX9WxNxDlG6g2WiY8voDBB0YnUJsn0kVRjBKX9OceROxrfT4K4dVbQZsdt+SLaXWL4lGJFrFZL3LZqvySvq6xfhJfakQDDivW4hUOhFPXPHrE5/Ia3T7A= dsa-key-20130709", - // CHECKSTYLE:ON - Arrays.asList( - new SimpleImmutableEntry<>( - BuiltinDigests.md5, - "MD5:fb:29:14:8d:94:f9:1d:cf:6b:0e:a4:35:1d:83:44:2f" - ), - new SimpleImmutableEntry<>( - BuiltinDigests.sha256, - "SHA256:grxw4KhY1cK6eOczBWs7tDVvo9V0PQw4E1wN1gJvHlw" - ) - ) - ), - new SimpleImmutableEntry<>( - // CHECKSTYLE:OFF - "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBFImZtcTj842stlcVHLFBFxTEx7lu3jW9aZCvd0r9fUNKZ6LbRPh6l1oJ4ozArnw7XreQBUc5oNd9HB5RNJ8jl1nWXY5cXBA7McZrKZrYmk+zxNhH6UL+kMLaJkyngJHQw== root@osv-linux", - // CHECKSTYLE:ON - Arrays.asList( - new SimpleImmutableEntry<>( - BuiltinDigests.md5, - "MD5:e6:dc:a2:4f:5b:11:b2:3c:0f:e8:f6:d8:d1:01:e9:d3" - ), - new SimpleImmutableEntry<>( - BuiltinDigests.sha512, - "SHA512:4w6ZB78tmFWhpN2J50Ok6WeMJhZp1X0xN0EKWxZmRLcYDbCWhyJDe8lgrQKWqdTCMZ5aNEBl9xQUklcC5Gt2jg" - ) - ) - ) - )); - - List<Object[]> ret = new ArrayList<>(); - for (Map.Entry<String, ? extends Collection<? extends Map.Entry<DigestFactory, String>>> kentry : keyEntries) { - String keyValue = kentry.getKey(); - try { - PublicKey key = PublicKeyEntry.parsePublicKeyEntry(keyValue).resolvePublicKey(PublicKeyEntryResolver.FAILING); - for (Map.Entry<DigestFactory, String> dentry : kentry.getValue()) { - DigestFactory factory = dentry.getKey(); - String fingerprint = dentry.getValue(); - if (!factory.isSupported()) { - System.out.println("Skip unsupported digest: " + fingerprint); - continue; - } - - ret.add(new Object[]{key, factory, fingerprint}); - } - } catch (InvalidKeySpecException e) { - System.out.println("Skip unsupported key: " + keyValue); - } - } - - return ret; - } - - @Test - public void testFingerprint() throws Exception { - String name = digestFactory.getName(); - assertEquals( - String.format("Fingerprint does not match for digest %s", name), - expected, - KeyUtils.getFingerPrint(digestFactory, key) - ); - assertEquals( - String.format("Fingerprint check failed for digest %s", name), - new SimpleImmutableEntry<>(true, expected), - KeyUtils.checkFingerPrint(expected, digestFactory, key) - ); - assertEquals( - String.format("Fingerprint check succeeded for invalid digest %s", name), - new SimpleImmutableEntry<>(false, expected), - KeyUtils.checkFingerPrint(expected + "A", digestFactory, key) - ); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java deleted file mode 100644 index 0f7e07c..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config.keys; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.PosixFilePermission; -import java.security.DigestException; -import java.util.Collection; -import java.util.Date; -import java.util.Map; - -import org.apache.sshd.common.digest.BaseDigest; -import org.apache.sshd.common.digest.BuiltinDigests; -import org.apache.sshd.common.digest.Digest; -import org.apache.sshd.common.digest.DigestFactory; -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.common.util.OsUtils; -import org.apache.sshd.common.util.io.IoUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class KeyUtilsTest extends BaseTestSupport { - public KeyUtilsTest() { - super(); - } - - @Test - public void testGenerateFingerPrintOnException() { - for (DigestFactory info : BuiltinDigests.VALUES) { - if (!info.isSupported()) { - System.out.println("Skip unsupported digest: " + info.getAlgorithm()); - continue; - } - - Exception thrown = new DigestException(info.getAlgorithm() + ":" + info.getBlockSize()); - Digest digest = new BaseDigest(info.getAlgorithm(), info.getBlockSize()) { - @Override - public byte[] digest() throws Exception { - throw thrown; - } - }; - String actual = KeyUtils.getFingerPrint(new DigestFactory() { - @Override - public String getName() { - return getCurrentTestName(); - } - - @Override - public String getAlgorithm() { - return digest.getAlgorithm(); - } - - @Override - public boolean isSupported() { - return info.isSupported(); - } - - @Override - public int getBlockSize() { - return info.getBlockSize(); - } - - @Override - public Digest create() { - return digest; - } - }, getCurrentTestName()); - String expected = thrown.getClass().getSimpleName(); - assertEquals("Mismatched fingerprint for " + thrown.getMessage(), expected, actual); - } - } - - @Test - public void testGenerateDefaultFingerprintDigest() { - DigestFactory defaultValue = KeyUtils.getDefaultFingerPrintFactory(); - assertNotNull("No current default fingerprint digest factory", defaultValue); - try { - for (DigestFactory f : BuiltinDigests.VALUES) { - if (!f.isSupported()) { - System.out.println("Skip unsupported digest=" + f.getAlgorithm()); - continue; - } - - KeyUtils.setDefaultFingerPrintFactory(f); - - String data = getClass().getName() + "#" + getCurrentTestName() + "(" + f.getName() + ")"; - String expected = KeyUtils.getFingerPrint(f, data); - String actual = KeyUtils.getFingerPrint(data); - assertEquals("Mismatched fingerprint for digest=" + f.getName(), expected, actual); - } - } finally { - KeyUtils.setDefaultFingerPrintFactory(defaultValue); // restore the original - } - } - - @Test // see SSHD-606 - public void testValidateStrictKeyFilePermissions() throws IOException { - Path file = getTempTargetRelativeFile(getClass().getSimpleName(), getCurrentTestName()); - outputDebugMessage("%s deletion result=%s", file, Files.deleteIfExists(file)); - assertNull("Unexpected violation for non-existent file: " + file, KeyUtils.validateStrictKeyFilePermissions(file)); - - assertHierarchyTargetFolderExists(file.getParent()); - try (OutputStream output = Files.newOutputStream(file)) { - output.write((getClass().getName() + "#" + getCurrentTestName() + "@" + new Date(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8)); - } - - Collection<PosixFilePermission> perms = IoUtils.getPermissions(file); - if (GenericUtils.isEmpty(perms)) { - assertNull("Unexpected violation for no permissions file: " + file, KeyUtils.validateStrictKeyFilePermissions(file)); - } else if (OsUtils.isUNIX()) { - Map.Entry<String, Object> violation = null; - for (PosixFilePermission p : KeyUtils.STRICTLY_PROHIBITED_FILE_PERMISSION) { - if (perms.contains(p)) { - violation = KeyUtils.validateStrictKeyFilePermissions(file); - assertNotNull("Unexpected success for permission=" + p + " of file " + file + " permissions=" + perms, violation); - break; - } - } - - if (violation == null) { // we expect a failure since the parent does not have the necessary permissions - assertNotNull("Unexpected UNIX success for file " + file + " permissions=" + perms, KeyUtils.validateStrictKeyFilePermissions(file)); - } - } else { - assertNull("Unexpected Windows violation for file " + file + " permissions=" + perms, KeyUtils.validateStrictKeyFilePermissions(file)); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/PublicKeyEntryTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/PublicKeyEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/PublicKeyEntryTest.java deleted file mode 100644 index eee2d72..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/PublicKeyEntryTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common.config.keys; - -import java.security.GeneralSecurityException; -import java.security.PublicKey; -import java.security.spec.InvalidKeySpecException; -import java.util.Arrays; - -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class PublicKeyEntryTest extends BaseTestSupport { - public PublicKeyEntryTest() { - super(); - } - - @Test - public void testFallbackResolver() throws Exception { - PublicKeyEntry entry = // TODO use some - PublicKeyEntry.parsePublicKeyEntry( - GenericUtils.join( - Arrays.asList(getCurrentTestName(), "AAAA", getClass().getSimpleName()), ' ')); - for (PublicKeyEntryResolver resolver : new PublicKeyEntryResolver[]{ - null, PublicKeyEntryResolver.FAILING, PublicKeyEntryResolver.IGNORING}) { - try { - PublicKey key = entry.resolvePublicKey(resolver); - assertSame("Mismatched successful resolver", PublicKeyEntryResolver.IGNORING, resolver); - assertNull("Unexpected success for resolver=" + resolver + ": " + KeyUtils.getFingerPrint(key), key); - } catch (GeneralSecurityException e) { - assertObjectInstanceOf("Mismatched thrown exception for resolver=" + resolver, InvalidKeySpecException.class, e); - } - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/AESPrivateKeyObfuscatorTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/AESPrivateKeyObfuscatorTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/AESPrivateKeyObfuscatorTest.java deleted file mode 100644 index cc3c379..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/AESPrivateKeyObfuscatorTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sshd.common.config.keys.loader; - -import java.security.GeneralSecurityException; -import java.security.Key; -import java.util.List; -import java.util.Random; - -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; - -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.common.util.security.SecurityUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@Category({ NoIoTestCase.class }) -public class AESPrivateKeyObfuscatorTest extends BaseTestSupport { - private static final Random RANDOMIZER = new Random(System.currentTimeMillis()); - - private final int keyLength; - - public AESPrivateKeyObfuscatorTest(int keyLength) { - this.keyLength = keyLength; - } - - @Parameters(name = "keyLength={0}") - public static List<Object[]> parameters() { - List<Integer> lengths = AESPrivateKeyObfuscator.getAvailableKeyLengths(); - assertFalse("No lengths available", GenericUtils.isEmpty(lengths)); - return parameterize(lengths); - } - - @Test - public void testAvailableKeyLengthExists() throws GeneralSecurityException { - assertEquals("Not a BYTE size multiple", 0, keyLength % Byte.SIZE); - - byte[] iv = new byte[keyLength / Byte.SIZE]; - synchronized (RANDOMIZER) { - RANDOMIZER.nextBytes(iv); - } - - Key key = new SecretKeySpec(iv, AESPrivateKeyObfuscator.CIPHER_NAME); - Cipher c = SecurityUtils.getCipher(AESPrivateKeyObfuscator.CIPHER_NAME); - c.init(Cipher.DECRYPT_MODE, key); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParserTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParserTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParserTest.java deleted file mode 100644 index 482037d..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParserTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sshd.common.config.keys.loader.openssh; - -import java.net.URL; -import java.security.KeyPair; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.util.Collection; -import java.util.List; - -import org.apache.sshd.common.config.keys.AuthorizedKeyEntry; -import org.apache.sshd.common.config.keys.BuiltinIdentities; -import org.apache.sshd.common.config.keys.FilePasswordProvider; -import org.apache.sshd.common.config.keys.PrivateKeyEntryDecoder; -import org.apache.sshd.common.config.keys.PublicKeyEntryResolver; -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.common.util.ValidateUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.Assume; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@Category({ NoIoTestCase.class }) -public class OpenSSHKeyPairResourceParserTest extends BaseTestSupport { - private static final OpenSSHKeyPairResourceParser PARSER = OpenSSHKeyPairResourceParser.INSTANCE; - private final BuiltinIdentities identity; - - public OpenSSHKeyPairResourceParserTest(BuiltinIdentities identity) { - this.identity = identity; - } - - @Parameters(name = "type={0}") - public static List<Object[]> parameters() { - return parameterize(BuiltinIdentities.VALUES); - } - - @Test - public void testLoadKeyPairs() throws Exception { - Assume.assumeTrue(identity + " not supported", identity.isSupported()); - - String resourceKey = getClass().getSimpleName() + "-" + identity.getName().toUpperCase() + "-" + KeyPair.class.getSimpleName(); - URL urlKeyPair = getClass().getResource(resourceKey); - assertNotNull("Missing key-pair resource: " + resourceKey, urlKeyPair); - - Collection<KeyPair> pairs = PARSER.loadKeyPairs(urlKeyPair, FilePasswordProvider.EMPTY); - assertEquals("Mismatched pairs count", 1, GenericUtils.size(pairs)); - - URL urlPubKey = getClass().getResource(resourceKey + ".pub"); - assertNotNull("Missing public key resource: " + resourceKey, urlPubKey); - - List<AuthorizedKeyEntry> entries = AuthorizedKeyEntry.readAuthorizedKeys(urlPubKey); - assertEquals("Mismatched public keys count", 1, GenericUtils.size(entries)); - - AuthorizedKeyEntry entry = entries.get(0); - PublicKey pubEntry = entry.resolvePublicKey(PublicKeyEntryResolver.FAILING); - assertNotNull("Cannot retrieve public key", pubEntry); - - Class<? extends PublicKey> pubType = identity.getPublicKeyType(); - Class<? extends PrivateKey> prvType = identity.getPrivateKeyType(); - for (KeyPair kp : pairs) { - PublicKey pubKey = ValidateUtils.checkInstanceOf(kp.getPublic(), pubType, "Mismatched public key type"); - assertKeyEquals("Mismatched identity public key", pubEntry, pubKey); - - PrivateKey prvKey = ValidateUtils.checkInstanceOf(kp.getPrivate(), prvType, "Mismatched private key type"); - @SuppressWarnings("rawtypes") - PrivateKeyEntryDecoder decoder = - OpenSSHKeyPairResourceParser.getPrivateKeyEntryDecoder(prvKey); - assertNotNull("No private key decoder", decoder); - - if (decoder.isPublicKeyRecoverySupported()) { - @SuppressWarnings("unchecked") - PublicKey recKey = decoder.recoverPublicKey(prvKey); - assertKeyEquals("Mismatched recovered public key", pubKey, recKey); - } - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java deleted file mode 100644 index 69e6b66..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sshd.common.config.keys.loader.pem; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.PrivateKey; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.commons.ssl.PEMItem; -import org.apache.commons.ssl.PEMUtil; -import org.apache.sshd.common.config.keys.KeyUtils; -import org.apache.sshd.common.util.security.SecurityUtils; -import org.apache.sshd.util.test.BaseTestSupport; -import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory; -import org.apache.sshd.util.test.NoIoTestCase; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.junit.runners.Parameterized.UseParametersRunnerFactory; - -/** - * TODO Add javadoc - * - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests -@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class PKCS8PEMResourceKeyPairParserTest extends BaseTestSupport { - private final String algorithm; - private final int keySize; - - public PKCS8PEMResourceKeyPairParserTest(String algorithm, int keySize) { - this.algorithm = algorithm; - this.keySize = keySize; - } - - @Parameters(name = "{0} / {1}") - public static List<Object[]> parameters() { - List<Object[]> params = new ArrayList<>(); - for (Integer ks : RSA_SIZES) { - params.add(new Object[]{KeyUtils.RSA_ALGORITHM, ks}); - } - for (Integer ks : DSS_SIZES) { - params.add(new Object[]{KeyUtils.DSS_ALGORITHM, ks}); - } - return params; - } - - @Test // see SSHD-760 - public void testPkcs8() throws IOException, GeneralSecurityException { - KeyPairGenerator generator = SecurityUtils.getKeyPairGenerator(algorithm); - if (keySize > 0) { - generator.initialize(keySize); - } - KeyPair kp = generator.generateKeyPair(); - - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { - Collection<Object> items = new ArrayList<>(); - PrivateKey prv1 = kp.getPrivate(); - items.add(new PEMItem(prv1.getEncoded(), "PRIVATE KEY")); - byte[] bytes = PEMUtil.encode(items); - os.write(bytes); - os.close(); - - try (ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) { - KeyPair kp2 = SecurityUtils.loadKeyPairIdentity(getCurrentTestName(), bais, null); - - assertEquals("Mismatched public key", kp.getPublic(), kp2.getPublic()); - assertEquals("Mismatched private key", prv1, kp2.getPrivate()); - } - } - } - - @Override - public String toString() { - return getClass().getSimpleName() + "[" + algorithm + "/" + keySize + "]"; - } -}
