diff options
author | Joe Crayne <joe@jerkface.net> | 2020-01-25 04:07:50 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-25 19:18:12 -0500 |
commit | c20841ec96a8432d74c111db0a88b7437395b532 (patch) | |
tree | f36934f420817af1dcae5b5783dd74ffe5979fe5 | |
parent | e3ec604c8b918eee0c88866679ed0444a36a2803 (diff) |
Reject OOB netcrypto sessions.
-rw-r--r-- | dht/src/Network/Tox/Session.hs | 15 |
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 #-} |
3 | module Network.Tox.Session | 4 | module Network.Tox.Session |
4 | ( SessionParams(..) | 5 | ( SessionParams(..) |
@@ -21,14 +22,16 @@ import Crypto.Tox | |||
21 | import Data.PacketBuffer (PacketInboundEvent (..)) | 22 | import Data.PacketBuffer (PacketInboundEvent (..)) |
22 | import qualified Data.Tox.DHT.Multi as Multi | 23 | import qualified Data.Tox.DHT.Multi as Multi |
23 | import Data.Tox.Msg | 24 | import Data.Tox.Msg |
24 | import DPut | ||
25 | import DebugTag | 25 | import DebugTag |
26 | import DPut | ||
26 | import Network.Lossless | 27 | import Network.Lossless |
27 | import Network.QueryResponse | 28 | import Network.QueryResponse |
28 | import Network.SessionTransports | 29 | import Network.SessionTransports |
29 | import Network.Tox.Crypto.Transport | 30 | import Network.Tox.Crypto.Transport |
30 | import Network.Tox.DHT.Transport (Cookie (..), key2id, longTermKey, CookieData (..)) | 31 | import Network.Tox.DHT.Transport (Cookie (..), CookieData (..), key2id, |
32 | longTermKey) | ||
31 | import Network.Tox.Handshake | 33 | import Network.Tox.Handshake |
34 | import 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 |