mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-26 13:19:42 +00:00
Only delete secrets from the old place if the new place is persisted storage (#185260)
Only delete credentials from the old place if the new place is persisted storage ref #185212
This commit is contained in:
committed by
GitHub
parent
9fdc988ecc
commit
979ae3940a
@@ -13,6 +13,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
||||
export const ISecretStorageService = createDecorator<ISecretStorageService>('secretStorageService');
|
||||
|
||||
export interface ISecretStorageProvider {
|
||||
type: 'in-memory' | 'persisted' | 'unknown';
|
||||
get(key: string): Promise<string | undefined>;
|
||||
set(key: string, value: string): Promise<void>;
|
||||
delete(key: string): Promise<void>;
|
||||
@@ -34,6 +35,8 @@ export class SecretStorageService implements ISecretStorageService {
|
||||
private readonly _sequencer = new SequencerByKey<string>();
|
||||
private initialized = this.init();
|
||||
|
||||
private _type: 'in-memory' | 'persisted' | 'unknown' = 'unknown';
|
||||
|
||||
constructor(
|
||||
@IStorageService private _storageService: IStorageService,
|
||||
@IEncryptionService private _encryptionService: IEncryptionService,
|
||||
@@ -42,6 +45,10 @@ export class SecretStorageService implements ISecretStorageService {
|
||||
this._storageService.onDidChangeValue(e => this.onDidChangeValue(e.key));
|
||||
}
|
||||
|
||||
get type() {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
private onDidChangeValue(key: string): void {
|
||||
if (!key.startsWith(this._storagePrefix)) {
|
||||
return;
|
||||
@@ -109,11 +116,13 @@ export class SecretStorageService implements ISecretStorageService {
|
||||
|
||||
private async init(): Promise<void> {
|
||||
if (await this._encryptionService.isEncryptionAvailable()) {
|
||||
this._type = 'persisted';
|
||||
return;
|
||||
}
|
||||
|
||||
this._logService.trace('[SecretStorageService] Encryption is not available, falling back to in-memory storage');
|
||||
|
||||
this._type = 'in-memory';
|
||||
this._storageService = new InMemoryStorageService();
|
||||
}
|
||||
|
||||
|
||||
@@ -225,11 +225,14 @@ export class MainThreadSecretState extends Disposable implements MainThreadSecre
|
||||
private async getAndDeleteOldPassword(extensionId: string, key: string): Promise<string | undefined> {
|
||||
const password = await this.getOldPassword(extensionId, key);
|
||||
if (password) {
|
||||
await this.deleteOldPassword(extensionId, key);
|
||||
const fullKey = this.getKey(extensionId, key);
|
||||
this.logService.trace('[mainThreadSecretState] Setting old password to new location for: ', extensionId, key);
|
||||
await this.secretStorageService.set(fullKey, password);
|
||||
this.logService.trace('[mainThreadSecretState] Old Password set to new location for: ', extensionId, key);
|
||||
if (this.secretStorageService.type === 'persisted') {
|
||||
this.logService.trace('[mainThreadSecretState] Deleting old password for since it was persisted in the new location: ', extensionId, key);
|
||||
await this.deleteOldPassword(extensionId, key);
|
||||
}
|
||||
}
|
||||
return password;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,14 @@ export class BrowserSecretStorageService extends SecretStorageService {
|
||||
|
||||
return super.delete(key);
|
||||
}
|
||||
|
||||
override get type() {
|
||||
if (this._secretStorageProvider) {
|
||||
return this._secretStorageProvider.type;
|
||||
}
|
||||
|
||||
return super.type;
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(ISecretStorageService, BrowserSecretStorageService, InstantiationType.Delayed);
|
||||
|
||||
Reference in New Issue
Block a user