Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
debug('ERROR')
debug(`No xccdf found in ${archivePath}`)
unlinkSync(desiredFile)
reject(err)
})
.pipe(createWriteStream(desiredFile))
.on('finish', () => {
resolve({ data: 'complete' })
})
} else {
// for some reason Apple Workstation 10.8 STIGs xccdf is zipped up
// inside a zip. ¯\_(ツ)_/¯
debug('Working on a zip inside a zip')
const secondZipPath = archivePath.replace('.zip', '-secondary.zip')
createReadStream(archivePath)
.pipe(unzipper.ParseOne(/.*.zip/i)) // nested ZIP archives YAY!
.on('error', err => {
debug(err)
debug('ERROR')
unlinkSync()
reject(err)
})
.pipe(createWriteStream(secondZipPath))
.on('finish', () => {
createReadStream(secondZipPath)
.pipe(unzipper.ParseOne(/.*Manual-xccdf.xml/i))
.on('error', err => {
debug(err)
debug('ERROR')
unlinkSync()
return reject(err)
})
return new Promise((resolve, reject) => {
try {
if (!archivePath.includes('U_Apple_OS_X_10-8')) {
createReadStream(archivePath)
.pipe(unzipper.ParseOne(/.*Manual-xccdf.xml/i))
.on('error', err => {
debug(err)
debug('ERROR')
debug(`No xccdf found in ${archivePath}`)
unlinkSync(desiredFile)
reject(err)
})
.pipe(createWriteStream(desiredFile))
.on('finish', () => {
resolve({ data: 'complete' })
})
} else {
// for some reason Apple Workstation 10.8 STIGs xccdf is zipped up
// inside a zip. ¯\_(ツ)_/¯
debug('Working on a zip inside a zip')
const secondZipPath = archivePath.replace('.zip', '-secondary.zip')
return peek({ newline: false, maxBuffer: 10 }, function (data, swap) {
if (maxRecursion < 0) return swap(new Error('Maximum recursion reached'))
switch (isCompressed(data)) {
case 1: return swap(null, pumpify(inflate.gzip(), unzipStream(inflate, maxRecursion - 1)))
case 2: return swap(null, pumpify(inflate.deflate(), unzipStream(inflate, maxRecursion - 1)))
case 3: return swap(null, pumpify(unZipper.ParseOne(), unzipStream(inflate, maxRecursion - 1)))
}
return swap(null, new Minipass())
})
}
const readAPKManifest = (cb) => {
D(`Reading APK Manifest`);
const apk_manifest_chunks = [];
function cb_once(err, manifest) {
cb && cb(err, manifest);
cb = null;
}
fs.createReadStream(this.apk_fpn)
.pipe(unzipper.ParseOne(/^AndroidManifest\.xml$/))
.on('data', chunk => {
apk_manifest_chunks.push(chunk);
})
.once('error', err => {
cb_once(err);
})
.once('end', () => {
try {
const manifest = decode_binary_xml(Buffer.concat(apk_manifest_chunks));
D(`APK manifest read complete`);
cb_once(null, manifest);
} catch (err) {
D(`APK manifest decode failed: ${err.message}`);
cb_once(err);
}
});