diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Crypto/Tox.hs | 2 | ||||
-rw-r--r-- | src/Network/Tox.hs | 8 | ||||
-rw-r--r-- | src/Network/Tox/ContactInfo.hs | 9 | ||||
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 2 | ||||
-rw-r--r-- | src/Network/Tox/Onion/Transport.hs | 4 |
5 files changed, 17 insertions, 8 deletions
diff --git a/src/Crypto/Tox.hs b/src/Crypto/Tox.hs index acb98e3e..864e17df 100644 --- a/src/Crypto/Tox.hs +++ b/src/Crypto/Tox.hs | |||
@@ -527,7 +527,7 @@ data TransportCrypto = TransportCrypto | |||
527 | , rendezvousPublic :: PublicKey | 527 | , rendezvousPublic :: PublicKey |
528 | , transportSymmetric :: STM SymmetricKey | 528 | , transportSymmetric :: STM SymmetricKey |
529 | , transportNewNonce :: STM Nonce24 | 529 | , transportNewNonce :: STM Nonce24 |
530 | , userKeys :: TVar [(SecretKey,PublicKey)] | 530 | , userKeys :: STM [(SecretKey,PublicKey)] |
531 | , pendingCookies :: TVar [(SockAddr, (Int, PublicKey))] | 531 | , pendingCookies :: TVar [(SockAddr, (Int, PublicKey))] |
532 | , secretsCache :: SecretsCache | 532 | , secretsCache :: SecretsCache |
533 | } | 533 | } |
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index a3291a0f..69982c81 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -145,7 +145,7 @@ newCrypto = do | |||
145 | let (nonce, drg2) = withDRG drg1 (Nonce24 <$> getRandomBytes 24) | 145 | let (nonce, drg2) = withDRG drg1 (Nonce24 <$> getRandomBytes 24) |
146 | writeTVar noncevar drg2 | 146 | writeTVar noncevar drg2 |
147 | return nonce | 147 | return nonce |
148 | , userKeys = ukeys | 148 | , userKeys = return [] |
149 | , pendingCookies = cookieKeys | 149 | , pendingCookies = cookieKeys |
150 | , secretsCache = cache | 150 | , secretsCache = cache |
151 | } | 151 | } |
@@ -415,11 +415,13 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
415 | return (crypto,sessionsState) | 415 | return (crypto,sessionsState) |
416 | Just s -> return (transportCrypto s, s) | 416 | Just s -> return (transportCrypto s, s) |
417 | 417 | ||
418 | roster <- newContactInfo | ||
418 | let crypto = fromMaybe crypto0 $do | 419 | let crypto = fromMaybe crypto0 $do |
419 | k <- suppliedDHTKey | 420 | k <- suppliedDHTKey |
420 | return crypto0 | 421 | return crypto0 |
421 | { transportSecret = k | 422 | { transportSecret = k |
422 | , transportPublic = toPublic k | 423 | , transportPublic = toPublic k |
424 | , userKeys = myKeyPairs roster | ||
423 | } | 425 | } |
424 | forM_ suppliedDHTKey $ \k -> do | 426 | forM_ suppliedDHTKey $ \k -> do |
425 | maybe (hPutStrLn stderr "failed to encode suppliedDHTKey") | 427 | maybe (hPutStrLn stderr "failed to encode suppliedDHTKey") |
@@ -433,7 +435,8 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
433 | let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building. | 435 | let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building. |
434 | orouter <- newOnionRouter ignoreErrors | 436 | orouter <- newOnionRouter ignoreErrors |
435 | (dhtcrypt,onioncrypt,dtacrypt,cryptonet) <- toxTransport crypto orouter lookupClose udp | 437 | (dhtcrypt,onioncrypt,dtacrypt,cryptonet) <- toxTransport crypto orouter lookupClose udp |
436 | let sessionsState = sessionsState0 { sessionTransport = cryptonet } | 438 | let sessionsState = sessionsState0 { sessionTransport = cryptonet |
439 | , transportCrypto = crypto } | ||
437 | let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt | 440 | let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt |
438 | tbl4 = DHT.routing4 $ mkrouting (error "missing client") | 441 | tbl4 = DHT.routing4 $ mkrouting (error "missing client") |
439 | tbl6 = DHT.routing6 $ mkrouting (error "missing client") | 442 | tbl6 = DHT.routing6 $ mkrouting (error "missing client") |
@@ -453,7 +456,6 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
453 | (hookQueries orouter DHT.transactionKey) | 456 | (hookQueries orouter DHT.transactionKey) |
454 | (const id) | 457 | (const id) |
455 | 458 | ||
456 | roster <- newContactInfo | ||
457 | return Tox | 459 | return Tox |
458 | { toxDHT = dhtclient | 460 | { toxDHT = dhtclient |
459 | , toxOnion = onionclient | 461 | , toxOnion = onionclient |
diff --git a/src/Network/Tox/ContactInfo.hs b/src/Network/Tox/ContactInfo.hs index d9d9a510..df3365a2 100644 --- a/src/Network/Tox/ContactInfo.hs +++ b/src/Network/Tox/ContactInfo.hs | |||
@@ -12,10 +12,11 @@ import qualified Data.HashMap.Strict as HashMap | |||
12 | import Data.Maybe | 12 | import Data.Maybe |
13 | import qualified Data.Set as Set | 13 | import qualified Data.Set as Set |
14 | ;import Data.Set (Set) | 14 | ;import Data.Set (Set) |
15 | import Network.Socket | ||
15 | import Network.Tox.DHT.Transport as DHT | 16 | import Network.Tox.DHT.Transport as DHT |
17 | import Network.Tox.NodeId (id2key) | ||
16 | import Network.Tox.Onion.Transport as Onion | 18 | import Network.Tox.Onion.Transport as Onion |
17 | import System.IO | 19 | import System.IO |
18 | import Network.Socket | ||
19 | 20 | ||
20 | newtype ContactInfo = ContactInfo | 21 | newtype ContactInfo = ContactInfo |
21 | -- | Map our toxid public key to an Account record. | 22 | -- | Map our toxid public key to an Account record. |
@@ -150,3 +151,9 @@ friendRequests (ContactInfo roster) = do | |||
150 | $ HashMap.toList cs | 151 | $ HashMap.toList cs |
151 | return remotes | 152 | return remotes |
152 | 153 | ||
154 | myKeyPairs :: ContactInfo -> STM [(SecretKey,PublicKey)] | ||
155 | myKeyPairs (ContactInfo accounts) = do | ||
156 | acnts <- readTVar accounts | ||
157 | forM (HashMap.toList acnts) $ \(nid, Account{userSecret}) -> do | ||
158 | return (userSecret,id2key nid) | ||
159 | |||
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 95cb1bc8..9e5bd94e 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -543,7 +543,7 @@ cryptoNetHandler sessions addr (NetHandshake (Handshake (Cookie n24 ecookie) non | |||
543 | allsessions = netCryptoSessions sessions | 543 | allsessions = netCryptoSessions sessions |
544 | anyRight [] f = return $ Left "missing key" | 544 | anyRight [] f = return $ Left "missing key" |
545 | anyRight (x:xs) f = f x >>= either (const $ anyRight xs f) (return . Right) | 545 | anyRight (x:xs) f = f x >>= either (const $ anyRight xs f) (return . Right) |
546 | seckeys <- map fst <$> atomically (readTVar (userKeys crypto)) | 546 | seckeys <- map fst <$> atomically (userKeys crypto) |
547 | symkey <- atomically $ transportSymmetric crypto | 547 | symkey <- atomically $ transportSymmetric crypto |
548 | now <- getPOSIXTime | 548 | now <- getPOSIXTime |
549 | dput XNetCrypto ("Decrypt cookie with n24=" ++ show n24 ++ "\n symkey= " ++ show symkey) | 549 | dput XNetCrypto ("Decrypt cookie with n24=" ++ show n24 ++ "\n symkey= " ++ show symkey) |
diff --git a/src/Network/Tox/Onion/Transport.hs b/src/Network/Tox/Onion/Transport.hs index 550a7730..d604a5c8 100644 --- a/src/Network/Tox/Onion/Transport.hs +++ b/src/Network/Tox/Onion/Transport.hs | |||
@@ -848,7 +848,7 @@ instance Read AnnouncedRendezvous where | |||
848 | selectAlias :: TransportCrypto -> NodeId -> STM AliasSelector | 848 | selectAlias :: TransportCrypto -> NodeId -> STM AliasSelector |
849 | selectAlias crypto pkey = do | 849 | selectAlias crypto pkey = do |
850 | ks <- filter (\(sk,pk) -> pk == id2key pkey) | 850 | ks <- filter (\(sk,pk) -> pk == id2key pkey) |
851 | <$> readTVar (userKeys crypto) | 851 | <$> userKeys crypto |
852 | maybe (return SearchingAlias) | 852 | maybe (return SearchingAlias) |
853 | (return . uncurry AnnouncingAlias) | 853 | (return . uncurry AnnouncingAlias) |
854 | (listToMaybe ks) | 854 | (listToMaybe ks) |
@@ -859,7 +859,7 @@ parseDataToRoute | |||
859 | -> (OnionMessage Encrypted,OnionDestination r) | 859 | -> (OnionMessage Encrypted,OnionDestination r) |
860 | -> IO (Either ((PublicKey,OnionData),AnnouncedRendezvous) (OnionMessage Encrypted, OnionDestination r)) | 860 | -> IO (Either ((PublicKey,OnionData),AnnouncedRendezvous) (OnionMessage Encrypted, OnionDestination r)) |
861 | parseDataToRoute crypto (OnionToRouteResponse dta, od) = do | 861 | parseDataToRoute crypto (OnionToRouteResponse dta, od) = do |
862 | ks <- atomically $ readTVar $ userKeys crypto | 862 | ks <- atomically $ userKeys crypto |
863 | 863 | ||
864 | omsg0 <- decryptMessage crypto (rendezvousSecret crypto,rendezvousPublic crypto) | 864 | omsg0 <- decryptMessage crypto (rendezvousSecret crypto,rendezvousPublic crypto) |
865 | (asymmNonce dta) | 865 | (asymmNonce dta) |