another fix related to #7099

This commit is contained in:
Christian Grothoff 2021-11-21 12:47:16 +01:00
parent 56318f53e2
commit 5159badd0e
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 61 additions and 23 deletions

View File

@ -229,18 +229,19 @@ TES_read_work (void *cls,
{ {
struct TES_Client *client = cls; struct TES_Client *client = cls;
char *buf = client->iobuf; char *buf = client->iobuf;
ssize_t buf_size;
size_t off = 0; size_t off = 0;
uint16_t msize; uint16_t msize;
const struct GNUNET_MessageHeader *hdr; const struct GNUNET_MessageHeader *hdr;
do do
{ {
buf_size = recv (client->csock, ssize_t recv_size;
&buf[off],
sizeof (client->iobuf) - off, recv_size = recv (client->csock,
0); &buf[off],
if (-1 == buf_size) sizeof (client->iobuf) - off,
0);
if (-1 == recv_size)
{ {
if ( (0 == off) && if ( (0 == off) &&
(EAGAIN == errno) ) (EAGAIN == errno) )
@ -257,17 +258,23 @@ TES_read_work (void *cls,
"recv"); "recv");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (0 == buf_size) if (0 == recv_size)
{ {
/* regular disconnect? */ /* regular disconnect? */
GNUNET_break_op (0 == off); GNUNET_break_op (0 == off);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
off += buf_size; off += recv_size;
if (off < sizeof (struct GNUNET_MessageHeader)) if (off < sizeof (struct GNUNET_MessageHeader))
continue; continue;
hdr = (const struct GNUNET_MessageHeader *) buf; hdr = (const struct GNUNET_MessageHeader *) buf;
msize = ntohs (hdr->size); msize = ntohs (hdr->size);
#if 0
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received message of type %u with %u bytes\n",
(unsigned int) ntohs (hdr->type),
(unsigned int) msize);
#endif
if (msize < sizeof (struct GNUNET_MessageHeader)) if (msize < sizeof (struct GNUNET_MessageHeader))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);

View File

@ -282,8 +282,8 @@ 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, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Removing past key %s (expired %s ago)\n", "Deleting past key %s (expired %s ago)\n",
key->filename, TALER_B2S (&nxt->exchange_pub),
GNUNET_STRINGS_relative_time_to_string ( GNUNET_STRINGS_relative_time_to_string (
GNUNET_TIME_absolute_get_duration ( GNUNET_TIME_absolute_get_duration (
GNUNET_TIME_absolute_add (key->anchor, GNUNET_TIME_absolute_add (key->anchor,
@ -400,7 +400,15 @@ static void
purge_key (struct Key *key) purge_key (struct Key *key)
{ {
if (key->purge) if (key->purge)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Key %s already purged, skipping\n",
TALER_B2S (&key->exchange_pub));
return; return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Purging key %s\n",
TALER_B2S (&key->exchange_pub));
if (0 != unlink (key->filename)) if (0 != unlink (key->filename))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
"unlink", "unlink",
@ -449,8 +457,8 @@ handle_revoke_request (struct TES_Client *client,
key_gen++; key_gen++;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Revoking key %p, bumping generation to %llu\n", "Revoking key %s, bumping generation to %llu\n",
key, TALER_B2S (&key->exchange_pub),
(unsigned long long) key_gen); (unsigned long long) key_gen);
purge_key (key); purge_key (key);
@ -570,13 +578,23 @@ eddsa_client_init (struct TES_Client *client)
static enum GNUNET_GenericReturnValue static enum GNUNET_GenericReturnValue
eddsa_update_client_keys (struct TES_Client *client) eddsa_update_client_keys (struct TES_Client *client)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Updating client %p to generation %llu\n",
client,
(unsigned long long) key_gen);
GNUNET_assert (0 == pthread_mutex_lock (&keys_lock)); GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
for (struct Key *key = keys_head; for (struct Key *key = keys_head;
NULL != key; NULL != key;
key = key->next) key = key->next)
{ {
if (key->key_gen <= client->key_gen) if (key->key_gen <= client->key_gen)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Skipping key %s, no change since generation %llu\n",
TALER_B2S (&key->exchange_pub),
(unsigned long long) client->key_gen);
continue; continue;
}
if (key->purge) if (key->purge)
{ {
if (GNUNET_OK != if (GNUNET_OK !=
@ -715,7 +733,7 @@ update_keys (void *cls)
} }
} }
nxt = keys_head; nxt = keys_head;
/* remove expired keys */ /* purge expired keys */
while ( (NULL != nxt) && while ( (NULL != nxt) &&
GNUNET_TIME_absolute_is_past ( GNUNET_TIME_absolute_is_past (
GNUNET_TIME_absolute_add (nxt->anchor, GNUNET_TIME_absolute_add (nxt->anchor,
@ -727,8 +745,8 @@ update_keys (void *cls)
wake = true; wake = true;
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Removing past key %s (expired %s ago)\n", "Purging past key %s (expired %s ago)\n",
nxt->filename, TALER_B2S (&nxt->exchange_pub),
GNUNET_STRINGS_relative_time_to_string ( GNUNET_STRINGS_relative_time_to_string (
GNUNET_TIME_absolute_get_duration ( GNUNET_TIME_absolute_get_duration (
GNUNET_TIME_absolute_add (nxt->anchor, GNUNET_TIME_absolute_add (nxt->anchor,
@ -1075,13 +1093,13 @@ run (void *cls,
global_ret = EXIT_NOTCONFIGURED; global_ret = EXIT_NOTCONFIGURED;
return; return;
} }
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
global_ret = TES_listen_start (cfg, global_ret = TES_listen_start (cfg,
"taler-exchange-secmod-eddsa", "taler-exchange-secmod-eddsa",
&cb); &cb);
if (0 != global_ret) if (0 != global_ret)
return; return;
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
/* Load keys */ /* Load keys */
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
GNUNET_DISK_directory_create (keydir)); GNUNET_DISK_directory_create (keydir));

View File

@ -27,7 +27,7 @@
* we should never have more than 6 active keys, plus for during * we should never have more than 6 active keys, plus for during
* key expiration / revocation. * key expiration / revocation.
*/ */
#define MAX_KEYS 7 #define MAX_KEYS 20
/** /**
* How many random key revocations should we test? * How many random key revocations should we test?
@ -121,7 +121,14 @@ key_cb (void *cls,
(void) cls; (void) cls;
(void) sm_pub; (void) sm_pub;
(void) sm_sig; (void) sm_sig;
if (0 == validity_duration.rel_value_us)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Update on key %s (%s)...",
TALER_B2S (exchange_pub),
GNUNET_STRINGS_relative_time_to_string (validity_duration,
GNUNET_YES));
if (GNUNET_TIME_relative_is_zero (validity_duration))
{ {
bool found = false; bool found = false;
@ -190,14 +197,20 @@ test_revocation (struct TALER_CRYPTO_ExchangeSignHelper *esh)
} }
keys[j].revoked = true; keys[j].revoked = true;
fprintf (stderr, fprintf (stderr,
"Revoking key ..."); "Revoking key %s ...",
TALER_B2S (&keys[j].exchange_pub));
TALER_CRYPTO_helper_esign_revoke (esh, TALER_CRYPTO_helper_esign_revoke (esh,
&keys[j].exchange_pub); &keys[j].exchange_pub);
for (unsigned int k = 0; k<1000; k++) for (unsigned int k = 0; k<1000; k++)
{ {
TALER_CRYPTO_helper_esign_poll (esh); TALER_CRYPTO_helper_esign_poll (esh);
if (! keys[j].revoked) if ( (! keys[j].revoked) ||
(GNUNET_TIME_absolute_is_past (
GNUNET_TIME_absolute_add (keys[j].start_time,
keys[j].validity_duration))) )
{
break; break;
}
nanosleep (&req, NULL); nanosleep (&req, NULL);
fprintf (stderr, "."); fprintf (stderr, ".");
} }
@ -470,7 +483,7 @@ main (int argc,
(void) argc; (void) argc;
(void) argv; (void) argv;
GNUNET_log_setup ("test-helper-eddsa", GNUNET_log_setup ("test-helper-eddsa",
"WARNING", "INFO",
NULL); NULL);
GNUNET_OS_init (TALER_project_data_default ()); GNUNET_OS_init (TALER_project_data_default ());
libexec_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); libexec_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
@ -486,7 +499,7 @@ main (int argc,
"-c", "-c",
"test_helper_eddsa.conf", "test_helper_eddsa.conf",
"-L", "-L",
"WARNING", "INFO",
NULL); NULL);
if (NULL == helper) if (NULL == helper)
{ {