Skip to content

Instantly share code, notes, and snippets.

@edef1c
Last active April 10, 2022 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edef1c/847a90adf21f97ce0f5c24bebd35f099 to your computer and use it in GitHub Desktop.
Save edef1c/847a90adf21f97ce0f5c24bebd35f099 to your computer and use it in GitHub Desktop.
wireguard-go key dumping patch
From 4181bdea33c11bc0209f1951315107cf0fcff11a Mon Sep 17 00:00:00 2001
From: edef <edef@edef.eu>
Date: Sun, 10 Apr 2022 17:19:29 +0000
Subject: [PATCH] key dumping
Same output format as extract-keys.sh
Signed-off-by: edef <edef@edef.eu>
---
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