diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-20 10:18:03 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-20 10:18:03 +0000 |
commit | ab18dc025d49c720bf59eb88748a8c1d58d50af2 (patch) | |
tree | 366040cbd328b02fff28d9193f30498a76c31f53 /src | |
parent | 3a97e98e8036bf1652562715b4b4bff4193efb4e (diff) | |
download | gnunet-ab18dc025d49c720bf59eb88748a8c1d58d50af2.tar.gz gnunet-ab18dc025d49c720bf59eb88748a8c1d58d50af2.zip |
sensor: fixes for proof-of-work, test passes now
Diffstat (limited to 'src')
-rw-r--r-- | src/sensor/sensor_util_lib_crypto.c | 27 | ||||
-rw-r--r-- | src/sensor/test_gnunet-service-sensor_reporting.c | 12 | ||||
-rw-r--r-- | src/sensor/test_pow_sign.c | 35 |
3 files changed, 53 insertions, 21 deletions
diff --git a/src/sensor/sensor_util_lib_crypto.c b/src/sensor/sensor_util_lib_crypto.c index 7cf505186..e097ed3ae 100644 --- a/src/sensor/sensor_util_lib_crypto.c +++ b/src/sensor/sensor_util_lib_crypto.c | |||
@@ -167,8 +167,8 @@ calculate_pow (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
167 | htonl (GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT); | 167 | htonl (GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT); |
168 | result_block->purpose.size = | 168 | result_block->purpose.size = |
169 | htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 169 | htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + |
170 | sizeof (struct GNUNET_TIME_Absolute) + | 170 | sizeof (struct GNUNET_TIME_Absolute) + |
171 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + cx->msg_size); | 171 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + cx->msg_size); |
172 | memcpy (&result_block[1], &cx[1], cx->msg_size); | 172 | memcpy (&result_block[1], &cx[1], cx->msg_size); |
173 | sign_result = | 173 | sign_result = |
174 | GNUNET_CRYPTO_eddsa_sign (&cx->private_key, &result_block->purpose, | 174 | GNUNET_CRYPTO_eddsa_sign (&cx->private_key, &result_block->purpose, |
@@ -178,6 +178,7 @@ calculate_pow (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
178 | GNUNET_SENSOR_crypto_pow_sign_cancel (cx); | 178 | GNUNET_SENSOR_crypto_pow_sign_cancel (cx); |
179 | if (NULL != callback) | 179 | if (NULL != callback) |
180 | callback (callback_cls, (GNUNET_OK == sign_result) ? result_block : NULL); | 180 | callback (callback_cls, (GNUNET_OK == sign_result) ? result_block : NULL); |
181 | return; | ||
181 | } | 182 | } |
182 | cx->pow++; | 183 | cx->pow++; |
183 | cx->calculate_pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cx); | 184 | cx->calculate_pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cx); |
@@ -193,7 +194,13 @@ void | |||
193 | GNUNET_SENSOR_crypto_pow_sign_cancel (struct GNUNET_SENSOR_crypto_pow_context | 194 | GNUNET_SENSOR_crypto_pow_sign_cancel (struct GNUNET_SENSOR_crypto_pow_context |
194 | *cx) | 195 | *cx) |
195 | { | 196 | { |
197 | if (GNUNET_SCHEDULER_NO_TASK != cx->calculate_pow_task) | ||
198 | { | ||
199 | GNUNET_SCHEDULER_cancel (cx->calculate_pow_task); | ||
200 | cx->calculate_pow_task = GNUNET_SCHEDULER_NO_TASK; | ||
201 | } | ||
196 | GNUNET_free (cx); | 202 | GNUNET_free (cx); |
203 | cx = NULL; | ||
197 | } | 204 | } |
198 | 205 | ||
199 | 206 | ||
@@ -262,23 +269,27 @@ GNUNET_SENSOR_crypto_verify_pow_sign (struct GNUNET_SENSOR_crypto_pow_block * | |||
262 | void **payload) | 269 | void **payload) |
263 | { | 270 | { |
264 | /* Check public key */ | 271 | /* Check public key */ |
265 | if (0 != memcmp (public_key, &block->public_key, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) | 272 | if (0 != |
273 | memcmp (public_key, &block->public_key, | ||
274 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) | ||
266 | { | 275 | { |
267 | LOG (GNUNET_ERROR_TYPE_WARNING, "Public key mismatch.\n"); | 276 | LOG (GNUNET_ERROR_TYPE_WARNING, "Public key mismatch.\n"); |
268 | return 0; | 277 | return 0; |
269 | } | 278 | } |
270 | /* Check signature */ | 279 | /* Check signature */ |
271 | if (GNUNET_OK != | 280 | if (GNUNET_OK != |
272 | GNUNET_CRYPTO_eddsa_verify (purpose, &block->purpose, | 281 | GNUNET_CRYPTO_eddsa_verify (purpose, &block->purpose, &block->signature, |
273 | &block->signature, public_key)) | 282 | public_key)) |
274 | { | 283 | { |
275 | LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid signature.\n"); | 284 | LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid signature.\n"); |
276 | return 0; | 285 | return 0; |
277 | } | 286 | } |
278 | /* Check pow */ | 287 | /* Check pow */ |
279 | if (GNUNET_NO == check_pow (&block->timestamp, | 288 | if (GNUNET_NO == |
280 | sizeof (struct GNUNET_TIME_Absolute) + | 289 | check_pow (&block->timestamp, |
281 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + block->msg_size, block->pow, matching_bits)) | 290 | sizeof (struct GNUNET_TIME_Absolute) + |
291 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + block->msg_size, | ||
292 | block->pow, matching_bits)) | ||
282 | { | 293 | { |
283 | LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid proof-of-work.\n"); | 294 | LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid proof-of-work.\n"); |
284 | return 0; | 295 | return 0; |
diff --git a/src/sensor/test_gnunet-service-sensor_reporting.c b/src/sensor/test_gnunet-service-sensor_reporting.c index afe45afea..acb0e7165 100644 --- a/src/sensor/test_gnunet-service-sensor_reporting.c +++ b/src/sensor/test_gnunet-service-sensor_reporting.c | |||
@@ -356,7 +356,11 @@ sensor_service_started (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
356 | { | 356 | { |
357 | struct TestPeer *peer = cls; | 357 | struct TestPeer *peer = cls; |
358 | 358 | ||
359 | GNUNET_assert (NULL == emsg); | 359 | if (NULL != emsg) |
360 | { | ||
361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
362 | GNUNET_assert (0); | ||
363 | } | ||
360 | peer->sensor_op = | 364 | peer->sensor_op = |
361 | GNUNET_TESTBED_service_connect (NULL, peer->testbed_peer, "sensor", | 365 | GNUNET_TESTBED_service_connect (NULL, peer->testbed_peer, "sensor", |
362 | &sensor_connect_cb, peer, | 366 | &sensor_connect_cb, peer, |
@@ -441,7 +445,11 @@ static void | |||
441 | dashboard_started (void *cls, struct GNUNET_TESTBED_Operation *op, | 445 | dashboard_started (void *cls, struct GNUNET_TESTBED_Operation *op, |
442 | const char *emsg) | 446 | const char *emsg) |
443 | { | 447 | { |
444 | GNUNET_assert (NULL == emsg); | 448 | if (NULL != emsg) |
449 | { | ||
450 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
451 | GNUNET_assert (0); | ||
452 | } | ||
445 | GNUNET_TESTBED_operation_done (op); | 453 | GNUNET_TESTBED_operation_done (op); |
446 | /* Connect to peerstore service on first peer */ | 454 | /* Connect to peerstore service on first peer */ |
447 | peerstore_op = | 455 | peerstore_op = |
diff --git a/src/sensor/test_pow_sign.c b/src/sensor/test_pow_sign.c index 84e990cff..e1e78a721 100644 --- a/src/sensor/test_pow_sign.c +++ b/src/sensor/test_pow_sign.c | |||
@@ -107,18 +107,29 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | static void pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block) | 110 | static void |
111 | pow_cb (void *cls, struct GNUNET_SENSOR_crypto_pow_block *block) | ||
111 | { | 112 | { |
112 | void *response; | 113 | void *response; |
113 | 114 | ||
114 | printf ("Received block:\n" | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
115 | "pow: %" PRIu64 ".\n", block->pow); | 116 | "Received block:\n" "pow: %" PRIu64 ".\n", block->pow); |
117 | /* Test that the block is valid */ | ||
116 | GNUNET_assert (MSG_SIZE == | 118 | GNUNET_assert (MSG_SIZE == |
117 | GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS, | 119 | GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS, |
118 | public_key, GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT, &response)); | 120 | public_key, |
119 | GNUNET_assert (0 == memcmp(msg, response, MSG_SIZE)); | 121 | GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT, |
122 | &response)); | ||
123 | GNUNET_assert (0 == memcmp (msg, response, MSG_SIZE)); | ||
124 | /* Modify the payload and test that verification returns invalid */ | ||
125 | block->pow++; | ||
126 | GNUNET_assert (0 == | ||
127 | GNUNET_SENSOR_crypto_verify_pow_sign (block, MATCHING_BITS, | ||
128 | public_key, | ||
129 | GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT, | ||
130 | &response)); | ||
120 | ok = 0; | 131 | ok = 0; |
121 | GNUNET_SCHEDULER_cancel(shutdown_task); | 132 | GNUNET_SCHEDULER_cancel (shutdown_task); |
122 | GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | 133 | GNUNET_SCHEDULER_add_now (do_shutdown, NULL); |
123 | } | 134 | } |
124 | 135 | ||
@@ -140,17 +151,19 @@ peer_info_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | |||
140 | struct GNUNET_TIME_Absolute timestamp; | 151 | struct GNUNET_TIME_Absolute timestamp; |
141 | 152 | ||
142 | /* generate random data block */ | 153 | /* generate random data block */ |
143 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, msg, MSG_SIZE); | 154 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, msg, MSG_SIZE); |
144 | /* get private and public keys */ | 155 | /* get private and public keys */ |
145 | private_key = | 156 | private_key = |
146 | GNUNET_CRYPTO_eddsa_key_create_from_configuration (pinfo->result.cfg); | 157 | GNUNET_CRYPTO_eddsa_key_create_from_configuration (pinfo->result.cfg); |
147 | GNUNET_assert (NULL != private_key); | 158 | GNUNET_assert (NULL != private_key); |
148 | public_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPublicKey); | 159 | public_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPublicKey); |
160 | |||
149 | GNUNET_CRYPTO_eddsa_key_get_public (private_key, public_key); | 161 | GNUNET_CRYPTO_eddsa_key_get_public (private_key, public_key); |
150 | /* create pow and sign */ | 162 | /* create pow and sign */ |
151 | timestamp = GNUNET_TIME_absolute_get(); | 163 | timestamp = GNUNET_TIME_absolute_get (); |
152 | GNUNET_SENSOR_crypto_pow_sign (msg, MSG_SIZE, ×tamp, | 164 | GNUNET_SENSOR_crypto_pow_sign (msg, MSG_SIZE, ×tamp, public_key, |
153 | public_key, private_key, MATCHING_BITS, &pow_cb, NULL); | 165 | private_key, MATCHING_BITS, &pow_cb, NULL); |
166 | GNUNET_TESTBED_operation_done (op); | ||
154 | } | 167 | } |
155 | 168 | ||
156 | 169 | ||