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

Add large scale https updates with bloom filter #355

Merged
merged 21 commits into from
Aug 23, 2018

Conversation

subsymbolic
Copy link
Contributor

@subsymbolic subsymbolic commented Aug 22, 2018

Task/Issue URL: https://app.asana.com/0/72649045549333/721626625236431
Tech Design URL: https://app.asana.com/0/72649045549333/727813825116580

Description:
Add large scale https support:

  • Remove legacy https solution
  • Add updated https solution
  • Add new api requests
  • Update core data model and persitence layer to support new data

Steps to test this PR:

TEST ONE:

  1. Visit http://example.com
  2. Check the logs and ensure they report that this site is "upgradable"
  3. Note that the scheme is updated to https

TEST TWO:

  1. Visit http://aaaaaaaaaaaaa.co.uk
  2. Check the logs and ensure they report that this site is not "upgradable"
  3. Note that the scheme remains as "http"
  4. The site itself doesn't exist (thus definitely not in our upgrade list), so won't load

TEST THREE:

  1. Visit any site from https://staticcdn.duckduckgo.com/https/https-mobile-whitelist.json
  2. Note the logs stats that it is whitelisted and cannot be autoupgraded
  3. Note that the scheme remains as "http" (beware some sites will upgrade themselves!)

TEST FOUR:

  1. Install the app from develop and run it
  2. Then install this version over the top
  3. Ensure that nothing in the db goes boom!

Internal references:

Software Engineering Expectations
Technical Design Template

@subsymbolic subsymbolic changed the title Add large scale https updates with bloom filter - WIP Add large scale https updates with bloom filter Aug 22, 2018
@subsymbolic subsymbolic requested a review from brindy August 22, 2018 13:37
@subsymbolic
Copy link
Contributor Author

I am seeing an atb test failure on CI (but not locally) which I am investigating. Other than that, this is ready for review @brindy.

@subsymbolic
Copy link
Contributor Author

@brindy and I are seeing the ATB Test failures on other branches too so have ruled out it being introduced by this PR. We will investigate it separately.

@brindy brindy self-assigned this Aug 23, 2018
Copy link
Contributor

@brindy brindy left a comment

Choose a reason for hiding this comment

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

A few comments.

In summary, I think CoreData is unnecessary here and adding complexity that isn't needed.

Otherwise, it's looking good and HTTPS functionality seems to work sweetly.

import Foundation

public struct HTTPSTransientBloomFilterSpecification {
let totalEntries: Int
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be Decodable which would make the JSON parsing a little easier. Can use optionals if you're worried about data missing in future versions of the file. Data in the JSON that isn't handled is ignored by default.

}

static func bloomFilterSpecification(fromJSONData data: Data) -> HTTPSTransientBloomFilterSpecification? {
guard let json = try? JSONSerialization.jsonObject(with: data, options: []) else { return nil }
Copy link
Contributor

Choose a reason for hiding this comment

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

If HTTPSTransientBloomFilterSpecification was Decodable you could just use the JSONDecoder. Likewise for this whitelist.

We've got a couple of examples in the code already, though we also have examples of JSONSeralization, but I'd like us to move to the Codable pattern as our standard. I'll add a LHF task to update them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. I had considered using Codable but was refactoring existing code and didn't know we had it in the project. I feel better using the modern pattern here, thanks!

<element name="HTTPSUpgradeSimpleDomain" positionX="-63" positionY="-18" width="128" height="60"/>
<element name="HTTPSUpgradeWildcardDomain" positionX="-54" positionY="-9" width="128" height="60"/>
<element name="HTTPSBloomFilterSpecification" positionX="-1269" positionY="-171" width="128" height="90"/>
<element name="HTTPSWhitlistedDomain" positionX="-1098" positionY="-157" width="128" height="58"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Spelling mistake HTTPSWhitlisted -> HTTPSWhitelisted


import Foundation

public struct HTTPSTransientBloomFilterSpecification: Equatable {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is starting to seem overly complex with too many layers.

Why not just dump Core Data for this and store the files on disk? Using Codable pattern and optionals vars will help with migration issues.

If the whitelist is not likely to grow too big, drop Core Data for that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We discussed this and decided that it made sense to stick with CoreData over files on disk for structured data for the migration benefits.

Copy link
Contributor

@brindy brindy left a comment

Choose a reason for hiding this comment

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

Looks good! Nice work!

@subsymbolic
Copy link
Contributor Author

Thanks for the review @brindy!

@subsymbolic subsymbolic merged commit dfc3521 into develop Aug 23, 2018
@subsymbolic subsymbolic deleted the feature/large_scale_https branch August 23, 2018 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants