diff options
Diffstat (limited to 'src/secretsharing/secretsharing_api.c')
-rw-r--r-- | src/secretsharing/secretsharing_api.c | 96 |
1 files changed, 59 insertions, 37 deletions
diff --git a/src/secretsharing/secretsharing_api.c b/src/secretsharing/secretsharing_api.c index 78c444810..441164850 100644 --- a/src/secretsharing/secretsharing_api.c +++ b/src/secretsharing/secretsharing_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012 GNUnet e.V. | 3 | Copyright (C) 2012, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -166,38 +166,51 @@ handle_decrypt_client_error (void *cls, | |||
166 | * result to the application. | 166 | * result to the application. |
167 | * | 167 | * |
168 | * @param cls the `struct GNUNET_SECRETSHARING_Session` | 168 | * @param cls the `struct GNUNET_SECRETSHARING_Session` |
169 | * @param msg message with the result | 169 | * @param m message with the result |
170 | */ | ||
171 | static int | ||
172 | check_secret_ready (void *cls, | ||
173 | const struct GNUNET_SECRETSHARING_SecretReadyMessage *m) | ||
174 | { | ||
175 | /* FIXME: actually check m is well-formed here! */ | ||
176 | return GNUNET_OK; | ||
177 | } | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Handler invoked with the final result message from | ||
182 | * secret sharing. Decodes the message and passes the | ||
183 | * result to the application. | ||
184 | * | ||
185 | * @param cls the `struct GNUNET_SECRETSHARING_Session` | ||
186 | * @param m message with the result | ||
170 | */ | 187 | */ |
171 | static void | 188 | static void |
172 | handle_secret_ready (void *cls, | 189 | handle_secret_ready (void *cls, |
173 | const struct GNUNET_MessageHeader *msg) | 190 | const struct GNUNET_SECRETSHARING_SecretReadyMessage *m) |
174 | { | 191 | { |
175 | struct GNUNET_SECRETSHARING_Session *s = cls; | 192 | struct GNUNET_SECRETSHARING_Session *s = cls; |
176 | const struct GNUNET_SECRETSHARING_SecretReadyMessage *m; | ||
177 | struct GNUNET_SECRETSHARING_Share *share; | 193 | struct GNUNET_SECRETSHARING_Share *share; |
178 | size_t share_size; | 194 | size_t share_size; |
179 | 195 | ||
180 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 196 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
181 | "Got secret ready message of size %u\n", | 197 | "Got secret ready message of size %u\n", |
182 | ntohs (msg->size)); | 198 | ntohs (m->header.size)); |
183 | if (ntohs (msg->size) < sizeof (struct GNUNET_SECRETSHARING_SecretReadyMessage)) | ||
184 | { | ||
185 | GNUNET_break (0); | ||
186 | s->secret_ready_cb (s->secret_ready_cls, NULL, NULL, 0, NULL); | ||
187 | GNUNET_SECRETSHARING_session_destroy (s); | ||
188 | return; | ||
189 | } | ||
190 | m = (const struct GNUNET_SECRETSHARING_SecretReadyMessage *) msg; | ||
191 | share_size = ntohs (m->header.size) - sizeof (struct GNUNET_SECRETSHARING_SecretReadyMessage); | 199 | share_size = ntohs (m->header.size) - sizeof (struct GNUNET_SECRETSHARING_SecretReadyMessage); |
192 | 200 | ||
193 | share = GNUNET_SECRETSHARING_share_read (&m[1], | 201 | share = GNUNET_SECRETSHARING_share_read (&m[1], |
194 | share_size, | 202 | share_size, |
195 | NULL); | 203 | NULL); |
204 | GNUNET_assert (NULL != share); // FIXME: this can fail! | ||
205 | // should have been checked in #check_secret_ready! | ||
206 | // FIXME: below we never check &m[1] is valid! | ||
207 | // FIXME: do we leak 'share' here? | ||
196 | s->secret_ready_cb (s->secret_ready_cls, | 208 | s->secret_ready_cb (s->secret_ready_cls, |
197 | share, /* FIXME */ | 209 | share, /* FIXME */ |
198 | &share->public_key, | 210 | &share->public_key, |
199 | share->num_peers, | 211 | share->num_peers, |
200 | (struct GNUNET_PeerIdentity *) &m[1]); | 212 | (const struct GNUNET_PeerIdentity *) &m[1]); |
213 | |||
201 | GNUNET_SECRETSHARING_session_destroy (s); | 214 | GNUNET_SECRETSHARING_session_destroy (s); |
202 | } | 215 | } |
203 | 216 | ||
@@ -246,16 +259,18 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c | |||
246 | GNUNET_SECRETSHARING_SecretReadyCallback cb, | 259 | GNUNET_SECRETSHARING_SecretReadyCallback cb, |
247 | void *cls) | 260 | void *cls) |
248 | { | 261 | { |
249 | struct GNUNET_SECRETSHARING_Session *s; | 262 | GNUNET_MQ_hd_var_size (secret_ready, |
263 | GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY, | ||
264 | struct GNUNET_SECRETSHARING_SecretReadyMessage); | ||
265 | struct GNUNET_SECRETSHARING_Session *s | ||
266 | = GNUNET_new (struct GNUNET_SECRETSHARING_Session); | ||
267 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | ||
268 | make_secret_ready_handler (s), | ||
269 | GNUNET_MQ_handler_end () | ||
270 | }; | ||
250 | struct GNUNET_MQ_Envelope *ev; | 271 | struct GNUNET_MQ_Envelope *ev; |
251 | struct GNUNET_SECRETSHARING_CreateMessage *msg; | 272 | struct GNUNET_SECRETSHARING_CreateMessage *msg; |
252 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { | ||
253 | { &handle_secret_ready, | ||
254 | GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY, 0}, | ||
255 | GNUNET_MQ_HANDLERS_END | ||
256 | }; | ||
257 | 273 | ||
258 | s = GNUNET_new (struct GNUNET_SECRETSHARING_Session); | ||
259 | s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); | 274 | s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); |
260 | if (NULL == s->client) | 275 | if (NULL == s->client) |
261 | { | 276 | { |
@@ -293,20 +308,16 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c | |||
293 | 308 | ||
294 | static void | 309 | static void |
295 | handle_decrypt_done (void *cls, | 310 | handle_decrypt_done (void *cls, |
296 | const struct GNUNET_MessageHeader *msg) | 311 | const struct GNUNET_SECRETSHARING_DecryptResponseMessage *m) |
297 | { | 312 | { |
298 | struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls; | 313 | struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls; |
299 | const struct GNUNET_SECRETSHARING_DecryptResponseMessage *m = | ||
300 | (const void *) msg; // FIXME: size check!? | ||
301 | const struct GNUNET_SECRETSHARING_Plaintext *plaintext; | 314 | const struct GNUNET_SECRETSHARING_Plaintext *plaintext; |
302 | 315 | ||
303 | if (m->success == 0) | 316 | if (m->success == 0) |
304 | plaintext = NULL; | 317 | plaintext = NULL; |
305 | else | 318 | else |
306 | plaintext = (void *) &m->plaintext; | 319 | plaintext = (void *) &m->plaintext; |
307 | |||
308 | dh->decrypt_cb (dh->decrypt_cls, plaintext); | 320 | dh->decrypt_cb (dh->decrypt_cls, plaintext); |
309 | |||
310 | GNUNET_SECRETSHARING_decrypt_cancel (dh); | 321 | GNUNET_SECRETSHARING_decrypt_cancel (dh); |
311 | } | 322 | } |
312 | 323 | ||
@@ -333,17 +344,19 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
333 | GNUNET_SECRETSHARING_DecryptCallback decrypt_cb, | 344 | GNUNET_SECRETSHARING_DecryptCallback decrypt_cb, |
334 | void *decrypt_cb_cls) | 345 | void *decrypt_cb_cls) |
335 | { | 346 | { |
336 | struct GNUNET_SECRETSHARING_DecryptionHandle *s; | 347 | GNUNET_MQ_hd_fixed_size (decrypt_done, |
348 | GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_DONE, | ||
349 | struct GNUNET_SECRETSHARING_DecryptResponseMessage); | ||
350 | struct GNUNET_SECRETSHARING_DecryptionHandle *s | ||
351 | = GNUNET_new (struct GNUNET_SECRETSHARING_DecryptionHandle); | ||
352 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | ||
353 | make_decrypt_done_handler (s), | ||
354 | GNUNET_MQ_handler_end () | ||
355 | }; | ||
337 | struct GNUNET_MQ_Envelope *ev; | 356 | struct GNUNET_MQ_Envelope *ev; |
338 | struct GNUNET_SECRETSHARING_DecryptRequestMessage *msg; | 357 | struct GNUNET_SECRETSHARING_DecryptRequestMessage *msg; |
339 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { | ||
340 | {handle_decrypt_done, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_DONE, 0}, | ||
341 | GNUNET_MQ_HANDLERS_END | ||
342 | }; | ||
343 | size_t share_size; | 358 | size_t share_size; |
344 | 359 | ||
345 | |||
346 | s = GNUNET_new (struct GNUNET_SECRETSHARING_DecryptionHandle); | ||
347 | s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); | 360 | s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); |
348 | s->decrypt_cb = decrypt_cb; | 361 | s->decrypt_cb = decrypt_cb; |
349 | s->decrypt_cls = decrypt_cb_cls; | 362 | s->decrypt_cls = decrypt_cb_cls; |
@@ -354,13 +367,19 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
354 | s); | 367 | s); |
355 | GNUNET_assert (NULL != s->mq); | 368 | GNUNET_assert (NULL != s->mq); |
356 | 369 | ||
357 | GNUNET_assert (GNUNET_OK == GNUNET_SECRETSHARING_share_write (share, NULL, 0, &share_size)); | 370 | GNUNET_assert (GNUNET_OK == |
371 | GNUNET_SECRETSHARING_share_write (share, NULL, 0, | ||
372 | &share_size)); | ||
358 | 373 | ||
359 | ev = GNUNET_MQ_msg_extra (msg, | 374 | ev = GNUNET_MQ_msg_extra (msg, |
360 | share_size, | 375 | share_size, |
361 | GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT); | 376 | GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT); |
362 | 377 | ||
363 | GNUNET_assert (GNUNET_OK == GNUNET_SECRETSHARING_share_write (share, &msg[1], share_size, NULL)); | 378 | GNUNET_assert (GNUNET_OK == |
379 | GNUNET_SECRETSHARING_share_write (share, | ||
380 | &msg[1], | ||
381 | share_size, | ||
382 | NULL)); | ||
364 | 383 | ||
365 | msg->start = GNUNET_TIME_absolute_hton (start); | 384 | msg->start = GNUNET_TIME_absolute_hton (start); |
366 | msg->deadline = GNUNET_TIME_absolute_hton (deadline); | 385 | msg->deadline = GNUNET_TIME_absolute_hton (deadline); |
@@ -368,7 +387,8 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
368 | 387 | ||
369 | GNUNET_MQ_send (s->mq, ev); | 388 | GNUNET_MQ_send (s->mq, ev); |
370 | 389 | ||
371 | LOG (GNUNET_ERROR_TYPE_DEBUG, "decrypt session created\n"); | 390 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
391 | "decrypt session created\n"); | ||
372 | return s; | 392 | return s; |
373 | } | 393 | } |
374 | 394 | ||
@@ -403,7 +423,9 @@ GNUNET_SECRETSHARING_plaintext_generate_i (struct GNUNET_SECRETSHARING_Plaintext | |||
403 | return GNUNET_SYSERR; | 423 | return GNUNET_SYSERR; |
404 | } | 424 | } |
405 | 425 | ||
406 | GNUNET_CRYPTO_mpi_print_unsigned (plaintext, sizeof (struct GNUNET_SECRETSHARING_Plaintext), x); | 426 | GNUNET_CRYPTO_mpi_print_unsigned (plaintext, |
427 | sizeof (struct GNUNET_SECRETSHARING_Plaintext), | ||
428 | x); | ||
407 | 429 | ||
408 | return GNUNET_OK; | 430 | return GNUNET_OK; |
409 | } | 431 | } |