1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-04 23:40:26 +08:00

feat: add preshared key

This commit is contained in:
源文雨
2023-08-03 18:01:48 +08:00
parent fda910cb4b
commit b35d2787ad
11 changed files with 145 additions and 46 deletions

View File

@@ -107,7 +107,19 @@ func (wg *WG) init(srcport, dstport uint16) {
}
n := copy(peerkey[:], base14.Decode(k))
if n != 32 {
panic("peer public key length is not 32")
panic("peer public key length < 32")
}
var pshk *[32]byte
if peer.PresharedKey != "" {
k, err := base14.UTF82UTF16BE(helper.StringToBytes(peer.PresharedKey + suffix32))
if err != nil {
panic(err)
}
pshk = &[32]byte{}
n := copy(pshk[:], base14.Decode(k))
if n != 32 {
panic("peer preshared key length < 32")
}
}
wg.me.AddPeer(&link.PeerConfig{
PeerIP: peer.IP,
@@ -115,6 +127,7 @@ func (wg *WG) init(srcport, dstport uint16) {
AllowedIPs: peer.AllowedIPs,
Querys: peer.QueryList,
PubicKey: &peerkey,
PresharedKey: pshk,
KeepAliveDur: peer.KeepAliveSeconds,
QueryTick: peer.QuerySeconds,
MTU: uint16(peer.MTU),