Last active
April 10, 2022 17:22
-
-
Save edef1c/847a90adf21f97ce0f5c24bebd35f099 to your computer and use it in GitHub Desktop.
wireguard-go key dumping patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 4181bdea33c11bc0209f1951315107cf0fcff11a Mon Sep 17 00:00:00 2001 | |
From: edef <[email protected]> | |
Date: Sun, 10 Apr 2022 17:19:29 +0000 | |
Subject: [PATCH] key dumping | |
Same output format as extract-keys.sh | |
Signed-off-by: edef <[email protected]> | |
--- | |
device/noise-protocol.go | 15 +++++++++++++++ | |
1 file changed, 15 insertions(+) | |
diff --git a/device/noise-protocol.go b/device/noise-protocol.go | |
index ffa0452..3a0437f 100644 | |
--- a/device/noise-protocol.go | |
+++ b/device/noise-protocol.go | |
@@ -6,6 +6,7 @@ | |
package device | |
import ( | |
+ "encoding/base64" | |
"errors" | |
"fmt" | |
"sync" | |
@@ -132,6 +133,18 @@ type Handshake struct { | |
lastSentHandshake time.Time | |
} | |
+func (device *Device) dumpKeys(handshake *Handshake) { | |
+ fmt.Println("New handshake session:") | |
+ for k, v := range map[string][]byte{ | |
+ "LOCAL_STATIC_PRIVATE_KEY": device.staticIdentity.privateKey[:], | |
+ "REMOTE_STATIC_PUBLIC_KEY": handshake.remoteStatic[:], | |
+ "LOCAL_EPHEMERAL_PRIVATE_KEY": handshake.localEphemeral[:], | |
+ "PRESHARED_KEY": handshake.presharedKey[:], | |
+ } { | |
+ fmt.Printf(" %s = %s\n", k, base64.StdEncoding.EncodeToString(v)) | |
+ } | |
+} | |
+ | |
var ( | |
InitialChainKey [blake2s.Size]byte | |
InitialHash [blake2s.Size]byte | |
@@ -192,6 +205,7 @@ func (device *Device) CreateMessageInitiation(peer *Peer) (*MessageInitiation, e | |
if err != nil { | |
return nil, err | |
} | |
+ device.dumpKeys(handshake) | |
handshake.mixHash(handshake.remoteStatic[:]) | |
@@ -380,6 +394,7 @@ func (device *Device) CreateMessageResponse(peer *Peer) (*MessageResponse, error | |
if err != nil { | |
return nil, err | |
} | |
+ device.dumpKeys(handshake) | |
msg.Ephemeral = handshake.localEphemeral.publicKey() | |
handshake.mixHash(msg.Ephemeral[:]) | |
handshake.mixKey(msg.Ephemeral[:]) | |
-- | |
2.35.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment