diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index 884d920cd..0df8ff435 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -184,7 +184,7 @@ - (void)setChatRoom:(LinphoneChatRoom *)room { if (room) { - _vfsEnabled = [[LinphoneManager instance] lpConfigBoolForKey:@"vfs_enabled_preference"] && (linphone_chat_room_get_capabilities(room) & LinphoneChatRoomCapabilitiesEncrypted); + _vfsEnabled = [VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] && (linphone_chat_room_get_capabilities(room) & LinphoneChatRoomCapabilitiesEncrypted); } _chatRoom = room; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 1a9c2e2e8..320ca404f 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -246,14 +246,14 @@ [FIRApp configure]; #endif - - if ([[LinphoneManager instance] lpConfigBoolForKey:@"vfs_enabled_preference"]) { + + if ([VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId]) { if (TARGET_IPHONE_SIMULATOR) { LOGW(@"[VFS] Can not active for simulators."); - [[LinphoneManager instance] lpConfigSetBool:FALSE forKey:@"vfs_enabled_preference"]; + [VFSUtil setVfsEnabbledWithEnabled:false groupName:kLinphoneMsgNotificationAppGroupId]; } else if (!VFSUtil.activateVFS) { [VFSUtil oslogWithLog:@"[VFS] Error unable to activate." level:OS_LOG_TYPE_ERROR]; - [[LinphoneManager instance] lpConfigSetBool:FALSE forKey:@"vfs_enabled_preference"]; + [VFSUtil setVfsEnabbledWithEnabled:false groupName:kLinphoneMsgNotificationAppGroupId]; } } diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index af1b88815..2eb3e266a 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -340,7 +340,7 @@ int maxSize = linphone_core_get_max_size_for_auto_download_incoming_files(LC); [self setObject:maxSize==0 ? @"Always" : (maxSize==-1 ? @"Nerver" : @"Customize") forKey:@"auto_download_mode"]; [self setInteger:maxSize forKey:@"auto_download_incoming_files_max_size"]; - [self setBool:[lm lpConfigBoolForKey:@"vfs_enabled_preference" withDefault:NO] forKey:@"vfs_enabled_mode"]; + [self setBool:[VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] forKey:@"vfs_enabled_mode"]; [self setBool:[lm lpConfigBoolForKey:@"auto_write_to_gallery_preference" withDefault:YES] forKey:@"auto_write_to_gallery_mode"]; } @@ -792,18 +792,18 @@ } linphone_core_set_max_size_for_auto_download_incoming_files(LC, maxSize); [lm lpConfigSetString:[self stringForKey:@"auto_download_mode"] forKey:@"auto_download_mode"]; - BOOL vfsEnabled = [self boolForKey:@"vfs_enabled_mode"] || [lm lpConfigBoolForKey:@"vfs_enabled_preference"]; + BOOL vfsEnabled = [self boolForKey:@"vfs_enabled_mode"] || [VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId]; if (vfsEnabled) { if (TARGET_IPHONE_SIMULATOR) { LOGW(@"[VFS] Can not active for simulators."); - [lm lpConfigSetBool:FALSE forKey:@"vfs_enabled_preference"]; + [VFSUtil setVfsEnabbledWithEnabled:false groupName:kLinphoneMsgNotificationAppGroupId]; [self setBool:FALSE forKey:@"vfs_enabled_mode"]; } else if (!VFSUtil.activateVFS) { [VFSUtil oslogWithLog:@"[VFS] Error unable to activate." level:OS_LOG_TYPE_ERROR]; - [lm lpConfigSetBool:FALSE forKey:@"vfs_enabled_preference"]; + [VFSUtil setVfsEnabbledWithEnabled:false groupName:kLinphoneMsgNotificationAppGroupId]; [self setBool:FALSE forKey:@"vfs_enabled_mode"]; } else { - [lm lpConfigSetBool:TRUE forKey:@"vfs_enabled_preference"]; + [VFSUtil setVfsEnabbledWithEnabled:true groupName:kLinphoneMsgNotificationAppGroupId]; [self setBool:TRUE forKey:@"vfs_enabled_mode"]; } } diff --git a/Classes/VFSUtil.swift b/Classes/VFSUtil.swift index 8389077cb..4e98aa803 100644 --- a/Classes/VFSUtil.swift +++ b/Classes/VFSUtil.swift @@ -27,8 +27,12 @@ import os @objc class VFSUtil: NSObject { - @objc static let keyName = Bundle.main.bundleIdentifier!+".vfskey" - @objc static let prefName = Bundle.main.bundleIdentifier!+".vfspref" + @objc static let keyChainSharingGroup = "org.linphone.phone" // Enable Keychain Sharing capabilities in app and all app extensions that need to activate VFS and set key chain group to be the bundle ID for all and here + @objc static let TEAM_ID = "Z2V957B3D6" // Apple TEAM ID + + @objc static let keyName = "\(keyChainSharingGroup).vfskey" + @objc static let prefName = "\(keyChainSharingGroup).vfspref" + @objc static let accessGroup = "\(TEAM_ID).\(keyChainSharingGroup)" @objc static func generateKey(requiresBiometry: Bool = false) throws { @@ -51,7 +55,8 @@ import os kSecAttrIsPermanent as String : true, kSecAttrApplicationTag as String : tag, kSecAttrAccessControl as String : access - ] + ], + kSecAttrAccessGroup as String : accessGroup ] var error: Unmanaged? @@ -66,7 +71,8 @@ import os kSecClass as String : kSecClassKey, kSecAttrApplicationTag as String : tag, kSecAttrKeyType as String : kSecAttrKeyTypeEC, - kSecReturnRef as String : true + kSecReturnRef as String : true, + kSecAttrAccessGroup as String : accessGroup ] var item: CFTypeRef? @@ -106,11 +112,16 @@ import os @objc static func addSecuredPreference(key:String, value:String) -> Bool { - let delQuery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,kSecAttrAccount as String: key.data(using: .utf8)!] + let delQuery: [String: Any] = [kSecClass as String: kSecClassGenericPassword, + kSecAttrAccount as String: key.data(using: .utf8)!, + kSecAttrAccessGroup as String : accessGroup] SecItemDelete(delQuery as CFDictionary) - let insertQUery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,kSecAttrAccount as String: key.data(using: .utf8)!, kSecValueData as String:value.data(using: .utf8)!] + let insertQUery: [String: Any] = [kSecClass as String: kSecClassGenericPassword, + kSecAttrAccessGroup as String : accessGroup, + kSecAttrAccount as String: key.data(using: .utf8)!, + kSecValueData as String:value.data(using: .utf8)!] let insertStatus = SecItemAdd(insertQUery as CFDictionary, nil) return insertStatus == errSecSuccess @@ -120,7 +131,8 @@ import os let query: [String:Any] = [ kSecClass as String: kSecClassGenericPassword, kSecAttrAccount as String: key.data(using: .utf8)!, - kSecReturnData as String: kCFBooleanTrue + kSecReturnData as String: kCFBooleanTrue, + kSecAttrAccessGroup as String : accessGroup ] var result: AnyObject? @@ -167,6 +179,15 @@ import os } } + @objc static func vfsEnabled(groupName: String) -> Bool { + let defaults = UserDefaults.init(suiteName: groupName) + return defaults?.bool(forKey: "vfs_enabled_preference") == true + } + + @objc static func setVfsEnabbled(enabled: Bool, groupName: String) { + let defaults = UserDefaults.init(suiteName: groupName) + defaults?.setValue(enabled, forKey: "vfs_enabled_preference") + } @objc static func oslog(log:String, level: OSLogType) { if #available(iOS 10.0, *) { diff --git a/linphone.entitlements b/linphone.entitlements index a9bc9d575..9e64877db 100644 --- a/linphone.entitlements +++ b/linphone.entitlements @@ -26,5 +26,9 @@ group.belledonne-communications.linphone.widget group.org.linphone.phone.msgNotification + keychain-access-groups + + $(AppIdentifierPrefix)org.linphone.phone + diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 03cf8b019..71986178a 100644 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -674,6 +674,8 @@ 8CF25D9E1F9F76BD00BEA0C1 /* chat_group_informations@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CF25D9C1F9F76BD00BEA0C1 /* chat_group_informations@2x.png */; }; 93566413F75DA69D2811A716 /* Pods_msgNotificationService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F30EA7BEA39DA427CE0754E /* Pods_msgNotificationService.framework */; }; A634ABAFCB39B6AAE4CA991D /* Pods_linphone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65CEDD144CABFAA70A29AF27 /* Pods_linphone.framework */; }; + C666756F264C925800A0273C /* VFSUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6DA657B261C950C0020CB43 /* VFSUtil.swift */; }; + C6667571264C925B00A0273C /* VFSUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6DA657B261C950C0020CB43 /* VFSUtil.swift */; }; C6DA657C261C950C0020CB43 /* VFSUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6DA657B261C950C0020CB43 /* VFSUtil.swift */; }; C90FAA7915AF54E6002091CB /* HistoryDetailsView.m in Sources */ = {isa = PBXBuildFile; fileRef = C90FAA7715AF54E6002091CB /* HistoryDetailsView.m */; }; CF15F21E20E4F9A3008B1DE6 /* UIImageViewDeletable.m in Sources */ = {isa = PBXBuildFile; fileRef = CF15F21C20E4F9A3008B1DE6 /* UIImageViewDeletable.m */; }; @@ -4322,6 +4324,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C666756F264C925800A0273C /* VFSUtil.swift in Sources */, EA3650DB2330D2E30001148A /* NotificationService.swift in Sources */, EAE6C88423FABF690076A018 /* Utils.swift in Sources */, ); @@ -4331,6 +4334,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C6667571264C925B00A0273C /* VFSUtil.swift in Sources */, EA8CB82C239F96CA00C330CC /* NotificationViewController.swift in Sources */, EAE6C88523FABF690076A018 /* Utils.swift in Sources */, ); diff --git a/msgNotificationContent/NotificationViewController.swift b/msgNotificationContent/NotificationViewController.swift index a923e83c6..5bad22ba4 100644 --- a/msgNotificationContent/NotificationViewController.swift +++ b/msgNotificationContent/NotificationViewController.swift @@ -132,6 +132,9 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi } func startCore() throws { + if (VFSUtil.vfsEnabled(groupName: APP_GROUP_ID) && !VFSUtil.activateVFS()) { + VFSUtil.oslog(log: "[VFS] Error unable to activate.", level: .error) + } config = Config.newForSharedCore(appGroupId: APP_GROUP_ID, configFilename: "linphonerc", factoryConfigFilename: "") log = LoggingService.Instance /*enable liblinphone logs.*/ logDelegate = try! LinphoneLoggingServiceManager(config: config, log: log, domain: "msgNotificationContent") diff --git a/msgNotificationContent/msgNotificationContent.entitlements b/msgNotificationContent/msgNotificationContent.entitlements index f176b9127..b63a67474 100644 --- a/msgNotificationContent/msgNotificationContent.entitlements +++ b/msgNotificationContent/msgNotificationContent.entitlements @@ -6,5 +6,9 @@ group.org.linphone.phone.msgNotification + keychain-access-groups + + $(AppIdentifierPrefix)org.linphone.phone + diff --git a/msgNotificationService/NotificationService.swift b/msgNotificationService/NotificationService.swift index 4959f8506..f1bc77966 100644 --- a/msgNotificationService/NotificationService.swift +++ b/msgNotificationService/NotificationService.swift @@ -182,6 +182,11 @@ class NotificationService: UNNotificationServiceExtension { func createCore() { NSLog("[msgNotificationService] create core") + + if (VFSUtil.vfsEnabled(groupName: APP_GROUP_ID) && !VFSUtil.activateVFS()) { + VFSUtil.oslog(log: "[VFS] Error unable to activate.", level: .error) + } + let config = Config.newForSharedCore(appGroupId: APP_GROUP_ID, configFilename: "linphonerc", factoryConfigFilename: "") if (NotificationService.log == nil) { diff --git a/msgNotificationService/msgNotificationService.entitlements b/msgNotificationService/msgNotificationService.entitlements index f176b9127..b63a67474 100644 --- a/msgNotificationService/msgNotificationService.entitlements +++ b/msgNotificationService/msgNotificationService.entitlements @@ -6,5 +6,9 @@ group.org.linphone.phone.msgNotification + keychain-access-groups + + $(AppIdentifierPrefix)org.linphone.phone +