summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dht-client.cabal1
-rw-r--r--examples/testcookie.hs13
-rw-r--r--src/Network/Tox/Crypto/Transport.hs4
-rw-r--r--src/Network/Tox/DHT/Transport.hs1
4 files changed, 17 insertions, 2 deletions
diff --git a/dht-client.cabal b/dht-client.cabal
index 81521e05..ef634a01 100644
--- a/dht-client.cabal
+++ b/dht-client.cabal
@@ -286,6 +286,7 @@ executable dhtd
286 ghc-options: -rtsopts -fdefer-typed-holes -threaded 286 ghc-options: -rtsopts -fdefer-typed-holes -threaded
287 287
288executable testcookie 288executable testcookie
289 buildable: False
289 hs-source-dirs: examples 290 hs-source-dirs: examples
290 main-is: testcookie.hs 291 main-is: testcookie.hs
291 default-language: Haskell2010 292 default-language: Haskell2010
diff --git a/examples/testcookie.hs b/examples/testcookie.hs
index c4974125..5f5d4e83 100644
--- a/examples/testcookie.hs
+++ b/examples/testcookie.hs
@@ -7,6 +7,7 @@ import Crypto.Tox
7import Network.Tox 7import Network.Tox
8import Network.Tox.DHT.Handlers 8import Network.Tox.DHT.Handlers
9import Network.Tox.Crypto.Handlers 9import Network.Tox.Crypto.Handlers
10import Network.Tox.DHT.Transport (Cookie(..))
10 11
11import Data.Serialize as S 12import Data.Serialize as S
12 13
@@ -28,6 +29,18 @@ import Data.Serialize as S
28 29
29main = do 30main = do
30 crypto <- newCrypto 31 crypto <- newCrypto
32 secUser <- generateSecretKey
33 let pubUser = toPublic secUser
34 node = read "Ivr3mkGriCmv5FeF91UPZbkirDfpIagXcfvo6ozUCRp@92.99.99.99:33412"
35 ecookie@(Cookie cookieNonce eCookieData) <- createCookie crypto node pubUser
36
37 let bs = encode ecookie
38 print $ (decode bs :: Either String Cookie)
39
40
41 sym <- atomically $ transportSymmetric crypto
42 print $ decryptSymmetric sym cookieNonce eCookieData >>= decodePlain
43
31 n24 <- atomically $ transportNewNonce crypto 44 n24 <- atomically $ transportNewNonce crypto
32 putStrLn $ "n24 = " ++ show n24 45 putStrLn $ "n24 = " ++ show n24
33 let e24 = S.encode n24 46 let e24 = S.encode n24
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs
index 141ef792..1444ffca 100644
--- a/src/Network/Tox/Crypto/Transport.hs
+++ b/src/Network/Tox/Crypto/Transport.hs
@@ -81,8 +81,8 @@ data NetCrypto
81 | NetCrypto (CryptoPacket Encrypted) 81 | NetCrypto (CryptoPacket Encrypted)
82 82
83parseNetCrypto :: ByteString -> SockAddr -> Either String (NetCrypto, SockAddr) 83parseNetCrypto :: ByteString -> SockAddr -> Either String (NetCrypto, SockAddr)
84parseNetCrypto pkt@(B.uncons -> Just (0x1a,_)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetHandshake <$> runGet get pkt 84parseNetCrypto (B.uncons -> Just (0x1a,pkt)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetHandshake <$> runGet get pkt
85parseNetCrypto pkt@(B.uncons -> Just (0x1b,_)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetCrypto <$> runGet get pkt 85parseNetCrypto (B.uncons -> Just (0x1b,pkt)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetCrypto <$> runGet get pkt
86parseNetCrypto _ _ = Left "parseNetCrypto: ?" 86parseNetCrypto _ _ = Left "parseNetCrypto: ?"
87 87
88encodeNetCrypto :: NetCrypto -> SockAddr -> (ByteString, SockAddr) 88encodeNetCrypto :: NetCrypto -> SockAddr -> (ByteString, SockAddr)
diff --git a/src/Network/Tox/DHT/Transport.hs b/src/Network/Tox/DHT/Transport.hs
index f7feea3b..59b22673 100644
--- a/src/Network/Tox/DHT/Transport.hs
+++ b/src/Network/Tox/DHT/Transport.hs
@@ -371,6 +371,7 @@ data CookieData = CookieData -- 16 (mac)
371 , longTermKey :: PublicKey -- 32 371 , longTermKey :: PublicKey -- 32
372 , dhtKey :: PublicKey -- + 32 372 , dhtKey :: PublicKey -- + 32
373 } -- = 88 bytes when encrypted. 373 } -- = 88 bytes when encrypted.
374 deriving Show
374 375
375instance Sized CookieData where 376instance Sized CookieData where
376 size = ConstSize 72 377 size = ConstSize 72