diff options
Diffstat (limited to 'DHTTransport.hs')
-rw-r--r-- | DHTTransport.hs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/DHTTransport.hs b/DHTTransport.hs index 013fa322..ac263cdc 100644 --- a/DHTTransport.hs +++ b/DHTTransport.hs | |||
@@ -307,15 +307,18 @@ forwardDHTRequests crypto closeLookup dht = dht { awaitMessage = await' } | |||
307 | m -> pass m | 307 | m -> pass m |
308 | 308 | ||
309 | encrypt :: TransportCrypto -> DHTMessage ((,) Nonce8) -> NodeInfo -> (DHTMessage Encrypted8, NodeInfo) | 309 | encrypt :: TransportCrypto -> DHTMessage ((,) Nonce8) -> NodeInfo -> (DHTMessage Encrypted8, NodeInfo) |
310 | encrypt crypto msg ni = (transcode (encryptMessage crypto) msg, ni) | 310 | encrypt crypto msg ni = ( transcode (encryptMessage crypto (id2key $ nodeId ni)) msg |
311 | , ni ) | ||
311 | 312 | ||
312 | encryptMessage :: Serialize a => | 313 | encryptMessage :: Serialize a => |
313 | TransportCrypto -> Nonce24 -> Either (Nonce8,a) (Assym (Nonce8,a)) -> Encrypted8 a | 314 | TransportCrypto -> |
314 | encryptMessage crypto n (Right assym) = E8 $ ToxCrypto.encrypt secret plain | 315 | PublicKey -> |
316 | Nonce24 -> Either (Nonce8,a) (Assym (Nonce8,a)) -> Encrypted8 a | ||
317 | encryptMessage crypto destKey n (Right assym) = E8 $ ToxCrypto.encrypt secret plain | ||
315 | where | 318 | where |
316 | secret = computeSharedSecret (transportSecret crypto) (senderKey assym) n | 319 | secret = computeSharedSecret (transportSecret crypto) destKey n |
317 | plain = encodePlain $ swap $ assymData assym | 320 | plain = encodePlain $ swap $ assymData assym |
318 | encryptMessage crypto n (Left plain) = _todo -- need cached public key. | 321 | encryptMessage crypto destKey n (Left plain) = _todo -- need cached public key. |
319 | 322 | ||
320 | decrypt :: TransportCrypto -> DHTMessage Encrypted8 -> NodeInfo -> Either String (DHTMessage ((,) Nonce8), NodeInfo) | 323 | decrypt :: TransportCrypto -> DHTMessage Encrypted8 -> NodeInfo -> Either String (DHTMessage ((,) Nonce8), NodeInfo) |
321 | decrypt crypto msg ni = (, ni) <$> (sequenceMessage $ transcode (decryptMessage crypto) msg) | 324 | decrypt crypto msg ni = (, ni) <$> (sequenceMessage $ transcode (decryptMessage crypto) msg) |