fix remaining libtalerutil tests FTBFS issues

This commit is contained in:
Christian Grothoff 2021-10-23 06:20:28 +02:00
parent 43223899e7
commit 57c334fb1f
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 52 additions and 44 deletions

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
(C) 2015, 2020 Taler Systems SA (C) 2015, 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 General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -90,18 +90,21 @@ test_planchets (void)
struct TALER_PlanchetDetail pd; struct TALER_PlanchetDetail pd;
struct GNUNET_CRYPTO_RsaSignature *blind_sig; struct GNUNET_CRYPTO_RsaSignature *blind_sig;
struct TALER_FreshCoin coin; struct TALER_FreshCoin coin;
struct GNUNET_HashCode c_hash; struct TALER_CoinPubHash c_hash;
dk_priv.rsa_private_key = GNUNET_CRYPTO_rsa_private_key_create (1024); dk_priv.cipher = TALER_DENOMINATION_RSA;
dk_pub.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public ( dk_priv.details.rsa_private_key
dk_priv.rsa_private_key); = GNUNET_CRYPTO_rsa_private_key_create (1024);
TALER_denom_priv_to_pub (&dk_priv,
0,
&dk_pub);
TALER_planchet_setup_random (&ps); TALER_planchet_setup_random (&ps);
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_planchet_prepare (&dk_pub, TALER_planchet_prepare (&dk_pub,
&ps, &ps,
&c_hash, &c_hash,
&pd)); &pd));
blind_sig = GNUNET_CRYPTO_rsa_sign_blinded (dk_priv.rsa_private_key, blind_sig = GNUNET_CRYPTO_rsa_sign_blinded (dk_priv.details.rsa_private_key,
pd.coin_ev, pd.coin_ev,
pd.coin_ev_size); pd.coin_ev_size);
GNUNET_assert (NULL != blind_sig); GNUNET_assert (NULL != blind_sig);
@ -112,15 +115,15 @@ test_planchets (void)
&c_hash, &c_hash,
&coin)); &coin));
GNUNET_CRYPTO_rsa_signature_free (blind_sig); GNUNET_CRYPTO_rsa_signature_free (blind_sig);
GNUNET_CRYPTO_rsa_signature_free (coin.sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (coin.sig.details.rsa_signature);
GNUNET_CRYPTO_rsa_private_key_free (dk_priv.rsa_private_key); GNUNET_CRYPTO_rsa_private_key_free (dk_priv.details.rsa_private_key);
GNUNET_CRYPTO_rsa_public_key_free (dk_pub.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (dk_pub.details.rsa_public_key);
return 0; return 0;
} }
static int static int
test_exchange_sigs () test_exchange_sigs (void)
{ {
const char *pt = "payto://x-taler-bank/localhost/Account"; const char *pt = "payto://x-taler-bank/localhost/Account";
struct TALER_MasterPrivateKeyP priv; struct TALER_MasterPrivateKeyP priv;
@ -155,7 +158,7 @@ test_exchange_sigs ()
static int static int
test_merchant_sigs () test_merchant_sigs (void)
{ {
const char *pt = "payto://x-taler-bank/localhost/Account"; const char *pt = "payto://x-taler-bank/localhost/Account";
struct TALER_WireSalt salt; struct TALER_WireSalt salt;

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
(C) 2020 Taler Systems SA (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 General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -62,7 +62,7 @@ struct KeyData
/** /**
* Hash of the public key. * Hash of the public key.
*/ */
struct GNUNET_HashCode h_denom_pub; struct TALER_DenominationHash h_denom_pub;
/** /**
* Full public key. * Full public key.
@ -110,7 +110,7 @@ key_cb (void *cls,
const char *section_name, const char *section_name,
struct GNUNET_TIME_Absolute start_time, struct GNUNET_TIME_Absolute start_time,
struct GNUNET_TIME_Relative validity_duration, struct GNUNET_TIME_Relative validity_duration,
const struct GNUNET_HashCode *h_denom_pub, const struct TALER_DenominationHash *h_denom_pub,
const struct TALER_DenominationPublicKey *denom_pub, const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub, const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig) const struct TALER_SecurityModuleSignatureP *sm_sig)
@ -119,7 +119,7 @@ key_cb (void *cls,
(void) sm_sig; (void) sm_sig;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Key notification about key %s in `%s'\n", "Key notification about key %s in `%s'\n",
GNUNET_h2s (h_denom_pub), GNUNET_h2s (&h_denom_pub->hash),
section_name); section_name);
if (0 == validity_duration.rel_value_us) if (0 == validity_duration.rel_value_us)
{ {
@ -133,8 +133,9 @@ key_cb (void *cls,
{ {
keys[i].valid = false; keys[i].valid = false;
keys[i].revoked = false; keys[i].revoked = false;
GNUNET_CRYPTO_rsa_public_key_free (keys[i].denom_pub.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (
keys[i].denom_pub.rsa_public_key = NULL; keys[i].denom_pub.details.rsa_public_key);
keys[i].denom_pub.details.rsa_public_key = NULL;
GNUNET_assert (num_keys > 0); GNUNET_assert (num_keys > 0);
num_keys--; num_keys--;
found = true; found = true;
@ -155,8 +156,9 @@ key_cb (void *cls,
keys[i].h_denom_pub = *h_denom_pub; keys[i].h_denom_pub = *h_denom_pub;
keys[i].start_time = start_time; keys[i].start_time = start_time;
keys[i].validity_duration = validity_duration; keys[i].validity_duration = validity_duration;
keys[i].denom_pub.rsa_public_key keys[i].denom_pub = *denom_pub;
= GNUNET_CRYPTO_rsa_public_key_dup (denom_pub->rsa_public_key); keys[i].denom_pub.details.rsa_public_key
= GNUNET_CRYPTO_rsa_public_key_dup (denom_pub->details.rsa_public_key);
num_keys++; num_keys++;
return; return;
} }
@ -199,7 +201,7 @@ test_revocation (struct TALER_CRYPTO_DenominationHelper *dh)
keys[j].revoked = true; keys[j].revoked = true;
fprintf (stderr, fprintf (stderr,
"Revoking key %s ...", "Revoking key %s ...",
GNUNET_h2s (&keys[j].h_denom_pub)); GNUNET_h2s (&keys[j].h_denom_pub.hash));
TALER_CRYPTO_helper_denom_revoke (dh, TALER_CRYPTO_helper_denom_revoke (dh,
&keys[j].h_denom_pub); &keys[j].h_denom_pub);
for (unsigned int k = 0; k<1000; k++) for (unsigned int k = 0; k<1000; k++)
@ -238,7 +240,7 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
struct TALER_DenominationSignature ds; struct TALER_DenominationSignature ds;
enum TALER_ErrorCode ec; enum TALER_ErrorCode ec;
bool success = false; bool success = false;
struct GNUNET_HashCode m_hash; struct TALER_CoinPubHash m_hash;
struct GNUNET_CRYPTO_RsaBlindingKeySecret bks; struct GNUNET_CRYPTO_RsaBlindingKeySecret bks;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
@ -246,7 +248,7 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
sizeof (bks)); sizeof (bks));
GNUNET_CRYPTO_hash ("Hello", GNUNET_CRYPTO_hash ("Hello",
strlen ("Hello"), strlen ("Hello"),
&m_hash); &m_hash.hash);
for (unsigned int i = 0; i<MAX_KEYS; i++) for (unsigned int i = 0; i<MAX_KEYS; i++)
{ {
if (! keys[i].valid) if (! keys[i].valid)
@ -258,13 +260,13 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
TALER_rsa_blind (&m_hash, TALER_rsa_blind (&m_hash,
&bks, &bks,
keys[i].denom_pub.rsa_public_key, keys[i].denom_pub.details.rsa_public_key,
&buf, &buf,
&buf_size)); &buf_size));
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting signature over %u bytes with key %s\n", "Requesting signature over %u bytes with key %s\n",
(unsigned int) buf_size, (unsigned int) buf_size,
GNUNET_h2s (&keys[i].h_denom_pub)); GNUNET_h2s (&keys[i].h_denom_pub.hash));
ds = TALER_CRYPTO_helper_denom_sign (dh, ds = TALER_CRYPTO_helper_denom_sign (dh,
&keys[i].h_denom_pub, &keys[i].h_denom_pub,
buf, buf,
@ -290,32 +292,34 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
return 5; return 5;
} }
{ {
struct GNUNET_CRYPTO_RsaSignature *rs; struct TALER_DenominationSignature rs;
rs = TALER_rsa_unblind (ds.rsa_signature, rs.cipher = TALER_DENOMINATION_RSA;
rs.details.rsa_signature
= TALER_rsa_unblind (ds.details.rsa_signature,
&bks, &bks,
keys[i].denom_pub.rsa_public_key); keys[i].denom_pub.details.rsa_public_key);
if (NULL == rs) if (NULL == rs.details.rsa_signature)
{ {
GNUNET_break (0); GNUNET_break (0);
return 6; return 6;
} }
GNUNET_CRYPTO_rsa_signature_free (ds.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (ds.details.rsa_signature);
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CRYPTO_rsa_verify (&m_hash, TALER_denom_pub_verify (&keys[i].denom_pub,
rs, &rs,
keys[i].denom_pub.rsa_public_key)) &m_hash))
{ {
/* signature invalid */ /* signature invalid */
GNUNET_break (0); GNUNET_break (0);
GNUNET_CRYPTO_rsa_signature_free (rs); GNUNET_CRYPTO_rsa_signature_free (rs.details.rsa_signature);
return 7; return 7;
} }
GNUNET_CRYPTO_rsa_signature_free (rs); GNUNET_CRYPTO_rsa_signature_free (rs.details.rsa_signature);
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received valid signature for key %s\n", "Received valid signature for key %s\n",
GNUNET_h2s (&keys[i].h_denom_pub)); GNUNET_h2s (&keys[i].h_denom_pub.hash));
success = true; success = true;
break; break;
case TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY: case TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY:
@ -350,7 +354,7 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
/* check signing does not work if the key is unknown */ /* check signing does not work if the key is unknown */
{ {
struct GNUNET_HashCode rnd; struct TALER_DenominationHash rnd;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd, &rnd,
@ -367,7 +371,7 @@ test_signing (struct TALER_CRYPTO_DenominationHelper *dh)
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Signing with invalid key %s failed as desired\n", "Signing with invalid key %s failed as desired\n",
GNUNET_h2s (&rnd)); GNUNET_h2s (&rnd.hash));
} }
return 0; return 0;
} }
@ -384,7 +388,7 @@ perf_signing (struct TALER_CRYPTO_DenominationHelper *dh)
{ {
struct TALER_DenominationSignature ds; struct TALER_DenominationSignature ds;
enum TALER_ErrorCode ec; enum TALER_ErrorCode ec;
struct GNUNET_HashCode m_hash; struct TALER_CoinPubHash m_hash;
struct GNUNET_CRYPTO_RsaBlindingKeySecret bks; struct GNUNET_CRYPTO_RsaBlindingKeySecret bks;
struct GNUNET_TIME_Relative duration; struct GNUNET_TIME_Relative duration;
@ -393,7 +397,7 @@ perf_signing (struct TALER_CRYPTO_DenominationHelper *dh)
sizeof (bks)); sizeof (bks));
GNUNET_CRYPTO_hash ("Hello", GNUNET_CRYPTO_hash ("Hello",
strlen ("Hello"), strlen ("Hello"),
&m_hash); &m_hash.hash);
duration = GNUNET_TIME_UNIT_ZERO; duration = GNUNET_TIME_UNIT_ZERO;
for (unsigned int j = 0; j<NUM_SIGN_TESTS;) for (unsigned int j = 0; j<NUM_SIGN_TESTS;)
{ {
@ -415,7 +419,7 @@ perf_signing (struct TALER_CRYPTO_DenominationHelper *dh)
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
TALER_rsa_blind (&m_hash, TALER_rsa_blind (&m_hash,
&bks, &bks,
keys[i].denom_pub.rsa_public_key, keys[i].denom_pub.details.rsa_public_key,
&buf, &buf,
&buf_size)); &buf_size));
/* use this key as long as it works */ /* use this key as long as it works */
@ -434,7 +438,7 @@ perf_signing (struct TALER_CRYPTO_DenominationHelper *dh)
delay = GNUNET_TIME_absolute_get_duration (start); delay = GNUNET_TIME_absolute_get_duration (start);
duration = GNUNET_TIME_relative_add (duration, duration = GNUNET_TIME_relative_add (duration,
delay); delay);
GNUNET_CRYPTO_rsa_signature_free (ds.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (ds.details.rsa_signature);
j++; j++;
if (NUM_SIGN_TESTS == j) if (NUM_SIGN_TESTS == j)
break; break;
@ -526,8 +530,9 @@ run_test (void)
for (unsigned int i = 0; i<MAX_KEYS; i++) for (unsigned int i = 0; i<MAX_KEYS; i++)
if (keys[i].valid) if (keys[i].valid)
{ {
GNUNET_CRYPTO_rsa_public_key_free (keys[i].denom_pub.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (
keys[i].denom_pub.rsa_public_key = NULL; keys[i].denom_pub.details.rsa_public_key);
keys[i].denom_pub.details.rsa_public_key = NULL;
GNUNET_assert (num_keys > 0); GNUNET_assert (num_keys > 0);
num_keys--; num_keys--;
} }