From fdd55a79c04ac79930029732eccfe1b024c38e34 Mon Sep 17 00:00:00 2001 From: Keeyou Date: Tue, 7 May 2024 14:06:29 +0800 Subject: [PATCH] ios: add add post quantum kyber in settings --- CMakeLists.txt | 4 ++++ src/ios/Settings.bundle/Root.plist | 21 ++++++++++++++++++ src/ios/Settings.bundle/en.lproj/Root.strings | Bin 0 -> 724 bytes .../zh-Hans.lproj/Root.strings | Bin 0 -> 676 bytes src/ios/YassAppDelegate.mm | 15 +++++++++++++ .../extensions/YassPacketTunnelProvider.mm | 3 +++ src/ios/utils.h | 2 ++ 7 files changed, 45 insertions(+) create mode 100644 src/ios/Settings.bundle/Root.plist create mode 100644 src/ios/Settings.bundle/en.lproj/Root.strings create mode 100644 src/ios/Settings.bundle/zh-Hans.lproj/Root.strings diff --git a/CMakeLists.txt b/CMakeLists.txt index 83797552c..9055dda2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 diff --git a/src/ios/Settings.bundle/Root.plist b/src/ios/Settings.bundle/Root.plist new file mode 100644 index 000000000..aa1a1d436 --- /dev/null +++ b/src/ios/Settings.bundle/Root.plist @@ -0,0 +1,21 @@ + + + + + StringsTable + Root + PreferenceSpecifiers + + + Type + PSToggleSwitchSpecifier + Title + Kyber post-quantum key agreement for TLS + Key + ENABLE_POST_QUANTUM_KYBER + DefaultValue + + + + + diff --git a/src/ios/Settings.bundle/en.lproj/Root.strings b/src/ios/Settings.bundle/en.lproj/Root.strings new file mode 100644 index 0000000000000000000000000000000000000000..e611b0b436f6ecab4b57895b9315384fda0dfda1 GIT binary patch literal 724 zcmb`Ey-veG5QL}ZDNZRPAP;~jC=dmRhP;5|pJ0*LA+dwP!vo)(Z5&V}8f2aCZgzHd zcJK3Jrm2E%SUZ)fwA4y@yfxbP$c}r#*^zV3Z+cb@-@FFA>2pdj>uiXm;LgdFfmu1| zKvs)tfUzY~u)J5W^FB94JJ(u?F5%7N&6=m(xSq9Y?WvKGX-8HFc&gD&*h{^G*hdOh z!Entca%=t>47*;zK76BtPD{)_J%c*#IXwFe+zbAH_2o{cn(2&hqPys~rQQVmn)MUA zimXR!tf@P4Mx^dq%G*2#yq|Qh0>1G|@Uo4`z%0)K zPXul;iDEFz>}gF@MOF{S5>LvpJBOXLu@Siw%@yhhUf?Xtxm%6Zvs{I0YQ#jEBFo^R zsUUC2o#`3GbVOh|469i>Zoxl>VX9}a*Bi9UQ{gk6HiN?52|Uy3VW<56>&rSBXsA6t zUl&eqMLi$fUHi?=HL#T)h| z{Y}~lEU0O_IMgGX4BZqfbb5M#VY3TSV>`7Sc2n-=7U)W&t$L09Quh`1gU{F7@yGc6 M?Phd-=gSoQ0P|{hU;qFB literal 0 HcmV?d00001 diff --git a/src/ios/YassAppDelegate.mm b/src/ios/YassAppDelegate.mm index 76539e918..6bae7ca19 100644 --- a/src/ios/YassAppDelegate.mm +++ b/src/ios/YassAppDelegate.mm @@ -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*)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 @@ -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 = @""; @@ -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"); diff --git a/src/ios/extensions/YassPacketTunnelProvider.mm b/src/ios/extensions/YassPacketTunnelProvider.mm index 7aab90582..4d529bb5f 100644 --- a/src/ios/extensions/YassPacketTunnelProvider.mm +++ b/src/ios/extensions/YassPacketTunnelProvider.mm @@ -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, @@ -59,6 +60,8 @@ - (void)startTunnelWithOptions:(NSDictionary*)options completionHandler:(void (^ return; } + absl::SetFlag(&FLAGS_enable_post_quantum_kyber, enable_post_quantum_kyber); + absl::AnyInvocable callback = [self, completionHandler](asio::error_code ec) { bool successed = false; std::string err_msg; diff --git a/src/ios/utils.h b/src/ios/utils.h index 74ef1320e..1e1675fe7 100644 --- a/src/ios/utils.h +++ b/src/ios/utils.h @@ -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