2016-04-02 20:58:22 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2018-04-02 14:24:45 +02:00
|
|
|
Copyright (C) 2015-2018 Taler Systems SA
|
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"
|
2018-04-02 14:24:45 +02:00
|
|
|
#include "taler_json_lib.h"
|
|
|
|
#include "taler_exchangedb_lib.h"
|
2016-04-02 20:58:22 +02:00
|
|
|
#include "taler_signatures.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filename of the master private key.
|
|
|
|
*/
|
|
|
|
static char *masterkeyfile;
|
|
|
|
|
|
|
|
/**
|
2018-04-02 14:24:45 +02:00
|
|
|
* Private key for signing.
|
2016-04-02 20:58:22 +02:00
|
|
|
*/
|
2018-04-02 14:24:45 +02:00
|
|
|
static struct TALER_MasterPrivateKeyP master_priv;
|
2016-04-02 20:58:22 +02:00
|
|
|
|
|
|
|
/**
|
2018-04-02 14:24:45 +02:00
|
|
|
* Return value from main().
|
2016-04-02 20:58:22 +02:00
|
|
|
*/
|
2018-04-02 14:24:45 +02:00
|
|
|
static int global_ret;
|
2016-04-02 20:58:22 +02:00
|
|
|
|
|
|
|
|
2016-04-10 17:10:20 +02:00
|
|
|
/**
|
2018-04-02 14:24:45 +02:00
|
|
|
* Function called with information about a wire account. Signs
|
|
|
|
* the account's wire details and writes out the JSON file to disk.
|
|
|
|
*
|
|
|
|
* @param cls closure
|
|
|
|
* @param ai account information
|
2016-04-10 17:10:20 +02:00
|
|
|
*/
|
2018-04-02 14:24:45 +02:00
|
|
|
static void
|
|
|
|
sign_account_data (void *cls,
|
|
|
|
const struct TALER_EXCHANGEDB_AccountInfo *ai)
|
|
|
|
{
|
|
|
|
json_t *wire;
|
|
|
|
char *json_out;
|
|
|
|
FILE *out;
|
|
|
|
|
|
|
|
if (GNUNET_NO == ai->credit_enabled)
|
|
|
|
return;
|
|
|
|
if (NULL == ai->wire_response_filename)
|
|
|
|
{
|
|
|
|
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
ai->section_name,
|
|
|
|
"WIRE_RESPONSE");
|
|
|
|
global_ret = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wire = TALER_JSON_wire_signature_make (ai->payto_url,
|
|
|
|
&master_priv);
|
|
|
|
json_out = json_dumps (wire,
|
|
|
|
JSON_INDENT(2));
|
|
|
|
json_decref (wire);
|
|
|
|
GNUNET_assert (NULL != json_out);
|
2018-04-02 16:35:14 +02:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
GNUNET_DISK_directory_create_for_file (ai->wire_response_filename))
|
|
|
|
{
|
|
|
|
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"mkdir",
|
|
|
|
ai->wire_response_filename);
|
|
|
|
global_ret = 1;
|
|
|
|
free (json_out);
|
|
|
|
return;
|
|
|
|
}
|
2018-04-02 14:24:45 +02:00
|
|
|
|
|
|
|
out = fopen (ai->wire_response_filename,
|
|
|
|
"w+");
|
|
|
|
if (NULL == out)
|
|
|
|
{
|
|
|
|
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"fopen",
|
|
|
|
ai->wire_response_filename);
|
|
|
|
global_ret = 1;
|
2018-04-02 16:35:14 +02:00
|
|
|
free (json_out);
|
2018-04-02 14:24:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf (out,
|
|
|
|
"%s",
|
|
|
|
json_out);
|
|
|
|
fclose (out);
|
|
|
|
free (json_out);
|
|
|
|
}
|
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;
|
|
|
|
|
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
|
|
|
}
|
2018-04-02 14:24:45 +02:00
|
|
|
if (GNUNET_YES !=
|
|
|
|
GNUNET_DISK_file_test (masterkeyfile))
|
2016-05-05 15:03:43 +02:00
|
|
|
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
|
|
|
}
|
2018-04-02 14:24:45 +02:00
|
|
|
master_priv.eddsa_priv = *eddsa_priv;
|
|
|
|
TALER_EXCHANGEDB_find_accounts (cfg,
|
|
|
|
&sign_account_data,
|
|
|
|
NULL);
|
2016-04-02 20:58:22 +02:00
|
|
|
GNUNET_free (eddsa_priv);
|
|
|
|
}
|
|
|
|
|
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_filename ('m',
|
2017-03-15 12:01:06 +01:00
|
|
|
"master-key",
|
|
|
|
"FILENAME",
|
|
|
|
"master key file (private key)",
|
|
|
|
&masterkeyfile),
|
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 */
|