Update fronting to use country-specific Google domains.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 566c6e15d1
commit cc78978be5

@ -7,7 +7,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSCensorshipConfiguration : NSObject @interface OWSCensorshipConfiguration : NSObject
- (NSString *)frontingHost; - (NSString *)frontingHost:(NSString *)e164PhonNumber;
- (NSString *)reflectorHost; - (NSString *)reflectorHost;
- (BOOL)isCensoredPhoneNumber:(NSString *)e164PhonNumber; - (BOOL)isCensoredPhoneNumber:(NSString *)e164PhonNumber;

@ -6,14 +6,29 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
NSString *const OWSCensorshipConfigurationFrontingHost = @"https://google.com";
NSString *const OWSCensorshipConfigurationReflectorHost = @"signal-reflector-meek.appspot.com"; NSString *const OWSCensorshipConfigurationReflectorHost = @"signal-reflector-meek.appspot.com";
@implementation OWSCensorshipConfiguration @implementation OWSCensorshipConfiguration
- (NSString *)frontingHost - (NSString *)frontingHost:(NSString *)e164PhonNumber
{ {
return OWSCensorshipConfigurationFrontingHost; OWSAssert(e164PhonNumber.length > 0);
NSString *domain = nil;
for (NSString *countryCode in self.censoredCountryCodes.allKeys) {
if ([e164PhonNumber hasPrefix:countryCode]) {
domain = self.censoredCountryCodes[countryCode];
}
}
// Fronting should only be used for countries specified in censoredCountryCodes,
// all of which have a domain specified.
OWSAssert(domain);
if (!domain) {
domain = @"google.com";
}
return [@"https://" stringByAppendingString:domain];
} }
- (NSString *)reflectorHost - (NSString *)reflectorHost
@ -21,26 +36,31 @@ NSString *const OWSCensorshipConfigurationReflectorHost = @"signal-reflector-mee
return OWSCensorshipConfigurationReflectorHost; return OWSCensorshipConfigurationReflectorHost;
} }
- (NSArray<NSString *> *)censoredCountryCodes - (NSDictionary<NSString *, NSString *> *)censoredCountryCodes
{ {
// Reports of censorship in: // Domain fronting should be used for the following countries.
return @[ //
// For each country, we should the appropriate google domain,
// per: https://en.wikipedia.org/wiki/List_of_Google_domains
return @{
// Egypt // Egypt
@"+20", @"+20": @"google.com.eg",
// Cuba // Cuba
@"+53", @"+53": @"google.com.cu",
// Oman // Oman
@"+968", @"+968": @"google.com.om",
// UAE // UAE
@"+971", @"+971": @"google.com.ae",
// Iran // Iran
@"+98", //
]; // There does not appear to be a specific Google domain for Iran.
@"+98": @"google.com",
};
} }
- (BOOL)isCensoredPhoneNumber:(NSString *)e164PhonNumber - (BOOL)isCensoredPhoneNumber:(NSString *)e164PhonNumber
{ {
for (NSString *countryCode in self.censoredCountryCodes) { for (NSString *countryCode in self.censoredCountryCodes.allKeys) {
if ([e164PhonNumber hasPrefix:countryCode]) { if ([e164PhonNumber hasPrefix:countryCode]) {
return YES; return YES;
} }

@ -69,8 +69,11 @@ NS_ASSUME_NONNULL_BEGIN
- (AFHTTPSessionManager *)reflectorHTTPSessionManager - (AFHTTPSessionManager *)reflectorHTTPSessionManager
{ {
NSString *localNumber = [TSAccountManager localNumber];
OWSAssert(localNumber.length > 0);
// Target fronting domain // Target fronting domain
NSURL *baseURL = [[NSURL alloc] initWithString:self.censorshipConfiguration.frontingHost]; NSURL *baseURL = [[NSURL alloc] initWithString:[self.censorshipConfiguration frontingHost:localNumber]];
NSURLSessionConfiguration *sessionConf = NSURLSessionConfiguration.ephemeralSessionConfiguration; NSURLSessionConfiguration *sessionConf = NSURLSessionConfiguration.ephemeralSessionConfiguration;
AFHTTPSessionManager *sessionManager = AFHTTPSessionManager *sessionManager =
[[AFHTTPSessionManager alloc] initWithBaseURL:baseURL sessionConfiguration:sessionConf]; [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL sessionConfiguration:sessionConf];

@ -10,7 +10,6 @@
#import <CommonCrypto/CommonHMAC.h> #import <CommonCrypto/CommonHMAC.h>
#import "Cryptography.h" #import "Cryptography.h"
#import "NSData+Base64.h" #import "NSData+Base64.h"
#define HMAC256_KEY_LENGTH 32 #define HMAC256_KEY_LENGTH 32

Loading…
Cancel
Save