From 4c00df9463ea4fd70b73c620e439f5c3ee5efa60 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sun, 18 Sep 2016 13:58:15 +0300 Subject: [PATCH] Abort handshake if establishing DH shared secret fails Fixes #27 --- libtransmission/handshake.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index c72869600..e7ff1319f 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -425,7 +425,8 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf) /* compute the secret */ evbuffer_remove (inbuf, yb, KEY_LEN); - tr_cryptoComputeSecret (handshake->crypto, yb); + if (!tr_cryptoComputeSecret (handshake->crypto, yb)) + return tr_handshakeDone (handshake, false); /* now send these: HASH ('req1', S), HASH ('req2', SKEY) xor HASH ('req3', S), * ENCRYPT (VC, crypto_provide, len (PadC), PadC, len (IA)), ENCRYPT (IA) */ @@ -741,7 +742,9 @@ readYa (tr_handshake * handshake, /* read the incoming peer's public key */ evbuffer_remove (inbuf, ya, KEY_LEN); - tr_cryptoComputeSecret (handshake->crypto, ya); + if (!tr_cryptoComputeSecret (handshake->crypto, ya)) + return tr_handshakeDone (handshake, false); + computeRequestHash (handshake, "req1", handshake->myReq1); /* send our public key to the peer */