Skip to content

Commit d7b7347

Browse files
committed
JBDS-4026 Bundled binaries sha256 is not verified after download
1 parent 52c6b38 commit d7b7347

6 files changed

Lines changed: 65 additions & 31 deletions

File tree

browser/main.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,24 @@ let mainModule =
110110
reqs['oc.zip'].url,
111111
null,
112112
'cdk',
113+
reqs['cdk.zip'].sha256sum,
114+
reqs['rhel-vagrant-virtualbox.box'].sha256sum,
113115
reqs['oc.zip'].sha256sum),
114116

115117
jdk = new JdkInstall(
116118
installerDataSvc,
117119
reqs['jdk.msi'].dmUrl,
118120
null,
119121
reqs['jdk.msi'].prefix,
120-
'jdk8'),
122+
'jdk8',
123+
reqs['jdk.msi'].sha256sum),
121124

122125
jbds = new JbdsInstall(
123126
installerDataSvc,
124127
reqs['jbds.jar'].dmUrl,
125128
null,
126-
'developer-studio');
129+
'developer-studio',
130+
reqs['jbds.jar'].sha256sum);
127131

128132
installerDataSvc.addItemsToInstall(virtualbox,cygwin,vagrant,cdk,jdk,jbds);
129133

browser/model/cdk.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Installer from './helpers/installer';
1414
import Util from './helpers/util.js';
1515

1616
class CDKInstall extends InstallableItem {
17-
constructor(installerDataSvc, $timeout, cdkUrl, cdkBoxUrl, ocUrl, installFile, targetFolderName, ocSha256) {
17+
constructor(installerDataSvc, $timeout, cdkUrl, cdkBoxUrl, ocUrl, installFile, targetFolderName, cdkSha256, boxSha256, ocSha256) {
1818
super('cdk',
1919
900,
2020
cdkUrl,
@@ -25,6 +25,9 @@ class CDKInstall extends InstallableItem {
2525
this.$timeout = $timeout;
2626
this.cdkBoxUrl = cdkBoxUrl;
2727
this.ocUrl = ocUrl;
28+
29+
this.cdkSha256 = cdkSha256;
30+
this.boxSha256 = boxSha256;
2831
this.ocSha256 = ocSha256;
2932

3033
this.cdkFileName = 'cdk.zip';
@@ -62,7 +65,7 @@ class CDKInstall extends InstallableItem {
6265
if(!fs.existsSync(path.join(this.downloadFolder, this.boxName))) {
6366
let cdkBoxWriteStream = fs.createWriteStream(this.cdkBoxDownloadedFile);
6467
this.downloader.setWriteStream(cdkBoxWriteStream);
65-
this.downloader.downloadAuth(this.cdkBoxUrl,username,password);
68+
this.downloader.downloadAuth(this.cdkBoxUrl,username,password,this.cdkBoxDownloadedFile,this.boxSha256);
6669
} else {
6770
this.cdkBoxDownloadedFile = path.join(this.downloadFolder, this.boxName);
6871
this.downloader.closeHandler();
@@ -71,7 +74,7 @@ class CDKInstall extends InstallableItem {
7174
if(!fs.existsSync(path.join(this.downloadFolder, this.cdkFileName))) {
7275
let cdkWriteStream = fs.createWriteStream(this.cdkDownloadedFile);
7376
this.downloader.setWriteStream(cdkWriteStream);
74-
this.downloader.downloadAuth(this.getDownloadUrl(), username, password);
77+
this.downloader.downloadAuth(this.getDownloadUrl(),username,password,this.cdkDownloadedFile, this.cdkSha256);
7578
} else {
7679
this.cdkDownloadedFile = path.join(this.downloadFolder, this.cdkFileName);
7780
this.downloader.closeHandler();

browser/model/jbds.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import CDKInstall from './cdk.js';
1717
import Util from './helpers/util';
1818

1919
class JbdsInstall extends InstallableItem {
20-
constructor(installerDataSvc, downloadUrl, installFile, targetFolderName) {
20+
constructor(installerDataSvc, downloadUrl, installFile, targetFolderName, jbdsSha256) {
2121
super('jbds',
2222
1600,
2323
downloadUrl,
@@ -26,6 +26,7 @@ class JbdsInstall extends InstallableItem {
2626
installerDataSvc);
2727

2828
this.downloadedFileName = 'jbds.jar';
29+
this.jbdsSha256 = jbdsSha256;
2930
this.bundledFile = path.join(this.downloadFolder, this.downloadedFileName);
3031
this.downloadedFile = path.join(this.installerDataSvc.tempDir(), 'jbds.jar');
3132
this.installConfigFile = path.join(this.installerDataSvc.tempDir(), 'jbds-autoinstall.xml');
@@ -123,7 +124,7 @@ class JbdsInstall extends InstallableItem {
123124
let writeStream = fs.createWriteStream(this.downloadedFile);
124125
this.downloader = new Downloader(progress, success, failure);
125126
this.downloader.setWriteStream(writeStream);
126-
this.downloader.downloadAuth(this.downloadUrl,username,password);
127+
this.downloader.downloadAuth(this.downloadUrl,username,password,this.downloadedFile,this.jbdsSha256);
127128
} else {
128129
this.downloadedFile = this.bundledFile;
129130
success();

browser/model/jdk-install.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Util from './helpers/util';
1515
import Version from './helpers/version';
1616

1717
class JdkInstall extends InstallableItem {
18-
constructor(installerDataSvc, downloadUrl, installFile, prefix, targetFolderName) {
18+
constructor(installerDataSvc, downloadUrl, installFile, prefix, targetFolderName,jdkSha256) {
1919
super('jdk',
2020
260,
2121
downloadUrl,
@@ -24,6 +24,7 @@ class JdkInstall extends InstallableItem {
2424
installerDataSvc);
2525

2626
this.downloadedFileName = 'jdk.msi';
27+
this.jdkSha256 = jdkSha256;
2728
this.bundledFile = path.join(this.downloadFolder, this.downloadedFileName);
2829
this.downloadedFile = path.join(this.installerDataSvc.tempDir(), this.downloadedFileName);
2930
this.existingVersion = '';
@@ -123,7 +124,7 @@ class JdkInstall extends InstallableItem {
123124
let writeStream = fs.createWriteStream(this.downloadedFile);
124125
this.downloader = new Downloader(progress, success, failure);
125126
this.downloader.setWriteStream(writeStream);
126-
this.downloader.downloadAuth(this.downloadUrl,username,password);
127+
this.downloader.downloadAuth(this.downloadUrl,username,password,this.downloadedFile,this.jdkSha256);
127128
} else {
128129
this.downloadedFile = this.bundledFile;
129130
success();

gulpfile.js

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ gulp.task('transpile:app', ['create-modules-link'], function() {
6262
.pipe(sourcemaps.write())
6363
.pipe(gulp.dest('transpiled'));
6464

65-
var resources = gulp.src(['browser/**/*', '!browser/**/*.js', '*.json', 'uninstaller/*.ps1'], {base: '.'})
65+
var resources = gulp.src(['browser/**/*', '!browser/**/*.js', '!requirements.json', '*.json', 'uninstaller/*.ps1'], {base: '.'})
6666
.pipe(gulp.dest('transpiled'));
6767

6868
return merge(sources, resources);
@@ -151,23 +151,49 @@ gulp.task('create-7zip-archive', function(cb) {
151151
exec(packCmd, createExecCallback(cb, true));
152152
});
153153

154-
gulp.task('update-devstudio-version', function(cb) {
155-
let url = reqs['jbds.jar'].url.substring(0, reqs['jbds.jar'].url.lastIndexOf("/")) + '/content.json';
156-
request(url, function(err, response, body) {
157-
if (err) {
158-
cb(err);
159-
} else {
160-
let versionRegex = /(\d+\.\d+\.\d+\.\w+\d*).*/;
161-
let finalVersion = versionRegex.exec(body)[1];
154+
gulp.task('update-requirements',['create-modules-link'], function() {
162155

163-
if (reqs['jbds.jar'].version != finalVersion) {
164-
reqs['jbds.jar'].version = finalVersion;
165-
fs.writeFile('./requirements.json', JSON.stringify(reqs, null, 2), cb);
166-
} else {
167-
cb();
156+
let updateDevStudioVersion = ()=>{
157+
return new Promise((resolve,reject) => {
158+
let url = reqs['jbds.jar'].url.substring(0, reqs['jbds.jar'].url.lastIndexOf("/")) + '/content.json';
159+
request(url, (err, response, body)=>{
160+
if (err) {
161+
reject(err);
162+
} else {
163+
let versionRegex = /(\d+\.\d+\.\d+\.\w+\d*).*/;
164+
let finalVersion = versionRegex.exec(body)[1];
165+
166+
if (reqs['jbds.jar'].version != finalVersion) {
167+
reqs['jbds.jar'].version = finalVersion;
168+
}
169+
resolve()
170+
}
171+
});
172+
});
173+
};
174+
175+
let updateDevStudioSha = ()=>{
176+
return new Promise((resolve,reject) => {
177+
let url = reqs['jbds.jar'].sha256sum;
178+
if (url.length == 64 && url.indexOf("http")<0 && url.indexOf("ftp")<0) {
179+
resolve();
180+
} else {
181+
request(url, (err, response, body) => {
182+
reqs['jbds.jar'].sha256sum = body;
183+
resolve();
184+
});
168185
}
169-
}
170-
});
186+
});
187+
};
188+
189+
return Promise.resolve()
190+
.then(updateDevStudioVersion)
191+
.then(updateDevStudioSha)
192+
.then(()=>{
193+
fs.writeFile('./transpiled/requirements.json', JSON.stringify(reqs, null, 2));
194+
}).catch((err)=>{
195+
console.log(err);
196+
});
171197
});
172198

173199
gulp.task('update-metadata', function(cb) {
@@ -228,18 +254,18 @@ function createSHA256File(filename, cb) {
228254

229255
// Create stub installer that will then download all the requirements
230256
gulp.task('package-simple', function(cb) {
231-
runSequence(['check-requirements', 'clean'], 'create-dist-win-dir', 'update-devstudio-version', ['generate',
257+
runSequence(['check-requirements', 'clean'], 'create-dist-win-dir', 'update-requirements', ['generate',
232258
'prepare-tools'], 'package', 'cleanup', cb);
233259
});
234260

235261
gulp.task('package-bundle', function(cb) {
236-
runSequence(['check-requirements', 'clean'], 'create-dist-win-dir', 'update-devstudio-version', ['generate',
262+
runSequence(['check-requirements', 'clean'], 'create-dist-win-dir', 'update-requirements', ['generate',
237263
'prepare-tools'], 'prefetch', 'package', 'cleanup', cb);
238264
});
239265

240266
// Create both installers
241267
gulp.task('dist', function(cb) {
242-
runSequence(['check-requirements', 'clean'], 'create-dist-win-dir', 'update-devstudio-version', ['generate',
268+
runSequence(['check-requirements', 'clean'], 'create-dist-win-dir', 'update-requirements', ['generate',
243269
'prepare-tools'], 'package', 'prefetch', 'package', 'cleanup', cb);
244270
});
245271

@@ -351,8 +377,7 @@ function prefetch(bundle, targetFolder) {
351377
function downloadAndReadSHA256(targetFolder, fileName, reqURL, reject, processResult) {
352378
let currentFile = path.join(targetFolder, fileName);
353379
let currentSHA256 = 'NOSHA256SUM';
354-
if (reqURL.length == 64 && reqURL.indexOf("http")<0 && reqURL.indexOf("ftp")<0)
355-
{
380+
if (reqURL.length == 64 && reqURL.indexOf("http")<0 && reqURL.indexOf("ftp")<0) {
356381
// return the hardcoded SHA256sum in requirements.json
357382
if(!fileName.endsWith('.sha256')) {
358383
console.log('[INFO] \'' + fileName + '\' hardcoded sha256 check');

test/unit/model/cdk-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('CDK installer', function() {
101101
ocUrl = reqs['oc.zip'].url;
102102

103103
beforeEach(function () {
104-
installer = new CDKInstall(installerDataSvc, 900, cdkUrl, cdkBoxUrl, ocUrl, null);
104+
installer = new CDKInstall(installerDataSvc, 900, cdkUrl, cdkBoxUrl, ocUrl, null, null, null);
105105
sandbox = sinon.sandbox.create();
106106
});
107107

0 commit comments

Comments
 (0)