Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/com/trilead/ssh2/transport/KexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,15 @@ public synchronized void handleMessage(byte[] msg, int msglen) throws IOExceptio
throw new IllegalStateException("Unkown KEX method! (" + kxs.np.kex_algo + ")");
}

/**
* Returns whether strict key exchange has been negotiated for the current exchange.
*
* @return {@code true} if strict key exchange has been negotiated, or {@code false}
* if negotiation has not completed or strict key exchange is not enabled
*/
public boolean isStrictKex() {
return kxs.np.isStrictKex;
KexState currentKex = kxs;
NegotiatedParameters negotiatedParameters = currentKex == null ? null : currentKex.np;
return negotiatedParameters != null && negotiatedParameters.isStrictKex;
}
Comment thread
kruton marked this conversation as resolved.
}
8 changes: 8 additions & 0 deletions src/test/java/com/trilead/ssh2/transport/KexManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.security.SecureRandom;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -76,6 +77,13 @@ public void twoKEXCalls_OneOutputPacket() throws Exception {
verify(tm, times(1)).sendKexMessage(any());
}

@Test
public void strictKexBeforeNegotiation_ReturnsFalse() throws Exception {
kexManager.initiateKEX(new CryptoWishList(), new DHGexParameters());

assertFalse(kexManager.isStrictKex());
}

@Test
public void handlePacket_BeforeKex_NotKexInit_ThrowsException() throws Exception {
assertThrows(IOException.class, () -> {
Expand Down
Loading