Skip to content

Commit 7a030b2

Browse files
committed
Merge upstream master branch
2 parents cfe79b5 + 3c2dc23 commit 7a030b2

File tree

19 files changed

+656
-106
lines changed

19 files changed

+656
-106
lines changed

.travis.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1+
sudo: required
12
language: java
23
jdk:
34
- oraclejdk9
45
- oraclejdk8
5-
- openjdk7
6+
addons:
7+
apt:
8+
packages:
9+
- oracle-java8-installer
10+
services:
11+
- docker
612
cache:
713
directories:
814
- "$HOME/.gradle/caches"
915
- "$HOME/.gradle/wrapper"
1016
before_cache:
1117
- find $HOME/.gradle -name "*.lock" -exec rm {} \;
1218
- rm -rf $HOME/.gradle/caches/[1-9]*
13-
install:
14-
- |
15-
if [ -d "${JAVA_HOME}"/jre/lib/ext ]; then \
16-
sudo wget "https://bouncycastle.org/download/bcprov-ext-jdk15on-158.jar" -O "${JAVA_HOME}"/jre/lib/ext/bcprov-ext-jdk15on-158.jar && \
17-
sudo perl -pi.bak -e 's/^(security\.provider\.)([0-9]+)/$1.($2+1)/ge' /etc/java-7-openjdk/security/java.security && \
18-
echo "security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider" | sudo tee -a /etc/java-7-openjdk/security/java.security
19-
fi
2019
after_success:
2120
- "./gradlew bintrayUpload artifactoryPublish"
2221
env:

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,40 @@ but has had several features added to it since then.
88
This library retains its original [3-Clause BSD license](
99
https://opensource.org/licenses/BSD-3-Clause).
1010

11+
##### Encryption:
12+
* aes256-ctr ([RFC 4344](https://tools.ietf.org/html/rfc4344#section-4))
13+
* aes128-ctr ([RFC 4344](https://tools.ietf.org/html/rfc4344#section-4))
14+
* aes256-cbc ([RFC 4253](https://tools.ietf.org/html/rfc4253#section-6.3))
15+
* aes128-cbc ([RFC 4253](https://tools.ietf.org/html/rfc4253#section-6.3))
16+
* 3des-ctr ([RFC 4344](https://tools.ietf.org/html/rfc4344#section-4))
17+
* 3des-cbc ([RFC 4253](https://tools.ietf.org/html/rfc4253#section-6.3))
18+
19+
##### MACs:
20+
* hmac-sha2-512-etm@openssh.com ([OpenSSH PROTOCOL](
21+
https://github.com/openssh/openssh-portable/blob/e1b26ce504662a5d5b991091228984ccfd25f280/PROTOCOL#L54))
22+
* hmac-sha2-256-etm@openssh.com ([OpenSSH PROTOCOL](
23+
https://github.com/openssh/openssh-portable/blob/e1b26ce504662a5d5b991091228984ccfd25f280/PROTOCOL#L54))
24+
* hmac-sha1-etm@openssh.com ([OpenSSH PROTOCOL](
25+
https://github.com/openssh/openssh-portable/blob/e1b26ce504662a5d5b991091228984ccfd25f280/PROTOCOL#L54))
26+
* hmac-sha2-512 ([RFC 4868](https://tools.ietf.org/html/rfc4868))
27+
* hmac-sha2-256 ([RFC 4868](https://tools.ietf.org/html/rfc4868))
28+
* hmac-sha1 ([RFC 4253](https://tools.ietf.org/html/rfc4253#section-6.4))
29+
1130
##### Key support:
12-
* ECDSA (RFC 5656)
13-
* Ed25519 (draft-bjh21-ssh-ed25519-02)
31+
* Ed25519 ([draft-ietf-curdle-ssh-ed25519-ed448-03](
32+
https://tools.ietf.org/html/draft-ietf-curdle-ssh-ed25519-ed448-03))
33+
* ECDSA ([RFC 5656](https://tools.ietf.org/html/rfc5656#section-3))
34+
* RSA ([RFC 4253](https://tools.ietf.org/html/rfc4253#section-6.6))
1435

1536
##### Key exchange:
16-
* ECDH (RFC 5656)
17-
* X25519 (curve25519-sha256@libssh.org)
37+
* ecdh-sha2-nistp521 ([RFC 5656](https://tools.ietf.org/html/rfc5656#section-4))
38+
* ecdh-sha2-nistp384 ([RFC 5656](https://tools.ietf.org/html/rfc5656#section-4))
39+
* ecdh-sha2-nistp256 ([RFC 5656](https://tools.ietf.org/html/rfc5656#section-4))
40+
* curve25519-sha256 ([curve25519-sha256](https://tools.ietf.org/id/draft-ietf-curdle-ssh-curves-07.html))
41+
* diffie-hellman-group18-sha512 ([RFC 8268](https://tools.ietf.org/html/rfc8268))
42+
* diffie-hellman-group16-sha512 ([RFC 8268](https://tools.ietf.org/html/rfc8268))
43+
* diffie-hellman-group14-sha256 ([RFC 8268](https://tools.ietf.org/html/rfc8268))
44+
* diffie-hellman-group-exchange-sha256 ([RFC 4419](https://tools.ietf.org/html/rfc4419))
45+
* diffie-hellman-group-exchange-sha1 ([RFC 4419](https://tools.ietf.org/html/rfc4419))
46+
* diffie-hellman-group14-sha1 ([RFC 4253](https://tools.ietf.org/html/rfc4253#section-8.1))
47+
* diffie-hellman-group1-sha1 ([RFC 4253](https://tools.ietf.org/html/rfc4253#section-8.1))

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Sun, 19 Aug 2018 00:26:58 +0200
1+
#Mon, 27 Aug 2018 07:46:46 +0900
22
# Project-wide Gradle settings.
33

44
# IDE (e.g. Android Studio) users:
@@ -18,7 +18,7 @@
1818
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1919
# org.gradle.parallel=true
2020

21-
version=2.2.6
21+
version=2.2.7
2222
group=org.connectbot
2323
description=SSH library used in the ConnectBot app
2424

sshlib/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ dependencies {
2323
testCompile 'junit:junit:4.12'
2424
testCompile 'commons-io:commons-io:2.6'
2525
testCompile 'commons-codec:commons-codec:1.11'
26+
testCompile 'org.testcontainers:testcontainers:1.8.3'
27+
testCompile 'ch.qos.logback:logback-classic:1.2.3'
2628
}
2729

2830
compileJava {

sshlib/src/main/java/com/trilead/ssh2/Connection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @version $Id: Connection.java,v 1.3 2008/04/01 12:38:09 cplattne Exp $
4646
*/
4747

48-
public class Connection
48+
public class Connection implements AutoCloseable
4949
{
5050
/**
5151
* The identifier presented to the SSH-2 server.

sshlib/src/main/java/com/trilead/ssh2/ConnectionInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,16 @@ public class ConnectionInfo
5050
* Number of kex exchanges performed on this connection so far.
5151
*/
5252
public int keyExchangeCounter = 0;
53+
54+
/**
55+
* The currently used compression algorithm for packets from the client to
56+
* the server.
57+
*/
58+
public String clientToServerCompressionAlgorithm;
59+
60+
/**
61+
* The currently used compression algorithm for packets from the server to
62+
* the client.
63+
*/
64+
public String serverToClientCompressionAlgorithm;
5365
}

sshlib/src/main/java/com/trilead/ssh2/Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @author Christian Plattner, plattner@trilead.com
2121
* @version $Id: Session.java,v 1.2 2008/03/03 07:01:36 cplattne Exp $
2222
*/
23-
public class Session
23+
public class Session implements AutoCloseable
2424
{
2525
ChannelManager cm;
2626
Channel cn;

sshlib/src/main/java/com/trilead/ssh2/crypto/dh/Curve25519Exchange.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* Created by Kenny Root on 1/23/16.
1111
*/
1212
public class Curve25519Exchange extends GenericDhExchange {
13-
public static final String NAME = "curve25519-sha256@libssh.org";
13+
public static final String NAME = "curve25519-sha256";
14+
public static final String ALT_NAME = "curve25519-sha256@libssh.org";
1415

1516
private final byte[] clientPublic = new byte[Curve25519.KEY_SIZE];
1617
private final byte[] clientPrivate = new byte[Curve25519.KEY_SIZE];
@@ -33,7 +34,7 @@ public Curve25519Exchange(byte[] secret) {
3334

3435
@Override
3536
public void init(String name) throws IOException {
36-
if (!NAME.equals(name)) {
37+
if (!NAME.equals(name) && !ALT_NAME.equals(name)) {
3738
throw new IOException("Invalid name " + name);
3839
}
3940

sshlib/src/main/java/com/trilead/ssh2/crypto/dh/DhExchange.java

Lines changed: 108 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
*/
44
package com.trilead.ssh2.crypto.dh;
55

6-
import java.io.IOException;
7-
import java.math.BigInteger;
8-
import java.security.InvalidAlgorithmParameterException;
9-
import java.security.InvalidKeyException;
10-
import java.security.KeyFactory;
11-
import java.security.KeyPair;
12-
import java.security.KeyPairGenerator;
13-
import java.security.NoSuchAlgorithmException;
14-
import java.security.spec.InvalidKeySpecException;
15-
166
import javax.crypto.KeyAgreement;
177
import javax.crypto.interfaces.DHPrivateKey;
188
import javax.crypto.interfaces.DHPublicKey;
199
import javax.crypto.spec.DHParameterSpec;
2010
import javax.crypto.spec.DHPublicKeySpec;
11+
import java.io.IOException;
12+
import java.math.BigInteger;
13+
import java.security.*;
14+
import java.security.spec.InvalidKeySpecException;
2115

2216
/**
2317
* @author kenny
@@ -28,28 +22,100 @@ public class DhExchange extends GenericDhExchange {
2822
/* Given by the standard */
2923

3024
private static final BigInteger P1 = new BigInteger(
31-
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
32-
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
33-
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
34-
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
35-
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"
36-
+ "FFFFFFFFFFFFFFFF", 16);
25+
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"+
26+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"+
27+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"+
28+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"+
29+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"+
30+
"FFFFFFFFFFFFFFFF",16);
3731

3832
private static final BigInteger P14 = new BigInteger(
39-
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
40-
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
41-
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
42-
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
43-
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
44-
+ "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
45-
+ "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
46-
+ "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
47-
+ "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
48-
+ "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
49-
+ "15728E5A8AACAA68FFFFFFFFFFFFFFFF", 16);
33+
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
34+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
35+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
36+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
37+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
38+
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
39+
"83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
40+
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
41+
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
42+
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
43+
"15728E5A8AACAA68FFFFFFFFFFFFFFFF", 16);
44+
45+
private static final BigInteger P16 = new BigInteger(
46+
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
47+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
48+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
49+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
50+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
51+
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
52+
"83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
53+
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
54+
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
55+
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
56+
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" +
57+
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" +
58+
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" +
59+
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" +
60+
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" +
61+
"43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" +
62+
"88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" +
63+
"2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" +
64+
"287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" +
65+
"1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" +
66+
"93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" +
67+
"FFFFFFFFFFFFFFFF", 16);
68+
69+
private static final BigInteger P18 = new BigInteger(
70+
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
71+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
72+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
73+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
74+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
75+
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
76+
"83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
77+
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
78+
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
79+
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
80+
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" +
81+
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" +
82+
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" +
83+
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" +
84+
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" +
85+
"43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" +
86+
"88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" +
87+
"2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" +
88+
"287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" +
89+
"1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" +
90+
"93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492" +
91+
"36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BD" +
92+
"F8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831" +
93+
"179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B" +
94+
"DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF" +
95+
"5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6" +
96+
"D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F3" +
97+
"23A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA" +
98+
"CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE328" +
99+
"06A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55C" +
100+
"DA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE" +
101+
"12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E4" +
102+
"38777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300" +
103+
"741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F568" +
104+
"3423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD9" +
105+
"22222E04A4037C0713EB57A81A23F0C73473FC646CEA306B" +
106+
"4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A" +
107+
"062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A36" +
108+
"4597E899A0255DC164F31CC50846851DF9AB48195DED7EA1" +
109+
"B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92" +
110+
"4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E47" +
111+
"9558E4475677E9AA9E3050E2765694DFC81F56E880B96E71" +
112+
"60C980DD98EDD3DFFFFFFFFFFFFFFFFF", 16);
50113

51114
private static final BigInteger G = BigInteger.valueOf(2);
52115

116+
/* Hash algorithm to use */
117+
private String hashAlgo;
118+
53119
/* Client public and private */
54120

55121
private DHPrivateKey clientPrivate;
@@ -62,10 +128,21 @@ public class DhExchange extends GenericDhExchange {
62128
@Override
63129
public void init(String name) throws IOException {
64130
final DHParameterSpec spec;
65-
if ("diffie-hellman-group1-sha1".equals(name)) {
66-
spec = new DHParameterSpec(P1, G);
131+
if ("diffie-hellman-group18-sha512".equals(name)) {
132+
spec = new DHParameterSpec(P18, G);
133+
hashAlgo = "SHA-512";
134+
} else if ("diffie-hellman-group16-sha512".equals(name)) {
135+
spec = new DHParameterSpec(P16, G);
136+
hashAlgo = "SHA-512";
137+
} else if ("diffie-hellman-group14-sha256".equals(name)) {
138+
spec = new DHParameterSpec(P14, G);
139+
hashAlgo = "SHA-256";
67140
} else if ("diffie-hellman-group14-sha1".equals(name)) {
68141
spec = new DHParameterSpec(P14, G);
142+
hashAlgo = "SHA-1";
143+
} else if ("diffie-hellman-group1-sha1".equals(name)) {
144+
spec = new DHParameterSpec(P1, G);
145+
hashAlgo = "SHA-1";
69146
} else {
70147
throw new IllegalArgumentException("Unknown DH group " + name);
71148
}
@@ -116,9 +193,7 @@ public void setF(byte[] f) throws IOException {
116193
ka.doPhase(serverPublic, true);
117194
} catch (NoSuchAlgorithmException e) {
118195
throw new IOException("No DH key agreement method", e);
119-
} catch (InvalidKeyException e) {
120-
throw new IOException("Invalid DH key", e);
121-
} catch (InvalidKeySpecException e) {
196+
} catch (InvalidKeyException | InvalidKeySpecException e) {
122197
throw new IOException("Invalid DH key", e);
123198
}
124199

@@ -127,6 +202,6 @@ public void setF(byte[] f) throws IOException {
127202

128203
@Override
129204
public String getHashAlgo() {
130-
return "SHA1";
205+
return hashAlgo;
131206
}
132207
}

sshlib/src/main/java/com/trilead/ssh2/crypto/dh/GenericDhExchange.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected GenericDhExchange()
2929
}
3030

3131
public static GenericDhExchange getInstance(String algo) {
32-
if (algo.startsWith("curve25519-sha256@libssh.org")) {
32+
if (Curve25519Exchange.NAME.equals(algo) || Curve25519Exchange.ALT_NAME.equals(algo)) {
3333
return new Curve25519Exchange();
3434
}
3535
if (algo.startsWith("ecdh-sha2-")) {

0 commit comments

Comments
 (0)