pipes-cacophony 0.1.0 → 0.1.1
raw patch · 7 files changed
+317/−340 lines, 7 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- .travis.yml +1/−1
- changelog.md +10/−0
- pipes-cacophony.cabal +7/−6
- src/Pipes/Noise.hs +56/−69
- tests/.hlint +6/−0
- tests/Handshake.hs +41/−57
- tests/HandshakeStates.hs +196/−207
.travis.yml view
@@ -81,4 +81,4 @@ # If there are no other `.tar.gz` files in `dist`, this can be even simpler: # `cabal install --force-reinstalls dist/*-*.tar.gz` - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&- (cd dist && cabal install --force-reinstalls "$SRC_TGZ")+ (cd dist && cabal install --enable-tests --run-tests --force-reinstalls "$SRC_TGZ")
changelog.md view
@@ -1,3 +1,13 @@+# 0.1.1++* Enabled test verification on sdist package (for unit testing)++* Brought code in line with cacophony API changes++* Fixed build problems with cabal file++* Refactored unit tests+ # 0.1.0 * First version.
pipes-cacophony.cabal view
@@ -1,5 +1,5 @@ name: pipes-cacophony-version: 0.1.0+version: 0.1.1 synopsis: Pipes for Noise-secured network connections. license: PublicDomain license-file: LICENSE@@ -20,6 +20,7 @@ README.md changelog.md LICENSE+ tests/.hlint source-repository head type: git@@ -44,7 +45,7 @@ library build-depends:- base >=4.8 && <4.9,+ base >=4.8 && <5, bytestring, cacophony, pipes@@ -70,7 +71,7 @@ aeson, async, auto-update,- base >=4.8 && <4.9,+ base >=4.8 && <5, base64-bytestring, bytestring, cacophony,@@ -98,7 +99,7 @@ build-depends: aeson, async,- base >=4.8 && <4.9,+ base >=4.8 && <5, base64-bytestring, bytestring, cacophony,@@ -127,7 +128,7 @@ build-depends: async,- base >= 4.8 && < 4.9,+ base >=4.8 && <5, bytestring, cacophony, mtl,@@ -155,5 +156,5 @@ buildable: False else build-depends:- base >= 4.8 && < 4.9,+ base >=4.8 && <5, hlint
src/Pipes/Noise.hs view
@@ -81,7 +81,6 @@ import Crypto.Noise.Cipher (Plaintext(..), Cipher) import Crypto.Noise.Curve (Curve)-import Crypto.Noise.Descriptors import Crypto.Noise.Hash (Hash) import Crypto.Noise.Handshake import Crypto.Noise.Types (bsToSB', sbToBS')@@ -97,229 +96,229 @@ => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNNIPipe hs csmv = twoMessageI hs csmv noiseNNI1 noiseNNI2+noiseNNIPipe = twoMessageI noiseNNRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNNRPipe hs csmv = twoMessageR hs csmv noiseNNR1 noiseNNR2+noiseNNRPipe = twoMessageR noiseKNIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKNIPipe hs csmv = twoMessageI hs csmv noiseKNI1 noiseKNI2+noiseKNIPipe = twoMessageI noiseKNRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKNRPipe hs csmv = twoMessageR hs csmv noiseKNR1 noiseKNR2+noiseKNRPipe = twoMessageR noiseNKIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNKIPipe hs csmv = twoMessageI hs csmv noiseNKI1 noiseNKI2+noiseNKIPipe = twoMessageI noiseNKRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNKRPipe hs csmv = twoMessageR hs csmv noiseNKR1 noiseNKR2+noiseNKRPipe = twoMessageR noiseKKIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKKIPipe hs csmv = twoMessageI hs csmv noiseKKI1 noiseKKI2+noiseKKIPipe = twoMessageI noiseKKRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKKRPipe hs csmv = twoMessageR hs csmv noiseKKR1 noiseKKR2+noiseKKRPipe = twoMessageR noiseNEIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNEIPipe hs csmv = twoMessageI hs csmv noiseNEI1 noiseNEI2+noiseNEIPipe = twoMessageI noiseNERPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNERPipe hs csmv = twoMessageR hs csmv noiseNER1 noiseNER2+noiseNERPipe = twoMessageR noiseKEIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKEIPipe hs csmv = twoMessageI hs csmv noiseKEI1 noiseKEI2+noiseKEIPipe = twoMessageI noiseKERPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKERPipe hs csmv = twoMessageR hs csmv noiseKER1 noiseKER2+noiseKERPipe = twoMessageR noiseNXIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNXIPipe hs csmv = twoMessageI hs csmv noiseNXI1 noiseNXI2+noiseNXIPipe = twoMessageI noiseNXRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNXRPipe hs csmv = twoMessageR hs csmv noiseNXR1 noiseNXR2+noiseNXRPipe = twoMessageR noiseKXIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKXIPipe hs csmv = twoMessageI hs csmv noiseKXI1 noiseKXI2+noiseKXIPipe = twoMessageI noiseKXRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKXRPipe hs csmv = twoMessageR hs csmv noiseKXR1 noiseKXR2+noiseKXRPipe = twoMessageR noiseXNIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXNIPipe hs csmv = threeMessageI hs csmv noiseXNI1 noiseXNI2 noiseXNI3+noiseXNIPipe = threeMessageI noiseXNRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXNRPipe hs csmv = threeMessageR hs csmv noiseXNR1 noiseXNR2 noiseXNR3+noiseXNRPipe = threeMessageR noiseINIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseINIPipe hs csmv = twoMessageI hs csmv noiseINI1 noiseINI2+noiseINIPipe = twoMessageI noiseINRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseINRPipe hs csmv = twoMessageR hs csmv noiseINR1 noiseINR2+noiseINRPipe = twoMessageR noiseXKIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXKIPipe hs csmv = threeMessageI hs csmv noiseXKI1 noiseXKI2 noiseXKI3+noiseXKIPipe = threeMessageI noiseXKRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXKRPipe hs csmv = threeMessageR hs csmv noiseXKR1 noiseXKR2 noiseXKR3+noiseXKRPipe = threeMessageR noiseIKIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseIKIPipe hs csmv = twoMessageI hs csmv noiseIKI1 noiseIKI2+noiseIKIPipe = twoMessageI noiseIKRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseIKRPipe hs csmv = twoMessageR hs csmv noiseIKR1 noiseIKR2+noiseIKRPipe = twoMessageR noiseXEIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXEIPipe hs csmv = threeMessageI hs csmv noiseXEI1 noiseXEI2 noiseXEI3+noiseXEIPipe = threeMessageI noiseXERPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXERPipe hs csmv = threeMessageR hs csmv noiseXER1 noiseXER2 noiseXER3+noiseXERPipe = threeMessageR noiseIEIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseIEIPipe hs csmv = twoMessageI hs csmv noiseIEI1 noiseIEI2+noiseIEIPipe = twoMessageI noiseIERPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseIERPipe hs csmv = twoMessageR hs csmv noiseIER1 noiseIER2+noiseIERPipe = twoMessageR noiseXXIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXXIPipe hs csmv = threeMessageI hs csmv noiseXXI1 noiseXXI2 noiseXXI3+noiseXXIPipe = threeMessageI noiseXXRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXXRPipe hs csmv = threeMessageR hs csmv noiseXXR1 noiseXXR2 noiseXXR3+noiseXXRPipe = threeMessageR noiseIXIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseIXIPipe hs csmv = twoMessageI hs csmv noiseIXI1 noiseIXI2+noiseIXIPipe = twoMessageI noiseIXRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseIXRPipe hs csmv = twoMessageR hs csmv noiseIXR1 noiseIXR2+noiseIXRPipe = twoMessageR noiseNIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNIPipe hs csmv = oneMessageI hs csmv noiseNI1+noiseNIPipe = oneMessageI noiseNRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseNRPipe hs csmv = oneMessageR hs csmv noiseNR1+noiseNRPipe = oneMessageR noiseKIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKIPipe hs csmv = oneMessageI hs csmv noiseKI1+noiseKIPipe = oneMessageI noiseKRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseKRPipe hs csmv = oneMessageR hs csmv noiseKR1+noiseKRPipe = oneMessageR noiseXIPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXIPipe hs csmv = oneMessageI hs csmv noiseXI1+noiseXIPipe = oneMessageI noiseXRPipe :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c) -> HandshakePipe IO ()-noiseXRPipe hs csmv = oneMessageR hs csmv noiseXR1+noiseXRPipe = oneMessageR messageEncryptPipe :: Cipher c => MVar (CipherStatePair c)@@ -349,10 +348,9 @@ oneMessageI :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c)- -> DescriptorIO c d h ByteString -> HandshakePipe IO ()-oneMessageI hs csmv desc1 = do- (msg1, cs1, _) <- lift $ writeHandshakeMsgFinal hs desc1 emptyPT+oneMessageI hs csmv = do+ (msg1, cs1, _) <- lift $ writeMessageFinal hs emptyPT yield msg1 lift $ putMVar csmv (cs1, undefined)@@ -360,39 +358,34 @@ oneMessageR :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c)- -> (ByteString -> Descriptor c d h ByteString) -> HandshakePipe IO ()-oneMessageR hs csmv desc1 = do+oneMessageR hs csmv = do msg1 <- await - let (_, cs1, _) = readHandshakeMsgFinal hs msg1 desc1+ let (_, cs1, _) = readMessageFinal hs msg1 lift $ putMVar csmv (undefined, cs1) twoMessageI :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c)- -> DescriptorIO c d h ByteString- -> (ByteString -> Descriptor c d h ByteString) -> HandshakePipe IO ()-twoMessageI hs csmv desc1 desc2 = do- (msg1, hs') <- lift $ writeHandshakeMsg hs desc1 emptyPT+twoMessageI hs csmv = do+ (msg1, hs') <- lift $ writeMessage hs emptyPT yield msg1 msg2 <- await- let (_, cs1, cs2) = readHandshakeMsgFinal hs' msg2 desc2+ let (_, cs1, cs2) = readMessageFinal hs' msg2 lift $ putMVar csmv (cs1, cs2) twoMessageR :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c)- -> (ByteString -> Descriptor c d h ByteString)- -> DescriptorIO c d h ByteString -> HandshakePipe IO ()-twoMessageR hs csmv desc1 desc2 = do+twoMessageR hs csmv = do msg1 <- await - let (_, hs') = readHandshakeMsg hs msg1 desc1- (msg2, cs1, cs2) <- lift $ writeHandshakeMsgFinal hs' desc2 emptyPT+ let (_, hs') = readMessage hs msg1+ (msg2, cs1, cs2) <- lift $ writeMessageFinal hs' emptyPT lift $ putMVar csmv (cs2, cs1) yield msg2@@ -400,17 +393,14 @@ threeMessageI :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c)- -> DescriptorIO c d h ByteString- -> (ByteString -> Descriptor c d h ByteString)- -> DescriptorIO c d h ByteString -> HandshakePipe IO ()-threeMessageI hs csmv desc1 desc2 desc3 = do- (msg1, hs') <- lift $ writeHandshakeMsg hs desc1 emptyPT+threeMessageI hs csmv = do+ (msg1, hs') <- lift $ writeMessage hs emptyPT yield msg1 msg2 <- await- let (_, hs'') = readHandshakeMsg hs' msg2 desc2- (msg3, cs1, cs2) <- lift $ writeHandshakeMsgFinal hs'' desc3 emptyPT+ let (_, hs'') = readMessage hs' msg2+ (msg3, cs1, cs2) <- lift $ writeMessageFinal hs'' emptyPT lift $ putMVar csmv (cs1, cs2) yield msg3@@ -418,17 +408,14 @@ threeMessageR :: (Cipher c, Curve d, Hash h) => HandshakeState c d h -> MVar (CipherStatePair c)- -> (ByteString -> Descriptor c d h ByteString)- -> DescriptorIO c d h ByteString- -> (ByteString -> Descriptor c d h ByteString) -> HandshakePipe IO ()-threeMessageR hs csmv desc1 desc2 desc3 = do+threeMessageR hs csmv = do msg1 <- await - let (_, hs') = readHandshakeMsg hs msg1 desc1- (msg2, hs'') <- lift $ writeHandshakeMsg hs' desc2 emptyPT+ let (_, hs') = readMessage hs msg1+ (msg2, hs'') <- lift $ writeMessage hs' emptyPT yield msg2 msg3 <- await- let (_, cs1, cs2) = readHandshakeMsgFinal hs'' msg3 desc3+ let (_, cs1, cs2) = readMessageFinal hs'' msg3 lift $ putMVar csmv (cs2, cs1)
+ tests/.hlint view
@@ -0,0 +1,6 @@+import "hint" HLint.Default+import "hint" HLint.Dollar+import "hint" HLint.Generalise+import "hint" HLint.HLint++ignore "Reduce duplication"
tests/Handshake.hs view
@@ -1,10 +1,6 @@ {-# LANGUAGE OverloadedStrings, RankNTypes #-} module Handshake where -import Imports-import Instances()-import HandshakeStates- import Control.Concurrent.Async (concurrently) import Control.Concurrent.MVar (MVar, newEmptyMVar, takeMVar, putMVar, newMVar)@@ -12,24 +8,13 @@ import Data.ByteString (ByteString) import Crypto.Noise.Cipher.ChaChaPoly1305-import Crypto.Noise.Curve-import Crypto.Noise.Curve.Curve25519-import Crypto.Noise.Types import Pipes hiding (Proxy) import Pipes.Noise -is :: KeyPair Curve25519-is = curveBytesToPair . bsToSB' $ "I\f\232\218A\210\230\147\FS\222\167\v}l\243!\168.\ESC\t\SYN\"\169\179A`\DC28\211\169tC"--rs :: KeyPair Curve25519-rs = curveBytesToPair . bsToSB' $ "\ETB\157\&7\DC2\252\NUL\148\172\148\133\218\207\&8\221y\144\209\168FX\224Ser_\178|\153.\FSg&"--re :: KeyPair Curve25519-re = curveBytesToPair . bsToSB' $ "<\231\151\151\180\217\146\DLEI}\160N\163iKc\162\210Y\168R\213\206&gm\169r\SUB[\\'"--handshakeKeys :: HandshakeKeys-handshakeKeys = HandshakeKeys is rs re+import HandshakeStates+import Imports+import Instances() data HandshakeType = NoiseNN | NoiseKN@@ -53,50 +38,49 @@ deriving (Eq) mkHandshakePipe :: HandshakeType- -> HandshakeKeys -> MVar (CipherStatePair ChaChaPoly1305) -> MVar (CipherStatePair ChaChaPoly1305) -> (HandshakePipe IO (), HandshakePipe IO ())-mkHandshakePipe ht hks csmv1 csmv2 =+mkHandshakePipe ht csmv1 csmv2 = case ht of NoiseNN -> (noiseNNIPipe noiseNNIHS csmv1, noiseNNRPipe noiseNNRHS csmv2)- NoiseKN -> (noiseKNIPipe (noiseKNIHS hks) csmv1,- noiseKNRPipe (noiseKNRHS hks) csmv2)- NoiseNK -> (noiseNKIPipe (noiseNKIHS hks) csmv1,- noiseNKRPipe (noiseNKRHS hks) csmv2)- NoiseKK -> (noiseKKIPipe (noiseKKIHS hks) csmv1,- noiseKKRPipe (noiseKKRHS hks) csmv2)- NoiseNE -> (noiseNEIPipe (noiseNEIHS hks) csmv1,- noiseNERPipe (noiseNERHS hks) csmv2)- NoiseKE -> (noiseKEIPipe (noiseKEIHS hks) csmv1,- noiseKERPipe (noiseKERHS hks) csmv2)- NoiseNX -> (noiseNXIPipe (noiseNXIHS hks) csmv1,- noiseNXRPipe (noiseNXRHS hks) csmv2)- NoiseKX -> (noiseKXIPipe (noiseKXIHS hks) csmv1,- noiseKXRPipe (noiseKXRHS hks) csmv2)- NoiseXN -> (noiseXNIPipe (noiseXNIHS hks) csmv1,- noiseXNRPipe (noiseXNRHS hks) csmv2)- NoiseIN -> (noiseINIPipe (noiseINIHS hks) csmv1,- noiseINRPipe (noiseINRHS hks) csmv2)- NoiseXK -> (noiseXKIPipe (noiseXKIHS hks) csmv1,- noiseXKRPipe (noiseXKRHS hks) csmv2)- NoiseIK -> (noiseIKIPipe (noiseIKIHS hks) csmv1,- noiseIKRPipe (noiseIKRHS hks) csmv2)- NoiseXE -> (noiseXEIPipe (noiseXEIHS hks) csmv1,- noiseXERPipe (noiseXERHS hks) csmv2)- NoiseIE -> (noiseIEIPipe (noiseIEIHS hks) csmv1,- noiseIERPipe (noiseIERHS hks) csmv2)- NoiseXX -> (noiseXXIPipe (noiseXXIHS hks) csmv1,- noiseXXRPipe (noiseXXRHS hks) csmv2)- NoiseIX -> (noiseIXIPipe (noiseIXIHS hks) csmv1,- noiseIXRPipe (noiseIXRHS hks) csmv2)- NoiseN -> (noiseNIPipe (noiseNIHS hks) csmv1,- noiseNRPipe (noiseNRHS hks) csmv2)- NoiseK -> (noiseKIPipe (noiseKIHS hks) csmv1,- noiseKRPipe (noiseKRHS hks) csmv2)- NoiseX -> (noiseXIPipe (noiseXIHS hks) csmv1,- noiseXRPipe (noiseXRHS hks) csmv2)+ NoiseKN -> (noiseKNIPipe noiseKNIHS csmv1,+ noiseKNRPipe noiseKNRHS csmv2)+ NoiseNK -> (noiseNKIPipe noiseNKIHS csmv1,+ noiseNKRPipe noiseNKRHS csmv2)+ NoiseKK -> (noiseKKIPipe noiseKKIHS csmv1,+ noiseKKRPipe noiseKKRHS csmv2)+ NoiseNE -> (noiseNEIPipe noiseNEIHS csmv1,+ noiseNERPipe noiseNERHS csmv2)+ NoiseKE -> (noiseKEIPipe noiseKEIHS csmv1,+ noiseKERPipe noiseKERHS csmv2)+ NoiseNX -> (noiseNXIPipe noiseNXIHS csmv1,+ noiseNXRPipe noiseNXRHS csmv2)+ NoiseKX -> (noiseKXIPipe noiseKXIHS csmv1,+ noiseKXRPipe noiseKXRHS csmv2)+ NoiseXN -> (noiseXNIPipe noiseXNIHS csmv1,+ noiseXNRPipe noiseXNRHS csmv2)+ NoiseIN -> (noiseINIPipe noiseINIHS csmv1,+ noiseINRPipe noiseINRHS csmv2)+ NoiseXK -> (noiseXKIPipe noiseXKIHS csmv1,+ noiseXKRPipe noiseXKRHS csmv2)+ NoiseIK -> (noiseIKIPipe noiseIKIHS csmv1,+ noiseIKRPipe noiseIKRHS csmv2)+ NoiseXE -> (noiseXEIPipe noiseXEIHS csmv1,+ noiseXERPipe noiseXERHS csmv2)+ NoiseIE -> (noiseIEIPipe noiseIEIHS csmv1,+ noiseIERPipe noiseIERHS csmv2)+ NoiseXX -> (noiseXXIPipe noiseXXIHS csmv1,+ noiseXXRPipe noiseXXRHS csmv2)+ NoiseIX -> (noiseIXIPipe noiseIXIHS csmv1,+ noiseIXRPipe noiseIXRHS csmv2)+ NoiseN -> (noiseNIPipe noiseNIHS csmv1,+ noiseNRPipe noiseNRHS csmv2)+ NoiseK -> (noiseKIPipe noiseKIHS csmv1,+ noiseKRPipe noiseKRHS csmv2)+ NoiseX -> (noiseXIPipe noiseXIHS csmv1,+ noiseXRPipe noiseXRHS csmv2) aggregator :: MVar [ByteString] -> Consumer' ByteString IO ()@@ -125,7 +109,7 @@ csmv1 <- newEmptyMVar csmv2 <- newEmptyMVar - let (initPipe, respPipe) = mkHandshakePipe ht handshakeKeys csmv1 csmv2+ let (initPipe, respPipe) = mkHandshakePipe ht csmv1 csmv2 _ <- concurrently (runEffect (mVarProducer msgmv1 >-> initPipe >-> mVarConsumer msgmv2)) (runEffect (mVarProducer msgmv2 >-> respPipe >-> mVarConsumer msgmv1))
tests/HandshakeStates.hs view
@@ -1,448 +1,437 @@-{-# LANGUAGE OverloadedStrings, RecordWildCards #-}+{-# LANGUAGE OverloadedStrings #-} module HandshakeStates where -import Data.ByteString (ByteString)-import Data.Proxy--import Crypto.Noise.Descriptors-import Crypto.Noise.Handshake-import Crypto.Noise.Cipher import Crypto.Noise.Cipher.ChaChaPoly1305 import Crypto.Noise.Curve import Crypto.Noise.Curve.Curve25519-import Crypto.Noise.Hash+import Crypto.Noise.Handshake+import Crypto.Noise.HandshakePatterns import Crypto.Noise.Hash.SHA256 import Crypto.Noise.Types -data HandshakeKeys =- HandshakeKeys { initStatic :: KeyPair Curve25519- , respStatic :: KeyPair Curve25519- , respEphemeral :: KeyPair Curve25519- }+initStatic :: KeyPair Curve25519+initStatic = curveBytesToPair . bsToSB' $ "I\f\232\218A\210\230\147\FS\222\167\v}l\243!\168.\ESC\t\SYN\"\169\179A`\DC28\211\169tC" -makeHSN :: ByteString -> ScrubbedBytes-makeHSN hs = concatSB [p, convert hs, u, a, u, b, u, c]- where- a = curveName (Proxy :: Proxy Curve25519)- b = cipherName (Proxy :: Proxy ChaChaPoly1305)- c = hashName (Proxy :: Proxy SHA256)- u = bsToSB' "_"- p = bsToSB' "Noise_"+respStatic :: KeyPair Curve25519+respStatic = curveBytesToPair . bsToSB' $ "\ETB\157\&7\DC2\252\NUL\148\172\148\133\218\207\&8\221y\144\209\168FX\224Ser_\178|\153.\FSg&" +respEphemeral :: KeyPair Curve25519+respEphemeral = curveBytesToPair . bsToSB' $ "<\231\151\151\180\217\146\DLEI}\160N\163iKc\162\210Y\168R\213\206&gm\169r\SUB[\\'"+ noiseNNIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256 noiseNNIHS = handshakeState- (makeHSN "NN")- Nothing+ "NN"+ noiseNNI+ "" Nothing Nothing Nothing Nothing -noiseKNIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKNIHS HandshakeKeys{..} =+noiseKNIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKNIHS = handshakeState- (makeHSN "KN")+ "KN"+ noiseKNI+ "" (Just initStatic) Nothing Nothing Nothing- (Just noiseKNI0) -noiseNKIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNKIHS HandshakeKeys{..} =+noiseNKIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNKIHS = handshakeState- (makeHSN "NK")+ "NK"+ noiseNKI+ "" Nothing Nothing (Just (snd respStatic)) Nothing- (Just noiseNKI0) -noiseKKIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKKIHS HandshakeKeys{..} =+noiseKKIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKKIHS = handshakeState- (makeHSN "KK")+ "KK"+ noiseKKI+ "" (Just initStatic) Nothing (Just (snd respStatic)) Nothing- (Just noiseKKI0) -noiseNEIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNEIHS HandshakeKeys{..} =+noiseNEIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNEIHS = handshakeState- (makeHSN "NE")+ "NE"+ noiseNEI+ "" Nothing Nothing (Just (snd respStatic)) (Just (snd respEphemeral))- (Just noiseNEI0) -noiseKEIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKEIHS HandshakeKeys{..} =+noiseKEIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKEIHS = handshakeState- (makeHSN "KE")+ "KE"+ noiseKEI+ "" (Just initStatic) Nothing (Just (snd respStatic)) (Just (snd respEphemeral))- (Just noiseKEI0) -noiseNXIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNXIHS HandshakeKeys{..} =+noiseNXIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNXIHS = handshakeState- (makeHSN "NX")- Nothing+ "NX"+ noiseNXI+ "" Nothing Nothing Nothing Nothing -noiseKXIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKXIHS HandshakeKeys{..} =+noiseKXIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKXIHS = handshakeState- (makeHSN "KX")+ "KX"+ noiseKXI+ "" (Just initStatic) Nothing (Just (snd respStatic)) Nothing- (Just noiseKXI0) -noiseXNIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXNIHS HandshakeKeys{..} =+noiseXNIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXNIHS = handshakeState- (makeHSN "XN")+ "XN"+ noiseXNI+ "" (Just initStatic) Nothing Nothing Nothing- Nothing -noiseINIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseINIHS HandshakeKeys{..} =+noiseINIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseINIHS = handshakeState- (makeHSN "IN")+ "IN"+ noiseINI+ "" (Just initStatic) Nothing Nothing Nothing- Nothing -noiseXKIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXKIHS HandshakeKeys{..} =+noiseXKIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXKIHS = handshakeState- (makeHSN "XK")+ "XK"+ noiseXKI+ "" (Just initStatic) Nothing (Just (snd respStatic)) Nothing- (Just noiseXKI0) -noiseIKIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseIKIHS HandshakeKeys{..} =+noiseIKIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseIKIHS = handshakeState- (makeHSN "IK")+ "IK"+ noiseIKI+ "" (Just initStatic) Nothing (Just (snd respStatic)) Nothing- (Just noiseIKI0) -noiseXEIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXEIHS HandshakeKeys{..} =+noiseXEIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXEIHS = handshakeState- (makeHSN "XE")+ "XE"+ noiseXEI+ "" (Just initStatic) Nothing (Just (snd respStatic)) (Just (snd respEphemeral))- (Just noiseXEI0) -noiseIEIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseIEIHS HandshakeKeys{..} =+noiseIEIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseIEIHS = handshakeState- (makeHSN "IE")+ "IE"+ noiseIEI+ "" (Just initStatic) Nothing (Just (snd respStatic)) (Just (snd respEphemeral))- (Just noiseIEI0) -noiseXXIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXXIHS HandshakeKeys{..} =+noiseXXIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXXIHS = handshakeState- (makeHSN "XX")+ "XX"+ noiseXXI+ "" (Just initStatic) Nothing Nothing Nothing- Nothing -noiseIXIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseIXIHS HandshakeKeys{..} =+noiseIXIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseIXIHS = handshakeState- (makeHSN "IX")+ "IX"+ noiseIXI+ "" (Just initStatic) Nothing Nothing Nothing- Nothing -noiseNIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNIHS HandshakeKeys{..} =+noiseNIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNIHS = handshakeState- (makeHSN "N")+ "N"+ noiseNI+ "" Nothing Nothing (Just (snd respStatic)) Nothing- (Just noiseNI0) -noiseKIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKIHS HandshakeKeys{..} =+noiseKIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKIHS = handshakeState- (makeHSN "K")+ "K"+ noiseKI+ "" (Just initStatic) Nothing (Just (snd respStatic)) Nothing- (Just noiseKI0) -noiseXIHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXIHS HandshakeKeys{..} =+noiseXIHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXIHS = handshakeState- (makeHSN "X")+ "X"+ noiseXI+ "" (Just initStatic) Nothing (Just (snd respStatic)) Nothing- (Just noiseXI0) noiseNNRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256 noiseNNRHS = handshakeState- (makeHSN "NN")- Nothing+ "NN"+ noiseNNR+ "" Nothing Nothing Nothing Nothing -noiseKNRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKNRHS HandshakeKeys{..} =+noiseKNRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKNRHS = handshakeState- (makeHSN "KN")+ "KN"+ noiseKNR+ "" Nothing Nothing (Just (snd initStatic)) Nothing- (Just noiseKNR0) -noiseNKRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNKRHS HandshakeKeys{..} =+noiseNKRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNKRHS = handshakeState- (makeHSN "NK")+ "NK"+ noiseNKR+ "" (Just respStatic) Nothing Nothing Nothing- (Just noiseNKR0) -noiseKKRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKKRHS HandshakeKeys{..} =+noiseKKRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKKRHS = handshakeState- (makeHSN "KK")+ "KK"+ noiseKKR+ "" (Just respStatic) Nothing (Just (snd initStatic)) Nothing- (Just noiseKKR0) -noiseNERHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNERHS HandshakeKeys{..} =+noiseNERHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNERHS = handshakeState- (makeHSN "NE")+ "NE"+ noiseNER+ "" (Just respStatic) (Just respEphemeral) Nothing Nothing- (Just noiseNER0) -noiseKERHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKERHS HandshakeKeys{..} =+noiseKERHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKERHS = handshakeState- (makeHSN "KE")+ "KE"+ noiseKER+ "" (Just respStatic) (Just respEphemeral) (Just (snd initStatic)) Nothing- (Just noiseKER0) -noiseNXRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNXRHS HandshakeKeys{..} =+noiseNXRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNXRHS = handshakeState- (makeHSN "NX")+ "NX"+ noiseNXR+ "" (Just respStatic) Nothing Nothing Nothing- Nothing -noiseKXRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKXRHS HandshakeKeys{..} =+noiseKXRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKXRHS = handshakeState- (makeHSN "KX")+ "KX"+ noiseKXR+ "" (Just respStatic) Nothing (Just (snd initStatic)) Nothing- (Just noiseKXR0) -noiseXNRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXNRHS HandshakeKeys{..} =+noiseXNRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXNRHS = handshakeState- (makeHSN "XN")- Nothing+ "XN"+ noiseXNR+ "" Nothing Nothing Nothing Nothing -noiseINRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseINRHS HandshakeKeys{..} =+noiseINRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseINRHS = handshakeState- (makeHSN "IN")- Nothing+ "IN"+ noiseINR+ "" Nothing Nothing Nothing Nothing -noiseXKRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXKRHS HandshakeKeys{..} =+noiseXKRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXKRHS = handshakeState- (makeHSN "XK")+ "XK"+ noiseXKR+ "" (Just respStatic) Nothing Nothing Nothing- (Just noiseXKR0) -noiseIKRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseIKRHS HandshakeKeys{..} =+noiseIKRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseIKRHS = handshakeState- (makeHSN "IK")+ "IK"+ noiseIKR+ "" (Just respStatic) Nothing Nothing Nothing- (Just noiseIKR0) -noiseXERHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXERHS HandshakeKeys{..} =+noiseXERHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXERHS = handshakeState- (makeHSN "XE")+ "XE"+ noiseXER+ "" (Just respStatic) (Just respEphemeral) Nothing Nothing- (Just noiseXER0) -noiseIERHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseIERHS HandshakeKeys{..} =+noiseIERHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseIERHS = handshakeState- (makeHSN "IE")+ "IE"+ noiseIER+ "" (Just respStatic) (Just respEphemeral) Nothing Nothing- (Just noiseIER0) -noiseXXRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXXRHS HandshakeKeys{..} =+noiseXXRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXXRHS = handshakeState- (makeHSN "XX")+ "XX"+ noiseXXR+ "" (Just respStatic) Nothing Nothing Nothing- Nothing -noiseIXRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseIXRHS HandshakeKeys{..} =+noiseIXRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseIXRHS = handshakeState- (makeHSN "IX")+ "IX"+ noiseIXR+ "" (Just respStatic) Nothing Nothing Nothing- Nothing -noiseNRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseNRHS HandshakeKeys{..} =+noiseNRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseNRHS = handshakeState- (makeHSN "N")+ "N"+ noiseNR+ "" (Just respStatic) Nothing Nothing Nothing- Nothing -noiseKRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseKRHS HandshakeKeys{..} =+noiseKRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseKRHS = handshakeState- (makeHSN "K")+ "K"+ noiseKR+ "" (Just respStatic) Nothing (Just (snd initStatic)) Nothing- (Just noiseKR0) -noiseXRHS :: HandshakeKeys- -> HandshakeState ChaChaPoly1305 Curve25519 SHA256-noiseXRHS HandshakeKeys{..} =+noiseXRHS :: HandshakeState ChaChaPoly1305 Curve25519 SHA256+noiseXRHS = handshakeState- (makeHSN "X")+ "X"+ noiseXR+ "" (Just respStatic) Nothing Nothing Nothing- (Just noiseXR0)--