summaryrefslogtreecommitdiff
path: root/src/credential/credential_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/credential_api.c')
-rw-r--r--src/credential/credential_api.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/credential/credential_api.c b/src/credential/credential_api.c
index 3cbaf6c21..7323d3b1c 100644
--- a/src/credential/credential_api.c
+++ b/src/credential/credential_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19*/
20/** 20/**
21 * @file credential/credential_api.c 21 * @file credential/credential_api.c
22 * @brief library to access the CREDENTIAL service 22 * @brief library to access the CREDENTIAL service
@@ -35,13 +35,14 @@
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
42 */ 42 */
43struct GNUNET_CREDENTIAL_Request 43struct GNUNET_CREDENTIAL_Request
44{ 44{
45
45 /** 46 /**
46 * DLL 47 * DLL
47 */ 48 */
@@ -76,6 +77,7 @@ struct GNUNET_CREDENTIAL_Request
76 * request id 77 * request id
77 */ 78 */
78 uint32_t r_id; 79 uint32_t r_id;
80
79}; 81};
80 82
81 83
@@ -84,6 +86,7 @@ struct GNUNET_CREDENTIAL_Request
84 */ 86 */
85struct GNUNET_CREDENTIAL_Handle 87struct GNUNET_CREDENTIAL_Handle
86{ 88{
89
87 /** 90 /**
88 * Configuration to use. 91 * Configuration to use.
89 */ 92 */
@@ -118,6 +121,7 @@ struct GNUNET_CREDENTIAL_Handle
118 * Request Id generator. Incremented by one for each request. 121 * Request Id generator. Incremented by one for each request.
119 */ 122 */
120 uint32_t r_id_gen; 123 uint32_t r_id_gen;
124
121}; 125};
122 126
123 127
@@ -159,8 +163,8 @@ force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
159 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); 163 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
160 handle->reconnect_task 164 handle->reconnect_task
161 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, 165 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
162 &reconnect_task, 166 &reconnect_task,
163 handle); 167 handle);
164} 168}
165 169
166 170
@@ -191,7 +195,7 @@ static int
191check_result (void *cls, 195check_result (void *cls,
192 const struct DelegationChainResultMessage *vr_msg) 196 const struct DelegationChainResultMessage *vr_msg)
193{ 197{
194 // TODO 198 //TODO
195 return GNUNET_OK; 199 return GNUNET_OK;
196} 200}
197 201
@@ -209,11 +213,12 @@ handle_result (void *cls,
209 struct GNUNET_CREDENTIAL_Handle *handle = cls; 213 struct GNUNET_CREDENTIAL_Handle *handle = cls;
210 uint32_t r_id = ntohl (vr_msg->id); 214 uint32_t r_id = ntohl (vr_msg->id);
211 struct GNUNET_CREDENTIAL_Request *vr; 215 struct GNUNET_CREDENTIAL_Request *vr;
212 size_t mlen = ntohs (vr_msg->header.size) - sizeof(*vr_msg); 216 size_t mlen = ntohs (vr_msg->header.size) - sizeof (*vr_msg);
213 uint32_t d_count = ntohl (vr_msg->d_count); 217 uint32_t d_count = ntohl (vr_msg->d_count);
214 uint32_t c_count = ntohl (vr_msg->c_count); 218 uint32_t c_count = ntohl (vr_msg->c_count);
215 struct GNUNET_CREDENTIAL_Delegation d_chain[d_count]; 219 struct GNUNET_CREDENTIAL_Delegation d_chain[d_count];
216 struct GNUNET_CREDENTIAL_Credential creds[c_count]; 220 //TODO rename creds
221 struct GNUNET_CREDENTIAL_Delegate creds[c_count];
217 GNUNET_CREDENTIAL_CredentialResultProcessor proc; 222 GNUNET_CREDENTIAL_CredentialResultProcessor proc;
218 void *proc_cls; 223 void *proc_cls;
219 224
@@ -233,9 +238,7 @@ handle_result (void *cls,
233 GNUNET_free (vr); 238 GNUNET_free (vr);
234 GNUNET_assert (GNUNET_OK == 239 GNUNET_assert (GNUNET_OK ==
235 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen, 240 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen,
236 (const 241 (const char*) &vr_msg[1],
237 char*) &vr_msg
238 [1],
239 d_count, 242 d_count,
240 d_chain, 243 d_chain,
241 c_count, 244 c_count,
@@ -246,10 +249,8 @@ handle_result (void *cls,
246 0, 249 0,
247 NULL, 250 NULL,
248 0, 251 0,
249 NULL); // TODO 252 NULL); // TODO
250 } 253 } else {
251 else
252 {
253 proc (proc_cls, 254 proc (proc_cls,
254 d_count, 255 d_count,
255 d_chain, 256 d_chain,
@@ -362,7 +363,7 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
362 363
363/** 364/**
364 * Performs attribute collection. 365 * Performs attribute collection.
365 * Collects all credentials of subject to fulfill the 366 * Collects all credentials of subject to fulfill the
366 * attribute, if possible 367 * attribute, if possible
367 * 368 *
368 * @param handle handle to the Credential service 369 * @param handle handle to the Credential service
@@ -375,11 +376,9 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
375 */ 376 */
376struct GNUNET_CREDENTIAL_Request* 377struct GNUNET_CREDENTIAL_Request*
377GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle, 378GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
378 const struct 379 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
379 GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
380 const char *issuer_attribute, 380 const char *issuer_attribute,
381 const struct 381 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key,
382 GNUNET_CRYPTO_EcdsaPrivateKey *subject_key,
383 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 382 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
384 void *proc_cls) 383 void *proc_cls)
385{ 384{
@@ -394,12 +393,12 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
394 return NULL; 393 return NULL;
395 } 394 }
396 395
397 // DEBUG LOG 396 //DEBUG LOG
398 LOG (GNUNET_ERROR_TYPE_DEBUG, 397 LOG (GNUNET_ERROR_TYPE_DEBUG,
399 "Trying to collect `%s' in CREDENTIAL\n", 398 "Trying to collect `%s' in CREDENTIAL\n",
400 issuer_attribute); 399 issuer_attribute);
401 nlen = strlen (issuer_attribute) + 1; 400 nlen = strlen (issuer_attribute) + 1;
402 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*vr)) 401 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr))
403 { 402 {
404 GNUNET_break (0); 403 GNUNET_break (0);
405 return NULL; 404 return NULL;
@@ -414,8 +413,11 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
414 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT); 413 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT);
415 c_msg->id = htonl (vr->r_id); 414 c_msg->id = htonl (vr->r_id);
416 c_msg->subject_key = *subject_key; 415 c_msg->subject_key = *subject_key;
417 c_msg->issuer_key = *issuer_key; 416 c_msg->issuer_key = *issuer_key;
418 c_msg->issuer_attribute_len = htons (strlen (issuer_attribute)); 417 c_msg->issuer_attribute_len = htons(strlen(issuer_attribute));
418 //c_msg->resolution_algo = htons(Backward);
419 c_msg->resolution_algo = htons(Forward);
420
419 GNUNET_memcpy (&c_msg[1], 421 GNUNET_memcpy (&c_msg[1],
420 issuer_attribute, 422 issuer_attribute,
421 strlen (issuer_attribute)); 423 strlen (issuer_attribute));
@@ -449,11 +451,9 @@ struct GNUNET_CREDENTIAL_Request*
449GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle, 451GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
450 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 452 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
451 const char *issuer_attribute, 453 const char *issuer_attribute,
452 const struct 454 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
453 GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
454 uint32_t credential_count, 455 uint32_t credential_count,
455 const struct 456 const struct GNUNET_CREDENTIAL_Delegate *credentials,
456 GNUNET_CREDENTIAL_Credential *credentials,
457 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 457 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
458 void *proc_cls) 458 void *proc_cls)
459{ 459{
@@ -463,7 +463,7 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
463 size_t nlen; 463 size_t nlen;
464 size_t clen; 464 size_t clen;
465 465
466 if ((NULL == issuer_attribute)||(NULL == credentials)) 466 if (NULL == issuer_attribute || NULL == credentials)
467 { 467 {
468 GNUNET_break (0); 468 GNUNET_break (0);
469 return NULL; 469 return NULL;
@@ -472,12 +472,12 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
472 clen = GNUNET_CREDENTIAL_credentials_get_size (credential_count, 472 clen = GNUNET_CREDENTIAL_credentials_get_size (credential_count,
473 credentials); 473 credentials);
474 474
475 // DEBUG LOG 475 //DEBUG LOG
476 LOG (GNUNET_ERROR_TYPE_DEBUG, 476 LOG (GNUNET_ERROR_TYPE_DEBUG,
477 "Trying to verify `%s' in CREDENTIAL\n", 477 "Trying to verify `%s' in CREDENTIAL\n",
478 issuer_attribute); 478 issuer_attribute);
479 nlen = strlen (issuer_attribute) + 1 + clen; 479 nlen = strlen (issuer_attribute) + 1 + clen;
480 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*vr)) 480 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr))
481 { 481 {
482 GNUNET_break (0); 482 GNUNET_break (0);
483 return NULL; 483 return NULL;
@@ -492,16 +492,19 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
492 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY); 492 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY);
493 v_msg->id = htonl (vr->r_id); 493 v_msg->id = htonl (vr->r_id);
494 v_msg->subject_key = *subject_key; 494 v_msg->subject_key = *subject_key;
495 v_msg->c_count = htonl (credential_count); 495 v_msg->c_count = htonl(credential_count);
496 v_msg->issuer_key = *issuer_key; 496 v_msg->issuer_key = *issuer_key;
497 v_msg->issuer_attribute_len = htons (strlen (issuer_attribute)); 497 v_msg->issuer_attribute_len = htons(strlen(issuer_attribute));
498 //v_msg->resolution_algo = htons(Backward);
499 v_msg->resolution_algo = htons(Forward);
500
498 GNUNET_memcpy (&v_msg[1], 501 GNUNET_memcpy (&v_msg[1],
499 issuer_attribute, 502 issuer_attribute,
500 strlen (issuer_attribute)); 503 strlen (issuer_attribute));
501 GNUNET_CREDENTIAL_credentials_serialize (credential_count, 504 GNUNET_CREDENTIAL_credentials_serialize (credential_count,
502 credentials, 505 credentials,
503 clen, 506 clen,
504 ((char*) &v_msg[1]) 507 ((char*)&v_msg[1])
505 + strlen (issuer_attribute) + 1); 508 + strlen (issuer_attribute) + 1);
506 GNUNET_CONTAINER_DLL_insert (handle->request_head, 509 GNUNET_CONTAINER_DLL_insert (handle->request_head,
507 handle->request_tail, 510 handle->request_tail,