diff options
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index ac7379d4..453d4b08 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -47,6 +47,7 @@ import Control.Concurrent.Supply | |||
47 | import Data.InOrOut | 47 | import Data.InOrOut |
48 | import DPut | 48 | import DPut |
49 | import Debug.Trace | 49 | import Debug.Trace |
50 | import Text.Printf | ||
50 | import Data.Bool | 51 | import Data.Bool |
51 | 52 | ||
52 | -- util, todo: move to another module | 53 | -- util, todo: move to another module |
@@ -369,7 +370,7 @@ ncToWire getState seqno bufend pktno msg = do | |||
369 | $ lookupInRangeMap typ64 msgOutMapVar | 370 | $ lookupInRangeMap typ64 msgOutMapVar |
370 | case result1 of -- msgOutMapLookup typ64 msgOutMap of | 371 | case result1 of -- msgOutMapLookup typ64 msgOutMap of |
371 | Nothing -> trace "lookupInRangeMap gave Nothing!" $ return Nothing | 372 | Nothing -> trace "lookupInRangeMap gave Nothing!" $ return Nothing |
372 | Just outid -> do | 373 | Just outid -> trace ("encrypting packet with Nonce: " ++ show n24) $ do |
373 | let setMessageId (OneByte _) mid = OneByte (toEnum8 mid) | 374 | let setMessageId (OneByte _) mid = OneByte (toEnum8 mid) |
374 | setMessageId (TwoByte _ x) mid = TwoByte (toEnum8 mid) x | 375 | setMessageId (TwoByte _ x) mid = TwoByte (toEnum8 mid) x |
375 | setMessageId (UpToN _ x) mid = UpToN (toEnum8 mid) x | 376 | setMessageId (UpToN _ x) mid = UpToN (toEnum8 mid) x |
@@ -384,7 +385,9 @@ ncToWire getState seqno bufend pktno msg = do | |||
384 | } | 385 | } |
385 | plain = encodePlain cd | 386 | plain = encodePlain cd |
386 | encrypted = encrypt state plain | 387 | encrypted = encrypt state plain |
387 | pkt = CryptoPacket { pktNonce = nonce24ToWord16 n24, pktData = encrypted } | 388 | pkt = CryptoPacket { pktNonce = let r = nonce24ToWord16 n24 |
389 | in trace (printf "converting n24 to word16: 0x%x" r) r | ||
390 | , pktData = encrypted } | ||
388 | in return (Just (pkt, pktno)) | 391 | in return (Just (pkt, pktno)) |
389 | Lossless -> let cd = | 392 | Lossless -> let cd = |
390 | CryptoData | 393 | CryptoData |
@@ -667,7 +670,9 @@ cryptoNetHandler sessions addr (NetCrypto (CryptoPacket nonce16 encrypted)) = do | |||
667 | pubkey <- maybeToEither ncTheirSessionPublic | 670 | pubkey <- maybeToEither ncTheirSessionPublic |
668 | Right $ do -- IO Monad | 671 | Right $ do -- IO Monad |
669 | dput XNetCrypto $ "cryptoNetHandler: pubkey = " ++ show (key2id $ pubkey) | 672 | dput XNetCrypto $ "cryptoNetHandler: pubkey = " ++ show (key2id $ pubkey) |
673 | dput XNetCrypto $ "cryptoNetHandler: theirBaseNonce = " ++ show theirBaseNonce | ||
670 | dput XNetCrypto $ "cryptoNetHandler: tempNonce = " ++ show tempNonce | 674 | dput XNetCrypto $ "cryptoNetHandler: tempNonce = " ++ show tempNonce |
675 | ++ " nonce16=" ++ printf "0x%x" nonce16 ++ " last2bytes =" ++ printf "0x%x" (last2Bytes theirBaseNonce) | ||
671 | secret <- lookupSharedSecret crypto ncSessionSecret pubkey tempNonce | 676 | secret <- lookupSharedSecret crypto ncSessionSecret pubkey tempNonce |
672 | let step1 = decrypt secret encrypted | 677 | let step1 = decrypt secret encrypted |
673 | case step1 of | 678 | case step1 of |
@@ -696,6 +701,8 @@ cryptoNetHandler sessions addr (NetCrypto (CryptoPacket nonce16 encrypted)) = do | |||
696 | atomically $ do | 701 | atomically $ do |
697 | y <- readTVar ncTheirBaseNonce | 702 | y <- readTVar ncTheirBaseNonce |
698 | let x = addtoNonce24 y (fromIntegral dATA_NUM_THRESHOLD) | 703 | let x = addtoNonce24 y (fromIntegral dATA_NUM_THRESHOLD) |
704 | trace ("nonce y(" ++ show y ++ ") + " ++ show (fromIntegral dATA_NUM_THRESHOLD) | ||
705 | ++ " = " ++ show x) (return ()) | ||
699 | writeTVar ncTheirBaseNonce y | 706 | writeTVar ncTheirBaseNonce y |
700 | -- then set session confirmed, | 707 | -- then set session confirmed, |
701 | atomically $ writeTVar ncState Confirmed {-Established-} | 708 | atomically $ writeTVar ncState Confirmed {-Established-} |
@@ -721,7 +728,7 @@ cryptoNetHandler sessions addr (NetCrypto (CryptoPacket nonce16 encrypted)) = do | |||
721 | where | 728 | where |
722 | last2Bytes :: Nonce24 -> Word16 | 729 | last2Bytes :: Nonce24 -> Word16 |
723 | last2Bytes (Nonce24 bs) = case S.decode (B.drop 22 bs) of | 730 | last2Bytes (Nonce24 bs) = case S.decode (B.drop 22 bs) of |
724 | Right n -> byteSwap16 n | 731 | Right n -> trace ("byteSwap16 " ++ printf "0x%x" n ++ " = " ++ printf "0x%x" (byteSwap16 n)) $ byteSwap16 n |
725 | _ -> error "unreachable-last2Bytes" | 732 | _ -> error "unreachable-last2Bytes" |
726 | dATA_NUM_THRESHOLD = 21845 -- = 65535 / 3 | 733 | dATA_NUM_THRESHOLD = 21845 -- = 65535 / 3 |
727 | 734 | ||