@@ -155,6 +155,16 @@ QString CryptoService::decryptToString(const QString &text) {
155155 return legacyDecryptToString (text);
156156}
157157
158+ QString CryptoService::decryptToStringWithPlaintextFallback (const QString &text) {
159+ const QString plainText = decryptToString (text);
160+
161+ if (plainText.isEmpty () && !text.isEmpty () && !isKeychainReference (text)) {
162+ return text;
163+ }
164+
165+ return plainText;
166+ }
167+
158168bool CryptoService::isKeychainReference (const QString &text) {
159169 return text.startsWith (KeychainMarkerPrefix);
160170}
@@ -247,10 +257,12 @@ QStringList CryptoService::keychainReferencesFromDiskDatabase() {
247257}
248258
249259QString CryptoService::legacyEncryptToString (const QString &text) {
260+ // Keep this compatible with the pre-qtkeychain SimpleCrypt storage format.
250261 return _simpleCrypt->encryptToString (text);
251262}
252263
253264QString CryptoService::legacyDecryptToString (const QString &text) {
265+ // Keep this compatible with the pre-qtkeychain SimpleCrypt storage format.
254266 return _simpleCrypt->decryptToString (text);
255267}
256268
@@ -321,7 +333,16 @@ bool CryptoService::migrateSecret(QString *storedValue, const QString &key,
321333 plainText = *storedValue;
322334 }
323335
324- if (plainText.isEmpty () || !writeSecret (key, plainText)) {
336+ if (plainText.isEmpty ()) {
337+ return false ;
338+ }
339+
340+ if (!writeSecret (key, plainText)) {
341+ if (allowPlaintextFallback && *storedValue == plainText) {
342+ *storedValue = legacyEncryptToString (plainText);
343+ return true ;
344+ }
345+
325346 return false ;
326347 }
327348
@@ -350,7 +371,10 @@ void CryptoService::migrateSettingsSecrets() {
350371 };
351372 const QStringList plaintextFallbackSettingsKeys = {
352373 QStringLiteral (" webSocketServerService/bookmarkSuggestionApiToken" ),
374+ QStringLiteral (" webSocketServerService/token" ),
375+ QStringLiteral (" webAppClientService/token" ),
353376 QStringLiteral (" ai/mcpServerToken" ),
377+ QStringLiteral (" languageToolApiKey" ),
354378 };
355379
356380 SettingsService settings;
0 commit comments