diff options
author | joe <joe@jerkface.net> | 2017-10-23 18:35:50 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-10-23 18:35:50 -0400 |
commit | ffe298780ce5945dd7a3a5fa957cf2770ca34b56 (patch) | |
tree | 455f8f012fecb804944c929dc44b3dd16e54e791 /src/Network/Tox | |
parent | 14657ce8b7231f2163438111fc22ba2955b65ed4 (diff) |
Decryption layer for data-to-route messages.
Diffstat (limited to 'src/Network/Tox')
-rw-r--r-- | src/Network/Tox/Onion/Transport.hs | 33 | ||||
-rw-r--r-- | src/Network/Tox/Transport.hs | 4 |
2 files changed, 24 insertions, 13 deletions
diff --git a/src/Network/Tox/Onion/Transport.hs b/src/Network/Tox/Onion/Transport.hs index bdaef651..4c3de3e6 100644 --- a/src/Network/Tox/Onion/Transport.hs +++ b/src/Network/Tox/Onion/Transport.hs | |||
@@ -738,16 +738,27 @@ instance Show Rendezvous where | |||
738 | parseDataToRoute | 738 | parseDataToRoute |
739 | :: TransportCrypto | 739 | :: TransportCrypto |
740 | -> (OnionMessage Encrypted,OnionDestination r) | 740 | -> (OnionMessage Encrypted,OnionDestination r) |
741 | -> Either (Asymm (Encrypted DataToRoute),Rendezvous) (OnionMessage Encrypted, OnionDestination r) | 741 | -> IO (Either (DataToRoute,Rendezvous) (OnionMessage Encrypted, OnionDestination r)) |
742 | parseDataToRoute crypto (OnionToRouteResponse dta, od) | 742 | parseDataToRoute crypto (OnionToRouteResponse dta, od) = |
743 | = Left ( dta | 743 | return $ either (const $ Right (OnionToRouteResponse dta,od)) Left $ do |
744 | , Rendezvous (rendezvousAliasPublic crypto) $ onionNodeInfo od ) | 744 | -- XXX: Do something with decryption failure? |
745 | parseDataToRoute _ msg = Right msg | 745 | decrypted <- uncomposed |
746 | $ decryptMessage (rendezvousSecret crypto,rendezvousPublic crypto) | ||
747 | (asymmNonce dta) | ||
748 | (Right dta) | ||
749 | return ( runIdentity decrypted | ||
750 | , Rendezvous (rendezvousPublic crypto) $ onionNodeInfo od ) | ||
751 | parseDataToRoute _ msg = return $ Right msg | ||
746 | 752 | ||
747 | encodeDataToRoute :: TransportCrypto | 753 | encodeDataToRoute :: TransportCrypto |
748 | -> (Asymm (Encrypted DataToRoute),Rendezvous) | 754 | -> (DataToRoute,Rendezvous) |
749 | -> Maybe (OnionMessage Encrypted,OnionDestination r) | 755 | -> IO (Maybe (OnionMessage Encrypted,OnionDestination r)) |
750 | encodeDataToRoute crypto (dta, Rendezvous pub ni) | 756 | encodeDataToRoute crypto (plain, Rendezvous pub ni) = do |
751 | = Just ( OnionToRoute pub -- Public key of destination node | 757 | nonce <- atomically $ transportNewNonce crypto |
752 | dta | 758 | let dta = encryptMessage (onionAliasSecret crypto) pub nonce plain |
753 | , OnionDestination SearchingAlias ni Nothing ) | 759 | return $ Just ( OnionToRoute pub -- Public key of destination node |
760 | Asymm { senderKey = onionAliasPublic crypto | ||
761 | , asymmNonce = nonce | ||
762 | , asymmData = dta | ||
763 | } | ||
764 | , OnionDestination SearchingAlias ni Nothing ) | ||
diff --git a/src/Network/Tox/Transport.hs b/src/Network/Tox/Transport.hs index 59c0cf6f..2a4e7eee 100644 --- a/src/Network/Tox/Transport.hs +++ b/src/Network/Tox/Transport.hs | |||
@@ -24,14 +24,14 @@ toxTransport :: | |||
24 | -> UDPTransport | 24 | -> UDPTransport |
25 | -> IO ( Transport String NodeInfo (DHTMessage Encrypted8) | 25 | -> IO ( Transport String NodeInfo (DHTMessage Encrypted8) |
26 | , Transport String (OnionDestination RouteId) (OnionMessage Encrypted) | 26 | , Transport String (OnionDestination RouteId) (OnionMessage Encrypted) |
27 | , Transport String Rendezvous (Asymm (Encrypted DataToRoute)) | 27 | , Transport String Rendezvous DataToRoute |
28 | , Transport String SockAddr NetCrypto ) | 28 | , Transport String SockAddr NetCrypto ) |
29 | toxTransport crypto orouter closeLookup udp = do | 29 | toxTransport crypto orouter closeLookup udp = do |
30 | (dht,udp1) <- partitionTransport parseDHTAddr (Just . encodeDHTAddr) $ forwardOnions crypto udp | 30 | (dht,udp1) <- partitionTransport parseDHTAddr (Just . encodeDHTAddr) $ forwardOnions crypto udp |
31 | (onion1,udp2) <- partitionTransportM (parseOnionAddr $ lookupSender orouter) | 31 | (onion1,udp2) <- partitionTransportM (parseOnionAddr $ lookupSender orouter) |
32 | (encodeOnionAddr $ lookupRoute orouter) | 32 | (encodeOnionAddr $ lookupRoute orouter) |
33 | udp1 | 33 | udp1 |
34 | (dta,onion) <- partitionTransport (parseDataToRoute crypto) (encodeDataToRoute crypto) onion1 | 34 | (dta,onion) <- partitionTransportM (parseDataToRoute crypto) (encodeDataToRoute crypto) onion1 |
35 | let netcrypto = layerTransport parseNetCrypto encodeNetCrypto udp2 | 35 | let netcrypto = layerTransport parseNetCrypto encodeNetCrypto udp2 |
36 | return ( forwardDHTRequests crypto closeLookup dht | 36 | return ( forwardDHTRequests crypto closeLookup dht |
37 | , onion | 37 | , onion |