From b5cba3251053c22bf1df46282f1dd0a4c46f6a38 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 1 Mar 2016 15:35:04 +0100 Subject: renaming mint->exchange --- src/exchange-lib/exchange_api_handle.c | 902 +++++++++++++++++++++++++++++++++ 1 file changed, 902 insertions(+) create mode 100644 src/exchange-lib/exchange_api_handle.c (limited to 'src/exchange-lib/exchange_api_handle.c') diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c new file mode 100644 index 00000000..d4b3e4de --- /dev/null +++ b/src/exchange-lib/exchange_api_handle.c @@ -0,0 +1,902 @@ +/* + This file is part of TALER + Copyright (C) 2014, 2015 GNUnet e.V. + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, If not, see + +*/ +/** + * @file exchange-lib/exchange_api_handle.c + * @brief Implementation of the "handle" component of the exchange's HTTP API + * @author Sree Harsha Totakura + * @author Christian Grothoff + */ +#include "platform.h" +#include +#include +#include +#include +#include "taler_exchange_service.h" +#include "taler_signatures.h" +#include "exchange_api_context.h" +#include "exchange_api_json.h" +#include "exchange_api_handle.h" + + +/** + * Log error related to CURL operations. + * + * @param type log level + * @param function which function failed to run + * @param code what was the curl error code + */ +#define CURL_STRERROR(type, function, code) \ + GNUNET_log (type, "Curl function `%s' has failed at `%s:%d' with error: %s", \ + function, __FILE__, __LINE__, curl_easy_strerror (code)); + + +/** + * Stages of initialization for the `struct TALER_EXCHANGE_Handle` + */ +enum ExchangeHandleState +{ + /** + * Just allocated. + */ + MHS_INIT = 0, + + /** + * Obtained the exchange's certification data and keys. + */ + MHS_CERT = 1, + + /** + * Failed to initialize (fatal). + */ + MHS_FAILED = 2 +}; + + +/** + * Data for the request to get the /keys of a exchange. + */ +struct KeysRequest; + + +/** + * Handle to the exchange + */ +struct TALER_EXCHANGE_Handle +{ + /** + * The context of this handle + */ + struct TALER_EXCHANGE_Context *ctx; + + /** + * The URL of the exchange (i.e. "http://exchange.taler.net/") + */ + char *url; + + /** + * Function to call with the exchange's certification data, + * NULL if this has already been done. + */ + TALER_EXCHANGE_CertificationCallback cert_cb; + + /** + * Closure to pass to @e cert_cb. + */ + void *cert_cb_cls; + + /** + * Data for the request to get the /keys of a exchange, + * NULL once we are past stage #MHS_INIT. + */ + struct KeysRequest *kr; + + /** + * Key data of the exchange, only valid if + * @e handshake_complete is past stage #MHS_CERT. + */ + struct TALER_EXCHANGE_Keys key_data; + + /** + * Stage of the exchange's initialization routines. + */ + enum ExchangeHandleState state; + +}; + + +/* ***************** Internal /keys fetching ************* */ + +/** + * Data for the request to get the /keys of a exchange. + */ +struct KeysRequest +{ + /** + * The connection to exchange this request handle will use + */ + struct TALER_EXCHANGE_Handle *exchange; + + /** + * The url for this handle + */ + char *url; + + /** + * Entry for this request with the `struct TALER_EXCHANGE_Context`. + */ + struct MAC_Job *job; + + /** + * Data structure for the download. + */ + struct MAC_DownloadBuffer db; + +}; + + +/** + * Release memory occupied by a keys request. + * Note that this does not cancel the request + * itself. + * + * @param kr request to free + */ +static void +free_keys_request (struct KeysRequest *kr) +{ + GNUNET_free_non_null (kr->db.buf); + GNUNET_free (kr->url); + GNUNET_free (kr); +} + + +#define EXITIF(cond) \ + do { \ + if (cond) { GNUNET_break (0); goto EXITIF_exit; } \ + } while (0) + + +/** + * Parse a exchange's signing key encoded in JSON. + * + * @param[out] sign_key where to return the result + * @param[in] sign_key_obj json to parse + * @param master_key master key to use to verify signature + * @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if the signature is + * invalid or the json malformed. + */ +static int +parse_json_signkey (struct TALER_EXCHANGE_SigningPublicKey *sign_key, + json_t *sign_key_obj, + const struct TALER_MasterPublicKeyP *master_key) +{ + struct TALER_ExchangeSigningKeyValidityPS sign_key_issue; + struct GNUNET_CRYPTO_EddsaSignature sig; + struct GNUNET_TIME_Absolute valid_from; + struct GNUNET_TIME_Absolute valid_until; + struct GNUNET_TIME_Absolute valid_legal; + struct MAJ_Specification spec[] = { + MAJ_spec_fixed_auto ("master_sig", + &sig), + MAJ_spec_fixed_auto ("key", + &sign_key_issue.signkey_pub), + MAJ_spec_absolute_time ("stamp_start", + &valid_from), + MAJ_spec_absolute_time ("stamp_expire", + &valid_until), + MAJ_spec_absolute_time ("stamp_end", + &valid_legal), + MAJ_spec_end + }; + + if (GNUNET_OK != + MAJ_parse_json (sign_key_obj, + spec)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + + sign_key_issue.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY); + sign_key_issue.purpose.size = + htonl (sizeof (struct TALER_ExchangeSigningKeyValidityPS) + - offsetof (struct TALER_ExchangeSigningKeyValidityPS, + purpose)); + sign_key_issue.master_public_key = *master_key; + sign_key_issue.start = GNUNET_TIME_absolute_hton (valid_from); + sign_key_issue.expire = GNUNET_TIME_absolute_hton (valid_until); + sign_key_issue.end = GNUNET_TIME_absolute_hton (valid_legal); + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY, + &sign_key_issue.purpose, + &sig, + &master_key->eddsa_pub)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + sign_key->valid_from = valid_from; + sign_key->valid_until = valid_until; + sign_key->key = sign_key_issue.signkey_pub; + return GNUNET_OK; +} + + +/** + * Parse a exchange's denomination key encoded in JSON. + * + * @param[out] denom_key where to return the result + * @param[in] denom_key_obj json to parse + * @param master_key master key to use to verify signature + * @param hash_context where to accumulate data for signature verification + * @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if the signature is + * invalid or the json malformed. + */ +static int +parse_json_denomkey (struct TALER_EXCHANGE_DenomPublicKey *denom_key, + json_t *denom_key_obj, + struct TALER_MasterPublicKeyP *master_key, + struct GNUNET_HashContext *hash_context) +{ + struct GNUNET_TIME_Absolute valid_from; + struct GNUNET_TIME_Absolute withdraw_valid_until; + struct GNUNET_TIME_Absolute deposit_valid_until; + struct GNUNET_TIME_Absolute expire_legal; + struct TALER_Amount value; + struct TALER_Amount fee_withdraw; + struct TALER_Amount fee_deposit; + struct TALER_Amount fee_refresh; + struct TALER_DenominationKeyValidityPS denom_key_issue; + struct GNUNET_CRYPTO_rsa_PublicKey *pk; + struct GNUNET_CRYPTO_EddsaSignature sig; + + struct MAJ_Specification spec[] = { + MAJ_spec_fixed_auto ("master_sig", + &sig), + MAJ_spec_absolute_time ("stamp_expire_deposit", + &deposit_valid_until), + MAJ_spec_absolute_time ("stamp_expire_withdraw", + &withdraw_valid_until), + MAJ_spec_absolute_time ("stamp_start", + &valid_from), + MAJ_spec_absolute_time ("stamp_expire_legal", + &expire_legal), + MAJ_spec_amount ("value", + &value), + MAJ_spec_amount ("fee_withdraw", + &fee_withdraw), + MAJ_spec_amount ("fee_deposit", + &fee_deposit), + MAJ_spec_amount ("fee_refresh", + &fee_refresh), + MAJ_spec_rsa_public_key ("denom_pub", + &pk), + MAJ_spec_end + }; + + if (GNUNET_OK != + MAJ_parse_json (denom_key_obj, + spec)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + + memset (&denom_key_issue, 0, sizeof (denom_key_issue)); + GNUNET_CRYPTO_rsa_public_key_hash (pk, + &denom_key_issue.denom_hash); + denom_key_issue.purpose.purpose + = htonl (TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY); + denom_key_issue.purpose.size + = htonl (sizeof (struct TALER_DenominationKeyValidityPS)); + denom_key_issue.master = *master_key; + denom_key_issue.start = GNUNET_TIME_absolute_hton (valid_from); + denom_key_issue.expire_withdraw = GNUNET_TIME_absolute_hton (withdraw_valid_until); + denom_key_issue.expire_spend = GNUNET_TIME_absolute_hton (deposit_valid_until); + denom_key_issue.expire_legal = GNUNET_TIME_absolute_hton (expire_legal); + TALER_amount_hton (&denom_key_issue.value, + &value); + TALER_amount_hton (&denom_key_issue.fee_withdraw, + &fee_withdraw); + TALER_amount_hton (&denom_key_issue.fee_deposit, + &fee_deposit); + TALER_amount_hton (&denom_key_issue.fee_refresh, + &fee_refresh); + EXITIF (GNUNET_SYSERR == + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY, + &denom_key_issue.purpose, + &sig, + &master_key->eddsa_pub)); + GNUNET_CRYPTO_hash_context_read (hash_context, + &denom_key_issue.denom_hash, + sizeof (struct GNUNET_HashCode)); + denom_key->key.rsa_public_key = pk; + denom_key->h_key = denom_key_issue.denom_hash; + denom_key->valid_from = valid_from; + denom_key->withdraw_valid_until = withdraw_valid_until; + denom_key->deposit_valid_until = deposit_valid_until; + denom_key->expire_legal = expire_legal; + denom_key->value = value; + denom_key->fee_withdraw = fee_withdraw; + denom_key->fee_deposit = fee_deposit; + denom_key->fee_refresh = fee_refresh; + return GNUNET_OK; + + EXITIF_exit: + MAJ_parse_free (spec); + return GNUNET_SYSERR; +} + + +/** + * Parse a exchange's auditor information encoded in JSON. + * + * @param[out] auditor where to return the result + * @param[in] auditor_obj json to parse + * @param key_data information about denomination keys + * @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if the signature is + * invalid or the json malformed. + */ +static int +parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, + json_t *auditor_obj, + const struct TALER_EXCHANGE_Keys *key_data) +{ + json_t *keys; + json_t *key; + unsigned int len; + unsigned int off; + unsigned int i; + struct TALER_ExchangeKeyValidityPS kv; + struct MAJ_Specification spec[] = { + MAJ_spec_fixed_auto ("auditor_pub", + &auditor->auditor_pub), + MAJ_spec_json ("denomination_keys", + &keys), + MAJ_spec_end + }; + + auditor->auditor_url = NULL; /* #3987 */ + if (GNUNET_OK != + MAJ_parse_json (auditor_obj, + spec)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + kv.purpose.purpose = htonl (TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS); + kv.purpose.size = htonl (sizeof (struct TALER_ExchangeKeyValidityPS)); + kv.master = key_data->master_pub; + len = json_array_size (keys); + auditor->denom_keys = GNUNET_new_array (len, + const struct TALER_EXCHANGE_DenomPublicKey *); + i = 0; + off = 0; + json_array_foreach (keys, i, key) { + struct TALER_AuditorSignatureP auditor_sig; + struct GNUNET_HashCode denom_h; + const struct TALER_EXCHANGE_DenomPublicKey *dk; + unsigned int j; + struct MAJ_Specification spec[] = { + MAJ_spec_fixed_auto ("denom_pub_h", + &denom_h), + MAJ_spec_fixed_auto ("auditor_sig", + &auditor_sig), + MAJ_spec_end + }; + + if (GNUNET_OK != + MAJ_parse_json (key, + spec)) + { + GNUNET_break_op (0); + continue; + } + dk = NULL; + for (j=0;jnum_denom_keys;j++) + { + if (0 == memcmp (&denom_h, + &key_data->denom_keys[j].h_key, + sizeof (struct GNUNET_HashCode))) + { + dk = &key_data->denom_keys[j]; + break; + } + } + if (NULL == dk) + { + GNUNET_break_op (0); + continue; + } + kv.start = GNUNET_TIME_absolute_hton (dk->valid_from); + kv.expire_withdraw = GNUNET_TIME_absolute_hton (dk->withdraw_valid_until); + kv.expire_spend = GNUNET_TIME_absolute_hton (dk->deposit_valid_until); + kv.expire_legal = GNUNET_TIME_absolute_hton (dk->expire_legal); + TALER_amount_hton (&kv.value, + &dk->value); + TALER_amount_hton (&kv.fee_withdraw, + &dk->fee_withdraw); + TALER_amount_hton (&kv.fee_deposit, + &dk->fee_deposit); + TALER_amount_hton (&kv.fee_refresh, + &dk->fee_refresh); + kv.denom_hash = dk->h_key; + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS, + &kv.purpose, + &auditor_sig.eddsa_sig, + &auditor->auditor_pub.eddsa_pub)) + { + GNUNET_break_op (0); + continue; + } + auditor->denom_keys[off] = dk; + off++; + } + auditor->num_denom_keys = off; + return GNUNET_OK; +} + + +/** + * Decode the JSON in @a resp_obj from the /keys response and store the data + * in the @a key_data. + * + * @param[in] resp_obj JSON object to parse + * @param[out] key_data where to store the results we decoded + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (malformed JSON) + */ +static int +decode_keys_json (json_t *resp_obj, + struct TALER_EXCHANGE_Keys *key_data) +{ + struct GNUNET_TIME_Absolute list_issue_date; + struct TALER_ExchangeSignatureP sig; + struct TALER_ExchangeKeySetPS ks; + struct GNUNET_HashContext *hash_context; + struct TALER_ExchangePublicKeyP pub; + + if (JSON_OBJECT != json_typeof (resp_obj)) + return GNUNET_SYSERR; + + hash_context = GNUNET_CRYPTO_hash_context_start (); + /* parse the master public key and issue date of the response */ + { + struct MAJ_Specification spec[] = { + MAJ_spec_fixed_auto ("master_public_key", + &key_data->master_pub), + MAJ_spec_fixed_auto ("eddsa_sig", + &sig), + MAJ_spec_fixed_auto ("eddsa_pub", + &pub), + MAJ_spec_absolute_time ("list_issue_date", + &list_issue_date), + MAJ_spec_end + }; + + EXITIF (GNUNET_OK != + MAJ_parse_json (resp_obj, + spec)); + } + + /* parse the signing keys */ + { + json_t *sign_keys_array; + json_t *sign_key_obj; + unsigned int index; + + EXITIF (NULL == (sign_keys_array = + json_object_get (resp_obj, + "signkeys"))); + EXITIF (JSON_ARRAY != json_typeof (sign_keys_array)); + EXITIF (0 == (key_data->num_sign_keys = + json_array_size (sign_keys_array))); + key_data->sign_keys + = GNUNET_new_array (key_data->num_sign_keys, + struct TALER_EXCHANGE_SigningPublicKey); + index = 0; + json_array_foreach (sign_keys_array, index, sign_key_obj) { + EXITIF (GNUNET_SYSERR == + parse_json_signkey (&key_data->sign_keys[index], + sign_key_obj, + &key_data->master_pub)); + } + } + + /* parse the denomination keys */ + { + json_t *denom_keys_array; + json_t *denom_key_obj; + unsigned int index; + + EXITIF (NULL == (denom_keys_array = + json_object_get (resp_obj, "denoms"))); + EXITIF (JSON_ARRAY != json_typeof (denom_keys_array)); + EXITIF (0 == (key_data->num_denom_keys = json_array_size (denom_keys_array))); + key_data->denom_keys = GNUNET_new_array (key_data->num_denom_keys, + struct TALER_EXCHANGE_DenomPublicKey); + index = 0; + json_array_foreach (denom_keys_array, index, denom_key_obj) { + EXITIF (GNUNET_SYSERR == + parse_json_denomkey (&key_data->denom_keys[index], + denom_key_obj, + &key_data->master_pub, + hash_context)); + } + } + + /* parse the auditor information */ + { + json_t *auditors_array; + json_t *auditor_info; + unsigned int len; + unsigned int index; + + EXITIF (NULL == (auditors_array = + json_object_get (resp_obj, "auditors"))); + EXITIF (JSON_ARRAY != json_typeof (auditors_array)); + len = json_array_size (auditors_array); + if (0 != len) + { + key_data->auditors = GNUNET_new_array (len, + struct TALER_EXCHANGE_AuditorInformation); + index = 0; + json_array_foreach (auditors_array, index, auditor_info) { + EXITIF (GNUNET_SYSERR == + parse_json_auditor (&key_data->auditors[index], + auditor_info, + key_data)); + } + } + } + + /* Validate signature... */ + ks.purpose.size = htonl (sizeof (ks)); + ks.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_KEY_SET); + ks.list_issue_date = GNUNET_TIME_absolute_hton (list_issue_date); + GNUNET_CRYPTO_hash_context_finish (hash_context, + &ks.hc); + hash_context = NULL; + EXITIF (GNUNET_OK != + TALER_EXCHANGE_test_signing_key (key_data, + &pub)); + EXITIF (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_KEY_SET, + &ks.purpose, + &sig.eddsa_signature, + &pub.eddsa_pub)); + return GNUNET_OK; + EXITIF_exit: + + if (NULL != hash_context) + GNUNET_CRYPTO_hash_context_abort (hash_context); + return GNUNET_SYSERR; +} + + +/** + * Callback used when downloading the reply to a /keys request + * is complete. + * + * @param cls the `struct KeysRequest` + * @param eh easy handle of the original request + */ +static void +keys_completed_cb (void *cls, + CURL *eh) +{ + struct KeysRequest *kr = cls; + struct TALER_EXCHANGE_Handle *exchange = kr->exchange; + json_t *resp_obj; + long response_code; + TALER_EXCHANGE_CertificationCallback cb; + + resp_obj = MAC_download_get_result (&kr->db, + eh, + &response_code); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received keys from URL `%s' with status %ld.\n", + kr->url, + response_code); + switch (response_code) { + case 0: + break; + case MHD_HTTP_OK: + if ( (NULL == resp_obj) || + (GNUNET_OK != + decode_keys_json (resp_obj, + &kr->exchange->key_data)) ) + response_code = 0; + break; + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u\n", + response_code); + break; + } + if (NULL != resp_obj) + json_decref (resp_obj); + + if (MHD_HTTP_OK != response_code) + { + exchange->kr = NULL; + free_keys_request (kr); + exchange->state = MHS_FAILED; + /* notify application that we failed */ + if (NULL != (cb = exchange->cert_cb)) + { + exchange->cert_cb = NULL; + cb (exchange->cert_cb_cls, + NULL); + } + return; + } + exchange->kr = NULL; + free_keys_request (kr); + exchange->state = MHS_CERT; + /* notify application about the key information */ + if (NULL != (cb = exchange->cert_cb)) + { + exchange->cert_cb = NULL; + cb (exchange->cert_cb_cls, + &exchange->key_data); + } +} + + +/* ********************* library internal API ********* */ + + +/** + * Get the context of a exchange. + * + * @param h the exchange handle to query + * @return ctx context to execute jobs in + */ +struct TALER_EXCHANGE_Context * +MAH_handle_to_context (struct TALER_EXCHANGE_Handle *h) +{ + return h->ctx; +} + + +/** + * Check if the handle is ready to process requests. + * + * @param h the exchange handle to query + * @return #GNUNET_YES if we are ready, #GNUNET_NO if not + */ +int +MAH_handle_is_ready (struct TALER_EXCHANGE_Handle *h) +{ + return (MHS_CERT == h->state) ? GNUNET_YES : GNUNET_NO; +} + + +/** + * Obtain the URL to use for an API request. + * + * @param h the exchange handle to query + * @param path Taler API path (i.e. "/reserve/withdraw") + * @return the full URI to use with cURL + */ +char * +MAH_path_to_url (struct TALER_EXCHANGE_Handle *h, + const char *path) +{ + char *url; + + if ( ('/' == path[0]) && + (0 < strlen (h->url)) && + ('/' == h->url[strlen (h->url) - 1]) ) + path++; /* avoid generating URL with "//" from concat */ + GNUNET_asprintf (&url, + "%s%s", + h->url, + path); + return url; +} + + +/* ********************* public API ******************* */ + +/** + * Initialise a connection to the exchange. Will connect to the + * exchange and obtain information about the exchange's master public + * key and the exchange's auditor. The respective information will + * be passed to the @a cert_cb once available, and all future + * interactions with the exchange will be checked to be signed + * (where appropriate) by the respective master key. + * + * @param ctx the context + * @param url HTTP base URL for the exchange + * @param cert_cb function to call with the exchange's certification information + * @param cert_cb_cls closure for @a cert_cb + * @param ... list of additional arguments, terminated by #TALER_EXCHANGE_OPTION_END. + * @return the exchange handle; NULL upon error + */ +struct TALER_EXCHANGE_Handle * +TALER_EXCHANGE_connect (struct TALER_EXCHANGE_Context *ctx, + const char *url, + TALER_EXCHANGE_CertificationCallback cert_cb, + void *cert_cb_cls, + ...) +{ + struct TALER_EXCHANGE_Handle *exchange; + struct KeysRequest *kr; + CURL *c; + + exchange = GNUNET_new (struct TALER_EXCHANGE_Handle); + exchange->ctx = ctx; + exchange->url = GNUNET_strdup (url); + exchange->cert_cb = cert_cb; + exchange->cert_cb_cls = cert_cb_cls; + kr = GNUNET_new (struct KeysRequest); + kr->exchange = exchange; + kr->url = MAH_path_to_url (exchange, "/keys"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requesting keys with URL `%s'.\n", + kr->url); + c = curl_easy_init (); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (c, + CURLOPT_VERBOSE, + 0)); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (c, + CURLOPT_STDERR, + stdout)); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (c, + CURLOPT_URL, + kr->url)); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (c, + CURLOPT_WRITEFUNCTION, + &MAC_download_cb)); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (c, + CURLOPT_WRITEDATA, + &kr->db)); + kr->job = MAC_job_add (exchange->ctx, + c, + GNUNET_NO, + &keys_completed_cb, + kr); + exchange->kr = kr; + return exchange; +} + + +/** + * Disconnect from the exchange + * + * @param exchange the exchange handle + */ +void +TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange) +{ + unsigned int i; + + if (NULL != exchange->kr) + { + MAC_job_cancel (exchange->kr->job); + free_keys_request (exchange->kr); + exchange->kr = NULL; + } + GNUNET_array_grow (exchange->key_data.sign_keys, + exchange->key_data.num_sign_keys, + 0); + for (i=0;ikey_data.num_denom_keys;i++) + GNUNET_CRYPTO_rsa_public_key_free (exchange->key_data.denom_keys[i].key.rsa_public_key); + GNUNET_array_grow (exchange->key_data.denom_keys, + exchange->key_data.num_denom_keys, + 0); + GNUNET_array_grow (exchange->key_data.auditors, + exchange->key_data.num_auditors, + 0); + GNUNET_free (exchange->url); + GNUNET_free (exchange); +} + + +/** + * Test if the given @a pub is a the current signing key from the exchange + * according to @a keys. + * + * @param keys the exchange's key set + * @param pub claimed current online signing key for the exchange + * @return #GNUNET_OK if @a pub is (according to /keys) a current signing key + */ +int +TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys, + const struct TALER_ExchangePublicKeyP *pub) +{ + struct GNUNET_TIME_Absolute now; + unsigned int i; + + /* we will check using a tolerance of 1h for the time */ + now = GNUNET_TIME_absolute_get (); + for (i=0;inum_sign_keys;i++) + if ( (keys->sign_keys[i].valid_from.abs_value_us <= now.abs_value_us + 60 * 60 * 1000LL * 1000LL) && + (keys->sign_keys[i].valid_until.abs_value_us > now.abs_value_us - 60 * 60 * 1000LL * 1000LL) && + (0 == memcmp (pub, + &keys->sign_keys[i].key, + sizeof (struct TALER_ExchangePublicKeyP))) ) + return GNUNET_OK; + return GNUNET_SYSERR; +} + + +/** + * Obtain the denomination key details from the exchange. + * + * @param keys the exchange's key set + * @param pk public key of the denomination to lookup + * @return details about the given denomination key, NULL if the key is + * not found + */ +const struct TALER_EXCHANGE_DenomPublicKey * +TALER_EXCHANGE_get_denomination_key (const struct TALER_EXCHANGE_Keys *keys, + const struct TALER_DenominationPublicKey *pk) +{ + unsigned int i; + + for (i=0;inum_denom_keys;i++) + if (0 == GNUNET_CRYPTO_rsa_public_key_cmp (pk->rsa_public_key, + keys->denom_keys[i].key.rsa_public_key)) + return &keys->denom_keys[i]; + return NULL; +} + + +/** + * Obtain the denomination key details from the exchange. + * + * @param keys the exchange's key set + * @param hc hash of the public key of the denomination to lookup + * @return details about the given denomination key + */ +const struct TALER_EXCHANGE_DenomPublicKey * +TALER_EXCHANGE_get_denomination_key_by_hash (const struct TALER_EXCHANGE_Keys *keys, + const struct GNUNET_HashCode *hc) +{ + unsigned int i; + + for (i=0;inum_denom_keys;i++) + if (0 == memcmp (hc, + &keys->denom_keys[i].h_key, + sizeof (struct GNUNET_HashCode))) + return &keys->denom_keys[i]; + return NULL; +} + + +/** + * Obtain the keys from the exchange. + * + * @param exchange the exchange handle + * @return the exchange's key set + */ +const struct TALER_EXCHANGE_Keys * +TALER_EXCHANGE_get_keys (const struct TALER_EXCHANGE_Handle *exchange) +{ + return &exchange->key_data; +} + + +/* end of exchange_api_handle.c */ -- cgit v1.2.3 From ae726ea31b8607eacd2896617251cc0cab253111 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 19 Mar 2016 15:54:21 +0100 Subject: remove duplicated JSON parsing code from exchange-lib (#4150) --- src/exchange-lib/Makefile.am | 1 - src/exchange-lib/exchange_api_admin.c | 1 - src/exchange-lib/exchange_api_common.c | 41 +- src/exchange-lib/exchange_api_deposit.c | 14 +- src/exchange-lib/exchange_api_deposit_wtid.c | 41 +- src/exchange-lib/exchange_api_handle.c | 96 ++--- src/exchange-lib/exchange_api_json.c | 541 -------------------------- src/exchange-lib/exchange_api_json.h | 352 ----------------- src/exchange-lib/exchange_api_refresh.c | 55 +-- src/exchange-lib/exchange_api_refresh_link.c | 66 ++-- src/exchange-lib/exchange_api_reserve.c | 69 ++-- src/exchange-lib/exchange_api_wire.c | 23 +- src/exchange-lib/exchange_api_wire_deposits.c | 39 +- 13 files changed, 231 insertions(+), 1108 deletions(-) delete mode 100644 src/exchange-lib/exchange_api_json.c delete mode 100644 src/exchange-lib/exchange_api_json.h (limited to 'src/exchange-lib/exchange_api_handle.c') diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am index a043e860..10188c8f 100644 --- a/src/exchange-lib/Makefile.am +++ b/src/exchange-lib/Makefile.am @@ -16,7 +16,6 @@ libtalerexchange_la_LDFLAGS = \ libtalerexchange_la_SOURCES = \ exchange_api_common.c exchange_api_common.h \ exchange_api_context.c exchange_api_context.h \ - exchange_api_json.c exchange_api_json.h \ exchange_api_handle.c exchange_api_handle.h \ exchange_api_admin.c \ exchange_api_deposit.c \ diff --git a/src/exchange-lib/exchange_api_admin.c b/src/exchange-lib/exchange_api_admin.c index 4ed761fb..871a88a6 100644 --- a/src/exchange-lib/exchange_api_admin.c +++ b/src/exchange-lib/exchange_api_admin.c @@ -27,7 +27,6 @@ #include #include "taler_json_lib.h" #include "taler_exchange_service.h" -#include "exchange_api_json.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" diff --git a/src/exchange-lib/exchange_api_common.c b/src/exchange-lib/exchange_api_common.c index 805c3fc4..6d2408d9 100644 --- a/src/exchange-lib/exchange_api_common.c +++ b/src/exchange-lib/exchange_api_common.c @@ -21,7 +21,7 @@ */ #include "platform.h" #include "exchange_api_common.h" -#include "exchange_api_json.h" +#include "taler_json_lib.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -66,24 +66,25 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, void *details; size_t details_size; const char *type; - struct MAJ_Specification spec[] = { - MAJ_spec_amount ("amount", + struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_amount ("amount", &amount), - MAJ_spec_string ("type", + GNUNET_JSON_spec_string ("type", &type), - MAJ_spec_fixed_auto ("signature", + GNUNET_JSON_spec_fixed_auto ("signature", &sig), - MAJ_spec_varsize ("details", + GNUNET_JSON_spec_varsize ("details", &details, &details_size), - MAJ_spec_end + GNUNET_JSON_spec_end() }; transaction = json_array_get (history, off); if (GNUNET_OK != - MAJ_parse_json (transaction, - spec)) + GNUNET_JSON_parse (transaction, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -97,14 +98,14 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, if (details_size != sizeof (struct TALER_DepositRequestPS)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } dr = (const struct TALER_DepositRequestPS *) details; if (details_size != ntohl (dr->purpose.size)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -114,7 +115,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, &coin_pub->eddsa_pub)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } @@ -125,7 +126,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, &amount)) { GNUNET_break (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -138,14 +139,14 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, if (details_size != sizeof (struct TALER_RefreshMeltCoinAffirmationPS)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } rm = (const struct TALER_RefreshMeltCoinAffirmationPS *) details; if (details_size != ntohl (rm->purpose.size)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -155,7 +156,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, &coin_pub->eddsa_pub)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } TALER_amount_ntoh (&rm_amount, @@ -164,7 +165,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, &amount)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -172,7 +173,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, { /* signature not supported, new version on server? */ GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -182,10 +183,10 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency, { /* overflow in history already!? inconceivable! Bad exchange! */ GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); } return GNUNET_OK; } diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c index ef7a59e6..8ec45a23 100644 --- a/src/exchange-lib/exchange_api_deposit.c +++ b/src/exchange-lib/exchange_api_deposit.c @@ -29,7 +29,6 @@ #include "taler_json_lib.h" #include "taler_exchange_service.h" #include "exchange_api_common.h" -#include "exchange_api_json.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -109,15 +108,16 @@ verify_deposit_signature_ok (const struct TALER_EXCHANGE_DepositHandle *dh, struct TALER_ExchangeSignatureP exchange_sig; struct TALER_ExchangePublicKeyP exchange_pub; const struct TALER_EXCHANGE_Keys *key_state; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("sig", &exchange_sig), - MAJ_spec_fixed_auto ("pub", &exchange_pub), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("sig", &exchange_sig), + GNUNET_JSON_spec_fixed_auto ("pub", &exchange_pub), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; diff --git a/src/exchange-lib/exchange_api_deposit_wtid.c b/src/exchange-lib/exchange_api_deposit_wtid.c index f3b5d2c0..1ad1dd01 100644 --- a/src/exchange-lib/exchange_api_deposit_wtid.c +++ b/src/exchange-lib/exchange_api_deposit_wtid.c @@ -25,9 +25,9 @@ #include /* just for HTTP status codes */ #include #include +#include "taler_json_lib.h" #include "taler_exchange_service.h" #include "exchange_api_common.h" -#include "exchange_api_json.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -98,15 +98,16 @@ verify_deposit_wtid_signature_ok (const struct TALER_EXCHANGE_DepositWtidHandle struct TALER_ExchangeSignatureP exchange_sig; struct TALER_ExchangePublicKeyP exchange_pub; const struct TALER_EXCHANGE_Keys *key_state; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("exchange_sig", &exchange_sig), - MAJ_spec_fixed_auto ("exchange_pub", &exchange_pub), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig), + GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -161,16 +162,17 @@ handle_deposit_wtid_finished (void *cls, break; case MHD_HTTP_OK: { - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("wtid", &dwh->depconf.wtid), - MAJ_spec_absolute_time ("execution_time", &execution_time), - MAJ_spec_amount ("coin_contribution", &coin_contribution_s), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("wtid", &dwh->depconf.wtid), + GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time), + TALER_JSON_spec_amount ("coin_contribution", &coin_contribution_s), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); response_code = 0; @@ -193,14 +195,15 @@ handle_deposit_wtid_finished (void *cls, case MHD_HTTP_ACCEPTED: { /* Transaction known, but not executed yet */ - struct MAJ_Specification spec[] = { - MAJ_spec_absolute_time ("execution_time", &execution_time), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); response_code = 0; diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c index d4b3e4de..aaca8bac 100644 --- a/src/exchange-lib/exchange_api_handle.c +++ b/src/exchange-lib/exchange_api_handle.c @@ -22,13 +22,11 @@ */ #include "platform.h" #include -#include -#include #include +#include "taler_json_lib.h" #include "taler_exchange_service.h" #include "taler_signatures.h" #include "exchange_api_context.h" -#include "exchange_api_json.h" #include "exchange_api_handle.h" @@ -189,23 +187,24 @@ parse_json_signkey (struct TALER_EXCHANGE_SigningPublicKey *sign_key, struct GNUNET_TIME_Absolute valid_from; struct GNUNET_TIME_Absolute valid_until; struct GNUNET_TIME_Absolute valid_legal; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("master_sig", + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("master_sig", &sig), - MAJ_spec_fixed_auto ("key", + GNUNET_JSON_spec_fixed_auto ("key", &sign_key_issue.signkey_pub), - MAJ_spec_absolute_time ("stamp_start", + GNUNET_JSON_spec_absolute_time ("stamp_start", &valid_from), - MAJ_spec_absolute_time ("stamp_expire", + GNUNET_JSON_spec_absolute_time ("stamp_expire", &valid_until), - MAJ_spec_absolute_time ("stamp_end", + GNUNET_JSON_spec_absolute_time ("stamp_end", &valid_legal), - MAJ_spec_end + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (sign_key_obj, - spec)) + GNUNET_JSON_parse (sign_key_obj, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -264,33 +263,33 @@ parse_json_denomkey (struct TALER_EXCHANGE_DenomPublicKey *denom_key, struct GNUNET_CRYPTO_rsa_PublicKey *pk; struct GNUNET_CRYPTO_EddsaSignature sig; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("master_sig", + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("master_sig", &sig), - MAJ_spec_absolute_time ("stamp_expire_deposit", + GNUNET_JSON_spec_absolute_time ("stamp_expire_deposit", &deposit_valid_until), - MAJ_spec_absolute_time ("stamp_expire_withdraw", + GNUNET_JSON_spec_absolute_time ("stamp_expire_withdraw", &withdraw_valid_until), - MAJ_spec_absolute_time ("stamp_start", + GNUNET_JSON_spec_absolute_time ("stamp_start", &valid_from), - MAJ_spec_absolute_time ("stamp_expire_legal", + GNUNET_JSON_spec_absolute_time ("stamp_expire_legal", &expire_legal), - MAJ_spec_amount ("value", + TALER_JSON_spec_amount ("value", &value), - MAJ_spec_amount ("fee_withdraw", + TALER_JSON_spec_amount ("fee_withdraw", &fee_withdraw), - MAJ_spec_amount ("fee_deposit", + TALER_JSON_spec_amount ("fee_deposit", &fee_deposit), - MAJ_spec_amount ("fee_refresh", + TALER_JSON_spec_amount ("fee_refresh", &fee_refresh), - MAJ_spec_rsa_public_key ("denom_pub", + GNUNET_JSON_spec_rsa_public_key ("denom_pub", &pk), - MAJ_spec_end + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (denom_key_obj, - spec)) + GNUNET_JSON_parse (denom_key_obj, + spec, NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -337,7 +336,7 @@ parse_json_denomkey (struct TALER_EXCHANGE_DenomPublicKey *denom_key, return GNUNET_OK; EXITIF_exit: - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } @@ -362,18 +361,19 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, unsigned int off; unsigned int i; struct TALER_ExchangeKeyValidityPS kv; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("auditor_pub", + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("auditor_pub", &auditor->auditor_pub), - MAJ_spec_json ("denomination_keys", + GNUNET_JSON_spec_json ("denomination_keys", &keys), - MAJ_spec_end + GNUNET_JSON_spec_end() }; auditor->auditor_url = NULL; /* #3987 */ if (GNUNET_OK != - MAJ_parse_json (auditor_obj, - spec)) + GNUNET_JSON_parse (auditor_obj, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -391,17 +391,18 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, struct GNUNET_HashCode denom_h; const struct TALER_EXCHANGE_DenomPublicKey *dk; unsigned int j; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("denom_pub_h", + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("denom_pub_h", &denom_h), - MAJ_spec_fixed_auto ("auditor_sig", + GNUNET_JSON_spec_fixed_auto ("auditor_sig", &auditor_sig), - MAJ_spec_end + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (key, - spec)) + GNUNET_JSON_parse (key, + spec, + NULL, NULL)) { GNUNET_break_op (0); continue; @@ -476,21 +477,22 @@ decode_keys_json (json_t *resp_obj, hash_context = GNUNET_CRYPTO_hash_context_start (); /* parse the master public key and issue date of the response */ { - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("master_public_key", + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("master_public_key", &key_data->master_pub), - MAJ_spec_fixed_auto ("eddsa_sig", + GNUNET_JSON_spec_fixed_auto ("eddsa_sig", &sig), - MAJ_spec_fixed_auto ("eddsa_pub", + GNUNET_JSON_spec_fixed_auto ("eddsa_pub", &pub), - MAJ_spec_absolute_time ("list_issue_date", + GNUNET_JSON_spec_absolute_time ("list_issue_date", &list_issue_date), - MAJ_spec_end + GNUNET_JSON_spec_end() }; EXITIF (GNUNET_OK != - MAJ_parse_json (resp_obj, - spec)); + GNUNET_JSON_parse (resp_obj, + spec, + NULL, NULL)); } /* parse the signing keys */ diff --git a/src/exchange-lib/exchange_api_json.c b/src/exchange-lib/exchange_api_json.c deleted file mode 100644 index d6c54be5..00000000 --- a/src/exchange-lib/exchange_api_json.c +++ /dev/null @@ -1,541 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014, 2015 GNUnet e.V. - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License along with - TALER; see the file COPYING. If not, If not, see -*/ -/** - * @file exchange-lib/exchange_api_json.c - * @brief functions to parse incoming requests (JSON snippets) - * @author Florian Dold - * @author Benedikt Mueller - * @author Christian Grothoff - */ -#include "platform.h" -#include "exchange_api_json.h" -#include "taler_json_lib.h" - -/** - * Navigate and parse data in a JSON tree. - * - * @param root the JSON node to start the navigation at. - * @param spec parse specification array - * @return offset in @a spec where parsing failed, -1 on success (!) - */ -static int -parse_json (json_t *root, - struct MAJ_Specification *spec) -{ - int i; - json_t *pos; /* what's our current position? */ - - pos = root; - for (i=0;MAJ_CMD_END != spec[i].cmd;i++) - { - pos = json_object_get (root, - spec[i].field); - if (NULL == pos) - { - GNUNET_break_op (0); - return i; - } - switch (spec[i].cmd) - { - case MAJ_CMD_END: - GNUNET_assert (0); - return i; - case MAJ_CMD_AMOUNT: - { - struct GNUNET_JSON_Specification nspec[] = { - TALER_JSON_spec_amount (NULL, spec[i].details.amount), - GNUNET_JSON_spec_end () - }; - - if (GNUNET_OK != - GNUNET_JSON_parse (pos, - nspec, - NULL, NULL)) - { - GNUNET_break_op (0); - return i; - } - break; - } - case MAJ_CMD_TIME_ABSOLUTE: - { - struct GNUNET_JSON_Specification nspec[] = { - GNUNET_JSON_spec_absolute_time (NULL, spec[i].details.abs_time), - GNUNET_JSON_spec_end () - }; - - if (GNUNET_OK != - GNUNET_JSON_parse (pos, - nspec, - NULL, NULL)) - { - GNUNET_break_op (0); - return i; - } - break; - } - case MAJ_CMD_STRING: - { - const char *str; - - str = json_string_value (pos); - if (NULL == str) - { - GNUNET_break_op (0); - return i; - } - *spec[i].details.strptr = str; - } - break; - - case MAJ_CMD_BINARY_FIXED: - { - const char *str; - int res; - - str = json_string_value (pos); - if (NULL == str) - { - GNUNET_break_op (0); - return i; - } - res = GNUNET_STRINGS_string_to_data (str, strlen (str), - spec[i].details.fixed_data.dest, - spec[i].details.fixed_data.dest_size); - if (GNUNET_OK != res) - { - GNUNET_break_op (0); - return i; - } - } - break; - - case MAJ_CMD_BINARY_VARIABLE: - { - const char *str; - size_t size; - void *data; - int res; - - str = json_string_value (pos); - if (NULL == str) - { - GNUNET_break_op (0); - return i; - } - size = (strlen (str) * 5) / 8; - if (size >= 1024) - { - GNUNET_break_op (0); - return i; - } - data = GNUNET_malloc (size); - res = GNUNET_STRINGS_string_to_data (str, - strlen (str), - data, - size); - if (GNUNET_OK != res) - { - GNUNET_break_op (0); - GNUNET_free (data); - return i; - } - *spec[i].details.variable_data.dest_p = data; - *spec[i].details.variable_data.dest_size_p = size; - } - break; - - case MAJ_CMD_RSA_PUBLIC_KEY: - { - size_t size; - const char *str; - int res; - void *buf; - - str = json_string_value (pos); - if (NULL == str) - { - GNUNET_break_op (0); - return i; - } - size = (strlen (str) * 5) / 8; - buf = GNUNET_malloc (size); - res = GNUNET_STRINGS_string_to_data (str, - strlen (str), - buf, - size); - if (GNUNET_OK != res) - { - GNUNET_free (buf); - GNUNET_break_op (0); - return i; - } - *spec[i].details.rsa_public_key - = GNUNET_CRYPTO_rsa_public_key_decode (buf, - size); - GNUNET_free (buf); - if (NULL == spec[i].details.rsa_public_key) - { - GNUNET_break_op (0); - return i; - } - } - break; - - case MAJ_CMD_RSA_SIGNATURE: - { - size_t size; - const char *str; - int res; - void *buf; - - str = json_string_value (pos); - if (NULL == str) - { - GNUNET_break_op (0); - return i; - } - size = (strlen (str) * 5) / 8; - buf = GNUNET_malloc (size); - res = GNUNET_STRINGS_string_to_data (str, - strlen (str), - buf, - size); - if (GNUNET_OK != res) - { - GNUNET_free (buf); - GNUNET_break_op (0); - return i; - } - *spec[i].details.rsa_signature - = GNUNET_CRYPTO_rsa_signature_decode (buf, - size); - GNUNET_free (buf); - if (NULL == spec[i].details.rsa_signature) - return i; - } - break; - - case MAJ_CMD_UINT16: - { - json_int_t val; - - if (! json_is_integer (pos)) - { - GNUNET_break_op (0); - return i; - } - val = json_integer_value (pos); - if ( (0 > val) || (val > UINT16_MAX) ) - { - GNUNET_break_op (0); - return i; - } - *spec[i].details.u16 = (uint16_t) val; - } - break; - - case MAJ_CMD_UINT64: - { - json_int_t val; - - if (! json_is_integer (pos)) - { - GNUNET_break_op (0); - return i; - } - val = json_integer_value (pos); - *spec[i].details.u64 = (uint64_t) val; - } - break; - - case MAJ_CMD_JSON_OBJECT: - { - if (! (json_is_object (pos) || json_is_array (pos)) ) - { - GNUNET_break_op (0); - return i; - } - json_incref (pos); - *spec[i].details.obj = pos; - } - break; - - default: - GNUNET_break (0); - return i; - } - } - return -1; /* all OK! */ -} - - -/** - * Free all elements allocated during a - * #MAJ_parse_json() operation. - * - * @param spec specification of the parse operation - * @param end number of elements in @a spec to process - */ -static void -parse_free (struct MAJ_Specification *spec, - int end) -{ - int i; - - for (i=0;i -*/ -/** - * @file exchange-lib/exchange_api_json.h - * @brief functions to parse incoming requests (JSON snippets) - * @author Florian Dold - * @author Benedikt Mueller - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include "taler_util.h" -#include - - -/** - * Enumeration with the various commands for the - * #MAJ_parse_json interpreter. - */ -enum MAJ_Command -{ - - /** - * End of command list. - */ - MAJ_CMD_END, - - /** - * Parse amount at current position. - */ - MAJ_CMD_AMOUNT, - - /** - * Parse absolute time at current position. - */ - MAJ_CMD_TIME_ABSOLUTE, - - /** - * Parse fixed binary value at current position. - */ - MAJ_CMD_BINARY_FIXED, - - /** - * Parse variable-size binary value at current position. - */ - MAJ_CMD_BINARY_VARIABLE, - - /** - * Parse RSA public key at current position. - */ - MAJ_CMD_RSA_PUBLIC_KEY, - - /** - * Parse RSA signature at current position. - */ - MAJ_CMD_RSA_SIGNATURE, - - /** - * Parse `const char *` JSON string at current position. - */ - MAJ_CMD_STRING, - - /** - * Parse `uint16_t` integer at the current position. - */ - MAJ_CMD_UINT16, - - /** - * Parse `uint64_t` integer at the current position. - */ - MAJ_CMD_UINT64, - - /** - * Parse JSON object at the current position. - */ - MAJ_CMD_JSON_OBJECT, - - /** - * Parse ??? at current position. - */ - MAJ_CMD_C - -}; - - -/** - * @brief Entry in parser specification for #MAJ_parse_json. - */ -struct MAJ_Specification -{ - - /** - * Command to execute. - */ - enum MAJ_Command cmd; - - /** - * Name of the field to access. - */ - const char *field; - - /** - * Further details for the command. - */ - union { - - /** - * Where to store amount for #MAJ_CMD_AMOUNT. - */ - struct TALER_Amount *amount; - - /** - * Where to store time, for #MAJ_CMD_TIME_ABSOLUTE. - */ - struct GNUNET_TIME_Absolute *abs_time; - - /** - * Where to write binary data, for #MAJ_CMD_BINARY_FIXED. - */ - struct { - /** - * Where to write the data. - */ - void *dest; - - /** - * How many bytes to write to @e dest. - */ - size_t dest_size; - - } fixed_data; - - /** - * Where to write binary data, for #MAJ_CMD_BINARY_VARIABLE. - */ - struct { - /** - * Where to store the pointer with the data (is allocated). - */ - void **dest_p; - - /** - * Where to store the number of bytes allocated at `*dest`. - */ - size_t *dest_size_p; - - } variable_data; - - /** - * Where to store the RSA public key for #MAJ_CMD_RSA_PUBLIC_KEY - */ - struct GNUNET_CRYPTO_rsa_PublicKey **rsa_public_key; - - /** - * Where to store the RSA signature for #MAJ_CMD_RSA_SIGNATURE - */ - struct GNUNET_CRYPTO_rsa_Signature **rsa_signature; - - /** - * Details for #MAJ_CMD_EDDSA_SIGNATURE - */ - struct { - - /** - * Where to store the purpose. - */ - struct GNUNET_CRYPTO_EccSignaturePurpose **purpose_p; - - /** - * Key to verify the signature against. - */ - const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key; - - } eddsa_signature; - - /** - * Where to store a pointer to the string. - */ - const char **strptr; - - /** - * Where to store 16-bit integer. - */ - uint16_t *u16; - - /** - * Where to store 64-bit integer. - */ - uint64_t *u64; - - /** - * Where to store a JSON object. - */ - json_t **obj; - - } details; - -}; - - -/** - * Navigate and parse data in a JSON tree. - * - * @param root the JSON node to start the navigation at. - * @param spec parse specification array - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int -MAJ_parse_json (const json_t *root, - struct MAJ_Specification *spec); - - -/** - * Free all elements allocated during a - * #MAJ_parse_json() operation. - * - * @param spec specification of the parse operation - */ -void -MAJ_parse_free (struct MAJ_Specification *spec); - - -/** - * End of a parser specification. - */ -#define MAJ_spec_end { .cmd = MAJ_CMD_END } - -/** - * Fixed size object (in network byte order, encoded using Crockford - * Base32hex encoding). - * - * @param name name of the JSON field - * @param obj pointer where to write the data (type of `*obj` will determine size) - */ -#define MAJ_spec_fixed_auto(name,obj) { .cmd = MAJ_CMD_BINARY_FIXED, .field = name, .details.fixed_data.dest = obj, .details.fixed_data.dest_size = sizeof (*obj) } - - -/** - * Variable size object (in network byte order, encoded using Crockford - * Base32hex encoding). - * - * @param name name of the JSON field - * @param obj pointer where to write the data (a `void **`) - * @param size where to store the number of bytes allocated for @a obj (of type `size_t *` - */ -#define MAJ_spec_varsize(name,obj,size) { .cmd = MAJ_CMD_BINARY_VARIABLE, .field = name, .details.variable_data.dest_p = obj, .details.variable_data.dest_size_p = size } - - -/** - * The expected field stores a string. - * - * @param name name of the JSON field - * @param strptr where to store a pointer to the field - */ -struct MAJ_Specification -MAJ_spec_string (const char *name, - const char **strptr); - - -/** - * Absolute time. - * - * @param name name of the JSON field - * @param[out] at where to store the absolute time found under @a name - */ -struct MAJ_Specification -MAJ_spec_absolute_time (const char *name, - struct GNUNET_TIME_Absolute *at); - - -/** - * 16-bit integer. - * - * @param name name of the JSON field - * @param[out] u16 where to store the integer found under @a name - */ -struct MAJ_Specification -MAJ_spec_uint16 (const char *name, - uint16_t *u16); - - -/** - * 64-bit integer. - * - * @param name name of the JSON field - * @param[out] u64 where to store the integer found under @a name - */ -struct MAJ_Specification -MAJ_spec_uint64 (const char *name, - uint64_t *u64); - - -/** - * JSON object. - * - * @param name name of the JSON field - * @param[out] jsonp where to store the JSON found under @a name - */ -struct MAJ_Specification -MAJ_spec_json (const char *name, - json_t **jsonp); - - -/** - * Specification for parsing an amount value. - * - * @param name name of the JSON field - * @param amount where to store the amount under @a name - */ -struct MAJ_Specification -MAJ_spec_amount (const char *name, - struct TALER_Amount *amount); - - -/** - * Specification for parsing an RSA public key. - * - * @param name name of the JSON field - * @param pk where to store the RSA key found under @a name - */ -struct MAJ_Specification -MAJ_spec_rsa_public_key (const char *name, - struct GNUNET_CRYPTO_rsa_PublicKey **pk); - - -/** - * Specification for parsing an RSA signature. - * - * @param name name of the JSON field - * @param sig where to store the RSA signature found under @a name - */ -struct MAJ_Specification -MAJ_spec_rsa_signature (const char *name, - struct GNUNET_CRYPTO_rsa_Signature **sig); - - - - -/* end of exchange_api_json.h */ diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c index bcec1354..2949cf1e 100644 --- a/src/exchange-lib/exchange_api_refresh.c +++ b/src/exchange-lib/exchange_api_refresh.c @@ -28,7 +28,6 @@ #include "taler_json_lib.h" #include "taler_exchange_service.h" #include "exchange_api_common.h" -#include "exchange_api_json.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -1086,17 +1085,18 @@ verify_refresh_melt_signature_ok (struct TALER_EXCHANGE_RefreshMeltHandle *rmh, struct TALER_ExchangeSignatureP exchange_sig; struct TALER_ExchangePublicKeyP exchange_pub; const struct TALER_EXCHANGE_Keys *key_state; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("exchange_sig", &exchange_sig), - MAJ_spec_fixed_auto ("exchange_pub", &exchange_pub), - MAJ_spec_uint16 ("noreveal_index", noreveal_index), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig), + GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), + GNUNET_JSON_spec_uint16 ("noreveal_index", noreveal_index), + GNUNET_JSON_spec_end() }; struct TALER_RefreshMeltConfirmationPS confirm; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1156,19 +1156,20 @@ verify_refresh_melt_signature_forbidden (struct TALER_EXCHANGE_RefreshMeltHandle struct TALER_Amount total; struct TALER_CoinSpendPublicKeyP coin_pub; unsigned int i; - struct MAJ_Specification spec[] = { - MAJ_spec_json ("history", &history), - MAJ_spec_fixed_auto ("coin_pub", &coin_pub), - MAJ_spec_amount ("original_value", &original_value), - MAJ_spec_amount ("requested_value", &melt_value_with_fee), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_json ("history", &history), + GNUNET_JSON_spec_fixed_auto ("coin_pub", &coin_pub), + TALER_JSON_spec_amount ("original_value", &original_value), + TALER_JSON_spec_amount ("requested_value", &melt_value_with_fee), + GNUNET_JSON_spec_end() }; const struct MeltedCoin *mc; /* parse JSON reply */ if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1731,14 +1732,15 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh, { unsigned int i; json_t *jsona; - struct MAJ_Specification spec[] = { - MAJ_spec_json ("ev_sigs", &jsona), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_json ("ev_sigs", &jsona), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1765,9 +1767,9 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh, struct TALER_CoinSpendPublicKeyP coin_pub; struct GNUNET_HashCode coin_hash; - struct MAJ_Specification spec[] = { - MAJ_spec_rsa_signature ("ev_sig", &blind_sig), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_rsa_signature ("ev_sig", &blind_sig), + GNUNET_JSON_spec_end() }; fc = &rrh->md->fresh_coins[rrh->noreveal_index][i]; @@ -1776,8 +1778,9 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh, GNUNET_assert (NULL != jsonai); if (GNUNET_OK != - MAJ_parse_json (jsonai, - spec)) + GNUNET_JSON_parse (jsonai, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; diff --git a/src/exchange-lib/exchange_api_refresh_link.c b/src/exchange-lib/exchange_api_refresh_link.c index 9576916b..41d421f5 100644 --- a/src/exchange-lib/exchange_api_refresh_link.c +++ b/src/exchange-lib/exchange_api_refresh_link.c @@ -21,11 +21,10 @@ */ #include "platform.h" #include -#include #include /* just for HTTP status codes */ #include #include "taler_exchange_service.h" -#include "exchange_api_json.h" +#include "taler_json_lib.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -101,11 +100,11 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh, size_t link_enc_size; struct GNUNET_CRYPTO_rsa_Signature *bsig; struct GNUNET_CRYPTO_rsa_PublicKey *rpub; - struct MAJ_Specification spec[] = { - MAJ_spec_varsize ("link_enc", &link_enc, &link_enc_size), - MAJ_spec_rsa_public_key ("denom_pub", &rpub), - MAJ_spec_rsa_signature ("ev_sig", &bsig), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_varsize ("link_enc", &link_enc, &link_enc_size), + GNUNET_JSON_spec_rsa_public_key ("denom_pub", &rpub), + GNUNET_JSON_spec_rsa_signature ("ev_sig", &bsig), + GNUNET_JSON_spec_end() }; struct TALER_RefreshLinkEncrypted *rle; struct TALER_RefreshLinkDecrypted *rld; @@ -113,8 +112,9 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh, /* parse reply */ if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -126,7 +126,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh, if (NULL == rle) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -136,7 +136,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh, &secret)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } rld = TALER_refresh_decrypt (rle, @@ -144,7 +144,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh, if (NULL == rld) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } @@ -158,7 +158,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh, /* clean up */ GNUNET_free (rld); pub->rsa_public_key = GNUNET_CRYPTO_rsa_public_key_dup (rpub); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return GNUNET_OK; } @@ -199,15 +199,16 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh, for (session=0;session #include #include "taler_exchange_service.h" -#include "exchange_api_json.h" +#include "taler_json_lib.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -117,19 +117,20 @@ parse_reserve_history (json_t *history, json_t *transaction; struct TALER_Amount amount; const char *type; - struct MAJ_Specification hist_spec[] = { - MAJ_spec_string ("type", &type), - MAJ_spec_amount ("amount", + struct GNUNET_JSON_Specification hist_spec[] = { + GNUNET_JSON_spec_string ("type", &type), + TALER_JSON_spec_amount ("amount", &amount), /* 'wire' and 'signature' are optional depending on 'type'! */ - MAJ_spec_end + GNUNET_JSON_spec_end() }; transaction = json_array_get (history, off); if (GNUNET_OK != - MAJ_parse_json (transaction, - hist_spec)) + GNUNET_JSON_parse (transaction, + hist_spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -171,19 +172,20 @@ parse_reserve_history (json_t *history, struct TALER_ReserveSignatureP sig; struct TALER_WithdrawRequestPS withdraw_purpose; struct TALER_Amount amount_from_purpose; - struct MAJ_Specification withdraw_spec[] = { - MAJ_spec_fixed_auto ("signature", + struct GNUNET_JSON_Specification withdraw_spec[] = { + GNUNET_JSON_spec_fixed_auto ("signature", &sig), - MAJ_spec_fixed_auto ("details", + GNUNET_JSON_spec_fixed_auto ("details", &withdraw_purpose), - MAJ_spec_end + GNUNET_JSON_spec_end() }; unsigned int i; rhistory[off].type = TALER_EXCHANGE_RTT_WITHDRAWAL; if (GNUNET_OK != - MAJ_parse_json (transaction, - withdraw_spec)) + GNUNET_JSON_parse (transaction, + withdraw_spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -196,7 +198,7 @@ parse_reserve_history (json_t *history, &reserve_pub->eddsa_pub)) { GNUNET_break_op (0); - MAJ_parse_free (withdraw_spec); + GNUNET_JSON_parse_free (withdraw_spec); return GNUNET_SYSERR; } TALER_amount_ntoh (&amount_from_purpose, @@ -205,7 +207,7 @@ parse_reserve_history (json_t *history, &amount_from_purpose)) { GNUNET_break_op (0); - MAJ_parse_free (withdraw_spec); + GNUNET_JSON_parse_free (withdraw_spec); return GNUNET_SYSERR; } rhistory[off].details.out_authorization_sig = json_object_get (transaction, @@ -225,7 +227,7 @@ parse_reserve_history (json_t *history, sizeof (struct GNUNET_HashCode))) { GNUNET_break_op (0); - MAJ_parse_free (withdraw_spec); + GNUNET_JSON_parse_free (withdraw_spec); return GNUNET_SYSERR; } } @@ -238,7 +240,7 @@ parse_reserve_history (json_t *history, { /* overflow in history already!? inconceivable! Bad exchange! */ GNUNET_break_op (0); - MAJ_parse_free (withdraw_spec); + GNUNET_JSON_parse_free (withdraw_spec); return GNUNET_SYSERR; } /* end type==WITHDRAW */ @@ -296,14 +298,15 @@ handle_reserve_status_finished (void *cls, unsigned int len; struct TALER_Amount balance; struct TALER_Amount balance_from_history; - struct MAJ_Specification spec[] = { - MAJ_spec_amount ("balance", &balance), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_amount ("balance", &balance), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); response_code = 0; @@ -563,14 +566,15 @@ reserve_withdraw_ok (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh, struct GNUNET_CRYPTO_rsa_Signature *blind_sig; struct GNUNET_CRYPTO_rsa_Signature *sig; struct TALER_DenominationSignature dsig; - struct MAJ_Specification spec[] = { - MAJ_spec_rsa_signature ("ev_sig", &blind_sig), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_rsa_signature ("ev_sig", &blind_sig), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -622,14 +626,15 @@ reserve_withdraw_payment_required (struct TALER_EXCHANGE_ReserveWithdrawHandle * struct TALER_Amount requested_amount; json_t *history; size_t len; - struct MAJ_Specification spec[] = { - MAJ_spec_amount ("balance", &balance), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_amount ("balance", &balance), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return GNUNET_SYSERR; diff --git a/src/exchange-lib/exchange_api_wire.c b/src/exchange-lib/exchange_api_wire.c index 35c443ff..27ae1dce 100644 --- a/src/exchange-lib/exchange_api_wire.c +++ b/src/exchange-lib/exchange_api_wire.c @@ -25,9 +25,9 @@ #include /* just for HTTP status codes */ #include #include "taler_exchange_service.h" +#include "taler_json_lib.h" #include "taler_wire_plugin.h" #include "exchange_api_common.h" -#include "exchange_api_json.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" @@ -311,17 +311,18 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh, json_t *methods; const struct TALER_EXCHANGE_Keys *key_state; struct GNUNET_HashContext *hc; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("sig", &exchange_sig), - MAJ_spec_fixed_auto ("pub", &exchange_pub), - MAJ_spec_json ("methods", &methods), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("sig", &exchange_sig), + GNUNET_JSON_spec_fixed_auto ("pub", &exchange_pub), + GNUNET_JSON_spec_json ("methods", &methods), + GNUNET_JSON_spec_end() }; unsigned int i; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); return NULL; @@ -329,7 +330,7 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh, if (! json_is_array (methods)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return NULL; } @@ -351,7 +352,7 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh, { GNUNET_CRYPTO_hash_context_abort (hc); GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return NULL; } method = json_string_value (element); @@ -371,7 +372,7 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh, &exchange_pub.eddsa_pub)) { GNUNET_break_op (0); - MAJ_parse_free (spec); + GNUNET_JSON_parse_free (spec); return NULL; } return methods; diff --git a/src/exchange-lib/exchange_api_wire_deposits.c b/src/exchange-lib/exchange_api_wire_deposits.c index 40625602..0112f856 100644 --- a/src/exchange-lib/exchange_api_wire_deposits.c +++ b/src/exchange-lib/exchange_api_wire_deposits.c @@ -24,10 +24,9 @@ #include #include /* just for HTTP status codes */ #include -#include #include "taler_exchange_service.h" #include "exchange_api_common.h" -#include "exchange_api_json.h" +#include "taler_json_lib.h" #include "exchange_api_context.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -102,17 +101,18 @@ handle_wire_deposits_finished (void *cls, struct TALER_Amount total_amount; struct TALER_MerchantPublicKeyP merchant_pub; unsigned int num_details; - struct MAJ_Specification spec[] = { - MAJ_spec_fixed_auto ("H_wire", &h_wire), - MAJ_spec_fixed_auto ("merchant_pub", &merchant_pub), - MAJ_spec_amount ("total_amount", &total_amount), - MAJ_spec_json ("details", &details_j), - MAJ_spec_end + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("H_wire", &h_wire), + GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), + TALER_JSON_spec_amount ("total_amount", &total_amount), + GNUNET_JSON_spec_json ("details", &details_j), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (json, - spec)) + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { GNUNET_break_op (0); response_code = 0; @@ -127,18 +127,19 @@ handle_wire_deposits_finished (void *cls, { struct TALER_WireDepositDetails *detail = &details[i]; struct json_t *detail_j = json_array_get (details_j, i); - struct MAJ_Specification spec_detail[] = { - MAJ_spec_fixed_auto ("H_contract", &detail->h_contract), - MAJ_spec_amount ("deposit_value", &detail->coin_value), - MAJ_spec_amount ("deposit_fee", &detail->coin_fee), - MAJ_spec_uint64 ("transaction_id", &detail->transaction_id), - MAJ_spec_fixed_auto ("coin_pub", &detail->coin_pub), - MAJ_spec_end + struct GNUNET_JSON_Specification spec_detail[] = { + GNUNET_JSON_spec_fixed_auto ("H_contract", &detail->h_contract), + TALER_JSON_spec_amount ("deposit_value", &detail->coin_value), + TALER_JSON_spec_amount ("deposit_fee", &detail->coin_fee), + GNUNET_JSON_spec_uint64 ("transaction_id", &detail->transaction_id), + GNUNET_JSON_spec_fixed_auto ("coin_pub", &detail->coin_pub), + GNUNET_JSON_spec_end() }; if (GNUNET_OK != - MAJ_parse_json (detail_j, - spec_detail)) + GNUNET_JSON_parse (detail_j, + spec_detail, + NULL, NULL)) { GNUNET_break_op (0); response_code = 0; -- cgit v1.2.3 From 6f8fa678c1f4672165cd82ddb43ec3546d9552a9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 21 Mar 2016 01:45:53 +0100 Subject: implementing #3987 --- doc/taler-auditor-sign.1 | 5 +- src/exchange-lib/exchange_api_handle.c | 12 +++- src/exchange-tools/taler-auditor-sign.c | 31 +++++++--- src/exchange/taler-exchange-httpd_keystate.c | 10 ++- src/exchangedb/exchangedb_keyio.c | 92 +++++++++++++++++++++------- src/include/taler_exchange_service.h | 20 +++--- src/include/taler_exchangedb_lib.h | 51 +++++++-------- src/include/taler_signatures.h | 7 ++- 8 files changed, 159 insertions(+), 69 deletions(-) (limited to 'src/exchange-lib/exchange_api_handle.c') diff --git a/doc/taler-auditor-sign.1 b/doc/taler-auditor-sign.1 index 177d0df0..f0f90a5b 100644 --- a/doc/taler-auditor-sign.1 +++ b/doc/taler-auditor-sign.1 @@ -1,4 +1,4 @@ -.TH TALER\-AUDITOR\-SIGN 1 "Sep 15, 2015" "GNU Taler" +.TH TALER\-AUDITOR\-SIGN 1 "Mar 15, 2016" "GNU Taler" .SH NAME taler\-auditor\-sign \- Sign exchange denomination as auditor. @@ -22,6 +22,9 @@ Print short help on options. .IP "\-m KEY, \-\-exchange-key=KEY" Public key of the exchange in Crockford base32 encoding, for example as generated by gnunet\-ecc \-p. .B +.IP "\-u URL, \-\-auditor-url=URL" +URL of the auditor. Provides informative link for the user to learn more about the auditor. +.B .IP "\-r FILE, \-\-exchange-request=FILE" File with the exchange's denomination key signing request as generated by taler\-exchange\-keyup \-o. .B diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c index aaca8bac..26f5e7e1 100644 --- a/src/exchange-lib/exchange_api_handle.c +++ b/src/exchange-lib/exchange_api_handle.c @@ -360,16 +360,18 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, unsigned int len; unsigned int off; unsigned int i; + const char *auditor_url; struct TALER_ExchangeKeyValidityPS kv; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("auditor_pub", - &auditor->auditor_pub), + &auditor->auditor_pub), + GNUNET_JSON_spec_string ("auditor_url", + &auditor_url), GNUNET_JSON_spec_json ("denomination_keys", - &keys), + &keys), GNUNET_JSON_spec_end() }; - auditor->auditor_url = NULL; /* #3987 */ if (GNUNET_OK != GNUNET_JSON_parse (auditor_obj, spec, @@ -378,8 +380,12 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, GNUNET_break_op (0); return GNUNET_SYSERR; } + auditor->auditor_url = GNUNET_strdup (auditor_url); kv.purpose.purpose = htonl (TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS); kv.purpose.size = htonl (sizeof (struct TALER_ExchangeKeyValidityPS)); + GNUNET_CRYPTO_hash (auditor_url, + strlen (auditor_url) + 1, + &kv.auditor_url_hash); kv.master = key_data->master_pub; len = json_array_size (keys); auditor->denom_keys = GNUNET_new_array (len, diff --git a/src/exchange-tools/taler-auditor-sign.c b/src/exchange-tools/taler-auditor-sign.c index e4821f41..bde34b2a 100644 --- a/src/exchange-tools/taler-auditor-sign.c +++ b/src/exchange-tools/taler-auditor-sign.c @@ -49,6 +49,11 @@ static char *exchange_request_file; */ static char *output_file; +/** + * URL of the auditor (informative for the user). + */ +static char *auditor_url; + /** * Master public key of the exchange. */ @@ -134,6 +139,10 @@ main (int argc, {'m', "exchange-key", "KEY", "public key of the exchange (Crockford base32 encoded)", 1, &GNUNET_GETOPT_set_filename, &exchange_public_key}, + {'u', "auditor-url", "URL", + "URL of the auditor (informative link for the user)", 1, + &GNUNET_GETOPT_set_string, &auditor_url}, + TALER_GETOPT_OPTION_HELP ("Private key of the auditor to use for signing"), {'r', "exchange-request", "FILE", "set of keys the exchange requested the auditor to sign", 1, &GNUNET_GETOPT_set_string, &exchange_request_file}, @@ -168,6 +177,12 @@ main (int argc, "Auditor key file not given\n"); return 1; } + if (NULL == auditor_url) + { + fprintf (stderr, + "Auditor URL not given\n"); + return 1; + } eddsa_priv = GNUNET_CRYPTO_eddsa_key_create_from_file (auditor_key_file); if (NULL == eddsa_priv) { @@ -240,6 +255,9 @@ main (int argc, dks_len = in_size / sizeof (struct TALER_DenominationKeyValidityPS); kv.purpose.purpose = htonl (TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS); kv.purpose.size = htonl (sizeof (struct TALER_ExchangeKeyValidityPS)); + GNUNET_CRYPTO_hash (auditor_url, + strlen (auditor_url) + 1, + &kv.auditor_url_hash); kv.master = master_public_key; dks = GNUNET_new_array (dks_len, struct TALER_DenominationKeyValidityPS); @@ -281,8 +299,6 @@ main (int argc, GNUNET_CRYPTO_eddsa_sign (eddsa_priv, &kv.purpose, &sigs[i].eddsa_sig); - - } if (NULL == output_file) @@ -298,11 +314,12 @@ main (int argc, /* write result to disk */ if (GNUNET_OK != TALER_EXCHANGEDB_auditor_write (output_file, - &apub, - sigs, - &master_public_key, - dks_len, - dks)) + &apub, + auditor_url, + sigs, + &master_public_key, + dks_len, + dks)) { fprintf (stderr, "Failed to write to file `%s': %s\n", diff --git a/src/exchange/taler-exchange-httpd_keystate.c b/src/exchange/taler-exchange-httpd_keystate.c index bf91b818..dbb72fab 100644 --- a/src/exchange/taler-exchange-httpd_keystate.c +++ b/src/exchange/taler-exchange-httpd_keystate.c @@ -419,6 +419,7 @@ reload_keys_sign_iter (void *cls, * Convert information from an auditor to a JSON object. * * @param apub the auditor's public key + * @param auditor_url URL of the auditor * @param dki_len length of @a dki and @a asigs arrays * @param asigs the auditor's signatures * @param dki array of denomination coin data signed by the auditor @@ -426,6 +427,7 @@ reload_keys_sign_iter (void *cls, */ static json_t * auditor_to_json (const struct TALER_AuditorPublicKeyP *apub, + const char *auditor_url, unsigned int dki_len, const struct TALER_AuditorSignatureP **asigs, const struct TALER_DenominationKeyValidityPS **dki) @@ -442,10 +444,11 @@ auditor_to_json (const struct TALER_AuditorPublicKeyP *apub, sizeof (struct GNUNET_HashCode)), "auditor_sig", GNUNET_JSON_from_data (asigs[i], - sizeof (struct TALER_AuditorSignatureP)))); + sizeof (struct TALER_AuditorSignatureP)))); return - json_pack ("{s:o, s:o}", + json_pack ("{s:o, s:s, s:o}", "denomination_keys", ja, + "auditor_url", auditor_url, "auditor_pub", GNUNET_JSON_from_data (apub, sizeof (struct TALER_AuditorPublicKeyP))); @@ -460,6 +463,7 @@ auditor_to_json (const struct TALER_AuditorPublicKeyP *apub, * * @param cls closure with the `struct TMH_KS_StateHandle *` * @param apub the auditor's public key + * @param auditor_url URL of the auditor * @param mpub the exchange's public key (as expected by the auditor) * @param dki_len length of @a dki and @a asigs * @param asigs array with the auditor's signatures, of length @a dki_len @@ -471,6 +475,7 @@ auditor_to_json (const struct TALER_AuditorPublicKeyP *apub, static int reload_auditor_iter (void *cls, const struct TALER_AuditorPublicKeyP *apub, + const char *auditor_url, const struct TALER_MasterPublicKeyP *mpub, unsigned int dki_len, const struct TALER_AuditorSignatureP *asigs, @@ -508,6 +513,7 @@ reload_auditor_iter (void *cls, /* add auditor information to our /keys response */ json_array_append_new (ctx->auditors_array, auditor_to_json (apub, + auditor_url, keep, kept_asigs, kept_dkis)); diff --git a/src/exchangedb/exchangedb_keyio.c b/src/exchangedb/exchangedb_keyio.c index 6b8ca24e..e560e8d6 100644 --- a/src/exchangedb/exchangedb_keyio.c +++ b/src/exchangedb/exchangedb_keyio.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014, 2015 GNUnet e.V. + Copyright (C) 2014, 2015, 2016 Inria & GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -93,8 +93,8 @@ signkeys_iterate_dir_iter (void *cls, */ int TALER_EXCHANGEDB_signing_keys_iterate (const char *exchange_base_dir, - TALER_EXCHANGEDB_SigningKeyIterator it, - void *it_cls) + TALER_EXCHANGEDB_SigningKeyIterator it, + void *it_cls) { char *signkey_dir; struct SignkeysIterateContext skc; @@ -123,7 +123,7 @@ TALER_EXCHANGEDB_signing_keys_iterate (const char *exchange_base_dir, */ int TALER_EXCHANGEDB_denomination_key_read (const char *filename, - struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki) + struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki) { uint64_t size; size_t offset; @@ -186,7 +186,7 @@ TALER_EXCHANGEDB_denomination_key_read (const char *filename, */ int TALER_EXCHANGEDB_denomination_key_write (const char *filename, - const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki) + const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki) { char *priv_enc; size_t priv_enc_size; @@ -331,8 +331,8 @@ denomkeys_iterate_topdir_iter (void *cls, */ int TALER_EXCHANGEDB_denomination_keys_iterate (const char *exchange_base_dir, - TALER_EXCHANGEDB_DenominationKeyIterator it, - void *it_cls) + TALER_EXCHANGEDB_DenominationKeyIterator it, + void *it_cls) { char *dir; struct DenomkeysIterateContext dic; @@ -388,6 +388,11 @@ struct AuditorFileHeaderP */ struct TALER_MasterPublicKeyP mpub; + /** + * Number of signatures and DKI entries in this file. + */ + uint32_t dki_len; + }; GNUNET_NETWORK_STRUCT_END @@ -412,7 +417,9 @@ auditor_iter (void *cls, struct AuditorFileHeaderP *af; const struct TALER_AuditorSignatureP *sigs; const struct TALER_DenominationKeyValidityPS *dki; - unsigned int len; + const char *auditor_url; + unsigned int dki_len; + size_t url_len; int ret; if (GNUNET_OK != GNUNET_DISK_file_size (filename, @@ -425,10 +432,7 @@ auditor_iter (void *cls, filename); return GNUNET_SYSERR; } - if ( (size < sizeof (struct AuditorFileHeaderP)) || - (0 != (len = ((size - sizeof (struct AuditorFileHeaderP)) % - (sizeof (struct TALER_DenominationKeyValidityPS) + - sizeof (struct TALER_AuditorSignatureP))))) ) + if (size < sizeof (struct AuditorFileHeaderP)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -445,12 +449,49 @@ auditor_iter (void *cls, GNUNET_free (af); return GNUNET_SYSERR; } + dki_len = ntohl (af->dki_len); + if (0 == dki_len) + { + GNUNET_break_op (0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "No signed keys in %s\n", + filename); + GNUNET_free (af); + return GNUNET_SYSERR; + } + if ( (size - sizeof (struct AuditorFileHeaderP)) / dki_len < + (sizeof (struct TALER_DenominationKeyValidityPS) + + sizeof (struct TALER_AuditorSignatureP)) ) + { + GNUNET_break_op (0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Malformed key file %s\n", + filename); + GNUNET_free (af); + return GNUNET_SYSERR; + } + url_len = size + - sizeof (struct AuditorFileHeaderP) + - dki_len * (sizeof (struct TALER_DenominationKeyValidityPS) + + sizeof (struct TALER_AuditorSignatureP)); sigs = (const struct TALER_AuditorSignatureP *) &af[1]; - dki = (const struct TALER_DenominationKeyValidityPS *) &sigs[len]; + dki = (const struct TALER_DenominationKeyValidityPS *) &sigs[dki_len]; + auditor_url = (const char *) &dki[dki_len]; + if ( (0 == url_len) || + ('\0' != auditor_url[url_len - 1]) ) + { + GNUNET_break_op (0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Malformed key file %s\n", + filename); + GNUNET_free (af); + return GNUNET_SYSERR; + } ret = aic->it (aic->it_cls, &af->apub, + auditor_url, &af->mpub, - len, + dki_len, sigs, dki); GNUNET_free (af); @@ -473,8 +514,8 @@ auditor_iter (void *cls, */ int TALER_EXCHANGEDB_auditor_iterate (const char *exchange_base_dir, - TALER_EXCHANGEDB_AuditorIterator it, - void *it_cls) + TALER_EXCHANGEDB_AuditorIterator it, + void *it_cls) { char *dir; struct AuditorIterateContext aic; @@ -498,6 +539,7 @@ TALER_EXCHANGEDB_auditor_iterate (const char *exchange_base_dir, * * @param filename the file where to write the auditor information to * @param apub the auditor's public key + * @param auditor_url the URL of the auditor * @param asigs the auditor's signatures, array of length @a dki_len * @param mpub the exchange's public key (as expected by the auditor) * @param dki_len length of @a dki @@ -506,11 +548,12 @@ TALER_EXCHANGEDB_auditor_iterate (const char *exchange_base_dir, */ int TALER_EXCHANGEDB_auditor_write (const char *filename, - const struct TALER_AuditorPublicKeyP *apub, - const struct TALER_AuditorSignatureP *asigs, - const struct TALER_MasterPublicKeyP *mpub, - unsigned int dki_len, - const struct TALER_DenominationKeyValidityPS *dki) + const struct TALER_AuditorPublicKeyP *apub, + const char *auditor_url, + const struct TALER_AuditorSignatureP *asigs, + const struct TALER_MasterPublicKeyP *mpub, + unsigned int dki_len, + const struct TALER_DenominationKeyValidityPS *dki) { struct AuditorFileHeaderP af; struct GNUNET_DISK_FileHandle *fh; @@ -521,6 +564,7 @@ TALER_EXCHANGEDB_auditor_write (const char *filename, af.apub = *apub; af.mpub = *mpub; + af.dki_len = htonl ((uint32_t) dki_len); ret = GNUNET_SYSERR; if (NULL == (fh = GNUNET_DISK_file_open (filename, @@ -546,6 +590,12 @@ TALER_EXCHANGEDB_auditor_write (const char *filename, dki, wsize)) ret = GNUNET_OK; + wsize = strlen (auditor_url) + 1; + if (wsize == + GNUNET_DISK_file_write (fh, + auditor_url, + wsize)) + ret = GNUNET_OK; cleanup: eno = errno; if (NULL != fh) diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index c3ecba96..cb1bd12a 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -208,19 +208,19 @@ struct TALER_EXCHANGE_DenomPublicKey struct TALER_EXCHANGE_AuditorInformation { /** - * Public key of the auditing institution. + * Public key of the auditing institution. Wallets and merchants + * are expected to be configured with a set of public keys of + * auditors that they deem acceptable. These public keys are + * the roots of the Taler PKI. */ struct TALER_AuditorPublicKeyP auditor_pub; /** - * URL of the auditing institution. The application must check that - * this is an acceptable auditor for its purpose and also verify - * that the @a auditor_pub matches the auditor's public key given at - * that website. We expect that in practice software is going to - * often ship with an initial list of accepted auditors, just like - * browsers ship with a CA root store. - * - * This field may be NULL. (#3987). + * URL of the auditing institution. Signed by the auditor's public + * key, this URL is a place where applications can direct users for + * additional information about the auditor. In the future, there + * should also be an auditor API for automated submission about + * claims of misbehaving exchange providers. */ const char *auditor_url; @@ -230,7 +230,7 @@ struct TALER_EXCHANGE_AuditorInformation unsigned int num_denom_keys; /** - * Array of length @a denom_keys with the denomination + * Array of length @a num_denom_keys with the denomination * keys audited by this auditor. Note that the array * elements point to the same locations as the entries * in the key's main `denom_keys` array. diff --git a/src/include/taler_exchangedb_lib.h b/src/include/taler_exchangedb_lib.h index 347ad065..e13df2d4 100644 --- a/src/include/taler_exchangedb_lib.h +++ b/src/include/taler_exchangedb_lib.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014, 2015 GNUnet e.V. + Copyright (C) 2014, 2015, 2016 Inria & GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -125,8 +125,8 @@ struct TALER_EXCHANGEDB_DenominationKeyIssueInformation */ typedef int (*TALER_EXCHANGEDB_SigningKeyIterator)(void *cls, - const char *filename, - const struct TALER_EXCHANGEDB_PrivateSigningKeyInformationP *ski); + const char *filename, + const struct TALER_EXCHANGEDB_PrivateSigningKeyInformationP *ski); /** @@ -143,8 +143,8 @@ typedef int */ int TALER_EXCHANGEDB_signing_keys_iterate (const char *exchange_base_dir, - TALER_EXCHANGEDB_SigningKeyIterator it, - void *it_cls); + TALER_EXCHANGEDB_SigningKeyIterator it, + void *it_cls); @@ -160,8 +160,8 @@ TALER_EXCHANGEDB_signing_keys_iterate (const char *exchange_base_dir, */ typedef int (*TALER_EXCHANGEDB_DenominationKeyIterator)(void *cls, - const char *alias, - const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki); + const char *alias, + const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki); /** @@ -179,8 +179,8 @@ typedef int */ int TALER_EXCHANGEDB_denomination_keys_iterate (const char *exchange_base_dir, - TALER_EXCHANGEDB_DenominationKeyIterator it, - void *it_cls); + TALER_EXCHANGEDB_DenominationKeyIterator it, + void *it_cls); /** @@ -192,7 +192,7 @@ TALER_EXCHANGEDB_denomination_keys_iterate (const char *exchange_base_dir, */ int TALER_EXCHANGEDB_denomination_key_write (const char *filename, - const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki); + const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki); /** @@ -204,7 +204,7 @@ TALER_EXCHANGEDB_denomination_key_write (const char *filename, */ int TALER_EXCHANGEDB_denomination_key_read (const char *filename, - struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki); + struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki); /** @@ -212,6 +212,7 @@ TALER_EXCHANGEDB_denomination_key_read (const char *filename, * * @param cls closure * @param apub the auditor's public key + * @param auditor_url URL of the auditor * @param mpub the exchange's public key (as expected by the auditor) * @param dki_len length of @a asig and @a dki arrays * @param asigs array of the auditor's signatures over the @a dks, of length @a dki_len @@ -222,11 +223,12 @@ TALER_EXCHANGEDB_denomination_key_read (const char *filename, */ typedef int (*TALER_EXCHANGEDB_AuditorIterator)(void *cls, - const struct TALER_AuditorPublicKeyP *apub, - const struct TALER_MasterPublicKeyP *mpub, - unsigned int dki_len, - const struct TALER_AuditorSignatureP *asigs, - const struct TALER_DenominationKeyValidityPS *dki); + const struct TALER_AuditorPublicKeyP *apub, + const char *auditor_url, + const struct TALER_MasterPublicKeyP *mpub, + unsigned int dki_len, + const struct TALER_AuditorSignatureP *asigs, + const struct TALER_DenominationKeyValidityPS *dki); /** @@ -244,8 +246,8 @@ typedef int */ int TALER_EXCHANGEDB_auditor_iterate (const char *exchange_base_dir, - TALER_EXCHANGEDB_AuditorIterator it, - void *it_cls); + TALER_EXCHANGEDB_AuditorIterator it, + void *it_cls); /** @@ -253,6 +255,7 @@ TALER_EXCHANGEDB_auditor_iterate (const char *exchange_base_dir, * * @param filename the file where to write the auditor information to * @param apub the auditor's public key + * @param auditor_url the URL of the auditor * @param asigs the auditor's signatures, array of length @a dki_len * @param mpub the exchange's public key (as expected by the auditor) * @param dki_len length of @a dki and @a asigs arrays @@ -261,11 +264,12 @@ TALER_EXCHANGEDB_auditor_iterate (const char *exchange_base_dir, */ int TALER_EXCHANGEDB_auditor_write (const char *filename, - const struct TALER_AuditorPublicKeyP *apub, - const struct TALER_AuditorSignatureP *asigs, - const struct TALER_MasterPublicKeyP *mpub, - unsigned int dki_len, - const struct TALER_DenominationKeyValidityPS *dki); + const struct TALER_AuditorPublicKeyP *apub, + const char *auditor_url, + const struct TALER_AuditorSignatureP *asigs, + const struct TALER_MasterPublicKeyP *mpub, + unsigned int dki_len, + const struct TALER_DenominationKeyValidityPS *dki); /** @@ -287,5 +291,4 @@ void TALER_EXCHANGEDB_plugin_unload (struct TALER_EXCHANGEDB_Plugin *plugin); - #endif diff --git a/src/include/taler_signatures.h b/src/include/taler_signatures.h index 729bed26..d958f16b 100644 --- a/src/include/taler_signatures.h +++ b/src/include/taler_signatures.h @@ -655,9 +655,14 @@ struct TALER_ExchangeKeyValidityPS */ struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + /** + * Hash of the auditor's URL. + */ + struct GNUNET_HashCode auditor_url_hash; + /** * The long-term offline master key of the exchange, affirmed by the - * auditor. + * auditor. Hashed string, including 0-terminator. */ struct TALER_MasterPublicKeyP master; -- cgit v1.2.3 From 3cb188e8a7ffa30a6b264355011f45f594725741 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 21 Mar 2016 14:40:57 +0100 Subject: rename to match GNUnet symbol change --- src/exchange-lib/exchange_api_handle.c | 2 +- src/exchange-lib/exchange_api_refresh.c | 4 ++-- src/exchange-lib/exchange_api_refresh_link.c | 4 ++-- src/exchange-lib/exchange_api_reserve.c | 4 ++-- src/exchange/taler-exchange-httpd_test.c | 6 +++--- src/exchangedb/exchangedb_keyio.c | 2 +- src/exchangedb/plugin_exchangedb_postgres.c | 4 ++-- src/include/taler_crypto_lib.h | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/exchange-lib/exchange_api_handle.c') diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c index aaca8bac..c3dd0d4c 100644 --- a/src/exchange-lib/exchange_api_handle.c +++ b/src/exchange-lib/exchange_api_handle.c @@ -260,7 +260,7 @@ parse_json_denomkey (struct TALER_EXCHANGE_DenomPublicKey *denom_key, struct TALER_Amount fee_deposit; struct TALER_Amount fee_refresh; struct TALER_DenominationKeyValidityPS denom_key_issue; - struct GNUNET_CRYPTO_rsa_PublicKey *pk; + struct GNUNET_CRYPTO_RsaPublicKey *pk; struct GNUNET_CRYPTO_EddsaSignature sig; struct GNUNET_JSON_Specification spec[] = { diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c index 2949cf1e..5cdf059b 100644 --- a/src/exchange-lib/exchange_api_refresh.c +++ b/src/exchange-lib/exchange_api_refresh.c @@ -1762,8 +1762,8 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh, const struct FreshCoin *fc; struct TALER_DenominationPublicKey *pk; json_t *jsonai; - struct GNUNET_CRYPTO_rsa_Signature *blind_sig; - struct GNUNET_CRYPTO_rsa_Signature *sig; + struct GNUNET_CRYPTO_RsaSignature *blind_sig; + struct GNUNET_CRYPTO_RsaSignature *sig; struct TALER_CoinSpendPublicKeyP coin_pub; struct GNUNET_HashCode coin_hash; diff --git a/src/exchange-lib/exchange_api_refresh_link.c b/src/exchange-lib/exchange_api_refresh_link.c index 41d421f5..8bb40d7f 100644 --- a/src/exchange-lib/exchange_api_refresh_link.c +++ b/src/exchange-lib/exchange_api_refresh_link.c @@ -98,8 +98,8 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh, { void *link_enc; size_t link_enc_size; - struct GNUNET_CRYPTO_rsa_Signature *bsig; - struct GNUNET_CRYPTO_rsa_PublicKey *rpub; + struct GNUNET_CRYPTO_RsaSignature *bsig; + struct GNUNET_CRYPTO_RsaPublicKey *rpub; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_varsize ("link_enc", &link_enc, &link_enc_size), GNUNET_JSON_spec_rsa_public_key ("denom_pub", &rpub), diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c index 87d7b37f..8c366324 100644 --- a/src/exchange-lib/exchange_api_reserve.c +++ b/src/exchange-lib/exchange_api_reserve.c @@ -563,8 +563,8 @@ static int reserve_withdraw_ok (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh, json_t *json) { - struct GNUNET_CRYPTO_rsa_Signature *blind_sig; - struct GNUNET_CRYPTO_rsa_Signature *sig; + struct GNUNET_CRYPTO_RsaSignature *blind_sig; + struct GNUNET_CRYPTO_RsaSignature *sig; struct TALER_DenominationSignature dsig; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_rsa_signature ("ev_sig", &blind_sig), diff --git a/src/exchange/taler-exchange-httpd_test.c b/src/exchange/taler-exchange-httpd_test.c index 0a4181ed..3fc8f473 100644 --- a/src/exchange/taler-exchange-httpd_test.c +++ b/src/exchange/taler-exchange-httpd_test.c @@ -33,7 +33,7 @@ /** * Private key the test module uses for signing. */ -static struct GNUNET_CRYPTO_rsa_PrivateKey *rsa_pk; +static struct GNUNET_CRYPTO_RsaPrivateKey *rsa_pk; /** @@ -415,7 +415,7 @@ TMH_TEST_handler_test_rsa_get (struct TMH_RequestHandler *rh, size_t *upload_data_size) { int res; - struct GNUNET_CRYPTO_rsa_PublicKey *pub; + struct GNUNET_CRYPTO_RsaPublicKey *pub; if (NULL == rsa_pk) rsa_pk = GNUNET_CRYPTO_rsa_private_key_create (1024); @@ -463,7 +463,7 @@ TMH_TEST_handler_test_rsa_sign (struct TMH_RequestHandler *rh, { json_t *json; int res; - struct GNUNET_CRYPTO_rsa_Signature *sig; + struct GNUNET_CRYPTO_RsaSignature *sig; void *in_ptr; size_t in_ptr_size; struct GNUNET_JSON_Specification spec[] = { diff --git a/src/exchangedb/exchangedb_keyio.c b/src/exchangedb/exchangedb_keyio.c index 6b8ca24e..177af2a0 100644 --- a/src/exchangedb/exchangedb_keyio.c +++ b/src/exchangedb/exchangedb_keyio.c @@ -128,7 +128,7 @@ TALER_EXCHANGEDB_denomination_key_read (const char *filename, uint64_t size; size_t offset; void *data; - struct GNUNET_CRYPTO_rsa_PrivateKey *priv; + struct GNUNET_CRYPTO_RsaPrivateKey *priv; if (GNUNET_OK != GNUNET_DISK_file_size (filename, &size, diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 0395c208..bcd6b9a0 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -3457,8 +3457,8 @@ postgres_get_link_data_list (void *cls, for (i = 0; i < nrows; i++) { struct TALER_RefreshLinkEncrypted *link_enc; - struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub; - struct GNUNET_CRYPTO_rsa_Signature *sig; + struct GNUNET_CRYPTO_RsaPublicKey *denom_pub; + struct GNUNET_CRYPTO_RsaSignature *sig; void *ld_buf; size_t ld_buf_size; struct GNUNET_PQ_ResultSpec rs[] = { diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index e948fa28..a3275b74 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -299,7 +299,7 @@ struct TALER_DenominationSignature /** * Taler uses RSA for blinding. */ - struct GNUNET_CRYPTO_rsa_Signature *rsa_signature; + struct GNUNET_CRYPTO_RsaSignature *rsa_signature; }; @@ -311,7 +311,7 @@ struct TALER_DenominationPublicKey /** * Taler uses RSA for signing coins. */ - struct GNUNET_CRYPTO_rsa_PublicKey *rsa_public_key; + struct GNUNET_CRYPTO_RsaPublicKey *rsa_public_key; }; @@ -323,7 +323,7 @@ struct TALER_DenominationPrivateKey /** * Taler uses RSA for signing coins. */ - struct GNUNET_CRYPTO_rsa_PrivateKey *rsa_private_key; + struct GNUNET_CRYPTO_RsaPrivateKey *rsa_private_key; }; -- cgit v1.2.3