2016-04-02 20:58:22 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2017-03-15 12:01:06 +01:00
|
|
|
Copyright (C) 2015, 2016, 2017 Inria
|
2016-04-02 20:58:22 +02:00
|
|
|
|
|
|
|
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
|
2016-07-07 17:55:25 +02:00
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2016-04-02 20:58:22 +02:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @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"
|
2016-04-16 13:10:29 +02:00
|
|
|
#include "taler_util.h"
|
2016-04-11 13:01:20 +02:00
|
|
|
#include "taler_wire_lib.h"
|
2016-04-02 20:58:22 +02:00
|
|
|
#include "taler_signatures.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filename of the master private key.
|
|
|
|
*/
|
|
|
|
static char *masterkeyfile;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Account holder information in JSON format.
|
|
|
|
*/
|
2017-03-15 12:01:06 +01:00
|
|
|
static json_t *account_holder;
|
2016-04-02 20:58:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Which wire method is this for?
|
|
|
|
*/
|
2017-03-15 12:01:06 +01:00
|
|
|
static char *method;
|
2016-04-02 20:58:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Where to write the result.
|
|
|
|
*/
|
|
|
|
static char *output_filename;
|
|
|
|
|
2016-04-10 17:10:20 +02:00
|
|
|
/**
|
2016-04-16 12:44:45 +02:00
|
|
|
* Return value from main().
|
2016-04-10 17:10:20 +02:00
|
|
|
*/
|
2016-04-16 12:44:45 +02:00
|
|
|
static int global_ret;
|
2016-04-02 20:58:22 +02:00
|
|
|
|
2016-04-16 13:10:29 +02:00
|
|
|
|
2016-04-02 20:58:22 +02:00
|
|
|
/**
|
2016-04-16 12:44:45 +02:00
|
|
|
* Main function that will be run.
|
2016-04-02 20:58:22 +02:00
|
|
|
*
|
2016-04-16 12:44:45 +02:00
|
|
|
* @param cls closure
|
|
|
|
* @param args remaining command-line arguments
|
|
|
|
* @param cfgfile name of the configuration file used (for saving, can be NULL!)
|
2017-04-20 07:49:56 +02:00
|
|
|
* @param cfg configuration
|
2016-04-02 20:58:22 +02:00
|
|
|
*/
|
2016-04-16 12:44:45 +02:00
|
|
|
static void
|
|
|
|
run (void *cls,
|
|
|
|
char *const *args,
|
|
|
|
const char *cfgfile,
|
|
|
|
const struct GNUNET_CONFIGURATION_Handle *cfg)
|
2016-04-02 20:58:22 +02:00
|
|
|
{
|
|
|
|
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
|
|
|
|
struct TALER_MasterPrivateKeyP key;
|
|
|
|
struct TALER_MasterSignatureP sig;
|
|
|
|
char *json_out;
|
|
|
|
struct GNUNET_HashCode salt;
|
|
|
|
struct TALER_WIRE_Plugin *plugin;
|
|
|
|
|
2016-04-10 17:10:20 +02:00
|
|
|
if ( (NULL == masterkeyfile) &&
|
|
|
|
(GNUNET_OK !=
|
|
|
|
GNUNET_CONFIGURATION_get_value_filename (cfg,
|
2016-04-16 12:46:01 +02:00
|
|
|
"exchange",
|
2016-04-10 17:10:20 +02:00
|
|
|
"MASTER_PRIV_FILE",
|
|
|
|
&masterkeyfile)) )
|
2016-04-02 20:58:22 +02:00
|
|
|
{
|
|
|
|
fprintf (stderr,
|
2016-04-10 17:10:20 +02:00
|
|
|
"Master key file not given in neither configuration nor command-line\n");
|
2016-04-16 12:44:45 +02:00
|
|
|
global_ret = 1;
|
|
|
|
return;
|
2016-04-02 20:58:22 +02:00
|
|
|
}
|
2016-05-05 15:03:43 +02:00
|
|
|
if (GNUNET_YES != GNUNET_DISK_file_test (masterkeyfile))
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Exchange master private key `%s' does not exist yet, creating it!\n",
|
|
|
|
masterkeyfile);
|
2016-04-02 20:58:22 +02:00
|
|
|
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);
|
2016-04-16 12:44:45 +02:00
|
|
|
global_ret = 1;
|
|
|
|
return;
|
2016-04-02 20:58:22 +02:00
|
|
|
}
|
2016-11-19 18:27:27 +01:00
|
|
|
if (NULL == method)
|
|
|
|
{
|
|
|
|
json_t *test;
|
2017-03-15 12:01:06 +01:00
|
|
|
const char *m;
|
|
|
|
|
|
|
|
test = json_object_get(account_holder,
|
|
|
|
"type");
|
|
|
|
if ( (NULL == test) ||
|
|
|
|
(NULL == (m = json_string_value (test))))
|
2016-11-19 18:27:27 +01:00
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"Required -t argument missing\n");
|
|
|
|
global_ret = 1;
|
|
|
|
return;
|
|
|
|
}
|
2017-03-15 12:01:06 +01:00
|
|
|
method = GNUNET_strdup (m);
|
2016-11-19 18:27:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-15 12:01:06 +01:00
|
|
|
json_object_set_new (account_holder,
|
2016-11-19 18:27:27 +01:00
|
|
|
"type",
|
|
|
|
json_string (method));
|
|
|
|
}
|
2016-04-02 20:58:22 +02:00
|
|
|
key.eddsa_priv = *eddsa_priv;
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
|
|
|
|
&salt,
|
|
|
|
sizeof (salt));
|
2016-04-11 13:01:20 +02:00
|
|
|
plugin = TALER_WIRE_plugin_load (cfg,
|
|
|
|
method);
|
2016-04-02 20:58:22 +02:00
|
|
|
if (NULL == plugin)
|
|
|
|
{
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Wire transfer method `%s' not supported\n",
|
|
|
|
method);
|
2017-03-15 12:01:06 +01:00
|
|
|
GNUNET_free (method);
|
2016-04-16 12:44:45 +02:00
|
|
|
global_ret = 1;
|
|
|
|
return;
|
2016-04-02 20:58:22 +02:00
|
|
|
}
|
2017-03-15 12:01:06 +01:00
|
|
|
GNUNET_free (method);
|
2016-04-02 20:58:22 +02:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
plugin->sign_wire_details (plugin->cls,
|
2017-03-15 12:01:06 +01:00
|
|
|
account_holder,
|
2016-04-02 20:58:22 +02:00
|
|
|
&key,
|
|
|
|
&salt,
|
|
|
|
&sig))
|
|
|
|
{
|
|
|
|
/* sign function should have logged applicable errors */
|
2017-03-15 12:01:06 +01:00
|
|
|
json_decref (account_holder);
|
2016-04-11 13:01:20 +02:00
|
|
|
TALER_WIRE_plugin_unload (plugin);
|
2016-04-16 12:44:45 +02:00
|
|
|
global_ret = 1;
|
|
|
|
return;
|
2016-04-02 20:58:22 +02:00
|
|
|
}
|
2016-04-11 13:01:20 +02:00
|
|
|
TALER_WIRE_plugin_unload (plugin);
|
2016-04-02 20:58:22 +02:00
|
|
|
GNUNET_free (eddsa_priv);
|
|
|
|
|
|
|
|
/* add signature and salt to JSON message */
|
2017-03-15 12:01:06 +01:00
|
|
|
json_object_set_new (account_holder,
|
2016-04-02 20:58:22 +02:00
|
|
|
"salt",
|
|
|
|
GNUNET_JSON_from_data (&salt,
|
|
|
|
sizeof (salt)));
|
2017-03-15 12:01:06 +01:00
|
|
|
json_object_set_new (account_holder,
|
2016-04-02 20:58:22 +02:00
|
|
|
"sig",
|
|
|
|
GNUNET_JSON_from_data (&sig,
|
|
|
|
sizeof (sig)));
|
|
|
|
|
|
|
|
/* dump result to stdout */
|
2017-03-15 12:01:06 +01:00
|
|
|
json_out = json_dumps (account_holder,
|
|
|
|
JSON_INDENT(2));
|
|
|
|
json_decref (account_holder);
|
2016-04-02 20:58:22 +02:00
|
|
|
GNUNET_assert (NULL != json_out);
|
|
|
|
|
|
|
|
if (NULL != output_filename)
|
|
|
|
{
|
2016-05-05 17:40:38 +02:00
|
|
|
if (NULL != stdout)
|
|
|
|
fclose (stdout);
|
2016-04-02 20:58:22 +02:00
|
|
|
stdout = fopen (output_filename,
|
|
|
|
"w+");
|
2016-05-05 17:40:38 +02:00
|
|
|
if (NULL == stdout)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"Failed to open `%s': %s\n",
|
|
|
|
output_filename,
|
|
|
|
STRERROR (errno));
|
|
|
|
return;
|
|
|
|
}
|
2016-04-02 20:58:22 +02:00
|
|
|
}
|
|
|
|
fprintf (stdout,
|
|
|
|
"%s",
|
|
|
|
json_out);
|
|
|
|
fflush (stdout);
|
|
|
|
free (json_out);
|
|
|
|
}
|
|
|
|
|
2016-04-16 12:44:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The main function of the taler-exchange-wire tool. This tool is
|
|
|
|
* used to sign the 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)
|
|
|
|
{
|
|
|
|
const struct GNUNET_GETOPT_CommandLineOption options[] = {
|
2017-03-25 21:22:22 +01:00
|
|
|
GNUNET_GETOPT_option_mandatory
|
2017-03-15 12:01:06 +01:00
|
|
|
(GNUNET_JSON_getopt ('j',
|
|
|
|
"json",
|
|
|
|
"JSON",
|
|
|
|
"account information in JSON format",
|
|
|
|
&account_holder)),
|
2017-03-25 21:22:22 +01:00
|
|
|
GNUNET_GETOPT_option_filename ('m',
|
2017-03-15 12:01:06 +01:00
|
|
|
"master-key",
|
|
|
|
"FILENAME",
|
|
|
|
"master key file (private key)",
|
|
|
|
&masterkeyfile),
|
2017-03-25 21:22:22 +01:00
|
|
|
GNUNET_GETOPT_option_string ('t',
|
2017-03-15 12:01:06 +01:00
|
|
|
"type",
|
|
|
|
"METHOD",
|
|
|
|
"which wire transfer method (i.e. 'test' or 'sepa') is this for?",
|
|
|
|
&method),
|
2017-03-25 21:22:22 +01:00
|
|
|
GNUNET_GETOPT_option_filename ('o',
|
2017-03-15 12:01:06 +01:00
|
|
|
"output",
|
|
|
|
"FILENAME",
|
|
|
|
"where to write the result",
|
|
|
|
&output_filename),
|
2016-04-16 12:44:45 +02:00
|
|
|
GNUNET_GETOPT_OPTION_END
|
|
|
|
};
|
|
|
|
|
2016-04-16 13:10:29 +02:00
|
|
|
/* force linker to link against libtalerutil; if we do
|
|
|
|
not do this, the linker may "optimize" libtalerutil
|
|
|
|
away and skip #TALER_OS_init(), which we do need */
|
|
|
|
(void) TALER_project_data_default ();
|
2016-04-16 12:44:45 +02:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
GNUNET_log_setup ("taler-exchange-wire",
|
|
|
|
"WARNING",
|
|
|
|
NULL));
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
GNUNET_PROGRAM_run (argc, argv,
|
|
|
|
"taler-exchange-wire",
|
|
|
|
"Setup /wire response",
|
|
|
|
options,
|
|
|
|
&run, NULL))
|
|
|
|
return 1;
|
|
|
|
return global_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-02 20:58:22 +02:00
|
|
|
/* end of taler-exchange-wire.c */
|