summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2020-01-25 04:07:50 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-25 19:18:12 -0500
commitc20841ec96a8432d74c111db0a88b7437395b532 (patch)
treef36934f420817af1dcae5b5783dd74ffe5979fe5
parente3ec604c8b918eee0c88866679ed0444a36a2803 (diff)
Reject OOB netcrypto sessions.
-rw-r--r--dht/src/Network/Tox/Session.hs15
1 files 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 @@
1-- | This module implements the lossless Tox session protocol. 1-- | This module implements the lossless Tox session protocol.
2{-# LANGUAGE GADTs #-}
2{-# LANGUAGE TupleSections #-} 3{-# LANGUAGE TupleSections #-}
3module Network.Tox.Session 4module Network.Tox.Session
4 ( SessionParams(..) 5 ( SessionParams(..)
@@ -21,14 +22,16 @@ import Crypto.Tox
21import Data.PacketBuffer (PacketInboundEvent (..)) 22import Data.PacketBuffer (PacketInboundEvent (..))
22import qualified Data.Tox.DHT.Multi as Multi 23import qualified Data.Tox.DHT.Multi as Multi
23import Data.Tox.Msg 24import Data.Tox.Msg
24import DPut
25import DebugTag 25import DebugTag
26import DPut
26import Network.Lossless 27import Network.Lossless
27import Network.QueryResponse 28import Network.QueryResponse
28import Network.SessionTransports 29import Network.SessionTransports
29import Network.Tox.Crypto.Transport 30import Network.Tox.Crypto.Transport
30import Network.Tox.DHT.Transport (Cookie (..), key2id, longTermKey, CookieData (..)) 31import Network.Tox.DHT.Transport (Cookie (..), CookieData (..), key2id,
32 longTermKey)
31import Network.Tox.Handshake 33import Network.Tox.Handshake
34import Network.Tox.TCP (ViaRelay (..))
32 35
33-- | Alias for 'SecretKey' to document that it is used as the temporary Tox 36-- | Alias for 'SecretKey' to document that it is used as the temporary Tox
34-- session key corresponding to the 'PublicKey' we sent in the handshake. 37-- session key corresponding to the 'PublicKey' we sent in the handshake.
@@ -127,9 +130,13 @@ plainHandshakeH sp saddr0 skey handshake = do
127 , " : baseNonce=" ++ show (baseNonce hd) 130 , " : baseNonce=" ++ show (baseNonce hd)
128 ] 131 ]
129 sent <- spGetSentHandshake sp skey saddr0 (handshakeCookie handshake) (otherCookie hd) 132 sent <- spGetSentHandshake sp skey saddr0 (handshakeCookie handshake) (otherCookie hd)
130 -- TODO: this is always returning sent = Nothing
131 dput XNetCrypto $ " <-- (cached) handshake baseNonce " ++ show (fmap (baseNonce . snd . snd) sent) 133 dput XNetCrypto $ " <-- (cached) handshake baseNonce " ++ show (fmap (baseNonce . snd . snd) sent)
132 forM_ sent $ \(saddr, (hd_skey,hd_sent)) -> do 134 sent' <- case sent of
135 Just (Multi.SessionTCP :=> Identity (ViaRelay Nothing _ _),_) -> do
136 dput XNetCrypto $ "Rejecting OOB netcrypto session because it is incompatible with toxcore."
137 return Nothing
138 _ -> return sent
139 forM_ sent' $ \(saddr, (hd_skey,hd_sent)) -> do
133 let Cookie _ (Identity CookieData{ longTermKey = them }) = handshakeCookie handshake 140 let Cookie _ (Identity CookieData{ longTermKey = them }) = handshakeCookie handshake
134 sk <- SessionKeys (spCrypto sp) 141 sk <- SessionKeys (spCrypto sp)
135 hd_skey 142 hd_skey