Selaa lähdekoodia

Merge remote-tracking branch 'origin/develop' into develop

Marino Faggiana 7 vuotta sitten
vanhempi
commit
87c47b8453
44 muutettua tiedostoa jossa 66 lisäystä ja 67 poistoa
  1. 0 1
      iOSClient/CCGlobal.h
  2. 20 31
      iOSClient/Main/CCMain.m
  3. 20 1
      iOSClient/Networking/CCNetworking.m
  4. 1 0
      iOSClient/Security/NCEndToEndEncryption.h
  5. 14 31
      iOSClient/Security/NCEndToEndEncryption.m
  6. 8 3
      iOSClient/Security/NCEntoToEndInterface.swift
  7. 1 0
      iOSClient/Settings/CCAdvanced.m
  8. 2 0
      iOSClient/Settings/NCManageEndToEndEncryption.m
  9. BIN
      iOSClient/Supporting Files/es_GT.lproj/BKPasscodeView.strings
  10. BIN
      iOSClient/Supporting Files/es_GT.lproj/CTAssetsPicker.strings
  11. BIN
      iOSClient/Supporting Files/es_GT.lproj/Error.strings
  12. BIN
      iOSClient/Supporting Files/es_GT.lproj/InfoPlist.strings
  13. BIN
      iOSClient/Supporting Files/es_GT.lproj/Intro.strings
  14. BIN
      iOSClient/Supporting Files/es_GT.lproj/Localizable.strings
  15. BIN
      iOSClient/Supporting Files/es_GT.lproj/SwiftWebVC.strings
  16. BIN
      iOSClient/Supporting Files/es_HN.lproj/BKPasscodeView.strings
  17. BIN
      iOSClient/Supporting Files/es_HN.lproj/CTAssetsPicker.strings
  18. BIN
      iOSClient/Supporting Files/es_HN.lproj/Error.strings
  19. BIN
      iOSClient/Supporting Files/es_HN.lproj/InfoPlist.strings
  20. BIN
      iOSClient/Supporting Files/es_HN.lproj/Intro.strings
  21. BIN
      iOSClient/Supporting Files/es_HN.lproj/Localizable.strings
  22. BIN
      iOSClient/Supporting Files/es_HN.lproj/SwiftWebVC.strings
  23. BIN
      iOSClient/Supporting Files/es_NI.lproj/BKPasscodeView.strings
  24. BIN
      iOSClient/Supporting Files/es_NI.lproj/CTAssetsPicker.strings
  25. BIN
      iOSClient/Supporting Files/es_NI.lproj/Error.strings
  26. BIN
      iOSClient/Supporting Files/es_NI.lproj/InfoPlist.strings
  27. BIN
      iOSClient/Supporting Files/es_NI.lproj/Intro.strings
  28. BIN
      iOSClient/Supporting Files/es_NI.lproj/Localizable.strings
  29. BIN
      iOSClient/Supporting Files/es_NI.lproj/SwiftWebVC.strings
  30. BIN
      iOSClient/Supporting Files/es_PA.lproj/BKPasscodeView.strings
  31. BIN
      iOSClient/Supporting Files/es_PA.lproj/CTAssetsPicker.strings
  32. BIN
      iOSClient/Supporting Files/es_PA.lproj/Error.strings
  33. BIN
      iOSClient/Supporting Files/es_PA.lproj/InfoPlist.strings
  34. BIN
      iOSClient/Supporting Files/es_PA.lproj/Intro.strings
  35. BIN
      iOSClient/Supporting Files/es_PA.lproj/Localizable.strings
  36. BIN
      iOSClient/Supporting Files/es_PA.lproj/SwiftWebVC.strings
  37. BIN
      iOSClient/Supporting Files/es_SV.lproj/BKPasscodeView.strings
  38. BIN
      iOSClient/Supporting Files/es_SV.lproj/CTAssetsPicker.strings
  39. BIN
      iOSClient/Supporting Files/es_SV.lproj/Error.strings
  40. BIN
      iOSClient/Supporting Files/es_SV.lproj/InfoPlist.strings
  41. BIN
      iOSClient/Supporting Files/es_SV.lproj/Intro.strings
  42. BIN
      iOSClient/Supporting Files/es_SV.lproj/Localizable.strings
  43. BIN
      iOSClient/Supporting Files/es_SV.lproj/SwiftWebVC.strings
  44. BIN
      iOSClient/Supporting Files/nl.lproj/Localizable.strings

+ 0 - 1
iOSClient/CCGlobal.h

@@ -148,7 +148,6 @@ extern NSString *const dav;
 #define selectorGetUserAndGroup                         @"getUserAndGroup"
 #define selectorLoadFileView                            @"loadFileView"
 #define selectorLoadModelView                           @"loadModelView"
-#define selectorLoadPlist                               @"loadPlist"
 #define selectorLoadViewImage                           @"loadViewImage"
 #define selectorLoadCopy                                @"loadCopy"
 #define selectorMove                                    @"move"

+ 20 - 31
iOSClient/Main/CCMain.m

@@ -1139,10 +1139,13 @@
         
             //UIImage *themingBackground = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[capabilities.themingBackground stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]]; DEPRECATED iOS9
             UIImage *themingBackground = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[capabilities.themingBackground stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]]]];
-            if (themingBackground)
-                [UIImagePNGRepresentation(themingBackground) writeToFile:[NSString stringWithFormat:@"%@/themingBackground.png", app.directoryUser] atomically:YES];
-            else
+            if (themingBackground) {
+                 dispatch_async(dispatch_get_main_queue(), ^{
+                     [UIImagePNGRepresentation(themingBackground) writeToFile:[NSString stringWithFormat:@"%@/themingBackground.png", app.directoryUser] atomically:YES];
+                 });
+            } else {
                 [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/themingBackground.png", app.directoryUser] error:nil];
+            }
         }
         
         dispatch_async(dispatch_get_main_queue(), ^{
@@ -1295,11 +1298,17 @@
 
 - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
 {
-    __block tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
-    
+    tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
     if (metadata == nil)
         return;
     
+    tableE2eEncryption *e2eEncryption = [[NCManageDatabase sharedInstance] getE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"fileNameIdentifier = %@ AND serverUrl = %@", metadata.fileName, serverUrl]];
+    if (e2eEncryption) {
+        metadata.encrypted = true;
+        metadata.fileName = e2eEncryption.fileName;
+        [CCUtility insertTypeFileIconName:metadata.fileName metadata:metadata];
+    }
+    
     // Download
     if ([selector isEqualToString:selectorDownloadFile]) {
         [self reloadDatasource:serverUrl];
@@ -1401,30 +1410,6 @@
         [self copyFileToPasteboard:metadata];
     }
     
-    //download file plist
-    if ([selector isEqualToString:selectorLoadPlist]) {
-        
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-        
-            long countSelectorLoadPlist = 0;
-        
-            for (NSOperation *operation in [app.netQueue operations]) {
-            
-                if ([((OCnetworking *)operation).metadataNet.selector isEqualToString:selectorLoadPlist])
-                    countSelectorLoadPlist++;
-            }
-            
-            NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
-            
-            if ((countSelectorLoadPlist == 0 || countSelectorLoadPlist % k_maxConcurrentOperation == 0) && [metadata.directoryID isEqualToString:directoryID] && directoryID) {
-            
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [self reloadDatasource:serverUrl];
-                });
-            }
-        });
-    }
-    
     //selectorLoadViewImage
     if ([selector isEqualToString:selectorLoadViewImage]) {
         
@@ -1895,7 +1880,7 @@
 #pragma mark ===== Search =====
 #pragma --------------------------------------------------------------------------------------------
 
--(void)searchStartTimer
+- (void)searchStartTimer
 {
     NSString *home = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
     
@@ -1907,7 +1892,7 @@
     [self.tableView reloadEmptyDataSet];
 }
 
--(void)updateSearchResultsForSearchController:(UISearchController *)searchController
+- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
 {
     //[self setNeedsStatusBarAppearanceUpdate];
 
@@ -4228,6 +4213,10 @@
     _directoryGroupBy = [CCUtility getGroupBySettings];
     _directoryOrder = [CCUtility getOrderSettings];
     
+    // Remove optimization for encrypted directory
+    if ([CCUtility isFolderEncrypted:self.serverUrl account:app.activeAccount])
+        _dateReadDataSource = nil;
+    
     // Controllo data lettura Data Source
     tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, serverUrl]];
     

+ 20 - 1
iOSClient/Networking/CCNetworking.m

@@ -572,6 +572,7 @@
     NSData *authData = [[NSString stringWithFormat:@"%@:%@", _activeUser, _activePassword] dataUsingEncoding:NSUTF8StringEncoding];
     NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
     [request setValue:authValue forHTTPHeaderField:@"Authorization"];
+    [request setValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
     
     if ([session isEqualToString:k_download_session]) sessionDownload = [self sessionDownload];
     else if ([session isEqualToString:k_download_session_foreground]) sessionDownload = [self sessionDownloadForeground];
@@ -718,6 +719,23 @@
         if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
             [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata directoryUser:_directoryUser activeAccount:_activeAccount];
 
+        // Decrypted
+        tableE2eEncryption *object = [[NCManageDatabase sharedInstance] getE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"fileNameIdentifier = %@ AND serverUrl = %@", fileName, serverUrl]];
+        if (object) {
+            BOOL result = [[NCEndToEndEncryption sharedManager] decryptFileID:fileID directoryUser:_directoryUser key:object.key initializationVector:object.initializationVector authenticationTag:object.authenticationTag];
+            if (!result) {
+                
+                [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:fileID action:k_activityDebugActionUpload selector:@"" note:[NSString stringWithFormat:@"Serious error internal download : decrypt error %@", fileName] type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
+                
+                dispatch_async(dispatch_get_main_queue(), ^{
+                    if ([self.delegate respondsToSelector:@selector(downloadFileFailure:serverUrl:selector:message:errorCode:)])
+                        [self.delegate downloadFileFailure:fileID serverUrl:serverUrl selector:selector message:[NSString stringWithFormat:@"Serious error internal download : decrypt error %@", fileName] errorCode:k_CCErrorInternalError];
+                });
+                
+                return;
+            }
+        }
+        
         // Icon
         [CCGraphics createNewImageFrom:metadata.fileID directoryUser:_directoryUser fileNameTo:metadata.fileID extension:[metadata.fileName pathExtension] size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
                 
@@ -1041,7 +1059,8 @@
     NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
     [request setHTTPMethod:@"PUT"];
     [request setValue:authValue forHTTPHeaderField:@"Authorization"];
-    
+    [request setValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
+
     // Change date file upload with header : X-OC-Mtime (ctime assetLocalIdentifier)
     if (assetLocalIdentifier) {
         PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetLocalIdentifier] options:nil];

+ 1 - 0
iOSClient/Security/NCEndToEndEncryption.h

@@ -39,6 +39,7 @@
 - (NSString *)decryptMetadata:(NSString *)encrypted key:(NSString *)key;
 
 - (BOOL)encryptFileName:(NSString *)fileName fileNameIdentifier:(NSString *)fileNameIdentifier directoryUser:(NSString *)directoryUser key:(NSString **)key initializationVector:(NSString **)initializationVector authenticationTag:(NSString **)authenticationTag;
+- (BOOL)decryptFileID:(NSString *)fileID directoryUser:(NSString *)directoryUser key:(NSString *)key initializationVector:(NSString *)initializationVector authenticationTag:(NSString *)authenticationTag;
 
 - (NSString *)createSHA512:(NSString *)string;
 

+ 14 - 31
iOSClient/Security/NCEndToEndEncryption.m

@@ -493,9 +493,8 @@ cleanup:
 {
     NSMutableData *cipherData;
     NSData *tagData;
-    NSData *plainData;
-    
-    plainData = [[NSFileManager defaultManager] contentsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileName]];
+   
+    NSData *plainData = [[NSFileManager defaultManager] contentsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileName]];
     if (plainData == nil)
         return false;
     
@@ -518,42 +517,26 @@ cleanup:
     return false;
 }
 
-/*
-- (void)decryptMetadata:(NSString *)metadata activeUrl:(NSString *)activeUrl
+- (BOOL)decryptFileID:(NSString *)fileID directoryUser:(NSString *)directoryUser key:(NSString *)key initializationVector:(NSString *)initializationVector authenticationTag:(NSString *)authenticationTag
 {
     NSMutableData *plainData;
-    
-    NSData *cipherData = [[NSFileManager defaultManager] contentsAtPath:[NSString stringWithFormat:@"%@/%@", activeUrl, metadata.fileID]];
-    NSData *keyData = [[NSData alloc] initWithBase64EncodedString:@"WANM0gRv+DhaexIsI0T3Lg==" options:0];
-    NSData *ivData = [[NSData alloc] initWithBase64EncodedString:@"gKm3n+mJzeY26q4OfuZEqg==" options:0];
-    NSData *tagData = [[NSData alloc] initWithBase64EncodedString:@"PboI9tqHHX3QeAA22PIu4w==" options:0];
-    
-    BOOL result = [self decryptData:cipherData plainData:&plainData keyData:keyData keyLen:AES_KEY_128_LENGTH ivData:ivData tagData:tagData];
-    
-    if (plainData != nil && result) {
-        [plainData writeToFile:[NSString stringWithFormat:@"%@/%@", activeUrl, @"decrypted"] atomically:YES];
-    }
-}
 
-- (NSString *)decryptMetadata:(NSString *)cipher key:(NSString *)key iv:(NSString *)iv tag:(NSString *)tag
-{
-    NSMutableData *plainData;
+    NSData *cipherData = [[NSFileManager defaultManager] contentsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]];
+    if (cipherData == nil)
+        return false;
     
-    NSData *cipherData = [cipher dataUsingEncoding:NSUTF8StringEncoding];
-    NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
-    NSData *ivData = [iv dataUsingEncoding:NSUTF8StringEncoding];
-    NSData *tagData = [tag dataUsingEncoding:NSUTF8StringEncoding];
+    NSData *keyData = [[NSData alloc] initWithBase64EncodedString:key options:0];
+    NSData *ivData = [[NSData alloc] initWithBase64EncodedString:initializationVector options:0];
+    NSData *tagData = [[NSData alloc] initWithBase64EncodedString:authenticationTag options:0];
 
-    
     BOOL result = [self decryptData:cipherData plainData:&plainData keyData:keyData keyLen:AES_KEY_128_LENGTH ivData:ivData tagData:tagData];
+    if (plainData != nil && result) {
+        [plainData writeToFile:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID] atomically:YES];
+        return true;
+    }
     
-    if (plainData != nil && result)
-        return [[NSString alloc] initWithData:plainData encoding:NSUTF8StringEncoding];
-    else
-        return nil;
+    return false;
 }
-*/
-
 
 // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------

+ 8 - 3
iOSClient/Security/NCEntoToEndInterface.swift

@@ -318,6 +318,11 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
         
         CCUtility.setEndToEndPublicKeyServer(appDelegate.activeAccount, publicKey: metadataNet.key)
         
+        // Clear Table
+        NCManageDatabase.sharedInstance.clearTable(tableMetadata.self, account: appDelegate.activeAccount)
+        NCManageDatabase.sharedInstance.clearTable(tableDirectory.self, account: appDelegate.activeAccount)
+        NCManageDatabase.sharedInstance.clearTable(tableE2eEncryption.self, account: appDelegate.activeAccount)
+
         // All OK Activated flsg on Manage EndToEnd Encryption
         NotificationCenter.default.post(name: Notification.Name("reloadManageEndToEndEncryption"), object: nil)
     }
@@ -416,13 +421,13 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
         
         guard let privateKey = CCUtility.getEndToEndPrivateKey(appDelegate.activeAccount) else {
             
-            appDelegate.messageNotification("E2E Get Metadata Success", description: "Serious internal error: PrivareKey not found", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
+            appDelegate.messageNotification("E2E Get Metadata", description: "Serious internal error: PrivareKey not found", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             return
         }
 
         guard let main = appDelegate.listMainVC[metadataNet.serverUrl] as? CCMain else {
             
-            appDelegate.messageNotification("E2E Get Metadata Success", description: "Serious internal error: Main not found", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
+            appDelegate.messageNotification("E2E Get Metadata", description: "Serious internal error: Main not found", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             return
         }
         
@@ -433,7 +438,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
         }
 
         // Reload data source
-        main.reloadDatasource(metadataNet.serverUrl)
+        main.reloadDatasource(serverUrl)
     }
     
     func getEndToEndMetadataFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {

+ 1 - 0
iOSClient/Settings/CCAdvanced.m

@@ -330,6 +330,7 @@
         [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:app.activeAccount];
         [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:app.activeAccount];
         [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:app.activeAccount];
+        [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:app.activeAccount];
         [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:app.activeAccount];
         [[NCManageDatabase sharedInstance] clearTable:[tableGPS class] account:nil];
         [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:app.activeAccount];

+ 2 - 0
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -143,6 +143,7 @@
         [section addFormRow:row];   
     }
     
+/*
 #ifdef DEBUG
     // Section DELETE KEYS -------------------------------------------------
     
@@ -166,6 +167,7 @@
     [section addFormRow:row];
     
 #endif
+*/
     
     self.form = form;
 }

BIN
iOSClient/Supporting Files/es_GT.lproj/BKPasscodeView.strings


BIN
iOSClient/Supporting Files/es_GT.lproj/CTAssetsPicker.strings


BIN
iOSClient/Supporting Files/es_GT.lproj/Error.strings


BIN
iOSClient/Supporting Files/es_GT.lproj/InfoPlist.strings


BIN
iOSClient/Supporting Files/es_GT.lproj/Intro.strings


BIN
iOSClient/Supporting Files/es_GT.lproj/Localizable.strings


BIN
iOSClient/Supporting Files/es_GT.lproj/SwiftWebVC.strings


BIN
iOSClient/Supporting Files/es_HN.lproj/BKPasscodeView.strings


BIN
iOSClient/Supporting Files/es_HN.lproj/CTAssetsPicker.strings


BIN
iOSClient/Supporting Files/es_HN.lproj/Error.strings


BIN
iOSClient/Supporting Files/es_HN.lproj/InfoPlist.strings


BIN
iOSClient/Supporting Files/es_HN.lproj/Intro.strings


BIN
iOSClient/Supporting Files/es_HN.lproj/Localizable.strings


BIN
iOSClient/Supporting Files/es_HN.lproj/SwiftWebVC.strings


BIN
iOSClient/Supporting Files/es_NI.lproj/BKPasscodeView.strings


BIN
iOSClient/Supporting Files/es_NI.lproj/CTAssetsPicker.strings


BIN
iOSClient/Supporting Files/es_NI.lproj/Error.strings


BIN
iOSClient/Supporting Files/es_NI.lproj/InfoPlist.strings


BIN
iOSClient/Supporting Files/es_NI.lproj/Intro.strings


BIN
iOSClient/Supporting Files/es_NI.lproj/Localizable.strings


BIN
iOSClient/Supporting Files/es_NI.lproj/SwiftWebVC.strings


BIN
iOSClient/Supporting Files/es_PA.lproj/BKPasscodeView.strings


BIN
iOSClient/Supporting Files/es_PA.lproj/CTAssetsPicker.strings


BIN
iOSClient/Supporting Files/es_PA.lproj/Error.strings


BIN
iOSClient/Supporting Files/es_PA.lproj/InfoPlist.strings


BIN
iOSClient/Supporting Files/es_PA.lproj/Intro.strings


BIN
iOSClient/Supporting Files/es_PA.lproj/Localizable.strings


BIN
iOSClient/Supporting Files/es_PA.lproj/SwiftWebVC.strings


BIN
iOSClient/Supporting Files/es_SV.lproj/BKPasscodeView.strings


BIN
iOSClient/Supporting Files/es_SV.lproj/CTAssetsPicker.strings


BIN
iOSClient/Supporting Files/es_SV.lproj/Error.strings


BIN
iOSClient/Supporting Files/es_SV.lproj/InfoPlist.strings


BIN
iOSClient/Supporting Files/es_SV.lproj/Intro.strings


BIN
iOSClient/Supporting Files/es_SV.lproj/Localizable.strings


BIN
iOSClient/Supporting Files/es_SV.lproj/SwiftWebVC.strings


BIN
iOSClient/Supporting Files/nl.lproj/Localizable.strings