2015-01-08 18:37:20 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2015-03-15 21:10:05 +01:00
|
|
|
Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
|
2015-01-08 18:37:20 +01: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
|
|
|
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file taler-mint-keycheck.c
|
2015-03-15 21:10:05 +01:00
|
|
|
* @brief Check mint keys for validity. Reads the signing and denomination
|
|
|
|
* keys from the mint directory and checks to make sure they are
|
|
|
|
* well-formed. This is purely a diagnostic tool.
|
2015-01-08 18:37:20 +01:00
|
|
|
* @author Florian Dold
|
|
|
|
* @author Benedikt Mueller
|
2015-03-15 21:10:05 +01:00
|
|
|
* @author Christian Grothoff
|
2015-01-08 18:37:20 +01:00
|
|
|
*/
|
|
|
|
#include <platform.h>
|
|
|
|
#include <gnunet/gnunet_util_lib.h>
|
2015-03-28 11:06:00 +01:00
|
|
|
#include "taler_mintdb_lib.h"
|
2015-01-08 18:37:20 +01:00
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
/**
|
|
|
|
* Mint directory with the keys.
|
|
|
|
*/
|
2015-03-27 19:58:40 +01:00
|
|
|
static char *mint_directory;
|
2015-03-15 16:52:19 +01:00
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
/**
|
|
|
|
* Our configuration.
|
|
|
|
*/
|
2015-01-08 18:37:20 +01:00
|
|
|
static struct GNUNET_CONFIGURATION_Handle *kcfg;
|
|
|
|
|
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
/**
|
|
|
|
* Function called on each signing key.
|
|
|
|
*
|
|
|
|
* @param cls closure (NULL)
|
|
|
|
* @param filename name of the file the key came from
|
|
|
|
* @param ski the sign key
|
|
|
|
* @return #GNUNET_OK to continue to iterate,
|
|
|
|
* #GNUNET_NO to stop iteration with no error,
|
|
|
|
* #GNUNET_SYSERR to abort iteration with error!
|
|
|
|
*/
|
2015-01-08 18:37:20 +01:00
|
|
|
static int
|
2015-03-15 16:52:19 +01:00
|
|
|
signkeys_iter (void *cls,
|
|
|
|
const char *filename,
|
2015-03-28 12:29:35 +01:00
|
|
|
const struct TALER_MINTDB_PrivateSigningKeyInformationP *ski)
|
2015-01-08 18:37:20 +01:00
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
|
|
|
"Iterating over key `%s' for start time %s\n",
|
|
|
|
filename,
|
|
|
|
GNUNET_STRINGS_absolute_time_to_string
|
|
|
|
(GNUNET_TIME_absolute_ntoh (ski->issue.start)));
|
2015-01-08 18:37:20 +01:00
|
|
|
|
2015-01-09 18:18:59 +01:00
|
|
|
if (ntohl (ski->issue.purpose.size) !=
|
2015-03-27 19:58:40 +01:00
|
|
|
(sizeof (struct TALER_MintSigningKeyValidityPS) -
|
2015-03-28 18:18:38 +01:00
|
|
|
offsetof (struct TALER_MintSigningKeyValidityPS,
|
|
|
|
purpose)))
|
2015-01-08 18:37:20 +01:00
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Signing key `%s' has invalid purpose size\n",
|
|
|
|
filename);
|
2015-01-08 18:37:20 +01:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2015-03-15 21:10:05 +01:00
|
|
|
if (GNUNET_OK !=
|
2015-03-28 14:22:21 +01:00
|
|
|
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY,
|
2015-03-15 21:10:05 +01:00
|
|
|
&ski->issue.purpose,
|
2015-03-22 22:14:30 +01:00
|
|
|
&ski->issue.signature.eddsa_signature,
|
2015-03-27 19:58:40 +01:00
|
|
|
&ski->issue.master_public_key.eddsa_pub))
|
2015-01-08 18:37:20 +01:00
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Signing key `%s' has invalid signature\n",
|
|
|
|
filename);
|
2015-01-08 18:37:20 +01:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2015-03-15 21:10:05 +01:00
|
|
|
printf ("Signing key `%s' valid\n",
|
|
|
|
filename);
|
2015-01-08 18:37:20 +01:00
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
/**
|
|
|
|
* Check signing keys.
|
|
|
|
*
|
|
|
|
* @return #GNUNET_OK if the keys are OK
|
|
|
|
* #GNUNET_NO if not
|
|
|
|
*/
|
2015-01-08 18:37:20 +01:00
|
|
|
static int
|
|
|
|
mint_signkeys_check ()
|
|
|
|
{
|
2015-03-28 12:29:35 +01:00
|
|
|
if (0 > TALER_MINTDB_signing_keys_iterate (mint_directory,
|
2015-03-15 21:10:05 +01:00
|
|
|
&signkeys_iter,
|
|
|
|
NULL))
|
2015-01-08 18:37:20 +01:00
|
|
|
return GNUNET_NO;
|
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
/**
|
|
|
|
* Function called on each denomination key.
|
|
|
|
*
|
|
|
|
* @param cls closure (NULL)
|
|
|
|
* @param dki the denomination key
|
|
|
|
* @param alias coin alias
|
|
|
|
* @return #GNUNET_OK to continue to iterate,
|
|
|
|
* #GNUNET_NO to stop iteration with no error,
|
|
|
|
* #GNUNET_SYSERR to abort iteration with error!
|
|
|
|
*/
|
2015-01-09 18:18:59 +01:00
|
|
|
static int
|
|
|
|
denomkeys_iter (void *cls,
|
|
|
|
const char *alias,
|
2015-03-28 12:29:35 +01:00
|
|
|
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki)
|
2015-01-08 18:37:20 +01:00
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
struct GNUNET_HashCode hc;
|
2015-01-08 18:37:20 +01:00
|
|
|
|
2015-01-09 18:18:59 +01:00
|
|
|
if (ntohl (dki->issue.purpose.size) !=
|
2015-06-19 11:16:55 +02:00
|
|
|
sizeof (struct TALER_DenominationKeyValidityPS) -
|
|
|
|
offsetof (struct TALER_DenominationKeyValidityPS,
|
|
|
|
purpose))
|
2015-01-08 18:37:20 +01:00
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Denomination key for `%s' has invalid purpose size\n",
|
|
|
|
alias);
|
2015-01-08 18:37:20 +01:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:18:59 +01:00
|
|
|
if (GNUNET_OK !=
|
2015-03-28 14:22:21 +01:00
|
|
|
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY,
|
2015-01-09 18:18:59 +01:00
|
|
|
&dki->issue.purpose,
|
2015-03-22 22:14:30 +01:00
|
|
|
&dki->issue.signature.eddsa_signature,
|
|
|
|
&dki->issue.master.eddsa_pub))
|
2015-01-08 18:37:20 +01:00
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Denomination key for `%s' has invalid signature\n",
|
|
|
|
alias);
|
2015-01-08 18:37:20 +01:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2015-03-22 22:14:30 +01:00
|
|
|
GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_key,
|
2015-03-15 21:10:05 +01:00
|
|
|
&hc);
|
|
|
|
if (0 != memcmp (&hc,
|
|
|
|
&dki->issue.denom_hash,
|
|
|
|
sizeof (struct GNUNET_HashCode)))
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"Public key for `%s' does not match signature\n",
|
|
|
|
alias);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
printf ("Denomination key `%s' is valid\n",
|
|
|
|
alias);
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
/**
|
|
|
|
* Check denomination keys.
|
|
|
|
*
|
|
|
|
* @return #GNUNET_OK if the keys are OK
|
|
|
|
* #GNUNET_NO if not
|
|
|
|
*/
|
2015-01-08 18:37:20 +01:00
|
|
|
static int
|
|
|
|
mint_denomkeys_check ()
|
|
|
|
{
|
2015-03-28 12:29:35 +01:00
|
|
|
if (0 > TALER_MINTDB_denomination_keys_iterate (mint_directory,
|
2015-06-19 11:24:34 +02:00
|
|
|
&denomkeys_iter,
|
|
|
|
NULL))
|
2015-01-08 18:37:20 +01:00
|
|
|
return GNUNET_NO;
|
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main function of the keyup tool
|
|
|
|
*
|
|
|
|
* @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[] = {
|
2015-03-15 21:10:05 +01:00
|
|
|
GNUNET_GETOPT_OPTION_HELP ("gnunet-mint-keycheck OPTIONS"),
|
|
|
|
{'d', "directory", "DIRECTORY",
|
|
|
|
"mint directory with keys to check", 1,
|
2015-03-27 19:58:40 +01:00
|
|
|
&GNUNET_GETOPT_set_filename, &mint_directory},
|
2015-01-08 18:37:20 +01:00
|
|
|
GNUNET_GETOPT_OPTION_END
|
|
|
|
};
|
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
GNUNET_log_setup ("taler-mint-keycheck",
|
|
|
|
"WARNING",
|
|
|
|
NULL));
|
2015-01-08 18:37:20 +01:00
|
|
|
|
2015-03-15 21:10:05 +01:00
|
|
|
if (GNUNET_GETOPT_run ("taler-mint-keycheck",
|
|
|
|
options,
|
|
|
|
argc, argv) < 0)
|
2015-01-08 18:37:20 +01:00
|
|
|
return 1;
|
2015-03-27 19:58:40 +01:00
|
|
|
if (NULL == mint_directory)
|
2015-01-08 18:37:20 +01:00
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Mint directory not given\n");
|
2015-01-08 18:37:20 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-03-27 19:58:40 +01:00
|
|
|
kcfg = TALER_config_load (mint_directory);
|
2015-01-08 18:37:20 +01:00
|
|
|
if (NULL == kcfg)
|
|
|
|
{
|
2015-03-15 21:10:05 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Failed to load mint configuration\n");
|
2015-01-08 18:37:20 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2015-03-15 21:10:05 +01:00
|
|
|
if ( (GNUNET_OK != mint_signkeys_check ()) ||
|
|
|
|
(GNUNET_OK != mint_denomkeys_check ()) )
|
|
|
|
{
|
|
|
|
GNUNET_CONFIGURATION_destroy (kcfg);
|
2015-01-08 18:37:20 +01:00
|
|
|
return 1;
|
2015-03-15 21:10:05 +01:00
|
|
|
}
|
|
|
|
GNUNET_CONFIGURATION_destroy (kcfg);
|
2015-01-08 18:37:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-03-15 21:10:05 +01:00
|
|
|
|
|
|
|
/* end of taler-mint-keycheck.c */
|