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

use sha256 for validating windows updates #201777

Merged
merged 2 commits into from
Jan 5, 2024
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
6 changes: 3 additions & 3 deletions src/vs/base/node/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import * as crypto from 'crypto';
import * as fs from 'fs';
import { createSingleCallFunction } from 'vs/base/common/functional';

export async function checksum(path: string, sha1hash: string | undefined): Promise<void> {
export async function checksum(path: string, sha256hash: string | undefined): Promise<void> {
const checksumPromise = new Promise<string | undefined>((resolve, reject) => {
const input = fs.createReadStream(path);
const hash = crypto.createHash('sha1');
const hash = crypto.createHash('sha256');
input.pipe(hash);

const done = createSingleCallFunction((err?: Error, result?: string) => {
Expand All @@ -32,7 +32,7 @@ export async function checksum(path: string, sha1hash: string | undefined): Prom

const hash = await checksumPromise;

if (hash !== sha1hash) {
if (hash !== sha256hash) {
throw new Error('Hash mismatch');
}
}
2 changes: 1 addition & 1 deletion src/vs/base/test/node/crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ flakySuite('Crypto', () => {
const testFile = join(testDir, 'checksum.txt');
await Promises.writeFile(testFile, 'Hello World');

await checksum(testFile, '0a4d55a8d778e5022fab701977c5d840bbc486d0');
await checksum(testFile, 'a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e');
});
});
2 changes: 1 addition & 1 deletion src/vs/platform/update/common/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IUpdate {
version: string;
productVersion: string;
url?: string;
hash?: string;
sha256hash?: string;
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/vs/platform/update/electron-main/updateService.win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,11 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
return Promise.resolve(updatePackagePath);
}

const url = update.url;
const hash = update.hash;
const downloadPath = `${updatePackagePath}.tmp`;

return this.requestService.request({ url }, CancellationToken.None)
return this.requestService.request({ url: update.url }, CancellationToken.None)
.then(context => this.fileService.writeFile(URI.file(downloadPath), context.stream))
.then(hash ? () => checksum(downloadPath, update.hash) : () => undefined)
.then(update.sha256hash ? () => checksum(downloadPath, update.sha256hash) : () => undefined)
.then(() => pfs.Promises.rename(downloadPath, updatePackagePath, false /* no retry */))
.then(() => updatePackagePath);
});
Expand Down