Commit 9c27bcc0 authored by Christophe Deschamps's avatar Christophe Deschamps Committed by DanmeiChen
Browse files

Enable VFS in app extensions via Keychain sharing

parent f47eb4f2
......@@ -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;
......
......@@ -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];
}
}
......
......@@ -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"];
}
}
......
......@@ -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<CFError>?
......@@ -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, *) {
......
......@@ -26,5 +26,9 @@
<string>group.belledonne-communications.linphone.widget</string>
<string>group.org.linphone.phone.msgNotification</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)org.linphone.phone</string>
</array>
</dict>
</plist>
......@@ -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 */,
);
......
......@@ -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")
......
......@@ -6,5 +6,9 @@
<array>
<string>group.org.linphone.phone.msgNotification</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)org.linphone.phone</string>
</array>
</dict>
</plist>
......@@ -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) {
......
......@@ -6,5 +6,9 @@
<array>
<string>group.org.linphone.phone.msgNotification</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)org.linphone.phone</string>
</array>
</dict>
</plist>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment