diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b4625b..b3319c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## UNRELEASED +### Changed +- Move private Ox key into JID folder in ~/.local/share/go-sendxmpp. ## [v0.10.0] 2024-04-13 ### Changed diff --git a/ox.go b/ox.go index b47f711..904284f 100644 --- a/ox.go +++ b/ox.go @@ -316,15 +316,20 @@ func oxPublishPubKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ, pubKey * } func oxGetPrivKeyLoc(jid string) (string, error) { - dataDir, err := getDataPath("oxprivkeys/") + dataDir, err := getDataPath(strings.Replace(strings.Replace(jid, "@", "_at_", -1), ".", "_", -1)) + if err != nil { + return strError, fmt.Errorf("oxGetPubKeyLoc: %w", err) + } + oldDataDir, err := getDataPath("oxprivkeys/") if err != nil { return strError, fmt.Errorf("oxGetPubKeyLoc: %w", err) } // TODO: Remove handling of oldDataFile in a later version when it's very likely that there are no // more versions in use using the oldDataFile (<0.8.3). - oldDataFile := dataDir + base64.StdEncoding.EncodeToString([]byte(jid)) - oldDataFile2 := dataDir + strings.Replace(jid, "@", "_at_", -1) - dataFile := dataDir + strings.Replace(strings.Replace(jid, "@", "_at_", -1), ".", "_", -1) + oldDataFile := oldDataDir + base64.StdEncoding.EncodeToString([]byte(jid)) + oldDataFile2 := oldDataDir + strings.Replace(jid, "@", "_at_", -1) + oldDataFile3 := oldDataDir + strings.Replace(strings.Replace(jid, "@", "_at_", -1), ".", "_", -1) + dataFile := dataDir + "oxprivkey" if _, err := os.Stat(oldDataFile); err == nil { err := os.Rename(oldDataFile, dataFile) if err != nil { @@ -337,6 +342,12 @@ func oxGetPrivKeyLoc(jid string) (string, error) { return dataFile, err } } + if _, err := os.Stat(oldDataFile3); err == nil { + err := os.Rename(oldDataFile3, dataFile) + if err != nil { + return dataFile, err + } + } return dataFile, nil }