fix(custom): read wireguard presharedkey from peer section
This commit is contained in:
@@ -43,6 +43,17 @@ func (s *Source) readWireguard() (wireguard settings.Wireguard, err error) {
|
|||||||
return wireguard, fmt.Errorf("getting interface section: %w", err)
|
return wireguard, fmt.Errorf("getting interface section: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peerSection, err := iniFile.GetSection("Peer")
|
||||||
|
if err == nil {
|
||||||
|
wireguard.PreSharedKey, err = parseINIWireguardKey(peerSection, "PresharedKey")
|
||||||
|
if err != nil {
|
||||||
|
return wireguard, fmt.Errorf("parsing peer section: %w", err)
|
||||||
|
}
|
||||||
|
} else if !regexINISectionNotExist.MatchString(err.Error()) {
|
||||||
|
// can never happen
|
||||||
|
return wireguard, fmt.Errorf("getting peer section: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return wireguard, nil
|
return wireguard, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,11 +64,6 @@ func parseWireguardInterfaceSection(interfaceSection *ini.Section,
|
|||||||
return err // error is already wrapped correctly
|
return err // error is already wrapped correctly
|
||||||
}
|
}
|
||||||
|
|
||||||
wireguard.PreSharedKey, err = parseINIWireguardKey(interfaceSection, "PresharedKey")
|
|
||||||
if err != nil {
|
|
||||||
return err // error is already wrapped correctly
|
|
||||||
}
|
|
||||||
|
|
||||||
wireguard.Addresses, err = parseINIWireguardAddress(interfaceSection)
|
wireguard.Addresses, err = parseINIWireguardAddress(interfaceSection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err // error is already wrapped correctly
|
return err // error is already wrapped correctly
|
||||||
|
|||||||
@@ -63,11 +63,11 @@ PrivateKey = x
|
|||||||
fileContent: `
|
fileContent: `
|
||||||
[Interface]
|
[Interface]
|
||||||
PrivateKey = QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8=
|
PrivateKey = QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8=
|
||||||
PresharedKey = YJ680VN+dGrdsWNjSFqZ6vvwuiNhbq502ZL3G7Q3o3g=
|
|
||||||
Address = 10.38.22.35/32
|
Address = 10.38.22.35/32
|
||||||
DNS = 193.138.218.74
|
DNS = 193.138.218.74
|
||||||
|
|
||||||
[Peer]
|
[Peer]
|
||||||
|
PresharedKey = YJ680VN+dGrdsWNjSFqZ6vvwuiNhbq502ZL3G7Q3o3g=
|
||||||
`,
|
`,
|
||||||
wireguard: settings.Wireguard{
|
wireguard: settings.Wireguard{
|
||||||
PrivateKey: ptrTo("QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8="),
|
PrivateKey: ptrTo("QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8="),
|
||||||
@@ -119,14 +119,6 @@ PrivateKey = x`,
|
|||||||
"wgtypes: failed to parse base64-encoded key: " +
|
"wgtypes: failed to parse base64-encoded key: " +
|
||||||
"illegal base64 data at input byte 0",
|
"illegal base64 data at input byte 0",
|
||||||
},
|
},
|
||||||
"pre shared key error": {
|
|
||||||
iniData: `[Interface]
|
|
||||||
PresharedKey = x
|
|
||||||
`,
|
|
||||||
errMessage: "parsing PresharedKey: x: " +
|
|
||||||
"wgtypes: failed to parse base64-encoded key: " +
|
|
||||||
"illegal base64 data at input byte 0",
|
|
||||||
},
|
|
||||||
"address error": {
|
"address error": {
|
||||||
iniData: `[Interface]
|
iniData: `[Interface]
|
||||||
Address = x
|
Address = x
|
||||||
@@ -137,12 +129,10 @@ Address = x
|
|||||||
iniData: `
|
iniData: `
|
||||||
[Interface]
|
[Interface]
|
||||||
PrivateKey = QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8=
|
PrivateKey = QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8=
|
||||||
PresharedKey = YJ680VN+dGrdsWNjSFqZ6vvwuiNhbq502ZL3G7Q3o3g=
|
|
||||||
Address = 10.38.22.35/32
|
Address = 10.38.22.35/32
|
||||||
`,
|
`,
|
||||||
wireguard: settings.Wireguard{
|
wireguard: settings.Wireguard{
|
||||||
PrivateKey: ptrTo("QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8="),
|
PrivateKey: ptrTo("QOlCgyA/Sn/c/+YNTIEohrjm8IZV+OZ2AUFIoX20sk8="),
|
||||||
PreSharedKey: ptrTo("YJ680VN+dGrdsWNjSFqZ6vvwuiNhbq502ZL3G7Q3o3g="),
|
|
||||||
Addresses: []netip.Prefix{
|
Addresses: []netip.Prefix{
|
||||||
netip.PrefixFrom(netip.AddrFrom4([4]byte{10, 38, 22, 35}), 32),
|
netip.PrefixFrom(netip.AddrFrom4([4]byte{10, 38, 22, 35}), 32),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user