summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_reserves_attest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/exchange_api_reserves_attest.c')
-rw-r--r--src/lib/exchange_api_reserves_attest.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/lib/exchange_api_reserves_attest.c b/src/lib/exchange_api_reserves_attest.c
index a7a89a2ef..d5a867114 100644
--- a/src/lib/exchange_api_reserves_attest.c
+++ b/src/lib/exchange_api_reserves_attest.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 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
@@ -16,7 +16,7 @@
*/
/**
* @file lib/exchange_api_reserves_attest.c
- * @brief Implementation of the POST /reserves/$RESERVE_PUB/attest requests
+ * @brief Implementation of the POST /reserves-attest/$RESERVE_PUB requests
* @author Christian Grothoff
*/
#include "platform.h"
@@ -33,15 +33,15 @@
/**
- * @brief A /reserves/$RID/attest Handle
+ * @brief A /reserves-attest/$RID Handle
*/
struct TALER_EXCHANGE_ReservesAttestHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -93,18 +93,18 @@ handle_reserves_attest_ok (struct TALER_EXCHANGE_ReservesAttestHandle *rsh,
.hr.reply = j,
.hr.http_status = MHD_HTTP_OK
};
- json_t *attributes;
+ const json_t *attributes;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_timestamp ("exchange_timestamp",
&rs.details.ok.exchange_time),
- GNUNET_JSON_spec_timestamp ("exchange_timestamp",
+ GNUNET_JSON_spec_timestamp ("expiration_time",
&rs.details.ok.expiration_time),
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
&rs.details.ok.exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&rs.details.ok.exchange_pub),
- GNUNET_JSON_spec_json ("attributes",
- &attributes),
+ GNUNET_JSON_spec_object_const ("attributes",
+ &attributes),
GNUNET_JSON_spec_end ()
};
@@ -117,6 +117,19 @@ handle_reserves_attest_ok (struct TALER_EXCHANGE_ReservesAttestHandle *rsh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ if (GNUNET_OK !=
+ TALER_EXCHANGE_test_signing_key (rsh->keys,
+ &rs.details.ok.exchange_pub))
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_SIGNATURE_BY_EXCHANGE;
+ rsh->cb (rsh->cb_cls,
+ &rs);
+ rsh->cb = NULL;
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_SYSERR;
+ }
rs.details.ok.attributes = attributes;
if (GNUNET_OK !=
TALER_exchange_online_reserve_attest_details_verify (
@@ -141,7 +154,7 @@ handle_reserves_attest_ok (struct TALER_EXCHANGE_ReservesAttestHandle *rsh,
/**
* Function called when we're done processing the
- * HTTP /reserves/$RID/attest request.
+ * HTTP /reserves-attest/$RID request.
*
* @param cls the `struct TALER_EXCHANGE_ReservesAttestHandle`
* @param response_code HTTP response code, 0 on error
@@ -228,15 +241,16 @@ handle_reserves_attest_finished (void *cls,
struct TALER_EXCHANGE_ReservesAttestHandle *
TALER_EXCHANGE_reserves_attest (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
unsigned int attributes_length,
- const char *const*attributes,
+ const char *attributes[const static attributes_length],
TALER_EXCHANGE_ReservesPostAttestCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_ReservesAttestHandle *rsh;
- struct GNUNET_CURL_Context *ctx;
CURL *eh;
char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
struct TALER_ReserveSignatureP reserve_sig;
@@ -248,12 +262,6 @@ TALER_EXCHANGE_reserves_attest (
GNUNET_break (0);
return NULL;
}
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
details = json_array ();
GNUNET_assert (NULL != details);
for (unsigned int i = 0; i<attributes_length; i++)
@@ -263,7 +271,6 @@ TALER_EXCHANGE_reserves_attest (
json_string (attributes[i])));
}
rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesAttestHandle);
- rsh->exchange = exchange;
rsh->cb = cb;
rsh->cb_cls = cb_cls;
GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
@@ -280,11 +287,12 @@ TALER_EXCHANGE_reserves_attest (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/reserves/%s/attest",
+ "reserves-attest/%s",
pub_str);
}
- rsh->url = TEAH_path_to_url (exchange,
- arg_str);
+ rsh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == rsh->url)
{
json_decref (details);
@@ -311,8 +319,8 @@ TALER_EXCHANGE_reserves_attest (
&reserve_sig),
GNUNET_JSON_pack_timestamp ("request_timestamp",
ts),
- GNUNET_JSON_pack_object_steal ("details",
- details));
+ GNUNET_JSON_pack_array_steal ("details",
+ details));
if (GNUNET_OK !=
TALER_curl_easy_post (&rsh->post_ctx,
@@ -328,12 +336,12 @@ TALER_EXCHANGE_reserves_attest (
}
json_decref (attest_obj);
}
- ctx = TEAH_handle_to_context (exchange);
rsh->job = GNUNET_CURL_job_add2 (ctx,
eh,
rsh->post_ctx.headers,
&handle_reserves_attest_finished,
rsh);
+ rsh->keys = TALER_EXCHANGE_keys_incref (keys);
return rsh;
}
@@ -348,6 +356,7 @@ TALER_EXCHANGE_reserves_attest_cancel (
rsh->job = NULL;
}
TALER_curl_easy_post_finished (&rsh->post_ctx);
+ TALER_EXCHANGE_keys_decref (rsh->keys);
GNUNET_free (rsh->url);
GNUNET_free (rsh);
}