You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/09/06 16:03:16 UTC
[06/51] [abbrv] mina-sshd git commit: [SSHD-842] Split common
utilities code from sshd-core into sshd-common (new artifact)
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseReaderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseReaderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseReaderTest.java
deleted file mode 100644
index 193aabd..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseReaderTest.java
+++ /dev/null
@@ -1,95 +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.util.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Date;
-
-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:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class NoCloseReaderTest extends BaseTestSupport {
- public NoCloseReaderTest() {
- super();
- }
-
- @Test
- public void testCanKeepReadingAfterClose() throws IOException {
- String expected = getClass().getName() + "#" + getCurrentTestName() + "@" + new Date();
- Path dir = createTempClassFolder();
- Path file = Files.write(dir.resolve(getCurrentTestName() + ".txt"), expected.getBytes(StandardCharsets.UTF_8));
- try (InputStream fileStream = Files.newInputStream(file);
- Reader rdr = new InputStreamReader(fileStream, StandardCharsets.UTF_8);
- Reader shielded = new NoCloseReader(rdr)) {
- int index = 0;
-
- int availLen = expected.length();
- for (; index < (availLen / 2); index++) {
- shielded.close();
-
- int readValue = shielded.read();
- if (readValue == -1) {
- fail("Premature EOF after shield read of " + index + " bytes");
- }
-
- char expValue = expected.charAt(index);
- char actValue = (char) (readValue & 0xFFFF);
- if (expValue != actValue) {
- fail("Mismatched shielded read value after " + index + " bytes");
- }
- }
-
- for (; index < availLen; index++) {
- int readValue = rdr.read();
- if (readValue == -1) {
- fail("Premature EOF after original read of " + index + " bytes");
- }
-
- char expValue = expected.charAt(index);
- char actValue = (char) (readValue & 0xFFFF);
- if (expValue != actValue) {
- fail("Mismatched original read value after " + index + " bytes");
- }
- }
-
- int readValue = shielded.read();
- assertEquals("Shielded EOF not signalled", -1, readValue);
-
- readValue = rdr.read();
- assertEquals("Original EOF not signalled", -1, readValue);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseWriterTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseWriterTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseWriterTest.java
deleted file mode 100644
index efc6a91..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseWriterTest.java
+++ /dev/null
@@ -1,73 +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.util.io;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Date;
-
-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:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class NoCloseWriterTest extends BaseTestSupport {
- public NoCloseWriterTest() {
- super();
- }
-
- @Test
- public void testCanKeepWritingAfterClose() throws IOException {
- Path dir = createTempClassFolder();
- Path file = dir.resolve(getCurrentTestName() + ".txt");
- Files.deleteIfExists(file);
-
- String expected = getClass().getName() + "#" + getCurrentTestName() + "@" + new Date();
- try (OutputStream fileStream = Files.newOutputStream(file);
- Writer w = new OutputStreamWriter(fileStream, StandardCharsets.UTF_8);
- Writer shielded = new NoCloseWriter(w)) {
- int index = 0;
- int availLen = expected.length();
- for (; index < (availLen / 2); index++) {
- shielded.close();
- shielded.write(expected.charAt(index));
- }
-
- w.write(expected, index, availLen - index);
- }
-
- byte[] actualBytes = Files.readAllBytes(file);
- String actual = new String(actualBytes, StandardCharsets.UTF_8);
- assertEquals(expected, actual);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullInputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullInputStreamTest.java
deleted file mode 100644
index bc97b9c..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullInputStreamTest.java
+++ /dev/null
@@ -1,118 +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.util.io;
-
-import java.io.EOFException;
-import java.io.IOException;
-
-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:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class NullInputStreamTest extends BaseTestSupport {
- private static final NullInputStream INSTANCE = new NullInputStream();
-
- public NullInputStreamTest() {
- super();
- }
-
- @Test
- public void testReadOneChar() throws IOException {
- assertEquals(-1, INSTANCE.read());
- }
-
- @Test
- public void testReadFullBuffer() throws IOException {
- assertEquals(-1, INSTANCE.read(new byte[Byte.SIZE]));
- }
-
- @Test
- public void testReadPartialBuffer() throws IOException {
- byte[] buf = new byte[Byte.SIZE];
- assertEquals(-1, INSTANCE.read(buf, buf.length / 2, (buf.length / 2) - 1));
- }
-
- @Test
- public void testSkip() throws IOException {
- assertEquals(0L, INSTANCE.skip(Long.SIZE));
- }
-
- @Test
- public void testAvailable() throws IOException {
- assertEquals(0, INSTANCE.available());
- }
-
- @Test
- public void testNotAllowedToAccessAfterClose() throws IOException {
- NullInputStream stream = new NullInputStream();
- stream.close();
- assertFalse("Stream not marked as closed", stream.isOpen());
-
- try {
- int nRead = stream.read();
- fail("Unexpected single byte read: " + nRead);
- } catch (EOFException e) {
- // expected
- }
-
- byte[] buf = new byte[Byte.SIZE];
- try {
- int nRead = stream.read(buf);
- fail("Unexpected full buffer read: " + nRead);
- } catch (EOFException e) {
- // expected
- }
-
- try {
- int nRead = stream.read(buf, buf.length / 2, (buf.length / 2) - 1);
- fail("Unexpected partial buffer read: " + nRead);
- } catch (EOFException e) {
- // expected
- }
-
- try {
- long skip = stream.skip(Long.SIZE);
- fail("Unexpected skip result: " + skip);
- } catch (EOFException e) {
- // expected
- }
-
- try {
- int nRead = stream.available();
- fail("Unexpected available count: " + nRead);
- } catch (IOException e) {
- // expected
- }
- try {
- stream.reset();
- fail("Unexpected reset success");
- } catch (EOFException e) {
- // expected
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullOutputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullOutputStreamTest.java
deleted file mode 100644
index b6a0230..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NullOutputStreamTest.java
+++ /dev/null
@@ -1,80 +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.util.io;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.util.Arrays;
-
-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:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class NullOutputStreamTest extends BaseTestSupport {
- public NullOutputStreamTest() {
- super();
- }
-
- @Test
- public void testNoAccessAllowedAfterClose() throws IOException {
- NullOutputStream stream = new NullOutputStream();
- stream.close();
- assertFalse("Stream not marked as closed", stream.isOpen());
-
- try {
- stream.write('a');
- fail("Unexpected single value write success");
- } catch (EOFException e) {
- // expected
- }
-
- byte[] buf = new byte[Byte.SIZE];
- try {
- Arrays.fill(buf, (byte) 0x41);
- stream.write(buf);
- fail("Unexpected full buffer write success");
- } catch (EOFException e) {
- // expected
- }
-
- try {
- Arrays.fill(buf, (byte) 0x42);
- stream.write(buf, buf.length / 2, (buf.length / 2) - 1);
- fail("Unexpected partial buffer write success");
- } catch (EOFException e) {
- // expected
- }
-
- try {
- stream.flush();
- fail("Unexpected flush success");
- } catch (EOFException e) {
- // expected
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1ClassTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1ClassTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1ClassTest.java
deleted file mode 100644
index 04bcb0e..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1ClassTest.java
+++ /dev/null
@@ -1,67 +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.util.io.der;
-
-import java.util.List;
-
-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:dev@mina.apache.org">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 ASN1ClassTest extends BaseTestSupport {
- private final ASN1Class expected;
-
- public ASN1ClassTest(ASN1Class expected) {
- this.expected = expected;
- }
-
- @Parameters(name = "{0}")
- public static List<Object[]> parameters() {
- return parameterize(ASN1Class.VALUES);
- }
-
- @Test
- public void testFromName() {
- String name = expected.name();
- for (int index = 1, count = name.length(); index <= count; index++) {
- assertSame(name, expected, ASN1Class.fromName(name));
- name = shuffleCase(name);
- }
- }
-
- @Test // NOTE: this also tests "fromTypeValue" since "fromDERValue" invokes it
- public void testFromDERValue() {
- assertSame(expected, ASN1Class.fromDERValue((expected.getClassValue() << 6) & 0xFF));
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1TypeTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1TypeTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1TypeTest.java
deleted file mode 100644
index 82b9611..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/ASN1TypeTest.java
+++ /dev/null
@@ -1,67 +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.util.io.der;
-
-import java.util.List;
-
-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:dev@mina.apache.org">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 ASN1TypeTest extends BaseTestSupport {
- private final ASN1Type expected;
-
- public ASN1TypeTest(ASN1Type expected) {
- this.expected = expected;
- }
-
- @Parameters(name = "{0}")
- public static List<Object[]> parameters() {
- return parameterize(ASN1Type.VALUES);
- }
-
- @Test
- public void testFromName() {
- String name = expected.name();
- for (int index = 1, count = name.length(); index <= count; index++) {
- assertSame(name, expected, ASN1Type.fromName(name));
- name = shuffleCase(name);
- }
- }
-
- @Test
- public void testFromTypeValue() {
- assertSame(expected, ASN1Type.fromTypeValue(expected.getTypeValue()));
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERParserTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERParserTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERParserTest.java
deleted file mode 100644
index df8e992..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERParserTest.java
+++ /dev/null
@@ -1,61 +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.util.io.der;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StreamCorruptedException;
-
-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:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class DERParserTest extends BaseTestSupport {
- public DERParserTest() {
- super();
- }
-
- @Test
- public void testReadLengthConstraint() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- try (DERWriter w = new DERWriter(baos)) {
- w.writeLength(DERParser.MAX_DER_VALUE_LENGTH + 1);
- }
- } finally {
- baos.close();
- }
-
- try (DERParser parser = new DERParser(baos.toByteArray())) {
- int len = parser.readLength();
- fail("Unexpected success: len=" + len);
- } catch (StreamCorruptedException e) {
- // expected ignored
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERWriterTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERWriterTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERWriterTest.java
deleted file mode 100644
index 9abe446..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/der/DERWriterTest.java
+++ /dev/null
@@ -1,64 +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.util.io.der;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-
-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:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class DERWriterTest extends BaseTestSupport {
- public DERWriterTest() {
- super();
- }
-
- @Test
- public void testWriteStripLeadingZeroes() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- try (DERWriter w = new DERWriter(baos)) {
- w.writeBigInteger(BigInteger.valueOf(-1));
- w.writeBigInteger(BigInteger.valueOf(129));
- w.writeBigInteger(new byte[] {0, 0}, 0, 2);
- w.writeBigInteger(new byte[] {0, 1}, 0, 2);
- }
- } finally {
- baos.close();
- }
-
- try (DERParser parser = new DERParser(baos.toByteArray())) {
- assertEquals(BigInteger.valueOf(255), parser.readBigInteger());
- assertEquals(BigInteger.valueOf(129), parser.readBigInteger());
- assertEquals(BigInteger.valueOf(0), parser.readBigInteger());
- assertEquals(BigInteger.valueOf(1), parser.readBigInteger());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java
deleted file mode 100644
index cc69df5..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java
+++ /dev/null
@@ -1,88 +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.util.net;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-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:dev@mina.apache.org">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 SshdSocketIpv6AddressTest extends BaseTestSupport {
- public static final List<String> VALID_ADDRESSES =
- Collections.unmodifiableList(
- Arrays.asList(
- "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "2001:db8:85a3:0:0:8a2e:370:7334",
- "2001:db8:85a3::8a2e:370:7334",
- "2001:0db8::0001", "2001:db8::1",
- "2001:db8:0:0:0:0:2:1", "2001:db8::2:1",
- "2001:db8:0000:1:1:1:1:1", "2001:db8:0:1:1:1:1:1",
- "2001:db8:85a3:8d3:1319:8a2e:370:7348",
- "fe80::1ff:fe23:4567:890a", "fe80::1ff:fe23:4567:890a%eth2",
- "fe80::1ff:fe23:4567:890a%3", "fe80:3::1ff:fe23:4567:890a",
- "::ffff:c000:0280", "::ffff:192.0.2.128"));
-
- private final String address;
- private final boolean matches;
-
- public SshdSocketIpv6AddressTest(String address, boolean matches) {
- this.address = address;
- this.matches = matches;
- }
-
- @Parameters(name = "{0}")
- public static List<Object[]> parameters() {
- return Stream
- .concat(SshdSocketAddress.WELL_KNOWN_IPV6_ADDRESSES.stream(), VALID_ADDRESSES.stream())
- .map(address -> new Object[] {address, Boolean.TRUE})
- .collect(Collectors.toList());
- }
-
- @Test
- public void testIPv6AddressValidity() {
- assertEquals(address, matches, SshdSocketAddress.isIPv6Address(address));
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName()
- + "[address=" + address
- + " , matches=" + matches
- + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java
deleted file mode 100644
index c0c89eb..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java
+++ /dev/null
@@ -1,75 +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.util.security;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.crypto.Cipher;
-
-import org.apache.sshd.common.cipher.BuiltinCiphers;
-import org.apache.sshd.common.cipher.CipherInformation;
-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:dev@mina.apache.org">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 SecurityProviderRegistrarCipherNameTest extends BaseTestSupport {
- private final CipherInformation cipherInfo;
-
- public SecurityProviderRegistrarCipherNameTest(CipherInformation cipherInfo) {
- this.cipherInfo = cipherInfo;
- }
-
- @Parameters(name = "{0}")
- public static List<Object[]> parameters() {
- List<Object[]> params = new ArrayList<>();
- for (CipherInformation cipherInfo : BuiltinCiphers.VALUES) {
- String algorithm = cipherInfo.getAlgorithm();
- String xform = cipherInfo.getTransformation();
- if (!xform.startsWith(algorithm)) {
- continue;
- }
-
- params.add(new Object[]{cipherInfo});
- }
- return params;
- }
-
- @Test
- public void testGetEffectiveSecurityEntityName() {
- String expected = cipherInfo.getAlgorithm();
- String actual = SecurityProviderRegistrar.getEffectiveSecurityEntityName(Cipher.class, cipherInfo.getTransformation());
- assertEquals("Mismatched pure cipher name", expected, actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarTestSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarTestSupport.java
deleted file mode 100644
index 57999de..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarTestSupport.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.util.security;
-
-import java.security.Provider;
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.experimental.categories.Category;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@Category({ NoIoTestCase.class })
-public abstract class SecurityProviderRegistrarTestSupport extends BaseTestSupport {
- protected SecurityProviderRegistrarTestSupport() {
- super();
- }
-
- public static Provider testGetSecurityProviderCaching(String prefix, SecurityProviderRegistrar registrar) {
- return testGetSecurityProviderCaching(prefix, registrar, registrar.getSecurityProvider());
- }
-
- public static <P extends Provider> P testGetSecurityProviderCaching(String prefix, SecurityProviderRegistrar registrar, P expected) {
- for (int index = 1; index <= Byte.SIZE; index++) {
- Provider actual = registrar.getSecurityProvider();
- assertSame(prefix + ": Mismatched provider instance at invocation #" + index, expected, actual);
- }
-
- return expected;
- }
-
- public static void assertSecurityEntitySupportState(
- String prefix, SecurityProviderRegistrar registrar, boolean expected, String name, Class<?>... entities) {
- assertSecurityEntitySupportState(prefix, registrar, expected, name, Arrays.asList(entities));
- }
-
- public static void assertSecurityEntitySupportState(
- String prefix, SecurityProviderRegistrar registrar, boolean expected, String name, Collection<Class<?>> entities) {
- for (Class<?> entity : entities) {
- assertEquals(prefix + "[" + entity.getSimpleName() + "]", expected, registrar.isSecurityEntitySupported(entity, name));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EDDSAProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EDDSAProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EDDSAProviderTest.java
deleted file mode 100644
index d30fe92..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EDDSAProviderTest.java
+++ /dev/null
@@ -1,126 +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.util.security.eddsa;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.security.GeneralSecurityException;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.Signature;
-
-import org.apache.sshd.common.config.keys.AuthorizedKeyEntry;
-import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.buffer.Buffer;
-import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
-import org.apache.sshd.common.util.security.SecurityUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-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.runners.MethodSorters;
-
-import net.i2p.crypto.eddsa.EdDSAEngine;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class EDDSAProviderTest extends BaseTestSupport {
- private static KeyPair keyPair;
-
- public EDDSAProviderTest() {
- super();
- }
-
- @BeforeClass
- public static void checkProviderSupported() throws GeneralSecurityException {
- Assume.assumeTrue(SecurityUtils.EDDSA + " not supported", SecurityUtils.isEDDSACurveSupported());
- KeyPairGenerator g = SecurityUtils.getKeyPairGenerator(SecurityUtils.EDDSA);
- assertNotNull("No generator instance", g);
-
- keyPair = g.generateKeyPair();
- assertNotNull("No key pair generated", keyPair);
-
- PublicKey pubKey = keyPair.getPublic();
- assertNotNull("No public key", pubKey);
- assertEquals("Mismatched public key algorithm", SecurityUtils.EDDSA, pubKey.getAlgorithm());
- assertEquals("Mismatched public key type", KeyPairProvider.SSH_ED25519, KeyUtils.getKeyType(pubKey));
-
- PrivateKey prvKey = keyPair.getPrivate();
- assertNotNull("No private key", prvKey);
- assertEquals("Mismatched key-pair algorithm", pubKey.getAlgorithm(), prvKey.getAlgorithm());
- assertEquals("Mismatched private key type", KeyPairProvider.SSH_ED25519, KeyUtils.getKeyType(prvKey));
- }
-
- @Test
- public void testSignature() throws GeneralSecurityException {
- Signature s = SecurityUtils.getSignature(EdDSAEngine.SIGNATURE_ALGORITHM);
- assertNotNull("No signature instance", s);
- s.initSign(keyPair.getPrivate());
-
- byte[] data = (getClass().getName() + "#" + getCurrentTestName()).getBytes(StandardCharsets.UTF_8);
- s.update(data);
- byte[] signed = s.sign();
-
- s = SecurityUtils.getSignature(EdDSAEngine.SIGNATURE_ALGORITHM);
- s.initVerify(keyPair.getPublic());
- s.update(data);
- assertTrue("Failed to verify", s.verify(signed));
- }
-
- @Test
- public void testPublicKeyEntryDecoder() throws IOException, GeneralSecurityException {
- String comment = getCurrentTestName() + "@" + getClass().getSimpleName();
- String expected = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGPKSUTyz1HwHReFVvD5obVsALAgJRNarH4TRpNePnAS " + comment;
- AuthorizedKeyEntry keyEntry = AuthorizedKeyEntry.parseAuthorizedKeyEntry(expected);
- assertNotNull("No extracted key entry", keyEntry);
-
- assertEquals("Mismatched key type", KeyPairProvider.SSH_ED25519, keyEntry.getKeyType());
- assertEquals("Mismatched comment", comment, keyEntry.getComment());
-
- StringBuilder sb = new StringBuilder(expected.length());
- PublicKey pubKey = keyEntry.appendPublicKey(sb, null);
- assertEquals("Mismatched encoded result", expected, sb.toString());
-
- testPublicKeyRecovery(pubKey);
- }
-
- @Test
- public void testGeneratedPublicKeyRecovery() throws IOException, GeneralSecurityException {
- testPublicKeyRecovery(keyPair.getPublic());
- }
-
- private void testPublicKeyRecovery(PublicKey pubKey) throws IOException, GeneralSecurityException {
- assertNotNull("No public key generated", pubKey);
- assertEquals("Mismatched public key algorithm", SecurityUtils.EDDSA, pubKey.getAlgorithm());
-
- Buffer buf = SecurityUtils.putRawEDDSAPublicKey(new ByteArrayBuffer(), pubKey);
- PublicKey actual = buf.getRawPublicKey();
- assertEquals("Mismatched key algorithm", pubKey.getAlgorithm(), actual.getAlgorithm());
- assertEquals("Mismatched recovered key", pubKey, actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java
deleted file mode 100644
index 23e5517..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java
+++ /dev/null
@@ -1,238 +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.util.security.eddsa;
-
-import java.nio.charset.StandardCharsets;
-import java.security.GeneralSecurityException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.sshd.common.signature.Signature;
-import org.apache.sshd.common.util.buffer.BufferUtils;
-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;
-
-import net.i2p.crypto.eddsa.EdDSAPrivateKey;
-import net.i2p.crypto.eddsa.EdDSAPublicKey;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- * @see <A HREF="https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02#section-6">
- * EdDSA and Ed25519 draft-josefsson-eddsa-ed25519-02 - section 6 - Test Vectors for Ed25519</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 Ed25519VectorsTest extends BaseTestSupport {
- private final byte[] prvBytes;
- private final PrivateKey privateKey;
- private final byte[] pubBytes;
- private final PublicKey publicKey;
- private final byte[] msgBytes;
- private final byte[] expSignature;
-
- public Ed25519VectorsTest(String name, String prvKey, String pubKey, String msg, String signature)
- throws GeneralSecurityException {
- prvBytes = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, prvKey);
- privateKey = EdDSASecurityProviderUtils.generateEDDSAPrivateKey(prvBytes.clone());
- pubBytes = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, pubKey);
- publicKey = EdDSASecurityProviderUtils.generateEDDSAPublicKey(pubBytes.clone());
- msgBytes = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, msg);
- expSignature = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, signature);
- }
-
- @Parameters(name = "{0}")
- @SuppressWarnings("checkstyle:anoninnerlength")
- public static List<Object[]> parameters() {
- return new ArrayList<>(Arrays.asList(
- new Object[]{
- "TEST1 - empty message",
- "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60",
- "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a",
- "",
- "e5564300c360ac729086e2cc806e828a"
- + "84877f1eb8e5d974d873e06522490155"
- + "5fb8821590a33bacc61e39701cf9b46b"
- + "d25bf5f0595bbe24655141438e7a100b"
- },
- new Object[]{
- "TEST2 - one byte",
- "4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb",
- "3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c",
- "72",
- "92a009a9f0d4cab8720e820b5f642540"
- + "a2b27b5416503f8fb3762223ebdb69da"
- + "085ac1e43e15996e458f3613d0f11d8c"
- + "387b2eaeb4302aeeb00d291612bb0c00"
- },
- new Object[]{
- "TEST3 - 2 bytes",
- "c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7",
- "fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025",
- "af82",
- "6291d657deec24024827e69c3abe01a3"
- + "0ce548a284743a445e3680d7db5ac3ac"
- + "18ff9b538d16f290ae67f760984dc659"
- + "4a7c15e9716ed28dc027beceea1ec40a"
- },
- new Object[]{
- "TEST1024 - large message",
- "f5e5767cf153319517630f226876b86c8160cc583bc013744c6bf255f5cc0ee5",
- "278117fc144c72340f67d0f2316e8386ceffbf2b2428c9c51fef7c597f1d426e",
- "08b8b2b733424243760fe426a4b54908"
- + "632110a66c2f6591eabd3345e3e4eb98"
- + "fa6e264bf09efe12ee50f8f54e9f77b1"
- + "e355f6c50544e23fb1433ddf73be84d8"
- + "79de7c0046dc4996d9e773f4bc9efe57"
- + "38829adb26c81b37c93a1b270b20329d"
- + "658675fc6ea534e0810a4432826bf58c"
- + "941efb65d57a338bbd2e26640f89ffbc"
- + "1a858efcb8550ee3a5e1998bd177e93a"
- + "7363c344fe6b199ee5d02e82d522c4fe"
- + "ba15452f80288a821a579116ec6dad2b"
- + "3b310da903401aa62100ab5d1a36553e"
- + "06203b33890cc9b832f79ef80560ccb9"
- + "a39ce767967ed628c6ad573cb116dbef"
- + "efd75499da96bd68a8a97b928a8bbc10"
- + "3b6621fcde2beca1231d206be6cd9ec7"
- + "aff6f6c94fcd7204ed3455c68c83f4a4"
- + "1da4af2b74ef5c53f1d8ac70bdcb7ed1"
- + "85ce81bd84359d44254d95629e9855a9"
- + "4a7c1958d1f8ada5d0532ed8a5aa3fb2"
- + "d17ba70eb6248e594e1a2297acbbb39d"
- + "502f1a8c6eb6f1ce22b3de1a1f40cc24"
- + "554119a831a9aad6079cad88425de6bd"
- + "e1a9187ebb6092cf67bf2b13fd65f270"
- + "88d78b7e883c8759d2c4f5c65adb7553"
- + "878ad575f9fad878e80a0c9ba63bcbcc"
- + "2732e69485bbc9c90bfbd62481d9089b"
- + "eccf80cfe2df16a2cf65bd92dd597b07"
- + "07e0917af48bbb75fed413d238f5555a"
- + "7a569d80c3414a8d0859dc65a46128ba"
- + "b27af87a71314f318c782b23ebfe808b"
- + "82b0ce26401d2e22f04d83d1255dc51a"
- + "ddd3b75a2b1ae0784504df543af8969b"
- + "e3ea7082ff7fc9888c144da2af58429e"
- + "c96031dbcad3dad9af0dcbaaaf268cb8"
- + "fcffead94f3c7ca495e056a9b47acdb7"
- + "51fb73e666c6c655ade8297297d07ad1"
- + "ba5e43f1bca32301651339e22904cc8c"
- + "42f58c30c04aafdb038dda0847dd988d"
- + "cda6f3bfd15c4b4c4525004aa06eeff8"
- + "ca61783aacec57fb3d1f92b0fe2fd1a8"
- + "5f6724517b65e614ad6808d6f6ee34df"
- + "f7310fdc82aebfd904b01e1dc54b2927"
- + "094b2db68d6f903b68401adebf5a7e08"
- + "d78ff4ef5d63653a65040cf9bfd4aca7"
- + "984a74d37145986780fc0b16ac451649"
- + "de6188a7dbdf191f64b5fc5e2ab47b57"
- + "f7f7276cd419c17a3ca8e1b939ae49e4"
- + "88acba6b965610b5480109c8b17b80e1"
- + "b7b750dfc7598d5d5011fd2dcc5600a3"
- + "2ef5b52a1ecc820e308aa342721aac09"
- + "43bf6686b64b2579376504ccc493d97e"
- + "6aed3fb0f9cd71a43dd497f01f17c0e2"
- + "cb3797aa2a2f256656168e6c496afc5f"
- + "b93246f6b1116398a346f1a641f3b041"
- + "e989f7914f90cc2c7fff357876e506b5"
- + "0d334ba77c225bc307ba537152f3f161"
- + "0e4eafe595f6d9d90d11faa933a15ef1"
- + "369546868a7f3a45a96768d40fd9d034"
- + "12c091c6315cf4fde7cb68606937380d"
- + "b2eaaa707b4c4185c32eddcdd306705e"
- + "4dc1ffc872eeee475a64dfac86aba41c"
- + "0618983f8741c5ef68d3a101e8a3b8ca"
- + "c60c905c15fc910840b94c00a0b9d0",
- "0aab4c900501b3e24d7cdf4663326a3a"
- + "87df5e4843b2cbdb67cbf6e460fec350"
- + "aa5371b1508f9f4528ecea23c436d94b"
- + "5e8fcd4f681e30a6ac00a9704a188a03"
- }));
- }
-
- @BeforeClass
- public static void checkEDDSASupported() {
- Assume.assumeTrue("EDDSA N/A", SecurityUtils.isEDDSACurveSupported());
- }
-
- @Test
- public void testPublicKeyBytes() {
- byte[] publicSeed = Ed25519PublicKeyDecoder.getSeedValue((EdDSAPublicKey) publicKey);
- assertArrayEquals("Mismatched public seed value", pubBytes, publicSeed);
- }
-
- @Test
- public void testPrivateKeyBytes() {
- assertArrayEquals("Mismatched private seed value", prvBytes, ((EdDSAPrivateKey) privateKey).getSeed());
- }
-
- @Test
- public void testSignature() throws Exception {
- Signature signer = EdDSASecurityProviderUtils.getEDDSASignature();
- signer.initSigner(privateKey);
- signer.update(msgBytes.clone());
-
- byte[] actSignature = signer.sign();
- assertArrayEquals("Mismatched signature", expSignature, actSignature);
-
- Signature verifier = EdDSASecurityProviderUtils.getEDDSASignature();
- verifier.initVerifier(publicKey);
- verifier.update(msgBytes.clone());
- assertTrue("Verification failed", verifier.verify(expSignature));
- }
-
- @Test
- public void testPartialBufferSignature() throws Exception {
- byte[] extraData = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
- byte[] dataBuf = new byte[msgBytes.length + extraData.length];
- int offset = extraData.length / 2;
- System.arraycopy(extraData, 0, dataBuf, 0, offset);
- System.arraycopy(msgBytes, 0, dataBuf, offset, msgBytes.length);
- System.arraycopy(extraData, offset, dataBuf, offset + msgBytes.length, extraData.length - offset);
-
- Signature signer = EdDSASecurityProviderUtils.getEDDSASignature();
- signer.initSigner(privateKey);
- signer.update(dataBuf.clone(), offset, msgBytes.length);
-
- byte[] actSignature = signer.sign();
- assertArrayEquals("Mismatched signature", expSignature, actSignature);
-
- Signature verifier = EdDSASecurityProviderUtils.getEDDSASignature();
- verifier.initVerifier(publicKey);
- verifier.update(dataBuf.clone(), offset, msgBytes.length);
- assertTrue("Verification failed", verifier.verify(expSignature));
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrarTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrarTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrarTest.java
deleted file mode 100644
index c2ce550..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrarTest.java
+++ /dev/null
@@ -1,85 +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.util.security.eddsa;
-
-import java.security.KeyFactory;
-import java.security.KeyPairGenerator;
-import java.security.Provider;
-import java.security.Signature;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.apache.sshd.common.util.security.SecurityProviderRegistrar;
-import org.apache.sshd.common.util.security.SecurityProviderRegistrarTestSupport;
-import org.apache.sshd.common.util.security.SecurityUtils;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-import net.i2p.crypto.eddsa.EdDSASecurityProvider;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class EdDSASecurityProviderRegistrarTest extends SecurityProviderRegistrarTestSupport {
- private static SecurityProviderRegistrar registrarInstance;
-
- public EdDSASecurityProviderRegistrarTest() {
- super();
- }
-
- @BeforeClass
- public static void checkEDDSASupported() {
- Assume.assumeTrue(SecurityUtils.isEDDSACurveSupported());
- registrarInstance = new EdDSASecurityProviderRegistrar();
- }
-
- @Test
- public void testSupportedSecurityEntities() {
- assertSecurityEntitySupportState(getCurrentTestName(), registrarInstance, true, registrarInstance.getName(),
- KeyPairGenerator.class, KeyFactory.class);
- assertSecurityEntitySupportState(getCurrentTestName(), registrarInstance, true,
- SecurityUtils.CURVE_ED25519_SHA512, Signature.class);
-
- Collection<Class<?>> supported = new HashSet<>(Arrays.asList(KeyPairGenerator.class, KeyFactory.class, Signature.class));
- for (Class<?> entity : SecurityProviderRegistrar.SECURITY_ENTITIES) {
- if (supported.contains(entity)) {
- continue;
- }
- assertFalse("Unexpected support for " + entity.getSimpleName(), registrarInstance.isSecurityEntitySupported(entity, registrarInstance.getName()));
- }
- }
-
- @Test
- public void testGetSecurityProvider() {
- Provider expected = registrarInstance.getSecurityProvider();
- assertNotNull("No provider created", expected);
- assertEquals("Mismatched provider name", registrarInstance.getName(), expected.getName());
- assertObjectInstanceOf("Mismatched provider type", EdDSASecurityProvider.class, expected);
- }
-
- @Test
- public void testGetSecurityProviderCaching() {
- testGetSecurityProviderCaching(getCurrentTestName(), registrarInstance);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
index 01c96b4..50d83ed 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
@@ -44,7 +44,7 @@ import org.apache.sshd.server.auth.keyboard.KeyboardInteractiveAuthenticator;
import org.apache.sshd.server.auth.password.PasswordAuthenticator;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.Utils;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
@@ -68,11 +68,11 @@ public class ServerSessionListenerTest extends BaseTestSupport {
@BeforeClass
public static void setupClientAndServer() throws Exception {
- sshd = Utils.setupTestServer(ServerSessionListenerTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(ServerSessionListenerTest.class);
sshd.start();
port = sshd.getPort();
- client = Utils.setupTestClient(ServerSessionListenerTest.class);
+ client = CoreTestSupportUtils.setupTestClient(ServerSessionListenerTest.class);
client.start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerPhaseTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerPhaseTest.java b/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerPhaseTest.java
index 35f032b..bcb5311 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerPhaseTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerPhaseTest.java
@@ -30,8 +30,8 @@ import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.server.ServerAuthenticationManager;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
-import org.apache.sshd.util.test.Utils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
@@ -66,11 +66,11 @@ public class WelcomeBannerPhaseTest extends BaseTestSupport {
@BeforeClass
public static void setupClientAndServer() throws Exception {
- sshd = Utils.setupTestServer(WelcomeBannerPhaseTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(WelcomeBannerPhaseTest.class);
sshd.start();
port = sshd.getPort();
- client = Utils.setupTestClient(WelcomeBannerPhaseTest.class);
+ client = CoreTestSupportUtils.setupTestClient(WelcomeBannerPhaseTest.class);
client.start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerTest.java
index 04bf7d6..e417aa9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/auth/WelcomeBannerTest.java
@@ -39,7 +39,7 @@ import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.server.ServerAuthenticationManager;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.Utils;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
@@ -61,11 +61,11 @@ public class WelcomeBannerTest extends BaseTestSupport {
@BeforeClass
public static void setupClientAndServer() throws Exception {
- sshd = Utils.setupTestServer(WelcomeBannerTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(WelcomeBannerTest.class);
sshd.start();
port = sshd.getPort();
- client = Utils.setupTestClient(WelcomeBannerTest.class);
+ client = CoreTestSupportUtils.setupTestClient(WelcomeBannerTest.class);
client.start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java
deleted file mode 100644
index 7a2d326..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java
+++ /dev/null
@@ -1,83 +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.server.keyprovider;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.security.GeneralSecurityException;
-import java.security.KeyPair;
-import java.util.concurrent.atomic.AtomicInteger;
-
-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;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class AbstractGeneratorHostKeyProviderTest extends BaseTestSupport {
- public AbstractGeneratorHostKeyProviderTest() {
- super();
- }
-
- @SuppressWarnings("synthetic-access")
- @Test
- public void testOverwriteKey() throws Exception {
- Path tempDir = assertHierarchyTargetFolderExists(getTempTargetFolder());
- Path keyPairFile = tempDir.resolve(getCurrentTestName() + ".key");
- Files.deleteIfExists(keyPairFile);
-
- TestProvider provider = new TestProvider(keyPairFile);
- provider.loadKeys();
- assertEquals("Mismatched generate write count", 1, provider.getWriteCount());
-
- provider = new TestProvider(keyPairFile);
- provider.setOverwriteAllowed(false);
- provider.loadKeys();
- assertEquals("Mismatched load write count", 0, provider.getWriteCount());
- }
-
- private static final class TestProvider extends AbstractGeneratorHostKeyProvider {
- private final AtomicInteger writes = new AtomicInteger(0);
-
- private TestProvider(Path file) {
- setKeySize(512);
- setPath(file);
- }
-
- @Override
- protected KeyPair doReadKeyPair(String resourceKey, InputStream inputStream) throws IOException, GeneralSecurityException {
- return null;
- }
-
- @Override
- protected void doWriteKeyPair(String resourceKey, KeyPair kp, OutputStream outputStream) throws IOException, GeneralSecurityException {
- writes.incrementAndGet();
- }
-
- public int getWriteCount() {
- return writes.get();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/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
deleted file mode 100644
index 620033c..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
+++ /dev/null
@@ -1,141 +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.server.keyprovider;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.security.KeyPair;
-import java.security.PublicKey;
-import java.security.interfaces.ECPublicKey;
-import java.security.spec.AlgorithmParameterSpec;
-import java.security.spec.ECGenParameterSpec;
-
-import org.apache.sshd.common.cipher.ECCurves;
-import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.io.IoUtils;
-import org.apache.sshd.common.util.security.SecurityUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-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.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class PEMGeneratorHostKeyProviderTest extends BaseTestSupport {
- public PEMGeneratorHostKeyProviderTest() {
- super();
- }
-
- @Test
- public void testDSA() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- testPEMGeneratorHostKeyProvider(KeyUtils.DSS_ALGORITHM, KeyPairProvider.SSH_DSS, 512, null);
- }
-
- @Test
- public void testRSA() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- testPEMGeneratorHostKeyProvider(KeyUtils.RSA_ALGORITHM, KeyPairProvider.SSH_RSA, 512, null);
- }
-
- @Test
- public void testECnistp256() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- Assume.assumeTrue("ECC not supported", SecurityUtils.isECCSupported());
- Assume.assumeTrue(ECCurves.nistp256 + " N/A", ECCurves.nistp256.isSupported());
- testPEMGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
- }
-
- @Test
- public void testECnistp384() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- Assume.assumeTrue("ECC not supported", SecurityUtils.isECCSupported());
- Assume.assumeTrue(ECCurves.nistp384 + " N/A", ECCurves.nistp384.isSupported());
- testPEMGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
- }
-
- @Test
- public void testECnistp521() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- Assume.assumeTrue("ECC not supported", SecurityUtils.isECCSupported());
- Assume.assumeTrue(ECCurves.nistp521 + " N/A", ECCurves.nistp521.isSupported());
- testPEMGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
- }
-
- private Path testPEMGeneratorHostKeyProvider(String algorithm, String keyType, int keySize, AlgorithmParameterSpec keySpec) throws IOException {
- Path path = initKeyFileLocation(algorithm);
- KeyPair kpWrite = invokePEMGeneratorHostKeyProvider(path, algorithm, keyType, keySize, keySpec);
- assertTrue("Key file not generated: " + path, Files.exists(path, IoUtils.EMPTY_LINK_OPTIONS));
-
- KeyPair kpRead = invokePEMGeneratorHostKeyProvider(path, algorithm, keyType, keySize, keySpec);
- PublicKey pubWrite = kpWrite.getPublic();
- PublicKey pubRead = kpRead.getPublic();
- if (pubWrite instanceof ECPublicKey) {
- // The algorithm is reported as ECDSA instead of EC
- assertECPublicKeyEquals("Mismatched EC public key", ECPublicKey.class.cast(pubWrite), ECPublicKey.class.cast(pubRead));
- } else {
- assertKeyEquals("Mismatched public keys", pubWrite, pubRead);
- }
- return path;
- }
-
- private static KeyPair invokePEMGeneratorHostKeyProvider(Path path, String algorithm, String keyType, int keySize, AlgorithmParameterSpec keySpec) {
- AbstractGeneratorHostKeyProvider provider = SecurityUtils.createGeneratorHostKeyProvider(path.toAbsolutePath().normalize());
- provider.setAlgorithm(algorithm);
- provider.setOverwriteAllowed(true);
- if (keySize > 0) {
- provider.setKeySize(keySize);
- }
- if (keySpec != null) {
- provider.setKeySpec(keySpec);
- }
-
- return validateKeyPairProvider(provider, keyType);
- }
-
- private static KeyPair validateKeyPairProvider(KeyPairProvider provider, String keyType) {
- Iterable<String> types = provider.getKeyTypes();
- KeyPair kp = null;
- for (String type : types) {
- if (keyType.equals(type)) {
- kp = provider.loadKey(keyType);
- assertNotNull("Failed to load key for " + keyType, kp);
- break;
- }
- }
-
- assertNotNull("Expected key type not found: " + keyType, kp);
- return kp;
- }
-
- private Path initKeyFileLocation(String algorithm) throws IOException {
- Path path = assertHierarchyTargetFolderExists(getTempTargetRelativeFile(getClass().getSimpleName()));
- path = path.resolve(algorithm + "-PEM.key");
- Files.deleteIfExists(path);
- return path;
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/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
deleted file mode 100644
index 1ac3ef9..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
+++ /dev/null
@@ -1,133 +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.server.keyprovider;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.security.KeyPair;
-import java.security.spec.AlgorithmParameterSpec;
-import java.security.spec.ECGenParameterSpec;
-
-import org.apache.sshd.common.cipher.ECCurves;
-import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.io.IoUtils;
-import org.apache.sshd.common.util.security.SecurityUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-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.runners.MethodSorters;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class SimpleGeneratorHostKeyProviderTest extends BaseTestSupport {
- public SimpleGeneratorHostKeyProviderTest() {
- super();
- }
-
- @Test
- public void testDSA() throws IOException {
- testSimpleGeneratorHostKeyProvider(KeyUtils.DSS_ALGORITHM, KeyPairProvider.SSH_DSS, 512, null);
- }
-
- @Test
- public void testRSA() throws IOException {
- testSimpleGeneratorHostKeyProvider(KeyUtils.RSA_ALGORITHM, KeyPairProvider.SSH_RSA, 512, null);
- }
-
- @Test
- public void testECnistp256() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- Assume.assumeTrue("ECC not supported", SecurityUtils.isECCSupported());
- Assume.assumeTrue(ECCurves.nistp256 + " N/A", ECCurves.nistp256.isSupported());
- testSimpleGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
- }
-
- @Test
- public void testECnistp384() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- Assume.assumeTrue("ECC not supported", SecurityUtils.isECCSupported());
- Assume.assumeTrue(ECCurves.nistp384 + " N/A", ECCurves.nistp384.isSupported());
- testSimpleGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
- }
-
- @Test
- public void testECnistp521() throws IOException {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- Assume.assumeTrue("ECC not supported", SecurityUtils.isECCSupported());
- Assume.assumeTrue(ECCurves.nistp521 + " N/A", ECCurves.nistp521.isSupported());
- testSimpleGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
- }
-
- private Path testSimpleGeneratorHostKeyProvider(String algorithm, String keyType, int keySize, AlgorithmParameterSpec keySpec) throws IOException {
- Path path = initKeyFileLocation(algorithm);
- KeyPair kpWrite = invokeSimpleGeneratorHostKeyProvider(path, algorithm, keyType, keySize, keySpec);
- assertTrue("Key file not generated: " + path, Files.exists(path, IoUtils.EMPTY_LINK_OPTIONS));
-
- KeyPair kpRead = invokeSimpleGeneratorHostKeyProvider(path, algorithm, keyType, keySize, keySpec);
- assertKeyPairEquals("Mismatched write/read key pairs", kpWrite, kpRead);
- return path;
- }
-
- private static KeyPair invokeSimpleGeneratorHostKeyProvider(Path path, String algorithm, String keyType, int keySize, AlgorithmParameterSpec keySpec) {
- SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
- provider.setAlgorithm(algorithm);
- provider.setOverwriteAllowed(true);
- provider.setPath(path);
- if (keySize > 0) {
- provider.setKeySize(keySize);
- }
- if (keySpec != null) {
- provider.setKeySpec(keySpec);
- }
-
- return validateKeyPairProvider(provider, keyType);
- }
-
- private static KeyPair validateKeyPairProvider(KeyPairProvider provider, String keyType) {
- Iterable<String> types = provider.getKeyTypes();
- KeyPair kp = null;
- for (String type : types) {
- if (keyType.equals(type)) {
- kp = provider.loadKey(keyType);
- assertNotNull("Failed to load key for " + keyType, kp);
- break;
- }
- }
-
- assertNotNull("Expected key type not found: " + keyType, kp);
- return kp;
- }
-
- private Path initKeyFileLocation(String algorithm) throws IOException {
- Path path = assertHierarchyTargetFolderExists(getTempTargetRelativeFile(getClass().getSimpleName()));
- path = path.resolve(algorithm + "-simple.key");
- Files.deleteIfExists(path);
- return path;
- }
-}