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/Onion | |
parent | 14657ce8b7231f2163438111fc22ba2955b65ed4 (diff) |
Decryption layer for data-to-route messages.
Diffstat (limited to 'src/Network/Tox/Onion')
-rw-r--r-- | src/Network/Tox/Onion/Transport.hs | 33 |
1 files changed, 22 insertions, 11 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 ) | ||