Skip to content

Commit 65a6e4f

Browse files
More logs around SecretStorage (#165542)
1 parent e8fa3e4 commit 65a6e4f

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/vs/platform/encryption/node/encryptionMainService.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ICommonEncryptionService } from 'vs/platform/encryption/common/encryptionService';
7+
import { ILogService } from 'vs/platform/log/common/log';
78

89
export interface Encryption {
910
encrypt(salt: string, value: string): Promise<string>;
@@ -12,28 +13,42 @@ export interface Encryption {
1213
export class EncryptionMainService implements ICommonEncryptionService {
1314
declare readonly _serviceBrand: undefined;
1415
constructor(
15-
private machineId: string) {
16-
17-
}
16+
private machineId: string,
17+
@ILogService private readonly logService: ILogService
18+
) { }
1819

1920
private encryption(): Promise<Encryption> {
2021
return new Promise((resolve, reject) => require(['vscode-encrypt'], resolve, reject));
2122
}
2223

2324
async encrypt(value: string): Promise<string> {
25+
let encryption: Encryption;
26+
try {
27+
encryption = await this.encryption();
28+
} catch (e) {
29+
return value;
30+
}
31+
2432
try {
25-
const encryption = await this.encryption();
2633
return encryption.encrypt(this.machineId, value);
2734
} catch (e) {
35+
this.logService.error(e);
2836
return value;
2937
}
3038
}
3139

3240
async decrypt(value: string): Promise<string> {
41+
let encryption: Encryption;
42+
try {
43+
encryption = await this.encryption();
44+
} catch (e) {
45+
return value;
46+
}
47+
3348
try {
34-
const encryption = await this.encryption();
3549
return encryption.decrypt(this.machineId, value);
3650
} catch (e) {
51+
this.logService.error(e);
3752
return value;
3853
}
3954
}

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,21 @@ export class MainThreadSecretState extends Disposable implements MainThreadSecre
3636
}
3737

3838
async $getPassword(extensionId: string, key: string): Promise<string | undefined> {
39-
this.logService.trace(`Getting password for ${extensionId} extension:`, key);
39+
this.logService.trace(`MainThreadSecretState#getPassword: Getting password for ${extensionId} extension: `, key);
4040
const fullKey = await this.getFullKey(extensionId);
4141
const password = await this.credentialsService.getPassword(fullKey, key);
4242
if (!password) {
43-
this.logService.trace('No password found for:', key);
43+
this.logService.trace('MainThreadSecretState#getPassword: No password found for: ', key);
4444
return undefined;
4545
}
4646

4747
let decrypted: string | null;
4848
try {
49+
this.logService.trace('MainThreadSecretState#getPassword: Decrypting password for: ', key);
4950
decrypted = await this.encryptionService.decrypt(password);
5051
} catch (e) {
5152
this.logService.error(e);
53+
this.logService.trace('MainThreadSecretState#getPassword: Trying migration for: ', key);
5254

5355
// If we are on a platform that newly started encrypting secrets before storing them,
5456
// then passwords previously stored were stored un-encrypted (NOTE: but still being stored in a secure keyring).
@@ -65,7 +67,7 @@ export class MainThreadSecretState extends Disposable implements MainThreadSecre
6567
try {
6668
const value = JSON.parse(decrypted);
6769
if (value.extensionId === extensionId) {
68-
this.logService.trace('Password found for:', key);
70+
this.logService.trace('MainThreadSecretState#getPassword: Password found for: ', key);
6971
return value.content;
7072
}
7173
} catch (parseError) {
@@ -82,17 +84,20 @@ export class MainThreadSecretState extends Disposable implements MainThreadSecre
8284
}
8385
}
8486

85-
this.logService.trace('No password found for:', key);
87+
this.logService.trace('MainThreadSecretState#getPassword: No password found for: ', key);
8688
return undefined;
8789
}
8890

8991
async $setPassword(extensionId: string, key: string, value: string): Promise<void> {
92+
this.logService.trace(`MainThreadSecretState#setPassword: Setting password for ${extensionId} extension: `, key);
9093
const fullKey = await this.getFullKey(extensionId);
9194
const toEncrypt = JSON.stringify({
9295
extensionId,
9396
content: value
9497
});
98+
this.logService.trace('MainThreadSecretState#setPassword: Encrypting password for: ', key);
9599
const encrypted = await this.encryptionService.encrypt(toEncrypt);
100+
this.logService.trace('MainThreadSecretState#setPassword: Storing password for: ', key);
96101
return await this.credentialsService.setPassword(fullKey, key, encrypted);
97102
}
98103

0 commit comments

Comments
 (0)