Skip to content

Commit

Permalink
ios: add server sni ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Oct 23, 2024
1 parent 66b2c14 commit f96a67a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 15 deletions.
39 changes: 28 additions & 11 deletions src/ios/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<rect key="frame" x="20" y="48" width="374" height="870"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="EMh-aI-fmy">
<rect key="frame" x="0.0" y="0.0" width="374" height="657"/>
<rect key="frame" x="0.0" y="0.0" width="374" height="703"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="Ju1-Bx-M7I">
<rect key="frame" x="0.0" y="0.0" width="374" height="34"/>
Expand All @@ -39,8 +39,24 @@
</textField>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="0KF-ya-nWX">
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="9a8-LA-xiz">
<rect key="frame" x="0.0" y="46" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Server SNI" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cQD-Db-bXg">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="a7A-sz-LMO">
<rect key="frame" x="187" y="0.0" width="187" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="next" textContentType="url"/>
</textField>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="0KF-ya-nWX">
<rect key="frame" x="0.0" y="92" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="748" text="Server Port" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h37-oZ-p8D">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
Expand All @@ -56,7 +72,7 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="tJU-ei-ozQ">
<rect key="frame" x="0.0" y="92" width="374" height="34"/>
<rect key="frame" x="0.0" y="138" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Username" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dFn-KS-gx8">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
Expand All @@ -72,7 +88,7 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="eiU-kQ-upq">
<rect key="frame" x="0.0" y="138" width="374" height="34"/>
<rect key="frame" x="0.0" y="184" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Password" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bEh-We-3bh">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
Expand All @@ -88,7 +104,7 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="O8H-4C-Ga2">
<rect key="frame" x="0.0" y="184" width="374" height="216"/>
<rect key="frame" x="0.0" y="230" width="374" height="216"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cipher/Method" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ENX-yq-A0k">
<rect key="frame" x="0.0" y="0.0" width="93.5" height="216"/>
Expand All @@ -105,7 +121,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="PPI-hg-IXg">
<rect key="frame" x="0.0" y="412" width="374" height="34"/>
<rect key="frame" x="0.0" y="458" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DNS over HTTPS URL" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Nki-Be-f2P">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
Expand All @@ -121,7 +137,7 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="Wly-Qj-2G3">
<rect key="frame" x="0.0" y="458" width="374" height="34"/>
<rect key="frame" x="0.0" y="504" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DNS over TLS Host" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bm9-gV-Cny">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
Expand All @@ -137,7 +153,7 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="Vcf-QO-65S">
<rect key="frame" x="0.0" y="504" width="374" height="34"/>
<rect key="frame" x="0.0" y="550" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Limit Rate" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tx-Ul-6iU">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
Expand All @@ -153,7 +169,7 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="j59-Ui-faY">
<rect key="frame" x="0.0" y="550" width="374" height="34"/>
<rect key="frame" x="0.0" y="596" width="374" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Timeout" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3S5-0B-efx">
<rect key="frame" x="0.0" y="0.0" width="187" height="34"/>
Expand All @@ -169,13 +185,13 @@
</subviews>
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="READY" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wp5-6B-wJp">
<rect key="frame" x="0.0" y="596" width="374" height="14.5"/>
<rect key="frame" x="0.0" y="642" width="374" height="14.5"/>
<fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="paQ-LB-b98">
<rect key="frame" x="0.0" y="622.5" width="374" height="34.5"/>
<rect key="frame" x="0.0" y="668.5" width="374" height="34.5"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mgH-S8-WUJ">
<rect key="frame" x="0.0" y="0.0" width="187" height="34.5"/>
Expand Down Expand Up @@ -228,6 +244,7 @@
<outlet property="password" destination="pfU-fE-5kl" id="x6M-3I-sMa"/>
<outlet property="serverHost" destination="GsR-Z4-fTf" id="mJM-Ny-yXp"/>
<outlet property="serverPort" destination="1hy-kK-Mai" id="oWU-M2-gfa"/>
<outlet property="serverSNI" destination="a7A-sz-LMO" id="J6d-6E-bPG"/>
<outlet property="startButton" destination="mgH-S8-WUJ" id="6ZK-ME-DZA"/>
<outlet property="status" destination="wp5-6B-wJp" id="VHC-T0-P7X"/>
<outlet property="stopButton" destination="MGs-Nl-c5G" id="S0E-AH-zch"/>
Expand Down
6 changes: 5 additions & 1 deletion src/ios/YassAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ @implementation YassAppDelegate {
NSTimer* refresh_timer_;

NSString* server_host_;
NSString* server_sni_;
NSString* server_port_;
NSString* username_;
NSString* password_;
Expand Down Expand Up @@ -258,6 +259,7 @@ - (void)OnStartSaveAndLoadInstance:(NETunnelProviderManager*)vpn_manager {

tunnelProtocol.providerConfiguration = @{
@(kServerHostFieldName) : server_host_,
@(kServerSNIFieldName) : server_sni_,
@(kServerPortFieldName) : server_port_,
@(kUsernameFieldName) : username_,
@(kPasswordFieldName) : password_,
Expand Down Expand Up @@ -415,6 +417,7 @@ - (void)OnStopped {
- (std::string)SaveConfig {
YassViewController* viewController = [self getRootViewController];
server_host_ = viewController.serverHost.text;
server_sni_ = viewController.serverSNI.text;
server_port_ = viewController.serverPort.text;
username_ = viewController.username.text;
password_ = viewController.password.text;
Expand All @@ -425,6 +428,7 @@ - (void)OnStopped {
connect_timeout_ = viewController.timeout.text;

auto server_host = SysNSStringToUTF8(server_host_);
auto server_sni = SysNSStringToUTF8(server_sni_);
auto server_port = SysNSStringToUTF8(server_port_);
auto username = SysNSStringToUTF8(username_);
auto password = SysNSStringToUTF8(password_);
Expand All @@ -434,7 +438,7 @@ - (void)OnStopped {
auto limit_rate = SysNSStringToUTF8(limit_rate_);
auto connect_timeout = SysNSStringToUTF8(connect_timeout_);

return config::ReadConfigFromArgument(server_host, "" /*server_sni*/, server_port, username, password, method_string,
return config::ReadConfigFromArgument(server_host, server_sni, server_port, username, password, method_string,
"127.0.0.1", "0", doh_url, dot_host, limit_rate, connect_timeout);
}

Expand Down
1 change: 1 addition & 0 deletions src/ios/YassViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@property(weak, nonatomic) IBOutlet UIButton* startButton;
@property(weak, nonatomic) IBOutlet UIButton* stopButton;
@property(weak, nonatomic) IBOutlet UITextField* serverHost;
@property(weak, nonatomic) IBOutlet UITextField* serverSNI;
@property(weak, nonatomic) IBOutlet UITextField* serverPort;
@property(weak, nonatomic) IBOutlet UITextField* username;
@property(weak, nonatomic) IBOutlet UITextField* password;
Expand Down
15 changes: 15 additions & 0 deletions src/ios/YassViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ - (void)viewDidLoad {
[self.cipherMethod setDataSource:self];
[self.cipherMethod reloadAllComponents];
[self.serverHost setDelegate:self];
[self.serverSNI setDelegate:self];
[self.serverPort setDelegate:self];
[self.username setDelegate:self];
[self.password setDelegate:self];
Expand Down Expand Up @@ -99,6 +100,9 @@ - (void)viewWillAppear:(BOOL)animated {

- (BOOL)textFieldShouldReturn:(UITextField*)textField {
if (textField == self.serverHost) {
[textField resignFirstResponder];
[self.serverSNI becomeFirstResponder];
} else if (textField == self.serverSNI) {
[textField resignFirstResponder];
[self.serverPort becomeFirstResponder];
} else if (textField == self.serverPort) {
Expand Down Expand Up @@ -133,6 +137,11 @@ - (BOOL)textFieldShouldEndEditing:(UITextField*)textField {
return NO;
}
}
if (textField == self.serverSNI) {
if (textField.text.length > TLSEXT_MAXLEN_host_name) {
return NO;
}
}
if (textField == self.serverPort) {
int port;
return StringToInt(SysNSStringToUTF8(textField.text), &port) && port > 0 && port <= UINT16_MAX ? YES : NO;
Expand Down Expand Up @@ -198,6 +207,7 @@ - (void)OnStop {
- (void)Starting {
[self UpdateStatusBar];
[self.serverHost setUserInteractionEnabled:FALSE];
[self.serverSNI setUserInteractionEnabled:FALSE];
[self.serverPort setUserInteractionEnabled:FALSE];
[self.username setUserInteractionEnabled:FALSE];
[self.password setUserInteractionEnabled:FALSE];
Expand All @@ -213,6 +223,7 @@ - (void)Starting {
- (void)Started {
[self UpdateStatusBar];
[self.serverHost setUserInteractionEnabled:FALSE];
[self.serverSNI setUserInteractionEnabled:FALSE];
[self.serverPort setUserInteractionEnabled:FALSE];
[self.username setUserInteractionEnabled:FALSE];
[self.password setUserInteractionEnabled:FALSE];
Expand All @@ -228,6 +239,7 @@ - (void)Started {
- (void)StartFailed {
[self UpdateStatusBar];
[self.serverHost setUserInteractionEnabled:TRUE];
[self.serverSNI setUserInteractionEnabled:TRUE];
[self.serverPort setUserInteractionEnabled:TRUE];
[self.username setUserInteractionEnabled:TRUE];
[self.password setUserInteractionEnabled:TRUE];
Expand All @@ -243,6 +255,7 @@ - (void)StartFailed {
- (void)Stopping {
[self UpdateStatusBar];
[self.serverHost setUserInteractionEnabled:FALSE];
[self.serverSNI setUserInteractionEnabled:FALSE];
[self.serverPort setUserInteractionEnabled:FALSE];
[self.username setUserInteractionEnabled:FALSE];
[self.password setUserInteractionEnabled:FALSE];
Expand All @@ -258,6 +271,7 @@ - (void)Stopping {
- (void)Stopped {
[self UpdateStatusBar];
[self.serverHost setUserInteractionEnabled:TRUE];
[self.serverSNI setUserInteractionEnabled:TRUE];
[self.serverPort setUserInteractionEnabled:TRUE];
[self.username setUserInteractionEnabled:TRUE];
[self.password setUserInteractionEnabled:TRUE];
Expand Down Expand Up @@ -308,6 +322,7 @@ - (void)UpdateStatusBar {

- (void)LoadChanges {
self.serverHost.text = SysUTF8ToNSString(absl::GetFlag(FLAGS_server_host));
self.serverSNI.text = SysUTF8ToNSString(absl::GetFlag(FLAGS_server_sni));
self.serverPort.text = SysUTF8ToNSString(std::to_string(absl::GetFlag(FLAGS_server_port)));
self.username.text = SysUTF8ToNSString(absl::GetFlag(FLAGS_username));
self.password.text = SysUTF8ToNSString(absl::GetFlag(FLAGS_password));
Expand Down
Loading

0 comments on commit f96a67a

Please sign in to comment.