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

Feat: Add support for http and https proxies #535

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ooniprobe/Utility/ProxySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
typedef NS_ENUM(NSInteger, ProxyProtocol) {
NONE,
PSIPHON,
SOCKS5
SOCKS5,
HTTP,
HTTPS
};

@interface ProxySettings : NSObject
Expand Down
32 changes: 30 additions & 2 deletions ooniprobe/Utility/ProxySettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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 @"";

}
Expand All @@ -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";
Expand Down
20 changes: 16 additions & 4 deletions ooniprobe/View/Settings/ProxyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand Down