Marino Faggiana 1 жил өмнө
parent
commit
e36a2dd79b

+ 4 - 2
iOSClient/Networking/E2EE/NCEndToEndMetadataV20.swift

@@ -35,7 +35,8 @@ extension NCEndToEndMetadata {
 
         guard let privateKey = CCUtility.getEndToEndPrivateKey(account),
               let publicKey = CCUtility.getEndToEndPublicKey(account),
-              let certificate = CCUtility.getEndToEndCertificate(account) else {
+              let certificate = CCUtility.getEndToEndCertificate(account),
+              let directoryTop = NCUtility.shared.getDirectoryE2EETop(serverUrl: serverUrl, account: account) else {
             return (nil, nil)
         }
 
@@ -140,7 +141,8 @@ extension NCEndToEndMetadata {
 
     func decoderMetadataV20(_ json: String, signature: String?, serverUrl: String, account: String, ocIdServerUrl: String, urlBase: String, userId: String, ownerId: String?) -> NKError {
 
-        guard let data = json.data(using: .utf8) else {
+        guard let data = json.data(using: .utf8),
+              let directoryTop = NCUtility.shared.getDirectoryE2EETop(serverUrl: serverUrl, account: account) else {
             return NKError(errorCode: NCGlobal.shared.errorE2EE, errorDescription: "Error decoding JSON")
         }
 

+ 20 - 0
iOSClient/Utility/NCUtility.swift

@@ -750,9 +750,11 @@ class NCUtility: NSObject {
     func isDirectoryE2EE(serverUrl: String, userBase: NCUserBaseUrl) -> Bool {
         return isDirectoryE2EE(serverUrl: serverUrl, account: userBase.account, urlBase: userBase.urlBase, userId: userBase.userId)
     }
+
     func isDirectoryE2EE(file: NKFile) -> Bool {
         return isDirectoryE2EE(serverUrl: file.serverUrl, account: file.account, urlBase: file.urlBase, userId: file.userId)
     }
+
     @objc func isDirectoryE2EE(serverUrl: String, account: String, urlBase: String, userId: String) -> Bool {
         if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: urlBase, userId: userId) || serverUrl == ".." { return false }
         if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, serverUrl)) {
@@ -760,6 +762,7 @@ class NCUtility: NSObject {
         }
         return false
     }
+
     func isDirectoryE2EETop(serverUrl: String, account: String) -> Bool {
         if let url = URL(string: serverUrl)?.deletingLastPathComponent() {
             if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, String(url.absoluteString.dropLast()))) {
@@ -769,6 +772,23 @@ class NCUtility: NSObject {
         return true
     }
 
+    func getDirectoryE2EETop(serverUrl: String, account: String) -> tableDirectory? {
+        var serverUrl = serverUrl
+        var top = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, serverUrl))
+        while true {
+            if let url = URL(string: serverUrl)?.deletingLastPathComponent() {
+                serverUrl = String(url.absoluteString.dropLast())
+                if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, serverUrl)) {
+                    if directory.e2eEncrypted {
+                        top = directory
+                    } else {
+                        return top
+                    }
+                } else { return top }
+            } else { return top }
+        }
+    }
+
     func createViewImageAndText(image: UIImage, title: String? = nil) -> UIView {
 
         let imageView = UIImageView()