aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-01-19 09:24:09 +0800
committerFelix Lange <fjl@twurst.com>2015-02-06 07:00:34 +0800
commit3b6385b14624faee26445a3d98fa94efdb30d29a (patch)
tree3e95a5752c37dc8c55b0298680158da78ef1c4c1 /p2p
parent714b955d6e03a822af80b566b0fa73098761f57a (diff)
downloadgo-tangerine-3b6385b14624faee26445a3d98fa94efdb30d29a.tar.gz
go-tangerine-3b6385b14624faee26445a3d98fa94efdb30d29a.tar.zst
go-tangerine-3b6385b14624faee26445a3d98fa94efdb30d29a.zip
handshake test to crypto
Diffstat (limited to 'p2p')
-rw-r--r--p2p/crypto.go2
-rw-r--r--p2p/crypto_test.go54
2 files changed, 54 insertions, 2 deletions
diff --git a/p2p/crypto.go b/p2p/crypto.go
index 643bd431e..10c82d3a1 100644
--- a/p2p/crypto.go
+++ b/p2p/crypto.go
@@ -1,11 +1,9 @@
package p2p
import (
- // "bytes"
"crypto/ecdsa"
"crypto/rand"
"fmt"
- // "io"
"github.com/ethereum/go-ethereum/crypto"
"github.com/obscuren/ecies"
diff --git a/p2p/crypto_test.go b/p2p/crypto_test.go
new file mode 100644
index 000000000..6b4afb16a
--- /dev/null
+++ b/p2p/crypto_test.go
@@ -0,0 +1,54 @@
+package p2p
+
+import (
+ // "bytes"
+ "fmt"
+ "testing"
+
+ "github.com/ethereum/go-ethereum/crypto"
+)
+
+func TestCryptoHandshake(t *testing.T) {
+ var err error
+ var sessionToken []byte
+ prvInit, _ := crypto.GenerateKey()
+ pubInit := &prvInit.PublicKey
+ prvResp, _ := crypto.GenerateKey()
+ pubResp := &prvResp.PublicKey
+
+ var initiator, responder *cryptoId
+ if initiator, err = newCryptoId(&peerId{crypto.FromECDSA(prvInit), crypto.FromECDSAPub(pubInit)}); err != nil {
+ return
+ }
+ if responder, err = newCryptoId(&peerId{crypto.FromECDSA(prvResp), crypto.FromECDSAPub(pubResp)}); err != nil {
+ return
+ }
+
+ auth, initNonce, _, _ := initiator.initAuth(responder.pubKeyDER, sessionToken)
+
+ response, remoteRespNonce, remoteInitNonce, remoteRandomPubKey, _ := responder.verifyAuth(auth, sessionToken, pubInit)
+
+ respNonce, randomPubKey, _, _ := initiator.verifyAuthResp(response)
+
+ fmt.Printf("%x\n%x\n%x\n%x\n%x\n%x\n%x\n%x\n", auth, initNonce, response, remoteRespNonce, remoteInitNonce, remoteRandomPubKey, respNonce, randomPubKey)
+ // initSessionToken, initSecretRW, _ := initiator.newSession(initNonce, respNonce, auth, randomPubKey)
+ // respSessionToken, respSecretRW, _ := responder.newSession(remoteInitNonce, remoteRespNonce, auth, remoteRandomPubKey)
+
+ // if !bytes.Equal(initSessionToken, respSessionToken) {
+ // t.Errorf("session tokens do not match")
+ // }
+ // // aesSecret, macSecret, egressMac, ingressMac
+ // if !bytes.Equal(initSecretRW.aesSecret, respSecretRW.aesSecret) {
+ // t.Errorf("AES secrets do not match")
+ // }
+ // if !bytes.Equal(initSecretRW.macSecret, respSecretRW.macSecret) {
+ // t.Errorf("macSecrets do not match")
+ // }
+ // if !bytes.Equal(initSecretRW.egressMac, respSecretRW.egressMac) {
+ // t.Errorf("egressMacs do not match")
+ // }
+ // if !bytes.Equal(initSecretRW.ingressMac, respSecretRW.ingressMac) {
+ // t.Errorf("ingressMacs do not match")
+ // }
+
+}