From c20841ec96a8432d74c111db0a88b7437395b532 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 25 Jan 2020 04:07:50 -0500 Subject: Reject OOB netcrypto sessions. --- dht/src/Network/Tox/Session.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dht/src/Network/Tox/Session.hs b/dht/src/Network/Tox/Session.hs index 457ed1a0..d34dfc7a 100644 --- a/dht/src/Network/Tox/Session.hs +++ b/dht/src/Network/Tox/Session.hs @@ -1,4 +1,5 @@ -- | This module implements the lossless Tox session protocol. +{-# LANGUAGE GADTs #-} {-# LANGUAGE TupleSections #-} module Network.Tox.Session ( SessionParams(..) @@ -21,14 +22,16 @@ import Crypto.Tox import Data.PacketBuffer (PacketInboundEvent (..)) import qualified Data.Tox.DHT.Multi as Multi import Data.Tox.Msg -import DPut import DebugTag +import DPut import Network.Lossless import Network.QueryResponse import Network.SessionTransports import Network.Tox.Crypto.Transport -import Network.Tox.DHT.Transport (Cookie (..), key2id, longTermKey, CookieData (..)) +import Network.Tox.DHT.Transport (Cookie (..), CookieData (..), key2id, + longTermKey) import Network.Tox.Handshake +import Network.Tox.TCP (ViaRelay (..)) -- | Alias for 'SecretKey' to document that it is used as the temporary Tox -- session key corresponding to the 'PublicKey' we sent in the handshake. @@ -127,9 +130,13 @@ plainHandshakeH sp saddr0 skey handshake = do , " : baseNonce=" ++ show (baseNonce hd) ] sent <- spGetSentHandshake sp skey saddr0 (handshakeCookie handshake) (otherCookie hd) - -- TODO: this is always returning sent = Nothing dput XNetCrypto $ " <-- (cached) handshake baseNonce " ++ show (fmap (baseNonce . snd . snd) sent) - forM_ sent $ \(saddr, (hd_skey,hd_sent)) -> do + sent' <- case sent of + Just (Multi.SessionTCP :=> Identity (ViaRelay Nothing _ _),_) -> do + dput XNetCrypto $ "Rejecting OOB netcrypto session because it is incompatible with toxcore." + return Nothing + _ -> return sent + forM_ sent' $ \(saddr, (hd_skey,hd_sent)) -> do let Cookie _ (Identity CookieData{ longTermKey = them }) = handshakeCookie handshake sk <- SessionKeys (spCrypto sp) hd_skey -- cgit v1.2.3