forked from EvanOxfeld/node-unzip
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from ZJONSSON/crx
Crx
- Loading branch information
Showing
8 changed files
with
202 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var temp = require('temp'); | ||
var dirdiff = require('dirdiff'); | ||
var unzip = require('../'); | ||
|
||
test('parse/extract crx archive', function (t) { | ||
var archive = path.join(__dirname, '../testData/compressed-standard-crx/archive.crx'); | ||
|
||
temp.mkdir('node-unzip-', function (err, dirPath) { | ||
if (err) { | ||
throw err; | ||
} | ||
var unzipExtractor = unzip.Extract({ path: dirPath }); | ||
unzipExtractor.on('error', function(err) { | ||
throw err; | ||
}); | ||
unzipExtractor.on('close', testExtractionResults); | ||
|
||
fs.createReadStream(archive).pipe(unzipExtractor); | ||
|
||
function testExtractionResults() { | ||
t.same(unzipExtractor.crxHeader.version,2); | ||
dirdiff(path.join(__dirname, '../testData/compressed-standard/inflated'), dirPath, { | ||
fileContents: true | ||
}, function (err, diffs) { | ||
if (err) { | ||
throw err; | ||
} | ||
t.equal(diffs.length, 0, 'extracted directory contents'); | ||
t.end(); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
test('open methods', function(t) { | ||
var archive = path.join(__dirname, '../testData/compressed-standard-crx/archive.crx'); | ||
var buffer = fs.readFileSync(archive); | ||
var request = require('request'); | ||
var AWS = require('aws-sdk'); | ||
var s3 = new AWS.S3({region: 'us-east-1'}); | ||
|
||
// We have to modify the `getObject` and `headObject` to use makeUnauthenticated | ||
s3.getObject = function(params,cb) { | ||
return s3.makeUnauthenticatedRequest('getObject',params,cb); | ||
}; | ||
|
||
s3.headObject = function(params,cb) { | ||
return s3.makeUnauthenticatedRequest('headObject',params,cb); | ||
}; | ||
|
||
var tests = [ | ||
{name: 'buffer',args: [buffer]}, | ||
{name: 'file', args: [archive]}, | ||
{name: 'url', args: [request, 'https://s3.amazonaws.com/unzipper/archive.crx']}, | ||
{name: 's3', args: [s3, { Bucket: 'unzipper', Key: 'archive.crx'}]} | ||
]; | ||
|
||
tests.forEach(function(test) { | ||
t.test(test.name, function(t) { | ||
t.test('opening with crx option', function(t) { | ||
var method = unzip.Open[test.name]; | ||
method.apply(method, test.args.concat({crx:true})) | ||
.then(function(d) { | ||
return d.files[1].buffer(); | ||
}) | ||
.then(function(d) { | ||
t.same(String(d), '42\n', test.name + ' content matches'); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash -e | ||
# | ||
# Purpose: Pack a Chromium extension directory into crx format | ||
|
||
crx="archive.crx" | ||
pub="publickey.tmp" | ||
sig="signature.tmp" | ||
zip="../compressed-standard/archive.zip" | ||
key="./key" | ||
|
||
# signature | ||
openssl sha1 -sha1 -binary -sign key.pem < "$zip" > "$sig" | ||
|
||
# public key | ||
openssl rsa -pubout -outform DER < key.pem > "$pub" 2>/dev/null | ||
|
||
byte_swap () { | ||
# Take "abcdefgh" and return it as "ghefcdab" | ||
echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}" | ||
} | ||
|
||
crmagic_hex="4372 3234" # Cr24 | ||
version_hex="0200 0000" # 2 | ||
pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}'))) | ||
sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}'))) | ||
( | ||
echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p | ||
cat "$pub" "$sig" "$zip" | ||
) > "$crx" | ||
rm *.tmp | ||
echo "Wrote $crx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDP/wGpId0UmDp9 | ||
hLSepNEErUJGeATwDWGbNyGkK621CHPAMrDqNO8Z2XAimic6bbxUg6NxYLKwkxDM | ||
+5kGY3lHFQkqmwO1nYwMTq8hSjmEtgfF+vF3EM5DJamv9vHVgQ6uW3v6VSvlSl7v | ||
RlO8IgoIh1hTpVZN6w3rKIcQdENlTtfZJZIHWcv2oYp05+tw+hAWKB8WAmLrRzKF | ||
tP9VrIPYIVClqhyOQR386d1U+8YW26LKOTQmLZ9Fy45bzQSYKA3qDObYustvncvR | ||
1IOvTHKM+/2DPT+k9QvvWe0osKkDfG9lmsxO3Pv0XJ5F1TEjW621OychV46u4k2E | ||
ugcqLw7JAgMBAAECggEBAK8kSrCxjCj4WmAxK6penIa0ohcWnwnIKsV5cgF8qiPD | ||
fzx7Ms+0TRXWK39nkNq5Zpk/05P32d+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