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

Introduce ISignService #75200

Merged
merged 4 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import { RemoteAgentConnectionContext } from 'vs/platform/remote/common/remoteAg
import { nodeWebSocketFactory } from 'vs/platform/remote/node/nodeWebSocketFactory';
import { VSBuffer } from 'vs/base/common/buffer';
import { statSync } from 'fs';
import { ISignService } from 'vs/platform/sign/common/sign';

export class CodeApplication extends Disposable {

Expand All @@ -95,7 +96,8 @@ export class CodeApplication extends Disposable {
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@ILifecycleService private readonly lifecycleService: ILifecycleService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IStateService private readonly stateService: IStateService
@IStateService private readonly stateService: IStateService,
@ISignService private readonly signService: ISignService
) {
super();

Expand Down Expand Up @@ -646,7 +648,7 @@ export class CodeApplication extends Disposable {
private readonly _connection: Promise<ManagementPersistentConnection>;
private readonly _disposeRunner: RunOnceScheduler;

constructor(authority: string, host: string, port: number) {
constructor(authority: string, host: string, port: number, signService: ISignService) {
this._authority = authority;

const options: IConnectionOptions = {
Expand All @@ -657,7 +659,8 @@ export class CodeApplication extends Disposable {
getAddress: () => {
return Promise.resolve({ host, port });
}
}
},
signService: signService
isidorn marked this conversation as resolved.
Show resolved Hide resolved
};

this._connection = connectRemoteAgentManagement(options, authority, `main`);
Expand Down Expand Up @@ -726,7 +729,7 @@ export class CodeApplication extends Disposable {
return;
}

activeConnection = new ActiveConnection(uri.authority, resolvedAuthority.host, resolvedAuthority.port);
activeConnection = new ActiveConnection(uri.authority, resolvedAuthority.host, resolvedAuthority.port, this.signService);
connectionPool.set(uri.authority, activeConnection);
}

Expand Down
3 changes: 3 additions & 0 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { setUnexpectedErrorHandler } from 'vs/base/common/errors';
import { IThemeMainService, ThemeMainService } from 'vs/platform/theme/electron-main/themeMainService';
import { Client } from 'vs/base/parts/ipc/common/ipc.net';
import { once } from 'vs/base/common/functional';
import { ISignService } from 'vs/platform/sign/common/sign';
import { SignService } from 'vs/platform/sign/node/signService';

class ExpectedError extends Error {
readonly isExpected = true;
Expand Down Expand Up @@ -147,6 +149,7 @@ class CodeMain {
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IDiagnosticsService, new SyncDescriptor(DiagnosticsService));
services.set(IThemeMainService, new SyncDescriptor(ThemeMainService));
services.set(ISignService, new SyncDescriptor(SignService));

return [new InstantiationService(services, true), instanceEnvironment];
}
Expand Down
23 changes: 6 additions & 17 deletions src/vs/platform/remote/common/remoteAgentConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { generateUuid } from 'vs/base/common/uuid';
import { RemoteAgentConnectionContext } from 'vs/platform/remote/common/remoteAgentEnvironment';
import { Disposable } from 'vs/base/common/lifecycle';
import { VSBuffer } from 'vs/base/common/buffer';
import * as platform from 'vs/base/common/platform';
import { Emitter } from 'vs/base/common/event';
import { RemoteAuthorityResolverError } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { ISignService } from 'vs/platform/sign/common/sign';

export const enum ConnectionType {
Management = 1,
Expand Down Expand Up @@ -58,6 +58,7 @@ interface ISimpleConnectionOptions {
reconnectionToken: string;
reconnectionProtocol: PersistentProtocol | null;
webSocketFactory: IWebSocketFactory;
signService: ISignService;
}

export interface IConnectCallback {
Expand Down Expand Up @@ -92,7 +93,7 @@ async function connectToRemoteExtensionHostAgent(options: ISimpleConnectionOptio

return new Promise<PersistentProtocol>((c, e) => {

const messageRegistration = protocol.onControlMessage(raw => {
const messageRegistration = protocol.onControlMessage(async raw => {
const msg = <HandshakeMessage>JSON.parse(raw.toString());
// Stop listening for further events
messageRegistration.dispose();
Expand All @@ -104,21 +105,7 @@ async function connectToRemoteExtensionHostAgent(options: ISimpleConnectionOptio

if (msg.type === 'sign') {

let signed = msg.data;
if (platform.isNative) {
try {
const vsda = <any>require.__$__nodeRequire('vsda');
const signer = new vsda.signer();
if (signer) {
signed = signer.sign(msg.data);
}
} catch (e) {
console.error('signer.sign: ' + e);
}
} else {
signed = (<any>self).CONNECTION_AUTH_TOKEN;
}

const signed = await options.signService.sign(msg.data);
const connTypeRequest: ConnectionTypeRequest = {
type: 'connectionType',
commit: options.commit,
Expand Down Expand Up @@ -216,6 +203,7 @@ export interface IConnectionOptions {
commit: string | undefined;
webSocketFactory: IWebSocketFactory;
addressProvider: IAddressProvider;
signService: ISignService;
}

async function resolveConnectionOptions(options: IConnectionOptions, reconnectionToken: string, reconnectionProtocol: PersistentProtocol | null): Promise<ISimpleConnectionOptions> {
Expand All @@ -228,6 +216,7 @@ async function resolveConnectionOptions(options: IConnectionOptions, reconnectio
reconnectionToken: reconnectionToken,
reconnectionProtocol: reconnectionProtocol,
webSocketFactory: options.webSocketFactory,
signService: options.signService
};
}

Expand Down
14 changes: 14 additions & 0 deletions src/vs/platform/sign/browser/signService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ISignService } from 'vs/platform/sign/common/sign';

export class SignService implements ISignService {
_serviceBrand: any;

async sign(value: string): Promise<string> {
return Promise.resolve((<any>self).CONNECTION_AUTH_TOKEN);
}
}
15 changes: 15 additions & 0 deletions src/vs/platform/sign/common/sign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

export const SIGN_SERVICE_ID = 'signService';
export const ISignService = createDecorator<ISignService>(SIGN_SERVICE_ID);

export interface ISignService {
_serviceBrand: any;

sign(value: string): Promise<string>;
}
24 changes: 24 additions & 0 deletions src/vs/platform/sign/node/signService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ISignService } from 'vs/platform/sign/common/sign';

export class SignService implements ISignService {
_serviceBrand: any;

async sign(value: string): Promise<string> {
try {
const vsda = await import('vsda');
const signer = new vsda.signer();
if (signer) {
return signer.sign(value);
}
} catch (e) {
console.error('signer.sign: ' + e);
}

return value;
}
}
8 changes: 7 additions & 1 deletion src/vs/workbench/browser/web.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { WorkspaceService } from 'vs/workbench/services/configuration/browser/co
import { ConfigurationCache } from 'vs/workbench/services/configuration/browser/configurationCache';
import { ConfigurationFileService } from 'vs/workbench/services/configuration/common/configuration';
import { WebResources } from 'vs/workbench/browser/web.resources';
import { ISignService } from 'vs/platform/sign/common/sign';
import { SignService } from 'vs/platform/sign/browser/signService';

interface IWindowConfiguration {
settingsUri: URI;
Expand Down Expand Up @@ -96,7 +98,11 @@ class CodeRendererMain extends Disposable {
const remoteAuthorityResolverService = new RemoteAuthorityResolverService();
serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);

const remoteAgentService = this._register(new RemoteAgentService(environmentService, productService, remoteAuthorityResolverService));
// Sign
const signService = new SignService();
serviceCollection.set(ISignService, signService);

const remoteAgentService = this._register(new RemoteAgentService(environmentService, productService, remoteAuthorityResolverService, signService));
serviceCollection.set(IRemoteAgentService, remoteAgentService);

// Files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ReplModel } from 'vs/workbench/contrib/debug/common/replModel';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ISignService } from 'vs/platform/sign/common/sign';

export class DebugSession implements IDebugSession {

Expand Down Expand Up @@ -66,7 +67,8 @@ export class DebugSession implements IDebugSession {
@IViewletService private readonly viewletService: IViewletService,
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@INotificationService private readonly notificationService: INotificationService
@INotificationService private readonly notificationService: INotificationService,
@ISignService private readonly signService: ISignService
) {
this.id = generateUuid();
this.repl = new ReplModel(this);
Expand Down Expand Up @@ -167,7 +169,7 @@ export class DebugSession implements IDebugSession {

return dbgr.createDebugAdapter(this).then(debugAdapter => {

this.raw = new RawDebugSession(debugAdapter, dbgr, this.telemetryService, customTelemetryService, this.environmentService);
this.raw = new RawDebugSession(debugAdapter, dbgr, this.telemetryService, customTelemetryService, this.environmentService, this.signService);

return this.raw!.start().then(() => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { IDebugAdapter, IConfig, AdapterEndEvent, IDebugger } from 'vs/workbench
import { createErrorWithActions } from 'vs/base/common/errorsWithActions';
import * as cp from 'child_process';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ISignService } from 'vs/platform/sign/common/sign';

/**
* This interface represents a single command line argument split into a "prefix" and a "path" half.
Expand Down Expand Up @@ -69,9 +70,10 @@ export class RawDebugSession {
constructor(
debugAdapter: IDebugAdapter,
dbgr: IDebugger,
private telemetryService: ITelemetryService,
public customTelemetryService: ITelemetryService | undefined,
private environmentService: IEnvironmentService
private readonly telemetryService: ITelemetryService,
public readonly customTelemetryService: ITelemetryService | undefined,
private readonly environmentService: IEnvironmentService,
private readonly signService: ISignService
) {
this.debugAdapter = debugAdapter;
this._capabilities = Object.create(null);
Expand Down Expand Up @@ -528,11 +530,9 @@ export class RawDebugSession {
break;
case 'handshake':
try {
const vsda = await import('vsda');
const obj = new vsda.signer();
const sig = obj.sign(request.arguments.value);
const signature = await this.signService.sign(request.arguments.value);
response.body = {
signature: sig
signature: signature
};
safeSendResponse(response);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ReplModel } from 'vs/workbench/contrib/debug/common/replModel';
import { IBreakpointUpdateData } from 'vs/workbench/contrib/debug/common/debug';

function createMockSession(model: DebugModel, name = 'mockSession', parentSession?: DebugSession | undefined): DebugSession {
return new DebugSession({ resolved: { name, type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, parentSession, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!);
return new DebugSession({ resolved: { name, type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, parentSession, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!);
}

suite('Debug - Model', () => {
Expand Down Expand Up @@ -437,7 +437,7 @@ suite('Debug - Model', () => {
// Repl output

test('repl output', () => {
const session = new DebugSession({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, undefined, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!);
const session = new DebugSession({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, undefined!, model, undefined, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!, undefined!);
const repl = new ReplModel(session);
repl.appendToRepl('first line\n', severity.Error);
repl.appendToRepl('second line ', severity.Error);
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/electron-browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import { DefaultConfigurationExportHelper } from 'vs/workbench/services/configur
import { ConfigurationCache } from 'vs/workbench/services/configuration/node/configurationCache';
import { ConfigurationFileService } from 'vs/workbench/services/configuration/node/configurationFileService';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
import { SignService } from 'vs/platform/sign/node/signService';
import { ISignService } from 'vs/platform/sign/common/sign';

class CodeRendererMain extends Disposable {

Expand Down Expand Up @@ -183,7 +185,11 @@ class CodeRendererMain extends Disposable {
const remoteAuthorityResolverService = new RemoteAuthorityResolverService();
serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);

const remoteAgentService = this._register(new RemoteAgentService(this.configuration, environmentService, remoteAuthorityResolverService));
// Sign
const signService = new SignService();
serviceCollection.set(ISignService, signService);

const remoteAgentService = this._register(new RemoteAgentService(this.configuration, environmentService, remoteAuthorityResolverService, signService));
serviceCollection.set(IRemoteAgentService, remoteAgentService);

// Files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ConfigurationFileService } from 'vs/workbench/services/configuration/no
import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
import { IConfigurationCache } from 'vs/workbench/services/configuration/common/configuration';
import { VSBuffer } from 'vs/base/common/buffer';
import { SignService } from 'vs/platform/sign/browser/signService';

class SettingsTestEnvironmentService extends EnvironmentService {

Expand Down Expand Up @@ -103,7 +104,7 @@ suite('WorkspaceContextService - Folder', () => {
workspaceResource = folderDir;
const globalSettingsFile = path.join(parentDir, 'settings.json');
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
workspaceContextService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), new RemoteAgentService(<IWindowConfiguration>{}, environmentService, new RemoteAuthorityResolverService()));
workspaceContextService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), new RemoteAgentService(<IWindowConfiguration>{}, environmentService, new RemoteAuthorityResolverService(), new SignService()));
return (<WorkspaceService>workspaceContextService).initialize(convertToWorkspacePayload(URI.file(folderDir)));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { VSBuffer } from 'vs/base/common/buffer';
import { IExtensionHostDebugService } from 'vs/workbench/services/extensions/common/extensionHostDebug';
import { IProductService } from 'vs/platform/product/common/product';
import { ISignService } from 'vs/platform/sign/common/sign';

export interface IInitDataProvider {
readonly remoteAuthority: string;
Expand Down Expand Up @@ -55,7 +56,8 @@ export class RemoteExtensionHostClient extends Disposable implements IExtensionH
@ILabelService private readonly _labelService: ILabelService,
@IRemoteAuthorityResolverService private readonly remoteAuthorityResolverService: IRemoteAuthorityResolverService,
@IExtensionHostDebugService private readonly _extensionHostDebugService: IExtensionHostDebugService,
@IProductService private readonly _productService: IProductService
@IProductService private readonly _productService: IProductService,
@ISignService private readonly _signService: ISignService
) {
super();
this._protocol = null;
Expand All @@ -77,7 +79,8 @@ export class RemoteExtensionHostClient extends Disposable implements IExtensionH
const { host, port } = await this.remoteAuthorityResolverService.resolveAuthority(this._initDataProvider.remoteAuthority);
return { host, port };
}
}
},
signService: this._signService
};
return this.remoteAuthorityResolverService.resolveAuthority(this._initDataProvider.remoteAuthority).then((resolvedAuthority) => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remot
import { AbstractRemoteAgentService, RemoteAgentConnection } from 'vs/workbench/services/remote/common/abstractRemoteAgentService';
import { IProductService } from 'vs/platform/product/common/product';
import { browserWebSocketFactory } from 'vs/platform/remote/browser/browserWebSocketFactory';
import { ISignService } from 'vs/platform/sign/common/sign';

export class RemoteAgentService extends AbstractRemoteAgentService {

Expand All @@ -17,11 +18,12 @@ export class RemoteAgentService extends AbstractRemoteAgentService {
constructor(
@IEnvironmentService environmentService: IEnvironmentService,
@IProductService productService: IProductService,
@IRemoteAuthorityResolverService remoteAuthorityResolverService: IRemoteAuthorityResolverService
@IRemoteAuthorityResolverService remoteAuthorityResolverService: IRemoteAuthorityResolverService,
@ISignService signService: ISignService
) {
super(environmentService);
const authority = document.location.host;
this._connection = this._register(new RemoteAgentConnection(authority, productService.commit, browserWebSocketFactory, environmentService, remoteAuthorityResolverService));
this._connection = this._register(new RemoteAgentConnection(authority, productService.commit, browserWebSocketFactory, environmentService, remoteAuthorityResolverService, signService));
}

getConnection(): IRemoteAgentConnection | null {
Expand Down
Loading