Skip to content

Commit 6657f99

Browse files
authored
Merge pull request #2742 from akshita31/validate_integrity
Validate integrity of the downloaded packages using the downloaded zip checksum
2 parents 8e1b471 + 1a0b635 commit 6657f99

22 files changed

+319
-80
lines changed

package-lock.json

Lines changed: 35 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"request-light": "0.2.4",
8282
"rxjs": "5.5.6",
8383
"semver": "*",
84+
"stream": "0.0.2",
8485
"strip-bom": "3.0.0",
8586
"tmp": "0.0.33",
8687
"vscode-debugprotocol": "1.6.1",
@@ -172,7 +173,8 @@
172173
"x86_64"
173174
],
174175
"installTestPath": "./.omnisharp/1.32.8/OmniSharp.exe",
175-
"platformId": "win-x64"
176+
"platformId": "win-x64",
177+
"integrity": "74accabc25766f02c4cb0f8ea49abb447428ed86fc103fd549a5b778a39de82c"
176178
},
177179
{
178180
"id": "OmniSharp",

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { AbsolutePathPackage } from './packageManager/AbsolutePathPackage';
4242
import { downloadAndInstallPackages } from './packageManager/downloadAndInstallPackages';
4343
import IInstallDependencies from './packageManager/IInstallDependencies';
4444
import { installRuntimeDependencies } from './InstallRuntimeDependencies';
45+
import { isValidDownload } from './packageManager/isValidDownload';
4546

4647
export async function activate(context: vscode.ExtensionContext): Promise<CSharpExtensionExports> {
4748

@@ -119,7 +120,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
119120
eventStream.subscribe(telemetryObserver.post);
120121

121122
let networkSettingsProvider = vscodeNetworkSettingsProvider(vscode);
122-
let installDependencies: IInstallDependencies = (dependencies: AbsolutePathPackage[]) => downloadAndInstallPackages(dependencies, networkSettingsProvider, eventStream);
123+
let installDependencies: IInstallDependencies = (dependencies: AbsolutePathPackage[]) => downloadAndInstallPackages(dependencies, networkSettingsProvider, eventStream, isValidDownload);
123124
let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, eventStream, platformInfo, installDependencies);
124125

125126
// activate language services

src/observers/CsharpChannelObserver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { BaseChannelObserver } from "./BaseChannelObserver";
7-
import { BaseEvent, InstallationFailure, DebuggerNotInstalledFailure, DebuggerPrerequisiteFailure, ProjectJsonDeprecatedWarning, PackageInstallStart } from "../omnisharp/loggingEvents";
7+
import { BaseEvent, InstallationFailure, DebuggerNotInstalledFailure, DebuggerPrerequisiteFailure, ProjectJsonDeprecatedWarning, PackageInstallStart, IntegrityCheckFailure } from "../omnisharp/loggingEvents";
88

99
export class CsharpChannelObserver extends BaseChannelObserver {
1010
public post = (event: BaseEvent) => {
1111
switch (event.constructor.name) {
1212
case PackageInstallStart.name:
13+
case IntegrityCheckFailure.name:
1314
this.showChannel(true);
1415
break;
1516
case InstallationFailure.name:

src/observers/CsharpLoggerObserver.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ export class CsharpLoggerObserver extends BaseLoggerObserver {
5858
case Event.LatestBuildDownloadStart.name:
5959
this.logger.appendLine("Getting latest OmniSharp version information");
6060
break;
61+
case Event.IntegrityCheckFailure.name:
62+
this.handleIntegrityCheckFailure(<Event.IntegrityCheckFailure>event);
63+
break;
64+
case Event.DownloadValidation.name:
65+
this.handleDownloadValidation(<Event.DownloadValidation>event);
66+
break;
67+
case Event.IntegrityCheckSuccess.name:
68+
this.handleIntegrityCheckSuccess(<Event.IntegrityCheckSuccess>event);
69+
break;
70+
}
71+
}
72+
73+
private handleDownloadValidation(event: Event.DownloadValidation) {
74+
this.logger.appendLine("Validating download...");
75+
}
76+
77+
private handleIntegrityCheckSuccess(event: Event.IntegrityCheckSuccess) {
78+
this.logger.appendLine("Integrity Check succeeded.");
79+
}
80+
81+
private handleIntegrityCheckFailure(event: Event.IntegrityCheckFailure) {
82+
if (event.retry) {
83+
this.logger.appendLine(`Package ${event.packageDescription} failed integrity check. Retrying..`);
84+
}
85+
else {
86+
this.logger.appendLine(`Package ${event.packageDescription} download from ${event.url} failed integrity check. Some features may not work as expected. Please restart Visual Studio Code to retrigger the download.`);
6187
}
6288
}
6389

src/observers/ErrorMessageObserver.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { BaseEvent, ZipError, DotNetTestRunFailure, DotNetTestDebugStartFailure } from "../omnisharp/loggingEvents";
6+
import { BaseEvent, ZipError, DotNetTestRunFailure, DotNetTestDebugStartFailure, IntegrityCheckFailure } from "../omnisharp/loggingEvents";
77
import { vscode } from "../vscodeAdapter";
88
import showErrorMessage from "./utils/ShowErrorMessage";
99

1010
export class ErrorMessageObserver {
11-
1211
constructor(private vscode: vscode) {
1312
}
1413

@@ -23,6 +22,14 @@ export class ErrorMessageObserver {
2322
case DotNetTestDebugStartFailure.name:
2423
this.handleDotNetTestDebugStartFailure(<DotNetTestDebugStartFailure>event);
2524
break;
25+
case IntegrityCheckFailure.name:
26+
this.handleIntegrityCheckFailure(<IntegrityCheckFailure> event);
27+
}
28+
}
29+
30+
handleIntegrityCheckFailure(event: IntegrityCheckFailure) {
31+
if (!event.retry) {
32+
showErrorMessage(this.vscode, `Package ${event.packageDescription} download from ${event.url} failed integrity check. Some features may not work as expected. Please restart Visual Studio Code to retrigger the download`);
2633
}
2734
}
2835

src/omnisharp/OmnisharpDownloader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { downloadAndInstallPackages } from '../packageManager/downloadAndInstall
1212
import { DownloadFile } from '../packageManager/FileDownloader';
1313
import { getRuntimeDependenciesPackages } from '../tools/RuntimeDependencyPackageUtils';
1414
import { getAbsolutePathPackagesToInstall } from '../packageManager/getAbsolutePathPackagesToInstall';
15+
import { isValidDownload } from '../packageManager/isValidDownload';
1516

1617
export class OmnisharpDownloader {
1718

@@ -30,7 +31,7 @@ export class OmnisharpDownloader {
3031
if (packagesToInstall && packagesToInstall.length > 0) {
3132
this.eventStream.post(new PackageInstallation(`OmniSharp Version = ${version}`));
3233
this.eventStream.post(new LogPlatformInfo(this.platformInfo));
33-
await downloadAndInstallPackages(packagesToInstall, this.networkSettingsProvider, this.eventStream);
34+
await downloadAndInstallPackages(packagesToInstall, this.networkSettingsProvider, this.eventStream, isValidDownload);
3435
this.eventStream.post(new InstallationSuccess());
3536
}
3637
}

src/omnisharp/OmnisharpPackageCreator.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ function GetPackage(inputPackage: Package, serverUrl: string, version: string, i
3737
throw new Error('Invalid version');
3838
}
3939

40-
let versionPackage = {...inputPackage,
41-
"description": `${inputPackage.description}, Version = ${version}`,
42-
"url": `${serverUrl}/releases/${version}/omnisharp-${inputPackage.platformId}.zip`,
43-
"installPath": `${installPath}/${version}`,
44-
"installTestPath": `./${installPath}/${version}/${installBinary}`,
45-
"fallbackUrl": "" //setting to empty so that we dont use the fallback url of the default packages
40+
let versionPackage: Package = {
41+
id: inputPackage.id,
42+
description: `${inputPackage.description}, Version = ${version}`,
43+
url: `${serverUrl}/releases/${version}/omnisharp-${inputPackage.platformId}.zip`,
44+
installPath: `${installPath}/${version}`,
45+
installTestPath: `./${installPath}/${version}/${installBinary}`,
46+
platforms: inputPackage.platforms,
47+
architectures: inputPackage.architectures,
48+
binaries: inputPackage.binaries,
49+
platformId: inputPackage.platformId
4650
};
4751

4852
return versionPackage;

src/omnisharp/loggingEvents.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ export class OpenURL {
162162
constructor(public url: string) { }
163163
}
164164

165+
export class IntegrityCheckFailure {
166+
constructor(public packageDescription: string, public url: string, public retry: boolean){ }
167+
}
168+
169+
export class IntegrityCheckSuccess {
170+
constructor() { }
171+
}
172+
165173
export class RazorPluginPathSpecified implements BaseEvent {
166174
constructor(public path: string) {}
167175
}
@@ -201,4 +209,5 @@ export class OmnisharpServerOnStop implements BaseEvent { }
201209
export class OmnisharpServerOnStart implements BaseEvent { }
202210
export class LatestBuildDownloadStart implements BaseEvent { }
203211
export class OmnisharpRestart implements BaseEvent { }
204-
export class DotNetTestDebugComplete implements BaseEvent { }
212+
export class DotNetTestDebugComplete implements BaseEvent { }
213+
export class DownloadValidation implements BaseEvent { }

src/packageManager/AbsolutePathPackage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class AbsolutePathPackage implements IPackage{
1717
public installPath?: AbsolutePath,
1818
public installTestPath?: AbsolutePath,
1919
public fallbackUrl?: string,
20-
public platformId?: string) {
20+
public platformId?: string,
21+
public integrity?: string) {
2122
}
2223

2324
public static getAbsolutePathPackage(pkg: Package, extensionPath: string) {
@@ -31,7 +32,8 @@ export class AbsolutePathPackage implements IPackage{
3132
getAbsoluteInstallPath(pkg, extensionPath),
3233
getAbsoluteInstallTestPath(pkg, extensionPath),
3334
pkg.fallbackUrl,
34-
pkg.platformId
35+
pkg.platformId,
36+
pkg.integrity
3537
);
3638
}
3739
}

0 commit comments

Comments
 (0)