summaryrefslogtreecommitdiff
path: root/src/exchange-tools
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-02 20:58:22 +0200
committerChristian Grothoff <christian@grothoff.org>2016-04-02 20:58:22 +0200
commitdaae3d3ddf1cbee4761a6a2c0066732fb4723fb0 (patch)
treeba2e9a677f6a1bede7f871adc9ca0c97ac62e7c6 /src/exchange-tools
parent937078bbdc747c92d45a3879862ff4664d1ff636 (diff)
downloadexchange-daae3d3ddf1cbee4761a6a2c0066732fb4723fb0.tar.gz
exchange-daae3d3ddf1cbee4761a6a2c0066732fb4723fb0.tar.bz2
exchange-daae3d3ddf1cbee4761a6a2c0066732fb4723fb0.zip
change taler-exchange-sepa to a more generic taler-exchange-wire tool using the wire plugins (#4237)
Diffstat (limited to 'src/exchange-tools')
-rw-r--r--src/exchange-tools/Makefile.am10
-rw-r--r--src/exchange-tools/taler-exchange-sepa.c189
-rw-r--r--src/exchange-tools/taler-exchange-wire.c201
3 files changed, 206 insertions, 194 deletions
diff --git a/src/exchange-tools/Makefile.am b/src/exchange-tools/Makefile.am
index fda9cefa..feb3c314 100644
--- a/src/exchange-tools/Makefile.am
+++ b/src/exchange-tools/Makefile.am
@@ -11,7 +11,7 @@ bin_PROGRAMS = \
taler-exchange-keyup \
taler-exchange-keycheck \
taler-exchange-reservemod \
- taler-exchange-sepa \
+ taler-exchange-wire \
taler-exchange-dbinit
taler_exchange_keyup_SOURCES = \
@@ -33,15 +33,15 @@ taler_auditor_sign_LDADD = \
-lgnunetutil $(XLIB)
-taler_exchange_sepa_SOURCES = \
- taler-exchange-sepa.c
-taler_exchange_sepa_LDADD = \
+taler_exchange_wire_SOURCES = \
+ taler-exchange-wire.c
+taler_exchange_wire_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
-lgnunetjson \
-lgnunetutil \
-ljansson $(XLIB)
-taler_exchange_sepa_LDFLAGS = $(POSTGRESQL_LDFLAGS)
+taler_exchange_wire_LDFLAGS = $(POSTGRESQL_LDFLAGS)
taler_exchange_keycheck_SOURCES = \
taler-exchange-keycheck.c
diff --git a/src/exchange-tools/taler-exchange-sepa.c b/src/exchange-tools/taler-exchange-sepa.c
deleted file mode 100644
index 1bfb4913..00000000
--- a/src/exchange-tools/taler-exchange-sepa.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2015 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
- 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, If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-exchange-sepa.c
- * @brief Create signed response for /wire/sepa requests.
- * @author Christian Grothoff
- */
-#include <platform.h>
-#include <jansson.h>
-#include <gnunet/gnunet_json_lib.h>
-#include "taler_crypto_lib.h"
-#include "taler_signatures.h"
-
-
-/**
- * Filename of the master private key.
- */
-static char *masterkeyfile;
-
-/**
- * Account holder name.
- */
-static char *sepa_name;
-
-/**
- * Account holder address.
- */
-static char *sepa_address;
-
-/**
- * IBAN number.
- */
-static char *iban;
-
-/**
- * BIC number.
- */
-static char *bic;
-
-/**
- * Where to write the result.
- */
-static char *output_filename;
-
-
-/**
- * The main function of the taler-exchange-sepa tool. This tool is used
- * to sign the SEPA bank account details using the master key.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return 0 ok, 1 on error
- */
-int
-main (int argc,
- char *const *argv)
-{
- static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'a', "address", "ADDRESS",
- "account holder address", 1,
- &GNUNET_GETOPT_set_string, &sepa_address},
- {'b', "bic", "BICCODE",
- "bank BIC code", 1,
- &GNUNET_GETOPT_set_string, &bic},
- {'i', "iban", "IBAN",
- "IBAN number of the account", 1,
- &GNUNET_GETOPT_set_string, &iban},
- {'m', "master-key", "FILE",
- "master key file (private key)", 1,
- &GNUNET_GETOPT_set_filename, &masterkeyfile},
- {'n', "name", "NAME",
- "name of the account holder", 1,
- &GNUNET_GETOPT_set_string, &sepa_name},
- {'o', "output", "FILE",
- "where to write the result", 1,
- &GNUNET_GETOPT_set_filename, &output_filename},
- TALER_GETOPT_OPTION_HELP ("Setup /wire/sepa response"),
- GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
- struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
- struct TALER_MasterWireSepaDetailsPS wsd;
- struct TALER_MasterSignatureP sig;
- struct GNUNET_HashContext *hc;
- json_t *reply;
- char *json_str;
- struct GNUNET_HashCode salt;
-
- GNUNET_assert (GNUNET_OK ==
- GNUNET_log_setup ("taler-exchange-sepa",
- "WARNING",
- NULL));
-
- if (GNUNET_GETOPT_run ("taler-exchange-sepa",
- options,
- argc, argv) < 0)
- return 1;
- if (NULL == masterkeyfile)
- {
- fprintf (stderr,
- "Master key file not given\n");
- return 1;
- }
- eddsa_priv = GNUNET_CRYPTO_eddsa_key_create_from_file (masterkeyfile);
- if (NULL == eddsa_priv)
- {
- fprintf (stderr,
- "Failed to initialize master key from file `%s'\n",
- masterkeyfile);
- return 1;
- }
- if ( (NULL == sepa_address) ||
- (NULL == iban) ||
- (NULL == sepa_name) ||
- (NULL == bic) )
- {
- fprintf (stderr,
- "Required arguments missing\n");
- return 1;
- }
-
- /* Compute message to sign */
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
- &salt,
- sizeof (salt));
- hc = GNUNET_CRYPTO_hash_context_start ();
- GNUNET_CRYPTO_hash_context_read (hc,
- sepa_name,
- strlen (sepa_name) + 1);
- GNUNET_CRYPTO_hash_context_read (hc,
- iban,
- strlen (iban) + 1);
- GNUNET_CRYPTO_hash_context_read (hc,
- bic,
- strlen (bic) + 1);
- wsd.purpose.size = htonl (sizeof (wsd));
- wsd.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_SEPA_DETAILS);
- GNUNET_CRYPTO_hash_context_finish (hc,
- &wsd.h_sepa_details);
- GNUNET_CRYPTO_eddsa_sign (eddsa_priv,
- &wsd.purpose,
- &sig.eddsa_signature);
- GNUNET_free (eddsa_priv);
-
- /* build JSON message */
- reply = json_pack ("{s:s, s:s, s:s, s:s, s:s, s:o, s:o}",
- "type", "sepa",
- "address", sepa_address,
- "receiver_name", sepa_name,
- "iban", iban,
- "bic", bic,
- "salt", GNUNET_JSON_from_data (&salt,
- sizeof (salt)),
- "sig", GNUNET_JSON_from_data (&sig,
- sizeof (sig)));
- GNUNET_assert (NULL != reply);
-
- /* dump result to stdout */
- json_str = json_dumps (reply, JSON_INDENT(2));
- GNUNET_assert (NULL != json_str);
-
- if (NULL != output_filename)
- {
- fclose (stdout);
- stdout = fopen (output_filename,
- "w+");
- }
- fprintf (stdout,
- "%s",
- json_str);
- fflush (stdout);
- free (json_str);
- return 0;
-}
-
-/* end of taler-exchange-sepa.c */
diff --git a/src/exchange-tools/taler-exchange-wire.c b/src/exchange-tools/taler-exchange-wire.c
new file mode 100644
index 00000000..3bea78f6
--- /dev/null
+++ b/src/exchange-tools/taler-exchange-wire.c
@@ -0,0 +1,201 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2015, 2016 Inria
+
+ 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, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-wire.c
+ * @brief Create signed response for /wire requests.
+ * @author Christian Grothoff
+ */
+#include <platform.h>
+#include <jansson.h>
+#include <gnunet/gnunet_json_lib.h>
+#include "taler_crypto_lib.h"
+#include "taler_wire_plugin.h"
+#include "taler_signatures.h"
+
+
+/**
+ * Filename of the master private key.
+ */
+static char *masterkeyfile;
+
+/**
+ * Account holder information in JSON format.
+ */
+static char *json_in;
+
+/**
+ * Which wire method is this for?
+ */
+static char *method;
+
+/**
+ * Where to write the result.
+ */
+static char *output_filename;
+
+
+/**
+ * The main function of the taler-exchange-sepa tool. This tool is used
+ * to sign the SEPA bank account details using the master key.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv)
+{
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ {'j', "json", "JSON",
+ "account information in JSON format", 1,
+ &GNUNET_GETOPT_set_string, &json_in},
+ {'m', "master-key", "FILE",
+ "master key file (private key)", 1,
+ &GNUNET_GETOPT_set_filename, &masterkeyfile},
+ {'t', "type", "METHOD",
+ "which wire transfer method (i.e. 'test' or 'sepa') is this for?", 1,
+ &GNUNET_GETOPT_set_filename, &method},
+ {'o', "output", "FILE",
+ "where to write the result", 1,
+ &GNUNET_GETOPT_set_filename, &output_filename},
+ TALER_GETOPT_OPTION_HELP ("Setup /wire response"),
+ GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END
+ };
+ struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
+ struct TALER_MasterPrivateKeyP key;
+ struct TALER_MasterSignatureP sig;
+ json_t *j;
+ json_error_t err;
+ char *json_out;
+ struct GNUNET_HashCode salt;
+ char *lib_name;
+ struct TALER_WIRE_Plugin *plugin;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_log_setup ("taler-exchange-wire",
+ "WARNING",
+ NULL));
+
+ if (GNUNET_GETOPT_run ("taler-exchange-wire",
+ options,
+ argc, argv) < 0)
+ return 1;
+ if (NULL == masterkeyfile)
+ {
+ fprintf (stderr,
+ "Master key file not given\n");
+ return 1;
+ }
+ eddsa_priv = GNUNET_CRYPTO_eddsa_key_create_from_file (masterkeyfile);
+ if (NULL == eddsa_priv)
+ {
+ fprintf (stderr,
+ "Failed to initialize master key from file `%s'\n",
+ masterkeyfile);
+ return 1;
+ }
+ if (NULL == json_in)
+ {
+ fprintf (stderr,
+ "Required -j argument missing\n");
+ return 1;
+ }
+ if (NULL == method)
+ {
+ fprintf (stderr,
+ "Required -t argument missing\n");
+ return 1;
+ }
+ j = json_loads (json_in,
+ JSON_REJECT_DUPLICATES,
+ &err);
+ if (NULL == j)
+ {
+ fprintf (stderr,
+ "Failed to parse JSON: %s (at offset %u)\n",
+ err.text,
+ (unsigned int) err.position);
+ return 1;
+ }
+ key.eddsa_priv = *eddsa_priv;
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &salt,
+ sizeof (salt));
+ (void) GNUNET_asprintf (&lib_name,
+ "libtaler_plugin_wire_%s",
+ method);
+ plugin = GNUNET_PLUGIN_load (lib_name,
+ NULL);
+ if (NULL == plugin)
+ {
+ GNUNET_free (lib_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Wire transfer method `%s' not supported\n",
+ method);
+ return 1;
+ }
+ plugin->library_name = lib_name;
+ if (GNUNET_OK !=
+ plugin->sign_wire_details (plugin->cls,
+ j,
+ &key,
+ &salt,
+ &sig))
+ {
+ /* sign function should have logged applicable errors */
+ json_decref (j);
+ GNUNET_PLUGIN_unload (lib_name,
+ plugin);
+ GNUNET_free (lib_name);
+ return 1;
+ }
+ GNUNET_PLUGIN_unload (lib_name,
+ plugin);
+ GNUNET_free (lib_name);
+ GNUNET_free (eddsa_priv);
+
+ /* add signature and salt to JSON message */
+ json_object_set_new (j,
+ "salt",
+ GNUNET_JSON_from_data (&salt,
+ sizeof (salt)));
+ json_object_set_new (j,
+ "sig",
+ GNUNET_JSON_from_data (&sig,
+ sizeof (sig)));
+
+ /* dump result to stdout */
+ json_out = json_dumps (j, JSON_INDENT(2));
+ json_decref (j);
+ GNUNET_assert (NULL != json_out);
+
+ if (NULL != output_filename)
+ {
+ fclose (stdout);
+ stdout = fopen (output_filename,
+ "w+");
+ }
+ fprintf (stdout,
+ "%s",
+ json_out);
+ fflush (stdout);
+ free (json_out);
+ return 0;
+}
+
+/* end of taler-exchange-wire.c */