summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto/Handlers.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2017-11-01 15:56:03 +0000
committerJames Crayne <jim.crayne@gmail.com>2017-11-01 15:56:03 +0000
commit6880807978615fe52a28a1ca85134e4df68b9ac4 (patch)
treef2cfa3b0aa5a8449cc568e0933da129e548d2105 /src/Network/Tox/Crypto/Handlers.hs
parent850ffe53566bdded7d89009cc6d6a20cb092d2e0 (diff)
fix build
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index e8cdfcdd..b8e99d2d 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -38,6 +38,7 @@ data NetCryptoSession = NCrypto { ncState :: TVar NetCryptoSessionStatus
38 , ncMyPacketNonce :: TVar Nonce24 -- base nonce + packet number 38 , ncMyPacketNonce :: TVar Nonce24 -- base nonce + packet number
39 , ncHandShake :: TVar (Maybe (Handshake Encrypted)) 39 , ncHandShake :: TVar (Maybe (Handshake Encrypted))
40 , ncCookie :: TVar (Maybe Cookie) 40 , ncCookie :: TVar (Maybe Cookie)
41 , ncTheirDHTKey :: PublicKey
41 , ncTheirSessionPublic :: Maybe PublicKey 42 , ncTheirSessionPublic :: Maybe PublicKey
42 , ncSessionSecret :: SecretKey 43 , ncSessionSecret :: SecretKey
43 , ncSockAddr :: SockAddr 44 , ncSockAddr :: SockAddr
@@ -87,7 +88,7 @@ freshCryptoSession sessions
87 , hpMySecretKey = key 88 , hpMySecretKey = key
88 , hpCookieRemotePubkey = remotePublicKey 89 , hpCookieRemotePubkey = remotePublicKey
89 , hpCookieRemoteDhtkey = remoteDhtPublicKey 90 , hpCookieRemoteDhtkey = remoteDhtPublicKey
90 }) -> do 91 }) = do
91 let crypto = transportCrypto sessions 92 let crypto = transportCrypto sessions
92 allsessions = netCryptoSessions sessions 93 allsessions = netCryptoSessions sessions
93 ncState0 <- atomically $ newTVar Accepted 94 ncState0 <- atomically $ newTVar Accepted
@@ -114,6 +115,7 @@ freshCryptoSession sessions
114 , ncMyPacketNonce = ncMyPacketNonce0 115 , ncMyPacketNonce = ncMyPacketNonce0
115 , ncHandShake = ncHandShake0 116 , ncHandShake = ncHandShake0
116 , ncCookie = cookie0 117 , ncCookie = cookie0
118 , ncTheirDHTKey = remoteDhtPublicKey
117 , ncTheirSessionPublic = Just theirSessionKey 119 , ncTheirSessionPublic = Just theirSessionKey
118 , ncSessionSecret = newsession 120 , ncSessionSecret = newsession
119 , ncSockAddr = addr 121 , ncSockAddr = addr
@@ -129,19 +131,18 @@ updateCryptoSession :: NetCryptoSessions -> SockAddr -> HandshakeParams -> NetCr
129updateCryptoSession sessions addr hp session = do 131updateCryptoSession sessions addr hp session = do
130 ncState0 <- atomically $ readTVar (ncState session) 132 ncState0 <- atomically $ readTVar (ncState session)
131 ncTheirBaseNonce0 <- atomically $ readTVar (ncTheirBaseNonce session) 133 ncTheirBaseNonce0 <- atomically $ readTVar (ncTheirBaseNonce session)
132 (Cookie _ _ presentCookieDHTKey )<- atomically $ readTVar (ncCookie session)
133 if (ncState0 >= Accepted) 134 if (ncState0 >= Accepted)
134 -- If the nonce in the handshake and the dht key are both the same as 135 -- If the nonce in the handshake and the dht key are both the same as
135 -- the ones we have saved, assume we already handled this and this is a 136 -- the ones we have saved, assume we already handled this and this is a
136 -- duplicate handshake packet, otherwise disregard everything, and 137 -- duplicate handshake packet, otherwise disregard everything, and
137 -- refresh all state. 138 -- refresh all state.
138 -- 139 --
139 then when ( ncTheirBaseNonce0 /= hpTheirBaseNonce hp 140 then when ( Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp
140 || presentCookieDHTKey /= hpCookieRemoteDhtkey hp 141 || ncTheirDHTKey session /= hpCookieRemoteDhtkey hp
141 ) $ freshCryptoSession sessions addr hp 142 ) $ freshCryptoSession sessions addr hp
142 else if ( ncTheirBaseNonce0 /= hpTheirBaseNonce) 143 else if ( Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp)
143 then freshCryptoSession sessions addr hp -- basenonce mismatch, trigger refresh 144 then freshCryptoSession sessions addr hp -- basenonce mismatch, trigger refresh
144 else atomically $ modifyTVar (ncState session) Accepted 145 else atomically $ writeTVar (ncState session) Accepted
145 146
146 147
147cryptoNetHandler :: NetCryptoSessions -> SockAddr -> NetCrypto -> IO (Maybe (NetCrypto -> NetCrypto)) 148cryptoNetHandler :: NetCryptoSessions -> SockAddr -> NetCrypto -> IO (Maybe (NetCrypto -> NetCrypto))