Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 27 additions & 2 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ var fs = require('fs');
var path = require('path');
var os = require('os');
var unzip = require('unzip');
var crypto = require('crypto');

var WIX_BINARY_URL = 'http://static.wixtoolset.org/releases/v3.9.1006.0/wix39-binaries.zip'
var zip_hash = '0f05d338d364b348d20c1ccb79f6103cc5209417382ce1e705ce436ea85fb46f0bc32b75d5f5de9ad62bbda5b2d93ff9f1497370e918d5ef0c3fa12d60308ca1';

var zipPath = path.resolve(os.tmpdir(), 'wix.zip');
var file = fs.createWriteStream(zipPath);
Expand All @@ -15,8 +17,31 @@ var request = http.get(WIX_BINARY_URL, function(response) {
process.stdout.write(".");
});
response.on('end', function() {
console.log('Extracting');
fs.createReadStream(zipPath).pipe(unzip.Extract({path: path.resolve(__dirname, 'wix-bin')}));
console.log('Download complete');
console.log('Starting integrity check...');

// Verify file using hash make MITM harder
var fstream = fs.createReadStream(zipPath);
var hash = crypto.createHash('sha512');
hash.setEncoding('hex');

fstream.on('end', function() {
hash.end();
calculated_hash = hash.read();
if (zip_hash === calculated_hash){
console.log('Extracting');
fs.createReadStream(zipPath).pipe(unzip.Extract({path: path.resolve(__dirname, 'wix-bin')}));
console.log("Extraction complete")
}else{
console.error(`File verification failed:\nDownloaded file sha512: ${calculated_hash}`);
fs.unlink(zipPath, function(err) {
if (err) throw err;
console.log('File deleted');
process.exit(-1);
});
}
});
fstream.pipe(hash);
})
});

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"crypto": "^1.0.1",
"unzip": "^0.1.11"
},
"repository" :
{ "type" : "git"
, "url" : "https://github.com/rewiredpictures/node-wixtoolset.git"
"repository": {
"type": "git",
"url": "https://github.com/rewiredpictures/node-wixtoolset.git"
}

}