diff options
author | joe <joe@jerkface.net> | 2018-05-30 23:53:44 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-05-30 23:53:44 -0400 |
commit | 514d0cad3f2ccaf0e89aadb4ab3067884ec20a6c (patch) | |
tree | a7d15e0d3592f123b10f2da3a458c023bd74de5b | |
parent | 2cffde93a0d814ebb54bdcbd3d6e598cbaae6ee1 (diff) |
tox: Removed obsolete "userKeys" TVar, use keys from ContactInfo.
-rw-r--r-- | examples/dhtd.hs | 35 | ||||
-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 |
6 files changed, 28 insertions, 32 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index b24a90fb..09817d4e 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -412,7 +412,6 @@ data Session = Session | |||
412 | , swarms :: Mainline.SwarmsDatabase | 412 | , swarms :: Mainline.SwarmsDatabase |
413 | , cryptosessions :: Tox.NetCryptoSessions | 413 | , cryptosessions :: Tox.NetCryptoSessions |
414 | , toxkeys :: TVar Tox.AnnouncedKeys | 414 | , toxkeys :: TVar Tox.AnnouncedKeys |
415 | , userkeys :: TVar [(SecretKey,PublicKey)] | ||
416 | , roster :: Tox.ContactInfo | 415 | , roster :: Tox.ContactInfo |
417 | , announceToLan :: IO () | 416 | , announceToLan :: IO () |
418 | , connectionManager :: Maybe ConnectionManager | 417 | , connectionManager :: Maybe ConnectionManager |
@@ -451,13 +450,6 @@ clientSession0 s sock cnum h = do | |||
451 | `catch` \e -> if isEOFError e then return () | 450 | `catch` \e -> if isEOFError e then return () |
452 | else throwIO e | 451 | else throwIO e |
453 | 452 | ||
454 | readKeys :: TVar [(SecretKey, PublicKey)] | ||
455 | -> TVar (HashMap.HashMap Tox.NodeId Account) -- ContactInfo { accounts } | ||
456 | -> STM [(SecretKey, PublicKey)] | ||
457 | readKeys userkeys roster = do | ||
458 | uks <- readTVar userkeys | ||
459 | as <- readTVar roster | ||
460 | return $ uks ++ map ((userSecret *** Tox.id2key) . swap) (HashMap.toList as) | ||
461 | 453 | ||
462 | clientSession :: Session -> t1 -> t -> ClientHandle -> IO () | 454 | clientSession :: Session -> t1 -> t -> ClientHandle -> IO () |
463 | clientSession s@Session{..} sock cnum h = do | 455 | clientSession s@Session{..} sock cnum h = do |
@@ -644,7 +636,7 @@ clientSession s@Session{..} sock cnum h = do | |||
644 | -- k secrets (list key pairs, including secret keys) | 636 | -- k secrets (list key pairs, including secret keys) |
645 | 637 | ||
646 | ("k", s) | "" <- strp s -> cmd0 $ do | 638 | ("k", s) | "" <- strp s -> cmd0 $ do |
647 | ks <- atomically $ readKeys userkeys (accounts roster) | 639 | ks <- atomically $ myKeyPairs roster |
648 | let spaces k | Just sel <- selectedKey, (sel == k) = " *" | 640 | let spaces k | Just sel <- selectedKey, (sel == k) = " *" |
649 | | otherwise = " " | 641 | | otherwise = " " |
650 | hPutClient h $ unlines $ map (\(_,k) -> mappend (spaces k) . show . Tox.key2id $ k) ks | 642 | hPutClient h $ unlines $ map (\(_,k) -> mappend (spaces k) . show . Tox.key2id $ k) ks |
@@ -652,8 +644,7 @@ clientSession s@Session{..} sock cnum h = do | |||
652 | secret <- generateSecretKey | 644 | secret <- generateSecretKey |
653 | let pubkey = toPublic secret | 645 | let pubkey = toPublic secret |
654 | oldks <- atomically $ do | 646 | oldks <- atomically $ do |
655 | ks <- readTVar userkeys | 647 | ks <- myKeyPairs roster |
656 | modifyTVar userkeys ((secret,pubkey):) | ||
657 | Tox.addContactInfo roster secret | 648 | Tox.addContactInfo roster secret |
658 | return ks | 649 | return ks |
659 | let asString = show . Tox.key2id | 650 | let asString = show . Tox.key2id |
@@ -661,14 +652,14 @@ clientSession s@Session{..} sock cnum h = do | |||
661 | ++ [mappend " *" . show . Tox.key2id $ pubkey] | 652 | ++ [mappend " *" . show . Tox.key2id $ pubkey] |
662 | switchKey $ Just pubkey | 653 | switchKey $ Just pubkey |
663 | | "secrets" <- strp s -> cmd0 $ do | 654 | | "secrets" <- strp s -> cmd0 $ do |
664 | ks <- atomically $ readKeys userkeys (accounts roster) | 655 | ks <- atomically $ myKeyPairs roster |
665 | skey <- maybe (return Nothing) (atomically . dhtSecretKey) | 656 | skey <- maybe (return Nothing) (atomically . dhtSecretKey) |
666 | $ Map.lookup netname dhts | 657 | $ Map.lookup netname dhts |
667 | hPutClient h . showReport $ map mkrow ks ++ case skey >>= encodeSecret of | 658 | hPutClient h . showReport $ map mkrow ks ++ case skey >>= encodeSecret of |
668 | Just x -> [("",""),("dht-key:",B.unpack x)] | 659 | Just x -> [("",""),("dht-key:",B.unpack x)] |
669 | Nothing -> [] | 660 | Nothing -> [] |
670 | | ("sel",_:expr) <- break isSpace s -> do | 661 | | ("sel",_:expr) <- break isSpace s -> do |
671 | ks <- atomically $ map (show . Tox.key2id . snd) <$> readKeys userkeys (accounts roster) | 662 | ks <- atomically $ map (show . Tox.key2id . snd) <$> myKeyPairs roster |
672 | case find (isInfixOf expr) ks of | 663 | case find (isInfixOf expr) ks of |
673 | Just k -> do | 664 | Just k -> do |
674 | hPutClient h $ "Selected key: "++k | 665 | hPutClient h $ "Selected key: "++k |
@@ -682,8 +673,7 @@ clientSession s@Session{..} sock cnum h = do | |||
682 | let toPair x = (x,toPublic x) | 673 | let toPair x = (x,toPublic x) |
683 | pairs = map (toPair . f) mbSecs | 674 | pairs = map (toPair . f) mbSecs |
684 | oldks <- atomically $ do | 675 | oldks <- atomically $ do |
685 | oldks <- readTVar userkeys | 676 | oldks <- myKeyPairs roster |
686 | modifyTVar userkeys (pairs ++) | ||
687 | forM pairs $ \(sk,_) -> Tox.addContactInfo roster sk | 677 | forM pairs $ \(sk,_) -> Tox.addContactInfo roster sk |
688 | return oldks | 678 | return oldks |
689 | hPutClient h $ unlines $ map (mappend " " . show . Tox.key2id . snd) oldks | 679 | hPutClient h $ unlines $ map (mappend " " . show . Tox.key2id . snd) oldks |
@@ -697,9 +687,8 @@ clientSession s@Session{..} sock cnum h = do | |||
697 | let toPair x = (x,toPublic x) | 687 | let toPair x = (x,toPublic x) |
698 | pairs = map (toPair . f) mbSecs | 688 | pairs = map (toPair . f) mbSecs |
699 | ks <- atomically $ do | 689 | ks <- atomically $ do |
700 | modifyTVar userkeys (filter (`notElem` pairs) ) | ||
701 | forM pairs $ \(_,pk) -> Tox.delContactInfo roster pk | 690 | forM pairs $ \(_,pk) -> Tox.delContactInfo roster pk |
702 | readTVar userkeys | 691 | myKeyPairs roster |
703 | hPutClient h . showReport $ map mkrow ks | 692 | hPutClient h . showReport $ map mkrow ks |
704 | switchKey $ do | 693 | switchKey $ do |
705 | k <- selectedKey | 694 | k <- selectedKey |
@@ -946,7 +935,7 @@ clientSession s@Session{..} sock cnum h = do | |||
946 | $ readEither nidstr | 935 | $ readEither nidstr |
947 | goTarget (Left nodeinfo) = do | 936 | goTarget (Left nodeinfo) = do |
948 | msec <- atomically $ do | 937 | msec <- atomically $ do |
949 | ks <- map swap <$> readKeys userkeys (accounts roster) | 938 | ks <- map swap <$> myKeyPairs roster |
950 | return $ Data.List.lookup mypubkey ks | 939 | return $ Data.List.lookup mypubkey ks |
951 | case mbTox of | 940 | case mbTox of |
952 | Nothing -> hPutClient h "Requires Tox enabled." | 941 | Nothing -> hPutClient h "Requires Tox enabled." |
@@ -966,7 +955,7 @@ clientSession s@Session{..} sock cnum h = do | |||
966 | hPutClient h "Handshake sent" | 955 | hPutClient h "Handshake sent" |
967 | goTarget (Right nid) = do | 956 | goTarget (Right nid) = do |
968 | msec <- atomically $ do | 957 | msec <- atomically $ do |
969 | ks <- map swap <$> readKeys userkeys (accounts roster) | 958 | ks <- map swap <$> myKeyPairs roster |
970 | return $ Data.List.lookup mypubkey ks | 959 | return $ Data.List.lookup mypubkey ks |
971 | case mbTox of | 960 | case mbTox of |
972 | Nothing -> hPutClient h "Requires Tox enabled." | 961 | Nothing -> hPutClient h "Requires Tox enabled." |
@@ -1931,13 +1920,12 @@ main = runResourceT $ liftBaseWith $ \resT -> do | |||
1931 | installHandler sigTERM (CatchOnce (atomically $ writeTVar signalQuit True)) Nothing | 1920 | installHandler sigTERM (CatchOnce (atomically $ writeTVar signalQuit True)) Nothing |
1932 | installHandler sigINT (CatchOnce (atomically $ writeTVar signalQuit True)) Nothing | 1921 | installHandler sigINT (CatchOnce (atomically $ writeTVar signalQuit True)) Nothing |
1933 | let defaultToxData = do | 1922 | let defaultToxData = do |
1934 | toxids <- atomically $ newTVar [] | ||
1935 | rster <- Tox.newContactInfo | 1923 | rster <- Tox.newContactInfo |
1936 | orouter <- newOnionRouter (hPutStrLn stderr) | 1924 | orouter <- newOnionRouter (hPutStrLn stderr) |
1937 | return (toxids, rster, orouter) | 1925 | return (rster, orouter) |
1938 | (toxids,rstr,orouter) <- fromMaybe defaultToxData $ do | 1926 | (rstr,orouter) <- fromMaybe defaultToxData $ do |
1939 | tox <- mbtox | 1927 | tox <- mbtox |
1940 | return $ return ( userKeys (Tox.toxCryptoKeys tox), Tox.toxContactInfo tox, Tox.toxOnionRoutes tox ) | 1928 | return $ return ( Tox.toxContactInfo tox, Tox.toxOnionRoutes tox ) |
1941 | let session = clientSession0 $ Session | 1929 | let session = clientSession0 $ Session |
1942 | { netname = concat $ take 1 $ Map.keys dhts -- initial default DHT | 1930 | { netname = concat $ take 1 $ Map.keys dhts -- initial default DHT |
1943 | , selectedKey = Nothing | 1931 | , selectedKey = Nothing |
@@ -1946,7 +1934,6 @@ main = runResourceT $ liftBaseWith $ \resT -> do | |||
1946 | , swarms = swarms | 1934 | , swarms = swarms |
1947 | , cryptosessions = netCryptoSessionsState | 1935 | , cryptosessions = netCryptoSessionsState |
1948 | , toxkeys = keysdb | 1936 | , toxkeys = keysdb |
1949 | , userkeys = toxids | ||
1950 | , roster = rstr | 1937 | , roster = rstr |
1951 | , announceToLan = fromMaybe (return ()) $ Tox.toxAnnounceToLan <$> mbtox | 1938 | , announceToLan = fromMaybe (return ()) $ Tox.toxAnnounceToLan <$> mbtox |
1952 | , connectionManager = ConnectionManager <$> mconns | 1939 | , connectionManager = ConnectionManager <$> mconns |
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) |