Permalink
Please sign in to comment.
Browse files
add an implementation of HTTPS Everywhere
A ruby script converts all of the XML rule files into hashes and dumps them to plist files, which are parsed by the app at startup. When intercepting URLs, check for matching rules by hostname (using the same wildcarding as the Javascript in the Firefox extension) and then rewrite them. Supports exclusions as well. Seems to be pretty fast, and has a cache size of (currently) 20 rules to avoid having to recompile all those regexes and stuff on every request.
- Loading branch information...
Showing
with
484,533 additions
and 60 deletions.
- +3 −0 .gitmodules
- +4 −0 Podfile
- +3 −0 Podfile.lock
- +70 −0 endless Tests/HTTPSEverywhere_Tests.m
- +24 −0 endless Tests/Info.plist
- +211 −0 endless Tests/mock_rules.plist
- +34 −0 endless Tests/mock_targets.plist
- +229 −14 endless.xcodeproj/project.pbxproj
- +1 −2 endless/AppDelegate.h
- +7 −0 endless/AppDelegate.m
- +4 −4 endless/Base.lproj/Main.storyboard
- +13 −0 endless/HTTPSEverywhere.h
- +128 −0 endless/HTTPSEverywhere.m
- +18 −0 endless/HTTPSEverywhereRule.h
- +172 −0 endless/HTTPSEverywhereRule.m
- +55 −30 endless/URLInterceptor.m
- +2 −8 endless/WebViewController.m
- +14 −0 endless/endless-Prefix.pch
- +0 −2 endless/main.m
- +1 −0 https-everywhere
- +428,814 −0 https-everywhere_rules.plist
- +54,678 −0 https-everywhere_targets.plist
- +48 −0 https-everywhere_to_plist.rb
| @@ -0,0 +1,3 @@ | ||
| [submodule "https-everywhere"] | ||
| path = https-everywhere | ||
| url = https://github.com/EFForg/https-everywhere |
| @@ -0,0 +1,70 @@ | ||
| #import <UIKit/UIKit.h> | ||
| #import <XCTest/XCTest.h> | ||
| #import <OCMock/OCMock.h> | ||
| #import "HTTPSEverywhere.h" | ||
| @interface HTTPSEverywhere_Tests : XCTestCase | ||
| @end | ||
| @implementation HTTPSEverywhere_Tests | ||
| id HEMocked; | ||
| - (void)setUp { | ||
| [super setUp]; | ||
| // Put setup code here. This method is called before the invocation of each test method in the class. | ||
| HEMocked = OCMClassMock([HTTPSEverywhere class]); | ||
| NSFileManager *fm = [NSFileManager defaultManager]; | ||
| NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"mock_rules" ofType:@"plist"]; | ||
| if (![fm fileExistsAtPath:path]) | ||
| abort(); | ||
| OCMStub([HEMocked rules]).andReturn([NSDictionary dictionaryWithContentsOfFile:path]); | ||
| NSString *tpath = [[NSBundle bundleForClass:[self class]] pathForResource:@"mock_targets" ofType:@"plist"]; | ||
| if (![fm fileExistsAtPath:tpath]) | ||
| abort(); | ||
| OCMStub([HEMocked targets]).andReturn([NSDictionary dictionaryWithContentsOfFile:tpath]); | ||
| } | ||
| - (void)tearDown { | ||
| // Put teardown code here. This method is called after the invocation of each test method in the class. | ||
| [super tearDown]; | ||
| } | ||
| - (void)testMock { | ||
| XCTAssertNotNil([[HTTPSEverywhere rules] objectForKey:@"Reddit"]); | ||
| XCTAssertNotNil([[HTTPSEverywhere rules] objectForKey:@"Better Business Bureau (partial)"]); | ||
| // make sure the big list didn't get loaded | ||
| XCTAssertNil([[HTTPSEverywhere rules] objectForKey:@"EFF"]); | ||
| } | ||
| - (void)testApplicableRules { | ||
| NSArray *results = [HTTPSEverywhere potentiallyApplicableRulesFor:@"www.reddit.com"]; | ||
| XCTAssertEqual([results count], 1U); | ||
| XCTAssert([[results objectAtIndex:0] isKindOfClass:[HTTPSEverywhereRule class]]); | ||
| XCTAssert([[(HTTPSEverywhereRule *)[results objectAtIndex:0] name] isEqualToString:@"Reddit"]); | ||
| } | ||
| - (void)testRewrittenURI { | ||
| NSURL *rewritten = [HTTPSEverywhere rewrittenURI:[NSURL URLWithString:@"http://www.reddit.com/test"]]; | ||
| XCTAssert([[rewritten absoluteString] isEqualToString:@"https://www.reddit.com/test"]); | ||
| /* a more complex rewrite */ | ||
| rewritten = [HTTPSEverywhere rewrittenURI:[NSURL URLWithString:@"http://bbbonline.org/cks.asp?id=1234"]]; | ||
| XCTAssert([[rewritten absoluteString] isEqualToString:@"https://www.bbb.org/us/bbb-online-business/?id=1234"]); | ||
| } | ||
| - (void)testRewrittenURIWithExclusion { | ||
| NSString *input = @"http://www.dc.bbb.org/"; | ||
| NSURL *rewritten = [HTTPSEverywhere rewrittenURI:[NSURL URLWithString:input]]; | ||
| XCTAssert([[rewritten absoluteString] isEqualToString:input]); | ||
| } | ||
| @end |
| @@ -0,0 +1,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleDevelopmentRegion</key> | ||
| <string>en</string> | ||
| <key>CFBundleExecutable</key> | ||
| <string>$(EXECUTABLE_NAME)</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>org.jcs.$(PRODUCT_NAME:rfc1034identifier)</string> | ||
| <key>CFBundleInfoDictionaryVersion</key> | ||
| <string>6.0</string> | ||
| <key>CFBundleName</key> | ||
| <string>$(PRODUCT_NAME)</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>BNDL</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>1.0</string> | ||
| <key>CFBundleSignature</key> | ||
| <string>????</string> | ||
| <key>CFBundleVersion</key> | ||
| <string>1</string> | ||
| </dict> | ||
| </plist> |
| @@ -0,0 +1,211 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>Better Business Bureau (partial)</key> | ||
| <dict> | ||
| <key>ruleset</key> | ||
| <dict> | ||
| <key>exclusion</key> | ||
| <array> | ||
| <dict> | ||
| <key>pattern</key> | ||
| <string>^http://(?:www\.)?dc\.</string> | ||
| </dict> | ||
| <dict> | ||
| <key>pattern</key> | ||
| <string>http://(?:www\.)?seflorida\.</string> | ||
| </dict> | ||
| </array> | ||
| <key>name</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>platform</key> | ||
| <string>mixedcontent</string> | ||
| <key>rule</key> | ||
| <array> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^https?://(?:www\.)?la\.?bbb\.org/</string> | ||
| <key>to</key> | ||
| <string>https://www.labbb.org/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://bbb\.org/</string> | ||
| <key>to</key> | ||
| <string>https://www.bbb.org/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://(?:www\.)?([\w\-]+)\.bbb\.org/</string> | ||
| <key>to</key> | ||
| <string>https://$1.bbb.org/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://hurdman\.app\.bbb\.org/</string> | ||
| <key>to</key> | ||
| <string>https://hurdman.app.bbb.org/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^https?://(?:www\.)?bbbonline\.org/cks\.asp\?id=(\d+)</string> | ||
| <key>to</key> | ||
| <string>https://www.bbb.org/us/bbb-online-business/?id=$1</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://(www\.)?bbbsilicon\.org/</string> | ||
| <key>to</key> | ||
| <string>https://$1bbbsilicon.org/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^https?://(?:www\.)?sanjose\.bbb\.org/</string> | ||
| <key>to</key> | ||
| <string>https://bbbsilicon.org/</string> | ||
| </dict> | ||
| </array> | ||
| <key>securecookie</key> | ||
| <array> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>^.*\.bbb\.org$</string> | ||
| <key>name</key> | ||
| <string>.*</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>^(.*\.)?bbbsilicon\.org$</string> | ||
| <key>name</key> | ||
| <string>.*</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>^www\.labbb\.org$</string> | ||
| <key>name</key> | ||
| <string>.*</string> | ||
| </dict> | ||
| </array> | ||
| <key>target</key> | ||
| <array> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>bbb.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>hurdman.app.bbb.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>*.bbb.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>www.*.bbb.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>bbbonline.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>www.bbbonline.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>bbbsilicon.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>www.bbbsilicon.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>labbb.org</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>www.labbb.org</string> | ||
| </dict> | ||
| </array> | ||
| </dict> | ||
| </dict> | ||
| <key>Reddit</key> | ||
| <dict> | ||
| <key>ruleset</key> | ||
| <dict> | ||
| <key>name</key> | ||
| <string>Reddit</string> | ||
| <key>rule</key> | ||
| <array> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://((?:[a-z]{1,2}|[a-z]{2}-[a-z]{2}|blog|pay|redditama|ssl|static|www)\.)?reddit\.com/</string> | ||
| <key>to</key> | ||
| <string>https://$1reddit.com/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://(?:www\.)?np\.reddit\.com/</string> | ||
| <key>to</key> | ||
| <string>https://np.reddit.com/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://thumbs\.reddit\.com/</string> | ||
| <key>to</key> | ||
| <string>https://s3.amazonaws.com/thumbs.reddit.com/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://(\w+\.)?thumbs\.redditmedia\.com/</string> | ||
| <key>to</key> | ||
| <string>https://$1thumbs.redditmedia.com/</string> | ||
| </dict> | ||
| <dict> | ||
| <key>from</key> | ||
| <string>^http://www\.redditstatic\.com/</string> | ||
| <key>to</key> | ||
| <string>https://www.redditstatic.com/</string> | ||
| </dict> | ||
| </array> | ||
| <key>securecookie</key> | ||
| <array> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>.*\.reddit\.com$</string> | ||
| <key>name</key> | ||
| <string>.+</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>^\.redditmedia\.com$</string> | ||
| <key>name</key> | ||
| <string>^__cfduid$</string> | ||
| </dict> | ||
| </array> | ||
| <key>target</key> | ||
| <array> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>reddit.com</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>*.reddit.com</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>*.redditmedia.com</string> | ||
| </dict> | ||
| <dict> | ||
| <key>host</key> | ||
| <string>www.redditstatic.com</string> | ||
| </dict> | ||
| </array> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </plist> |
| @@ -0,0 +1,34 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>*.bbb.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>*.reddit.com</key> | ||
| <string>Reddit</string> | ||
| <key>*.redditmedia.com</key> | ||
| <string>Reddit</string> | ||
| <key>bbb.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>bbbonline.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>bbbsilicon.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>hurdman.app.bbb.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>labbb.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>reddit.com</key> | ||
| <string>Reddit</string> | ||
| <key>www.*.bbb.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>www.bbbonline.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>www.bbbsilicon.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>www.labbb.org</key> | ||
| <string>Better Business Bureau (partial)</string> | ||
| <key>www.redditstatic.com</key> | ||
| <string>Reddit</string> | ||
| </dict> | ||
| </plist> |
Oops, something went wrong.
0 comments on commit
7456109