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 2016/03/01 13:30:31 UTC
mina-sshd git commit: Using literal constants for key algorithm names
Repository: mina-sshd
Updated Branches:
refs/heads/master 05f3c8f2d -> e81814dec
Using literal constants for key algorithm names
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/e81814de
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/e81814de
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/e81814de
Branch: refs/heads/master
Commit: e81814deca5b18930f4d89e0a10960d3000a2a8f
Parents: 05f3c8f
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Tue Mar 1 14:31:19 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Tue Mar 1 14:31:19 2016 +0200
----------------------------------------------------------------------
.../sshd/common/config/keys/BuiltinIdentities.java | 6 +++---
.../config/keys/DSSPublicKeyEntryDecoder.java | 4 ++--
.../config/keys/ECDSAPublicKeyEntryDecoder.java | 4 ++--
.../apache/sshd/common/config/keys/KeyUtils.java | 14 ++++++++++++++
.../common/config/keys/RSAPublicKeyDecoder.java | 4 ++--
.../main/java/org/apache/sshd/common/kex/ECDH.java | 6 ++++--
.../org/apache/sshd/common/util/SecurityUtils.java | 3 ++-
.../org/apache/sshd/common/util/buffer/Buffer.java | 7 ++++---
.../util/buffer/keys/DSSBufferPublicKeyParser.java | 3 ++-
.../util/buffer/keys/ECBufferPublicKeyParser.java | 3 ++-
.../util/buffer/keys/RSABufferPublicKeyParser.java | 3 ++-
.../AbstractGeneratorHostKeyProvider.java | 2 +-
.../java/org/apache/sshd/client/ClientTest.java | 3 ++-
.../KnownHostsServerKeyVerifierTest.java | 5 +++--
.../apache/sshd/common/auth/AuthenticationTest.java | 16 ++++++++--------
.../sshd/common/auth/SinglePublicKeyAuthTest.java | 2 +-
.../sshd/common/signature/SignatureRSATest.java | 3 ++-
.../apache/sshd/common/util/SecurityUtilsTest.java | 2 +-
.../PEMGeneratorHostKeyProviderTest.java | 11 ++++++-----
.../SimpleGeneratorHostKeyProviderTest.java | 11 ++++++-----
.../test/java/org/apache/sshd/util/test/Utils.java | 5 +++--
21 files changed, 72 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/config/keys/BuiltinIdentities.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/BuiltinIdentities.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/BuiltinIdentities.java
index cbba41c..f63ca5e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/BuiltinIdentities.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/BuiltinIdentities.java
@@ -45,7 +45,7 @@ import org.apache.sshd.common.util.SecurityUtils;
public enum BuiltinIdentities implements Identity {
RSA(Constants.RSA, RSAPublicKey.class, RSAPrivateKey.class),
DSA(Constants.DSA, DSAPublicKey.class, DSAPrivateKey.class),
- ECDSA(Constants.ECDSA, "EC", ECPublicKey.class, ECPrivateKey.class) {
+ ECDSA(Constants.ECDSA, KeyUtils.EC_ALGORITHM, ECPublicKey.class, ECPrivateKey.class) {
@Override
public boolean isSupported() {
return SecurityUtils.hasEcc();
@@ -192,8 +192,8 @@ public enum BuiltinIdentities implements Identity {
* Contains the names of the identities
*/
public static final class Constants {
- public static final String RSA = "RSA";
- public static final String DSA = "DSA";
+ public static final String RSA = KeyUtils.RSA_ALGORITHM;
+ public static final String DSA = KeyUtils.DSS_ALGORITHM;
public static final String ECDSA = "ECDSA";
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/config/keys/DSSPublicKeyEntryDecoder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/DSSPublicKeyEntryDecoder.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/DSSPublicKeyEntryDecoder.java
index ac4a418..424d0c6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/DSSPublicKeyEntryDecoder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/DSSPublicKeyEntryDecoder.java
@@ -107,11 +107,11 @@ public class DSSPublicKeyEntryDecoder extends AbstractPublicKeyEntryDecoder<DSAP
@Override
public KeyPairGenerator getKeyPairGenerator() throws GeneralSecurityException {
- return SecurityUtils.getKeyPairGenerator("DSA");
+ return SecurityUtils.getKeyPairGenerator(KeyUtils.DSS_ALGORITHM);
}
@Override
public KeyFactory getKeyFactoryInstance() throws GeneralSecurityException {
- return SecurityUtils.getKeyFactory("DSA");
+ return SecurityUtils.getKeyFactory(KeyUtils.DSS_ALGORITHM);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/config/keys/ECDSAPublicKeyEntryDecoder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/ECDSAPublicKeyEntryDecoder.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/ECDSAPublicKeyEntryDecoder.java
index d4b0608..4fd1de5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/ECDSAPublicKeyEntryDecoder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/ECDSAPublicKeyEntryDecoder.java
@@ -156,7 +156,7 @@ public class ECDSAPublicKeyEntryDecoder extends AbstractPublicKeyEntryDecoder<EC
@Override
public KeyFactory getKeyFactoryInstance() throws GeneralSecurityException {
if (SecurityUtils.hasEcc()) {
- return SecurityUtils.getKeyFactory("EC");
+ return SecurityUtils.getKeyFactory(KeyUtils.EC_ALGORITHM);
} else {
throw new NoSuchProviderException("ECC not supported");
}
@@ -177,7 +177,7 @@ public class ECDSAPublicKeyEntryDecoder extends AbstractPublicKeyEntryDecoder<EC
@Override
public KeyPairGenerator getKeyPairGenerator() throws GeneralSecurityException {
if (SecurityUtils.hasEcc()) {
- return SecurityUtils.getKeyPairGenerator("EC");
+ return SecurityUtils.getKeyPairGenerator(KeyUtils.EC_ALGORITHM);
} else {
throw new NoSuchProviderException("ECC not supported");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
index 9622a3a..0ee6ff8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
@@ -76,6 +76,20 @@ import org.apache.sshd.common.util.io.IoUtils;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public final class KeyUtils {
+ /**
+ * Name of algorithm for RSA keys to be used when calling security provider
+ */
+ public static final String RSA_ALGORITHM = "RSA";
+
+ /**
+ * Name of algorithm for DSS keys to be used when calling security provider
+ */
+ public static final String DSS_ALGORITHM = "DSA";
+
+ /**
+ * Name of algorithm for EC keys to be used when calling security provider
+ */
+ public static final String EC_ALGORITHM = "EC";
/**
* The {@link Set} of {@link PosixFilePermission} <U>not</U> allowed if strict
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/config/keys/RSAPublicKeyDecoder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/RSAPublicKeyDecoder.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/RSAPublicKeyDecoder.java
index 3b434b7..b9cabc9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/RSAPublicKeyDecoder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/RSAPublicKeyDecoder.java
@@ -105,11 +105,11 @@ public class RSAPublicKeyDecoder extends AbstractPublicKeyEntryDecoder<RSAPublic
@Override
public KeyPairGenerator getKeyPairGenerator() throws GeneralSecurityException {
- return SecurityUtils.getKeyPairGenerator("RSA");
+ return SecurityUtils.getKeyPairGenerator(KeyUtils.RSA_ALGORITHM);
}
@Override
public KeyFactory getKeyFactoryInstance() throws GeneralSecurityException {
- return SecurityUtils.getKeyFactory("RSA");
+ return SecurityUtils.getKeyFactory(KeyUtils.RSA_ALGORITHM);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/kex/ECDH.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/ECDH.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/ECDH.java
index 1dd298c..143e15c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/ECDH.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/ECDH.java
@@ -26,10 +26,12 @@ import java.security.interfaces.ECPublicKey;
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPoint;
import java.security.spec.ECPublicKeySpec;
+
import javax.crypto.KeyAgreement;
import org.apache.sshd.common.cipher.ECCurves;
import org.apache.sshd.common.config.keys.ECDSAPublicKeyEntryDecoder;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.digest.Digest;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.common.util.ValidateUtils;
@@ -61,7 +63,7 @@ public class ECDH extends AbstractDH {
}
public ECDH(ECParameterSpec paramSpec) throws Exception {
- myKpairGen = SecurityUtils.getKeyPairGenerator("EC");
+ myKpairGen = SecurityUtils.getKeyPairGenerator(KeyUtils.EC_ALGORITHM);
myKeyAgree = SecurityUtils.getKeyAgreement("ECDH");
params = paramSpec;
}
@@ -82,7 +84,7 @@ public class ECDH extends AbstractDH {
@Override
protected byte[] calculateK() throws Exception {
ValidateUtils.checkNotNull(params, "No ECParameterSpec(s)");
- KeyFactory myKeyFac = SecurityUtils.getKeyFactory("EC");
+ KeyFactory myKeyFac = SecurityUtils.getKeyFactory(KeyUtils.EC_ALGORITHM);
ECPublicKeySpec keySpec = new ECPublicKeySpec(f, params);
PublicKey yourPubKey = myKeyFac.generatePublic(keySpec);
myKeyAgree.doPhase(yourPubKey, true);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
index 03efdfb..462e8fa 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
@@ -44,6 +44,7 @@ import javax.crypto.Mac;
import javax.crypto.spec.DHParameterSpec;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.AbstractClassLoadableResourceKeyPairProvider;
import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
import org.apache.sshd.common.random.AbstractRandom;
@@ -129,7 +130,7 @@ public final class SecurityUtils {
String propValue = System.getProperty(ECC_SUPPORTED_PROP);
if (GenericUtils.isEmpty(propValue)) {
try {
- getKeyPairGenerator("EC");
+ getKeyPairGenerator(KeyUtils.EC_ALGORITHM);
hasEcc = Boolean.TRUE;
} catch (Throwable t) {
hasEcc = Boolean.FALSE;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
index 99e2b2a..c708a3e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
@@ -54,6 +54,7 @@ import org.apache.sshd.common.PropertyResolver;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.cipher.ECCurves;
import org.apache.sshd.common.config.keys.ECDSAPublicKeyEntryDecoder;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.Int2IntFunction;
@@ -348,7 +349,7 @@ public abstract class Buffer implements Readable {
BigInteger p = getMPInt();
BigInteger dP = d.remainder(p.subtract(BigInteger.valueOf(1)));
BigInteger dQ = d.remainder(q.subtract(BigInteger.valueOf(1)));
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("RSA");
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.RSA_ALGORITHM);
pub = keyFactory.generatePublic(new RSAPublicKeySpec(n, e));
prv = keyFactory.generatePrivate(new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv));
} else if (KeyPairProvider.SSH_DSS.equals(keyAlg)) {
@@ -357,7 +358,7 @@ public abstract class Buffer implements Readable {
BigInteger g = getMPInt();
BigInteger y = getMPInt();
BigInteger x = getMPInt();
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("DSA");
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.DSS_ALGORITHM);
pub = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g));
prv = keyFactory.generatePrivate(new DSAPrivateKeySpec(x, p, q, g));
} else {
@@ -399,7 +400,7 @@ public abstract class Buffer implements Readable {
e);
}
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("EC");
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.EC_ALGORITHM);
PublicKey pubKey = keyFactory.generatePublic(new ECPublicKeySpec(group, spec));
PrivateKey privKey = keyFactory.generatePrivate(new ECPrivateKeySpec(exponent, spec));
return new KeyPair(pubKey, privKey);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/DSSBufferPublicKeyParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/DSSBufferPublicKeyParser.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/DSSBufferPublicKeyParser.java
index af1b383..4eec49a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/DSSBufferPublicKeyParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/DSSBufferPublicKeyParser.java
@@ -24,6 +24,7 @@ import java.security.GeneralSecurityException;
import java.security.interfaces.DSAPublicKey;
import java.security.spec.DSAPublicKeySpec;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -45,7 +46,7 @@ public class DSSBufferPublicKeyParser extends AbstractBufferPublicKeyParser<DSAP
BigInteger q = buffer.getMPInt();
BigInteger g = buffer.getMPInt();
BigInteger y = buffer.getMPInt();
- return generatePublicKey("DSA", new DSAPublicKeySpec(y, p, q, g));
+ return generatePublicKey(KeyUtils.DSS_ALGORITHM, new DSAPublicKeySpec(y, p, q, g));
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/ECBufferPublicKeyParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/ECBufferPublicKeyParser.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/ECBufferPublicKeyParser.java
index 71b80ff..84cf4a4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/ECBufferPublicKeyParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/ECBufferPublicKeyParser.java
@@ -29,6 +29,7 @@ import java.security.spec.InvalidKeySpecException;
import org.apache.sshd.common.cipher.ECCurves;
import org.apache.sshd.common.config.keys.ECDSAPublicKeyEntryDecoder;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -76,6 +77,6 @@ public class ECBufferPublicKeyParser extends AbstractBufferPublicKeyParser<ECPub
e);
}
- return generatePublicKey("EC", new ECPublicKeySpec(w, spec));
+ return generatePublicKey(KeyUtils.EC_ALGORITHM, new ECPublicKeySpec(w, spec));
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/RSABufferPublicKeyParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/RSABufferPublicKeyParser.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/RSABufferPublicKeyParser.java
index 1c8119f..363b07e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/RSABufferPublicKeyParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/RSABufferPublicKeyParser.java
@@ -24,6 +24,7 @@ import java.security.GeneralSecurityException;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAPublicKeySpec;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -43,6 +44,6 @@ public class RSABufferPublicKeyParser extends AbstractBufferPublicKeyParser<RSAP
ValidateUtils.checkTrue(isKeyTypeSupported(keyType), "Unsupported key type: %s", keyType);
BigInteger e = buffer.getMPInt();
BigInteger n = buffer.getMPInt();
- return generatePublicKey("RSA", new RSAPublicKeySpec(n, e));
+ return generatePublicKey(KeyUtils.RSA_ALGORITHM, new RSAPublicKeySpec(n, e));
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java b/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
index 52b1b21..6a57763 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
@@ -49,7 +49,7 @@ import org.apache.sshd.common.util.io.IoUtils;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public abstract class AbstractGeneratorHostKeyProvider extends AbstractKeyPairProvider {
- public static final String DEFAULT_ALGORITHM = "DSA";
+ public static final String DEFAULT_ALGORITHM = KeyUtils.DSS_ALGORITHM;
public static final boolean DEFAULT_ALLOWED_TO_OVERWRITE = true;
private final AtomicReference<KeyPair> keyPairHolder = new AtomicReference<>();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index 7182dfe..7ca04aa 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -79,6 +79,7 @@ import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelListener;
import org.apache.sshd.common.channel.ChannelListenerManager;
import org.apache.sshd.common.channel.TestChannelListener;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoReadFuture;
@@ -984,7 +985,7 @@ public class ClientTest extends BaseTestSupport {
@Test
public void testPublicKeyAuthNewWithFailureOnFirstIdentity() throws Exception {
SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
- provider.setAlgorithm("RSA");
+ provider.setAlgorithm(KeyUtils.RSA_ALGORITHM);
final KeyPair pair = createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA);
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java b/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
index 28abac5..e7f028e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
@@ -41,6 +41,7 @@ import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier.HostEntryP
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.config.keys.AuthorizedKeyEntry;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.config.keys.PublicKeyEntry;
import org.apache.sshd.common.config.keys.PublicKeyEntryResolver;
import org.apache.sshd.common.mac.Mac;
@@ -239,7 +240,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
@Test
public void testRejectModifiedServerKey() throws Exception {
- KeyPair kp = Utils.generateKeyPair("RSA", 1024);
+ KeyPair kp = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
final PublicKey modifiedKey = kp.getPublic();
final AtomicInteger acceptCount = new AtomicInteger(0);
ServerKeyVerifier verifier = new KnownHostsServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE, createKnownHostsCopy()) {
@@ -266,7 +267,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
@Test
public void testAcceptModifiedServerKeyUpdatesFile() throws Exception {
- KeyPair kp = Utils.generateKeyPair("RSA", 1024);
+ KeyPair kp = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
final PublicKey modifiedKey = kp.getPublic();
Path path = createKnownHostsCopy();
ServerKeyVerifier verifier = new KnownHostsServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE, path) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
index 0e78344..3fea9c2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
@@ -633,14 +633,14 @@ public class AuthenticationTest extends BaseTestSupport {
@Test // see SSHD-618
public void testPublicKeyAuthDifferentThanKex() throws Exception {
final KeyPairProvider serverKeys = KeyPairProvider.Utils.wrap(
- Utils.generateKeyPair("RSA", 1024),
- Utils.generateKeyPair("DSA", 512),
- Utils.generateKeyPair("EC", 256));
+ Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024),
+ Utils.generateKeyPair(KeyUtils.DSS_ALGORITHM, 512),
+ Utils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256));
sshd.setKeyPairProvider(serverKeys);
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE);
sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
- final KeyPair clientIdentity = Utils.generateKeyPair("EC", 256);
+ final KeyPair clientIdentity = Utils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256);
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
@@ -702,7 +702,7 @@ public class AuthenticationTest extends BaseTestSupport {
super.sendPublicKeyResponse(session, username, KeyPairProvider.SSH_DSS, key, keyBlob, offset, blobLen, buffer);
} else if (count == 2) {
// send another key
- KeyPair otherPair = org.apache.sshd.util.test.Utils.generateKeyPair("RSA", 1024);
+ KeyPair otherPair = org.apache.sshd.util.test.Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
PublicKey otherKey = otherPair.getPublic();
Buffer buf = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_PK_OK, blobLen + alg.length() + Long.SIZE);
buf.putString(alg);
@@ -718,7 +718,7 @@ public class AuthenticationTest extends BaseTestSupport {
}));
try (SshClient client = setupTestClient()) {
- KeyPair clientIdentity = Utils.generateKeyPair("RSA", 1024);
+ KeyPair clientIdentity = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
client.start();
try {
@@ -745,7 +745,7 @@ public class AuthenticationTest extends BaseTestSupport {
public void testHostBasedAuthentication() throws Exception {
final String hostClienUser = getClass().getSimpleName();
final String hostClientName = SshdSocketAddress.toAddressString(SshdSocketAddress.getFirstExternalNetwork4Address());
- final KeyPair hostClientKey = Utils.generateKeyPair("RSA", 1024);
+ final KeyPair hostClientKey = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
final AtomicInteger invocationCount = new AtomicInteger(0);
sshd.setHostBasedAuthenticator(new HostBasedAuthenticator() {
@Override
@@ -814,7 +814,7 @@ public class AuthenticationTest extends BaseTestSupport {
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE);
try (SshClient client = setupTestClient()) {
- KeyPair kp = Utils.generateKeyPair("RSA", 1024);
+ KeyPair kp = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
client.start();
try {
for (int index = 1; index < 3; index++) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java
index f1ca19c..d35a5c8 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java
@@ -61,7 +61,7 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport {
public SinglePublicKeyAuthTest() {
SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
- provider.setAlgorithm("RSA");
+ provider.setAlgorithm(KeyUtils.RSA_ALGORITHM);
pairRsaBad = provider.loadKey(KeyPairProvider.SSH_RSA);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
index 6496801..d12e7e3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
@@ -26,6 +26,7 @@ import java.security.PublicKey;
import java.security.spec.RSAPublicKeySpec;
import org.apache.sshd.common.Factory;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.util.Base64;
import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.SecurityUtils;
@@ -57,7 +58,7 @@ public class SignatureRSATest extends BaseTestSupport {
byte[] exp = Base64.decodeString("Iw==");
@SuppressWarnings("checkstyle:linelength")
byte[] mod = Base64.decodeString("AMs9HO/NH/Now+6fSnESebaG4wzaYQWA1b/q1TGV1wHNtCg9fGFGVSKs0VxKF4cfVyrSLtgLjnlXQTn+Lm7xiYKGbBbsTQWOqEDaBVBsRbAkxIkpuvr6/EBxwrtDbKmSQYTJZVJSD2bZRYjGsR9gpZXPorOOKFd5EPCMHXsqnhp2hidTGH7cK6RuLk7MNnPISsY0Nbx8/ZvikiPROGcoTZ8bzUv4IaLr3veW6epSeQem8tJqhnrpTHhbLU99zf045M0Gsnk/azjjlBM+qrHZ5FNdC1kowJnLtf2Oy/rUQNpkGJtcBPT8xvreV0wLsn9t3hSxzsc0+VkDNTQRlfU+o3M=");
- KeyFactory kf = SecurityUtils.getKeyFactory("RSA");
+ KeyFactory kf = SecurityUtils.getKeyFactory(KeyUtils.RSA_ALGORITHM);
testKey = kf.generatePublic(new RSAPublicKeySpec(new BigInteger(mod), new BigInteger(exp)));
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java
index 41e4531..f2f57d2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java
@@ -191,7 +191,7 @@ public class SecurityUtilsTest extends BaseTestSupport {
Assume.assumeFalse(SecurityUtils.REGISTER_BOUNCY_CASTLE_PROP + " property is " + propValue, Boolean.parseBoolean(propValue));
assertFalse("Unexpected registration of provider", SecurityUtils.isBouncyCastleRegistered());
- KeyPairGenerator kpg = SecurityUtils.getKeyPairGenerator("RSA");
+ KeyPairGenerator kpg = SecurityUtils.getKeyPairGenerator(KeyUtils.RSA_ALGORITHM);
Provider provider = kpg.getProvider();
assertNotEquals("Unexpected used provider", SecurityUtils.BOUNCY_CASTLE, provider.getName());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
index 815b545..5a42ec2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
@@ -27,6 +27,7 @@ import java.security.interfaces.ECPublicKey;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.ECGenParameterSpec;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.common.util.io.IoUtils;
@@ -50,34 +51,34 @@ public class PEMGeneratorHostKeyProviderTest extends BaseTestSupport {
@Test
public void testDSA() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- testPEMGeneratorHostKeyProvider("DSA", KeyPairProvider.SSH_DSS, 512, null);
+ testPEMGeneratorHostKeyProvider(KeyUtils.DSS_ALGORITHM, KeyPairProvider.SSH_DSS, 512, null);
}
@Test
public void testRSA() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- testPEMGeneratorHostKeyProvider("RSA", KeyPairProvider.SSH_RSA, 512, null);
+ testPEMGeneratorHostKeyProvider(KeyUtils.RSA_ALGORITHM, KeyPairProvider.SSH_RSA, 512, null);
}
@Test
public void testECnistp256() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc());
- testPEMGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
+ testPEMGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
}
@Test
public void testECnistp384() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc());
- testPEMGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
+ testPEMGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
}
@Test
public void testECnistp521() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc());
- testPEMGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
+ testPEMGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
}
private Path testPEMGeneratorHostKeyProvider(String algorithm, String keyType, int keySize, AlgorithmParameterSpec keySpec) throws IOException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
index 8897c97..b05cd76 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
@@ -25,6 +25,7 @@ import java.security.KeyPair;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.ECGenParameterSpec;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.common.util.io.IoUtils;
@@ -47,30 +48,30 @@ public class SimpleGeneratorHostKeyProviderTest extends BaseTestSupport {
@Test
public void testDSA() throws IOException {
- testSimpleGeneratorHostKeyProvider("DSA", KeyPairProvider.SSH_DSS, 512, null);
+ testSimpleGeneratorHostKeyProvider(KeyUtils.DSS_ALGORITHM, KeyPairProvider.SSH_DSS, 512, null);
}
@Test
public void testRSA() throws IOException {
- testSimpleGeneratorHostKeyProvider("RSA", KeyPairProvider.SSH_RSA, 512, null);
+ testSimpleGeneratorHostKeyProvider(KeyUtils.RSA_ALGORITHM, KeyPairProvider.SSH_RSA, 512, null);
}
@Test
public void testECnistp256() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- testSimpleGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
+ testSimpleGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
}
@Test
public void testECnistp384() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- testSimpleGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
+ testSimpleGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
}
@Test
public void testECnistp521() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- testSimpleGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
+ testSimpleGeneratorHostKeyProvider(KeyUtils.EC_ALGORITHM, KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
}
private Path testSimpleGeneratorHostKeyProvider(String algorithm, String keyType, int keySize, AlgorithmParameterSpec keySpec) throws IOException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e81814de/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java b/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
index be121dd..d349ed1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
@@ -53,6 +53,7 @@ import org.apache.sshd.client.config.hosts.HostConfigEntryResolver;
import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.cipher.ECCurves;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
import org.apache.sshd.common.keyprovider.KeyIdentityProvider;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
@@ -106,7 +107,7 @@ public final class Utils {
Collections.unmodifiableList(
Arrays.asList("target" /* Maven */, "build" /* Gradle */));
- public static final String DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM = "RSA";
+ public static final String DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM = KeyUtils.RSA_ALGORITHM;
// uses a cached instance to avoid re-creating the keys as it is a time-consuming effort
private static final AtomicReference<KeyPairProvider> KEYPAIR_PROVIDER_HOLDER = new AtomicReference<KeyPairProvider>();
// uses a cached instance to avoid re-creating the keys as it is a time-consuming effort
@@ -159,7 +160,7 @@ public final class Utils {
public static KeyPair generateKeyPair(String algorithm, int keySize) throws GeneralSecurityException {
KeyPairGenerator gen = SecurityUtils.getKeyPairGenerator(algorithm);
- if ("EC".equalsIgnoreCase(algorithm)) {
+ if (KeyUtils.EC_ALGORITHM.equalsIgnoreCase(algorithm)) {
ECCurves curve = ECCurves.fromCurveSize(keySize);
if (curve == null) {
throw new InvalidKeySpecException("Unknown curve for key size=" + keySize);