diff options
author | Felix Lange <fjl@twurst.com> | 2015-02-27 10:09:53 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-04 19:27:23 +0800 |
commit | 51e01cceca81bc5e82896815754b7c33bb6e6005 (patch) | |
tree | fc3b47378a8947e14b5e5fe9169e0f638c1b14ba /p2p/rlpx_test.go | |
parent | 936dd0f3bc19457c8496af00b181f0a8a2f18d6f (diff) | |
download | dexon-51e01cceca81bc5e82896815754b7c33bb6e6005.tar dexon-51e01cceca81bc5e82896815754b7c33bb6e6005.tar.gz dexon-51e01cceca81bc5e82896815754b7c33bb6e6005.tar.bz2 dexon-51e01cceca81bc5e82896815754b7c33bb6e6005.tar.lz dexon-51e01cceca81bc5e82896815754b7c33bb6e6005.tar.xz dexon-51e01cceca81bc5e82896815754b7c33bb6e6005.tar.zst dexon-51e01cceca81bc5e82896815754b7c33bb6e6005.zip |
p2p: encrypted and authenticated RLPx frame I/O
Diffstat (limited to 'p2p/rlpx_test.go')
-rw-r--r-- | p2p/rlpx_test.go | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/p2p/rlpx_test.go b/p2p/rlpx_test.go index 380d9aba6..b3c2adf8d 100644 --- a/p2p/rlpx_test.go +++ b/p2p/rlpx_test.go @@ -16,14 +16,18 @@ import ( func TestRlpxFrameFake(t *testing.T) { buf := new(bytes.Buffer) - secret := crypto.Sha3() hash := fakeHash([]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) - rw := newRlpxFrameRW(buf, secret, hash, hash) + rw := newRlpxFrameRW(buf, secrets{ + AES: crypto.Sha3(), + MAC: crypto.Sha3(), + IngressMAC: hash, + EgressMAC: hash, + }) golden := unhex(` -000006C2808000000000000000000000 +00828ddae471818bb0bfa6b551d1cb42 01010101010101010101010101010101 -08C40102030400000000000000000000 +ba628a4ba590cb43f7848f41c4382885 01010101010101010101010101010101 01010101010101010101010101010101 `) @@ -75,27 +79,35 @@ func unhex(str string) []byte { func TestRlpxFrameRW(t *testing.T) { var ( + aesSecret = make([]byte, 16) macSecret = make([]byte, 16) egressMACinit = make([]byte, 32) ingressMACinit = make([]byte, 32) ) - for _, s := range [][]byte{macSecret, egressMACinit, ingressMACinit} { + for _, s := range [][]byte{aesSecret, macSecret, egressMACinit, ingressMACinit} { rand.Read(s) } - conn := new(bytes.Buffer) - em1 := sha3.NewKeccak256() - em1.Write(egressMACinit) - im1 := sha3.NewKeccak256() - im1.Write(ingressMACinit) - rw1 := newRlpxFrameRW(conn, macSecret, em1, im1) - - em2 := sha3.NewKeccak256() - em2.Write(ingressMACinit) - im2 := sha3.NewKeccak256() - im2.Write(egressMACinit) - rw2 := newRlpxFrameRW(conn, macSecret, em2, im2) + s1 := secrets{ + AES: aesSecret, + MAC: macSecret, + EgressMAC: sha3.NewKeccak256(), + IngressMAC: sha3.NewKeccak256(), + } + s1.EgressMAC.Write(egressMACinit) + s1.IngressMAC.Write(ingressMACinit) + rw1 := newRlpxFrameRW(conn, s1) + + s2 := secrets{ + AES: aesSecret, + MAC: macSecret, + EgressMAC: sha3.NewKeccak256(), + IngressMAC: sha3.NewKeccak256(), + } + s2.EgressMAC.Write(ingressMACinit) + s2.IngressMAC.Write(egressMACinit) + rw2 := newRlpxFrameRW(conn, s2) // send some messages for i := 0; i < 10; i++ { |