Skip to content

Commit 33118c0

Browse files
internal: send a disconnect when key exchange fails
- Send SSH_MSG_DISCONNECT with KEY_EXCHANGE_FAILED from DoKexDhInit(), DoKexDhReply() and DoKexDhGexGroup() when the key exchange fails. - Add KEXDH_REPLY f-truncation and KEXDH_INIT e-truncation and e-empty mutator modes to the regression harness. - Record outbound disconnects on the duplex endpoints and assert the reason code in the truncated-key and host-key rejection tests. - Scan only plaintext records for the disconnect, validate minimum packet framing, and bound the reason code against the payload. - Assert no disconnect is seen on a successful handshake. Issue: F-8838
1 parent 326d181 commit 33118c0

2 files changed

Lines changed: 279 additions & 15 deletions

File tree

src/internal.c

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

5711+
/* RFC 4253 7.1: both codes mean the peer's key exchange input was
5712+
* rejected: the e range check or the server key agreement. */
5713+
if (ret == WS_CRYPTO_FAILED || ret == WS_PUBKEY_REJECTED_E) {
5714+
(void)SendDisconnect(ssh, WOLFSSH_DISCONNECT_KEY_EXCHANGE_FAILED);
5715+
}
5716+
57115717
return ret;
57125718
}
57135719

@@ -7391,6 +7397,15 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
73917397

73927398
if (sigKeyBlock_ptr)
73937399
WFREE(sigKeyBlock_ptr, ssh->ctx->heap, DYNTYPE_PRIVKEY);
7400+
/* RFC 4253 11.1: WS_PUBKEY_REJECTED_E here is only the host key check,
7401+
* which is server authentication, so it gets its own reason. */
7402+
if (ret == WS_CRYPTO_FAILED) {
7403+
(void)SendDisconnect(ssh, WOLFSSH_DISCONNECT_KEY_EXCHANGE_FAILED);
7404+
}
7405+
else if (ret == WS_PUBKEY_REJECTED_E) {
7406+
(void)SendDisconnect(ssh,
7407+
WOLFSSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
7408+
}
73947409
WLOG(WS_LOG_DEBUG, "Leaving DoKexDhReply(), ret = %d", ret);
73957410
return ret;
73967411
}
@@ -7791,6 +7806,12 @@ static int DoKexDhGexGroup(WOLFSSH* ssh,
77917806
ret = SendKexDhInit(ssh);
77927807
}
77937808

7809+
/* RFC 4253 7.1: WS_DH_SIZE_E is the GEX modulus range rejection,
7810+
* which only this handler raises. */
7811+
if (ret == WS_CRYPTO_FAILED || ret == WS_DH_SIZE_E) {
7812+
(void)SendDisconnect(ssh, WOLFSSH_DISCONNECT_KEY_EXCHANGE_FAILED);
7813+
}
7814+
77947815
return ret;
77957816
}
77967817

0 commit comments

Comments
 (0)