summaryrefslogtreecommitdiff
path: root/src/exchange-lib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-11-17 15:15:51 +0100
committerChristian Grothoff <christian@grothoff.org>2018-11-17 15:15:51 +0100
commit4d058c4eb7283b1a77a877d583daaefa847213ec (patch)
treecded82c1127f7060e359caca09a702c662d56319 /src/exchange-lib
parent17edb09f384689da5923689dfe4b6d071797091c (diff)
downloadexchange-4d058c4eb7283b1a77a877d583daaefa847213ec.tar.gz
exchange-4d058c4eb7283b1a77a877d583daaefa847213ec.tar.bz2
exchange-4d058c4eb7283b1a77a877d583daaefa847213ec.zip
work towards testing auditor deposit-confirmation API
Diffstat (limited to 'src/exchange-lib')
-rw-r--r--src/exchange-lib/Makefile.am2
-rw-r--r--src/exchange-lib/exchange_api_deposit.c23
-rw-r--r--src/exchange-lib/testing_api_cmd_deposit.c68
-rw-r--r--src/exchange-lib/testing_api_trait_exchange_pub.c77
-rw-r--r--src/exchange-lib/testing_api_trait_exchange_sig.c77
5 files changed, 225 insertions, 22 deletions
diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am
index 3e1b4507e..c22c47b53 100644
--- a/src/exchange-lib/Makefile.am
+++ b/src/exchange-lib/Makefile.am
@@ -65,6 +65,8 @@ libtalertesting_la_SOURCES = \
testing_api_trait_coin_priv.c \
testing_api_trait_denom_pub.c \
testing_api_trait_denom_sig.c \
+ testing_api_trait_exchange_pub.c \
+ testing_api_trait_exchange_sig.c \
testing_api_trait_json.c \
testing_api_trait_process.c \
testing_api_trait_reserve_priv.c \
diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c
index c388e6816..355464099 100644
--- a/src/exchange-lib/exchange_api_deposit.c
+++ b/src/exchange-lib/exchange_api_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015 GNUnet e.V.
+ Copyright (C) 2014, 2015, 2018 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,19 +93,19 @@ struct TALER_EXCHANGE_DepositHandle
*
* @param dh deposit handle
* @param json json reply with the signature
- * @param exchange_pub set to the exchange's public key
+ * @param exchange_sig[out] set to the exchange's signature
+ * @param exchange_pub[out] set to the exchange's public key
* @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not
*/
static int
verify_deposit_signature_ok (const struct TALER_EXCHANGE_DepositHandle *dh,
const json_t *json,
+ struct TALER_ExchangeSignatureP *exchange_sig,
struct TALER_ExchangePublicKeyP *exchange_pub)
{
- struct TALER_ExchangeSignatureP exchange_sig;
-
const struct TALER_EXCHANGE_Keys *key_state;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("sig", &exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("sig", exchange_sig),
GNUNET_JSON_spec_fixed_auto ("pub", exchange_pub),
GNUNET_JSON_spec_end()
};
@@ -129,7 +129,7 @@ verify_deposit_signature_ok (const struct TALER_EXCHANGE_DepositHandle *dh,
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT,
&dh->depconf.purpose,
- &exchange_sig.eddsa_signature,
+ &exchange_sig->eddsa_signature,
&exchange_pub->eddsa_pub))
{
GNUNET_break_op (0);
@@ -158,9 +158,9 @@ verify_deposit_signature_forbidden (const struct TALER_EXCHANGE_DepositHandle *d
"history");
if (GNUNET_OK !=
TALER_EXCHANGE_verify_coin_history (dh->coin_value.currency,
- &dh->depconf.coin_pub,
- history,
- &total))
+ &dh->depconf.coin_pub,
+ history,
+ &total))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -201,7 +201,9 @@ handle_deposit_finished (void *cls,
const void *response)
{
struct TALER_EXCHANGE_DepositHandle *dh = cls;
+ struct TALER_ExchangeSignatureP exchange_sig;
struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_ExchangeSignatureP *es = NULL;
struct TALER_ExchangePublicKeyP *ep = NULL;
const json_t *j = response;
@@ -214,6 +216,7 @@ handle_deposit_finished (void *cls,
if (GNUNET_OK !=
verify_deposit_signature_ok (dh,
j,
+ &exchange_sig,
&exchange_pub))
{
GNUNET_break_op (0);
@@ -221,6 +224,7 @@ handle_deposit_finished (void *cls,
}
else
{
+ es = &exchange_sig;
ep = &exchange_pub;
}
break;
@@ -263,6 +267,7 @@ handle_deposit_finished (void *cls,
dh->cb (dh->cb_cls,
response_code,
TALER_JSON_get_error_code (j),
+ es,
ep,
j);
TALER_EXCHANGE_deposit_cancel (dh);
diff --git a/src/exchange-lib/testing_api_cmd_deposit.c b/src/exchange-lib/testing_api_cmd_deposit.c
index 604fa949b..4f3757f5d 100644
--- a/src/exchange-lib/testing_api_cmd_deposit.c
+++ b/src/exchange-lib/testing_api_cmd_deposit.c
@@ -112,6 +112,24 @@ struct DepositState
*/
int do_retry;
+ /**
+ * Set to #GNUNET_YES if the /deposit succeeded
+ * and we now can provide the resulting traits.
+ */
+ int traits_ready;
+
+ /**
+ * Signing key used by the exchange to sign the
+ * deposit confirmation.
+ */
+ struct TALER_ExchangePublicKeyP exchange_pub;
+
+ /**
+ * Signature from the exchange on the
+ * deposit confirmation.
+ */
+ struct TALER_ExchangeSignatureP exchange_sig;
+
};
@@ -152,6 +170,8 @@ do_retry (void *cls)
* @param cls closure.
* @param http_status HTTP response code.
* @param ec taler-specific error code.
+ * @param exchange_sig signature provided by the exchange
+ * (NULL on errors)
* @param exchange_pub public key of the exchange,
* used for signing the response.
* @param obj raw response from the exchange.
@@ -160,6 +180,7 @@ static void
deposit_cb (void *cls,
unsigned int http_status,
enum TALER_ErrorCode ec,
+ const struct TALER_ExchangeSignatureP *exchange_sig,
const struct TALER_ExchangePublicKeyP *exchange_pub,
const json_t *obj)
{
@@ -183,9 +204,10 @@ deposit_cb (void *cls,
ds->backoff = GNUNET_TIME_UNIT_ZERO;
else
ds->backoff = EXCHANGE_LIB_BACKOFF (ds->backoff);
- ds->retry_task = GNUNET_SCHEDULER_add_delayed (ds->backoff,
- &do_retry,
- ds);
+ ds->retry_task
+ = GNUNET_SCHEDULER_add_delayed (ds->backoff,
+ &do_retry,
+ ds);
return;
}
}
@@ -199,6 +221,12 @@ deposit_cb (void *cls,
TALER_TESTING_interpreter_fail (ds->is);
return;
}
+ if (MHD_HTTP_OK == http_status)
+ {
+ ds->traits_ready = GNUNET_YES;
+ ds->exchange_pub = *exchange_pub;
+ ds->exchange_sig = *exchange_sig;
+ }
TALER_TESTING_interpreter_next (ds->is);
}
@@ -425,7 +453,8 @@ deposit_traits (void *cls,
struct TALER_CoinSpendPrivateKeyP *coin_spent_priv;
coin_cmd = TALER_TESTING_interpreter_lookup_command
- (ds->is, ds->coin_reference);
+ (ds->is,
+ ds->coin_reference);
if (NULL == coin_cmd)
{
@@ -434,8 +463,10 @@ deposit_traits (void *cls,
return GNUNET_NO;
}
- if (GNUNET_OK != TALER_TESTING_get_trait_coin_priv
- (coin_cmd, ds->coin_index, &coin_spent_priv))
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_priv (coin_cmd,
+ ds->coin_index,
+ &coin_spent_priv))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
@@ -443,16 +474,27 @@ deposit_traits (void *cls,
}
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_coin_priv (0, coin_spent_priv),
- TALER_TESTING_make_trait_wire_details (0, ds->wire_details),
- TALER_TESTING_make_trait_contract_terms
- (0, ds->contract_terms),
- TALER_TESTING_make_trait_peer_key
- (0, &ds->merchant_priv.eddsa_priv),
+ /* First two traits are only available if
+ ds->traits is #GNUNET_YES */
+ TALER_TESTING_make_trait_exchange_pub (0,
+ &ds->exchange_pub),
+ TALER_TESTING_make_trait_exchange_sig (0,
+ &ds->exchange_sig),
+ /* These traits are always available */
+ TALER_TESTING_make_trait_coin_priv (0,
+ coin_spent_priv),
+ TALER_TESTING_make_trait_wire_details (0,
+ ds->wire_details),
+ TALER_TESTING_make_trait_contract_terms (0,
+ ds->contract_terms),
+ TALER_TESTING_make_trait_peer_key (0,
+ &ds->merchant_priv.eddsa_priv),
TALER_TESTING_trait_end ()
};
- return TALER_TESTING_get_trait (traits,
+ return TALER_TESTING_get_trait ((ds->traits_ready)
+ ? traits
+ : &traits[2],
ret,
trait,
index);
diff --git a/src/exchange-lib/testing_api_trait_exchange_pub.c b/src/exchange-lib/testing_api_trait_exchange_pub.c
new file mode 100644
index 000000000..4bef98af6
--- /dev/null
+++ b/src/exchange-lib/testing_api_trait_exchange_pub.c
@@ -0,0 +1,77 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2018 Taler Systems SA
+
+ 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, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchange-lib/testing_api_trait_exchange_pub.c
+ * @brief exchange pub traits.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "taler_testing_lib.h"
+
+#define TALER_TESTING_TRAIT_EXCHANGE_PUB "exchange-public-key"
+
+
+/**
+ * Obtain a exchange public key from a @a cmd.
+ *
+ * @param cmd command to extract trait from
+ * @param index index number of the exchange to obtain.
+ * @param exchange_pub[out] set to the offered exchange pub.
+ * @return #GNUNET_OK on success.
+ */
+int
+TALER_TESTING_get_trait_exchange_pub
+ (const struct TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const struct TALER_ExchangePublicKeyP **exchange_pub)
+{
+ return cmd->traits (cmd->cls,
+ (void **) exchange_pub,
+ TALER_TESTING_TRAIT_EXCHANGE_PUB,
+ index);
+}
+
+
+/**
+ * Make a trait for a exchange public key.
+ *
+ * @param index index number to associate to the offered exchange pub.
+ * @param exchange_pub exchange pub to offer with this trait.
+ *
+ * @return the trait.
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_exchange_pub
+ (unsigned int index,
+ const struct TALER_ExchangePublicKeyP *exchange_pub)
+{
+ struct TALER_TESTING_Trait ret = {
+ .index = index,
+ .trait_name = TALER_TESTING_TRAIT_EXCHANGE_PUB,
+ .ptr = (const void *) exchange_pub
+ };
+
+ return ret;
+}
+
+/* end of testing_api_trait_exchange_pub.c */
diff --git a/src/exchange-lib/testing_api_trait_exchange_sig.c b/src/exchange-lib/testing_api_trait_exchange_sig.c
new file mode 100644
index 000000000..00d4243f1
--- /dev/null
+++ b/src/exchange-lib/testing_api_trait_exchange_sig.c
@@ -0,0 +1,77 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2018 Taler Systems SA
+
+ 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, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchange-lib/testing_api_trait_exchange_sig.c
+ * @brief exchange pub traits.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "taler_testing_lib.h"
+
+#define TALER_TESTING_TRAIT_EXCHANGE_SIG "exchange-online-signature"
+
+
+/**
+ * Obtain a exchange signature (online sig) from a @a cmd.
+ *
+ * @param cmd command to extract trait from
+ * @param index index number of the exchange to obtain.
+ * @param exchange_sig[out] set to the offered exchange signature.
+ * @return #GNUNET_OK on success.
+ */
+int
+TALER_TESTING_get_trait_exchange_sig
+ (const struct TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const struct TALER_ExchangeSignatureP **exchange_sig)
+{
+ return cmd->traits (cmd->cls,
+ (void **) exchange_sig,
+ TALER_TESTING_TRAIT_EXCHANGE_SIG,
+ index);
+}
+
+
+/**
+ * Make a trait for a exchange signature.
+ *
+ * @param index index number to associate to the offered exchange pub.
+ * @param exchange_sig exchange signature to offer with this trait.
+ *
+ * @return the trait.
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_exchange_sig
+ (unsigned int index,
+ const struct TALER_ExchangeSignatureP *exchange_sig)
+{
+ struct TALER_TESTING_Trait ret = {
+ .index = index,
+ .trait_name = TALER_TESTING_TRAIT_EXCHANGE_SIG,
+ .ptr = (const void *) exchange_sig
+ };
+
+ return ret;
+}
+
+/* end of testing_api_trait_exchange_sig.c */