aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-10-29 18:06:26 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-10-29 18:06:26 +0900
commit0f2da4636e108c70697c589d9e38781f2bafefba (patch)
tree0e831befd71d4323596cdae55e8431df7720c531
parent4e2259f14be320c8e2fe2a672a473e09677269c4 (diff)
downloadgnunet-0f2da4636e108c70697c589d9e38781f2bafefba.tar.gz
gnunet-0f2da4636e108c70697c589d9e38781f2bafefba.zip
IDENTITY
This commit is a major rework of the unclean GNUNET_IDENTITY_*Key structures and its use in serialized objects (e.g. RPC messages). The structures are now no longer to be used directly but instead through their serialization helper functions whenever needed.
-rw-r--r--src/conversation/conversation.h33
-rw-r--r--src/conversation/conversation_api.c38
-rw-r--r--src/conversation/conversation_api_call.c12
-rw-r--r--src/conversation/gnunet-service-conversation.c105
-rw-r--r--src/conversation/test_conversation_api.c13
-rw-r--r--src/conversation/test_conversation_api_reject.c13
-rw-r--r--src/conversation/test_conversation_api_twocalls.c13
-rw-r--r--src/gns/plugin_gnsrecord_gns.c2
-rw-r--r--src/gnsrecord/gnsrecord_misc.c2
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c12
-rw-r--r--src/identity/Makefile.am1
-rw-r--r--src/identity/gnunet-service-identity.c47
-rw-r--r--src/identity/identity.h15
-rw-r--r--src/identity/identity_api.c151
-rw-r--r--src/identity/identity_api_lookup.c23
-rw-r--r--src/identity/identity_api_suffix_lookup.c22
-rwxr-xr-xsrc/identity/test_identity_messages.sh2
-rw-r--r--src/include/gnunet_identity_service.h82
-rw-r--r--src/include/gnunet_reclaim_service.h37
-rw-r--r--src/namestore/Makefile.am1
-rw-r--r--src/namestore/gnunet-namestore.c15
-rw-r--r--src/namestore/gnunet-service-namestore.c241
-rw-r--r--src/namestore/namestore.h65
-rw-r--r--src/namestore/namestore_api.c137
-rw-r--r--src/namestore/namestore_api_monitor.c47
-rw-r--r--src/reclaim/Makefile.am1
-rw-r--r--src/reclaim/gnunet-service-reclaim.c410
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c68
-rw-r--r--src/reclaim/reclaim.h127
-rw-r--r--src/reclaim/reclaim_api.c432
-rw-r--r--src/reclaim/test_did_helper.c5
-rw-r--r--src/reclaim/test_reclaim.conf6
-rwxr-xr-xsrc/reclaim/test_reclaim_attribute.sh2
-rwxr-xr-xsrc/reclaim/test_reclaim_consume.sh6
-rwxr-xr-xsrc/reclaim/test_reclaim_issue.sh4
-rw-r--r--src/revocation/gnunet-revocation-tvg.c4
-rw-r--r--src/revocation/gnunet-revocation.c2
-rw-r--r--src/revocation/gnunet-service-revocation.c4
-rw-r--r--src/revocation/plugin_block_revocation.c50
-rw-r--r--src/revocation/revocation_api.c27
40 files changed, 1703 insertions, 574 deletions
diff --git a/src/conversation/conversation.h b/src/conversation/conversation.h
index d244f5163..ee4ca372c 100644
--- a/src/conversation/conversation.h
+++ b/src/conversation/conversation.h
@@ -105,9 +105,13 @@ struct ClientPhoneRingMessage
105 uint32_t cid GNUNET_PACKED; 105 uint32_t cid GNUNET_PACKED;
106 106
107 /** 107 /**
108 * Who is calling us? 108 * The identity key length
109 */
110 uint32_t key_len;
111
112 /**
113 * followed by who is calling us?, a public key
109 */ 114 */
110 struct GNUNET_IDENTITY_PublicKey caller_id;
111}; 115};
112 116
113 117
@@ -230,9 +234,13 @@ struct ClientCallMessage
230 struct GNUNET_HashCode line_port; 234 struct GNUNET_HashCode line_port;
231 235
232 /** 236 /**
233 * Identity of the caller. 237 * The identity key length
238 */
239 uint32_t key_len;
240
241 /**
242 * followed by the identity of the caller.
234 */ 243 */
235 struct GNUNET_IDENTITY_PrivateKey caller_id;
236}; 244};
237 245
238 246
@@ -301,19 +309,24 @@ struct CadetPhoneRingMessage
301 uint32_t reserved GNUNET_PACKED; 309 uint32_t reserved GNUNET_PACKED;
302 310
303 /** 311 /**
304 * Who is calling us? (also who is signing). 312 * When does the signature expire?
305 */ 313 */
306 struct GNUNET_IDENTITY_PublicKey caller_id; 314 struct GNUNET_TIME_AbsoluteNBO expiration_time;
307 315
308 /** 316 /**
309 * When does the signature expire? 317 * The length of the key
310 */ 318 */
311 struct GNUNET_TIME_AbsoluteNBO expiration_time; 319 uint32_t key_len;
320
321 /**
322 * The length of the signature
323 */
324 uint32_t sig_len;
312 325
313 /** 326 /**
314 * Signature over a `struct CadetPhoneRingInfoPS` 327 * Followed by the public key of who is calling us? (also who is signing).
328 * followed by the signature over a `struct CadetPhoneRingInfoPS`
315 */ 329 */
316 struct GNUNET_IDENTITY_Signature signature;
317}; 330};
318 331
319 332
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c
index 2ede33586..9c4c520be 100644
--- a/src/conversation/conversation_api.c
+++ b/src/conversation/conversation_api.c
@@ -238,7 +238,19 @@ transmit_phone_audio (void *cls,
238 e); 238 e);
239} 239}
240 240
241 241/**
242 * We received a `struct ClientPhoneRingMessage`
243 *
244 * @param cls the `struct GNUNET_CONVERSATION_Phone`
245 * @param ring the message
246 */
247static enum GNUNET_GenericReturnValue
248check_phone_ring (void *cls,
249 const struct ClientPhoneRingMessage *ring)
250{
251 //FIXME
252 return GNUNET_OK;
253}
242/** 254/**
243 * We received a `struct ClientPhoneRingMessage` 255 * We received a `struct ClientPhoneRingMessage`
244 * 256 *
@@ -251,7 +263,11 @@ handle_phone_ring (void *cls,
251{ 263{
252 struct GNUNET_CONVERSATION_Phone *phone = cls; 264 struct GNUNET_CONVERSATION_Phone *phone = cls;
253 struct GNUNET_CONVERSATION_Caller *caller; 265 struct GNUNET_CONVERSATION_Caller *caller;
266 struct GNUNET_IDENTITY_PublicKey caller_id;
267 size_t key_len;
268 size_t read;
254 269
270 key_len = ntohl (ring->key_len);
255 switch (phone->state) 271 switch (phone->state)
256 { 272 {
257 case PS_REGISTER: 273 case PS_REGISTER:
@@ -259,12 +275,22 @@ handle_phone_ring (void *cls,
259 break; 275 break;
260 276
261 case PS_READY: 277 case PS_READY:
278 if ((GNUNET_SYSERR ==
279 GNUNET_IDENTITY_read_public_key_from_buffer (&ring[1],
280 key_len,
281 &caller_id,
282 &read)) ||
283 (read != key_len))
284 {
285 GNUNET_break (0);
286 break;
287 }
262 caller = GNUNET_new (struct GNUNET_CONVERSATION_Caller); 288 caller = GNUNET_new (struct GNUNET_CONVERSATION_Caller);
263 caller->phone = phone; 289 caller->phone = phone;
264 GNUNET_CONTAINER_DLL_insert (phone->caller_head, 290 GNUNET_CONTAINER_DLL_insert (phone->caller_head,
265 phone->caller_tail, 291 phone->caller_tail,
266 caller); 292 caller);
267 caller->caller_id = ring->caller_id; 293 caller->caller_id = caller_id;
268 caller->cid = ring->cid; 294 caller->cid = ring->cid;
269 caller->state = CS_RINGING; 295 caller->state = CS_RINGING;
270 phone->event_handler (phone->event_handler_cls, 296 phone->event_handler (phone->event_handler_cls,
@@ -562,10 +588,10 @@ static void
562reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) 588reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
563{ 589{
564 struct GNUNET_MQ_MessageHandler handlers[] = { 590 struct GNUNET_MQ_MessageHandler handlers[] = {
565 GNUNET_MQ_hd_fixed_size (phone_ring, 591 GNUNET_MQ_hd_var_size (phone_ring,
566 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, 592 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING,
567 struct ClientPhoneRingMessage, 593 struct ClientPhoneRingMessage,
568 phone), 594 phone),
569 GNUNET_MQ_hd_fixed_size (phone_hangup, 595 GNUNET_MQ_hd_fixed_size (phone_hangup,
570 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, 596 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
571 struct ClientPhoneHangupMessage, 597 struct ClientPhoneHangupMessage,
diff --git a/src/conversation/conversation_api_call.c b/src/conversation/conversation_api_call.c
index 909b603ac..129192bf0 100644
--- a/src/conversation/conversation_api_call.c
+++ b/src/conversation/conversation_api_call.c
@@ -455,6 +455,8 @@ handle_gns_response (void *cls,
455 struct GNUNET_CONVERSATION_Call *call = cls; 455 struct GNUNET_CONVERSATION_Call *call = cls;
456 struct GNUNET_MQ_Envelope *e; 456 struct GNUNET_MQ_Envelope *e;
457 struct ClientCallMessage *ccm; 457 struct ClientCallMessage *ccm;
458 const struct GNUNET_IDENTITY_PrivateKey *caller_id;
459 size_t key_len;
458 460
459 (void) was_gns; 461 (void) was_gns;
460 GNUNET_break (NULL != call->gns_lookup); 462 GNUNET_break (NULL != call->gns_lookup);
@@ -472,11 +474,15 @@ handle_gns_response (void *cls,
472 GNUNET_memcpy (&call->phone_record, 474 GNUNET_memcpy (&call->phone_record,
473 rd[i].data, 475 rd[i].data,
474 rd[i].data_size); 476 rd[i].data_size);
475 e = GNUNET_MQ_msg (ccm, 477 caller_id = GNUNET_IDENTITY_ego_get_private_key (call->caller_id);
476 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL); 478 key_len = GNUNET_IDENTITY_private_key_get_length (caller_id);
479 e = GNUNET_MQ_msg_extra (ccm, key_len,
480 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL);
477 ccm->line_port = call->phone_record.line_port; 481 ccm->line_port = call->phone_record.line_port;
478 ccm->target = call->phone_record.peer; 482 ccm->target = call->phone_record.peer;
479 ccm->caller_id = *GNUNET_IDENTITY_ego_get_private_key (call->caller_id); 483 GNUNET_IDENTITY_write_private_key_to_buffer (caller_id,
484 &ccm[1], key_len);
485 ccm->key_len = htonl (key_len);
480 GNUNET_MQ_send (call->mq, 486 GNUNET_MQ_send (call->mq,
481 e); 487 e);
482 call->state = CS_RINGING; 488 call->state = CS_RINGING;
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c
index a69c95a80..a551bed1a 100644
--- a/src/conversation/gnunet-service-conversation.c
+++ b/src/conversation/gnunet-service-conversation.c
@@ -729,6 +729,18 @@ handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg)
729 GNUNET_SERVICE_client_continue (line->client); 729 GNUNET_SERVICE_client_continue (line->client);
730} 730}
731 731
732/**
733 * Function to handle a ring message incoming over cadet
734 *
735 * @param cls closure, NULL
736 * @param msg the incoming message
737 */
738static enum GNUNET_GenericReturnValue
739check_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg)
740{
741 //FIXME
742 return GNUNET_OK;
743}
732 744
733/** 745/**
734 * Function to handle a ring message incoming over cadet 746 * Function to handle a ring message incoming over cadet
@@ -744,19 +756,40 @@ handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg)
744 struct GNUNET_MQ_Envelope *env; 756 struct GNUNET_MQ_Envelope *env;
745 struct ClientPhoneRingMessage *cring; 757 struct ClientPhoneRingMessage *cring;
746 struct CadetPhoneRingInfoPS rs; 758 struct CadetPhoneRingInfoPS rs;
759 struct GNUNET_IDENTITY_PublicKey identity;
760 struct GNUNET_IDENTITY_Signature sig;
761 size_t key_len;
762 size_t sig_len;
763 size_t read;
747 764
748 rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); 765 rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING);
749 rs.purpose.size = htonl (sizeof(struct CadetPhoneRingInfoPS)); 766 rs.purpose.size = htonl (sizeof(struct CadetPhoneRingInfoPS));
750 rs.line_port = line->line_port; 767 rs.line_port = line->line_port;
751 rs.target_peer = my_identity; 768 rs.target_peer = my_identity;
752 rs.expiration_time = msg->expiration_time; 769 rs.expiration_time = msg->expiration_time;
753 770 key_len = ntohl (msg->key_len);
771 sig_len = ntohl (msg->sig_len);
772
773 if ((GNUNET_SYSERR ==
774 GNUNET_IDENTITY_read_public_key_from_buffer (&msg[1],
775 key_len,
776 &identity,
777 &read)) ||
778 (read != key_len))
779 {
780 GNUNET_break_op (0);
781 destroy_line_cadet_channels (ch);
782 return;
783 }
784 GNUNET_IDENTITY_read_signature_from_buffer (&sig,
785 (char*) &msg[1] + read,
786 sig_len);
754 if (GNUNET_OK != 787 if (GNUNET_OK !=
755 GNUNET_IDENTITY_signature_verify ( 788 GNUNET_IDENTITY_signature_verify (
756 GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, 789 GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING,
757 &rs, 790 &rs,
758 &msg->signature, 791 &sig,
759 &msg->caller_id)) 792 &identity))
760 { 793 {
761 GNUNET_break_op (0); 794 GNUNET_break_op (0);
762 destroy_line_cadet_channels (ch); 795 destroy_line_cadet_channels (ch);
@@ -782,9 +815,12 @@ handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg)
782 } 815 }
783 GNUNET_CADET_receive_done (ch->channel); 816 GNUNET_CADET_receive_done (ch->channel);
784 ch->status = CS_CALLEE_RINGING; 817 ch->status = CS_CALLEE_RINGING;
785 env = GNUNET_MQ_msg (cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); 818 env = GNUNET_MQ_msg_extra (cring,
819 key_len,
820 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
786 cring->cid = ch->cid; 821 cring->cid = ch->cid;
787 cring->caller_id = msg->caller_id; 822 memcpy (&cring[1], &msg[1], key_len);
823 cring->key_len = msg->key_len;
788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789 "Sending RING message to client. CID is %u\n", 825 "Sending RING message to client. CID is %u\n",
790 (unsigned int) ch->cid); 826 (unsigned int) ch->cid);
@@ -1080,6 +1116,18 @@ inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel)
1080 clean_up_channel (ch); 1116 clean_up_channel (ch);
1081} 1117}
1082 1118
1119/**
1120 * Function to handle call request from the client
1121 *
1122 * @param cls the `struct Line` the message is about
1123 * @param msg the message from the client
1124 */
1125static enum GNUNET_GenericReturnValue
1126check_client_call_message (void *cls, const struct ClientCallMessage *msg)
1127{
1128 // FIXME
1129 return GNUNET_OK;
1130}
1083 1131
1084/** 1132/**
1085 * Function to handle call request from the client 1133 * Function to handle call request from the client
@@ -1117,6 +1165,14 @@ handle_client_call_message (void *cls, const struct ClientCallMessage *msg)
1117 struct GNUNET_MQ_Envelope *e; 1165 struct GNUNET_MQ_Envelope *e;
1118 struct CadetPhoneRingMessage *ring; 1166 struct CadetPhoneRingMessage *ring;
1119 struct CadetPhoneRingInfoPS rs; 1167 struct CadetPhoneRingInfoPS rs;
1168 struct GNUNET_IDENTITY_PrivateKey caller_id;
1169 struct GNUNET_IDENTITY_PublicKey caller_id_pub;
1170 struct GNUNET_IDENTITY_Signature sig;
1171 ssize_t written;
1172 size_t key_len;
1173 size_t pkey_len;
1174 size_t sig_len;
1175 size_t read;
1120 1176
1121 line->line_port = msg->line_port; 1177 line->line_port = msg->line_port;
1122 rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); 1178 rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING);
@@ -1136,10 +1192,27 @@ handle_client_call_message (void *cls, const struct ClientCallMessage *msg)
1136 &inbound_end, 1192 &inbound_end,
1137 cadet_handlers); 1193 cadet_handlers);
1138 ch->mq = GNUNET_CADET_get_mq (ch->channel); 1194 ch->mq = GNUNET_CADET_get_mq (ch->channel);
1139 e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); 1195 key_len = ntohl (msg->key_len);
1140 GNUNET_IDENTITY_key_get_public (&msg->caller_id, &ring->caller_id); 1196 GNUNET_IDENTITY_read_private_key_from_buffer (&msg[1],
1197 key_len,
1198 &caller_id,
1199 &read);
1200 GNUNET_assert (read == key_len);
1201 GNUNET_IDENTITY_sign (&caller_id, &rs, &sig);
1202 sig_len = GNUNET_IDENTITY_signature_get_length (&sig);
1203 GNUNET_IDENTITY_key_get_public (&caller_id, &caller_id_pub);
1204 pkey_len = GNUNET_IDENTITY_public_key_get_length (&caller_id_pub);
1205 e = GNUNET_MQ_msg_extra (ring, pkey_len + sig_len,
1206 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING);
1207 written = GNUNET_IDENTITY_write_public_key_to_buffer (&caller_id_pub,
1208 &ring[1],
1209 pkey_len);
1141 ring->expiration_time = rs.expiration_time; 1210 ring->expiration_time = rs.expiration_time;
1142 GNUNET_IDENTITY_sign (&msg->caller_id, &rs, &ring->signature); 1211 ring->key_len = htonl (pkey_len);
1212 ring->sig_len = htonl (sig_len);
1213 GNUNET_IDENTITY_write_signature_to_buffer (&sig,
1214 (char *) &ring[1] + written,
1215 sig_len);
1143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); 1216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n");
1144 GNUNET_MQ_send (ch->mq, e); 1217 GNUNET_MQ_send (ch->mq, e);
1145 GNUNET_SERVICE_client_continue (line->client); 1218 GNUNET_SERVICE_client_continue (line->client);
@@ -1246,10 +1319,10 @@ handle_client_register_message (void *cls,
1246{ 1319{
1247 struct Line *line = cls; 1320 struct Line *line = cls;
1248 struct GNUNET_MQ_MessageHandler cadet_handlers[] = 1321 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1249 { GNUNET_MQ_hd_fixed_size (cadet_ring_message, 1322 { GNUNET_MQ_hd_var_size (cadet_ring_message,
1250 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, 1323 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING,
1251 struct CadetPhoneRingMessage, 1324 struct CadetPhoneRingMessage,
1252 NULL), 1325 NULL),
1253 GNUNET_MQ_hd_fixed_size (cadet_hangup_message, 1326 GNUNET_MQ_hd_fixed_size (cadet_hangup_message,
1254 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, 1327 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP,
1255 struct CadetPhoneHangupMessage, 1328 struct CadetPhoneHangupMessage,
@@ -1367,10 +1440,10 @@ GNUNET_SERVICE_MAIN (
1367 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, 1440 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
1368 struct ClientPhoneHangupMessage, 1441 struct ClientPhoneHangupMessage,
1369 NULL), 1442 NULL),
1370 GNUNET_MQ_hd_fixed_size (client_call_message, 1443 GNUNET_MQ_hd_var_size (client_call_message,
1371 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, 1444 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL,
1372 struct ClientCallMessage, 1445 struct ClientCallMessage,
1373 NULL), 1446 NULL),
1374 GNUNET_MQ_hd_var_size (client_audio_message, 1447 GNUNET_MQ_hd_var_size (client_audio_message,
1375 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, 1448 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
1376 struct ClientAudioMessage, 1449 struct ClientAudioMessage,
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c
index 41ef75821..22e9b1dd9 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -386,21 +386,20 @@ call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
386static void 386static void
387caller_ego_create_cont (void *cls, 387caller_ego_create_cont (void *cls,
388 const struct GNUNET_IDENTITY_PrivateKey *pk, 388 const struct GNUNET_IDENTITY_PrivateKey *pk,
389 const char *emsg) 389 enum GNUNET_ErrorCode ec)
390{ 390{
391 (void) cls; 391 (void) cls;
392 op = NULL; 392 op = NULL;
393 GNUNET_assert (NULL == emsg); 393 GNUNET_assert (GNUNET_EC_NONE == ec);
394} 394}
395 395
396 396
397static void 397static void
398namestore_put_cont (void *cls, int32_t success, const char *emsg) 398namestore_put_cont (void *cls, enum GNUNET_ErrorCode ec)
399{ 399{
400 (void) cls; 400 (void) cls;
401 qe = NULL; 401 qe = NULL;
402 GNUNET_assert (GNUNET_YES == success); 402 GNUNET_assert (GNUNET_EC_NONE == ec);
403 GNUNET_assert (NULL == emsg);
404 GNUNET_assert (NULL == op); 403 GNUNET_assert (NULL == op);
405 op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, 404 op = GNUNET_IDENTITY_create (id, "caller-ego", NULL,
406 GNUNET_IDENTITY_TYPE_ECDSA, 405 GNUNET_IDENTITY_TYPE_ECDSA,
@@ -468,11 +467,11 @@ identity_cb (void *cls,
468static void 467static void
469phone_ego_create_cont (void *cls, 468phone_ego_create_cont (void *cls,
470 const struct GNUNET_IDENTITY_PrivateKey *pk, 469 const struct GNUNET_IDENTITY_PrivateKey *pk,
471 const char *emsg) 470 enum GNUNET_ErrorCode ec)
472{ 471{
473 (void) cls; 472 (void) cls;
474 op = NULL; 473 op = NULL;
475 GNUNET_assert (NULL == emsg); 474 GNUNET_assert (GNUNET_EC_NONE == ec);
476} 475}
477 476
478 477
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c
index 15728123b..a7aab069f 100644
--- a/src/conversation/test_conversation_api_reject.c
+++ b/src/conversation/test_conversation_api_reject.c
@@ -239,21 +239,20 @@ call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
239static void 239static void
240caller_ego_create_cont (void *cls, 240caller_ego_create_cont (void *cls,
241 const struct GNUNET_IDENTITY_PrivateKey *pk, 241 const struct GNUNET_IDENTITY_PrivateKey *pk,
242 const char *emsg) 242 enum GNUNET_ErrorCode ec)
243{ 243{
244 (void) cls; 244 (void) cls;
245 op = NULL; 245 op = NULL;
246 GNUNET_assert (NULL == emsg); 246 GNUNET_assert (GNUNET_EC_NONE == ec);
247} 247}
248 248
249 249
250static void 250static void
251namestore_put_cont (void *cls, int32_t success, const char *emsg) 251namestore_put_cont (void *cls, enum GNUNET_ErrorCode ec)
252{ 252{
253 (void) cls; 253 (void) cls;
254 qe = NULL; 254 qe = NULL;
255 GNUNET_assert (GNUNET_YES == success); 255 GNUNET_assert (GNUNET_EC_NONE == ec);
256 GNUNET_assert (NULL == emsg);
257 GNUNET_assert (NULL == op); 256 GNUNET_assert (NULL == op);
258 op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, 257 op = GNUNET_IDENTITY_create (id, "caller-ego", NULL,
259 GNUNET_IDENTITY_TYPE_ECDSA, 258 GNUNET_IDENTITY_TYPE_ECDSA,
@@ -321,11 +320,11 @@ identity_cb (void *cls,
321static void 320static void
322phone_ego_create_cont (void *cls, 321phone_ego_create_cont (void *cls,
323 const struct GNUNET_IDENTITY_PrivateKey *pk, 322 const struct GNUNET_IDENTITY_PrivateKey *pk,
324 const char *emsg) 323 enum GNUNET_ErrorCode ec)
325{ 324{
326 (void) cls; 325 (void) cls;
327 op = NULL; 326 op = NULL;
328 GNUNET_assert (NULL == emsg); 327 GNUNET_assert (GNUNET_EC_NONE == ec);
329} 328}
330 329
331 330
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c
index 9abf91d0b..1bd2b4e22 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -508,21 +508,20 @@ call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
508static void 508static void
509caller_ego_create_cont (void *cls, 509caller_ego_create_cont (void *cls,
510 const struct GNUNET_IDENTITY_PrivateKey *pk, 510 const struct GNUNET_IDENTITY_PrivateKey *pk,
511 const char *emsg) 511 enum GNUNET_ErrorCode ec)
512{ 512{
513 (void) cls; 513 (void) cls;
514 op = NULL; 514 op = NULL;
515 GNUNET_assert (NULL == emsg); 515 GNUNET_assert (GNUNET_EC_NONE == ec);
516} 516}
517 517
518 518
519static void 519static void
520namestore_put_cont (void *cls, int32_t success, const char *emsg) 520namestore_put_cont (void *cls, enum GNUNET_ErrorCode ec)
521{ 521{
522 (void) cls; 522 (void) cls;
523 qe = NULL; 523 qe = NULL;
524 GNUNET_assert (GNUNET_YES == success); 524 GNUNET_assert (GNUNET_EC_NONE == ec);
525 GNUNET_assert (NULL == emsg);
526 GNUNET_assert (NULL == op); 525 GNUNET_assert (NULL == op);
527 op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, 526 op = GNUNET_IDENTITY_create (id, "caller-ego", NULL,
528 GNUNET_IDENTITY_TYPE_ECDSA, 527 GNUNET_IDENTITY_TYPE_ECDSA,
@@ -597,11 +596,11 @@ identity_cb (void *cls,
597static void 596static void
598phone_ego_create_cont (void *cls, 597phone_ego_create_cont (void *cls,
599 const struct GNUNET_IDENTITY_PrivateKey *pk, 598 const struct GNUNET_IDENTITY_PrivateKey *pk,
600 const char *emsg) 599 enum GNUNET_ErrorCode ec)
601{ 600{
602 (void) cls; 601 (void) cls;
603 op = NULL; 602 op = NULL;
604 GNUNET_assert (NULL == emsg); 603 GNUNET_assert (GNUNET_EC_NONE == ec);
605} 604}
606 605
607 606
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 0ce782a43..296957f19 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -178,7 +178,7 @@ gns_string_to_value (void *cls,
178 s); 178 s);
179 return GNUNET_SYSERR; 179 return GNUNET_SYSERR;
180 } 180 }
181 *data_size = GNUNET_IDENTITY_key_get_length (&pk); 181 *data_size = GNUNET_IDENTITY_public_key_get_length (&pk);
182 if (GNUNET_OK != 182 if (GNUNET_OK !=
183 GNUNET_GNSRECORD_data_from_identity (&pk, 183 GNUNET_GNSRECORD_data_from_identity (&pk,
184 (char **) data, 184 (char **) data,
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 742eaf186..97ca7b135 100644
--- a/src/gnsrecord/gnsrecord_misc.c
+++ b/src/gnsrecord/gnsrecord_misc.c
@@ -304,7 +304,7 @@ GNUNET_GNSRECORD_data_from_identity (const struct
304{ 304{
305 char *tmp; 305 char *tmp;
306 *type = ntohl (key->type); 306 *type = ntohl (key->type);
307 *data_size = GNUNET_IDENTITY_key_get_length (key) - sizeof (key->type); 307 *data_size = GNUNET_IDENTITY_public_key_get_length (key) - sizeof (key->type);
308 if (0 == *data_size) 308 if (0 == *data_size)
309 return GNUNET_SYSERR; 309 return GNUNET_SYSERR;
310 tmp = GNUNET_malloc (*data_size); 310 tmp = GNUNET_malloc (*data_size);
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index 4d5eb73b3..91abe1954 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -154,10 +154,10 @@ run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
154 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1); 154 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1);
155 printf ("\n"); 155 printf ("\n");
156 printf ("Zone identifier (ztype|zkey):\n"); 156 printf ("Zone identifier (ztype|zkey):\n");
157 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub)); 157 GNUNET_assert (0 < GNUNET_IDENTITY_public_key_get_length (&id_pub));
158 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 158 print_bytes (&id_pub, GNUNET_IDENTITY_public_key_get_length (&id_pub), 8);
159 GNUNET_STRINGS_data_to_string (&id_pub, 159 GNUNET_STRINGS_data_to_string (&id_pub,
160 GNUNET_IDENTITY_key_get_length (&id_pub), 160 GNUNET_IDENTITY_public_key_get_length (&id_pub),
161 ztld, 161 ztld,
162 sizeof (ztld)); 162 sizeof (ztld));
163 printf ("\n"); 163 printf ("\n");
@@ -280,10 +280,10 @@ run_edkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char*label)
280 GNUNET_CRYPTO_EddsaPrivateKey), 8); 280 GNUNET_CRYPTO_EddsaPrivateKey), 8);
281 printf ("\n"); 281 printf ("\n");
282 printf ("Zone identifier (ztype|zkey):\n"); 282 printf ("Zone identifier (ztype|zkey):\n");
283 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub)); 283 GNUNET_assert (0 < GNUNET_IDENTITY_public_key_get_length (&id_pub));
284 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 284 print_bytes (&id_pub, GNUNET_IDENTITY_public_key_get_length (&id_pub), 8);
285 GNUNET_STRINGS_data_to_string (&id_pub, 285 GNUNET_STRINGS_data_to_string (&id_pub,
286 GNUNET_IDENTITY_key_get_length (&id_pub), 286 GNUNET_IDENTITY_public_key_get_length (&id_pub),
287 ztld, 287 ztld,
288 sizeof (ztld)); 288 sizeof (ztld));
289 printf ("\n"); 289 printf ("\n");
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am
index 12d3906a8..be6bbf822 100644
--- a/src/identity/Makefile.am
+++ b/src/identity/Makefile.am
@@ -54,6 +54,7 @@ libexec_PROGRAMS = \
54gnunet_service_identity_SOURCES = \ 54gnunet_service_identity_SOURCES = \
55 gnunet-service-identity.c 55 gnunet-service-identity.c
56gnunet_service_identity_LDADD = \ 56gnunet_service_identity_LDADD = \
57 libgnunetidentity.la \
57 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 58 $(top_builddir)/src/statistics/libgnunetstatistics.la \
58 $(top_builddir)/src/util/libgnunetutil.la \ 59 $(top_builddir)/src/util/libgnunetutil.la \
59 $(GN_LIBINTL) 60 $(GN_LIBINTL)
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 5e3f7bb35..f1156e0b6 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -236,13 +236,18 @@ create_update_message (struct Ego *ego)
236 struct UpdateMessage *um; 236 struct UpdateMessage *um;
237 struct GNUNET_MQ_Envelope *env; 237 struct GNUNET_MQ_Envelope *env;
238 size_t name_len; 238 size_t name_len;
239 ssize_t key_len;
239 240
241 key_len = GNUNET_IDENTITY_private_key_get_length (&ego->pk);
240 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 242 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
241 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 243 env = GNUNET_MQ_msg_extra (um, name_len + key_len,
244 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
242 um->name_len = htons (name_len); 245 um->name_len = htons (name_len);
243 um->end_of_list = htons (GNUNET_NO); 246 um->end_of_list = htons (GNUNET_NO);
244 um->private_key = ego->pk;
245 GNUNET_memcpy (&um[1], ego->identifier, name_len); 247 GNUNET_memcpy (&um[1], ego->identifier, name_len);
248 GNUNET_IDENTITY_write_private_key_to_buffer (&ego->pk,
249 ((char*) &um[1]) + name_len,
250 key_len);
246 return env; 251 return env;
247} 252}
248 253
@@ -412,15 +417,19 @@ notify_listeners (struct Ego *ego)
412{ 417{
413 struct UpdateMessage *um; 418 struct UpdateMessage *um;
414 size_t name_len; 419 size_t name_len;
420 ssize_t key_len;
415 421
416 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 422 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
417 um = GNUNET_malloc (sizeof(struct UpdateMessage) + name_len); 423 key_len = GNUNET_IDENTITY_private_key_get_length (&ego->pk);
424 um = GNUNET_malloc (sizeof(struct UpdateMessage) + name_len + key_len);
418 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 425 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
419 um->header.size = htons (sizeof(struct UpdateMessage) + name_len); 426 um->header.size = htons (sizeof(struct UpdateMessage) + name_len + key_len);
420 um->name_len = htons (name_len); 427 um->name_len = htons (name_len);
421 um->end_of_list = htons (GNUNET_NO); 428 um->end_of_list = htons (GNUNET_NO);
422 um->private_key = ego->pk;
423 GNUNET_memcpy (&um[1], ego->identifier, name_len); 429 GNUNET_memcpy (&um[1], ego->identifier, name_len);
430 GNUNET_IDENTITY_write_private_key_to_buffer (&ego->pk,
431 ((char*) &um[1]) + name_len,
432 key_len);
424 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO); 433 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
425 GNUNET_free (um); 434 GNUNET_free (um);
426} 435}
@@ -439,6 +448,7 @@ check_create_message (void *cls,
439{ 448{
440 uint16_t size; 449 uint16_t size;
441 uint16_t name_len; 450 uint16_t name_len;
451 size_t key_len;
442 const char *str; 452 const char *str;
443 453
444 size = ntohs (msg->header.size); 454 size = ntohs (msg->header.size);
@@ -448,13 +458,14 @@ check_create_message (void *cls,
448 return GNUNET_SYSERR; 458 return GNUNET_SYSERR;
449 } 459 }
450 name_len = ntohs (msg->name_len); 460 name_len = ntohs (msg->name_len);
461 key_len = ntohl (msg->key_len);
451 GNUNET_break (0 == ntohs (msg->reserved)); 462 GNUNET_break (0 == ntohs (msg->reserved));
452 if (name_len + sizeof(struct CreateRequestMessage) != size) 463 if (name_len + key_len + sizeof(struct CreateRequestMessage) != size)
453 { 464 {
454 GNUNET_break (0); 465 GNUNET_break (0);
455 return GNUNET_SYSERR; 466 return GNUNET_SYSERR;
456 } 467 }
457 str = (const char *) &msg[1]; 468 str = (const char *) &msg[1] + key_len;
458 if ('\0' != str[name_len - 1]) 469 if ('\0' != str[name_len - 1])
459 { 470 {
460 GNUNET_break (0); 471 GNUNET_break (0);
@@ -474,14 +485,28 @@ static void
474handle_create_message (void *cls, 485handle_create_message (void *cls,
475 const struct CreateRequestMessage *crm) 486 const struct CreateRequestMessage *crm)
476{ 487{
488 struct GNUNET_IDENTITY_PrivateKey private_key;
477 struct GNUNET_SERVICE_Client *client = cls; 489 struct GNUNET_SERVICE_Client *client = cls;
478 struct Ego *ego; 490 struct Ego *ego;
479 char *str; 491 char *str;
480 char *fn; 492 char *fn;
493 size_t key_len;
494 size_t kb_read;
481 495
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n"); 496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
483 str = GNUNET_strdup ((const char *) &crm[1]); 497 key_len = ntohl (crm->key_len);
484 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str); 498 if ((GNUNET_SYSERR ==
499 GNUNET_IDENTITY_read_private_key_from_buffer (&crm[1],
500 key_len,
501 &private_key,
502 &kb_read)) ||
503 (kb_read != key_len))
504 {
505 GNUNET_SERVICE_client_drop (client);
506 return;
507 }
508 str = GNUNET_strdup ((const char *) &crm[1] + key_len);
509 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1] + key_len, str);
485 for (ego = ego_head; NULL != ego; ego = ego->next) 510 for (ego = ego_head; NULL != ego; ego = ego->next)
486 { 511 {
487 if (0 == strcmp (ego->identifier, str)) 512 if (0 == strcmp (ego->identifier, str))
@@ -494,7 +519,7 @@ handle_create_message (void *cls,
494 } 519 }
495 } 520 }
496 ego = GNUNET_new (struct Ego); 521 ego = GNUNET_new (struct Ego);
497 ego->pk = crm->private_key; 522 ego->pk = private_key;
498 ego->identifier = GNUNET_strdup (str); 523 ego->identifier = GNUNET_strdup (str);
499 GNUNET_CONTAINER_DLL_insert (ego_head, 524 GNUNET_CONTAINER_DLL_insert (ego_head,
500 ego_tail, 525 ego_tail,
@@ -503,7 +528,7 @@ handle_create_message (void *cls,
503 fn = get_ego_filename (ego); 528 fn = get_ego_filename (ego);
504 if (GNUNET_OK != 529 if (GNUNET_OK !=
505 GNUNET_DISK_fn_write (fn, 530 GNUNET_DISK_fn_write (fn,
506 &crm->private_key, 531 &private_key,
507 sizeof(struct GNUNET_IDENTITY_PrivateKey), 532 sizeof(struct GNUNET_IDENTITY_PrivateKey),
508 GNUNET_DISK_PERM_USER_READ 533 GNUNET_DISK_PERM_USER_READ
509 | GNUNET_DISK_PERM_USER_WRITE)) 534 | GNUNET_DISK_PERM_USER_WRITE))
diff --git a/src/identity/identity.h b/src/identity/identity.h
index 57ce091b8..dc57ee11e 100644
--- a/src/identity/identity.h
+++ b/src/identity/identity.h
@@ -128,12 +128,8 @@ struct UpdateMessage
128 */ 128 */
129 uint16_t end_of_list GNUNET_PACKED; 129 uint16_t end_of_list GNUNET_PACKED;
130 130
131 /**
132 * The private key
133 */
134 struct GNUNET_IDENTITY_PrivateKey private_key;
135
136 /* followed by 0-terminated ego name */ 131 /* followed by 0-terminated ego name */
132 /* followed by the private key */
137}; 133};
138 134
139 135
@@ -158,12 +154,11 @@ struct CreateRequestMessage
158 */ 154 */
159 uint16_t reserved GNUNET_PACKED; 155 uint16_t reserved GNUNET_PACKED;
160 156
161 /** 157 uint32_t key_len GNUNET_PACKED;
162 * The private key
163 */
164 struct GNUNET_IDENTITY_PrivateKey private_key;
165 158
166 /* followed by 0-terminated identity name */ 159 /*
160 * Followed by the private key
161 * followed by 0-terminated identity name */
167}; 162};
168 163
169 164
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index d41e05104..4abd62434 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -164,7 +164,7 @@ GNUNET_IDENTITY_ego_get_anonymous ()
164 anon.pub.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); 164 anon.pub.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA);
165 anon.pk.ecdsa_key = *GNUNET_CRYPTO_ecdsa_key_get_anonymous (); 165 anon.pk.ecdsa_key = *GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
166 GNUNET_CRYPTO_hash (&anon.pk, 166 GNUNET_CRYPTO_hash (&anon.pk,
167 sizeof(anon.pk), 167 GNUNET_IDENTITY_private_key_get_length (&anon.pk),
168 &anon.id); 168 &anon.id);
169 setup = 1; 169 setup = 1;
170 return &anon; 170 return &anon;
@@ -194,8 +194,7 @@ GNUNET_IDENTITY_key_get_public (const struct
194 return GNUNET_OK; 194 return GNUNET_OK;
195} 195}
196 196
197 197static enum GNUNET_GenericReturnValue
198static int
199private_key_create (enum GNUNET_IDENTITY_KeyType ktype, 198private_key_create (enum GNUNET_IDENTITY_KeyType ktype,
200 struct GNUNET_IDENTITY_PrivateKey *key) 199 struct GNUNET_IDENTITY_PrivateKey *key)
201{ 200{
@@ -368,7 +367,7 @@ check_identity_update (void *cls,
368 uint16_t name_len = ntohs (um->name_len); 367 uint16_t name_len = ntohs (um->name_len);
369 const char *str = (const char *) &um[1]; 368 const char *str = (const char *) &um[1];
370 369
371 if ((size != name_len + sizeof(struct UpdateMessage)) || 370 if ((size < name_len + sizeof(struct UpdateMessage)) ||
372 ((0 != name_len) && ('\0' != str[name_len - 1]))) 371 ((0 != name_len) && ('\0' != str[name_len - 1])))
373 { 372 {
374 GNUNET_break (0); 373 GNUNET_break (0);
@@ -390,9 +389,13 @@ handle_identity_update (void *cls,
390{ 389{
391 struct GNUNET_IDENTITY_Handle *h = cls; 390 struct GNUNET_IDENTITY_Handle *h = cls;
392 uint16_t name_len = ntohs (um->name_len); 391 uint16_t name_len = ntohs (um->name_len);
393 const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; 392 const char *str;
393 size_t key_len;
394 size_t kb_read;
394 struct GNUNET_HashCode id; 395 struct GNUNET_HashCode id;
395 struct GNUNET_IDENTITY_Ego *ego; 396 struct GNUNET_IDENTITY_Ego *ego;
397 struct GNUNET_IDENTITY_PrivateKey private_key;
398 const char *tmp;
396 399
397 if (GNUNET_YES == ntohs (um->end_of_list)) 400 if (GNUNET_YES == ntohs (um->end_of_list))
398 { 401 {
@@ -401,8 +404,18 @@ handle_identity_update (void *cls,
401 h->cb (h->cb_cls, NULL, NULL, NULL); 404 h->cb (h->cb_cls, NULL, NULL, NULL);
402 return; 405 return;
403 } 406 }
404 GNUNET_CRYPTO_hash (&um->private_key, 407 tmp = (const char*) &um[1];
405 sizeof (um->private_key), 408 str = (0 == name_len) ? NULL : tmp;
409 memset (&private_key, 0, sizeof (private_key));
410 key_len = ntohs (um->header.size) - name_len;
411 GNUNET_assert (GNUNET_SYSERR !=
412 GNUNET_IDENTITY_read_private_key_from_buffer (tmp + name_len,
413 key_len,
414 &private_key,
415 &kb_read));
416 GNUNET_assert (0 <= GNUNET_IDENTITY_private_key_get_length (&private_key));
417 GNUNET_CRYPTO_hash (&private_key,
418 GNUNET_IDENTITY_private_key_get_length (&private_key),
406 &id); 419 &id);
407 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, 420 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
408 &id); 421 &id);
@@ -418,7 +431,7 @@ handle_identity_update (void *cls,
418 } 431 }
419 ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); 432 ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
420 ego->pub_initialized = GNUNET_NO; 433 ego->pub_initialized = GNUNET_NO;
421 ego->pk = um->private_key; 434 ego->pk = private_key;
422 ego->name = GNUNET_strdup (str); 435 ego->name = GNUNET_strdup (str);
423 ego->id = id; 436 ego->id = id;
424 GNUNET_assert (GNUNET_YES == 437 GNUNET_assert (GNUNET_YES ==
@@ -572,10 +585,12 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
572 GNUNET_IDENTITY_CreateContinuation cont, 585 GNUNET_IDENTITY_CreateContinuation cont,
573 void *cont_cls) 586 void *cont_cls)
574{ 587{
588 struct GNUNET_IDENTITY_PrivateKey private_key;
575 struct GNUNET_IDENTITY_Operation *op; 589 struct GNUNET_IDENTITY_Operation *op;
576 struct GNUNET_MQ_Envelope *env; 590 struct GNUNET_MQ_Envelope *env;
577 struct CreateRequestMessage *crm; 591 struct CreateRequestMessage *crm;
578 size_t slen; 592 size_t slen;
593 size_t key_len;
579 594
580 if (NULL == h->mq) 595 if (NULL == h->mq)
581 return NULL; 596 return NULL;
@@ -590,18 +605,23 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
590 op->create_cont = cont; 605 op->create_cont = cont;
591 op->cls = cont_cls; 606 op->cls = cont_cls;
592 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 607 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
593 env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
594 crm->name_len = htons (slen);
595 crm->reserved = htons (0);
596 if (NULL == privkey) 608 if (NULL == privkey)
597 { 609 {
598 GNUNET_assert (GNUNET_OK == 610 GNUNET_assert (GNUNET_OK ==
599 private_key_create (ktype, &crm->private_key)); 611 private_key_create (ktype, &private_key));
600 } 612 }
601 else 613 else
602 crm->private_key = *privkey; 614 private_key = *privkey;
603 op->pk = crm->private_key; 615 key_len = GNUNET_IDENTITY_private_key_get_length (&private_key);
604 GNUNET_memcpy (&crm[1], name, slen); 616 env = GNUNET_MQ_msg_extra (crm, slen + key_len, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
617 crm->name_len = htons (slen);
618 crm->reserved = htons (0);
619 GNUNET_IDENTITY_write_private_key_to_buffer (&private_key,
620 &crm[1],
621 key_len);
622 crm->key_len = htonl (key_len);
623 op->pk = private_key;
624 GNUNET_memcpy ((char*) &crm[1] + key_len, name, slen);
605 GNUNET_MQ_send (h->mq, env); 625 GNUNET_MQ_send (h->mq, env);
606 return op; 626 return op;
607} 627}
@@ -780,8 +800,9 @@ check_key_type (uint32_t type)
780} 800}
781 801
782 802
783static ssize_t 803ssize_t
784private_key_get_length (const struct GNUNET_IDENTITY_PrivateKey *key) 804GNUNET_IDENTITY_private_key_get_length (const struct
805 GNUNET_IDENTITY_PrivateKey *key)
785{ 806{
786 switch (ntohl (key->type)) 807 switch (ntohl (key->type))
787 { 808 {
@@ -792,6 +813,8 @@ private_key_get_length (const struct GNUNET_IDENTITY_PrivateKey *key)
792 return sizeof (key->type) + sizeof (key->eddsa_key); 813 return sizeof (key->type) + sizeof (key->eddsa_key);
793 break; 814 break;
794 default: 815 default:
816 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
817 "Got key type %u\n", ntohl (key->type));
795 GNUNET_break (0); 818 GNUNET_break (0);
796 } 819 }
797 return -1; 820 return -1;
@@ -799,7 +822,8 @@ private_key_get_length (const struct GNUNET_IDENTITY_PrivateKey *key)
799 822
800 823
801ssize_t 824ssize_t
802GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key) 825GNUNET_IDENTITY_public_key_get_length (const struct
826 GNUNET_IDENTITY_PublicKey *key)
803{ 827{
804 switch (ntohl (key->type)) 828 switch (ntohl (key->type))
805 { 829 {
@@ -813,36 +837,99 @@ GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key)
813 return -1; 837 return -1;
814} 838}
815 839
816
817ssize_t 840ssize_t
818GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, 841GNUNET_IDENTITY_private_key_length_by_type (enum GNUNET_IDENTITY_KeyType kt)
819 const void *buffer, 842{
820 size_t len) 843 switch (kt)
844 {
845 case GNUNET_IDENTITY_TYPE_ECDSA:
846 return sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
847 break;
848 case GNUNET_IDENTITY_TYPE_EDDSA:
849 return sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
850 break;
851 default:
852 GNUNET_break (0);
853 }
854 return -1;
855}
856
857
858
859enum GNUNET_GenericReturnValue
860GNUNET_IDENTITY_read_public_key_from_buffer (const void *buffer,
861 size_t len,
862 struct GNUNET_IDENTITY_PublicKey *
863 key,
864 size_t *kb_read)
821{ 865{
822 if (len < sizeof (key->type)) 866 if (len < sizeof (key->type))
823 return -1; 867 return GNUNET_SYSERR;
824 GNUNET_memcpy (&key->type, 868 GNUNET_memcpy (&key->type,
825 buffer, 869 buffer,
826 sizeof (key->type)); 870 sizeof (key->type));
827 ssize_t length = GNUNET_IDENTITY_key_get_length (key); 871 ssize_t length = GNUNET_IDENTITY_public_key_get_length (key);
872 if (len < length)
873 return GNUNET_SYSERR;
874 if (length < 0)
875 return GNUNET_SYSERR;
876 GNUNET_memcpy (&key->ecdsa_key,
877 buffer + sizeof (key->type),
878 length - sizeof (key->type));
879 *kb_read = length;
880 return GNUNET_OK;
881}
882
883
884ssize_t
885GNUNET_IDENTITY_write_public_key_to_buffer (const struct
886 GNUNET_IDENTITY_PublicKey *key,
887 void*buffer,
888 size_t len)
889{
890 const ssize_t length = GNUNET_IDENTITY_public_key_get_length (key);
828 if (len < length) 891 if (len < length)
829 return -1; 892 return -1;
830 if (length < 0) 893 if (length < 0)
831 return -2; 894 return -2;
895 GNUNET_memcpy (buffer, &(key->type), sizeof (key->type));
896 GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length
897 - sizeof (key->type));
898 return length;
899}
900
901enum GNUNET_GenericReturnValue
902GNUNET_IDENTITY_read_private_key_from_buffer (const void *buffer,
903 size_t len,
904 struct
905 GNUNET_IDENTITY_PrivateKey *key,
906 size_t *kb_read)
907{
908 if (len < sizeof (key->type))
909 return GNUNET_SYSERR;
910 GNUNET_memcpy (&key->type,
911 buffer,
912 sizeof (key->type));
913 ssize_t length = GNUNET_IDENTITY_private_key_get_length (key);
914 if (len < length)
915 return GNUNET_SYSERR;
916 if (length < 0)
917 return GNUNET_SYSERR;
832 GNUNET_memcpy (&key->ecdsa_key, 918 GNUNET_memcpy (&key->ecdsa_key,
833 buffer + sizeof (key->type), 919 buffer + sizeof (key->type),
834 length - sizeof (key->type)); 920 length - sizeof (key->type));
835 return length; 921 *kb_read = length;
922 return GNUNET_OK;
836} 923}
837 924
838 925
839ssize_t 926ssize_t
840GNUNET_IDENTITY_write_key_to_buffer (const struct 927GNUNET_IDENTITY_write_private_key_to_buffer (const struct
841 GNUNET_IDENTITY_PublicKey *key, 928 GNUNET_IDENTITY_PrivateKey *key,
842 void*buffer, 929 void *buffer,
843 size_t len) 930 size_t len)
844{ 931{
845 const ssize_t length = GNUNET_IDENTITY_key_get_length (key); 932 const ssize_t length = GNUNET_IDENTITY_private_key_get_length (key);
846 if (len < length) 933 if (len < length)
847 return -1; 934 return -1;
848 if (length < 0) 935 if (length < 0)
@@ -1123,7 +1210,7 @@ char *
1123GNUNET_IDENTITY_public_key_to_string (const struct 1210GNUNET_IDENTITY_public_key_to_string (const struct
1124 GNUNET_IDENTITY_PublicKey *key) 1211 GNUNET_IDENTITY_PublicKey *key)
1125{ 1212{
1126 size_t size = GNUNET_IDENTITY_key_get_length (key); 1213 size_t size = GNUNET_IDENTITY_public_key_get_length (key);
1127 return GNUNET_STRINGS_data_to_string_alloc (key, 1214 return GNUNET_STRINGS_data_to_string_alloc (key,
1128 size); 1215 size);
1129} 1216}
@@ -1133,7 +1220,7 @@ char *
1133GNUNET_IDENTITY_private_key_to_string (const struct 1220GNUNET_IDENTITY_private_key_to_string (const struct
1134 GNUNET_IDENTITY_PrivateKey *key) 1221 GNUNET_IDENTITY_PrivateKey *key)
1135{ 1222{
1136 size_t size = private_key_get_length (key); 1223 size_t size = GNUNET_IDENTITY_private_key_get_length (key);
1137 return GNUNET_STRINGS_data_to_string_alloc (key, 1224 return GNUNET_STRINGS_data_to_string_alloc (key,
1138 size); 1225 size);
1139} 1226}
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c
index 51afb2515..4cc0b6334 100644
--- a/src/identity/identity_api_lookup.c
+++ b/src/identity/identity_api_lookup.c
@@ -105,7 +105,7 @@ check_identity_update (void *cls, const struct UpdateMessage *um)
105 uint16_t name_len = ntohs (um->name_len); 105 uint16_t name_len = ntohs (um->name_len);
106 const char *str = (const char *) &um[1]; 106 const char *str = (const char *) &um[1];
107 107
108 if ((size != name_len + sizeof(struct UpdateMessage)) || 108 if ((size < name_len + sizeof(struct UpdateMessage)) ||
109 ((0 != name_len) && ('\0' != str[name_len - 1]))) 109 ((0 != name_len) && ('\0' != str[name_len - 1])))
110 { 110 {
111 GNUNET_break (0); 111 GNUNET_break (0);
@@ -126,14 +126,29 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
126{ 126{
127 struct GNUNET_IDENTITY_EgoLookup *el = cls; 127 struct GNUNET_IDENTITY_EgoLookup *el = cls;
128 uint16_t name_len = ntohs (um->name_len); 128 uint16_t name_len = ntohs (um->name_len);
129 const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; 129 const char *str;
130 size_t key_len;
131 size_t kb_read;
130 struct GNUNET_HashCode id; 132 struct GNUNET_HashCode id;
131 struct GNUNET_IDENTITY_Ego ego; 133 struct GNUNET_IDENTITY_Ego ego;
134 struct GNUNET_IDENTITY_PrivateKey private_key;
135 const char *tmp;
136
132 memset (&ego, 0, sizeof (ego)); 137 memset (&ego, 0, sizeof (ego));
133 138
134 GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); 139 GNUNET_break (GNUNET_YES != ntohs (um->end_of_list));
135 GNUNET_CRYPTO_hash (&um->private_key, sizeof(um->private_key), &id); 140 tmp = (const char*) &um[1];
136 ego.pk = um->private_key; 141 str = (0 == name_len) ? NULL : tmp;
142 memset (&private_key, 0, sizeof (private_key));
143 key_len = ntohs (um->header.size) - sizeof (*um) - name_len;
144 GNUNET_assert (GNUNET_SYSERR !=
145 GNUNET_IDENTITY_read_private_key_from_buffer (tmp + name_len,
146 key_len,
147 &private_key,
148 &kb_read));
149 GNUNET_assert (key_len == kb_read);
150 GNUNET_CRYPTO_hash (&private_key, sizeof (private_key), &id);
151 ego.pk = private_key;
137 ego.name = (char *) str; 152 ego.name = (char *) str;
138 ego.id = id; 153 ego.id = id;
139 el->cb (el->cb_cls, &ego); 154 el->cb (el->cb_cls, &ego);
diff --git a/src/identity/identity_api_suffix_lookup.c b/src/identity/identity_api_suffix_lookup.c
index 2667ddbc8..fa6bd8310 100644
--- a/src/identity/identity_api_suffix_lookup.c
+++ b/src/identity/identity_api_suffix_lookup.c
@@ -108,7 +108,7 @@ check_identity_update (void *cls, const struct UpdateMessage *um)
108 const char *str = (const char *) &um[1]; 108 const char *str = (const char *) &um[1];
109 109
110 (void) cls; 110 (void) cls;
111 if ((size != name_len + sizeof(struct UpdateMessage)) || 111 if ((size < name_len + sizeof(struct UpdateMessage)) ||
112 ((0 != name_len) && ('\0' != str[name_len - 1]))) 112 ((0 != name_len) && ('\0' != str[name_len - 1])))
113 { 113 {
114 GNUNET_break (0); 114 GNUNET_break (0);
@@ -129,9 +129,23 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
129{ 129{
130 struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; 130 struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls;
131 uint16_t name_len = ntohs (um->name_len); 131 uint16_t name_len = ntohs (um->name_len);
132 const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; 132 const char *str;
133 133 size_t key_len;
134 el->cb (el->cb_cls, &um->private_key, str); 134 size_t kb_read;
135 struct GNUNET_IDENTITY_PrivateKey private_key;
136 const char *tmp;
137
138 tmp = (const char*) &um[1];
139 str = (0 == name_len) ? NULL : tmp;
140 memset (&private_key, 0, sizeof (private_key));
141 key_len = ntohs (um->header.size) - name_len;
142 GNUNET_assert (GNUNET_SYSERR !=
143 GNUNET_IDENTITY_read_private_key_from_buffer (tmp + name_len,
144 key_len,
145 &private_key,
146 &kb_read));
147 GNUNET_assert (key_len == kb_read);
148 el->cb (el->cb_cls, &private_key, str);
135 GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); 149 GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el);
136} 150}
137 151
diff --git a/src/identity/test_identity_messages.sh b/src/identity/test_identity_messages.sh
index daecb1ed2..0879061e4 100755
--- a/src/identity/test_identity_messages.sh
+++ b/src/identity/test_identity_messages.sh
@@ -27,7 +27,7 @@ gnunet-identity -D recipientego -c test_identity.conf
27gnunet-arm -e -c test_identity.conf 27gnunet-arm -e -c test_identity.conf
28if [ "$TEST_MSG" != "$MSG_DEC" ] 28if [ "$TEST_MSG" != "$MSG_DEC" ]
29then 29then
30 echo "Failed - $TEST_MSG != $MSG_DEC" 30 echo "Failed - \"$TEST_MSG\" != \"$MSG_DEC\""
31 exit 1 31 exit 1
32fi 32fi
33 33
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h
index d234ff552..cd745ba51 100644
--- a/src/include/gnunet_identity_service.h
+++ b/src/include/gnunet_identity_service.h
@@ -85,11 +85,10 @@ struct GNUNET_IDENTITY_Handle;
85 */ 85 */
86struct GNUNET_IDENTITY_Ego; 86struct GNUNET_IDENTITY_Ego;
87 87
88// FIXME: these types are NOT packed,
89// NOT 64-bit aligned, but used in messages!!??
90
91/** 88/**
92 * A private key for an identity as per LSD0001. 89 * A private key for an identity as per LSD0001.
90 * Note that these types are NOT packed and MUST NOT be used in RPC
91 * messages. Use the respective serialization functions.
93 */ 92 */
94struct GNUNET_IDENTITY_PrivateKey 93struct GNUNET_IDENTITY_PrivateKey
95{ 94{
@@ -406,8 +405,7 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
406 * @return -1 on error, else the compacted length of the key. 405 * @return -1 on error, else the compacted length of the key.
407 */ 406 */
408ssize_t 407ssize_t
409GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key); 408GNUNET_IDENTITY_public_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key);
410
411 409
412/** 410/**
413 * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer. 411 * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer.
@@ -416,15 +414,32 @@ GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key);
416 * If the buffer is too small, the function returns -1 as error. 414 * If the buffer is too small, the function returns -1 as error.
417 * If the buffer does not contain a valid key, it returns -2 as error. 415 * If the buffer does not contain a valid key, it returns -2 as error.
418 * 416 *
419 * @param key the key
420 * @param buffer the buffer 417 * @param buffer the buffer
421 * @param len the length of buffer 418 * @param len the length of buffer
422 * @return -1 or -2 on error, else the amount of bytes read from the buffer 419 * @param key the key
420 * @param the amount of bytes read from the buffer
421 * @return GNUNET_SYSERR on error
422 */
423enum GNUNET_GenericReturnValue
424GNUNET_IDENTITY_read_public_key_from_buffer (const void *buffer,
425 size_t len,
426 struct
427 GNUNET_IDENTITY_PublicKey *key,
428 size_t *read);
429
430/**
431 * Get the compacted length of a #GNUNET_IDENTITY_PrivateKey.
432 * Compacted means that it returns the minimum number of bytes this
433 * key is long, as opposed to the union structure inside
434 * #GNUNET_IDENTITY_PrivateKey.
435 * Useful for compact serializations.
436 *
437 * @param key the key.
438 * @return -1 on error, else the compacted length of the key.
423 */ 439 */
424ssize_t 440ssize_t
425GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, 441GNUNET_IDENTITY_private_key_get_length (const struct
426 const void*buffer, 442 GNUNET_IDENTITY_PrivateKey *key);
427 size_t len);
428 443
429 444
430/** 445/**
@@ -440,10 +455,49 @@ GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key,
440 * @return -1 or -2 on error, else the amount of bytes written to the buffer 455 * @return -1 or -2 on error, else the amount of bytes written to the buffer
441 */ 456 */
442ssize_t 457ssize_t
443GNUNET_IDENTITY_write_key_to_buffer (const struct 458GNUNET_IDENTITY_write_public_key_to_buffer (const struct
444 GNUNET_IDENTITY_PublicKey *key, 459 GNUNET_IDENTITY_PublicKey *key,
445 void*buffer, 460 void*buffer,
446 size_t len); 461 size_t len);
462
463
464/**
465 * Reads a #GNUNET_IDENTITY_PrivateKey from a compact buffer.
466 * The buffer has to contain at least the compacted length of
467 * a #GNUNET_IDENTITY_PrivateKey in bytes.
468 * If the buffer is too small, the function returns GNUNET_SYSERR as error.
469 *
470 * @param buffer the buffer
471 * @param len the length of buffer
472 * @param key the key
473 * @param the amount of bytes read from the buffer
474 * @return GNUNET_SYSERR on error
475 */
476enum GNUNET_GenericReturnValue
477GNUNET_IDENTITY_read_private_key_from_buffer (const void*buffer,
478 size_t len,
479 struct
480 GNUNET_IDENTITY_PrivateKey *key,
481 size_t *read);
482
483
484/**
485 * Writes a #GNUNET_IDENTITY_PrivateKey to a compact buffer.
486 * The buffer requires space for at least the compacted length of
487 * a #GNUNET_IDENTITY_PrivateKey in bytes.
488 * If the buffer is too small, the function returns -1 as error.
489 * If the key is not valid, it returns -2 as error.
490 *
491 * @param key the key
492 * @param buffer the buffer
493 * @param len the length of buffer
494 * @return -1 or -2 on error, else the amount of bytes written to the buffer
495 */
496ssize_t
497GNUNET_IDENTITY_write_private_key_to_buffer (const struct
498 GNUNET_IDENTITY_PrivateKey *key,
499 void*buffer,
500 size_t len);
447 501
448 502
449/** 503/**
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h
index e9e0f144d..a3f6c19b6 100644
--- a/src/include/gnunet_reclaim_service.h
+++ b/src/include/gnunet_reclaim_service.h
@@ -498,6 +498,43 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
498void 498void
499GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op); 499GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
500 500
501/**
502 * Get serialized ticket size
503 *
504 * @param tkt the ticket
505 * @return the buffer length requirement for a serialization
506 */
507size_t
508GNUNET_RECLAIM_ticket_serialize_get_size (const struct GNUNET_RECLAIM_Ticket *tkt);
509
510/**
511 * Deserializes a ticket
512 *
513 * @param buffer the buffer to read from
514 * @param len the length of the buffer
515 * @param tkt the ticket to write to (must be allocated)
516 * @param kb_read how many bytes were read from buffer
517 * @return GNUNET_SYSERR on error
518 */
519enum GNUNET_GenericReturnValue
520GNUNET_RECLAIM_read_ticket_from_buffer (const void *buffer,
521 size_t len,
522 struct GNUNET_RECLAIM_Ticket *tkt,
523 size_t *tb_read);
524
525/**
526 * Serializes a ticket
527 *
528 * @param tkt the ticket to serialize
529 * @param buffer the buffer to serialize to (must be allocated with sufficient size
530 * @param len the length of the buffer
531 * @return the number of written bytes or < 0 on error
532 */
533ssize_t
534GNUNET_RECLAIM_write_ticket_to_buffer (const struct
535 GNUNET_RECLAIM_Ticket *tkt,
536 void *buffer,
537 size_t len);
501 538
502#if 0 /* keep Emacsens' auto-indent happy */ 539#if 0 /* keep Emacsens' auto-indent happy */
503{ 540{
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 2a1558e09..fb2a670bc 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -179,7 +179,6 @@ gnunet_namestore_fcfsd_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
179 179
180gnunet_service_namestore_SOURCES = \ 180gnunet_service_namestore_SOURCES = \
181 gnunet-service-namestore.c 181 gnunet-service-namestore.c
182
183gnunet_service_namestore_LDADD = \ 182gnunet_service_namestore_LDADD = \
184 $(top_builddir)/src/namecache/libgnunetnamecache.la \ 183 $(top_builddir)/src/namecache/libgnunetnamecache.la \
185 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 184 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 843158c68..6444d446d 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -129,11 +129,6 @@ static struct GNUNET_IDENTITY_EgoLookup *el;
129static struct GNUNET_IDENTITY_Handle *idh; 129static struct GNUNET_IDENTITY_Handle *idh;
130 130
131/** 131/**
132 * Obtain default ego
133 */
134struct GNUNET_IDENTITY_Operation *get_default;
135
136/**
137 * Name of the ego controlling the zone. 132 * Name of the ego controlling the zone.
138 */ 133 */
139static char *ego_name; 134static char *ego_name;
@@ -342,10 +337,10 @@ do_shutdown (void *cls)
342 struct MarkedRecord *mrec; 337 struct MarkedRecord *mrec;
343 struct MarkedRecord *mrec_tmp; 338 struct MarkedRecord *mrec_tmp;
344 (void) cls; 339 (void) cls;
345 if (NULL != get_default) 340 if (NULL != ego_name)
346 { 341 {
347 GNUNET_IDENTITY_cancel (get_default); 342 GNUNET_free (ego_name);
348 get_default = NULL; 343 ego_name = NULL;
349 } 344 }
350 if (NULL != purge_task) 345 if (NULL != purge_task)
351 { 346 {
@@ -1530,7 +1525,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1530 } 1525 }
1531 memset (&rd, 0, sizeof(rd)); 1526 memset (&rd, 0, sizeof(rd));
1532 rd.data = &pkey; 1527 rd.data = &pkey;
1533 rd.data_size = GNUNET_IDENTITY_key_get_length (&pkey); 1528 rd.data_size = GNUNET_IDENTITY_public_key_get_length (&pkey);
1534 rd.record_type = ntohl (pkey.type); 1529 rd.record_type = ntohl (pkey.type);
1535 rd.expiration_time = etime; 1530 rd.expiration_time = etime;
1536 if (GNUNET_YES == etime_is_rel) 1531 if (GNUNET_YES == etime_is_rel)
@@ -1589,8 +1584,6 @@ identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
1589 return; 1584 return;
1590 } 1585 }
1591 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); 1586 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1592 GNUNET_free (ego_name);
1593 ego_name = NULL;
1594 run_with_zone_pkey (cfg); 1587 run_with_zone_pkey (cfg);
1595} 1588}
1596 1589
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 92c81c4eb..f0739cbeb 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -711,6 +711,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
711 unsigned int res_count; 711 unsigned int res_count;
712 unsigned int rd_nf_count; 712 unsigned int rd_nf_count;
713 size_t name_len; 713 size_t name_len;
714 size_t key_len;
714 ssize_t rd_ser_len; 715 ssize_t rd_ser_len;
715 char *name_tmp; 716 char *name_tmp;
716 char *rd_ser; 717 char *rd_ser;
@@ -778,16 +779,20 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
778 GNUNET_SERVICE_client_drop (nc->client); 779 GNUNET_SERVICE_client_drop (nc->client);
779 return 0; 780 return 0;
780 } 781 }
782 key_len = GNUNET_IDENTITY_private_key_get_length (zone_key);
781 env = GNUNET_MQ_msg_extra (zir_msg, 783 env = GNUNET_MQ_msg_extra (zir_msg,
782 name_len + rd_ser_len, 784 name_len + rd_ser_len + key_len,
783 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); 785 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
784 zir_msg->gns_header.r_id = htonl (request_id); 786 zir_msg->gns_header.r_id = htonl (request_id);
785 zir_msg->name_len = htons (name_len); 787 zir_msg->name_len = htons (name_len);
786 zir_msg->rd_count = htons (res_count); 788 zir_msg->rd_count = htons (res_count);
787 zir_msg->rd_len = htons ((uint16_t) rd_ser_len); 789 zir_msg->rd_len = htons ((uint16_t) rd_ser_len);
788 zir_msg->private_key = *zone_key; 790 zir_msg->key_len = htonl (key_len);
791 GNUNET_IDENTITY_write_private_key_to_buffer (zone_key,
792 &zir_msg[1],
793 key_len);
789 zir_msg->expire = GNUNET_TIME_absolute_hton (block_exp); 794 zir_msg->expire = GNUNET_TIME_absolute_hton (block_exp);
790 name_tmp = (char *) &zir_msg[1]; 795 name_tmp = (char *) &zir_msg[1] + key_len;
791 GNUNET_memcpy (name_tmp, name, name_len); 796 GNUNET_memcpy (name_tmp, name, name_len);
792 rd_ser = &name_tmp[name_len]; 797 rd_ser = &name_tmp[name_len];
793 GNUNET_assert ( 798 GNUNET_assert (
@@ -1309,16 +1314,17 @@ check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1309{ 1314{
1310 uint32_t name_len; 1315 uint32_t name_len;
1311 size_t src_size; 1316 size_t src_size;
1317 size_t key_len;
1312 1318
1313 (void) cls; 1319 (void) cls;
1314 name_len = ntohl (ll_msg->label_len); 1320 name_len = ntohl (ll_msg->label_len);
1321 key_len = ntohl (ll_msg->key_len);
1315 src_size = ntohs (ll_msg->gns_header.header.size); 1322 src_size = ntohs (ll_msg->gns_header.header.size);
1316 if (name_len != src_size - sizeof(struct LabelLookupMessage)) 1323 if (name_len + key_len != src_size - sizeof(struct LabelLookupMessage))
1317 { 1324 {
1318 GNUNET_break (0); 1325 GNUNET_break (0);
1319 return GNUNET_SYSERR; 1326 return GNUNET_SYSERR;
1320 } 1327 }
1321 GNUNET_MQ_check_zero_termination (ll_msg);
1322 return GNUNET_OK; 1328 return GNUNET_OK;
1323} 1329}
1324 1330
@@ -1332,6 +1338,7 @@ check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1332static void 1338static void
1333handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) 1339handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1334{ 1340{
1341 struct GNUNET_IDENTITY_PrivateKey zone;
1335 struct NamestoreClient *nc = cls; 1342 struct NamestoreClient *nc = cls;
1336 struct GNUNET_MQ_Envelope *env; 1343 struct GNUNET_MQ_Envelope *env;
1337 struct LabelLookupResponseMessage *llr_msg; 1344 struct LabelLookupResponseMessage *llr_msg;
@@ -1341,8 +1348,23 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1341 char *conv_name; 1348 char *conv_name;
1342 uint32_t name_len; 1349 uint32_t name_len;
1343 int res; 1350 int res;
1344 1351 size_t key_len;
1345 name_tmp = (const char *) &ll_msg[1]; 1352 size_t kb_read;
1353
1354 key_len = ntohl (ll_msg->key_len);
1355 if ((GNUNET_SYSERR ==
1356 GNUNET_IDENTITY_read_private_key_from_buffer (&ll_msg[1],
1357 key_len,
1358 &zone,
1359 &kb_read)) ||
1360 (kb_read != key_len))
1361 {
1362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1363 "Error reading private key\n");
1364 GNUNET_SERVICE_client_drop (nc->client);
1365 return;
1366 }
1367 name_tmp = (const char *) &ll_msg[1] + key_len;
1346 GNUNET_SERVICE_client_continue (nc->client); 1368 GNUNET_SERVICE_client_continue (nc->client);
1347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1348 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", 1370 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n",
@@ -1366,37 +1388,38 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1366 rlc.res_rd_count = 0; 1388 rlc.res_rd_count = 0;
1367 rlc.res_rd = NULL; 1389 rlc.res_rd = NULL;
1368 rlc.rd_ser_len = 0; 1390 rlc.rd_ser_len = 0;
1369 rlc.nick = get_nick_record (&ll_msg->zone); 1391 rlc.nick = get_nick_record (&zone);
1370 if (GNUNET_YES != ntohl (ll_msg->is_edit_request)) 1392 if (GNUNET_YES != ntohl (ll_msg->is_edit_request))
1371 res = nc->GSN_database->lookup_records (nc->GSN_database->cls, 1393 res = nc->GSN_database->lookup_records (nc->GSN_database->cls,
1372 &ll_msg->zone, 1394 &zone,
1373 conv_name, 1395 conv_name,
1374 &lookup_it, 1396 &lookup_it,
1375 &rlc); 1397 &rlc);
1376 else 1398 else
1377 res = nc->GSN_database->edit_records (nc->GSN_database->cls, 1399 res = nc->GSN_database->edit_records (nc->GSN_database->cls,
1378 &ll_msg->zone, 1400 &zone,
1379 conv_name, 1401 conv_name,
1380 &lookup_it, 1402 &lookup_it,
1381 &rlc); 1403 &rlc);
1382 1404
1383 env = 1405 env =
1384 GNUNET_MQ_msg_extra (llr_msg, 1406 GNUNET_MQ_msg_extra (llr_msg,
1385 name_len + rlc.rd_ser_len, 1407 key_len + name_len + rlc.rd_ser_len,
1386 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); 1408 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE);
1387 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; 1409 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id;
1388 llr_msg->private_key = ll_msg->zone; 1410 GNUNET_memcpy (&llr_msg[1], &ll_msg[1], key_len);
1411 llr_msg->key_len = ll_msg->key_len;
1389 llr_msg->name_len = htons (name_len); 1412 llr_msg->name_len = htons (name_len);
1390 llr_msg->rd_count = htons (rlc.res_rd_count); 1413 llr_msg->rd_count = htons (rlc.res_rd_count);
1391 llr_msg->rd_len = htons (rlc.rd_ser_len); 1414 llr_msg->rd_len = htons (rlc.rd_ser_len);
1392 res_name = (char *) &llr_msg[1]; 1415 res_name = ((char *) &llr_msg[1]) + key_len;
1393 if (GNUNET_YES == rlc.found) 1416 if (GNUNET_YES == rlc.found)
1394 llr_msg->found = htons (GNUNET_YES); 1417 llr_msg->found = htons (GNUNET_YES);
1395 else if (GNUNET_SYSERR == res) 1418 else if (GNUNET_SYSERR == res)
1396 llr_msg->found = htons (GNUNET_SYSERR); 1419 llr_msg->found = htons (GNUNET_SYSERR);
1397 else 1420 else
1398 llr_msg->found = htons (GNUNET_NO); 1421 llr_msg->found = htons (GNUNET_NO);
1399 GNUNET_memcpy (&llr_msg[1], conv_name, name_len); 1422 GNUNET_memcpy (res_name, conv_name, name_len);
1400 GNUNET_memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len); 1423 GNUNET_memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len);
1401 GNUNET_MQ_send (nc->mq, env); 1424 GNUNET_MQ_send (nc->mq, env);
1402 GNUNET_free (rlc.res_rd); 1425 GNUNET_free (rlc.res_rd);
@@ -1418,11 +1441,14 @@ check_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1418 size_t msg_size; 1441 size_t msg_size;
1419 size_t min_size_exp; 1442 size_t min_size_exp;
1420 size_t rd_set_count; 1443 size_t rd_set_count;
1444 size_t key_len;
1421 1445
1422 (void) cls; 1446 (void) cls;
1423 msg_size = ntohs (rp_msg->gns_header.header.size); 1447 msg_size = ntohs (rp_msg->gns_header.header.size);
1424 rd_set_count = ntohs (rp_msg->rd_set_count); 1448 rd_set_count = ntohs (rp_msg->rd_set_count);
1425 min_size_exp = sizeof(struct RecordStoreMessage) + sizeof (struct RecordSet) 1449 key_len = ntohl (rp_msg->key_len);
1450
1451 min_size_exp = sizeof(*rp_msg) + key_len + sizeof (struct RecordSet)
1426 * rd_set_count; 1452 * rd_set_count;
1427 if (msg_size < min_size_exp) 1453 if (msg_size < min_size_exp)
1428 { 1454 {
@@ -1701,24 +1727,40 @@ store_record_set (struct NamestoreClient *nc,
1701static void 1727static void
1702handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) 1728handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1703{ 1729{
1730 struct GNUNET_IDENTITY_PrivateKey zone;
1704 struct NamestoreClient *nc = cls; 1731 struct NamestoreClient *nc = cls;
1705 uint32_t rid; 1732 uint32_t rid;
1706 uint16_t rd_set_count; 1733 uint16_t rd_set_count;
1707 const char *buf; 1734 const char *buf;
1708 ssize_t read; 1735 ssize_t read;
1736 size_t key_len;
1737 size_t kb_read;
1709 struct StoreActivity *sa; 1738 struct StoreActivity *sa;
1710 struct RecordSet *rs; 1739 struct RecordSet *rs;
1711 enum GNUNET_ErrorCode res; 1740 enum GNUNET_ErrorCode res;
1712 1741
1742 key_len = ntohl (rp_msg->key_len);
1743 if ((GNUNET_SYSERR ==
1744 GNUNET_IDENTITY_read_private_key_from_buffer (&rp_msg[1],
1745 key_len,
1746 &zone,
1747 &kb_read)) ||
1748 (kb_read != key_len))
1749 {
1750 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1751 "Error reading private key\n");
1752 GNUNET_SERVICE_client_drop (nc->client);
1753 return;
1754 }
1713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1714 "Received NAMESTORE_RECORD_STORE message\n"); 1756 "Received NAMESTORE_RECORD_STORE message\n");
1715 rid = ntohl (rp_msg->gns_header.r_id); 1757 rid = ntohl (rp_msg->gns_header.r_id);
1716 rd_set_count = ntohs (rp_msg->rd_set_count); 1758 rd_set_count = ntohs (rp_msg->rd_set_count);
1717 buf = (const char *) &rp_msg[1]; 1759 buf = (const char *) &rp_msg[1] + key_len;
1718 for (int i = 0; i < rd_set_count; i++) 1760 for (int i = 0; i < rd_set_count; i++)
1719 { 1761 {
1720 rs = (struct RecordSet *) buf; 1762 rs = (struct RecordSet *) buf;
1721 res = store_record_set (nc, &rp_msg->private_key, 1763 res = store_record_set (nc, &zone,
1722 rs, &read); 1764 rs, &read);
1723 if (GNUNET_EC_NONE != res) 1765 if (GNUNET_EC_NONE != res)
1724 { 1766 {
@@ -1735,11 +1777,11 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1735 sa->nc = nc; 1777 sa->nc = nc;
1736 sa->rs = (struct RecordSet *) &sa[1]; 1778 sa->rs = (struct RecordSet *) &sa[1];
1737 sa->rd_set_count = rd_set_count; 1779 sa->rd_set_count = rd_set_count;
1738 GNUNET_memcpy (&sa[1], (char *) &rp_msg[1], 1780 GNUNET_memcpy (&sa[1], (char *) &rp_msg[1] + key_len,
1739 ntohs (rp_msg->gns_header.header.size) - sizeof (*rp_msg)); 1781 ntohs (rp_msg->gns_header.header.size) - sizeof (*rp_msg));
1740 sa->rid = rid; 1782 sa->rid = rid;
1741 sa->rd_set_pos = 0; 1783 sa->rd_set_pos = 0;
1742 sa->private_key = rp_msg->private_key; 1784 sa->private_key = zone;
1743 sa->zm_pos = monitor_head; 1785 sa->zm_pos = monitor_head;
1744 sa->uncommited = nc->in_transaction; 1786 sa->uncommited = nc->in_transaction;
1745 continue_store_activity (sa, GNUNET_YES); 1787 continue_store_activity (sa, GNUNET_YES);
@@ -1913,6 +1955,7 @@ handle_zone_to_name_it (void *cls,
1913 struct GNUNET_MQ_Envelope *env; 1955 struct GNUNET_MQ_Envelope *env;
1914 struct ZoneToNameResponseMessage *ztnr_msg; 1956 struct ZoneToNameResponseMessage *ztnr_msg;
1915 size_t name_len; 1957 size_t name_len;
1958 size_t key_len;
1916 ssize_t rd_ser_len; 1959 ssize_t rd_ser_len;
1917 size_t msg_size; 1960 size_t msg_size;
1918 char *name_tmp; 1961 char *name_tmp;
@@ -1931,7 +1974,9 @@ handle_zone_to_name_it (void *cls,
1931 ztn_ctx->ec = htonl (GNUNET_EC_NAMESTORE_UNKNOWN); 1974 ztn_ctx->ec = htonl (GNUNET_EC_NAMESTORE_UNKNOWN);
1932 return; 1975 return;
1933 } 1976 }
1934 msg_size = sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len; 1977 key_len = GNUNET_IDENTITY_private_key_get_length (zone_key);
1978 msg_size = sizeof(struct ZoneToNameResponseMessage)
1979 + name_len + rd_ser_len + key_len;
1935 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) 1980 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE)
1936 { 1981 {
1937 GNUNET_break (0); 1982 GNUNET_break (0);
@@ -1940,7 +1985,7 @@ handle_zone_to_name_it (void *cls,
1940 } 1985 }
1941 env = 1986 env =
1942 GNUNET_MQ_msg_extra (ztnr_msg, 1987 GNUNET_MQ_msg_extra (ztnr_msg,
1943 name_len + rd_ser_len, 1988 key_len + name_len + rd_ser_len,
1944 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); 1989 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1945 ztnr_msg->gns_header.header.size = htons (msg_size); 1990 ztnr_msg->gns_header.header.size = htons (msg_size);
1946 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); 1991 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid);
@@ -1948,8 +1993,11 @@ handle_zone_to_name_it (void *cls,
1948 ztnr_msg->rd_len = htons (rd_ser_len); 1993 ztnr_msg->rd_len = htons (rd_ser_len);
1949 ztnr_msg->rd_count = htons (rd_count); 1994 ztnr_msg->rd_count = htons (rd_count);
1950 ztnr_msg->name_len = htons (name_len); 1995 ztnr_msg->name_len = htons (name_len);
1951 ztnr_msg->zone = *zone_key; 1996 ztnr_msg->key_len = htonl (key_len);
1952 name_tmp = (char *) &ztnr_msg[1]; 1997 GNUNET_IDENTITY_write_private_key_to_buffer (zone_key,
1998 &ztnr_msg[1],
1999 key_len);
2000 name_tmp = (char *) &ztnr_msg[1] + key_len;
1953 GNUNET_memcpy (name_tmp, name, name_len); 2001 GNUNET_memcpy (name_tmp, name, name_len);
1954 rd_tmp = &name_tmp[name_len]; 2002 rd_tmp = &name_tmp[name_len];
1955 GNUNET_assert ( 2003 GNUNET_assert (
@@ -1959,6 +2007,13 @@ handle_zone_to_name_it (void *cls,
1959 GNUNET_MQ_send (ztn_ctx->nc->mq, env); 2007 GNUNET_MQ_send (ztn_ctx->nc->mq, env);
1960} 2008}
1961 2009
2010static enum GNUNET_GenericReturnValue
2011check_zone_to_name (void *cls,
2012 const struct ZoneToNameMessage *zis_msg)
2013{
2014 return GNUNET_OK;
2015}
2016
1962 2017
1963/** 2018/**
1964 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message 2019 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message
@@ -1969,18 +2024,52 @@ handle_zone_to_name_it (void *cls,
1969static void 2024static void
1970handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) 2025handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg)
1971{ 2026{
2027 struct GNUNET_IDENTITY_PrivateKey zone;
2028 struct GNUNET_IDENTITY_PublicKey value_zone;
1972 struct NamestoreClient *nc = cls; 2029 struct NamestoreClient *nc = cls;
1973 struct ZoneToNameCtx ztn_ctx; 2030 struct ZoneToNameCtx ztn_ctx;
1974 struct GNUNET_MQ_Envelope *env; 2031 struct GNUNET_MQ_Envelope *env;
1975 struct ZoneToNameResponseMessage *ztnr_msg; 2032 struct ZoneToNameResponseMessage *ztnr_msg;
2033 size_t key_len;
2034 size_t pkey_len;
2035 size_t kb_read;
1976 2036
1977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n"); 2037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n");
1978 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 2038 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1979 ztn_ctx.nc = nc; 2039 ztn_ctx.nc = nc;
1980 ztn_ctx.ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; 2040 ztn_ctx.ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND;
2041 key_len = ntohl (ztn_msg->key_len);
2042 if ((GNUNET_SYSERR ==
2043 GNUNET_IDENTITY_read_private_key_from_buffer (&ztn_msg[1],
2044 key_len,
2045 &zone,
2046 &kb_read)) ||
2047 (kb_read != key_len))
2048 {
2049 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2050 "Error parsing private key.\n");
2051 GNUNET_SERVICE_client_drop (nc->client);
2052 GNUNET_break (0);
2053 return;
2054 }
2055 pkey_len = ntohl (ztn_msg->pkey_len);
2056 if ((GNUNET_SYSERR ==
2057 GNUNET_IDENTITY_read_public_key_from_buffer ((char*) &ztn_msg[1]
2058 + key_len,
2059 pkey_len,
2060 &value_zone,
2061 &kb_read)) ||
2062 (kb_read != pkey_len))
2063 {
2064 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2065 "Error parsing public key.\n");
2066 GNUNET_SERVICE_client_drop (nc->client);
2067 GNUNET_break (0);
2068 return;
2069 }
1981 if (GNUNET_SYSERR == nc->GSN_database->zone_to_name (nc->GSN_database->cls, 2070 if (GNUNET_SYSERR == nc->GSN_database->zone_to_name (nc->GSN_database->cls,
1982 &ztn_msg->zone, 2071 &zone,
1983 &ztn_msg->value_zone, 2072 &value_zone,
1984 &handle_zone_to_name_it, 2073 &handle_zone_to_name_it,
1985 &ztn_ctx)) 2074 &ztn_ctx))
1986 { 2075 {
@@ -2133,6 +2222,24 @@ run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit)
2133 zone_iteration_done_client_continue (zi); 2222 zone_iteration_done_client_continue (zi);
2134} 2223}
2135 2224
2225static enum GNUNET_GenericReturnValue
2226check_iteration_start (void *cls,
2227 const struct ZoneIterationStartMessage *zis_msg)
2228{
2229 uint16_t size;
2230 size_t key_len;
2231
2232 size = ntohs (zis_msg->gns_header.header.size);
2233 key_len = ntohs (zis_msg->key_len);
2234
2235 if (size < key_len + sizeof(*zis_msg))
2236 {
2237 GNUNET_break (0);
2238 return GNUNET_SYSERR;
2239 }
2240 return GNUNET_OK;
2241}
2242
2136 2243
2137/** 2244/**
2138 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message 2245 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message
@@ -2144,18 +2251,35 @@ static void
2144handle_iteration_start (void *cls, 2251handle_iteration_start (void *cls,
2145 const struct ZoneIterationStartMessage *zis_msg) 2252 const struct ZoneIterationStartMessage *zis_msg)
2146{ 2253{
2254 struct GNUNET_IDENTITY_PrivateKey zone;
2147 struct NamestoreClient *nc = cls; 2255 struct NamestoreClient *nc = cls;
2148 struct ZoneIteration *zi; 2256 struct ZoneIteration *zi;
2257 size_t key_len;
2258 size_t kb_read;
2149 2259
2150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2151 "Received ZONE_ITERATION_START message\n"); 2261 "Received ZONE_ITERATION_START message\n");
2262 key_len = ntohl (zis_msg->key_len);
2152 zi = GNUNET_new (struct ZoneIteration); 2263 zi = GNUNET_new (struct ZoneIteration);
2264 if (0 < key_len)
2265 {
2266 if ((GNUNET_SYSERR ==
2267 GNUNET_IDENTITY_read_private_key_from_buffer (&zis_msg[1],
2268 key_len,
2269 &zone,
2270 &kb_read)) ||
2271 (kb_read != key_len))
2272 {
2273 GNUNET_SERVICE_client_drop (nc->client);
2274 GNUNET_free (zi);
2275 return;
2276 }
2277 zi->zone = zone;
2278 }
2153 zi->request_id = ntohl (zis_msg->gns_header.r_id); 2279 zi->request_id = ntohl (zis_msg->gns_header.r_id);
2154 zi->filter = ntohs (zis_msg->filter); 2280 zi->filter = ntohs (zis_msg->filter);
2155 zi->offset = 0; 2281 zi->offset = 0;
2156 zi->nc = nc; 2282 zi->nc = nc;
2157 zi->zone = zis_msg->zone;
2158
2159 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 2283 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
2160 run_zone_iteration_round (zi, 1); 2284 run_zone_iteration_round (zi, 1);
2161} 2285}
@@ -2349,6 +2473,24 @@ monitor_iterate_cb (void *cls,
2349 } 2473 }
2350} 2474}
2351 2475
2476static enum GNUNET_GenericReturnValue
2477check_monitor_start (void *cls,
2478 const struct ZoneMonitorStartMessage *zis_msg)
2479{
2480 uint16_t size;
2481 size_t key_len;
2482
2483 size = ntohs (zis_msg->header.size);
2484 key_len = ntohs (zis_msg->key_len);
2485
2486 if (size < key_len + sizeof(*zis_msg))
2487 {
2488 GNUNET_break (0);
2489 return GNUNET_SYSERR;
2490 }
2491 return GNUNET_OK;
2492}
2493
2352 2494
2353/** 2495/**
2354 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message 2496 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message
@@ -2360,14 +2502,33 @@ static void
2360handle_monitor_start (void *cls, const struct 2502handle_monitor_start (void *cls, const struct
2361 ZoneMonitorStartMessage *zis_msg) 2503 ZoneMonitorStartMessage *zis_msg)
2362{ 2504{
2505 struct GNUNET_IDENTITY_PrivateKey zone;
2363 struct NamestoreClient *nc = cls; 2506 struct NamestoreClient *nc = cls;
2364 struct ZoneMonitor *zm; 2507 struct ZoneMonitor *zm;
2508 size_t key_len;
2509 size_t kb_read;
2365 2510
2366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2367 "Received ZONE_MONITOR_START message\n"); 2512 "Received ZONE_MONITOR_START message\n");
2368 zm = GNUNET_new (struct ZoneMonitor); 2513 zm = GNUNET_new (struct ZoneMonitor);
2369 zm->nc = nc; 2514 zm->nc = nc;
2370 zm->zone = zis_msg->zone; 2515 key_len = ntohl (zis_msg->key_len);
2516 if (0 < key_len)
2517 {
2518 if ((GNUNET_SYSERR ==
2519 GNUNET_IDENTITY_read_private_key_from_buffer (&zis_msg[1],
2520 key_len,
2521 &zone,
2522 &kb_read)) ||
2523 (kb_read != key_len))
2524 {
2525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2526 "Error reading private key\n");
2527 GNUNET_SERVICE_client_drop (nc->client);
2528 return;
2529 }
2530 zm->zone = zone;
2531 }
2371 zm->limit = 1; 2532 zm->limit = 1;
2372 zm->filter = ntohs (zis_msg->filter); 2533 zm->filter = ntohs (zis_msg->filter);
2373 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first)); 2534 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
@@ -2557,14 +2718,14 @@ GNUNET_SERVICE_MAIN (
2557 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, 2718 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP,
2558 struct LabelLookupMessage, 2719 struct LabelLookupMessage,
2559 NULL), 2720 NULL),
2560 GNUNET_MQ_hd_fixed_size (zone_to_name, 2721 GNUNET_MQ_hd_var_size (zone_to_name,
2561 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 2722 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME,
2562 struct ZoneToNameMessage, 2723 struct ZoneToNameMessage,
2563 NULL), 2724 NULL),
2564 GNUNET_MQ_hd_fixed_size (iteration_start, 2725 GNUNET_MQ_hd_var_size (iteration_start,
2565 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, 2726 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START,
2566 struct ZoneIterationStartMessage, 2727 struct ZoneIterationStartMessage,
2567 NULL), 2728 NULL),
2568 GNUNET_MQ_hd_fixed_size (iteration_next, 2729 GNUNET_MQ_hd_fixed_size (iteration_next,
2569 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 2730 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT,
2570 struct ZoneIterationNextMessage, 2731 struct ZoneIterationNextMessage,
@@ -2573,10 +2734,10 @@ GNUNET_SERVICE_MAIN (
2573 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 2734 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP,
2574 struct ZoneIterationStopMessage, 2735 struct ZoneIterationStopMessage,
2575 NULL), 2736 NULL),
2576 GNUNET_MQ_hd_fixed_size (monitor_start, 2737 GNUNET_MQ_hd_var_size (monitor_start,
2577 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, 2738 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START,
2578 struct ZoneMonitorStartMessage, 2739 struct ZoneMonitorStartMessage,
2579 NULL), 2740 NULL),
2580 GNUNET_MQ_hd_fixed_size (monitor_next, 2741 GNUNET_MQ_hd_fixed_size (monitor_next,
2581 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT, 2742 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT,
2582 struct ZoneMonitorNextMessage, 2743 struct ZoneMonitorNextMessage,
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index 37c1576bc..0b50ac1ab 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -91,16 +91,17 @@ struct RecordStoreMessage
91 struct GNUNET_NAMESTORE_Header gns_header; 91 struct GNUNET_NAMESTORE_Header gns_header;
92 92
93 /** 93 /**
94 * The private key of the authority. 94 * Number of record sets
95 */ 95 */
96 struct GNUNET_IDENTITY_PrivateKey private_key; 96 uint16_t rd_set_count;
97 97
98 /** 98 /**
99 * Number of record sets 99 * Length of the zone key
100 */ 100 */
101 uint16_t rd_set_count; 101 uint32_t key_len GNUNET_PACKED;
102 102
103 /** 103 /**
104 * Followed by the private zone key
104 * Followed by rd_set_count RecordSets 105 * Followed by rd_set_count RecordSets
105 */ 106 */
106}; 107};
@@ -150,11 +151,12 @@ struct LabelLookupMessage
150 uint16_t filter; 151 uint16_t filter;
151 152
152 /** 153 /**
153 * The private key of the zone to look up in 154 * Length of the zone key
154 */ 155 */
155 struct GNUNET_IDENTITY_PrivateKey zone; 156 uint32_t key_len GNUNET_PACKED;
156 157
157 /* followed by: 158 /* followed by:
159 * the private zone key
158 * name with length name_len 160 * name with length name_len
159 */ 161 */
160}; 162};
@@ -192,11 +194,12 @@ struct LabelLookupResponseMessage
192 int16_t found GNUNET_PACKED; 194 int16_t found GNUNET_PACKED;
193 195
194 /** 196 /**
195 * The private key of the authority. 197 * Length of the zone key
196 */ 198 */
197 struct GNUNET_IDENTITY_PrivateKey private_key; 199 uint32_t key_len GNUNET_PACKED;
198 200
199 /* followed by: 201 /* followed by:
202 * the private zone key
200 * name with length name_len 203 * name with length name_len
201 * serialized record data with rd_count records 204 * serialized record data with rd_count records
202 */ 205 */
@@ -214,14 +217,20 @@ struct ZoneToNameMessage
214 struct GNUNET_NAMESTORE_Header gns_header; 217 struct GNUNET_NAMESTORE_Header gns_header;
215 218
216 /** 219 /**
217 * The private key of the zone to look up in 220 * Length of the zone key
221 */
222 uint32_t key_len GNUNET_PACKED;
223
224 /**
225 * Length of the public value zone key
218 */ 226 */
219 struct GNUNET_IDENTITY_PrivateKey zone; 227 uint32_t pkey_len GNUNET_PACKED;
220 228
221 /** 229 /**
222 * The public key of the target zone 230 * Followed by
231 * - the private zone key to look up in
232 * - the public key of the target zone
223 */ 233 */
224 struct GNUNET_IDENTITY_PublicKey value_zone;
225}; 234};
226 235
227 236
@@ -259,11 +268,12 @@ struct ZoneToNameResponseMessage
259 int32_t ec GNUNET_PACKED; 268 int32_t ec GNUNET_PACKED;
260 269
261 /** 270 /**
262 * The private key of the zone that contained the name. 271 * Length of the zone key
263 */ 272 */
264 struct GNUNET_IDENTITY_PrivateKey zone; 273 uint32_t key_len GNUNET_PACKED;
265 274
266 /* followed by: 275 /* followed by:
276 * the private zone key
267 * name with length name_len 277 * name with length name_len
268 * serialized record data with rd_count records 278 * serialized record data with rd_count records
269 */ 279 */
@@ -307,11 +317,12 @@ struct RecordResultMessage
307 uint16_t reserved GNUNET_PACKED; 317 uint16_t reserved GNUNET_PACKED;
308 318
309 /** 319 /**
310 * The private key of the authority. 320 * Length of the zone key
311 */ 321 */
312 struct GNUNET_IDENTITY_PrivateKey private_key; 322 uint32_t key_len GNUNET_PACKED;
313 323
314 /* followed by: 324 /* followed by:
325 * the private key of the authority
315 * name with length name_len 326 * name with length name_len
316 * serialized record data with rd_count records 327 * serialized record data with rd_count records
317 */ 328 */
@@ -386,9 +397,13 @@ struct ZoneMonitorStartMessage
386 uint16_t reserved; 397 uint16_t reserved;
387 398
388 /** 399 /**
389 * Zone key. 400 * Length of the zone key
401 */
402 uint32_t key_len GNUNET_PACKED;
403
404 /**
405 * Followed by the private zone key.
390 */ 406 */
391 struct GNUNET_IDENTITY_PrivateKey zone;
392}; 407};
393 408
394 409
@@ -427,11 +442,6 @@ struct ZoneIterationStartMessage
427 struct GNUNET_NAMESTORE_Header gns_header; 442 struct GNUNET_NAMESTORE_Header gns_header;
428 443
429 /** 444 /**
430 * Zone key. All zeros for "all zones".
431 */
432 struct GNUNET_IDENTITY_PrivateKey zone;
433
434 /**
435 * Record set filter control flags. 445 * Record set filter control flags.
436 * See GNUNET_NAMESTORE_Filter enum. 446 * See GNUNET_NAMESTORE_Filter enum.
437 */ 447 */
@@ -441,6 +451,15 @@ struct ZoneIterationStartMessage
441 * Reserved for alignment 451 * Reserved for alignment
442 */ 452 */
443 uint16_t reserved; 453 uint16_t reserved;
454
455 /**
456 * Length of the zone key
457 */
458 uint32_t key_len GNUNET_PACKED;
459
460 /**
461 * Followed by the private zone key (optional)
462 */
444}; 463};
445 464
446 465
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 41c1fcc73..e020b9e42 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -401,18 +401,20 @@ check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
401 size_t msg_len; 401 size_t msg_len;
402 size_t name_len; 402 size_t name_len;
403 size_t rd_len; 403 size_t rd_len;
404 size_t key_len;
404 405
405 (void) cls; 406 (void) cls;
406 rd_len = ntohs (msg->rd_len); 407 rd_len = ntohs (msg->rd_len);
407 msg_len = ntohs (msg->gns_header.header.size); 408 msg_len = ntohs (msg->gns_header.header.size);
408 name_len = ntohs (msg->name_len); 409 name_len = ntohs (msg->name_len);
409 exp_msg_len = sizeof(*msg) + name_len + rd_len; 410 key_len = ntohl (msg->key_len);
411 exp_msg_len = sizeof(*msg) + name_len + rd_len + key_len;
410 if (msg_len != exp_msg_len) 412 if (msg_len != exp_msg_len)
411 { 413 {
412 GNUNET_break (0); 414 GNUNET_break (0);
413 return GNUNET_SYSERR; 415 return GNUNET_SYSERR;
414 } 416 }
415 name = (const char *) &msg[1]; 417 name = (const char *) &msg[1] + key_len;
416 if ((name_len > 0) && ('\0' != name[name_len - 1])) 418 if ((name_len > 0) && ('\0' != name[name_len - 1]))
417 { 419 {
418 GNUNET_break (0); 420 GNUNET_break (0);
@@ -443,10 +445,13 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
443{ 445{
444 struct GNUNET_NAMESTORE_Handle *h = cls; 446 struct GNUNET_NAMESTORE_Handle *h = cls;
445 struct GNUNET_NAMESTORE_QueueEntry *qe; 447 struct GNUNET_NAMESTORE_QueueEntry *qe;
448 struct GNUNET_IDENTITY_PrivateKey private_key;
446 const char *name; 449 const char *name;
447 const char *rd_tmp; 450 const char *rd_tmp;
448 size_t name_len; 451 size_t name_len;
449 size_t rd_len; 452 size_t rd_len;
453 size_t key_len;
454 size_t kbytes_read;
450 unsigned int rd_count; 455 unsigned int rd_count;
451 int16_t found = (int16_t) ntohs (msg->found); 456 int16_t found = (int16_t) ntohs (msg->found);
452 457
@@ -458,12 +463,19 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
458 rd_len = ntohs (msg->rd_len); 463 rd_len = ntohs (msg->rd_len);
459 rd_count = ntohs (msg->rd_count); 464 rd_count = ntohs (msg->rd_count);
460 name_len = ntohs (msg->name_len); 465 name_len = ntohs (msg->name_len);
461 name = (const char *) &msg[1]; 466 key_len = ntohl (msg->key_len);
467 GNUNET_assert (GNUNET_SYSERR !=
468 GNUNET_IDENTITY_read_private_key_from_buffer (&msg[1],
469 key_len,
470 &private_key,
471 &kbytes_read));
472 GNUNET_assert (kbytes_read == key_len);
473 name = (const char *) &msg[1] + key_len;
462 if (GNUNET_NO == found) 474 if (GNUNET_NO == found)
463 { 475 {
464 /* label was not in namestore */ 476 /* label was not in namestore */
465 if (NULL != qe->proc) 477 if (NULL != qe->proc)
466 qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL); 478 qe->proc (qe->proc_cls, &private_key, name, 0, NULL);
467 free_qe (qe); 479 free_qe (qe);
468 return; 480 return;
469 } 481 }
@@ -486,7 +498,7 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
486 name = NULL; 498 name = NULL;
487 if (NULL != qe->proc) 499 if (NULL != qe->proc)
488 qe->proc (qe->proc_cls, 500 qe->proc (qe->proc_cls,
489 &msg->private_key, 501 &private_key,
490 name, 502 name,
491 rd_count, 503 rd_count,
492 (rd_count > 0) ? rd : NULL); 504 (rd_count > 0) ? rd : NULL);
@@ -506,33 +518,35 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
506static int 518static int
507check_record_result (void *cls, const struct RecordResultMessage *msg) 519check_record_result (void *cls, const struct RecordResultMessage *msg)
508{ 520{
509 static struct GNUNET_IDENTITY_PrivateKey priv_dummy;
510 const char *name; 521 const char *name;
511 size_t msg_len; 522 size_t msg_len;
512 size_t name_len; 523 size_t name_len;
513 size_t rd_len; 524 size_t rd_len;
525 size_t key_len;
514 526
515 (void) cls; 527 (void) cls;
516 rd_len = ntohs (msg->rd_len); 528 rd_len = ntohs (msg->rd_len);
517 msg_len = ntohs (msg->gns_header.header.size); 529 msg_len = ntohs (msg->gns_header.header.size);
530 key_len = ntohl (msg->key_len);
518 name_len = ntohs (msg->name_len); 531 name_len = ntohs (msg->name_len);
519 if (0 != ntohs (msg->reserved)) 532 if (0 != ntohs (msg->reserved))
520 { 533 {
521 GNUNET_break (0); 534 GNUNET_break (0);
522 return GNUNET_SYSERR; 535 return GNUNET_SYSERR;
523 } 536 }
524 if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len) 537 if (msg_len != sizeof(struct RecordResultMessage) + key_len + name_len
538 + rd_len)
525 { 539 {
526 GNUNET_break (0); 540 GNUNET_break (0);
527 return GNUNET_SYSERR; 541 return GNUNET_SYSERR;
528 } 542 }
529 name = (const char *) &msg[1]; 543 name = (const char *) &msg[1] + key_len;
530 if ((0 == name_len) || ('\0' != name[name_len - 1])) 544 if ((0 == name_len) || ('\0' != name[name_len - 1]))
531 { 545 {
532 GNUNET_break (0); 546 GNUNET_break (0);
533 return GNUNET_SYSERR; 547 return GNUNET_SYSERR;
534 } 548 }
535 if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy)) 549 if (0 == key_len)
536 { 550 {
537 GNUNET_break (0); 551 GNUNET_break (0);
538 return GNUNET_SYSERR; 552 return GNUNET_SYSERR;
@@ -554,16 +568,20 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
554 struct GNUNET_NAMESTORE_Handle *h = cls; 568 struct GNUNET_NAMESTORE_Handle *h = cls;
555 struct GNUNET_NAMESTORE_QueueEntry *qe; 569 struct GNUNET_NAMESTORE_QueueEntry *qe;
556 struct GNUNET_NAMESTORE_ZoneIterator *ze; 570 struct GNUNET_NAMESTORE_ZoneIterator *ze;
571 struct GNUNET_IDENTITY_PrivateKey private_key;
557 const char *name; 572 const char *name;
558 const char *rd_tmp; 573 const char *rd_tmp;
559 size_t name_len; 574 size_t name_len;
560 size_t rd_len; 575 size_t rd_len;
576 size_t key_len;
577 size_t kbytes_read;
561 unsigned int rd_count; 578 unsigned int rd_count;
562 579
563 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n"); 580 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
564 rd_len = ntohs (msg->rd_len); 581 rd_len = ntohs (msg->rd_len);
565 rd_count = ntohs (msg->rd_count); 582 rd_count = ntohs (msg->rd_count);
566 name_len = ntohs (msg->name_len); 583 name_len = ntohs (msg->name_len);
584 key_len = ntohl (msg->key_len);
567 ze = find_zi (h, ntohl (msg->gns_header.r_id)); 585 ze = find_zi (h, ntohl (msg->gns_header.r_id));
568 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 586 qe = find_qe (h, ntohl (msg->gns_header.r_id));
569 if ((NULL == ze) && (NULL == qe)) 587 if ((NULL == ze) && (NULL == qe))
@@ -574,7 +592,13 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
574 force_reconnect (h); 592 force_reconnect (h);
575 return; 593 return;
576 } 594 }
577 name = (const char *) &msg[1]; 595 name = (const char *) &msg[1] + key_len;
596 GNUNET_assert (GNUNET_SYSERR !=
597 GNUNET_IDENTITY_read_private_key_from_buffer (&msg[1],
598 key_len,
599 &private_key,
600 &kbytes_read));
601 GNUNET_assert (kbytes_read == key_len);
578 rd_tmp = &name[name_len]; 602 rd_tmp = &name[name_len];
579 { 603 {
580 struct GNUNET_GNSRECORD_Data rd[rd_count]; 604 struct GNUNET_GNSRECORD_Data rd[rd_count];
@@ -588,7 +612,7 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
588 { 612 {
589 if (NULL != qe->proc) 613 if (NULL != qe->proc)
590 qe->proc (qe->proc_cls, 614 qe->proc (qe->proc_cls,
591 &msg->private_key, 615 &private_key,
592 name, 616 name,
593 rd_count, 617 rd_count,
594 (rd_count > 0) ? rd : NULL); 618 (rd_count > 0) ? rd : NULL);
@@ -598,9 +622,9 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
598 if (NULL != ze) 622 if (NULL != ze)
599 { 623 {
600 if (NULL != ze->proc) 624 if (NULL != ze->proc)
601 ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd); 625 ze->proc (ze->proc_cls, &private_key, name, rd_count, rd);
602 if (NULL != ze->proc2) 626 if (NULL != ze->proc2)
603 ze->proc2 (ze->proc_cls, &msg->private_key, name, 627 ze->proc2 (ze->proc_cls, &private_key, name,
604 rd_count, rd, GNUNET_TIME_absolute_ntoh (msg->expire)); 628 rd_count, rd, GNUNET_TIME_absolute_ntoh (msg->expire));
605 return; 629 return;
606 } 630 }
@@ -680,20 +704,23 @@ check_zone_to_name_response (void *cls,
680{ 704{
681 size_t name_len; 705 size_t name_len;
682 size_t rd_ser_len; 706 size_t rd_ser_len;
707 size_t key_len;
683 const char *name_tmp; 708 const char *name_tmp;
684 709
685 (void) cls; 710 (void) cls;
686 if (GNUNET_EC_NONE != ntohl (msg->ec)) 711 if (GNUNET_EC_NONE != ntohl (msg->ec))
687 return GNUNET_OK; 712 return GNUNET_OK;
713 key_len = ntohl (msg->key_len);
688 name_len = ntohs (msg->name_len); 714 name_len = ntohs (msg->name_len);
689 rd_ser_len = ntohs (msg->rd_len); 715 rd_ser_len = ntohs (msg->rd_len);
690 if (ntohs (msg->gns_header.header.size) != 716 if (ntohs (msg->gns_header.header.size) !=
691 sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len) 717 sizeof(struct ZoneToNameResponseMessage) + key_len + name_len
718 + rd_ser_len)
692 { 719 {
693 GNUNET_break (0); 720 GNUNET_break (0);
694 return GNUNET_SYSERR; 721 return GNUNET_SYSERR;
695 } 722 }
696 name_tmp = (const char *) &msg[1]; 723 name_tmp = (const char *) &msg[1] + key_len;
697 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1])) 724 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
698 { 725 {
699 GNUNET_break (0); 726 GNUNET_break (0);
@@ -716,12 +743,15 @@ handle_zone_to_name_response (void *cls,
716{ 743{
717 struct GNUNET_NAMESTORE_Handle *h = cls; 744 struct GNUNET_NAMESTORE_Handle *h = cls;
718 struct GNUNET_NAMESTORE_QueueEntry *qe; 745 struct GNUNET_NAMESTORE_QueueEntry *qe;
746 struct GNUNET_IDENTITY_PrivateKey zone;
719 enum GNUNET_ErrorCode res; 747 enum GNUNET_ErrorCode res;
720 size_t name_len; 748 size_t name_len;
721 size_t rd_ser_len; 749 size_t rd_ser_len;
722 unsigned int rd_count; 750 unsigned int rd_count;
723 const char *name_tmp; 751 const char *name_tmp;
724 const char *rd_tmp; 752 const char *rd_tmp;
753 size_t key_len;
754 size_t kbytes_read;
725 755
726 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n"); 756 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
727 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 757 qe = find_qe (h, ntohl (msg->gns_header.r_id));
@@ -732,6 +762,13 @@ handle_zone_to_name_response (void *cls,
732 return; 762 return;
733 } 763 }
734 res = ntohl (msg->ec); 764 res = ntohl (msg->ec);
765 key_len = ntohl (msg->key_len);
766 GNUNET_assert (GNUNET_SYSERR !=
767 GNUNET_IDENTITY_read_private_key_from_buffer (&msg[1],
768 key_len,
769 &zone,
770 &kbytes_read));
771 GNUNET_assert (kbytes_read == key_len);
735 switch (res) 772 switch (res)
736 { 773 {
737 break; 774 break;
@@ -740,7 +777,7 @@ handle_zone_to_name_response (void *cls,
740 LOG (GNUNET_ERROR_TYPE_DEBUG, 777 LOG (GNUNET_ERROR_TYPE_DEBUG,
741 "Namestore has no result for zone to name mapping \n"); 778 "Namestore has no result for zone to name mapping \n");
742 if (NULL != qe->proc) 779 if (NULL != qe->proc)
743 qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL); 780 qe->proc (qe->proc_cls, &zone, NULL, 0, NULL);
744 free_qe (qe); 781 free_qe (qe);
745 return; 782 return;
746 783
@@ -750,7 +787,7 @@ handle_zone_to_name_response (void *cls,
750 name_len = ntohs (msg->name_len); 787 name_len = ntohs (msg->name_len);
751 rd_count = ntohs (msg->rd_count); 788 rd_count = ntohs (msg->rd_count);
752 rd_ser_len = ntohs (msg->rd_len); 789 rd_ser_len = ntohs (msg->rd_len);
753 name_tmp = (const char *) &msg[1]; 790 name_tmp = (const char *) &msg[1] + key_len;
754 rd_tmp = &name_tmp[name_len]; 791 rd_tmp = &name_tmp[name_len];
755 { 792 {
756 struct GNUNET_GNSRECORD_Data rd[rd_count]; 793 struct GNUNET_GNSRECORD_Data rd[rd_count];
@@ -762,7 +799,7 @@ handle_zone_to_name_response (void *cls,
762 rd)); 799 rd));
763 /* normal end, call continuation with result */ 800 /* normal end, call continuation with result */
764 if (NULL != qe->proc) 801 if (NULL != qe->proc)
765 qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd); 802 qe->proc (qe->proc_cls, &zone, name_tmp, rd_count, rd);
766 /* return is important here: break would call continuation with error! */ 803 /* return is important here: break would call continuation with error! */
767 free_qe (qe); 804 free_qe (qe);
768 return; 805 return;
@@ -1050,7 +1087,10 @@ GNUNET_NAMESTORE_records_store2 (
1050 ssize_t sret; 1087 ssize_t sret;
1051 int i; 1088 int i;
1052 size_t rd_set_len = 0; 1089 size_t rd_set_len = 0;
1053 size_t max_len = UINT16_MAX - sizeof (struct RecordStoreMessage); 1090 size_t key_len = 0;
1091 size_t max_len;
1092 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1093 max_len = UINT16_MAX - key_len - sizeof (struct RecordStoreMessage);
1054 1094
1055 *rds_sent = 0; 1095 *rds_sent = 0;
1056 for (i = 0; i < rd_set_count; i++) 1096 for (i = 0; i < rd_set_count; i++)
@@ -1093,17 +1133,19 @@ GNUNET_NAMESTORE_records_store2 (
1093 qe->cont_cls = cont_cls; 1133 qe->cont_cls = cont_cls;
1094 qe->op_id = rid; 1134 qe->op_id = rid;
1095 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1135 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1096
1097 /* setup msg */ 1136 /* setup msg */
1098 env = GNUNET_MQ_msg_extra (msg, 1137 env = GNUNET_MQ_msg_extra (msg,
1099 rd_set_len, 1138 key_len + rd_set_len,
1100 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); 1139 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE);
1101 GNUNET_assert (NULL != msg); 1140 GNUNET_assert (NULL != msg);
1102 GNUNET_assert (NULL != env); 1141 GNUNET_assert (NULL != env);
1103 msg->gns_header.r_id = htonl (rid); 1142 msg->gns_header.r_id = htonl (rid);
1143 msg->key_len = htonl (key_len);
1104 msg->rd_set_count = htons ((uint16_t) (*rds_sent)); 1144 msg->rd_set_count = htons ((uint16_t) (*rds_sent));
1105 msg->private_key = *pkey; 1145 GNUNET_IDENTITY_write_private_key_to_buffer (pkey,
1106 rd_set = (struct RecordSet*) &msg[1]; 1146 &msg[1],
1147 key_len);
1148 rd_set = (struct RecordSet*) (((char*) &msg[1]) + key_len);
1107 for (int i = 0; i < *rds_sent; i++) 1149 for (int i = 0; i < *rds_sent; i++)
1108 { 1150 {
1109 label = record_info[i].a_label; 1151 label = record_info[i].a_label;
@@ -1162,6 +1204,7 @@ records_lookup (
1162 struct GNUNET_MQ_Envelope *env; 1204 struct GNUNET_MQ_Envelope *env;
1163 struct LabelLookupMessage *msg; 1205 struct LabelLookupMessage *msg;
1164 size_t label_len; 1206 size_t label_len;
1207 size_t key_len;
1165 1208
1166 if (1 == (label_len = strlen (label) + 1)) 1209 if (1 == (label_len = strlen (label) + 1))
1167 { 1210 {
@@ -1178,15 +1221,20 @@ records_lookup (
1178 qe->op_id = get_op_id (h); 1221 qe->op_id = get_op_id (h);
1179 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1222 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1180 1223
1224 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1181 env = GNUNET_MQ_msg_extra (msg, 1225 env = GNUNET_MQ_msg_extra (msg,
1182 label_len, 1226 label_len + key_len,
1183 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP); 1227 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP);
1184 msg->gns_header.r_id = htonl (qe->op_id); 1228 msg->gns_header.r_id = htonl (qe->op_id);
1185 msg->zone = *pkey; 1229 GNUNET_IDENTITY_write_private_key_to_buffer (pkey,
1230 &msg[1],
1231 key_len);
1232
1233 msg->key_len = htonl (key_len);
1186 msg->is_edit_request = htonl (is_edit_request); 1234 msg->is_edit_request = htonl (is_edit_request);
1187 msg->label_len = htonl (label_len); 1235 msg->label_len = htonl (label_len);
1188 msg->filter = htons (filter); 1236 msg->filter = htons (filter);
1189 GNUNET_memcpy (&msg[1], label, label_len); 1237 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1190 if (NULL == h->mq) 1238 if (NULL == h->mq)
1191 qe->env = env; 1239 qe->env = env;
1192 else 1240 else
@@ -1257,6 +1305,8 @@ GNUNET_NAMESTORE_zone_to_name (
1257 struct GNUNET_MQ_Envelope *env; 1305 struct GNUNET_MQ_Envelope *env;
1258 struct ZoneToNameMessage *msg; 1306 struct ZoneToNameMessage *msg;
1259 uint32_t rid; 1307 uint32_t rid;
1308 size_t key_len;
1309 ssize_t pkey_len;
1260 1310
1261 rid = get_op_id (h); 1311 rid = get_op_id (h);
1262 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1312 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
@@ -1268,10 +1318,17 @@ GNUNET_NAMESTORE_zone_to_name (
1268 qe->op_id = rid; 1318 qe->op_id = rid;
1269 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1319 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1270 1320
1271 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); 1321 key_len = GNUNET_IDENTITY_private_key_get_length (zone);
1322 pkey_len = GNUNET_IDENTITY_public_key_get_length (value_zone);
1323 env = GNUNET_MQ_msg_extra (msg, key_len + pkey_len,
1324 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
1272 msg->gns_header.r_id = htonl (rid); 1325 msg->gns_header.r_id = htonl (rid);
1273 msg->zone = *zone; 1326 msg->key_len = htonl (key_len);
1274 msg->value_zone = *value_zone; 1327 msg->pkey_len = htonl (pkey_len);
1328 GNUNET_IDENTITY_write_private_key_to_buffer (zone, &msg[1], key_len);
1329 GNUNET_IDENTITY_write_public_key_to_buffer (value_zone,
1330 (char*) &msg[1] + key_len,
1331 pkey_len);
1275 if (NULL == h->mq) 1332 if (NULL == h->mq)
1276 qe->env = env; 1333 qe->env = env;
1277 else 1334 else
@@ -1295,6 +1352,7 @@ GNUNET_NAMESTORE_zone_iteration_start (
1295 struct GNUNET_MQ_Envelope *env; 1352 struct GNUNET_MQ_Envelope *env;
1296 struct ZoneIterationStartMessage *msg; 1353 struct ZoneIterationStartMessage *msg;
1297 uint32_t rid; 1354 uint32_t rid;
1355 size_t key_len = 0;
1298 1356
1299 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); 1357 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1300 rid = get_op_id (h); 1358 rid = get_op_id (h);
@@ -1308,12 +1366,18 @@ GNUNET_NAMESTORE_zone_iteration_start (
1308 it->proc_cls = proc_cls; 1366 it->proc_cls = proc_cls;
1309 it->op_id = rid; 1367 it->op_id = rid;
1310 if (NULL != zone) 1368 if (NULL != zone)
1369 {
1311 it->zone = *zone; 1370 it->zone = *zone;
1371 key_len = GNUNET_IDENTITY_private_key_get_length (zone);
1372 }
1312 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); 1373 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1313 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); 1374 env = GNUNET_MQ_msg_extra (msg,
1375 key_len,
1376 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1314 msg->gns_header.r_id = htonl (rid); 1377 msg->gns_header.r_id = htonl (rid);
1378 msg->key_len = htonl (key_len);
1315 if (NULL != zone) 1379 if (NULL != zone)
1316 msg->zone = *zone; 1380 GNUNET_IDENTITY_write_private_key_to_buffer (zone, &msg[1], key_len);
1317 if (NULL == h->mq) 1381 if (NULL == h->mq)
1318 it->env = env; 1382 it->env = env;
1319 else 1383 else
@@ -1337,6 +1401,7 @@ GNUNET_NAMESTORE_zone_iteration_start2 (
1337 struct GNUNET_MQ_Envelope *env; 1401 struct GNUNET_MQ_Envelope *env;
1338 struct ZoneIterationStartMessage *msg; 1402 struct ZoneIterationStartMessage *msg;
1339 uint32_t rid; 1403 uint32_t rid;
1404 size_t key_len = 0;
1340 1405
1341 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); 1406 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1342 rid = get_op_id (h); 1407 rid = get_op_id (h);
@@ -1350,13 +1415,19 @@ GNUNET_NAMESTORE_zone_iteration_start2 (
1350 it->proc_cls = proc_cls; 1415 it->proc_cls = proc_cls;
1351 it->op_id = rid; 1416 it->op_id = rid;
1352 if (NULL != zone) 1417 if (NULL != zone)
1418 {
1353 it->zone = *zone; 1419 it->zone = *zone;
1420 key_len = GNUNET_IDENTITY_private_key_get_length (zone);
1421 }
1354 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); 1422 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1355 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); 1423 env = GNUNET_MQ_msg_extra (msg,
1424 key_len,
1425 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1356 msg->gns_header.r_id = htonl (rid); 1426 msg->gns_header.r_id = htonl (rid);
1427 msg->key_len = htonl (key_len);
1357 msg->filter = htons ((uint16_t) filter); 1428 msg->filter = htons ((uint16_t) filter);
1358 if (NULL != zone) 1429 if (NULL != zone)
1359 msg->zone = *zone; 1430 GNUNET_IDENTITY_write_private_key_to_buffer (zone, &msg[1], key_len);
1360 if (NULL == h->mq) 1431 if (NULL == h->mq)
1361 it->env = env; 1432 it->env = env;
1362 else 1433 else
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 56ae8cb53..81ea41f7d 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -98,6 +98,11 @@ struct GNUNET_NAMESTORE_ZoneMonitor
98 * Do we first iterate over all existing records? 98 * Do we first iterate over all existing records?
99 */ 99 */
100 int iterate_first; 100 int iterate_first;
101
102 /**
103 * Zone key length
104 */
105 uint32_t key_len;
101}; 106};
102 107
103 108
@@ -146,10 +151,12 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
146 unsigned rd_count; 151 unsigned rd_count;
147 const char *name_tmp; 152 const char *name_tmp;
148 const char *rd_ser_tmp; 153 const char *rd_ser_tmp;
154 size_t key_len;
149 155
156 (void) zm;
157 key_len = ntohl (lrm->key_len);
150 (void) cls; 158 (void) cls;
151 if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) && 159 if (0 == key_len)
152 (GNUNET_NO == GNUNET_is_zero (&zm->zone)))
153 { 160 {
154 GNUNET_break (0); 161 GNUNET_break (0);
155 return GNUNET_SYSERR; 162 return GNUNET_SYSERR;
@@ -163,7 +170,7 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
163 GNUNET_break (0); 170 GNUNET_break (0);
164 return GNUNET_SYSERR; 171 return GNUNET_SYSERR;
165 } 172 }
166 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len; 173 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len + key_len;
167 if (lrm_len != exp_lrm_len) 174 if (lrm_len != exp_lrm_len)
168 { 175 {
169 GNUNET_break (0); 176 GNUNET_break (0);
@@ -174,7 +181,7 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
174 GNUNET_break (0); 181 GNUNET_break (0);
175 return GNUNET_SYSERR; 182 return GNUNET_SYSERR;
176 } 183 }
177 name_tmp = (const char *) &lrm[1]; 184 name_tmp = (const char *) &lrm[1] + key_len;
178 if (name_tmp[name_len - 1] != '\0') 185 if (name_tmp[name_len - 1] != '\0')
179 { 186 {
180 GNUNET_break (0); 187 GNUNET_break (0);
@@ -206,16 +213,26 @@ static void
206handle_result (void *cls, const struct RecordResultMessage *lrm) 213handle_result (void *cls, const struct RecordResultMessage *lrm)
207{ 214{
208 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 215 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
216 struct GNUNET_IDENTITY_PrivateKey private_key;
209 size_t name_len; 217 size_t name_len;
210 size_t rd_len; 218 size_t rd_len;
219 size_t key_len;
220 size_t kbytes_read;
211 unsigned rd_count; 221 unsigned rd_count;
212 const char *name_tmp; 222 const char *name_tmp;
213 const char *rd_ser_tmp; 223 const char *rd_ser_tmp;
214 224
225 key_len = ntohl (lrm->key_len);
215 rd_len = ntohs (lrm->rd_len); 226 rd_len = ntohs (lrm->rd_len);
216 rd_count = ntohs (lrm->rd_count); 227 rd_count = ntohs (lrm->rd_count);
217 name_len = ntohs (lrm->name_len); 228 name_len = ntohs (lrm->name_len);
218 name_tmp = (const char *) &lrm[1]; 229 name_tmp = (const char *) &lrm[1] + key_len;
230 GNUNET_assert (GNUNET_SYSERR !=
231 GNUNET_IDENTITY_read_private_key_from_buffer (&lrm[1],
232 key_len,
233 &private_key,
234 &kbytes_read));
235 GNUNET_assert (kbytes_read == key_len);
219 rd_ser_tmp = (const char *) &name_tmp[name_len]; 236 rd_ser_tmp = (const char *) &name_tmp[name_len];
220 { 237 {
221 struct GNUNET_GNSRECORD_Data rd[rd_count]; 238 struct GNUNET_GNSRECORD_Data rd[rd_count];
@@ -224,10 +241,10 @@ handle_result (void *cls, const struct RecordResultMessage *lrm)
224 GNUNET_OK == 241 GNUNET_OK ==
225 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)); 242 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd));
226 if (NULL != zm->monitor2) 243 if (NULL != zm->monitor2)
227 zm->monitor2 (zm->monitor_cls, &lrm->private_key, name_tmp, 244 zm->monitor2 (zm->monitor_cls, &private_key, name_tmp,
228 rd_count, rd, GNUNET_TIME_absolute_ntoh (lrm->expire)); 245 rd_count, rd, GNUNET_TIME_absolute_ntoh (lrm->expire));
229 else 246 else
230 zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); 247 zm->monitor (zm->monitor_cls, &private_key, name_tmp, rd_count, rd);
231 } 248 }
232} 249}
233 250
@@ -283,9 +300,15 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
283 zm); 300 zm);
284 if (NULL == zm->mq) 301 if (NULL == zm->mq)
285 return; 302 return;
286 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); 303 env = GNUNET_MQ_msg_extra (sm,
304 zm->key_len,
305 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
287 sm->iterate_first = htonl (zm->iterate_first); 306 sm->iterate_first = htonl (zm->iterate_first);
288 sm->zone = zm->zone; 307 if (0 < zm->key_len)
308 GNUNET_IDENTITY_write_private_key_to_buffer (&zm->zone,
309 &sm[1],
310 zm->key_len);
311 sm->key_len = htonl (zm->key_len);
289 sm->filter = htons (zm->filter); 312 sm->filter = htons (zm->filter);
290 GNUNET_MQ_send (zm->mq, env); 313 GNUNET_MQ_send (zm->mq, env);
291} 314}
@@ -307,7 +330,10 @@ GNUNET_NAMESTORE_zone_monitor_start (
307 330
308 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor); 331 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
309 if (NULL != zone) 332 if (NULL != zone)
333 {
334 zm->key_len = GNUNET_IDENTITY_private_key_get_length (zone);
310 zm->zone = *zone; 335 zm->zone = *zone;
336 }
311 zm->iterate_first = iterate_first; 337 zm->iterate_first = iterate_first;
312 zm->error_cb = error_cb; 338 zm->error_cb = error_cb;
313 zm->error_cb_cls = error_cb_cls; 339 zm->error_cb_cls = error_cb_cls;
@@ -342,7 +368,10 @@ GNUNET_NAMESTORE_zone_monitor_start2 (
342 368
343 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor); 369 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
344 if (NULL != zone) 370 if (NULL != zone)
371 {
372 zm->key_len = GNUNET_IDENTITY_private_key_get_length (zone);
345 zm->zone = *zone; 373 zm->zone = *zone;
374 }
346 zm->iterate_first = iterate_first; 375 zm->iterate_first = iterate_first;
347 zm->error_cb = error_cb; 376 zm->error_cb = error_cb;
348 zm->error_cb_cls = error_cb_cls; 377 zm->error_cb_cls = error_cb_cls;
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index d29b5857a..37af360c8 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -138,6 +138,7 @@ libgnunetreclaim_la_SOURCES = \
138 reclaim_credential.h 138 reclaim_credential.h
139libgnunetreclaim_la_LIBADD = \ 139libgnunetreclaim_la_LIBADD = \
140 $(top_builddir)/src/util/libgnunetutil.la \ 140 $(top_builddir)/src/util/libgnunetutil.la \
141 $(top_builddir)/src/identity/libgnunetidentity.la \
141 $(GN_LIBINTL) $(XLIB) 142 $(GN_LIBINTL) $(XLIB)
142libgnunetreclaim_la_LDFLAGS = \ 143libgnunetreclaim_la_LDFLAGS = \
143 $(GN_LIB_LDFLAGS) \ 144 $(GN_LIB_LDFLAGS) \
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 5c484e55d..ea97f8749 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -657,18 +657,27 @@ send_ticket_result (const struct IdpClient *client,
657 struct TicketResultMessage *irm; 657 struct TicketResultMessage *irm;
658 struct GNUNET_MQ_Envelope *env; 658 struct GNUNET_MQ_Envelope *env;
659 size_t pres_len = 0; 659 size_t pres_len = 0;
660 size_t tkt_len = 0;
661 ssize_t written;
662 char *buf;
660 663
661 if (NULL != presentations) 664 if (NULL != presentations)
662 { 665 {
663 pres_len = 666 pres_len =
664 GNUNET_RECLAIM_presentation_list_serialize_get_size (presentations); 667 GNUNET_RECLAIM_presentation_list_serialize_get_size (presentations);
665 } 668 }
669 if (NULL != ticket)
670 tkt_len = GNUNET_RECLAIM_ticket_serialize_get_size (ticket);
666 env = GNUNET_MQ_msg_extra (irm, 671 env = GNUNET_MQ_msg_extra (irm,
667 pres_len, 672 pres_len + tkt_len,
668 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); 673 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
674 buf = (char*) &irm[1];
669 if (NULL != ticket) 675 if (NULL != ticket)
670 { 676 {
671 irm->ticket = *ticket; 677 irm->tkt_len = htonl (tkt_len);
678 written = GNUNET_RECLAIM_write_ticket_to_buffer (ticket, buf, tkt_len);
679 GNUNET_assert (0 <= written);
680 buf += written;
672 } 681 }
673 // TODO add success member 682 // TODO add success member
674 irm->id = htonl (r_id); 683 irm->id = htonl (r_id);
@@ -676,7 +685,7 @@ send_ticket_result (const struct IdpClient *client,
676 if (NULL != presentations) 685 if (NULL != presentations)
677 { 686 {
678 GNUNET_RECLAIM_presentation_list_serialize (presentations, 687 GNUNET_RECLAIM_presentation_list_serialize (presentations,
679 (char*) &irm[1]); 688 buf);
680 } 689 }
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); 690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n");
682 GNUNET_MQ_send (client->mq, env); 691 GNUNET_MQ_send (client->mq, env);
@@ -732,11 +741,15 @@ check_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
732{ 741{
733 uint16_t size; 742 uint16_t size;
734 size_t attrs_len; 743 size_t attrs_len;
744 size_t key_len;
745 size_t pkey_len;
735 746
736 size = ntohs (im->header.size); 747 size = ntohs (im->header.size);
737 attrs_len = ntohs (im->attr_len); 748 attrs_len = ntohs (im->attr_len);
738 749 key_len = ntohl (im->key_len);
739 if (attrs_len > size - sizeof(struct IssueTicketMessage)) 750 pkey_len = ntohl (im->pkey_len);
751 if (size != attrs_len + key_len + pkey_len + sizeof(struct
752 IssueTicketMessage))
740 { 753 {
741 GNUNET_break (0); 754 GNUNET_break (0);
742 return GNUNET_SYSERR; 755 return GNUNET_SYSERR;
@@ -758,12 +771,43 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
758 struct IdpClient *idp = cls; 771 struct IdpClient *idp = cls;
759 struct GNUNET_RECLAIM_AttributeList *attrs; 772 struct GNUNET_RECLAIM_AttributeList *attrs;
760 struct GNUNET_RECLAIM_AttributeListEntry *le; 773 struct GNUNET_RECLAIM_AttributeListEntry *le;
774 struct GNUNET_IDENTITY_PrivateKey identity;
775 struct GNUNET_IDENTITY_PublicKey rp;
761 size_t attrs_len; 776 size_t attrs_len;
777 size_t key_len;
778 size_t pkey_len;
779 size_t read;
780 char *buf;
762 781
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n"); 782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n");
783 key_len = ntohl (im->key_len);
784 buf = (char *) &im[1];
785 if ((GNUNET_SYSERR ==
786 GNUNET_IDENTITY_read_private_key_from_buffer (buf, key_len,
787 &identity, &read)) ||
788 (read != key_len))
789 {
790 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
791 "Failed to read private key\n");
792 GNUNET_SERVICE_client_drop (idp->client);
793 return;
794 }
795 buf += read;
796 pkey_len = ntohl (im->pkey_len);
797 if ((GNUNET_SYSERR ==
798 GNUNET_IDENTITY_read_public_key_from_buffer (buf, pkey_len,
799 &rp, &read)) ||
800 (read != pkey_len))
801 {
802 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
803 "Failed to read public key\n");
804 GNUNET_SERVICE_client_drop (idp->client);
805 return;
806 }
807 buf += read;
764 tio = GNUNET_new (struct TicketIssueOperation); 808 tio = GNUNET_new (struct TicketIssueOperation);
765 attrs_len = ntohs (im->attr_len); 809 attrs_len = ntohs (im->attr_len);
766 attrs = GNUNET_RECLAIM_attribute_list_deserialize ((char *) &im[1], 810 attrs = GNUNET_RECLAIM_attribute_list_deserialize (buf,
767 attrs_len); 811 attrs_len);
768 for (le = attrs->list_head; NULL != le; le = le->next) 812 for (le = attrs->list_head; NULL != le; le = le->next)
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -772,9 +816,9 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
772 tio->r_id = ntohl (im->id); 816 tio->r_id = ntohl (im->id);
773 tio->client = idp; 817 tio->client = idp;
774 GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio); 818 GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio);
775 RECLAIM_TICKETS_issue (&im->identity, 819 RECLAIM_TICKETS_issue (&identity,
776 attrs, 820 attrs,
777 &im->rp, 821 &rp,
778 &issue_ticket_result_cb, 822 &issue_ticket_result_cb,
779 tio); 823 tio);
780 GNUNET_SERVICE_client_continue (idp->client); 824 GNUNET_SERVICE_client_continue (idp->client);
@@ -846,15 +890,44 @@ handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm)
846{ 890{
847 struct TicketRevocationOperation *rop; 891 struct TicketRevocationOperation *rop;
848 struct IdpClient *idp = cls; 892 struct IdpClient *idp = cls;
893 struct GNUNET_IDENTITY_PrivateKey identity;
894 struct GNUNET_RECLAIM_Ticket ticket;
895 size_t key_len;
896 size_t tkt_len;
897 size_t read;
898 char *buf;
849 899
850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n"); 900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n");
901 key_len = ntohl (rm->key_len);
902 buf = (char *) &rm[1];
903 if ((GNUNET_SYSERR ==
904 GNUNET_IDENTITY_read_private_key_from_buffer (buf, key_len,
905 &identity, &read)) ||
906 (read != key_len))
907 {
908 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
909 "Failed to read private key\n");
910 GNUNET_SERVICE_client_drop (idp->client);
911 return;
912 }
913 buf += read;
914 tkt_len = ntohl (rm->tkt_len);
915 if ((GNUNET_SYSERR ==
916 GNUNET_RECLAIM_read_ticket_from_buffer (buf, key_len,
917 &ticket, &read)) ||
918 (read != tkt_len))
919 {
920 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
921 "Failed to read ticket\n");
922 GNUNET_SERVICE_client_drop (idp->client);
923 return;
924 }
851 rop = GNUNET_new (struct TicketRevocationOperation); 925 rop = GNUNET_new (struct TicketRevocationOperation);
852 rop->r_id = ntohl (rm->id); 926 rop->r_id = ntohl (rm->id);
853 rop->client = idp; 927 rop->client = idp;
854 GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, idp->revoke_op_tail, rop); 928 GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, idp->revoke_op_tail, rop);
855 rop->rh 929 rop->rh
856 = RECLAIM_TICKETS_revoke (&rm->ticket, &rm->identity, &revoke_result_cb, 930 = RECLAIM_TICKETS_revoke (&ticket, &identity, &revoke_result_cb, rop);
857 rop);
858 GNUNET_SERVICE_client_continue (idp->client); 931 GNUNET_SERVICE_client_continue (idp->client);
859} 932}
860 933
@@ -882,6 +955,8 @@ consume_result_cb (void *cls,
882 char *data_tmp; 955 char *data_tmp;
883 size_t attrs_len = 0; 956 size_t attrs_len = 0;
884 size_t pres_len = 0; 957 size_t pres_len = 0;
958 size_t key_len;
959 ssize_t written;
885 960
886 if (GNUNET_OK != success) 961 if (GNUNET_OK != success)
887 { 962 {
@@ -890,17 +965,23 @@ consume_result_cb (void *cls,
890 attrs_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs); 965 attrs_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs);
891 pres_len = GNUNET_RECLAIM_presentation_list_serialize_get_size ( 966 pres_len = GNUNET_RECLAIM_presentation_list_serialize_get_size (
892 presentations); 967 presentations);
968 key_len = GNUNET_IDENTITY_public_key_get_length (identity);
893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
894 "Sending CONSUME_TICKET_RESULT message\n"); 970 "Sending CONSUME_TICKET_RESULT message\n");
895 env = GNUNET_MQ_msg_extra (crm, 971 env = GNUNET_MQ_msg_extra (crm,
896 attrs_len + pres_len, 972 attrs_len + pres_len + key_len,
897 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); 973 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT);
898 crm->id = htonl (cop->r_id); 974 crm->id = htonl (cop->r_id);
899 crm->attrs_len = htons (attrs_len); 975 crm->attrs_len = htons (attrs_len);
900 crm->presentations_len = htons (pres_len); 976 crm->presentations_len = htons (pres_len);
901 crm->identity = *identity; 977 crm->key_len = htonl (key_len);
902 crm->result = htonl (success); 978 crm->result = htonl (success);
903 data_tmp = (char *) &crm[1]; 979 data_tmp = (char *) &crm[1];
980 written = GNUNET_IDENTITY_write_public_key_to_buffer (identity,
981 data_tmp,
982 key_len);
983 GNUNET_assert (0 <= written);
984 data_tmp += written;
904 GNUNET_RECLAIM_attribute_list_serialize (attrs, data_tmp); 985 GNUNET_RECLAIM_attribute_list_serialize (attrs, data_tmp);
905 data_tmp += attrs_len; 986 data_tmp += attrs_len;
906 GNUNET_RECLAIM_presentation_list_serialize (presentations, data_tmp); 987 GNUNET_RECLAIM_presentation_list_serialize (presentations, data_tmp);
@@ -924,7 +1005,7 @@ check_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm)
924 uint16_t size; 1005 uint16_t size;
925 1006
926 size = ntohs (cm->header.size); 1007 size = ntohs (cm->header.size);
927 if (size != sizeof(struct ConsumeTicketMessage)) 1008 if (size <= sizeof(struct ConsumeTicketMessage))
928 { 1009 {
929 GNUNET_break (0); 1010 GNUNET_break (0);
930 return GNUNET_SYSERR; 1011 return GNUNET_SYSERR;
@@ -944,13 +1025,43 @@ handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm)
944{ 1025{
945 struct ConsumeTicketOperation *cop; 1026 struct ConsumeTicketOperation *cop;
946 struct IdpClient *idp = cls; 1027 struct IdpClient *idp = cls;
1028 struct GNUNET_IDENTITY_PrivateKey identity;
1029 struct GNUNET_RECLAIM_Ticket ticket;
1030 size_t key_len;
1031 size_t tkt_len;
1032 size_t read;
1033 char *buf;
947 1034
948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n"); 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n");
1036 key_len = ntohl (cm->key_len);
1037 buf = (char *) &cm[1];
1038 if ((GNUNET_SYSERR ==
1039 GNUNET_IDENTITY_read_private_key_from_buffer (buf, key_len,
1040 &identity, &read)) ||
1041 (read != key_len))
1042 {
1043 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1044 "Failed to read private key\n");
1045 GNUNET_SERVICE_client_drop (idp->client);
1046 return;
1047 }
1048 buf += read;
1049 tkt_len = ntohl (cm->tkt_len);
1050 if ((GNUNET_SYSERR ==
1051 GNUNET_RECLAIM_read_ticket_from_buffer (buf, tkt_len,
1052 &ticket, &read)) ||
1053 (read != tkt_len))
1054 {
1055 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1056 "Failed to read ticket\n");
1057 GNUNET_SERVICE_client_drop (idp->client);
1058 return;
1059 }
949 cop = GNUNET_new (struct ConsumeTicketOperation); 1060 cop = GNUNET_new (struct ConsumeTicketOperation);
950 cop->r_id = ntohl (cm->id); 1061 cop->r_id = ntohl (cm->id);
951 cop->client = idp; 1062 cop->client = idp;
952 cop->ch 1063 cop->ch
953 = RECLAIM_TICKETS_consume (&cm->identity, &cm->ticket, &consume_result_cb, 1064 = RECLAIM_TICKETS_consume (&identity, &ticket, &consume_result_cb,
954 cop); 1065 cop);
955 GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, idp->consume_op_tail, cop); 1066 GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, idp->consume_op_tail, cop);
956 GNUNET_SERVICE_client_continue (idp->client); 1067 GNUNET_SERVICE_client_continue (idp->client);
@@ -1077,21 +1188,37 @@ handle_attribute_store_message (void *cls,
1077{ 1188{
1078 struct AttributeStoreHandle *ash; 1189 struct AttributeStoreHandle *ash;
1079 struct IdpClient *idp = cls; 1190 struct IdpClient *idp = cls;
1191 struct GNUNET_IDENTITY_PrivateKey identity;
1080 size_t data_len; 1192 size_t data_len;
1193 size_t key_len;
1194 size_t read;
1195 char *buf;
1081 1196
1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_STORE message\n"); 1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_STORE message\n");
1083 1198
1084 data_len = ntohs (sam->attr_len); 1199 data_len = ntohs (sam->attr_len);
1085 1200 key_len = ntohl (sam->key_len);
1201 buf = (char *) &sam[1];
1202 if ((GNUNET_SYSERR ==
1203 GNUNET_IDENTITY_read_private_key_from_buffer (buf, key_len,
1204 &identity, &read)) ||
1205 (read != key_len))
1206 {
1207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1208 "Failed to read private key\n");
1209 GNUNET_SERVICE_client_drop (idp->client);
1210 return;
1211 }
1212 buf += read;
1086 ash = GNUNET_new (struct AttributeStoreHandle); 1213 ash = GNUNET_new (struct AttributeStoreHandle);
1087 GNUNET_RECLAIM_attribute_deserialize ((char *) &sam[1], 1214 GNUNET_RECLAIM_attribute_deserialize (buf,
1088 data_len, 1215 data_len,
1089 &ash->claim); 1216 &ash->claim);
1090 1217
1091 ash->r_id = ntohl (sam->id); 1218 ash->r_id = ntohl (sam->id);
1092 ash->identity = sam->identity; 1219 ash->identity = identity;
1093 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); 1220 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp);
1094 GNUNET_IDENTITY_key_get_public (&sam->identity, &ash->identity_pkey); 1221 GNUNET_IDENTITY_key_get_public (&identity, &ash->identity_pkey);
1095 1222
1096 GNUNET_SERVICE_client_continue (idp->client); 1223 GNUNET_SERVICE_client_continue (idp->client);
1097 ash->client = idp; 1224 ash->client = idp;
@@ -1262,20 +1389,36 @@ handle_credential_store_message (void *cls,
1262{ 1389{
1263 struct AttributeStoreHandle *ash; 1390 struct AttributeStoreHandle *ash;
1264 struct IdpClient *idp = cls; 1391 struct IdpClient *idp = cls;
1392 struct GNUNET_IDENTITY_PrivateKey identity;
1265 size_t data_len; 1393 size_t data_len;
1394 size_t key_len;
1395 size_t read;
1396 char *buf;
1266 1397
1267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREDENTIAL_STORE message\n"); 1398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREDENTIAL_STORE message\n");
1268 1399
1269 data_len = ntohs (sam->attr_len); 1400 data_len = ntohs (sam->attr_len);
1270 1401 key_len = ntohl (sam->key_len);
1402 buf = (char *) &sam[1];
1403 if ((GNUNET_SYSERR ==
1404 GNUNET_IDENTITY_read_private_key_from_buffer (buf, key_len,
1405 &identity, &read)) ||
1406 (read != key_len))
1407 {
1408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1409 "Failed to read private key\n");
1410 GNUNET_SERVICE_client_drop (idp->client);
1411 return;
1412 }
1413 buf += read;
1271 ash = GNUNET_new (struct AttributeStoreHandle); 1414 ash = GNUNET_new (struct AttributeStoreHandle);
1272 ash->credential = GNUNET_RECLAIM_credential_deserialize ((char *) &sam[1], 1415 ash->credential = GNUNET_RECLAIM_credential_deserialize (buf,
1273 data_len); 1416 data_len);
1274 1417
1275 ash->r_id = ntohl (sam->id); 1418 ash->r_id = ntohl (sam->id);
1276 ash->identity = sam->identity; 1419 ash->identity = identity;
1277 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); 1420 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp);
1278 GNUNET_IDENTITY_key_get_public (&sam->identity, &ash->identity_pkey); 1421 GNUNET_IDENTITY_key_get_public (&identity, &ash->identity_pkey);
1279 1422
1280 GNUNET_SERVICE_client_continue (idp->client); 1423 GNUNET_SERVICE_client_continue (idp->client);
1281 ash->client = idp; 1424 ash->client = idp;
@@ -1717,20 +1860,36 @@ handle_attribute_delete_message (void *cls,
1717{ 1860{
1718 struct AttributeDeleteHandle *adh; 1861 struct AttributeDeleteHandle *adh;
1719 struct IdpClient *idp = cls; 1862 struct IdpClient *idp = cls;
1863 struct GNUNET_IDENTITY_PrivateKey identity;
1720 size_t data_len; 1864 size_t data_len;
1865 size_t key_len;
1866 size_t read;
1867 char *buf;
1721 1868
1722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_DELETE message\n"); 1869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_DELETE message\n");
1723 1870
1724 data_len = ntohs (dam->attr_len); 1871 data_len = ntohs (dam->attr_len);
1725 1872 key_len = ntohl (dam->key_len);
1873 buf = (char *) &dam[1];
1874 if ((GNUNET_SYSERR ==
1875 GNUNET_IDENTITY_read_private_key_from_buffer (buf, key_len,
1876 &identity, &read)) ||
1877 (read != key_len))
1878 {
1879 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1880 "Failed to read private key\n");
1881 GNUNET_SERVICE_client_drop (idp->client);
1882 return;
1883 }
1884 buf += read;
1726 adh = GNUNET_new (struct AttributeDeleteHandle); 1885 adh = GNUNET_new (struct AttributeDeleteHandle);
1727 GNUNET_RECLAIM_attribute_deserialize ((char *) &dam[1], 1886 GNUNET_RECLAIM_attribute_deserialize (buf,
1728 data_len, 1887 data_len,
1729 &adh->claim); 1888 &adh->claim);
1730 adh->credential = NULL; 1889 adh->credential = NULL;
1731 1890
1732 adh->r_id = ntohl (dam->id); 1891 adh->r_id = ntohl (dam->id);
1733 adh->identity = dam->identity; 1892 adh->identity = identity;
1734 adh->label 1893 adh->label
1735 = GNUNET_STRINGS_data_to_string_alloc (&adh->claim->id, 1894 = GNUNET_STRINGS_data_to_string_alloc (&adh->claim->id,
1736 sizeof(adh->claim->id)); 1895 sizeof(adh->claim->id));
@@ -1808,19 +1967,35 @@ handle_credential_delete_message (void *cls,
1808{ 1967{
1809 struct AttributeDeleteHandle *adh; 1968 struct AttributeDeleteHandle *adh;
1810 struct IdpClient *idp = cls; 1969 struct IdpClient *idp = cls;
1970 struct GNUNET_IDENTITY_PrivateKey identity;
1811 size_t data_len; 1971 size_t data_len;
1972 size_t key_len;
1973 size_t read;
1974 char *buf;
1812 1975
1813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREDENTIAL_DELETE message\n"); 1976 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREDENTIAL_DELETE message\n");
1814 1977
1815 data_len = ntohs (dam->attr_len); 1978 data_len = ntohs (dam->attr_len);
1816 1979 key_len = ntohl (dam->key_len);
1980 buf = (char *) &dam[1];
1981 if ((GNUNET_SYSERR ==
1982 GNUNET_IDENTITY_read_private_key_from_buffer (buf, key_len,
1983 &identity, &read)) ||
1984 (read != key_len))
1985 {
1986 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1987 "Failed to read private key\n");
1988 GNUNET_SERVICE_client_drop (idp->client);
1989 return;
1990 }
1991 buf += read;
1817 adh = GNUNET_new (struct AttributeDeleteHandle); 1992 adh = GNUNET_new (struct AttributeDeleteHandle);
1818 adh->credential = GNUNET_RECLAIM_credential_deserialize ((char *) &dam[1], 1993 adh->credential = GNUNET_RECLAIM_credential_deserialize (buf,
1819 data_len); 1994 data_len);
1820 adh->claim = NULL; 1995 adh->claim = NULL;
1821 1996
1822 adh->r_id = ntohl (dam->id); 1997 adh->r_id = ntohl (dam->id);
1823 adh->identity = dam->identity; 1998 adh->identity = identity;
1824 adh->label 1999 adh->label
1825 = GNUNET_STRINGS_data_to_string_alloc (&adh->credential->id, 2000 = GNUNET_STRINGS_data_to_string_alloc (&adh->credential->id,
1826 sizeof(adh->credential->id)); 2001 sizeof(adh->credential->id));
@@ -1858,6 +2033,7 @@ attr_iter_finished (void *cls)
1858 env = GNUNET_MQ_msg (arm, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); 2033 env = GNUNET_MQ_msg (arm, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
1859 arm->id = htonl (ai->request_id); 2034 arm->id = htonl (ai->request_id);
1860 arm->attr_len = htons (0); 2035 arm->attr_len = htons (0);
2036 arm->pkey_len = htonl (0);
1861 GNUNET_MQ_send (ai->client->mq, env); 2037 GNUNET_MQ_send (ai->client->mq, env);
1862 GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head, 2038 GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head,
1863 ai->client->attr_iter_tail, 2039 ai->client->attr_iter_tail,
@@ -1899,7 +2075,10 @@ attr_iter_cb (void *cls,
1899{ 2075{
1900 struct Iterator *ai = cls; 2076 struct Iterator *ai = cls;
1901 struct GNUNET_MQ_Envelope *env; 2077 struct GNUNET_MQ_Envelope *env;
2078 struct GNUNET_IDENTITY_PublicKey identity;
1902 char *data_tmp; 2079 char *data_tmp;
2080 size_t key_len;
2081 ssize_t written;
1903 2082
1904 if ((rd_count != 1) || 2083 if ((rd_count != 1) ||
1905 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE != rd->record_type)) 2084 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE != rd->record_type))
@@ -1912,18 +2091,44 @@ attr_iter_cb (void *cls,
1912 label); 2091 label);
1913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1914 "Sending ATTRIBUTE_RESULT message\n"); 2093 "Sending ATTRIBUTE_RESULT message\n");
2094 GNUNET_IDENTITY_key_get_public (zone, &identity);
2095 key_len = GNUNET_IDENTITY_public_key_get_length (&identity);
1915 env = GNUNET_MQ_msg_extra (arm, 2096 env = GNUNET_MQ_msg_extra (arm,
1916 rd->data_size, 2097 rd->data_size + key_len,
1917 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); 2098 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
1918 arm->id = htonl (ai->request_id); 2099 arm->id = htonl (ai->request_id);
1919 arm->attr_len = htons (rd->data_size); 2100 arm->attr_len = htons (rd->data_size);
1920 GNUNET_IDENTITY_key_get_public (zone, &arm->identity);
1921 data_tmp = (char *) &arm[1]; 2101 data_tmp = (char *) &arm[1];
2102 arm->pkey_len = htonl (key_len);
2103 written = GNUNET_IDENTITY_write_public_key_to_buffer (&identity,
2104 data_tmp,
2105 key_len);
2106 GNUNET_assert (0 <= written);
2107 data_tmp += written;
1922 GNUNET_memcpy (data_tmp, rd->data, rd->data_size); 2108 GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
1923 GNUNET_MQ_send (ai->client->mq, env); 2109 GNUNET_MQ_send (ai->client->mq, env);
1924} 2110}
1925 2111
1926 2112
2113static enum GNUNET_GenericReturnValue
2114check_iteration_start (
2115 void *cls,
2116 const struct AttributeIterationStartMessage *ais_msg)
2117{
2118 uint16_t size;
2119 size_t key_len;
2120
2121 size = ntohs (ais_msg->header.size);
2122 key_len = ntohs (ais_msg->key_len);
2123
2124 if (size < key_len + sizeof(*ais_msg))
2125 {
2126 GNUNET_break (0);
2127 return GNUNET_SYSERR;
2128 }
2129 return GNUNET_OK;
2130}
2131
1927/** 2132/**
1928 * Iterate over zone to get attributes 2133 * Iterate over zone to get attributes
1929 * 2134 *
@@ -1936,13 +2141,29 @@ handle_iteration_start (void *cls,
1936{ 2141{
1937 struct IdpClient *idp = cls; 2142 struct IdpClient *idp = cls;
1938 struct Iterator *ai; 2143 struct Iterator *ai;
2144 struct GNUNET_IDENTITY_PrivateKey identity;
2145 size_t key_len;
2146 size_t read;
1939 2147
1940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1941 "Received ATTRIBUTE_ITERATION_START message\n"); 2149 "Received ATTRIBUTE_ITERATION_START message\n");
2150 key_len = ntohl (ais_msg->key_len);
2151 if ((GNUNET_SYSERR ==
2152 GNUNET_IDENTITY_read_private_key_from_buffer (&ais_msg[1],
2153 key_len,
2154 &identity,
2155 &read)) ||
2156 (read != key_len))
2157 {
2158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2159 "Failed to read private key.\n");
2160 GNUNET_SERVICE_client_drop (idp->client);
2161 return;
2162 }
1942 ai = GNUNET_new (struct Iterator); 2163 ai = GNUNET_new (struct Iterator);
1943 ai->request_id = ntohl (ais_msg->id); 2164 ai->request_id = ntohl (ais_msg->id);
1944 ai->client = idp; 2165 ai->client = idp;
1945 ai->identity = ais_msg->identity; 2166 ai->identity = identity;
1946 2167
1947 GNUNET_CONTAINER_DLL_insert (idp->attr_iter_head, idp->attr_iter_tail, ai); 2168 GNUNET_CONTAINER_DLL_insert (idp->attr_iter_head, idp->attr_iter_tail, ai);
1948 ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start (nsh, 2169 ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start (nsh,
@@ -2084,7 +2305,10 @@ cred_iter_cb (void *cls,
2084 struct Iterator *ai = cls; 2305 struct Iterator *ai = cls;
2085 struct GNUNET_MQ_Envelope *env; 2306 struct GNUNET_MQ_Envelope *env;
2086 struct CredentialResultMessage *arm; 2307 struct CredentialResultMessage *arm;
2308 struct GNUNET_IDENTITY_PublicKey identity;
2087 char *data_tmp; 2309 char *data_tmp;
2310 size_t key_len;
2311 ssize_t written;
2088 2312
2089 if ((rd_count != 1) || 2313 if ((rd_count != 1) ||
2090 (GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL != rd->record_type)) 2314 (GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL != rd->record_type))
@@ -2096,18 +2320,42 @@ cred_iter_cb (void *cls,
2096 label); 2320 label);
2097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2098 "Sending CREDENTIAL_RESULT message\n"); 2322 "Sending CREDENTIAL_RESULT message\n");
2323 GNUNET_IDENTITY_key_get_public (zone, &identity);
2324 key_len = GNUNET_IDENTITY_public_key_get_length (&identity);
2099 env = GNUNET_MQ_msg_extra (arm, 2325 env = GNUNET_MQ_msg_extra (arm,
2100 rd->data_size, 2326 rd->data_size + key_len,
2101 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_RESULT); 2327 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_RESULT);
2102 arm->id = htonl (ai->request_id); 2328 arm->id = htonl (ai->request_id);
2103 arm->credential_len = htons (rd->data_size); 2329 arm->credential_len = htons (rd->data_size);
2104 GNUNET_IDENTITY_key_get_public (zone, &arm->identity);
2105 data_tmp = (char *) &arm[1]; 2330 data_tmp = (char *) &arm[1];
2331 written = GNUNET_IDENTITY_write_public_key_to_buffer (&identity,
2332 data_tmp,
2333 key_len);
2334 GNUNET_assert (written >= 0);
2335 data_tmp += written;
2106 GNUNET_memcpy (data_tmp, rd->data, rd->data_size); 2336 GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
2107
2108 GNUNET_MQ_send (ai->client->mq, env); 2337 GNUNET_MQ_send (ai->client->mq, env);
2109} 2338}
2110 2339
2340static enum GNUNET_GenericReturnValue
2341check_credential_iteration_start (
2342 void *cls,
2343 const struct CredentialIterationStartMessage *cis_msg)
2344{
2345 uint16_t size;
2346 size_t key_len;
2347
2348 size = ntohs (cis_msg->header.size);
2349 key_len = ntohs (cis_msg->key_len);
2350
2351 if (size < key_len + sizeof(*cis_msg))
2352 {
2353 GNUNET_break (0);
2354 return GNUNET_SYSERR;
2355 }
2356 return GNUNET_OK;
2357}
2358
2111 2359
2112/** 2360/**
2113 * Iterate over zone to get attributes 2361 * Iterate over zone to get attributes
@@ -2122,13 +2370,29 @@ handle_credential_iteration_start (void *cls,
2122{ 2370{
2123 struct IdpClient *idp = cls; 2371 struct IdpClient *idp = cls;
2124 struct Iterator *ai; 2372 struct Iterator *ai;
2373 struct GNUNET_IDENTITY_PrivateKey identity;
2374 size_t key_len;
2375 size_t read;
2125 2376
2126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2127 "Received CREDENTIAL_ITERATION_START message\n"); 2378 "Received CREDENTIAL_ITERATION_START message\n");
2379 key_len = ntohl (ais_msg->key_len);
2380 if ((GNUNET_SYSERR ==
2381 GNUNET_IDENTITY_read_private_key_from_buffer (&ais_msg[1],
2382 key_len,
2383 &identity,
2384 &read)) ||
2385 (read != key_len))
2386 {
2387 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2388 "Failed to read private key.\n");
2389 GNUNET_SERVICE_client_drop (idp->client);
2390 return;
2391 }
2128 ai = GNUNET_new (struct Iterator); 2392 ai = GNUNET_new (struct Iterator);
2129 ai->request_id = ntohl (ais_msg->id); 2393 ai->request_id = ntohl (ais_msg->id);
2130 ai->client = idp; 2394 ai->client = idp;
2131 ai->identity = ais_msg->identity; 2395 ai->identity = identity;
2132 2396
2133 GNUNET_CONTAINER_DLL_insert (idp->cred_iter_head, idp->cred_iter_tail, 2397 GNUNET_CONTAINER_DLL_insert (idp->cred_iter_head, idp->cred_iter_tail,
2134 ai); 2398 ai);
@@ -2227,8 +2491,16 @@ ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket)
2227 struct TicketIteration *ti = cls; 2491 struct TicketIteration *ti = cls;
2228 struct GNUNET_MQ_Envelope *env; 2492 struct GNUNET_MQ_Envelope *env;
2229 struct TicketResultMessage *trm; 2493 struct TicketResultMessage *trm;
2494 size_t tkt_len;
2230 2495
2231 env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); 2496 if (NULL == ticket)
2497 tkt_len = 0;
2498 else
2499 tkt_len = GNUNET_RECLAIM_ticket_serialize_get_size (ticket);
2500
2501 env = GNUNET_MQ_msg_extra (trm,
2502 tkt_len,
2503 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
2232 if (NULL == ticket) 2504 if (NULL == ticket)
2233 { 2505 {
2234 /* send empty response to indicate end of list */ 2506 /* send empty response to indicate end of list */
@@ -2238,8 +2510,11 @@ ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket)
2238 } 2510 }
2239 else 2511 else
2240 { 2512 {
2241 trm->ticket = *ticket; 2513 GNUNET_RECLAIM_write_ticket_to_buffer (ticket,
2514 &trm[1],
2515 tkt_len);
2242 } 2516 }
2517 trm->tkt_len = htonl (tkt_len);
2243 trm->id = htonl (ti->r_id); 2518 trm->id = htonl (ti->r_id);
2244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); 2519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n");
2245 GNUNET_MQ_send (ti->client->mq, env); 2520 GNUNET_MQ_send (ti->client->mq, env);
@@ -2247,6 +2522,24 @@ ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket)
2247 GNUNET_free (ti); 2522 GNUNET_free (ti);
2248} 2523}
2249 2524
2525static enum GNUNET_GenericReturnValue
2526check_ticket_iteration_start (
2527 void *cls,
2528 const struct TicketIterationStartMessage *tis_msg)
2529{
2530 uint16_t size;
2531 size_t key_len;
2532
2533 size = ntohs (tis_msg->header.size);
2534 key_len = ntohs (tis_msg->key_len);
2535
2536 if (size < key_len + sizeof(*tis_msg))
2537 {
2538 GNUNET_break (0);
2539 return GNUNET_SYSERR;
2540 }
2541 return GNUNET_OK;
2542}
2250 2543
2251/** 2544/**
2252 * Client requests a ticket iteration 2545 * Client requests a ticket iteration
@@ -2259,20 +2552,35 @@ handle_ticket_iteration_start (
2259 void *cls, 2552 void *cls,
2260 const struct TicketIterationStartMessage *tis_msg) 2553 const struct TicketIterationStartMessage *tis_msg)
2261{ 2554{
2555 struct GNUNET_IDENTITY_PrivateKey identity;
2262 struct IdpClient *client = cls; 2556 struct IdpClient *client = cls;
2263 struct TicketIteration *ti; 2557 struct TicketIteration *ti;
2558 size_t key_len;
2559 size_t read;
2264 2560
2265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2266 "Received TICKET_ITERATION_START message\n"); 2562 "Received TICKET_ITERATION_START message\n");
2563 key_len = ntohl (tis_msg->key_len);
2564 if ((GNUNET_SYSERR ==
2565 GNUNET_IDENTITY_read_private_key_from_buffer (&tis_msg[1],
2566 key_len,
2567 &identity,
2568 &read)) ||
2569 (read != key_len))
2570 {
2571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2572 "Failed to read private key\n");
2573 GNUNET_SERVICE_client_drop (client->client);
2574 return;
2575 }
2267 ti = GNUNET_new (struct TicketIteration); 2576 ti = GNUNET_new (struct TicketIteration);
2268 ti->r_id = ntohl (tis_msg->id); 2577 ti->r_id = ntohl (tis_msg->id);
2269 ti->client = client; 2578 ti->client = client;
2270
2271 GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head, 2579 GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head,
2272 client->ticket_iter_tail, 2580 client->ticket_iter_tail,
2273 ti); 2581 ti);
2274 ti->iter 2582 ti->iter
2275 = RECLAIM_TICKETS_iteration_start (&tis_msg->identity, &ticket_iter_cb, ti); 2583 = RECLAIM_TICKETS_iteration_start (&identity, &ticket_iter_cb, ti);
2276 GNUNET_SERVICE_client_continue (client->client); 2584 GNUNET_SERVICE_client_continue (client->client);
2277} 2585}
2278 2586
@@ -2451,10 +2759,10 @@ GNUNET_SERVICE_MAIN (
2451 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_DELETE, 2759 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_DELETE,
2452 struct AttributeDeleteMessage, 2760 struct AttributeDeleteMessage,
2453 NULL), 2761 NULL),
2454 GNUNET_MQ_hd_fixed_size (iteration_start, 2762 GNUNET_MQ_hd_var_size (iteration_start,
2455 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, 2763 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START,
2456 struct AttributeIterationStartMessage, 2764 struct AttributeIterationStartMessage,
2457 NULL), 2765 NULL),
2458 GNUNET_MQ_hd_fixed_size (iteration_next, 2766 GNUNET_MQ_hd_fixed_size (iteration_next,
2459 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, 2767 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT,
2460 struct AttributeIterationNextMessage, 2768 struct AttributeIterationNextMessage,
@@ -2463,10 +2771,10 @@ GNUNET_SERVICE_MAIN (
2463 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP, 2771 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP,
2464 struct AttributeIterationStopMessage, 2772 struct AttributeIterationStopMessage,
2465 NULL), 2773 NULL),
2466 GNUNET_MQ_hd_fixed_size (credential_iteration_start, 2774 GNUNET_MQ_hd_var_size (credential_iteration_start,
2467 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_ITERATION_START, 2775 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_ITERATION_START,
2468 struct CredentialIterationStartMessage, 2776 struct CredentialIterationStartMessage,
2469 NULL), 2777 NULL),
2470 GNUNET_MQ_hd_fixed_size (credential_iteration_next, 2778 GNUNET_MQ_hd_fixed_size (credential_iteration_next,
2471 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_ITERATION_NEXT, 2779 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_ITERATION_NEXT,
2472 struct CredentialIterationNextMessage, 2780 struct CredentialIterationNextMessage,
@@ -2484,10 +2792,10 @@ GNUNET_SERVICE_MAIN (
2484 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET, 2792 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET,
2485 struct ConsumeTicketMessage, 2793 struct ConsumeTicketMessage,
2486 NULL), 2794 NULL),
2487 GNUNET_MQ_hd_fixed_size (ticket_iteration_start, 2795 GNUNET_MQ_hd_var_size (ticket_iteration_start,
2488 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START, 2796 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START,
2489 struct TicketIterationStartMessage, 2797 struct TicketIterationStartMessage,
2490 NULL), 2798 NULL),
2491 GNUNET_MQ_hd_fixed_size (ticket_iteration_next, 2799 GNUNET_MQ_hd_fixed_size (ticket_iteration_next,
2492 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT, 2800 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT,
2493 struct TicketIterationNextMessage, 2801 struct TicketIterationNextMessage,
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index 9552094f1..5e2a5e974 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -742,7 +742,8 @@ rvk_move_attr_cb (void *cls,
742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential %s\n", 742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential %s\n",
743 new_label); 743 new_label);
744 GNUNET_free (credential); 744 GNUNET_free (credential);
745 } else { 745 }
746 else {
746 memcpy (&new_rd[i], &rd[i], sizeof (struct GNUNET_GNSRECORD_Data)); 747 memcpy (&new_rd[i], &rd[i], sizeof (struct GNUNET_GNSRECORD_Data));
747 } 748 }
748 } 749 }
@@ -1197,9 +1198,11 @@ RECLAIM_TICKETS_consume (const struct GNUNET_IDENTITY_PrivateKey *id,
1197 label = 1198 label =
1198 GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, 1199 GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd,
1199 sizeof(cth->ticket.rnd)); 1200 sizeof(cth->ticket.rnd));
1201 char *str = GNUNET_IDENTITY_public_key_to_string (&cth->ticket.identity);
1200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1201 "Looking for AuthZ info under %s\n", 1203 "Looking for AuthZ info under %s in %s\n",
1202 label); 1204 label, str);
1205 GNUNET_free (str);
1203 cth->lookup_start_time = GNUNET_TIME_absolute_get (); 1206 cth->lookup_start_time = GNUNET_TIME_absolute_get ();
1204 cth->lookup_request = 1207 cth->lookup_request =
1205 GNUNET_GNS_lookup (gns, 1208 GNUNET_GNS_lookup (gns,
@@ -1289,6 +1292,7 @@ issue_ticket (struct TicketIssueHandle *ih)
1289 struct GNUNET_RECLAIM_PresentationListEntry *ple; 1292 struct GNUNET_RECLAIM_PresentationListEntry *ple;
1290 struct GNUNET_GNSRECORD_Data *attrs_record; 1293 struct GNUNET_GNSRECORD_Data *attrs_record;
1291 char *label; 1294 char *label;
1295 char *tkt_data;
1292 int i; 1296 int i;
1293 int j; 1297 int j;
1294 int attrs_count = 0; 1298 int attrs_count = 0;
@@ -1376,8 +1380,13 @@ issue_ticket (struct TicketIssueHandle *ih)
1376 } 1380 }
1377 } 1381 }
1378 } 1382 }
1379 attrs_record[i].data = &ih->ticket; 1383 attrs_record[i].data_size =
1380 attrs_record[i].data_size = sizeof(struct GNUNET_RECLAIM_Ticket); 1384 GNUNET_RECLAIM_ticket_serialize_get_size (&ih->ticket);
1385 tkt_data = GNUNET_malloc (attrs_record[i].data_size);
1386 GNUNET_RECLAIM_write_ticket_to_buffer (&ih->ticket,
1387 tkt_data,
1388 attrs_record[i].data_size);
1389 attrs_record[i].data = tkt_data;
1381 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; 1390 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
1382 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET; 1391 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET;
1383 attrs_record[i].flags = 1392 attrs_record[i].flags =
@@ -1387,6 +1396,13 @@ issue_ticket (struct TicketIssueHandle *ih)
1387 label = 1396 label =
1388 GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, 1397 GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd,
1389 sizeof(ih->ticket.rnd)); 1398 sizeof(ih->ticket.rnd));
1399 struct GNUNET_IDENTITY_PublicKey pub;
1400 GNUNET_IDENTITY_key_get_public (&ih->identity,
1401 &pub);
1402 char *str = GNUNET_IDENTITY_public_key_to_string (&pub);
1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1404 "Storing AuthZ information under %s in %s\n", label, str);
1405 GNUNET_free (str);
1390 // Publish record 1406 // Publish record
1391 ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 1407 ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1392 &ih->identity, 1408 &ih->identity,
@@ -1404,6 +1420,7 @@ issue_ticket (struct TicketIssueHandle *ih)
1404 char *ptr = (char*) attrs_record[j].data; 1420 char *ptr = (char*) attrs_record[j].data;
1405 GNUNET_free (ptr); 1421 GNUNET_free (ptr);
1406 } 1422 }
1423 GNUNET_free (tkt_data);
1407 GNUNET_free (attrs_record); 1424 GNUNET_free (attrs_record);
1408 GNUNET_free (label); 1425 GNUNET_free (label);
1409} 1426}
@@ -1454,7 +1471,7 @@ filter_tickets_cb (void *cls,
1454 const struct GNUNET_GNSRECORD_Data *rd) 1471 const struct GNUNET_GNSRECORD_Data *rd)
1455{ 1472{
1456 struct TicketIssueHandle *tih = cls; 1473 struct TicketIssueHandle *tih = cls;
1457 struct GNUNET_RECLAIM_Ticket *ticket = NULL; 1474 struct GNUNET_RECLAIM_Ticket ticket;
1458 struct GNUNET_RECLAIM_Presentation *presentation; 1475 struct GNUNET_RECLAIM_Presentation *presentation;
1459 struct GNUNET_RECLAIM_PresentationList *ticket_presentations; 1476 struct GNUNET_RECLAIM_PresentationList *ticket_presentations;
1460 struct GNUNET_RECLAIM_Credential *cred; 1477 struct GNUNET_RECLAIM_Credential *cred;
@@ -1462,6 +1479,7 @@ filter_tickets_cb (void *cls,
1462 struct GNUNET_RECLAIM_AttributeListEntry *le; 1479 struct GNUNET_RECLAIM_AttributeListEntry *le;
1463 unsigned int attr_cnt = 0; 1480 unsigned int attr_cnt = 0;
1464 unsigned int pres_cnt = 0; 1481 unsigned int pres_cnt = 0;
1482 int ticket_found = GNUNET_NO;
1465 1483
1466 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1484 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1467 { 1485 {
@@ -1473,6 +1491,7 @@ filter_tickets_cb (void *cls,
1473 // ticket search 1491 // ticket search
1474 unsigned int found_attrs_cnt = 0; 1492 unsigned int found_attrs_cnt = 0;
1475 unsigned int found_pres_cnt = 0; 1493 unsigned int found_pres_cnt = 0;
1494 size_t read;
1476 ticket_presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList); 1495 ticket_presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
1477 1496
1478 for (int i = 0; i < rd_count; i++) 1497 for (int i = 0; i < rd_count; i++)
@@ -1480,16 +1499,28 @@ filter_tickets_cb (void *cls,
1480 // found ticket 1499 // found ticket
1481 if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET == rd[i].record_type) 1500 if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET == rd[i].record_type)
1482 { 1501 {
1483 ticket = (struct GNUNET_RECLAIM_Ticket *) rd[i].data; 1502 if ((GNUNET_SYSERR ==
1503 GNUNET_RECLAIM_read_ticket_from_buffer (rd[i].data,
1504 rd[i].data_size,
1505 &ticket,
1506 &read)) ||
1507 (read != rd[i].data_size))
1508 {
1509 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1510 "Failed to deserialize ticket from record\n");
1511 continue;
1512 }
1484 // cmp audience 1513 // cmp audience
1514 // FIXME this is ugly, GNUNET_IDENTITY_PublicKey cannot be compared
1515 // like this
1485 if (0 == memcmp (&tih->ticket.audience, 1516 if (0 == memcmp (&tih->ticket.audience,
1486 &ticket->audience, 1517 &ticket.audience,
1487 sizeof(struct GNUNET_IDENTITY_PublicKey))) 1518 sizeof(struct GNUNET_IDENTITY_PublicKey)))
1488 { 1519 {
1489 tih->ticket = *ticket; 1520 tih->ticket = ticket;
1521 ticket_found = GNUNET_YES;
1490 continue; 1522 continue;
1491 } 1523 }
1492 ticket = NULL;
1493 } 1524 }
1494 1525
1495 // cmp requested attributes with ticket attributes 1526 // cmp requested attributes with ticket attributes
@@ -1573,7 +1604,7 @@ filter_tickets_cb (void *cls,
1573 */ 1604 */
1574 if ((attr_cnt == found_attrs_cnt) && 1605 if ((attr_cnt == found_attrs_cnt) &&
1575 (pres_cnt == found_pres_cnt) && 1606 (pres_cnt == found_pres_cnt) &&
1576 (NULL != ticket)) 1607 (GNUNET_YES == ticket_found))
1577 { 1608 {
1578 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); 1609 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it);
1579 tih->cb (tih->cb_cls, &tih->ticket, ticket_presentations, GNUNET_OK, NULL); 1610 tih->cb (tih->cb_cls, &tih->ticket, ticket_presentations, GNUNET_OK, NULL);
@@ -1683,12 +1714,25 @@ collect_tickets_cb (void *cls,
1683 const struct GNUNET_GNSRECORD_Data *rd) 1714 const struct GNUNET_GNSRECORD_Data *rd)
1684{ 1715{
1685 struct RECLAIM_TICKETS_Iterator *iter = cls; 1716 struct RECLAIM_TICKETS_Iterator *iter = cls;
1717 struct GNUNET_RECLAIM_Ticket ticket;
1718 size_t read;
1686 1719
1687 for (int i = 0; i < rd_count; i++) 1720 for (int i = 0; i < rd_count; i++)
1688 { 1721 {
1689 if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type) 1722 if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type)
1690 continue; 1723 continue;
1691 iter->cb (iter->cb_cls, (struct GNUNET_RECLAIM_Ticket *) rd[i].data); 1724 if ((GNUNET_SYSERR ==
1725 GNUNET_RECLAIM_read_ticket_from_buffer (rd[i].data,
1726 rd[i].data_size,
1727 &ticket,
1728 &read)) ||
1729 (read != rd[i].data_size))
1730 {
1731 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1732 "Failed to deserialize ticket from record\n");
1733 continue;
1734 }
1735 iter->cb (iter->cb_cls, &ticket);
1692 return; 1736 return;
1693 } 1737 }
1694 GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1); 1738 GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1);
diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h
index aae8ee89a..5813beaf7 100644
--- a/src/reclaim/reclaim.h
+++ b/src/reclaim/reclaim.h
@@ -45,6 +45,11 @@ struct AttributeStoreMessage
45 struct GNUNET_MessageHeader header; 45 struct GNUNET_MessageHeader header;
46 46
47 /** 47 /**
48 * The expiration interval of the attribute
49 */
50 uint64_t exp GNUNET_PACKED;
51
52 /**
48 * Unique identifier for this request (for key collisions). 53 * Unique identifier for this request (for key collisions).
49 */ 54 */
50 uint32_t id GNUNET_PACKED; 55 uint32_t id GNUNET_PACKED;
@@ -55,16 +60,13 @@ struct AttributeStoreMessage
55 uint32_t attr_len GNUNET_PACKED; 60 uint32_t attr_len GNUNET_PACKED;
56 61
57 /** 62 /**
58 * The expiration interval of the attribute 63 * The length of the private key
59 */
60 uint64_t exp GNUNET_PACKED;
61
62 /**
63 * Identity
64 */ 64 */
65 struct GNUNET_IDENTITY_PrivateKey identity; 65 uint32_t key_len GNUNET_PACKED;
66 66
67 /* followed by the serialized attribute */ 67 /*
68 * followed by the zone private key
69 * followed by the serialized attribute */
68}; 70};
69 71
70 72
@@ -89,9 +91,9 @@ struct AttributeDeleteMessage
89 uint32_t attr_len GNUNET_PACKED; 91 uint32_t attr_len GNUNET_PACKED;
90 92
91 /** 93 /**
92 * Identity 94 * The length of the private key
93 */ 95 */
94 struct GNUNET_IDENTITY_PrivateKey identity; 96 uint32_t key_len GNUNET_PACKED;
95 97
96 /* followed by the serialized attribute */ 98 /* followed by the serialized attribute */
97}; 99};
@@ -149,11 +151,13 @@ struct AttributeResultMessage
149 uint16_t reserved GNUNET_PACKED; 151 uint16_t reserved GNUNET_PACKED;
150 152
151 /** 153 /**
152 * The public key of the identity. 154 * The length of the public key
153 */ 155 */
154 struct GNUNET_IDENTITY_PublicKey identity; 156 uint32_t pkey_len GNUNET_PACKED;
155 157
156 /* followed by: 158 /**
159 * followed by the public key key.
160 * followed by:
157 * serialized attribute data 161 * serialized attribute data
158 */ 162 */
159}; 163};
@@ -184,11 +188,13 @@ struct CredentialResultMessage
184 uint16_t reserved GNUNET_PACKED; 188 uint16_t reserved GNUNET_PACKED;
185 189
186 /** 190 /**
187 * The public key of the identity. 191 * The length of the public key
188 */ 192 */
189 struct GNUNET_IDENTITY_PublicKey identity; 193 uint32_t key_len GNUNET_PACKED;
190 194
191 /* followed by: 195 /**
196 * followed by the private key.
197 * followed by:
192 * serialized credential data 198 * serialized credential data
193 */ 199 */
194}; 200};
@@ -210,9 +216,13 @@ struct AttributeIterationStartMessage
210 uint32_t id GNUNET_PACKED; 216 uint32_t id GNUNET_PACKED;
211 217
212 /** 218 /**
213 * Identity. 219 * The length of the private key
220 */
221 uint32_t key_len GNUNET_PACKED;
222
223 /**
224 * followed by the private key.
214 */ 225 */
215 struct GNUNET_IDENTITY_PrivateKey identity;
216}; 226};
217 227
218 228
@@ -249,9 +259,13 @@ struct CredentialIterationStartMessage
249 uint32_t id GNUNET_PACKED; 259 uint32_t id GNUNET_PACKED;
250 260
251 /** 261 /**
252 * Identity. 262 * The length of the private key
263 */
264 uint32_t key_len GNUNET_PACKED;
265
266 /**
267 * followed by the private key.
253 */ 268 */
254 struct GNUNET_IDENTITY_PrivateKey identity;
255}; 269};
256 270
257 271
@@ -321,9 +335,13 @@ struct TicketIterationStartMessage
321 uint32_t id GNUNET_PACKED; 335 uint32_t id GNUNET_PACKED;
322 336
323 /** 337 /**
324 * Identity. 338 * The length of the private key
339 */
340 uint32_t key_len GNUNET_PACKED;
341
342 /**
343 * followed by the private key.
325 */ 344 */
326 struct GNUNET_IDENTITY_PrivateKey identity;
327}; 345};
328 346
329 347
@@ -377,21 +395,25 @@ struct IssueTicketMessage
377 uint32_t id GNUNET_PACKED; 395 uint32_t id GNUNET_PACKED;
378 396
379 /** 397 /**
380 * Identity. 398 * length of serialized attribute list
381 */ 399 */
382 struct GNUNET_IDENTITY_PrivateKey identity; 400 uint32_t attr_len GNUNET_PACKED;
383 401
384 /** 402 /**
385 * Requesting party. 403 * The length of the identity private key
386 */ 404 */
387 struct GNUNET_IDENTITY_PublicKey rp; 405 uint32_t key_len GNUNET_PACKED;
388 406
389 /** 407 /**
390 * length of serialized attribute list 408 * The length of the relying party public key
391 */ 409 */
392 uint32_t attr_len GNUNET_PACKED; 410 uint32_t pkey_len GNUNET_PACKED;
393 411
394 // Followed by a serialized attribute list 412 /**
413 * Followed by the private key.
414 * Followed by the public key.
415 * Followed by a serialized attribute list
416 */
395}; 417};
396 418
397/** 419/**
@@ -410,19 +432,20 @@ struct RevokeTicketMessage
410 uint32_t id GNUNET_PACKED; 432 uint32_t id GNUNET_PACKED;
411 433
412 /** 434 /**
413 * Identity. 435 * The length of the private key
414 */ 436 */
415 struct GNUNET_IDENTITY_PrivateKey identity; 437 uint32_t key_len GNUNET_PACKED;
416 438
417 /** 439 /**
418 * length of serialized attribute list 440 * The length of the ticket
419 */ 441 */
420 uint32_t attrs_len GNUNET_PACKED; 442 uint32_t tkt_len GNUNET_PACKED;
421 443
422 /** 444 /**
423 * The ticket to revoke 445 * Followed by the serialized ticket.
446 * Followed by the private key.
447 * Followed by a serialized attribute list
424 */ 448 */
425 struct GNUNET_RECLAIM_Ticket ticket;
426}; 449};
427 450
428/** 451/**
@@ -463,16 +486,19 @@ struct TicketResultMessage
463 uint32_t id GNUNET_PACKED; 486 uint32_t id GNUNET_PACKED;
464 487
465 /** 488 /**
466 * Length of new presentations created 489 * Ticket length
467 */ 490 */
468 uint32_t presentations_len GNUNET_PACKED; 491 uint32_t tkt_len GNUNET_PACKED;
469 492
470 /** 493 /**
471 * The new ticket 494 * Length of new presentations created
472 */ 495 */
473 struct GNUNET_RECLAIM_Ticket ticket; 496 uint32_t presentations_len GNUNET_PACKED;
474 497
475 /* Followed by the serialized GNUNET_RECLAIM_PresentationList */ 498 /*
499 * Followed by the serialized ticket
500 * Followed by the serialized GNUNET_RECLAIM_PresentationList
501 */
476}; 502};
477 503
478/** 504/**
@@ -491,14 +517,19 @@ struct ConsumeTicketMessage
491 uint32_t id GNUNET_PACKED; 517 uint32_t id GNUNET_PACKED;
492 518
493 /** 519 /**
494 * Identity. 520 * The length of the private key
495 */ 521 */
496 struct GNUNET_IDENTITY_PrivateKey identity; 522 uint32_t key_len GNUNET_PACKED;
497 523
498 /** 524 /**
499 * The ticket to consume 525 * The length of the ticket
526 */
527 uint32_t tkt_len GNUNET_PACKED;
528
529 /**
530 * Followed by the private key.
531 * Followed by the serialized ticket.
500 */ 532 */
501 struct GNUNET_RECLAIM_Ticket ticket;
502}; 533};
503 534
504/** 535/**
@@ -537,11 +568,13 @@ struct ConsumeTicketResultMessage
537 uint16_t reserved GNUNET_PACKED; 568 uint16_t reserved GNUNET_PACKED;
538 569
539 /** 570 /**
540 * The public key of the identity. 571 * The length of the private key
541 */ 572 */
542 struct GNUNET_IDENTITY_PublicKey identity; 573 uint32_t key_len GNUNET_PACKED;
543 574
544 /* followed by: 575 /**
576 * Followed by the private key.
577 * followed by:
545 * serialized attributes data 578 * serialized attributes data
546 */ 579 */
547}; 580};
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index 6f55d62e4..efc45e616 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -567,12 +567,13 @@ check_consume_ticket_result (void *cls,
567 size_t msg_len; 567 size_t msg_len;
568 size_t attrs_len; 568 size_t attrs_len;
569 size_t pl_len; 569 size_t pl_len;
570 size_t key_len;
570 571
571 msg_len = ntohs (msg->header.size); 572 msg_len = ntohs (msg->header.size);
572 attrs_len = ntohs (msg->attrs_len); 573 attrs_len = ntohs (msg->attrs_len);
574 key_len = ntohl (msg->key_len);
573 pl_len = ntohs (msg->presentations_len); 575 pl_len = ntohs (msg->presentations_len);
574 if (msg_len != 576 if (msg_len != sizeof(*msg) + attrs_len + pl_len + key_len)
575 sizeof(struct ConsumeTicketResultMessage) + attrs_len + pl_len)
576 { 577 {
577 GNUNET_break (0); 578 GNUNET_break (0);
578 return GNUNET_SYSERR; 579 return GNUNET_SYSERR;
@@ -592,14 +593,18 @@ static void
592handle_consume_ticket_result (void *cls, 593handle_consume_ticket_result (void *cls,
593 const struct ConsumeTicketResultMessage *msg) 594 const struct ConsumeTicketResultMessage *msg)
594{ 595{
596 struct GNUNET_IDENTITY_PublicKey identity;
595 struct GNUNET_RECLAIM_Handle *h = cls; 597 struct GNUNET_RECLAIM_Handle *h = cls;
596 struct GNUNET_RECLAIM_Operation *op; 598 struct GNUNET_RECLAIM_Operation *op;
597 size_t attrs_len; 599 size_t attrs_len;
598 size_t pl_len; 600 size_t pl_len;
601 size_t key_len;
602 size_t read;
599 uint32_t r_id = ntohl (msg->id); 603 uint32_t r_id = ntohl (msg->id);
600 char *read_ptr; 604 char *read_ptr;
601 605
602 attrs_len = ntohs (msg->attrs_len); 606 attrs_len = ntohs (msg->attrs_len);
607 key_len = ntohl (msg->key_len);
603 pl_len = ntohs (msg->presentations_len); 608 pl_len = ntohs (msg->presentations_len);
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing ticket result.\n"); 609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing ticket result.\n");
605 610
@@ -615,15 +620,22 @@ handle_consume_ticket_result (void *cls,
615 struct GNUNET_RECLAIM_AttributeListEntry *le; 620 struct GNUNET_RECLAIM_AttributeListEntry *le;
616 struct GNUNET_RECLAIM_PresentationList *pl; 621 struct GNUNET_RECLAIM_PresentationList *pl;
617 struct GNUNET_RECLAIM_PresentationListEntry *ple; 622 struct GNUNET_RECLAIM_PresentationListEntry *ple;
623 read_ptr = (char *) &msg[1];
624 GNUNET_assert (GNUNET_SYSERR !=
625 GNUNET_IDENTITY_read_public_key_from_buffer (read_ptr,
626 key_len,
627 &identity,
628 &read));
629 read_ptr += read;
618 attrs = 630 attrs =
619 GNUNET_RECLAIM_attribute_list_deserialize ((char *) &msg[1], attrs_len); 631 GNUNET_RECLAIM_attribute_list_deserialize (read_ptr, attrs_len);
620 read_ptr = ((char *) &msg[1]) + attrs_len; 632 read_ptr += attrs_len;
621 pl = GNUNET_RECLAIM_presentation_list_deserialize (read_ptr, pl_len); 633 pl = GNUNET_RECLAIM_presentation_list_deserialize (read_ptr, pl_len);
622 if (NULL != op->atr_cb) 634 if (NULL != op->atr_cb)
623 { 635 {
624 if (NULL == attrs) 636 if (NULL == attrs)
625 { 637 {
626 op->atr_cb (op->cls, &msg->identity, NULL, NULL); 638 op->atr_cb (op->cls, &identity, NULL, NULL);
627 } 639 }
628 else 640 else
629 { 641 {
@@ -638,7 +650,7 @@ handle_consume_ticket_result (void *cls,
638 GNUNET_RECLAIM_id_is_equal (&le->attribute->credential, 650 GNUNET_RECLAIM_id_is_equal (&le->attribute->credential,
639 &ple->presentation->credential_id)) 651 &ple->presentation->credential_id))
640 { 652 {
641 op->atr_cb (op->cls, &msg->identity, 653 op->atr_cb (op->cls, &identity,
642 le->attribute, ple->presentation); 654 le->attribute, ple->presentation);
643 break; 655 break;
644 } 656 }
@@ -647,7 +659,7 @@ handle_consume_ticket_result (void *cls,
647 } 659 }
648 else // No credentials 660 else // No credentials
649 { 661 {
650 op->atr_cb (op->cls, &msg->identity, 662 op->atr_cb (op->cls, &identity,
651 le->attribute, NULL); 663 le->attribute, NULL);
652 } 664 }
653 } 665 }
@@ -679,10 +691,12 @@ check_attribute_result (void *cls, const struct AttributeResultMessage *msg)
679{ 691{
680 size_t msg_len; 692 size_t msg_len;
681 size_t attr_len; 693 size_t attr_len;
694 size_t key_len;
682 695
683 msg_len = ntohs (msg->header.size); 696 msg_len = ntohs (msg->header.size);
684 attr_len = ntohs (msg->attr_len); 697 attr_len = ntohs (msg->attr_len);
685 if (msg_len != sizeof(struct AttributeResultMessage) + attr_len) 698 key_len = ntohl (msg->pkey_len);
699 if (msg_len != sizeof(*msg) + attr_len + key_len)
686 { 700 {
687 GNUNET_break (0); 701 GNUNET_break (0);
688 return GNUNET_SYSERR; 702 return GNUNET_SYSERR;
@@ -701,17 +715,20 @@ check_attribute_result (void *cls, const struct AttributeResultMessage *msg)
701static void 715static void
702handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) 716handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
703{ 717{
704 static struct GNUNET_IDENTITY_PrivateKey identity_dummy; 718 static struct GNUNET_IDENTITY_PublicKey identity;
705 struct GNUNET_RECLAIM_Handle *h = cls; 719 struct GNUNET_RECLAIM_Handle *h = cls;
706 struct GNUNET_RECLAIM_AttributeIterator *it; 720 struct GNUNET_RECLAIM_AttributeIterator *it;
707 struct GNUNET_RECLAIM_Operation *op; 721 struct GNUNET_RECLAIM_Operation *op;
708 size_t attr_len; 722 size_t attr_len;
723 size_t key_len;
724 size_t read;
709 uint32_t r_id = ntohl (msg->id); 725 uint32_t r_id = ntohl (msg->id);
726 char *buf;
710 727
711 attr_len = ntohs (msg->attr_len); 728 attr_len = ntohs (msg->attr_len);
729 key_len = ntohl (msg->pkey_len);
712 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); 730 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
713 731
714
715 for (it = h->it_head; NULL != it; it = it->next) 732 for (it = h->it_head; NULL != it; it = it->next)
716 if (it->r_id == r_id) 733 if (it->r_id == r_id)
717 break; 734 break;
@@ -721,8 +738,8 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
721 if ((NULL == it) && (NULL == op)) 738 if ((NULL == it) && (NULL == op))
722 return; 739 return;
723 740
724 if ((0 == 741 buf = (char *) &msg[1];
725 (memcmp (&msg->identity, &identity_dummy, sizeof(identity_dummy))))) 742 if (0 == key_len)
726 { 743 {
727 if ((NULL == it) && (NULL == op)) 744 if ((NULL == it) && (NULL == op))
728 { 745 {
@@ -748,17 +765,22 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
748 765
749 { 766 {
750 struct GNUNET_RECLAIM_Attribute *attr; 767 struct GNUNET_RECLAIM_Attribute *attr;
751 GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len, 768 GNUNET_assert (GNUNET_SYSERR !=
752 &attr); 769 GNUNET_IDENTITY_read_public_key_from_buffer (buf,
770 key_len,
771 &identity,
772 &read));
773 buf += read;
774 GNUNET_RECLAIM_attribute_deserialize (buf, attr_len, &attr);
753 if (NULL != it) 775 if (NULL != it)
754 { 776 {
755 if (NULL != it->proc) 777 if (NULL != it->proc)
756 it->proc (it->proc_cls, &msg->identity, attr); 778 it->proc (it->proc_cls, &identity, attr);
757 } 779 }
758 else if (NULL != op) 780 else if (NULL != op)
759 { 781 {
760 if (NULL != op->ar_cb) 782 if (NULL != op->ar_cb)
761 op->ar_cb (op->cls, &msg->identity, attr); 783 op->ar_cb (op->cls, &identity, attr);
762 } 784 }
763 GNUNET_free (attr); 785 GNUNET_free (attr);
764 return; 786 return;
@@ -780,10 +802,12 @@ check_credential_result (void *cls, const struct CredentialResultMessage *msg)
780{ 802{
781 size_t msg_len; 803 size_t msg_len;
782 size_t cred_len; 804 size_t cred_len;
805 size_t key_len;
783 806
784 msg_len = ntohs (msg->header.size); 807 msg_len = ntohs (msg->header.size);
785 cred_len = ntohs (msg->credential_len); 808 cred_len = ntohs (msg->credential_len);
786 if (msg_len != sizeof(struct CredentialResultMessage) + cred_len) 809 key_len = ntohl (msg->key_len);
810 if (msg_len != sizeof(*msg) + cred_len + key_len)
787 { 811 {
788 GNUNET_break (0); 812 GNUNET_break (0);
789 return GNUNET_SYSERR; 813 return GNUNET_SYSERR;
@@ -803,13 +827,17 @@ static void
803handle_credential_result (void *cls, const struct 827handle_credential_result (void *cls, const struct
804 CredentialResultMessage *msg) 828 CredentialResultMessage *msg)
805{ 829{
806 static struct GNUNET_IDENTITY_PrivateKey identity_dummy; 830 struct GNUNET_IDENTITY_PublicKey identity;
807 struct GNUNET_RECLAIM_Handle *h = cls; 831 struct GNUNET_RECLAIM_Handle *h = cls;
808 struct GNUNET_RECLAIM_CredentialIterator *it; 832 struct GNUNET_RECLAIM_CredentialIterator *it;
809 struct GNUNET_RECLAIM_Operation *op; 833 struct GNUNET_RECLAIM_Operation *op;
810 size_t att_len; 834 size_t att_len;
835 size_t key_len;
836 size_t read;
811 uint32_t r_id = ntohl (msg->id); 837 uint32_t r_id = ntohl (msg->id);
838 char *buf;
812 839
840 key_len = ntohl (msg->key_len);
813 att_len = ntohs (msg->credential_len); 841 att_len = ntohs (msg->credential_len);
814 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing credential result.\n"); 842 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing credential result.\n");
815 843
@@ -823,8 +851,17 @@ handle_credential_result (void *cls, const struct
823 if ((NULL == it) && (NULL == op)) 851 if ((NULL == it) && (NULL == op))
824 return; 852 return;
825 853
826 if ((0 == 854 buf = (char *) &msg[1];
827 (memcmp (&msg->identity, &identity_dummy, sizeof(identity_dummy))))) 855 if (0 < key_len)
856 {
857 GNUNET_assert (GNUNET_SYSERR !=
858 GNUNET_IDENTITY_read_public_key_from_buffer (buf,
859 key_len,
860 &identity,
861 &read));
862 buf += read;
863 }
864 if (0 == key_len)
828 { 865 {
829 if ((NULL == it) && (NULL == op)) 866 if ((NULL == it) && (NULL == op))
830 { 867 {
@@ -850,17 +887,17 @@ handle_credential_result (void *cls, const struct
850 887
851 { 888 {
852 struct GNUNET_RECLAIM_Credential *att; 889 struct GNUNET_RECLAIM_Credential *att;
853 att = GNUNET_RECLAIM_credential_deserialize ((char *) &msg[1], att_len); 890 att = GNUNET_RECLAIM_credential_deserialize (buf, att_len);
854 891
855 if (NULL != it) 892 if (NULL != it)
856 { 893 {
857 if (NULL != it->proc) 894 if (NULL != it->proc)
858 it->proc (it->proc_cls, &msg->identity, att); 895 it->proc (it->proc_cls, &identity, att);
859 } 896 }
860 else if (NULL != op) 897 else if (NULL != op)
861 { 898 {
862 if (NULL != op->at_cb) 899 if (NULL != op->at_cb)
863 op->at_cb (op->cls, &msg->identity, att); 900 op->at_cb (op->cls, &identity, att);
864 } 901 }
865 GNUNET_free (att); 902 GNUNET_free (att);
866 return; 903 return;
@@ -882,10 +919,12 @@ check_ticket_result (void *cls, const struct TicketResultMessage *msg)
882{ 919{
883 size_t msg_len; 920 size_t msg_len;
884 size_t pres_len; 921 size_t pres_len;
922 size_t tkt_len;
885 923
886 msg_len = ntohs (msg->header.size); 924 msg_len = ntohs (msg->header.size);
887 pres_len = ntohs (msg->presentations_len); 925 pres_len = ntohs (msg->presentations_len);
888 if (msg_len != sizeof(struct TicketResultMessage) + pres_len) 926 tkt_len = ntohl (msg->tkt_len);
927 if (msg_len != sizeof(*msg) + pres_len + tkt_len)
889 { 928 {
890 GNUNET_break (0); 929 GNUNET_break (0);
891 return GNUNET_SYSERR; 930 return GNUNET_SYSERR;
@@ -909,9 +948,14 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
909 struct GNUNET_RECLAIM_TicketIterator *it; 948 struct GNUNET_RECLAIM_TicketIterator *it;
910 struct GNUNET_RECLAIM_PresentationList *presentation; 949 struct GNUNET_RECLAIM_PresentationList *presentation;
911 uint32_t r_id = ntohl (msg->id); 950 uint32_t r_id = ntohl (msg->id);
912 static const struct GNUNET_RECLAIM_Ticket ticket; 951 struct GNUNET_RECLAIM_Ticket ticket;
913 uint32_t pres_len = ntohs (msg->presentations_len); 952 size_t pres_len;
953 size_t tkt_len;
954 size_t tb_read;
955 char *buf;
914 956
957 tkt_len = ntohl (msg->tkt_len);
958 pres_len = ntohs (msg->presentations_len);
915 for (op = handle->op_head; NULL != op; op = op->next) 959 for (op = handle->op_head; NULL != op; op = op->next)
916 if (op->r_id == r_id) 960 if (op->r_id == r_id)
917 break; 961 break;
@@ -920,15 +964,21 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
920 break; 964 break;
921 if ((NULL == op) && (NULL == it)) 965 if ((NULL == op) && (NULL == it))
922 return; 966 return;
967 buf = (char*) &msg[1];
968 GNUNET_assert (GNUNET_SYSERR !=
969 GNUNET_RECLAIM_read_ticket_from_buffer (buf,
970 tkt_len,
971 &ticket,
972 &tb_read));
973 buf += tb_read;
923 if (NULL != op) 974 if (NULL != op)
924 { 975 {
925 if (0 < pres_len) 976 if (0 < pres_len)
926 presentation = GNUNET_RECLAIM_presentation_list_deserialize ( 977 presentation = GNUNET_RECLAIM_presentation_list_deserialize (
927 (char*) &msg[1], 978 buf,
928 pres_len); 979 pres_len);
929 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); 980 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
930 if (0 == 981 if (0 == tb_read)
931 memcmp (&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket)))
932 { 982 {
933 if (NULL != op->ti_cb) 983 if (NULL != op->ti_cb)
934 op->ti_cb (op->cls, NULL, NULL); 984 op->ti_cb (op->cls, NULL, NULL);
@@ -937,7 +987,7 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
937 { 987 {
938 if (NULL != op->ti_cb) 988 if (NULL != op->ti_cb)
939 op->ti_cb (op->cls, 989 op->ti_cb (op->cls,
940 &msg->ticket, 990 &ticket,
941 (0 < pres_len) ? presentation : NULL); 991 (0 < pres_len) ? presentation : NULL);
942 } 992 }
943 if (0 < pres_len) 993 if (0 < pres_len)
@@ -947,8 +997,7 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
947 } 997 }
948 else if (NULL != it) 998 else if (NULL != it)
949 { 999 {
950 if (0 == 1000 if (0 == tkt_len)
951 memcmp (&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket)))
952 { 1001 {
953 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, 1002 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
954 handle->ticket_it_tail, 1003 handle->ticket_it_tail,
@@ -959,7 +1008,7 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
959 else 1008 else
960 { 1009 {
961 if (NULL != it->tr_cb) 1010 if (NULL != it->tr_cb)
962 it->tr_cb (it->cls, &msg->ticket); 1011 it->tr_cb (it->cls, &ticket);
963 } 1012 }
964 return; 1013 return;
965 } 1014 }
@@ -1110,18 +1159,6 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h)
1110} 1159}
1111 1160
1112 1161
1113/**
1114 * Store an attribute. If the attribute is already present,
1115 * it is replaced with the new attribute.
1116 *
1117 * @param h handle to the re:claimID service
1118 * @param pkey private key of the identity
1119 * @param attr the attribute value
1120 * @param exp_interval the relative expiration interval for the attribute
1121 * @param cont continuation to call when done
1122 * @param cont_cls closure for @a cont
1123 * @return handle to abort the request
1124 */
1125struct GNUNET_RECLAIM_Operation * 1162struct GNUNET_RECLAIM_Operation *
1126GNUNET_RECLAIM_attribute_store ( 1163GNUNET_RECLAIM_attribute_store (
1127 struct GNUNET_RECLAIM_Handle *h, 1164 struct GNUNET_RECLAIM_Handle *h,
@@ -1134,6 +1171,9 @@ GNUNET_RECLAIM_attribute_store (
1134 struct GNUNET_RECLAIM_Operation *op; 1171 struct GNUNET_RECLAIM_Operation *op;
1135 struct AttributeStoreMessage *sam; 1172 struct AttributeStoreMessage *sam;
1136 size_t attr_len; 1173 size_t attr_len;
1174 size_t key_len;
1175 ssize_t written;
1176 char *buf;
1137 1177
1138 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1178 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1139 op->h = h; 1179 op->h = h;
@@ -1141,15 +1181,20 @@ GNUNET_RECLAIM_attribute_store (
1141 op->cls = cont_cls; 1181 op->cls = cont_cls;
1142 op->r_id = h->r_id_gen++; 1182 op->r_id = h->r_id_gen++;
1143 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1183 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1184 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1144 attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (attr); 1185 attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (attr);
1145 op->env = GNUNET_MQ_msg_extra (sam, 1186 op->env = GNUNET_MQ_msg_extra (sam,
1146 attr_len, 1187 attr_len + key_len,
1147 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); 1188 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE);
1148 sam->identity = *pkey; 1189 sam->key_len = htonl (key_len);
1190 buf = (char *) &sam[1];
1191 written = GNUNET_IDENTITY_write_private_key_to_buffer (pkey, buf, key_len);
1192 GNUNET_assert (0 < written);
1193 buf += written;
1149 sam->id = htonl (op->r_id); 1194 sam->id = htonl (op->r_id);
1150 sam->exp = GNUNET_htonll (exp_interval->rel_value_us); 1195 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
1151 1196
1152 GNUNET_RECLAIM_attribute_serialize (attr, (char *) &sam[1]); 1197 GNUNET_RECLAIM_attribute_serialize (attr, buf);
1153 1198
1154 sam->attr_len = htons (attr_len); 1199 sam->attr_len = htons (attr_len);
1155 if (NULL != h->mq) 1200 if (NULL != h->mq)
@@ -1158,17 +1203,6 @@ GNUNET_RECLAIM_attribute_store (
1158} 1203}
1159 1204
1160 1205
1161/**
1162 * Delete an attribute. Tickets used to share this attribute are updated
1163 * accordingly.
1164 *
1165 * @param h handle to the re:claimID service
1166 * @param pkey Private key of the identity to add an attribute to
1167 * @param attr The attribute
1168 * @param cont Continuation to call when done
1169 * @param cont_cls Closure for @a cont
1170 * @return handle Used to to abort the request
1171 */
1172struct GNUNET_RECLAIM_Operation * 1206struct GNUNET_RECLAIM_Operation *
1173GNUNET_RECLAIM_attribute_delete ( 1207GNUNET_RECLAIM_attribute_delete (
1174 struct GNUNET_RECLAIM_Handle *h, 1208 struct GNUNET_RECLAIM_Handle *h,
@@ -1180,6 +1214,9 @@ GNUNET_RECLAIM_attribute_delete (
1180 struct GNUNET_RECLAIM_Operation *op; 1214 struct GNUNET_RECLAIM_Operation *op;
1181 struct AttributeDeleteMessage *dam; 1215 struct AttributeDeleteMessage *dam;
1182 size_t attr_len; 1216 size_t attr_len;
1217 size_t key_len;
1218 ssize_t written;
1219 char *buf;
1183 1220
1184 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1221 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1185 op->h = h; 1222 op->h = h;
@@ -1187,13 +1224,18 @@ GNUNET_RECLAIM_attribute_delete (
1187 op->cls = cont_cls; 1224 op->cls = cont_cls;
1188 op->r_id = h->r_id_gen++; 1225 op->r_id = h->r_id_gen++;
1189 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1226 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1227 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1190 attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (attr); 1228 attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (attr);
1191 op->env = GNUNET_MQ_msg_extra (dam, 1229 op->env = GNUNET_MQ_msg_extra (dam,
1192 attr_len, 1230 attr_len + key_len,
1193 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE); 1231 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE);
1194 dam->identity = *pkey; 1232 dam->key_len = htonl (key_len);
1233 buf = (char *) &dam[1];
1234 written = GNUNET_IDENTITY_write_private_key_to_buffer (pkey, buf, key_len);
1235 GNUNET_assert (0 < written);
1236 buf += written;
1195 dam->id = htonl (op->r_id); 1237 dam->id = htonl (op->r_id);
1196 GNUNET_RECLAIM_attribute_serialize (attr, (char *) &dam[1]); 1238 GNUNET_RECLAIM_attribute_serialize (attr, buf);
1197 1239
1198 dam->attr_len = htons (attr_len); 1240 dam->attr_len = htons (attr_len);
1199 if (NULL != h->mq) 1241 if (NULL != h->mq)
@@ -1214,22 +1256,30 @@ GNUNET_RECLAIM_credential_store (
1214 struct GNUNET_RECLAIM_Operation *op; 1256 struct GNUNET_RECLAIM_Operation *op;
1215 struct AttributeStoreMessage *sam; 1257 struct AttributeStoreMessage *sam;
1216 size_t attr_len; 1258 size_t attr_len;
1259 size_t key_len;
1260 ssize_t written;
1261 char *buf;
1217 1262
1218 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1263 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1219 op->h = h; 1264 op->h = h;
1220 op->as_cb = cont; 1265 op->as_cb = cont;
1221 op->cls = cont_cls; 1266 op->cls = cont_cls;
1222 op->r_id = h->r_id_gen++; 1267 op->r_id = h->r_id_gen++;
1268 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1223 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1269 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1224 attr_len = GNUNET_RECLAIM_credential_serialize_get_size (credential); 1270 attr_len = GNUNET_RECLAIM_credential_serialize_get_size (credential);
1225 op->env = GNUNET_MQ_msg_extra (sam, 1271 op->env = GNUNET_MQ_msg_extra (sam,
1226 attr_len, 1272 attr_len + key_len,
1227 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_STORE); 1273 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_STORE);
1228 sam->identity = *pkey; 1274 sam->key_len = htonl (key_len);
1275 buf = (char *) &sam[1];
1276 written = GNUNET_IDENTITY_write_private_key_to_buffer (pkey, buf, key_len);
1277 GNUNET_assert (0 <= written);
1278 buf += written;
1229 sam->id = htonl (op->r_id); 1279 sam->id = htonl (op->r_id);
1230 sam->exp = GNUNET_htonll (exp_interval->rel_value_us); 1280 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
1231 1281
1232 GNUNET_RECLAIM_credential_serialize (credential, (char *) &sam[1]); 1282 GNUNET_RECLAIM_credential_serialize (credential, buf);
1233 1283
1234 sam->attr_len = htons (attr_len); 1284 sam->attr_len = htons (attr_len);
1235 if (NULL != h->mq) 1285 if (NULL != h->mq)
@@ -1249,20 +1299,28 @@ GNUNET_RECLAIM_credential_delete (
1249 struct GNUNET_RECLAIM_Operation *op; 1299 struct GNUNET_RECLAIM_Operation *op;
1250 struct AttributeDeleteMessage *dam; 1300 struct AttributeDeleteMessage *dam;
1251 size_t attr_len; 1301 size_t attr_len;
1302 size_t key_len;
1303 ssize_t written;
1304 char *buf;
1252 1305
1253 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1306 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1254 op->h = h; 1307 op->h = h;
1255 op->as_cb = cont; 1308 op->as_cb = cont;
1256 op->cls = cont_cls; 1309 op->cls = cont_cls;
1257 op->r_id = h->r_id_gen++; 1310 op->r_id = h->r_id_gen++;
1311 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1258 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1312 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1259 attr_len = GNUNET_RECLAIM_credential_serialize_get_size (attr); 1313 attr_len = GNUNET_RECLAIM_credential_serialize_get_size (attr);
1260 op->env = GNUNET_MQ_msg_extra (dam, 1314 op->env = GNUNET_MQ_msg_extra (dam,
1261 attr_len, 1315 attr_len + key_len,
1262 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_DELETE); 1316 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_DELETE);
1263 dam->identity = *pkey; 1317 dam->key_len = htonl (key_len);
1318 buf = (char *) &dam[1];
1319 written = GNUNET_IDENTITY_write_private_key_to_buffer (pkey, buf, key_len);
1320 GNUNET_assert (0 <= written);
1321 buf += written;
1264 dam->id = htonl (op->r_id); 1322 dam->id = htonl (op->r_id);
1265 GNUNET_RECLAIM_credential_serialize (attr, (char *) &dam[1]); 1323 GNUNET_RECLAIM_credential_serialize (attr, buf);
1266 1324
1267 dam->attr_len = htons (attr_len); 1325 dam->attr_len = htons (attr_len);
1268 if (NULL != h->mq) 1326 if (NULL != h->mq)
@@ -1271,30 +1329,6 @@ GNUNET_RECLAIM_credential_delete (
1271} 1329}
1272 1330
1273 1331
1274/**
1275 * List all attributes for a local identity.
1276 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
1277 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
1278 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
1279 * immediately, and then again after
1280 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
1281 *
1282 * On error (disconnect), @a error_cb will be invoked.
1283 * On normal completion, @a finish_cb proc will be
1284 * invoked.
1285 *
1286 * @param h Handle to the re:claimID service
1287 * @param identity Identity to iterate over
1288 * @param error_cb Function to call on error (i.e. disconnect),
1289 * the handle is afterwards invalid
1290 * @param error_cb_cls Closure for @a error_cb
1291 * @param proc Function to call on each attribute
1292 * @param proc_cls Closure for @a proc
1293 * @param finish_cb Function to call on completion
1294 * the handle is afterwards invalid
1295 * @param finish_cb_cls Closure for @a finish_cb
1296 * @return an iterator Handle to use for iteration
1297 */
1298struct GNUNET_RECLAIM_AttributeIterator * 1332struct GNUNET_RECLAIM_AttributeIterator *
1299GNUNET_RECLAIM_get_attributes_start ( 1333GNUNET_RECLAIM_get_attributes_start (
1300 struct GNUNET_RECLAIM_Handle *h, 1334 struct GNUNET_RECLAIM_Handle *h,
@@ -1310,6 +1344,7 @@ GNUNET_RECLAIM_get_attributes_start (
1310 struct GNUNET_MQ_Envelope *env; 1344 struct GNUNET_MQ_Envelope *env;
1311 struct AttributeIterationStartMessage *msg; 1345 struct AttributeIterationStartMessage *msg;
1312 uint32_t rid; 1346 uint32_t rid;
1347 size_t key_len;
1313 1348
1314 rid = h->r_id_gen++; 1349 rid = h->r_id_gen++;
1315 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator); 1350 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator);
@@ -1322,11 +1357,15 @@ GNUNET_RECLAIM_get_attributes_start (
1322 it->proc_cls = proc_cls; 1357 it->proc_cls = proc_cls;
1323 it->r_id = rid; 1358 it->r_id = rid;
1324 it->identity = *identity; 1359 it->identity = *identity;
1360 key_len = GNUNET_IDENTITY_private_key_get_length (identity);
1325 GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it); 1361 GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it);
1326 env = 1362 env =
1327 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); 1363 GNUNET_MQ_msg_extra (msg,
1364 key_len,
1365 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
1328 msg->id = htonl (rid); 1366 msg->id = htonl (rid);
1329 msg->identity = *identity; 1367 msg->key_len = htonl (key_len);
1368 GNUNET_IDENTITY_write_private_key_to_buffer (identity, &msg[1], key_len);
1330 if (NULL == h->mq) 1369 if (NULL == h->mq)
1331 it->env = env; 1370 it->env = env;
1332 else 1371 else
@@ -1349,13 +1388,6 @@ GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it)
1349} 1388}
1350 1389
1351 1390
1352/**
1353 * Stops iteration and releases the handle for further calls. Must
1354 * be called on any iteration that has not yet completed prior to calling
1355 * #GNUNET_RECLAIM_disconnect.
1356 *
1357 * @param it the iterator
1358 */
1359void 1391void
1360GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) 1392GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1361{ 1393{
@@ -1374,30 +1406,6 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1374} 1406}
1375 1407
1376 1408
1377/**
1378 * List all credentials for a local identity.
1379 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
1380 * for any other calls than #GNUNET_RECLAIM_get_credentials_next() and
1381 * #GNUNET_RECLAIM_get_credentials_stop. @a proc will be called once
1382 * immediately, and then again after
1383 * #GNUNET_RECLAIM_get_credentials_next() is invoked.
1384 *
1385 * On error (disconnect), @a error_cb will be invoked.
1386 * On normal completion, @a finish_cb proc will be
1387 * invoked.
1388 *
1389 * @param h Handle to the re:claimID service
1390 * @param identity Identity to iterate over
1391 * @param error_cb Function to call on error (i.e. disconnect),
1392 * the handle is afterwards invalid
1393 * @param error_cb_cls Closure for @a error_cb
1394 * @param proc Function to call on each credential
1395 * @param proc_cls Closure for @a proc
1396 * @param finish_cb Function to call on completion
1397 * the handle is afterwards invalid
1398 * @param finish_cb_cls Closure for @a finish_cb
1399 * @return an iterator Handle to use for iteration
1400 */
1401struct GNUNET_RECLAIM_CredentialIterator * 1409struct GNUNET_RECLAIM_CredentialIterator *
1402GNUNET_RECLAIM_get_credentials_start ( 1410GNUNET_RECLAIM_get_credentials_start (
1403 struct GNUNET_RECLAIM_Handle *h, 1411 struct GNUNET_RECLAIM_Handle *h,
@@ -1413,6 +1421,7 @@ GNUNET_RECLAIM_get_credentials_start (
1413 struct GNUNET_MQ_Envelope *env; 1421 struct GNUNET_MQ_Envelope *env;
1414 struct CredentialIterationStartMessage *msg; 1422 struct CredentialIterationStartMessage *msg;
1415 uint32_t rid; 1423 uint32_t rid;
1424 size_t key_len;
1416 1425
1417 rid = h->r_id_gen++; 1426 rid = h->r_id_gen++;
1418 ait = GNUNET_new (struct GNUNET_RECLAIM_CredentialIterator); 1427 ait = GNUNET_new (struct GNUNET_RECLAIM_CredentialIterator);
@@ -1425,12 +1434,15 @@ GNUNET_RECLAIM_get_credentials_start (
1425 ait->proc_cls = proc_cls; 1434 ait->proc_cls = proc_cls;
1426 ait->r_id = rid; 1435 ait->r_id = rid;
1427 ait->identity = *identity; 1436 ait->identity = *identity;
1437 key_len = GNUNET_IDENTITY_private_key_get_length (identity);
1428 GNUNET_CONTAINER_DLL_insert_tail (h->ait_head, h->ait_tail, ait); 1438 GNUNET_CONTAINER_DLL_insert_tail (h->ait_head, h->ait_tail, ait);
1429 env = 1439 env =
1430 GNUNET_MQ_msg (msg, 1440 GNUNET_MQ_msg_extra (msg,
1431 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_ITERATION_START); 1441 key_len,
1442 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_ITERATION_START);
1432 msg->id = htonl (rid); 1443 msg->id = htonl (rid);
1433 msg->identity = *identity; 1444 msg->key_len = htonl (key_len);
1445 GNUNET_IDENTITY_write_private_key_to_buffer (identity, &msg[1], key_len);
1434 if (NULL == h->mq) 1446 if (NULL == h->mq)
1435 ait->env = env; 1447 ait->env = env;
1436 else 1448 else
@@ -1486,23 +1498,35 @@ GNUNET_RECLAIM_ticket_issue (
1486 struct GNUNET_RECLAIM_Operation *op; 1498 struct GNUNET_RECLAIM_Operation *op;
1487 struct IssueTicketMessage *tim; 1499 struct IssueTicketMessage *tim;
1488 size_t attr_len; 1500 size_t attr_len;
1501 size_t key_len;
1502 size_t rpk_len;
1503 ssize_t written;
1504 char *buf;
1489 1505
1490 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1506 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1491 op->h = h; 1507 op->h = h;
1492 op->ti_cb = cb; 1508 op->ti_cb = cb;
1493 op->cls = cb_cls; 1509 op->cls = cb_cls;
1494 op->r_id = h->r_id_gen++; 1510 op->r_id = h->r_id_gen++;
1511 key_len = GNUNET_IDENTITY_private_key_get_length (iss);
1512 rpk_len = GNUNET_IDENTITY_public_key_get_length (rp);
1495 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1513 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1496 attr_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs); 1514 attr_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs);
1497 op->env = GNUNET_MQ_msg_extra (tim, 1515 op->env = GNUNET_MQ_msg_extra (tim,
1498 attr_len, 1516 attr_len + key_len + rpk_len,
1499 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); 1517 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET);
1500 tim->identity = *iss; 1518 tim->key_len = htonl (key_len);
1501 tim->rp = *rp; 1519 tim->pkey_len = htonl (rpk_len);
1520 buf = (char *) &tim[1];
1521 written = GNUNET_IDENTITY_write_private_key_to_buffer (iss, buf, key_len);
1522 GNUNET_assert (0 <= written);
1523 buf += written;
1524 written = GNUNET_IDENTITY_write_public_key_to_buffer (rp, buf, rpk_len);
1525 GNUNET_assert (0 <= written);
1526 buf += written;
1502 tim->id = htonl (op->r_id); 1527 tim->id = htonl (op->r_id);
1503 1528
1504 GNUNET_RECLAIM_attribute_list_serialize (attrs, (char *) &tim[1]); 1529 GNUNET_RECLAIM_attribute_list_serialize (attrs, buf);
1505
1506 tim->attr_len = htons (attr_len); 1530 tim->attr_len = htons (attr_len);
1507 if (NULL != h->mq) 1531 if (NULL != h->mq)
1508 GNUNET_MQ_send_copy (h->mq, op->env); 1532 GNUNET_MQ_send_copy (h->mq, op->env);
@@ -1532,17 +1556,28 @@ GNUNET_RECLAIM_ticket_consume (
1532{ 1556{
1533 struct GNUNET_RECLAIM_Operation *op; 1557 struct GNUNET_RECLAIM_Operation *op;
1534 struct ConsumeTicketMessage *ctm; 1558 struct ConsumeTicketMessage *ctm;
1559 size_t key_len;
1560 size_t tkt_len;
1561 char *buf;
1535 1562
1536 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1563 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1537 op->h = h; 1564 op->h = h;
1538 op->atr_cb = cb; 1565 op->atr_cb = cb;
1539 op->cls = cb_cls; 1566 op->cls = cb_cls;
1540 op->r_id = h->r_id_gen++; 1567 op->r_id = h->r_id_gen++;
1568 key_len = GNUNET_IDENTITY_private_key_get_length (identity);
1569 tkt_len = GNUNET_RECLAIM_ticket_serialize_get_size (ticket);
1541 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1570 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1542 op->env = GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); 1571 op->env = GNUNET_MQ_msg_extra (ctm,
1543 ctm->identity = *identity; 1572 key_len + tkt_len,
1573 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET);
1574 ctm->key_len = htonl (key_len);
1575 buf = (char*) &ctm[1];
1576 GNUNET_IDENTITY_write_private_key_to_buffer (identity, buf, key_len);
1577 buf += key_len;
1578 ctm->tkt_len = htonl (tkt_len);
1579 GNUNET_RECLAIM_write_ticket_to_buffer (ticket, buf, tkt_len);
1544 ctm->id = htonl (op->r_id); 1580 ctm->id = htonl (op->r_id);
1545 ctm->ticket = *ticket;
1546 if (NULL != h->mq) 1581 if (NULL != h->mq)
1547 GNUNET_MQ_send_copy (h->mq, op->env); 1582 GNUNET_MQ_send_copy (h->mq, op->env);
1548 else 1583 else
@@ -1551,23 +1586,6 @@ GNUNET_RECLAIM_ticket_consume (
1551} 1586}
1552 1587
1553 1588
1554/**
1555 * Lists all tickets that have been issued to remote
1556 * identites (relying parties)
1557 *
1558 * @param h the reclaim to use
1559 * @param identity the issuing identity
1560 * @param error_cb function to call on error (i.e. disconnect),
1561 * the handle is afterwards invalid
1562 * @param error_cb_cls closure for @a error_cb
1563 * @param proc function to call on each ticket; it
1564 * will be called repeatedly with a value (if available)
1565 * @param proc_cls closure for @a proc
1566 * @param finish_cb function to call on completion
1567 * the handle is afterwards invalid
1568 * @param finish_cb_cls closure for @a finish_cb
1569 * @return an iterator handle to use for iteration
1570 */
1571struct GNUNET_RECLAIM_TicketIterator * 1589struct GNUNET_RECLAIM_TicketIterator *
1572GNUNET_RECLAIM_ticket_iteration_start ( 1590GNUNET_RECLAIM_ticket_iteration_start (
1573 struct GNUNET_RECLAIM_Handle *h, 1591 struct GNUNET_RECLAIM_Handle *h,
@@ -1583,6 +1601,7 @@ GNUNET_RECLAIM_ticket_iteration_start (
1583 struct GNUNET_MQ_Envelope *env; 1601 struct GNUNET_MQ_Envelope *env;
1584 struct TicketIterationStartMessage *msg; 1602 struct TicketIterationStartMessage *msg;
1585 uint32_t rid; 1603 uint32_t rid;
1604 size_t key_len;
1586 1605
1587 rid = h->r_id_gen++; 1606 rid = h->r_id_gen++;
1588 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator); 1607 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator);
@@ -1594,10 +1613,17 @@ GNUNET_RECLAIM_ticket_iteration_start (
1594 it->tr_cb = proc; 1613 it->tr_cb = proc;
1595 it->cls = proc_cls; 1614 it->cls = proc_cls;
1596 it->r_id = rid; 1615 it->r_id = rid;
1616
1617 key_len = GNUNET_IDENTITY_private_key_get_length (identity);
1597 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it); 1618 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it);
1598 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START); 1619 env = GNUNET_MQ_msg_extra (msg,
1620 key_len,
1621 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START);
1599 msg->id = htonl (rid); 1622 msg->id = htonl (rid);
1600 msg->identity = *identity; 1623 msg->key_len = htonl (key_len);
1624 GNUNET_IDENTITY_write_private_key_to_buffer (identity,
1625 &msg[1],
1626 key_len);
1601 if (NULL == h->mq) 1627 if (NULL == h->mq)
1602 it->env = env; 1628 it->env = env;
1603 else 1629 else
@@ -1674,6 +1700,10 @@ GNUNET_RECLAIM_ticket_revoke (
1674 struct GNUNET_RECLAIM_Operation *op; 1700 struct GNUNET_RECLAIM_Operation *op;
1675 struct RevokeTicketMessage *msg; 1701 struct RevokeTicketMessage *msg;
1676 uint32_t rid; 1702 uint32_t rid;
1703 size_t key_len;
1704 size_t tkt_len;
1705 ssize_t written;
1706 char *buf;
1677 1707
1678 rid = h->r_id_gen++; 1708 rid = h->r_id_gen++;
1679 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1709 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
@@ -1682,10 +1712,23 @@ GNUNET_RECLAIM_ticket_revoke (
1682 op->cls = cb_cls; 1712 op->cls = cb_cls;
1683 op->r_id = rid; 1713 op->r_id = rid;
1684 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1714 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
1685 op->env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET); 1715 key_len = GNUNET_IDENTITY_private_key_get_length (identity);
1716 tkt_len = GNUNET_RECLAIM_ticket_serialize_get_size (ticket);
1717 op->env = GNUNET_MQ_msg_extra (msg,
1718 key_len + tkt_len,
1719 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET);
1686 msg->id = htonl (rid); 1720 msg->id = htonl (rid);
1687 msg->identity = *identity; 1721 msg->key_len = htonl (key_len);
1688 msg->ticket = *ticket; 1722 msg->tkt_len = htonl (tkt_len);
1723 buf = (char*) &msg[1];
1724 written = GNUNET_IDENTITY_write_private_key_to_buffer (identity,
1725 buf,
1726 key_len);
1727 GNUNET_assert (0 <= written);
1728 buf += written;
1729 GNUNET_RECLAIM_write_ticket_to_buffer (ticket,
1730 buf,
1731 tkt_len);
1689 if (NULL != h->mq) 1732 if (NULL != h->mq)
1690 { 1733 {
1691 GNUNET_MQ_send (h->mq, op->env); 1734 GNUNET_MQ_send (h->mq, op->env);
@@ -1694,5 +1737,78 @@ GNUNET_RECLAIM_ticket_revoke (
1694 return op; 1737 return op;
1695} 1738}
1696 1739
1740size_t
1741GNUNET_RECLAIM_ticket_serialize_get_size (const struct
1742 GNUNET_RECLAIM_Ticket *tkt)
1743{
1744 size_t size = sizeof (tkt->rnd);
1745 size += GNUNET_IDENTITY_public_key_get_length (&tkt->identity);
1746 size += GNUNET_IDENTITY_public_key_get_length (&tkt->audience);
1747 return size;
1748}
1749
1750enum GNUNET_GenericReturnValue
1751GNUNET_RECLAIM_read_ticket_from_buffer (const void *buffer,
1752 size_t len,
1753 struct GNUNET_RECLAIM_Ticket *tkt,
1754 size_t *tb_read)
1755{
1756 const char *tmp = buffer;
1757 size_t read = 0;
1758 size_t left = len;
1759 if (GNUNET_SYSERR ==
1760 GNUNET_IDENTITY_read_public_key_from_buffer (tmp,
1761 left,
1762 &tkt->identity,
1763 &read))
1764 return GNUNET_SYSERR;
1765 left -= read;
1766 tmp += read;
1767 if (GNUNET_SYSERR ==
1768 GNUNET_IDENTITY_read_public_key_from_buffer (tmp,
1769 left,
1770 &tkt->audience,
1771 &read))
1772 return GNUNET_SYSERR;
1773 left -= read;
1774 tmp += read;
1775 if (left < sizeof (tkt->rnd))
1776 return GNUNET_SYSERR;
1777 memcpy (&tkt->rnd, tmp, sizeof (tkt->rnd));
1778 *tb_read = tmp - (char*) buffer + sizeof (tkt->rnd);
1779 return GNUNET_OK;
1780}
1781
1782
1783ssize_t
1784GNUNET_RECLAIM_write_ticket_to_buffer (const struct
1785 GNUNET_RECLAIM_Ticket *tkt,
1786 void *buffer,
1787 size_t len)
1788{
1789 char *tmp = buffer;
1790 size_t left = len;
1791 ssize_t written = 0;
1792 written = GNUNET_IDENTITY_write_public_key_to_buffer (&tkt->identity,
1793 buffer,
1794 left);
1795 if (0 > written)
1796 return written;
1797 left -= written;
1798 tmp += written;
1799 written = GNUNET_IDENTITY_write_public_key_to_buffer (&tkt->audience,
1800 tmp,
1801 left);
1802 if (0 > written)
1803 return written;
1804 left -= written;
1805 tmp += written;
1806 if (left < sizeof (tkt->rnd))
1807 return -1;
1808 memcpy (tmp, &tkt->rnd, sizeof (tkt->rnd));
1809 return tmp - (char*) buffer + sizeof (tkt->rnd);
1810}
1811
1812
1697 1813
1698/* end of reclaim_api.c */ 1814/* end of reclaim_api.c */
diff --git a/src/reclaim/test_did_helper.c b/src/reclaim/test_did_helper.c
index 698edf180..446c199fc 100644
--- a/src/reclaim/test_did_helper.c
+++ b/src/reclaim/test_did_helper.c
@@ -78,8 +78,9 @@ test_GNUNET_DID_did_to_pkey ()
78 DID_did_to_pkey ((char *) test_did, &pkey); 78 DID_did_to_pkey ((char *) test_did, &pkey);
79 79
80 GNUNET_assert (test_pkey.type = pkey.type); 80 GNUNET_assert (test_pkey.type = pkey.type);
81 GNUNET_assert (strcmp (pkey.eddsa_key.q_y, 81 GNUNET_assert (memcmp (&pkey.eddsa_key,
82 test_pkey.eddsa_key.q_y) == 0); 82 &test_pkey.eddsa_key,
83 sizeof (test_pkey.eddsa_key)) == 0);
83} 84}
84 85
85// void 86// void
diff --git a/src/reclaim/test_reclaim.conf b/src/reclaim/test_reclaim.conf
index 2dc53fe81..faa195ae1 100644
--- a/src/reclaim/test_reclaim.conf
+++ b/src/reclaim/test_reclaim.conf
@@ -13,9 +13,13 @@ PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/r
13[transport] 13[transport]
14PLUGINS = 14PLUGINS =
15 15
16[zonemaster]
17START_ON_DEMAND = YES
18IMMEDIATE_START = YES
19
16[reclaim] 20[reclaim]
17START_ON_DEMAND = YES 21START_ON_DEMAND = YES
18TICKET_REFRESH_INTERVAL = 30 s 22TICKET_REFRESH_INTERVAL = 1 h
19#PREFIX = valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file=$GNUNET_TMP/idplog 23#PREFIX = valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file=$GNUNET_TMP/idplog
20 24
21[gns] 25[gns]
diff --git a/src/reclaim/test_reclaim_attribute.sh b/src/reclaim/test_reclaim_attribute.sh
index 744c898ed..17f7863d4 100755
--- a/src/reclaim/test_reclaim_attribute.sh
+++ b/src/reclaim/test_reclaim_attribute.sh
@@ -29,7 +29,7 @@ gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf 29gnunet-identity -C rpego -c test_reclaim.conf
30TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf) 30TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf)
31gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf 31gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
32gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf > /dev/null 2>&1 32gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
33if test $? != 0 33if test $? != 0
34then 34then
35 echo "Failed." 35 echo "Failed."
diff --git a/src/reclaim/test_reclaim_consume.sh b/src/reclaim/test_reclaim_consume.sh
index c012862c3..8a88136c6 100755
--- a/src/reclaim/test_reclaim_consume.sh
+++ b/src/reclaim/test_reclaim_consume.sh
@@ -25,6 +25,7 @@ which timeout >/dev/null 2>&1 && DO_TIMEOUT="timeout 30"
25TEST_ATTR="test" 25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf 26gnunet-arm -s -c test_reclaim.conf
27#gnunet-arm -i rest -c test_reclaim.conf 27#gnunet-arm -i rest -c test_reclaim.conf
28gnunet-arm -I
28gnunet-identity -C testego -c test_reclaim.conf 29gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf 30gnunet-identity -C rpego -c test_reclaim.conf
30SUBJECT_KEY=$(gnunet-identity -d -e rpego -q -c test_reclaim.conf) 31SUBJECT_KEY=$(gnunet-identity -d -e rpego -q -c test_reclaim.conf)
@@ -32,7 +33,10 @@ TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf)
32gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf 33gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
33gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf 34gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
34TICKET=$(gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf | awk '{print $1}') 35TICKET=$(gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf | awk '{print $1}')
35gnunet-reclaim -e rpego -C $TICKET -c test_reclaim.conf #>/dev/null 2>&1 36gnunet-namestore -z testego -D -c test_reclaim.conf
37gnunet-identity -d -c test_reclaim.conf
38sleep 1
39gnunet-reclaim -e rpego -C $TICKET -c test_reclaim.conf
36 40
37RES=$? 41RES=$?
38gnunet-identity -D testego -c test_reclaim.conf 42gnunet-identity -D testego -c test_reclaim.conf
diff --git a/src/reclaim/test_reclaim_issue.sh b/src/reclaim/test_reclaim_issue.sh
index cfddc9407..63140e54c 100755
--- a/src/reclaim/test_reclaim_issue.sh
+++ b/src/reclaim/test_reclaim_issue.sh
@@ -29,8 +29,8 @@ gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf 29gnunet-identity -C rpego -c test_reclaim.conf
30SUBJECT_KEY=$(gnunet-identity -d -e rpego -q -c test_reclaim.conf) 30SUBJECT_KEY=$(gnunet-identity -d -e rpego -q -c test_reclaim.conf)
31TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf) 31TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf)
32gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf > /dev/null 2>&1 32gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
33gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf > /dev/null 2>&1 33gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
34#gnunet-reclaim -e testego -D -c test_reclaim.conf 34#gnunet-reclaim -e testego -D -c test_reclaim.conf
35gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf > /dev/null 2>&1 35gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf > /dev/null 2>&1
36if test $? != 0 36if test $? != 0
diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c
index 682f41530..a126709ce 100644
--- a/src/revocation/gnunet-revocation-tvg.c
+++ b/src/revocation/gnunet-revocation-tvg.c
@@ -115,14 +115,14 @@ run (void *cls,
115 GNUNET_IDENTITY_key_get_public (&id_priv, 115 GNUNET_IDENTITY_key_get_public (&id_priv,
116 &id_pub); 116 &id_pub);
117 GNUNET_STRINGS_data_to_string (&id_pub, 117 GNUNET_STRINGS_data_to_string (&id_pub,
118 GNUNET_IDENTITY_key_get_length (&id_pub), 118 GNUNET_IDENTITY_public_key_get_length (&id_pub),
119 ztld, 119 ztld,
120 sizeof (ztld)); 120 sizeof (ztld));
121 fprintf (stdout, "Zone private key (d, big-endian scalar):\n"); 121 fprintf (stdout, "Zone private key (d, big-endian scalar):\n");
122 print_bytes_ (&id_priv.ecdsa_key, sizeof(id_priv.ecdsa_key), 8, 1); 122 print_bytes_ (&id_priv.ecdsa_key, sizeof(id_priv.ecdsa_key), 8, 1);
123 fprintf (stdout, "\n"); 123 fprintf (stdout, "\n");
124 fprintf (stdout, "Zone identifier (ztype|zkey):\n"); 124 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
125 key_len = GNUNET_IDENTITY_key_get_length (&id_pub); 125 key_len = GNUNET_IDENTITY_public_key_get_length (&id_pub);
126 GNUNET_assert (0 < key_len); 126 GNUNET_assert (0 < key_len);
127 print_bytes (&id_pub, key_len, 8); 127 print_bytes (&id_pub, key_len, 8);
128 fprintf (stdout, "\n"); 128 fprintf (stdout, "\n");
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index a7f96385c..853ca0f71 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -343,7 +343,7 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego)
343 GNUNET_DISK_fn_read (filename, proof_of_work, 343 GNUNET_DISK_fn_read (filename, proof_of_work,
344 GNUNET_REVOCATION_MAX_PROOF_SIZE)))) 344 GNUNET_REVOCATION_MAX_PROOF_SIZE))))
345 { 345 {
346 ssize_t ksize = GNUNET_IDENTITY_key_get_length (&key); 346 ssize_t ksize = GNUNET_IDENTITY_public_key_get_length (&key);
347 if (0 > ksize) 347 if (0 > ksize)
348 { 348 {
349 fprintf (stderr, 349 fprintf (stderr,
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index 4494ade83..fe74201f3 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -316,7 +316,7 @@ publicize_rm (const struct RevokeMessage *rm)
316 const struct GNUNET_IDENTITY_PublicKey *pk 316 const struct GNUNET_IDENTITY_PublicKey *pk
317 = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; 317 = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
318 318
319 pklen = GNUNET_IDENTITY_key_get_length (pk); 319 pklen = GNUNET_IDENTITY_public_key_get_length (pk);
320 if (0 > pklen) 320 if (0 > pklen)
321 { 321 {
322 GNUNET_break_op (0); 322 GNUNET_break_op (0);
@@ -950,7 +950,7 @@ run (void *cls,
950 GNUNET_REVOCATION_PowP *) &rm[1]; 950 GNUNET_REVOCATION_PowP *) &rm[1];
951 ssize_t ksize; 951 ssize_t ksize;
952 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; 952 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
953 ksize = GNUNET_IDENTITY_key_get_length (pk); 953 ksize = GNUNET_IDENTITY_public_key_get_length (pk);
954 if (0 > ksize) 954 if (0 > ksize)
955 { 955 {
956 GNUNET_break_op (0); 956 GNUNET_break_op (0);
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c
index 12ec555e4..0c81440eb 100644
--- a/src/revocation/plugin_block_revocation.c
+++ b/src/revocation/plugin_block_revocation.c
@@ -56,10 +56,10 @@ struct InternalContext
56 */ 56 */
57static enum GNUNET_GenericReturnValue 57static enum GNUNET_GenericReturnValue
58block_plugin_revocation_check_query (void *cls, 58block_plugin_revocation_check_query (void *cls,
59 enum GNUNET_BLOCK_Type type, 59 enum GNUNET_BLOCK_Type type,
60 const struct GNUNET_HashCode *query, 60 const struct GNUNET_HashCode *query,
61 const void *xquery, 61 const void *xquery,
62 size_t xquery_size) 62 size_t xquery_size)
63{ 63{
64 (void) cls; 64 (void) cls;
65 (void) query; 65 (void) query;
@@ -86,16 +86,16 @@ block_plugin_revocation_check_query (void *cls,
86 */ 86 */
87static enum GNUNET_GenericReturnValue 87static enum GNUNET_GenericReturnValue
88block_plugin_revocation_check_block (void *cls, 88block_plugin_revocation_check_block (void *cls,
89 enum GNUNET_BLOCK_Type type, 89 enum GNUNET_BLOCK_Type type,
90 const void *block, 90 const void *block,
91 size_t block_size) 91 size_t block_size)
92{ 92{
93 struct InternalContext *ic = cls; 93 struct InternalContext *ic = cls;
94 const struct RevokeMessage *rm = block; 94 const struct RevokeMessage *rm = block;
95 const struct GNUNET_REVOCATION_PowP *pow 95 const struct GNUNET_REVOCATION_PowP *pow
96 = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; 96 = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
97 struct GNUNET_IDENTITY_PublicKey pk; 97 struct GNUNET_IDENTITY_PublicKey pk;
98 ssize_t pklen; 98 size_t pklen;
99 size_t left; 99 size_t left;
100 100
101 if (GNUNET_BLOCK_TYPE_REVOCATION != type) 101 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
@@ -114,9 +114,10 @@ block_plugin_revocation_check_block (void *cls,
114 return GNUNET_NO; 114 return GNUNET_NO;
115 } 115 }
116 left = block_size - sizeof (*rm) - sizeof (*pow); 116 left = block_size - sizeof (*rm) - sizeof (*pow);
117 pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk, 117 GNUNET_IDENTITY_read_public_key_from_buffer (&pow[1],
118 &pow[1], 118 left,
119 left); 119 &pk,
120 &pklen);
120 if (0 > pklen) 121 if (0 > pklen)
121 { 122 {
122 GNUNET_break_op (0); 123 GNUNET_break_op (0);
@@ -152,14 +153,14 @@ block_plugin_revocation_check_block (void *cls,
152 */ 153 */
153static enum GNUNET_BLOCK_ReplyEvaluationResult 154static enum GNUNET_BLOCK_ReplyEvaluationResult
154block_plugin_revocation_check_reply ( 155block_plugin_revocation_check_reply (
155 void *cls, 156 void *cls,
156 enum GNUNET_BLOCK_Type type, 157 enum GNUNET_BLOCK_Type type,
157 struct GNUNET_BLOCK_Group *group, 158 struct GNUNET_BLOCK_Group *group,
158 const struct GNUNET_HashCode *query, 159 const struct GNUNET_HashCode *query,
159 const void *xquery, 160 const void *xquery,
160 size_t xquery_size, 161 size_t xquery_size,
161 const void *reply_block, 162 const void *reply_block,
162 size_t reply_block_size) 163 size_t reply_block_size)
163{ 164{
164 (void) cls; 165 (void) cls;
165 (void) group; 166 (void) group;
@@ -199,7 +200,7 @@ block_plugin_revocation_get_key (void *cls,
199 const struct GNUNET_REVOCATION_PowP *pow 200 const struct GNUNET_REVOCATION_PowP *pow
200 = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; 201 = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
201 struct GNUNET_IDENTITY_PublicKey pk; 202 struct GNUNET_IDENTITY_PublicKey pk;
202 ssize_t pklen; 203 size_t pklen;
203 size_t left; 204 size_t left;
204 205
205 if (GNUNET_BLOCK_TYPE_REVOCATION != type) 206 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
@@ -218,9 +219,10 @@ block_plugin_revocation_get_key (void *cls,
218 return GNUNET_NO; 219 return GNUNET_NO;
219 } 220 }
220 left = block_size - sizeof (*rm) - sizeof (*pow); 221 left = block_size - sizeof (*rm) - sizeof (*pow);
221 pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk, 222 GNUNET_IDENTITY_read_public_key_from_buffer (&pow[1],
222 &pow[1], 223 left,
223 left); 224 &pk,
225 &pklen);
224 if (0 > pklen) 226 if (0 > pklen)
225 { 227 {
226 GNUNET_break_op (0); 228 GNUNET_break_op (0);
@@ -242,7 +244,7 @@ void *
242libgnunet_plugin_block_revocation_init (void *cls) 244libgnunet_plugin_block_revocation_init (void *cls)
243{ 245{
244 static const enum GNUNET_BLOCK_Type types[] = { 246 static const enum GNUNET_BLOCK_Type types[] = {
245 GNUNET_BLOCK_TYPE_REVOCATION, 247 GNUNET_BLOCK_TYPE_REVOCATION,
246 GNUNET_BLOCK_TYPE_ANY /* end of list */ 248 GNUNET_BLOCK_TYPE_ANY /* end of list */
247 }; 249 };
248 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 250 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 78b3c083a..34b4eddd7 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -407,14 +407,14 @@ REV_create_signature_message (const struct GNUNET_REVOCATION_PowP *pow)
407 size_t ksize; 407 size_t ksize;
408 408
409 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; 409 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
410 ksize = GNUNET_IDENTITY_key_get_length (pk); 410 ksize = GNUNET_IDENTITY_public_key_get_length (pk);
411 spurp = GNUNET_malloc (sizeof (*spurp) + ksize); 411 spurp = GNUNET_malloc (sizeof (*spurp) + ksize);
412 spurp->timestamp = pow->timestamp; 412 spurp->timestamp = pow->timestamp;
413 spurp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); 413 spurp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
414 spurp->purpose.size = htonl (sizeof(*spurp) + ksize); 414 spurp->purpose.size = htonl (sizeof(*spurp) + ksize);
415 GNUNET_IDENTITY_write_key_to_buffer (pk, 415 GNUNET_IDENTITY_write_public_key_to_buffer (pk,
416 (char*) &spurp[1], 416 (char*) &spurp[1],
417 ksize); 417 ksize);
418 return spurp; 418 return spurp;
419} 419}
420 420
@@ -426,14 +426,15 @@ check_signature_identity (const struct GNUNET_REVOCATION_PowP *pow,
426 unsigned char *sig; 426 unsigned char *sig;
427 size_t ksize; 427 size_t ksize;
428 428
429 ksize = GNUNET_IDENTITY_key_get_length (key); 429 ksize = GNUNET_IDENTITY_public_key_get_length (key);
430 spurp = REV_create_signature_message (pow); 430 spurp = REV_create_signature_message (pow);
431 sig = ((unsigned char*) &pow[1] + ksize); 431 sig = ((unsigned char*) &pow[1] + ksize);
432 if (GNUNET_OK != 432 if (GNUNET_OK !=
433 GNUNET_IDENTITY_signature_verify_raw_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, 433 GNUNET_IDENTITY_signature_verify_raw_ (
434 &spurp->purpose, 434 GNUNET_SIGNATURE_PURPOSE_REVOCATION,
435 sig, 435 &spurp->purpose,
436 key)) 436 sig,
437 key))
437 { 438 {
438 return GNUNET_SYSERR; 439 return GNUNET_SYSERR;
439 } 440 }
@@ -503,7 +504,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
503 GNUNET_memcpy (&buf[sizeof(uint64_t)], 504 GNUNET_memcpy (&buf[sizeof(uint64_t)],
504 &pow->timestamp, 505 &pow->timestamp,
505 sizeof (uint64_t)); 506 sizeof (uint64_t));
506 pklen = GNUNET_IDENTITY_key_get_length (pk); 507 pklen = GNUNET_IDENTITY_public_key_get_length (pk);
507 if (0 > pklen) 508 if (0 > pklen)
508 { 509 {
509 GNUNET_break (0); 510 GNUNET_break (0);
@@ -578,7 +579,7 @@ sign_pow_identity (const struct GNUNET_IDENTITY_PrivateKey *key,
578 ts = GNUNET_TIME_absolute_subtract (ts, 579 ts = GNUNET_TIME_absolute_subtract (ts,
579 GNUNET_TIME_UNIT_WEEKS); 580 GNUNET_TIME_UNIT_WEEKS);
580 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; 581 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
581 ksize = GNUNET_IDENTITY_key_get_length (pk); 582 ksize = GNUNET_IDENTITY_public_key_get_length (pk);
582 pow->timestamp = GNUNET_TIME_absolute_hton (ts); 583 pow->timestamp = GNUNET_TIME_absolute_hton (ts);
583 rp = REV_create_signature_message (pow); 584 rp = REV_create_signature_message (pow);
584 sig = ((char*) &pow[1]) + ksize; 585 sig = ((char*) &pow[1]) + ksize;
@@ -691,7 +692,7 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
691 GNUNET_memcpy (&buf[sizeof(uint64_t)], 692 GNUNET_memcpy (&buf[sizeof(uint64_t)],
692 &pc->pow->timestamp, 693 &pc->pow->timestamp,
693 sizeof (uint64_t)); 694 sizeof (uint64_t));
694 ksize = GNUNET_IDENTITY_key_get_length (pk); 695 ksize = GNUNET_IDENTITY_public_key_get_length (pk);
695 GNUNET_assert (0 < ksize); 696 GNUNET_assert (0 < ksize);
696 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], 697 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
697 pk, 698 pk,
@@ -749,7 +750,7 @@ GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow)
749 750
750 size = sizeof (struct GNUNET_REVOCATION_PowP); 751 size = sizeof (struct GNUNET_REVOCATION_PowP);
751 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; 752 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
752 ksize = GNUNET_IDENTITY_key_get_length (pk); 753 ksize = GNUNET_IDENTITY_public_key_get_length (pk);
753 size += ksize; 754 size += ksize;
754 size += GNUNET_IDENTITY_signature_get_raw_length_by_type (pk->type); 755 size += GNUNET_IDENTITY_signature_get_raw_length_by_type (pk->type);
755 return size; 756 return size;