Skip to content

Commit d80b37e

Browse files
internal: send a disconnect when key exchange fails
- DoKexDhInit() sends SSH_MSG_DISCONNECT with KEY_EXCHANGE_FAILED on WS_CRYPTO_FAILED and WS_PUBKEY_REJECTED_E, DoKexDhGexGroup() on WS_CRYPTO_FAILED and WS_DH_SIZE_E. - DoKexDhReply() sends KEY_EXCHANGE_FAILED on WS_CRYPTO_FAILED and HOST_KEY_NOT_VERIFIABLE on WS_PUBKEY_REJECTED_E. - DuplexEndpoint records the reason code of a plaintext outbound disconnect, and InitKexReplyHarnessKex() takes an explicit KEX algorithm. - New mutator modes shorten f and e, write a zero-length e, cut the GEX prime below the requested floor and set the GEX generator to 1; LocateSinglePacketPayload() finds the payload for the single-packet rewriters. - Tests assert the reason code on the wire for each new mode and for host key rejection, and assert no disconnect on a successful handshake. Issue: F-8838
1 parent f494688 commit d80b37e

2 files changed

Lines changed: 438 additions & 15 deletions

File tree

src/internal.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5936,6 +5936,12 @@ static int DoKexDhInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
59365936
ret = SendKexDhReply(ssh);
59375937
}
59385938

5939+
/* RFC 8731 sec. 3: a rejected key exchange input aborts with a
5940+
* disconnect */
5941+
if (ret == WS_CRYPTO_FAILED || ret == WS_PUBKEY_REJECTED_E) {
5942+
(void)SendDisconnect(ssh, WOLFSSH_DISCONNECT_KEY_EXCHANGE_FAILED);
5943+
}
5944+
59395945
return ret;
59405946
}
59415947

@@ -7619,6 +7625,15 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
76197625

76207626
if (sigKeyBlock_ptr)
76217627
WFREE(sigKeyBlock_ptr, ssh->ctx->heap, DYNTYPE_PRIVKEY);
7628+
/* RFC 4253 11.1: WS_PUBKEY_REJECTED_E here is only the host key check,
7629+
* which is server authentication, so it gets its own reason. */
7630+
if (ret == WS_CRYPTO_FAILED) {
7631+
(void)SendDisconnect(ssh, WOLFSSH_DISCONNECT_KEY_EXCHANGE_FAILED);
7632+
}
7633+
else if (ret == WS_PUBKEY_REJECTED_E) {
7634+
(void)SendDisconnect(ssh,
7635+
WOLFSSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
7636+
}
76227637
WLOG(WS_LOG_DEBUG, "Leaving DoKexDhReply(), ret = %d", ret);
76237638
return ret;
76247639
}
@@ -8019,6 +8034,12 @@ static int DoKexDhGexGroup(WOLFSSH* ssh,
80198034
ret = SendKexDhInit(ssh);
80208035
}
80218036

8037+
/* RFC 4419 sec. 3: a group outside the requested range fails the key
8038+
* exchange */
8039+
if (ret == WS_CRYPTO_FAILED || ret == WS_DH_SIZE_E) {
8040+
(void)SendDisconnect(ssh, WOLFSSH_DISCONNECT_KEY_EXCHANGE_FAILED);
8041+
}
8042+
80228043
return ret;
80238044
}
80248045

0 commit comments

Comments
 (0)