Marino Faggiana 7 years ago
parent
commit
d209ebac8d
2 changed files with 10 additions and 13 deletions
  1. 10 11
      iOSClient/Security/NCEndToEndEncryption.m
  2. 0 2
      iOSClient/Settings/CCSettings.m

+ 10 - 11
iOSClient/Security/NCEndToEndEncryption.m

@@ -390,17 +390,19 @@ cleanup:
     
     CCKeyDerivationPBKDF(kCCPBKDF2, passphrase.UTF8String, passphrase.length, saltData.bytes, saltData.length, kCCPRFHmacAlgSHA1, PBKDF2_INTERACTION_COUNT, keyData.mutableBytes, keyData.length);
     
-    // Split
+    // Find range for IV_DELIMITER_ENCODED
     NSRange range = [privateKeyCipher rangeOfString:IV_DELIMITER_ENCODED];
-    NSInteger idx = range.location + range.length;
+   
+    // Init Vector
+    NSString *initVectorBase64 = [privateKeyCipher substringFromIndex:(range.location + range.length)];
+    NSData *initVectorData = [[NSData alloc] initWithBase64EncodedString:initVectorBase64 options:0];
+    
+    // TAG
+    NSString *tag = [privateKeyCipher substringWithRange:NSMakeRange(range.location - AES_GCM_TAG_LENGTH, AES_GCM_TAG_LENGTH)];
     
     // PrivateKey
-    NSString *privateKeyCipherBase64 = [privateKeyCipher substringToIndex:range.location];
+    NSString *privateKeyCipherBase64 = [privateKeyCipher substringToIndex:(range.location - AES_GCM_TAG_LENGTH)];
     NSData *privateKeyCipherData = [[NSData alloc] initWithBase64EncodedString:privateKeyCipherBase64 options:0];
-
-    // Init Vector
-    NSString *initVectorBase64 = [privateKeyCipher substringFromIndex:idx];
-    NSData *initVectorData = [[NSData alloc] initWithBase64EncodedString:initVectorBase64 options:0];
     
     //TEST
     keyData = [[NSData alloc] initWithBase64EncodedString:@"djv1aVEVz6GROxRjme7Sx8jRJ6qpobRi8auVZnPfuN0=" options:0];
@@ -411,10 +413,7 @@ cleanup:
     
     if (result && privateKeyData) {
         
-        NSString *privateKey;
-        
-        privateKey = [privateKeyData base64EncodedStringWithOptions:0];
-        //privateKey = [[NSString alloc] initWithData:privateKeyData encoding:NSUTF8StringEncoding];
+        NSString *privateKey = [privateKeyData base64EncodedStringWithOptions:0];
         
         NSData *encryptData = [self encryptAsymmetricString:ASYMMETRIC_STRING_TEST publicKey:publicKey];
         if (!encryptData)

+ 0 - 2
iOSClient/Settings/CCSettings.m

@@ -108,7 +108,6 @@
     [section addFormRow:row];
     
 #ifdef DEBUG
-    /*
     // Section : E2EEncryption --------------------------------------------------------------
 
     section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
@@ -121,7 +120,6 @@
     [row.cellConfig setObject:[UIImage imageNamed:@"settingsE2EEncryption"] forKey:@"imageView.image"];
     row.action.viewControllerClass = [NCManageEndToEndEncryption class];
     [section addFormRow:row];
-    */
 #endif
     
     // Section Advanced -------------------------------------------------