diff options
author | joe <joe@jerkface.net> | 2017-10-13 13:32:46 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-10-13 13:32:46 -0400 |
commit | 8d7f1fee8b06f7c38fad950d53abd382102ca4c6 (patch) | |
tree | 36f95c8b370fd3dc4df5e9d5b28b52414b3feeb8 /src/Network/Tox.hs | |
parent | 37a7fa4978f89072d9231bcc9bd0848bb52c676c (diff) |
Use alias for onion-routed queries for true anonymization.
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r-- | src/Network/Tox.hs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 3860d309..51ee0a4d 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -100,7 +100,9 @@ import Data.Word64Map (fitsInInt) | |||
100 | newCrypto :: IO TransportCrypto | 100 | newCrypto :: IO TransportCrypto |
101 | newCrypto = do | 101 | newCrypto = do |
102 | secret <- generateSecretKey | 102 | secret <- generateSecretKey |
103 | alias <- generateSecretKey | ||
103 | let pubkey = toPublic secret | 104 | let pubkey = toPublic secret |
105 | aliaspub = toPublic alias | ||
104 | (symkey, drg) <- do | 106 | (symkey, drg) <- do |
105 | drg0 <- getSystemDRG | 107 | drg0 <- getSystemDRG |
106 | return $ randomBytesGenerate 32 drg0 :: IO (ByteString, SystemDRG) | 108 | return $ randomBytesGenerate 32 drg0 :: IO (ByteString, SystemDRG) |
@@ -111,6 +113,8 @@ newCrypto = do | |||
111 | return TransportCrypto | 113 | return TransportCrypto |
112 | { transportSecret = secret | 114 | { transportSecret = secret |
113 | , transportPublic = pubkey | 115 | , transportPublic = pubkey |
116 | , onionAliasSecret = alias | ||
117 | , onionAliasPublic = aliaspub | ||
114 | , transportSymmetric = return $ SymmetricKey symkey | 118 | , transportSymmetric = return $ SymmetricKey symkey |
115 | , transportNewNonce = do | 119 | , transportNewNonce = do |
116 | drg1 <- readTVar noncevar | 120 | drg1 <- readTVar noncevar |
@@ -205,6 +209,7 @@ data Tox = Tox | |||
205 | , toxOnionRoutes :: OnionRouter | 209 | , toxOnionRoutes :: OnionRouter |
206 | } | 210 | } |
207 | 211 | ||
212 | isLocalHost :: SockAddr -> Bool | ||
208 | isLocalHost (SockAddrInet _ host32) = (fromBE32 host32 == 0x7f000001) | 213 | isLocalHost (SockAddrInet _ host32) = (fromBE32 host32 == 0x7f000001) |
209 | isLocalHost _ = False | 214 | isLocalHost _ = False |
210 | 215 | ||
@@ -227,6 +232,14 @@ newKeysDatabase :: IO (TVar Onion.AnnouncedKeys) | |||
227 | newKeysDatabase = | 232 | newKeysDatabase = |
228 | atomically $ newTVar $ Onion.AnnouncedKeys PSQ.empty MinMaxPSQ.empty | 233 | atomically $ newTVar $ Onion.AnnouncedKeys PSQ.empty MinMaxPSQ.empty |
229 | 234 | ||
235 | |||
236 | getOnionAlias :: TransportCrypto -> STM NodeInfo -> Maybe (Onion.OnionDestination r) -> IO (Onion.OnionDestination r) | ||
237 | getOnionAlias crypto dhtself remoteNode = atomically $ do | ||
238 | ni <- dhtself | ||
239 | let alias = ni { nodeId = key2id (onionAliasPublic crypto) } | ||
240 | return $ Onion.OnionDestination alias Nothing | ||
241 | |||
242 | |||
230 | newTox :: TVar Onion.AnnouncedKeys -> SockAddr -> IO Tox | 243 | newTox :: TVar Onion.AnnouncedKeys -> SockAddr -> IO Tox |
231 | newTox keydb addr = do | 244 | newTox keydb addr = do |
232 | udp <- addVerbosity <$> udpTransport addr | 245 | udp <- addVerbosity <$> udpTransport addr |
@@ -249,10 +262,7 @@ newTox keydb addr = do | |||
249 | oniondrg <- drgNew | 262 | oniondrg <- drgNew |
250 | let onionnet = layerTransport (Onion.decrypt crypto) (Onion.encrypt crypto) onioncrypt | 263 | let onionnet = layerTransport (Onion.decrypt crypto) (Onion.encrypt crypto) onioncrypt |
251 | onionclient <- newClient oniondrg onionnet Onion.classify | 264 | onionclient <- newClient oniondrg onionnet Onion.classify |
252 | (const $ atomically | 265 | (getOnionAlias crypto $ R.thisNode <$> readTVar (DHT.routing4 routing)) |
253 | $ flip Onion.OnionDestination Nothing | ||
254 | . R.thisNode | ||
255 | <$> readTVar (DHT.routing4 routing)) | ||
256 | (Onion.handlers onionnet routing toks keydb) | 266 | (Onion.handlers onionnet routing toks keydb) |
257 | (hookQueries orouter DHT.transactionKey) | 267 | (hookQueries orouter DHT.transactionKey) |
258 | (const id) | 268 | (const id) |