Skip to content

Commit f526a2d

Browse files
authored
Merge pull request #153 from ethereum/validate-release-hash
Validate release hash on download
2 parents bd4eb69 + d1aaa92 commit f526a2d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

downloadCurrentVersion.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var pkg = require('./package.json');
77
var fs = require('fs');
88
var https = require('https');
99
var MemoryStream = require('memorystream');
10+
var ethJSUtil = require('ethereumjs-util');
1011

1112
function getVersionList (cb) {
1213
console.log('Retrieving available version list...');
@@ -24,10 +25,10 @@ function getVersionList (cb) {
2425
});
2526
}
2627

27-
function downloadBinary (version) {
28+
function downloadBinary (outputName, version, expectedHash) {
2829
console.log('Downloading version', version);
2930

30-
var file = fs.createWriteStream('soljson.js');
31+
var file = fs.createWriteStream(outputName, { encoding: 'binary' });
3132
https.get('https://ethereum.github.io/solc-bin/bin/' + version, function (response) {
3233
if (response.statusCode !== 200) {
3334
console.log('Error downloading file: ' + response.statusCode);
@@ -36,6 +37,11 @@ function downloadBinary (version) {
3637
response.pipe(file);
3738
file.on('finish', function () {
3839
file.close(function () {
40+
var hash = '0x' + ethJSUtil.sha3(fs.readFileSync(outputName, { encoding: 'binary' })).toString('hex');
41+
if (expectedHash !== hash) {
42+
console.log('Hash mismatch: ' + expectedHash + ' vs ' + hash);
43+
process.exit(1);
44+
}
3945
console.log('Done.');
4046
});
4147
});
@@ -47,5 +53,7 @@ console.log('Downloading correct solidity binary...');
4753
getVersionList(function (list) {
4854
list = JSON.parse(list);
4955
var wanted = pkg.version.match(/^(\d+\.\d+\.\d+)$/)[1];
50-
downloadBinary(list.releases[wanted]);
56+
var releaseFileName = list.releases[wanted];
57+
var expectedHash = list.builds.filter(function (entry) { return entry.path === releaseFileName; })[0].keccak256;
58+
downloadBinary('soljson.js', releaseFileName, expectedHash);
5159
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"yargs": "^4.7.1"
4545
},
4646
"devDependencies": {
47+
"ethereumjs-util": "^5.1.2",
4748
"semistandard": "^11.0.0",
4849
"tape": "^4.5.1",
4950
"tape-spawn": "^1.4.2"

0 commit comments

Comments
 (0)