You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2015/03/30 11:17:55 UTC
[6/6] mina-sshd git commit: [SSHD-430] Refactor digests, macs,
signatures as enums
[SSHD-430] Refactor digests, macs, signatures as enums
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/b9e1401c
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/b9e1401c
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/b9e1401c
Branch: refs/heads/master
Commit: b9e1401c1f7d8938f6a6db66c6bccf930139074a
Parents: 31d4dc5
Author: Guillaume Nodet <gn...@apache.org>
Authored: Fri Mar 27 08:35:04 2015 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Mar 30 10:52:43 2015 +0200
----------------------------------------------------------------------
.../main/java/org/apache/sshd/SshBuilder.java | 55 +++----
.../main/java/org/apache/sshd/SshClient.java | 5 -
.../org/apache/sshd/agent/local/AgentImpl.java | 10 +-
.../org/apache/sshd/common/NamedFactory.java | 7 +-
.../org/apache/sshd/common/cipher/ECCurves.java | 10 +-
.../sshd/common/digest/BuiltinDigests.java | 141 ++++++++++++++++++
.../java/org/apache/sshd/common/digest/MD5.java | 51 -------
.../org/apache/sshd/common/digest/SHA1.java | 51 -------
.../org/apache/sshd/common/digest/SHA256.java | 52 -------
.../org/apache/sshd/common/digest/SHA384.java | 52 -------
.../org/apache/sshd/common/digest/SHA512.java | 52 -------
.../sshd/common/kex/BuiltinDHFactories.java | 11 +-
.../org/apache/sshd/common/mac/BuiltinMacs.java | 149 +++++++++++++++++++
.../org/apache/sshd/common/mac/HMACMD5.java | 48 ------
.../org/apache/sshd/common/mac/HMACMD596.java | 49 ------
.../org/apache/sshd/common/mac/HMACSHA1.java | 48 ------
.../org/apache/sshd/common/mac/HMACSHA196.java | 48 ------
.../org/apache/sshd/common/mac/HMACSHA256.java | 48 ------
.../org/apache/sshd/common/mac/HMACSHA512.java | 48 ------
.../common/signature/AbstractSignatureDSA.java | 91 -----------
.../common/signature/BuiltinSignatures.java | 149 +++++++++++++++++++
.../sshd/common/signature/SignatureDSA.java | 77 +++++++---
.../sshd/common/signature/SignatureECDSA.java | 68 ---------
.../sshd/common/signature/SignatureRSA.java | 15 --
.../org/apache/sshd/common/util/KeyUtils.java | 5 +-
.../server/session/ServerUserAuthService.java | 2 +-
.../test/java/org/apache/sshd/EcdsaTest.java | 44 +-----
.../src/test/java/org/apache/sshd/LoadTest.java | 8 +-
.../src/test/java/org/apache/sshd/MacTest.java | 19 +--
29 files changed, 557 insertions(+), 856 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java b/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
index df9fad8..38ebf63 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
@@ -46,20 +46,13 @@ import org.apache.sshd.common.file.nativefs.NativeFileSystemFactory;
import org.apache.sshd.common.forward.DefaultTcpipForwarderFactory;
import org.apache.sshd.common.forward.TcpipServerChannel;
import org.apache.sshd.common.kex.BuiltinDHFactories;
-import org.apache.sshd.common.mac.HMACMD5;
-import org.apache.sshd.common.mac.HMACMD596;
-import org.apache.sshd.common.mac.HMACSHA1;
-import org.apache.sshd.common.mac.HMACSHA196;
-import org.apache.sshd.common.mac.HMACSHA256;
-import org.apache.sshd.common.mac.HMACSHA512;
import org.apache.sshd.common.kex.DHFactory;
+import org.apache.sshd.common.mac.BuiltinMacs;
import org.apache.sshd.common.random.BouncyCastleRandom;
import org.apache.sshd.common.random.JceRandom;
import org.apache.sshd.common.random.SingletonRandomFactory;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.signature.SignatureDSA;
-import org.apache.sshd.common.signature.SignatureECDSA;
-import org.apache.sshd.common.signature.SignatureRSA;
+import org.apache.sshd.common.signature.BuiltinSignatures;
import org.apache.sshd.common.util.ObjectBuilder;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.server.channel.ChannelSession;
@@ -106,12 +99,12 @@ public class SshBuilder {
protected S fillWithDefaultValues() {
if (SecurityUtils.isBouncyCastleRegistered()) {
if (signatureFactories == null) {
- signatureFactories = Arrays.asList(
- new SignatureECDSA.NISTP256Factory(),
- new SignatureECDSA.NISTP384Factory(),
- new SignatureECDSA.NISTP521Factory(),
- new SignatureDSA.Factory(),
- new SignatureRSA.Factory());
+ signatureFactories = Arrays.<NamedFactory<Signature>>asList(
+ BuiltinSignatures.nistp256,
+ BuiltinSignatures.nistp384,
+ BuiltinSignatures.nistp521,
+ BuiltinSignatures.dsa,
+ BuiltinSignatures.rsa);
}
if (randomFactory == null) {
randomFactory = new SingletonRandomFactory(new BouncyCastleRandom.Factory());
@@ -119,21 +112,21 @@ public class SshBuilder {
// EC keys are not supported until OpenJDK 7
} else if (SecurityUtils.hasEcc()) {
if (signatureFactories == null) {
- signatureFactories = Arrays.asList(
- new SignatureECDSA.NISTP256Factory(),
- new SignatureECDSA.NISTP384Factory(),
- new SignatureECDSA.NISTP521Factory(),
- new SignatureDSA.Factory(),
- new SignatureRSA.Factory());
+ signatureFactories = Arrays.<NamedFactory<Signature>>asList(
+ BuiltinSignatures.nistp256,
+ BuiltinSignatures.nistp384,
+ BuiltinSignatures.nistp521,
+ BuiltinSignatures.dsa,
+ BuiltinSignatures.rsa);
}
if (randomFactory == null) {
randomFactory = new SingletonRandomFactory(new JceRandom.Factory());
}
} else {
if (signatureFactories == null) {
- signatureFactories = Arrays.asList(
- new SignatureDSA.Factory(),
- new SignatureRSA.Factory());
+ signatureFactories = Arrays.<NamedFactory<Signature>>asList(
+ BuiltinSignatures.dsa,
+ BuiltinSignatures.rsa);
}
if (randomFactory == null) {
randomFactory = new SingletonRandomFactory(new JceRandom.Factory());
@@ -156,13 +149,13 @@ public class SshBuilder {
new CompressionNone.Factory());
}
if (macFactories == null) {
- macFactories = Arrays.asList(
- new HMACSHA256.Factory(),
- new HMACSHA512.Factory(),
- new HMACSHA1.Factory(),
- new HMACMD5.Factory(),
- new HMACSHA196.Factory(),
- new HMACMD596.Factory());
+ macFactories = Arrays.<NamedFactory<Mac>>asList(
+ BuiltinMacs.hmacsha256,
+ BuiltinMacs.hmacsha512,
+ BuiltinMacs.hmacsha1,
+ BuiltinMacs.hmacmd5,
+ BuiltinMacs.hmacsha196,
+ BuiltinMacs.hmacmd596);
}
if (fileSystemFactory == null) {
fileSystemFactory = new NativeFileSystemFactory();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
index 25be1f4..b3c102e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
@@ -19,15 +19,11 @@
package org.apache.sshd;
import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.io.Writer;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
@@ -71,7 +67,6 @@ import org.apache.sshd.common.io.IoConnectFuture;
import org.apache.sshd.common.io.IoConnector;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.NoCloseInputStream;
import org.apache.sshd.common.util.NoCloseOutputStream;
import org.apache.sshd.common.util.SecurityUtils;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
index 179d9f2..dc1694c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
@@ -32,9 +32,7 @@ import java.util.List;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.common.Signature;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.signature.SignatureDSA;
-import org.apache.sshd.common.signature.SignatureECDSA;
-import org.apache.sshd.common.signature.SignatureRSA;
+import org.apache.sshd.common.signature.BuiltinSignatures;
/**
* A local SSH agent implementation
@@ -66,12 +64,12 @@ public class AgentImpl implements SshAgent {
try {
Signature verif;
if (kp.getFirst().getPublic() instanceof DSAPublicKey) {
- verif = new SignatureDSA();
+ verif = BuiltinSignatures.dsa.create();
} else if (kp.getFirst().getPublic() instanceof ECPublicKey) {
ECPublicKey pubKey = (ECPublicKey) kp.getFirst().getPublic();
- verif = SignatureECDSA.getByCurveSize(pubKey.getParams());
+ verif = BuiltinSignatures.getByCurveSize(pubKey.getParams());
} else if (kp.getFirst().getPublic() instanceof RSAPublicKey) {
- verif = new SignatureRSA();
+ verif = BuiltinSignatures.rsa.create();
} else {
throw new SshException("Unsupported key type");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/NamedFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/NamedFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/NamedFactory.java
index 6850b8d..9d2c164 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/NamedFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/NamedFactory.java
@@ -48,7 +48,7 @@ public interface NamedFactory<T> extends Factory<T>, NamedResource {
return Collections.emptyList();
}
- List<String> names = new ArrayList<String>(factories.size());
+ List<String> names = new ArrayList<>(factories.size());
for (NamedFactory<?> f : factories) {
names.add(f.getName());
}
@@ -78,12 +78,11 @@ public interface NamedFactory<T> extends Factory<T>, NamedResource {
* Get a comma separated list of the factory names from the given list.
*
* @param factories list of available factories
- * @param <T> type of object to create
* @return a comma separated list of factory names
*/
- public static <T> String getNames(Collection<? extends NamedFactory<T>> factories) {
+ public static String getNames(Collection<? extends NamedFactory<?>> factories) {
StringBuilder sb = new StringBuilder();
- for (NamedFactory<T> f : factories) {
+ for (NamedFactory<?> f : factories) {
if (sb.length() > 0) {
sb.append(",");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
index 7c7a951..927b94c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
@@ -27,9 +27,7 @@ import java.util.Map;
import java.util.TreeMap;
import org.apache.sshd.common.Digest;
-import org.apache.sshd.common.digest.SHA256;
-import org.apache.sshd.common.digest.SHA384;
-import org.apache.sshd.common.digest.SHA512;
+import org.apache.sshd.common.digest.BuiltinDigests;
/**
* Utilities for working with elliptic curves.
@@ -76,11 +74,11 @@ public class ECCurves {
public static Digest getDigestForParams(ECParameterSpec params) {
int size = getCurveSize(params);
if (size <= 256) {
- return new SHA256();
+ return BuiltinDigests.sha256.create();
} else if (size <= 384) {
- return new SHA384();
+ return BuiltinDigests.sha384.create();
} else {
- return new SHA512();
+ return BuiltinDigests.sha512.create();
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/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
new file mode 100644
index 0000000..bb57f4c
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/digest/BuiltinDigests.java
@@ -0,0 +1,141 @@
+/*
+ * 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.digest;
+
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+
+import org.apache.sshd.common.Digest;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.util.GenericUtils;
+
+/**
+ * Provides easy access to the currently implemented digests
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public enum BuiltinDigests implements NamedFactory<Digest> {
+ md5(Constants.MD5) {
+ @Override
+ public Digest create() {
+ return new BaseDigest("MD5", 16);
+ }
+ },
+ sha1(Constants.SHA1) {
+ @Override
+ public Digest create() {
+ return new BaseDigest("SHA-1", 20);
+ }
+ },
+ sha256(Constants.SHA256) {
+ @Override
+ public Digest create() {
+ return new BaseDigest("SHA-256", 32);
+ }
+ },
+ sha384(Constants.SHA384) {
+ @Override
+ public Digest create() {
+ return new BaseDigest("SHA-384", 48);
+ }
+ },
+ sha512(Constants.SHA512) {
+ @Override
+ public Digest create() {
+ return new BaseDigest("SHA-512", 64);
+ }
+ };
+
+ private final String factoryName;
+
+ @Override
+ public final String getName() {
+ return factoryName;
+ }
+
+ BuiltinDigests(String facName) {
+ factoryName = facName;
+ }
+
+
+ public static final Set<BuiltinDigests> VALUES =
+ Collections.unmodifiableSet(EnumSet.allOf(BuiltinDigests.class));
+
+ /**
+ * @param s The {@link Enum}'s name - ignored if {@code null}/empty
+ * @return The matching {@link org.apache.sshd.common.digest.BuiltinDigests} whose {@link Enum#name()} matches
+ * (case <U>insensitive</U>) the provided argument - {@code null} if no match
+ */
+ public static BuiltinDigests fromString(String s) {
+ if (GenericUtils.isEmpty(s)) {
+ return null;
+ }
+
+ for (BuiltinDigests c : VALUES) {
+ if (s.equalsIgnoreCase(c.name())) {
+ return c;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param factory The {@link org.apache.sshd.common.NamedFactory} for the cipher - ignored if {@code null}
+ * @return The matching {@link org.apache.sshd.common.digest.BuiltinDigests} whose factory name matches
+ * (case <U>insensitive</U>) the digest factory name
+ * @see #fromFactoryName(String)
+ */
+ public static BuiltinDigests fromFactory(NamedFactory<Digest> factory) {
+ if (factory == null) {
+ return null;
+ } else {
+ return fromFactoryName(factory.getName());
+ }
+ }
+
+ /**
+ * @param n The factory name - ignored if {@code null}/empty
+ * @return The matching {@link org.apache.sshd.common.digest.BuiltinDigests} whose factory name matches
+ * (case <U>insensitive</U>) the provided name - {@code null} if no match
+ */
+ public static BuiltinDigests fromFactoryName(String n) {
+ if (GenericUtils.isEmpty(n)) {
+ return null;
+ }
+
+ for (BuiltinDigests c : VALUES) {
+ if (n.equalsIgnoreCase(c.getName())) {
+ return c;
+ }
+ }
+
+ return null;
+ }
+
+ private static class Constants {
+ public static final String MD5 = "md5";
+ public static final String SHA1 = "sha1";
+ public static final String SHA256 = "sha256";
+ public static final String SHA384 = "sha384";
+ public static final String SHA512 = "sha512";
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/digest/MD5.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/MD5.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/MD5.java
deleted file mode 100644
index 72f2f16..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/MD5.java
+++ /dev/null
@@ -1,51 +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.digest;
-
-import org.apache.sshd.common.Digest;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * MD5 Digest.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class MD5 extends BaseDigest {
-
- /**
- * Named factory for MD5 digest
- */
- public static class Factory implements NamedFactory<Digest> {
-
- public String getName() {
- return "md5";
- }
-
- public Digest create() {
- return new MD5();
- }
- }
-
- /**
- * Create a new instance of a MD5 digest
- */
- public MD5() {
- super("MD5", 16);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA1.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA1.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA1.java
deleted file mode 100644
index 0c8d6ce..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA1.java
+++ /dev/null
@@ -1,51 +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.digest;
-
-import org.apache.sshd.common.Digest;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * SHA1 Digest.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class SHA1 extends BaseDigest {
-
- /**
- * Named factory for SHA1 digest
- */
- public static class Factory implements NamedFactory<Digest> {
-
- public String getName() {
- return "sha1";
- }
-
- public Digest create() {
- return new SHA1();
- }
- }
-
- /**
- * Create a new instance of a SHA1 digest
- */
- public SHA1() {
- super("SHA-1", 20);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA256.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA256.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA256.java
deleted file mode 100644
index 079663d..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA256.java
+++ /dev/null
@@ -1,52 +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.digest;
-
-import org.apache.sshd.common.Digest;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * SHA-256 Digest.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class SHA256 extends BaseDigest {
-
- /**
- * Named factory for SHA1 digest
- */
- public static class Factory implements NamedFactory<Digest> {
-
- public String getName() {
- return "sha256";
- }
-
- public Digest create() {
- return new SHA256();
- }
- }
-
- /**
- * Create a new instance of a SHA-256 digest
- */
- public SHA256() {
- super("SHA-256", 32);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA384.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA384.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA384.java
deleted file mode 100644
index 04dc356..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA384.java
+++ /dev/null
@@ -1,52 +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.digest;
-
-import org.apache.sshd.common.Digest;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * SHA-384 Digest.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class SHA384 extends BaseDigest {
-
- /**
- * Named factory for SHA1 digest
- */
- public static class Factory implements NamedFactory<Digest> {
-
- public String getName() {
- return "sha384";
- }
-
- public Digest create() {
- return new SHA384();
- }
- }
-
- /**
- * Create a new instance of a SHA-384 digest
- */
- public SHA384() {
- super("SHA-384", 48);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA512.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA512.java b/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA512.java
deleted file mode 100644
index 943ee9a..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/digest/SHA512.java
+++ /dev/null
@@ -1,52 +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.digest;
-
-import org.apache.sshd.common.Digest;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * SHA-512 Digest.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class SHA512 extends BaseDigest {
-
- /**
- * Named factory for SHA1 digest
- */
- public static class Factory implements NamedFactory<Digest> {
-
- public String getName() {
- return "sha512";
- }
-
- public Digest create() {
- return new SHA512();
- }
- }
-
- /**
- * Create a new instance of a SHA-512 digest
- */
- public SHA512() {
- super("SHA-512", 64);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
index b2c63cd..b3ba27d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
@@ -25,8 +25,7 @@ import java.util.EnumSet;
import java.util.Set;
import org.apache.sshd.common.cipher.ECCurves;
-import org.apache.sshd.common.digest.SHA1;
-import org.apache.sshd.common.digest.SHA256;
+import org.apache.sshd.common.digest.BuiltinDigests;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.SecurityUtils;
@@ -41,7 +40,7 @@ public enum BuiltinDHFactories implements DHFactory {
if (params != null && params.length > 0) {
throw new IllegalArgumentException("No accepted parameters for " + getName());
}
- return new DHG(new SHA1.Factory(), new BigInteger(DHGroupData.getP1()), new BigInteger(DHGroupData.getG()));
+ return new DHG(BuiltinDigests.sha1, new BigInteger(DHGroupData.getP1()), new BigInteger(DHGroupData.getG()));
}
},
dhg14(Constants.DIFFIE_HELLMAN_GROUP14_SHA1) {
@@ -50,7 +49,7 @@ public enum BuiltinDHFactories implements DHFactory {
if (params != null && params.length > 0) {
throw new IllegalArgumentException("No accepted parameters for " + getName());
}
- return new DHG(new SHA1.Factory(), new BigInteger(DHGroupData.getP14()), new BigInteger(DHGroupData.getG()));
+ return new DHG(BuiltinDigests.sha1, new BigInteger(DHGroupData.getP14()), new BigInteger(DHGroupData.getG()));
}
@Override
public boolean isSupported() {
@@ -64,7 +63,7 @@ public enum BuiltinDHFactories implements DHFactory {
|| !(params[0] instanceof BigInteger) || !(params[1] instanceof BigInteger)) {
throw new IllegalArgumentException("Bad parameters for " + getName());
}
- return new DHG(new SHA1.Factory(), (BigInteger) params[0], (BigInteger) params[1]);
+ return new DHG(BuiltinDigests.sha1, (BigInteger) params[0], (BigInteger) params[1]);
}
@Override
public boolean isGroupExchange() {
@@ -78,7 +77,7 @@ public enum BuiltinDHFactories implements DHFactory {
|| !(params[0] instanceof BigInteger) || !(params[1] instanceof BigInteger)) {
throw new IllegalArgumentException("Bad parameters for " + getName());
}
- return new DHG(new SHA256.Factory(), (BigInteger) params[0], (BigInteger) params[1]);
+ return new DHG(BuiltinDigests.sha256, (BigInteger) params[0], (BigInteger) params[1]);
}
@Override
public boolean isSupported() { // avoid "Prime size must be multiple of 64, and can only range from 512 to 2048 (inclusive)"
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java
new file mode 100644
index 0000000..df8aa6d
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java
@@ -0,0 +1,149 @@
+/*
+ * 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.mac;
+
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+
+import org.apache.sshd.common.Digest;
+import org.apache.sshd.common.Mac;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.util.GenericUtils;
+
+/**
+ * Provides easy access to the currently implemented macs
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public enum BuiltinMacs implements NamedFactory<Mac> {
+ hmacmd5(Constants.HMAC_MD5) {
+ @Override
+ public Mac create() {
+ return new BaseMac("HmacMD5", 16, 16);
+ }
+ },
+ hmacmd596(Constants.HMAC_MD5_96) {
+ @Override
+ public Mac create() {
+ return new BaseMac("HmacMD5", 12, 16);
+ }
+ },
+ hmacsha1(Constants.HMAC_SHA1) {
+ @Override
+ public Mac create() {
+ return new BaseMac("HmacSHA1", 20, 20);
+ }
+ },
+ hmacsha196(Constants.HMAC_SHA1_96) {
+ @Override
+ public Mac create() {
+ return new BaseMac("HmacSHA1", 12, 20);
+ }
+ },
+ hmacsha256(Constants.HMAC_SHA2_256) {
+ @Override
+ public Mac create() {
+ return new BaseMac("HmacSHA256", 32, 32);
+ }
+ },
+ hmacsha512(Constants.HMAC_SHA2_512) {
+ @Override
+ public Mac create() {
+ return new BaseMac("HmacSHA1", 64, 64);
+ }
+ };
+
+ private final String factoryName;
+
+ @Override
+ public final String getName() {
+ return factoryName;
+ }
+
+ BuiltinMacs(String facName) {
+ factoryName = facName;
+ }
+
+
+ public static final Set<BuiltinMacs> VALUES =
+ Collections.unmodifiableSet(EnumSet.allOf(BuiltinMacs.class));
+
+ /**
+ * @param s The {@link Enum}'s name - ignored if {@code null}/empty
+ * @return The matching {@link org.apache.sshd.common.mac.BuiltinMacs} whose {@link Enum#name()} matches
+ * (case <U>insensitive</U>) the provided argument - {@code null} if no match
+ */
+ public static BuiltinMacs fromString(String s) {
+ if (GenericUtils.isEmpty(s)) {
+ return null;
+ }
+
+ for (BuiltinMacs c : VALUES) {
+ if (s.equalsIgnoreCase(c.name())) {
+ return c;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param factory The {@link org.apache.sshd.common.NamedFactory} for the cipher - ignored if {@code null}
+ * @return The matching {@link org.apache.sshd.common.mac.BuiltinMacs} whose factory name matches
+ * (case <U>insensitive</U>) the digest factory name
+ * @see #fromFactoryName(String)
+ */
+ public static BuiltinMacs fromFactory(NamedFactory<Digest> factory) {
+ if (factory == null) {
+ return null;
+ } else {
+ return fromFactoryName(factory.getName());
+ }
+ }
+
+ /**
+ * @param n The factory name - ignored if {@code null}/empty
+ * @return The matching {@link org.apache.sshd.common.mac.BuiltinMacs} whose factory name matches
+ * (case <U>insensitive</U>) the provided name - {@code null} if no match
+ */
+ public static BuiltinMacs fromFactoryName(String n) {
+ if (GenericUtils.isEmpty(n)) {
+ return null;
+ }
+
+ for (BuiltinMacs c : VALUES) {
+ if (n.equalsIgnoreCase(c.getName())) {
+ return c;
+ }
+ }
+
+ return null;
+ }
+
+ private static class Constants {
+ public static final String HMAC_MD5 = "hmac-md5";
+ public static final String HMAC_MD5_96 = "hmac-md5-96";
+ public static final String HMAC_SHA1 = "hmac-sha1";
+ public static final String HMAC_SHA1_96 = "hmac-sha1-96";
+ public static final String HMAC_SHA2_256 = "hmac-sha2-256";
+ public static final String HMAC_SHA2_512 = "hmac-sha2-512";
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD5.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD5.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD5.java
deleted file mode 100644
index 6d9023f..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD5.java
+++ /dev/null
@@ -1,48 +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.mac;
-
-import org.apache.sshd.common.Mac;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * HMAC-MD5 <code>Mac</code>.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class HMACMD5 extends BaseMac {
-
- /**
- * Named factory for the HMACMD5 <code>Mac</code>
- */
- public static class Factory implements NamedFactory<Mac> {
-
- public String getName() {
- return "hmac-md5";
- }
-
- public Mac create() {
- return new HMACMD5();
- }
- }
-
- public HMACMD5() {
- super("HmacMD5", 16, 16);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD596.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD596.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD596.java
deleted file mode 100644
index 73b92cf..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACMD596.java
+++ /dev/null
@@ -1,49 +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.mac;
-
-import org.apache.sshd.common.Mac;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * HMAC-MD5-96 <code>Mac</code>
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class HMACMD596 extends BaseMac {
-
- /**
- * Named factory for the HMAC-MD5-96 <code>Mac</code>
- */
- public static class Factory implements NamedFactory<Mac> {
-
- public String getName() {
- return "hmac-md5-96";
- }
-
- public Mac create() {
- return new HMACMD596();
- }
- }
-
- public HMACMD596() {
- super("HmacMD5", 12, 16);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA1.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA1.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA1.java
deleted file mode 100644
index 454badf..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA1.java
+++ /dev/null
@@ -1,48 +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.mac;
-
-import org.apache.sshd.common.Mac;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * HMAC-SHA1 <code>Mac</code>
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class HMACSHA1 extends BaseMac {
-
- /**
- * Named factory for the HMAC-SHA1 <code>Mac</code>
- */
- public static class Factory implements NamedFactory<Mac> {
-
- public String getName() {
- return "hmac-sha1";
- }
-
- public Mac create() {
- return new HMACSHA1();
- }
- }
-
- public HMACSHA1() {
- super("HmacSHA1", 20, 20);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA196.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA196.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA196.java
deleted file mode 100644
index 23a2f95..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA196.java
+++ /dev/null
@@ -1,48 +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.mac;
-
-import org.apache.sshd.common.Mac;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * HMAC-SHA1-96 <code>Mac</code>
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class HMACSHA196 extends BaseMac {
-
- /**
- * Named factory for the HMAC-SHA1-96 <code>Mac</code>
- */
- public static class Factory implements NamedFactory<Mac> {
-
- public String getName() {
- return "hmac-sha1-96";
- }
-
- public Mac create() {
- return new HMACSHA196();
- }
- }
-
- public HMACSHA196() {
- super("HmacSHA1", 12, 20);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA256.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA256.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA256.java
deleted file mode 100644
index 5f70e0b..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA256.java
+++ /dev/null
@@ -1,48 +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.mac;
-
-import org.apache.sshd.common.Mac;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * HMAC-SHA256 <code>Mac</code>
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class HMACSHA256 extends BaseMac {
-
- /**
- * Named factory for the HMAC-SHA256 <code>Mac</code>
- */
- public static class Factory implements NamedFactory<Mac> {
-
- public String getName() {
- return "hmac-sha2-256";
- }
-
- public Mac create() {
- return new HMACSHA256();
- }
- }
-
- public HMACSHA256() {
- super("HmacSHA256", 32, 32);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA512.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA512.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA512.java
deleted file mode 100644
index e0ac66f..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/HMACSHA512.java
+++ /dev/null
@@ -1,48 +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.mac;
-
-import org.apache.sshd.common.Mac;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * HMAC-SHA512 <code>Mac</code>
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class HMACSHA512 extends BaseMac {
-
- /**
- * Named factory for the HMAC-SHA512 <code>Mac</code>
- */
- public static class Factory implements NamedFactory<Mac> {
-
- public String getName() {
- return "hmac-sha2-512";
- }
-
- public Mac create() {
- return new HMACSHA512();
- }
- }
-
- public HMACSHA512() {
- super("HmacSHA512", 64, 64);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignatureDSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignatureDSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignatureDSA.java
deleted file mode 100644
index bd2f466..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignatureDSA.java
+++ /dev/null
@@ -1,91 +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.signature;
-
-
-/**
- * DSA <code>Signature</code>
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public abstract class AbstractSignatureDSA extends AbstractSignature {
- protected AbstractSignatureDSA(String algorithm) {
- super(algorithm);
- }
-
- public byte[] sign() throws Exception {
- byte[] sig = signature.sign();
-
- // sig is in ASN.1
- // SEQUENCE::={ r INTEGER, s INTEGER }
- int len = 0;
- int index = 3;
- len = sig[index++] & 0xff;
- byte[] r = new byte[len];
- System.arraycopy(sig, index, r, 0, r.length);
- index = index + len + 1;
- len = sig[index++] & 0xff;
- byte[] s = new byte[len];
- System.arraycopy(sig, index, s, 0, s.length);
-
- byte[] result = new byte[40];
-
- // result must be 40 bytes, but length of r and s may not be 20 bytes
-
- System.arraycopy(r,
- (r.length > 20) ? 1 : 0,
- result,
- (r.length > 20) ? 0 : 20 - r.length,
- (r.length > 20) ? 20 : r.length);
- System.arraycopy(s,
- (s.length > 20) ? 1 : 0,
- result,
- (s.length > 20) ? 20 : 40 - s.length,
- (s.length > 20) ? 20 : s.length);
-
- return result;
- }
-
- public boolean verify(byte[] sig) throws Exception {
- sig = extractSig(sig);
-
- // ASN.1
- int frst = ((sig[0] & 0x80) != 0 ? 1 : 0);
- int scnd = ((sig[20] & 0x80) != 0 ? 1 : 0);
-
- int length = sig.length + 6 + frst + scnd;
- byte[] tmp = new byte[length];
- tmp[0] = (byte) 0x30;
- tmp[1] = (byte) 0x2c;
- tmp[1] += frst;
- tmp[1] += scnd;
- tmp[2] = (byte) 0x02;
- tmp[3] = (byte) 0x14;
- tmp[3] += frst;
- System.arraycopy(sig, 0, tmp, 4 + frst, 20);
- tmp[4 + tmp[3]] = (byte) 0x02;
- tmp[5 + tmp[3]] = (byte) 0x14;
- tmp[5 + tmp[3]] += scnd;
- System.arraycopy(sig, 20, tmp, 6 + tmp[3] + scnd, 20);
- sig = tmp;
-
- return signature.verify(sig);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java
new file mode 100644
index 0000000..425a47f
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java
@@ -0,0 +1,149 @@
+/*
+ * 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.signature;
+
+import java.security.spec.ECParameterSpec;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+
+import org.apache.sshd.common.Digest;
+import org.apache.sshd.common.KeyPairProvider;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.Signature;
+import org.apache.sshd.common.cipher.ECCurves;
+import org.apache.sshd.common.util.GenericUtils;
+
+/**
+ * Provides easy access to the currently implemented macs
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public enum BuiltinSignatures implements NamedFactory<Signature> {
+ dsa(KeyPairProvider.SSH_DSS) {
+ @Override
+ public Signature create() {
+ return new SignatureDSA("SHA1withDSA");
+ }
+ },
+ rsa(KeyPairProvider.SSH_RSA) {
+ @Override
+ public Signature create() {
+ return new SignatureRSA();
+ }
+ },
+ nistp256(KeyPairProvider.ECDSA_SHA2_NISTP256) {
+ @Override
+ public Signature create() {
+ return new SignatureECDSA("SHA256withECDSA");
+ }
+ },
+ nistp384(KeyPairProvider.ECDSA_SHA2_NISTP384) {
+ @Override
+ public Signature create() {
+ return new SignatureECDSA("SHA384withECDSA");
+ }
+ },
+ nistp521(KeyPairProvider.ECDSA_SHA2_NISTP521) {
+ @Override
+ public Signature create() {
+ return new SignatureECDSA("SHA512withECDSA");
+ }
+ };
+
+ private final String factoryName;
+
+ public static Signature getByCurveSize(ECParameterSpec params) {
+ int curveSize = ECCurves.getCurveSize(params);
+ if (curveSize <= 256) {
+ return nistp256.create();
+ } else if (curveSize <= 384) {
+ return nistp384.create();
+ } else {
+ return nistp521.create();
+ }
+ }
+
+ @Override
+ public final String getName() {
+ return factoryName;
+ }
+
+ BuiltinSignatures(String facName) {
+ factoryName = facName;
+ }
+
+
+ public static final Set<BuiltinSignatures> VALUES =
+ Collections.unmodifiableSet(EnumSet.allOf(BuiltinSignatures.class));
+
+ /**
+ * @param s The {@link Enum}'s name - ignored if {@code null}/empty
+ * @return The matching {@link org.apache.sshd.common.signature.BuiltinSignatures} whose {@link Enum#name()} matches
+ * (case <U>insensitive</U>) the provided argument - {@code null} if no match
+ */
+ public static BuiltinSignatures fromString(String s) {
+ if (GenericUtils.isEmpty(s)) {
+ return null;
+ }
+
+ for (BuiltinSignatures c : VALUES) {
+ if (s.equalsIgnoreCase(c.name())) {
+ return c;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param factory The {@link org.apache.sshd.common.NamedFactory} for the cipher - ignored if {@code null}
+ * @return The matching {@link org.apache.sshd.common.signature.BuiltinSignatures} whose factory name matches
+ * (case <U>insensitive</U>) the digest factory name
+ * @see #fromFactoryName(String)
+ */
+ public static BuiltinSignatures fromFactory(NamedFactory<Digest> factory) {
+ if (factory == null) {
+ return null;
+ } else {
+ return fromFactoryName(factory.getName());
+ }
+ }
+
+ /**
+ * @param n The factory name - ignored if {@code null}/empty
+ * @return The matching {@link org.apache.sshd.common.signature.BuiltinSignatures} whose factory name matches
+ * (case <U>insensitive</U>) the provided name - {@code null} if no match
+ */
+ public static BuiltinSignatures fromFactoryName(String n) {
+ if (GenericUtils.isEmpty(n)) {
+ return null;
+ }
+
+ for (BuiltinSignatures c : VALUES) {
+ if (n.equalsIgnoreCase(c.getName())) {
+ return c;
+ }
+ }
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
index 1109f54..d682b3a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
@@ -18,32 +18,75 @@
*/
package org.apache.sshd.common.signature;
-import org.apache.sshd.common.KeyPairProvider;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.Signature;
/**
- * TODO Add javadoc
+ * DSA <code>Signature</code>
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SignatureDSA extends AbstractSignatureDSA {
- /**
- * A named factory for DSA signature
- */
- public static class Factory implements NamedFactory<Signature> {
+public class SignatureDSA extends AbstractSignature {
- public String getName() {
- return KeyPairProvider.SSH_DSS;
- }
+ protected SignatureDSA(String algorithm) {
+ super(algorithm);
+ }
+
+ public byte[] sign() throws Exception {
+ byte[] sig = signature.sign();
+
+ // sig is in ASN.1
+ // SEQUENCE::={ r INTEGER, s INTEGER }
+ int len = 0;
+ int index = 3;
+ len = sig[index++] & 0xff;
+ byte[] r = new byte[len];
+ System.arraycopy(sig, index, r, 0, r.length);
+ index = index + len + 1;
+ len = sig[index++] & 0xff;
+ byte[] s = new byte[len];
+ System.arraycopy(sig, index, s, 0, s.length);
+
+ byte[] result = new byte[40];
+
+ // result must be 40 bytes, but length of r and s may not be 20 bytes
- public Signature create() {
- return new SignatureDSA();
- }
+ System.arraycopy(r,
+ (r.length > 20) ? 1 : 0,
+ result,
+ (r.length > 20) ? 0 : 20 - r.length,
+ (r.length > 20) ? 20 : r.length);
+ System.arraycopy(s,
+ (s.length > 20) ? 1 : 0,
+ result,
+ (s.length > 20) ? 20 : 40 - s.length,
+ (s.length > 20) ? 20 : s.length);
+ return result;
}
- public SignatureDSA() {
- super("SHA1withDSA");
+ public boolean verify(byte[] sig) throws Exception {
+ sig = extractSig(sig);
+
+ // ASN.1
+ int frst = ((sig[0] & 0x80) != 0 ? 1 : 0);
+ int scnd = ((sig[20] & 0x80) != 0 ? 1 : 0);
+
+ int length = sig.length + 6 + frst + scnd;
+ byte[] tmp = new byte[length];
+ tmp[0] = (byte) 0x30;
+ tmp[1] = (byte) 0x2c;
+ tmp[1] += frst;
+ tmp[1] += scnd;
+ tmp[2] = (byte) 0x02;
+ tmp[3] = (byte) 0x14;
+ tmp[3] += frst;
+ System.arraycopy(sig, 0, tmp, 4 + frst, 20);
+ tmp[4 + tmp[3]] = (byte) 0x02;
+ tmp[5 + tmp[3]] = (byte) 0x14;
+ tmp[5 + tmp[3]] += scnd;
+ System.arraycopy(sig, 20, tmp, 6 + tmp[3] + scnd, 20);
+ sig = tmp;
+
+ return signature.verify(sig);
}
+
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
index bbaa44c..b1e5a07 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
@@ -35,78 +35,10 @@ import org.apache.sshd.common.util.Buffer;
*/
public class SignatureECDSA extends AbstractSignature {
- /**
- * Signature algorithm for curves of above 384 bits.
- */
- private static final String SIGNATURE_ALGORITHM_512 = "SHA512withECDSA";
-
- /**
- * Signature algorithm for curves from 256 to 384 bits.
- */
- private static final String SIGNATURE_ALGORITHM_384 = "SHA384withECDSA";
-
- /**
- * Signature algorithm for curves of 256 bits and below.
- */
- private static final String SIGNATURE_ALGORITHM_256 = "SHA256withECDSA";
-
- /**
- * A named factory for ECDSA signatures of NIST P-256
- */
- public static class NISTP256Factory implements NamedFactory<Signature> {
-
- public String getName() {
- return KeyPairProvider.ECDSA_SHA2_NISTP256;
- }
-
- public Signature create() {
- return new SignatureECDSA(SIGNATURE_ALGORITHM_256);
- }
- }
-
- /**
- * A named factory for ECDSA signatures of NIST P-384
- */
- public static class NISTP384Factory implements NamedFactory<Signature> {
-
- public String getName() {
- return KeyPairProvider.ECDSA_SHA2_NISTP384;
- }
-
- public Signature create() {
- return new SignatureECDSA(SIGNATURE_ALGORITHM_384);
- }
- }
-
- /**
- * A named factory for ECDSA signatures of NIST P-521
- */
- public static class NISTP521Factory implements NamedFactory<Signature> {
-
- public String getName() {
- return KeyPairProvider.ECDSA_SHA2_NISTP521;
- }
-
- public Signature create() {
- return new SignatureECDSA(SIGNATURE_ALGORITHM_512);
- }
- }
-
protected SignatureECDSA(String algo) {
super(algo);
}
- public static Signature getByCurveSize(ECParameterSpec params) {
- int curveSize = ECCurves.getCurveSize(params);
- if (curveSize <= 256) {
- return new SignatureECDSA(SIGNATURE_ALGORITHM_256);
- } else if (curveSize <= 384) {
- return new SignatureECDSA(SIGNATURE_ALGORITHM_384);
- } else {
- return new SignatureECDSA(SIGNATURE_ALGORITHM_512);
- }
- }
-
public byte[] sign() throws Exception {
byte[] sig = signature.sign();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
index de5349f..5c3558a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
@@ -29,21 +29,6 @@ import org.apache.sshd.common.Signature;
*/
public class SignatureRSA extends AbstractSignature {
- /**
- * A named factory for RSA <code>Signature</code>
- */
- public static class Factory implements NamedFactory<Signature> {
-
- public String getName() {
- return KeyPairProvider.SSH_RSA;
- }
-
- public Signature create() {
- return new SignatureRSA();
- }
-
- }
-
public SignatureRSA() {
super("SHA1withRSA");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
index a47050d..6c7800a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
@@ -26,9 +26,10 @@ import java.security.interfaces.ECKey;
import java.security.interfaces.RSAKey;
import java.security.spec.ECParameterSpec;
+import org.apache.sshd.common.Digest;
import org.apache.sshd.common.KeyPairProvider;
import org.apache.sshd.common.cipher.ECCurves;
-import org.apache.sshd.common.digest.MD5;
+import org.apache.sshd.common.digest.BuiltinDigests;
/**
* Utility class for keys
@@ -47,7 +48,7 @@ public class KeyUtils {
try {
Buffer buffer = new Buffer();
buffer.putRawPublicKey(key);
- MD5 md5 = new MD5();
+ Digest md5 = BuiltinDigests.md5.create();
md5.init();
md5.update(buffer.array(), 0, buffer.wpos());
byte[] data = md5.digest();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
index baa0e83..8929896 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
@@ -187,7 +187,7 @@ public class ServerUserAuthService extends CloseableUtils.AbstractCloseable impl
Integer maxSessionCount = FactoryManagerUtils.getInteger(manager, ServerFactoryManager.MAX_CONCURRENT_SESSIONS);
if (maxSessionCount != null) {
int currentSessionCount = session.getActiveSessionCountForUser(username);
- if (currentSessionCount >= maxSessionCount.intValue()) {
+ if (currentSessionCount >= maxSessionCount) {
session.disconnect(SshConstants.SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE,
"Too many concurrent connections (" + currentSessionCount + ") - max. allowed: " + maxSessionCount);
return;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java b/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
index ae60071..98de765 100644
--- a/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
@@ -18,65 +18,29 @@
*/
package org.apache.sshd;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PublicKey;
import java.security.SecureRandom;
-import java.security.spec.ECFieldFp;
import java.security.spec.ECGenParameterSpec;
-import java.security.spec.ECParameterSpec;
-import java.security.spec.EllipticCurve;
import java.util.Arrays;
import java.util.Collections;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import org.apache.sshd.client.SessionFactory;
-import org.apache.sshd.client.channel.ChannelShell;
-import org.apache.sshd.client.future.AuthFuture;
-import org.apache.sshd.client.session.ClientSessionImpl;
-import org.apache.sshd.common.KeyPairProvider;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.RuntimeSshException;
-import org.apache.sshd.common.Session;
-import org.apache.sshd.common.SessionListener;
import org.apache.sshd.common.Signature;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.cipher.ECCurves;
-import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.keyprovider.AbstractKeyPairProvider;
-import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.signature.SignatureDSA;
-import org.apache.sshd.common.signature.SignatureECDSA;
-import org.apache.sshd.common.signature.SignatureRSA;
+import org.apache.sshd.common.signature.BuiltinSignatures;
import org.apache.sshd.common.util.SecurityUtils;
-import org.apache.sshd.server.Command;
import org.apache.sshd.server.PublickeyAuthenticator;
-import org.apache.sshd.server.command.ScpCommandFactory;
-import org.apache.sshd.server.keyprovider.AbstractGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
-import org.apache.sshd.server.sftp.SftpSubsystem;
import org.apache.sshd.util.BaseTest;
import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
-import org.bouncycastle.jce.ECPointUtil;
-import org.bouncycastle.util.encoders.Hex;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
/**
* TODO Add javadoc
*
@@ -128,9 +92,9 @@ public class EcdsaTest extends BaseTest {
client = SshClient.setUpDefaultClient();
client.setSignatureFactories(Arrays.<NamedFactory<Signature>>asList(
- new SignatureECDSA.NISTP256Factory(),
- new SignatureECDSA.NISTP384Factory(),
- new SignatureECDSA.NISTP521Factory()));
+ BuiltinSignatures.nistp256,
+ BuiltinSignatures.nistp384,
+ BuiltinSignatures.nistp521));
client.start();
ClientSession s = client.connect("smx", "localhost", port).await().getSession();
s.addPasswordIdentity("smx");
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
index 86ce8b4..ca07844 100644
--- a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
@@ -18,8 +18,6 @@
*/
package org.apache.sshd;
-import static org.junit.Assert.assertArrayEquals;
-
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -28,13 +26,11 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
-import org.apache.sshd.client.kex.DHGClient;
import org.apache.sshd.common.Cipher;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.cipher.BuiltinCiphers;
-import org.apache.sshd.common.kex.AbstractDH;
import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.util.BaseTest;
import org.apache.sshd.util.BogusPasswordAuthenticator;
@@ -44,6 +40,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertArrayEquals;
+
public class LoadTest extends BaseTest {
private SshServer sshd;
@@ -118,7 +116,7 @@ public class LoadTest extends BaseTest {
FactoryManagerUtils.updateProperty(props, FactoryManager.MAX_PACKET_SIZE, 1024 * 16);
FactoryManagerUtils.updateProperty(props, FactoryManager.WINDOW_SIZE, 1024 * 8);
client.setKeyExchangeFactories(Arrays.asList(
- DHGClient.newFactory(BuiltinDHFactories.dhg1)));
+ SshBuilder.ClientBuilder.getKeyExchangeFactory(BuiltinDHFactories.dhg1)));
client.setCipherFactories(Arrays.<NamedFactory<Cipher>>asList(BuiltinCiphers.blowfishcbc));
client.start();
try {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9e1401c/sshd-core/src/test/java/org/apache/sshd/MacTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/MacTest.java b/sshd-core/src/test/java/org/apache/sshd/MacTest.java
index b0d7092..c8d97d3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/MacTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/MacTest.java
@@ -28,12 +28,7 @@ import org.apache.sshd.common.Mac;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Random;
import org.apache.sshd.common.cipher.BuiltinCiphers;
-import org.apache.sshd.common.mac.HMACMD5;
-import org.apache.sshd.common.mac.HMACMD596;
-import org.apache.sshd.common.mac.HMACSHA1;
-import org.apache.sshd.common.mac.HMACSHA196;
-import org.apache.sshd.common.mac.HMACSHA256;
-import org.apache.sshd.common.mac.HMACSHA512;
+import org.apache.sshd.common.mac.BuiltinMacs;
import org.apache.sshd.common.random.BouncyCastleRandom;
import org.apache.sshd.util.BaseTest;
import org.apache.sshd.util.BogusPasswordAuthenticator;
@@ -59,38 +54,38 @@ public class MacTest extends BaseTest {
@Test
public void testHMACMD5() throws Exception {
- setUp(new HMACMD5.Factory());
+ setUp(BuiltinMacs.hmacmd5);
runTest();
}
@Test
public void testHMACMD596() throws Exception {
- setUp(new HMACMD596.Factory());
+ setUp(BuiltinMacs.hmacmd596);
runTest();
}
@Test
public void testHMACSHA1() throws Exception {
- setUp(new HMACSHA1.Factory());
+ setUp(BuiltinMacs.hmacsha1);
runTest();
}
@Test
public void testHMACSHA196() throws Exception {
- setUp(new HMACSHA196.Factory());
+ setUp(BuiltinMacs.hmacsha196);
runTest();
}
@Test
public void testHMACSHA256() throws Exception {
- setUp(new HMACSHA256.Factory());
+ setUp(BuiltinMacs.hmacsha256);
runTest();
}
@Test
@Ignore("Lead to ArrayIndexOutOfBoundsException in JSch")
public void testHMACSHA512() throws Exception {
- setUp(new HMACSHA512.Factory());
+ setUp(BuiltinMacs.hmacsha512);
runTest();
}