Browse Source

Merge pull request #2298 from nextcloud/ManageE2EE

Manage e2ee
Marino Faggiana 2 years ago
parent
commit
400e536393

+ 4 - 6
Nextcloud.xcodeproj/project.pbxproj

@@ -147,6 +147,7 @@
 		F719D9E2288D396100762E33 /* NCColorPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F719D9E1288D396100762E33 /* NCColorPicker.swift */; };
 		F71CD6CA2930D7B1006C95C1 /* NCApplicationHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F71CD6C92930D7B1006C95C1 /* NCApplicationHandle.swift */; };
 		F7226EDC1EE4089300EBECB1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7226EDB1EE4089300EBECB1 /* Main.storyboard */; };
+		F7237DD1295463E700A9D8B7 /* NCBrandFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7237DD0295463E700A9D8B7 /* NCBrandFont.swift */; };
 		F723985C253C95CE00257F49 /* NCViewerRichdocument.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F723985B253C95CE00257F49 /* NCViewerRichdocument.storyboard */; };
 		F7239871253D86B600257F49 /* NCEmptyDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7239870253D86B600257F49 /* NCEmptyDataSet.swift */; };
 		F7239877253D86D300257F49 /* NCEmptyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7239876253D86D300257F49 /* NCEmptyView.xib */; };
@@ -188,7 +189,6 @@
 		F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7381EDA218218C9000B1560 /* NCOffline.swift */; };
 		F7381EE5218218C9000B1560 /* NCOffline.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7381EDE218218C9000B1560 /* NCOffline.storyboard */; };
 		F738D4902756740100CD1D38 /* NCLoginNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F738D48F2756740100CD1D38 /* NCLoginNavigationController.swift */; };
-		F738E8421F90FFD100F95C8E /* NCManageEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F738E8411F90FFD100F95C8E /* NCManageEndToEndEncryption.m */; };
 		F73ADD1C265546890069EA0D /* SwiftEntryKit in Frameworks */ = {isa = PBXBuildFile; productRef = F73ADD1B265546890069EA0D /* SwiftEntryKit */; };
 		F73ADD2126554F8E0069EA0D /* SwiftEntryKit in Frameworks */ = {isa = PBXBuildFile; productRef = F73ADD2026554F8E0069EA0D /* SwiftEntryKit */; };
 		F73ADD2226554FD10069EA0D /* NCContentPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F765608E23BF813500765969 /* NCContentPresenter.swift */; };
@@ -774,6 +774,7 @@
 		F719D9E1288D396100762E33 /* NCColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCColorPicker.swift; sourceTree = "<group>"; };
 		F71CD6C92930D7B1006C95C1 /* NCApplicationHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCApplicationHandle.swift; sourceTree = "<group>"; };
 		F7226EDB1EE4089300EBECB1 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
+		F7237DD0295463E700A9D8B7 /* NCBrandFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCBrandFont.swift; sourceTree = "<group>"; };
 		F723985B253C95CE00257F49 /* NCViewerRichdocument.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCViewerRichdocument.storyboard; sourceTree = "<group>"; };
 		F7239870253D86B600257F49 /* NCEmptyDataSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEmptyDataSet.swift; sourceTree = "<group>"; };
 		F7239876253D86D300257F49 /* NCEmptyView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCEmptyView.xib; sourceTree = "<group>"; };
@@ -811,8 +812,6 @@
 		F7381EDA218218C9000B1560 /* NCOffline.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCOffline.swift; sourceTree = "<group>"; };
 		F7381EDE218218C9000B1560 /* NCOffline.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCOffline.storyboard; sourceTree = "<group>"; };
 		F738D48F2756740100CD1D38 /* NCLoginNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCLoginNavigationController.swift; sourceTree = "<group>"; };
-		F738E8401F90FFD100F95C8E /* NCManageEndToEndEncryption.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCManageEndToEndEncryption.h; sourceTree = "<group>"; };
-		F738E8411F90FFD100F95C8E /* NCManageEndToEndEncryption.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCManageEndToEndEncryption.m; sourceTree = "<group>"; };
 		F73B42292476764F00A30FD3 /* NCNotification.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = NCNotification.storyboard; path = Notification/NCNotification.storyboard; sourceTree = "<group>"; };
 		F73B422A2476764F00A30FD3 /* NCNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NCNotification.swift; path = Notification/NCNotification.swift; sourceTree = "<group>"; };
 		F73CB3B122E072A000AD728E /* NCShareHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCShareHeaderView.xib; sourceTree = "<group>"; };
@@ -1836,8 +1835,6 @@
 				F7ACE4311BAC0268006C0017 /* NCSettings.m */,
 				F7A7FA6229265CF4000603EF /* NCManageE2EE.swift */,
 				F726EEEB1FED1C820030B9C8 /* NCEndToEndInitialize.swift */,
-				F738E8401F90FFD100F95C8E /* NCManageEndToEndEncryption.h */,
-				F738E8411F90FFD100F95C8E /* NCManageEndToEndEncryption.m */,
 			);
 			path = Settings;
 			sourceTree = "<group>";
@@ -1930,6 +1927,7 @@
 				F70F96AF2874394B006C8379 /* Nextcloud-Bridging-Header.h */,
 				F73CB5771ED46807005F2A5A /* NCBridgeSwift.h */,
 				F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */,
+				F7237DD0295463E700A9D8B7 /* NCBrandFont.swift */,
 			);
 			path = Brand;
 			sourceTree = "<group>";
@@ -3045,7 +3043,6 @@
 				F77BB74A2899857B0090FC19 /* UINavigationController+Extension.swift in Sources */,
 				F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
 				F769454622E9F1B0000A798A /* NCShareCommon.swift in Sources */,
-				F738E8421F90FFD100F95C8E /* NCManageEndToEndEncryption.m in Sources */,
 				F70753F12542A9A200972D44 /* NCViewerMedia.swift in Sources */,
 				F78A18B823CDE2B300F681F3 /* NCViewerRichWorkspace.swift in Sources */,
 				F7A60F86292D215000FCE1F2 /* NCTalkAccounts.swift in Sources */,
@@ -3075,6 +3072,7 @@
 				F76673ED22C901F6007ED366 /* FileProviderDomain.swift in Sources */,
 				F7A321AD1E9E6AD50069AD1B /* CCAdvanced.m in Sources */,
 				F77B0E4F1D118A16002130FE /* CCManageAutoUpload.m in Sources */,
+				F7237DD1295463E700A9D8B7 /* NCBrandFont.swift in Sources */,
 				F7BAADC81ED5A87C00B7EAD4 /* NCDatabase.swift in Sources */,
 				F75C0C4823D1FAE300163CC8 /* NCRichWorkspaceCommon.swift in Sources */,
 				F78ACD4A21903F850088454D /* NCTrashListCell+NCTrashCellProtocol.swift in Sources */,

+ 9 - 6
iOSClient/AppDelegate.swift

@@ -295,12 +295,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         NCNetworking.shared.cancelAllDownloadTransfer()
 
-        let content = UNMutableNotificationContent()
-        content.title = NCBrandOptions.shared.brand
-        content.body = NSLocalizedString("_keep_running_", comment: "")
-        let req = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
-        let notificationCenter = UNUserNotificationCenter.current()
-        notificationCenter.add(req)
+        if UIApplication.shared.backgroundRefreshStatus == .available {
+
+            let content = UNMutableNotificationContent()
+            content.title = NCBrandOptions.shared.brand
+            content.body = NSLocalizedString("_keep_running_", comment: "")
+            let req = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
+            let notificationCenter = UNUserNotificationCenter.current()
+            notificationCenter.add(req)
+        }
 
         NKCommon.shared.writeLog("bye bye")
     }

+ 2 - 2
iOSClient/Brand/NCBrand.swift

@@ -324,9 +324,9 @@ class NCBrandColor: NSObject {
         }
         
         createImagesThemingColor()
-        #if !EXTENSION
+#if !EXTENSION
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
-        #endif
+#endif
     }
 
     private func stepCalc(steps: Int, color1: CGColor, color2: CGColor) -> [CGFloat] {

+ 12 - 10
iOSClient/Settings/NCManageEndToEndEncryption.h → iOSClient/Brand/NCBrandFont.swift

@@ -1,9 +1,9 @@
 //
-//  NCManageEndToEndEncryption.h
+//  NCBrandFont.swift
 //  Nextcloud
 //
-//  Created by Marino Faggiana on 13/10/17.
-//  Copyright © 2017 Marino Faggiana. All rights reserved.
+//  Created by Marino Faggiana on 22/12/22.
+//  Copyright © 2022 Marino Faggiana. All rights reserved.
 //
 //  Author Marino Faggiana <marino.faggiana@nextcloud.com>
 //
@@ -21,12 +21,14 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-#import <XLForm.h>
+import Foundation
+import SwiftUI
 
-@class NCEndToEndInitialize;
+class NCBrandFont: NSObject {
+    static let shared: NCBrandFont = {
+        let instance = NCBrandFont()
+        return instance
+    }()
 
-@interface NCManageEndToEndEncryption : XLFormViewController
-
-@property (nonatomic, strong) NCEndToEndInitialize *endToEndInitialize;
-
-@end
+    var settings: Font = .subheadline
+}

+ 4 - 4
iOSClient/Data/NCManageDatabase.swift

@@ -111,10 +111,10 @@ class NCManageDatabase: NSObject {
             } catch {
                 if let databaseFileUrlPath = databaseFileUrlPath {
                     do {
-                        #if !EXTENSION
+#if !EXTENSION
                         let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_database_corrupt_")
                         NCContentPresenter.shared.showError(error: error, priority: .max)
-                        #endif
+#endif
                         NKCommon.shared.writeLog("DATABASE CORRUPT: removed")
                         try FileManager.default.removeItem(at: databaseFileUrlPath)
                     } catch {}
@@ -135,10 +135,10 @@ class NCManageDatabase: NSObject {
         } catch {
             if let databaseFileUrlPath = databaseFileUrlPath {
                 do {
-                    #if !EXTENSION
+#if !EXTENSION
                     let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_database_corrupt_")
                     NCContentPresenter.shared.showError(error: error, priority: .max)
-                    #endif
+#endif
                     NKCommon.shared.writeLog("DATABASE CORRUPT: removed")
                     try FileManager.default.removeItem(at: databaseFileUrlPath)
                 } catch {}

+ 33 - 33
iOSClient/Networking/NCNetworking.swift

@@ -79,7 +79,7 @@ import Photos
         return session
     }()
 
-    #if EXTENSION
+#if EXTENSION
     @objc public lazy var sessionManagerBackgroundExtension: URLSession = {
         let configuration = URLSessionConfiguration.background(withIdentifier: sessionIdentifierBackgroundExtension)
         configuration.allowsCellularAccess = true
@@ -91,7 +91,7 @@ import Photos
         let session = URLSession(configuration: configuration, delegate: NKBackground.shared, delegateQueue: OperationQueue.main)
         return session
     }()
-    #endif
+#endif
 
     // REQUESTS
 
@@ -103,19 +103,19 @@ import Photos
     override init() {
         super.init()
 
-        #if EXTENSION
+#if EXTENSION
         _ = sessionIdentifierBackgroundExtension
-        #else
+#else
         _ = sessionManagerBackground
         _ = sessionManagerBackgroundWWan
-        #endif
+#endif
     }
 
     // MARK: - Communication Delegate
 
     func networkReachabilityObserver(_ typeReachability: NKCommon.typeReachability) {
 
-        #if !EXTENSION
+#if !EXTENSION
         if typeReachability == NKCommon.typeReachability.reachableCellular || typeReachability == NKCommon.typeReachability.reachableEthernetOrWiFi {
             if !lastReachability {
                 NCService.shared.startRequestServicesServer()
@@ -129,7 +129,7 @@ import Photos
             lastReachability = false
         }
         networkReachability = typeReachability
-        #endif
+#endif
     }
 
     func authenticationChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
@@ -148,13 +148,13 @@ import Photos
 
     func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
 
-        #if !EXTENSION
+#if !EXTENSION
         if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let completionHandler = appDelegate.backgroundSessionCompletionHandler {
             NKCommon.shared.writeLog("[INFO] Called urlSessionDidFinishEvents for Background URLSession")
             appDelegate.backgroundSessionCompletionHandler = nil
             completionHandler()
         }
-        #endif
+#endif
     }
 
     // MARK: - Pinning check
@@ -194,9 +194,9 @@ import Photos
         if isTrusted {
             completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
         } else {
-            #if !EXTENSION
+#if !EXTENSION
             DispatchQueue.main.async { (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host) }
-            #endif
+#endif
             completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
         }
     }
@@ -366,12 +366,12 @@ import Photos
 
                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: "", sessionError: "", sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusNormal, etag: etag)
                 NCManageDatabase.shared.addLocalFile(metadata: metadata)
-                #if !EXTENSION
+#if !EXTENSION
                 if let result = NCManageDatabase.shared.getE2eEncryption(predicate: NSPredicate(format: "fileNameIdentifier == %@ AND serverUrl == %@", metadata.fileName, metadata.serverUrl)) {
                     NCEndToEndEncryption.sharedManager()?.decryptFileName(metadata.fileName, fileNameView: metadata.fileNameView, ocId: metadata.ocId, key: result.key, initializationVector: result.initializationVector, authenticationTag: result.authenticationTag)
                 }
                 CCUtility.setExif(metadata) { _, _, _, _, _ in }
-                #endif
+#endif
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "selector": selector, "error": error])
 
             } else {
@@ -397,12 +397,12 @@ import Photos
         NKCommon.shared.writeLog("[INFO] Upload file \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier) with size \(metadata.size) [CHUNCK \(metadata.chunk), E2EE \(isDirectoryE2EE)]")
 
         if isDirectoryE2EE {
-            #if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
+#if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
             Task {
                 let error = await NCNetworkingE2EEUpload.shared.upload(metadata: metadata, uploadE2EEDelegate: uploadE2EEDelegate)
                 completion(error)
             }
-            #endif
+#endif
         } else if metadata.chunk {
             uploadChunkedFile(metadata: metadata, start: start, progressHandler: progressHandler) { error in
                 completion(error)
@@ -508,9 +508,9 @@ import Photos
 
     func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, error: NKError) {
         var isApplicationStateActive = false
-        #if !EXTENSION
+#if !EXTENSION
         isApplicationStateActive = UIApplication.shared.applicationState == .active
-        #endif
+#endif
         DispatchQueue.global().async {
             guard self.delegate == nil, let metadata = NCManageDatabase.shared.getMetadataFromOcId(description) else {
                 self.delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: task, error: error)
@@ -578,10 +578,10 @@ import Photos
                             NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadCancelFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
                         }))
-                        #if !EXTENSION
+#if !EXTENSION
                         let appDelegate = UIApplication.shared.delegate as! AppDelegate
                         appDelegate.window?.rootViewController?.present(alertController, animated: true)
-                        #endif
+#endif
                     }
 
                 } else {
@@ -736,9 +736,9 @@ import Photos
             }
         }
 
-        #if !EXTENSION
+#if !EXTENSION
         NCOperationQueue.shared.downloadCancelAll()
-        #endif
+#endif
     }
 
     func cancelAllDownloadTransfer() {
@@ -753,9 +753,9 @@ import Photos
             }
         }
 
-        #if !EXTENSION
+#if !EXTENSION
         NCOperationQueue.shared.downloadCancelAll()
-        #endif
+#endif
     }
 
     // MARK: - WebDav Read file, folder
@@ -1032,12 +1032,12 @@ import Photos
         let fileName = fileName.trimmingCharacters(in: .whitespacesAndNewlines)
         
         if isDirectoryEncrypted {
-            #if !EXTENSION
+#if !EXTENSION
             Task {
                 let error = await NCNetworkingE2EECreateFolder.shared.createFolder(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase, userId: userId)
                 completion(error)
             }
-            #endif
+#endif
         } else {
             createFolderPlain(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase, overwrite: overwrite, completion: completion)
         }
@@ -1168,7 +1168,7 @@ import Photos
         let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
 
         if isDirectoryEncrypted {
-            #if !EXTENSION
+#if !EXTENSION
             Task {
                 if let metadataLive = metadataLive {
                     let error = await NCNetworkingE2EEDelete.shared.delete(metadata: metadataLive)
@@ -1183,7 +1183,7 @@ import Photos
                     completion(error)
                 }
             }
-            #endif
+#endif
         } else {
             if metadataLive == nil {
                 self.deleteMetadataPlain(metadata, customHeader: nil, completion: completion)
@@ -1268,11 +1268,11 @@ import Photos
         NextcloudKit.shared.setFavorite(fileName: fileName, favorite: favorite) { account, error in
             if error == .success && metadata.account == account {
                 NCManageDatabase.shared.setMetadataFavorite(ocId: metadata.ocId, favorite: favorite)
-                #if !EXTENSION
+#if !EXTENSION
                 if favorite {
                     NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorReadFile)
                 }
-                #endif
+#endif
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteFile, userInfo: ["ocId": ocId, "serverUrl": metadata.serverUrl])
             }
             completion(error)
@@ -1292,11 +1292,11 @@ import Photos
             NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in
                 NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas)
                 if selector != NCGlobal.shared.selectorListingFavorite {
-                    #if !EXTENSION
+#if !EXTENSION
                     for metadata in metadatas {
                         NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selector)
                     }
-                    #endif
+#endif
                 }
                 completion(account, metadatas, error)
             }
@@ -1331,7 +1331,7 @@ import Photos
         let fileNameNewLive = (fileNameNew as NSString).deletingPathExtension + ".mov"
 
         if isDirectoryEncrypted {
-            #if !EXTENSION
+#if !EXTENSION
             Task {
                 if let metadataLive = metadataLive {
                     let error = await NCNetworkingE2EERename.shared.rename(metadata: metadataLive, fileNameNew: fileNameNew)
@@ -1346,7 +1346,7 @@ import Photos
                     DispatchQueue.main.async { completion(error) }
                 }
             }
-            #endif
+#endif
         } else {
             if metadataLive == nil {
                 renameMetadataPlain(metadata, fileNameNew: fileNameNew, completion: completion)

+ 2 - 2
iOSClient/Security/NCEndToEndEncryption.m

@@ -205,10 +205,10 @@
     if(keyBytes)
         free(keyBytes);
     
-    #ifdef DEBUG
+#ifdef DEBUG
     // Save to disk [DEBUG MODE]
     [self saveToDiskPEMWithCert:x509 key:pkey directory:directory];
-    #endif
+#endif
     
     return YES;
 }

+ 229 - 52
iOSClient/Settings/NCManageE2EE.swift

@@ -27,26 +27,45 @@ import TOPasscodeViewController
 import LocalAuthentication
 
 @objc class NCManageE2EEInterface: NSObject {
+
     @objc func makeShipDetailsUI(account: String) -> UIViewController {
-        let details = NCViewE2EE()
+        let account = (UIApplication.shared.delegate as! AppDelegate).account
+        let details = NCViewE2EE(account: account)
         return UIHostingController(rootView: details)
     }
 }
 
-class NCManageE2EE: NSObject, NCEndToEndInitializeDelegate, TOPasscodeViewControllerDelegate {
+class NCManageE2EE: NSObject, ObservableObject, NCEndToEndInitializeDelegate, TOPasscodeViewControllerDelegate {
 
     let endToEndInitialize = NCEndToEndInitialize()
-    private let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    private var passcodeType = ""
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var passcodeType = ""
+
+    @Published var isEndToEndEnabled: Bool = false
+    @Published var statusOfService: String = NSLocalizedString("_status_in_progress_", comment: "")
 
     override init() {
         super.init()
 
         endToEndInitialize.delegate = self
+        isEndToEndEnabled = CCUtility.isEnd(toEndEnabled: appDelegate.account)
+        if isEndToEndEnabled {
+            statusOfService = NSLocalizedString("_status_e2ee_configured_", comment: "")
+        } else {
+            endToEndInitialize.statusOfService { error in
+                if error == .success {
+                    self.statusOfService = NSLocalizedString("_status_e2ee_on_server_", comment: "")
+                } else {
+                    self.statusOfService = NSLocalizedString("_status_e2ee_not_setup_", comment: "")
+                }
+            }
+        }
     }
 
+    // MARK: - Delegate
+
     func endToEndInitializeSuccess() {
-       //details.isEndToEndEnabled = true
+        isEndToEndEnabled = true
     }
 
     // MARK: - Passcode
@@ -78,13 +97,30 @@ class NCManageE2EE: NSObject, NCEndToEndInitializeDelegate, TOPasscodeViewContro
 
     @objc func correctPasscode() {
 
-        if self.passcodeType == "removeLocallyEncryption" {
+        switch self.passcodeType {
+        case "startE2E":
+            endToEndInitialize.initEndToEndEncryption()
+        case "readPassphrase":
+            if let e2ePassphrase = CCUtility.getEndToEndPassphrase(appDelegate.account) {
+                print("[LOG]Passphrase: " + e2ePassphrase)
+                let message = "\n" + NSLocalizedString("_e2e_settings_the_passphrase_is_", comment: "") + "\n\n\n" + e2ePassphrase
+                let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in }))
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_copy_passphrase_", comment: ""), style: .default, handler: { action in
+                    UIPasteboard.general.string = e2ePassphrase
+                }))
+                appDelegate.window?.rootViewController?.present(alertController, animated: true)
+            }
+        case "removeLocallyEncryption":
             let alertController = UIAlertController(title: NSLocalizedString("_e2e_settings_remove_", comment: ""), message: NSLocalizedString("_e2e_settings_remove_message_", comment: ""), preferredStyle: .alert)
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_", comment: ""), style: .default, handler: { action in
                 CCUtility.clearAllKeysEnd(toEnd: self.appDelegate.account)
+                self.isEndToEndEnabled = CCUtility.isEnd(toEndEnabled: self.appDelegate.account)
             }))
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default, handler: { action in }))
             appDelegate.window?.rootViewController?.present(alertController, animated: true)
+        default:
+            break
         }
     }
 
@@ -117,72 +153,213 @@ class NCManageE2EE: NSObject, NCEndToEndInitializeDelegate, TOPasscodeViewContro
     }
 }
 
+// MARK: Views
+
 struct NCViewE2EE: View {
 
-    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
+    @ObservedObject var manageE2EE = NCManageE2EE()
+    @State var account: String = ""
 
     var body: some View {
+
+        let versionE2EE = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesE2EEApiVersion) ?? ""
+
         VStack {
             VStack {
 
-                Text("Hello, world! 1 come stai spero bene ma secondo te quanto è lunga questa cosa, Hello, world! 1 come stai spero bene ma secondo te quanto è lunga questa cosa, versione 2 perchè la versione 1 e poi altro testo ")
-                    .frame(height: 100)
-                    .padding()
+                if manageE2EE.isEndToEndEnabled {
+
+                    List {
+
+                        Section(header: SectionView(height: 10), footer:Text(manageE2EE.statusOfService + "\n\n" + "End-to-End Encryption " + versionE2EE)) {
+                            Label {
+                                Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
+                                    .font(NCBrandFont.shared.settings)
+                            } icon: {
+                                Image(systemName: "checkmark.circle.fill")
+                                    .resizable()
+                                    .scaledToFit()
+                                    .frame(width: 25, height: 25)
+                                    .foregroundColor(.green)
+                            }
+                        }
+
+                        Label {
+                            Text(NSLocalizedString("_e2e_settings_read_passphrase_", comment: ""))
+                                .font(NCBrandFont.shared.settings)
+                                .onTapGesture {
+                                    if CCUtility.getPasscode().isEmpty {
+                                        NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
+                                    } else {
+                                        manageE2EE.requestPasscodeType("readPassphrase")
+                                    }
+                                }
+                        } icon: {
+                            Image(systemName: "doc.plaintext")
+                                .resizable()
+                                .scaledToFit()
+                                .frame(width: 25, height: 25)
+                                .foregroundColor(Color(UIColor.systemGray))
+                        }
+
+                        Label {
+                            Text(NSLocalizedString("_e2e_settings_remove_", comment: ""))
+                                .font(NCBrandFont.shared.settings)
+                                .onTapGesture {
+                                    if CCUtility.getPasscode().isEmpty {
+                                        NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
+                                    } else {
+                                        manageE2EE.requestPasscodeType("removeLocallyEncryption")
+                                    }
+                                }
+                        } icon: {
+                            Image(systemName: "trash.circle")
+                                .resizable()
+                                .scaledToFit()
+                                .frame(width: 25, height: 25)
+                                .foregroundColor(Color.red)
+                        }
 
-                Button(action: {}) {
-                    HStack{
-                        Image(systemName: "person.crop.circle.fill")
-                        Text("This is a button")
-                            .padding(.horizontal)
+#if DEBUG
+                        DeleteCerificateSection()
+#endif
                     }
-                    .padding()
-                }
-                .foregroundColor(Color.white)
-                .background(Color.blue)
-                .cornerRadius(.infinity)
-                .frame(height: 100)
 
-                if CCUtility.isEnd(toEndEnabled: appDelegate.account) {
-                    Text("Activated")
                 } else {
-                    Button(action: {
-                        //manageE2EE.endToEndInitialize.initEndToEndEncryption()
-                    }, label: {
-                        Text("Start E2EE")
-                    })
-                }
 
+                    List {
 
-                Button(action: {
-                    if CCUtility.getPasscode().isEmpty {
-                        NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
-                    } else {
-                        //manageE2EE.requestPasscodeType("removeLocallyEncryption")
-                    }
-                }, label: {
-                    Text(NSLocalizedString("_e2e_settings_remove_", comment: ""))
-                })
+                        Section(header: SectionView(height: 10), footer:Text(manageE2EE.statusOfService + "\n\n" + "End-to-End Encryption " + versionE2EE)) {
+                            Label {
+                                Text(NSLocalizedString("_e2e_settings_start_", comment: ""))
+                                    .font(NCBrandFont.shared.settings)
+                                    .onTapGesture {
+                                        if CCUtility.getPasscode().isEmpty {
+                                            NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
+                                        } else {
+                                            manageE2EE.requestPasscodeType("startE2E")
+                                        }
+                                    }
+                            } icon: {
+                                Image(systemName: "play.circle")
+                                    .resizable()
+                                    .scaledToFit()
+                                    .frame(width: 25, height: 25)
+                                    .foregroundColor(.green)
+                            }
+                        }
 
 #if DEBUG
-                Button(action: {
+                        DeleteCerificateSection()
+#endif
+                    }
+                }
+            }
+        }
+        .background(Color(UIColor.systemGroupedBackground))
+        .navigationTitle(NSLocalizedString("_e2e_settings_", comment: ""))
+    }
+}
 
-                }, label: {
-                    Text("Delete Certificate")
-                })
-                Button(action: {
-                    NextcloudKit.shared.deleteE2EEPrivateKey { account, error in
+struct DeleteCerificateSection: View {
+
+    var body: some View {
 
+        Section(header: Text("Delete Server keys"), footer: Text("Available only in debug")) {
+
+            Label {
+                Text("Delete certificate")
+                    .font(NCBrandFont.shared.settings)
+                    .onTapGesture {
+                    NextcloudKit.shared.deleteE2EECertificate { account, error in
+                        if error == .success {
+                            NCContentPresenter.shared.messageNotification("E2E delete certificate", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .success)
+                        } else {
+                            NCContentPresenter.shared.messageNotification("E2E delete certificate", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
+                        }
                     }
-                }, label: {
-                    Text("Delete PrivateKey")
-                })
-#endif
+                }
+            } icon: {
+                Image(systemName: "exclamationmark.triangle")
+                    .resizable()
+                    .scaledToFit()
+                    .frame(width: 25, height: 25)
+                    .foregroundColor(Color(UIColor.systemGray))
+            }
 
+            Label {
+                Text("Delete PrivateKey")
+                    .font(NCBrandFont.shared.settings)
+                    .onTapGesture {
+                    NextcloudKit.shared.deleteE2EEPrivateKey { account, error in
+                        if error == .success {
+                            NCContentPresenter.shared.messageNotification("E2E delete privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .success)
+                        } else {
+                            NCContentPresenter.shared.messageNotification("E2E delete privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
+                        }
+                    }
+                }
+            } icon: {
+                Image(systemName: "exclamationmark.triangle")
+                    .resizable()
+                    .scaledToFit()
+                    .frame(width: 25, height: 25)
+                    .foregroundColor(Color(UIColor.systemGray))
             }
-            .background(Color.green)
-            Spacer()
         }
-        .background(Color.gray)
-        .navigationTitle("Cifratura End-To-End")
+    }
+}
+
+struct SectionView: View {
+
+    @State var height: CGFloat = 0
+    @State var text: String = ""
+
+    var body: some View {
+        HStack {
+            Text(text)
+        }
+        .frame(maxWidth: .infinity, minHeight: height, alignment: .bottomLeading)
+    }
+}
+
+// MARK: - Preview
+
+struct NCViewE2EETest: View {
+
+    var body: some View {
+
+        VStack {
+            List {
+                Section(header:SectionView(height: 50, text: "Section Header View")) {
+                    Label {
+                        Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
+                    } icon: {
+                        Image(systemName: "checkmark.circle.fill")
+                            .resizable()
+                            .scaledToFit()
+                            .frame(width: 25, height: 25)
+                            .foregroundColor(.green)
+                    }
+                }
+                Section(header:SectionView(text: "Section Header View 42")) {
+                    Label {
+                        Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
+                    } icon: {
+                        Image(systemName: "checkmark.circle.fill")
+                            .resizable()
+                            .scaledToFit()
+                            .frame(width: 25, height: 25)
+                            .foregroundColor(.red)
+                    }
+                }
+            }
+        }
+    }
+}
+
+struct NCViewE2EE_Previews: PreviewProvider {
+    static var previews: some View {
+        NCViewE2EETest()
     }
 }

+ 0 - 415
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -1,415 +0,0 @@
-//
-//  NCManageEndToEndEncryption.m
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 13/10/17.
-//  Copyright © 2017 Marino Faggiana. All rights reserved.
-//
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#import "NCManageEndToEndEncryption.h"
-#import "NSNotificationCenter+MainThread.h"
-#import <LocalAuthentication/LocalAuthentication.h>
-#import <TOPasscodeViewController/TOPasscodeViewController.h>
-#import "NCBridgeSwift.h"
-#import "CCUtility.h"
-
-@interface NCManageEndToEndEncryption () <NCEndToEndInitializeDelegate, TOPasscodeViewControllerDelegate>
-{
-    AppDelegate *appDelegate;
-    NSString *passcodeType;
-    TOPasscodeViewController *passcodeViewController;
-}
-@end
-
-@implementation NCManageEndToEndEncryption
-
-- (void)initializeForm:(NKError *)error
-{
-    XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
-    XLFormSectionDescriptor *section;
-    XLFormRowDescriptor *row;
-    
-    BOOL isE2EEEnabled = [[NCManageDatabase shared] getCapabilitiesServerBoolWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesE2EEEnabled exists:false];
-    NSString *versionE2EE = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesE2EEApiVersion];
-    
-    if (![versionE2EE isEqual:[[NCGlobal shared] e2eeVersion]] && isE2EEEnabled) {
-        NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"_err_e2ee_app_version_"];
-        [[NCContentPresenter shared] messageNotification:@"_error_e2ee_" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError];
-    }
-
-    if ([CCUtility isEndToEndEnabled:appDelegate.account]) {
-        
-        // Section SERVICE ACTIVATED -------------------------------------------------
-        
-        section = [XLFormSectionDescriptor formSection];
-        section.footerTitle = [NSString stringWithFormat:@"End-to-End Encryption %@", versionE2EE];
-        [form addFormSection:section];
-        
-        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"serviceActivated" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_e2e_settings_activated_", nil)];
-        row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-        [row.cellConfig setObject:[[UIImage imageNamed:@"checkmark.circle.fill"] imageWithColor:[UIColor greenColor] size:25] forKey:@"imageView.image"];
-        [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-        [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
-        [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
-        [section addFormRow:row];
-        
-        // Section PASSPHRASE -------------------------------------------------
-        
-        section = [XLFormSectionDescriptor formSection];
-        [form addFormSection:section];
-        
-        // Read Passphrase
-        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"readPassphrase" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_read_passphrase_", nil)];
-        row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-        [row.cellConfig setObject:[[UIImage imageNamed:@"e2eReadPassphrase"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
-        [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-        [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
-        [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
-        row.action.formSelector = @selector(readPassphrase:);
-        [section addFormRow:row];
-        
-        // Section DELETE -------------------------------------------------
-        
-        section = [XLFormSectionDescriptor formSection];
-        [form addFormSection:section];
-        
-        // remove locally Encryption
-        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"removeLocallyEncryption" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_remove_", nil)];
-        row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-        [row.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
-        [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-        [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
-        [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
-        row.action.formSelector = @selector(removeLocallyEncryption:);
-        [section addFormRow:row];
-        
-    } else {
-        
-        // Section START E2E -------------------------------------------------
-
-        section = [XLFormSectionDescriptor formSection];
-        if (error == nil) {
-            section.footerTitle = NSLocalizedString(@"_status_in_progress_", nil);
-        } else if (error.errorCode == 0) {
-            section.footerTitle = NSLocalizedString(@"_status_e2ee_on_server_", nil);
-        } else {
-            section.footerTitle = NSLocalizedString(@"_status_e2ee_not_setup_", nil);
-        }
-        [form addFormSection:section];
-    
-        // Start e2e
-        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"startE2E" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_start_", nil)];
-        row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-        [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-        [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
-        [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
-        row.action.formSelector = @selector(startE2E:);
-        [section addFormRow:row];   
-    }
-    
-    #ifdef DEBUG
-    // Section DELETE KEYS -------------------------------------------------
-    
-    section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"Delete server keys ", nil)];
-    [form addFormSection:section];
-    
-    // Delete publicKey
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deleteCertificate" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Delete certificate", nil)];
-    row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-    [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-    [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
-    [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
-    row.action.formSelector = @selector(deleteCertificate:);
-    [section addFormRow:row];
-    
-    // Delete privateKey
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deletePrivateKey" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Delete PrivateKey", nil)];
-    row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
-    [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-    [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
-    [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
-    row.action.formSelector = @selector(deletePrivateKey:);
-    [section addFormRow:row];
-    #endif
-    
-    self.tableView.showsVerticalScrollIndicator = NO;
-    self.form = form;
-}
-
-// MARK: - View Life Cycle
-
-- (void)viewDidLoad
-{
-    [super viewDidLoad];
-    
-    self.title = NSLocalizedString(@"_e2e_settings_", nil);
-    appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-    self.view.backgroundColor = UIColor.systemGroupedBackgroundColor;
-    
-    self.tableView.backgroundColor = UIColor.systemGroupedBackgroundColor;
-        
-    // E2EE
-    self.endToEndInitialize = [NCEndToEndInitialize new];
-    self.endToEndInitialize.delegate = self;
-    
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:NCGlobal.shared.notificationCenterApplicationDidEnterBackground object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initialize) name:NCGlobal.shared.notificationCenterInitialize object:nil];
-
-    [self initializeForm:nil];
-    /*
-    NKRequestOptions *options = [[NKRequestOptions alloc] initWithEndpoint:nil customHeader:nil customUserAgent:nil contentType:nil e2eToken: nil timeout:30 queue:dispatch_get_main_queue()];
-    [[NextcloudKit shared] getE2EECertificateWithOptions:options completionHandler:^(NSString* account, NSString *certificate, NSData *data, NKError *error) {
-
-    }];
-    */
-}
-
-- (void)viewWillAppear:(BOOL)animated
-{
-    [super viewWillAppear:animated];
-    
-    appDelegate.activeViewController = self;
-
-    [[NCEndToEndInitialize alloc] statusOfServiceWithCompletion:^(NKError * error) {
-        [self initializeForm:error];
-    }];
-}
-
-#pragma mark - NotificationCenter
-
-- (void)applicationDidEnterBackground
-{
-    if (passcodeViewController.view.window != nil) {
-        [passcodeViewController dismissViewControllerAnimated:true completion:nil];
-    }
-}
-
-- (void)initialize
-{
-    [[self navigationController] popViewControllerAnimated:YES];
-}
-
-#pragma mark - Action
-
-- (void)startE2E:(XLFormRowDescriptor *)sender
-{
-    [self deselectFormRow:sender];
-
-    if ([[CCUtility getPasscode] length]) {
-        
-        [self passcodeType:@"startE2E"];
-        
-    } else {
-        
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_info_", nil) message:NSLocalizedString(@"_e2e_settings_lock_not_active_", nil) preferredStyle:UIAlertControllerStyleAlert];
-        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-        }];
-        [alertController addAction:okAction];
-        [self presentViewController:alertController animated:YES completion:nil];
-    }
-}
-
-- (void)readPassphrase:(XLFormRowDescriptor *)sender
-{
-    [self deselectFormRow:sender];
-    
-    if ([[CCUtility getPasscode] length]) {
-        
-        [self passcodeType:@"readPassphrase"];
-        
-    } else {
-        
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_info_", nil) message:NSLocalizedString(@"_e2e_settings_lock_not_active_", nil) preferredStyle:UIAlertControllerStyleAlert];
-        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-        }];
-        [alertController addAction:okAction];
-        [self presentViewController:alertController animated:YES completion:nil];
-    }
-}
-
-- (void)removeLocallyEncryption:(XLFormRowDescriptor *)sender
-{
-    [self deselectFormRow:sender];
-    
-    if ([[CCUtility getPasscode] length]) {
-        
-        [self passcodeType:@"removeLocallyEncryption"];
-        
-    } else {
-        
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_info_", nil) message:NSLocalizedString(@"_e2e_settings_lock_not_active_", nil) preferredStyle:UIAlertControllerStyleAlert];
-        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-        }];
-        [alertController addAction:okAction];
-        [self presentViewController:alertController animated:YES completion:nil];
-    }
-}
-
-#pragma mark - Passcode -
-
-- (void)passcodeType:(NSString *)type
-{
-    LAContext *laContext = [LAContext new];
-    NSError *error;
-    
-    if ([[CCUtility getPasscode] length] > 0) {
-        
-        passcodeViewController = [[TOPasscodeViewController alloc] initPasscodeType:TOPasscodeTypeSixDigits allowCancel:true];
-        passcodeViewController.delegate = self;
-        passcodeViewController.keypadButtonShowLettering = false;
-        
-        if (CCUtility.getEnableTouchFaceID && [laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
-            if (error == NULL) {
-                if (laContext.biometryType == LABiometryTypeFaceID) {
-                    passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
-                    passcodeViewController.allowBiometricValidation = true;
-                    passcodeViewController.automaticallyPromptForBiometricValidation = true;
-                } else if (laContext.biometryType == LABiometryTypeTouchID) {
-                    passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
-                    passcodeViewController.allowBiometricValidation = true;
-                    passcodeViewController.automaticallyPromptForBiometricValidation = true;
-                } else {
-                    NSLog(@"No Biometric support");
-                }
-            }
-        }
-        
-        // Type of passcode
-        passcodeType = type;
-        
-        [self presentViewController:passcodeViewController animated:YES completion:nil];
-    }
-}
-
-- (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
-{
-    [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
-}
-
-- (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code
-{
-    if ([code isEqualToString:[CCUtility getPasscode]]) {
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-            [self passcodeCorrectCode];
-        });
-        return YES;
-    }
-         
-    return NO;
-}
-
-- (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
-{
-    [[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions shared] brand] reply:^(BOOL success, NSError * _Nullable error) {
-        if (success) {
-            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-                [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
-                [self passcodeCorrectCode];
-            });
-        }
-    }];
-}
-
--(void)passcodeCorrectCode {
-    
-    if ([passcodeType isEqualToString:@"startE2E"]) {
-        
-        [self.endToEndInitialize initEndToEndEncryption];
-        
-    } else if ([passcodeType isEqualToString:@"readPassphrase"]) {
-        
-        NSString *e2ePassphrase = [CCUtility getEndToEndPassphrase:appDelegate.account];
-        NSLog(@"[LOG] Passphrase: %@", e2ePassphrase);
-        
-        NSString *message = [NSString stringWithFormat:@"\n%@\n\n\n%@", NSLocalizedString(@"_e2e_settings_the_passphrase_is_", nil), e2ePassphrase];
-        
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_info_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
-        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { }];
-        UIAlertAction *copyPassphrase = [UIAlertAction actionWithTitle:NSLocalizedString(@"_copy_passphrase_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-            UIPasteboard.generalPasteboard.string = e2ePassphrase;
-        }];
-
-        [alertController addAction:okAction];
-        [alertController addAction:copyPassphrase];
-        [self presentViewController:alertController animated:YES completion:nil];
-        
-    } else if ([passcodeType isEqualToString:@"removeLocallyEncryption"]) {
-        
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_e2e_settings_remove_", nil) message:NSLocalizedString(@"_e2e_settings_remove_message_", nil) preferredStyle:UIAlertControllerStyleAlert];
-        
-        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-            [CCUtility clearAllKeysEndToEnd:appDelegate.account];
-            [self initializeForm:nil];
-        }];
-        
-        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {}];
-        
-        [alertController addAction:okAction];
-        [alertController addAction:cancelAction];
-        [self presentViewController:alertController animated:YES completion:nil];
-    }
-}
-
-
-- (void)deleteCertificate:(XLFormRowDescriptor *)sender
-{
-    [self deselectFormRow:sender];
-
-    NKRequestOptions *options = [[NKRequestOptions alloc] initWithEndpoint:nil customHeader:nil customUserAgent:nil contentType:nil e2eToken: nil timeout:60 queue:dispatch_get_main_queue()];
-    [[NextcloudKit shared] deleteE2EECertificateWithOptions:options completionHandler:^(NSString *account, NKError *error) {
-        if (error == NKError.success && [account isEqualToString:appDelegate.account]) {
-            NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"Success"];
-             [[NCContentPresenter shared] messageNotification:@"E2E delete certificate" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeSuccess];
-         } else {
-             [[NCContentPresenter shared] messageNotification:@"E2E delete certificate" error:error  delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError];
-         }
-    }];
-}
-
-- (void)deletePrivateKey:(XLFormRowDescriptor *)sender
-{
-    [self deselectFormRow:sender];
-
-    NKRequestOptions *options = [[NKRequestOptions alloc] initWithEndpoint:nil customHeader:nil customUserAgent:nil contentType:nil e2eToken: nil timeout:60 queue:dispatch_get_main_queue()];
-    [[NextcloudKit shared] deleteE2EEPrivateKeyWithOptions: options completionHandler:^(NSString *account, NKError *error) {
-        if (error == NKError.success && [account isEqualToString:appDelegate.account]) {
-            NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"Success"];
-            [[NCContentPresenter shared] messageNotification:@"E2E delete privateKey" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeSuccess];
-        } else {
-            [[NCContentPresenter shared] messageNotification:@"E2E delete privateKey" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError];
-        }
-    }];
-}
-
-#pragma mark - Delegate
-
-- (void)endToEndInitializeSuccess
-{
-    // Reload All Datasource
-    [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCGlobal.shared.notificationCenterReloadDataSource object:nil];
-
-    [self initializeForm:nil];
-}
-
-#pragma mark -
-
-- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-    return NCGlobal.shared.heightCellSettings;
-}
-
-@end

+ 1 - 3
iOSClient/Settings/NCSettings.m

@@ -25,7 +25,6 @@
 #import "CCAdvanced.h"
 #import "CCManageAccount.h"
 #import "CCManageAutoUpload.h"
-#import "NCManageEndToEndEncryption.h"
 #import "NCBridgeSwift.h"
 #import "NSNotificationCenter+MainThread.h"
 #import <LocalAuthentication/LocalAuthentication.h>
@@ -134,8 +133,7 @@
         [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
         [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
         [row.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
-        //row.action.formSelector = @selector(manageE2EE:);
-        row.action.viewControllerClass = [NCManageEndToEndEncryption class];
+        row.action.formSelector = @selector(manageE2EE:);
         [section addFormRow:row];
     }
 

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -906,6 +906,7 @@
 "_status_in_progress_"      = "Status reading in progress …";
 "_status_e2ee_on_server_"   = "The end-to-end encryption is already configured in the server but not yet enabled on this device";
 "_status_e2ee_not_setup_"   = "The end-to-end encryption is not yet configured on the server";
+"_status_e2ee_configured_"  = "The end-to-end encryption is correctly configured";
 "_change_upload_filename_"  = "Do you want to save the file with a different name ?";
 "_save_file_as_"            = "Save file as %@";
 "_password_ascii_"          = "The password cannot contain special characters";

+ 3 - 3
iOSClient/Utility/NCActivityIndicator.swift

@@ -62,7 +62,7 @@ class NCActivityIndicator: NSObject {
             self.viewActivityIndicator?.layer.masksToBounds = true
             self.viewActivityIndicator?.backgroundColor = .clear
 
-            #if !EXTENSION
+#if !EXTENSION
             if backgroundView == nil {
                 if let window = (UIApplication.shared.connectedScenes.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }.first { $0.isKeyWindow }) {
                     self.viewBackgroundActivityIndicator?.removeFromSuperview()
@@ -74,9 +74,9 @@ class NCActivityIndicator: NSObject {
             } else {
                 self.viewBackgroundActivityIndicator = backgroundView
             }
-            #else
+#else
             self.viewBackgroundActivityIndicator = backgroundView
-            #endif
+#endif
 
             // VIEW ACTIVITY INDICATOR
 

+ 8 - 8
iOSClient/Utility/NCAskAuthorization.swift

@@ -40,9 +40,9 @@ class NCAskAuthorization: NSObject {
         case AVAudioSession.RecordPermission.denied:
             let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_microphone_", comment: ""), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { _ in
-                #if !EXTENSION
+#if !EXTENSION
                 UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
-                #endif
+#endif
                 completion(false)
             }))
             alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
@@ -78,9 +78,9 @@ class NCAskAuthorization: NSObject {
         case PHAuthorizationStatus.denied, PHAuthorizationStatus.limited, PHAuthorizationStatus.restricted:
             let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_photolibrary_", comment: ""), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { _ in
-                #if !EXTENSION
+#if !EXTENSION
                 UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
-                #endif
+#endif
                 completion(false)
             }))
             alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
@@ -94,9 +94,9 @@ class NCAskAuthorization: NSObject {
             isRequesting = true
             PHPhotoLibrary.requestAuthorization { allowed in
                 self.isRequesting = false
-                #if !EXTENSION
+#if !EXTENSION
                 DispatchQueue.main.async { (UIApplication.shared.delegate as? AppDelegate)?.hidePrivacyProtectionWindow() }
-                #endif
+#endif
                 DispatchQueue.main.async {
                     if allowed == PHAuthorizationStatus.authorized {
                         completion(true)
@@ -112,7 +112,7 @@ class NCAskAuthorization: NSObject {
         }
     }
 
-    #if !EXTENSION
+#if !EXTENSION
     func checkBackgroundRefreshStatus() {
         switch UIApplication.shared.backgroundRefreshStatus {
         case .available:
@@ -128,5 +128,5 @@ class NCAskAuthorization: NSObject {
             print("Unknown property")
         }
     }
-    #endif
+#endif
 }

+ 2 - 2
iOSClient/Utility/NCUtility.swift

@@ -207,7 +207,7 @@ class NCUtility: NSObject {
         return Array(Set(editor))
     }
 
-    #if !EXTENSION
+#if !EXTENSION
     @objc func removeAllSettings() {
 
         URLCache.shared.memoryCapacity = 0
@@ -226,7 +226,7 @@ class NCUtility: NSObject {
 
         CCUtility.deleteAllChainStore()
     }
-    #endif
+#endif
 
     @objc func permissionsContainsString(_ metadataPermissions: String, permissions: String) -> Bool {