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/07/17 18:18:39 UTC
[19/25] mina-sshd git commit: [SSHD-542] Checkstyle validation
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
index 5a7f3ee..4ab4974 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
@@ -71,6 +71,12 @@ public enum BuiltinCiphers implements CipherFactory {
blowfishcbc(Constants.BLOWFISH_CBC, 8, 16, "Blowfish", "Blowfish/CBC/NoPadding"),
tripledescbc(Constants.TRIPLE_DES_CBC, 8, 24, "DESede", "DESede/CBC/NoPadding");
+ public static final Set<BuiltinCiphers> VALUES =
+ Collections.unmodifiableSet(EnumSet.allOf(BuiltinCiphers.class));
+
+ private static final Map<String, CipherFactory> EXTENSIONS =
+ new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+
private final String factoryName;
private final int ivsize;
private final int blocksize;
@@ -79,16 +85,6 @@ public enum BuiltinCiphers implements CipherFactory {
private final String transformation;
private final boolean supported;
- @Override
- public final String getName() {
- return factoryName;
- }
-
- @Override
- public final String toString() {
- return getName();
- }
-
BuiltinCiphers(String factoryName, int ivsize, int blocksize, String algorithm, String transformation) {
this.factoryName = factoryName;
this.ivsize = ivsize;
@@ -105,6 +101,16 @@ public enum BuiltinCiphers implements CipherFactory {
this.supported = checkSupported(this.transformation, this.keysize);
}
+ @Override
+ public final String getName() {
+ return factoryName;
+ }
+
+ @Override
+ public final String toString() {
+ return getName();
+ }
+
/**
* @return {@code true} if the current JVM configuration supports this
* cipher - e.g., AES-256 requires the <A HREF="http://www.oracle.com/technetwork/java/javase/downloads/">
@@ -118,15 +124,12 @@ public enum BuiltinCiphers implements CipherFactory {
private static boolean checkSupported(String xform, int keyLength) {
try {
int maxKeyLength = javax.crypto.Cipher.getMaxAllowedKeyLength(xform);
- if (maxKeyLength >= keyLength) {
- return true;
- } else {
- return false; // debug breakpoint
- }
+ return maxKeyLength >= keyLength;
} catch (Exception e) {
return false;
}
}
+
/**
* @return The key size (in bits) for the cipher
*/
@@ -167,26 +170,22 @@ public enum BuiltinCiphers implements CipherFactory {
return new BaseCipher(getIVSize(), getBlockSize(), getAlgorithm(), getTransformation());
}
- public static Set<BuiltinCiphers> VALUES =
- Collections.unmodifiableSet(EnumSet.allOf(BuiltinCiphers.class));
- private static final Map<String,CipherFactory> extensions =
- new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
-
/**
* Registered a {@link NamedFactory} to be available besides the built-in
* ones when parsing configuration
+ *
* @param extension The factory to register
* @throws IllegalArgumentException if factory instance is {@code null},
- * or overrides a built-in one or overrides another registered factory
- * with the same name (case <U>insensitive</U>).
+ * or overrides a built-in one or overrides another registered factory
+ * with the same name (case <U>insensitive</U>).
*/
public static void registerExtension(CipherFactory extension) {
- String name=ValidateUtils.checkNotNull(extension, "No extension provided").getName();
+ String name = ValidateUtils.checkNotNull(extension, "No extension provided").getName();
ValidateUtils.checkTrue(fromFactoryName(name) == null, "Extension overrides built-in: %s", name);
- synchronized(extensions) {
- ValidateUtils.checkTrue(!extensions.containsKey(name), "Extension overrides existinh: %s", name);
- extensions.put(name, extension);
+ synchronized (EXTENSIONS) {
+ ValidateUtils.checkTrue(!EXTENSIONS.containsKey(name), "Extension overrides existing: %s", name);
+ EXTENSIONS.put(name, extension);
}
}
@@ -196,13 +195,14 @@ public enum BuiltinCiphers implements CipherFactory {
*/
public static SortedSet<CipherFactory> getRegisteredExtensions() {
// TODO for JDK-8 return Collections.emptySortedSet()
- synchronized(extensions) {
- return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, extensions.values());
+ synchronized (EXTENSIONS) {
+ return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, EXTENSIONS.values());
}
}
/**
* Unregisters specified extension
+ *
* @param name The factory name - ignored if {@code null}/empty
* @return The registered extension - {@code null} if not found
*/
@@ -210,9 +210,9 @@ public enum BuiltinCiphers implements CipherFactory {
if (GenericUtils.isEmpty(name)) {
return null;
}
-
- synchronized(extensions) {
- return extensions.remove(name);
+
+ synchronized (EXTENSIONS) {
+ return EXTENSIONS.remove(name);
}
}
@@ -260,7 +260,7 @@ public enum BuiltinCiphers implements CipherFactory {
/**
* @param ciphers A comma-separated list of ciphers' names - ignored
- * if {@code null}/empty
+ * if {@code null}/empty
* @return A {@link ParseResult} containing the successfully parsed
* factories and the unknown ones. <B>Note:</B> it is up to caller to
* ensure that the lists do not contain duplicates
@@ -269,7 +269,7 @@ public enum BuiltinCiphers implements CipherFactory {
return parseCiphersList(GenericUtils.split(ciphers, ','));
}
- public static ParseResult parseCiphersList(String ... ciphers) {
+ public static ParseResult parseCiphersList(String... ciphers) {
return parseCiphersList(GenericUtils.isEmpty((Object[]) ciphers) ? Collections.<String>emptyList() : Arrays.asList(ciphers));
}
@@ -277,11 +277,11 @@ public enum BuiltinCiphers implements CipherFactory {
if (GenericUtils.isEmpty(ciphers)) {
return ParseResult.EMPTY;
}
-
- List<CipherFactory> factories=new ArrayList<>(ciphers.size());
- List<String> unknown=Collections.emptyList();
+
+ List<CipherFactory> factories = new ArrayList<>(ciphers.size());
+ List<String> unknown = Collections.emptyList();
for (String name : ciphers) {
- CipherFactory c=resolveFactory(name);
+ CipherFactory c = resolveFactory(name);
if (c != null) {
factories.add(c);
} else {
@@ -292,47 +292,59 @@ public enum BuiltinCiphers implements CipherFactory {
unknown.add(name);
}
}
-
+
return new ParseResult(factories, unknown);
}
/**
* @param name The factory name
* @return The factory or {@code null} if it is neither a built-in one
- * or a registered extension
+ * or a registered extension
*/
public static CipherFactory resolveFactory(String name) {
if (GenericUtils.isEmpty(name)) {
return null;
}
- CipherFactory c=fromFactoryName(name);
+ CipherFactory c = fromFactoryName(name);
if (c != null) {
return c;
}
-
- synchronized(extensions) {
- return extensions.get(name);
+
+ synchronized (EXTENSIONS) {
+ return EXTENSIONS.get(name);
}
}
/**
* Holds the result of {@link BuiltinCiphers#parseCiphersList(String)}
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
- public static class ParseResult extends NamedFactoriesListParseResult<Cipher,CipherFactory> {
- public static ParseResult EMPTY=new ParseResult(Collections.<CipherFactory>emptyList(), Collections.<String>emptyList());
-
+ public static class ParseResult extends NamedFactoriesListParseResult<Cipher, CipherFactory> {
+ public static final ParseResult EMPTY = new ParseResult(Collections.<CipherFactory>emptyList(), Collections.<String>emptyList());
+
public ParseResult(List<CipherFactory> parsed, List<String> unsupported) {
super(parsed, unsupported);
}
}
public static class Constants {
- public static String NONE = "none";
- public static Pattern NONE_CIPHER_PATTERN =
+ public static final String NONE = "none";
+ public static final Pattern NONE_CIPHER_PATTERN =
Pattern.compile("(^|.*,)" + NONE + "($|,.*)");
+ public static final String AES128_CBC = "aes128-cbc";
+ public static final String AES128_CTR = "aes128-ctr";
+ public static final String AES192_CBC = "aes192-cbc";
+ public static final String AES192_CTR = "aes192-ctr";
+ public static final String AES256_CBC = "aes256-cbc";
+ public static final String AES256_CTR = "aes256-ctr";
+ public static final String ARCFOUR128 = "arcfour128";
+ public static final String ARCFOUR256 = "arcfour256";
+ public static final String BLOWFISH_CBC = "blowfish-cbc";
+ public static final String TRIPLE_DES_CBC = "3des-cbc";
+
/**
* @param s A comma-separated list of ciphers - ignored if {@code null}/empty
* @return {@code true} if the {@link #NONE} cipher name appears in it
@@ -341,24 +353,9 @@ public enum BuiltinCiphers implements CipherFactory {
if (GenericUtils.isEmpty(s)) {
return false;
}
-
Matcher m = NONE_CIPHER_PATTERN.matcher(s);
- if (m.matches()) {
- return true;
- } else {
- return false; // debug breakpoint
- }
+ return m.matches();
}
- public static String AES128_CBC = "aes128-cbc";
- public static String AES128_CTR = "aes128-ctr";
- public static String AES192_CBC = "aes192-cbc";
- public static String AES192_CTR = "aes192-ctr";
- public static String AES256_CBC = "aes256-cbc";
- public static String AES256_CTR = "aes256-ctr";
- public static String ARCFOUR128 = "arcfour128";
- public static String ARCFOUR256 = "arcfour256";
- public static String BLOWFISH_CBC = "blowfish-cbc";
- public static String TRIPLE_DES_CBC = "3des-cbc";
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
index b614fa3..ad2a94d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
@@ -24,7 +24,7 @@ package org.apache.sshd.common.cipher;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface Cipher {
+public interface Cipher {
enum Mode {
Encrypt, Decrypt
@@ -43,15 +43,17 @@ public interface Cipher {
/**
* Initialize the cipher for encryption or decryption with
* the given key and initialization vector
+ *
* @param mode Encrypt/Decrypt initialization
- * @param key Key bytes
- * @param iv Initialization vector bytes
+ * @param key Key bytes
+ * @param iv Initialization vector bytes
* @throws Exception If failed to initialize
*/
void init(Mode mode, byte[] key, byte[] iv) throws Exception;
/**
* Performs in-place encryption or decryption on the given data.
+ *
* @param input The input/output bytes
* @throws Exception If failed to execute
* @see #update(byte[], int, int)
@@ -60,9 +62,10 @@ public interface Cipher {
/**
* Performs in-place encryption or decryption on the given data.
- * @param input The input/output bytes
+ *
+ * @param input The input/output bytes
* @param inputOffset The offset of the data in the data buffer
- * @param inputLen The number of bytes to update - starting at the given offset
+ * @param inputLen The number of bytes to update - starting at the given offset
* @throws Exception If failed to execute
*/
void update(byte[] input, int inputOffset, int inputLen) throws Exception;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherFactory.java
index 94834b4..f744bb9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherFactory.java
@@ -19,19 +19,12 @@
package org.apache.sshd.common.cipher;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.OptionalFeature;
-import org.apache.sshd.common.util.Transformer;
+import org.apache.sshd.common.BuiltinFactory;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface CipherFactory extends NamedFactory<Cipher>, OptionalFeature {
- // required because of generics issues
- Transformer<CipherFactory,NamedFactory<Cipher>> FAC2NAMED=new Transformer<CipherFactory,NamedFactory<Cipher>>() {
- @Override
- public NamedFactory<Cipher> transform(CipherFactory input) {
- return input;
- }
- };
+// CHECKSTYLE:OFF
+public interface CipherFactory extends BuiltinFactory<Cipher> {
+
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 598bfd7..e0eefec 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
@@ -44,58 +44,110 @@ import org.apache.sshd.common.util.ValidateUtils;
*/
public enum ECCurves implements NamedResource, OptionalFeature {
nistp256(Constants.NISTP256,
- new ECParameterSpec(
- new EllipticCurve(
- new ECFieldFp(new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16)),
- new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", 16),
- new BigInteger("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", 16)),
- new ECPoint(
- new BigInteger("6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", 16),
- new BigInteger("4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", 16)),
- new BigInteger("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 16),
- 1),
- 32) {
- @Override
- public Digest getDigestForParams() {
- return BuiltinDigests.sha256.create();
- }
- },
+ new ECParameterSpec(
+ new EllipticCurve(
+ new ECFieldFp(new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16)),
+ new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", 16),
+ new BigInteger("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", 16)),
+ new ECPoint(
+ new BigInteger("6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", 16),
+ new BigInteger("4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", 16)),
+ new BigInteger("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 16),
+ 1),
+ 32) {
+ @Override
+ public Digest getDigestForParams() {
+ return BuiltinDigests.sha256.create();
+ }
+ },
nistp384(Constants.NISTP384,
- new ECParameterSpec(
- new EllipticCurve(
- new ECFieldFp(new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", 16)),
- new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", 16),
- new BigInteger("B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", 16)),
- new ECPoint(
- new BigInteger("AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7", 16),
- new BigInteger("3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F", 16)),
- new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", 16),
+ new ECParameterSpec(
+ new EllipticCurve(
+ new ECFieldFp(new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", 16)),
+ new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", 16),
+ new BigInteger("B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", 16)),
+ new ECPoint(
+ new BigInteger("AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7", 16),
+ new BigInteger("3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F", 16)),
+ new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", 16),
1),
- 48) {
- @Override
- public Digest getDigestForParams() {
- return BuiltinDigests.sha384.create();
- }
- },
+ 48) {
+ @Override
+ public Digest getDigestForParams() {
+ return BuiltinDigests.sha384.create();
+ }
+ },
nistp521(Constants.NISTP521,
- new ECParameterSpec(
- new EllipticCurve(
- new ECFieldFp(new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16)),
- new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16),
- new BigInteger("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", 16)),
- new ECPoint(
- new BigInteger("00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66", 16),
- new BigInteger("011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650", 16)),
- new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", 16),
+ new ECParameterSpec(
+ new EllipticCurve(
+ new ECFieldFp(new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+ + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16)),
+ new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+ + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16),
+ new BigInteger("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951"
+ + "EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", 16)),
+ new ECPoint(
+ new BigInteger("00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77"
+ + "EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66", 16),
+ new BigInteger("011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE7299"
+ + "5EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650", 16)),
+ new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B"
+ + "7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", 16),
1),
- 66) {
- @Override
- public Digest getDigestForParams() {
- return BuiltinDigests.sha512.create();
- }
- };
+ 66) {
+ @Override
+ public Digest getDigestForParams() {
+ return BuiltinDigests.sha512.create();
+ }
+ };
+
+ /**
+ * A {@link Set} of all the known curves
+ */
+ public static final Set<ECCurves> VALUES =
+ Collections.unmodifiableSet(EnumSet.allOf(ECCurves.class));
+
+ /**
+ * A {@link Set} of all the known curves names
+ */
+ public static final Set<String> NAMES =
+ Collections.unmodifiableSet(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) {
+ private static final long serialVersionUID = 1L; // we're not serializing it
+
+ {
+ for (ECCurves c : VALUES) {
+ add(c.getName());
+ }
+ }
+ });
+
+ /**
+ * A {@link Set} of all the known curves key types
+ */
+ public static final Set<String> KEY_TYPES =
+ Collections.unmodifiableSet(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) {
+ private static final long serialVersionUID = 1L; // we're not serializing it
+
+ {
+ for (ECCurves c : VALUES) {
+ add(c.getKeyType());
+ }
+ }
+ });
- private final String name, keyType;
+ private final String name;
+ private final String keyType;
+ private final ECParameterSpec params;
+ private final int keySize;
+ private final int numOctets;
+
+ ECCurves(String name, ECParameterSpec params, int numOctets) {
+ this.name = ValidateUtils.checkNotNullAndNotEmpty(name, "No curve name");
+ this.keyType = Constants.ECDSA_SHA2_PREFIX + name;
+ this.params = ValidateUtils.checkNotNull(params, "No EC params for %s", name);
+ this.keySize = getCurveSize(params);
+ this.numOctets = numOctets;
+ }
@Override // The curve name
public final String getName() {
@@ -114,13 +166,10 @@ public enum ECCurves implements NamedResource, OptionalFeature {
return SecurityUtils.hasEcc();
}
- private final ECParameterSpec params;
public final ECParameterSpec getParameters() {
return params;
}
- private final int keySize, numOctets;
-
/**
* @return The size (in bits) of the key
*/
@@ -140,48 +189,6 @@ public enum ECCurves implements NamedResource, OptionalFeature {
*/
public abstract Digest getDigestForParams();
- ECCurves(String name, ECParameterSpec params, int numOctets) {
- this.name = ValidateUtils.checkNotNullAndNotEmpty(name, "No curve name");
- this.keyType = Constants.ECDSA_SHA2_PREFIX + name;
- this.params = ValidateUtils.checkNotNull(params, "No EC params for %s", name);
- this.keySize = getCurveSize(params);
- this.numOctets = numOctets;
- }
-
- /**
- * A {@link Set} of all the known curves
- */
- public static final Set<ECCurves> VALUES =
- Collections.unmodifiableSet(EnumSet.allOf(ECCurves.class));
-
- /**
- * A {@link Set} of all the known curves names
- */
- public static final Set<String> NAMES =
- Collections.unmodifiableSet(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) {
- private static final long serialVersionUID = 1L; // we're not serializing it
-
- {
- for (ECCurves c : VALUES) {
- add(c.getName());
- }
- }
- });
-
- /**
- * A {@link Set} of all the known curves key types
- */
- public static final Set<String> KEY_TYPES =
- Collections.unmodifiableSet(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) {
- private static final long serialVersionUID = 1L; // we're not serializing it
-
- {
- for (ECCurves c : VALUES) {
- add(c.getKeyType());
- }
- }
- });
-
/**
* @param type The key type value - ignored if {@code null}/empty
* @return The matching {@link ECCurves} constant - {@code null} if
@@ -191,26 +198,26 @@ public enum ECCurves implements NamedResource, OptionalFeature {
if (GenericUtils.isEmpty(type)) {
return null;
}
-
+
for (ECCurves c : VALUES) {
if (type.equalsIgnoreCase(c.getKeyType())) {
return c;
}
}
-
+
return null;
}
/**
* @param name The curve name (case <U>insensitive</U> - ignored if
- * {@code null}/empty
+ * {@code null}/empty
* @return The matching {@link ECCurves} instance - {@code null} if no
* match found
*/
public static ECCurves fromCurveName(String name) {
return NamedResource.Utils.findByName(name, String.CASE_INSENSITIVE_ORDER, VALUES);
}
-
+
/**
* @param params The curve's {@link ECParameterSpec} - ignored if {@code null}
* @return The matching {@link ECCurves} value - {@code null} if no match found
@@ -224,7 +231,7 @@ public enum ECCurves implements NamedResource, OptionalFeature {
return fromCurveSize(getCurveSize(params));
}
}
-
+
/**
* @param keySize The key size (in bits)
* @return The matching {@link ECCurves} value - {@code null} if no
@@ -234,13 +241,13 @@ public enum ECCurves implements NamedResource, OptionalFeature {
if (keySize <= 0) {
return null;
}
-
+
for (ECCurves c : VALUES) {
if (keySize == c.getKeySize()) {
return c;
}
}
-
+
return null;
}
@@ -250,7 +257,7 @@ public enum ECCurves implements NamedResource, OptionalFeature {
* @throws IllegalArgumentException if invalid parameters provided
*/
public static int getCurveSize(ECParameterSpec params) {
- EllipticCurve curve = ValidateUtils.checkNotNull(params, "No EC params").getCurve();
+ EllipticCurve curve = ValidateUtils.checkNotNull(params, "No EC params").getCurve();
ECField field = ValidateUtils.checkNotNull(curve, "No EC curve").getField();
return ValidateUtils.checkNotNull(field, "No EC field").getFieldSize();
}
@@ -262,22 +269,18 @@ public enum ECCurves implements NamedResource, OptionalFeature {
public static byte[] encodeECPoint(ECPoint group, EllipticCurve curve) {
// M has len 2 ceil(log_2(q)/8) + 1 ?
int elementSize = (curve.getField().getFieldSize() + 7) / 8;
- byte[] M = new byte[2 * elementSize + 1];
+ byte[] m = new byte[2 * elementSize + 1];
// Uncompressed format
- M[0] = 0x04;
+ m[0] = 0x04;
- {
- byte[] affineX = removeLeadingZeroes(group.getAffineX().toByteArray());
- System.arraycopy(affineX, 0, M, 1 + elementSize - affineX.length, affineX.length);
- }
+ byte[] affineX = removeLeadingZeroes(group.getAffineX().toByteArray());
+ System.arraycopy(affineX, 0, m, 1 + elementSize - affineX.length, affineX.length);
- {
- byte[] affineY = removeLeadingZeroes(group.getAffineY().toByteArray());
- System.arraycopy(affineY, 0, M, 1 + elementSize + elementSize - affineY.length, affineY.length);
- }
+ byte[] affineY = removeLeadingZeroes(group.getAffineY().toByteArray());
+ System.arraycopy(affineY, 0, m, 1 + elementSize + elementSize - affineY.length, affineY.length);
- return M;
+ return m;
}
private static byte[] removeLeadingZeroes(byte[] input) {
@@ -294,7 +297,7 @@ public enum ECCurves implements NamedResource, OptionalFeature {
System.arraycopy(input, pos, output, 0, output.length);
return output;
}
-
+
public static final class Constants {
/**
* Standard prefix of NISTP key types when encoded
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/cipher/package.html
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/package.html b/sshd-core/src/main/java/org/apache/sshd/common/cipher/package.html
index 7458bf5..197a89d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/package.html
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/package.html
@@ -19,8 +19,8 @@
</head>
<body>
- <a href="{@docRoot}/org/apache/sshd/common/cipher/Cipher.html"><code>Cipher</code></a>
- implementations.
+<a href="{@docRoot}/org/apache/sshd/common/cipher/Cipher.html"><code>Cipher</code></a>
+implementations.
</body>
</html>
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
index 42a5335..b2c2945 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
@@ -30,7 +30,6 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
-import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.config.NamedFactoriesListParseResult;
import org.apache.sshd.common.util.GenericUtils;
@@ -41,25 +40,35 @@ import org.apache.sshd.common.util.ValidateUtils;
*/
public enum BuiltinCompressions implements CompressionFactory {
none(Constants.NONE) {
- @Override
- public Compression create() {
- return null;
- }
- },
+ @Override
+ public Compression create() {
+ return null;
+ }
+ },
zlib(Constants.ZLIB) {
- @Override
- public Compression create() {
- return new CompressionZlib();
- }
- },
+ @Override
+ public Compression create() {
+ return new CompressionZlib();
+ }
+ },
delayedZlib(Constants.DELAYED_ZLIB) {
- @Override
- public Compression create() {
- return new CompressionDelayedZlib();
- }
- };
-
- private final String name;
+ @Override
+ public Compression create() {
+ return new CompressionDelayedZlib();
+ }
+ };
+
+ public static final Set<BuiltinCompressions> VALUES =
+ Collections.unmodifiableSet(EnumSet.allOf(BuiltinCompressions.class));
+
+ private static final Map<String, CompressionFactory> EXTENSIONS =
+ new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+
+ private final String name;
+
+ BuiltinCompressions(String n) {
+ name = n;
+ }
@Override
public final String getName() {
@@ -76,30 +85,22 @@ public enum BuiltinCompressions implements CompressionFactory {
return true;
}
- BuiltinCompressions(String n) {
- name = n;
- }
-
- public static Set<BuiltinCompressions> VALUES =
- Collections.unmodifiableSet(EnumSet.allOf(BuiltinCompressions.class));
- private static final Map<String,CompressionFactory> extensions =
- new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
-
/**
- * Registered a {@link NamedFactory} to be available besides the built-in
+ * Registered a {@link org.apache.sshd.common.NamedFactory} to be available besides the built-in
* ones when parsing configuration
+ *
* @param extension The factory to register
* @throws IllegalArgumentException if factory instance is {@code null},
- * or overrides a built-in one or overrides another registered factory
- * with the same name (case <U>insensitive</U>).
+ * or overrides a built-in one or overrides another registered factory
+ * with the same name (case <U>insensitive</U>).
*/
public static void registerExtension(CompressionFactory extension) {
- String name=ValidateUtils.checkNotNull(extension, "No extension provided").getName();
+ String name = ValidateUtils.checkNotNull(extension, "No extension provided").getName();
ValidateUtils.checkTrue(fromFactoryName(name) == null, "Extension overrides built-in: %s", name);
- synchronized(extensions) {
- ValidateUtils.checkTrue(!extensions.containsKey(name), "Extension overrides existinh: %s", name);
- extensions.put(name, extension);
+ synchronized (EXTENSIONS) {
+ ValidateUtils.checkTrue(!EXTENSIONS.containsKey(name), "Extension overrides existing: %s", name);
+ EXTENSIONS.put(name, extension);
}
}
@@ -109,13 +110,14 @@ public enum BuiltinCompressions implements CompressionFactory {
*/
public static SortedSet<CompressionFactory> getRegisteredExtensions() {
// TODO for JDK-8 return Collections.emptySortedSet()
- synchronized(extensions) {
- return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, extensions.values());
+ synchronized (EXTENSIONS) {
+ return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, EXTENSIONS.values());
}
}
/**
* Unregisters specified extension
+ *
* @param name The factory name - ignored if {@code null}/empty
* @return The registered extension - {@code null} if not found
*/
@@ -123,9 +125,9 @@ public enum BuiltinCompressions implements CompressionFactory {
if (GenericUtils.isEmpty(name)) {
return null;
}
-
- synchronized(extensions) {
- return extensions.remove(name);
+
+ synchronized (EXTENSIONS) {
+ return EXTENSIONS.remove(name);
}
}
@@ -134,29 +136,29 @@ public enum BuiltinCompressions implements CompressionFactory {
}
/**
- * @param Compressions A comma-separated list of Compressions' names - ignored
- * if {@code null}/empty
+ * @param compressions A comma-separated list of Compressions' names - ignored
+ * if {@code null}/empty
* @return A {@link ParseResult} containing the successfully parsed
* factories and the unknown ones. <B>Note:</B> it is up to caller to
* ensure that the lists do not contain duplicates
*/
- public static ParseResult parseCompressionsList(String Compressions) {
- return parseCompressionsList(GenericUtils.split(Compressions, ','));
+ public static ParseResult parseCompressionsList(String compressions) {
+ return parseCompressionsList(GenericUtils.split(compressions, ','));
}
- public static ParseResult parseCompressionsList(String ... Compressions) {
- return parseCompressionsList(GenericUtils.isEmpty((Object[]) Compressions) ? Collections.<String>emptyList() : Arrays.asList(Compressions));
+ public static ParseResult parseCompressionsList(String... compressions) {
+ return parseCompressionsList(GenericUtils.isEmpty((Object[]) compressions) ? Collections.<String>emptyList() : Arrays.asList(compressions));
}
- public static ParseResult parseCompressionsList(Collection<String> Compressions) {
- if (GenericUtils.isEmpty(Compressions)) {
+ public static ParseResult parseCompressionsList(Collection<String> compressions) {
+ if (GenericUtils.isEmpty(compressions)) {
return ParseResult.EMPTY;
}
-
- List<CompressionFactory> factories=new ArrayList<>(Compressions.size());
- List<String> unknown=Collections.emptyList();
- for (String name : Compressions) {
- CompressionFactory c=resolveFactory(name);
+
+ List<CompressionFactory> factories = new ArrayList<>(compressions.size());
+ List<String> unknown = Collections.emptyList();
+ for (String name : compressions) {
+ CompressionFactory c = resolveFactory(name);
if (c != null) {
factories.add(c);
} else {
@@ -167,45 +169,46 @@ public enum BuiltinCompressions implements CompressionFactory {
unknown.add(name);
}
}
-
+
return new ParseResult(factories, unknown);
}
/**
* @param name The factory name
* @return The factory or {@code null} if it is neither a built-in one
- * or a registered extension
+ * or a registered extension
*/
public static CompressionFactory resolveFactory(String name) {
if (GenericUtils.isEmpty(name)) {
return null;
}
- CompressionFactory c=fromFactoryName(name);
+ CompressionFactory c = fromFactoryName(name);
if (c != null) {
return c;
}
-
- synchronized(extensions) {
- return extensions.get(name);
+
+ synchronized (EXTENSIONS) {
+ return EXTENSIONS.get(name);
}
}
/**
* Holds the result of {@link BuiltinCompressions#parseCompressionsList(String)}
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
- public static class ParseResult extends NamedFactoriesListParseResult<Compression,CompressionFactory> {
- public static ParseResult EMPTY=new ParseResult(Collections.<CompressionFactory>emptyList(), Collections.<String>emptyList());
-
+ public static class ParseResult extends NamedFactoriesListParseResult<Compression, CompressionFactory> {
+ public static final ParseResult EMPTY = new ParseResult(Collections.<CompressionFactory>emptyList(), Collections.<String>emptyList());
+
public ParseResult(List<CompressionFactory> parsed, List<String> unsupported) {
super(parsed, unsupported);
}
}
public static class Constants {
- public static String NONE="none";
- public static String ZLIB="zlib";
- public static String DELAYED_ZLIB="zlib@openssh.com";
+ public static final String NONE = "none";
+ public static final String ZLIB = "zlib";
+ public static final String DELAYED_ZLIB = "zlib@openssh.com";
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
index 12abc4b..ff53d35 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
@@ -56,7 +56,7 @@ public interface Compression {
* <code>compress</code> or <code>uncompress</code> methods can be
* called.
*
- * @param type compression type
+ * @param type compression type
* @param level compression level
*/
void init(Type type, int level);
@@ -73,7 +73,7 @@ public interface Compression {
* Uncompress the data in a buffer into another buffer.
*
* @param from the buffer containing the data to uncompress
- * @param to the buffer receiving the uncompressed data
+ * @param to the buffer receiving the uncompressed data
* @throws IOException if an error occurs
*/
void uncompress(Buffer from, Buffer to) throws IOException;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionDelayedZlib.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionDelayedZlib.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionDelayedZlib.java
index 5c4e1a0..0b4faa5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionDelayedZlib.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionDelayedZlib.java
@@ -22,9 +22,8 @@ package org.apache.sshd.common.compression;
/**
* ZLib delayed compression.
*
- * @see Compression#isDelayed()
- *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ * @see Compression#isDelayed()
*/
public class CompressionDelayedZlib extends CompressionZlib {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionFactory.java
index 9895922..a55bd16 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionFactory.java
@@ -19,19 +19,12 @@
package org.apache.sshd.common.compression;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.OptionalFeature;
-import org.apache.sshd.common.util.Transformer;
+import org.apache.sshd.common.BuiltinFactory;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface CompressionFactory extends NamedFactory<Compression>, OptionalFeature {
- // required because of generics issues
- Transformer<CompressionFactory,NamedFactory<Compression>> FAC2NAMED=new Transformer<CompressionFactory,NamedFactory<Compression>>() {
- @Override
- public NamedFactory<Compression> transform(CompressionFactory input) {
- return input;
- }
- };
+// CHECKSTYLE:OFF
+public interface CompressionFactory extends BuiltinFactory<Compression> {
+
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
index 4b50c3b..64b0e7f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
@@ -31,7 +31,8 @@ import org.apache.sshd.common.util.buffer.Buffer;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class CompressionZlib implements Compression {
- static private final int BUF_SIZE = 4096;
+
+ private static final int BUF_SIZE = 4096;
private byte[] tmpbuf = new byte[BUF_SIZE];
private Deflater compresser;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/AllowTcpForwardingValue.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/AllowTcpForwardingValue.java b/sshd-core/src/main/java/org/apache/sshd/common/config/AllowTcpForwardingValue.java
index ace4741..f3c0b8d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/AllowTcpForwardingValue.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/AllowTcpForwardingValue.java
@@ -35,7 +35,7 @@ public enum AllowTcpForwardingValue {
LOCAL,
REMOTE;
- public static final Set<AllowTcpForwardingValue> VALUES=
+ public static final Set<AllowTcpForwardingValue> VALUES =
Collections.unmodifiableSet(EnumSet.allOf(AllowTcpForwardingValue.class));
// NOTE: it also interprets "yes" as "all" and "no" as "none"
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/CompressionConfigValue.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/CompressionConfigValue.java b/sshd-core/src/main/java/org/apache/sshd/common/config/CompressionConfigValue.java
index 936d052..5b92594 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/CompressionConfigValue.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/CompressionConfigValue.java
@@ -23,7 +23,6 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
-import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.compression.BuiltinCompressions;
import org.apache.sshd.common.compression.Compression;
import org.apache.sshd.common.compression.CompressionFactory;
@@ -31,7 +30,8 @@ import org.apache.sshd.common.util.GenericUtils;
/**
* Provides a "bridge" between the configuration values and the
- * actual {@link NamedFactory} for the {@link Compression}.
+ * actual {@link org.apache.sshd.common.NamedFactory} for the {@link Compression}.
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public enum CompressionConfigValue implements CompressionFactory {
@@ -39,13 +39,20 @@ public enum CompressionConfigValue implements CompressionFactory {
NO(BuiltinCompressions.none),
DELAYED(BuiltinCompressions.delayedZlib);
+ public static final Set<CompressionConfigValue> VALUES =
+ Collections.unmodifiableSet(EnumSet.allOf(CompressionConfigValue.class));
+
private final CompressionFactory factory;
+ CompressionConfigValue(CompressionFactory delegate) {
+ factory = delegate;
+ }
+
@Override
- public final String getName() {
+ public final String getName() {
return factory.getName();
}
-
+
@Override
public final Compression create() {
return factory.create();
@@ -61,13 +68,6 @@ public enum CompressionConfigValue implements CompressionFactory {
return getName();
}
- CompressionConfigValue(CompressionFactory delegate) {
- factory = delegate;
- }
-
- public static final Set<CompressionConfigValue> VALUES=
- Collections.unmodifiableSet(EnumSet.allOf(CompressionConfigValue.class));
-
public static CompressionConfigValue fromName(String n) {
if (GenericUtils.isEmpty(n)) {
return null;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/FactoriesListParseResult.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/FactoriesListParseResult.java b/sshd-core/src/main/java/org/apache/sshd/common/config/FactoriesListParseResult.java
index 853e16d..8b3a136 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/FactoriesListParseResult.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/FactoriesListParseResult.java
@@ -26,11 +26,11 @@ import org.apache.sshd.common.Factory;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public abstract class FactoriesListParseResult<T,F extends Factory<T>> extends ListParseResult<F> {
+public abstract class FactoriesListParseResult<T, F extends Factory<T>> extends ListParseResult<F> {
protected FactoriesListParseResult(List<F> parsed, List<String> unsupported) {
super(parsed, unsupported);
}
-
+
/**
* @return The {@link List} of successfully parsed {@link Factory} instances
* in the <U>same order</U> as they were encountered during parsing
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/ListParseResult.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/ListParseResult.java b/sshd-core/src/main/java/org/apache/sshd/common/config/ListParseResult.java
index bf39c89..90e59ec 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/ListParseResult.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/ListParseResult.java
@@ -29,6 +29,7 @@ import org.apache.sshd.common.util.GenericUtils;
* and {@link #getUnsupportedValues()} methods. <B>Note:</B> the returned {@link List}s may
* be un-modifiable, so it is recommended to avoid attempting changing the, returned
* list(s)
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public abstract class ListParseResult<E> {
@@ -55,11 +56,10 @@ public abstract class ListParseResult<E> {
public List<String> getUnsupportedValues() {
return unsupported;
}
-
+
@Override
public String toString() {
return "parsed=" + GenericUtils.join(getParsedValues(), ',')
- + ";unsupported=" + GenericUtils.join(getUnsupportedValues(), ',')
- ;
+ + ";unsupported=" + GenericUtils.join(getUnsupportedValues(), ',');
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/LogLevelValue.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/LogLevelValue.java b/sshd-core/src/main/java/org/apache/sshd/common/config/LogLevelValue.java
index cd59caa..14ad66e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/LogLevelValue.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/LogLevelValue.java
@@ -37,7 +37,7 @@ public enum LogLevelValue {
*/
QUIET, FATAL, ERROR, INFO, VERBOSE, DEBUG, DEBUG1, DEBUG2, DEBUG3;
- public static final Set<LogLevelValue> VALUES=
+ public static final Set<LogLevelValue> VALUES =
Collections.unmodifiableSet(EnumSet.allOf(LogLevelValue.class));
public static LogLevelValue fromName(String n) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/NamedFactoriesListParseResult.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/NamedFactoriesListParseResult.java b/sshd-core/src/main/java/org/apache/sshd/common/config/NamedFactoriesListParseResult.java
index 9e1b817..66a9c4e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/NamedFactoriesListParseResult.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/NamedFactoriesListParseResult.java
@@ -27,10 +27,11 @@ import org.apache.sshd.common.util.GenericUtils;
/**
* Holds the result of parsing a list of {@link NamedFactory}ies
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public abstract class NamedFactoriesListParseResult<T,F extends NamedFactory<T>>
- extends FactoriesListParseResult<T,F> {
+public abstract class NamedFactoriesListParseResult<T, F extends NamedFactory<T>>
+ extends FactoriesListParseResult<T, F> {
protected NamedFactoriesListParseResult(List<F> parsed, List<String> unsupported) {
super(parsed, unsupported);
@@ -39,7 +40,6 @@ public abstract class NamedFactoriesListParseResult<T,F extends NamedFactory<T>>
@Override
public String toString() {
return "parsed=" + NamedResource.Utils.getNames(getParsedFactories())
- + ";unknown=" + GenericUtils.join(getUnsupportedFactories(), ',')
- ;
+ + ";unknown=" + GenericUtils.join(getUnsupportedFactories(), ',');
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/NamedResourceListParseResult.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/NamedResourceListParseResult.java b/sshd-core/src/main/java/org/apache/sshd/common/config/NamedResourceListParseResult.java
index 03805ef..e75ca11 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/NamedResourceListParseResult.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/NamedResourceListParseResult.java
@@ -51,7 +51,6 @@ public abstract class NamedResourceListParseResult<R extends NamedResource> exte
@Override
public String toString() {
return "parsed=" + NamedResource.Utils.getNames(getParsedResources())
- + ";unknown=" + GenericUtils.join(getUnsupportedResources(), ',')
- ;
+ + ";unknown=" + GenericUtils.join(getUnsupportedResources(), ',');
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/common/config/SshConfigFileReader.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/SshConfigFileReader.java b/sshd-core/src/main/java/org/apache/sshd/common/config/SshConfigFileReader.java
index 8ff7f36..ae3637d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/SshConfigFileReader.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/SshConfigFileReader.java
@@ -41,10 +41,10 @@ import java.util.concurrent.TimeUnit;
import org.apache.sshd.client.ClientBuilder;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.common.AbstractFactoryManager;
+import org.apache.sshd.common.BuiltinFactory;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.cipher.Cipher;
-import org.apache.sshd.common.cipher.CipherFactory;
import org.apache.sshd.common.compression.BuiltinCompressions;
import org.apache.sshd.common.compression.Compression;
import org.apache.sshd.common.compression.CompressionFactory;
@@ -54,10 +54,8 @@ import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.mac.BuiltinMacs;
import org.apache.sshd.common.mac.Mac;
-import org.apache.sshd.common.mac.MacFactory;
import org.apache.sshd.common.signature.BuiltinSignatures;
import org.apache.sshd.common.signature.Signature;
-import org.apache.sshd.common.signature.SignatureFactory;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.Transformer;
import org.apache.sshd.common.util.ValidateUtils;
@@ -70,111 +68,115 @@ import org.apache.sshd.server.SshServer;
/**
* Reads and interprets some useful configurations from an OpenSSH
* configuration file.
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
* @see <a href="https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5">ssh_config(5)</a>
*/
-public class SshConfigFileReader {
- public static final char COMMENT_CHAR='#';
+public final class SshConfigFileReader {
+
+ public static final char COMMENT_CHAR = '#';
// Some well known configuration properties names and values
- public static final String BANNER_CONFIG_PROP="Banner";
- public static final String COMPRESSION_PROP="Compression";
- public static final String DEFAULT_COMPRESSION=CompressionConfigValue.NO.getName();
- public static final String ALLOW_TCP_FORWARDING_CONFIG_PROP="AllowTcpForwarding";
- public static final String DEFAULT_TCP_FORWARDING="yes";
- public static final boolean DEFAULT_TCP_FORWARDING_VALUE=parseBooleanValue(DEFAULT_TCP_FORWARDING);
- public static final String ALLOW_AGENT_FORWARDING_CONFIG_PROP="AllowAgentForwarding";
- public static final String DEFAULT_AGENT_FORWARDING="yes";
- public static final boolean DEFAULT_AGENT_FORWARDING_VALUE=parseBooleanValue(DEFAULT_AGENT_FORWARDING);
- public static final String ALLOW_X11_FORWARDING_CONFIG_PROP="X11Forwarding";
- public static final String DEFAULT_X11_FORWARDING="yes";
- public static final boolean DEFAULT_X11_FORWARDING_VALUE=parseBooleanValue(DEFAULT_X11_FORWARDING);
- public static final String MAX_SESSIONS_CONFIG_PROP="MaxSessions";
- public static final int DEFAULT_MAX_SESSIONS=10;
- public static final String PASSWORD_AUTH_CONFIG_PROP="PasswordAuthentication";
- public static final String DEFAULT_PASSWORD_AUTH="no";
- public static final boolean DEFAULT_PASSWORD_AUTH_VALUE=parseBooleanValue(DEFAULT_PASSWORD_AUTH);
- public static final String LISTEN_ADDRESS_CONFIG_PROP="ListenAddress";
- public static final String DEFAULT_BIND_ADDRESS="0.0.0.0";
- public static final String PORT_CONFIG_PROP="Port";
- public static final int DEFAULT_PORT=22;
- public static final String KEEP_ALIVE_CONFIG_PROP="TCPKeepAlive";
- public static final boolean DEFAULT_KEEP_ALIVE=true;
- public static final String USE_DNS_CONFIG_PROP="UseDNS";
- // NOTE: the usual default is TRUE
- public static final boolean DEFAULT_USE_DNS=true;
- public static final String PUBKEY_AUTH_CONFIG_PROP="PubkeyAuthentication";
- public static final String DEFAULT_PUBKEY_AUTH="yes";
- public static final boolean DEFAULT_PUBKEY_AUTH_VALUE=parseBooleanValue(DEFAULT_PUBKEY_AUTH);
- public static final String AUTH_KEYS_FILE_CONFIG_PROP="AuthorizedKeysFile";
- public static final String MAX_AUTH_TRIES_CONFIG_PROP="MaxAuthTries";
- public static final int DEFAULT_MAX_AUTH_TRIES=6;
- public static final String MAX_STARTUPS_CONFIG_PROP= "MaxStartups";
- public static final int DEFAULT_MAX_STARTUPS=10;
- public static final String LOGIN_GRACE_TIME_CONFIG_PROP="LoginGraceTime";
- public static final long DEFAULT_LOGIN_GRACE_TIME=TimeUnit.SECONDS.toMillis(120);
- public static final String KEY_REGENERATE_INTERVAL_CONFIG_PROP="KeyRegenerationInterval";
- public static final long DEFAULT_REKEY_TIME_LIMIT=TimeUnit.HOURS.toMillis(1L);
+ public static final String BANNER_CONFIG_PROP = "Banner";
+ public static final String COMPRESSION_PROP = "Compression";
+ public static final String DEFAULT_COMPRESSION = CompressionConfigValue.NO.getName();
+ public static final String ALLOW_TCP_FORWARDING_CONFIG_PROP = "AllowTcpForwarding";
+ public static final String DEFAULT_TCP_FORWARDING = "yes";
+ public static final boolean DEFAULT_TCP_FORWARDING_VALUE = parseBooleanValue(DEFAULT_TCP_FORWARDING);
+ public static final String ALLOW_AGENT_FORWARDING_CONFIG_PROP = "AllowAgentForwarding";
+ public static final String DEFAULT_AGENT_FORWARDING = "yes";
+ public static final boolean DEFAULT_AGENT_FORWARDING_VALUE = parseBooleanValue(DEFAULT_AGENT_FORWARDING);
+ public static final String ALLOW_X11_FORWARDING_CONFIG_PROP = "X11Forwarding";
+ public static final String DEFAULT_X11_FORWARDING = "yes";
+ public static final boolean DEFAULT_X11_FORWARDING_VALUE = parseBooleanValue(DEFAULT_X11_FORWARDING);
+ public static final String MAX_SESSIONS_CONFIG_PROP = "MaxSessions";
+ public static final int DEFAULT_MAX_SESSIONS = 10;
+ public static final String PASSWORD_AUTH_CONFIG_PROP = "PasswordAuthentication";
+ public static final String DEFAULT_PASSWORD_AUTH = "no";
+ public static final boolean DEFAULT_PASSWORD_AUTH_VALUE = parseBooleanValue(DEFAULT_PASSWORD_AUTH);
+ public static final String LISTEN_ADDRESS_CONFIG_PROP = "ListenAddress";
+ public static final String DEFAULT_BIND_ADDRESS = "0.0.0.0";
+ public static final String PORT_CONFIG_PROP = "Port";
+ public static final int DEFAULT_PORT = 22;
+ public static final String KEEP_ALIVE_CONFIG_PROP = "TCPKeepAlive";
+ public static final boolean DEFAULT_KEEP_ALIVE = true;
+ public static final String USE_DNS_CONFIG_PROP = "UseDNS";
+ // NOTE: the usual default is TRUE
+ public static final boolean DEFAULT_USE_DNS = true;
+ public static final String PUBKEY_AUTH_CONFIG_PROP = "PubkeyAuthentication";
+ public static final String DEFAULT_PUBKEY_AUTH = "yes";
+ public static final boolean DEFAULT_PUBKEY_AUTH_VALUE = parseBooleanValue(DEFAULT_PUBKEY_AUTH);
+ public static final String AUTH_KEYS_FILE_CONFIG_PROP = "AuthorizedKeysFile";
+ public static final String MAX_AUTH_TRIES_CONFIG_PROP = "MaxAuthTries";
+ public static final int DEFAULT_MAX_AUTH_TRIES = 6;
+ public static final String MAX_STARTUPS_CONFIG_PROP = "MaxStartups";
+ public static final int DEFAULT_MAX_STARTUPS = 10;
+ public static final String LOGIN_GRACE_TIME_CONFIG_PROP = "LoginGraceTime";
+ public static final long DEFAULT_LOGIN_GRACE_TIME = TimeUnit.SECONDS.toMillis(120);
+ public static final String KEY_REGENERATE_INTERVAL_CONFIG_PROP = "KeyRegenerationInterval";
+ public static final long DEFAULT_REKEY_TIME_LIMIT = TimeUnit.HOURS.toMillis(1L);
// see http://manpages.ubuntu.com/manpages/precise/en/man5/sshd_config.5.html
- public static final String CIPHERS_CONFIG_PROP="Ciphers";
- public static final String DEFAULT_CIPHERS=
- "aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour";
+ public static final String CIPHERS_CONFIG_PROP = "Ciphers";
+ public static final String DEFAULT_CIPHERS =
+ "aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour";
// see http://manpages.ubuntu.com/manpages/precise/en/man5/sshd_config.5.html
- public static final String MACS_CONFIG_PROP="MACs";
- public static final String DEFAULT_MACS=
- "hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96";
+ public static final String MACS_CONFIG_PROP = "MACs";
+ public static final String DEFAULT_MACS =
+ "hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96";
// see http://manpages.ubuntu.com/manpages/precise/en/man5/sshd_config.5.html
- public static final String KEX_ALGORITHMS_CONFIG_PROP="KexAlgorithms";
- public static final String DEFAULT_KEX_ALGORITHMS=
- "ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521"
- + "," + "diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1"
- + "," + "diffie-hellman-group14-sha1,diffie-hellman-group1-sha1"
- ;
+ public static final String KEX_ALGORITHMS_CONFIG_PROP = "KexAlgorithms";
+ public static final String DEFAULT_KEX_ALGORITHMS =
+ "ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521"
+ + "," + "diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1"
+ + "," + "diffie-hellman-group14-sha1,diffie-hellman-group1-sha1";
// see http://linux.die.net/man/5/ssh_config
- public static final String HOST_KEY_ALGORITHMS_CONFIG_PROP="HostKeyAlgorithms";
- // see https://tools.ietf.org/html/rfc5656
- public static final String DEFAULT_HOST_KEY_ALGORITHMS=
- KeyPairProvider.SSH_RSA
- + "," + KeyPairProvider.SSH_DSS
- ;
+ public static final String HOST_KEY_ALGORITHMS_CONFIG_PROP = "HostKeyAlgorithms";
+ // see https://tools.ietf.org/html/rfc5656
+ public static final String DEFAULT_HOST_KEY_ALGORITHMS =
+ KeyPairProvider.SSH_RSA
+ + "," + KeyPairProvider.SSH_DSS;
// see http://manpages.ubuntu.com/manpages/precise/en/man5/sshd_config.5.html
- public static final String LOG_LEVEL_CONFIG_PROP="LogLevel";
- public static final LogLevelValue DEFAULT_LOG_LEVEL=LogLevelValue.INFO;
+ public static final String LOG_LEVEL_CONFIG_PROP = "LogLevel";
+ public static final LogLevelValue DEFAULT_LOG_LEVEL = LogLevelValue.INFO;
// see https://www.freebsd.org/cgi/man.cgi?query=sshd_config&sektion=5
- public static final String SYSLOG_FACILITY_CONFIG_PROP="SyslogFacility";
- public static final SyslogFacilityValue DEFAULT_SYSLOG_FACILITY=SyslogFacilityValue.AUTH;
- public static final String SUBSYSTEM_CONFIG_PROP="Subsystem";
+ public static final String SYSLOG_FACILITY_CONFIG_PROP = "SyslogFacility";
+ public static final SyslogFacilityValue DEFAULT_SYSLOG_FACILITY = SyslogFacilityValue.AUTH;
+ public static final String SUBSYSTEM_CONFIG_PROP = "Subsystem";
+
+ private SshConfigFileReader() {
+ throw new UnsupportedOperationException("No instance allowed");
+ }
public static Properties readConfigFile(File file) throws IOException {
return readConfigFile(file.toPath(), IoUtils.EMPTY_OPEN_OPTIONS);
}
- public static Properties readConfigFile(Path path, OpenOption ... options) throws IOException {
- try(InputStream input = Files.newInputStream(path, options)) {
+ public static Properties readConfigFile(Path path, OpenOption... options) throws IOException {
+ try (InputStream input = Files.newInputStream(path, options)) {
return readConfigFile(input, true);
}
}
public static Properties readConfigFile(URL url) throws IOException {
- try(InputStream input=url.openStream()) {
+ try (InputStream input = url.openStream()) {
return readConfigFile(input, true);
}
}
public static Properties readConfigFile(String path) throws IOException {
- try(InputStream input=new FileInputStream(path)) {
+ try (InputStream input = new FileInputStream(path)) {
return readConfigFile(input, true);
}
}
public static Properties readConfigFile(InputStream input, boolean okToClose) throws IOException {
- try(Reader reader=new InputStreamReader(NoCloseInputStream.resolveInputStream(input, okToClose), StandardCharsets.UTF_8)) {
+ try (Reader reader = new InputStreamReader(NoCloseInputStream.resolveInputStream(input, okToClose), StandardCharsets.UTF_8)) {
return readConfigFile(reader, true);
}
}
public static Properties readConfigFile(Reader reader, boolean okToClose) throws IOException {
- try(BufferedReader buf=new BufferedReader(NoCloseReader.resolveReader(reader, okToClose))) {
+ try (BufferedReader buf = new BufferedReader(NoCloseReader.resolveReader(reader, okToClose))) {
return readConfigFile(buf);
}
}
@@ -184,20 +186,21 @@ public class SshConfigFileReader {
* <B>Note:</B> multiple keys value are concatenated using a comma - it is up to
* the caller to know which keys are expected to have multiple values and handle
* the split accordingly
+ *
* @param rdr The {@link BufferedReader} for reading the file
* @return The read properties
* @throws IOException If failed to read or malformed content
*/
public static Properties readConfigFile(BufferedReader rdr) throws IOException {
- Properties props=new Properties();
- int lineNumber=1;
- for (String line=rdr.readLine(); line != null; line=rdr.readLine(), lineNumber++) {
+ Properties props = new Properties();
+ int lineNumber = 1;
+ for (String line = rdr.readLine(); line != null; line = rdr.readLine(), lineNumber++) {
line = GenericUtils.trimToEmpty(line);
if (GenericUtils.isEmpty(line)) {
continue;
}
- int pos=line.indexOf(COMMENT_CHAR);
+ int pos = line.indexOf(COMMENT_CHAR);
if (pos == 0) {
continue;
}
@@ -211,7 +214,8 @@ public class SshConfigFileReader {
* Some options use '=', others use ' ' - try both
* NOTE: we do not validate the format for each option separately
*/
- if ((pos=line.indexOf(' ')) < 0) {
+ pos = line.indexOf(' ');
+ if (pos < 0) {
pos = line.indexOf('=');
}
@@ -219,10 +223,10 @@ public class SshConfigFileReader {
throw new StreamCorruptedException("No delimiter at line " + lineNumber + ": " + line);
}
- String key=line.substring(0, pos);
- String value=line.substring(pos + 1).trim();
+ String key = line.substring(0, pos);
+ String value = line.substring(pos + 1).trim();
// see if need to concatenate multi-valued keys
- String prev=props.getProperty(key);
+ String prev = props.getProperty(key);
if (!GenericUtils.isEmpty(prev)) {
value = prev + "," + value;
}
@@ -333,10 +337,10 @@ public class SshConfigFileReader {
}
/**
- * @param v The value to parse - if {@code null}/empty then the default
- * value is returned, otherwise {@link #parseBooleanValue(String)} is used
+ * @param v The value to parse - if {@code null}/empty then the default
+ * value is returned, otherwise {@link #parseBooleanValue(String)} is used
* @param defaultValue The default value to return if {@code null}/empty
- * input string
+ * input string
* @return The result
*/
public static boolean parseBooleanValue(String v, boolean defaultValue) {
@@ -349,21 +353,17 @@ public class SshConfigFileReader {
/**
* @param v Checks if the value is "yes", "y"
- * or "on" or "true".
+ * or "on" or "true".
* @return The result - <B>Note:</B> {@code null}/empty values are
* intrepreted as {@code false}
*/
public static boolean parseBooleanValue(String v) {
- if ("yes".equalsIgnoreCase(v)
- || "y".equalsIgnoreCase(v)
- || "on".equalsIgnoreCase(v)
- || "true".equalsIgnoreCase(v)) {
- return true;
- } else {
- return false;
- }
+ return "yes".equalsIgnoreCase(v)
+ || "y".equalsIgnoreCase(v)
+ || "on".equalsIgnoreCase(v)
+ || "true".equalsIgnoreCase(v);
}
-
+
/**
* @param props The {@link Properties} - ignored if {@code null}/empty
* @return A {@link BuiltinCiphers.ParseResult} of all the {@link NamedFactory}-ies
@@ -378,7 +378,7 @@ public class SshConfigFileReader {
public static BuiltinCiphers.ParseResult getCiphers(Properties props) {
return BuiltinCiphers.parseCiphersList((props == null) ? null : props.getProperty(CIPHERS_CONFIG_PROP));
}
-
+
/**
* @param props The {@link Properties} - ignored if {@code null}/empty
* @return A {@link BuiltinMacs.ParseResult} of all the {@link NamedFactory}-ies
@@ -393,7 +393,7 @@ public class SshConfigFileReader {
public static BuiltinMacs.ParseResult getMacs(Properties props) {
return BuiltinMacs.parseMacsList((props == null) ? null : props.getProperty(MACS_CONFIG_PROP));
}
-
+
/**
* @param props The {@link Properties} - ignored if {@code null}/empty
* @return A {@link BuiltinSignatures.ParseResult} of all the {@link NamedFactory}
@@ -407,7 +407,7 @@ public class SshConfigFileReader {
public static BuiltinSignatures.ParseResult getSignatures(Properties props) {
return BuiltinSignatures.parseSignatureList((props == null) ? null : props.getProperty(HOST_KEY_ALGORITHMS_CONFIG_PROP));
}
-
+
/**
* @param props The {@link Properties} - ignored if {@code null}/empty
* @return A {@link BuiltinDHFactories.ParseResult} of all the {@link DHFactory}-ies
@@ -421,16 +421,16 @@ public class SshConfigFileReader {
public static BuiltinDHFactories.ParseResult getKexFactories(Properties props) {
return BuiltinDHFactories.parseDHFactoriesList((props == null) ? null : props.getProperty(KEX_ALGORITHMS_CONFIG_PROP));
}
-
+
/**
* @param props The {@link Properties} - ignored if {@code null}/empty
* @return The matching {@link NamedFactory} for the configured value.
- * {@code null} if no configuration or unknown name specified
+ * {@code null} if no configuration or unknown name specified
*/
public static CompressionFactory getCompression(Properties props) {
return CompressionConfigValue.fromName((props == null) ? null : props.getProperty(COMPRESSION_PROP));
}
-
+
public static <S extends SshServer> S configure(S server, Properties props, boolean lenient, boolean ignoreUnsupported) {
configure((AbstractFactoryManager) server, props, lenient, ignoreUnsupported);
configureKeyExchanges(server, props, lenient, ServerBuilder.DH2KEX, ignoreUnsupported);
@@ -447,20 +447,21 @@ public class SshConfigFileReader {
* <P>Configures an {@link AbstractFactoryManager} with the values read from
* some configuration. Currently it configures:</P></BR>
* <UL>
- * <LI>The {@link Cipher}s - via the {@link #CIPHERS_CONFIG_PROP}</LI>
- * <LI>The {@link Mac}s - via the {@link #MACS_CONFIG_PROP}</LI>
- * <LI>The {@link Signature}s - via the {@link #HOST_KEY_ALGORITHMS_CONFIG_PROP}</LI>
- * <LI>The {@link Compression} - via the {@link #COMPRESSION_PROP}</LI>
+ * <LI>The {@link Cipher}s - via the {@link #CIPHERS_CONFIG_PROP}</LI>
+ * <LI>The {@link Mac}s - via the {@link #MACS_CONFIG_PROP}</LI>
+ * <LI>The {@link Signature}s - via the {@link #HOST_KEY_ALGORITHMS_CONFIG_PROP}</LI>
+ * <LI>The {@link Compression} - via the {@link #COMPRESSION_PROP}</LI>
* </UL>
- * @param manager The {@link AbstractFactoryManager} to configure
- * @param props The {@link Properties} to use for configuration - <B>Note:</B>
- * if any known configuration value has a default and does not appear in the
- * properties, the default is used
- * @param lenient If {@code true} then any unknown configuration values are ignored.
- * Otherwise an {@link IllegalArgumentException} is thrown
+ *
+ * @param manager The {@link AbstractFactoryManager} to configure
+ * @param props The {@link Properties} to use for configuration - <B>Note:</B>
+ * if any known configuration value has a default and does not appear in the
+ * properties, the default is used
+ * @param lenient If {@code true} then any unknown configuration values are ignored.
+ * Otherwise an {@link IllegalArgumentException} is thrown
* @param ignoreUnsupported filter out unsupported configuration values (e.g., ciphers,
- * key exchanges, etc..). <B>Note:</B> if after filtering out all the unknown
- * or unsupported values there is an empty configuration exception is thrown
+ * key exchanges, etc..). <B>Note:</B> if after filtering out all the unknown
+ * or unsupported values there is an empty configuration exception is thrown
* @return The configured manager
*/
public static <M extends AbstractFactoryManager> M configure(M manager, Properties props, boolean lenient, boolean ignoreUnsupported) {
@@ -480,12 +481,12 @@ public class SshConfigFileReader {
public static <M extends AbstractFactoryManager> M configureCiphers(M manager, String value, boolean lenient, boolean ignoreUnsupported) {
ValidateUtils.checkNotNull(manager, "No manager to configure");
- BuiltinCiphers.ParseResult result=BuiltinCiphers.parseCiphersList(value);
- Collection<String> unsupported=result.getUnsupportedFactories();
+ BuiltinCiphers.ParseResult result = BuiltinCiphers.parseCiphersList(value);
+ Collection<String> unsupported = result.getUnsupportedFactories();
ValidateUtils.checkTrue(lenient || GenericUtils.isEmpty(unsupported), "Unsupported cipher(s) (%s) in %s", unsupported, value);
- List<NamedFactory<Cipher>> factories =
- NamedFactory.Utils.setUpTransformedFactories(ignoreUnsupported, result.getParsedFactories(), CipherFactory.FAC2NAMED);
+ List<NamedFactory<Cipher>> factories =
+ BuiltinFactory.Utils.setUpFactories(ignoreUnsupported, result.getParsedFactories());
manager.setCipherFactories(ValidateUtils.checkNotNullAndNotEmpty(factories, "No known/unsupported ciphers(s): %s", value));
return manager;
}
@@ -498,16 +499,16 @@ public class SshConfigFileReader {
public static <M extends AbstractFactoryManager> M configureSignatures(M manager, String value, boolean lenient, boolean ignoreUnsupported) {
ValidateUtils.checkNotNull(manager, "No manager to configure");
- BuiltinSignatures.ParseResult result=BuiltinSignatures.parseSignatureList(value);
- Collection<String> unsupported=result.getUnsupportedFactories();
+ BuiltinSignatures.ParseResult result = BuiltinSignatures.parseSignatureList(value);
+ Collection<String> unsupported = result.getUnsupportedFactories();
ValidateUtils.checkTrue(lenient || GenericUtils.isEmpty(unsupported), "Unsupported signatures (%s) in %s", unsupported, value);
-
- List<NamedFactory<Signature>> factories =
- NamedFactory.Utils.setUpTransformedFactories(ignoreUnsupported, result.getParsedFactories(), SignatureFactory.FAC2NAMED);
+
+ List<NamedFactory<Signature>> factories =
+ BuiltinFactory.Utils.setUpFactories(ignoreUnsupported, result.getParsedFactories());
manager.setSignatureFactories(ValidateUtils.checkNotNullAndNotEmpty(factories, "No known/supported signatures: %s", value));
return manager;
}
-
+
public static <M extends AbstractFactoryManager> M configureMacs(M manager, Properties props, boolean lenient, boolean ignoreUnsupported) {
ValidateUtils.checkNotNull(props, "No properties to configure");
return configureMacs(manager, props.getProperty(MACS_CONFIG_PROP, DEFAULT_MACS), lenient, ignoreUnsupported);
@@ -516,26 +517,26 @@ public class SshConfigFileReader {
public static <M extends AbstractFactoryManager> M configureMacs(M manager, String value, boolean lenient, boolean ignoreUnsupported) {
ValidateUtils.checkNotNull(manager, "No manager to configure");
- BuiltinMacs.ParseResult result=BuiltinMacs.parseMacsList(value);
- Collection<String> unsupported=result.getUnsupportedFactories();
+ BuiltinMacs.ParseResult result = BuiltinMacs.parseMacsList(value);
+ Collection<String> unsupported = result.getUnsupportedFactories();
ValidateUtils.checkTrue(lenient || GenericUtils.isEmpty(unsupported), "Unsupported MAC(s) (%s) in %s", unsupported, value);
-
+
List<NamedFactory<Mac>> factories =
- NamedFactory.Utils.setUpTransformedFactories(ignoreUnsupported, result.getParsedFactories(), MacFactory.FAC2NAMED);
+ BuiltinFactory.Utils.setUpFactories(ignoreUnsupported, result.getParsedFactories());
manager.setMacFactories(ValidateUtils.checkNotNullAndNotEmpty(factories, "No known/supported MAC(s): %s", value));
return manager;
}
/**
- * @param manager The {@link AbstractFactoryManager} to set up (may not be {@code null})
- * @param props The (non-{@code null}) {@link Properties} containing the configuration
- * @param lenient If {@code true} then any unknown/unsupported configuration
- * values are ignored. Otherwise an {@link IllegalArgumentException} is thrown
- * @param xformer A {@link Transformer} to convert the configured {@link DHFactory}-ies
- * to {@link NamedFactory}-ies of {@link KeyExchange}
+ * @param manager The {@link AbstractFactoryManager} to set up (may not be {@code null})
+ * @param props The (non-{@code null}) {@link Properties} containing the configuration
+ * @param lenient If {@code true} then any unknown/unsupported configuration
+ * values are ignored. Otherwise an {@link IllegalArgumentException} is thrown
+ * @param xformer A {@link Transformer} to convert the configured {@link DHFactory}-ies
+ * to {@link NamedFactory}-ies of {@link KeyExchange}
* @param ignoreUnsupported Filter out any un-supported configurations - <B>Note:</B>
- * if after ignoring the unknown and un-supported values the result is an empty
- * list of factories and exception is thrown
+ * if after ignoring the unknown and un-supported values the result is an empty
+ * list of factories and exception is thrown
* @return The configured manager
* @see #KEX_ALGORITHMS_CONFIG_PROP
* @see #DEFAULT_KEX_ALGORITHMS
@@ -551,10 +552,10 @@ public class SshConfigFileReader {
ValidateUtils.checkNotNull(manager, "No manager to configure");
ValidateUtils.checkNotNull(xformer, "No DHFactory transformer");
- BuiltinDHFactories.ParseResult result=BuiltinDHFactories.parseDHFactoriesList(value);
- Collection<String> unsupported=result.getUnsupportedFactories();
+ BuiltinDHFactories.ParseResult result = BuiltinDHFactories.parseDHFactoriesList(value);
+ Collection<String> unsupported = result.getUnsupportedFactories();
ValidateUtils.checkTrue(lenient || GenericUtils.isEmpty(unsupported), "Unsupported KEX(s) (%s) in %s", unsupported, value);
-
+
List<NamedFactory<KeyExchange>> factories =
NamedFactory.Utils.setUpTransformedFactories(ignoreUnsupported, result.getParsedFactories(), xformer);
manager.setKeyExchangeFactories(ValidateUtils.checkNotNullAndNotEmpty(factories, "No known/supported KEXS(s): %s", value));
@@ -563,26 +564,27 @@ public class SshConfigFileReader {
/**
* Configure the factory manager using one of the known {@link CompressionConfigValue}s.
- * @param manager The {@link AbstractFactoryManager} to configure
- * @param props The configuration {@link Properties}
- * @param lenient If {@code true} and an unknown value is provided then
- * it is ignored
+ *
+ * @param manager The {@link AbstractFactoryManager} to configure
+ * @param props The configuration {@link Properties}
+ * @param lenient If {@code true} and an unknown value is provided then
+ * it is ignored
* @param ignoreUnsupported If {@code false} then check if the compression
- * is currently supported before setting it
+ * is currently supported before setting it
* @return The configured manager - <B>Note:</B> if the result of filtering due
* to lenient mode or ignored unsupported value is empty then no factories are set
*/
public static <M extends AbstractFactoryManager> M configureCompression(M manager, Properties props, boolean lenient, boolean ignoreUnsupported) {
ValidateUtils.checkNotNull(manager, "No manager to configure");
ValidateUtils.checkNotNull(props, "No properties to configure");
-
- String value=props.getProperty(COMPRESSION_PROP, DEFAULT_COMPRESSION);
- CompressionFactory factory=CompressionConfigValue.fromName(value);
+
+ String value = props.getProperty(COMPRESSION_PROP, DEFAULT_COMPRESSION);
+ CompressionFactory factory = CompressionConfigValue.fromName(value);
ValidateUtils.checkTrue(lenient || (factory != null), "Unsupported compression value: %s", value);
if ((factory != null) && factory.isSupported()) {
manager.setCompressionFactories(Collections.<NamedFactory<Compression>>singletonList(factory));
}
-
+
return manager;
}
@@ -590,19 +592,19 @@ public class SshConfigFileReader {
public static <M extends AbstractFactoryManager> M configureCompression(M manager, String value, boolean lenient, boolean ignoreUnsupported) {
ValidateUtils.checkNotNull(manager, "No manager to configure");
- CompressionFactory factory=CompressionConfigValue.fromName(value);
+ CompressionFactory factory = CompressionConfigValue.fromName(value);
if (factory != null) {
// SSH can work without compression
if (ignoreUnsupported || factory.isSupported()) {
manager.setCompressionFactories(Collections.<NamedFactory<Compression>>singletonList(factory));
}
- } else {
- BuiltinCompressions.ParseResult result=BuiltinCompressions.parseCompressionsList(value);
- Collection<String> unsupported=result.getUnsupportedFactories();
+ } else {
+ BuiltinCompressions.ParseResult result = BuiltinCompressions.parseCompressionsList(value);
+ Collection<String> unsupported = result.getUnsupportedFactories();
ValidateUtils.checkTrue(lenient || GenericUtils.isEmpty(unsupported), "Unsupported compressions(s) (%s) in %s", unsupported, value);
-
+
List<NamedFactory<Compression>> factories =
- NamedFactory.Utils.setUpTransformedFactories(ignoreUnsupported, result.getParsedFactories(), CompressionFactory.FAC2NAMED);
+ BuiltinFactory.Utils.setUpFactories(ignoreUnsupported, result.getParsedFactories());
// SSH can work without compression
if (GenericUtils.size(factories) > 0) {
manager.setCompressionFactories(factories);