Skip to content

Commit c5792fe

Browse files
committed
Added Kex integration test
1 parent 02cfeb9 commit c5792fe

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

README.adoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ key exchange::
7373
`diffie-hellman-group14-sha256`, `diffie-hellman-group15-sha512`, `diffie-hellman-group16-sha512`, `diffie-hellman-group17-sha512`, `diffie-hellman-group18-sha512`
7474
`diffie-hellman-group-exchange-sha1`, `diffie-hellman-group-exchange-sha256`,
7575
`ecdh-sha2-nistp256`, `ecdh-sha2-nistp384`, `ecdh-sha2-nistp521`, `curve25519-sha256@libssh.org`
76+
7677
SSHJ also supports the following extended (non official) key exchange algoriths:
7778
`diffie-hellman-group14-sha256@ssh.com`, `diffie-hellman-group15-sha256`, `diffie-hellman-group15-sha256@ssh.com`, `diffie-hellman-group15-sha384@ssh.com`,
7879
`diffie-hellman-group16-sha256`, `diffie-hellman-group16-sha384@ssh.com`, `diffie-hellman-group16-sha512@ssh.com`, `diffie-hellman-group18-sha512@ssh.com`
@@ -81,7 +82,7 @@ signatures::
8182
`ssh-rsa`, `ssh-dss`, `ecdsa-sha2-nistp256`, `ecdsa-sha2-nistp384`, `ecdsa-sha2-nistp521`, `ssh-ed25519`
8283

8384
mac::
84-
`hmac-md5`, `hmac-md5-96`, `hmac-sha1`, `hmac-sha1-96`, `hmac-sha2-256`, `hmac-sha2-512`, `hmac-ripemd160`
85+
`hmac-md5`, `hmac-md5-96`, `hmac-sha1`, `hmac-sha1-96`, `hmac-sha2-256`, `hmac-sha2-512`, `hmac-ripemd160`, `hmac-ripemd160@openssh.com`
8586

8687
compression::
8788
`zlib` and `zlib@openssh.com` (delayed zlib)

src/itest/docker-image/test-container/sshd_config

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ Subsystem sftp /usr/lib/ssh/sftp-server
128128
# PermitTTY no
129129
# ForceCommand cvs server
130130

131-
131+
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
132132
macs umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.hierynomus.sshj.transport.kex
2+
3+
import com.hierynomus.sshj.IntegrationBaseSpec
4+
import com.hierynomus.sshj.transport.mac.Macs
5+
import net.schmizz.sshj.DefaultConfig
6+
import net.schmizz.sshj.transport.kex.Curve25519DH
7+
import net.schmizz.sshj.transport.kex.Curve25519SHA256
8+
import net.schmizz.sshj.transport.kex.DH
9+
import net.schmizz.sshj.transport.kex.DHGexSHA1
10+
import net.schmizz.sshj.transport.kex.DHGexSHA256
11+
import net.schmizz.sshj.transport.kex.ECDH
12+
import net.schmizz.sshj.transport.kex.ECDHNistP
13+
import spock.lang.Unroll
14+
15+
class KexSpec extends IntegrationBaseSpec {
16+
17+
@Unroll
18+
def "should correctly connect with #kex Key Exchange"() {
19+
given:
20+
def cfg = new DefaultConfig()
21+
cfg.setKeyExchangeFactories(kexFactory)
22+
def client = getConnectedClient(cfg)
23+
24+
when:
25+
client.authPublickey(USERNAME, KEYFILE)
26+
27+
then:
28+
client.authenticated
29+
30+
where:
31+
kexFactory << [DHGroups.Group1SHA1(),
32+
DHGroups.Group14SHA1(),
33+
DHGroups.Group14SHA256(),
34+
DHGroups.Group16SHA512(),
35+
DHGroups.Group18SHA512(),
36+
new DHGexSHA1.Factory(),
37+
new DHGexSHA256.Factory(),
38+
new Curve25519SHA256.Factory(),
39+
new Curve25519SHA256.FactoryLibSsh(),
40+
new ECDHNistP.Factory256(),
41+
new ECDHNistP.Factory384(),
42+
new ECDHNistP.Factory521()]
43+
kex = kexFactory.name
44+
}
45+
46+
}

src/main/java/net/schmizz/sshj/transport/kex/Curve25519SHA256.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
public class Curve25519SHA256 extends AbstractDHG {
2323
/** Named factory for Curve25519SHA256 key exchange */
24-
public static class Factory
24+
public static class FactoryLibSsh
2525
implements net.schmizz.sshj.common.Factory.Named<KeyExchange> {
2626

2727
@Override
@@ -35,6 +35,21 @@ public String getName() {
3535
}
3636
}
3737

38+
/** Named factory for Curve25519SHA256 key exchange */
39+
public static class Factory
40+
implements net.schmizz.sshj.common.Factory.Named<KeyExchange> {
41+
42+
@Override
43+
public KeyExchange create() {
44+
return new Curve25519SHA256();
45+
}
46+
47+
@Override
48+
public String getName() {
49+
return "curve25519-sha256";
50+
}
51+
}
52+
3853
public Curve25519SHA256() {
3954
super(new Curve25519DH(), new SHA256());
4055
}

0 commit comments

Comments
 (0)