taler-mdb

GNU Taler Extensions and Integrations
Log | Files | Refs | Submodules | README | LICENSE

commit 0531b848525e566c9fd6934e92390d960778d478
parent b483c802730d5c3f3851a95dc73c829542289045
Author: BOSS_Marco <bossm8@students.bfh.ch>
Date:   Tue,  5 Nov 2019 21:11:00 +0100

pseudo nonce

Diffstat:
Msrc/communication.c | 10+++++++---
Msrc/configuration.h | 4++++
Msrc/product.c | 23++++++++++++++++++++++-
Msrc/product.h | 8+++++---
4 files changed, 38 insertions(+), 7 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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