diff options
-rw-r--r-- | src/Network/Tox/Crypto/Transport.hs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs index 1583ef6f..f7fd0f7e 100644 --- a/src/Network/Tox/Crypto/Transport.hs +++ b/src/Network/Tox/Crypto/Transport.hs | |||
@@ -68,9 +68,18 @@ encodeNetCrypto (NetHandshake x) saddr = (B.cons 0x1a (runPut $ put x),saddr) | |||
68 | encodeNetCrypto (NetCrypto x) saddr = (B.cons 0x1b (runPut $ put x),saddr) | 68 | encodeNetCrypto (NetCrypto x) saddr = (B.cons 0x1b (runPut $ put x),saddr) |
69 | 69 | ||
70 | data Handshake (f :: * -> *) = Handshake | 70 | data Handshake (f :: * -> *) = Handshake |
71 | { handshakeCookie :: Cookie | 71 | { -- The cookie is a cookie obtained by |
72 | -- sending a cookie request packet to the peer and getting a cookie | ||
73 | -- response packet with a cookie in it. It may also be obtained in the | ||
74 | -- handshake packet by a peer receiving a handshake packet (Other | ||
75 | -- Cookie). | ||
76 | handshakeCookie :: Cookie | ||
77 | -- The nonce is a nonce used to encrypt the encrypted part of the handshake | ||
78 | -- packet. | ||
72 | , handshakeNonce :: Nonce24 | 79 | , handshakeNonce :: Nonce24 |
73 | , hadshakeData :: f HandshakeData | 80 | -- The encrypted part of the handshake packet is encrypted with the long |
81 | -- term user-keys of both peers. | ||
82 | , handshakeData :: f HandshakeData | ||
74 | } | 83 | } |
75 | 84 | ||
76 | instance Serialize (Handshake Encrypted) where | 85 | instance Serialize (Handshake Encrypted) where |
@@ -91,7 +100,11 @@ instance Sized HandshakeData where | |||
91 | <> contramap otherCookie size | 100 | <> contramap otherCookie size |
92 | 101 | ||
93 | data CryptoPacket (f :: * -> *) = CryptoPacket | 102 | data CryptoPacket (f :: * -> *) = CryptoPacket |
94 | { pktNonce :: Word16 | 103 | { -- | The last 2 bytes of the nonce used to encrypt 'pktData' |
104 | pktNonce :: Word16 | ||
105 | -- The payload is encrypted with the session key and 'baseNonce' set by | ||
106 | -- the receiver in their handshake + packet number (starting at 0, big | ||
107 | -- endian math). | ||
95 | , pktData :: f CryptoData | 108 | , pktData :: f CryptoData |
96 | } | 109 | } |
97 | 110 | ||
@@ -148,8 +161,10 @@ erCompat lens = error $ "Use of '" ++ lens ++ "' lens on incompatible CryptoMes | |||
148 | typingStatus :: Functor f => (UserStatus -> f UserStatus)-> (CryptoMessage -> f CryptoMessage) | 161 | typingStatus :: Functor f => (UserStatus -> f UserStatus)-> (CryptoMessage -> f CryptoMessage) |
149 | typingStatus = lens getter setter | 162 | typingStatus = lens getter setter |
150 | where | 163 | where |
164 | getter :: CryptoMessage -> UserStatus | ||
151 | getter (TwoByte TYPING status) = toEnum $ fromIntegral status | 165 | getter (TwoByte TYPING status) = toEnum $ fromIntegral status |
152 | getter _ = erCompat "typingStatus" | 166 | getter _ = erCompat "typingStatus" |
167 | setter :: CryptoMessage -> UserStatus -> CryptoMessage | ||
153 | setter (TwoByte TYPING _) status = TwoByte TYPING (fromIntegral . fromEnum $ status) | 168 | setter (TwoByte TYPING _) status = TwoByte TYPING (fromIntegral . fromEnum $ status) |
154 | setter _ _ = erCompat "typingStatus" | 169 | setter _ _ = erCompat "typingStatus" |
155 | 170 | ||