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 13:37:25 UTC

mina-sshd git commit: [SSHD-586] openssh compliant public key fingerprint

Repository: mina-sshd
Updated Branches:
  refs/heads/master 0c89da89e -> e4cb8082d


[SSHD-586] openssh compliant public key fingerprint

* Based on https://github.com/apache/mina-sshd/pull/19

Signed-off-by: Lyor Goldstein <lg...@vmware.com>


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/e4cb8082
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/e4cb8082
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/e4cb8082

Branch: refs/heads/master
Commit: e4cb8082d692b546c56be6c7642981ee4249d2da
Parents: 0c89da8
Author: Alon Bar-Lev <al...@gmail.com>
Authored: Tue Nov 24 14:37:15 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Tue Nov 24 14:37:15 2015 +0200

----------------------------------------------------------------------
 .../common/config/keys/OpenSSHKeyUtils.java     | 163 +++++++++++++++++++
 .../sshd/common/digest/DigestFactory.java       |   7 +-
 .../java/org/apache/sshd/common/util/Pair.java  |  27 ++-
 .../sshd/common/config/keys/KeyUtilsTest.java   |   5 +
 .../config/keys/OpenSSHKeyUtilsAlgoTest.java    | 151 +++++++++++++++++
 .../config/keys/OpenSSHKeyUtilsCheckTest.java   |  90 ++++++++++
 6 files changed, 438 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e4cb8082/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
new file mode 100644
index 0000000..0674ea0
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtils.java
@@ -0,0 +1,163 @@
+/*
+ * 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/e4cb8082/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestFactory.java
index ee8630f..0bff18f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/digest/DigestFactory.java
@@ -24,8 +24,9 @@ import org.apache.sshd.common.NamedFactory;
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
-// CHECKSTYLE:OFF
 public interface DigestFactory extends NamedFactory<Digest> {
-
+    /**
+     * @return The underlying digest algorithm
+     */
+    String getAlgorithm();
 }
-//CHECKSTYLE:ON

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e4cb8082/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java
index b1e76b9..4621862 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java
@@ -36,15 +36,38 @@ public class Pair<F, S> {
         this.second = second;
     }
 
-    public F getFirst() {
+    public final F getFirst() {
         return first;
     }
 
-    public S getSecond() {
+    public final S getSecond() {
         return second;
     }
 
     @Override
+    public int hashCode() {
+        return Objects.hashCode(getFirst()) * 31 + Objects.hashCode(getSecond());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+
+        if (obj == this) {
+            return true;
+        }
+
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+
+        Pair<?, ?> other = (Pair<?, ?>)obj;
+        return Objects.equals(getFirst(), other.getFirst()) && Objects.equals(getSecond(), other.getSecond());
+    }
+
+    @Override
     public String toString() {
         return Objects.toString(getFirst()) + ", " + Objects.toString(getSecond());
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e4cb8082/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
index afe5c7d..4ac309c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
@@ -125,6 +125,11 @@ public class KeyUtilsTest extends BaseTestSupport {
                 }
 
                 @Override
+                public String getAlgorithm() {
+                    return digest.getAlgorithm();
+                }
+
+                @Override
                 public Digest create() {
                     return digest;
                 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e4cb8082/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
new file mode 100644
index 0000000..9b10f15
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsAlgoTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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/e4cb8082/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
new file mode 100644
index 0000000..2c2a69d
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/OpenSSHKeyUtilsCheckTest.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.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));
+    }
+
+}