[
https://issues.apache.org/jira/browse/SSHD-506?focusedWorklogId=435499&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-435499
]
ASF GitHub Bot logged work on SSHD-506:
---------------------------------------
Author: ASF GitHub Bot
Created on: 20/May/20 15:29
Start Date: 20/May/20 15:29
Worklog Time Spent: 10m
Work Description: lgoldstein commented on a change in pull request #132:
URL: https://github.com/apache/mina-sshd/pull/132#discussion_r428103603
##########
File path:
sshd-common/src/main/java/org/apache/sshd/common/cipher/BaseGCMCipher.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+import org.apache.sshd.common.util.security.SecurityUtils;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.GCMParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+public class BaseGCMCipher extends BaseCipher {
+
+ private Mode mode;
+ private SecretKey secretKey;
+
+ public BaseGCMCipher(
+ final int ivsize, final int kdfSize, final String algorithm, final
int keySize, final String transformation,
+ final int blkSize, final int authSize) {
+ super(ivsize, authSize, kdfSize, algorithm, keySize, transformation,
blkSize);
+ }
+
+ @Override
+ protected byte[] initializeKeyData(final Mode mode, final byte[] key,
final int reqLen) {
+ byte[] keyData = super.initializeKeyData(mode, key, reqLen);
+ secretKey = new SecretKeySpec(keyData, getAlgorithm());
+ return keyData;
+ }
+
+ @Override
+ protected Cipher createCipherInstance(final Mode mode, final byte[] key,
final byte[] iv) throws Exception {
Review comment:
Please remove `final` modifier from parameters
##########
File path:
sshd-common/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
##########
@@ -46,39 +46,48 @@
* @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a>
*/
public enum BuiltinCiphers implements CipherFactory {
- none(Constants.NONE, 0, 0, "None", 0, "None", 0) {
+ none(Constants.NONE, 0, 0, 0, "None", 0, "None", 0) {
@Override
public Cipher create() {
return new CipherNone();
}
},
- aes128cbc(Constants.AES128_CBC, 16, 16, "AES", 128, "AES/CBC/NoPadding",
16),
- aes128ctr(Constants.AES128_CTR, 16, 16, "AES", 128, "AES/CTR/NoPadding",
16),
- aes192cbc(Constants.AES192_CBC, 16, 24, "AES", 192, "AES/CBC/NoPadding",
16),
- aes192ctr(Constants.AES192_CTR, 16, 24, "AES", 192, "AES/CTR/NoPadding",
16),
- aes256cbc(Constants.AES256_CBC, 16, 32, "AES", 256, "AES/CBC/NoPadding",
16),
- aes256ctr(Constants.AES256_CTR, 16, 32, "AES", 256, "AES/CTR/NoPadding",
16),
- arcfour128(Constants.ARCFOUR128, 8, 16, "ARCFOUR", 128, "RC4", 16) {
+ aes128cbc(Constants.AES128_CBC, 16, 0, 16, "AES", 128,
"AES/CBC/NoPadding", 16),
+ aes128ctr(Constants.AES128_CTR, 16, 0, 16, "AES", 128,
"AES/CTR/NoPadding", 16),
+ aes128gcm(Constants.AES128_GCM, 12, 16, 16, "AES", 128,
"AES/GCM/NoPadding", 16) {
+ @Override
+ public Cipher create() {
+ return new BaseGCMCipher(
+ getIVSize(), getKdfSize(), getAlgorithm(), getKeySize(),
getTransformation(), getCipherBlockSize(), getAuthenticationTagSize());
+ }
+ },
+ // TODO: aes256gcm
Review comment:
Also AES192 GCM
##########
File path:
sshd-common/src/main/java/org/apache/sshd/common/cipher/BaseGCMCipher.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+import org.apache.sshd.common.util.security.SecurityUtils;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.GCMParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+public class BaseGCMCipher extends BaseCipher {
+
+ private Mode mode;
+ private SecretKey secretKey;
+
+ public BaseGCMCipher(
+ final int ivsize, final int kdfSize, final String algorithm, final
int keySize, final String transformation,
+ final int blkSize, final int authSize) {
+ super(ivsize, authSize, kdfSize, algorithm, keySize, transformation,
blkSize);
+ }
+
+ @Override
+ protected byte[] initializeKeyData(final Mode mode, final byte[] key,
final int reqLen) {
Review comment:
Please remove `final` modifier from parameters
##########
File path:
sshd-common/src/main/java/org/apache/sshd/common/cipher/BaseGCMCipher.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+import org.apache.sshd.common.util.security.SecurityUtils;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.GCMParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+public class BaseGCMCipher extends BaseCipher {
+
+ private Mode mode;
+ private SecretKey secretKey;
+
+ public BaseGCMCipher(
+ final int ivsize, final int kdfSize, final String algorithm, final
int keySize, final String transformation,
+ final int blkSize, final int authSize) {
+ super(ivsize, authSize, kdfSize, algorithm, keySize, transformation,
blkSize);
+ }
+
+ @Override
+ protected byte[] initializeKeyData(final Mode mode, final byte[] key,
final int reqLen) {
+ byte[] keyData = super.initializeKeyData(mode, key, reqLen);
+ secretKey = new SecretKeySpec(keyData, getAlgorithm());
+ return keyData;
+ }
+
+ @Override
+ protected Cipher createCipherInstance(final Mode mode, final byte[] key,
final byte[] iv) throws Exception {
+ this.mode = mode;
+ Cipher instance = SecurityUtils.getCipher(getTransformation());
+ instance.init(
+ Mode.Encrypt.equals(this.mode) ? Cipher.ENCRYPT_MODE :
Cipher.DECRYPT_MODE,
+ secretKey,
+ new GCMParameterSpec(getAuthenticationTagSize() * Byte.SIZE,
iv));
+ return instance;
+ }
+
+ public void incrementIV() throws Exception {
+ Cipher cipher = getCipherInstance();
+ Buffer iv = new ByteArrayBuffer(cipher.getIV());
+ iv.rpos(Integer.BYTES);
+ long ic = iv.getLong();
+ ic = (ic + 1) & 0x0ffffffffL;
+ iv.wpos(Integer.BYTES);
+ iv.putLong(ic);
+ cipher.init(
+ mode == Mode.Encrypt ? Cipher.ENCRYPT_MODE :
Cipher.DECRYPT_MODE,
+ secretKey,
+ new GCMParameterSpec(getAuthenticationTagSize() * Byte.SIZE,
iv.array()));
+ }
+
+ public void updateAAD(final byte[] additionalAuthenticatedData, final int
aadOffset, final int aadLength) {
Review comment:
Please remove `final` modifier from parameters
##########
File path:
sshd-common/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
##########
@@ -87,10 +96,11 @@ public Cipher create() {
private final boolean supported;
BuiltinCiphers(
- String factoryName, int ivsize, int kdfSize,
Review comment:
Please remove `final` modifier from `authSize`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 435499)
Time Spent: 40m (was: 0.5h)
> Add support for aes128/256-gcm ciphers
> --------------------------------------
>
> Key: SSHD-506
> URL: https://issues.apache.org/jira/browse/SSHD-506
> Project: MINA SSHD
> Issue Type: Improvement
> Reporter: Lyor Goldstein
> Priority: Major
> Time Spent: 40m
> Remaining Estimate: 0h
>
> See:
> * [rfc5647|https://tools.ietf.org/html/rfc5647]
> *
> [draft-igoe-secsh-aes-gcm-01|https://tools.ietf.org/html/draft-igoe-secsh-aes-gcm-01]
> * [OpenSSH v6.2|http://www.openssh.com/txt/release-6.2]
> * [JAVA AES 256 GCM encrypt/decrypt
> example|https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/]
> - especially the usage of {{GCMParameterSpec}} to initialize the cipher
> * [OpenJDK 8 AESCipher.java source
> code|https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/com/sun/crypto/provider/AESCipher.java]
> ** See also
> [CipherCore.java|https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/com/sun/crypto/provider/CipherCore.java],
>
> [FeedbackCipher.java|https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/com/sun/crypto/provider/FeedbackCipher.java],
>
> [GaloisCounterMode.java|https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/com/sun/crypto/provider/GaloisCounterMode.java]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]