2020-11-22 18:31:33 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2021-10-23 06:20:28 +02:00
|
|
|
(C) 2020, 2021 Taler Systems SA
|
2020-11-22 18:31:33 +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, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file util/test_helper_rsa.c
|
|
|
|
* @brief Tests for RSA crypto helper
|
|
|
|
* @author Christian Grothoff
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_util.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration has 1 minute duration and 5 minutes lookahead, so
|
|
|
|
* we should never have more than 6 active keys, plus for during
|
|
|
|
* key expiration / revocation.
|
|
|
|
*/
|
|
|
|
#define MAX_KEYS 7
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How many random key revocations should we test?
|
|
|
|
*/
|
2020-11-23 21:10:55 +01:00
|
|
|
#define NUM_REVOKES 3
|
2020-11-22 18:31:33 +01:00
|
|
|
|
2020-11-22 22:25:49 +01:00
|
|
|
/**
|
|
|
|
* How many iterations of the successful signing test should we run?
|
|
|
|
*/
|
2020-11-23 21:10:55 +01:00
|
|
|
#define NUM_SIGN_TESTS 5
|
2020-11-22 22:25:49 +01:00
|
|
|
|
2020-11-22 18:31:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of keys currently in #keys.
|
|
|
|
*/
|
|
|
|
static unsigned int num_keys;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keys currently managed by the helper.
|
|
|
|
*/
|
|
|
|
struct KeyData
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Validity start point.
|
|
|
|
*/
|
|
|
|
struct GNUNET_TIME_Absolute start_time;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Key expires for signing at @e start_time plus this value.
|
|
|
|
*/
|
|
|
|
struct GNUNET_TIME_Relative validity_duration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash of the public key.
|
|
|
|
*/
|
2021-10-23 06:20:28 +02:00
|
|
|
struct TALER_DenominationHash h_denom_pub;
|
2020-11-22 18:31:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Full public key.
|
|
|
|
*/
|
|
|
|
struct TALER_DenominationPublicKey denom_pub;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this key currently valid?
|
|
|
|
*/
|
|
|
|
bool valid;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Did the test driver revoke this key?
|
|
|
|
*/
|
|
|
|
bool revoked;
|
|
|
|
};
|
|
|
|
|
2020-11-22 19:02:49 +01:00
|
|
|
/**
|
|
|
|
* Array of all the keys we got from the helper.
|
|
|
|
*/
|
2020-11-22 18:31:33 +01:00
|
|
|
static struct KeyData keys[MAX_KEYS];
|
|
|
|
|
|
|
|
|
2020-11-22 19:02:49 +01:00
|
|
|
/**
|
|
|
|
* Function called with information about available keys for signing. Usually
|
|
|
|
* only called once per key upon connect. Also called again in case a key is
|
|
|
|
* being revoked, in that case with an @a end_time of zero. Stores the keys
|
|
|
|
* status in #keys.
|
|
|
|
*
|
|
|
|
* @param cls closure, NULL
|
|
|
|
* @param section_name name of the denomination type in the configuration;
|
|
|
|
* NULL if the key has been revoked or purged
|
|
|
|
* @param start_time when does the key become available for signing;
|
|
|
|
* zero if the key has been revoked or purged
|
|
|
|
* @param validity_duration how long does the key remain available for signing;
|
|
|
|
* zero if the key has been revoked or purged
|
|
|
|
* @param h_denom_pub hash of the @a denom_pub that is available (or was purged)
|
|
|
|
* @param denom_pub the public key itself, NULL if the key was revoked or purged
|
2020-11-23 21:10:55 +01:00
|
|
|
* @param sm_pub public key of the security module, NULL if the key was revoked or purged
|
|
|
|
* @param sm_sig signature from the security module, NULL if the key was revoked or purged
|
|
|
|
* The signature was already verified against @a sm_pub.
|
2020-11-22 19:02:49 +01:00
|
|
|
*/
|
2020-11-22 18:31:33 +01:00
|
|
|
static void
|
|
|
|
key_cb (void *cls,
|
|
|
|
const char *section_name,
|
|
|
|
struct GNUNET_TIME_Absolute start_time,
|
|
|
|
struct GNUNET_TIME_Relative validity_duration,
|
2021-10-23 06:20:28 +02:00
|
|
|
const struct TALER_DenominationHash *h_denom_pub,
|
2020-11-23 21:10:55 +01:00
|
|
|
const struct TALER_DenominationPublicKey *denom_pub,
|
|
|
|
const struct TALER_SecurityModulePublicKeyP *sm_pub,
|
|
|
|
const struct TALER_SecurityModuleSignatureP *sm_sig)
|
2020-11-22 18:31:33 +01:00
|
|
|
{
|
2020-11-23 21:10:55 +01:00
|
|
|
(void) sm_pub;
|
|
|
|
(void) sm_sig;
|
2020-11-22 18:31:33 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Key notification about key %s in `%s'\n",
|
2021-10-23 06:20:28 +02:00
|
|
|
GNUNET_h2s (&h_denom_pub->hash),
|
2020-11-22 18:31:33 +01:00
|
|
|
section_name);
|
|
|
|
if (0 == validity_duration.rel_value_us)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
GNUNET_break (NULL == denom_pub);
|
|
|
|
GNUNET_break (NULL == section_name);
|
|
|
|
for (unsigned int i = 0; i<MAX_KEYS; i++)
|
|
|
|
if (0 == GNUNET_memcmp (h_denom_pub,
|
|
|
|
&keys[i].h_denom_pub))
|
|
|
|
{
|
|
|
|
keys[i].valid = false;
|
|
|
|
keys[i].revoked = false;
|
2021-11-05 14:18:13 +01:00
|
|
|
TALER_denom_pub_free (&keys[i].denom_pub);
|
2020-11-22 18:31:33 +01:00
|
|
|
GNUNET_assert (num_keys > 0);
|
|
|
|
num_keys--;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (! found)
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"Error: helper announced expiration of unknown key!\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2021-08-05 11:07:20 +02:00
|
|
|
|
2020-11-22 18:31:33 +01:00
|
|
|
GNUNET_break (NULL != denom_pub);
|
|
|
|
for (unsigned int i = 0; i<MAX_KEYS; i++)
|
|
|
|
if (! keys[i].valid)
|
|
|
|
{
|
|
|
|
keys[i].valid = true;
|
|
|
|
keys[i].h_denom_pub = *h_denom_pub;
|
|
|
|
keys[i].start_time = start_time;
|
|
|
|
keys[i].validity_duration = validity_duration;
|
2021-10-23 06:20:28 +02:00
|
|
|
keys[i].denom_pub = *denom_pub;
|
2021-11-05 14:18:13 +01:00
|
|
|
TALER_denom_pub_deep_copy (&keys[i].denom_pub,
|
|
|
|
denom_pub);
|
2020-11-22 18:31:33 +01:00
|
|
|
num_keys++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* too many keys! */
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"Error: received %d live keys from the service!\n",
|
|
|
|
MAX_KEYS + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-22 19:02:49 +01:00
|
|
|
* Test key revocation logic.
|
|
|
|
*
|
|
|
|
* @param dh handle to the helper
|
|
|
|
* @return 0 on success
|
2020-11-22 18:31:33 +01:00
|
|
|
*/
|
|
|
|
static int
|
2020-11-22 19:02:49 +01:00
|
|
|
test_revocation (struct TALER_CRYPTO_DenominationHelper *dh)
|
2020-11-22 18:31:33 +01:00
|
|
|
{
|
|
|
|
struct timespec req = {
|
|
|
|
.tv_nsec = 250000000
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i<NUM_REVOKES; i++)
|
|
|
|
{
|
|
|
|
uint32_t off;
|
|
|
|
|
|
|
|
off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
|
|
num_keys);
|
|
|
|
/* find index of key to revoke */
|
|
|
|
for (unsigned int j = 0; j < MAX_KEYS; j++)
|
|
|
|
{
|
|
|
|
if (! keys[j].valid)
|
|
|
|
continue;
|
|
|
|
if (0 != off)
|
|
|
|
{
|
|
|
|
off--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
keys[j].revoked = true;
|
|
|
|
fprintf (stderr,
|
|
|
|
"Revoking key %s ...",
|
2021-10-23 06:20:28 +02:00
|
|
|
GNUNET_h2s (&keys[j].h_denom_pub.hash));
|
2020-11-22 18:31:33 +01:00
|
|
|
TALER_CRYPTO_helper_denom_revoke (dh,
|
|
|
|
&keys[j].h_denom_pub);
|
2020-11-22 22:25:49 +01:00
|
|
|
for (unsigned int k = 0; k<1000; k++)
|
2020-11-22 18:31:33 +01:00
|
|
|
{
|
2020-11-23 20:30:10 +01:00
|
|
|
TALER_CRYPTO_helper_denom_poll (dh);
|
2020-11-22 18:31:33 +01:00
|
|
|
if (! keys[j].revoked)
|
|
|
|
break;
|
|
|
|
nanosleep (&req, NULL);
|
|
|
|
fprintf (stderr, ".");
|
|
|
|
}
|
|
|
|
if (keys[j].revoked)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"\nFAILED: timeout trying to revoke key %u\n",
|
|
|
|
j);
|
|
|
|
TALER_CRYPTO_helper_denom_disconnect (dh);
|
|
|
|
return 2;
|
|
|
|
}
|
2020-11-22 22:25:49 +01:00
|
|
|
fprintf (stderr, "\n");
|
2020-11-22 18:31:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 19:02:49 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-11-22 18:31:33 +01:00
|
|
|
|
|
|
|
|
2020-11-22 19:02:49 +01:00
|
|
|
/**
|
|
|
|
* Test signing logic.
|
|
|
|
*
|
|
|
|
* @param dh handle to the helper
|
|
|
|
* @return 0 on success
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
|
|
|
|
{
|
2021-10-31 18:01:19 +01:00
|
|
|
struct TALER_BlindedDenominationSignature ds;
|
2020-11-22 19:02:49 +01:00
|
|
|
enum TALER_ErrorCode ec;
|
|
|
|
bool success = false;
|
2021-10-23 06:20:28 +02:00
|
|
|
struct TALER_CoinPubHash m_hash;
|
2021-11-05 14:18:13 +01:00
|
|
|
struct TALER_BlindingSecret bks;
|
2020-11-22 19:02:49 +01:00
|
|
|
|
2021-11-05 14:18:13 +01:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_blinding_secret_create (&bks,
|
|
|
|
TALER_DENOMINATION_RSA));
|
2020-11-22 19:02:49 +01:00
|
|
|
GNUNET_CRYPTO_hash ("Hello",
|
|
|
|
strlen ("Hello"),
|
2021-10-23 06:20:28 +02:00
|
|
|
&m_hash.hash);
|
2020-11-22 19:02:49 +01:00
|
|
|
for (unsigned int i = 0; i<MAX_KEYS; i++)
|
|
|
|
{
|
|
|
|
if (! keys[i].valid)
|
|
|
|
continue;
|
2020-11-22 22:25:49 +01:00
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
size_t buf_size;
|
2021-08-05 11:07:20 +02:00
|
|
|
|
2020-11-22 22:25:49 +01:00
|
|
|
GNUNET_assert (GNUNET_YES ==
|
2020-12-04 12:09:27 +01:00
|
|
|
TALER_rsa_blind (&m_hash,
|
2021-11-05 14:18:13 +01:00
|
|
|
&bks.details.rsa_bks,
|
2021-10-23 06:20:28 +02:00
|
|
|
keys[i].denom_pub.details.rsa_public_key,
|
2020-12-04 12:09:27 +01:00
|
|
|
&buf,
|
|
|
|
&buf_size));
|
2020-11-22 22:25:49 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Requesting signature over %u bytes with key %s\n",
|
|
|
|
(unsigned int) buf_size,
|
2021-10-23 06:20:28 +02:00
|
|
|
GNUNET_h2s (&keys[i].h_denom_pub.hash));
|
2020-11-22 22:25:49 +01:00
|
|
|
ds = TALER_CRYPTO_helper_denom_sign (dh,
|
|
|
|
&keys[i].h_denom_pub,
|
|
|
|
buf,
|
|
|
|
buf_size,
|
|
|
|
&ec);
|
|
|
|
GNUNET_free (buf);
|
|
|
|
}
|
2020-11-22 19:02:49 +01:00
|
|
|
switch (ec)
|
|
|
|
{
|
|
|
|
case TALER_EC_NONE:
|
|
|
|
if (GNUNET_TIME_absolute_get_remaining (keys[i].start_time).rel_value_us >
|
|
|
|
GNUNET_TIME_UNIT_SECONDS.rel_value_us)
|
|
|
|
{
|
|
|
|
/* key worked too early */
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (GNUNET_TIME_absolute_get_duration (keys[i].start_time).rel_value_us >
|
|
|
|
keys[i].validity_duration.rel_value_us)
|
|
|
|
{
|
|
|
|
/* key worked too later */
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
{
|
2021-10-23 06:20:28 +02:00
|
|
|
struct TALER_DenominationSignature rs;
|
|
|
|
|
2021-11-05 14:18:13 +01:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_denom_sig_unblind (&rs,
|
|
|
|
&ds,
|
|
|
|
&bks,
|
|
|
|
&keys[i].denom_pub))
|
2020-11-22 22:25:49 +01:00
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 6;
|
|
|
|
}
|
2021-10-31 18:01:19 +01:00
|
|
|
TALER_blinded_denom_sig_free (&ds);
|
2020-11-22 22:25:49 +01:00
|
|
|
if (GNUNET_OK !=
|
2021-10-23 06:20:28 +02:00
|
|
|
TALER_denom_pub_verify (&keys[i].denom_pub,
|
|
|
|
&rs,
|
|
|
|
&m_hash))
|
2020-11-22 22:25:49 +01:00
|
|
|
{
|
|
|
|
/* signature invalid */
|
|
|
|
GNUNET_break (0);
|
2021-11-05 17:19:47 +01:00
|
|
|
TALER_denom_sig_free (&rs);
|
2020-11-22 22:25:49 +01:00
|
|
|
return 7;
|
|
|
|
}
|
2021-11-05 17:19:47 +01:00
|
|
|
TALER_denom_sig_free (&rs);
|
2020-11-22 19:02:49 +01:00
|
|
|
}
|
2020-11-22 22:25:49 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Received valid signature for key %s\n",
|
2021-10-23 06:20:28 +02:00
|
|
|
GNUNET_h2s (&keys[i].h_denom_pub.hash));
|
2020-11-22 19:02:49 +01:00
|
|
|
success = true;
|
|
|
|
break;
|
2020-11-22 22:25:49 +01:00
|
|
|
case TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY:
|
|
|
|
/* This 'failure' is expected, we're testing also for the
|
|
|
|
error handling! */
|
2020-11-22 19:02:49 +01:00
|
|
|
if ( (0 ==
|
|
|
|
GNUNET_TIME_absolute_get_remaining (
|
|
|
|
keys[i].start_time).rel_value_us) &&
|
|
|
|
(GNUNET_TIME_absolute_get_duration (
|
|
|
|
keys[i].start_time).rel_value_us <
|
|
|
|
keys[i].validity_duration.rel_value_us) )
|
|
|
|
{
|
|
|
|
/* key should have worked! */
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unexpected error */
|
2021-01-28 21:23:16 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"Unexpected error %d\n",
|
|
|
|
ec);
|
2020-11-22 19:02:49 +01:00
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! success)
|
|
|
|
{
|
|
|
|
/* no valid key for signing found, also bad */
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check signing does not work if the key is unknown */
|
|
|
|
{
|
2021-10-23 06:20:28 +02:00
|
|
|
struct TALER_DenominationHash rnd;
|
2020-11-22 19:02:49 +01:00
|
|
|
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
|
|
&rnd,
|
|
|
|
sizeof (rnd));
|
|
|
|
(void) TALER_CRYPTO_helper_denom_sign (dh,
|
|
|
|
&rnd,
|
|
|
|
"Hello",
|
|
|
|
strlen ("Hello"),
|
|
|
|
&ec);
|
|
|
|
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 17;
|
|
|
|
}
|
2020-11-22 22:25:49 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Signing with invalid key %s failed as desired\n",
|
2021-10-23 06:20:28 +02:00
|
|
|
GNUNET_h2s (&rnd.hash));
|
2020-11-22 19:02:49 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-22 22:25:49 +01:00
|
|
|
/**
|
|
|
|
* Benchmark signing logic.
|
|
|
|
*
|
|
|
|
* @param dh handle to the helper
|
|
|
|
* @return 0 on success
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
perf_signing (struct TALER_CRYPTO_DenominationHelper *dh)
|
|
|
|
{
|
2021-10-31 18:01:19 +01:00
|
|
|
struct TALER_BlindedDenominationSignature ds;
|
2020-11-22 22:25:49 +01:00
|
|
|
enum TALER_ErrorCode ec;
|
2021-10-23 06:20:28 +02:00
|
|
|
struct TALER_CoinPubHash m_hash;
|
2020-11-22 22:25:49 +01:00
|
|
|
struct GNUNET_TIME_Relative duration;
|
2021-11-05 17:19:47 +01:00
|
|
|
struct TALER_PlanchetSecretsP ps;
|
2020-11-22 22:25:49 +01:00
|
|
|
|
2021-11-05 17:19:47 +01:00
|
|
|
TALER_planchet_setup_random (&ps);
|
2020-11-22 22:25:49 +01:00
|
|
|
GNUNET_CRYPTO_hash ("Hello",
|
|
|
|
strlen ("Hello"),
|
2021-10-23 06:20:28 +02:00
|
|
|
&m_hash.hash);
|
2020-11-22 22:25:49 +01:00
|
|
|
duration = GNUNET_TIME_UNIT_ZERO;
|
|
|
|
for (unsigned int j = 0; j<NUM_SIGN_TESTS;)
|
|
|
|
{
|
2020-11-23 20:30:10 +01:00
|
|
|
TALER_CRYPTO_helper_denom_poll (dh);
|
2020-11-22 22:25:49 +01:00
|
|
|
for (unsigned int i = 0; i<MAX_KEYS; i++)
|
|
|
|
{
|
|
|
|
if (! keys[i].valid)
|
|
|
|
continue;
|
|
|
|
if (GNUNET_TIME_absolute_get_remaining (keys[i].start_time).rel_value_us >
|
|
|
|
GNUNET_TIME_UNIT_SECONDS.rel_value_us)
|
|
|
|
continue;
|
|
|
|
if (GNUNET_TIME_absolute_get_duration (keys[i].start_time).rel_value_us >
|
|
|
|
keys[i].validity_duration.rel_value_us)
|
|
|
|
continue;
|
|
|
|
{
|
2021-11-05 17:19:47 +01:00
|
|
|
struct TALER_CoinPubHash c_hash;
|
|
|
|
struct TALER_PlanchetDetail pd;
|
2020-11-22 22:25:49 +01:00
|
|
|
|
|
|
|
GNUNET_assert (GNUNET_YES ==
|
2021-11-05 17:19:47 +01:00
|
|
|
TALER_planchet_prepare (&keys[i].denom_pub,
|
|
|
|
&ps,
|
|
|
|
&c_hash,
|
|
|
|
&pd));
|
2020-11-22 22:25:49 +01:00
|
|
|
/* use this key as long as it works */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get ();
|
|
|
|
struct GNUNET_TIME_Relative delay;
|
|
|
|
|
|
|
|
ds = TALER_CRYPTO_helper_denom_sign (dh,
|
|
|
|
&keys[i].h_denom_pub,
|
2021-11-05 17:19:47 +01:00
|
|
|
pd.coin_ev,
|
|
|
|
pd.coin_ev_size,
|
2020-11-22 22:25:49 +01:00
|
|
|
&ec);
|
|
|
|
if (TALER_EC_NONE != ec)
|
|
|
|
break;
|
|
|
|
delay = GNUNET_TIME_absolute_get_duration (start);
|
|
|
|
duration = GNUNET_TIME_relative_add (duration,
|
|
|
|
delay);
|
2021-10-31 18:01:19 +01:00
|
|
|
TALER_blinded_denom_sig_free (&ds);
|
2020-11-22 22:25:49 +01:00
|
|
|
j++;
|
|
|
|
if (NUM_SIGN_TESTS == j)
|
|
|
|
break;
|
|
|
|
}
|
2021-11-05 17:19:47 +01:00
|
|
|
GNUNET_free (pd.coin_ev);
|
2020-11-22 22:25:49 +01:00
|
|
|
}
|
|
|
|
} /* for i */
|
|
|
|
} /* for j */
|
|
|
|
fprintf (stderr,
|
|
|
|
"%u (sequential) signature operations took %s\n",
|
|
|
|
(unsigned int) NUM_SIGN_TESTS,
|
|
|
|
GNUNET_STRINGS_relative_time_to_string (duration,
|
|
|
|
GNUNET_YES));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-22 19:02:49 +01:00
|
|
|
/**
|
|
|
|
* Main entry point into the test logic with the helper already running.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
run_test (void)
|
|
|
|
{
|
|
|
|
struct GNUNET_CONFIGURATION_Handle *cfg;
|
|
|
|
struct TALER_CRYPTO_DenominationHelper *dh;
|
|
|
|
struct timespec req = {
|
|
|
|
.tv_nsec = 250000000
|
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
cfg = GNUNET_CONFIGURATION_create ();
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
GNUNET_CONFIGURATION_load (cfg,
|
|
|
|
"test_helper_rsa.conf"))
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 77;
|
|
|
|
}
|
2021-07-30 18:37:54 +02:00
|
|
|
|
|
|
|
fprintf (stderr, "Waiting for helper client directory to become available ");
|
|
|
|
for (unsigned int i = 0; i<1000; i++)
|
|
|
|
{
|
|
|
|
dh = TALER_CRYPTO_helper_denom_connect (cfg,
|
|
|
|
&key_cb,
|
|
|
|
NULL);
|
|
|
|
if (NULL != dh)
|
|
|
|
break;
|
|
|
|
nanosleep (&req, NULL);
|
|
|
|
fprintf (stderr, ".");
|
|
|
|
}
|
2020-11-22 19:02:49 +01:00
|
|
|
GNUNET_CONFIGURATION_destroy (cfg);
|
|
|
|
if (NULL == dh)
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 1;
|
|
|
|
}
|
2021-07-30 18:37:54 +02:00
|
|
|
fprintf (stderr, " done.\n");
|
|
|
|
|
2020-11-22 19:02:49 +01:00
|
|
|
/* wait for helper to start and give us keys */
|
|
|
|
fprintf (stderr, "Waiting for helper to start ");
|
2020-11-22 22:25:49 +01:00
|
|
|
for (unsigned int i = 0; i<1000; i++)
|
2020-11-22 19:02:49 +01:00
|
|
|
{
|
2020-11-23 20:30:10 +01:00
|
|
|
TALER_CRYPTO_helper_denom_poll (dh);
|
2020-11-22 19:02:49 +01:00
|
|
|
if (0 != num_keys)
|
|
|
|
break;
|
|
|
|
nanosleep (&req, NULL);
|
|
|
|
fprintf (stderr, ".");
|
|
|
|
}
|
|
|
|
if (0 == num_keys)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"\nFAILED: timeout trying to connect to helper\n");
|
|
|
|
TALER_CRYPTO_helper_denom_disconnect (dh);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
fprintf (stderr,
|
|
|
|
"\nOK: Helper ready (%u keys)\n",
|
|
|
|
num_keys);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
if (0 == ret)
|
|
|
|
ret = test_revocation (dh);
|
|
|
|
if (0 == ret)
|
|
|
|
ret = test_signing (dh);
|
2020-11-22 22:25:49 +01:00
|
|
|
if (0 == ret)
|
|
|
|
ret = perf_signing (dh);
|
2020-11-22 18:31:33 +01:00
|
|
|
TALER_CRYPTO_helper_denom_disconnect (dh);
|
|
|
|
/* clean up our state */
|
|
|
|
for (unsigned int i = 0; i<MAX_KEYS; i++)
|
|
|
|
if (keys[i].valid)
|
|
|
|
{
|
2021-11-05 17:19:47 +01:00
|
|
|
TALER_denom_pub_free (&keys[i].denom_pub);
|
2020-11-22 18:31:33 +01:00
|
|
|
GNUNET_assert (num_keys > 0);
|
|
|
|
num_keys--;
|
|
|
|
}
|
2020-11-22 19:02:49 +01:00
|
|
|
return ret;
|
2020-11-22 18:31:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
const char *const argv[])
|
|
|
|
{
|
|
|
|
struct GNUNET_OS_Process *helper;
|
|
|
|
char *libexec_dir;
|
|
|
|
char *binary_name;
|
|
|
|
int ret;
|
|
|
|
enum GNUNET_OS_ProcessStatusType type;
|
|
|
|
unsigned long code;
|
|
|
|
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
GNUNET_log_setup ("test-helper-rsa",
|
2021-01-28 21:23:16 +01:00
|
|
|
"INFO",
|
2020-11-22 18:31:33 +01:00
|
|
|
NULL);
|
|
|
|
GNUNET_OS_init (TALER_project_data_default ());
|
2020-12-31 22:31:32 +01:00
|
|
|
libexec_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
|
2020-11-22 18:31:33 +01:00
|
|
|
GNUNET_asprintf (&binary_name,
|
|
|
|
"%s/%s",
|
|
|
|
libexec_dir,
|
2021-01-17 20:07:55 +01:00
|
|
|
"taler-exchange-secmod-rsa");
|
2020-11-22 18:31:33 +01:00
|
|
|
GNUNET_free (libexec_dir);
|
|
|
|
helper = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ERR,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
binary_name,
|
|
|
|
binary_name,
|
|
|
|
"-c",
|
|
|
|
"test_helper_rsa.conf",
|
|
|
|
"-L",
|
2021-01-28 21:23:16 +01:00
|
|
|
"INFO",
|
2020-11-22 18:31:33 +01:00
|
|
|
NULL);
|
|
|
|
if (NULL == helper)
|
|
|
|
{
|
|
|
|
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"exec",
|
|
|
|
binary_name);
|
|
|
|
GNUNET_free (binary_name);
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
GNUNET_free (binary_name);
|
|
|
|
ret = run_test ();
|
|
|
|
|
|
|
|
GNUNET_OS_process_kill (helper,
|
|
|
|
SIGTERM);
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
GNUNET_OS_process_wait_status (helper,
|
|
|
|
&type,
|
|
|
|
&code))
|
|
|
|
{
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"Helper process did not die voluntarily, killing hard\n");
|
|
|
|
GNUNET_OS_process_kill (helper,
|
|
|
|
SIGKILL);
|
|
|
|
ret = 4;
|
|
|
|
}
|
|
|
|
else if ( (GNUNET_OS_PROCESS_EXITED != type) ||
|
|
|
|
(0 != code) )
|
|
|
|
{
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"Helper died with unexpected status %d/%d\n",
|
|
|
|
(int) type,
|
|
|
|
(int) code);
|
|
|
|
ret = 5;
|
|
|
|
}
|
|
|
|
GNUNET_OS_process_destroy (helper);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* end of test_helper_rsa.c */
|