diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-16 07:49:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-16 07:49:32 +0000 |
commit | b5a13bc0febdb8cf1a9d6dcca65b210882a21d95 (patch) | |
tree | a0c7184139790313e7958720531c638a7151090a /src | |
parent | 1cd462e473e674fa5ab78110ec4f4c26dce1fb73 (diff) | |
download | gnunet-b5a13bc0febdb8cf1a9d6dcca65b210882a21d95.tar.gz gnunet-b5a13bc0febdb8cf1a9d6dcca65b210882a21d95.zip |
-implement set handling
Diffstat (limited to 'src')
-rw-r--r-- | src/identity/gnunet-service-identity.c | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 25352170b..e1d4dff82 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -28,7 +28,6 @@ | |||
28 | * | 28 | * |
29 | * TODO: | 29 | * TODO: |
30 | * - disk operations | 30 | * - disk operations |
31 | * - default identity set/get handlers | ||
32 | */ | 31 | */ |
33 | #include "platform.h" | 32 | #include "platform.h" |
34 | #include "gnunet_util_lib.h" | 33 | #include "gnunet_util_lib.h" |
@@ -339,6 +338,26 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
339 | 338 | ||
340 | 339 | ||
341 | /** | 340 | /** |
341 | * Compare the given two private keys for equality. | ||
342 | * | ||
343 | * @param pk1 one private key | ||
344 | * @param pk2 another private key | ||
345 | * @return 0 if the keys are equal | ||
346 | */ | ||
347 | static int | ||
348 | key_cmp (const struct GNUNET_CRYPTO_EccPrivateKey *pk1, | ||
349 | const struct GNUNET_CRYPTO_EccPrivateKey *pk2) | ||
350 | { | ||
351 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p1; | ||
352 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p2; | ||
353 | |||
354 | GNUNET_CRYPTO_ecc_key_get_public (pk1, &p1); | ||
355 | GNUNET_CRYPTO_ecc_key_get_public (pk2, &p2); | ||
356 | return memcmp (&p1, &p2, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)); | ||
357 | } | ||
358 | |||
359 | |||
360 | /** | ||
342 | * Handler for SET_DEFAULT message from client, updates | 361 | * Handler for SET_DEFAULT message from client, updates |
343 | * default identity for some service. | 362 | * default identity for some service. |
344 | * | 363 | * |
@@ -350,12 +369,60 @@ static void | |||
350 | handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client, | 369 | handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client, |
351 | const struct GNUNET_MessageHeader *message) | 370 | const struct GNUNET_MessageHeader *message) |
352 | { | 371 | { |
372 | const struct GNUNET_IDENTITY_SetDefaultMessage *sdm; | ||
373 | uint16_t size; | ||
374 | uint16_t name_len; | ||
375 | uint16_t pk_len; | ||
376 | struct Ego *ego; | ||
377 | const char *str; | ||
378 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | ||
379 | |||
353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
354 | "Received SET_DEFAULT message from client\n"); | 381 | "Received SET_DEFAULT message from client\n"); |
355 | // setup_estimate_message (&em); | 382 | size = ntohs (message->size); |
356 | // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); | 383 | if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) |
357 | GNUNET_break (0); // not implemented! | 384 | { |
358 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 385 | GNUNET_break (0); |
386 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
387 | return; | ||
388 | } | ||
389 | sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message; | ||
390 | name_len = ntohs (sdm->name_len); | ||
391 | pk_len = ntohs (sdm->pk_len); | ||
392 | str = (const char *) &sdm[1]; | ||
393 | if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size) || | ||
394 | (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) ) | ||
395 | { | ||
396 | GNUNET_break (0); | ||
397 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
398 | return; | ||
399 | } | ||
400 | str = &str[pk_len]; | ||
401 | if ('\0' != str[name_len - 1]) | ||
402 | { | ||
403 | GNUNET_break (0); | ||
404 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
405 | return; | ||
406 | } | ||
407 | for (ego = ego_head; NULL != ego; ego = ego->next) | ||
408 | { | ||
409 | if (0 == key_cmp (ego->pk, | ||
410 | pk)) | ||
411 | { | ||
412 | GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, | ||
413 | str, | ||
414 | "DEFAULT_IDENTIFIER", | ||
415 | ego->identifier); | ||
416 | /* fixme: write configuration to disk... */ | ||
417 | send_result_code (client, 0, NULL); | ||
418 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
419 | GNUNET_CRYPTO_ecc_key_free (pk); | ||
420 | return; | ||
421 | } | ||
422 | } | ||
423 | send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); | ||
424 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
425 | GNUNET_CRYPTO_ecc_key_free (pk); | ||
359 | } | 426 | } |
360 | 427 | ||
361 | 428 | ||