Browse Source

change to End To End Encryption

Marino Faggiana 7 years ago
parent
commit
9639054901

+ 2 - 2
iOSClient/Database/NCDatabase.swift

@@ -85,8 +85,8 @@ class tableCapabilities: Object {
     @objc dynamic var versionMicro: Int = 0
     @objc dynamic var versionMinor: Int = 0
     @objc dynamic var versionString = ""
-    @objc dynamic var clientSideEncryption: Bool = false
-    @objc dynamic var clientSideEncryptionVersion = ""
+    @objc dynamic var endToEndEncryption: Bool = false
+    @objc dynamic var endToEndEncryptionVersion = ""
 }
 
 class tableCertificates: Object {

+ 3 - 3
iOSClient/Database/NCManageDatabase.swift

@@ -57,7 +57,7 @@ class NCManageDatabase: NSObject {
         let config = Realm.Configuration(
         
             fileURL: dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)"),
-            schemaVersion: 8,
+            schemaVersion: 9,
             
             migrationBlock: { migration, oldSchemaVersion in
                 // We haven’t migrated anything yet, so oldSchemaVersion == 0
@@ -562,8 +562,8 @@ class NCManageDatabase: NSObject {
                 resultCapabilities.versionMinor = capabilities.versionMinor
                 resultCapabilities.versionMicro = capabilities.versionMicro
                 resultCapabilities.versionString = capabilities.versionString
-                resultCapabilities.clientSideEncryption = capabilities.isClientSideEncryptionEnabled
-                resultCapabilities.clientSideEncryptionVersion = capabilities.clientSideEncryptionVersion
+                resultCapabilities.endToEndEncryption = capabilities.isEndToEndEncryptionEnabled
+                resultCapabilities.endToEndEncryptionVersion = capabilities.endToEndEncryptionVersion
             
                 if result == nil {
                     realm.add(resultCapabilities)

+ 3 - 3
iOSClient/Library/OCCommunicationLib/OCCapabilities.h

@@ -65,8 +65,8 @@
 @property (nonatomic, strong) NSString *themingSlogan;
 @property (nonatomic, strong) NSString *themingUrl;
 
-// Client Side Encryption
-@property (nonatomic) BOOL isClientSideEncryptionEnabled;
-@property (nonatomic, strong) NSString *clientSideEncryptionVersion;
+// End to End Encryption
+@property (nonatomic) BOOL isEndToEndEncryptionEnabled;
+@property (nonatomic, strong) NSString *endToEndEncryptionVersion;
 
 @end

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCCapabilities.m

@@ -28,7 +28,7 @@
         self.themingSlogan = @"";
         self.themingUrl = @"";
         
-        self.clientSideEncryptionVersion = @"";
+        self.endToEndEncryptionVersion = @"";
     }
     return self;
 }

+ 29 - 7
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -1429,17 +1429,17 @@
                         capabilities.themingUrl = [theming valueForKey:@"url"];
                 }
                 
-                //CLIENT SIDE ENCRYPTION
+                //END TO END Encryption
                 
-                NSDictionary *clientSideEncryption = [capabilitiesDict valueForKey:@"client-side-encryption"];
+                NSDictionary *endToEndEncryption = [capabilitiesDict valueForKey:@"end-to-end-encryption"];
                 
-                if ([clientSideEncryption count] > 0) {
+                if ([endToEndEncryption count] > 0) {
                     
-                    NSNumber *clientSideEncryptionEnabled = (NSNumber*)[clientSideEncryption valueForKey:@"enabled"];
-                    capabilities.isClientSideEncryptionEnabled = clientSideEncryptionEnabled.boolValue;
+                    NSNumber *endToEndEncryptionEnabled = (NSNumber*)[endToEndEncryption valueForKey:@"enabled"];
+                    capabilities.isEndToEndEncryptionEnabled = endToEndEncryptionEnabled.boolValue;
                     
-                    if ([clientSideEncryption valueForKey:@"api-version"] && ![[clientSideEncryption valueForKey:@"api-version"] isEqual:[NSNull null]])
-                        capabilities.clientSideEncryptionVersion = [clientSideEncryption valueForKey:@"api-version"];
+                    if ([endToEndEncryption valueForKey:@"api-version"] && ![[endToEndEncryption valueForKey:@"api-version"] isEqual:[NSNull null]])
+                        capabilities.endToEndEncryptionVersion = [endToEndEncryption valueForKey:@"api-version"];
                 }
             }
         
@@ -1952,6 +1952,28 @@
     }];
 }
 
+#pragma mark - End-to-End Encryption
+
+- (void) getE2EPrivateKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
+    
+    serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
+    serverPath = [serverPath stringByAppendingString:@"/private-key"];
+    serverPath = [serverPath encodeString:NSUTF8StringEncoding];
+    
+    OCWebDAVClient *request = [OCWebDAVClient new];
+    request = [self getRequestWithCredentials:request];
+    
+    [request getE2EPrivateKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
+        
+        //Return success
+        successRequest(response, request.redirectedServer);
+        
+    } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
+        
+        failureRequest(response, error, request.redirectedServer);
+    }];
+}
+    
 #pragma mark - Clear Cache
 
 - (void)eraseURLCache

+ 2 - 2
iOSClient/Library/OCCommunicationLib/OCFrameworkConstants.h

@@ -68,8 +68,8 @@
 //Url to access to User Profile API
 #define k_url_acces_remote_userprofile_api @"ocs/v2.php/cloud/user"
 
-//Url to access to Client Side Encription API
-#define k_url_client_side_encryption @"ocs/v2.php/apps/client_side_encryption/api/v1"
+//Url to access to End To End Encryption API
+#define k_url_client_side_encryption @"ocs/v2.php/apps/end_to_end_encryption/api/v1"
 
 //Version of the server that have share API
 #define k_version_support_shared [NSArray arrayWithObjects:  @"5", @"0", @"27", nil]

+ 7 - 0
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -596,4 +596,11 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
 
 - (void) getUserProfileServer:(NSString * _Nonnull)serverPath onCommunication:(OCCommunication * _Nonnull)sharedOCComunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id  _Nullable responseObject, NSError * _Nonnull error))failure;
 
+///-----------------------------------
+/// End-to-End Encryption
+///-----------------------------------
+
+- (void) getE2EPrivateKey:(NSString * _Nonnull)serverPath onCommunication:(OCCommunication * _Nonnull)sharedOCComunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id  _Nullable responseObject, NSError * _Nonnull error))failure;
+
+
 @end

+ 17 - 0
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -845,6 +845,23 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [operation resume];
 }
 
+#pragma mark - End-to-End Encryption
+
+- (void) getE2EPrivateKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success
+                      failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure{
+    
+    _requestMethod = @"GET";
+    
+    NSString *jsonQuery = [NSString stringWithFormat:@"?format=json"];
+    serverPath = [serverPath stringByAppendingString:jsonQuery];
+    
+    NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil];
+    
+    OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
+    [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
+    [operation resume];
+}
+
 #pragma mark - Manage Redirections
 
 - (void) setRedirectionBlockOnDatataskWithOCCommunication: (OCCommunication *) sharedOCCommunication andSessionManager:(AFURLSessionManager *) sessionManager{

+ 2 - 0
iOSClient/Main/CCMain.m

@@ -1181,6 +1181,8 @@
     // Read Activity
     metadataNet.action = actionGetActivityServer;
     [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+    
+    // End To End Encryption
 }
 
 #pragma mark -