You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2015/03/30 11:17:54 UTC
[5/6] mina-sshd git commit: [SSHD-430] Refactor BuiltinCiphers into a
Factory
[SSHD-430] Refactor BuiltinCiphers into a Factory<Cipher>
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/31d4dc5a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/31d4dc5a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/31d4dc5a
Branch: refs/heads/master
Commit: 31d4dc5ac5a41552ee72d688ba41124d4a020be4
Parents: 7355193
Author: Guillaume Nodet <gn...@apache.org>
Authored: Thu Mar 26 16:46:37 2015 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Mar 30 10:52:43 2015 +0200
----------------------------------------------------------------------
.../main/java/org/apache/sshd/SshBuilder.java | 2 +-
.../apache/sshd/common/cipher/AES128CBC.java | 54 ---------
.../apache/sshd/common/cipher/AES128CTR.java | 54 ---------
.../apache/sshd/common/cipher/AES192CBC.java | 54 ---------
.../apache/sshd/common/cipher/AES192CTR.java | 54 ---------
.../apache/sshd/common/cipher/AES256CBC.java | 54 ---------
.../apache/sshd/common/cipher/AES256CTR.java | 54 ---------
.../apache/sshd/common/cipher/ARCFOUR128.java | 54 ---------
.../apache/sshd/common/cipher/ARCFOUR256.java | 54 ---------
.../apache/sshd/common/cipher/BlowfishCBC.java | 54 ---------
.../sshd/common/cipher/BuiltinCiphers.java | 119 ++++++++-----------
.../apache/sshd/common/cipher/CipherNone.java | 19 ---
.../apache/sshd/common/cipher/TripleDESCBC.java | 54 ---------
.../test/java/org/apache/sshd/CipherTest.java | 22 ++--
.../test/java/org/apache/sshd/ClientTest.java | 5 +-
.../src/test/java/org/apache/sshd/LoadTest.java | 3 +-
.../src/test/java/org/apache/sshd/MacTest.java | 13 +-
.../sshd/common/cipher/AES192CTRTest.java | 2 +-
.../sshd/common/cipher/AES256CBCTest.java | 2 +-
.../sshd/common/cipher/ARCFOUR128Test.java | 2 +-
.../sshd/common/cipher/ARCFOUR256Test.java | 2 +-
.../sshd/common/cipher/BuiltinCiphersTest.java | 34 +++---
22 files changed, 87 insertions(+), 678 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java b/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
index e441457..df9fad8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshBuilder.java
@@ -297,7 +297,7 @@ public class SshBuilder {
List<NamedFactory<Cipher>> avail = new ArrayList<NamedFactory<Cipher>>(DEFAULT_CIPHERS_PREFERENCE.size());
for (BuiltinCiphers c : DEFAULT_CIPHERS_PREFERENCE) {
if (ignoreUnsupported || c.isSupported()) {
- avail.add(c.create());
+ avail.add(c);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CBC.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CBC.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CBC.java
deleted file mode 100644
index 39a1a08..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CBC.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * AES128CBC cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class AES128CBC extends BaseCipher {
-
- /**
- * Named factory for AES128CBC Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "aes128-cbc";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new AES128CBC();
- }
- }
-
- public AES128CBC() {
- super(16, 16, "AES", "AES/CBC/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CTR.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CTR.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CTR.java
deleted file mode 100644
index 2cbfb21..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES128CTR.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * AES128CTR cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class AES128CTR extends BaseCipher {
-
- /**
- * Named factory for AES128CTR Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "aes128-ctr";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new AES128CTR();
- }
- }
-
- public AES128CTR() {
- super(16, 16, "AES", "AES/CTR/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CBC.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CBC.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CBC.java
deleted file mode 100644
index 3d26f76..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CBC.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * AES192CBC Cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class AES192CBC extends BaseCipher {
-
- /**
- * Named factory for AES192CBC Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "aes192-cbc";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new AES192CBC();
- }
- }
-
- public AES192CBC() {
- super(16, 24, "AES", "AES/CBC/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CTR.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CTR.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CTR.java
deleted file mode 100644
index cf13b9f..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES192CTR.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * AES192CBC Cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class AES192CTR extends BaseCipher {
-
- /**
- * Named factory for AES192CBC Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "aes192-ctr";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new AES192CTR();
- }
- }
-
- public AES192CTR() {
- super(16, 24, "AES", "AES/CTR/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CBC.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CBC.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CBC.java
deleted file mode 100644
index 38122d8..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CBC.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * AES256CBC Cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class AES256CBC extends BaseCipher {
-
- /**
- * Named factory for AES256CBC Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "aes256-cbc";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new AES256CBC();
- }
- }
-
- public AES256CBC() {
- super(16, 32, "AES", "AES/CBC/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CTR.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CTR.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CTR.java
deleted file mode 100644
index 718017f..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/AES256CTR.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * AES256CTR Cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class AES256CTR extends BaseCipher {
-
- /**
- * Named factory for AES256CTR Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "aes256-ctr";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new AES256CTR();
- }
- }
-
- public AES256CTR() {
- super(16, 32, "AES", "AES/CTR/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR128.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR128.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR128.java
deleted file mode 100644
index 33d6a6e..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR128.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * ARCFOUR128 cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class ARCFOUR128 extends BaseRC4Cipher {
-
- /**
- * Named factory for ARCFOUR128 Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "arcfour128";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new ARCFOUR128();
- }
- }
-
- public ARCFOUR128() {
- super(8, 16);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR256.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR256.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR256.java
deleted file mode 100644
index 500c1b7..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ARCFOUR256.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * ARCFOUR256 cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class ARCFOUR256 extends BaseRC4Cipher {
-
- /**
- * Named factory for AES128CTR Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "arcfour256";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new ARCFOUR256();
- }
- }
-
- public ARCFOUR256() {
- super(8, 32);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BlowfishCBC.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BlowfishCBC.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/BlowfishCBC.java
deleted file mode 100644
index b2c6135..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BlowfishCBC.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * BlowfishCBC Cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class BlowfishCBC extends BaseCipher {
-
- /**
- * Named factory for BlowfishCBC Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "blowfish-cbc";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new BlowfishCBC();
- }
- }
-
- public BlowfishCBC() {
- super(8, 16, "Blowfish", "Blowfish/CBC/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/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 74c45f1..d6c0526 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
@@ -33,89 +33,83 @@ import org.apache.sshd.common.util.GenericUtils;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public enum BuiltinCiphers implements NamedFactory<NamedFactory<Cipher>> {
- none(CipherNone.Factory.NAME, CipherNone.class) {
+public enum BuiltinCiphers implements NamedFactory<Cipher> {
+ none(Constants.NONE) {
@Override
- public NamedFactory<Cipher> create() {
- return new CipherNone.Factory();
+ public Cipher create() {
+ return new CipherNone();
}
},
- aes128cbc(AES128CBC.Factory.NAME, AES128CBC.class) {
+ aes128cbc(Constants.AES128_CBC) {
@Override
- public NamedFactory<Cipher> create() {
- return new AES128CBC.Factory();
+ public Cipher create() {
+ return new BaseCipher(16, 16, "AES", "AES/CBC/NoPadding");
}
},
- aes128ctr(AES128CTR.Factory.NAME, AES128CTR.class) {
+ aes128ctr(Constants.AES128_CTR) {
@Override
- public NamedFactory<Cipher> create() {
- return new AES128CTR.Factory();
+ public Cipher create() {
+ return new BaseCipher(16, 16, "AES", "AES/CTR/NoPadding");
}
},
- aes192cbc(AES192CBC.Factory.NAME, AES192CBC.class) {
+ aes192cbc(Constants.AES192_CBC) {
@Override
- public NamedFactory<Cipher> create() {
- return new AES192CBC.Factory();
+ public Cipher create() {
+ return new BaseCipher(16, 24, "AES", "AES/CBC/NoPadding");
}
},
- aes192ctr(AES192CTR.Factory.NAME, AES192CTR.class) {
+ aes192ctr(Constants.AES192_CTR) {
@Override
- public NamedFactory<Cipher> create() {
- return new AES192CTR.Factory();
+ public Cipher create() {
+ return new BaseCipher(16, 24, "AES", "AES/CTR/NoPadding");
}
},
- aes256cbc(AES256CBC.Factory.NAME, AES256CBC.class) {
+ aes256cbc(Constants.AES256_CBC) {
@Override
- public NamedFactory<Cipher> create() {
- return new AES256CBC.Factory();
+ public Cipher create() {
+ return new BaseCipher(16, 32, "AES", "AES/CBC/NoPadding");
}
},
- aes256ctr(AES256CTR.Factory.NAME, AES256CTR.class) {
+ aes256ctr(Constants.AES256_CTR) {
@Override
- public NamedFactory<Cipher> create() {
- return new AES256CTR.Factory();
+ public Cipher create() {
+ return new BaseCipher(16, 32, "AES", "AES/CTR/NoPadding");
}
},
- arcfour128(ARCFOUR128.Factory.NAME, ARCFOUR128.class) {
+ arcfour128(Constants.ARCFOUR128) {
@Override
- public NamedFactory<Cipher> create() {
- return new ARCFOUR128.Factory();
+ public Cipher create() {
+ return new BaseRC4Cipher(8, 16);
}
},
- arcfour256(ARCFOUR256.Factory.NAME, ARCFOUR256.class) {
+ arcfour256(Constants.ARCFOUR256) {
@Override
- public NamedFactory<Cipher> create() {
- return new ARCFOUR256.Factory();
+ public Cipher create() {
+ return new BaseRC4Cipher(8, 32);
}
},
- blowfishcbc(BlowfishCBC.Factory.NAME, BlowfishCBC.class) {
+ blowfishcbc(Constants.BLOWFISH_CBC) {
@Override
- public NamedFactory<Cipher> create() {
- return new BlowfishCBC.Factory();
+ public Cipher create() {
+ return new BaseCipher(8, 16, "Blowfish", "Blowfish/CBC/NoPadding");
}
},
- tripledescbc(TripleDESCBC.Factory.NAME, TripleDESCBC.class) {
+ tripledescbc(Constants.DES_CBC) {
@Override
- public NamedFactory<Cipher> create() {
- return new TripleDESCBC.Factory();
+ public Cipher create() {
+ return new BaseCipher(8, 24, "DESede", "DESede/CBC/NoPadding");
}
};
private final String factoryName;
- private Class<? extends Cipher> cipherType;
@Override
public final String getName() {
return factoryName;
}
- public final Class<? extends Cipher> getCipherType() {
- return cipherType;
- }
-
- BuiltinCiphers(String facName, Class<? extends Cipher> cipherClass) {
+ BuiltinCiphers(String facName) {
factoryName = facName;
- cipherType = cipherClass;
}
private final AtomicReference<Boolean> _supported = new AtomicReference<>(null);
@@ -199,36 +193,17 @@ public enum BuiltinCiphers implements NamedFactory<NamedFactory<Cipher>> {
return null;
}
- /**
- * @param c The {@link Cipher} instance - ignored if {@code null}
- * @return The matching {@link BuiltinCiphers} - {@code null} if no match
- * @see #fromCipherType(Class)
- */
- public static BuiltinCiphers fromCipher(Cipher c) {
- if (c == null) {
- return null;
- } else {
- return fromCipherType(c.getClass());
- }
- }
-
- /**
- * @param type The cipher type - ignored if {@code null} or not a
- * {@link Cipher} derived class
- * @return The matching {@link BuiltinCiphers} - {@code null} if no match
- */
- public static BuiltinCiphers fromCipherType(Class<?> type) {
- if ((type == null) || (!Cipher.class.isAssignableFrom(type))) {
- return null;
- }
-
- for (BuiltinCiphers c : VALUES) {
- Class<?> t = c.getCipherType();
- if (t.isAssignableFrom(type)) {
- return c;
- }
- }
-
- return null;
+ private static class Constants {
+ public static final String NONE = "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 DES_CBC = "3des-cbc";
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
index 95c82d9..3484d93 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
@@ -31,25 +31,6 @@ import org.apache.sshd.common.NamedFactory;
*/
public class CipherNone implements Cipher {
- /**
- * Named factory for the no-op Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "none";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new CipherNone();
- }
- }
-
public int getIVSize() {
return 8;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/main/java/org/apache/sshd/common/cipher/TripleDESCBC.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/TripleDESCBC.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/TripleDESCBC.java
deleted file mode 100644
index 5cdae9a..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/TripleDESCBC.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.cipher;
-
-import org.apache.sshd.common.Cipher;
-import org.apache.sshd.common.NamedFactory;
-
-/**
- * TripleDESCBC Cipher
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class TripleDESCBC extends BaseCipher {
-
- /**
- * Named factory for TripleDESCBC Cipher
- */
- public static class Factory implements NamedFactory<Cipher> {
- public static final String NAME = "3des-cbc";
-
- public Factory() {
- super();
- }
-
- public String getName() {
- return NAME;
- }
-
- public Cipher create() {
- return new TripleDESCBC();
- }
- }
-
- public TripleDESCBC() {
- super(8, 24, "DESede", "DESede/CBC/NoPadding");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java b/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
index af53004..9f9fa74 100644
--- a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
@@ -26,11 +26,7 @@ import com.jcraft.jsch.JSch;
import org.apache.sshd.common.Cipher;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Random;
-import org.apache.sshd.common.cipher.AES128CBC;
-import org.apache.sshd.common.cipher.AES192CBC;
-import org.apache.sshd.common.cipher.AES256CBC;
-import org.apache.sshd.common.cipher.BlowfishCBC;
-import org.apache.sshd.common.cipher.TripleDESCBC;
+import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.random.BouncyCastleRandom;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.util.BaseTest;
@@ -56,14 +52,14 @@ public class CipherTest extends BaseTest {
@Test
public void testAES128CBC() throws Exception {
- setUp(new AES128CBC.Factory());
+ setUp(BuiltinCiphers.aes128cbc);
runTest();
}
@Test
public void testAES192CBC() throws Exception {
if (SecurityUtils.isBouncyCastleRegistered() && checkCipher(com.jcraft.jsch.jce.AES192CBC.class.getName())) {
- setUp(new AES192CBC.Factory());
+ setUp(BuiltinCiphers.aes192cbc);
runTest();
}
}
@@ -71,29 +67,29 @@ public class CipherTest extends BaseTest {
@Test
public void testAES256CBC() throws Exception {
if (SecurityUtils.isBouncyCastleRegistered() && checkCipher(com.jcraft.jsch.jce.AES256CBC.class.getName())) {
- setUp(new AES256CBC.Factory());
+ setUp(BuiltinCiphers.aes256cbc);
runTest();
}
}
@Test
public void testBlowfishCBC() throws Exception {
- setUp(new BlowfishCBC.Factory());
+ setUp(BuiltinCiphers.blowfishcbc);
runTest();
}
@Test
public void testTripleDESCBC() throws Exception {
- setUp(new TripleDESCBC.Factory());
+ setUp(BuiltinCiphers.tripledescbc);
runTest();
}
@Test
public void loadTest() throws Exception {
Random random = new BouncyCastleRandom();
- loadTest(new AES128CBC.Factory(), random);
- loadTest(new BlowfishCBC.Factory(), random);
- loadTest(new TripleDESCBC.Factory(), random);
+ loadTest(BuiltinCiphers.aes128cbc, random);
+ loadTest(BuiltinCiphers.blowfishcbc, random);
+ loadTest(BuiltinCiphers.tripledescbc, random);
}
protected void loadTest(NamedFactory<Cipher> factory, Random random) throws Exception {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
index 45881d9..8ae3830 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
@@ -51,6 +51,7 @@ import org.apache.sshd.common.Service;
import org.apache.sshd.common.Session;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
+import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.cipher.CipherNone;
import org.apache.sshd.common.forward.TcpipServerChannel;
import org.apache.sshd.common.future.CloseFuture;
@@ -747,8 +748,8 @@ public class ClientTest extends BaseTest {
@Test
public void testSwitchToNoneCipher() throws Exception {
- sshd.getCipherFactories().add(new CipherNone.Factory());
- client.getCipherFactories().add(new CipherNone.Factory());
+ sshd.getCipherFactories().add(BuiltinCiphers.none);
+ client.getCipherFactories().add(BuiltinCiphers.none);
client.start();
ClientSession session = client.connect("smx", "localhost", port).await().getSession();
session.addPasswordIdentity("smx");
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
index 6489265..86ce8b4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import org.apache.sshd.client.kex.DHGClient;
+import org.apache.sshd.common.Cipher;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.NamedFactory;
@@ -118,7 +119,7 @@ public class LoadTest extends BaseTest {
FactoryManagerUtils.updateProperty(props, FactoryManager.WINDOW_SIZE, 1024 * 8);
client.setKeyExchangeFactories(Arrays.asList(
DHGClient.newFactory(BuiltinDHFactories.dhg1)));
- client.setCipherFactories(Arrays.asList(BuiltinCiphers.blowfishcbc.create()));
+ client.setCipherFactories(Arrays.<NamedFactory<Cipher>>asList(BuiltinCiphers.blowfishcbc));
client.start();
try {
ClientSession session = client.connect("sshd", "localhost", port).await().getSession();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/MacTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/MacTest.java b/sshd-core/src/test/java/org/apache/sshd/MacTest.java
index 54e8d4a..b0d7092 100644
--- a/sshd-core/src/test/java/org/apache/sshd/MacTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/MacTest.java
@@ -27,11 +27,7 @@ import org.apache.sshd.common.Cipher;
import org.apache.sshd.common.Mac;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Random;
-import org.apache.sshd.common.cipher.AES128CBC;
-import org.apache.sshd.common.cipher.AES192CBC;
-import org.apache.sshd.common.cipher.AES256CBC;
-import org.apache.sshd.common.cipher.BlowfishCBC;
-import org.apache.sshd.common.cipher.TripleDESCBC;
+import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.mac.HMACMD5;
import org.apache.sshd.common.mac.HMACMD596;
import org.apache.sshd.common.mac.HMACSHA1;
@@ -39,7 +35,6 @@ import org.apache.sshd.common.mac.HMACSHA196;
import org.apache.sshd.common.mac.HMACSHA256;
import org.apache.sshd.common.mac.HMACSHA512;
import org.apache.sshd.common.random.BouncyCastleRandom;
-import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.util.BaseTest;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
@@ -102,9 +97,9 @@ public class MacTest extends BaseTest {
@Test
public void loadTest() throws Exception {
Random random = new BouncyCastleRandom();
- loadTest(new AES128CBC.Factory(), random);
- loadTest(new BlowfishCBC.Factory(), random);
- loadTest(new TripleDESCBC.Factory(), random);
+ loadTest(BuiltinCiphers.aes128cbc, random);
+ loadTest(BuiltinCiphers.blowfishcbc, random);
+ loadTest(BuiltinCiphers.tripledescbc, random);
}
protected void loadTest(NamedFactory<Cipher> factory, Random random) throws Exception {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java
index 12c3e97..138163e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java
@@ -33,6 +33,6 @@ public class AES192CTRTest extends BaseCipherTest {
public void testEncryptDecrypt() throws Exception {
// for AES 256 bits we need the JCE unlimited strength policy
ensureKeySizeSupported(16, 24, "AES", "AES/CTR/NoPadding");
- testEncryptDecrypt(new AES192CTR.Factory());
+ testEncryptDecrypt(BuiltinCiphers.aes192ctr);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java
index f63b3d8..fd1ab48 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java
@@ -33,6 +33,6 @@ public class AES256CBCTest extends BaseCipherTest {
public void testEncryptDecrypt() throws Exception {
// for AES 256 bits we need the JCE unlimited strength policy
ensureKeySizeSupported(16, 32, "AES", "AES/CBC/NoPadding");
- testEncryptDecrypt(new AES256CBC.Factory());
+ testEncryptDecrypt(BuiltinCiphers.aes256cbc);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java
index 369e67d..d7672bd 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java
@@ -31,6 +31,6 @@ public class ARCFOUR128Test extends BaseCipherTest {
@Test
public void testEncryptDecrypt() throws Exception {
- testEncryptDecrypt(new ARCFOUR128.Factory());
+ testEncryptDecrypt(BuiltinCiphers.arcfour128);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java
index 5d4b862..9026362 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java
@@ -33,6 +33,6 @@ public class ARCFOUR256Test extends BaseCipherTest {
public void testEncryptDecrypt() throws Exception {
// for RC4 256 bits we need the JCE unlimited strength policy
ensureKeySizeSupported(32, "ARCFOUR", "RC4");
- testEncryptDecrypt(new ARCFOUR256.Factory());
+ testEncryptDecrypt(BuiltinCiphers.arcfour256);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/31d4dc5a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java
index f9e2f04..357502b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java
@@ -67,7 +67,7 @@ public class BuiltinCiphersTest extends BaseTest {
continue;
}
- NamedFactory<Cipher> factory=expected.create();
+ NamedFactory<Cipher> factory=expected;
Assert.assertEquals(expected.name() + " - mismatched factory names", expected.getName(), factory.getName());
BuiltinCiphers actual=BuiltinCiphers.fromFactory(factory);
@@ -75,20 +75,20 @@ public class BuiltinCiphersTest extends BaseTest {
}
}
- @Test
- public void testFromCipher() {
- for (BuiltinCiphers expected : BuiltinCiphers.VALUES) {
- if (!expected.isSupported()) {
- System.out.append("Skip unsupported cipher: ").println(expected);
- continue;
- }
-
- NamedFactory<Cipher> factory=expected.create();
- Cipher cipher=factory.create();
- assertObjectInstanceOf(expected.name() + " - mismatched cipher type", expected.getCipherType(), cipher);
-
- BuiltinCiphers actual=BuiltinCiphers.fromCipher(cipher);
- Assert.assertSame(expected.getName() + " - mismatched enum values", expected, actual);
- }
- }
+// @Test
+// public void testFromCipher() {
+// for (BuiltinCiphers expected : BuiltinCiphers.VALUES) {
+// if (!expected.isSupported()) {
+// System.out.append("Skip unsupported cipher: ").println(expected);
+// continue;
+// }
+//
+// NamedFactory<Cipher> factory=expected;
+// Cipher cipher=factory.create();
+// assertObjectInstanceOf(expected.name() + " - mismatched cipher type", expected.getCipherType(), cipher);
+//
+// BuiltinCiphers actual=BuiltinCiphers.fromCipher(cipher);
+// Assert.assertSame(expected.getName() + " - mismatched enum values", expected, actual);
+// }
+// }
}