fix #5756, also change sepa->iban as per payto:// spec

This commit is contained in:
Christian Grothoff 2019-06-08 19:55:18 +02:00
parent 8800110b72
commit 4f846eab96
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
17 changed files with 250 additions and 698 deletions

View File

@ -1,3 +1,6 @@
Sat 08 Jun 2019 07:54:33 PM CEST
Change payto://sepa/ to payto://iban/ as per current spec. -CG
Fri 03 May 2019 05:36:10 PM CEST
Add support for compressing bodies during HTTP uploads to
exchange and auditor. -CG

View File

@ -33,6 +33,7 @@
#include "taler_signatures.h"
#include "taler_exchange_service.h"
#include "taler_json_lib.h"
#include "taler_wire_lib.h"
#include "taler_bank_service.h"
#include "taler_fakebank_lib.h"
#include "taler_testing_lib.h"
@ -68,34 +69,13 @@ enum BenchmarkError {
#define CMD_TRANSFER_TO_EXCHANGE(label, amount) \
TALER_TESTING_cmd_fakebank_transfer_retry \
(TALER_TESTING_cmd_fakebank_transfer (label, amount, \
exchange_bank_account.bank_base_url, \
exchange_bank_account.details.x_taler_bank.bank_base_url, \
USER_ACCOUNT_NUMBER, \
exchange_bank_account.no, \
exchange_bank_account.details.x_taler_bank.no, \
"dummy_user", \
"dummy_password", \
"http://example.com/"))
/**
* Information about an account extracted from a payto://-URL.
*/
struct Account
{
/**
* Hostname of the bank (possibly including port).
*/
char *hostname;
/**
* Bank account number.
*/
unsigned long long no;
/**
* Base URL of the bank hosting the account above.
*/
char *bank_base_url;
};
/**
* What mode should the benchmark run in?
@ -121,7 +101,7 @@ enum BenchmarkMode {
/**
* Hold information regarding which bank has the exchange account.
*/
static struct Account exchange_bank_account;
static struct TALER_Account exchange_bank_account;
/**
* Time snapshot taken right before executing the CMDs.
@ -229,106 +209,6 @@ pick_exchange_account_cb (void *cls,
}
/**
* Parse payto:// account URL (only account information,
* wire subject and amount are ignored).
*
* @param account_url URL to parse
* @param account[out] set to information, can be NULL
* @return #TALER_EC_NONE if @a account_url is well-formed
*/
static enum TALER_ErrorCode
parse_payto (const char *account_url,
struct Account *account)
{
const char *hostname;
const char *a;
const char *q;
unsigned long long no;
#define PREFIX "payto://x-taler-bank/"
#define MAX_ACCOUNT_NO (1LLU << 52)
if (0 != strncasecmp (account_url,
PREFIX,
strlen (PREFIX)))
return TALER_EC_PAYTO_WRONG_METHOD;
hostname = &account_url[strlen (PREFIX)];
if (NULL == (a = strchr (hostname,
(unsigned char) '/')))
return TALER_EC_PAYTO_MALFORMED;
a++;
if (NULL != (q = strchr (a,
(unsigned char) '?')))
{
char *s;
s = GNUNET_strndup (a,
q - a);
if (1 != sscanf (s,
"%llu",
&no))
{
GNUNET_free (s);
return TALER_EC_PAYTO_MALFORMED;
}
GNUNET_free (s);
}
else
{
if (1 != sscanf (a,
"%llu",
&no))
return TALER_EC_PAYTO_MALFORMED;
}
if (no > MAX_ACCOUNT_NO)
return TALER_EC_PAYTO_MALFORMED;
if (NULL != account)
{
long long unsigned port;
char *p;
/* the "-1" crops the final slash away. */
account->hostname = GNUNET_strndup (hostname,
a - hostname - 1);
account->no = no;
port = 443; /* if non given, equals 443. */
if (NULL != (p = strchr (account->hostname,
(unsigned char) ':')))
{
p++;
if (1 != sscanf (p,
"%llu",
&port))
{
GNUNET_break (0);
TALER_LOG_ERROR ("Malformed host from payto:// URI\n");
GNUNET_free (account->hostname);
return TALER_EC_PAYTO_MALFORMED;
}
}
if (443 != port)
{
GNUNET_assert
(GNUNET_SYSERR != GNUNET_asprintf
(&account->bank_base_url,
"http://%s",
account->hostname));
}
else
{
GNUNET_assert
(GNUNET_SYSERR != GNUNET_asprintf
(&account->bank_base_url,
"https://%s",
account->hostname));
}
}
return TALER_EC_NONE;
}
/**
* Throw a weighted coin with @a probability.
*
@ -436,7 +316,7 @@ run (void *cls,
0, /* Index of the one withdrawn coin in the traits. */
TALER_TESTING_make_wire_details
(USER_ACCOUNT_NUMBER,
exchange_bank_account.hostname),
exchange_bank_account.details.x_taler_bank.hostname),
order_enc,
GNUNET_TIME_UNIT_ZERO,
AMOUNT_1,
@ -580,7 +460,7 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
NULL == loglev ? "INFO" : loglev,
logfile);
GNUNET_SCHEDULER_run (&launch_fakebank,
exchange_bank_account.bank_base_url);
exchange_bank_account.details.x_taler_bank.bank_base_url);
exit (0);
}
if (-1 == fakebank)
@ -963,7 +843,7 @@ main (int argc,
}
if (TALER_EC_NONE !=
parse_payto (exchange_payto_url,
TALER_WIRE_payto_to_account (exchange_payto_url,
&exchange_bank_account))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -972,6 +852,14 @@ main (int argc,
GNUNET_free (exchange_payto_url);
return BAD_CONFIG_FILE;
}
if (TALER_PAC_X_TALER_BANK != exchange_bank_account.type)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Malformed payto:// URL `%s' in configuration: x-taler-bank required\n"),
exchange_payto_url);
GNUNET_free (exchange_payto_url);
return BAD_CONFIG_FILE;
}
GNUNET_free (exchange_payto_url);
}
if ( (MODE_EXCHANGE == mode) || (MODE_BOTH == mode) )

View File

@ -273,7 +273,7 @@ PERF_TALER_EXCHANGEDB_deposit_init (const struct PERF_TALER_EXCHANGEDB_Coin *coi
deposit->h_wire = h_wire;
deposit->receiver_wire_account
= json_pack ("{s:s, s:s}",
"url", "payto://sepa/DE67830654080004822650",
"url", "payto://iban/DE67830654080004822650",
"salt", "this-is-a-salt-value");
deposit->timestamp = timestamp;
deposit->refund_deadline = refund_deadline;

View File

@ -5202,7 +5202,7 @@ postgres_insert_reserve_closed (void *cls,
*
* @param cls closure
* @param session database connection
* @param type type of the wire transfer (i.e. "sepa")
* @param type type of the wire transfer (i.e. "iban")
* @param buf buffer with wire transfer preparation data
* @param buf_size number of bytes in @a buf
* @return query status code

View File

@ -1922,7 +1922,7 @@ struct TALER_EXCHANGEDB_Plugin
*
* @param cls closure
* @param session database connection
* @param type type of the wire transfer (i.e. "sepa")
* @param type type of the wire transfer (i.e. "iban")
* @param buf buffer with wire transfer preparation data
* @param buf_size number of bytes in @a buf
* @return query status code

View File

@ -72,7 +72,7 @@
#define TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED 1029
/**
* Signature where the Exchange confirms its SEPA details in
* Signature where the Exchange confirms its IBAN details in
* the /wire response.
*/
#define TALER_SIGNATURE_MASTER_WIRE_DETAILS 1030
@ -878,7 +878,7 @@ struct TALER_ExchangeKeyValidityPS
/**
* @brief Information signed by the exchange's master
* key affirming the SEPA details for the exchange.
* key affirming the IBAN details for the exchange.
*/
struct TALER_MasterWireDetailsPS
{
@ -911,7 +911,7 @@ struct TALER_MasterWireFeePS
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
/**
* Hash over the wire method (yes, H("test") or H("sepa")), in lower
* Hash over the wire method (yes, H("x-taler-bank") or H("iban")), in lower
* case, including 0-terminator. Used to uniquely identify which
* wire method these fees apply to.
*/

View File

@ -24,6 +24,103 @@
#include <gnunet/gnunet_util_lib.h>
#include "taler_wire_plugin.h"
/**
* Different account types supported by payto://.
*/
enum TALER_PaytoAccountType
{
/**
* Used to indicate an uninitialized struct.
*/
TALER_PAC_NONE = 0,
/**
* Account type of a bank running the x-taler-bank protocol.
*/
TALER_PAC_X_TALER_BANK,
/**
* Account identified by IBAN number.
*/
TALER_PAC_IBAN
};
/**
* Information about an account extracted from a payto://-URL.
*/
struct TALER_Account
{
/**
* How this the account represented.
*/
enum TALER_PaytoAccountType type;
/**
* Internals depending on @e type.
*/
union {
/**
* Taler bank address from x-taler-bank. Set if
* @e type is #TALER_AC_X_TALER_BANK.
*/
struct {
/**
* Hostname of the bank (possibly including port).
*/
char *hostname;
/**
* Bank account number.
*/
unsigned long long no;
/**
* Base URL of the bank hosting the account above.
*/
char *bank_base_url;
} x_taler_bank;
/**
* Taler bank address from iban. Set if
* @e type is #TALER_AC_IBAN.
*/
struct {
/**
* IBAN number.
*/
char *number;
} iban;
} details;
};
/**
* Release memory allocated in @a acc.
*
* @param acc account to free, the pointer itself is NOT free'd.
*/
void
TALER_WIRE_account_free (struct TALER_Account *acc);
/**
* Parse @a payto_url and store the result in @a acc
*
* @param payto_url URL to parse
* @param acc[in,out] account to initialize, free using #TALER_WIRE_account_free() later
* @return #TALER_EC_NONE if @a payto_url is well-formed
*/
enum TALER_ErrorCode
TALER_WIRE_payto_to_account (const char *payto_url,
struct TALER_Account *acc);
/**
* Obtain the payment method from a @a payto_url

View File

@ -172,7 +172,7 @@ struct TALER_WIRE_Plugin
/**
* Which wire method (payto://METHOD/") is supported by this plugin?
* For example, "sepa" or "x-taler-bank".
* For example, "iban" or "x-taler-bank".
*/
const char *method;
@ -180,7 +180,7 @@ struct TALER_WIRE_Plugin
/**
* Round amount DOWN to the amount that can be transferred via the wire
* method. For example, Taler may support 0.000001 EUR as a unit of
* payment, but SEPA only supports 0.01 EUR. This function would
* payment, but IBAN only supports 0.01 EUR. This function would
* round 0.125 EUR to 0.12 EUR in this case.
*
* @param cls the @e cls of this struct with the plugin-specific state

View File

@ -57,7 +57,7 @@ CONFIG = "postgres:///talercheck"
# advertised in /wire.
[account-1]
# What is the URL of our account?
URL = "payto://sepa/CH9300762011623852957"
URL = "payto://iban/CH9300762011623852957"
# This is the response we give out for the /wire request. It provides
# wallets with the bank information for transfers to the exchange.
WIRE_RESPONSE = ${TALER_CONFIG_HOME}/account-1.json
@ -89,7 +89,7 @@ ENABLE_CREDIT = YES
# Sections starting with "fee-" configure the wire fee for the
# respective wire method.
[fees-sepa]
[fees-iban]
# Fees for the forseeable future...
# If you see this after 2017, update to match the next 10 years...
WIRE-FEE-2018 = EUR:0.01

View File

@ -58,7 +58,7 @@ CONFIG = "postgres:///talercheck"
# advertised in /wire.
[account-1]
# What is the URL of our account?
URL = "payto://sepa/CH9300762011623852957"
URL = "payto://iban/CH9300762011623852957"
# This is the response we give out for the /wire request. It provides
# wallets with the bank information for transfers to the exchange.
WIRE_RESPONSE = ${TALER_CONFIG_HOME}/account-1.json
@ -90,7 +90,7 @@ ENABLE_CREDIT = YES
# Sections starting with "fee-" configure the wire fee for the
# respective wire method.
[fees-sepa]
[fees-iban]
# Fees for the forseeable future...
# If you see this after 2017, update to match the next 10 years...
WIRE-FEE-2018 = EUR:0.01

View File

@ -62,7 +62,7 @@ CONFIG = "postgres:///talercheck"
WIRE_RESPONSE = ${TALER_CONFIG_HOME}/iban.json
# What is the URL of our bank account? Must match WIRE_RESPONSE above!
URL = payto://sepa/FIXME
URL = payto://iban/FIXME
# Which plugin implements access for this account?
PLUGIN = "ebics"
@ -132,7 +132,7 @@ CLOSING-FEE-2034 = EUR:0.01
CLOSING-FEE-2035 = EUR:0.01
[fees-sepa]
[fees-iban]
# Fees for the forseeable future...
# If you see this after 2017, update to match the next 10 years...
WIRE-FEE-2017 = EUR:0.01

View File

@ -42,6 +42,7 @@ libtaler_plugin_wire_taler_bank_la_LDFLAGS = \
$(TALER_PLUGIN_LDFLAGS) \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/wire/libtalerwire.la \
$(top_builddir)/src/util/libtalerutil.la \
-lgnunetcurl \
-lgnunetutil $(XLIB)
@ -53,6 +54,7 @@ libtaler_plugin_wire_ebics_la_LIBADD = \
$(LTLIBINTL)
libtaler_plugin_wire_ebics_la_LDFLAGS = \
$(TALER_PLUGIN_LDFLAGS) \
$(top_builddir)/src/wire/libtalerwire.la \
$(top_builddir)/src/util/libtalerutil.la \
-lgnunetutil $(XLIB)

View File

@ -22,6 +22,7 @@
* @author Sree Harsha Totakura
*/
#include "platform.h"
#include "taler_wire_lib.h"
#include "taler_wire_plugin.h"
#include "taler_signatures.h"
#include <gnunet/gnunet_json_lib.h>
@ -81,358 +82,6 @@ ebics_amount_round (void *cls,
}
/* Taken from GNU gettext */
/**
* Entry in the country table.
*/
struct CountryTableEntry
{
/**
* 2-Character international country code.
*/
const char *code;
/**
* Long English name of the country.
*/
const char *english;
};
/* Keep the following table in sync with gettext.
WARNING: the entries should stay sorted according to the code */
/**
* List of country codes.
*/
static const struct CountryTableEntry country_table[] =
{
{ "AE", "U.A.E." },
{ "AF", "Afghanistan" },
{ "AL", "Albania" },
{ "AM", "Armenia" },
{ "AN", "Netherlands Antilles" },
{ "AR", "Argentina" },
{ "AT", "Austria" },
{ "AU", "Australia" },
{ "AZ", "Azerbaijan" },
{ "BA", "Bosnia and Herzegovina" },
{ "BD", "Bangladesh" },
{ "BE", "Belgium" },
{ "BG", "Bulgaria" },
{ "BH", "Bahrain" },
{ "BN", "Brunei Darussalam" },
{ "BO", "Bolivia" },
{ "BR", "Brazil" },
{ "BT", "Bhutan" },
{ "BY", "Belarus" },
{ "BZ", "Belize" },
{ "CA", "Canada" },
{ "CG", "Congo" },
{ "CH", "Switzerland" },
{ "CI", "Cote d'Ivoire" },
{ "CL", "Chile" },
{ "CM", "Cameroon" },
{ "CN", "People's Republic of China" },
{ "CO", "Colombia" },
{ "CR", "Costa Rica" },
{ "CS", "Serbia and Montenegro" },
{ "CZ", "Czech Republic" },
{ "DE", "Germany" },
{ "DK", "Denmark" },
{ "DO", "Dominican Republic" },
{ "DZ", "Algeria" },
{ "EC", "Ecuador" },
{ "EE", "Estonia" },
{ "EG", "Egypt" },
{ "ER", "Eritrea" },
{ "ES", "Spain" },
{ "ET", "Ethiopia" },
{ "FI", "Finland" },
{ "FO", "Faroe Islands" },
{ "FR", "France" },
{ "GB", "United Kingdom" },
{ "GD", "Caribbean" },
{ "GE", "Georgia" },
{ "GL", "Greenland" },
{ "GR", "Greece" },
{ "GT", "Guatemala" },
{ "HK", "Hong Kong" },
{ "HK", "Hong Kong S.A.R." },
{ "HN", "Honduras" },
{ "HR", "Croatia" },
{ "HT", "Haiti" },
{ "HU", "Hungary" },
{ "ID", "Indonesia" },
{ "IE", "Ireland" },
{ "IL", "Israel" },
{ "IN", "India" },
{ "IQ", "Iraq" },
{ "IR", "Iran" },
{ "IS", "Iceland" },
{ "IT", "Italy" },
{ "JM", "Jamaica" },
{ "JO", "Jordan" },
{ "JP", "Japan" },
{ "KE", "Kenya" },
{ "KG", "Kyrgyzstan" },
{ "KH", "Cambodia" },
{ "KR", "South Korea" },
{ "KW", "Kuwait" },
{ "KZ", "Kazakhstan" },
{ "LA", "Laos" },
{ "LB", "Lebanon" },
{ "LI", "Liechtenstein" },
{ "LK", "Sri Lanka" },
{ "LT", "Lithuania" },
{ "LU", "Luxembourg" },
{ "LV", "Latvia" },
{ "LY", "Libya" },
{ "MA", "Morocco" },
{ "MC", "Principality of Monaco" },
{ "MD", "Moldava" },
{ "MD", "Moldova" },
{ "ME", "Montenegro" },
{ "MK", "Former Yugoslav Republic of Macedonia" },
{ "ML", "Mali" },
{ "MM", "Myanmar" },
{ "MN", "Mongolia" },
{ "MO", "Macau S.A.R." },
{ "MT", "Malta" },
{ "MV", "Maldives" },
{ "MX", "Mexico" },
{ "MY", "Malaysia" },
{ "NG", "Nigeria" },
{ "NI", "Nicaragua" },
{ "NL", "Netherlands" },
{ "NO", "Norway" },
{ "NP", "Nepal" },
{ "NZ", "New Zealand" },
{ "OM", "Oman" },
{ "PA", "Panama" },
{ "PE", "Peru" },
{ "PH", "Philippines" },
{ "PK", "Islamic Republic of Pakistan" },
{ "PL", "Poland" },
{ "PR", "Puerto Rico" },
{ "PT", "Portugal" },
{ "PY", "Paraguay" },
{ "QA", "Qatar" },
{ "RE", "Reunion" },
{ "RO", "Romania" },
{ "RS", "Serbia" },
{ "RU", "Russia" },
{ "RW", "Rwanda" },
{ "SA", "Saudi Arabia" },
{ "SE", "Sweden" },
{ "SG", "Singapore" },
{ "SI", "Slovenia" },
{ "SK", "Slovak" },
{ "SN", "Senegal" },
{ "SO", "Somalia" },
{ "SR", "Suriname" },
{ "SV", "El Salvador" },
{ "SY", "Syria" },
{ "TH", "Thailand" },
{ "TJ", "Tajikistan" },
{ "TM", "Turkmenistan" },
{ "TN", "Tunisia" },
{ "TR", "Turkey" },
{ "TT", "Trinidad and Tobago" },
{ "TW", "Taiwan" },
{ "TZ", "Tanzania" },
{ "UA", "Ukraine" },
{ "US", "United States" },
{ "UY", "Uruguay" },
{ "VA", "Vatican" },
{ "VE", "Venezuela" },
{ "VN", "Viet Nam" },
{ "YE", "Yemen" },
{ "ZA", "South Africa" },
{ "ZW", "Zimbabwe" }
};
/**
* Country code comparator function, for binary search with bsearch().
*
* @param ptr1 pointer to a `struct table_entry`
* @param ptr2 pointer to a `struct table_entry`
* @return result of strncmp()'ing the 2-digit country codes of the entries
*/
static int
cmp_country_code (const void *ptr1,
const void *ptr2)
{
const struct CountryTableEntry *cc1 = ptr1;
const struct CountryTableEntry *cc2 = ptr2;
return strncmp (cc1->code,
cc2->code,
2);
}
/**
* Validates given IBAN according to the European Banking Standards. See:
* http://www.europeanpaymentscouncil.eu/documents/ECBS%20IBAN%20standard%20EBS204_V3.2.pdf
*
* @param iban the IBAN number to validate
* @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not
*/
static int
validate_iban (const char *iban)
{
char cc[2];
char ibancpy[35];
struct CountryTableEntry cc_entry;
unsigned int len;
char *nbuf;
unsigned long long dividend;
unsigned long long remainder;
int nread;
int ret;
unsigned int i;
unsigned int j;
len = strlen (iban);
if (len > 34)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"IBAN number too long to be valid\n");
return GNUNET_NO;
}
strncpy (cc, iban, 2);
strncpy (ibancpy, iban + 4, len - 4);
strncpy (ibancpy + len - 4, iban, 4);
ibancpy[len] = '\0';
cc_entry.code = cc;
cc_entry.english = NULL;
if (NULL ==
bsearch (&cc_entry,
country_table,
sizeof (country_table) / sizeof (struct CountryTableEntry),
sizeof (struct CountryTableEntry),
&cmp_country_code))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Country code `%c%c' not supported\n",
cc[0],
cc[1]);
return GNUNET_NO;
}
nbuf = GNUNET_malloc ((len * 2) + 1);
for (i=0, j=0; i < len; i++)
{
if (isalpha ((unsigned char) ibancpy[i]))
{
if (2 != snprintf(&nbuf[j],
3,
"%2u",
(ibancpy[i] - 'A' + 10)))
{
GNUNET_free (nbuf);
return GNUNET_NO;
}
j += 2;
continue;
}
nbuf[j] = ibancpy[i];
j++;
}
for (j=0;'\0' != nbuf[j];j++)
GNUNET_assert (isdigit( (unsigned char) nbuf[j]));
GNUNET_assert (sizeof(dividend) >= 8);
remainder = 0;
for (i=0; i<j; i+=16)
{
if (1 !=
(ret = sscanf (&nbuf[i],
"%16llu %n",
&dividend,
&nread)))
{
GNUNET_free (nbuf);
GNUNET_break_op (0);
return GNUNET_NO;
}
if (0 != remainder)
dividend += remainder * (pow (10, nread));
remainder = dividend % 97;
}
GNUNET_free (nbuf);
if (1 == remainder)
return GNUNET_YES;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"IBAN checksum wrong\n");
return GNUNET_NO;
}
/**
* Information about an account extracted from a payto://-URL.
*/
struct Account
{
/**
* The IBAN number.
*/
char *iban;
};
/**
* Parse payto:// account URL (only account information,
* wire subject and amount are ignored).
*
* @param account_url URL to parse
* @param account[out] set to information, can be NULL
* @return #TALER_EC_NONE if @a account_url is well-formed
*/
static enum TALER_ErrorCode
parse_payto (const char *account_url,
struct Account *account)
{
const char *iban;
const char *q;
char *result;
#define PREFIX "payto://sepa/"
if (0 != strncasecmp (account_url,
PREFIX,
strlen (PREFIX)))
return TALER_EC_PAYTO_WRONG_METHOD;
iban = &account_url[strlen (PREFIX)];
q = strchr (iban,
'?');
if (NULL != q)
{
result = GNUNET_strndup (iban,
q - iban);
}
else
{
result = GNUNET_strdup (iban);
}
if (GNUNET_OK !=
validate_iban (result))
{
GNUNET_free (result);
return TALER_EC_PAYTO_MALFORMED;
}
if (NULL != account)
{
account->iban = result;
}
else
{
GNUNET_free (result);
}
return TALER_EC_NONE;
}
/**
* Check if the given payto:// URL is correctly formatted for this plugin
*
@ -444,8 +93,19 @@ static enum TALER_ErrorCode
ebics_wire_validate (void *cls,
const char *account_url)
{
return parse_payto (account_url,
NULL);
(void) cls;
struct TALER_Account acc;
enum TALER_ErrorCode ec;
ec = TALER_WIRE_payto_to_account (account_url,
&acc);
if (TALER_EC_NONE == ec)
{
if (TALER_PAC_IBAN != acc.type)
ec = TALER_EC_PAYTO_WRONG_METHOD;
TALER_WIRE_account_free (&acc);
}
return ec;
}
@ -717,7 +377,7 @@ libtaler_plugin_wire_ebics_init (void *cls)
}
plugin = GNUNET_new (struct TALER_WIRE_Plugin);
plugin->cls = sc;
plugin->method = "sepa";
plugin->method = "iban";
plugin->amount_round = &ebics_amount_round;
plugin->wire_validate = &ebics_wire_validate;
plugin->prepare_wire_transfer = &ebics_prepare_wire_transfer;

View File

@ -22,6 +22,7 @@
#include "platform.h"
#include "taler_wire_plugin.h"
#include "taler_json_lib.h"
#include "taler_wire_lib.h"
#include "taler_bank_service.h"
#include "taler_signatures.h"
#include <gnunet/gnunet_curl_lib.h>
@ -29,11 +30,6 @@
/* only for HTTP status codes */
#include <microhttpd.h>
/**
* Maximum legal 'value' for an account number, based on IEEE double (for JavaScript compatibility).
*/
#define MAX_ACCOUNT_NO (1LLU << 52)
/**
* Type of the "cls" argument given to each of the functions in
* our API.
@ -188,124 +184,6 @@ taler_bank_amount_round (void *cls,
}
/**
* Information about an account extracted from a payto://-URL.
*/
struct Account
{
/**
* Hostname of the bank (possibly including port).
*/
char *hostname;
/**
* Bank account number.
*/
unsigned long long no;
/**
* Base URL of the bank hosting the account above.
*/
char *bank_base_url;
};
/**
* Parse payto:// account URL (only account information,
* wire subject and amount are ignored).
*
* @param account_url URL to parse
* @param account[out] set to information, can be NULL
* @return #TALER_EC_NONE if @a account_url is well-formed
*/
static enum TALER_ErrorCode
parse_payto (const char *account_url,
struct Account *r_account)
{
const char *hostname;
const char *account;
const char *q;
unsigned long long no;
#define PREFIX "payto://x-taler-bank/"
if (0 != strncasecmp (account_url,
PREFIX,
strlen (PREFIX)))
return TALER_EC_PAYTO_WRONG_METHOD;
hostname = &account_url[strlen (PREFIX)];
if (NULL == (account = strchr (hostname,
(unsigned char) '/')))
return TALER_EC_PAYTO_MALFORMED;
account++;
if (NULL != (q = strchr (account,
(unsigned char) '?')))
{
char *s;
s = GNUNET_strndup (account,
q - account);
if (1 != sscanf (s,
"%llu",
&no))
{
GNUNET_free (s);
return TALER_EC_PAYTO_MALFORMED;
}
GNUNET_free (s);
}
else if (1 != sscanf (account,
"%llu",
&no))
{
return TALER_EC_PAYTO_MALFORMED;
}
if (no > MAX_ACCOUNT_NO)
return TALER_EC_PAYTO_MALFORMED;
if (NULL != r_account)
{
long long unsigned port;
char *p;
r_account->hostname = GNUNET_strndup (hostname,
account - hostname);
r_account->no = no;
port = 443; /* if non given, equals 443. */
if (NULL != (p = strchr (r_account->hostname,
(unsigned char) ':')))
{
p++;
if (1 != sscanf (p,
"%llu",
&port))
{
GNUNET_break (0);
TALER_LOG_ERROR ("Malformed host from payto:// URI\n");
GNUNET_free (r_account->hostname);
return TALER_EC_PAYTO_MALFORMED;
}
}
if (443 != port)
{
GNUNET_assert
(GNUNET_SYSERR != GNUNET_asprintf
(&r_account->bank_base_url,
"http://%s",
r_account->hostname));
}
else
{
GNUNET_assert
(GNUNET_SYSERR != GNUNET_asprintf
(&r_account->bank_base_url,
"https://%s",
r_account->hostname));
}
}
return TALER_EC_NONE;
}
/**
* Check if the given payto:// URL is correctly formatted.
*
@ -318,9 +196,18 @@ taler_bank_wire_validate (void *cls,
const char *account_url)
{
(void) cls;
struct TALER_Account acc;
enum TALER_ErrorCode ec;
return parse_payto (account_url,
NULL);
ec = TALER_WIRE_payto_to_account (account_url,
&acc);
if (TALER_EC_NONE == ec)
{
if (TALER_PAC_X_TALER_BANK != acc.type)
ec = TALER_EC_PAYTO_WRONG_METHOD;
TALER_WIRE_account_free (&acc);
}
return ec;
}
@ -462,7 +349,7 @@ do_prepare (void *cls)
static int
parse_account_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *section,
struct Account *account)
struct TALER_Account *account)
{
char *account_url;
@ -479,7 +366,7 @@ parse_account_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
}
if (TALER_EC_NONE !=
parse_payto (account_url,
TALER_WIRE_payto_to_account (account_url,
account))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
@ -489,6 +376,16 @@ parse_account_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_free (account_url);
return GNUNET_SYSERR;
}
if (TALER_PAC_X_TALER_BANK != account->type)
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
section,
"URL",
"Malformed payto:// URL for x-taler-bank method");
GNUNET_free (account_url);
TALER_WIRE_account_free (account);
return GNUNET_SYSERR;
}
GNUNET_free (account_url);
return GNUNET_OK;
}
@ -525,12 +422,12 @@ taler_bank_prepare_wire_transfer (void *cls,
struct TalerBankClosure *tc = cls;
struct TALER_WIRE_PrepareHandle *pth;
char *origin_account_url;
struct Account a_in;
struct Account a_out;
struct TALER_Account a_in;
struct TALER_Account a_out;
/* Check that payto:// URLs are valid */
if (TALER_EC_NONE !=
parse_payto (destination_account_url,
TALER_WIRE_payto_to_account (destination_account_url,
&a_out))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -538,6 +435,14 @@ taler_bank_prepare_wire_transfer (void *cls,
destination_account_url);
return NULL;
}
if (TALER_PAC_X_TALER_BANK != a_out.type)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"payto://-URL `%s' is invalid!\n",
destination_account_url);
TALER_WIRE_account_free (&a_out);
return NULL;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (tc->cfg,
origin_account_section,
@ -547,12 +452,11 @@ taler_bank_prepare_wire_transfer (void *cls,
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
origin_account_section,
"URL");
GNUNET_free (a_out.hostname);
GNUNET_free (a_out.bank_base_url);
TALER_WIRE_account_free (&a_out);
return NULL;
}
if (TALER_EC_NONE !=
parse_payto (origin_account_url,
TALER_WIRE_payto_to_account (origin_account_url,
&a_in))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
@ -560,30 +464,35 @@ taler_bank_prepare_wire_transfer (void *cls,
"URL",
"Malformed payto:// URL for x-taler-bank method");
GNUNET_free (origin_account_url);
GNUNET_free (a_out.hostname);
GNUNET_free (a_out.bank_base_url);
TALER_WIRE_account_free (&a_out);
return NULL;
}
if (TALER_PAC_X_TALER_BANK != a_in.type)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"payto://-URL `%s' is invalid!\n",
origin_account_url);
GNUNET_free (origin_account_url);
TALER_WIRE_account_free (&a_in);
TALER_WIRE_account_free (&a_out);
return NULL;
}
/* Make sure the bank is the same! */
if (0 != strcasecmp (a_in.hostname,
a_out.hostname))
if (0 != strcasecmp (a_in.details.x_taler_bank.hostname,
a_out.details.x_taler_bank.hostname))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"x-taler-bank hostname missmatch: `%s' != `%s'\n",
a_in.hostname,
a_out.hostname);
GNUNET_free (a_in.hostname);
GNUNET_free (a_in.bank_base_url);
GNUNET_free (a_out.hostname);
GNUNET_free (a_out.bank_base_url);
a_in.details.x_taler_bank.hostname,
a_out.details.x_taler_bank.hostname);
TALER_WIRE_account_free (&a_in);
TALER_WIRE_account_free (&a_out);
GNUNET_free (origin_account_url);
return NULL;
}
GNUNET_free (a_in.hostname);
GNUNET_free (a_in.bank_base_url);
GNUNET_free (a_out.hostname);
GNUNET_free (a_out.bank_base_url);
TALER_WIRE_account_free (&a_in);
TALER_WIRE_account_free (&a_out);
pth = GNUNET_new (struct TALER_WIRE_PrepareHandle);
if (GNUNET_OK !=
@ -690,8 +599,8 @@ taler_bank_execute_wire_transfer (void *cls,
struct TalerBankClosure *tc = cls;
struct TALER_WIRE_ExecuteHandle *eh;
struct TALER_Amount amount;
struct Account origin_account;
struct Account destination_account;
struct TALER_Account origin_account;
struct TALER_Account destination_account;
struct BufFormatP bf;
const char *exchange_base_url;
const char *origin_account_url;
@ -770,29 +679,28 @@ taler_bank_execute_wire_transfer (void *cls,
}
if (TALER_EC_NONE !=
parse_payto (origin_account_url,
TALER_WIRE_payto_to_account (origin_account_url,
&origin_account))
{
GNUNET_break (0);
return NULL;
}
if (TALER_EC_NONE !=
parse_payto (destination_account_url,
TALER_WIRE_payto_to_account (destination_account_url,
&destination_account))
{
GNUNET_free_non_null (origin_account.hostname);
GNUNET_free_non_null (origin_account.bank_base_url);
TALER_WIRE_account_free (&origin_account);
GNUNET_break (0);
return NULL;
}
if (0 != strcasecmp (origin_account.hostname,
destination_account.hostname))
if ( (TALER_PAC_X_TALER_BANK != origin_account.type) ||
(TALER_PAC_X_TALER_BANK != destination_account.type) ||
(0 != strcasecmp (origin_account.details.x_taler_bank.hostname,
destination_account.details.x_taler_bank.hostname)) )
{
GNUNET_break (0);
GNUNET_free_non_null (origin_account.hostname);
GNUNET_free_non_null (destination_account.hostname);
GNUNET_free_non_null (origin_account.bank_base_url);
GNUNET_free_non_null (destination_account.bank_base_url);
TALER_WIRE_account_free (&origin_account);
TALER_WIRE_account_free (&destination_account);
return NULL;
}
@ -802,19 +710,17 @@ taler_bank_execute_wire_transfer (void *cls,
wire_s = GNUNET_STRINGS_data_to_string_alloc (&bf.wtid,
sizeof (bf.wtid));
eh->aaih = TALER_BANK_admin_add_incoming (tc->ctx,
origin_account.bank_base_url,
origin_account.details.x_taler_bank.bank_base_url,
&auth,
exchange_base_url,
wire_s,
&amount,
(uint64_t) origin_account.no,
(uint64_t) destination_account.no,
(uint64_t) origin_account.details.x_taler_bank.no,
(uint64_t) destination_account.details.x_taler_bank.no,
&execute_cb,
eh);
GNUNET_free_non_null (origin_account.bank_base_url);
GNUNET_free_non_null (destination_account.bank_base_url);
GNUNET_free_non_null (origin_account.hostname);
GNUNET_free_non_null (destination_account.hostname);
TALER_WIRE_account_free (&origin_account);
TALER_WIRE_account_free (&destination_account);
GNUNET_free (wire_s);
if (NULL == eh->aaih)
{
@ -1044,7 +950,7 @@ taler_bank_get_history (void *cls,
struct TALER_WIRE_HistoryHandle *whh;
const uint64_t *start_off_b64;
uint64_t start_row;
struct Account account;
struct TALER_Account account;
if (0 == num_results)
{
@ -1111,9 +1017,9 @@ taler_bank_get_history (void *cls,
whh->hres_cb_cls = hres_cb_cls;
whh->hh = TALER_BANK_history (tc->ctx,
account.bank_base_url,
account.details.x_taler_bank.bank_base_url,
&whh->auth,
(uint64_t) account.no,
(uint64_t) account.details.x_taler_bank.no,
direction,
/* Defaults to descending ordering always. */
GNUNET_NO,
@ -1126,12 +1032,10 @@ taler_bank_get_history (void *cls,
GNUNET_break (0);
taler_bank_get_history_cancel (NULL,
whh);
GNUNET_free (account.hostname);
GNUNET_free (account.bank_base_url);
TALER_WIRE_account_free (&account);
return NULL;
}
GNUNET_free (account.hostname);
GNUNET_free (account.bank_base_url);
TALER_WIRE_account_free (&account);
GNUNET_assert (NULL != whh);
return whh;
}
@ -1171,7 +1075,7 @@ taler_bank_get_history_range
GNUNET_break (0);
return NULL;
struct Account account;
struct TALER_Account account;
struct TalerBankClosure *tc = cls;
struct TALER_WIRE_HistoryHandle *whh;
@ -1204,9 +1108,9 @@ taler_bank_get_history_range
whh->hh = TALER_BANK_history_range (tc->ctx,
account.bank_base_url,
account.details.x_taler_bank.bank_base_url,
&whh->auth,
account.no,
account.details.x_taler_bank.no,
direction,
/* Just always descending. */
GNUNET_NO,
@ -1219,13 +1123,10 @@ taler_bank_get_history_range
GNUNET_break (0);
taler_bank_get_history_cancel (NULL,
whh);
GNUNET_free (account.hostname);
GNUNET_free (account.bank_base_url);
TALER_WIRE_account_free (&account);
return NULL;
}
GNUNET_free (account.hostname);
GNUNET_free (account.bank_base_url);
TALER_WIRE_account_free (&account);
GNUNET_assert (NULL != whh);
return whh;
@ -1339,7 +1240,7 @@ taler_bank_reject_transfer (void *cls,
struct TalerBankClosure *tc = cls;
const uint64_t *rowid_b64 = start_off;
struct TALER_WIRE_RejectHandle *rh;
struct Account account;
struct TALER_Account account;
if (sizeof (uint64_t) != start_off_len)
{
@ -1367,11 +1268,11 @@ taler_bank_reject_transfer (void *cls,
rh->rej_cb = rej_cb;
rh->rej_cb_cls = rej_cb_cls;
TALER_LOG_INFO ("Rejecting over %s bank URL\n",
account.hostname);
account.details.x_taler_bank.hostname);
rh->brh = TALER_BANK_reject (tc->ctx,
account.bank_base_url,
account.details.x_taler_bank.bank_base_url,
&rh->auth,
(uint64_t) account.no,
(uint64_t) account.details.x_taler_bank.no,
GNUNET_ntohll (*rowid_b64),
&reject_cb,
rh);
@ -1379,10 +1280,10 @@ taler_bank_reject_transfer (void *cls,
{
(void) taler_bank_reject_transfer_cancel (tc,
rh);
GNUNET_free (account.hostname);
TALER_WIRE_account_free (&account);
return NULL;
}
GNUNET_free (account.hostname);
TALER_WIRE_account_free (&account);
return rh;
}

View File

@ -26,17 +26,17 @@
/**
* Valid SEPA data
*/
static const char *valid_wire_str = "payto://sepa/DE67830654080004822650";
static const char *valid_wire_str = "payto://iban/DE67830654080004822650";
/**
* IBAN has wrong country code
*/
static const char *invalid_wire_str = "payto://sepa/XX67830654080004822650";
static const char *invalid_wire_str = "payto://iban/XX67830654080004822650";
/**
* IBAN has wrong checksum
*/
static const char *invalid_wire_str2 = "payto://sepa/DE67830654080004822651";
static const char *invalid_wire_str2 = "payto://iban/DE67830654080004822651";
/**
* Unsupported wireformat type

View File

@ -12,6 +12,7 @@ lib_LTLIBRARIES = \
libtalerwire.la
libtalerwire_la_SOURCES = \
payto.c \
wire.c \
wire_helper.c
libtalerwire_la_LIBADD = \

View File

@ -39,7 +39,7 @@ struct ConversionTable
{
/**
* Wire method (e.g. 'sepa', 'x-taler-bank', ..)
* Wire method (e.g. 'iban', 'x-taler-bank', ..)
*/
const char *method;
@ -87,7 +87,7 @@ TALER_WIRE_get_plugin_from_method (const char *method)
{
static const struct ConversionTable ct[] = {
{"x-taler-bank", "taler_bank"},
{"sepa", "ebics"},
{"iban", "ebics"},
{NULL, NULL}
};