summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-04-09 20:51:19 +0200
committerChristian Grothoff <christian@grothoff.org>2017-04-09 20:51:19 +0200
commitc298436020e31c2d555b66374e10dc6350c7453c (patch)
tree9994d22bd5c4224e315c7096dbff49134c74ffa8
parent11b8710a5caac9c81cb0eb6094b363fa46a74809 (diff)
downloadexchange-c298436020e31c2d555b66374e10dc6350c7453c.tar.gz
exchange-c298436020e31c2d555b66374e10dc6350c7453c.tar.bz2
exchange-c298436020e31c2d555b66374e10dc6350c7453c.zip
expand testcase to cover TALER_EXCHANGEDB_denomination_key_revoke
-rw-r--r--src/exchangedb/test_exchangedb_denomkeys.c87
1 files changed, 84 insertions, 3 deletions
diff --git a/src/exchangedb/test_exchangedb_denomkeys.c b/src/exchangedb/test_exchangedb_denomkeys.c
index fb728115..3d658534 100644
--- a/src/exchangedb/test_exchangedb_denomkeys.c
+++ b/src/exchangedb/test_exchangedb_denomkeys.c
@@ -51,6 +51,60 @@ dki_iter (void *cls,
{
const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *exp = cls;
+ if (NULL != revocation_master_sig)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 != memcmp (&exp->issue,
+ &dki->issue,
+ sizeof (struct TALER_EXCHANGEDB_DenominationKeyInformationP)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 !=
+ GNUNET_CRYPTO_rsa_private_key_cmp (exp->denom_priv.rsa_private_key,
+ dki->denom_priv.rsa_private_key))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 !=
+ GNUNET_CRYPTO_rsa_public_key_cmp (exp->denom_pub.rsa_public_key,
+ dki->denom_pub.rsa_public_key))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * @brief Iterator called on revoked denomination key.
+ *
+ * @param cls closure with expected DKI
+ * @param dki the denomination key
+ * @param alias coin alias
+ * @param revocation_master_sig non-NULL if @a dki was revoked
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to stop iteration with no error,
+ * #GNUNET_SYSERR to abort iteration with error!
+ */
+static int
+dki_iter_revoked (void *cls,
+ const char *alias,
+ const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki,
+ const struct TALER_MasterSignatureP *revocation_master_sig)
+{
+ const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *exp = cls;
+
+ if (NULL == revocation_master_sig)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (0 != memcmp (&exp->issue,
&dki->issue,
sizeof (struct TALER_EXCHANGEDB_DenominationKeyInformationP)))
@@ -72,6 +126,7 @@ dki_iter (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
+
return GNUNET_OK;
}
@@ -84,12 +139,16 @@ main (int argc,
char *enc;
size_t enc_size;
struct TALER_EXCHANGEDB_DenominationKeyIssueInformation dki_read;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ struct TALER_MasterPrivateKeyP master_priv;
struct TALER_MasterPublicKeyP master_pub;
char *enc_read;
size_t enc_read_size;
char *tmpfile;
+ char *tmpdir2;
char *tmpdir;
int ret;
+ struct GNUNET_TIME_Absolute start;
ret = 1;
GNUNET_log_setup ("test-exchangedb-denomkeys",
@@ -100,7 +159,11 @@ main (int argc,
tmpfile = NULL;
dki.denom_priv.rsa_private_key = NULL;
dki_read.denom_priv.rsa_private_key = NULL;
- memset (&master_pub, 42, sizeof (master_pub)); /* for now does not matter */
+ pk = GNUNET_CRYPTO_eddsa_key_create ();
+ master_priv.eddsa_priv = *pk;
+ GNUNET_CRYPTO_eddsa_key_get_public (pk,
+ &master_pub.eddsa_pub);
+ GNUNET_free (pk);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&dki.issue,
sizeof (struct TALER_EXCHANGEDB_DenominationKeyInformationP));
@@ -111,12 +174,13 @@ main (int argc,
enc_size = GNUNET_CRYPTO_rsa_private_key_encode (dki.denom_priv.rsa_private_key,
&enc);
EXITIF (NULL == (tmpdir = GNUNET_DISK_mkdtemp ("test_exchangedb_dki")));
+ start = GNUNET_TIME_absolute_ntoh (dki.issue.properties.start);
GNUNET_asprintf (&tmpfile,
- "%s/%s/%s/%s",
+ "%s/%s/%s/%llu",
tmpdir,
TALER_EXCHANGEDB_DIR_DENOMINATION_KEYS,
"cur-unit-uuid",
- "testkey.key");
+ (unsigned long long) start.abs_value_us);
EXITIF (GNUNET_OK !=
TALER_EXCHANGEDB_denomination_key_write (tmpfile,
&dki));
@@ -129,6 +193,23 @@ main (int argc,
&dki_iter,
&dki));
+ GNUNET_asprintf (&tmpdir2,
+ "%s/%s/",
+ tmpdir,
+ TALER_EXCHANGEDB_DIR_DENOMINATION_KEYS);
+ EXITIF (GNUNET_OK !=
+ TALER_EXCHANGEDB_denomination_key_revoke (tmpdir2,
+ "cur-unit-uuid",
+ &dki,
+ &master_priv));
+ GNUNET_free (tmpdir2);
+
+ EXITIF (1 !=
+ TALER_EXCHANGEDB_denomination_keys_iterate (tmpdir,
+ &master_pub,
+ &dki_iter_revoked,
+ &dki));
+
enc_read_size = GNUNET_CRYPTO_rsa_private_key_encode (dki_read.denom_priv.rsa_private_key,
&enc_read);