summaryrefslogtreecommitdiff
path: root/src/credential/credential_api.c
diff options
context:
space:
mode:
authorAndreas Ebner <a.e.bner@web.de>2019-10-07 11:48:07 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-10-07 12:18:42 +0200
commit1d468ecabd6c2ee5c0eae672292efa0f51bc9e48 (patch)
tree6b527980752f9603945e070c8187bfbb06232b6f /src/credential/credential_api.c
parent5cc45c7ee6a3ac522e5a1f58010d4efdf4fd102f (diff)
downloadgnunet-1d468ecabd6c2ee5c0eae672292efa0f51bc9e48.tar.gz
gnunet-1d468ecabd6c2ee5c0eae672292efa0f51bc9e48.zip
Renamed credential service to abd, replaced all related functions, parameters, etc
Diffstat (limited to 'src/credential/credential_api.c')
-rw-r--r--src/credential/credential_api.c556
1 files changed, 0 insertions, 556 deletions
diff --git a/src/credential/credential_api.c b/src/credential/credential_api.c
deleted file mode 100644
index 7acce7d9e..000000000
--- a/src/credential/credential_api.c
+++ /dev/null
@@ -1,556 +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 * @file credential/credential_api.c
22 * @brief library to access the CREDENTIAL service
23 * @author Martin Schanzenbach
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_constants.h"
28#include "gnunet_arm_service.h"
29#include "gnunet_hello_lib.h"
30#include "gnunet_protocols.h"
31#include "gnunet_signatures.h"
32#include "credential.h"
33#include "credential_serialization.h"
34#include "gnunet_credential_service.h"
35#include "gnunet_identity_service.h"
36
37
38#define LOG(kind, ...) GNUNET_log_from (kind, "credential-api", __VA_ARGS__)
39
40/**
41 * Handle to a verify request
42 */
43struct GNUNET_CREDENTIAL_Request
44{
45
46 /**
47 * DLL
48 */
49 struct GNUNET_CREDENTIAL_Request *next;
50
51 /**
52 * DLL
53 */
54 struct GNUNET_CREDENTIAL_Request *prev;
55
56 /**
57 * handle to credential service
58 */
59 struct GNUNET_CREDENTIAL_Handle *credential_handle;
60
61 /**
62 * processor to call on verify result
63 */
64 GNUNET_CREDENTIAL_CredentialResultProcessor verify_proc;
65
66 /**
67 * @e verify_proc closure
68 */
69 void *proc_cls;
70
71 /**
72 * processor to call on intermediate result
73 */
74 GNUNET_CREDENTIAL_IntermediateResultProcessor int_proc;
75
76 /**
77 * @e verify_proc2 closure
78 */
79 void *proc2_cls;
80
81 /**
82 * Envelope with the message for this queue entry.
83 */
84 struct GNUNET_MQ_Envelope *env;
85
86 /**
87 * request id
88 */
89 uint32_t r_id;
90};
91
92
93/**
94 * Connection to the CREDENTIAL service.
95 */
96struct GNUNET_CREDENTIAL_Handle
97{
98
99 /**
100 * Configuration to use.
101 */
102 const struct GNUNET_CONFIGURATION_Handle *cfg;
103
104 /**
105 * Connection to service (if available).
106 */
107 struct GNUNET_MQ_Handle *mq;
108
109 /**
110 * Head of linked list of active verify requests.
111 */
112 struct GNUNET_CREDENTIAL_Request *request_head;
113
114 /**
115 * Tail of linked list of active verify requests.
116 */
117 struct GNUNET_CREDENTIAL_Request *request_tail;
118
119 /**
120 * Reconnect task
121 */
122 struct GNUNET_SCHEDULER_Task *reconnect_task;
123
124 /**
125 * How long do we wait until we try to reconnect?
126 */
127 struct GNUNET_TIME_Relative reconnect_backoff;
128
129 /**
130 * Request Id generator. Incremented by one for each request.
131 */
132 uint32_t r_id_gen;
133};
134
135
136/**
137 * Reconnect to CREDENTIAL service.
138 *
139 * @param handle the handle to the CREDENTIAL service
140 */
141static void
142reconnect (struct GNUNET_CREDENTIAL_Handle *handle);
143
144
145/**
146 * Reconnect to CREDENTIAL
147 *
148 * @param cls the handle
149 */
150static void
151reconnect_task (void *cls)
152{
153 struct GNUNET_CREDENTIAL_Handle *handle = cls;
154
155 handle->reconnect_task = NULL;
156 reconnect (handle);
157}
158
159
160/**
161 * Disconnect from service and then reconnect.
162 *
163 * @param handle our handle
164 */
165static void
166force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
167{
168 GNUNET_MQ_destroy (handle->mq);
169 handle->mq = NULL;
170 handle->reconnect_backoff =
171 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
172 handle->reconnect_task =
173 GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
174 &reconnect_task,
175 handle);
176}
177
178
179/**
180 * Generic error handler, called with the appropriate error code and
181 * the same closure specified at the creation of the message queue.
182 * Not every message queue implementation supports an error handler.
183 *
184 * @param cls closure with the `struct GNUNET_CREDENTIAL_Handle *`
185 * @param error error code
186 */
187static void
188mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
189{
190 struct GNUNET_CREDENTIAL_Handle *handle = cls;
191
192 force_reconnect (handle);
193}
194
195/**
196 * Check validity of message received from the CREDENTIAL service
197 *
198 * @param cls the `struct GNUNET_CREDENTIAL_Handle *`
199 * @param vr_msg the incoming message
200 */
201static int
202check_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
203{
204 //TODO
205 return GNUNET_OK;
206}
207
208
209/**
210 * Handler for messages received from the CREDENTIAL service
211 *
212 * @param cls the `struct GNUNET_CREDENTIAL_Handle *`
213 * @param vr_msg the incoming message
214 */
215static void
216handle_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
217{
218 struct GNUNET_CREDENTIAL_Handle *handle = cls;
219 uint32_t r_id = ntohl (vr_msg->id);
220 struct GNUNET_CREDENTIAL_Request *vr;
221 size_t mlen = ntohs (vr_msg->header.size) - sizeof (*vr_msg);
222 uint32_t d_count = ntohl (vr_msg->d_count);
223 uint32_t c_count = ntohl (vr_msg->c_count);
224 struct GNUNET_CREDENTIAL_Delegation d_chain[d_count];
225 struct GNUNET_CREDENTIAL_Delegate dels[c_count];
226 GNUNET_CREDENTIAL_CredentialResultProcessor proc;
227 void *proc_cls;
228
229 LOG (GNUNET_ERROR_TYPE_DEBUG,
230 "Received verify reply from CREDENTIAL service\n");
231 for (vr = handle->request_head; NULL != vr; vr = vr->next)
232 if (vr->r_id == r_id)
233 break;
234 if (NULL == vr)
235 return;
236 proc = vr->verify_proc;
237 proc_cls = vr->proc_cls;
238 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, vr);
239 GNUNET_MQ_discard (vr->env);
240 GNUNET_free (vr);
241 GNUNET_assert (
242 GNUNET_OK ==
243 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen,
244 (const char *) &vr_msg[1],
245 d_count,
246 d_chain,
247 c_count,
248 dels));
249 if (GNUNET_NO == ntohl (vr_msg->del_found))
250 {
251 proc (proc_cls, 0, NULL, 0,
252 NULL);
253 }
254 else
255 {
256 proc (proc_cls, d_count, d_chain, c_count, dels);
257 }
258}
259
260static int
261check_intermediate (void *cls, const struct DelegationChainIntermediateMessage *vr_msg)
262{
263 //TODO
264 return GNUNET_OK;
265}
266
267static void
268handle_intermediate (void *cls, const struct DelegationChainIntermediateMessage *vr_msg)
269{
270 struct GNUNET_CREDENTIAL_Handle *handle = cls;
271 uint32_t r_id = ntohl (vr_msg->id);
272 uint32_t size = ntohl (vr_msg->size);
273 bool is_bw = ntohs(vr_msg->is_bw);
274 struct GNUNET_CREDENTIAL_Request *vr;
275 GNUNET_CREDENTIAL_IntermediateResultProcessor proc;
276 void *proc_cls;
277 struct GNUNET_CREDENTIAL_Delegation *dd;
278
279
280 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received intermediate reply from CREDENTIAL service\n");
281
282 for (vr = handle->request_head; NULL != vr; vr = vr->next)
283 if (vr->r_id == r_id)
284 break;
285 if (NULL == vr)
286 return;
287
288 proc = vr->int_proc;
289 proc_cls = vr->proc2_cls;
290
291 dd = GNUNET_new (struct GNUNET_CREDENTIAL_Delegation);
292 GNUNET_assert (
293 GNUNET_OK ==
294 GNUNET_CREDENTIAL_delegation_chain_deserialize (size,
295 (const char *) &vr_msg[1],
296 1,
297 dd,
298 0,
299 NULL));
300 proc (proc_cls, dd, is_bw);
301}
302
303
304
305/**
306 * Reconnect to CREDENTIAL service.
307 *
308 * @param handle the handle to the CREDENTIAL service
309 */
310static void
311reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
312{
313 struct GNUNET_MQ_MessageHandler handlers[] =
314 {GNUNET_MQ_hd_var_size (result,
315 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT,
316 struct DelegationChainResultMessage,
317 handle),
318 GNUNET_MQ_hd_var_size (result,
319 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT,
320 struct DelegationChainResultMessage,
321 handle),
322 GNUNET_MQ_hd_var_size (intermediate,
323 GNUNET_MESSAGE_TYPE_CREDENTIAL_INTERMEDIATE_RESULT,
324 struct DelegationChainIntermediateMessage,
325 handle),
326 GNUNET_MQ_handler_end ()};
327 struct GNUNET_CREDENTIAL_Request *vr;
328
329 GNUNET_assert (NULL == handle->mq);
330 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to CREDENTIAL\n");
331 handle->mq = GNUNET_CLIENT_connect (handle->cfg,
332 "credential",
333 handlers,
334 &mq_error_handler,
335 handle);
336 if (NULL == handle->mq)
337 return;
338 for (vr = handle->request_head; NULL != vr; vr = vr->next)
339 GNUNET_MQ_send_copy (handle->mq, vr->env);
340}
341
342
343/**
344 * Initialize the connection with the CREDENTIAL service.
345 *
346 * @param cfg configuration to use
347 * @return handle to the CREDENTIAL service, or NULL on error
348 */
349struct GNUNET_CREDENTIAL_Handle *
350GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
351{
352 struct GNUNET_CREDENTIAL_Handle *handle;
353
354 handle = GNUNET_new (struct GNUNET_CREDENTIAL_Handle);
355 handle->cfg = cfg;
356 reconnect (handle);
357 if (NULL == handle->mq)
358 {
359 GNUNET_free (handle);
360 return NULL;
361 }
362 return handle;
363}
364
365
366/**
367 * Shutdown connection with the CREDENTIAL service.
368 *
369 * @param handle handle of the CREDENTIAL connection to stop
370 */
371void
372GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle)
373{
374 if (NULL != handle->mq)
375 {
376 GNUNET_MQ_destroy (handle->mq);
377 handle->mq = NULL;
378 }
379 if (NULL != handle->reconnect_task)
380 {
381 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
382 handle->reconnect_task = NULL;
383 }
384 GNUNET_assert (NULL == handle->request_head);
385 GNUNET_free (handle);
386}
387
388
389/**
390 * Cancel pending verify request
391 *
392 * @param lr the verify request to cancel
393 */
394void
395GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
396{
397 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle;
398
399 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, lr);
400 GNUNET_MQ_discard (lr->env);
401 GNUNET_free (lr);
402}
403
404
405/**
406 * Performs attribute collection.
407 * Collects all credentials of subject to fulfill the
408 * attribute, if possible
409 *
410 * @param handle handle to the Credential service
411 * @param issuer_key the issuer public key
412 * @param issuer_attribute the issuer attribute
413 * @param subject_key the subject public key
414 * @param proc function to call on result
415 * @param proc_cls closure for processor
416 * @return handle to the queued request
417 */
418struct GNUNET_CREDENTIAL_Request *
419GNUNET_CREDENTIAL_collect (
420 struct GNUNET_CREDENTIAL_Handle *handle,
421 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
422 const char *issuer_attribute,
423 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key,
424 enum GNUNET_CREDENTIAL_AlgoDirectionFlags direction,
425 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
426 void *proc_cls,
427 GNUNET_CREDENTIAL_IntermediateResultProcessor proc2,
428 void *proc2_cls)
429{
430 /* IPC to shorten credential names, return shorten_handle */
431 struct CollectMessage *c_msg;
432 struct GNUNET_CREDENTIAL_Request *vr;
433 size_t nlen;
434
435 if (NULL == issuer_attribute)
436 {
437 GNUNET_break (0);
438 return NULL;
439 }
440
441 //DEBUG LOG
442 LOG (GNUNET_ERROR_TYPE_DEBUG,
443 "Trying to collect `%s' in CREDENTIAL\n",
444 issuer_attribute);
445 nlen = strlen (issuer_attribute) + 1;
446 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr))
447 {
448 GNUNET_break (0);
449 return NULL;
450 }
451 vr = GNUNET_new (struct GNUNET_CREDENTIAL_Request);
452 vr->credential_handle = handle;
453 vr->verify_proc = proc;
454 vr->proc_cls = proc_cls;
455 vr->int_proc = proc2;
456 vr->proc2_cls = proc2_cls;
457 vr->r_id = handle->r_id_gen++;
458 vr->env =
459 GNUNET_MQ_msg_extra (c_msg, nlen, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT);
460 c_msg->id = htonl (vr->r_id);
461 c_msg->subject_key = *subject_key;
462 c_msg->issuer_key = *issuer_key;
463 c_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
464 c_msg->resolution_algo = htons (direction);
465
466 GNUNET_memcpy (&c_msg[1], issuer_attribute, strlen (issuer_attribute));
467 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
468 if (NULL != handle->mq)
469 GNUNET_MQ_send_copy (handle->mq, vr->env);
470 return vr;
471}
472/**
473 * Performs attribute verification.
474 * Checks if there is a delegation chain from
475 * attribute ``issuer_attribute'' issued by the issuer
476 * with public key ``issuer_key'' maps to the attribute
477 * ``subject_attribute'' claimed by the subject with key
478 * ``subject_key''
479 *
480 * @param handle handle to the Credential service
481 * @param issuer_key the issuer public key
482 * @param issuer_attribute the issuer attribute
483 * @param subject_key the subject public key
484 * @param delegate_count number of delegates provided
485 * @param delegates subject delegates
486 * @param proc function to call on result
487 * @param proc_cls closure for processor
488 * @return handle to the queued request
489 */
490struct GNUNET_CREDENTIAL_Request *
491GNUNET_CREDENTIAL_verify (
492 struct GNUNET_CREDENTIAL_Handle *handle,
493 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
494 const char *issuer_attribute,
495 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
496 uint32_t delegate_count,
497 const struct GNUNET_CREDENTIAL_Delegate *delegates,
498 enum GNUNET_CREDENTIAL_AlgoDirectionFlags direction,
499 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
500 void *proc_cls,
501 GNUNET_CREDENTIAL_IntermediateResultProcessor proc2,
502 void *proc2_cls)
503{
504 /* IPC to shorten credential names, return shorten_handle */
505 struct VerifyMessage *v_msg;
506 struct GNUNET_CREDENTIAL_Request *vr;
507 size_t nlen;
508 size_t clen;
509
510 if (NULL == issuer_attribute || NULL == delegates)
511 {
512 GNUNET_break (0);
513 return NULL;
514 }
515
516 clen = GNUNET_CREDENTIAL_delegates_get_size (delegate_count, delegates);
517
518 //DEBUG LOG
519 LOG (GNUNET_ERROR_TYPE_DEBUG,
520 "Trying to verify `%s' in CREDENTIAL\n",
521 issuer_attribute);
522 nlen = strlen (issuer_attribute) + 1 + clen;
523 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr))
524 {
525 GNUNET_break (0);
526 return NULL;
527 }
528 vr = GNUNET_new (struct GNUNET_CREDENTIAL_Request);
529 vr->credential_handle = handle;
530 vr->verify_proc = proc;
531 vr->proc_cls = proc_cls;
532 vr->int_proc = proc2;
533 vr->proc2_cls = proc2_cls;
534 vr->r_id = handle->r_id_gen++;
535 vr->env =
536 GNUNET_MQ_msg_extra (v_msg, nlen, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY);
537 v_msg->id = htonl (vr->r_id);
538 v_msg->subject_key = *subject_key;
539 v_msg->d_count = htonl (delegate_count);
540 v_msg->issuer_key = *issuer_key;
541 v_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
542 v_msg->resolution_algo = htons (direction);
543
544 GNUNET_memcpy (&v_msg[1], issuer_attribute, strlen (issuer_attribute));
545 GNUNET_CREDENTIAL_delegates_serialize (delegate_count,
546 delegates,
547 clen,
548 ((char *) &v_msg[1]) +
549 strlen (issuer_attribute) + 1);
550 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
551 if (NULL != handle->mq)
552 GNUNET_MQ_send_copy (handle->mq, vr->env);
553 return vr;
554}
555
556/* end of credential_api.c */