marinofaggiana 4 years ago
parent
commit
a518d04ed1
2 changed files with 21 additions and 36 deletions
  1. 1 1
      Cartfile.resolved
  2. 20 35
      iOSClient/Networking/NCNetworkingE2EE.swift

+ 1 - 1
Cartfile.resolved

@@ -19,7 +19,7 @@ github "marinofaggiana/AFNetworking" "2967678c3e0e98c9b8d7e06222ad12d1f49c26f2"
 github "marinofaggiana/KTVHTTPCache" "2.0.2"
 github "marinofaggiana/TOPasscodeViewController" "0.0.6"
 github "marinofaggiana/XLForm" "eb9381ad8129f60402bf412250fb31b95a628a08"
-github "nextcloud/ios-communication-library" "060122620e3e75886ded8cb1a9911ee511c4712b"
+github "nextcloud/ios-communication-library" "0fc93d2039daded7048960f7aec9b4c88c1139bf"
 github "realm/realm-cocoa" "v4.4.1"
 github "rechsteiner/Parchment" "v1.7.0"
 github "scenee/FloatingPanel" "v1.7.4"

+ 20 - 35
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -29,6 +29,8 @@ import NCCommunication
         return instance
     }()
     
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    
     //MARK: - WebDav Create Folder
     
     func createFolder(fileName: String, serverUrl: String, account: String, user: String, userID: String, password: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
@@ -239,12 +241,18 @@ import NCCommunication
     
         self.lock(serverUrl: serverUrl, fileId: fileId) { (e2eToken, errorCode, errorDescription) in
             if errorCode == 0 && e2eToken != nil {
-            
-                let appDelegate = UIApplication.shared.delegate as! AppDelegate
-                let communication = OCNetworking.sharedManager()?.sharedOCCommunication()
-                
-                NCCommunication.shared.getE2EEMetadata(fileId: fileId, e2eToken: e2eToken) { (account, existsMetadata, errorCode, errorDescription) in
-                
+                          
+                NCCommunication.shared.getE2EEMetadata(fileId: fileId, e2eToken: e2eToken) { (account, metadata, errorCode, errorDescription) in
+                    var method = "POST"
+                    
+                    if errorCode == 0 && metadata != nil {
+                        if !NCEndToEndMetadata.sharedInstance.decoderMetadata(metadata!, privateKey: CCUtility.getEndToEndPrivateKey(account), serverUrl: serverUrl, account: account, url: self.appDelegate.activeUrl) {
+                            completion(Int(k_CCErrorInternalError), NSLocalizedString("_e2e_error_encode_metadata_", comment: ""))
+                            return
+                        }
+                        method = "PUT"
+                    }
+    
                     if (fileNameRename != nil && fileNameNewRename != nil) {
                         NCManageDatabase.sharedInstance.renameFileE2eEncryption(serverUrl: serverUrl, fileNameIdentifier: fileNameRename!, newFileName: fileNameNewRename!, newFileNamePath: CCUtility.returnFileNamePath(fromFileName: fileNameNewRename!, serverUrl: serverUrl, activeUrl: url))
                     }
@@ -258,38 +266,15 @@ import NCCommunication
                         return
                     }
             
-                    var method = ""
-                    if errorCode == 0 && existsMetadata != nil {
-                        method = "PUT"
-                        
-                        communication?.updateEnd(toEndMetadata: appDelegate.activeUrl+"/", fileId: fileId, encryptedMetadata: metadata, e2eToken: e2eToken, on: communication, successRequest: { (re, a, b) in
-                            
-                        }, failureRequest: { (re, e, a) in
-                            
-                        })
-                        
-                    } else if  errorCode == 404 {
-                        method = "POST"
-                        
-                        communication?.storeEnd(toEndMetadata: appDelegate.activeUrl+"/", fileId: fileId, e2eToken: e2eToken, encryptedMetadata: metadata, on: communication, successRequest: { (re, a, b) in
-                            
-                        }, failureRequest: { (re, er, a) in
-                            
-                        })
-                        
-                    } else {
-                        completion(errorCode, errorDescription)
-                    }
-                             
-                    
-                    
-                    NCCommunication.shared.putE2EEMetadata(fileId: fileId, e2eToken: e2eToken!, method: method, metadata: metadata) { (account, metadata, errorCodeSendMetadata, errorDescriptionSendMetadata) in
-                                                
+                    NCCommunication.shared.putE2EEMetadata(fileId: fileId, e2eToken: e2eToken!, metadata: metadata, method: method) { (account, metadata, errorCode, errorDescription) in
                         self.unlock(serverUrl: serverUrl, fileId: fileId) { (errorCode, errorDescription) in }
                         
-                        completion(errorCodeSendMetadata, errorDescriptionSendMetadata)
+                        if errorCode == 0 && metadata != nil {
+                            let result = NCEndToEndMetadata.sharedInstance.decoderMetadata(metadata!, privateKey: CCUtility.getEndToEndPrivateKey(account), serverUrl: serverUrl, account: account, url: self.appDelegate.activeUrl)
+                            print("\(result)")
+                        }
+                        completion(errorCode, errorDescription)
                     }
-                    
                 }
             } else {
                 completion(errorCode, errorDescription)