From 8debb9dad0e6c58867a59cd29be65b228c3d59ec Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 26 Nov 2020 12:47:59 +0100 Subject: conf: when migrating, write out reserialized config This catches encoding gotchas earlier. Signed-off-by: Jason A. Donenfeld --- conf/store.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'conf/store.go') 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 -- cgit v1.2.3-59-g8ed1b