summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Onion/Transport.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-10-13 13:32:46 -0400
committerjoe <joe@jerkface.net>2017-10-13 13:32:46 -0400
commit8d7f1fee8b06f7c38fad950d53abd382102ca4c6 (patch)
tree36f95c8b370fd3dc4df5e9d5b28b52414b3feeb8 /src/Network/Tox/Onion/Transport.hs
parent37a7fa4978f89072d9231bcc9bd0848bb52c676c (diff)
Use alias for onion-routed queries for true anonymization.
Diffstat (limited to 'src/Network/Tox/Onion/Transport.hs')
-rw-r--r--src/Network/Tox/Onion/Transport.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Network/Tox/Onion/Transport.hs b/src/Network/Tox/Onion/Transport.hs
index b5ac748a..eabd9473 100644
--- a/src/Network/Tox/Onion/Transport.hs
+++ b/src/Network/Tox/Onion/Transport.hs
@@ -457,7 +457,7 @@ peelOnion :: Serialize (Addressed (Forwarding n t))
457 -> Forwarding (S n) t 457 -> Forwarding (S n) t
458 -> Either String (Addressed (Forwarding n t)) 458 -> Either String (Addressed (Forwarding n t))
459peelOnion crypto nonce (Forwarding k fwd) = 459peelOnion crypto nonce (Forwarding k fwd) =
460 fmap runIdentity $ uncomposed $ decryptMessage crypto nonce (Right $ Assym k nonce fwd) 460 fmap runIdentity $ uncomposed $ decryptMessage (dhtKey crypto) nonce (Right $ Assym k nonce fwd)
461 461
462handleOnionResponse :: (KnownPeanoNat n, Sized (ReturnPath n), Serialize (ReturnPath n)) => proxy (S n) -> TransportCrypto -> SockAddr -> UDPTransport -> IO a -> OnionResponse (S n) -> IO a 462handleOnionResponse :: (KnownPeanoNat n, Sized (ReturnPath n), Serialize (ReturnPath n)) => proxy (S n) -> TransportCrypto -> SockAddr -> UDPTransport -> IO a -> OnionResponse (S n) -> IO a
463handleOnionResponse proxy crypto saddr udp kont (OnionResponse path msg) = do 463handleOnionResponse proxy crypto saddr udp kont (OnionResponse path msg) = do
@@ -576,7 +576,7 @@ encrypt crypto msg rpath = ( transcode ( (. (runIdentity . either id assymData))
576 msg 576 msg
577 , rpath) 577 , rpath)
578 where 578 where
579 skey = transportSecret crypto 579 skey = fst $ aliasKey crypto rpath
580 580
581 -- The OnionToMe case shouldn't happen, but we'll use our own public 581 -- The OnionToMe case shouldn't happen, but we'll use our own public
582 -- key in this situation. 582 -- key in this situation.
@@ -592,14 +592,21 @@ encryptMessage skey destKey n a = ToxCrypto.encrypt secret plain
592 592
593decrypt :: TransportCrypto -> OnionMessage Encrypted -> OnionDestination r -> Either String (OnionMessage Identity, OnionDestination r) 593decrypt :: TransportCrypto -> OnionMessage Encrypted -> OnionDestination r -> Either String (OnionMessage Identity, OnionDestination r)
594decrypt crypto msg addr = do 594decrypt crypto msg addr = do
595 msg <- sequenceMessage $ transcode (\n -> decryptMessage crypto n . left (senderkey addr)) msg 595 msg <- sequenceMessage $ transcode (\n -> decryptMessage (aliasKey crypto addr) n . left (senderkey addr)) msg
596 Right (msg, addr) 596 Right (msg, addr)
597 597
598senderkey :: OnionDestination r -> t -> (Maybe PublicKey, t) 598senderkey :: OnionDestination r -> t -> (Maybe PublicKey, t)
599senderkey addr e = (onionKey addr, e) 599senderkey addr e = (onionKey addr, e)
600 600
601aliasKey :: TransportCrypto -> OnionDestination r -> (SecretKey,PublicKey)
602aliasKey crypto (OnionToOwner {}) = (transportSecret &&& transportPublic) crypto
603aliasKey crypto (OnionDestination {}) = (onionAliasSecret &&& onionAliasPublic) crypto
604
605dhtKey :: TransportCrypto -> (SecretKey,PublicKey)
606dhtKey crypto = (transportSecret &&& transportPublic) crypto
607
601decryptMessage :: Serialize x => 608decryptMessage :: Serialize x =>
602 TransportCrypto 609 (SecretKey,PublicKey)
603 -> Nonce24 610 -> Nonce24
604 -> Either (Maybe PublicKey, Encrypted x) 611 -> Either (Maybe PublicKey, Encrypted x)
605 (Assym (Encrypted x)) 612 (Assym (Encrypted x))
@@ -609,7 +616,7 @@ decryptMessage crypto n arg
609 | otherwise = Composed $ Left "decryptMessage: Unknown sender" 616 | otherwise = Composed $ Left "decryptMessage: Unknown sender"
610 where 617 where
611 msecret = do sender <- mkey 618 msecret = do sender <- mkey
612 Just $ computeSharedSecret (transportSecret crypto) sender n 619 Just $ computeSharedSecret (fst crypto) sender n
613 (mkey,e) = either id (Just . senderKey &&& assymData) arg 620 (mkey,e) = either id (Just . senderKey &&& assymData) arg
614 plain = Composed . fmap Identity . (>>= decodePlain) 621 plain = Composed . fmap Identity . (>>= decodePlain)
615 622