Explorar el Código

fix test

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky hace 2 años
padre
commit
d9c71edba0

+ 1 - 1
app/src/androidTest/java/com/owncloud/android/util/EncryptionTestIT.java

@@ -533,7 +533,7 @@ public class EncryptionTestIT extends AbstractIT {
             arbitraryDataProvider,
             arbitraryDataProvider,
             user,
             user,
             folderID);
             folderID);
-        EncryptionUtils.encryptFileDropFiles(decryptedFolderMetadata1, encryptedFolderMetadata1);
+        EncryptionUtils.encryptFileDropFiles(decryptedFolderMetadata1, encryptedFolderMetadata1, cert);
 
 
         // serialize
         // serialize
         String encryptedJson = serializeJSON(encryptedFolderMetadata1);
         String encryptedJson = serializeJSON(encryptedFolderMetadata1);

+ 30 - 5
app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java

@@ -220,22 +220,47 @@ public final class EncryptionUtils {
         return encryptedFolderMetadata;
         return encryptedFolderMetadata;
     }
     }
 
 
+    /**
+     * normally done on server only internal test
+     */
     @VisibleForTesting
     @VisibleForTesting
     public static void encryptFileDropFiles(DecryptedFolderMetadata decryptedFolderMetadata,
     public static void encryptFileDropFiles(DecryptedFolderMetadata decryptedFolderMetadata,
-                                            EncryptedFolderMetadata encryptedFolderMetadata) {
+                                            EncryptedFolderMetadata encryptedFolderMetadata,
+                                            String cert) throws NoSuchPaddingException, IllegalBlockSizeException, CertificateException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, InvalidAlgorithmParameterException {
         final Map<String, EncryptedFiledrop> filesdrop = encryptedFolderMetadata.getFiledrop();
         final Map<String, EncryptedFiledrop> filesdrop = encryptedFolderMetadata.getFiledrop();
         for (Map.Entry<String, DecryptedFolderMetadata.DecryptedFile> entry : decryptedFolderMetadata
         for (Map.Entry<String, DecryptedFolderMetadata.DecryptedFile> entry : decryptedFolderMetadata
             .getFiledrop().entrySet()) {
             .getFiledrop().entrySet()) {
             String key = entry.getKey();
             String key = entry.getKey();
             DecryptedFolderMetadata.DecryptedFile decryptedFile = entry.getValue();
             DecryptedFolderMetadata.DecryptedFile decryptedFile = entry.getValue();
 
 
+            byte[] byt = generateKey();
+            String metadataKey0 = encodeBytesToBase64String(byt);
+            String enc = encryptStringAsymmetric(metadataKey0, cert);
+
             String dataJson = EncryptionUtils.serializeJSON(decryptedFile.getEncrypted());
             String dataJson = EncryptionUtils.serializeJSON(decryptedFile.getEncrypted());
-            EncryptedFiledrop encryptedFile = new EncryptedFiledrop(dataJson,
+
+            String encJson = encryptStringSymmetric(dataJson, byt);
+
+            int delimiterPosition = encJson.lastIndexOf(ivDelimiter);
+            String encryptedInitializationVector = encJson.substring(delimiterPosition + ivDelimiter.length());
+            String encodedCryptedBytes = encJson.substring(0, delimiterPosition);
+
+
+            byte[] bytes = decodeStringToBase64Bytes(encodedCryptedBytes);
+
+            // check authentication tag
+            byte[] extractedAuthenticationTag = Arrays.copyOfRange(bytes,
+                                                                   bytes.length - (128 / 8),
+                                                                   bytes.length);
+
+            String encryptedTag = encodeBytesToBase64String(extractedAuthenticationTag);
+
+            EncryptedFiledrop encryptedFile = new EncryptedFiledrop(encodedCryptedBytes,
                                                                     decryptedFile.getInitializationVector(),
                                                                     decryptedFile.getInitializationVector(),
                                                                     decryptedFile.getAuthenticationTag(),
                                                                     decryptedFile.getAuthenticationTag(),
-                                                                    "123",
-                                                                    "123",
-                                                                    "123");
+                                                                    enc,
+                                                                    encryptedTag,
+                                                                    encryptedInitializationVector);
 
 
             filesdrop.put(key, encryptedFile);
             filesdrop.put(key, encryptedFile);
         }
         }