New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always build HTTPSE with the latest rulesets, fix #7 #12
Merged
+44
−24
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Always build HTTPSE with the latest ruleset versions, fix #7
- Loading branch information
| @@ -1,34 +1,50 @@ | ||
| 'use strict' | ||
| const fs = require('fs') | ||
| const http = require('https') | ||
| const zlib = require('zlib') | ||
| const path = require('path') | ||
| const https = require('https') | ||
| const levelup = require('level') | ||
| const rmDir = require('./util').rmDir | ||
| const exec = require('child_process').exec | ||
|
|
||
| const xpiVersion = '2018.9.19' // Manually update this to latest version | ||
|
|
||
| const downloadRulesets = (dir, cb) => { | ||
| const downloadURL = `https://www.eff.org/files/https-everywhere-${xpiVersion}-eff.xpi` | ||
| const xpiFile = fs.createWriteStream('httpse.xpi') | ||
| http.get(downloadURL, (response) => { | ||
| response.pipe(xpiFile) | ||
| xpiFile.on('finish', () => { | ||
| xpiFile.close(() => { | ||
| exec('unzip ../httpse.xpi', { | ||
| cwd: 'https-everywhere' | ||
| }, (err) => { | ||
| if (err) { | ||
| throw err | ||
| } else { | ||
| let timestamp = '' | ||
| let baseURL = 'https://www.https-rulesets.org/v1/' | ||
cschanaj
Author
Contributor
|
||
|
|
||
| // Obtain the latest rulesets timestamp from EFF's official endpoint | ||
| https.get(baseURL + 'latest-rulesets-timestamp', (response) => { | ||
| response.on('data', (data) => { | ||
| timestamp += data.toString() | ||
| }) | ||
|
|
||
| // Download the rulesets once we obtained the timestamp | ||
| response.on('end', () => { | ||
| // ${timestamp} comes with trailing newlines, parse it and convert it back | ||
| let target = `default.rulesets.${Number(timestamp)}.gz` | ||
|
|
||
| https.get(baseURL + target, (stream) => { | ||
| // default.rulesets.${timestamp}.gz is gzipped, gunzip accordingly | ||
| // and pipe the output to ${filename} | ||
| let filename = path.join(dir, 'default.rulesets') | ||
| let zip = fs.createWriteStream(filename) | ||
|
|
||
| stream.pipe(zlib.createGunzip()).pipe(zip) | ||
|
|
||
| zip.on('finish', () => { | ||
| zip.close(() => { | ||
| // everything is fine here | ||
| cb() | ||
| } | ||
| }, (err) => { | ||
| console.log(`ERROR: Failed to write to ${filename}: ${err}`) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| .on('error', (err) => { | ||
| console.log(`Error downloading ${downloadURL}`, err) | ||
| }).on('error', (err) => { | ||
| console.log(`ERROR: Failed to retrieve ${target}: ${err}`) | ||
| }).end() | ||
| }) | ||
| }).on('error', (err) => { | ||
| console.log(`ERROR: Failed to retrieve the latest rulesets timestamp: ${err}`) | ||
| }).end() | ||
| } | ||
|
|
||
| const buildDataFiles = () => { | ||
| @@ -39,7 +55,10 @@ const buildDataFiles = () => { | ||
| 'Digg (partial)': 'breaks digg.com on C70+ with NET::ERR_CERT_SYMANTEC_LEGACY' | ||
| } | ||
|
|
||
| const rulesets = JSON.parse(fs.readFileSync('./https-everywhere/rules/default.rulesets', 'utf8')) | ||
| let rulesets = JSON.parse(fs.readFileSync('./https-everywhere/rules/default.rulesets', 'utf8')) | ||
| if (rulesets != null) { | ||
| rulesets = rulesets.rulesets | ||
| } | ||
|
|
||
| let jsonOutput = { | ||
| 'rulesetStrings': [], | ||
| @@ -157,8 +176,9 @@ const buildDataFiles = () => { | ||
|
|
||
| rmDir('./https-everywhere') | ||
| fs.mkdirSync('./https-everywhere') | ||
| fs.mkdirSync('./https-everywhere/rules') | ||
| rmDir('./out') | ||
| fs.mkdirSync('./out') | ||
|
|
||
| console.log('downloading rulesets') | ||
| downloadRulesets('./https-everywhere', buildDataFiles) | ||
| downloadRulesets('./https-everywhere/rules', buildDataFiles) | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
does EFF guarantee that the rulesets published under
v1will be compatible with HTTPSE'2018.9.19'? i assume so but just checking because they've done a few updates in the past where the format has changed (and so auto-updating would have broken Brave).otherwise this approach looks great