Marino Faggiana 1 year ago
parent
commit
2ecf8928ec

+ 2 - 2
File Provider Extension/FileProviderData.swift

@@ -93,7 +93,7 @@ class fileProviderData: NSObject {
 
 
             NCManageDatabase.shared.setCapabilities(account: account)
             NCManageDatabase.shared.setCapabilities(account: account)
 
 
-            NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
+            NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
             NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate
             NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate
 
 
             return tableAccount.init(value: activeAccount)
             return tableAccount.init(value: activeAccount)
@@ -117,7 +117,7 @@ class fileProviderData: NSObject {
 
 
                 NCManageDatabase.shared.setCapabilities(account: account)
                 NCManageDatabase.shared.setCapabilities(account: account)
 
 
-                NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
+                NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
                 NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate
                 NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate
 
 
                 return tableAccount.init(value: activeAccount)
                 return tableAccount.init(value: activeAccount)

+ 1 - 1
Share/NCShareExtension+NCDelegate.swift

@@ -88,7 +88,7 @@ extension NCShareExtension: NCEmptyDataSetDelegate, NCAccountRequestDelegate {
             account: activeAccount.account,
             account: activeAccount.account,
             user: activeAccount.user,
             user: activeAccount.user,
             userId: activeAccount.userId,
             userId: activeAccount.userId,
-            password: CCUtility.getPassword(activeAccount.account),
+            password: NCKeychain().getPassword(account: activeAccount.account),
             urlBase: activeAccount.urlBase,
             urlBase: activeAccount.urlBase,
             userAgent: userAgent,
             userAgent: userAgent,
             nextcloudVersion: 0,
             nextcloudVersion: 0,

+ 1 - 1
Widget/Dashboard/DashboardData.swift

@@ -130,7 +130,7 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis
     }
     }
 
 
     // NETWORKING
     // NETWORKING
-    let password = CCUtility.getPassword(account.account)!
+    let password = NCKeychain().getPassword(account: account.account)
     NextcloudKit.shared.setup(
     NextcloudKit.shared.setup(
         account: account.account,
         account: account.account,
         user: account.user,
         user: account.user,

+ 1 - 1
Widget/Files/FilesData.swift

@@ -124,7 +124,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
     }
     }
 
 
     // NETWORKING
     // NETWORKING
-    let password = CCUtility.getPassword(account.account)!
+    let password = NCKeychain().getPassword(account: account.account)
     NextcloudKit.shared.setup(
     NextcloudKit.shared.setup(
         account: account.account,
         account: account.account,
         user: account.user,
         user: account.user,

+ 1 - 1
Widget/Lockscreen/LockscreenData.swift

@@ -63,7 +63,7 @@ func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, fami
     }
     }
 
 
     // NETWORKING
     // NETWORKING
-    let password = CCUtility.getPassword(account.account)!
+    let password = NCKeychain().getPassword(account: account.account)
     NextcloudKit.shared.setup(
     NextcloudKit.shared.setup(
         account: account.account,
         account: account.account,
         user: account.user,
         user: account.user,

+ 4 - 4
iOSClient/AppDelegate.swift

@@ -117,7 +117,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
 
         if let account = NCManageDatabase.shared.getActiveAccount() {
         if let account = NCManageDatabase.shared.getActiveAccount() {
             NextcloudKit.shared.nkCommonInstance.writeLog("Account active \(account.account)")
             NextcloudKit.shared.nkCommonInstance.writeLog("Account active \(account.account)")
-            if CCUtility.getPassword(account.account).isEmpty {
+            if NCKeychain().getPassword(account: account.account).isEmpty {
                 NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] PASSWORD NOT FOUND for \(account.account)")
                 NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] PASSWORD NOT FOUND for \(account.account)")
             }
             }
         }
         }
@@ -128,7 +128,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             urlBase = activeAccount.urlBase
             urlBase = activeAccount.urlBase
             user = activeAccount.user
             user = activeAccount.user
             userId = activeAccount.userId
             userId = activeAccount.userId
-            password = CCUtility.getPassword(account)
+            password = NCKeychain().getPassword(account: account)
 
 
             NextcloudKit.shared.setup(account: account, user: user, userId: userId, password: password, urlBase: urlBase)
             NextcloudKit.shared.setup(account: account, user: user, userId: userId, password: password, urlBase: urlBase)
             NCManageDatabase.shared.setCapabilities(account: account)
             NCManageDatabase.shared.setCapabilities(account: account)
@@ -530,7 +530,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     }
     }
 
 
     @objc private func checkErrorNetworking() {
     @objc private func checkErrorNetworking() {
-        guard !account.isEmpty, CCUtility.getPassword(account)!.isEmpty else { return }
+        guard !account.isEmpty, NCKeychain().getPassword(account: account).isEmpty else { return }
         openLogin(viewController: window?.rootViewController, selector: NCGlobal.shared.introLogin, openLoginWeb: true)
         openLogin(viewController: window?.rootViewController, selector: NCGlobal.shared.introLogin, openLoginWeb: true)
     }
     }
 
 
@@ -584,7 +584,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         self.urlBase = tableAccount.urlBase
         self.urlBase = tableAccount.urlBase
         self.user = tableAccount.user
         self.user = tableAccount.user
         self.userId = tableAccount.userId
         self.userId = tableAccount.userId
-        self.password = CCUtility.getPassword(tableAccount.account)
+        self.password = NCKeychain().getPassword(account: tableAccount.account)
 
 
         NextcloudKit.shared.setup(account: account, user: user, userId: userId, password: password, urlBase: urlBase)
         NextcloudKit.shared.setup(account: account, user: user, userId: userId, password: password, urlBase: urlBase)
         NCManageDatabase.shared.setCapabilities(account: account)
         NCManageDatabase.shared.setCapabilities(account: account)

+ 2 - 2
iOSClient/Login/NCLoginWeb.swift

@@ -129,7 +129,7 @@ class NCLoginWeb: UIViewController {
         // TITLE
         // TITLE
         if let host = URL(string: urlBase)?.host {
         if let host = URL(string: urlBase)?.host {
             titleView = host
             titleView = host
-            if let account = NCManageDatabase.shared.getActiveAccount(), CCUtility.getPassword(account.account).isEmpty {
+            if let account = NCManageDatabase.shared.getActiveAccount(), NCKeychain().getPassword(account: account.account).isEmpty {
                 titleView = NSLocalizedString("_user_", comment: "") + " " + account.userId + " " + NSLocalizedString("_in_", comment: "") + " " + host
                 titleView = NSLocalizedString("_user_", comment: "") + " " + account.userId + " " + NSLocalizedString("_in_", comment: "") + " " + host
             }
             }
         }
         }
@@ -142,7 +142,7 @@ class NCLoginWeb: UIViewController {
         // Stop timer error network
         // Stop timer error network
         appDelegate.timerErrorNetworking?.invalidate()
         appDelegate.timerErrorNetworking?.invalidate()
 
 
-        if let account = NCManageDatabase.shared.getActiveAccount(), CCUtility.getPassword(account.account).isEmpty {
+        if let account = NCManageDatabase.shared.getActiveAccount(), NCKeychain().getPassword(account: account.account).isEmpty {
 
 
             let message = "\n" + NSLocalizedString("_password_not_present_", comment: "")
             let message = "\n" + NSLocalizedString("_password_not_present_", comment: "")
             let alertController = UIAlertController(title: titleView, message: message, preferredStyle: .alert)
             let alertController = UIAlertController(title: titleView, message: message, preferredStyle: .alert)

+ 2 - 1
iOSClient/Networking/NCNetworkingCheckRemoteUser.swift

@@ -28,8 +28,9 @@ class NCNetworkingCheckRemoteUser {
 
 
     func checkRemoteUser(account: String, error: NKError) {
     func checkRemoteUser(account: String, error: NKError) {
 
 
+        let token = NCKeychain().getPassword(account: account)
         guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)),
         guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)),
-              let token = CCUtility.getPassword(account), !token.isEmpty,
+              !token.isEmpty,
               let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
               let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
 
 
         NCNetworking.shared.cancel(inBackground: true)
         NCNetworking.shared.cancel(inBackground: true)

+ 2 - 2
iOSClient/PushNotification/NCPushNotification.m

@@ -106,7 +106,7 @@
     NSString *pushDevicePublicKey = [[NSString alloc] initWithData:pushPublicKey encoding:NSUTF8StringEncoding];
     NSString *pushDevicePublicKey = [[NSString alloc] initWithData:pushPublicKey encoding:NSUTF8StringEncoding];
     NSString *proxyServerPath = [NCBrandOptions shared].pushNotificationServerProxy;
     NSString *proxyServerPath = [NCBrandOptions shared].pushNotificationServerProxy;
     
     
-    [[NextcloudKit shared] subscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] pushTokenHash:pushTokenHash devicePublicKey:pushDevicePublicKey proxyServerUrl:proxyServerPath customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completion:^(NSString *account, NSString *deviceIdentifier, NSString *signature, NSString *publicKey, NSData *data, NKError *error) {
+    [[NextcloudKit shared] subscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[[[NCKeychain alloc] init] getPasswordWithAccount:account] pushTokenHash:pushTokenHash devicePublicKey:pushDevicePublicKey proxyServerUrl:proxyServerPath customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completion:^(NSString *account, NSString *deviceIdentifier, NSString *signature, NSString *publicKey, NSData *data, NKError *error) {
         if (error == NKError.success) {
         if (error == NKError.success) {
             NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [[NCBrandOptions shared] getUserAgent]];
             NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [[NCBrandOptions shared] getUserAgent]];
             [[NextcloudKit shared] subscribingPushProxyWithProxyServerUrl:proxyServerPath pushToken:self.pushKitToken deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent queue:dispatch_get_main_queue() completion:^(NKError *error) {
             [[NextcloudKit shared] subscribingPushProxyWithProxyServerUrl:proxyServerPath pushToken:self.pushKitToken deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent queue:dispatch_get_main_queue() completion:^(NKError *error) {
@@ -132,7 +132,7 @@
     NSString *signature = [CCUtility getPushNotificationDeviceIdentifierSignature:account];
     NSString *signature = [CCUtility getPushNotificationDeviceIdentifierSignature:account];
     NSString *publicKey = [CCUtility getPushNotificationSubscribingPublicKey:account];
     NSString *publicKey = [CCUtility getPushNotificationSubscribingPublicKey:account];
 
 
-    [[NextcloudKit shared] unsubscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completion:^(NSString *account, NKError *error) {
+    [[NextcloudKit shared] unsubscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[[[NCKeychain alloc] init] getPasswordWithAccount:account] customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completion:^(NSString *account, NKError *error) {
         if (error == NKError.success) {
         if (error == NKError.success) {
             NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [[NCBrandOptions shared] getUserAgent]];
             NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [[NCBrandOptions shared] getUserAgent]];
             NSString *proxyServerPath = [NCBrandOptions shared].pushNotificationServerProxy;
             NSString *proxyServerPath = [NCBrandOptions shared].pushNotificationServerProxy;

+ 2 - 2
iOSClient/Settings/CCAdvanced.m

@@ -48,7 +48,7 @@
     
     
     row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
     row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
     row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
     row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-    if ([[NCKeychain init] showHiddenFiles]) row.value = @"1";
+    if ([[[NCKeychain alloc] init] showHiddenFiles]) row.value = @"1";
     else row.value = @"0";
     else row.value = @"0";
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
     [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
     [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
@@ -62,7 +62,7 @@
 
 
     row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
     row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
     row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
     row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-    if ([[NCKeychain init] formatCompatibility]) row.value = @"1";
+    if ([[[NCKeychain alloc] init] formatCompatibility]) row.value = @"1";
     else row.value = @"0";
     else row.value = @"0";
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
     [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
     [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];

+ 1 - 1
iOSClient/Utility/CCUtility.h

@@ -65,7 +65,7 @@
 + (void)setDisableCrashservice:(BOOL)disable;
 + (void)setDisableCrashservice:(BOOL)disable;
 
 
 + (void)setPassword:(NSString *)account password:(NSString *)password;
 + (void)setPassword:(NSString *)account password:(NSString *)password;
-+ (NSString *)getPassword:(NSString *)account;
+//+ (NSString *)getPassword:(NSString *)account;
 
 
 + (void)setHCBusinessType:(NSString *)professions;
 + (void)setHCBusinessType:(NSString *)professions;
 + (NSString *)getHCBusinessType;
 + (NSString *)getHCBusinessType;

+ 3 - 3
iOSClient/Utility/CCUtility.m

@@ -495,7 +495,7 @@
     BOOL addFileNameType = NO;
     BOOL addFileNameType = NO;
 
 
     // Original FileName ?
     // Original FileName ?
-    if ([[NCKeychain init] getOriginalFileNameWithKey:keyFileNameOriginal] && !forcedNewFileName) {
+    if ([[[NCKeychain alloc] init] getOriginalFileNameWithKey:keyFileNameOriginal] && !forcedNewFileName) {
         return fileName;
         return fileName;
     }
     }
 
 
@@ -520,13 +520,13 @@
 
 
     // Use File Name Type
     // Use File Name Type
     if (keyFileNameType)
     if (keyFileNameType)
-        addFileNameType = [[NCKeychain init] getFileNameTypeWithKey:keyFileNameType];
+        addFileNameType = [[[NCKeychain alloc] init] getFileNameTypeWithKey:keyFileNameType];
 
 
     NSString *fileNameExt = [[fileName pathExtension] lowercaseString];
     NSString *fileNameExt = [[fileName pathExtension] lowercaseString];
 
 
     if (keyFileName) {
     if (keyFileName) {
 
 
-        fileName = [[NCKeychain init] getFileNameMaskWithKey:keyFileName];
+        fileName = [[[NCKeychain alloc] init] getFileNameMaskWithKey:keyFileName];
 
 
         if ([fileName length] > 0) {
         if ([fileName length] > 0) {
 
 

+ 10 - 0
iOSClient/Utility/NCKeychain.swift

@@ -35,6 +35,10 @@ import KeychainAccess
     let E2E_PublicKey = "EndToEndPublicKeyServer_"
     let E2E_PublicKey = "EndToEndPublicKeyServer_"
     // swiftlint:enable identifier_name
     // swiftlint:enable identifier_name
 
 
+    override init() {
+        super.init()
+    }
+
     var typeFilterScanDocument: NCGlobal.TypeFilterScanDocument {
     var typeFilterScanDocument: NCGlobal.TypeFilterScanDocument {
         get {
         get {
             if let rawValue = try? keychain.get("ScanDocumentTypeFilter"), let value = NCGlobal.TypeFilterScanDocument(rawValue: rawValue) {
             if let rawValue = try? keychain.get("ScanDocumentTypeFilter"), let value = NCGlobal.TypeFilterScanDocument(rawValue: rawValue) {
@@ -159,6 +163,12 @@ import KeychainAccess
         try? keychain.removeAll()
         try? keychain.removeAll()
     }
     }
 
 
+    @objc func getPassword(account: String) -> String {
+        let key = "password" + account
+        migrate(key: key)
+        return (try? keychain.get(key)) ?? ""
+    }
+
     @objc func getOriginalFileName(key: String) -> Bool {
     @objc func getOriginalFileName(key: String) -> Bool {
         migrate(key: key)
         migrate(key: key)
         if let value = try? keychain.get(key), let result = Bool(value) {
         if let value = try? keychain.get(key), let result = Bool(value) {