From d5ee6e1d07805b11e02831fac0823f83cb8f9edd Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 22 Jan 2019 19:04:19 +0100 Subject: Fix denoms comparison. --- src/lib/exchange_api_handle.c | 68 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 11 deletions(-) (limited to 'src/lib/exchange_api_handle.c') diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index b2ac596f..61b34fc8 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -719,6 +719,50 @@ update_auditors (struct TALER_EXCHANGE_Handle *exchange) } } +/** + * Compare two denomination keys. + * + * @param denoma first denomination key + * @param denomb second denomination key + * @return 0 if the two keys are equal (not necessarily + * the same object), 1 otherwise. + */ +unsigned int +TALER_denoms_cmp (struct TALER_EXCHANGE_DenomPublicKey *denom1, + struct TALER_EXCHANGE_DenomPublicKey *denom2) +{ + struct GNUNET_CRYPTO_RsaPublicKey *tmp1; + struct GNUNET_CRYPTO_RsaPublicKey *tmp2; + + /* First check if pub is the same. */ + if (0 != GNUNET_CRYPTO_rsa_public_key_cmp + (denom1->key.rsa_public_key, + denom2->key.rsa_public_key)) + return 1; + + tmp1 = denom1->key.rsa_public_key; + tmp2 = denom2->key.rsa_public_key; + + denom1->key.rsa_public_key = NULL; + denom2->key.rsa_public_key = NULL; + + /* Then procede with the rest of the object. */ + if (0 != memcmp (denom1, + denom2, + sizeof (struct TALER_EXCHANGE_DenomPublicKey))) + { + denom1->key.rsa_public_key = tmp1; + denom2->key.rsa_public_key = tmp2; + + return 1; + } + + denom1->key.rsa_public_key = tmp1; + denom2->key.rsa_public_key = tmp2; + + return 0; +} + /** * Decode the JSON in @a resp_obj from the /keys response @@ -857,7 +901,7 @@ decode_keys_json (const json_t *resp_obj, index = 0; json_array_foreach (denom_keys_array, index, denom_key_obj) { struct TALER_EXCHANGE_DenomPublicKey dk; - bool found = false; + int found = GNUNET_NO; EXITIF (GNUNET_SYSERR == parse_json_denomkey (&dk, @@ -865,17 +909,19 @@ decode_keys_json (const json_t *resp_obj, denom_key_obj, &key_data->master_pub, hash_context)); - for (unsigned int j=0;jnum_denom_keys;j++) + + for (unsigned int j=0; + jnum_denom_keys; + j++) { - if (0 == memcmp (&dk, - &key_data->denom_keys[j], - sizeof (dk))) + if (0 == TALER_denoms_cmp (&dk, + &key_data->denom_keys[j])) { - found = true; + found = GNUNET_YES; break; } } - if (found) + if (GNUNET_YES == found) { /* 0:0:0 did not support /keys cherry picking */ GNUNET_break_op (0 == current); @@ -910,7 +956,7 @@ decode_keys_json (const json_t *resp_obj, index = 0; json_array_foreach (auditors_array, index, auditor_info) { struct TALER_EXCHANGE_AuditorInformation ai; - bool found = false; + int found = GNUNET_NO; memset (&ai, 0, @@ -928,7 +974,7 @@ decode_keys_json (const json_t *resp_obj, &aix->auditor_pub, sizeof (struct TALER_AuditorPublicKeyP))) { - found = true; + found = GNUNET_YES; /* Merge denomination key signatures of downloaded /keys into existing auditor information 'aix'. */ GNUNET_array_grow (aix->denom_keys, @@ -940,7 +986,7 @@ decode_keys_json (const json_t *resp_obj, break; } } - if (found) + if (GNUNET_YES == found) continue; /* we are done */ if (key_data->auditors_size == key_data->num_auditors) GNUNET_array_grow (key_data->auditors, @@ -1077,7 +1123,6 @@ TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange, return GNUNET_TIME_UNIT_ZERO_ABS; } - /** * Callback used when downloading the reply to a /keys request * is complete. @@ -1136,6 +1181,7 @@ keys_completed_cb (void *cls, memcpy (kd.denom_keys, kd_old.denom_keys, kd_old.num_denom_keys * sizeof (struct TALER_EXCHANGE_DenomPublicKey)); + for (unsigned int i=0;i Date: Thu, 24 Jan 2019 17:53:10 +0100 Subject: Auditor tests. Fix double connection. --- src/include/taler_testing_lib.h | 6 ------ src/lib/auditor_api_handle.c | 3 +++ src/lib/exchange_api_handle.c | 9 +++++++++ src/lib/test_auditor_api.c | 4 ++++ src/lib/testing_api_loop.c | 1 + src/lib/testing_auditor_api_helpers.c | 34 ++-------------------------------- 6 files changed, 19 insertions(+), 38 deletions(-) (limited to 'src/lib/exchange_api_handle.c') diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 711a1323..6573d2cd 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -369,12 +369,6 @@ struct TALER_TESTING_Interpreter */ int working; - /** - * Is the auditor running (#GNUNET_YES) or waiting - * for /version (#GNUNET_NO)? - */ - int auditor_working; - /** * How often have we gotten a /keys response so far? */ diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c index 652566c0..dc60fc86 100644 --- a/src/lib/auditor_api_handle.c +++ b/src/lib/auditor_api_handle.c @@ -447,6 +447,9 @@ TALER_AUDITOR_connect (struct GNUNET_CURL_Context *ctx, { struct TALER_AUDITOR_Handle *auditor; + TALER_LOG_DEBUG ("Connecting to the auditor (%s)\n", + url); + auditor = GNUNET_new (struct TALER_AUDITOR_Handle); auditor->ctx = ctx; auditor->url = GNUNET_strdup (url); diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 61b34fc8..78219e61 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -685,8 +685,11 @@ update_auditors (struct TALER_EXCHANGE_Handle *exchange) { struct TALER_EXCHANGE_Keys *kd = &exchange->key_data; + TALER_LOG_DEBUG ("Updating auditors\n"); for (unsigned int i=0;inum_auditors;i++) { + /* Compare auditor data from /keys with auditor data + * from owned exchange structures. */ struct TALER_EXCHANGE_AuditorInformation *auditor = &kd->auditors[i]; struct TEAH_AuditorListEntry *ale = NULL; @@ -704,7 +707,9 @@ update_auditors (struct TALER_EXCHANGE_Handle *exchange) } if (NULL != ale) continue; /* found, no need to add */ + /* new auditor, add */ + TALER_LOG_DEBUG ("Found new auditor!\n"); ale = GNUNET_new (struct TEAH_AuditorListEntry); ale->auditor_pub = auditor->auditor_pub; ale->auditor_url = GNUNET_strdup (auditor->auditor_url); @@ -1206,6 +1211,7 @@ keys_completed_cb (void *cls, aold->num_denom_keys * sizeof (struct TALER_EXCHANGE_AuditorDenominationInfo)); } + /* Old auditors got just copied into new ones. */ if (GNUNET_OK != decode_keys_json (j, GNUNET_YES, @@ -1728,6 +1734,9 @@ TALER_EXCHANGE_connect va_list ap; enum TALER_EXCHANGE_Option opt; + TALER_LOG_DEBUG ("Connecting to the exchange (%s)\n", + url); + exchange = GNUNET_new (struct TALER_EXCHANGE_Handle); exchange->ctx = ctx; exchange->url = GNUNET_strdup (url); diff --git a/src/lib/test_auditor_api.c b/src/lib/test_auditor_api.c index cddd2119..04fbaa58 100644 --- a/src/lib/test_auditor_api.c +++ b/src/lib/test_auditor_api.c @@ -471,6 +471,8 @@ run (void *cls, }; struct TALER_TESTING_Command commands[] = { + + #if 0 CMD_RUN_AUDITOR("virgin-auditor"), CMD_RUN_WIRE_AUDITOR("virgin-wire-auditor"), TALER_TESTING_cmd_batch ("withdraw", @@ -489,6 +491,8 @@ run (void *cls, payback), CMD_RUN_AUDITOR("normal-auditor"), CMD_RUN_WIRE_AUDITOR("normal-wire-auditor"), + #endif + TALER_TESTING_cmd_end () }; diff --git a/src/lib/testing_api_loop.c b/src/lib/testing_api_loop.c index d0865c90..0582b73b 100644 --- a/src/lib/testing_api_loop.c +++ b/src/lib/testing_api_loop.c @@ -309,6 +309,7 @@ do_shutdown (void *cls) if (NULL != is->exchange) { + TALER_LOG_DEBUG ("Disconnecting the exchange\n"); TALER_EXCHANGE_disconnect (is->exchange); is->exchange = NULL; } diff --git a/src/lib/testing_auditor_api_helpers.c b/src/lib/testing_auditor_api_helpers.c index 7e710315..c85fe47b 100644 --- a/src/lib/testing_auditor_api_helpers.c +++ b/src/lib/testing_auditor_api_helpers.c @@ -70,28 +70,6 @@ cleanup_auditor (void *cls) GNUNET_free (cc); } - - -/** - * Function called with information about the auditor. - * - * @param cls closure - * @param vi basic information about the auditor - * @param compat protocol compatibility information - */ -static void -auditor_version_cb (void *cls, - const struct TALER_AUDITOR_VersionInformation *vi, - enum TALER_AUDITOR_VersionCompatibility compat) -{ - struct TALER_TESTING_Interpreter *is = cls; - - /* TODO: check vi/compat? */ - is->auditor_working = GNUNET_YES; -} - - - /** * Closure for #auditor_main_wrapper() */ @@ -145,21 +123,13 @@ auditor_main_wrapper (void *cls, "BASE_URL"); return; } - is->auditor = TALER_AUDITOR_connect (is->ctx, - auditor_base_url, - &auditor_version_cb, - is); + GNUNET_free (auditor_base_url); - if (NULL == is->auditor) - { - GNUNET_break (0); - return; - } cc = GNUNET_new (struct CleanupContext); cc->is = is; cc->fcb = is->final_cleanup_cb; cc->fcb_cls = is->final_cleanup_cb; - is->final_cleanup_cb = &cleanup_auditor; + is->final_cleanup_cb = NULL; is->final_cleanup_cb_cls = cc; mwc->main_cb (mwc->main_cb_cls, is); -- cgit v1.2.3