]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
go test: correct tai64n and formatting
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 1 Jun 2017 17:08:24 +0000 (19:08 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 1 Jun 2017 20:58:38 +0000 (22:58 +0200)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
contrib/external-tests/go/main.go

index 435063d2d1a8c48d8faf57abf3b94106ca4d5de2..4081bb5d0316fe2b58999e6f97795655d54f2e9d 100644 (file)
@@ -41,15 +41,15 @@ func main() {
        preshared, _ := base64.StdEncoding.DecodeString("FpCyhws9cxwWoV4xELtfJvjJN+zQVRPISllRWgeopVE=")
        cs := noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashBLAKE2s)
        hs := noise.NewHandshakeState(noise.Config{
-               CipherSuite:   cs,
-               Random:        rand.Reader,
-               Pattern:       noise.HandshakeIK,
-               Initiator:     true,
-               Prologue:      []byte("WireGuard v1 zx2c4 Jason@zx2c4.com"),
-               PresharedKey:  preshared,
+               CipherSuite:           cs,
+               Random:                rand.Reader,
+               Pattern:               noise.HandshakeIK,
+               Initiator:             true,
+               Prologue:              []byte("WireGuard v1 zx2c4 Jason@zx2c4.com"),
+               PresharedKey:          preshared,
                PresharedKeyPlacement: 2,
-               StaticKeypair: noise.DHKey{Private: ourPrivate, Public: ourPublic},
-               PeerStatic:    theirPublic,
+               StaticKeypair:         noise.DHKey{Private: ourPrivate, Public: ourPublic},
+               PeerStatic:            theirPublic,
        })
        conn, err := net.Dial("udp", "demo.wireguard.io:12913")
        if err != nil {
@@ -61,12 +61,12 @@ func main() {
        now := time.Now()
        tai64n := make([]byte, 12)
        binary.BigEndian.PutUint64(tai64n[:], 4611686018427387914+uint64(now.Unix()))
-       binary.BigEndian.PutUint32(tai64n[8:], uint32(now.UnixNano()))
+       binary.BigEndian.PutUint32(tai64n[8:], uint32(now.Nanosecond()))
        initiationPacket := make([]byte, 8)
-       initiationPacket[0] = 1 // Type: Initiation
-       initiationPacket[1] = 0 // Reserved
-       initiationPacket[2] = 0 // Reserved
-       initiationPacket[3] = 0 // Reserved
+       initiationPacket[0] = 1                                 // Type: Initiation
+       initiationPacket[1] = 0                                 // Reserved
+       initiationPacket[2] = 0                                 // Reserved
+       initiationPacket[3] = 0                                 // Reserved
        binary.LittleEndian.PutUint32(initiationPacket[4:], 28) // Sender index: 28 (arbitrary)
        initiationPacket, _, _ = hs.WriteMessage(initiationPacket, tai64n)
        hasher, _ := blake2s.New(&blake2s.Config{Size: 32})
@@ -130,13 +130,13 @@ func main() {
        pingData := append(append(pingHeader, pingMessage...), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        binary.BigEndian.PutUint16(pingData[10:], ipChecksum(pingData))
        pingPacket := make([]byte, 16)
-       pingPacket[0] = 4 // Type: Data
-       pingPacket[1] = 0 // Reserved
-       pingPacket[2] = 0 // Reserved
-       pingPacket[3] = 0 // Reserved
-       binary.LittleEndian.PutUint32(pingPacket[4:], theirIndex)
-       binary.LittleEndian.PutUint64(pingPacket[8:], 0) // Nonce
-       pingPacket = sendCipher.Encrypt(pingPacket, nil, pingData)
+       pingPacket[0] = 4                                          // Type: Data
+       pingPacket[1] = 0                                          // Reserved
+       pingPacket[2] = 0                                          // Reserved
+       pingPacket[3] = 0                                          // Reserved
+       binary.LittleEndian.PutUint32(pingPacket[4:], theirIndex)  // Their index
+       binary.LittleEndian.PutUint64(pingPacket[8:], 0)           // Nonce
+       pingPacket = sendCipher.Encrypt(pingPacket, nil, pingData) // Payload data
        if _, err := conn.Write(pingPacket); err != nil {
                log.Fatalf("error writing ping message: %s", err)
        }
@@ -174,12 +174,12 @@ func main() {
        }
 
        keepalivePacket := make([]byte, 16)
-       keepalivePacket[0] = 4 // Type: Data
-       keepalivePacket[1] = 0 // Reserved
-       keepalivePacket[2] = 0 // Reserved
-       keepalivePacket[3] = 0 // Reserved
-       binary.LittleEndian.PutUint32(keepalivePacket[4:], theirIndex)
-       binary.LittleEndian.PutUint64(keepalivePacket[8:], 1) // Nonce
+       keepalivePacket[0] = 4                                          // Type: Data
+       keepalivePacket[1] = 0                                          // Reserved
+       keepalivePacket[2] = 0                                          // Reserved
+       keepalivePacket[3] = 0                                          // Reserved
+       binary.LittleEndian.PutUint32(keepalivePacket[4:], theirIndex)  // Their index
+       binary.LittleEndian.PutUint64(keepalivePacket[8:], 1)           // Nonce
        keepalivePacket = sendCipher.Encrypt(keepalivePacket, nil, nil) // Empty data means keepalive
        if _, err := conn.Write(keepalivePacket); err != nil {
                log.Fatalf("error writing keepalive message: %s", err)