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 2015/11/23 10:22:42 UTC
mina-sshd git commit: [SSHD-590] skip EC tests if EC is not available
at JRE
Repository: mina-sshd
Updated Branches:
refs/heads/master b3eecb19d -> b2c0b47a1
[SSHD-590] skip EC tests if EC is not available at JRE
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/b2c0b47a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/b2c0b47a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/b2c0b47a
Branch: refs/heads/master
Commit: b2c0b47a16dbd0431b10198890f52b36b47cef00
Parents: b3eecb1
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Nov 23 11:22:31 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Nov 23 11:22:31 2015 +0200
----------------------------------------------------------------------
.../sshd/common/config/keys/KeyUtils.java | 6 +-
.../apache/sshd/common/util/SecurityUtils.java | 39 ++++--
.../server/config/keys/AuthorizedKeyEntry.java | 20 +++-
.../signature/SignatureECDSAFactoryTest.java | 2 +-
.../config/keys/AuthorizedKeyEntryTest.java | 62 ++++------
.../keys/AuthorizedKeysAuthenticatorTest.java | 25 +---
.../config/keys/AuthorizedKeysTestSupport.java | 118 +++++++++++++++++++
.../DefaultAuthorizedKeysAuthenticatorTest.java | 16 +--
8 files changed, 197 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
index 3af34a9..a9969f5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
@@ -63,6 +63,7 @@ import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.common.util.Pair;
+import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
@@ -102,7 +103,10 @@ public final class KeyUtils {
static {
registerPublicKeyEntryDecoder(RSAPublicKeyDecoder.INSTANCE);
registerPublicKeyEntryDecoder(DSSPublicKeyEntryDecoder.INSTANCE);
- registerPublicKeyEntryDecoder(ECDSAPublicKeyEntryDecoder.INSTANCE);
+
+ if (SecurityUtils.hasEcc()) {
+ registerPublicKeyEntryDecoder(ECDSAPublicKeyEntryDecoder.INSTANCE);
+ }
}
private KeyUtils() {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
index 21d874a..c2fbd38 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
@@ -101,6 +101,13 @@ public final class SecurityUtils {
*/
public static final String REGISTER_BOUNCY_CASTLE_PROP = "org.apache.sshd.registerBouncyCastle";
+ /**
+ * System property used to control whether Elliptic Curves are supported or not.
+ * If not set then the support is auto-detected. <B>Note:</B> if set to {@code true}
+ * it is up to the user to make sure that indeed there is a provider for them
+ */
+ public static final String ECC_SUPPORTED_PROP = "org.apache.sshd.eccSupport";
+
private static final AtomicInteger MAX_DHG_KEY_SIZE_HOLDER = new AtomicInteger(0);
private static String securityProvider;
@@ -112,15 +119,27 @@ public final class SecurityUtils {
throw new UnsupportedOperationException("No instance");
}
+ /**
+ * @return {@code true} if Elliptic Curve Cryptography is supported
+ * @see #ECC_SUPPORTED_PROP
+ */
public static boolean hasEcc() {
if (hasEcc == null) {
- try {
- getKeyPairGenerator("EC");
- hasEcc = Boolean.TRUE;
- } catch (Throwable t) {
- hasEcc = Boolean.FALSE;
+ String propValue = System.getProperty(ECC_SUPPORTED_PROP);
+ if (GenericUtils.isEmpty(propValue)) {
+ try {
+ getKeyPairGenerator("EC");
+ hasEcc = Boolean.TRUE;
+ } catch (Throwable t) {
+ hasEcc = Boolean.FALSE;
+ }
+ } else {
+ Logger logger = LoggerFactory.getLogger(SecurityUtils.class);
+ logger.info("Override ECC support value: " + propValue);
+ hasEcc = Boolean.valueOf(propValue);
}
}
+
return hasEcc;
}
@@ -155,6 +174,8 @@ public final class SecurityUtils {
}
}
} else {
+ Logger logger = LoggerFactory.getLogger(SecurityUtils.class);
+ logger.info("Override max. DH group exchange key size: " + propValue);
maxSupportedKeySize = Integer.parseInt(propValue);
// negative is OK - means user wants to disable DH group exchange
ValidateUtils.checkTrue(maxSupportedKeySize != 0,
@@ -205,9 +226,11 @@ public final class SecurityUtils {
private static void register() {
if (!registrationDone) {
if (registerBouncyCastle == null) {
- String prop = System.getProperty(REGISTER_BOUNCY_CASTLE_PROP);
- if (!GenericUtils.isEmpty(prop)) {
- registerBouncyCastle = Boolean.valueOf(prop);
+ String propValue = System.getProperty(REGISTER_BOUNCY_CASTLE_PROP);
+ if (!GenericUtils.isEmpty(propValue)) {
+ Logger logger = LoggerFactory.getLogger(SecurityUtils.class);
+ logger.info("Override BouncyCastle registration value: " + propValue);
+ registerBouncyCastle = Boolean.valueOf(propValue);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java
index a8908e5..142dd5b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java
@@ -202,7 +202,9 @@ public class AuthorizedKeyEntry extends PublicKeyEntry {
* @see #readAuthorizedKeys(InputStream, boolean)
*/
public static List<AuthorizedKeyEntry> readAuthorizedKeys(URL url) throws IOException {
- return readAuthorizedKeys(url.openStream(), true);
+ try (InputStream in = url.openStream()) {
+ return readAuthorizedKeys(in, true);
+ }
}
/**
@@ -214,7 +216,9 @@ public class AuthorizedKeyEntry extends PublicKeyEntry {
* @see #readAuthorizedKeys(InputStream, boolean)
*/
public static List<AuthorizedKeyEntry> readAuthorizedKeys(File file) throws IOException {
- return readAuthorizedKeys(new FileInputStream(file), true);
+ try (InputStream in = new FileInputStream(file)) {
+ return readAuthorizedKeys(in, true);
+ }
}
/**
@@ -229,7 +233,9 @@ public class AuthorizedKeyEntry extends PublicKeyEntry {
* @see Files#newInputStream(Path, OpenOption...)
*/
public static List<AuthorizedKeyEntry> readAuthorizedKeys(Path path, OpenOption... options) throws IOException {
- return readAuthorizedKeys(Files.newInputStream(path, options), true);
+ try (InputStream in = Files.newInputStream(path, options)) {
+ return readAuthorizedKeys(in, true);
+ }
}
/**
@@ -241,7 +247,9 @@ public class AuthorizedKeyEntry extends PublicKeyEntry {
* @see #readAuthorizedKeys(InputStream, boolean)
*/
public static List<AuthorizedKeyEntry> readAuthorizedKeys(String filePath) throws IOException {
- return readAuthorizedKeys(new FileInputStream(filePath), true);
+ try (InputStream in = new FileInputStream(filePath)) {
+ return readAuthorizedKeys(in, true);
+ }
}
/**
@@ -287,10 +295,10 @@ public class AuthorizedKeyEntry extends PublicKeyEntry {
List<AuthorizedKeyEntry> entries = null;
for (String line = rdr.readLine(); line != null; line = rdr.readLine()) {
- final AuthorizedKeyEntry entry;
+ AuthorizedKeyEntry entry;
try {
entry = parseAuthorizedKeyEntry(line.trim());
- if (entry == null) {
+ if (entry == null) { // null, empty or comment line
continue;
}
} catch (IllegalArgumentException e) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureECDSAFactoryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureECDSAFactoryTest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureECDSAFactoryTest.java
index bfb2132..d71a6d3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureECDSAFactoryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureECDSAFactoryTest.java
@@ -62,7 +62,7 @@ public class SignatureECDSAFactoryTest extends AbstractSignatureFactoryTestSuppo
@Test
public void testECDSAPublicKeyAuth() throws Exception {
- Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc() || SecurityUtils.isBouncyCastleRegistered());
+ Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc());
testKeyPairProvider(ECDSAPublicKeyEntryDecoder.INSTANCE, FACTORIES);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
index df21453..1ecfe76 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
@@ -19,23 +19,18 @@
package org.apache.sshd.server.config.keys;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.security.PublicKey;
import java.util.Collection;
+import java.util.List;
import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.config.keys.PublicKeyEntry;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
-import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
@@ -45,50 +40,41 @@ import org.junit.runners.MethodSorters;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class AuthorizedKeyEntryTest extends BaseTestSupport {
+public class AuthorizedKeyEntryTest extends AuthorizedKeysTestSupport {
public AuthorizedKeyEntryTest() {
super();
}
@Test
public void testReadAuthorizedKeysFile() throws Exception {
- URL url = getClass().getResource(AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME);
- assertNotNull("Missing " + AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME + " resource", url);
-
- runAuthorizedKeysTests(AuthorizedKeyEntry.readAuthorizedKeys(url));
+ Path file = getTempTargetRelativeFile(getCurrentTestName());
+ writeDefaultSupportedKeys(file);
+ runAuthorizedKeysTests(AuthorizedKeyEntry.readAuthorizedKeys(file));
}
@Test
public void testEncodePublicKeyEntry() throws Exception {
- URL url = getClass().getResource(AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME);
- assertNotNull("Missing " + AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME + " resource", url);
-
+ List<String> keyLines = loadDefaultSupportedKeys();
StringBuilder sb = new StringBuilder(Byte.MAX_VALUE);
- try (BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
- for (String line = rdr.readLine(); line != null; line = rdr.readLine()) {
- line = GenericUtils.trimToEmpty(line);
- if (GenericUtils.isEmpty(line) || (line.charAt(0) == PublicKeyEntry.COMMENT_CHAR)) {
- continue;
- }
-
- int pos = line.indexOf(' ');
- String keyType = line.substring(0, pos), data = line;
- // assume this happens if starts with login options
- if (KeyUtils.getPublicKeyEntryDecoder(keyType) == null) {
- data = line.substring(pos + 1).trim();
- }
-
- AuthorizedKeyEntry entry = AuthorizedKeyEntry.parseAuthorizedKeyEntry(data);
- if (sb.length() > 0) {
- sb.setLength(0);
- }
-
- PublicKey key = entry.appendPublicKey(sb);
- assertNotNull("No key for line=" + line, key);
-
- String encoded = sb.toString();
- assertEquals("Mismatched encoded form for line=" + line, data, encoded);
+ for (String line : keyLines) {
+ int pos = line.indexOf(' ');
+ String data = line;
+ String keyType = line.substring(0, pos);
+ // assume this happens if starts with login options
+ if (KeyUtils.getPublicKeyEntryDecoder(keyType) == null) {
+ data = line.substring(pos + 1).trim();
+ }
+
+ AuthorizedKeyEntry entry = AuthorizedKeyEntry.parseAuthorizedKeyEntry(data);
+ if (sb.length() > 0) {
+ sb.setLength(0);
}
+
+ PublicKey key = entry.appendPublicKey(sb);
+ assertNotNull("No key for line=" + line, key);
+
+ String encoded = sb.toString();
+ assertEquals("Mismatched encoded form for line=" + line, data, encoded);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
index a525dcf..c1e89c2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
@@ -19,26 +19,20 @@
package org.apache.sshd.server.config.keys;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.Writer;
-import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.PublicKey;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.sshd.common.config.keys.PublicKeyEntry;
-import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
import org.apache.sshd.server.session.ServerSession;
-import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
@@ -48,7 +42,7 @@ import org.mockito.Mockito;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class AuthorizedKeysAuthenticatorTest extends BaseTestSupport {
+public class AuthorizedKeysAuthenticatorTest extends AuthorizedKeysTestSupport {
public AuthorizedKeysAuthenticatorTest() {
super();
}
@@ -71,22 +65,7 @@ public class AuthorizedKeysAuthenticatorTest extends BaseTestSupport {
};
assertFalse("Unexpected authentication success for missing file " + file, auth.authenticate(getCurrentTestName(), Mockito.mock(PublicKey.class), null));
- URL url = getClass().getResource(AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME);
- assertNotNull("Missing " + AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME + " resource", url);
-
- List<String> keyLines = new ArrayList<String>();
- try (BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
- for (String l = rdr.readLine(); l != null; l = rdr.readLine()) {
- l = GenericUtils.trimToEmpty(l);
- // filter out empty and comment lines
- if (GenericUtils.isEmpty(l) || (l.charAt(0) == PublicKeyEntry.COMMENT_CHAR)) {
- continue;
- } else {
- keyLines.add(l);
- }
- }
- }
-
+ List<String> keyLines = loadDefaultSupportedKeys();
assertHierarchyTargetFolderExists(file.getParent());
while(keyLines.size() > 0) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysTestSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysTestSupport.java
new file mode 100644
index 0000000..659195c
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysTestSupport.java
@@ -0,0 +1,118 @@
+/*
+ * 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.config.keys;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.OpenOption;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sshd.common.cipher.ECCurves;
+import org.apache.sshd.common.config.keys.PublicKeyEntry;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.common.util.io.IoUtils;
+import org.apache.sshd.common.util.io.NoCloseInputStream;
+import org.apache.sshd.common.util.io.NoCloseReader;
+import org.apache.sshd.util.test.BaseTestSupport;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public abstract class AuthorizedKeysTestSupport extends BaseTestSupport {
+ protected AuthorizedKeysTestSupport() {
+ super();
+ }
+
+ protected List<String> writeDefaultSupportedKeys(Path file, OpenOption ... options) throws IOException {
+ List<String> keyLines = loadDefaultSupportedKeys();
+ if (Files.exists(file)) {
+ Files.delete(file);
+ }
+
+ try (Writer w = Files.newBufferedWriter(file, StandardCharsets.UTF_8, options)) {
+ w.append(PublicKeyEntry.COMMENT_CHAR)
+ .append(' ').append(getCurrentTestName())
+ .append(' ').append(String.valueOf(keyLines.size())).append(" remaining keys")
+ .append(IoUtils.EOL)
+ ;
+ for (String l : keyLines) {
+ w.append(l).append(IoUtils.EOL);
+ }
+ }
+
+ return keyLines;
+ }
+
+ protected List<String> loadDefaultSupportedKeys() throws IOException {
+ return loadSupportedKeys(
+ ValidateUtils.checkNotNull(
+ getClass().getResource(AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME),
+ "Missing resource=" + AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME));
+ }
+
+ public static List<String> loadSupportedKeys(URL url) throws IOException {
+ return loadSupportedKeys(url.openStream(), true);
+ }
+
+ public static List<String> loadSupportedKeys(InputStream input, boolean okToClose) throws IOException {
+ try (Reader r = new InputStreamReader(NoCloseInputStream.resolveInputStream(input, okToClose), StandardCharsets.UTF_8)) {
+ return loadSupportedKeys(r, true);
+ }
+ }
+
+ public static List<String> loadSupportedKeys(Reader rdr, boolean okToClose) throws IOException {
+ try (BufferedReader buf = new BufferedReader(NoCloseReader.resolveReader(rdr, okToClose))) {
+ return loadSupportedKeys(buf);
+ }
+ }
+
+ public static List<String> loadSupportedKeys(BufferedReader rdr) throws IOException {
+ List<String> keyLines = new ArrayList<String>();
+ boolean eccSupported = SecurityUtils.hasEcc();
+ for (String l = rdr.readLine(); l != null; l = rdr.readLine()) {
+ l = GenericUtils.trimToEmpty(l);
+ // filter out empty and comment lines
+ if (GenericUtils.isEmpty(l) || (l.charAt(0) == PublicKeyEntry.COMMENT_CHAR)) {
+ continue;
+ }
+
+ // skip EC keys if ECC not supported
+ if (l.contains(ECCurves.Constants.ECDSA_SHA2_PREFIX) && (!eccSupported)) {
+ System.out.println("Skip (ECC not supported) " + l);
+ continue;
+ }
+
+ keyLines.add(l);
+ }
+
+ return keyLines;
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b2c0b47a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticatorTest.java b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticatorTest.java
index 23883fe..68782c6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticatorTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticatorTest.java
@@ -19,18 +19,12 @@
package org.apache.sshd.server.config.keys;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.security.PublicKey;
import java.util.Collection;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
-import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
@@ -39,7 +33,7 @@ import org.junit.runners.MethodSorters;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class DefaultAuthorizedKeysAuthenticatorTest extends BaseTestSupport {
+public class DefaultAuthorizedKeysAuthenticatorTest extends AuthorizedKeysTestSupport {
public DefaultAuthorizedKeysAuthenticatorTest() {
super();
}
@@ -47,13 +41,7 @@ public class DefaultAuthorizedKeysAuthenticatorTest extends BaseTestSupport {
@Test
public void testUsernameValidation() throws Exception {
Path file = getTempTargetRelativeFile(getCurrentTestName());
- URL url = getClass().getResource(AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME);
- assertNotNull("Missing " + AuthorizedKeyEntry.STD_AUTHORIZED_KEYS_FILENAME + " resource", url);
-
- try (InputStream input = url.openStream();
- OutputStream output = Files.newOutputStream(file)) {
- IoUtils.copy(input, output);
- }
+ writeDefaultSupportedKeys(file);
Collection<AuthorizedKeyEntry> entries = AuthorizedKeyEntry.readAuthorizedKeys(file);
Collection<PublicKey> keySet = AuthorizedKeyEntry.resolveAuthorizedKeys(entries);