Skip to content

Commit 979ae39

Browse files
Only delete secrets from the old place if the new place is persisted storage (microsoft#185260)
Only delete credentials from the old place if the new place is persisted storage ref microsoft#185212
1 parent 9fdc988 commit 979ae39

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/vs/platform/secrets/common/secrets.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ILogService } from 'vs/platform/log/common/log';
1313
export const ISecretStorageService = createDecorator<ISecretStorageService>('secretStorageService');
1414

1515
export interface ISecretStorageProvider {
16+
type: 'in-memory' | 'persisted' | 'unknown';
1617
get(key: string): Promise<string | undefined>;
1718
set(key: string, value: string): Promise<void>;
1819
delete(key: string): Promise<void>;
@@ -34,6 +35,8 @@ export class SecretStorageService implements ISecretStorageService {
3435
private readonly _sequencer = new SequencerByKey<string>();
3536
private initialized = this.init();
3637

38+
private _type: 'in-memory' | 'persisted' | 'unknown' = 'unknown';
39+
3740
constructor(
3841
@IStorageService private _storageService: IStorageService,
3942
@IEncryptionService private _encryptionService: IEncryptionService,
@@ -42,6 +45,10 @@ export class SecretStorageService implements ISecretStorageService {
4245
this._storageService.onDidChangeValue(e => this.onDidChangeValue(e.key));
4346
}
4447

48+
get type() {
49+
return this._type;
50+
}
51+
4552
private onDidChangeValue(key: string): void {
4653
if (!key.startsWith(this._storagePrefix)) {
4754
return;
@@ -109,11 +116,13 @@ export class SecretStorageService implements ISecretStorageService {
109116

110117
private async init(): Promise<void> {
111118
if (await this._encryptionService.isEncryptionAvailable()) {
119+
this._type = 'persisted';
112120
return;
113121
}
114122

115123
this._logService.trace('[SecretStorageService] Encryption is not available, falling back to in-memory storage');
116124

125+
this._type = 'in-memory';
117126
this._storageService = new InMemoryStorageService();
118127
}
119128

src/vs/workbench/api/browser/mainThreadSecretState.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,14 @@ export class MainThreadSecretState extends Disposable implements MainThreadSecre
225225
private async getAndDeleteOldPassword(extensionId: string, key: string): Promise<string | undefined> {
226226
const password = await this.getOldPassword(extensionId, key);
227227
if (password) {
228-
await this.deleteOldPassword(extensionId, key);
229228
const fullKey = this.getKey(extensionId, key);
230229
this.logService.trace('[mainThreadSecretState] Setting old password to new location for: ', extensionId, key);
231230
await this.secretStorageService.set(fullKey, password);
232231
this.logService.trace('[mainThreadSecretState] Old Password set to new location for: ', extensionId, key);
232+
if (this.secretStorageService.type === 'persisted') {
233+
this.logService.trace('[mainThreadSecretState] Deleting old password for since it was persisted in the new location: ', extensionId, key);
234+
await this.deleteOldPassword(extensionId, key);
235+
}
233236
}
234237
return password;
235238
}

src/vs/workbench/services/secrets/browser/secretStorageService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export class BrowserSecretStorageService extends SecretStorageService {
5050

5151
return super.delete(key);
5252
}
53+
54+
override get type() {
55+
if (this._secretStorageProvider) {
56+
return this._secretStorageProvider.type;
57+
}
58+
59+
return super.type;
60+
}
5361
}
5462

5563
registerSingleton(ISecretStorageService, BrowserSecretStorageService, InstantiationType.Delayed);

0 commit comments

Comments
 (0)