-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the "[email protected]" KEX method
This uses a post-quantum key encapsulation method (KEM) to make key exchange future-proof against quantum attacks. It is to be preferred over curve25519-sha256 "when the extra communication size and computational requirements are acceptable."[1] (curve25519-sha256 exchanged 32 bytes where sntrup761x25519-sha512 exchanges 1190 or 1071 bytes.) This KEX method changes the encoding of the key from 'mpint' to 'string'. To make the handling of the K value more uniform, change it to 'string' everywhere, and convert mpints with the high bit set explicitly by prepending a zero byte. Separate the digest from MontgomeryCurve; handle combining curves and hashes (and KEMs) in the BuiltinDHFactories instead. In the BaseBuilder, add "[email protected]" as first (i.e., preferred) KEX algorithm. [1] https://www.ietf.org/archive/id/draft-josefsson-ntruprime-ssh-02.html
- Loading branch information
Showing
16 changed files
with
466 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,13 @@ | |
|
||
## New Features | ||
|
||
* The key exchange method [email protected] is now available if the Bouncy Castle library is available. | ||
|
||
This uses a post-quantum key encapsulation method (KEM) to make key exchange future-proof against quantum attacks. | ||
More information can be found in IETF Memo [Secure Shell (SSH) Key Exchange Method Using Hybrid Streamlined | ||
NTRU Prime sntrup761 and X25519 with SHA-512: sntrup761x25519-sha512](https://www.ietf.org/archive/id/draft-josefsson-ntruprime-ssh-02.html). | ||
|
||
|
||
## Behavioral changes and enhancements | ||
|
||
* [GH-468](https://github.com/apache/mina-sshd/issues/468) SFTP: validate length of data received: must not be more than requested | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
above mentioned hooks for [RFC 8308](https://tools.ietf.org/html/rfc8308). | ||
* [RFC 8731 - Secure Shell (SSH) Key Exchange Method Using Curve25519 and Curve448](https://tools.ietf.org/html/rfc8731) | ||
* [Key Exchange (KEX) Method Updates and Recommendations for Secure Shell](https://tools.ietf.org/html/draft-ietf-curdle-ssh-kex-sha2-03) | ||
* [Secure Shell (SSH) Key Exchange Method Using Hybrid Streamlined NTRU Prime sntrup761 and X25519 with SHA-512: sntrup761x25519-sha512](https://www.ietf.org/archive/id/draft-josefsson-ntruprime-ssh-02.html) | ||
|
||
### OpenSSH | ||
|
||
|
@@ -95,8 +96,10 @@ [email protected], [email protected], [email protected], 3 | |
|
||
* diffie-hellman-group1-sha1, diffie-hellman-group-exchange-sha256, diffie-hellman-group14-sha1, diffie-hellman-group14-sha256 | ||
, diffie-hellman-group15-sha512, diffie-hellman-group16-sha512, diffie-hellman-group17-sha512, diffie-hellman-group18-sha512 | ||
, ecdh-sha2-nistp256, ecdh-sha2-nistp384, ecdh-sha2-nistp521, curve25519-sha256, [email protected], curve448-sha512 | ||
, ecdh-sha2-nistp256, ecdh-sha2-nistp384, ecdh-sha2-nistp521, curve25519-sha256, [email protected], curve448-sha512, | ||
[email protected] | ||
* On Java versions before Java 11, [Bouncy Castle](./dependencies.md#bouncy-castle) is required for curve25519-sha256, [email protected], or curve448-sha512. | ||
* [Bouncy Castle](./dependencies.md#bouncy-castle) is required for [email protected]. | ||
|
||
### Compressions | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import org.apache.sshd.common.cipher.ECCurves; | ||
import org.apache.sshd.common.config.NamedResourceListParseResult; | ||
import org.apache.sshd.common.digest.BuiltinDigests; | ||
import org.apache.sshd.common.digest.Digest; | ||
import org.apache.sshd.common.util.GenericUtils; | ||
import org.apache.sshd.common.util.ValidateUtils; | ||
import org.apache.sshd.common.util.security.SecurityUtils; | ||
|
@@ -252,12 +253,19 @@ public XDH create(Object... params) throws Exception { | |
if (!GenericUtils.isEmpty(params)) { | ||
throw new IllegalArgumentException("No accepted parameters for " + getName()); | ||
} | ||
return new XDH(MontgomeryCurve.x25519); | ||
return new XDH(MontgomeryCurve.x25519) { | ||
|
||
@Override | ||
public Digest getHash() throws Exception { | ||
return BuiltinDigests.sha256.create(); | ||
} | ||
|
||
}; | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return MontgomeryCurve.x25519.isSupported(); | ||
return MontgomeryCurve.x25519.isSupported() && BuiltinDigests.sha256.isSupported(); | ||
} | ||
}, | ||
curve25519_libssh(Constants.CURVE25519_SHA256_LIBSSH) { | ||
|
@@ -266,12 +274,19 @@ public XDH create(Object... params) throws Exception { | |
if (!GenericUtils.isEmpty(params)) { | ||
throw new IllegalArgumentException("No accepted parameters for " + getName()); | ||
} | ||
return new XDH(MontgomeryCurve.x25519); | ||
return new XDH(MontgomeryCurve.x25519) { | ||
|
||
@Override | ||
public Digest getHash() throws Exception { | ||
return BuiltinDigests.sha256.create(); | ||
} | ||
|
||
}; | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return MontgomeryCurve.x25519.isSupported(); | ||
return MontgomeryCurve.x25519.isSupported() && BuiltinDigests.sha256.isSupported(); | ||
} | ||
}, | ||
/** | ||
|
@@ -283,12 +298,48 @@ public XDH create(Object... params) throws Exception { | |
if (!GenericUtils.isEmpty(params)) { | ||
throw new IllegalArgumentException("No accepted parameters for " + getName()); | ||
} | ||
return new XDH(MontgomeryCurve.x448); | ||
return new XDH(MontgomeryCurve.x448) { | ||
|
||
@Override | ||
public Digest getHash() throws Exception { | ||
return BuiltinDigests.sha512.create(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return MontgomeryCurve.x448.isSupported() && BuiltinDigests.sha512.isSupported(); | ||
} | ||
}, | ||
/** | ||
* @see <a href= | ||
* "https://www.ietf.org/archive/id/draft-josefsson-ntruprime-ssh-02.html">draft-josefsson-ntruprime-ssh-02.html</a> | ||
*/ | ||
sntrup761x25519(Constants.SNTRUP761_25519_SHA512) { | ||
@Override | ||
public XDH create(Object... params) throws Exception { | ||
if (!GenericUtils.isEmpty(params)) { | ||
throw new IllegalArgumentException("No accepted parameters for " + getName()); | ||
} | ||
return new XDH(MontgomeryCurve.x25519) { | ||
|
||
@Override | ||
public KeyEncapsulationMethod getKeyEncapsulation() { | ||
return BuiltinKEM.sntrup761; | ||
} | ||
|
||
@Override | ||
public Digest getHash() throws Exception { | ||
return BuiltinDigests.sha512.create(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return MontgomeryCurve.x448.isSupported(); | ||
return MontgomeryCurve.x25519.isSupported() && BuiltinDigests.sha512.isSupported() | ||
&& BuiltinKEM.sntrup761.isSupported(); | ||
} | ||
}; | ||
|
||
|
@@ -468,6 +519,7 @@ public static final class Constants { | |
public static final String CURVE25519_SHA256 = "curve25519-sha256"; | ||
public static final String CURVE25519_SHA256_LIBSSH = "[email protected]"; | ||
public static final String CURVE448_SHA512 = "curve448-sha512"; | ||
public static final String SNTRUP761_25519_SHA512 = "[email protected]"; | ||
|
||
private Constants() { | ||
throw new UnsupportedOperationException("No instance allowed"); | ||
|
59 changes: 59 additions & 0 deletions
59
sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinKEM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.kex; | ||
|
||
import org.apache.sshd.common.NamedResource; | ||
import org.apache.sshd.common.OptionalFeature; | ||
|
||
/** | ||
* All built in key encapsulation methods (KEM). | ||
*/ | ||
public enum BuiltinKEM implements KeyEncapsulationMethod, NamedResource, OptionalFeature { | ||
|
||
sntrup761("sntrup761") { | ||
|
||
@Override | ||
public Client getClient() { | ||
return new SNTRUP761.Client(); | ||
} | ||
|
||
@Override | ||
public Server getServer() { | ||
return new SNTRUP761.Server(); | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return SNTRUP761.isSupported(); | ||
} | ||
|
||
}; | ||
|
||
private String name; | ||
|
||
BuiltinKEM(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
} |
Oops, something went wrong.