diff options
-rw-r--r-- | dht-client.cabal | 1 | ||||
-rw-r--r-- | examples/testcookie.hs | 13 | ||||
-rw-r--r-- | src/Network/Tox/Crypto/Transport.hs | 4 | ||||
-rw-r--r-- | src/Network/Tox/DHT/Transport.hs | 1 |
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 | ||
288 | executable testcookie | 288 | executable 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 | |||
7 | import Network.Tox | 7 | import Network.Tox |
8 | import Network.Tox.DHT.Handlers | 8 | import Network.Tox.DHT.Handlers |
9 | import Network.Tox.Crypto.Handlers | 9 | import Network.Tox.Crypto.Handlers |
10 | import Network.Tox.DHT.Transport (Cookie(..)) | ||
10 | 11 | ||
11 | import Data.Serialize as S | 12 | import Data.Serialize as S |
12 | 13 | ||
@@ -28,6 +29,18 @@ import Data.Serialize as S | |||
28 | 29 | ||
29 | main = do | 30 | main = 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 | ||
83 | parseNetCrypto :: ByteString -> SockAddr -> Either String (NetCrypto, SockAddr) | 83 | parseNetCrypto :: ByteString -> SockAddr -> Either String (NetCrypto, SockAddr) |
84 | parseNetCrypto pkt@(B.uncons -> Just (0x1a,_)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetHandshake <$> runGet get pkt | 84 | parseNetCrypto (B.uncons -> Just (0x1a,pkt)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetHandshake <$> runGet get pkt |
85 | parseNetCrypto pkt@(B.uncons -> Just (0x1b,_)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetCrypto <$> runGet get pkt | 85 | parseNetCrypto (B.uncons -> Just (0x1b,pkt)) saddr = left ("parseNetCrypto: "++) $ (,saddr) . NetCrypto <$> runGet get pkt |
86 | parseNetCrypto _ _ = Left "parseNetCrypto: ?" | 86 | parseNetCrypto _ _ = Left "parseNetCrypto: ?" |
87 | 87 | ||
88 | encodeNetCrypto :: NetCrypto -> SockAddr -> (ByteString, SockAddr) | 88 | encodeNetCrypto :: 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 | ||
375 | instance Sized CookieData where | 376 | instance Sized CookieData where |
376 | size = ConstSize 72 | 377 | size = ConstSize 72 |