Skip to content
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
merged 3 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Builds HTTPS Everywhere ruleset files for Brave.

## Configuring

Update `xpiVersion` in `scripts/preloadHTTPSE.js` to the latest release number from https://www.eff.org/https-everywhere. If there are rulesets that are broken and need to be disabled, add them to the `exclusions` list.
If there are rulesets that are broken and need to be disabled, add them to the `exclusions` list.

If there is a breaking ruleset format change, bump the version number in
`package.json` by one major point release. (Ex: 5.2.21 to 5.3.0. The minor
Expand Down
66 changes: 43 additions & 23 deletions scripts/preloadHTTPSE.js
Original file line number Diff line number Diff line change
@@ -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/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does EFF guarantee that the rulesets published under v1 will 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

Copy link
Contributor Author

@cschanaj cschanaj Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The v1 directory was added as per EFForg/https-everywhere#14907 (comment) and EFForg/https-everywhere#14907 (comment), so I assume there shouldn't be breaking changes in the rulesets format. Maybe @Hainish @zoracon from EFF can help guarantee that?


// 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) => {
// ${target} is gzipped, gunzip accordingly
// and pipe the output to ${filename}
let filename = path.join(dir, 'default.rulesets')
let output = fs.createWriteStream(filename)

stream.pipe(zlib.createGunzip()).pipe(output)

output.on('finish', () => {
output.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 = () => {
Expand All @@ -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': [],
Expand Down Expand Up @@ -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)