提交 77de8fab 编写于 作者: I isidor

ISignService

上级 81d7885d
......@@ -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 {
......@@ -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();
......@@ -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 = {
......@@ -657,7 +659,8 @@ export class CodeApplication extends Disposable {
getAddress: () => {
return Promise.resolve({ host, port });
}
}
},
signService: signService
};
this._connection = connectRemoteAgentManagement(options, authority, `main`);
......@@ -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);
}
......
......@@ -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;
......@@ -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];
}
......
......@@ -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,
......@@ -58,6 +58,7 @@ interface ISimpleConnectionOptions {
reconnectionToken: string;
reconnectionProtocol: PersistentProtocol | null;
webSocketFactory: IWebSocketFactory;
signService: ISignService;
}
export interface IConnectCallback {
......@@ -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();
......@@ -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,
......@@ -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> {
......@@ -228,6 +216,7 @@ async function resolveConnectionOptions(options: IConnectionOptions, reconnectio
reconnectionToken: reconnectionToken,
reconnectionProtocol: reconnectionProtocol,
webSocketFactory: options.webSocketFactory,
signService: options.signService
};
}
......
/*---------------------------------------------------------------------------------------------
* 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);
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* 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>;
}
/*---------------------------------------------------------------------------------------------
* 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;
}
}
\ No newline at end of file
......@@ -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;
......@@ -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
......
......@@ -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 {
......@@ -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);
......@@ -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(() => {
......
......@@ -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.
......@@ -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);
......@@ -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) {
......
......@@ -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', () => {
......@@ -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);
......
......@@ -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 {
......@@ -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
......
......@@ -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 {
......@@ -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)));
});
});
......
......@@ -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;
......@@ -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;
......@@ -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) => {
......
......@@ -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 {
......@@ -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 {
......
......@@ -19,6 +19,7 @@ import { RemoteExtensionEnvironmentChannelClient } from 'vs/workbench/services/r
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IDiagnosticInfoOptions, IDiagnosticInfo } from 'vs/platform/diagnostics/common/diagnosticsService';
import { Emitter } from 'vs/base/common/event';
import { ISignService } from 'vs/platform/sign/common/sign';
export abstract class AbstractRemoteAgentService extends Disposable implements IRemoteAgentService {
......@@ -84,7 +85,8 @@ export class RemoteAgentConnection extends Disposable implements IRemoteAgentCon
private readonly _commit: string | undefined,
private readonly _webSocketFactory: IWebSocketFactory,
private readonly _environmentService: IEnvironmentService,
private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService
private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService,
private readonly _signService: ISignService
) {
super();
this.remoteAuthority = remoteAuthority;
......@@ -122,7 +124,8 @@ export class RemoteAgentConnection extends Disposable implements IRemoteAgentCon
const { host, port } = await this._remoteAuthorityResolverService.resolveAuthority(this.remoteAuthority);
return { host, port };
}
}
},
signService: this._signService
};
const connection = this._register(await connectRemoteAgentManagement(options, this.remoteAuthority, `renderer`));
this._register(connection.onDidStateChange(e => this._onDidStateChange.fire(e)));
......
......@@ -10,6 +10,7 @@ import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remot
import product from 'vs/platform/product/node/product';
import { nodeWebSocketFactory } from 'vs/platform/remote/node/nodeWebSocketFactory';
import { AbstractRemoteAgentService, RemoteAgentConnection } from 'vs/workbench/services/remote/common/abstractRemoteAgentService';
import { ISignService } from 'vs/platform/sign/common/sign';
export class RemoteAgentService extends AbstractRemoteAgentService {
......@@ -17,11 +18,12 @@ export class RemoteAgentService extends AbstractRemoteAgentService {
constructor({ remoteAuthority }: IWindowConfiguration,
@IEnvironmentService environmentService: IEnvironmentService,
@IRemoteAuthorityResolverService remoteAuthorityResolverService: IRemoteAuthorityResolverService
@IRemoteAuthorityResolverService remoteAuthorityResolverService: IRemoteAuthorityResolverService,
@ISignService signService: ISignService
) {
super(environmentService);
if (remoteAuthority) {
this._connection = this._register(new RemoteAgentConnection(remoteAuthority, product.commit, nodeWebSocketFactory, environmentService, remoteAuthorityResolverService));
this._connection = this._register(new RemoteAgentConnection(remoteAuthority, product.commit, nodeWebSocketFactory, environmentService, remoteAuthorityResolverService, signService));
}
}
......
......@@ -13,6 +13,7 @@ import { connectRemoteAgentTunnel, IConnectionOptions } from 'vs/platform/remote
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { ITunnelService, RemoteTunnel } from 'vs/platform/remote/common/tunnel';
import { nodeWebSocketFactory } from 'vs/platform/remote/node/nodeWebSocketFactory';
import { ISignService } from 'vs/platform/sign/common/sign';
export async function createRemoteTunnel(options: IConnectionOptions, tunnelRemotePort: number): Promise<RemoteTunnel> {
const tunnel = new NodeRemoteTunnel(options, tunnelRemotePort);
......@@ -88,6 +89,7 @@ export class TunnelService implements ITunnelService {
public constructor(
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IRemoteAuthorityResolverService private readonly remoteAuthorityResolverService: IRemoteAuthorityResolverService,
@ISignService private readonly signService: ISignService
) {
}
......@@ -106,7 +108,8 @@ export class TunnelService implements ITunnelService {
const { host, port } = await this.remoteAuthorityResolverService.resolveAuthority(remoteAuthority);
return { host, port };
}
}
},
signService: this.signService
};
return createRemoteTunnel(options, remotePort);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册