mirror of
https://github.com/fosrl/olm.git
synced 2026-02-28 07:46:41 +00:00
Import fixkey
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package olm
|
package olm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -142,20 +140,6 @@ func formatEndpoint(endpoint string) string {
|
|||||||
return endpoint
|
return endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func fixKey(key string) string {
|
|
||||||
// Remove any whitespace
|
|
||||||
key = strings.TrimSpace(key)
|
|
||||||
|
|
||||||
// Decode from base64
|
|
||||||
decoded, err := base64.StdEncoding.DecodeString(key)
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatal("Error decoding base64")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to hex
|
|
||||||
return hex.EncodeToString(decoded)
|
|
||||||
}
|
|
||||||
|
|
||||||
func mapToWireGuardLogLevel(level logger.LogLevel) int {
|
func mapToWireGuardLogLevel(level logger.LogLevel) int {
|
||||||
switch level {
|
switch level {
|
||||||
case logger.DEBUG:
|
case logger.DEBUG:
|
||||||
@@ -243,8 +227,8 @@ func ConfigurePeer(dev *device.Device, siteConfig SiteConfig, privateKey wgtypes
|
|||||||
|
|
||||||
// Construct WireGuard config for this peer
|
// Construct WireGuard config for this peer
|
||||||
var configBuilder strings.Builder
|
var configBuilder strings.Builder
|
||||||
configBuilder.WriteString(fmt.Sprintf("private_key=%s\n", fixKey(privateKey.String())))
|
configBuilder.WriteString(fmt.Sprintf("private_key=%s\n", util.FixKey(privateKey.String())))
|
||||||
configBuilder.WriteString(fmt.Sprintf("public_key=%s\n", fixKey(siteConfig.PublicKey)))
|
configBuilder.WriteString(fmt.Sprintf("public_key=%s\n", util.FixKey(siteConfig.PublicKey)))
|
||||||
|
|
||||||
// Add each allowed IP separately
|
// Add each allowed IP separately
|
||||||
for _, allowedIP := range allowedIPs {
|
for _, allowedIP := range allowedIPs {
|
||||||
@@ -275,7 +259,7 @@ func ConfigurePeer(dev *device.Device, siteConfig SiteConfig, privateKey wgtypes
|
|||||||
|
|
||||||
wgConfig := &peermonitor.WireGuardConfig{
|
wgConfig := &peermonitor.WireGuardConfig{
|
||||||
SiteID: siteConfig.SiteId,
|
SiteID: siteConfig.SiteId,
|
||||||
PublicKey: fixKey(siteConfig.PublicKey),
|
PublicKey: util.FixKey(siteConfig.PublicKey),
|
||||||
ServerIP: strings.Split(siteConfig.ServerIP, "/")[0],
|
ServerIP: strings.Split(siteConfig.ServerIP, "/")[0],
|
||||||
Endpoint: siteConfig.Endpoint,
|
Endpoint: siteConfig.Endpoint,
|
||||||
PrimaryRelay: primaryRelay,
|
PrimaryRelay: primaryRelay,
|
||||||
@@ -296,7 +280,7 @@ func ConfigurePeer(dev *device.Device, siteConfig SiteConfig, privateKey wgtypes
|
|||||||
func RemovePeer(dev *device.Device, siteId int, publicKey string) error {
|
func RemovePeer(dev *device.Device, siteId int, publicKey string) error {
|
||||||
// Construct WireGuard config to remove the peer
|
// Construct WireGuard config to remove the peer
|
||||||
var configBuilder strings.Builder
|
var configBuilder strings.Builder
|
||||||
configBuilder.WriteString(fmt.Sprintf("public_key=%s\n", fixKey(publicKey)))
|
configBuilder.WriteString(fmt.Sprintf("public_key=%s\n", util.FixKey(publicKey)))
|
||||||
configBuilder.WriteString("remove=true\n")
|
configBuilder.WriteString("remove=true\n")
|
||||||
|
|
||||||
config := configBuilder.String()
|
config := configBuilder.String()
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string,
|
|||||||
logger.Warn("Peer %d is disconnected", siteID)
|
logger.Warn("Peer %d is disconnected", siteID)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fixKey(privateKey.String()),
|
util.FixKey(privateKey.String()),
|
||||||
olm,
|
olm,
|
||||||
dev,
|
dev,
|
||||||
config.Holepunch,
|
config.Holepunch,
|
||||||
|
|||||||
Reference in New Issue
Block a user