From 330f627516d207a337ce7e5d83e3163af226d6ef Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 31 May 2018 03:33:54 -0400 Subject: Use user-keys (not DHT-key) when encrypting initial handshake. --- src/Network/Tox.hs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 5ad9c041..3bf7b6f1 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs @@ -321,18 +321,17 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do , hpTheirBaseNonce = error "netCrypto: Unreachable! hpTheirBaseNonce" , hpTheirSessionKeyPublic = error "netCrypto: Unreachable! hpTheirSessionKeyPublic" } - n24' <- atomically $ transportNewNonce crypto - dput XNetCrypto ("Handshake Nonce24: " <> show n24') - state <- lookupSharedSecret crypto myseckey theirDhtKey n24' - newBaseNonce <- atomically $ transportNewNonce crypto - mbMyhandshakeData <- newHandShakeData crypto newBaseNonce hp saddr - let encodeHandshake myhandshakeData = let plain = encodePlain myhandshakeData - encrypted = encrypt state plain - in Handshake { handshakeCookie = cookie - , handshakeNonce = n24' - , handshakeData = encrypted - } - let myhandshake = encodeHandshake <$> mbMyhandshakeData + myhandshake <- do + n24' <- atomically $ transportNewNonce crypto + dput XNetCrypto ("Handshake Nonce24: " <> show n24') + newBaseNonce <- atomically $ transportNewNonce crypto + mbMyhandshakeData <- newHandShakeData crypto newBaseNonce hp saddr + forM mbMyhandshakeData $ \hsdata -> do + state <- lookupSharedSecret crypto myseckey theirpubkey n24' + return Handshake { handshakeCookie = cookie + , handshakeNonce = n24' + , handshakeData = encrypt state $ encodePlain hsdata + } case myhandshake of Nothing -> hPutStrLn stderr "netCrypto: failed to create HandshakeData." >> return [] Just handshake -> do -- cgit v1.2.3