Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove vscode-encrypt from node.js side #189252

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions build/.moduleignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ vsda/SECURITY.md
vsda/targets
!vsda/build/Release/vsda.node

vscode-encrypt/build/**
vscode-encrypt/src/**
vscode-encrypt/vendor/**
vscode-encrypt/.gitignore
vscode-encrypt/binding.gyp
vscode-encrypt/README.md
!vscode-encrypt/build/Release/vscode-encrypt-native.node

@vscode/policy-watcher/build/**
@vscode/policy-watcher/.husky/**
@vscode/policy-watcher/src/**
Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ export class CodeApplication extends Disposable {
services.set(IIssueMainService, new SyncDescriptor(IssueMainService, [this.userEnv]));

// Encryption
services.set(IEncryptionMainService, new SyncDescriptor(EncryptionMainService, [machineId]));
services.set(IEncryptionMainService, new SyncDescriptor(EncryptionMainService));

// Keyboard Layout
services.set(IKeyboardLayoutMainService, new SyncDescriptor(KeyboardLayoutMainService));
Expand Down
30 changes: 3 additions & 27 deletions src/vs/platform/encryption/electron-main/encryptionMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class EncryptionMainService implements IEncryptionMainService {
_serviceBrand: undefined;

constructor(
private readonly machineId: string,
@ILogService private readonly logService: ILogService
) {
// if this commandLine switch is set, the user has opted in to using basic text encryption
Expand All @@ -47,17 +46,11 @@ export class EncryptionMainService implements IEncryptionMainService {
try {
parsedValue = JSON.parse(value);
if (!parsedValue.data) {
this.logService.trace('[EncryptionMainService] Unable to parse encrypted value. Attempting old decryption.');
return this.oldDecrypt(value);
throw new Error(`[EncryptionMainService] Invalid encrypted valu: ${value}`);
}
} catch (e) {
this.logService.trace('[EncryptionMainService] Unable to parse encrypted value. Attempting old decryption.', e);
return this.oldDecrypt(value);
}
const bufferToDecrypt = Buffer.from(parsedValue.data);
const bufferToDecrypt = Buffer.from(parsedValue.data);

this.logService.trace('[EncryptionMainService] Decrypting value.');
try {
this.logService.trace('[EncryptionMainService] Decrypting value.');
const result = safeStorage.decryptString(bufferToDecrypt);
this.logService.trace('[EncryptionMainService] Decrypted value.');
return result;
Expand Down Expand Up @@ -104,21 +97,4 @@ export class EncryptionMainService implements IEncryptionMainService {

safeStorage.setUsePlainTextEncryption(true);
}

// TODO: Remove this after a few releases
private async oldDecrypt(value: string): Promise<string> {
let encryption: { decrypt(salt: string, value: string): Promise<string> };
try {
encryption = await new Promise((resolve, reject) => require(['vscode-encrypt'], resolve, reject));
} catch (e) {
return value;
}

try {
return encryption.decrypt(this.machineId, value);
} catch (e) {
this.logService.error(e);
return value;
}
}
}
64 changes: 0 additions & 64 deletions src/vs/platform/encryption/node/encryptionMainService.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as assert from 'assert';
import { isLinux, isWindows } from 'vs/base/common/platform';
import { flakySuite } from 'vs/base/test/common/testUtils';
import { Encryption } from 'vs/platform/encryption/node/encryptionMainService';

function testErrorMessage(module: string): string {
return `Unable to load "${module}" dependency. It was probably not compiled for the right operating system architecture or had missing build tools.`;
Expand Down Expand Up @@ -61,21 +60,6 @@ flakySuite('Native Modules (all platforms)', () => {
assert.ok(typeof sqlite3.Database === 'function', testErrorMessage('@vscode/sqlite3'));
});

test('vscode-encrypt', async () => {
try {
const vscodeEncrypt: Encryption = globalThis._VSCODE_NODE_MODULES['vscode-encrypt'];
const encrypted = await vscodeEncrypt.encrypt('salt', 'value');
const decrypted = await vscodeEncrypt.decrypt('salt', encrypted);

assert.ok(typeof encrypted === 'string', testErrorMessage('vscode-encrypt'));
assert.ok(typeof decrypted === 'string', testErrorMessage('vscode-encrypt'));
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
throw error;
}
}
});

test('vsda', async () => {
try {
const vsda: any = globalThis._VSCODE_NODE_MODULES['vsda'];
Expand Down