Skip to content

Commit

Permalink
ios: add add post quantum kyber in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed May 7, 2024
1 parent e4efcd1 commit fdd55a7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4018,12 +4018,14 @@ if (GUI)
elseif (GUI_FLAVOUR STREQUAL "ios")
set(MAIN_STORYBOARD ${CMAKE_CURRENT_SOURCE_DIR}/src/ios/Base.lproj/Main.storyboard)
set(LAUNCH_STORYBOARD ${CMAKE_CURRENT_SOURCE_DIR}/src/ios/Base.lproj/LaunchScreen.storyboard)
file(GLOB SETTINGS_BUNDLE ${CMAKE_CURRENT_SOURCE_DIR}/src/ios/Settings.bundle)
set(ALLRESOURCES)
if (${CMAKE_GENERATOR} MATCHES "^Xcode.*")
set(ALLRESOURCES
${ALLRESOURCES}
${MAIN_STORYBOARD}
${LAUNCH_STORYBOARD}
${SETTINGS_BUNDLE}
src/ios/PrivacyInfo.xcprivacy
src/ios/en.lproj/Localizable.strings
src/ios/en.lproj/Main.strings
Expand Down Expand Up @@ -4377,6 +4379,8 @@ if (GUI)
MACOSX_PACKAGE_LOCATION "Resources/Base.lproj")
set_source_files_properties("${LAUNCH_STORYBOARD}" PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources/Base.lproj")
set_source_files_properties(${SETTINGS_BUNDLE} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
set_source_files_properties("src/ios/en.lproj/Localizable.strings" PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
set_source_files_properties("src/ios/en.lproj/Main.strings" PROPERTIES
Expand Down
21 changes: 21 additions & 0 deletions src/ios/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Kyber post-quantum key agreement for TLS</string>
<key>Key</key>
<string>ENABLE_POST_QUANTUM_KYBER</string>
<key>DefaultValue</key>
<false/>
</dict>
</array>
</dict>
</plist>
Binary file added src/ios/Settings.bundle/en.lproj/Root.strings
Binary file not shown.
Binary file added src/ios/Settings.bundle/zh-Hans.lproj/Root.strings
Binary file not shown.
15 changes: 15 additions & 0 deletions src/ios/YassAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ @implementation YassAppDelegate {
NSString* doh_url_;
NSString* dot_host_;
NSString* connect_timeout_;
BOOL enable_post_quantum_kyber_;
}

- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id>*)launchOptions {
state_ = STOPPED;
[self didDefaultsChanged:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didDefaultsChanged:)
name:NSUserDefaultsDidChangeNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didChangeVpnStatus:)
name:NEVPNStatusDidChangeNotification
Expand Down Expand Up @@ -256,6 +263,7 @@ - (void)OnStartSaveAndLoadInstance:(NETunnelProviderManager*)vpn_manager {
@(kDoHURLFieldName) : doh_url_,
@(kDoTHostFieldName) : dot_host_,
@(kConnectTimeoutFieldName) : connect_timeout_,
@(kEnablePostQuantumKyberKey) : @(enable_post_quantum_kyber_),
};
tunnelProtocol.username = @"";
tunnelProtocol.identityDataPassword = @"";
Expand Down Expand Up @@ -287,6 +295,13 @@ - (void)OnStartSaveAndLoadInstance:(NETunnelProviderManager*)vpn_manager {

#pragma mark - Notification

- (void)didDefaultsChanged:(NSNotification*)notification {
// Use standard one for data that is only for Host App.
// Use suiteName for data that you want to share between Extension and Host App.
enable_post_quantum_kyber_ = [[NSUserDefaults standardUserDefaults] boolForKey:@(kEnablePostQuantumKyberKey)];
absl::SetFlag(&FLAGS_enable_post_quantum_kyber, enable_post_quantum_kyber_);
}

- (void)didChangeVpnStatus:(NSNotification*)notification {
if (!vpn_manager_) {
status_ = NSLocalizedString(@"DISCONNECTED", @"Disconnected");
Expand Down
3 changes: 3 additions & 0 deletions src/ios/extensions/YassPacketTunnelProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ - (void)startTunnelWithOptions:(NSDictionary*)options completionHandler:(void (^
auto doh_url = SysNSStringToUTF8(dict[@(kDoHURLFieldName)]);
auto dot_host = SysNSStringToUTF8(dict[@(kDoTHostFieldName)]);
auto connect_timeout = SysNSStringToUTF8(dict[@(kConnectTimeoutFieldName)]);
auto enable_post_quantum_kyber = [dict[@(kEnablePostQuantumKyberKey)] boolValue];

auto err_msg =
config::ReadConfigFromArgument(server_host, "" /*server_sni*/, server_port, username, password, method_string,
Expand All @@ -59,6 +60,8 @@ - (void)startTunnelWithOptions:(NSDictionary*)options completionHandler:(void (^
return;
}

absl::SetFlag(&FLAGS_enable_post_quantum_kyber, enable_post_quantum_kyber);

absl::AnyInvocable<void(asio::error_code)> callback = [self, completionHandler](asio::error_code ec) {
bool successed = false;
std::string err_msg;
Expand Down
2 changes: 2 additions & 0 deletions src/ios/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ constexpr const char kDoHURLFieldName[] = "doh_url";
constexpr const char kDoTHostFieldName[] = "dot_host";
constexpr const char kConnectTimeoutFieldName[] = "connect_timeout";

constexpr const char kEnablePostQuantumKyberKey[] = "ENABLE_POST_QUANTUM_KYBER";

#endif // YASS_IOS_UTILS

0 comments on commit fdd55a7

Please sign in to comment.