-code cleanup
This commit is contained in:
parent
2c8bd158d9
commit
303f105985
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of TALER
|
This file is part of TALER
|
||||||
Copyright (C) 2020 Taler Systems SA
|
Copyright (C) 2020, 2021 Taler Systems SA
|
||||||
|
|
||||||
TALER is free software; you can redistribute it and/or modify it under the
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
terms of the GNU Affero General Public License as published by the Free Software
|
terms of the GNU Affero General Public License as published by the Free Software
|
||||||
@ -121,6 +121,7 @@ add_keys (void *cls,
|
|||||||
/* activate all denomination keys */
|
/* activate all denomination keys */
|
||||||
for (unsigned int i = 0; i<akc->nd_sigs; i++)
|
for (unsigned int i = 0; i<akc->nd_sigs; i++)
|
||||||
{
|
{
|
||||||
|
struct DenomSig *d = &akc->d_sigs[i];
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
bool is_active = false;
|
bool is_active = false;
|
||||||
struct TALER_EXCHANGEDB_DenominationKeyMetaData meta;
|
struct TALER_EXCHANGEDB_DenominationKeyMetaData meta;
|
||||||
@ -129,7 +130,7 @@ add_keys (void *cls,
|
|||||||
/* For idempotency, check if the key is already active */
|
/* For idempotency, check if the key is already active */
|
||||||
qs = TEH_plugin->lookup_denomination_key (
|
qs = TEH_plugin->lookup_denomination_key (
|
||||||
TEH_plugin->cls,
|
TEH_plugin->cls,
|
||||||
&akc->d_sigs[i].h_denom_pub,
|
&d->h_denom_pub,
|
||||||
&meta);
|
&meta);
|
||||||
if (qs < 0)
|
if (qs < 0)
|
||||||
{
|
{
|
||||||
@ -146,7 +147,7 @@ add_keys (void *cls,
|
|||||||
{
|
{
|
||||||
enum GNUNET_GenericReturnValue rv;
|
enum GNUNET_GenericReturnValue rv;
|
||||||
|
|
||||||
rv = TEH_keys_load_fees (&akc->d_sigs[i].h_denom_pub,
|
rv = TEH_keys_load_fees (&d->h_denom_pub,
|
||||||
&denom_pub,
|
&denom_pub,
|
||||||
&meta);
|
&meta);
|
||||||
switch (rv)
|
switch (rv)
|
||||||
@ -156,14 +157,14 @@ add_keys (void *cls,
|
|||||||
connection,
|
connection,
|
||||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||||
TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
|
TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
|
||||||
GNUNET_h2s (&akc->d_sigs[i].h_denom_pub.hash));
|
GNUNET_h2s (&d->h_denom_pub.hash));
|
||||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
case GNUNET_NO:
|
case GNUNET_NO:
|
||||||
*mhd_ret = TALER_MHD_reply_with_error (
|
*mhd_ret = TALER_MHD_reply_with_error (
|
||||||
connection,
|
connection,
|
||||||
MHD_HTTP_NOT_FOUND,
|
MHD_HTTP_NOT_FOUND,
|
||||||
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
|
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
|
||||||
GNUNET_h2s (&akc->d_sigs[i].h_denom_pub.hash));
|
GNUNET_h2s (&d->h_denom_pub.hash));
|
||||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
case GNUNET_OK:
|
case GNUNET_OK:
|
||||||
break;
|
break;
|
||||||
@ -175,10 +176,9 @@ add_keys (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check signature is valid */
|
/* check signature is valid */
|
||||||
{
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_exchange_offline_denom_validity_verify (
|
TALER_exchange_offline_denom_validity_verify (
|
||||||
&akc->d_sigs[i].h_denom_pub,
|
&d->h_denom_pub,
|
||||||
meta.start,
|
meta.start,
|
||||||
meta.expire_withdraw,
|
meta.expire_withdraw,
|
||||||
meta.expire_deposit,
|
meta.expire_deposit,
|
||||||
@ -189,25 +189,29 @@ add_keys (void *cls,
|
|||||||
&meta.fee_refresh,
|
&meta.fee_refresh,
|
||||||
&meta.fee_refund,
|
&meta.fee_refund,
|
||||||
&TEH_master_public_key,
|
&TEH_master_public_key,
|
||||||
&akc->d_sigs[i].master_sig))
|
&d->master_sig))
|
||||||
{
|
{
|
||||||
GNUNET_break_op (0);
|
GNUNET_break_op (0);
|
||||||
*mhd_ret = TALER_MHD_reply_with_error (
|
*mhd_ret = TALER_MHD_reply_with_error (
|
||||||
connection,
|
connection,
|
||||||
MHD_HTTP_FORBIDDEN,
|
MHD_HTTP_FORBIDDEN,
|
||||||
TALER_EC_EXCHANGE_MANAGEMENT_KEYS_DENOMKEY_ADD_SIGNATURE_INVALID,
|
TALER_EC_EXCHANGE_MANAGEMENT_KEYS_DENOMKEY_ADD_SIGNATURE_INVALID,
|
||||||
GNUNET_h2s (&akc->d_sigs[i].h_denom_pub.hash));
|
GNUNET_h2s (&d->h_denom_pub.hash));
|
||||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (is_active)
|
if (is_active)
|
||||||
|
{
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"Denomination key %s already active, skipping\n",
|
||||||
|
GNUNET_h2s (&d->h_denom_pub.hash));
|
||||||
continue; /* skip, already known */
|
continue; /* skip, already known */
|
||||||
|
}
|
||||||
qs = TEH_plugin->add_denomination_key (
|
qs = TEH_plugin->add_denomination_key (
|
||||||
TEH_plugin->cls,
|
TEH_plugin->cls,
|
||||||
&akc->d_sigs[i].h_denom_pub,
|
&d->h_denom_pub,
|
||||||
&denom_pub,
|
&denom_pub,
|
||||||
&meta,
|
&meta,
|
||||||
&akc->d_sigs[i].master_sig);
|
&d->master_sig);
|
||||||
TALER_denom_pub_free (&denom_pub);
|
TALER_denom_pub_free (&denom_pub);
|
||||||
if (qs < 0)
|
if (qs < 0)
|
||||||
{
|
{
|
||||||
@ -222,20 +226,20 @@ add_keys (void *cls,
|
|||||||
}
|
}
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Added offline signature for denomination `%s'\n",
|
"Added offline signature for denomination `%s'\n",
|
||||||
GNUNET_h2s (&akc->d_sigs[i].h_denom_pub.hash));
|
GNUNET_h2s (&d->h_denom_pub.hash));
|
||||||
GNUNET_assert (0 != qs);
|
GNUNET_assert (0 != qs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i<akc->ns_sigs; i++)
|
for (unsigned int i = 0; i<akc->ns_sigs; i++)
|
||||||
{
|
{
|
||||||
|
struct SigningSig *s = &akc->s_sigs[i];
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
bool is_active = false;
|
bool is_active = false;
|
||||||
struct TALER_EXCHANGEDB_SignkeyMetaData meta;
|
struct TALER_EXCHANGEDB_SignkeyMetaData meta;
|
||||||
|
|
||||||
qs = TEH_plugin->lookup_signing_key (
|
qs = TEH_plugin->lookup_signing_key (
|
||||||
TEH_plugin->cls,
|
TEH_plugin->cls,
|
||||||
&akc->s_sigs[i].exchange_pub,
|
&s->exchange_pub,
|
||||||
&meta);
|
&meta);
|
||||||
if (qs < 0)
|
if (qs < 0)
|
||||||
{
|
{
|
||||||
@ -251,7 +255,7 @@ add_keys (void *cls,
|
|||||||
if (0 == qs)
|
if (0 == qs)
|
||||||
{
|
{
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TEH_keys_get_timing (&akc->s_sigs[i].exchange_pub,
|
TEH_keys_get_timing (&s->exchange_pub,
|
||||||
&meta))
|
&meta))
|
||||||
{
|
{
|
||||||
/* For idempotency, check if the key is already active */
|
/* For idempotency, check if the key is already active */
|
||||||
@ -259,7 +263,7 @@ add_keys (void *cls,
|
|||||||
connection,
|
connection,
|
||||||
MHD_HTTP_NOT_FOUND,
|
MHD_HTTP_NOT_FOUND,
|
||||||
TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_UNKNOWN,
|
TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_UNKNOWN,
|
||||||
TALER_B2S (&akc->s_sigs[i].exchange_pub));
|
TALER_B2S (&s->exchange_pub));
|
||||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,32 +273,35 @@ add_keys (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check signature is valid */
|
/* check signature is valid */
|
||||||
{
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_exchange_offline_signkey_validity_verify (
|
TALER_exchange_offline_signkey_validity_verify (
|
||||||
&akc->s_sigs[i].exchange_pub,
|
&s->exchange_pub,
|
||||||
meta.start,
|
meta.start,
|
||||||
meta.expire_sign,
|
meta.expire_sign,
|
||||||
meta.expire_legal,
|
meta.expire_legal,
|
||||||
&TEH_master_public_key,
|
&TEH_master_public_key,
|
||||||
&akc->s_sigs[i].master_sig))
|
&s->master_sig))
|
||||||
{
|
{
|
||||||
GNUNET_break_op (0);
|
GNUNET_break_op (0);
|
||||||
*mhd_ret = TALER_MHD_reply_with_error (
|
*mhd_ret = TALER_MHD_reply_with_error (
|
||||||
connection,
|
connection,
|
||||||
MHD_HTTP_FORBIDDEN,
|
MHD_HTTP_FORBIDDEN,
|
||||||
TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_ADD_SIGNATURE_INVALID,
|
TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_ADD_SIGNATURE_INVALID,
|
||||||
GNUNET_h2s (&akc->d_sigs[i].h_denom_pub.hash));
|
TALER_B2S (&s->exchange_pub));
|
||||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (is_active)
|
if (is_active)
|
||||||
|
{
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"Signing key %s already active, skipping\n",
|
||||||
|
TALER_B2S (&s->exchange_pub));
|
||||||
continue; /* skip, already known */
|
continue; /* skip, already known */
|
||||||
|
}
|
||||||
qs = TEH_plugin->activate_signing_key (
|
qs = TEH_plugin->activate_signing_key (
|
||||||
TEH_plugin->cls,
|
TEH_plugin->cls,
|
||||||
&akc->s_sigs[i].exchange_pub,
|
&s->exchange_pub,
|
||||||
&meta,
|
&meta,
|
||||||
&akc->s_sigs[i].master_sig);
|
&s->master_sig);
|
||||||
if (qs < 0)
|
if (qs < 0)
|
||||||
{
|
{
|
||||||
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
|
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
|
||||||
@ -308,7 +315,7 @@ add_keys (void *cls,
|
|||||||
}
|
}
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Added offline signature for signing key `%s'\n",
|
"Added offline signature for signing key `%s'\n",
|
||||||
TALER_B2S (&akc->s_sigs[i].exchange_pub));
|
TALER_B2S (&s->exchange_pub));
|
||||||
GNUNET_assert (0 != qs);
|
GNUNET_assert (0 != qs);
|
||||||
}
|
}
|
||||||
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* only 'success', so >=0, matters here */
|
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* only 'success', so >=0, matters here */
|
||||||
|
@ -183,7 +183,8 @@ run (void *cls,
|
|||||||
MHD_HTTP_OK),
|
MHD_HTTP_OK),
|
||||||
/**
|
/**
|
||||||
* Melt the rest of the coin's value (EUR:4.00 = 3x EUR:1.03 + 7x
|
* Melt the rest of the coin's value (EUR:4.00 = 3x EUR:1.03 + 7x
|
||||||
* EUR:0.13) */
|
* EUR:0.13)
|
||||||
|
*/
|
||||||
TALER_TESTING_cmd_melt_double ("refresh-melt-1",
|
TALER_TESTING_cmd_melt_double ("refresh-melt-1",
|
||||||
"refresh-withdraw-coin-1",
|
"refresh-withdraw-coin-1",
|
||||||
MHD_HTTP_OK,
|
MHD_HTTP_OK,
|
||||||
|
@ -252,6 +252,7 @@ TES_read_work (void *cls,
|
|||||||
"recv");
|
"recv");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (ECONNRESET != errno)
|
||||||
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
|
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
|
||||||
"recv");
|
"recv");
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
|
@ -281,6 +281,14 @@ handle_sign_request (struct TES_Client *client,
|
|||||||
|
|
||||||
if (0 != key->rc)
|
if (0 != key->rc)
|
||||||
break; /* do later */
|
break; /* do later */
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"Removing past key %s (expired %s ago)\n",
|
||||||
|
key->filename,
|
||||||
|
GNUNET_STRINGS_relative_time_to_string (
|
||||||
|
GNUNET_TIME_absolute_get_duration (
|
||||||
|
GNUNET_TIME_absolute_add (key->anchor,
|
||||||
|
duration)),
|
||||||
|
GNUNET_YES));
|
||||||
GNUNET_CONTAINER_DLL_remove (keys_head,
|
GNUNET_CONTAINER_DLL_remove (keys_head,
|
||||||
keys_tail,
|
keys_tail,
|
||||||
key);
|
key);
|
||||||
@ -710,6 +718,14 @@ update_keys (void *cls)
|
|||||||
key_gen++;
|
key_gen++;
|
||||||
wake = true;
|
wake = true;
|
||||||
}
|
}
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"Removing past key %s (expired %s ago)\n",
|
||||||
|
keys_head->filename,
|
||||||
|
GNUNET_STRINGS_relative_time_to_string (
|
||||||
|
GNUNET_TIME_absolute_get_duration (
|
||||||
|
GNUNET_TIME_absolute_add (keys_head->anchor,
|
||||||
|
duration)),
|
||||||
|
GNUNET_YES));
|
||||||
purge_key (keys_head);
|
purge_key (keys_head);
|
||||||
}
|
}
|
||||||
GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
|
GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
|
||||||
@ -1063,7 +1079,15 @@ run (void *cls,
|
|||||||
GNUNET_DISK_directory_scan (keydir,
|
GNUNET_DISK_directory_scan (keydir,
|
||||||
&import_key,
|
&import_key,
|
||||||
NULL);
|
NULL);
|
||||||
|
if ( (NULL != keys_head) &&
|
||||||
|
(GNUNET_TIME_absolute_is_future (keys_head->anchor)) )
|
||||||
|
{
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
|
"Existing anchor is in the future. Refusing to start\n");
|
||||||
|
global_ret = EXIT_FAILURE;
|
||||||
|
GNUNET_SCHEDULER_shutdown ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* start job to keep keys up-to-date; MUST be run before the #listen_task,
|
/* start job to keep keys up-to-date; MUST be run before the #listen_task,
|
||||||
hence with priority. */
|
hence with priority. */
|
||||||
keygen_task = GNUNET_SCHEDULER_add_with_priority (
|
keygen_task = GNUNET_SCHEDULER_add_with_priority (
|
||||||
|
Loading…
Reference in New Issue
Block a user