-implement new client-side csr logic
This commit is contained in:
parent
63da97630d
commit
41d132757b
@ -53,11 +53,6 @@ struct TALER_EXCHANGE_CsRHandle
|
|||||||
*/
|
*/
|
||||||
void *cb_cls;
|
void *cb_cls;
|
||||||
|
|
||||||
/**
|
|
||||||
* Denomination key we are withdrawing.
|
|
||||||
*/
|
|
||||||
struct TALER_EXCHANGE_DenomPublicKey pk;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The url for this request.
|
* The url for this request.
|
||||||
*/
|
*/
|
||||||
@ -85,34 +80,51 @@ struct TALER_EXCHANGE_CsRHandle
|
|||||||
* If everything checks out, we return the unblinded signature
|
* If everything checks out, we return the unblinded signature
|
||||||
* to the application via the callback.
|
* to the application via the callback.
|
||||||
*
|
*
|
||||||
* @param wh operation handle
|
* @param csrh operation handle
|
||||||
* @param json reply from the exchange
|
* @param arr reply from the exchange
|
||||||
|
* @param hr http response details
|
||||||
* @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
|
* @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
|
||||||
*/
|
*/
|
||||||
static enum GNUNET_GenericReturnValue
|
static enum GNUNET_GenericReturnValue
|
||||||
csr_ok (const json_t *json,
|
csr_ok (struct TALER_EXCHANGE_CsRHandle *csrh,
|
||||||
struct TALER_EXCHANGE_CsRResponse *csrr)
|
json_t *arr,
|
||||||
|
struct TALER_EXCHANGE_HttpResponse *hr)
|
||||||
{
|
{
|
||||||
|
unsigned int alen = json_array_size (arr);
|
||||||
|
struct TALER_ExchangeWithdrawValues alg_values[GNUNET_NZL (alen)];
|
||||||
|
struct TALER_EXCHANGE_CsRResponse csrr = {
|
||||||
|
.hr = hr,
|
||||||
|
.details.success.alg_values_len = alen,
|
||||||
|
.details.success.alg_values = alg_values
|
||||||
|
};
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i<alen; i++)
|
||||||
|
{
|
||||||
|
json_t *av = json_array_get (arr,
|
||||||
|
i);
|
||||||
struct GNUNET_JSON_Specification spec[] = {
|
struct GNUNET_JSON_Specification spec[] = {
|
||||||
GNUNET_JSON_spec_fixed ("r_pub_0",
|
GNUNET_JSON_spec_fixed (
|
||||||
&csrr->details.success.r_pubs.r_pub[0],
|
"r_pub_0",
|
||||||
|
&alg_values[i].r_pub.r_pub[0],
|
||||||
sizeof (struct GNUNET_CRYPTO_CsRPublic)),
|
sizeof (struct GNUNET_CRYPTO_CsRPublic)),
|
||||||
GNUNET_JSON_spec_fixed ("r_pub_1",
|
GNUNET_JSON_spec_fixed (
|
||||||
&csrr->details.success.r_pubs.r_pub[1],
|
"r_pub_1",
|
||||||
|
&alg_values[i].r_pub.r_pub[1],
|
||||||
sizeof (struct GNUNET_CRYPTO_CsRPublic)),
|
sizeof (struct GNUNET_CRYPTO_CsRPublic)),
|
||||||
GNUNET_JSON_spec_end ()
|
GNUNET_JSON_spec_end ()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_JSON_parse (json,
|
GNUNET_JSON_parse (av,
|
||||||
spec,
|
spec,
|
||||||
NULL, NULL))
|
NULL, NULL))
|
||||||
{
|
{
|
||||||
GNUNET_break_op (0);
|
GNUNET_break_op (0);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
GNUNET_JSON_parse_free (spec);
|
csrh->cb (csrh->cb_cls,
|
||||||
|
&csrr);
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,16 +158,26 @@ handle_csr_finished (void *cls,
|
|||||||
csrr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
|
csrr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
|
||||||
break;
|
break;
|
||||||
case MHD_HTTP_OK:
|
case MHD_HTTP_OK:
|
||||||
if (GNUNET_OK !=
|
{
|
||||||
csr_ok (j,
|
json_t *arr;
|
||||||
&csrr))
|
|
||||||
|
arr = json_object_get (j,
|
||||||
|
"ewvs");
|
||||||
|
if ( (NULL == arr) ||
|
||||||
|
(0 == json_array_size (arr)) ||
|
||||||
|
(GNUNET_OK !=
|
||||||
|
csr_ok (csrh,
|
||||||
|
arr,
|
||||||
|
&hr)) )
|
||||||
{
|
{
|
||||||
GNUNET_break_op (0);
|
GNUNET_break_op (0);
|
||||||
csrr.hr.http_status = 0;
|
csrr.hr.http_status = 0;
|
||||||
csrr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
|
csrr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
TALER_EXCHANGE_csr_cancel (csrh);
|
||||||
|
return;
|
||||||
case MHD_HTTP_BAD_REQUEST:
|
case MHD_HTTP_BAD_REQUEST:
|
||||||
/* This should never happen, either us or the exchange is buggy
|
/* This should never happen, either us or the exchange is buggy
|
||||||
(or API version conflict); just pass JSON reply to the application */
|
(or API version conflict); just pass JSON reply to the application */
|
||||||
@ -204,14 +226,21 @@ handle_csr_finished (void *cls,
|
|||||||
|
|
||||||
struct TALER_EXCHANGE_CsRHandle *
|
struct TALER_EXCHANGE_CsRHandle *
|
||||||
TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange,
|
TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange,
|
||||||
const struct TALER_EXCHANGE_DenomPublicKey *pk,
|
unsigned int nks_len,
|
||||||
const struct TALER_CsNonce *nonce,
|
struct TALER_EXCHANGE_NonceKey *nks,
|
||||||
TALER_EXCHANGE_CsRCallback res_cb,
|
TALER_EXCHANGE_CsRCallback res_cb,
|
||||||
void *res_cb_cls)
|
void *res_cb_cls)
|
||||||
{
|
{
|
||||||
struct TALER_EXCHANGE_CsRHandle *csrh;
|
struct TALER_EXCHANGE_CsRHandle *csrh;
|
||||||
|
json_t *csr_arr;
|
||||||
|
|
||||||
if (TALER_DENOMINATION_CS != pk->key.cipher)
|
if (0 == nks_len)
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
for (unsigned int i = 0; i<nks_len; i++)
|
||||||
|
if (TALER_DENOMINATION_CS != nks[i].pk->key.cipher)
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -221,59 +250,65 @@ TALER_EXCHANGE_csr (struct TALER_EXCHANGE_Handle *exchange,
|
|||||||
csrh->exchange = exchange;
|
csrh->exchange = exchange;
|
||||||
csrh->cb = res_cb;
|
csrh->cb = res_cb;
|
||||||
csrh->cb_cls = res_cb_cls;
|
csrh->cb_cls = res_cb_cls;
|
||||||
csrh->pk = *pk;
|
|
||||||
|
|
||||||
|
csr_arr = json_array ();
|
||||||
|
GNUNET_assert (NULL != csr_arr);
|
||||||
|
for (unsigned int i = 0; i<nks_len; i++)
|
||||||
{
|
{
|
||||||
|
const struct TALER_EXCHANGE_NonceKey *nk = &nks[i];
|
||||||
json_t *csr_obj;
|
json_t *csr_obj;
|
||||||
|
|
||||||
csr_obj = GNUNET_JSON_PACK (GNUNET_JSON_pack_data_varsize ("nonce",
|
csr_obj = GNUNET_JSON_PACK (
|
||||||
nonce,
|
GNUNET_JSON_pack_data_varsize ("nonce",
|
||||||
sizeof(struct
|
nk->nonce,
|
||||||
TALER_CsNonce)),
|
sizeof(struct TALER_CsNonce)),
|
||||||
GNUNET_JSON_pack_data_varsize ("denom_pub_hash",
|
GNUNET_JSON_pack_data_varsize ("denom_pub_hash",
|
||||||
&pk->h_key,
|
&nk->pk->h_key,
|
||||||
sizeof(struct
|
sizeof(struct TALER_DenominationHash)));
|
||||||
TALER_DenominationHash)));
|
GNUNET_assert (NULL != csr_obj);
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
GNUNET_assert (0 ==
|
||||||
"Attempting to request R with denomination public key %s\n",
|
json_array_append_new (csr_arr,
|
||||||
TALER_B2S (&pk->key.details.cs_public_key));
|
csr_obj));
|
||||||
|
}
|
||||||
csrh->url = TEAH_path_to_url (exchange,
|
csrh->url = TEAH_path_to_url (exchange,
|
||||||
"/csr");
|
"/csr");
|
||||||
if (NULL == csrh->url)
|
if (NULL == csrh->url)
|
||||||
{
|
{
|
||||||
json_decref (csr_obj);
|
json_decref (csr_arr);
|
||||||
GNUNET_free (csrh);
|
GNUNET_free (csrh);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
CURL *eh;
|
CURL *eh;
|
||||||
struct GNUNET_CURL_Context *ctx;
|
struct GNUNET_CURL_Context *ctx;
|
||||||
|
json_t *req;
|
||||||
|
|
||||||
|
req = GNUNET_JSON_PACK (
|
||||||
|
GNUNET_JSON_pack_data_json ("nks",
|
||||||
|
csr_arr));
|
||||||
ctx = TEAH_handle_to_context (exchange);
|
ctx = TEAH_handle_to_context (exchange);
|
||||||
eh = TALER_EXCHANGE_curl_easy_get_ (csrh->url);
|
eh = TALER_EXCHANGE_curl_easy_get_ (csrh->url);
|
||||||
if ( (NULL == eh) ||
|
if ( (NULL == eh) ||
|
||||||
(GNUNET_OK !=
|
(GNUNET_OK !=
|
||||||
TALER_curl_easy_post (&csrh->post_ctx,
|
TALER_curl_easy_post (&csrh->post_ctx,
|
||||||
eh,
|
eh,
|
||||||
csr_obj)) )
|
req)) )
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
if (NULL != eh)
|
if (NULL != eh)
|
||||||
curl_easy_cleanup (eh);
|
curl_easy_cleanup (eh);
|
||||||
json_decref (csr_obj);
|
json_decref (req);
|
||||||
GNUNET_free (csrh->url);
|
GNUNET_free (csrh->url);
|
||||||
GNUNET_free (csrh);
|
GNUNET_free (csrh);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
json_decref (csr_obj);
|
json_decref (req);
|
||||||
csrh->job = GNUNET_CURL_job_add2 (ctx,
|
csrh->job = GNUNET_CURL_job_add2 (ctx,
|
||||||
eh,
|
eh,
|
||||||
csrh->post_ctx.headers,
|
csrh->post_ctx.headers,
|
||||||
&handle_csr_finished,
|
&handle_csr_finished,
|
||||||
csrh);
|
csrh);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return csrh;
|
return csrh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user