gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated (ae8f92a -> cad451f)


From: gnunet
Subject: [taler-anastasis] branch master updated (ae8f92a -> cad451f)
Date: Wed, 21 Oct 2020 15:36:42 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from ae8f92a  update .gitignore
     new a2a2379  fix memory leak in stasis, cleanup
     new cf01957  fix warnings
     new 5968c0f  fix memory leaks (db test)
     new cad451f  Merge branch 'master' of ssh://git.taler.net/anastasis into 
master

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/anastasis-httpd_policy.c    |   2 +-
 src/include/anastasis_database_plugin.h |  27 ++---
 src/stasis/anastasis_db_plugin.c        |   4 +-
 src/stasis/plugin_anastasis_postgres.c  |  82 ++++++--------
 src/stasis/test_anastasis_db.c          | 193 +++++++++-----------------------
 5 files changed, 111 insertions(+), 197 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy.c 
b/src/backend/anastasis-httpd_policy.c
index b2bf8a9..4cd0f30 100644
--- a/src/backend/anastasis-httpd_policy.c
+++ b/src/backend/anastasis-httpd_policy.c
@@ -80,9 +80,9 @@ AH_return_policy (struct MHD_Connection *connection,
     }
     qs = db->get_recovery_document (db->cls,
                                     account_pub,
+                                    version,
                                     &account_sig,
                                     &recovery_data_hash,
-                                    version,
                                     &res_recovery_data_size,
                                     &res_recovery_data);
   }
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index f2c3e99..ebaa810 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -200,26 +200,27 @@ struct ANASTASIS_DatabasePlugin
                              uint32_t *version);
 
   /**
-   * Fetch recovery document for user.
-   *
-   * @param cls closure
-   * @param anastasis_pub public key of the user's account
-   * @param account_sig signature
-   * @param recovery_data_hash hash of the current recovery data
-   * @param version[OUT] set to the version number of the policy the user 
requested
-   * @param data_size size of data blob
-   * @param data blob which contains the recovery document
-   * @return transaction status
-   */
+ * Fetch recovery document for user according given version.
+ *
+ * @param cls closure
+ * @param anastasis_pub public key of the user's account
+ * @param version the version number of the policy the user requests
+ * @param account_sig[OUT] signature
+ * @param recovery_data_hash[OUT] hash of the current recovery data
+ * @param data_size[OUT] size of data blob
+ * @param data[OUT] blob which contains the recovery document
+ * @return transaction status
+ */
   enum ANASTASIS_DB_QueryStatus
   (*get_recovery_document)(void *cls,
                            const struct
-                           ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
+                           ANASTASIS_CRYPTO_AccountPublicKeyP *
+                           anastasis_pub,
+                           uint32_t version,
                            struct
                            ANASTASIS_AccountSignatureP *account_sig,
                            struct
                            GNUNET_HashCode *recovery_data_hash,
-                           uint32_t version,
                            size_t *data_size,
                            void **data);
 
diff --git a/src/stasis/anastasis_db_plugin.c b/src/stasis/anastasis_db_plugin.c
index b0ebf02..db46ab8 100644
--- a/src/stasis/anastasis_db_plugin.c
+++ b/src/stasis/anastasis_db_plugin.c
@@ -54,12 +54,13 @@ ANASTASIS_DB_plugin_load (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
                           "libanastasis_plugin_db_%s",
                           plugin_name);
   GNUNET_free (plugin_name);
+  plugin_name = NULL;
   cfg_dup = GNUNET_CONFIGURATION_dup (cfg);
   plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup);
   if (NULL != plugin)
     plugin->library_name = lib_name;
   else
-    GNUNET_free (lib_name);
+    lib_name = NULL;
   GNUNET_CONFIGURATION_destroy (cfg_dup);
   return plugin;
 }
@@ -81,6 +82,7 @@ ANASTASIS_DB_plugin_unload (struct ANASTASIS_DatabasePlugin 
*plugin)
   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
                                                plugin));
   GNUNET_free (lib_name);
+  lib_name = NULL;
 }
 
 
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 70f2e83..8a68c96 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -457,7 +457,6 @@ postgres_store_recovery_document (void *cls,
     rollback (pg);
     return qs;
   case ANASTASIS_DB_STATUS_SOFT_ERROR:
-    // FIXME: or: retry internally?
     rollback (pg);
     return qs;
   case ANASTASIS_DB_STATUS_NO_RESULTS:
@@ -474,12 +473,6 @@ postgres_store_recovery_document (void *cls,
 
   /* First, check if account exists */
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "At %s:%d Public key used to query db is: %s\n",
-                __FILE__,
-                __LINE__,
-                TALER_B2S (anastasis_pub));
-
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
       GNUNET_PQ_query_param_end
@@ -601,6 +594,7 @@ postgres_store_recovery_document (void *cls,
   }
 
   /* check if existing recovery_data conflicts */
+  if (*version > 1)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "At %s:%d Public key used to query db is: %s\n",
@@ -622,31 +616,30 @@ postgres_store_recovery_document (void *cls,
                                                    
"recoverydocument_select_hash",
                                                    params,
                                                    rs);
+    switch (qs)
+    {
+    case GNUNET_DB_STATUS_HARD_ERROR:
+      return ANASTASIS_DB_STATUS_HARD_ERROR;
+    case GNUNET_DB_STATUS_SOFT_ERROR:
+      GNUNET_break (0);
+      return ANASTASIS_DB_STATUS_SOFT_ERROR;
+    case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+      /* original error must have been a hard error, oddly enough */
+      // return ANASTASIS_DB_STATUS_HARD_ERROR;
+      break;
+    case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+      /* handle interesting case below */
+      break;
+    default:
+      GNUNET_break (0);
+      return ANASTASIS_DB_STATUS_HARD_ERROR;
+    }
+    /* had an existing recovery_data, is it identical? */
+    if (0 == GNUNET_memcmp (&dh,
+                            recovery_data_hash))
+      /* previous conflicting recovery_data exists */
+      return ANASTASIS_DB_STATUS_OLD_RECOVERY_UPLOAD_MISSMATCH;
   }
-  switch (qs)
-  {
-  case GNUNET_DB_STATUS_HARD_ERROR:
-    return ANASTASIS_DB_STATUS_HARD_ERROR;
-  case GNUNET_DB_STATUS_SOFT_ERROR:
-    GNUNET_break (0);
-    return ANASTASIS_DB_STATUS_SOFT_ERROR;
-  case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
-    /* original error must have been a hard error, oddly enough */
-    // return ANASTASIS_DB_STATUS_HARD_ERROR;
-    break;
-  case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
-    /* handle interesting case below */
-    break;
-  default:
-    GNUNET_break (0);
-    return ANASTASIS_DB_STATUS_HARD_ERROR;
-  }
-  /* had an existing recovery_data, is it identical? */
-  if (0 == GNUNET_memcmp (&dh,
-                          recovery_data_hash))
-    /* previous conflicting recovery_data exists */
-    return ANASTASIS_DB_STATUS_OLD_RECOVERY_UPLOAD_MISSMATCH;
-
   {
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
@@ -985,6 +978,7 @@ postgres_record_recdoc_payment (void *cls,
   }
 }
 
+
 /**
  * Store payment for challenge.
  *
@@ -1016,9 +1010,6 @@ postgres_record_challenge_payment (void *cls,
   /*dummy funcion to check if truth is available*/
   void *truth;
   size_t truth_size;
-  char *truth_mime;
-  char *method;
-
 
   {
     // because of constraint at truth_id, first we have to verify
@@ -1031,10 +1022,6 @@ postgres_record_challenge_payment (void *cls,
       GNUNET_PQ_result_spec_variable_size ("encrypted_truth",
                                            &truth,
                                            &truth_size),
-      GNUNET_PQ_result_spec_string ("truth_mime",
-                                    &truth_mime),
-      GNUNET_PQ_result_spec_string ("method",
-                                    &method),
       GNUNET_PQ_result_spec_end
     };
     qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
@@ -1045,6 +1032,9 @@ postgres_record_challenge_payment (void *cls,
     {
       return qs;
     }
+    // free truth because not not needed
+    if (NULL != truth)
+      GNUNET_free (truth);
   }
 
   if (GNUNET_OK != begin_transaction (pg,
@@ -1091,6 +1081,8 @@ postgres_record_challenge_payment (void *cls,
 
   return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
 }
+
+
 /**
  * Check payment identifier. Used to check if a payment identifier given by
  * the user is valid (existing and paid).
@@ -1506,15 +1498,15 @@ postgres_get_latest_recovery_document (void *cls,
 
 
 /**
- * Fetch recovery document for user.
+ * Fetch recovery document for user according given version.
  *
  * @param cls closure
  * @param anastasis_pub public key of the user's account
- * @param account_sig signature
- * @param recovery_data_hash hash of the current recovery data
- * @param version[OUT] set to the version number of the policy the user 
requested
- * @param data_size size of data blob
- * @param data blob which contains the recovery document
+ * @param version the version number of the policy the user requests
+ * @param account_sig[OUT] signature
+ * @param recovery_data_hash[OUT] hash of the current recovery data
+ * @param data_size[OUT] size of data blob
+ * @param data[OUT] blob which contains the recovery document
  * @return transaction status
  */
 enum ANASTASIS_DB_QueryStatus
@@ -1522,11 +1514,11 @@ postgres_get_recovery_document (void *cls,
                                 const struct
                                 ANASTASIS_CRYPTO_AccountPublicKeyP *
                                 anastasis_pub,
+                                uint32_t version,
                                 struct
                                 ANASTASIS_AccountSignatureP *account_sig,
                                 struct
                                 GNUNET_HashCode *recovery_data_hash,
-                                uint32_t version,
                                 size_t *data_size,
                                 void **data)
 
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index f283105..0a6df85 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -50,91 +50,6 @@ static int result;
  */
 static struct ANASTASIS_DatabasePlugin *plugin;
 
-/**
- * Payment Secret for the test, set to a random value
- */
-static struct ANASTASIS_PaymentSecretP paymentSecretP;
-
-/**
- * User public key, set to a random value
- */
-static struct ANASTASIS_CRYPTO_AccountPublicKeyP accountPubP;
-
-/**
- * User private key
- */
-static struct ANASTASIS_CRYPTO_AccountPrivateKeyP accountPrivP;
-
-/**
- * Signature
- */
-static struct ANASTASIS_AccountSignatureP accountSig;
-
-/**
- * Signature
- */
-struct ANASTASIS_AccountSignatureP res_account_sig;
-
-/**
- * Hash of the recovery document to be uploaded
- */
-struct GNUNET_HashCode recoveryDataHash;
-
-/**
- * Hash of the current recovery document
- */
-struct GNUNET_HashCode res_recovery_data_hash;
-
-/**
- * How many posts are paid by the payment
- */
-static unsigned int post_counter;
-
-/**
- * Recoverydata which is stored into the Database, set to a random value
- */
-static void *recovery_data;
-
-/**
- * Recovery_data for the select test
- */
-static void *res_recovery_data;
-
-/**
- * Truthdata which is stored into the Database, set to a random value
- */
-static void *truth_data;
-
-/**
- * Keyshare which is stored into the Database, set to a random value
- */
-static void *key_share;
-
-/**
- * Keyshare for the select test
- */
-static void *res_key_share;
-
-/**
- * Mime-type of truth
- */
-static char *mime_type;
-
-/**
- * Method
- */
-static char *method;
-
-/**
- * Version of a Recoverydocument
- */
-static uint32_t docVersion;
-
-/**
- * Version of the latest Recoverydocument
- */
-static uint32_t res_version;
-
 
 /**
  * Main function that will be run by the scheduler.
@@ -166,84 +81,69 @@ run (void *cls)
     return;
   }
 
-  static uint32_t recversion = 1;
+  struct ANASTASIS_PaymentSecretP paymentSecretP;
+  struct ANASTASIS_CRYPTO_AccountPublicKeyP accountPubP;
+  struct ANASTASIS_AccountSignatureP accountSig;
+  struct ANASTASIS_AccountSignatureP res_account_sig;
+  struct GNUNET_HashCode recoveryDataHash;
+  struct GNUNET_HashCode res_recovery_data_hash;
+  struct GNUNET_HashCode r;
+  struct GNUNET_TIME_Relative challenge_expiration;
+  struct GNUNET_TIME_Relative rel_time;
+  struct ANASTASIS_CRYPTO_TruthPublicKeyP truth_public_key;
+  struct ANASTASIS_CRYPTO_NonceP truth_nonce;
+  struct ANASTASIS_CRYPTO_EncryptedKeyShareP key_share;
+  unsigned int post_counter;
+  char *mime_type;
+  char *method;
+  uint32_t docVersion;
+  uint32_t res_version;
   size_t recoverydatasize;
   size_t keysharesize;
-  const char *str = "AHV123456789";
-  struct GNUNET_HashCode r;
+  void *res_recovery_data = NULL;
+  void *res_key_share = NULL;
+  bool paid;
+  bool valid_counter;
+  uint32_t recversion = 1;
+  unsigned char aes_gcm_tag[16];
+  const char *recovery_data = "RECOVERY_DATA";
+  uint64_t challenge_code = 1234;
+
   struct ANASTASIS_UploadSignaturePS usp = {
     .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST),
     .purpose.size = htonl (sizeof (usp))
   };
-  uint64_t challenge_code = 1234;
 
-  struct GNUNET_TIME_Relative challenge_expiration;
   challenge_expiration = GNUNET_TIME_UNIT_HOURS;
-
-  GNUNET_CRYPTO_eddsa_private_key_from_string (str,
-                                               sizeof (str),
-                                               &accountPrivP.priv);
-
-  GNUNET_CRYPTO_eddsa_key_get_public (&accountPrivP.priv,
-                                      &accountPubP.pub);
-
-  int rec_val = 100;
-  recovery_data = &rec_val;
-  RND_BLK (recovery_data);
-
   GNUNET_CRYPTO_hash (recovery_data,
-                      sizeof (recovery_data),
+                      strlen (recovery_data),
                       &recoveryDataHash);
-
-  GNUNET_CRYPTO_eddsa_sign (&accountPrivP.priv,
-                            &usp,
-                            &accountSig.eddsa_sig);
   RND_BLK (&paymentSecretP);
-
-  int truth_val = 300;
-  truth_data = &truth_val;
-  RND_BLK (truth_data);
-
-  int key_val = 300;
-  key_share = &key_val;
-  RND_BLK (key_share);
-
-  unsigned char aes_gcm_tag[16];
   RND_BLK (&aes_gcm_tag);
-
-  bool paid;
-  bool valid_counter;
   post_counter = 2;
   mime_type = "Picture";
   method = "Methode";
   TALER_string_to_amount ("EUR:30",&amount);
 
-  struct ANASTASIS_CRYPTO_TruthPublicKeyP truth_public_key;
-  struct ANASTASIS_CRYPTO_NonceP truth_nonce;
   GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
                               &truth_nonce,
                               sizeof (struct ANASTASIS_CRYPTO_NonceP));
   ANASTASIS_CRYPTO_truth_public_key_derive (&truth_nonce,
                                             &truth_public_key);
-
-  uint32_t nonce;
-  RND_BLK (&nonce);
-
-  struct GNUNET_TIME_Relative rel_time;
   rel_time = GNUNET_TIME_UNIT_MONTHS;
 
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount ("EUR:1",
                                          &amount));
 
-
+  memset (&key_share, 1, sizeof (key_share));
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->store_truth (plugin->cls,
                                &truth_public_key,
-                               "key_share_data",
+                               &key_share,
                                mime_type,
                                "encrypted_truth",
-                               sizeof ("encrypted_truth"),
+                               strlen ("encrypted_truth"),
                                method,
                                rel_time));
 
@@ -253,6 +153,8 @@ run (void *cls)
                                             &paid,
                                             &valid_counter));
 
+  memset (&accountPubP, 2, sizeof (accountPubP));
+  memset (&accountSig, 3, sizeof (accountSig));
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->record_recdoc_payment (plugin->cls,
                                          &accountPubP,
@@ -301,8 +203,8 @@ run (void *cls)
                                            &accountPubP,
                                            &accountSig,
                                            &recoveryDataHash,
-                                           &recovery_data,
-                                           sizeof (&recovery_data),
+                                           recovery_data,
+                                           strlen (recovery_data),
                                            &paymentSecretP,
                                            &docVersion));
 
@@ -316,15 +218,25 @@ run (void *cls)
                                  &truth_public_key,
                                  &res_key_share,
                                  &keysharesize));
+  FAILIF (0 != memcmp (res_key_share,
+                       &key_share,
+                       sizeof (key_share)));
+  GNUNET_free (res_key_share);
+  res_key_share = NULL;
 
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->get_recovery_document (plugin->cls,
                                          &accountPubP,
+                                         recversion,
                                          &res_account_sig,
                                          &res_recovery_data_hash,
-                                         recversion,
                                          &recoverydatasize,
                                          &res_recovery_data));
+  FAILIF (0 != memcmp (res_recovery_data,
+                       recovery_data,
+                       strlen (recovery_data)));
+  GNUNET_free (res_recovery_data);
+  res_recovery_data = NULL;
 
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->get_latest_recovery_document (plugin->cls,
@@ -334,6 +246,11 @@ run (void *cls)
                                                 &recoverydatasize,
                                                 &res_recovery_data,
                                                 &res_version));
+  FAILIF (0 != memcmp (res_recovery_data,
+                       recovery_data,
+                       strlen (recovery_data)));
+  GNUNET_free (res_recovery_data);
+  res_recovery_data = NULL;
 
 
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
@@ -363,15 +280,17 @@ run (void *cls)
                                          &truth_public_key,
                                          challenge_code));
 
-
   if (-1 == result)
     result = 0;
 
 drop:
-/*  GNUNET_break (GNUNET_OK ==
-                plugin->drop_tables (plugin->cls));*/
+  GNUNET_break (GNUNET_OK ==
+                plugin->drop_tables (plugin->cls));
   ANASTASIS_DB_plugin_unload (plugin);
-  plugin = NULL;
+  if (NULL != plugin)
+  {
+    plugin = NULL;
+  }
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]