aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-26 12:47:59 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-27 12:50:53 +0100
commit8debb9dad0e6c58867a59cd29be65b228c3d59ec (patch)
treebc7c1a253f412b4df9873c08f41e4c59cac25dcf
parentconf: open temporary file with read sharing (diff)
downloadwireguard-windows-8debb9dad0e6c58867a59cd29be65b228c3d59ec.tar.xz
wireguard-windows-8debb9dad0e6c58867a59cd29be65b228c3d59ec.zip
conf: when migrating, write out reserialized config
This catches encoding gotchas earlier. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--conf/store.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/conf/store.go b/conf/store.go
index 4782aca0..35f0ba7d 100644
--- a/conf/store.go
+++ b/conf/store.go
@@ -100,20 +100,21 @@ func MigrateUnencryptedConfigs(sharingBase int) (int, []error) {
e++
continue
}
- _, err = FromWgQuickWithUnknownEncoding(string(bytes), "input")
+ configName := strings.TrimSuffix(name, configFileUnencryptedSuffix)
+ config, err := FromWgQuickWithUnknownEncoding(string(bytes), configName)
if err != nil {
errs[e] = err
e++
continue
}
- bytes, err = dpapi.Encrypt(bytes, strings.TrimSuffix(name, configFileUnencryptedSuffix))
+ bytes, err = dpapi.Encrypt([]byte(config.ToWgQuick()), name)
if err != nil {
errs[e] = err
e++
continue
}
- dstFile := strings.TrimSuffix(path, configFileUnencryptedSuffix) + configFileSuffix
+ dstFile := configName + configFileSuffix
err = writeEncryptedFile(dstFile, false, bytes)
if err != nil {
errs[e] = err