handle base32-wire transfer subject being followed by space+exchange base url in wire plugin and fakebank

This commit is contained in:
Christian Grothoff 2017-05-15 15:53:21 +02:00
parent be3b891dbd
commit 7c28823caf
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 45 additions and 13 deletions

View File

@ -512,8 +512,17 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
continue;
}
subject = GNUNET_STRINGS_data_to_string_alloc (&pos->wtid,
sizeof (pos->wtid));
{
char *ws;
ws = GNUNET_STRINGS_data_to_string_alloc (&pos->wtid,
sizeof (pos->wtid));
GNUNET_asprintf (&subject,
"%s %s",
ws,
pos->exchange_base_url);
GNUNET_free (ws);
}
trans = json_pack ("{s:I, s:o, s:o, s:s, s:I, s:s}",
"row_id", (json_int_t) pos->serial_id,
"date", GNUNET_JSON_from_time_abs (pos->date),

View File

@ -53,7 +53,7 @@ run (void *cls)
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
.details.admin_add_incoming.credit_account_no = 1,
.details.admin_add_incoming.debit_account_no = 2, /* Ignored */
.details.admin_add_incoming.amount = "PUDOS:5.01" },
.details.admin_add_incoming.amount = "KUDOS:5.01" },
/* Move money from Exchange to Bank */
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
.label = "deposit-2",
@ -61,7 +61,7 @@ run (void *cls)
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
.details.admin_add_incoming.credit_account_no = 1,
.details.admin_add_incoming.debit_account_no = 2, /* Ignored */
.details.admin_add_incoming.amount = "PUDOS:5.01" },
.details.admin_add_incoming.amount = "KUDOS:5.01" },
#if 0
/* Ask Exchange's incoming history */
{ .oc = TBI_OC_HISTORY,

View File

@ -52,7 +52,7 @@ run (void *cls)
.details.admin_add_incoming.credit_account_no = 1,
.details.admin_add_incoming.debit_account_no = 2,
.details.admin_add_incoming.exchange_base_url = "https://exchange.net/",
.details.admin_add_incoming.amount = "PUDOS:5.01" },
.details.admin_add_incoming.amount = "KUDOS:5.01" },
/* Add EUR:3.21 to account 3 */
{ .oc = TBI_OC_HISTORY,
.label = "history-1c",
@ -72,14 +72,14 @@ run (void *cls)
.details.admin_add_incoming.credit_account_no = 3,
.details.admin_add_incoming.debit_account_no = 2,
.details.admin_add_incoming.exchange_base_url = "https://exchange.org/",
.details.admin_add_incoming.amount = "PUDOS:3.21" },
.details.admin_add_incoming.amount = "KUDOS:3.21" },
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
.label = "credit-2",
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
.details.admin_add_incoming.credit_account_no = 2,
.details.admin_add_incoming.debit_account_no = 3,
.details.admin_add_incoming.exchange_base_url = "https://exchange.org/",
.details.admin_add_incoming.amount = "PUDOS:3.22" },
.details.admin_add_incoming.amount = "KUDOS:3.22" },
{ .oc = TBI_OC_HISTORY,
.label = "history-2b",
.details.history.account_number = 2,

View File

@ -323,9 +323,17 @@ build_history (struct InterpreterState *is,
/* h[total].execution_date; // unknown here */
h[total].serial_id
= pos->details.admin_add_incoming.serial_id;
h[total].details.wire_transfer_subject
= GNUNET_STRINGS_data_to_string_alloc (&pos->details.admin_add_incoming.wtid,
sizeof (struct TALER_WireTransferIdentifierRawP));
{
char *ws;
ws = GNUNET_STRINGS_data_to_string_alloc (&pos->details.admin_add_incoming.wtid,
sizeof (struct TALER_WireTransferIdentifierRawP));
GNUNET_asprintf (&h[total].details.wire_transfer_subject,
"%s %s",
ws,
pos->details.admin_add_incoming.exchange_base_url);
GNUNET_free (ws);
}
total++;
}
}

View File

@ -200,7 +200,8 @@ struct TALER_BANK_TransferDetails
struct GNUNET_TIME_Absolute execution_date;
/**
* Wire transfer subject
* Wire transfer subject. Usually a reserve public key
* followed by the BASE URI of the exchange.
*/
char *wire_transfer_subject;

View File

@ -822,16 +822,29 @@ bhist_cb (void *cls,
if (MHD_HTTP_OK == http_status)
{
char *subject;
char *space;
wd.amount = details->amount;
wd.execution_date = details->execution_date;
subject = GNUNET_strdup (details->wire_transfer_subject);
space = strchr (subject, (int) ' ');
if (NULL != space)
{
/* Space separates the actual wire transfer subject from the
exchange base URL (if present, expected only for outgoing
transactions). So we cut the string off at the space. */
*space = '\0';
}
/* NOTE: For a real bank, the subject should include a checksum! */
if (GNUNET_OK !=
GNUNET_STRINGS_string_to_data (details->wire_transfer_subject,
strlen (details->wire_transfer_subject),
GNUNET_STRINGS_string_to_data (subject,
strlen (subject),
&wd.reserve_pub,
sizeof (wd.reserve_pub)))
{
GNUNET_break (0);
GNUNET_free (subject);
/* NOTE: for a "real" bank, we would want to trigger logic to undo the
wire transfer. However, for the "demo" bank, it should currently
be "impossible" to do wire transfers with invalid subjects, and
@ -839,6 +852,7 @@ bhist_cb (void *cls,
that nicely either right now). So we don't handle this case for now. */
return;
}
GNUNET_free (subject);
wd.account_details = details->account_details;
if ( (NULL != whh->hres_cb) &&