gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: [testing] small changes


From: gnunet
Subject: [taler-donau] branch master updated: [testing] small changes
Date: Wed, 15 May 2024 00:03:39 +0200

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

lukas-matyja pushed a commit to branch master
in repository donau.

The following commit(s) were added to refs/heads/master by this push:
     new 741441e  [testing] small changes
741441e is described below

commit 741441eed9c4ef63ab9e5f6f121c127d491c3319
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
AuthorDate: Wed May 15 00:04:47 2024 +0200

    [testing] small changes
---
 src/donau/donau-httpd_csr.c                  |   2 +-
 src/include/donau_crypto_lib.h               |  13 ++
 src/include/donau_testing_lib.h              |   6 +-
 src/lib/donau_api_csr_post.c                 |  78 +++++-----
 src/testing/test_donau_api.c                 |   2 +-
 src/testing/testing_api_cmd_issue_receipts.c | 212 ++++++++++++++-------------
 src/util/donau_crypto.c                      |  13 ++
 7 files changed, 181 insertions(+), 145 deletions(-)

diff --git a/src/donau/donau-httpd_csr.c b/src/donau/donau-httpd_csr.c
index 62a0218..31311ba 100644
--- a/src/donau/donau-httpd_csr.c
+++ b/src/donau/donau-httpd_csr.c
@@ -115,7 +115,7 @@ DH_handler_csr_issue (struct DH_RequestContext *rc,
 
     return TALER_MHD_REPLY_JSON_PACK (
       rc->connection,
-      MHD_HTTP_OK,
+      MHD_HTTP_CREATED,
       TALER_JSON_pack_exchange_withdraw_values ("ewv",
                                                 &exw));
   }
diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h
index bc3049d..057c78a 100644
--- a/src/include/donau_crypto_lib.h
+++ b/src/include/donau_crypto_lib.h
@@ -653,6 +653,19 @@ const struct DONAU_BatchIssueValues *
 DONAU_donation_unit_ewv_rsa_singleton (void);
 
 
+/**
+ * Make a (deep) copy of the given @a bi_src to
+ * @a bi_dst.
+ *
+ * @param[out] bi_dst target to copy to
+ * @param bi_src blinding input values to copy
+ */
+void
+DONAU_donation_unit_ewv_copy (
+  struct DONAU_BatchIssueValues *bi_dst,
+  const struct DONAU_BatchIssueValues *bi_src);
+
+
 /**
  * Blind udi for blind signing with @a du_pub using blinding secret @a 
budi_secret.
  *
diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h
index 5476222..a23a6db 100644
--- a/src/include/donau_testing_lib.h
+++ b/src/include/donau_testing_lib.h
@@ -145,9 +145,9 @@ TALER_TESTING_cmd_issue_receipts (const char *label,
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_submit_receipts (const char *label,
-                                  const char *issue_receipt_reference,
-                                  const uint64_t year,
-                                  unsigned int expected_response_code);
+                                   const char *issue_receipt_reference,
+                                   const uint64_t year,
+                                   unsigned int expected_response_code);
 
 
 /**
diff --git a/src/lib/donau_api_csr_post.c b/src/lib/donau_api_csr_post.c
index dcfaedc..f0504c3 100644
--- a/src/lib/donau_api_csr_post.c
+++ b/src/lib/donau_api_csr_post.c
@@ -77,8 +77,8 @@ struct DONAU_CsRBatchIssueHandle
  */
 static void
 handle_csr_issue_post_finished (void *cls,
-                             long response_code,
-                             const void *resp_obj)
+                                long response_code,
+                                const void *resp_obj)
 {
   struct DONAU_CsRBatchIssueHandle *csrh = cls;
   const json_t *j = resp_obj;
@@ -92,35 +92,39 @@ handle_csr_issue_post_finished (void *cls,
   switch (response_code)
   {
   case MHD_HTTP_CREATED:
-         struct GNUNET_JSON_Specification spec[] = {
-           TALER_JSON_spec_exchange_withdraw_values ( // TODO: method for 
GNUNET
-             "ewv",
-                 (struct TALER_ExchangeWithdrawValues *) 
&csrresp.details.ok.alg_values),
-           GNUNET_JSON_spec_end ()
-         };
-         if (GNUNET_OK !=
-             GNUNET_JSON_parse (j,
-                                spec,
-                                NULL,
-                                NULL))
-         {
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                       "Could not parse response from csr 
POST\n");
-           GNUNET_break_op (0);
-         }
-         csrh->cb (csrh->cb_cls,
-                   &csrresp);
+    struct GNUNET_JSON_Specification spec[] = {
+      TALER_JSON_spec_exchange_withdraw_values ( // TODO: method for GNUNET
+        "ewv",
+        (struct TALER_ExchangeWithdrawValues *) 
&csrresp.details.ok.alg_values),
+      GNUNET_JSON_spec_end ()
+    };
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (j,
+                           spec,
+                           NULL,
+                           NULL))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Could not parse response from csr POST\n");
+      GNUNET_break_op (0);
+    }
+    csrh->cb (csrh->cb_cls,
+              &csrresp);
     break;
-    // Donation unit was revoked.
+  // Donation unit was revoked.
   case MHD_HTTP_GONE:
     csrresp.hr.ec = TALER_JSON_get_error_code (j);
     csrresp.hr.hint = TALER_JSON_get_error_hint (j);
     break;
-    // Donation unit or endpoint not found.
+  // Donation unit or endpoint not found.
   case MHD_HTTP_NOT_FOUND:
     csrresp.hr.ec = TALER_JSON_get_error_code (j);
     csrresp.hr.hint = TALER_JSON_get_error_hint (j);
     break;
+  case MHD_HTTP_BAD_REQUEST:
+       csrresp.hr.ec = TALER_JSON_get_error_code (j);
+       csrresp.hr.hint = TALER_JSON_get_error_hint (j);
+       break;
   default:
     /* unexpected response code */
     GNUNET_break_op (0);
@@ -136,7 +140,7 @@ handle_csr_issue_post_finished (void *cls,
   if (NULL != csrh->cb)
   {
     csrh->cb (csrh->cb_cls,
-             &csrresp);
+              &csrresp);
     csrh->cb = NULL;
   }
   DONAU_csr_cancel (csrh);
@@ -168,12 +172,12 @@ DONAU_csr_issue (
   csrh->cb_cls = cb_cls;
   csrh->ctx = ctx;
   csrh->url = TALER_url_join (url,
-                                                        "charities",
-                             NULL);
+                              "csr-issue",
+                              NULL);
   if (NULL == csrh->url)
   {
-       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                               "Could not construct requested URL.\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Could not construct requested URL.\n");
     GNUNET_free (csrh);
     return NULL;
   }
@@ -181,12 +185,12 @@ DONAU_csr_issue (
               "Request CS R with URL `%s'.\n",
               csrh->url);
   body = GNUNET_JSON_PACK (
-             GNUNET_JSON_pack_data_varsize ("nonce",
-                                            nonce,
-                                            sizeof(*nonce)),
-             GNUNET_JSON_pack_data_varsize ("donation_unit_pub_hash",
-                                            &h_donation_unit_pub,
-                                            sizeof(h_donation_unit_pub)));
+    GNUNET_JSON_pack_data_varsize ("nonce",
+                                   nonce,
+                                   sizeof(*nonce)),
+    GNUNET_JSON_pack_data_varsize ("du_pub_hash",
+                                   &h_donation_unit_pub,
+                                   sizeof(h_donation_unit_pub)));
   eh = DONAU_curl_easy_get_ (csrh->url);
   if ( (NULL == eh) ||
        (GNUNET_OK !=
@@ -203,10 +207,10 @@ DONAU_csr_issue (
   }
   json_decref (body);
   csrh->job = GNUNET_CURL_job_add2 (ctx,
-                                  eh,
-                                                                 
csrh->post_ctx.headers,
-                                  &handle_csr_issue_post_finished,
-                                  csrh);
+                                    eh,
+                                    csrh->post_ctx.headers,
+                                    &handle_csr_issue_post_finished,
+                                    csrh);
   return csrh;
 }
 
diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c
index 1a71053..e8caebc 100644
--- a/src/testing/test_donau_api.c
+++ b/src/testing/test_donau_api.c
@@ -90,7 +90,7 @@ run (void *cls,
       // FIXME
       TALER_TESTING_cmd_issue_receipts ("issue-receipts",
                                         "post-charity",
-                                                                               
uses_cs,
+                                        uses_cs,
                                         2024,
                                         "7560001010000", // tax id
                                         "1234", // salt for tax id hash
diff --git a/src/testing/testing_api_cmd_issue_receipts.c 
b/src/testing/testing_api_cmd_issue_receipts.c
index 4a4a988..f3a7fda 100644
--- a/src/testing/testing_api_cmd_issue_receipts.c
+++ b/src/testing/testing_api_cmd_issue_receipts.c
@@ -121,25 +121,25 @@ struct StatusState
 
 struct CSR_Data
 {
-    /**
-     * Handle to the "batch issue receipt status" operation.
-     */
-       struct DONAU_CsRBatchIssueHandle *csr_handle;
-
-       /**
-        * CS-Nonce
-        */
-       union GNUNET_CRYPTO_BlindSessionNonce nonce;
-
-       /**
-        * batch issue receipt status state
-        */
-       struct StatusState *ss;
-
-       /**
-        * array position in batch issue receipt request (first position is 
zero)
-        */
-       size_t position;
+  /**
+   * Handle to the "batch issue receipt status" operation.
+   */
+  struct DONAU_CsRBatchIssueHandle *csr_handle;
+
+  /**
+   * CS-Nonce
+   */
+  union GNUNET_CRYPTO_BlindSessionNonce nonce;
+
+  /**
+   * batch issue receipt status state
+   */
+  struct StatusState *ss;
+
+  /**
+   * array position in batch issue receipt request (first position is zero)
+   */
+  size_t position;
 };
 
 
@@ -201,15 +201,15 @@ phase_two (void *cls)
   struct StatusState *ss = cls;
   const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps = ss->bkps;
   ss->birh = DONAU_charity_issue_receipt (
-       TALER_TESTING_interpreter_get_context (ss->is),
-       TALER_TESTING_get_donau_url (ss->is),
-       &ss->charity_priv,
-       ss->charity_id,
-       ss->year,
-       ss->num_bkp,
-       bkps,
-       &issue_receipts_status_cb,
-       ss);
+    TALER_TESTING_interpreter_get_context (ss->is),
+    TALER_TESTING_get_donau_url (ss->is),
+    &ss->charity_priv,
+    ss->charity_id,
+    ss->year,
+    ss->num_bkp,
+    bkps,
+    &issue_receipts_status_cb,
+    ss);
 }
 
 
@@ -230,7 +230,7 @@ cs_stage_two_callback (
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unexpected HTTP response code: %d in %s:%u\n",
-                               csrresp->hr.http_status,
+                csrresp->hr.http_status,
                 __FILE__,
                 __LINE__);
     json_dumpf (csrresp->hr.reply,
@@ -240,41 +240,47 @@ cs_stage_two_callback (
     return;
   }
 
-  struct DONAU_DonationUnitPublicKey *cs_pk = 
&csr_data->ss->keys->donation_unit_keys[csr_data->position].key;
-  const struct DONAU_BatchIssueValues *alg_values = 
csr_data->ss->alg_values[csr_data->position];
+  struct DONAU_DonationUnitPublicKey *cs_pk =
+    &csr_data->ss->keys->donation_unit_keys[csr_data->position].key;
+  struct DONAU_BatchIssueValues *alg_values = {0};
   struct DONAU_BudiMasterSecretP ps;
-  struct DONAU_BlindedUniqueDonorIdentifier *blinded_udi = 
&csr_data->ss->bkps[csr_data->position].blinded_udi;
+  struct DONAU_BlindedUniqueDonorIdentifier *blinded_udi =
+    &csr_data->ss->bkps[csr_data->position].blinded_udi;
   struct DONAU_UniqueDonorIdentifierHashP *udi_hash = csr_data->ss->h_udis;
-  union GNUNET_CRYPTO_BlindingSecretP *blinding_secret = 
&csr_data->ss->blinding_secrets[csr_data->position];
-  struct DONAU_UniqueDonorIdentifierNonce *udi_nonce = 
&csr_data->ss->receipts[csr_data->position].nonce;
+  union GNUNET_CRYPTO_BlindingSecretP *blinding_secret =
+    &csr_data->ss->blinding_secrets[csr_data->position];
+  struct DONAU_UniqueDonorIdentifierNonce *udi_nonce =
+    &csr_data->ss->receipts[csr_data->position].nonce;
 
   GNUNET_assert (GNUNET_CRYPTO_BSA_CS == cs_pk->bsign_pub_key->cipher);
-  GNUNET_assert (NULL == alg_values);
-    // TODO: write GNUNET method
-    TALER_denom_ewv_copy ((struct TALER_ExchangeWithdrawValues *) alg_values,
-                                         (struct TALER_ExchangeWithdrawValues 
*) &csrresp->details.ok.alg_values);
-    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
-                                &ps,
-                                sizeof (ps));
-    DONAU_budi_secret_create (&ps,
-                                                       alg_values,
-                                                               
blinding_secret);
-    GNUNET_assert (GNUNET_OK ==
-                   DONAU_donation_unit_blind (
-                     cs_pk,
-                                        blinding_secret,
-                                        &csr_data->nonce,                  /* 
nonce only needed for cs */
-                     udi_nonce,
-                     csr_data->ss->h_donor_tax_id,
-                     alg_values,
-                     udi_hash,
-                     blinded_udi));
-    csr_data->ss->cs_pending--;
-    if (0 == csr_data->ss->cs_pending)
-      phase_two (csr_data->ss);
-    GNUNET_free(csr_data);
+
+  DONAU_donation_unit_ewv_copy ( alg_values,
+                         &csrresp->details.ok.
+                        alg_values);
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
+                              &ps,
+                              sizeof (ps));
+  DONAU_budi_secret_create (&ps,
+                            alg_values,
+                            blinding_secret);
+  GNUNET_assert (GNUNET_OK ==
+                 DONAU_donation_unit_blind (
+                   cs_pk,
+                   blinding_secret,
+                   &csr_data->nonce,          /* nonce only needed for cs */
+                   udi_nonce,
+                   csr_data->ss->h_donor_tax_id,
+                   alg_values,
+                   udi_hash,
+                   blinded_udi));
+  csr_data->ss->alg_values[csr_data->position] = alg_values;
+  csr_data->ss->cs_pending--;
+  if (0 == csr_data->ss->cs_pending)
+    phase_two (csr_data->ss);
+  GNUNET_free (csr_data);
 }
 
+
 /**
  * Run the command.
  *
@@ -346,8 +352,8 @@ status_run (void *cls,
     GNUNET_new_array (ss->num_bkp, struct DONAU_UniqueDonorIdentifierHashP);
   for (size_t cnt = 0; cnt < ss->num_bkp; cnt++)
   {
-       DONAU_donation_unit_pub_hash (&ss->keys->donation_unit_keys[0].key,
-                                                                 
&ss->bkps[cnt].h_donation_unit_pub);
+    DONAU_donation_unit_pub_hash (&ss->keys->donation_unit_keys[0].key,
+                                  &ss->bkps[cnt].h_donation_unit_pub);
     struct DONAU_UniqueDonorIdentifierNonce *udi_nonce =
       &ss->receipts[cnt].nonce;
     struct DONAU_BudiMasterSecretP ps;
@@ -363,45 +369,45 @@ status_run (void *cls,
                                 sizeof (*udi_nonce));
     switch (ss->keys->donation_unit_keys[0].key.bsign_pub_key->cipher)
     {
-               case GNUNET_CRYPTO_BSA_RSA:
-                       alg_values = DONAU_donation_unit_ewv_rsa_singleton ();
-                   DONAU_budi_secret_create (&ps,
-                                             alg_values,
-                                             &ss->blinding_secrets[cnt]);
-                   GNUNET_assert (GNUNET_OK ==
-                                  DONAU_donation_unit_blind (
-                                    &ss->keys->donation_unit_keys[0].key,
-                                    &ss->blinding_secrets[cnt],
-                                    NULL,                  /* no cs-nonce 
needed for rsa */
-                                    udi_nonce,
-                                    ss->h_donor_tax_id,
-                                    alg_values,
-                                    udi_hash,
-                                    blinded_udi));
-                   ss->alg_values[cnt] = alg_values;
-                       break;
-               case GNUNET_CRYPTO_BSA_CS:
-                       struct CSR_Data *csr_data = GNUNET_new (struct 
CSR_Data);
-                       TALER_cs_withdraw_nonce_derive ( // TODO: write new 
method
-                         (struct TALER_PlanchetMasterSecretP *) &ps,
-                         &csr_data->nonce.cs_nonce);
-                       csr_data->ss = ss;
-                       csr_data->position = cnt;
-                       csr_data->csr_handle = DONAU_csr_issue (
-                               TALER_TESTING_interpreter_get_context (is),
-                               TALER_TESTING_get_donau_url (is),
-                               &ss->keys->donation_unit_keys[0].key,
-                               &csr_data->nonce.cs_nonce,
-                           &cs_stage_two_callback,
-                               csr_data);
-                       if (NULL == csr_data->csr_handle)
-                       {
-                         GNUNET_break (0);
-                       }
-                       ss->cs_pending++;
-                       break;
-           default:
-             GNUNET_break (0);
+    case GNUNET_CRYPTO_BSA_RSA:
+      alg_values = DONAU_donation_unit_ewv_rsa_singleton ();
+      DONAU_budi_secret_create (&ps,
+                                alg_values,
+                                &ss->blinding_secrets[cnt]);
+      GNUNET_assert (GNUNET_OK ==
+                     DONAU_donation_unit_blind (
+                       &ss->keys->donation_unit_keys[0].key,
+                       &ss->blinding_secrets[cnt],
+                       NULL,                    /* no cs-nonce needed for rsa 
*/
+                       udi_nonce,
+                       ss->h_donor_tax_id,
+                       alg_values,
+                       udi_hash,
+                       blinded_udi));
+      ss->alg_values[cnt] = alg_values;
+      break;
+    case GNUNET_CRYPTO_BSA_CS:
+      struct CSR_Data *csr_data = GNUNET_new (struct CSR_Data);
+      TALER_cs_withdraw_nonce_derive ( // TODO: write new method
+        (struct TALER_PlanchetMasterSecretP *) &ps,
+        &csr_data->nonce.cs_nonce);
+      csr_data->ss = ss;
+      csr_data->position = cnt;
+      csr_data->csr_handle = DONAU_csr_issue (
+        TALER_TESTING_interpreter_get_context (is),
+        TALER_TESTING_get_donau_url (is),
+        &ss->keys->donation_unit_keys[0].key,
+        &csr_data->nonce.cs_nonce,
+        &cs_stage_two_callback,
+        csr_data);
+      if (NULL == csr_data->csr_handle)
+      {
+        GNUNET_break (0);
+      }
+      ss->cs_pending++;
+      break;
+    default:
+      GNUNET_break (0);
     }
   }
   if (0 == ss->cs_pending)
@@ -463,10 +469,10 @@ issue_receipts_traits (void *cls,
   struct StatusState *ss = cls;
   struct TALER_TESTING_Trait traits[] = {
     TALER_TESTING_make_trait_salted_tax_id_hash (
-               (const struct DONAU_HashDonorTaxId *) ss->h_donor_tax_id),
-       TALER_TESTING_make_trait_donation_receipts (
-                       (const struct DONAU_DonationReceipt **) &ss->receipts),
-       TALER_TESTING_make_trait_number_receipts ((const size_t *) 
&ss->num_bkp),
+      (const struct DONAU_HashDonorTaxId *) ss->h_donor_tax_id),
+    TALER_TESTING_make_trait_donation_receipts (
+      (const struct DONAU_DonationReceipt **) &ss->receipts),
+    TALER_TESTING_make_trait_number_receipts ((const size_t *) &ss->num_bkp),
     TALER_TESTING_trait_end ()
   };
 
diff --git a/src/util/donau_crypto.c b/src/util/donau_crypto.c
index 087aba9..99c0b70 100644
--- a/src/util/donau_crypto.c
+++ b/src/util/donau_crypto.c
@@ -289,4 +289,17 @@ DONAU_donation_unit_ewv_rsa_singleton ()
     .blinding_inputs = &bi
   };
   return &alg_values;
+}
+
+void
+DONAU_donation_unit_ewv_copy (struct DONAU_BatchIssueValues *bi_dst,
+                      const struct DONAU_BatchIssueValues *bi_src)
+{
+  if (bi_src == DONAU_donation_unit_ewv_rsa_singleton ())
+  {
+    *bi_dst = *bi_src;
+    return;
+  }
+  bi_dst->blinding_inputs
+    = GNUNET_CRYPTO_blinding_input_values_incref (bi_src->blinding_inputs);
 }
\ No newline at end of file

-- 
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]