htonl (GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT);
result_block->purpose.size =
htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
- sizeof (struct GNUNET_TIME_Absolute) +
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + cx->msg_size);
+ sizeof (struct GNUNET_TIME_Absolute) +
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + cx->msg_size);
memcpy (&result_block[1], &cx[1], cx->msg_size);
sign_result =
GNUNET_CRYPTO_eddsa_sign (&cx->private_key, &result_block->purpose,
GNUNET_SENSOR_crypto_pow_sign_cancel (cx);
if (NULL != callback)
callback (callback_cls, (GNUNET_OK == sign_result) ? result_block : NULL);
+ return;
}
cx->pow++;
cx->calculate_pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cx);
GNUNET_SENSOR_crypto_pow_sign_cancel (struct GNUNET_SENSOR_crypto_pow_context
*cx)
{
+ if (GNUNET_SCHEDULER_NO_TASK != cx->calculate_pow_task)
+ {
+ GNUNET_SCHEDULER_cancel (cx->calculate_pow_task);
+ cx->calculate_pow_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free (cx);
+ cx = NULL;
}
void **payload)
{
/* Check public key */
- if (0 != memcmp (public_key, &block->public_key, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))
+ if (0 !=
+ memcmp (public_key, &block->public_key,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))
{
LOG (GNUNET_ERROR_TYPE_WARNING, "Public key mismatch.\n");
return 0;
}
/* Check signature */
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify (purpose, &block->purpose,
- &block->signature, public_key))
+ GNUNET_CRYPTO_eddsa_verify (purpose, &block->purpose, &block->signature,
+ public_key))
{
LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid signature.\n");
return 0;
}
/* Check pow */
- if (GNUNET_NO == check_pow (&block->timestamp,
- sizeof (struct GNUNET_TIME_Absolute) +
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + block->msg_size, block->pow, matching_bits))
+ if (GNUNET_NO ==
+ check_pow (&block->timestamp,
+ sizeof (struct GNUNET_TIME_Absolute) +
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + block->msg_size,
+ block->pow, matching_bits))
{
LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid proof-of-work.\n");
return 0;
{
struct TestPeer *peer = cls;
- GNUNET_assert (NULL == emsg);
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg);
+ GNUNET_assert (0);
+ }
peer->sensor_op =
GNUNET_TESTBED_service_connect (NULL, peer->testbed_peer, "sensor",
&sensor_connect_cb, peer,
dashboard_started (void *cls, struct GNUNET_TESTBED_Operation *op,
const char *emsg)
{
- GNUNET_assert (NULL == emsg);
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg);
+ GNUNET_assert (0);
+ }
GNUNET_TESTBED_operation_done (op);
/* Connect to peerstore service on first peer */
peerstore_op =
}
-static void pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block)
+static void
+pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block)
{
void *response;
- printf ("Received block:\n"
- "pow: %" PRIu64 ".\n", block->pow);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received block:\n" "pow: %" PRIu64 ".\n", block->pow);
+ /* Test that the block is valid */
GNUNET_assert (MSG_SIZE ==
- GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS,
- public_key, GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT, &response));
- GNUNET_assert (0 == memcmp(msg, response, MSG_SIZE));
+ GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS,
+ public_key,
+ GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT,
+ &response));
+ GNUNET_assert (0 == memcmp (msg, response, MSG_SIZE));
+ /* Modify the payload and test that verification returns invalid */
+ block->pow++;
+ GNUNET_assert (0 ==
+ GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS,
+ public_key,
+ GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT,
+ &response));
ok = 0;
- GNUNET_SCHEDULER_cancel(shutdown_task);
+ GNUNET_SCHEDULER_cancel (shutdown_task);
GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
}
struct GNUNET_TIME_Absolute timestamp;
/* generate random data block */
- GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, msg, MSG_SIZE);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, msg, MSG_SIZE);
/* get private and public keys */
private_key =
GNUNET_CRYPTO_eddsa_key_create_from_configuration (pinfo->result.cfg);
GNUNET_assert (NULL != private_key);
public_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPublicKey);
+
GNUNET_CRYPTO_eddsa_key_get_public (private_key, public_key);
/* create pow and sign */
- timestamp = GNUNET_TIME_absolute_get();
- GNUNET_SENSOR_crypto_pow_sign (msg, MSG_SIZE, ×tamp,
- public_key, private_key, MATCHING_BITS, &pow_cb, NULL);
+ timestamp = GNUNET_TIME_absolute_get ();
+ GNUNET_SENSOR_crypto_pow_sign (msg, MSG_SIZE, ×tamp, public_key,
+ private_key, MATCHING_BITS, &pow_cb, NULL);
+ GNUNET_TESTBED_operation_done (op);
}