More updates for Java validations on darwin.

Also, now require version 8u52+, as pack200 algo changed after 8u45.
This commit is contained in:
Daniel Scalzi 2018-04-12 21:38:27 -04:00
parent 2a551f18ba
commit fc81016dc6
No known key found for this signature in database
GPG Key ID: 5CA2F145B63535F9

View File

@ -612,7 +612,27 @@ class AssetGuard extends EventEmitter {
} }
/** /**
* Validates the output of a JVM's properties. Currently validates that a JRE is x64. * Parses a **full** Java Runtime version string and resolves
* the version information. Uses Java 8 formatting.
*
* @param {string} verString Full version string to parse.
* @returns Object containing the version information.
*/
static parseJavaRuntimeVersion(verString){
// 1.{major}.0_{update}-b{build}
// ex. 1.8.0_152-b16
const ret = {}
let pts = verString.split('-')
ret.build = parseInt(pts[1].substring(1))
pts = verString[0].split('_')
ret.update = parseInt(pts[1])
ret.major = parseInt(pts[0].split['.'][1])
return ret
}
/**
* Validates the output of a JVM's properties. Currently validates that a JRE is x64
* and that the major = 8, update > 52.
* *
* @param {string} stderr The output to validate. * @param {string} stderr The output to validate.
* *
@ -622,15 +642,34 @@ class AssetGuard extends EventEmitter {
static _validateJVMProperties(stderr){ static _validateJVMProperties(stderr){
const res = stderr const res = stderr
const props = res.split('\n') const props = res.split('\n')
const goal = 2
let checksum = 0
for(let i=0; i<props.length; i++){ for(let i=0; i<props.length; i++){
if(props[i].indexOf('sun.arch.data.model') > -1){ if(props[i].indexOf('sun.arch.data.model') > -1){
let arch = props[i].split('=')[1].trim() let arch = props[i].split('=')[1].trim()
console.log(props[i].trim()) console.log(props[i].trim())
return parseInt(arch) >= 64 if(parseInt(arch) === 64){
++checksum
if(checksum === goal){
return true
} }
} }
// sun.arch.data.model not found? } else if(props[i].indexOf('java.runtime.version') > -1){
return false let verString = props[i].split('=')[1].trim()
console.log(props[i].trim())
const verOb = AssetGuard.parseJavaRuntimeVersion(verString)
if(verOb.major === 8 && verOb.update > 52){
++checksum
if(checksum === goal){
return true
}
}
}
}
return checksum === goal
} }
/** /**
@ -722,8 +761,13 @@ class AssetGuard extends EventEmitter {
console.log(err) console.log(err)
} else { } else {
for(let i=0; i<files.length; i++){ for(let i=0; i<files.length; i++){
if(process.platform === 'darwin'){
// On darwin, Java home is root/Contents/Home
res.add(path.join(x64RuntimeDir, files[i], 'Contents', 'Home'))
} else {
res.add(path.join(x64RuntimeDir, files[i])) res.add(path.join(x64RuntimeDir, files[i]))
} }
}
resolve(res) resolve(res)
} }
}) })
@ -902,17 +946,24 @@ class AssetGuard extends EventEmitter {
const pathSet = new Set() const pathSet = new Set()
// Check Internet Plugins folder.
const iPPath = AssetGuard._scanInternetPlugins() const iPPath = AssetGuard._scanInternetPlugins()
if(iPPath != null){ if(iPPath != null){
pathSet.add(iPPath) pathSet.add(iPPath)
} }
// Check the JAVA_HOME environment variable.
const jHome = AssetGuard._scanJavaHome() const jHome = AssetGuard._scanJavaHome()
if(jHome != null){ if(jHome != null){
pathSet.add(jHome) pathSet.add(jHome)
} }
let pathArr = Array.from(pathSet) // Get possible paths from the data directory.
const pathSet2 = await AssetGuard._scanDataFolder(dataDir)
// TODO Sort by highest version.
let pathArr = Array.from(pathSet2).concat(Array.from(pathSet))
for(let i=0; i<pathArr.length; i++) { for(let i=0; i<pathArr.length; i++) {
const execPath = AssetGuard.javaExecFromRoot(pathArr[i]) const execPath = AssetGuard.javaExecFromRoot(pathArr[i])
let res = await AssetGuard._validateJavaBinary(execPath) let res = await AssetGuard._validateJavaBinary(execPath)