aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/crypto_test.go
blob: 6b4afb16a456847b63b941a64885e0f0ce371230 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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")
    // }

}