diff --git a/ooniprobe/Utility/ProxySettings.h b/ooniprobe/Utility/ProxySettings.h index d3bfcd59..5f62d7d5 100644 --- a/ooniprobe/Utility/ProxySettings.h +++ b/ooniprobe/Utility/ProxySettings.h @@ -3,7 +3,9 @@ typedef NS_ENUM(NSInteger, ProxyProtocol) { NONE, PSIPHON, - SOCKS5 + SOCKS5, + HTTP, + HTTPS }; @interface ProxySettings : NSObject diff --git a/ooniprobe/Utility/ProxySettings.m b/ooniprobe/Utility/ProxySettings.m index 876732a8..8df9f732 100644 --- a/ooniprobe/Utility/ProxySettings.m +++ b/ooniprobe/Utility/ProxySettings.m @@ -12,6 +12,10 @@ - (id) init { self.protocol = PSIPHON; } else if ([protocol isEqualToString:[ProxySettings getProtocol:SOCKS5]]) { self.protocol = SOCKS5; + } else if ([protocol isEqualToString:[ProxySettings getProtocol:HTTP]]) { + self.protocol = HTTP; + } else if ([protocol isEqualToString:[ProxySettings getProtocol:HTTPS]]) { + self.protocol = HTTPS; } else { // This is where we will extend the code to add support for // more proxies, e.g., HTTP proxies. @@ -30,7 +34,7 @@ - (void)saveProxy{ } - (BOOL)isCustom{ - if (self.protocol == SOCKS5) + if (self.protocol == SOCKS5 || self.protocol == HTTP || self.protocol == HTTPS) return true; return false; } @@ -49,6 +53,24 @@ - (NSString*)getProxyString{ //URI url = new URI(urlStr); return urlStr; } + if (self.protocol == HTTP) { + // Alright, we now need to construct a new SOCKS5 URL. + NSString *urlStr = [NSString stringWithFormat:@"http://%@:%@/", self.hostname, self.port]; + if ([ProxySettings isIPv6:self.hostname]) { + urlStr = [NSString stringWithFormat:@"http://[%@]:%@/", self.hostname, self.port]; // IPv6 must be quoted in URLs + } + //URI url = new URI(urlStr); + return urlStr; + } + if (self.protocol == HTTPS) { + // Alright, we now need to construct a new SOCKS5 URL. + NSString *urlStr = [NSString stringWithFormat:@"https://%@:%@/", self.hostname, self.port]; + if ([ProxySettings isIPv6:self.hostname]) { + urlStr = [NSString stringWithFormat:@"https://[%@]:%@/", self.hostname, self.port]; // IPv6 must be quoted in URLs + } + //URI url = new URI(urlStr); + return urlStr; + } return @""; } @@ -69,7 +91,13 @@ + (NSString*)getProtocol:(ProxyProtocol) protocol { result = @"proxy_psiphon"; break; case SOCKS5: - result = @"SOCKS5"; + result = @"socks5"; + break; + case HTTP: + result = @"http"; + break; + case HTTPS: + result = @"https"; break; default: result = @"unknown"; diff --git a/ooniprobe/View/Settings/ProxyViewController.m b/ooniprobe/View/Settings/ProxyViewController.m index 4544ea5f..0e6d7443 100644 --- a/ooniprobe/View/Settings/ProxyViewController.m +++ b/ooniprobe/View/Settings/ProxyViewController.m @@ -33,7 +33,11 @@ - (void)reloadRows{ @[[ProxySettings getProtocol:NONE], [ProxySettings getProtocol:PSIPHON], @"proxy_custom"], - @[[ProxySettings getProtocol:SOCKS5]], + @[ + [ProxySettings getProtocol:SOCKS5], + [ProxySettings getProtocol:HTTP], + [ProxySettings getProtocol:HTTPS] + ], @[@"proxy_hostname", @"proxy_port"]]; else items = @[@[[ProxySettings getProtocol:NONE], @@ -124,15 +128,23 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath else if (indexPath.row == 1) currentProxy.protocol = PSIPHON; if (indexPath.row == 2) - [self setCustom]; + [self setCustom:SOCKS5]; + [self reloadRows]; + } else if (indexPath.section == 1){ + if (indexPath.row == 0) + [self setCustom:SOCKS5]; + else if (indexPath.row == 1) + [self setCustom:HTTP]; + else if (indexPath.row == 2) + [self setCustom:HTTPS]; [self reloadRows]; } //[self.view endEditing:YES]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; } --(void)setCustom { - currentProxy.protocol = SOCKS5; +- (void)setCustom:(enum ProxyProtocol)protocol { + currentProxy.protocol = protocol; } -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string