gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] 22/93: pseudo nonce


From: gnunet
Subject: [taler-taler-mdb] 22/93: pseudo nonce
Date: Mon, 18 Nov 2019 21:12:45 +0100

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

marco-boss pushed a commit to branch master
in repository taler-mdb.

commit 0531b848525e566c9fd6934e92390d960778d478
Author: BOSS_Marco <address@hidden>
AuthorDate: Tue Nov 5 21:11:00 2019 +0100

    pseudo nonce
---
 src/communication.c | 10 +++++++---
 src/configuration.h |  4 ++++
 src/product.c       | 23 ++++++++++++++++++++++-
 src/product.h       |  8 +++++---
 4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/src/communication.c b/src/communication.c
index 40ec181..7f51388 100644
--- a/src/communication.c
+++ b/src/communication.c
@@ -92,10 +92,11 @@ int SNACK_taler_create_order_req (ProductOrder *product)
            product->product);
 
   /* create the json object for the order request */
-  orderReq = json_pack ("{ s: { s:s, s:s, s:s }}", SNACK_JSON_REQ_ORDER,
+  orderReq = json_pack ("{ s: { s:s, s:s, s:s, s:s }}", SNACK_JSON_REQ_ORDER,
                         SNACK_JSON_REQ_SUMMARY, product->product,
-                        SNACK_JSON_REQ_AMOUNT,
-                        amountStr, SNACK_JSON_REQ_FULFILLMENT, fulfillmentUrl);
+                        SNACK_JSON_REQ_AMOUNT, amountStr,
+                        SNACK_JSON_REQ_FULFILLMENT, fulfillmentUrl,
+                        SNACK_JSON_REQ_NONCE, product->nonce);
   if ( ! orderReq )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -217,6 +218,9 @@ int SNACK_taler_check_payment_status (CURL *curl, 
ProductOrder *product)
   /* clean up */
   curl_slist_free_all (list);
 
+
+  printf ("%s\n", product->response->string);
+
   return EXIT_SUCCESS;
 }
 
diff --git a/src/configuration.h b/src/configuration.h
index 9dfb65b..26a52b2 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -63,6 +63,10 @@ along with
 #define SNACK_JSON_REQ_SUMMARY "summary"
 #define SNACK_JSON_REQ_AMOUNT "amount"
 #define SNACK_JSON_REQ_FULFILLMENT "fulfillment_url"
+#define SNACK_JSON_REQ_NONCE "nonce"
+
+/* nonce definitions */
+#define NONCE_SIZE 32
 
 /* Wallet AID */
 static const uint8_t taler_aid[] = { 0xF0, 0x00, 0x54, 0x41, 0x4c, 0x45, 0x52 
};
diff --git a/src/product.c b/src/product.c
index 4d5e3cc..2baae95 100644
--- a/src/product.c
+++ b/src/product.c
@@ -37,6 +37,9 @@ void SNACK_product_reset (ProductOrder *product)
   product->amount = NULL;
   product->product = NULL;
   product->paid = false;
+
+  /* regenerate nonce */
+  SNACK_product_generate_nonce (&(product->nonce), NONCE_SIZE);
 }
 
 int SNACK_product_init (ProductOrder *product, struct
@@ -85,13 +88,17 @@ int SNACK_product_init (ProductOrder *product, struct
   product->response = GNUNET_malloc (sizeof(TalerResponse));
   product->response->string = GNUNET_malloc (1);
   product->orderID = GNUNET_malloc (1);
-  product->orderRequest = GNUNET_malloc (1);
   product->payUrl = GNUNET_malloc (1);
   product->checkUrl = GNUNET_malloc (1);
+  product->orderRequest = GNUNET_malloc (1);
   product->amount = NULL;
   product->product = NULL;
   product->paid = false;
 
+  /* generate nonce */
+  product->nonce = GNUNET_malloc (NONCE_SIZE);
+  SNACK_product_generate_nonce (&(product->nonce), NONCE_SIZE);
+
   return EXIT_SUCCESS;
 }
 
@@ -99,6 +106,7 @@ void SNACK_product_exit (ProductOrder *product)
 {
   GNUNET_free (product->response->string);
   GNUNET_free (product->response);
+  GNUNET_free (product->nonce);
   GNUNET_free (product->orderID);
   GNUNET_free (product->orderRequest);
   GNUNET_free (product->payUrl);
@@ -200,3 +208,16 @@ int SNACK_product_set_cfg_value (struct 
GNUNET_CONFIGURATION_Handle *cfg, const
   }
   return EXIT_SUCCESS;
 }
+
+void SNACK_product_generate_nonce (char**nonce, size_t size)
+{
+  uint32_t temp;
+  for ( size_t i = 0; i < size; ++i) {
+    do temp = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 122);
+    while ( (temp < '1' || temp > '9') & (temp < 'A' || temp > 'Z') & (temp <
+                                                                       'a' ||
+                                                                       temp >
+                                                                       'z') );
+    (*nonce)[i] = temp;
+  }
+}
diff --git a/src/product.h b/src/product.h
index d1b131f..44fbb72 100644
--- a/src/product.h
+++ b/src/product.h
@@ -53,10 +53,11 @@ typedef struct ProductOrder
 {
   char *product;
   char *amount;
-  char *orderRequest;
+  char *nonce;
   char *orderID;
   char *checkUrl;
   char *payUrl;
+  char *orderRequest;
   bool paid;
   TalerConfig *talerCfg;
   TalerResponse *response;
@@ -78,8 +79,9 @@ int SNACK_product_set_pay_url (ProductOrder *product);
 
 int SNACK_product_set_paid_status (ProductOrder *product);
 
-int SNACK_product_set_cfg_value (struct GNUNET_CONFIGURATION_Handle*cfg, const
-                                 char*section, const char *key, char **value);
+int SNACK_product_set_cfg_value (struct GNUNET_CONFIGURATION_Handle *cfg, const
+                                 char *section, const char *key, char **value);
 
+void SNACK_product_generate_nonce (char **nonce, size_t size);
 
 #endif // PRODUCT_H

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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