aboutsummaryrefslogtreecommitdiff
path: root/src/credential
diff options
context:
space:
mode:
authorAndreas Ebner <pansy007@googlemail.com>2019-08-06 16:17:33 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-10-07 12:17:28 +0200
commit33525da20575ba0149d1c6bcaac74e52d4e0ddd7 (patch)
tree91966b82a290b9b9d34c9d6e1c10f13d1b8156ed /src/credential
parent15b0d71a635f02f5e0291a695d35a65698fdea05 (diff)
downloadgnunet-33525da20575ba0149d1c6bcaac74e52d4e0ddd7.tar.gz
gnunet-33525da20575ba0149d1c6bcaac74e52d4e0ddd7.zip
Removed GNUNET_CREDENTIAL_Credential, new cmdline parameters, formatting:
- removed all files and functions related to GNUNET_CREDENTIAL_Credential, has been replaced by GNUNET_CREDENTIAL_Delegate - renamed cmline parameter 'credential' - added cmline parameter for backward/forward search and a related enum - added cmline parameter to store private delegates - only private delegates are used as start/end of the search algorithm (set to vrh in collect) - run valgrind: no memory exceptions - run clang-format
Diffstat (limited to 'src/credential')
-rw-r--r--src/credential/Makefile.am2
-rw-r--r--src/credential/credential.h4
-rw-r--r--src/credential/credential_api.c189
-rw-r--r--src/credential/credential_misc.c176
-rw-r--r--src/credential/credential_misc.h36
-rw-r--r--src/credential/credential_serialization.c91
-rw-r--r--src/credential/credential_serialization.h112
-rw-r--r--src/credential/gnunet-credential.c294
-rw-r--r--src/credential/gnunet-service-credential.c643
-rw-r--r--src/credential/plugin_gnsrecord_credential.c21
-rwxr-xr-xsrc/credential/test_credential_own.sh28
11 files changed, 683 insertions, 913 deletions
diff --git a/src/credential/Makefile.am b/src/credential/Makefile.am
index d7d8964eb..e72cf4f79 100644
--- a/src/credential/Makefile.am
+++ b/src/credential/Makefile.am
@@ -72,8 +72,6 @@ libgnunetcredential_la_SOURCES = \
72 credential_api.c credential.h\ 72 credential_api.c credential.h\
73 credential_serialization.c \ 73 credential_serialization.c \
74 credential_serialization.h \ 74 credential_serialization.h \
75 credential_misc.c \
76 credential_misc.h \
77 delegate_misc.c \ 75 delegate_misc.c \
78 delegate_misc.h 76 delegate_misc.h
79libgnunetcredential_la_LIBADD = \ 77libgnunetcredential_la_LIBADD = \
diff --git a/src/credential/credential.h b/src/credential/credential.h
index ca8fb78d7..43ecec73f 100644
--- a/src/credential/credential.h
+++ b/src/credential/credential.h
@@ -29,8 +29,6 @@
29 29
30GNUNET_NETWORK_STRUCT_BEGIN 30GNUNET_NETWORK_STRUCT_BEGIN
31 31
32enum direction{Backward, Forward, Bidirectional};
33
34/** 32/**
35 * Message from client to Credential service to collect credentials. 33 * Message from client to Credential service to collect credentials.
36 */ 34 */
@@ -249,7 +247,7 @@ struct DelegateEntry
249 * Expiration time of this credential 247 * Expiration time of this credential
250 */ 248 */
251 uint64_t expiration GNUNET_PACKED; 249 uint64_t expiration GNUNET_PACKED;
252 250
253 /** 251 /**
254 * Issuer subject attribute length 252 * Issuer subject attribute length
255 */ 253 */
diff --git a/src/credential/credential_api.c b/src/credential/credential_api.c
index 4fe32465a..7c3b35464 100644
--- a/src/credential/credential_api.c
+++ b/src/credential/credential_api.c
@@ -35,7 +35,7 @@
35#include "gnunet_identity_service.h" 35#include "gnunet_identity_service.h"
36 36
37 37
38#define LOG(kind,...) GNUNET_log_from (kind, "credential-api",__VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "credential-api", __VA_ARGS__)
39 39
40/** 40/**
41 * Handle to a verify request 41 * Handle to a verify request
@@ -77,7 +77,6 @@ struct GNUNET_CREDENTIAL_Request
77 * request id 77 * request id
78 */ 78 */
79 uint32_t r_id; 79 uint32_t r_id;
80
81}; 80};
82 81
83 82
@@ -121,7 +120,6 @@ struct GNUNET_CREDENTIAL_Handle
121 * Request Id generator. Incremented by one for each request. 120 * Request Id generator. Incremented by one for each request.
122 */ 121 */
123 uint32_t r_id_gen; 122 uint32_t r_id_gen;
124
125}; 123};
126 124
127 125
@@ -159,12 +157,12 @@ force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
159{ 157{
160 GNUNET_MQ_destroy (handle->mq); 158 GNUNET_MQ_destroy (handle->mq);
161 handle->mq = NULL; 159 handle->mq = NULL;
162 handle->reconnect_backoff 160 handle->reconnect_backoff =
163 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); 161 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
164 handle->reconnect_task 162 handle->reconnect_task =
165 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, 163 GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
166 &reconnect_task, 164 &reconnect_task,
167 handle); 165 handle);
168} 166}
169 167
170 168
@@ -177,8 +175,7 @@ force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
177 * @param error error code 175 * @param error error code
178 */ 176 */
179static void 177static void
180mq_error_handler (void *cls, 178mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
181 enum GNUNET_MQ_Error error)
182{ 179{
183 struct GNUNET_CREDENTIAL_Handle *handle = cls; 180 struct GNUNET_CREDENTIAL_Handle *handle = cls;
184 181
@@ -192,8 +189,7 @@ mq_error_handler (void *cls,
192 * @param vr_msg the incoming message 189 * @param vr_msg the incoming message
193 */ 190 */
194static int 191static int
195check_result (void *cls, 192check_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
196 const struct DelegationChainResultMessage *vr_msg)
197{ 193{
198 //TODO 194 //TODO
199 return GNUNET_OK; 195 return GNUNET_OK;
@@ -207,8 +203,7 @@ check_result (void *cls,
207 * @param vr_msg the incoming message 203 * @param vr_msg the incoming message
208 */ 204 */
209static void 205static void
210handle_result (void *cls, 206handle_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
211 const struct DelegationChainResultMessage *vr_msg)
212{ 207{
213 struct GNUNET_CREDENTIAL_Handle *handle = cls; 208 struct GNUNET_CREDENTIAL_Handle *handle = cls;
214 uint32_t r_id = ntohl (vr_msg->id); 209 uint32_t r_id = ntohl (vr_msg->id);
@@ -230,31 +225,25 @@ handle_result (void *cls,
230 return; 225 return;
231 proc = vr->verify_proc; 226 proc = vr->verify_proc;
232 proc_cls = vr->proc_cls; 227 proc_cls = vr->proc_cls;
233 GNUNET_CONTAINER_DLL_remove (handle->request_head, 228 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, vr);
234 handle->request_tail,
235 vr);
236 GNUNET_MQ_discard (vr->env); 229 GNUNET_MQ_discard (vr->env);
237 GNUNET_free (vr); 230 GNUNET_free (vr);
238 GNUNET_assert (GNUNET_OK == 231 GNUNET_assert (
239 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen, 232 GNUNET_OK ==
240 (const char*) &vr_msg[1], 233 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen,
241 d_count, 234 (const char *) &vr_msg[1],
242 d_chain, 235 d_count,
243 c_count, 236 d_chain,
244 dels)); 237 c_count,
238 dels));
245 if (GNUNET_NO == ntohl (vr_msg->del_found)) 239 if (GNUNET_NO == ntohl (vr_msg->del_found))
246 { 240 {
247 proc (proc_cls, 241 proc (proc_cls, 0, NULL, 0,
248 0,
249 NULL,
250 0,
251 NULL); // TODO 242 NULL); // TODO
252 } else { 243 }
253 proc (proc_cls, 244 else
254 d_count, 245 {
255 d_chain, 246 proc (proc_cls, d_count, d_chain, c_count, dels);
256 c_count,
257 dels);
258 } 247 }
259} 248}
260 249
@@ -267,22 +256,20 @@ handle_result (void *cls,
267static void 256static void
268reconnect (struct GNUNET_CREDENTIAL_Handle *handle) 257reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
269{ 258{
270 struct GNUNET_MQ_MessageHandler handlers[] = { 259 struct GNUNET_MQ_MessageHandler handlers[] =
271 GNUNET_MQ_hd_var_size (result, 260 {GNUNET_MQ_hd_var_size (result,
272 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT, 261 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT,
273 struct DelegationChainResultMessage, 262 struct DelegationChainResultMessage,
274 handle), 263 handle),
275 GNUNET_MQ_hd_var_size (result, 264 GNUNET_MQ_hd_var_size (result,
276 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT, 265 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT,
277 struct DelegationChainResultMessage, 266 struct DelegationChainResultMessage,
278 handle), 267 handle),
279 GNUNET_MQ_handler_end () 268 GNUNET_MQ_handler_end ()};
280 };
281 struct GNUNET_CREDENTIAL_Request *vr; 269 struct GNUNET_CREDENTIAL_Request *vr;
282 270
283 GNUNET_assert (NULL == handle->mq); 271 GNUNET_assert (NULL == handle->mq);
284 LOG (GNUNET_ERROR_TYPE_DEBUG, 272 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to CREDENTIAL\n");
285 "Trying to connect to CREDENTIAL\n");
286 handle->mq = GNUNET_CLIENT_connect (handle->cfg, 273 handle->mq = GNUNET_CLIENT_connect (handle->cfg,
287 "credential", 274 "credential",
288 handlers, 275 handlers,
@@ -291,8 +278,7 @@ reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
291 if (NULL == handle->mq) 278 if (NULL == handle->mq)
292 return; 279 return;
293 for (vr = handle->request_head; NULL != vr; vr = vr->next) 280 for (vr = handle->request_head; NULL != vr; vr = vr->next)
294 GNUNET_MQ_send_copy (handle->mq, 281 GNUNET_MQ_send_copy (handle->mq, vr->env);
295 vr->env);
296} 282}
297 283
298 284
@@ -352,9 +338,7 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
352{ 338{
353 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle; 339 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle;
354 340
355 GNUNET_CONTAINER_DLL_remove (handle->request_head, 341 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, lr);
356 handle->request_tail,
357 lr);
358 GNUNET_MQ_discard (lr->env); 342 GNUNET_MQ_discard (lr->env);
359 GNUNET_free (lr); 343 GNUNET_free (lr);
360} 344}
@@ -373,13 +357,15 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
373 * @param proc_cls closure for processor 357 * @param proc_cls closure for processor
374 * @return handle to the queued request 358 * @return handle to the queued request
375 */ 359 */
376struct GNUNET_CREDENTIAL_Request* 360struct GNUNET_CREDENTIAL_Request *
377GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle, 361GNUNET_CREDENTIAL_collect (
378 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 362 struct GNUNET_CREDENTIAL_Handle *handle,
379 const char *issuer_attribute, 363 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
380 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key, 364 const char *issuer_attribute,
381 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 365 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key,
382 void *proc_cls) 366 enum GNUNET_CREDENTIAL_AlgoDirectionFlags direction,
367 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
368 void *proc_cls)
383{ 369{
384 /* IPC to shorten credential names, return shorten_handle */ 370 /* IPC to shorten credential names, return shorten_handle */
385 struct CollectMessage *c_msg; 371 struct CollectMessage *c_msg;
@@ -407,25 +393,18 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
407 vr->verify_proc = proc; 393 vr->verify_proc = proc;
408 vr->proc_cls = proc_cls; 394 vr->proc_cls = proc_cls;
409 vr->r_id = handle->r_id_gen++; 395 vr->r_id = handle->r_id_gen++;
410 vr->env = GNUNET_MQ_msg_extra (c_msg, 396 vr->env =
411 nlen, 397 GNUNET_MQ_msg_extra (c_msg, nlen, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT);
412 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT);
413 c_msg->id = htonl (vr->r_id); 398 c_msg->id = htonl (vr->r_id);
414 c_msg->subject_key = *subject_key; 399 c_msg->subject_key = *subject_key;
415 c_msg->issuer_key = *issuer_key; 400 c_msg->issuer_key = *issuer_key;
416 c_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); 401 c_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
417 c_msg->resolution_algo = htons(Backward); 402 c_msg->resolution_algo = htons (direction);
418 //c_msg->resolution_algo = htons(Forward); 403
419 404 GNUNET_memcpy (&c_msg[1], issuer_attribute, strlen (issuer_attribute));
420 GNUNET_memcpy (&c_msg[1], 405 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
421 issuer_attribute,
422 strlen (issuer_attribute));
423 GNUNET_CONTAINER_DLL_insert (handle->request_head,
424 handle->request_tail,
425 vr);
426 if (NULL != handle->mq) 406 if (NULL != handle->mq)
427 GNUNET_MQ_send_copy (handle->mq, 407 GNUNET_MQ_send_copy (handle->mq, vr->env);
428 vr->env);
429 return vr; 408 return vr;
430} 409}
431/** 410/**
@@ -446,15 +425,17 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
446 * @param proc_cls closure for processor 425 * @param proc_cls closure for processor
447 * @return handle to the queued request 426 * @return handle to the queued request
448 */ 427 */
449struct GNUNET_CREDENTIAL_Request* 428struct GNUNET_CREDENTIAL_Request *
450GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle, 429GNUNET_CREDENTIAL_verify (
451 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 430 struct GNUNET_CREDENTIAL_Handle *handle,
452 const char *issuer_attribute, 431 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
453 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, 432 const char *issuer_attribute,
454 uint32_t delegate_count, 433 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
455 const struct GNUNET_CREDENTIAL_Delegate *delegates, 434 uint32_t delegate_count,
456 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 435 const struct GNUNET_CREDENTIAL_Delegate *delegates,
457 void *proc_cls) 436 enum GNUNET_CREDENTIAL_AlgoDirectionFlags direction,
437 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
438 void *proc_cls)
458{ 439{
459 /* IPC to shorten credential names, return shorten_handle */ 440 /* IPC to shorten credential names, return shorten_handle */
460 struct VerifyMessage *v_msg; 441 struct VerifyMessage *v_msg;
@@ -468,8 +449,7 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
468 return NULL; 449 return NULL;
469 } 450 }
470 451
471 clen = GNUNET_CREDENTIAL_delegates_get_size (delegate_count, 452 clen = GNUNET_CREDENTIAL_delegates_get_size (delegate_count, delegates);
472 delegates);
473 453
474 //DEBUG LOG 454 //DEBUG LOG
475 LOG (GNUNET_ERROR_TYPE_DEBUG, 455 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -486,31 +466,24 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
486 vr->verify_proc = proc; 466 vr->verify_proc = proc;
487 vr->proc_cls = proc_cls; 467 vr->proc_cls = proc_cls;
488 vr->r_id = handle->r_id_gen++; 468 vr->r_id = handle->r_id_gen++;
489 vr->env = GNUNET_MQ_msg_extra (v_msg, 469 vr->env =
490 nlen, 470 GNUNET_MQ_msg_extra (v_msg, nlen, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY);
491 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY);
492 v_msg->id = htonl (vr->r_id); 471 v_msg->id = htonl (vr->r_id);
493 v_msg->subject_key = *subject_key; 472 v_msg->subject_key = *subject_key;
494 v_msg->d_count = htonl(delegate_count); 473 v_msg->d_count = htonl (delegate_count);
495 v_msg->issuer_key = *issuer_key; 474 v_msg->issuer_key = *issuer_key;
496 v_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); 475 v_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
497 v_msg->resolution_algo = htons(Backward); 476 v_msg->resolution_algo = htons (direction);
498 //v_msg->resolution_algo = htons(Forward); 477
499 478 GNUNET_memcpy (&v_msg[1], issuer_attribute, strlen (issuer_attribute));
500 GNUNET_memcpy (&v_msg[1],
501 issuer_attribute,
502 strlen (issuer_attribute));
503 GNUNET_CREDENTIAL_delegates_serialize (delegate_count, 479 GNUNET_CREDENTIAL_delegates_serialize (delegate_count,
504 delegates, 480 delegates,
505 clen, 481 clen,
506 ((char*)&v_msg[1]) 482 ((char *) &v_msg[1]) +
507 + strlen (issuer_attribute) + 1); 483 strlen (issuer_attribute) + 1);
508 GNUNET_CONTAINER_DLL_insert (handle->request_head, 484 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
509 handle->request_tail,
510 vr);
511 if (NULL != handle->mq) 485 if (NULL != handle->mq)
512 GNUNET_MQ_send_copy (handle->mq, 486 GNUNET_MQ_send_copy (handle->mq, vr->env);
513 vr->env);
514 return vr; 487 return vr;
515} 488}
516 489
diff --git a/src/credential/credential_misc.c b/src/credential/credential_misc.c
deleted file mode 100644
index 13435273e..000000000
--- a/src/credential/credential_misc.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21
22/**
23 * @file credential/credential_misc.c
24 * @brief Misc API for credentials
25 *
26 * @author Martin Schanzenbach
27 */
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_constants.h"
31#include "gnunet_credential_service.h"
32#include "gnunet_signatures.h"
33#include "credential.h"
34#include <inttypes.h>
35
36char*
37GNUNET_CREDENTIAL_credential_to_string (const struct
38 GNUNET_CREDENTIAL_Credential *cred)
39{
40 char *cred_str;
41 char *subject_pkey;
42 char *issuer_pkey;
43 char *signature;
44
45
46 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key);
47 issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key);
48 GNUNET_STRINGS_base64_encode ((char*) &cred->signature,
49 sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
50 &signature);
51 GNUNET_asprintf (&cred_str,
52 "%s.%s -> %s | %s | %" SCNu64,
53 issuer_pkey,
54 cred->issuer_attribute,
55 subject_pkey,
56 signature,
57 cred->expiration.abs_value_us);
58 GNUNET_free (subject_pkey);
59 GNUNET_free (issuer_pkey);
60 GNUNET_free (signature);
61 return cred_str;
62}
63
64struct GNUNET_CREDENTIAL_Credential*
65GNUNET_CREDENTIAL_credential_from_string (const char*s)
66{
67 struct GNUNET_CREDENTIAL_Credential *cred;
68 size_t enclen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
69
70 if (enclen % 5 > 0)
71 enclen += 5 - enclen % 5;
72 enclen /= 5; /* 260/5 = 52 */
73 char subject_pkey[enclen + 1];
74 char issuer_pkey[enclen + 1];
75 char name[253 + 1];
76 char signature[256]; // TODO max payload size
77
78 struct GNUNET_CRYPTO_EcdsaSignature *sig;
79 struct GNUNET_TIME_Absolute etime_abs;
80
81 if (5 != sscanf (s,
82 "%52s.%253s -> %52s | %s | %" SCNu64,
83 issuer_pkey,
84 name,
85 subject_pkey,
86 signature,
87 &etime_abs.abs_value_us))
88 {
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
90 _ ("Unable to parse CRED record string `%s'\n"),
91 s);
92 return NULL;
93 }
94 cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen (
95 name) + 1);
96 GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey,
97 strlen (subject_pkey),
98 &cred->subject_key);
99 GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey,
100 strlen (issuer_pkey),
101 &cred->issuer_key);
102 GNUNET_assert (sizeof(struct GNUNET_CRYPTO_EcdsaSignature) ==
103 GNUNET_STRINGS_base64_decode (signature,
104 strlen (
105 signature),
106 (
107 char**) &sig));
108 cred->signature = *sig;
109 cred->expiration = etime_abs;
110 GNUNET_free (sig);
111 GNUNET_memcpy (&cred[1],
112 name,
113 strlen (name) + 1);
114 cred->issuer_attribute_len = strlen ((char*) &cred[1]);
115 cred->issuer_attribute = (char*) &cred[1];
116 return cred;
117}
118
119/**
120 * Issue an attribute to a subject
121 *
122 * @param issuer the ego that should be used to issue the attribute
123 * @param subject the subject of the attribute
124 * @param attribute the name of the attribute
125 * @return handle to the queued request
126 */
127struct GNUNET_CREDENTIAL_Credential *
128GNUNET_CREDENTIAL_credential_issue (const struct
129 GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
130 struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
131 const char *attribute,
132 struct GNUNET_TIME_Absolute *expiration)
133{
134 struct CredentialEntry *crd;
135 struct GNUNET_CREDENTIAL_Credential *cred;
136 size_t size;
137
138 size = sizeof(struct CredentialEntry) + strlen (attribute) + 1;
139 crd = GNUNET_malloc (size);
140 cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen (
141 attribute) + 1);
142 crd->purpose.size = htonl (size - sizeof(struct
143 GNUNET_CRYPTO_EcdsaSignature));
144
145 crd->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
146 GNUNET_CRYPTO_ecdsa_key_get_public (issuer,
147 &crd->issuer_key);
148 crd->subject_key = *subject;
149 crd->expiration = GNUNET_htonll (expiration->abs_value_us);
150 crd->issuer_attribute_len = htonl (strlen (attribute) + 1);
151 GNUNET_memcpy ((char*) &crd[1],
152 attribute,
153 strlen (attribute) + 1);
154 if (GNUNET_OK !=
155 GNUNET_CRYPTO_ecdsa_sign (issuer,
156 &crd->purpose,
157 &crd->signature))
158 {
159 GNUNET_break (0);
160 GNUNET_free (crd);
161 GNUNET_free (cred);
162 return NULL;
163 }
164 cred->signature = crd->signature;
165 cred->expiration = *expiration;
166 GNUNET_CRYPTO_ecdsa_key_get_public (issuer,
167 &cred->issuer_key);
168
169 cred->subject_key = *subject;
170 GNUNET_memcpy (&cred[1],
171 attribute,
172 strlen (attribute) + 1);
173 cred->issuer_attribute = (char*) &cred[1];
174 GNUNET_free (crd);
175 return cred;
176}
diff --git a/src/credential/credential_misc.h b/src/credential/credential_misc.h
deleted file mode 100644
index 510e1aacb..000000000
--- a/src/credential/credential_misc.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file credential/credential_misc.h
22 * @brief Credential helper functions
23 */
24#ifndef CREDENTIAL_MISC_H
25#define CREDENTIAL_MISC_H
26
27#include "gnunet_credential_service.h"
28
29char *
30GNUNET_CREDENTIAL_credential_to_string (
31 const struct GNUNET_CREDENTIAL_Credential *cred);
32
33struct GNUNET_CREDENTIAL_Credential *
34GNUNET_CREDENTIAL_credential_from_string (const char *str);
35
36#endif
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c
index 65a85e37e..564d9957b 100644
--- a/src/credential/credential_serialization.c
+++ b/src/credential/credential_serialization.c
@@ -221,11 +221,10 @@ GNUNET_CREDENTIAL_delegates_serialize (
221 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 221 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
222 */ 222 */
223int 223int
224GNUNET_CREDENTIAL_delegates_deserialize ( 224GNUNET_CREDENTIAL_delegates_deserialize (size_t len,
225 size_t len, 225 const char *src,
226 const char *src, 226 unsigned int c_count,
227 unsigned int c_count, 227 struct GNUNET_CREDENTIAL_Delegate *cd)
228 struct GNUNET_CREDENTIAL_Delegate *cd)
229{ 228{
230 struct DelegateEntry c_rec; 229 struct DelegateEntry c_rec;
231 unsigned int i; 230 unsigned int i;
@@ -335,9 +334,9 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (
335 off += dd[i].subject_attribute_len; 334 off += dd[i].subject_attribute_len;
336 } 335 }
337 return off + GNUNET_CREDENTIAL_delegates_serialize (c_count, 336 return off + GNUNET_CREDENTIAL_delegates_serialize (c_count,
338 cd, 337 cd,
339 dest_size - off, 338 dest_size - off,
340 &dest[off]); 339 &dest[off]);
341} 340}
342 341
343 342
@@ -386,79 +385,9 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (
386 off += dd[i].subject_attribute_len; 385 off += dd[i].subject_attribute_len;
387 } 386 }
388 return GNUNET_CREDENTIAL_delegates_deserialize (len - off, 387 return GNUNET_CREDENTIAL_delegates_deserialize (len - off,
389 &src[off], 388 &src[off],
390 c_count, 389 c_count,
391 cd); 390 cd);
392}
393
394int
395GNUNET_CREDENTIAL_credential_serialize (
396 struct GNUNET_CREDENTIAL_Credential *cred,
397 char **data)
398{
399 size_t size;
400 struct CredentialEntry *cdata;
401
402 size = sizeof (struct CredentialEntry) + strlen (cred->issuer_attribute) + 1;
403 *data = GNUNET_malloc (size);
404 cdata = (struct CredentialEntry *) *data;
405 cdata->subject_key = cred->subject_key;
406 cdata->issuer_key = cred->issuer_key;
407 cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us);
408 cdata->signature = cred->signature;
409 cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1);
410 cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
411 cdata->purpose.size =
412 htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
413 GNUNET_memcpy (&cdata[1],
414 cred->issuer_attribute,
415 strlen (cred->issuer_attribute));
416
417 if (GNUNET_OK !=
418 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL,
419 &cdata->purpose,
420 &cdata->signature,
421 &cdata->issuer_key))
422 {
423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n");
424 //return NULL;
425 }
426 return size;
427}
428
429struct GNUNET_CREDENTIAL_Credential *
430GNUNET_CREDENTIAL_credential_deserialize (const char *data, size_t data_size)
431{
432 struct GNUNET_CREDENTIAL_Credential *cred;
433 struct CredentialEntry *cdata;
434 char *issuer_attribute;
435
436 if (data_size < sizeof (struct CredentialEntry))
437 return NULL;
438 cdata = (struct CredentialEntry *) data;
439 if (GNUNET_OK !=
440 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL,
441 &cdata->purpose,
442 &cdata->signature,
443 &cdata->issuer_key))
444 {
445 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n");
446 //return NULL;
447 }
448 issuer_attribute = (char *) &cdata[1];
449
450 cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) +
451 ntohl (cdata->issuer_attribute_len));
452
453 cred->issuer_key = cdata->issuer_key;
454 cred->subject_key = cdata->subject_key;
455 GNUNET_memcpy (&cred[1],
456 issuer_attribute,
457 ntohl (cdata->issuer_attribute_len));
458 cred->signature = cdata->signature;
459 cred->issuer_attribute = (char *) &cred[1];
460 cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration);
461 return cred;
462} 391}
463 392
464int 393int
diff --git a/src/credential/credential_serialization.h b/src/credential/credential_serialization.h
index 12988354b..0e106caa1 100644
--- a/src/credential/credential_serialization.h
+++ b/src/credential/credential_serialization.h
@@ -42,8 +42,9 @@
42 * @return the required size to serialize 42 * @return the required size to serialize
43 */ 43 */
44size_t 44size_t
45GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, 45GNUNET_CREDENTIAL_delegation_set_get_size (
46 const struct GNUNET_CREDENTIAL_DelegationSet *dsr); 46 unsigned int ds_count,
47 const struct GNUNET_CREDENTIAL_DelegationSet *dsr);
47 48
48/** 49/**
49 * Serizalize the given delegation record entries 50 * Serizalize the given delegation record entries
@@ -55,10 +56,11 @@ GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count,
55 * @return the size of the data, -1 on failure 56 * @return the size of the data, -1 on failure
56 */ 57 */
57ssize_t 58ssize_t
58GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, 59GNUNET_CREDENTIAL_delegation_set_serialize (
59 const struct GNUNET_CREDENTIAL_DelegationSet *dsr, 60 unsigned int d_count,
60 size_t dest_size, 61 const struct GNUNET_CREDENTIAL_DelegationSet *dsr,
61 char *dest); 62 size_t dest_size,
63 char *dest);
62 64
63 65
64/** 66/**
@@ -71,48 +73,51 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count,
71 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 73 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
72 */ 74 */
73int 75int
74GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, 76GNUNET_CREDENTIAL_delegation_set_deserialize (
75 const char *src, 77 size_t len,
76 unsigned int d_count, 78 const char *src,
77 struct GNUNET_CREDENTIAL_DelegationSet *dsr); 79 unsigned int d_count,
80 struct GNUNET_CREDENTIAL_DelegationSet *dsr);
78 81
79 /** 82/**
80 * Calculate how many bytes we will need to serialize 83 * Calculate how many bytes we will need to serialize
81 * the given delegation chain and credential 84 * the given delegation chain and credential
82 * 85 *
83 * @param d_count number of delegation chain entries 86 * @param d_count number of delegation chain entries
84 * @param dd array of #GNUNET_CREDENTIAL_Delegation 87 * @param dd array of #GNUNET_CREDENTIAL_Delegation
85 * @param c_count number of credential entries 88 * @param c_count number of credential entries
86 * @param cd a #GNUNET_CREDENTIAL_Credential 89 * @param cd a #GNUNET_CREDENTIAL_Delegate
87 * @return the required size to serialize 90 * @return the required size to serialize
88 */ 91 */
89 size_t 92size_t
90 GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, 93GNUNET_CREDENTIAL_delegation_chain_get_size (
91 const struct GNUNET_CREDENTIAL_Delegation *dd, 94 unsigned int d_count,
92 unsigned int c_count, 95 const struct GNUNET_CREDENTIAL_Delegation *dd,
93 const struct GNUNET_CREDENTIAL_Delegate *cd); 96 unsigned int c_count,
97 const struct GNUNET_CREDENTIAL_Delegate *cd);
94 98
95 /** 99/**
96 * Serizalize the given delegation chain entries and credential 100 * Serizalize the given delegation chain entries and credential
97 * 101 *
98 * @param d_count number of delegation chain entries 102 * @param d_count number of delegation chain entries
99 * @param dd array of #GNUNET_CREDENTIAL_Delegation 103 * @param dd array of #GNUNET_CREDENTIAL_Delegation
100 * @param c_count number of credential entries 104 * @param c_count number of credential entries
101 * @param cd a #GNUNET_CREDENTIAL_Credential 105 * @param cd a #GNUNET_CREDENTIAL_Delegate
102 * @param dest_size size of the destination 106 * @param dest_size size of the destination
103 * @param dest where to store the result 107 * @param dest where to store the result
104 * @return the size of the data, -1 on failure 108 * @return the size of the data, -1 on failure
105 */ 109 */
106 ssize_t 110ssize_t
107 GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, 111GNUNET_CREDENTIAL_delegation_chain_serialize (
108 const struct GNUNET_CREDENTIAL_Delegation *dd, 112 unsigned int d_count,
109 unsigned int c_count, 113 const struct GNUNET_CREDENTIAL_Delegation *dd,
110 const struct GNUNET_CREDENTIAL_Delegate *cd, 114 unsigned int c_count,
111 size_t dest_size, 115 const struct GNUNET_CREDENTIAL_Delegate *cd,
112 char *dest); 116 size_t dest_size,
117 char *dest);
113 118
114 119
115 /** 120/**
116 * Deserialize the given destination 121 * Deserialize the given destination
117 * 122 *
118 * @param len size of the serialized delegation chain and cred 123 * @param len size of the serialized delegation chain and cred
@@ -123,45 +128,38 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len,
123 * @param cd where to put the credential data 128 * @param cd where to put the credential data
124 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 129 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
125 */ 130 */
126 int 131int
127 GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, 132GNUNET_CREDENTIAL_delegation_chain_deserialize (
128 const char *src, 133 size_t len,
129 unsigned int d_count, 134 const char *src,
130 struct GNUNET_CREDENTIAL_Delegation *dd, 135 unsigned int d_count,
131 unsigned int c_count, 136 struct GNUNET_CREDENTIAL_Delegation *dd,
132 struct GNUNET_CREDENTIAL_Delegate *cd); 137 unsigned int c_count,
133 size_t 138 struct GNUNET_CREDENTIAL_Delegate *cd);
134 GNUNET_CREDENTIAL_delegates_get_size (unsigned int c_count, 139size_t
135 const struct GNUNET_CREDENTIAL_Delegate *cd); 140GNUNET_CREDENTIAL_delegates_get_size (
141 unsigned int c_count,
142 const struct GNUNET_CREDENTIAL_Delegate *cd);
136 143
137ssize_t 144ssize_t
138GNUNET_CREDENTIAL_delegates_serialize (unsigned int c_count, 145GNUNET_CREDENTIAL_delegates_serialize (
139 const struct GNUNET_CREDENTIAL_Delegate *cd, 146 unsigned int c_count,
140 size_t dest_size, 147 const struct GNUNET_CREDENTIAL_Delegate *cd,
141 char *dest); 148 size_t dest_size,
149 char *dest);
142 150
143 151
144int 152int
145GNUNET_CREDENTIAL_delegates_deserialize (size_t len, 153GNUNET_CREDENTIAL_delegates_deserialize (size_t len,
146 const char *src, 154 const char *src,
147 unsigned int c_count, 155 unsigned int c_count,
148 struct GNUNET_CREDENTIAL_Delegate *cd); 156 struct GNUNET_CREDENTIAL_Delegate *cd);
149
150
151int
152GNUNET_CREDENTIAL_credential_serialize (struct GNUNET_CREDENTIAL_Credential *cred,
153 char **data);
154
155struct GNUNET_CREDENTIAL_Credential*
156GNUNET_CREDENTIAL_credential_deserialize (const char* data,
157 size_t data_size);
158 157
159int 158int
160GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *cred, 159GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *cred,
161 char **data); 160 char **data);
162 161
163struct GNUNET_CREDENTIAL_Delegate* 162struct GNUNET_CREDENTIAL_Delegate *
164GNUNET_CREDENTIAL_delegate_deserialize (const char* data, 163GNUNET_CREDENTIAL_delegate_deserialize (const char *data, size_t data_size);
165 size_t data_size);
166#endif 164#endif
167/* end of credential_serialization.h */ 165/* end of credential_serialization.h */
diff --git a/src/credential/gnunet-credential.c b/src/credential/gnunet-credential.c
index 07148a1b5..5cc1a791e 100644
--- a/src/credential/gnunet-credential.c
+++ b/src/credential/gnunet-credential.c
@@ -27,7 +27,6 @@
27#include <gnunet_credential_service.h> 27#include <gnunet_credential_service.h>
28#include <gnunet_gnsrecord_lib.h> 28#include <gnunet_gnsrecord_lib.h>
29#include <gnunet_namestore_service.h> 29#include <gnunet_namestore_service.h>
30#include "credential_misc.h"
31#include "delegate_misc.h" 30#include "delegate_misc.h"
32#include "credential_serialization.h" 31#include "credential_serialization.h"
33 32
@@ -82,9 +81,9 @@ static struct GNUNET_SCHEDULER_Task *tt;
82static char *subject; 81static char *subject;
83 82
84/** 83/**
85 * Subject credential string 84 * Subject delegate string
86 */ 85 */
87static char *subject_credential; 86static char *subject_delegate;
88 87
89/** 88/**
90 * Credential TTL 89 * Credential TTL
@@ -123,11 +122,6 @@ static char *issuer_attr;
123static int verify; 122static int verify;
124 123
125/** 124/**
126 * Issue mode
127 */
128static int create_cred;
129
130/**
131 * Collect mode 125 * Collect mode
132 */ 126 */
133static int collect; 127static int collect;
@@ -153,6 +147,26 @@ static int sign_ss;
153static char *import; 147static char *import;
154 148
155/** 149/**
150 * Is record private
151 */
152static int is_private;
153
154/**
155 * Search direction: forward
156 */
157static int forward;
158
159/**
160 * Search direction: backward
161 */
162static int backward;
163
164/**
165 * API enum, filled and passed for collect/verify
166 */
167enum GNUNET_CREDENTIAL_AlgoDirectionFlags direction = 0;
168
169/**
156 * Queue entry for the 'add' operation. 170 * Queue entry for the 'add' operation.
157 */ 171 */
158static struct GNUNET_NAMESTORE_QueueEntry *add_qe; 172static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
@@ -268,8 +282,10 @@ handle_collect_result (void *cls,
268 printf ("%s\n", line); 282 printf ("%s\n", line);
269 GNUNET_free (line); 283 GNUNET_free (line);
270 } 284 }
271 } else { 285 }
272 printf("Received NULL\n"); 286 else
287 {
288 printf ("Received NULL\n");
273 } 289 }
274 290
275 GNUNET_SCHEDULER_shutdown (); 291 GNUNET_SCHEDULER_shutdown ();
@@ -344,10 +360,6 @@ static void
344identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) 360identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
345{ 361{
346 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; 362 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
347 struct GNUNET_CREDENTIAL_Credential *cred;
348 struct GNUNET_TIME_Absolute etime_abs;
349 struct GNUNET_TIME_Relative etime_rel;
350 char *res;
351 363
352 el = NULL; 364 el = NULL;
353 if (NULL == ego) 365 if (NULL == ego)
@@ -381,44 +393,11 @@ identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
381 &issuer_pkey, 393 &issuer_pkey,
382 issuer_attr, //TODO argument 394 issuer_attr, //TODO argument
383 privkey, 395 privkey,
396 direction,
384 &handle_collect_result, 397 &handle_collect_result,
385 NULL); 398 NULL);
386 return; 399 return;
387 } 400 }
388
389 //Else issue
390
391 if (NULL == expiration)
392 {
393 fprintf (stderr, "Please specify a TTL\n");
394 GNUNET_SCHEDULER_shutdown ();
395 return;
396 }
397 else if (GNUNET_OK ==
398 GNUNET_STRINGS_fancy_time_to_relative (expiration, &etime_rel))
399 {
400 etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel);
401 }
402 else if (GNUNET_OK !=
403 GNUNET_STRINGS_fancy_time_to_absolute (expiration, &etime_abs))
404 {
405 fprintf (stderr, "%s is not a valid ttl!\n", expiration);
406 GNUNET_SCHEDULER_shutdown ();
407 return;
408 }
409
410
411 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
412 GNUNET_free_non_null (ego_name);
413 ego_name = NULL;
414 cred = GNUNET_CREDENTIAL_credential_issue (privkey,
415 &subject_pkey,
416 issuer_attr,
417 &etime_abs);
418
419 res = GNUNET_CREDENTIAL_credential_to_string (cred);
420 GNUNET_free (cred);
421 printf ("%s\n", res);
422 GNUNET_SCHEDULER_shutdown (); 401 GNUNET_SCHEDULER_shutdown ();
423} 402}
424 403
@@ -506,9 +485,9 @@ get_existing_record (void *cls,
506 rde->record_type = type; 485 rde->record_type = type;
507 // Flags not required , TODO what have we said we do with that now? Look it up in my writing 486 // Flags not required , TODO what have we said we do with that now? Look it up in my writing
508 /*if (1 == is_shadow) 487 /*if (1 == is_shadow)
509 rde->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; 488 rde->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;*/
510 if (1 != is_public) 489 if (GNUNET_YES == is_private)
511 rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;*/ 490 rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
512 rde->expiration_time = etime; 491 rde->expiration_time = etime;
513 if (GNUNET_YES == etime_is_rel) 492 if (GNUNET_YES == etime_is_rel)
514 rde->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 493 rde->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
@@ -751,6 +730,7 @@ run (void *cls,
751 730
752 if (GNUNET_YES == create_ss) 731 if (GNUNET_YES == create_ss)
753 { 732 {
733
754 // check if signed parameter has been passed in cmd line call 734 // check if signed parameter has been passed in cmd line call
755 if (NULL == import) 735 if (NULL == import)
756 { 736 {
@@ -787,6 +767,20 @@ run (void *cls,
787 return; 767 return;
788 } 768 }
789 769
770 if (GNUNET_NO == forward && GNUNET_NO == backward)
771 {
772 fprintf (
773 stderr,
774 _ (
775 "You must state which search direction: '--forward' or '--backward'\n"));
776 GNUNET_SCHEDULER_shutdown ();
777 return;
778 }
779 if (GNUNET_YES == forward)
780 direction |= GNUNET_CREDENTIAL_FLAG_FORWARD;
781 if (GNUNET_YES == backward)
782 direction |= GNUNET_CREDENTIAL_FLAG_BACKWARD;
783
790 if (GNUNET_YES == collect) 784 if (GNUNET_YES == collect)
791 { 785 {
792 if (NULL == issuer_key) 786 if (NULL == issuer_key)
@@ -840,6 +834,15 @@ run (void *cls,
840 834
841 if (GNUNET_YES == verify) 835 if (GNUNET_YES == verify)
842 { 836 {
837 if (GNUNET_NO == forward && GNUNET_NO == backward)
838 {
839 fprintf (
840 stderr,
841 _ (
842 "You must state which search direction: '-forward' or 'backward'\n"));
843 GNUNET_SCHEDULER_shutdown ();
844 return;
845 }
843 if (NULL == issuer_key) 846 if (NULL == issuer_key)
844 { 847 {
845 fprintf (stderr, _ ("Issuer public key not well-formed\n")); 848 fprintf (stderr, _ ("Issuer public key not well-formed\n"));
@@ -865,7 +868,7 @@ run (void *cls,
865 GNUNET_SCHEDULER_shutdown (); 868 GNUNET_SCHEDULER_shutdown ();
866 return; 869 return;
867 } 870 }
868 if (NULL == issuer_attr || NULL == subject_credential) 871 if (NULL == issuer_attr || NULL == subject_delegate)
869 { 872 {
870 fprintf (stderr, _ ("You must provide issuer and subject attributes\n")); 873 fprintf (stderr, _ ("You must provide issuer and subject attributes\n"));
871 GNUNET_SCHEDULER_shutdown (); 874 GNUNET_SCHEDULER_shutdown ();
@@ -873,7 +876,7 @@ run (void *cls,
873 } 876 }
874 877
875 //Subject credentials are comma separated 878 //Subject credentials are comma separated
876 char *tmp = GNUNET_strdup (subject_credential); 879 char *tmp = GNUNET_strdup (subject_delegate);
877 char *tok = strtok (tmp, ","); 880 char *tok = strtok (tmp, ",");
878 if (NULL == tok) 881 if (NULL == tok)
879 { 882 {
@@ -886,20 +889,20 @@ run (void *cls,
886 int i; 889 int i;
887 while (NULL != (tok = strtok (NULL, ","))) 890 while (NULL != (tok = strtok (NULL, ",")))
888 count++; 891 count++;
889 struct GNUNET_CREDENTIAL_Delegate credentials[count]; 892 struct GNUNET_CREDENTIAL_Delegate delegates[count];
890 struct GNUNET_CREDENTIAL_Delegate *cred; 893 struct GNUNET_CREDENTIAL_Delegate *dele;
891 GNUNET_free (tmp); 894 GNUNET_free (tmp);
892 tmp = GNUNET_strdup (subject_credential); 895 tmp = GNUNET_strdup (subject_delegate);
893 tok = strtok (tmp, ","); 896 tok = strtok (tmp, ",");
894 for (i = 0; i < count; i++) 897 for (i = 0; i < count; i++)
895 { 898 {
896 cred = GNUNET_CREDENTIAL_delegate_from_string (tok); 899 dele = GNUNET_CREDENTIAL_delegate_from_string (tok);
897 GNUNET_memcpy (&credentials[i], 900 GNUNET_memcpy (&delegates[i],
898 cred, 901 dele,
899 sizeof (struct GNUNET_CREDENTIAL_Delegate)); 902 sizeof (struct GNUNET_CREDENTIAL_Delegate));
900 credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute); 903 delegates[i].issuer_attribute = GNUNET_strdup (dele->issuer_attribute);
901 tok = strtok (NULL, ","); 904 tok = strtok (NULL, ",");
902 GNUNET_free (cred); 905 GNUNET_free (dele);
903 } 906 }
904 907
905 verify_request = GNUNET_CREDENTIAL_verify (credential, 908 verify_request = GNUNET_CREDENTIAL_verify (credential,
@@ -907,27 +910,16 @@ run (void *cls,
907 issuer_attr, //TODO argument 910 issuer_attr, //TODO argument
908 &subject_pkey, 911 &subject_pkey,
909 count, 912 count,
910 credentials, 913 delegates,
914 direction,
911 &handle_verify_result, 915 &handle_verify_result,
912 NULL); 916 NULL);
913 for (i = 0; i < count; i++) 917 for (i = 0; i < count; i++)
914 { 918 {
915 GNUNET_free ((char *) credentials[i].issuer_attribute); 919 GNUNET_free ((char *) delegates[i].issuer_attribute);
916 } 920 }
917 GNUNET_free (tmp); 921 GNUNET_free (tmp);
918 } 922 }
919 else if (GNUNET_YES == create_cred)
920 {
921 if (NULL == ego_name)
922 {
923 fprintf (stderr, _ ("Issuer ego required\n"));
924 GNUNET_SCHEDULER_shutdown ();
925 return;
926 }
927 el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg);
928
929 return;
930 }
931 else 923 else
932 { 924 {
933 fprintf (stderr, 925 fprintf (stderr,
@@ -949,70 +941,94 @@ run (void *cls,
949int 941int
950main (int argc, char *const *argv) 942main (int argc, char *const *argv)
951{ 943{
952 struct GNUNET_GETOPT_CommandLineOption options[] = { 944 struct GNUNET_GETOPT_CommandLineOption options[] =
953 GNUNET_GETOPT_option_flag ('I', 945 {GNUNET_GETOPT_option_flag ('V',
954 "issue", 946 "verify",
955 gettext_noop ("create credential"), 947 gettext_noop (
956 &create_cred), 948 "verify credential against attribute"),
957 GNUNET_GETOPT_option_flag ('V', 949 &verify),
958 "verify", 950 GNUNET_GETOPT_option_string (
959 gettext_noop ("verify credential against attribute"), 951 's',
960 &verify), 952 "subject",
961 GNUNET_GETOPT_option_string ('s', 953 "PKEY",
962 "subject", 954 gettext_noop (
963 "PKEY", 955 "The public key of the subject to lookup the"
964 gettext_noop ("The public key of the subject to lookup the" 956 "credential for, or for issuer side storage: subject and its attributes"),
965 "credential for, or for issuer side storage: subject and its attributes"), 957 &subject),
966 &subject), 958 GNUNET_GETOPT_option_string (
967 GNUNET_GETOPT_option_string ('b', 959 'd',
968 "credential", 960 "delegate",
969 "CRED", 961 "DELE",
970 gettext_noop ("The name of the credential presented by the subject"), 962 gettext_noop ("The private, signed delegate presented by the subject"),
971 &subject_credential), 963 &subject_delegate),
972 GNUNET_GETOPT_option_string ('i', 964 GNUNET_GETOPT_option_string (
973 "issuer", 965 'i',
974 "PKEY", 966 "issuer",
975 gettext_noop ("The public key of the authority to verify the credential against"), 967 "PKEY",
976 &issuer_key), 968 gettext_noop (
977 GNUNET_GETOPT_option_string ('e', 969 "The public key of the authority to verify the credential against"),
978 "ego", 970 &issuer_key),
979 "EGO", 971 GNUNET_GETOPT_option_string ('e',
980 gettext_noop ("The ego/zone name to use"), 972 "ego",
981 &ego_name), 973 "EGO",
982 GNUNET_GETOPT_option_string ('a', 974 gettext_noop ("The ego/zone name to use"),
983 "attribute", 975 &ego_name),
984 "ATTR", 976 GNUNET_GETOPT_option_string (
985 gettext_noop ("The issuer attribute to verify against or to issue"), 977 'a',
986 &issuer_attr), 978 "attribute",
987 GNUNET_GETOPT_option_string ('T', 979 "ATTR",
988 "ttl", 980 gettext_noop ("The issuer attribute to verify against or to issue"),
989 "EXP", 981 &issuer_attr),
990 gettext_noop ("The time to live for the credential." 982 GNUNET_GETOPT_option_string ('T',
991 "e.g. 5m, 6h, \"1990-12-30 12:00:00\""), 983 "ttl",
992 &expiration), 984 "EXP",
993 GNUNET_GETOPT_option_flag ('g', 985 gettext_noop (
994 "collect", 986 "The time to live for the credential."
995 gettext_noop ("collect credentials"), 987 "e.g. 5m, 6h, \"1990-12-30 12:00:00\""),
996 &collect), 988 &expiration),
997 GNUNET_GETOPT_option_flag ('U', 989 GNUNET_GETOPT_option_flag ('g',
998 "createIssuerSide", 990 "collect",
999 gettext_noop ("Create and issue a credential issuer side."), 991 gettext_noop ("collect credentials"),
1000 &create_is), 992 &collect),
1001 GNUNET_GETOPT_option_flag ('C', 993 GNUNET_GETOPT_option_flag ('U',
1002 "createSubjectSide", 994 "createIssuerSide",
1003 gettext_noop ("Issue a credential subject side."), 995 gettext_noop (
1004 &create_ss), 996 "Create and issue a credential issuer side."),
1005 GNUNET_GETOPT_option_flag ('S', 997 &create_is),
1006 "signSubjectSide", 998 GNUNET_GETOPT_option_flag ('C',
1007 gettext_noop ("Create, sign and return a credential subject side."), 999 "createSubjectSide",
1008 &sign_ss), 1000 gettext_noop (
1009 GNUNET_GETOPT_option_string ('x', 1001 "Issue a credential subject side."),
1010 "import", 1002 &create_ss),
1011 "IMP", 1003 GNUNET_GETOPT_option_flag (
1012 gettext_noop ("Import signed credentials that should be issued to a zone/ego"), 1004 'S',
1013 &import), 1005 "signSubjectSide",
1014 GNUNET_GETOPT_OPTION_END 1006 gettext_noop ("Create, sign and return a credential subject side."),
1015 }; 1007 &sign_ss),
1008 GNUNET_GETOPT_option_string (
1009 'x',
1010 "import",
1011 "IMP",
1012 gettext_noop (
1013 "Import signed credentials that should be issued to a zone/ego"),
1014 &import),
1015 GNUNET_GETOPT_option_flag ('P',
1016 "private",
1017 gettext_noop ("Create private record entry."),
1018 &is_private),
1019 GNUNET_GETOPT_option_flag (
1020 'F',
1021 "forward",
1022 gettext_noop (
1023 "Indicates that the collect/verify process is done via forward search."),
1024 &forward),
1025 GNUNET_GETOPT_option_flag (
1026 'B',
1027 "backward",
1028 gettext_noop (
1029 "Indicates that the collect/verify process is done via forward search."),
1030 &backward),
1031 GNUNET_GETOPT_OPTION_END};
1016 int ret; 1032 int ret;
1017 1033
1018 timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1034 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 2d954f823..41f4f64d6 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -340,7 +340,7 @@ struct VerifyRequestHandle
340 /** 340 /**
341 * Direction of the resolution algo 341 * Direction of the resolution algo
342 */ 342 */
343 enum direction resolution_algo; 343 enum GNUNET_CREDENTIAL_AlgoDirectionFlags resolution_algo;
344 344
345 /** 345 /**
346 * Delegate iterator for lookup 346 * Delegate iterator for lookup
@@ -385,12 +385,14 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
385 return; 385 return;
386 386
387 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry; 387 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry;
388 dq_entry = ds_entry->queue_entries_head) { 388 dq_entry = ds_entry->queue_entries_head)
389 {
389 GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head, 390 GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head,
390 ds_entry->queue_entries_tail, 391 ds_entry->queue_entries_tail,
391 dq_entry); 392 dq_entry);
392 for (child = dq_entry->set_entries_head; NULL != child; 393 for (child = dq_entry->set_entries_head; NULL != child;
393 child = dq_entry->set_entries_head) { 394 child = dq_entry->set_entries_head)
395 {
394 GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head, 396 GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head,
395 dq_entry->set_entries_tail, 397 dq_entry->set_entries_tail,
396 child); 398 child);
@@ -403,11 +405,13 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
403 GNUNET_free_non_null (ds_entry->issuer_attribute); 405 GNUNET_free_non_null (ds_entry->issuer_attribute);
404 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation); 406 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation);
405 GNUNET_free_non_null (ds_entry->attr_trailer); 407 GNUNET_free_non_null (ds_entry->attr_trailer);
406 if (NULL != ds_entry->lookup_request) { 408 if (NULL != ds_entry->lookup_request)
409 {
407 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request); 410 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
408 ds_entry->lookup_request = NULL; 411 ds_entry->lookup_request = NULL;
409 } 412 }
410 if (NULL != ds_entry->delegation_chain_entry) { 413 if (NULL != ds_entry->delegation_chain_entry)
414 {
411 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute); 415 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute);
412 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute); 416 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute);
413 GNUNET_free (ds_entry->delegation_chain_entry); 417 GNUNET_free (ds_entry->delegation_chain_entry);
@@ -420,14 +424,16 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
420{ 424{
421 struct DelegateRecordEntry *del_entry; 425 struct DelegateRecordEntry *del_entry;
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n"); 426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
423 if (NULL != vrh->lookup_request) { 427 if (NULL != vrh->lookup_request)
428 {
424 GNUNET_GNS_lookup_cancel (vrh->lookup_request); 429 GNUNET_GNS_lookup_cancel (vrh->lookup_request);
425 vrh->lookup_request = NULL; 430 vrh->lookup_request = NULL;
426 } 431 }
427 cleanup_delegation_set (vrh->root_set); 432 cleanup_delegation_set (vrh->root_set);
428 GNUNET_free_non_null (vrh->issuer_attribute); 433 GNUNET_free_non_null (vrh->issuer_attribute);
429 for (del_entry = vrh->del_chain_head; NULL != vrh->del_chain_head; 434 for (del_entry = vrh->del_chain_head; NULL != vrh->del_chain_head;
430 del_entry = vrh->del_chain_head) { 435 del_entry = vrh->del_chain_head)
436 {
431 GNUNET_CONTAINER_DLL_remove (vrh->del_chain_head, 437 GNUNET_CONTAINER_DLL_remove (vrh->del_chain_head,
432 vrh->del_chain_tail, 438 vrh->del_chain_tail,
433 del_entry); 439 del_entry);
@@ -444,21 +450,25 @@ shutdown_task (void *cls)
444 450
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n"); 451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
446 452
447 while (NULL != (vrh = vrh_head)) { 453 while (NULL != (vrh = vrh_head))
454 {
448 // CREDENTIAL_resolver_lookup_cancel (clh->lookup); 455 // CREDENTIAL_resolver_lookup_cancel (clh->lookup);
449 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); 456 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
450 cleanup_handle (vrh); 457 cleanup_handle (vrh);
451 } 458 }
452 459
453 if (NULL != gns) { 460 if (NULL != gns)
461 {
454 GNUNET_GNS_disconnect (gns); 462 GNUNET_GNS_disconnect (gns);
455 gns = NULL; 463 gns = NULL;
456 } 464 }
457 if (NULL != namestore) { 465 if (NULL != namestore)
466 {
458 GNUNET_NAMESTORE_disconnect (namestore); 467 GNUNET_NAMESTORE_disconnect (namestore);
459 namestore = NULL; 468 namestore = NULL;
460 } 469 }
461 if (NULL != statistics) { 470 if (NULL != statistics)
471 {
462 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); 472 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
463 statistics = NULL; 473 statistics = NULL;
464 } 474 }
@@ -480,14 +490,16 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
480 490
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n"); 491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
482 dce = vrh->delegation_chain_head; 492 dce = vrh->delegation_chain_head;
483 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++) { 493 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++)
494 {
484 dd[i].issuer_key = dce->issuer_key; 495 dd[i].issuer_key = dce->issuer_key;
485 dd[i].subject_key = dce->subject_key; 496 dd[i].subject_key = dce->subject_key;
486 dd[i].issuer_attribute = dce->issuer_attribute; 497 dd[i].issuer_attribute = dce->issuer_attribute;
487 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1; 498 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1;
488 dd[i].subject_attribute_len = 0; 499 dd[i].subject_attribute_len = 0;
489 dd[i].subject_attribute = NULL; 500 dd[i].subject_attribute = NULL;
490 if (NULL != dce->subject_attribute) { 501 if (NULL != dce->subject_attribute)
502 {
491 dd[i].subject_attribute = dce->subject_attribute; 503 dd[i].subject_attribute = dce->subject_attribute;
492 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1; 504 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1;
493 } 505 }
@@ -495,16 +507,16 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
495 } 507 }
496 508
497 // Remove all not needed credentials 509 // Remove all not needed credentials
498 for (del = vrh->del_chain_head; NULL != del;) { 510 for (del = vrh->del_chain_head; NULL != del;)
499 if (del->refcount > 0) { 511 {
512 if (del->refcount > 0)
513 {
500 del = del->next; 514 del = del->next;
501 continue; 515 continue;
502 } 516 }
503 tmp = del; 517 tmp = del;
504 del = del->next; 518 del = del->next;
505 GNUNET_CONTAINER_DLL_remove (vrh->del_chain_head, 519 GNUNET_CONTAINER_DLL_remove (vrh->del_chain_head, vrh->del_chain_tail, tmp);
506 vrh->del_chain_tail,
507 tmp);
508 GNUNET_free (tmp->delegate); 520 GNUNET_free (tmp->delegate);
509 GNUNET_free (tmp); 521 GNUNET_free (tmp);
510 vrh->del_chain_size--; 522 vrh->del_chain_size--;
@@ -513,20 +525,21 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
513 // Get serialized record data 525 // Get serialized record data
514 // Append at the end of rmsg 526 // Append at the end of rmsg
515 del = vrh->del_chain_head; 527 del = vrh->del_chain_head;
516 for (uint32_t i = 0; i < vrh->del_chain_size; i++) { 528 for (uint32_t i = 0; i < vrh->del_chain_size; i++)
529 {
517 dele[i].issuer_key = del->delegate->issuer_key; 530 dele[i].issuer_key = del->delegate->issuer_key;
518 dele[i].subject_key = del->delegate->subject_key; 531 dele[i].subject_key = del->delegate->subject_key;
519 dele[i].issuer_attribute_len 532 dele[i].issuer_attribute_len = strlen (del->delegate->issuer_attribute) + 1;
520 = strlen (del->delegate->issuer_attribute) + 1;
521 dele[i].issuer_attribute = del->delegate->issuer_attribute; 533 dele[i].issuer_attribute = del->delegate->issuer_attribute;
522 dele[i].expiration = del->delegate->expiration; 534 dele[i].expiration = del->delegate->expiration;
523 dele[i].signature = del->delegate->signature; 535 dele[i].signature = del->delegate->signature;
524 del = del->next; 536 del = del->next;
525 } 537 }
526 size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size, 538 size =
527 dd, 539 GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size,
528 vrh->del_chain_size, 540 dd,
529 dele); 541 vrh->del_chain_size,
542 dele);
530 env = GNUNET_MQ_msg_extra (rmsg, 543 env = GNUNET_MQ_msg_extra (rmsg,
531 size, 544 size,
532 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); 545 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT);
@@ -541,13 +554,13 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
541 rmsg->del_found = htonl (GNUNET_NO); 554 rmsg->del_found = htonl (GNUNET_NO);
542 555
543 GNUNET_assert ( 556 GNUNET_assert (
544 -1 557 -1 !=
545 != GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size, 558 GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
546 dd, 559 dd,
547 vrh->del_chain_size, 560 vrh->del_chain_size,
548 dele, 561 dele,
549 size, 562 size,
550 (char *)&rmsg[1])); 563 (char *) &rmsg[1]));
551 564
552 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env); 565 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env);
553 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); 566 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
@@ -559,8 +572,11 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
559 GNUNET_NO); 572 GNUNET_NO);
560} 573}
561 574
562static char* 575static char *
563partial_match(char *tmp_trail, char *tmp_subattr, char *parent_trail, char *issuer_attribute) 576partial_match (char *tmp_trail,
577 char *tmp_subattr,
578 char *parent_trail,
579 char *issuer_attribute)
564{ 580{
565 char *saveptr1, *saveptr2; 581 char *saveptr1, *saveptr2;
566 char *trail_token; 582 char *trail_token;
@@ -574,14 +590,16 @@ partial_match(char *tmp_trail, char *tmp_subattr, char *parent_trail, char *issu
574 sub_token = strtok_r (tmp_subattr, ".", &saveptr2); 590 sub_token = strtok_r (tmp_subattr, ".", &saveptr2);
575 while (NULL != trail_token && NULL != sub_token) 591 while (NULL != trail_token && NULL != sub_token)
576 { 592 {
577 if(0 == strcmp(trail_token,sub_token)) 593 if (0 == strcmp (trail_token, sub_token))
578 { 594 {
579 // good, matches, remove 595 // good, matches, remove
580 } else { 596 }
597 else
598 {
581 // not relevant for solving the chain, end for iteration here 599 // not relevant for solving the chain, end for iteration here
582 return NULL; 600 return NULL;
583 } 601 }
584 602
585 trail_token = strtok_r (NULL, ".", &saveptr1); 603 trail_token = strtok_r (NULL, ".", &saveptr1);
586 sub_token = strtok_r (NULL, ".", &saveptr2); 604 sub_token = strtok_r (NULL, ".", &saveptr2);
587 } 605 }
@@ -590,47 +608,38 @@ partial_match(char *tmp_trail, char *tmp_subattr, char *parent_trail, char *issu
590 // 2. the trailer is NULL, but the subject has more attributes 608 // 2. the trailer is NULL, but the subject has more attributes
591 // Reason: This will lead to "startzone.attribute" but we're looking for a solution 609 // Reason: This will lead to "startzone.attribute" but we're looking for a solution
592 // for "<- startzone" 610 // for "<- startzone"
593 if(NULL == trail_token) 611 if (NULL == trail_token)
594 { 612 {
595 return NULL; 613 return NULL;
596 } 614 }
597 615
598 // do not have to check sub_token == NULL, if both would be NULL 616 // do not have to check sub_token == NULL, if both would be NULL
599 // at the same time, the complete match part above should have triggered already 617 // at the same time, the complete match part above should have triggered already
600 618
601 // otherwise, above while only ends when sub_token == NULL 619 // otherwise, above while only ends when sub_token == NULL
602 GNUNET_asprintf (&attr_trailer, 620 GNUNET_asprintf (&attr_trailer, "%s", trail_token);
603 "%s", 621 trail_token = strtok_r (NULL, ".", &saveptr1);
604 trail_token); 622 while (NULL != trail_token)
605 trail_token = strtok_r (NULL, ".", &saveptr1);
606 while(NULL != trail_token)
607 { 623 {
608 GNUNET_asprintf (&attr_trailer, 624 GNUNET_asprintf (&attr_trailer, "%s.%s", parent_trail, trail_token);
609 "%s.%s", 625 trail_token = strtok_r (NULL, ".", &saveptr1);
610 parent_trail,
611 trail_token);
612 trail_token = strtok_r (NULL, ".", &saveptr1);
613
614 } 626 }
615 GNUNET_asprintf (&attr_trailer, 627 GNUNET_asprintf (&attr_trailer, "%s.%s", issuer_attribute, attr_trailer);
616 "%s.%s",
617 issuer_attribute,
618 attr_trailer);
619 return attr_trailer; 628 return attr_trailer;
620} 629}
621 630
622static void 631static void
623forward_resolution (void *cls, 632forward_resolution (void *cls,
624 uint32_t rd_count, 633 uint32_t rd_count,
625 const struct GNUNET_GNSRECORD_Data *rd) 634 const struct GNUNET_GNSRECORD_Data *rd)
626{ 635{
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %d entries.\n", rd_count); 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %d entries.\n", rd_count);
628 637
629 struct VerifyRequestHandle *vrh; 638 struct VerifyRequestHandle *vrh;
630 struct DelegationSetQueueEntry *current_set; 639 struct DelegationSetQueueEntry *current_set;
631 struct DelegationSetQueueEntry *ds_entry; 640 struct DelegationSetQueueEntry *ds_entry;
632 struct DelegationQueueEntry *dq_entry; 641 struct DelegationQueueEntry *dq_entry;
633 642
634 current_set = cls; 643 current_set = cls;
635 // set handle to NULL (as el = NULL) 644 // set handle to NULL (as el = NULL)
636 current_set->lookup_request = NULL; 645 current_set->lookup_request = NULL;
@@ -638,20 +647,21 @@ forward_resolution (void *cls,
638 vrh->pending_lookups--; 647 vrh->pending_lookups--;
639 648
640 // Loop record entries 649 // Loop record entries
641 for (uint32_t i = 0; i < rd_count; i++) { 650 for (uint32_t i = 0; i < rd_count; i++)
651 {
642 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type) 652 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type)
643 continue; 653 continue;
644 654
645 // Start deserialize into Delegate 655 // Start deserialize into Delegate
646 struct GNUNET_CREDENTIAL_Delegate *del; 656 struct GNUNET_CREDENTIAL_Delegate *del;
647 del = GNUNET_CREDENTIAL_delegate_deserialize(rd[i].data, rd[i].data_size); 657 del = GNUNET_CREDENTIAL_delegate_deserialize (rd[i].data, rd[i].data_size);
648 658
649 // Start: Create DQ Entry 659 // Start: Create DQ Entry
650 dq_entry = GNUNET_new (struct DelegationQueueEntry); 660 dq_entry = GNUNET_new (struct DelegationQueueEntry);
651 // AND delegations are not possible, only 1 solution 661 // AND delegations are not possible, only 1 solution
652 dq_entry->required_solutions = 1; 662 dq_entry->required_solutions = 1;
653 dq_entry->parent_set = current_set; 663 dq_entry->parent_set = current_set;
654 664
655 // Insert it into the current set 665 // Insert it into the current set
656 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, 666 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
657 current_set->queue_entries_tail, 667 current_set->queue_entries_tail,
@@ -659,7 +669,7 @@ forward_resolution (void *cls,
659 669
660 // Start: Create DS Entry 670 // Start: Create DS Entry
661 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 671 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
662 672
663 // (1) A.a <- A.b.c 673 // (1) A.a <- A.b.c
664 // (2) A.b <- D.d 674 // (2) A.b <- D.d
665 // (3) D.d <- E 675 // (3) D.d <- E
@@ -671,42 +681,55 @@ forward_resolution (void *cls,
671 // 3. new solution: replace, add trailer 681 // 3. new solution: replace, add trailer
672 682
673 // At resolution chain start trailer of parent is NULL 683 // At resolution chain start trailer of parent is NULL
674 if (NULL == current_set->attr_trailer) { 684 if (NULL == current_set->attr_trailer)
685 {
675 // for (5) F.c <- G, remember .c when going upwards 686 // for (5) F.c <- G, remember .c when going upwards
676 ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute); 687 ds_entry->attr_trailer = GNUNET_strdup (del->issuer_attribute);
677 } else { 688 }
678 if (0 == del->subject_attribute_len){ 689 else
690 {
691 if (0 == del->subject_attribute_len)
692 {
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: New solution\n"); 693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: New solution\n");
680 // new solution 694 // new solution
681 // create new trailer del->issuer_attribute, ds_entry->attr_trailer 695 // create new trailer del->issuer_attribute, ds_entry->attr_trailer
682 GNUNET_asprintf (&ds_entry->attr_trailer, 696 GNUNET_asprintf (&ds_entry->attr_trailer,
683 "%s.%s", 697 "%s.%s",
684 del->issuer_attribute, 698 del->issuer_attribute,
685 current_set->attr_trailer); 699 current_set->attr_trailer);
686 } else if(0 == strcmp(del->subject_attribute, current_set->attr_trailer)){ 700 }
701 else if (0 == strcmp (del->subject_attribute, current_set->attr_trailer))
702 {
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Complete match\n"); 703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Complete match\n");
688 // complete match 704 // complete match
689 // new trailer == issuer attribute (e.g. (5) to (4)) 705 // new trailer == issuer attribute (e.g. (5) to (4))
690 // TODO memleak, free trailer before 706 // TODO memleak, free trailer before
691 ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute); 707 ds_entry->attr_trailer = GNUNET_strdup (del->issuer_attribute);
692 } else { 708 }
709 else
710 {
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Partial match\n"); 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Partial match\n");
694 // partial match 712 // partial match
695 713
696 char *trail = partial_match(GNUNET_strdup (current_set->attr_trailer), 714 char *trail = partial_match (GNUNET_strdup (current_set->attr_trailer),
697 GNUNET_strdup (del->subject_attribute), 715 GNUNET_strdup (del->subject_attribute),
698 current_set->attr_trailer, 716 current_set->attr_trailer,
699 GNUNET_strdup (del->issuer_attribute)); 717 GNUNET_strdup (del->issuer_attribute));
700 718
701 // if null: skip this record entry (reasons: mismatch or overmatch, both not relevant) 719 // if null: skip this record entry (reasons: mismatch or overmatch, both not relevant)
702 if(NULL == trail) { 720 if (NULL == trail)
703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entry not relevant, discarding: %s.%s <- %s.%s\n", 721 {
704 GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key), 722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
705 del->issuer_attribute, 723 "Entry not relevant, discarding: %s.%s <- %s.%s\n",
706 GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->subject_key), 724 GNUNET_CRYPTO_ecdsa_public_key_to_string (
707 del->subject_attribute); 725 &del->issuer_key),
726 del->issuer_attribute,
727 GNUNET_CRYPTO_ecdsa_public_key_to_string (
728 &del->subject_key),
729 del->subject_attribute);
708 continue; 730 continue;
709 } else 731 }
732 else
710 ds_entry->attr_trailer = trail; 733 ds_entry->attr_trailer = trail;
711 } 734 }
712 } 735 }
@@ -717,15 +740,17 @@ forward_resolution (void *cls,
717 // TODO: new ds_entry struct with subject_key (or one for both with contact_key or sth) 740 // TODO: new ds_entry struct with subject_key (or one for both with contact_key or sth)
718 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 741 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
719 GNUNET_memcpy (ds_entry->issuer_key, 742 GNUNET_memcpy (ds_entry->issuer_key,
720 &del->subject_key, 743 &del->subject_key,
721 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 744 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
722 745
723 ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry); 746 ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry);
724 ds_entry->delegation_chain_entry->subject_key = del->subject_key; 747 ds_entry->delegation_chain_entry->subject_key = del->subject_key;
725 if (0 < del->subject_attribute_len) 748 if (0 < del->subject_attribute_len)
726 ds_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup (del->subject_attribute); 749 ds_entry->delegation_chain_entry->subject_attribute =
750 GNUNET_strdup (del->subject_attribute);
727 ds_entry->delegation_chain_entry->issuer_key = del->issuer_key; 751 ds_entry->delegation_chain_entry->issuer_key = del->issuer_key;
728 ds_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (del->issuer_attribute); 752 ds_entry->delegation_chain_entry->issuer_attribute =
753 GNUNET_strdup (del->issuer_attribute);
729 754
730 // current delegation as parent 755 // current delegation as parent
731 ds_entry->parent_queue_entry = dq_entry; 756 ds_entry->parent_queue_entry = dq_entry;
@@ -733,66 +758,74 @@ forward_resolution (void *cls,
733 // Check for solution 758 // Check for solution
734 // if: issuer key we looking for 759 // if: issuer key we looking for
735 if (0 == memcmp (&del->issuer_key, 760 if (0 == memcmp (&del->issuer_key,
736 &vrh->issuer_key, 761 &vrh->issuer_key,
737 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 762 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
738 { 763 {
739 // if: issuer attr we looking for 764 // if: issuer attr we looking for
740 if (0 == strcmp (del->issuer_attribute, 765 if (0 == strcmp (del->issuer_attribute, vrh->issuer_attribute))
741 vrh->issuer_attribute)) 766 {
767 // if: complete match, meaning new trailer == issuer attr
768 if (0 == strcmp (vrh->issuer_attribute, ds_entry->attr_trailer))
742 { 769 {
743 // if: complete match, meaning new trailer == issuer attr 770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Solution\n");
744 if(0 == strcmp (vrh->issuer_attribute, ds_entry->attr_trailer)) 771
772 // Add found solution into delegation_chain
773 struct DelegationSetQueueEntry *tmp_set;
774 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
775 tmp_set = tmp_set->parent_queue_entry->parent_set)
745 { 776 {
746 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Found: Solution\n"); 777 if (NULL != tmp_set->delegation_chain_entry)
747 778 {
748 // Add found solution into delegation_chain 779 vrh->delegation_chain_size++;
749 struct DelegationSetQueueEntry *tmp_set; 780 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
750 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry; 781 vrh->delegation_chain_tail,
751 tmp_set = tmp_set->parent_queue_entry->parent_set) { 782 tmp_set->delegation_chain_entry);
752 if (NULL != tmp_set->delegation_chain_entry) {
753 vrh->delegation_chain_size++;
754 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
755 vrh->delegation_chain_tail,
756 tmp_set->delegation_chain_entry);
757 }
758 } 783 }
784 }
759 785
760 // Increase refcount for this delegate 786 // Increase refcount for this delegate
761 for (struct DelegateRecordEntry *del_entry = vrh->del_chain_head; del_entry != NULL; del_entry = del_entry->next) { 787 for (struct DelegateRecordEntry *del_entry = vrh->del_chain_head;
762 if (0 == memcmp (&del_entry->delegate->issuer_key, 788 del_entry != NULL;
763 &vrh->delegation_chain_head->subject_key, 789 del_entry = del_entry->next)
764 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 790 {
791 if (0 == memcmp (&del_entry->delegate->issuer_key,
792 &vrh->delegation_chain_head->subject_key,
793 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
794 {
795 if (0 == strcmp (del_entry->delegate->issuer_attribute,
796 vrh->delegation_chain_head->subject_attribute))
765 { 797 {
766 if (0 == strcmp (del_entry->delegate->issuer_attribute, 798 del_entry->refcount++;
767 vrh->delegation_chain_head->subject_attribute))
768 {
769 del_entry->refcount++;
770 }
771 } 799 }
772 } 800 }
773
774 send_lookup_response (vrh);
775 return;
776 } 801 }
802
803 send_lookup_response (vrh);
804 return;
777 } 805 }
806 }
778 } 807 }
779 808
780 // Starting a new GNS lookup 809 // Starting a new GNS lookup
781 vrh->pending_lookups++; 810 vrh->pending_lookups++;
782 ds_entry->handle = vrh; 811 ds_entry->handle = vrh;
783 812
784 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting to look up trailer %s in zone %s\n", ds_entry->attr_trailer, GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key)); 813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
785 814 "Starting to look up trailer %s in zone %s\n",
815 ds_entry->attr_trailer,
816 GNUNET_CRYPTO_ecdsa_public_key_to_string (&del->issuer_key));
817
786 GNUNET_GNS_lookup (gns, 818 GNUNET_GNS_lookup (gns,
787 GNUNET_GNS_EMPTY_LABEL_AT, 819 GNUNET_GNS_EMPTY_LABEL_AT,
788 &del->issuer_key, 820 &del->issuer_key,
789 GNUNET_GNSRECORD_TYPE_DELEGATE, 821 GNUNET_GNSRECORD_TYPE_DELEGATE,
790 GNUNET_GNS_LO_DEFAULT, 822 GNUNET_GNS_LO_DEFAULT,
791 &forward_resolution, 823 &forward_resolution,
792 ds_entry); 824 ds_entry);
793 } 825 }
794 826
795 if (0 == vrh->pending_lookups) { 827 if (0 == vrh->pending_lookups)
828 {
796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); 829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
797 send_lookup_response (vrh); 830 send_lookup_response (vrh);
798 return; 831 return;
@@ -820,23 +853,24 @@ backward_resolution (void *cls,
820 vrh->pending_lookups--; 853 vrh->pending_lookups--;
821 854
822 // Each OR 855 // Each OR
823 for (uint32_t i = 0; i < rd_count; i++) { 856 for (uint32_t i = 0; i < rd_count; i++)
857 {
824 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 858 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
825 continue; 859 continue;
826 860
827 sets = rd[i].data; 861 sets = rd[i].data;
828 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)]; 862 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)];
829 GNUNET_log ( 863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
830 GNUNET_ERROR_TYPE_DEBUG, 864 "Found new attribute delegation with %d sets. Creating new Job...\n",
831 "Found new attribute delegation with %d sets. Creating new Job...\n", 865 ntohl (sets->set_count));
832 ntohl (sets->set_count)); 866
833 867 if (GNUNET_OK !=
834 if (GNUNET_OK 868 GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (
835 != GNUNET_CREDENTIAL_delegation_set_deserialize ( 869 sets->data_size),
836 GNUNET_ntohll (sets->data_size), 870 (const char *) &sets[1],
837 (const char *)&sets[1], 871 ntohl (sets->set_count),
838 ntohl (sets->set_count), 872 set))
839 set)) { 873 {
840 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n"); 874 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
841 continue; 875 continue;
842 } 876 }
@@ -848,13 +882,17 @@ backward_resolution (void *cls,
848 current_set->queue_entries_tail, 882 current_set->queue_entries_tail,
849 dq_entry); 883 dq_entry);
850 // Each AND 884 // Each AND
851 for (uint32_t j = 0; j < ntohl (sets->set_count); j++) { 885 for (uint32_t j = 0; j < ntohl (sets->set_count); j++)
886 {
852 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 887 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
853 if (NULL != current_set->attr_trailer) { 888 if (NULL != current_set->attr_trailer)
854 if (0 == set[j].subject_attribute_len) { 889 {
890 if (0 == set[j].subject_attribute_len)
891 {
855 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer); 892 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
856 893 }
857 } else { 894 else
895 {
858 GNUNET_asprintf (&expanded_attr, 896 GNUNET_asprintf (&expanded_attr,
859 "%s.%s", 897 "%s.%s",
860 set[j].subject_attribute, 898 set[j].subject_attribute,
@@ -862,30 +900,33 @@ backward_resolution (void *cls,
862 } 900 }
863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr); 901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
864 ds_entry->unresolved_attribute_delegation = expanded_attr; 902 ds_entry->unresolved_attribute_delegation = expanded_attr;
865 } else { 903 }
866 if (0 != set[j].subject_attribute_len) { 904 else
905 {
906 if (0 != set[j].subject_attribute_len)
907 {
867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
868 "Not Expanding %s\n", 909 "Not Expanding %s\n",
869 set[j].subject_attribute); 910 set[j].subject_attribute);
870 ds_entry->unresolved_attribute_delegation 911 ds_entry->unresolved_attribute_delegation =
871 = GNUNET_strdup (set[j].subject_attribute); 912 GNUNET_strdup (set[j].subject_attribute);
872 } 913 }
873 } 914 }
874 915
875 // Add a credential chain entry 916 // Add a credential chain entry
876 ds_entry->delegation_chain_entry 917 ds_entry->delegation_chain_entry =
877 = GNUNET_new (struct DelegationChainEntry); 918 GNUNET_new (struct DelegationChainEntry);
878 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key; 919 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
879 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 920 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
880 GNUNET_memcpy (ds_entry->issuer_key, 921 GNUNET_memcpy (ds_entry->issuer_key,
881 &set[j].subject_key, 922 &set[j].subject_key,
882 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 923 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
883 if (0 < set[j].subject_attribute_len) 924 if (0 < set[j].subject_attribute_len)
884 ds_entry->delegation_chain_entry->subject_attribute 925 ds_entry->delegation_chain_entry->subject_attribute =
885 = GNUNET_strdup (set[j].subject_attribute); 926 GNUNET_strdup (set[j].subject_attribute);
886 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key; 927 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
887 ds_entry->delegation_chain_entry->issuer_attribute 928 ds_entry->delegation_chain_entry->issuer_attribute =
888 = GNUNET_strdup (current_set->lookup_attribute); 929 GNUNET_strdup (current_set->lookup_attribute);
889 930
890 ds_entry->parent_queue_entry = dq_entry; // current_delegation; 931 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
891 932
@@ -898,30 +939,31 @@ backward_resolution (void *cls,
898 * Check if this delegation already matches one of our credentials 939 * Check if this delegation already matches one of our credentials
899 */ 940 */
900 for (del_pointer = vrh->del_chain_head; del_pointer != NULL; 941 for (del_pointer = vrh->del_chain_head; del_pointer != NULL;
901 del_pointer = del_pointer->next) { 942 del_pointer = del_pointer->next)
943 {
902 // If key and attribute match credential continue and backtrack 944 // If key and attribute match credential continue and backtrack
903 if (0 945 if (0 != memcmp (&set->subject_key,
904 != memcmp (&set->subject_key, 946 &del_pointer->delegate->issuer_key,
905 &del_pointer->delegate->issuer_key, 947 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
906 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
907 continue; 948 continue;
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Checking if %s matches %s\n", 950 "Checking if %s matches %s\n",
910 ds_entry->unresolved_attribute_delegation, 951 ds_entry->unresolved_attribute_delegation,
911 del_pointer->delegate->issuer_attribute); 952 del_pointer->delegate->issuer_attribute);
912 953
913 if (0 954 if (0 != strcmp (ds_entry->unresolved_attribute_delegation,
914 != strcmp (ds_entry->unresolved_attribute_delegation, 955 del_pointer->delegate->issuer_attribute))
915 del_pointer->delegate->issuer_attribute))
916 continue; 956 continue;
917 957
918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n"); 958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
919 del_pointer->refcount++; 959 del_pointer->refcount++;
920 // Backtrack 960 // Backtrack
921 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry; 961 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
922 tmp_set = tmp_set->parent_queue_entry->parent_set) { 962 tmp_set = tmp_set->parent_queue_entry->parent_set)
963 {
923 tmp_set->parent_queue_entry->required_solutions--; 964 tmp_set->parent_queue_entry->required_solutions--;
924 if (NULL != tmp_set->delegation_chain_entry) { 965 if (NULL != tmp_set->delegation_chain_entry)
966 {
925 vrh->delegation_chain_size++; 967 vrh->delegation_chain_size++;
926 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head, 968 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
927 vrh->delegation_chain_tail, 969 vrh->delegation_chain_tail,
@@ -931,63 +973,69 @@ backward_resolution (void *cls,
931 break; 973 break;
932 } 974 }
933 975
934 if (NULL == tmp_set->parent_queue_entry) { 976 if (NULL == tmp_set->parent_queue_entry)
935 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n"); 977 {
978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All solutions found\n");
936 // Found match 979 // Found match
937 send_lookup_response (vrh); 980 send_lookup_response (vrh);
938 return; 981 return;
939 } 982 }
940 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n"); 983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not all solutions found yet.\n");
941 continue; 984 continue;
942 } 985 }
943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
944 "Building new lookup request from %s\n", 987 "Building new lookup request from %s\n",
945 ds_entry->unresolved_attribute_delegation); 988 ds_entry->unresolved_attribute_delegation);
946 // Continue with backward resolution 989 // Continue with backward resolution
947 char 990 char issuer_attribute_name[strlen (
948 issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation) 991 ds_entry->unresolved_attribute_delegation) +
949 + 1]; 992 1];
950 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation); 993 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
951 char *next_attr = strtok (issuer_attribute_name, "."); 994 char *next_attr = strtok (issuer_attribute_name, ".");
952 if (NULL == next_attr) { 995 if (NULL == next_attr)
996 {
953 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 997 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
954 "Failed to parse next attribute\n"); 998 "Failed to parse next attribute\n");
955 continue; 999 continue;
956 } 1000 }
957 GNUNET_asprintf (&lookup_attribute, "%s", next_attr); 1001 GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
958 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr); 1002 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
959 if (strlen (next_attr) 1003 if (strlen (next_attr) ==
960 == strlen (ds_entry->unresolved_attribute_delegation)) { 1004 strlen (ds_entry->unresolved_attribute_delegation))
1005 {
961 ds_entry->attr_trailer = NULL; 1006 ds_entry->attr_trailer = NULL;
962 } else { 1007 }
1008 else
1009 {
963 next_attr += strlen (next_attr) + 1; 1010 next_attr += strlen (next_attr) + 1;
964 ds_entry->attr_trailer = GNUNET_strdup (next_attr); 1011 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
965 } 1012 }
966 1013
967 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
968 "Looking up %s\n", 1015 "Looking up %s\n",
969 ds_entry->lookup_attribute); 1016 ds_entry->lookup_attribute);
970 if (NULL != ds_entry->attr_trailer) 1017 if (NULL != ds_entry->attr_trailer)
971 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
972 "%s still to go...\n", 1019 "%s still to go...\n",
973 ds_entry->attr_trailer); 1020 ds_entry->attr_trailer);
974 1021
975 vrh->pending_lookups++; 1022 vrh->pending_lookups++;
976 ds_entry->handle = vrh; 1023 ds_entry->handle = vrh;
977 ds_entry->lookup_request 1024 ds_entry->lookup_request =
978 = GNUNET_GNS_lookup (gns, 1025 GNUNET_GNS_lookup (gns,
979 lookup_attribute, 1026 lookup_attribute,
980 ds_entry->issuer_key, // issuer_key, 1027 ds_entry->issuer_key, // issuer_key,
981 GNUNET_GNSRECORD_TYPE_ATTRIBUTE, 1028 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
982 GNUNET_GNS_LO_DEFAULT, 1029 GNUNET_GNS_LO_DEFAULT,
983 &backward_resolution, 1030 &backward_resolution,
984 ds_entry); 1031 ds_entry);
985 1032
986 GNUNET_free (lookup_attribute); 1033 GNUNET_free (lookup_attribute);
987 } 1034 }
988 } 1035 }
989 1036
990 if (0 == vrh->pending_lookups) { 1037 if (0 == vrh->pending_lookups)
1038 {
991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); 1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
992 send_lookup_response (vrh); 1040 send_lookup_response (vrh);
993 return; 1041 return;
@@ -1008,20 +1056,22 @@ delegation_chain_bw_resolution_start (void *cls)
1008 struct DelegateRecordEntry *del_entry; 1056 struct DelegateRecordEntry *del_entry;
1009 vrh->lookup_request = NULL; 1057 vrh->lookup_request = NULL;
1010 1058
1011 if (0 == vrh->del_chain_size) { 1059 if (0 == vrh->del_chain_size)
1060 {
1012 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegates found\n"); 1061 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegates found\n");
1013 send_lookup_response (vrh); 1062 send_lookup_response (vrh);
1014 return; 1063 return;
1015 } 1064 }
1016 1065
1017 for (del_entry = vrh->del_chain_head; del_entry != NULL; 1066 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1018 del_entry = del_entry->next) { 1067 del_entry = del_entry->next)
1068 {
1019 if (0 != memcmp (&del_entry->delegate->issuer_key, 1069 if (0 != memcmp (&del_entry->delegate->issuer_key,
1020 &vrh->issuer_key, 1070 &vrh->issuer_key,
1021 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 1071 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
1022 continue; 1072 continue;
1023 if (0 != strcmp (del_entry->delegate->issuer_attribute, 1073 if (0 !=
1024 vrh->issuer_attribute)) 1074 strcmp (del_entry->delegate->issuer_attribute, vrh->issuer_attribute))
1025 continue; 1075 continue;
1026 del_entry->refcount++; 1076 del_entry->refcount++;
1027 // Found match prematurely 1077 // Found match prematurely
@@ -1029,7 +1079,7 @@ delegation_chain_bw_resolution_start (void *cls)
1029 return; 1079 return;
1030 } 1080 }
1031 1081
1032 1082
1033 //Check for attributes from the issuer and follow the chain 1083 //Check for attributes from the issuer and follow the chain
1034 //till you get the required subject's attributes 1084 //till you get the required subject's attributes
1035 char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1]; 1085 char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1];
@@ -1084,20 +1134,23 @@ delegation_chain_fw_resolution_start (void *cls)
1084 // X.x <- C 1134 // X.x <- C
1085 // Y.y <- C 1135 // Y.y <- C
1086 // wenn X.x oder Y.y nicht == A.a dann starte von A 1136 // wenn X.x oder Y.y nicht == A.a dann starte von A
1087 if (0 == vrh->del_chain_size) { 1137 if (0 == vrh->del_chain_size)
1138 {
1088 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegations found\n"); 1139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegations found\n");
1089 send_lookup_response (vrh); 1140 send_lookup_response (vrh);
1090 return; 1141 return;
1091 } 1142 }
1092 1143
1093 // Check if one of the delegations of the subject already match 1144 // Check if one of the delegations of the subject already match
1094 for (del_entry = vrh->del_chain_head; del_entry != NULL; del_entry = del_entry->next) { 1145 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1146 del_entry = del_entry->next)
1147 {
1095 if (0 != memcmp (&del_entry->delegate->issuer_key, 1148 if (0 != memcmp (&del_entry->delegate->issuer_key,
1096 &vrh->issuer_key, 1149 &vrh->issuer_key,
1097 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 1150 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
1098 continue; 1151 continue;
1099 if (0 != strcmp (del_entry->delegate->issuer_attribute, 1152 if (0 !=
1100 vrh->issuer_attribute)) 1153 strcmp (del_entry->delegate->issuer_attribute, vrh->issuer_attribute))
1101 continue; 1154 continue;
1102 del_entry->refcount++; 1155 del_entry->refcount++;
1103 // Found match prematurely 1156 // Found match prematurely
@@ -1110,33 +1163,39 @@ delegation_chain_fw_resolution_start (void *cls)
1110 1163
1111 // ds_entry created belongs to the first lookup, vrh still has the 1164 // ds_entry created belongs to the first lookup, vrh still has the
1112 // issuer+attr we look for 1165 // issuer+attr we look for
1113 for (del_entry = vrh->del_chain_head; del_entry != NULL; del_entry = del_entry->next) { 1166 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1167 del_entry = del_entry->next)
1168 {
1114 1169
1115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1116 "Looking for %s.%s\n", 1171 "Looking for %s.%s\n",
1117 GNUNET_CRYPTO_ecdsa_public_key_to_string(&del_entry->delegate->issuer_key), del_entry->delegate->issuer_attribute); 1172 GNUNET_CRYPTO_ecdsa_public_key_to_string (
1118 1173 &del_entry->delegate->issuer_key),
1174 del_entry->delegate->issuer_attribute);
1175
1119 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 1176 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
1120 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 1177 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
1121 // TODO: new ds_entry struct with subject_key (or one for both with contact_key or sth) 1178 // TODO: new ds_entry struct with subject_key (or one for both with contact_key or sth)
1122 GNUNET_memcpy (ds_entry->issuer_key, 1179 GNUNET_memcpy (ds_entry->issuer_key,
1123 &del_entry->delegate->subject_key, 1180 &del_entry->delegate->subject_key,
1124 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 1181 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1125 ds_entry->attr_trailer = GNUNET_strdup(del_entry->delegate->issuer_attribute); 1182 ds_entry->attr_trailer =
1183 GNUNET_strdup (del_entry->delegate->issuer_attribute);
1126 ds_entry->handle = vrh; 1184 ds_entry->handle = vrh;
1127 1185
1128 vrh->root_set = ds_entry; 1186 vrh->root_set = ds_entry;
1129 vrh->pending_lookups ++; 1187 vrh->pending_lookups++;
1130 // Start with forward resolution 1188 // Start with forward resolution
1131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start Forward Resolution\n"); 1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start Forward Resolution\n");
1132 1190
1133 ds_entry->lookup_request = GNUNET_GNS_lookup (gns, 1191 ds_entry->lookup_request =
1134 GNUNET_GNS_EMPTY_LABEL_AT, 1192 GNUNET_GNS_lookup (gns,
1135 &del_entry->delegate->issuer_key, // issuer_key, 1193 GNUNET_GNS_EMPTY_LABEL_AT,
1136 GNUNET_GNSRECORD_TYPE_DELEGATE, 1194 &del_entry->delegate->issuer_key, // issuer_key,
1137 GNUNET_GNS_LO_DEFAULT, 1195 GNUNET_GNSRECORD_TYPE_DELEGATE,
1138 &forward_resolution, 1196 GNUNET_GNS_LO_DEFAULT,
1139 ds_entry); 1197 &forward_resolution,
1198 ds_entry);
1140 } 1199 }
1141} 1200}
1142 1201
@@ -1147,17 +1206,20 @@ check_verify (void *cls, const struct VerifyMessage *v_msg)
1147 const char *attr; 1206 const char *attr;
1148 1207
1149 msg_size = ntohs (v_msg->header.size); 1208 msg_size = ntohs (v_msg->header.size);
1150 if (msg_size < sizeof (struct VerifyMessage)) { 1209 if (msg_size < sizeof (struct VerifyMessage))
1210 {
1151 GNUNET_break (0); 1211 GNUNET_break (0);
1152 return GNUNET_SYSERR; 1212 return GNUNET_SYSERR;
1153 } 1213 }
1154 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) { 1214 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
1215 {
1155 GNUNET_break (0); 1216 GNUNET_break (0);
1156 return GNUNET_SYSERR; 1217 return GNUNET_SYSERR;
1157 } 1218 }
1158 attr = (const char *)&v_msg[1]; 1219 attr = (const char *) &v_msg[1];
1159 1220
1160 if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) { 1221 if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)
1222 {
1161 GNUNET_break (0); 1223 GNUNET_break (0);
1162 return GNUNET_SYSERR; 1224 return GNUNET_SYSERR;
1163 } 1225 }
@@ -1179,7 +1241,7 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
1179 const char *utf_in; 1241 const char *utf_in;
1180 1242
1181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n"); 1243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
1182 utf_in = (const char *)&v_msg[1]; 1244 utf_in = (const char *) &v_msg[1];
1183 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 1245 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1184 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len)); 1246 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
1185 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0'; 1247 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
@@ -1190,50 +1252,52 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
1190 vrh->issuer_key = v_msg->issuer_key; 1252 vrh->issuer_key = v_msg->issuer_key;
1191 vrh->subject_key = v_msg->subject_key; 1253 vrh->subject_key = v_msg->subject_key;
1192 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 1254 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1193 vrh->resolution_algo = ntohs(v_msg->resolution_algo); 1255 vrh->resolution_algo = ntohs (v_msg->resolution_algo);
1194 1256
1195 GNUNET_SERVICE_client_continue (vrh->client); 1257 GNUNET_SERVICE_client_continue (vrh->client);
1196 if (0 == strlen (issuer_attribute)) { 1258 if (0 == strlen (issuer_attribute))
1259 {
1197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 1260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1198 send_lookup_response (vrh); 1261 send_lookup_response (vrh);
1199 return; 1262 return;
1200 } 1263 }
1201 1264
1202 // Parse delegates from verifaction message 1265 // Parse delegates from verifaction message
1203 delegate_count = ntohl (v_msg->d_count); 1266 delegate_count = ntohl (v_msg->d_count);
1204 delegate_data_size = ntohs (v_msg->header.size) 1267 delegate_data_size = ntohs (v_msg->header.size) -
1205 - sizeof (struct VerifyMessage) 1268 sizeof (struct VerifyMessage) -
1206 - ntohs (v_msg->issuer_attribute_len) - 1; 1269 ntohs (v_msg->issuer_attribute_len) - 1;
1207 struct GNUNET_CREDENTIAL_Delegate delegates[delegate_count]; 1270 struct GNUNET_CREDENTIAL_Delegate delegates[delegate_count];
1208 memset (delegates, 1271 memset (delegates,
1209 0, 1272 0,
1210 sizeof (struct GNUNET_CREDENTIAL_Delegate) * delegate_count); 1273 sizeof (struct GNUNET_CREDENTIAL_Delegate) * delegate_count);
1211 delegate_data = (char *)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1; 1274 delegate_data = (char *) &v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1;
1212 if (GNUNET_OK 1275 if (GNUNET_OK != GNUNET_CREDENTIAL_delegates_deserialize (delegate_data_size,
1213 != GNUNET_CREDENTIAL_delegates_deserialize (delegate_data_size, 1276 delegate_data,
1214 delegate_data, 1277 delegate_count,
1215 delegate_count, 1278 delegates))
1216 delegates)) { 1279 {
1217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize delegates!\n"); 1280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize delegates!\n");
1218 send_lookup_response (vrh); 1281 send_lookup_response (vrh);
1219 return; 1282 return;
1220 } 1283 }
1221 1284
1222 // Prepare vrh delegation chain for later validation 1285 // Prepare vrh delegation chain for later validation
1223 for (uint32_t i = 0; i < delegate_count; i++) { 1286 for (uint32_t i = 0; i < delegate_count; i++)
1287 {
1224 del_entry = GNUNET_new (struct DelegateRecordEntry); 1288 del_entry = GNUNET_new (struct DelegateRecordEntry);
1225 del_entry->delegate 1289 del_entry->delegate =
1226 = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) 1290 GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) +
1227 + delegates[i].issuer_attribute_len + 1); 1291 delegates[i].issuer_attribute_len + 1);
1228 GNUNET_memcpy (del_entry->delegate, 1292 GNUNET_memcpy (del_entry->delegate,
1229 &delegates[i], 1293 &delegates[i],
1230 sizeof (struct GNUNET_CREDENTIAL_Delegate)); 1294 sizeof (struct GNUNET_CREDENTIAL_Delegate));
1231 GNUNET_memcpy (&del_entry->delegate[1], 1295 GNUNET_memcpy (&del_entry->delegate[1],
1232 delegates[i].issuer_attribute, 1296 delegates[i].issuer_attribute,
1233 delegates[i].issuer_attribute_len); 1297 delegates[i].issuer_attribute_len);
1234 del_entry->delegate->issuer_attribute_len 1298 del_entry->delegate->issuer_attribute_len =
1235 = delegates[i].issuer_attribute_len; 1299 delegates[i].issuer_attribute_len;
1236 del_entry->delegate->issuer_attribute = (char *)&del_entry->delegate[1]; 1300 del_entry->delegate->issuer_attribute = (char *) &del_entry->delegate[1];
1237 GNUNET_CONTAINER_DLL_insert_tail (vrh->del_chain_head, 1301 GNUNET_CONTAINER_DLL_insert_tail (vrh->del_chain_head,
1238 vrh->del_chain_tail, 1302 vrh->del_chain_tail,
1239 del_entry); 1303 del_entry);
@@ -1241,11 +1305,16 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
1241 } 1305 }
1242 1306
1243 // Switch resolution algo 1307 // Switch resolution algo
1244 if(Backward == vrh->resolution_algo){ 1308 if (GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo)
1309 {
1245 delegation_chain_bw_resolution_start (vrh); 1310 delegation_chain_bw_resolution_start (vrh);
1246 } else if (Forward == vrh->resolution_algo){ 1311 }
1312 else if (GNUNET_CREDENTIAL_FLAG_FORWARD & vrh->resolution_algo)
1313 {
1247 delegation_chain_fw_resolution_start (vrh); 1314 delegation_chain_fw_resolution_start (vrh);
1248 } else{ 1315 }
1316 else
1317 {
1249 //TODO 1318 //TODO
1250 } 1319 }
1251} 1320}
@@ -1266,21 +1335,26 @@ delegate_collection_finished (void *cls)
1266 struct VerifyRequestHandle *vrh = cls; 1335 struct VerifyRequestHandle *vrh = cls;
1267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting delegates.\n"); 1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting delegates.\n");
1268 1337
1269 if(Backward == vrh->resolution_algo){ 1338 if (GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo)
1339 {
1270 delegation_chain_bw_resolution_start (vrh); 1340 delegation_chain_bw_resolution_start (vrh);
1271 } else if (Forward == vrh->resolution_algo){ 1341 }
1342 else if (GNUNET_CREDENTIAL_FLAG_FORWARD & vrh->resolution_algo)
1343 {
1272 delegation_chain_fw_resolution_start (vrh); 1344 delegation_chain_fw_resolution_start (vrh);
1273 } else{ 1345 }
1346 else
1347 {
1274 //TODO 1348 //TODO
1275 } 1349 }
1276} 1350}
1277 1351
1278static void 1352static void
1279handle_delegate_collection_cb (void *cls, 1353handle_delegate_collection_cb (void *cls,
1280 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 1354 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
1281 const char *label, 1355 const char *label,
1282 unsigned int rd_count, 1356 unsigned int rd_count,
1283 const struct GNUNET_GNSRECORD_Data *rd) 1357 const struct GNUNET_GNSRECORD_Data *rd)
1284{ 1358{
1285 struct VerifyRequestHandle *vrh = cls; 1359 struct VerifyRequestHandle *vrh = cls;
1286 struct GNUNET_CREDENTIAL_Delegate *del; 1360 struct GNUNET_CREDENTIAL_Delegate *del;
@@ -1289,25 +1363,31 @@ handle_delegate_collection_cb (void *cls,
1289 cred_record_count = 0; 1363 cred_record_count = 0;
1290 vrh->dele_qe = NULL; 1364 vrh->dele_qe = NULL;
1291 1365
1292 //TODO not all, only private and with sub_attr_len == 0 1366 for (uint32_t i = 0; i < rd_count; i++)
1293 for (uint32_t i = 0; i < rd_count; i++) { 1367 {
1294 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type) 1368 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type)
1295 continue; 1369 continue;
1296 cred_record_count++; 1370 cred_record_count++;
1297 del = GNUNET_CREDENTIAL_delegate_deserialize (rd[i].data, rd[i].data_size); 1371 del = GNUNET_CREDENTIAL_delegate_deserialize (rd[i].data, rd[i].data_size);
1298 if (NULL == del) { 1372 if (NULL == del)
1299 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n"); 1373 {
1374 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid delegate found\n");
1300 continue; 1375 continue;
1301 } 1376 }
1302 del_entry = GNUNET_new (struct DelegateRecordEntry); 1377 // only add the entries that are explicity marked as private
1303 del_entry->delegate = del; 1378 // and therefor symbolize the end of a chain
1304 GNUNET_CONTAINER_DLL_insert_tail (vrh->del_chain_head, 1379 if (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)
1305 vrh->del_chain_tail, 1380 {
1306 del_entry); 1381 del_entry = GNUNET_new (struct DelegateRecordEntry);
1307 vrh->del_chain_size++; 1382 del_entry->delegate = del;
1383 GNUNET_CONTAINER_DLL_insert_tail (vrh->del_chain_head,
1384 vrh->del_chain_tail,
1385 del_entry);
1386 vrh->del_chain_size++;
1387 }
1308 } 1388 }
1309 1389
1310 delegate_collection_finished(vrh); 1390 delegate_collection_finished (vrh);
1311} 1391}
1312 1392
1313static void 1393static void
@@ -1322,7 +1402,7 @@ handle_collect (void *cls, const struct CollectMessage *c_msg)
1322 1402
1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n"); 1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
1324 1404
1325 utf_in = (const char *)&c_msg[1]; 1405 utf_in = (const char *) &c_msg[1];
1326 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 1406 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1327 1407
1328 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len)); 1408 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
@@ -1334,23 +1414,25 @@ handle_collect (void *cls, const struct CollectMessage *c_msg)
1334 vrh->issuer_key = c_msg->issuer_key; 1414 vrh->issuer_key = c_msg->issuer_key;
1335 GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key); 1415 GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key);
1336 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 1416 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1337 vrh->resolution_algo = ntohs(c_msg->resolution_algo); 1417 vrh->resolution_algo = ntohs (c_msg->resolution_algo);
1338 1418
1339 if (0 == strlen (issuer_attribute)) { 1419 if (0 == strlen (issuer_attribute))
1420 {
1340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 1421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1341 send_lookup_response (vrh); 1422 send_lookup_response (vrh);
1342 return; 1423 return;
1343 } 1424 }
1344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting delegates for subject\n"); 1425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting delegates for subject\n");
1345 1426
1346 // Get all delegates from subject 1427 // Get all delegates from subject
1347 vrh->dele_qe = GNUNET_NAMESTORE_records_lookup (namestore, 1428 vrh->dele_qe =
1348 &c_msg->subject_key, 1429 GNUNET_NAMESTORE_records_lookup (namestore,
1349 GNUNET_GNS_EMPTY_LABEL_AT, 1430 &c_msg->subject_key,
1350 &handle_delegate_collection_error_cb, 1431 GNUNET_GNS_EMPTY_LABEL_AT,
1351 vrh, 1432 &handle_delegate_collection_error_cb,
1352 &handle_delegate_collection_cb, 1433 vrh,
1353 vrh); 1434 &handle_delegate_collection_cb,
1435 vrh);
1354 GNUNET_SERVICE_client_continue (vrh->client); 1436 GNUNET_SERVICE_client_continue (vrh->client);
1355} 1437}
1356 1438
@@ -1362,18 +1444,21 @@ check_collect (void *cls, const struct CollectMessage *c_msg)
1362 const char *attr; 1444 const char *attr;
1363 1445
1364 msg_size = ntohs (c_msg->header.size); 1446 msg_size = ntohs (c_msg->header.size);
1365 if (msg_size < sizeof (struct CollectMessage)) { 1447 if (msg_size < sizeof (struct CollectMessage))
1448 {
1366 GNUNET_break (0); 1449 GNUNET_break (0);
1367 return GNUNET_SYSERR; 1450 return GNUNET_SYSERR;
1368 } 1451 }
1369 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) { 1452 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
1453 {
1370 GNUNET_break (0); 1454 GNUNET_break (0);
1371 return GNUNET_SYSERR; 1455 return GNUNET_SYSERR;
1372 } 1456 }
1373 attr = (const char *)&c_msg[1]; 1457 attr = (const char *) &c_msg[1];
1374 1458
1375 if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) 1459 if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) ||
1376 || (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) { 1460 (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH))
1461 {
1377 GNUNET_break (0); 1462 GNUNET_break (0);
1378 return GNUNET_SYSERR; 1463 return GNUNET_SYSERR;
1379 } 1464 }
@@ -1411,11 +1496,13 @@ run (void *cls,
1411{ 1496{
1412 1497
1413 gns = GNUNET_GNS_connect (c); 1498 gns = GNUNET_GNS_connect (c);
1414 if (NULL == gns) { 1499 if (NULL == gns)
1500 {
1415 fprintf (stderr, _ ("Failed to connect to GNS\n")); 1501 fprintf (stderr, _ ("Failed to connect to GNS\n"));
1416 } 1502 }
1417 namestore = GNUNET_NAMESTORE_connect (c); 1503 namestore = GNUNET_NAMESTORE_connect (c);
1418 if (NULL == namestore) { 1504 if (NULL == namestore)
1505 {
1419 fprintf (stderr, _ ("Failed to connect to namestore\n")); 1506 fprintf (stderr, _ ("Failed to connect to namestore\n"));
1420 } 1507 }
1421 1508
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 784c7def1..088c4dd0e 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -27,7 +27,6 @@
27 27
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29 29
30#include "credential_misc.h"
31#include "delegate_misc.h" 30#include "delegate_misc.h"
32#include "credential_serialization.h" 31#include "credential_serialization.h"
33#include "gnunet_credential_service.h" 32#include "gnunet_credential_service.h"
@@ -79,7 +78,7 @@ credential_value_to_string (void *cls,
79 { 78 {
80 subject_pkey = 79 subject_pkey =
81 GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); 80 GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key);
82 81
83 if (0 == set[i].subject_attribute_len) 82 if (0 == set[i].subject_attribute_len)
84 { 83 {
85 if (0 == i) 84 if (0 == i)
@@ -117,16 +116,6 @@ credential_value_to_string (void *cls,
117 } 116 }
118 return attr_str; 117 return attr_str;
119 } 118 }
120 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
121 {
122 struct GNUNET_CREDENTIAL_Credential *cred;
123 char *cred_str;
124
125 cred = GNUNET_CREDENTIAL_credential_deserialize (data, data_size);
126 cred_str = GNUNET_CREDENTIAL_credential_to_string (cred);
127 GNUNET_free (cred);
128 return cred_str;
129 }
130 case GNUNET_GNSRECORD_TYPE_DELEGATE: 119 case GNUNET_GNSRECORD_TYPE_DELEGATE:
131 { 120 {
132 struct GNUNET_CREDENTIAL_Delegate *cred; 121 struct GNUNET_CREDENTIAL_Delegate *cred;
@@ -255,14 +244,6 @@ credential_string_to_value (void *cls,
255 GNUNET_free (tmp_str); 244 GNUNET_free (tmp_str);
256 return GNUNET_OK; 245 return GNUNET_OK;
257 } 246 }
258 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
259 {
260 struct GNUNET_CREDENTIAL_Credential *cred;
261 cred = GNUNET_CREDENTIAL_credential_from_string (s);
262
263 *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **) data);
264 return GNUNET_OK;
265 }
266 case GNUNET_GNSRECORD_TYPE_DELEGATE: 247 case GNUNET_GNSRECORD_TYPE_DELEGATE:
267 { 248 {
268 struct GNUNET_CREDENTIAL_Delegate *cred; 249 struct GNUNET_CREDENTIAL_Delegate *cred;
diff --git a/src/credential/test_credential_own.sh b/src/credential/test_credential_own.sh
index d2ed0b0ac..4ff1a8e08 100755
--- a/src/credential/test_credential_own.sh
+++ b/src/credential/test_credential_own.sh
@@ -74,8 +74,10 @@ gnunet-credential --createSubjectSide --ego=f --import "$SIGNED"
74gnunet-namestore -D -z f 74gnunet-namestore -D -z f
75 75
76SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=f --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"` 76SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=f --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"`
77gnunet-credential --createSubjectSide --ego=g --import "$SIGNED" 77gnunet-credential --createSubjectSide --ego=g --import "$SIGNED" --private
78SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=a --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"` 78SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=a --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"`
79gnunet-credential --createSubjectSide --ego=g --import "$SIGNED" --private
80SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=d --attribute="h.o" --subject="$GKEY" --ttl="2019-12-12 10:00:00"`
79gnunet-credential --createSubjectSide --ego=g --import "$SIGNED" 81gnunet-credential --createSubjectSide --ego=g --import "$SIGNED"
80gnunet-namestore -D -z g 82gnunet-namestore -D -z g
81 83
@@ -92,20 +94,20 @@ gnunet-credential --createIssuerSide --ego=stateu --attribute=$STATE_STUD_ATTR -
92 94
93# (4) RegistrarB issues Alice the credential "student" 95# (4) RegistrarB issues Alice the credential "student"
94SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=registrarb --attribute="$REG_STUD_ATTR" --subject="$ALICE_KEY" --ttl="2019-12-12 10:00:00"` 96SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=registrarb --attribute="$REG_STUD_ATTR" --subject="$ALICE_KEY" --ttl="2019-12-12 10:00:00"`
95gnunet-credential --createSubjectSide --ego=alice --import "$SIGNED" 97gnunet-credential --createSubjectSide --ego=alice --import "$SIGNED" --private
96 98
97# Starting to resolve 99# Starting to resolve
98echo "+++ Starting to Resolve +++" 100echo "+++ Starting to Resolve +++"
99 101
100#CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$AKEY --attribute="a" --ego=g -c test_credential_lookup.conf | paste -d, -s` 102#DELS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$AKEY --attribute="a" --ego=g --forward -c test_credential_lookup.conf | paste -d, -s`
101#echo $CREDS 103#echo $DELS
102#echo gnunet-credential --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --credential=\'$CREDS\' -c test_credential_lookup.conf 104#echo gnunet-credential --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --delegate=\'$DELS\' --forward -c test_credential_lookup.conf
103#RES_CRED=`gnunet-credential --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --credential="$CREDS" -c test_credential_lookup.conf` 105#RES_DELS=`gnunet-credential --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --delegate="$DELS" --forward -c test_credential_lookup.conf`
104 106
105CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute=$DISC_ATTR --ego=alice -c test_credential_lookup.conf | paste -d, -s` 107DELS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute=$DISC_ATTR --ego=alice --backward -c test_credential_lookup.conf | paste -d, -s`
106echo $CREDS 108echo $DELS
107echo gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential=\'$CREDS\' -c test_credential_lookup.conf 109echo gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --delegate=\'$DELS\' --backward -c test_credential_lookup.conf
108RES_CRED=`gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf` 110RES_DELS=`gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --delegate="$DELS" --backward -c test_credential_lookup.conf`
109 111
110 112
111# Cleanup properly 113# Cleanup properly
@@ -120,13 +122,13 @@ gnunet-namestore -z stateu -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_loo
120 122
121gnunet-arm -e -c test_credential_lookup.conf 123gnunet-arm -e -c test_credential_lookup.conf
122 124
123if [ "$RES_CRED" != "Failed." ] 125if [ "$RES_DELS" != "Failed." ]
124then 126then
125 # TODO: replace echo -e bashism 127 # TODO: replace echo -e bashism
126 echo -e "${RES_CRED}" 128 echo -e "${RES_DELS}"
127 exit 0 129 exit 0
128else 130else
129 echo "FAIL: Failed to verify credential $RES_CRED." 131 echo "FAIL: Failed to verify credential $RES_DELS."
130 exit 1 132 exit 1
131fi 133fi
132 134