marinofaggiana 4 years ago
parent
commit
c663a42c94

+ 0 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -151,7 +151,6 @@
 		F73D5E48246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
 		F73D5E49246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
 		F73D5E4A246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
-		F73DF57B247D140600E8659E /* NCNetworkingE2EE.swift in Sources */ = {isa = PBXBuildFile; fileRef = F785EE9C246196DF00B3F945 /* NCNetworkingE2EE.swift */; };
 		F73F537F1E929C8500F8678D /* CCMore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73F537E1E929C8500F8678D /* CCMore.swift */; };
 		F7417DB3216CE925007D05F5 /* NCTrashSectionHeaderFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7417DB2216CE925007D05F5 /* NCTrashSectionHeaderFooter.swift */; };
 		F7421EAF2294044B00C4B7C1 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7421EAE2294044B00C4B7C1 /* Accelerate.framework */; };
@@ -2179,7 +2178,6 @@
 				F7145A041D12E3B700CAFEEC /* CCloadItemData.swift in Sources */,
 				F711CCC3246AC99E0009B204 /* OCExternalSites.m in Sources */,
 				F711CCCB246AC99E0009B204 /* NCXMLGetAppPasswordParser.m in Sources */,
-				F73DF57B247D140600E8659E /* NCNetworkingE2EE.swift in Sources */,
 				F711CCB1246AC99E0009B204 /* NCRichDocumentTemplate.m in Sources */,
 				F711CCBB246AC99E0009B204 /* OCShareUser.m in Sources */,
 				F76B3CCF1EAE01BD00921AC9 /* NCBrand.swift in Sources */,

+ 12 - 7
iOSClient/Networking/CCNetworking.m

@@ -782,10 +782,12 @@
             [request setValue:[NSString stringWithFormat:@"%ld", dateFileCreation] forHTTPHeaderField:@"X-OC-Mtime"];
         }
     }
-    
+     
     // E2EE : CREATE AND SEND METADATA
     if ([CCUtility isFolderEncrypted:metadata.serverUrl e2eEncrypted:metadata.e2eEncrypted account:tableAccount.account] && [CCUtility isEndToEndEnabled:tableAccount.account]) {
-            
+         
+#ifndef EXTENSION
+        
         [[NCNetworkingE2EE shared] sendE2EMetadataWithAccount:tableAccount.account serverUrl:serverUrl fileNameRename:nil fileNameNewRename:nil deleteE2eEncryption:nil url:tableAccount.url upload:true completion:^(NSString *e2eToken, NSInteger errorCode, NSString *errorDescription) {
             
             if (errorCode == 0) {
@@ -817,7 +819,8 @@
                 [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"metadata": metadata, @"errorCode": @(errorCode), @"errorDescription": errorDescription}];
             }
         }];
-            
+#endif
+        
      } else {
     
          // NSURLSession
@@ -1032,15 +1035,17 @@
             (void)[[NCManageDatabase sharedInstance] addLocalFileWithMetadata:metadata];
         }
     }
-    
-    // Detect E2EE
+        
+#ifndef EXTENSION
+
+    // E2EE : UNLOCK
     tableMetadata *e2eeMetadataInSession = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND e2eEncrypted == 1 AND (status == %d OR status == %d)", metadata.account, metadata.serverUrl, k_metadataStatusInUpload, k_metadataStatusUploading]];
     
-    // E2EE : UNLOCK
     if (isE2EEDirectory && e2eeMetadataInSession == nil) {
         [[NCNetworkingE2EE shared] unlockWithAccount:tableAccount.account serverUrl:serverUrl completion:^(tableDirectory *directory, NSString *e2eToken, NSInteger errorCode, NSString *errorDescription) { }];
     }
-        
+#endif
+    
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"metadata": metadata, @"errorCode": @(errorCode), @"errorDescription": errorMessage}];
 }
 

+ 14 - 4
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, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
@@ -235,6 +237,7 @@ import NCCommunication
         var e2eMetadataKey = ""
         var e2eMetadataKeyIndex = 0
         let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadataForUpload.ocId, fileNameView: metadataForUpload.fileNameView)!
+        let serverUrlFileName = metadataForUpload.serverUrl + "/" + metadataForUpload.fileName
         
         NCEndToEndEncryption.sharedManager()?.encryptFileName(metadataForUpload.fileNameView, fileNameIdentifier: metadataForUpload.fileName, directory: CCUtility.getDirectoryProviderStorageOcId(metadataForUpload.ocId), key: &key, initializationVector: &initializationVector, authenticationTag: &authenticationTag)
         
@@ -266,11 +269,18 @@ import NCCommunication
             return
         }
         
-        let serverUrlFileName = metadataForUpload.serverUrl + "/" + metadataForUpload.fileName
-        
-        _ = NCCommunication.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: metadataForUpload.date as Date, dateModificationFile: metadataForUpload.date as Date, progressHandler: { (progress) in
+        //
+        NCNetworkingE2EE.shared.sendE2EMetadata(account: metadataForUpload.account, serverUrl: metadataForUpload.serverUrl, fileNameRename: nil, fileNameNewRename: nil, deleteE2eEncryption: nil, url: appDelegate.activeUrl) { (e2eToken, errorCode, errorDescription) in
             
-        }) { (account, ocId, etag, date, size, errorCode, errorDescription) in
+            if errorCode == 0 && e2eToken != nil {
+                
+                _ = NCCommunication.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: metadataForUpload.date as Date, dateModificationFile: metadataForUpload.date as Date, addCustomHeaders: ["e2e-token":e2eToken!], progressHandler: { (progress) in
+                           
+                    }) { (account, ocId, etag, date, size, errorCode, errorDescription) in
+                           
+                        NCNetworkingE2EE.shared.unlock(account: metadataForUpload.account, serverUrl: metadataForUpload.session) { (_, _, _, _) in }
+                    }
+            }
             
         }
     }