add private keys (undsigned) to the transcript

This commit is contained in:
Özgür Kesim 2022-10-06 14:46:48 +02:00
parent e1d6c8eb3e
commit 09af66c165
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7

View File

@ -502,7 +502,8 @@ tr_start (void *auction_closure)
} }
struct some_sig { struct some_sig
{
struct GNUNET_CRYPTO_EccSignaturePurpose purpose; struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
struct GNUNET_HashCode hc GNUNET_PACKED; struct GNUNET_HashCode hc GNUNET_PACKED;
}; };
@ -519,7 +520,7 @@ print_transcript (uint32_t highestprice)
json_t *transcript; json_t *transcript;
json_t *winners; json_t *winners;
struct GNUNET_HashCode hc; struct GNUNET_HashCode hc;
struct some_sig p = { .purpose.size = htonl(sizeof(struct some_sig)) }; struct some_sig p = { .purpose.size = htonl (sizeof(struct some_sig)) };
char price[256]; char price[256];
prices = json_array (); prices = json_array ();
@ -527,20 +528,22 @@ print_transcript (uint32_t highestprice)
for (size_t p = 0; p < tcase.k; p++) for (size_t p = 0; p < tcase.k; p++)
{ {
sprintf(price, "EUR:%d", highestprice--); sprintf (price, "EUR:%d", highestprice--);
GNUNET_assert ( GNUNET_assert (
-1 != json_array_append_new ( -1 != json_array_append_new (
prices, prices,
json_string(price))); json_string (price)));
} }
auction = json_pack ("{s:{s:o}, s:{s:o}, s:i, s:b, s:o, s:s, s:s}", auction = json_pack ("{s:{s:o}, s:{s:o}, s:i, s:b, s:o, s:s, s:s}",
"time_start", "t_s", json_integer (ad->time_start.abs_value_us / 1000LL), "time_start", "t_s", json_integer (
"time_round", "d_us", json_integer (ad->time_round.rel_value_us), ad->time_start.abs_value_us / 1000LL),
"time_round", "d_us", json_integer (
ad->time_round.rel_value_us),
"type", ad->m, "type", ad->m,
"public", ad->outcome_public == 0 ? json_false () : json_true (), "is_public", ad->outcome_public == 0 ? json_false () : json_true (),
"prices", prices, "prices", prices,
"payto", "payto://some/iban", "payto_uri", "payto://some/iban",
"pubkey", GNUNET_CRYPTO_eddsa_public_key_to_string ( "pubkey", GNUNET_CRYPTO_eddsa_public_key_to_string (
&tcase.pub[tcase.n])); &tcase.pub[tcase.n]));
GNUNET_assert (auction); GNUNET_assert (auction);
@ -560,24 +563,24 @@ print_transcript (uint32_t highestprice)
sigs = json_array (); sigs = json_array ();
GNUNET_assert (sigs); GNUNET_assert (sigs);
{ {
char *auc_js = json_dumps(auction, JSON_COMPACT); char *auc_js = json_dumps (auction, JSON_COMPACT);
GNUNET_CRYPTO_hash(auc_js, GNUNET_CRYPTO_hash (auc_js,
strlen(auc_js), strlen (auc_js),
&hc); &hc);
p.purpose.purpose = htonl(23); p.purpose.purpose = htonl (23);
p.hc = hc; p.hc = hc;
for (size_t b = 0; b < tcase.n; b++) for (size_t b = 0; b < tcase.n; b++)
{ {
struct GNUNET_CRYPTO_EddsaSignature sig; struct GNUNET_CRYPTO_EddsaSignature sig;
GNUNET_CRYPTO_eddsa_sign(&tcase.prv[b], GNUNET_CRYPTO_eddsa_sign (&tcase.prv[b],
&p, &p,
&sig); &sig);
GNUNET_assert (-1 != GNUNET_assert (-1 !=
json_array_append_new ( json_array_append_new (
sigs, sigs,
GNUNET_JSON_from_data_auto(&sig))); GNUNET_JSON_from_data_auto (&sig)));
} }
} }
@ -592,16 +595,16 @@ print_transcript (uint32_t highestprice)
if (NULL == msg) if (NULL == msg)
{ {
GNUNET_log(GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"skipping NULL msg[%ld]\n", i); "skipping NULL msg[%ld]\n", i);
continue; continue;
} }
GNUNET_assert (msg); GNUNET_assert (msg);
GNUNET_CRYPTO_hash(msg->buf, msg->buf_len, &hc); GNUNET_CRYPTO_hash (msg->buf, msg->buf_len, &hc);
p.purpose.purpose = htonl(42); p.purpose.purpose = htonl (42);
p.hc = hc; p.hc = hc;
GNUNET_CRYPTO_eddsa_sign ( GNUNET_CRYPTO_eddsa_sign (
@ -613,7 +616,7 @@ print_transcript (uint32_t highestprice)
entry = json_pack ("{s:i, s:o, s:o}", entry = json_pack ("{s:i, s:o, s:o}",
"bidder", msg->sender, "bidder", msg->sender,
"msg", GNUNET_JSON_from_data (msg->buf, msg->buf_len), "msg", GNUNET_JSON_from_data (msg->buf, msg->buf_len),
"sig", GNUNET_JSON_from_data_auto(&sig)); "sig", GNUNET_JSON_from_data_auto (&sig));
GNUNET_assert (entry); GNUNET_assert (entry);
GNUNET_assert (-1 != GNUNET_assert (-1 !=
@ -622,23 +625,23 @@ print_transcript (uint32_t highestprice)
} }
winners = json_array(); winners = json_array ();
GNUNET_assert (winners); GNUNET_assert (winners);
// add the winner(s) // add the winner(s)
{ {
for (uint16_t i = 0; i < tcase.res_len ; i++) for (uint16_t i = 0; i < tcase.res_len; i++)
{ {
json_t *res = json_pack("{s:i, s:i, s:o*}", json_t *res = json_pack ("{s:i, s:i, s:o*}",
"bidder", "bidder",
tcase.res[i].bidder, tcase.res[i].bidder,
"price_idx", "price_idx",
tcase.res[i].price, tcase.res[i].price,
"price", "price",
json_array_get(prices, tcase.res[i].price)); json_array_get (prices, tcase.res[i].price));
GNUNET_assert(res); GNUNET_assert (res);
GNUNET_assert(-1 != GNUNET_assert (-1 !=
json_array_append_new(winners, res)); json_array_append_new (winners, res));
} }
} }
@ -653,35 +656,56 @@ print_transcript (uint32_t highestprice)
GNUNET_assert (root); GNUNET_assert (root);
// Add signature of seller to H(auction, bidders, signatures, transscript, result) // Add signature of seller to H(auction, bidders, signatures, transcript, result)
{ {
struct GNUNET_CRYPTO_EddsaSignature sig; struct GNUNET_CRYPTO_EddsaSignature sig;
char *root_js = json_dumps(root, JSON_COMPACT|JSON_SORT_KEYS); char *root_js = json_dumps (root, JSON_COMPACT | JSON_SORT_KEYS);
GNUNET_CRYPTO_hash(root_js, GNUNET_CRYPTO_hash (root_js,
strlen(root_js), strlen (root_js),
&hc); &hc);
p.purpose.purpose = htonl(815); p.purpose.purpose = htonl (815);
p.hc = hc; p.hc = hc;
GNUNET_CRYPTO_eddsa_sign(&tcase.prv[tcase.n], GNUNET_CRYPTO_eddsa_sign (&tcase.prv[tcase.n],
&p, &p,
&sig); &sig);
GNUNET_assert ( -1 != GNUNET_assert (-1 !=
json_object_set_new ( json_object_set_new (
root, root,
"sig", "sig",
GNUNET_JSON_from_data_auto(&sig))); GNUNET_JSON_from_data_auto (&sig)));
free(root_js); free (root_js);
} }
printf ("%s\n", json_dumps (root, JSON_INDENT (2))); // After signing the transcript, add private key material, too, so it
// can be used in integration tests.
{
json_t *keys = json_array ();
GNUNET_assert (keys);
for (size_t b = 0; b <= /* = is important */ tcase.n; b++)
{
char *ps = GNUNET_CRYPTO_eddsa_private_key_to_string (&tcase.prv[b]);
GNUNET_assert (-1 !=
json_array_append_new (keys,
json_string (ps)));
}
json_object_set_new (
root,
"NOTSIGNED_keys",
keys);
}
printf ("\n%s\n", json_dumps (root, JSON_INDENT (2)));
json_decref (root); json_decref (root);
} }
static void static void
replay_transcript (void *arg) replay_transcript (void *arg)
{ {
@ -689,7 +713,7 @@ replay_transcript (void *arg)
size_t desc_len; size_t desc_len;
static struct GNUNET_CRYPTO_EccDlogContext *redc; static struct GNUNET_CRYPTO_EccDlogContext *redc;
print_transcript(96); print_transcript (96);
redc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); redc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
dprintf (2,"REPLAY, calling BRANDT_new...\n"); dprintf (2,"REPLAY, calling BRANDT_new...\n");
@ -713,8 +737,6 @@ replay_transcript (void *arg)
} }
/** /**
* Test a specific auction setup. * Test a specific auction setup.
* *