Skip to content

Commit 677089a

Browse files
committed
Fix the display of MACs when AEAD is selected
This is mostly a cosmetic issue, but it is annoying me in ConnectBot.
1 parent c5e1d9d commit 677089a

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

src/main/java/com/trilead/ssh2/transport/KexManager.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,22 @@ private NegotiatedParameters mergeKexParameters(KexParameters client, KexParamet
277277
log.log(20, "enc_algo_client_to_server=" + np.enc_algo_client_to_server);
278278
log.log(20, "enc_algo_server_to_client=" + np.enc_algo_server_to_client);
279279

280-
np.mac_algo_client_to_server = getFirstMatch(client.mac_algorithms_client_to_server,
281-
server.mac_algorithms_client_to_server);
282-
np.mac_algo_server_to_client = getFirstMatch(client.mac_algorithms_server_to_client,
283-
server.mac_algorithms_server_to_client);
280+
boolean c2s_is_aead = BlockCipherFactory.isAead(np.enc_algo_client_to_server);
281+
boolean s2c_is_aead = BlockCipherFactory.isAead(np.enc_algo_server_to_client);
282+
283+
if (c2s_is_aead) {
284+
np.mac_algo_client_to_server = null;
285+
} else {
286+
np.mac_algo_client_to_server = getFirstMatch(client.mac_algorithms_client_to_server,
287+
server.mac_algorithms_client_to_server);
288+
}
289+
290+
if (s2c_is_aead) {
291+
np.mac_algo_server_to_client = null;
292+
} else {
293+
np.mac_algo_server_to_client = getFirstMatch(client.mac_algorithms_server_to_client,
294+
server.mac_algorithms_server_to_client);
295+
}
284296

285297
log.log(20, "mac_algo_client_to_server=" + np.mac_algo_client_to_server);
286298
log.log(20, "mac_algo_server_to_client=" + np.mac_algo_server_to_client);

src/test/java/com/trilead/ssh2/AsyncSSHCompatibilityTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ public void canConnectWithCipherAes256Gcm() throws Exception {
201201
}
202202

203203
private void setMac(Connection c, String mac) {
204+
// This is needed because AEAD selection would result in null MAC.
205+
setCiphers(c, "aes128-ctr");
206+
204207
c.setClient2ServerMACs(new String[] { mac });
205208
c.setServer2ClientMACs(new String[] { mac });
206209
}

src/test/java/com/trilead/ssh2/DropbearCompatibilityTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ public void canConnectWithCipherChacha20Poly1305() throws Exception {
249249
}
250250

251251
private void setMac(Connection c, String mac) {
252+
// This is needed because AEAD selection would result in null MAC.
253+
setCiphers(c, "aes128-ctr");
254+
252255
c.setClient2ServerMACs(new String[] { mac });
253256
c.setServer2ClientMACs(new String[] { mac });
254257
}

src/test/java/com/trilead/ssh2/OpenSSHCompatibilityTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private ConnectionInfo connectToServerWithOptions(@NotNull String options) throw
8080

8181
private void assertCanConnectToServerThatHasKeyType(@NotNull String keyPath, String keyType) throws IOException {
8282
ConnectionInfo info = connectToServerWithOptions("-h " + keyPath);
83-
assertThat(keyType, is(info.serverHostKeyAlgorithm));
83+
assertThat(info.serverHostKeyAlgorithm, is(keyType));
8484
}
8585

8686
private void canConnectWithPubkey(String keyFilename) throws Exception {
@@ -159,7 +159,7 @@ public void connectToEd25519Host() throws Exception {
159159

160160
private void assertCanConnectToServerWithKex(@NotNull String kexType) throws IOException {
161161
ConnectionInfo info = connectToServerWithOptions("-oKexAlgorithms=" + kexType);
162-
assertThat(kexType, is(info.keyExchangeAlgorithm));
162+
assertThat(info.keyExchangeAlgorithm, is(kexType));
163163
}
164164

165165
@Test
@@ -230,8 +230,8 @@ public void canConnectWithKexMlKem768X25519() throws Exception {
230230

231231
private void assertCanConnectToServerWithCipher(@NotNull String ciphers) throws IOException {
232232
ConnectionInfo info = connectToServerWithOptions("-oCiphers=" + ciphers);
233-
assertThat(ciphers, is(info.clientToServerCryptoAlgorithm));
234-
assertThat(ciphers, is(info.serverToClientCryptoAlgorithm));
233+
assertThat(info.clientToServerCryptoAlgorithm, is(ciphers));
234+
assertThat(info.serverToClientCryptoAlgorithm, is(ciphers));
235235
}
236236

237237
@Test
@@ -275,9 +275,9 @@ public void canConnectWithCipherChaCha20Poly1305() throws Exception {
275275
}
276276

277277
private void assertCanConnectToServerWithMac(@NotNull String macs) throws IOException {
278-
ConnectionInfo info = connectToServerWithOptions("-oMACs=" + macs);
279-
assertThat(macs, is(info.clientToServerMACAlgorithm));
280-
assertThat(macs, is(info.serverToClientMACAlgorithm));
278+
ConnectionInfo info = connectToServerWithOptions("-oCiphers=aes128-ctr -oMACs=" + macs);
279+
assertThat(info.clientToServerMACAlgorithm, is(macs));
280+
assertThat(info.serverToClientMACAlgorithm, is(macs));
281281
}
282282

283283
@Test
@@ -324,15 +324,15 @@ public void canConnectWithCompression() throws Exception {
324324
}
325325

326326
ConnectionInfo info = c.getConnectionInfo();
327-
assertThat("zlib@openssh.com", is(info.clientToServerCompressionAlgorithm));
328-
assertThat("zlib@openssh.com", is(info.serverToClientCompressionAlgorithm));
327+
assertThat(info.clientToServerCompressionAlgorithm, is("zlib@openssh.com"));
328+
assertThat(info.serverToClientCompressionAlgorithm, is("zlib@openssh.com"));
329329
}
330330
}
331331
}
332332

333333
private void canConnectWithHostKeyAlgorithm(String keyPath, String hostKeyAlgorithm) throws Exception {
334334
ConnectionInfo info = connectToServerWithOptions("-h " + keyPath + " -oHostKeyAlgorithms=" + hostKeyAlgorithm);
335-
assertThat(hostKeyAlgorithm, is(info.serverHostKeyAlgorithm));
335+
assertThat(info.serverHostKeyAlgorithm, is(hostKeyAlgorithm));
336336
}
337337

338338
@Test

0 commit comments

Comments
 (0)