GNUnet 0.22.0
abd_api.c
Go to the documentation of this file.
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*/
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_constants.h"
28#include "gnunet_arm_service.h"
29#include "gnunet_protocols.h"
30#include "gnunet_signatures.h"
31#include "abd.h"
32#include "abd_serialization.h"
33#include "gnunet_abd_service.h"
35
36
37#define LOG(kind, ...) GNUNET_log_from (kind, "abd-api", __VA_ARGS__)
38
43{
44
49
54
59
64
68 void *proc_cls;
69
74
78 void *proc2_cls;
79
84
88 uint32_t r_id;
89};
90
91
96{
97
102
107
112
117
122
127
131 uint32_t r_id_gen;
132};
133
134
140static void
142
143
149static void
150reconnect_task (void *cls)
151{
152 struct GNUNET_ABD_Handle *handle = cls;
153
154 handle->reconnect_task = NULL;
156}
157
158
164static void
166{
168 handle->mq = NULL;
169 handle->reconnect_backoff =
170 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
171 handle->reconnect_task =
172 GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
174 handle);
175}
176
177
186static void
187mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
188{
189 struct GNUNET_ABD_Handle *handle = cls;
190
192}
193
194
201static int
202check_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
203{
204 // TODO
205 return GNUNET_OK;
206}
207
208
215static void
216handle_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
217{
218 struct GNUNET_ABD_Handle *handle = cls;
219 uint32_t r_id = ntohl (vr_msg->id);
220 struct GNUNET_ABD_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_ABD_Delegation d_chain[d_count];
225 struct GNUNET_ABD_Delegate dels[c_count];
227 void *proc_cls;
228
230 "Received verify reply from ABD 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);
240 GNUNET_free (vr);
242 GNUNET_OK ==
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
260
261static int
262check_intermediate (void *cls, const struct
264{
265 // TODO
266 return GNUNET_OK;
267}
268
269
270static void
271handle_intermediate (void *cls, const struct
273{
274 struct GNUNET_ABD_Handle *handle = cls;
275 uint32_t r_id = ntohl (vr_msg->id);
276 uint32_t size = ntohl (vr_msg->size);
277 bool is_bw = ntohs (vr_msg->is_bw);
278 struct GNUNET_ABD_Request *vr;
280 void *proc_cls;
281 struct GNUNET_ABD_Delegation *dd;
282
283
285 "Received intermediate reply from ABD service\n");
286
287 for (vr = handle->request_head; NULL != vr; vr = vr->next)
288 if (vr->r_id == r_id)
289 break;
290 if (NULL == vr)
291 return;
292
293 proc = vr->int_proc;
294 proc_cls = vr->proc2_cls;
295
296 dd = GNUNET_new (struct GNUNET_ABD_Delegation);
298 GNUNET_OK ==
300 (const char *) &vr_msg[1],
301 1,
302 dd,
303 0,
304 NULL));
305 proc (proc_cls, dd, is_bw);
306}
307
308
314static void
316{
321 handle),
325 handle),
326 GNUNET_MQ_hd_var_size (intermediate,
329 handle),
331 struct GNUNET_ABD_Request *vr;
332
333 GNUNET_assert (NULL == handle->mq);
334 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to ABD\n");
336 "abd",
337 handlers,
339 handle);
340 if (NULL == handle->mq)
341 return;
342 for (vr = handle->request_head; NULL != vr; vr = vr->next)
344}
345
346
353struct GNUNET_ABD_Handle *
355{
357
359 handle->cfg = cfg;
361 if (NULL == handle->mq)
362 {
364 return NULL;
365 }
366 return handle;
367}
368
369
375void
377{
378 if (NULL != handle->mq)
379 {
381 handle->mq = NULL;
382 }
383 if (NULL != handle->reconnect_task)
384 {
385 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
386 handle->reconnect_task = NULL;
387 }
388 GNUNET_assert (NULL == handle->request_head);
390}
391
392
398void
400{
401 struct GNUNET_ABD_Handle *handle = lr->abd_handle;
402
403 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, lr);
404 GNUNET_MQ_discard (lr->env);
405 GNUNET_free (lr);
406}
407
408
422struct GNUNET_ABD_Request *
426 const char *issuer_attribute,
427 const struct GNUNET_CRYPTO_PrivateKey *subject_key,
430 void *proc_cls,
432 void *proc2_cls)
433{
434 /* IPC to shorten abd names, return shorten_handle */
435 struct CollectMessage *c_msg;
436 struct GNUNET_ABD_Request *vr;
437 size_t nlen;
438
439 if (NULL == issuer_attribute)
440 {
441 GNUNET_break (0);
442 return NULL;
443 }
444
445 // DEBUG LOG
447 "Trying to collect `%s' in ABD\n",
448 issuer_attribute);
449 nlen = strlen (issuer_attribute) + 1;
450 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr))
451 {
452 GNUNET_break (0);
453 return NULL;
454 }
455 vr = GNUNET_new (struct GNUNET_ABD_Request);
456 vr->abd_handle = handle;
457 vr->verify_proc = proc;
458 vr->proc_cls = proc_cls;
459 vr->int_proc = proc2;
460 vr->proc2_cls = proc2_cls;
461 vr->r_id = handle->r_id_gen++;
462 vr->env =
464 c_msg->id = htonl (vr->r_id);
465 c_msg->subject_key = *subject_key;
466 c_msg->issuer_key = *issuer_key;
467 c_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
468 c_msg->resolution_algo = htons (direction);
469
470 GNUNET_memcpy (&c_msg[1], issuer_attribute, strlen (issuer_attribute));
471 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
472 if (NULL != handle->mq)
474 return vr;
475}
476
477
496struct GNUNET_ABD_Request *
500 const char *issuer_attribute,
501 const struct GNUNET_CRYPTO_PublicKey *subject_key,
502 uint32_t delegate_count,
503 const struct GNUNET_ABD_Delegate *delegates,
506 void *proc_cls,
508 void *proc2_cls)
509{
510 /* IPC to shorten abd names, return shorten_handle */
511 struct VerifyMessage *v_msg;
512 struct GNUNET_ABD_Request *vr;
513 size_t nlen;
514 size_t clen;
515
516 if ((NULL == issuer_attribute) || (NULL == delegates))
517 {
518 GNUNET_break (0);
519 return NULL;
520 }
521
522 clen = GNUNET_ABD_delegates_get_size (delegate_count, delegates);
523
524 // DEBUG LOG
526 "Trying to verify `%s' in ABD\n",
527 issuer_attribute);
528 nlen = strlen (issuer_attribute) + 1 + clen;
529 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr))
530 {
531 GNUNET_break (0);
532 return NULL;
533 }
534 vr = GNUNET_new (struct GNUNET_ABD_Request);
535 vr->abd_handle = handle;
536 vr->verify_proc = proc;
537 vr->proc_cls = proc_cls;
538 vr->int_proc = proc2;
539 vr->proc2_cls = proc2_cls;
540 vr->r_id = handle->r_id_gen++;
541 vr->env =
543 v_msg->id = htonl (vr->r_id);
544 v_msg->subject_key = *subject_key;
545 v_msg->d_count = htonl (delegate_count);
546 v_msg->issuer_key = *issuer_key;
547 v_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
548 v_msg->resolution_algo = htons (direction);
549
550 GNUNET_memcpy (&v_msg[1], issuer_attribute, strlen (issuer_attribute));
551 GNUNET_ABD_delegates_serialize (delegate_count,
552 delegates,
553 clen,
554 ((char *) &v_msg[1])
555 + strlen (issuer_attribute) + 1);
556 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
557 if (NULL != handle->mq)
559 return vr;
560}
561
562
563/* end of abd_api.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
IPC messages between ABD API and ABD service.
static void handle_intermediate(void *cls, const struct DelegationChainIntermediateMessage *vr_msg)
Definition: abd_api.c:271
static void handle_result(void *cls, const struct DelegationChainResultMessage *vr_msg)
Handler for messages received from the ABD service.
Definition: abd_api.c:216
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: abd_api.c:187
static void reconnect(struct GNUNET_ABD_Handle *handle)
Reconnect to ABD service.
Definition: abd_api.c:315
static void force_reconnect(struct GNUNET_ABD_Handle *handle)
Disconnect from service and then reconnect.
Definition: abd_api.c:165
static int check_intermediate(void *cls, const struct DelegationChainIntermediateMessage *vr_msg)
Definition: abd_api.c:262
#define LOG(kind,...)
Definition: abd_api.c:37
static int check_result(void *cls, const struct DelegationChainResultMessage *vr_msg)
Check validity of message received from the ABD service.
Definition: abd_api.c:202
static void reconnect_task(void *cls)
Reconnect to ABD.
Definition: abd_api.c:150
ssize_t GNUNET_ABD_delegates_serialize(unsigned int c_count, const struct GNUNET_ABD_Delegate *cd, size_t dest_size, char *dest)
Serizalize the given abds.
size_t GNUNET_ABD_delegates_get_size(unsigned int c_count, const struct GNUNET_ABD_Delegate *cd)
Calculate how many bytes we will need to serialize the abds.
int GNUNET_ABD_delegation_chain_deserialize(size_t len, const char *src, unsigned int d_count, struct GNUNET_ABD_Delegation *dd, unsigned int c_count, struct GNUNET_ABD_Delegate *cd)
Deserialize the given destination.
API to serialize and deserialize delegation chains and abds.
static char * issuer_key
Issuer pubkey string.
Definition: gnunet-abd.c:113
enum GNUNET_ABD_AlgoDirectionFlags direction
API enum, filled and passed for collect/verify.
Definition: gnunet-abd.c:173
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_GNS_LookupWithTldRequest * lr
Handle to lookup request.
Definition: gnunet-gns.c:98
static int result
Global testing status.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
API to the Credential service.
Identity service; implements identity management for GNUnet.
Constants for network protocols.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
void(* GNUNET_ABD_IntermediateResultProcessor)(void *cls, struct GNUNET_ABD_Delegation *delegation, bool is_bw)
GNUNET_ABD_AlgoDirectionFlags
struct GNUNET_ABD_Handle * GNUNET_ABD_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the ABD service.
Definition: abd_api.c:354
struct GNUNET_ABD_Request * GNUNET_ABD_verify(struct GNUNET_ABD_Handle *handle, const struct GNUNET_CRYPTO_PublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_PublicKey *subject_key, uint32_t delegate_count, const struct GNUNET_ABD_Delegate *delegates, enum GNUNET_ABD_AlgoDirectionFlags direction, GNUNET_ABD_CredentialResultProcessor proc, void *proc_cls, GNUNET_ABD_IntermediateResultProcessor proc2, void *proc2_cls)
Performs attribute verification.
Definition: abd_api.c:497
void GNUNET_ABD_disconnect(struct GNUNET_ABD_Handle *handle)
Shutdown connection with the ABD service.
Definition: abd_api.c:376
void GNUNET_ABD_request_cancel(struct GNUNET_ABD_Request *lr)
Cancel pending verify request.
Definition: abd_api.c:399
struct GNUNET_ABD_Request * GNUNET_ABD_collect(struct GNUNET_ABD_Handle *handle, const struct GNUNET_CRYPTO_PublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_PrivateKey *subject_key, enum GNUNET_ABD_AlgoDirectionFlags direction, GNUNET_ABD_CredentialResultProcessor proc, void *proc_cls, GNUNET_ABD_IntermediateResultProcessor proc2, void *proc2_cls)
Performs attribute collection.
Definition: abd_api.c:423
void(* GNUNET_ABD_CredentialResultProcessor)(void *cls, unsigned int d_count, struct GNUNET_ABD_Delegation *delegation_chain, unsigned int c_count, struct GNUNET_ABD_Delegate *delegte)
Iterator called on obtained result for an attribute verification.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send_copy(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MQ_Envelope *ev)
Send a copy of a message with the given message queue.
Definition: mq.c:384
GNUNET_MQ_Error
Error codes for the queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
#define GNUNET_MESSAGE_TYPE_ABD_COLLECT_RESULT
#define GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT
#define GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT
#define GNUNET_MESSAGE_TYPE_ABD_COLLECT
#define GNUNET_MESSAGE_TYPE_ABD_VERIFY
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1276
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static unsigned int size
Size of the "table".
Definition: peer.c:68
Message from client to Credential service to collect credentials.
Definition: abd.h:36
struct GNUNET_CRYPTO_PublicKey issuer_key
Trust anchor.
Definition: abd.h:50
uint16_t resolution_algo
Direction of the resolution algo.
Definition: abd.h:60
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: abd.h:55
struct GNUNET_CRYPTO_PrivateKey subject_key
Subject public key.
Definition: abd.h:45
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:65
Message from ABD service to client: new results.
Definition: abd.h:152
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:161
Message from ABD service to client: new results.
Definition: abd.h:119
uint32_t del_found
Indicates if credential has been found at all.
Definition: abd.h:133
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT.
Definition: abd.h:123
uint32_t d_count
The number of delegations in the response.
Definition: abd.h:138
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:128
uint32_t c_count
The number of credentials in the response.
Definition: abd.h:143
Connection to the ABD service.
Definition: abd_api.c:96
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
Definition: abd_api.c:121
struct GNUNET_ABD_Request * request_tail
Tail of linked list of active verify requests.
Definition: abd_api.c:116
struct GNUNET_ABD_Request * request_head
Head of linked list of active verify requests.
Definition: abd_api.c:111
struct GNUNET_MQ_Handle * mq
Connection to service (if available).
Definition: abd_api.c:106
uint32_t r_id_gen
Request Id generator.
Definition: abd_api.c:131
struct GNUNET_TIME_Relative reconnect_backoff
How long do we wait until we try to reconnect?
Definition: abd_api.c:126
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: abd_api.c:101
Handle to a verify request.
Definition: abd_api.c:43
void * proc_cls
verify_proc closure
Definition: abd_api.c:68
GNUNET_ABD_CredentialResultProcessor verify_proc
processor to call on verify result
Definition: abd_api.c:63
struct GNUNET_ABD_Handle * abd_handle
handle to abd service
Definition: abd_api.c:58
GNUNET_ABD_IntermediateResultProcessor int_proc
processor to call on intermediate result
Definition: abd_api.c:73
struct GNUNET_ABD_Request * next
DLL.
Definition: abd_api.c:48
void * proc2_cls
verify_proc2 closure
Definition: abd_api.c:78
struct GNUNET_MQ_Envelope * env
Envelope with the message for this queue entry.
Definition: abd_api.c:83
uint32_t r_id
request id
Definition: abd_api.c:88
struct GNUNET_ABD_Request * prev
DLL.
Definition: abd_api.c:53
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Entry in list of pending tasks.
Definition: scheduler.c:135
Time for relative time used by GNUnet, in microseconds.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: vpn_api.c:39
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44
Message from client to Credential service to verify attributes.
Definition: abd.h:75
uint16_t resolution_algo
Direction of the resolution algo.
Definition: abd.h:104
struct GNUNET_CRYPTO_PublicKey subject_key
Subject public key.
Definition: abd.h:84
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:109
uint32_t d_count
Number of delegates.
Definition: abd.h:94
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: abd.h:99
struct GNUNET_CRYPTO_PublicKey issuer_key
Trust anchor.
Definition: abd.h:89