This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
23 changed files
with
484,533 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "https-everywhere"] | ||
path = https-everywhere | ||
url = https://github.com/EFForg/https-everywhere |
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,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 |
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,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> |
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,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> |
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,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.