Jelajahi Sumber

Add test set with know password ...

Matthias Vogelgesang 7 tahun lalu
induk
melakukan
376dbb4b2c

+ 7 - 7
src/iridium-crypto.c

@@ -201,13 +201,13 @@ iridium_crypto_decrypt_item (const gchar *enc_content,
   gchar *content;
 
   enc_auth_key =
-      iridium_crypto_decrypt(enc_item_key, uuid, params->keys.master,
-                             params->keys.auth, sizeof(params->keys.master));
+      iridium_crypto_decrypt (enc_item_key, uuid, params->keys.master,
+                              params->keys.auth, sizeof(params->keys.master));
 
   if (enc_auth_key == NULL) {
-    g_set_error(error, IRIDIUM_CRYPTO_ERROR,
-                IRIDIUM_CRYPTO_ERROR_DECRYPT_ENCRYPTION_KEY,
-                "Could not decrypt encryption key for %s", uuid);
+    g_set_error (error, IRIDIUM_CRYPTO_ERROR,
+                 IRIDIUM_CRYPTO_ERROR_DECRYPT_ENCRYPTION_KEY,
+                 "Could not decrypt encryption key for %s", uuid);
     return NULL;
   }
 
@@ -218,8 +218,8 @@ iridium_crypto_decrypt_item (const gchar *enc_content,
   enc_key_bytes = iridium_crypto_unhexlify (enc_key, enc_key_size);
   auth_key_bytes = iridium_crypto_unhexlify (auth_key, enc_key_size);
 
-  content = iridium_crypto_decrypt(enc_content, uuid, enc_key_bytes,
-                                   auth_key_bytes, enc_key_size / 2);
+  content = iridium_crypto_decrypt (enc_content, uuid, enc_key_bytes,
+                                    auth_key_bytes, enc_key_size / 2);
 
   g_free (enc_key_bytes);
   g_free (auth_key_bytes);

+ 1 - 1
src/iridium-standard-file.c

@@ -374,7 +374,7 @@ iridium_standard_file_get_items (JsonParser *parser,
       continue;
 
     enc_content = json_object_get_string_member (data, "content");
-    content = iridium_crypto_decrypt_item(enc_content, auth_params,
+    content = iridium_crypto_decrypt_item (enc_content, auth_params,
                                           enc_item_key, uuid, &tmp_error);
 
     if (tmp_error) {

+ 100 - 0
test/dumps/003.decrypted.json

@@ -0,0 +1,100 @@
+{
+  "items": [
+    {
+      "uuid": "3f330762-f4e1-4c83-8f34-8bdf760b3f7d",
+      "content_type": "Note",
+      "created_at": "2018-10-18T13:30:33.243Z",
+      "content": {
+        "text": "1. List\n2. element",
+        "title": "First test note",
+        "references": [],
+        "appData": {
+          "org.standardnotes.sn": {
+            "client_updated_at": "2018-10-18T13:32:08.333Z"
+          }
+        }
+      },
+      "updated_at": "2018-10-18T13:32:08.542Z"
+    },
+    {
+      "uuid": "7602e7da-c43e-4973-adc7-6e97717b5ba8",
+      "content_type": "Tag",
+      "created_at": "2018-10-18T13:31:29.025Z",
+      "content": {
+        "title": "tag1",
+        "references": [
+          {
+            "uuid": "3f330762-f4e1-4c83-8f34-8bdf760b3f7d",
+            "content_type": "Note"
+          },
+          {
+            "uuid": "99e5472d-0085-400a-94ec-7b6db760a573",
+            "content_type": "Note"
+          }
+        ],
+        "appData": {
+          "org.standardnotes.sn": {
+            "client_updated_at": "2018-10-18T13:31:45.861Z"
+          }
+        }
+      },
+      "updated_at": "2018-10-18T13:31:46.102Z"
+    },
+    {
+      "uuid": "089bbfa2-f3b7-4e02-a0a0-885bce2b6d19",
+      "content_type": "Tag",
+      "created_at": "2018-10-18T13:31:29.027Z",
+      "content": {
+        "title": "tag2",
+        "references": [
+          {
+            "uuid": "3f330762-f4e1-4c83-8f34-8bdf760b3f7d",
+            "content_type": "Note"
+          }
+        ],
+        "appData": {
+          "org.standardnotes.sn": {
+            "client_updated_at": "2018-10-18T13:31:29.028Z"
+          }
+        }
+      },
+      "updated_at": "2018-10-18T13:31:29.309Z"
+    },
+    {
+      "uuid": "99e5472d-0085-400a-94ec-7b6db760a573",
+      "content_type": "Note",
+      "created_at": "2018-10-18T13:31:32.349Z",
+      "content": {
+        "text": "String *bold*\n\n* List\n* Element",
+        "title": "Second test note",
+        "references": [],
+        "appData": {
+          "org.standardnotes.sn": {
+            "client_updated_at": "2018-10-18T13:32:00.319Z"
+          }
+        }
+      },
+      "updated_at": "2018-10-18T13:32:00.517Z"
+    },
+    {
+      "uuid": "151f7be1-500d-4226-9dc5-b0f207a7a1af",
+      "content_type": "Tag",
+      "created_at": "2018-10-18T13:31:45.855Z",
+      "content": {
+        "title": "tag3",
+        "references": [
+          {
+            "uuid": "99e5472d-0085-400a-94ec-7b6db760a573",
+            "content_type": "Note"
+          }
+        ],
+        "appData": {
+          "org.standardnotes.sn": {
+            "client_updated_at": "2018-10-18T13:31:45.861Z"
+          }
+        }
+      },
+      "updated_at": "2018-10-18T13:31:46.124Z"
+    }
+  ]
+}

File diff ditekan karena terlalu besar
+ 55 - 0
test/dumps/003.encrypted.json


File diff ditekan karena terlalu besar
+ 0 - 28
test/dumps/003.json


+ 32 - 1
test/test-crypto.c

@@ -15,7 +15,7 @@ dump_003_set_up (Dump *dump, gconstpointer user_data)
   GBytes *data;
   GError *error = NULL;
 
-  data = g_resources_lookup_data ("/net/bloerg/Test/dumps/003.json",
+  data = g_resources_lookup_data ("/net/bloerg/Test/dumps/003.encrypted.json",
                                   G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
   g_assert_nonnull (data);
 
@@ -68,6 +68,34 @@ test_decrypt_003_wrong_password (Dump *dump, gconstpointer user_data)
   iridium_crypto_auth_params_free (params);
 }
 
+static void
+test_decrypt_003_correct_password (Dump *dump, gconstpointer user_data)
+{
+  IridiumAuthParams *params;
+  JsonNode *root;
+  JsonNode *nonce_node;
+  GList *items;
+  GError *error = NULL;
+
+  params = iridium_crypto_auth_params_new ();
+  root = json_parser_get_root (dump->parser);
+  g_assert_nonnull (root);
+
+  nonce_node = json_path_query ("$.auth_params.pw_nonce", root, &error);
+  g_assert_nonnull (nonce_node);
+  g_assert_null (error);
+  g_free (params->salt);
+  params->salt = g_strdup(json_node_get_string(
+      json_array_get_element(json_node_get_array(nonce_node), 0)));
+  json_node_unref (nonce_node);
+
+  iridium_crypto_derive_keys (params, "test123");
+  items = iridium_standard_file_get_items (dump->parser, params, &error);
+  g_assert_nonnull (items);
+  g_assert_null (error);
+  iridium_crypto_auth_params_free (params);
+}
+
 int
 main (int argc, char * argv[])
 {
@@ -78,5 +106,8 @@ main (int argc, char * argv[])
   g_test_add ("/crypto/decrypt/003/wrong-password", Dump, NULL,
               dump_003_set_up, test_decrypt_003_wrong_password, dump_003_tear_down);
 
+  g_test_add ("/crypto/decrypt/003/correct-password", Dump, NULL,
+              dump_003_set_up, test_decrypt_003_correct_password, dump_003_tear_down);
+
   return g_test_run ();
 }

+ 2 - 1
test/test.gresource.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/net/bloerg/Test">
-    <file>dumps/003.json</file>
+    <file>dumps/003.encrypted.json</file>
+    <file>dumps/003.decrypted.json</file>
   </gresource>
 </gresources>