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/24 14:36:40 UTC
mina-sshd git commit: [SSHD-598] Use OpenSSH key fingerprint as
default one
Repository: mina-sshd
Updated Branches:
refs/heads/master e4cb8082d -> f83908366
[SSHD-598] Use OpenSSH key fingerprint as default one
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/f8390836
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/f8390836
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/f8390836
Branch: refs/heads/master
Commit: f839083669f5789277e521c1ac97c37acf7aa423
Parents: e4cb808
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Tue Nov 24 15:36:29 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Tue Nov 24 15:36:29 2015 +0200
----------------------------------------------------------------------
.../sshd/common/config/keys/KeyUtils.java | 114 ++++++++++++-
.../common/config/keys/OpenSSHKeyUtils.java | 163 -------------------
.../sshd/common/digest/BuiltinDigests.java | 18 ++
.../apache/sshd/common/digest/DigestUtils.java | 63 ++++++-
.../KeyUtilsFingerprintCaseSensitivityTest.java | 90 ++++++++++
.../keys/KeyUtilsFingerprintGenerationTest.java | 144 ++++++++++++++++
.../config/keys/OpenSSHKeyUtilsAlgoTest.java | 151 -----------------
.../config/keys/OpenSSHKeyUtilsCheckTest.java | 90 ----------
8 files changed, 416 insertions(+), 417 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/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 a9969f5..be9e0e0 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
@@ -58,6 +58,7 @@ import org.apache.sshd.common.Factory;
import org.apache.sshd.common.cipher.ECCurves;
import org.apache.sshd.common.digest.BuiltinDigests;
import org.apache.sshd.common.digest.Digest;
+import org.apache.sshd.common.digest.DigestFactory;
import org.apache.sshd.common.digest.DigestUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.GenericUtils;
@@ -86,13 +87,20 @@ public final class KeyUtils {
PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_WRITE, PosixFilePermission.OTHERS_EXECUTE));
/**
+ * System property that can be used to control the default fingerprint factory used for keys.
+ * If not set the {@link #DEFAULT_FINGERPRINT_DIGEST_FACTORY} is used
+ */
+ public static final String KEY_FINGERPRINT_FACTORY_PROP = "org.apache.sshd.keyFingerprintFactory";
+
+ /**
* The default {@link Factory} of {@link Digest}s initialized
- * as the value of {@link #getDefaultFingerPrintFactory()}
+ * as the value of {@link #getDefaultFingerPrintFactory()} if not
+ * overridden by {@link #OPENSSH_KEY_FINGERPRINT_FACTORY_PROP} or
+ * {@link #setDefaultFingerPrintFactory(Factory)}
*/
- public static final Factory<Digest> DEFAULT_FINGERPRINT_DIGEST_FACTORY = BuiltinDigests.md5;
+ public static final Factory<Digest> DEFAULT_FINGERPRINT_DIGEST_FACTORY = BuiltinDigests.sha256;
- private static final AtomicReference<Factory<? extends Digest>> DEFAULT_DIGEST_HOLDER =
- new AtomicReference<Factory<? extends Digest>>(DEFAULT_FINGERPRINT_DIGEST_FACTORY);
+ private static final AtomicReference<Factory<? extends Digest>> DEFAULT_DIGEST_HOLDER = new AtomicReference<>();
private static final Map<String, PublicKeyEntryDecoder<?, ?>> BY_KEY_TYPE_DECODERS_MAP =
new TreeMap<String, PublicKeyEntryDecoder<?, ?>>(String.CASE_INSENSITIVE_ORDER);
@@ -361,10 +369,28 @@ public final class KeyUtils {
* @return The default {@link Factory} of {@link Digest}s used
* by the {@link #getFingerPrint(PublicKey)} and {@link #getFingerPrint(String)}
* methods
+ * @see #KEY_FINGERPRINT_FACTORY_PROP
* @see #setDefaultFingerPrintFactory(Factory)
*/
public static Factory<? extends Digest> getDefaultFingerPrintFactory() {
- return DEFAULT_DIGEST_HOLDER.get();
+ Factory<? extends Digest> factory = null;
+ synchronized (DEFAULT_DIGEST_HOLDER) {
+ factory = DEFAULT_DIGEST_HOLDER.get();
+ if (factory != null) {
+ return factory;
+ }
+
+ String propVal = System.getProperty(KEY_FINGERPRINT_FACTORY_PROP);
+ if (GenericUtils.isEmpty(propVal)) {
+ factory = DEFAULT_FINGERPRINT_DIGEST_FACTORY;
+ } else {
+ factory = ValidateUtils.checkNotNull(BuiltinDigests.fromFactoryName(propVal), "Unknown digest factory: %s", propVal);
+ }
+
+ DEFAULT_DIGEST_HOLDER.set(factory);
+ }
+
+ return factory;
}
/**
@@ -372,7 +398,9 @@ public final class KeyUtils {
* not be {@code null}
*/
public static void setDefaultFingerPrintFactory(Factory<? extends Digest> f) {
- DEFAULT_DIGEST_HOLDER.set(ValidateUtils.checkNotNull(f, "No digest factory"));
+ synchronized (DEFAULT_DIGEST_HOLDER) {
+ DEFAULT_DIGEST_HOLDER.set(ValidateUtils.checkNotNull(f, "No digest factory"));
+ }
}
/**
@@ -417,7 +445,7 @@ public final class KeyUtils {
* @see #getFingerPrint(Digest, PublicKey)
*/
public static String getFingerPrint(Factory<? extends Digest> f, PublicKey key) {
- return getFingerPrint(f.create(), key);
+ return getFingerPrint(ValidateUtils.checkNotNull(f, "No digest factory").create(), key);
}
/**
@@ -431,6 +459,7 @@ public final class KeyUtils {
if (key == null) {
return null;
}
+
try {
Buffer buffer = new ByteArrayBuffer();
buffer.putRawPublicKey(key);
@@ -490,6 +519,7 @@ public final class KeyUtils {
if (GenericUtils.isEmpty(s)) {
return null;
}
+
try {
return DigestUtils.getFingerPrint(d, s, charset);
} catch (Exception e) {
@@ -497,6 +527,76 @@ public final class KeyUtils {
}
}
+ /**
+ * @param expected The expected fingerprint if {@code null} or empty then returns a failure
+ * with the default fingerprint.
+ * @param key the {@link PublicKey} - if {@code null} then returns null.
+ * @return Pair<Boolean, String> - first is success indicator, second is actual fingerprint,
+ * {@code null} if no key.
+ * @see #getDefaultFingerPrintFactory()
+ * @see #checkFingerPrint(String, Factory, PublicKey)
+ */
+ public static Pair<Boolean, String> checkFingerPrint(String expected, PublicKey key) {
+ return checkFingerPrint(expected, getDefaultFingerPrintFactory(), key);
+ }
+
+ /**
+ * @param expected The expected fingerprint if {@code null} or empty then returns a failure
+ * with the default fingerprint.
+ * @param f The {@link Factory} to be used to generate the default {@link Digest} for the key
+ * @param key the {@link PublicKey} - if {@code null} then returns null.
+ * @return Pair<Boolean, String> - first is success indicator, second is actual fingerprint,
+ * {@code null} if no key.
+ */
+ public static Pair<Boolean, String> checkFingerPrint(String expected, Factory<? extends Digest> f, PublicKey key) {
+ return checkFingerPrint(expected, ValidateUtils.checkNotNull(f, "No digest factory").create(), key);
+ }
+
+ /**
+ * @param expected The expected fingerprint if {@code null} or empty then returns a failure
+ * with the default fingerprint.
+ * @param d The {@link Digest} to be used to generate the default fingerprint for the key
+ * @param key the {@link PublicKey} - if {@code null} then returns null.
+ * @return Pair<Boolean, String> - first is success indicator, second is actual fingerprint,
+ * {@code null} if no key.
+ */
+ public static Pair<Boolean, String> checkFingerPrint(String expected, Digest d, PublicKey key) {
+ if (key == null) {
+ return null;
+ }
+
+ if (GenericUtils.isEmpty(expected)) {
+ return new Pair<>(false, getFingerPrint(d, key));
+ }
+
+ // de-construct fingerprint
+ int pos = expected.indexOf(':');
+ if ((pos < 0) || (pos >= (expected.length() - 1))) {
+ return new Pair<>(false, getFingerPrint(d, key));
+ }
+
+ String name = expected.substring(0, pos);
+ String value = expected.substring(pos + 1);
+ DigestFactory expectedFactory;
+ // We know that all digest names have a length > 2 - if 2 (or less) then assume a pure HEX value
+ if (name.length() > 2) {
+ expectedFactory = BuiltinDigests.fromFactoryName(name);
+ if (expectedFactory == null) {
+ return new Pair<>(false, getFingerPrint(d, key));
+ }
+
+ expected = name.toUpperCase() + ":" + value;
+ } else {
+ expectedFactory = BuiltinDigests.md5;
+ expected = expectedFactory.getName().toUpperCase() + ":" + expected;
+ }
+
+ String fingerprint = getFingerPrint(expectedFactory, key);
+ boolean matches = BuiltinDigests.md5.getName().equals(expectedFactory.getName())
+ ? expected.equalsIgnoreCase(fingerprint) // HEX is case insensitive
+ : expected.equals(fingerprint);
+ return new Pair<>(matches, fingerprint);
+ }
/**
* @param kp a key pair - ignored if {@code null}. If the private
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/sshd-core/src/main/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtils.java
deleted file mode 100644
index 0674ea0..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtils.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.config.keys;
-
-import java.security.PublicKey;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.sshd.common.Factory;
-import org.apache.sshd.common.digest.BuiltinDigests;
-import org.apache.sshd.common.digest.Digest;
-import org.apache.sshd.common.digest.DigestFactory;
-import org.apache.sshd.common.util.Base64;
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
-import org.apache.sshd.common.util.ValidateUtils;
-import org.apache.sshd.common.util.buffer.Buffer;
-import org.apache.sshd.common.util.buffer.BufferUtils;
-import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
-
-/**
- * Utility class for keys
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public final class OpenSSHKeyUtils {
-
- /**
- * The default {@link Factory} of {@link Digest}s initialized
- * as the value of {@link #getDefaultFingerPrintFactory()}
- */
- public static final Factory<Digest> DEFAULT_FINGERPRINT_DIGEST_FACTORY = BuiltinDigests.sha256;
-
- private static final AtomicReference<Factory<? extends Digest>> DEFAULT_DIGEST_HOLDER =
- new AtomicReference<Factory<? extends Digest>>(DEFAULT_FINGERPRINT_DIGEST_FACTORY);
-
- private OpenSSHKeyUtils() {
- throw new UnsupportedOperationException("No instance");
- }
-
- /**
- * @return The default {@link Factory} of {@link Digest}s used
- * by the {@link #getFingerPrint(PublicKey)} and {@link #getFingerPrint(String)}
- * methods
- * @see #setDefaultFingerPrintFactory(Factory)
- */
- public static Factory<? extends Digest> getDefaultFingerPrintFactory() {
- return DEFAULT_DIGEST_HOLDER.get();
- }
-
- /**
- * @param f The {@link Factory} of {@link Digest}s to be used - may
- * not be {@code null}
- */
- public static void setDefaultFingerPrintFactory(Factory<? extends Digest> f) {
- DEFAULT_DIGEST_HOLDER.set(ValidateUtils.checkNotNull(f, "No digest factory"));
- }
-
- /**
- * @param key the public key - ignored if {@code null}
- * @return the fingerprint or {@code null} if no key.
- * <B>Note:</B> if exception encountered then returns the exception's simple class name
- * @throws Exception if cannot create fingerprint.
- * @see #getFingerPrint(Factory, PublicKey)
- */
- public static String getFingerPrint(PublicKey key) throws Exception {
- return getFingerPrint(getDefaultFingerPrintFactory(), key);
- }
-
- /**
- * @param f The {@link Factory} to create the {@link Digest} to use
- * @param key the public key - ignored if {@code null}
- * @return the fingerprint or {@code null} if no key.
- * <B>Note:</B> if exception encountered then returns the exception's simple class name
- * @throws Exception if cannot create fingerprint.
- * @see #getFingerPrint(Digest, PublicKey)
- */
- public static String getFingerPrint(Factory<? extends Digest> f, PublicKey key) throws Exception {
- return getFingerPrint(f.create(), key);
- }
-
- /**
- * @param d The {@link Digest} to use
- * @param key the public key - ignored if {@code null}
- * @return the fingerprint or {@code null} if no key.
- * @throws Exception if cannot create fingerprint.
- */
- public static String getFingerPrint(Digest d, PublicKey key) throws Exception {
- if (key == null) {
- return null;
- }
-
- Buffer buffer = new ByteArrayBuffer();
- buffer.putRawPublicKey(key);
-
- d.init();
- d.update(buffer.array(), 0, buffer.wpos());
-
- byte[] data = d.digest();
-
- String algo = d.getAlgorithm();
- if (BuiltinDigests.md5.getAlgorithm().equals(algo)) {
- return algo + ":" + BufferUtils.printHex(':', data);
- } else {
- return algo.replace("-", "").toUpperCase() + ":" + Base64.encodeToString(data).replaceAll("=", "");
- }
- }
-
- /**
- * @param expected The expected fingerprint if {@code null} or empty then returns a failure with the
- * default fingerprint.
- * @param key the public key - if {@code null} then returns null.
- * @return Pair<Boolean, String> - first is success indicator, second is actual fingerprint,
- * {@code null} if no key.
- */
- public static Pair<Boolean, String> checkFingerPrint(String expected, PublicKey key) throws Exception {
- if (key == null) {
- return null;
- }
-
- if (GenericUtils.isEmpty(expected)) {
- return new Pair<>(false, getFingerPrint(key));
- }
-
- String comps[] = GenericUtils.trimToEmpty(expected).split(":", 2);
- if (GenericUtils.length(comps) < 2) {
- return new Pair<>(false, getFingerPrint(key));
- }
-
- DigestFactory factory;
- // We know that all digests have a length > 2 - if 2 (or less) then assume a pure HEX value
- if (comps[0].length() > 2) {
- factory = BuiltinDigests.fromString(comps[0]);
- if (factory == null) {
- return new Pair<>(false, getFingerPrint(key));
- }
- expected = comps[0].toUpperCase() + ":" + comps[1];
- } else {
- factory = BuiltinDigests.md5;
- expected = factory.getName().toUpperCase() + ":" + expected;
- }
-
- String fingerprint = getFingerPrint(factory, key);
- boolean matches = BuiltinDigests.md5.getName().equals(factory.getName()) ? expected.equalsIgnoreCase(fingerprint) : expected.equals(fingerprint);
- return new Pair<>(matches, fingerprint);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/sshd-core/src/main/java/org/apache/sshd/common/digest/BuiltinDigests.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/BuiltinDigests.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/BuiltinDigests.java
index b23fae2..cf61a78 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/BuiltinDigests.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/digest/BuiltinDigests.java
@@ -119,6 +119,24 @@ public enum BuiltinDigests implements DigestInformation, DigestFactory {
return NamedResource.Utils.findByName(name, String.CASE_INSENSITIVE_ORDER, VALUES);
}
+ /**
+ * @param d The {@link Digest} instance - ignored if {@code null}
+ * @return The matching {@link org.apache.sshd.common.digest.BuiltinDigests} whose algorithm matches
+ * (case <U>insensitive</U>) the digets's algorithm - {@code null} if no match
+ */
+ public static BuiltinDigests fromDigest(Digest d) {
+ return fromAlgorithm((d == null) ? null : d.getAlgorithm());
+ }
+
+ /**
+ * @param algo The algorithm to find - ignored if {@code null}/empty
+ * @return The matching {@link org.apache.sshd.common.digest.BuiltinDigests} whose algorithm matches
+ * (case <U>insensitive</U>) the provided name - {@code null} if no match
+ */
+ public static BuiltinDigests fromAlgorithm(String algo) {
+ return DigestUtils.findFactoryByAlgorithm(algo, String.CASE_INSENSITIVE_ORDER, VALUES);
+ }
+
public static final class Constants {
public static final String MD5 = "md5";
public static final String SHA1 = "sha1";
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestUtils.java
index abfb462..30fc9bb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestUtils.java
@@ -21,9 +21,13 @@ package org.apache.sshd.common.digest;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Comparator;
import org.apache.sshd.common.Factory;
+import org.apache.sshd.common.util.Base64;
import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.BufferUtils;
/**
@@ -35,6 +39,50 @@ public final class DigestUtils {
}
/**
+ * @param <D> The generic type of digest factory
+ * @param algo The required algorithm name - ignored if {@code null}/empty
+ * @param comp The {@link Comparator} to use to compare algorithm names
+ * @param digests The factories to check - ignored if {@code null}/empty
+ * @return The first {@link DigestFactory} whose algorithm matches the required one
+ * according to the comparator - {@code null} if no match found
+ */
+ public static <D extends Digest> D findDigestByAlgorithm(String algo, Comparator<? super String> comp, Collection<? extends D> digests) {
+ if (GenericUtils.isEmpty(algo) || GenericUtils.isEmpty(digests)) {
+ return null;
+ }
+
+ for (D d : digests) {
+ if (comp.compare(algo, d.getAlgorithm()) == 0) {
+ return d;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param <F> The generic type of digest factory
+ * @param algo The required algorithm name - ignored if {@code null}/empty
+ * @param comp The {@link Comparator} to use to compare algorithm names
+ * @param factories The factories to check - ignored if {@code null}/empty
+ * @return The first {@link DigestFactory} whose algorithm matches the required one
+ * according to the comparator - {@code null} if no match found
+ */
+ public static <F extends DigestFactory> F findFactoryByAlgorithm(String algo, Comparator<? super String> comp, Collection<? extends F> factories) {
+ if (GenericUtils.isEmpty(algo) || GenericUtils.isEmpty(factories)) {
+ return null;
+ }
+
+ for (F f : factories) {
+ if (comp.compare(algo, f.getAlgorithm()) == 0) {
+ return f;
+ }
+ }
+
+ return null;
+ }
+
+ /**
* @param f The {@link Factory} to create the {@link Digest} to use
* @param s The {@link String} to digest - ignored if {@code null}/empty,
* otherwise its UTF-8 representation is used as input for the fingerprint
@@ -55,7 +103,7 @@ public final class DigestUtils {
* @throws Exception If failed to calculate the digest
*/
public static String getFingerPrint(Factory<? extends Digest> f, String s, Charset charset) throws Exception {
- return getFingerPrint(f.create(), s, charset);
+ return getFingerPrint(ValidateUtils.checkNotNull(f, "No factory").create(), s, charset);
}
/**
@@ -106,7 +154,7 @@ public final class DigestUtils {
* @throws Exception If failed to calculate the fingerprint
*/
public static String getFingerPrint(Factory<? extends Digest> f, byte[] buf, int offset, int len) throws Exception {
- return getFingerPrint(f.create(), buf, offset, len);
+ return getFingerPrint(ValidateUtils.checkNotNull(f, "No factory").create(), buf, offset, len);
}
/**
@@ -133,12 +181,15 @@ public final class DigestUtils {
return null;
}
- d.init();
+ ValidateUtils.checkNotNull(d, "No digest").init();
d.update(buf, offset, len);
byte[] data = d.digest();
- return BufferUtils.printHex(data, 0, data.length, ':');
+ String algo = d.getAlgorithm();
+ if (BuiltinDigests.md5.getAlgorithm().equals(algo)) {
+ return algo + ":" + BufferUtils.printHex(':', data).toLowerCase();
+ } else {
+ return algo.replace("-", "").toUpperCase() + ":" + Base64.encodeToString(data).replaceAll("=", "");
+ }
}
-
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java
new file mode 100644
index 0000000..82b61b6
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.common.config.keys;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.PublicKey;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.sshd.common.util.Pair;
+import org.apache.sshd.util.test.BaseTestSupport;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @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
+public class KeyUtilsFingerprintCaseSensitivityTest extends BaseTestSupport {
+
+ // CHECKSTYLE:OFF
+ private static final String KEY_STRING = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7";
+ // CHECKSTYLE:ON
+ private static final String MD5_PREFIX = "MD5:";
+ private static final String MD5 = "24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e";
+ private static final String MD5_FULL = MD5_PREFIX + MD5;
+ private static final String SHA1_PREFIX = "SHA1:";
+ private static final String SHA1 = "ZNLzC6u+F37oq8BpEAwP69EQtoA";
+ private static final String SHA1_FULL = SHA1_PREFIX + SHA1;
+
+ private static PublicKey key;
+
+ private String expected;
+ private String test;
+
+ public KeyUtilsFingerprintCaseSensitivityTest(String expected, String test) {
+ this.expected = expected;
+ this.test = test;
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws GeneralSecurityException, IOException {
+ key = PublicKeyEntry.parsePublicKeyEntry(KEY_STRING).resolvePublicKey(PublicKeyEntryResolver.FAILING);
+ }
+
+ @Parameters(name = "expected={0}, test={1}")
+ public static Collection<Object[]> parameters() {
+ return Arrays.asList(
+ new Object[] {MD5_FULL, MD5_FULL},
+ new Object[] {MD5_FULL, MD5_FULL.toUpperCase()},
+ new Object[] {MD5_FULL, MD5_FULL.toLowerCase()},
+ new Object[] {MD5_FULL, MD5_PREFIX.toUpperCase() + MD5},
+ new Object[] {MD5_FULL, MD5_PREFIX.toLowerCase() + MD5},
+ new Object[] {MD5_FULL, MD5.toLowerCase()},
+ new Object[] {MD5_FULL, MD5.toUpperCase()},
+ new Object[] {SHA1_FULL, SHA1_FULL},
+ new Object[] {SHA1_FULL, SHA1_PREFIX.toUpperCase() + SHA1},
+ new Object[] {SHA1_FULL, SHA1_PREFIX.toLowerCase() + SHA1}
+ );
+ }
+
+ @Test
+ public void testCase() throws Exception {
+ assertEquals("Check failed", new Pair<Boolean, String>(true, expected), KeyUtils.checkFingerPrint(test, key));
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java
new file mode 100644
index 0000000..69d989b
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.common.config.keys;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.sshd.common.digest.BuiltinDigests;
+import org.apache.sshd.common.digest.DigestFactory;
+import org.apache.sshd.common.util.Pair;
+import org.apache.sshd.util.test.BaseTestSupport;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @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
+public class KeyUtilsFingerprintGenerationTest extends BaseTestSupport {
+ private final PublicKey key;
+ private final DigestFactory digestFactory;
+ private final String expected;
+
+ public KeyUtilsFingerprintGenerationTest(PublicKey key, DigestFactory digestFactory, String expected) {
+ this.key = key;
+ this.digestFactory = digestFactory;
+ this.expected = expected;
+ }
+
+ @Parameters(name = "key={0}, digestFactory={1}, expected={2}")
+ public static Collection<Object[]> parameters() throws IOException, GeneralSecurityException {
+ @SuppressWarnings("cast")
+ List<Pair<String, List<Pair<DigestFactory, String>>>> KEY_ENTRIES = Collections.unmodifiableList(Arrays.asList(
+ new Pair<>(
+ // CHECKSTYLE:OFF
+ "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7",
+ // CHECKSTYLE:ON
+ Arrays.asList(
+ new Pair<>(
+ (DigestFactory)BuiltinDigests.md5,
+ "MD5:24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e"
+ ),
+ new Pair<>(
+ (DigestFactory)BuiltinDigests.sha256,
+ "SHA256:1wNOZO+/XgNGJMx8UUJst33V+bBMTz5EcL0B6y2iRv0"
+ )
+ )
+ ),
+ new Pair<>(
+ // CHECKSTYLE:OFF
+ "ssh-dss AAAAB3NzaC1kc3MAAACBAMg/IxsG5BxnF5gM7IKqqR0rftxZC+n5GlbO+J4H+iIb/KR8NBehkxG3CrBZMF96M2K1sEGYLob+3k4r71oWaPul8n5rt9kpd+JSq4iD2ygOyg6Kd1/YDBHoxneizy6I/bGsLwhAAKWcRNrXmYVKGzhrhvZWN12AJDq2mGdj3szLAAAAFQD7a2MltdUSF7FU3//SpW4WGjZbeQAAAIBf0nNsfKQL/TEMo7IpTrEMg5V0RnSigCX0+yUERS42GW/ZeCZBJw7oL2XZbuBtu63vMjDgVpnb92BdrcPgjJ7EFW6DlcyeuywStmg1ygXmDR2AQCxv0eX2CQgrdUczmRa155SDVUTvTQlO1IyKx0vwKAh1H7E3yJUfkTAJstbGYQAAAIEAtv+cdRfNevYFkp55jVqazc8zRLvfb64jzgc5oSJVc64kFs4yx+abYpGX9WxNxDlG6g2WiY8voDBB0YnUJsn0kVRjBKX9OceROxrfT4K4dVbQZsdt+SLaXWL4lGJFrFZL3LZqvySvq6xfhJfakQDDivW4hUOhFPXPHrE5/Ia3T7A= dsa-key-20130709",
+ // CHECKSTYLE:ON
+ Arrays.asList(
+ new Pair<>(
+ (DigestFactory)BuiltinDigests.md5,
+ "MD5:fb:29:14:8d:94:f9:1d:cf:6b:0e:a4:35:1d:83:44:2f"
+ ),
+ new Pair<>(
+ (DigestFactory)BuiltinDigests.sha256,
+ "SHA256:grxw4KhY1cK6eOczBWs7tDVvo9V0PQw4E1wN1gJvHlw"
+ )
+ )
+ ),
+ new Pair<>(
+ // CHECKSTYLE:OFF
+ "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBFImZtcTj842stlcVHLFBFxTEx7lu3jW9aZCvd0r9fUNKZ6LbRPh6l1oJ4ozArnw7XreQBUc5oNd9HB5RNJ8jl1nWXY5cXBA7McZrKZrYmk+zxNhH6UL+kMLaJkyngJHQw== root@osv-linux",
+ // CHECKSTYLE:ON
+ Arrays.asList(
+ new Pair<>(
+ (DigestFactory)BuiltinDigests.md5,
+ "MD5:e6:dc:a2:4f:5b:11:b2:3c:0f:e8:f6:d8:d1:01:e9:d3"
+ ),
+ new Pair<>(
+ (DigestFactory)BuiltinDigests.sha512,
+ "SHA512:4w6ZB78tmFWhpN2J50Ok6WeMJhZp1X0xN0EKWxZmRLcYDbCWhyJDe8lgrQKWqdTCMZ5aNEBl9xQUklcC5Gt2jg"
+ )
+ )
+ )
+ ));
+
+ List<Object[]> ret = new ArrayList<>();
+ for (Pair<String, List<Pair<DigestFactory, String>>> kentry : KEY_ENTRIES) {
+ try {
+ PublicKey key = PublicKeyEntry.parsePublicKeyEntry(kentry.getFirst()).resolvePublicKey(PublicKeyEntryResolver.FAILING);
+ for (Pair<DigestFactory, String> dentry : kentry.getSecond()) {
+ ret.add(new Object[]{key, dentry.getFirst(), dentry.getSecond()});
+ }
+ } catch (InvalidKeySpecException e) {
+ System.out.println("Skip unsupported key: " + kentry.getFirst());
+ }
+ }
+
+ return ret;
+ }
+
+ @Test
+ public void testFingerprint() throws Exception {
+ String name = digestFactory.getName();
+ assertEquals(
+ String.format("Fingerprint does not match for digest %s", name),
+ expected,
+ KeyUtils.getFingerPrint(digestFactory, key)
+ );
+ assertEquals(
+ String.format("Fingerprint check failed for digest %s", name),
+ new Pair<Boolean, String>(true, expected),
+ KeyUtils.checkFingerPrint(expected, digestFactory, key)
+ );
+ assertEquals(
+ String.format("Fingerprint check succeeded for invalid digest %s", name),
+ new Pair<Boolean, String>(false, expected),
+ KeyUtils.checkFingerPrint(expected + "A", digestFactory, key)
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsAlgoTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsAlgoTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsAlgoTest.java
deleted file mode 100644
index 9b10f15..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsAlgoTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.config.keys;
-
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-import java.security.PublicKey;
-import java.security.spec.InvalidKeySpecException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.sshd.common.digest.BuiltinDigests;
-import org.apache.sshd.common.digest.DigestFactory;
-import org.apache.sshd.common.util.Pair;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.junit.runners.Parameterized.Parameters;
-import org.junit.runners.Parameterized;
-
-/**
- * @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
-public class OpenSSHKeyUtilsAlgoTest extends BaseTestSupport {
-
- @SuppressWarnings("cast")
- private static final List<Pair<String, List<Pair<DigestFactory, String>>>> KEY_ENTRIES = Collections.unmodifiableList(Arrays.asList(
- new Pair<>(
- // CHECKSTYLE:OFF
- "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7",
- // CHECKSTYLE:ON
- Collections.unmodifiableList(Arrays.asList(
- new Pair<>(
- (DigestFactory)BuiltinDigests.md5,
- "MD5:24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e"
- ),
- new Pair<>(
- (DigestFactory)BuiltinDigests.sha256,
- "SHA256:1wNOZO+/XgNGJMx8UUJst33V+bBMTz5EcL0B6y2iRv0"
- )
- ))
- ),
- new Pair<>(
- // CHECKSTYLE:OFF
- "ssh-dss AAAAB3NzaC1kc3MAAACBAMg/IxsG5BxnF5gM7IKqqR0rftxZC+n5GlbO+J4H+iIb/KR8NBehkxG3CrBZMF96M2K1sEGYLob+3k4r71oWaPul8n5rt9kpd+JSq4iD2ygOyg6Kd1/YDBHoxneizy6I/bGsLwhAAKWcRNrXmYVKGzhrhvZWN12AJDq2mGdj3szLAAAAFQD7a2MltdUSF7FU3//SpW4WGjZbeQAAAIBf0nNsfKQL/TEMo7IpTrEMg5V0RnSigCX0+yUERS42GW/ZeCZBJw7oL2XZbuBtu63vMjDgVpnb92BdrcPgjJ7EFW6DlcyeuywStmg1ygXmDR2AQCxv0eX2CQgrdUczmRa155SDVUTvTQlO1IyKx0vwKAh1H7E3yJUfkTAJstbGYQAAAIEAtv+cdRfNevYFkp55jVqazc8zRLvfb64jzgc5oSJVc64kFs4yx+abYpGX9WxNxDlG6g2WiY8voDBB0YnUJsn0kVRjBKX9OceROxrfT4K4dVbQZsdt+SLaXWL4lGJFrFZL3LZqvySvq6xfhJfakQDDivW4hUOhFPXPHrE5/Ia3T7A= dsa-key-20130709",
- // CHECKSTYLE:ON
- Collections.unmodifiableList(Arrays.asList(
- new Pair<>(
- (DigestFactory)BuiltinDigests.md5,
- "MD5:fb:29:14:8d:94:f9:1d:cf:6b:0e:a4:35:1d:83:44:2f"
- ),
- new Pair<>(
- (DigestFactory)BuiltinDigests.sha256,
- "SHA256:grxw4KhY1cK6eOczBWs7tDVvo9V0PQw4E1wN1gJvHlw"
- )
- ))
- ),
- new Pair<>(
- // CHECKSTYLE:OFF
- "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBFImZtcTj842stlcVHLFBFxTEx7lu3jW9aZCvd0r9fUNKZ6LbRPh6l1oJ4ozArnw7XreQBUc5oNd9HB5RNJ8jl1nWXY5cXBA7McZrKZrYmk+zxNhH6UL+kMLaJkyngJHQw== root@osv-linux",
- // CHECKSTYLE:ON
- Collections.unmodifiableList(Arrays.asList(
- new Pair<>(
- (DigestFactory)BuiltinDigests.md5,
- "MD5:e6:dc:a2:4f:5b:11:b2:3c:0f:e8:f6:d8:d1:01:e9:d3"
- ),
- new Pair<>(
- (DigestFactory)BuiltinDigests.sha512,
- "SHA512:4w6ZB78tmFWhpN2J50Ok6WeMJhZp1X0xN0EKWxZmRLcYDbCWhyJDe8lgrQKWqdTCMZ5aNEBl9xQUklcC5Gt2jg"
- )
- ))
- )
- ));
-
- public final PublicKey key;
- public final DigestFactory digestFactory;
- public final String expected;
-
- public OpenSSHKeyUtilsAlgoTest(PublicKey key, DigestFactory digestFactory, String expected) {
- this.key = key;
- this.digestFactory = digestFactory;
- this.expected = expected;
- }
-
- @Parameters(name = "key={0}, digestFactory={1}, expected={2}")
- public static Collection<Object[]> parameters() throws IOException, GeneralSecurityException {
- List<Object[]> ret = new ArrayList<>();
- for (Pair<String, List<Pair<DigestFactory, String>>> kentry : KEY_ENTRIES) {
- try {
- PublicKey key = PublicKeyEntry.parsePublicKeyEntry(kentry.getFirst()).resolvePublicKey(PublicKeyEntryResolver.FAILING);
- for (Pair<DigestFactory, String> dentry : kentry.getSecond()) {
- ret.add(
- new Object[] {
- key,
- dentry.getFirst(),
- dentry.getSecond()
- }
- );
- }
- } catch (InvalidKeySpecException e) {
- System.out.println("Skip unsupported key: " + kentry.getFirst());
- }
- }
- return ret;
- }
-
- @Test
- public void testFingerprint() throws Exception {
- String name = digestFactory.getName();
- assertEquals(
- String.format("Fingerprint does not match for digest %s", name),
- expected,
- OpenSSHKeyUtils.getFingerPrint(digestFactory, key)
- );
- assertEquals(
- String.format("Fingerprint check failed for digest %s", name),
- new Pair<Boolean, String>(true, expected),
- OpenSSHKeyUtils.checkFingerPrint(expected, key)
- );
- assertEquals(
- String.format("Fingerprint check succeeded for invalid digest %s", name),
- new Pair<Boolean, String>(false, expected),
- OpenSSHKeyUtils.checkFingerPrint(expected + "A", key)
- );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f8390836/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsCheckTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsCheckTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsCheckTest.java
deleted file mode 100644
index 2c2a69d..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsCheckTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.config.keys;
-
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-import java.security.PublicKey;
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.sshd.common.util.Pair;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.junit.runners.Parameterized.Parameters;
-import org.junit.runners.Parameterized;
-
-/**
- * @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
-public class OpenSSHKeyUtilsCheckTest extends BaseTestSupport {
-
- // CHECKSTYLE:OFF
- private static final String KEY_STRING = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7";
- // CHECKSTYLE:ON
- private static final String MD5_PREFIX = "MD5:";
- private static final String MD5 = "24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e";
- private static final String MD5_FULL = MD5_PREFIX + MD5;
- private static final String SHA1_PREFIX = "SHA1:";
- private static final String SHA1 = "ZNLzC6u+F37oq8BpEAwP69EQtoA";
- private static final String SHA1_FULL = SHA1_PREFIX + SHA1;
-
- private static PublicKey key;
-
- private String expected;
- private String test;
-
- public OpenSSHKeyUtilsCheckTest(String expected, String test) {
- this.expected = expected;
- this.test = test;
- }
-
- @BeforeClass
- public static void beforeClass() throws GeneralSecurityException, IOException {
- key = PublicKeyEntry.parsePublicKeyEntry(KEY_STRING).resolvePublicKey(PublicKeyEntryResolver.FAILING);
- }
-
- @Parameters(name = "expected={0}, test={1}")
- public static Collection<Object[]> parameters() {
- return Arrays.asList(
- new Object[] {MD5_FULL, MD5_FULL},
- new Object[] {MD5_FULL, MD5_FULL.toUpperCase()},
- new Object[] {MD5_FULL, MD5_FULL.toLowerCase()},
- new Object[] {MD5_FULL, MD5_PREFIX.toUpperCase() + MD5},
- new Object[] {MD5_FULL, MD5_PREFIX.toLowerCase() + MD5},
- new Object[] {MD5_FULL, MD5.toLowerCase()},
- new Object[] {MD5_FULL, MD5.toUpperCase()},
- new Object[] {SHA1_FULL, SHA1_FULL},
- new Object[] {SHA1_FULL, SHA1_PREFIX.toUpperCase() + SHA1},
- new Object[] {SHA1_FULL, SHA1_PREFIX.toLowerCase() + SHA1}
- );
- }
-
- @Test
- public void testCase() throws Exception {
- assertEquals("Check failed", new Pair<Boolean, String>(true, expected), OpenSSHKeyUtils.checkFingerPrint(test, key));
- }
-
-}