aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/conf
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-22 14:35:27 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-22 16:49:48 +0200
commit014c2a75454d6108c4fc6a7495a37874a3535e74 (patch)
treeeac24aad094e9e3ac6343c1928f455c7b07a9d83 /conf
parenttunnel: disable firewall before destroying wintun (diff)
downloadwireguard-windows-014c2a75454d6108c4fc6a7495a37874a3535e74.tar.xz
wireguard-windows-014c2a75454d6108c4fc6a7495a37874a3535e74.zip
conf: read files potentially with UTF16
Diffstat (limited to 'conf')
-rw-r--r--conf/parser.go19
-rw-r--r--conf/store.go4
2 files changed, 21 insertions, 2 deletions
diff --git a/conf/parser.go b/conf/parser.go
index e98a0244..88802688 100644
--- a/conf/parser.go
+++ b/conf/parser.go
@@ -13,6 +13,8 @@ import (
"strconv"
"strings"
"time"
+
+ "golang.org/x/text/encoding/unicode"
)
type ParseError struct {
@@ -338,6 +340,23 @@ func FromWgQuick(s string, name string) (*Config, error) {
return &conf, nil
}
+func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) {
+ c, firstErr := FromWgQuick(s, name)
+ if firstErr == nil {
+ return c, nil
+ }
+ for _, encoding := range unicode.All {
+ decoded, err := encoding.NewDecoder().String(s)
+ if err == nil {
+ c, err := FromWgQuick(decoded, name)
+ if err == nil {
+ return c, nil
+ }
+ }
+ }
+ return nil, firstErr
+}
+
func FromUAPI(s string, existingConfig *Config) (*Config, error) {
lines := strings.Split(s, "\n")
parserState := inInterfaceSection
diff --git a/conf/store.go b/conf/store.go
index 9c645a6b..2886d027 100644
--- a/conf/store.go
+++ b/conf/store.go
@@ -84,7 +84,7 @@ func MigrateUnencryptedConfigs() (int, []error) {
e++
continue
}
- _, err = FromWgQuick(string(bytes), "input")
+ _, err = FromWgQuickWithUnknownEncoding(string(bytes), "input")
if err != nil {
errs[e] = err
e++
@@ -143,7 +143,7 @@ func LoadFromPath(path string) (*Config, error) {
return nil, err
}
}
- return FromWgQuick(string(bytes), name)
+ return FromWgQuickWithUnknownEncoding(string(bytes), name)
}
func NameFromPath(path string) (string, error) {