aboutsummaryrefslogtreecommitdiff
path: root/src/abd
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 14:46:22 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 14:46:22 +0200
commit76299f0b66a3f8ce86df90171b450da6b9cd9b7c (patch)
tree381f49fb3208a4b9ae19781372ffd6c492eae19c /src/abd
parent2f93ff3b6d3524e1e6dc23f70966fbae3ca9d3af (diff)
downloadgnunet-76299f0b66a3f8ce86df90171b450da6b9cd9b7c.tar.gz
gnunet-76299f0b66a3f8ce86df90171b450da6b9cd9b7c.zip
BUILD: Move experimental components to contrib
Diffstat (limited to 'src/abd')
-rw-r--r--src/abd/.gitignore2
-rw-r--r--src/abd/Makefile.am106
-rw-r--r--src/abd/abd.conf.in5
-rw-r--r--src/abd/abd.h251
-rw-r--r--src/abd/abd_api.c563
-rw-r--r--src/abd/abd_serialization.c516
-rw-r--r--src/abd/abd_serialization.h167
-rw-r--r--src/abd/delegate_misc.c279
-rw-r--r--src/abd/delegate_misc.h36
-rw-r--r--src/abd/gnunet-abd.c1108
-rw-r--r--src/abd/gnunet-service-abd.c1778
-rw-r--r--src/abd/plugin_gnsrecord_abd.c357
-rwxr-xr-xsrc/abd/test_abd_bi_and.sh98
-rwxr-xr-xsrc/abd/test_abd_bi_and2.sh94
-rwxr-xr-xsrc/abd/test_abd_bi_and3.sh96
-rwxr-xr-xsrc/abd/test_abd_bi_and4.sh83
-rwxr-xr-xsrc/abd/test_abd_bi_bw.sh87
-rwxr-xr-xsrc/abd/test_abd_bi_bw_link.sh92
-rwxr-xr-xsrc/abd/test_abd_bi_bw_link2.sh93
-rwxr-xr-xsrc/abd/test_abd_bi_fw.sh92
-rw-r--r--src/abd/test_abd_defaults.conf24
-rwxr-xr-xsrc/abd/test_abd_issue.sh46
-rw-r--r--src/abd/test_abd_lookup.conf28
-rwxr-xr-xsrc/abd/test_abd_own.sh139
-rwxr-xr-xsrc/abd/test_abd_verify.sh87
-rwxr-xr-xsrc/abd/test_abd_verify_and.sh86
-rwxr-xr-xsrc/abd/test_abd_verify_simple.sh56
27 files changed, 0 insertions, 6369 deletions
diff --git a/src/abd/.gitignore b/src/abd/.gitignore
deleted file mode 100644
index ee1eb7837..000000000
--- a/src/abd/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
1gnunet-abd
2gnunet-service-abd
diff --git a/src/abd/Makefile.am b/src/abd/Makefile.am
deleted file mode 100644
index 6fa2dc848..000000000
--- a/src/abd/Makefile.am
+++ /dev/null
@@ -1,106 +0,0 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4EXTRA_DIST = \
5 test_abd_defaults.conf \
6 test_abd_lookup.conf \
7 $(check_SCRIPTS) \
8 $(pkgdata_DATA)
9
10
11if USE_COVERAGE
12 AM_CFLAGS = --coverage -O0
13endif
14
15pkgcfgdir = $(pkgdatadir)/config.d/
16
17libexecdir= $(pkglibdir)/libexec/
18
19plugindir = $(libdir)/gnunet
20
21pkgcfg_DATA = \
22 abd.conf
23
24
25# /usr/lib - compiles a layer which can be used to be communicagte with the service
26lib_LTLIBRARIES = \
27 libgnunetabd.la
28
29# /usr/lib/gnunet/libexec - Business logic . Separate process
30libexec_PROGRAMS = \
31 gnunet-service-abd
32
33bin_PROGRAMS = \
34 gnunet-abd
35
36plugin_LTLIBRARIES = \
37 libgnunet_plugin_gnsrecord_abd.la
38
39
40gnunet_abd_SOURCES = \
41 gnunet-abd.c
42gnunet_abd_LDADD = \
43 libgnunetabd.la \
44 $(top_builddir)/src/lib/util/libgnunetutil.la \
45 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \
46 $(top_builddir)/src/identity/libgnunetidentity.la \
47 $(top_builddir)/src/namestore/libgnunetnamestore.la \
48 $(GN_LIBINTL)
49
50
51libgnunet_plugin_gnsrecord_abd_la_SOURCES = \
52 plugin_gnsrecord_abd.c
53libgnunet_plugin_gnsrecord_abd_la_LIBADD = \
54 libgnunetabd.la \
55 $(top_builddir)/src/lib/util/libgnunetutil.la \
56 $(top_builddir)/src/identity/libgnunetidentity.la \
57 $(LTLIBINTL)
58libgnunet_plugin_gnsrecord_abd_la_LDFLAGS = \
59 $(GN_PLUGIN_LDFLAGS)
60
61
62
63gnunet_service_abd_SOURCES = \
64 gnunet-service-abd.c
65gnunet_service_abd_LDADD = \
66 libgnunetabd.la \
67 $(top_builddir)/src/lib/util/libgnunetutil.la \
68 $(top_builddir)/src/gns/libgnunetgns.la \
69 $(top_builddir)/src/namestore/libgnunetnamestore.la \
70 $(top_builddir)/src/identity/libgnunetidentity.la \
71 $(top_builddir)/src/statistics/libgnunetstatistics.la \
72 $(GN_LIBINTL)
73
74
75libgnunetabd_la_SOURCES = \
76 abd_api.c abd.h\
77 abd_serialization.c \
78 abd_serialization.h \
79 delegate_misc.c \
80 delegate_misc.h
81libgnunetabd_la_LIBADD = \
82 $(top_builddir)/src/lib/util/libgnunetutil.la \
83 $(top_builddir)/src/identity/libgnunetidentity.la \
84 $(XLIB)
85libgnunetabd_la_LDFLAGS = \
86 $(GN_LIB_LDFLAGS)
87
88
89
90check_SCRIPTS = \
91 test_abd_issue.sh
92 # test_abd_verify_simple.sh \
93 # test_abd_verify.sh \
94 # test_abd_verify_and.sh
95
96if ENABLE_TEST_RUN
97if HAVE_SQLITE
98 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;
99 TESTS = $(check_SCRIPTS)
100endif
101endif
102
103
104
105
106
diff --git a/src/abd/abd.conf.in b/src/abd/abd.conf.in
deleted file mode 100644
index 7baf95fc8..000000000
--- a/src/abd/abd.conf.in
+++ /dev/null
@@ -1,5 +0,0 @@
1[abd]
2BINARY = gnunet-service-abd
3UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-abd.sock
4RUN_PER_USER = YES
5OPTIONS = -L DEBUG
diff --git a/src/abd/abd.h b/src/abd/abd.h
deleted file mode 100644
index 26b8e222e..000000000
--- a/src/abd/abd.h
+++ /dev/null
@@ -1,251 +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 abd/abd.h
22 * @brief IPC messages between ABD API and ABD service
23 * @author Martin Schanzenbach
24 */
25#ifndef ABD_H
26#define ABD_H
27
28#include "gnunet_abd_service.h"
29
30GNUNET_NETWORK_STRUCT_BEGIN
31
32/**
33 * Message from client to Credential service to collect credentials.
34 */
35struct CollectMessage
36{
37 /**
38 * Header of type #GNUNET_MESSAGE_TYPE_ABD_VERIFY
39 */
40 struct GNUNET_MessageHeader header;
41
42 /**
43 * Subject public key
44 */
45 struct GNUNET_CRYPTO_PrivateKey subject_key;
46
47 /**
48 * Trust anchor
49 */
50 struct GNUNET_CRYPTO_PublicKey issuer_key;
51
52 /**
53 * Length of the issuer attribute
54 */
55 uint16_t issuer_attribute_len;
56
57 /**
58 * Direction of the resolution algo
59 */
60 uint16_t resolution_algo;
61
62 /**
63 * Unique identifier for this request (for key collisions).
64 */
65 uint32_t id GNUNET_PACKED;
66
67 /* Followed by the zero-terminated attribute */
68};
69
70
71/**
72 * Message from client to Credential service to verify attributes.
73 */
74struct VerifyMessage
75{
76 /**
77 * Header of type #GNUNET_MESSAGE_TYPE_ABD_VERIFY
78 */
79 struct GNUNET_MessageHeader header;
80
81 /**
82 * Subject public key
83 */
84 struct GNUNET_CRYPTO_PublicKey subject_key;
85
86 /**
87 * Trust anchor
88 */
89 struct GNUNET_CRYPTO_PublicKey issuer_key;
90
91 /**
92 * Number of delegates
93 */
94 uint32_t d_count;
95
96 /**
97 * Length of the issuer attribute
98 */
99 uint16_t issuer_attribute_len;
100
101 /**
102 * Direction of the resolution algo
103 */
104 uint16_t resolution_algo;
105
106 /**
107 * Unique identifier for this request (for key collisions).
108 */
109 uint32_t id GNUNET_PACKED;
110
111 /* Followed by the zero-terminated attribute and credentials to look up */
112};
113
114
115/**
116 * Message from ABD service to client: new results.
117 */
118struct DelegationChainResultMessage
119{
120 /**
121 * Header of type #GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT
122 */
123 struct GNUNET_MessageHeader header;
124
125 /**
126 * Unique identifier for this request (for key collisions).
127 */
128 uint32_t id GNUNET_PACKED;
129
130 /**
131 * Indicates if credential has been found at all
132 */
133 uint32_t del_found GNUNET_PACKED;
134
135 /**
136 * The number of delegations in the response
137 */
138 uint32_t d_count GNUNET_PACKED;
139
140 /**
141 * The number of credentials in the response
142 */
143 uint32_t c_count GNUNET_PACKED;
144
145 /* followed by ad_count GNUNET_ABD_RecordData structs*/
146};
147
148/**
149 * Message from ABD service to client: new results.
150 */
151struct DelegationChainIntermediateMessage
152{
153 /**
154 * Header of type #GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT
155 */
156 struct GNUNET_MessageHeader header;
157
158 /**
159 * Unique identifier for this request (for key collisions).
160 */
161 uint32_t id GNUNET_PACKED;
162
163 uint16_t is_bw GNUNET_PACKED;
164
165 uint32_t size GNUNET_PACKED;
166};
167
168struct DelegationRecordData
169{
170 /**
171 * Subject key
172 */
173 struct GNUNET_CRYPTO_PublicKey subject_key;
174
175 /**
176 * Subject attributes
177 */
178 uint32_t subject_attribute_len GNUNET_PACKED;
179};
180
181
182struct ChainEntry
183{
184 /**
185 * Issuer key
186 */
187 struct GNUNET_CRYPTO_PublicKey issuer_key;
188
189 /**
190 * Subject key
191 */
192 struct GNUNET_CRYPTO_PublicKey subject_key;
193
194 /**
195 * Issuer attributes
196 */
197 uint32_t issuer_attribute_len GNUNET_PACKED;
198
199 /**
200 * Subject attributes
201 */
202 uint32_t subject_attribute_len GNUNET_PACKED;
203};
204
205
206struct DelegateEntry
207{
208 /**
209 * The signature for this credential by the issuer
210 */
211 struct GNUNET_CRYPTO_Signature signature;
212
213 /**
214 * Signature meta
215 */
216 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
217
218 /**
219 * Public key of the issuer
220 */
221 struct GNUNET_CRYPTO_PublicKey issuer_key;
222
223 /**
224 * Public key of the subject this credential was issued to
225 */
226 struct GNUNET_CRYPTO_PublicKey subject_key;
227
228 /**
229 * Expiration time of this credential
230 */
231 uint64_t expiration GNUNET_PACKED;
232
233 /**
234 * Issuer subject attribute length
235 */
236 uint32_t issuer_attribute_len;
237
238 /**
239 * Issuer attribute length
240 */
241 uint32_t subject_attribute_len;
242
243 /**
244 * Followed by the subject attribute string
245 */
246};
247
248
249GNUNET_NETWORK_STRUCT_END
250
251#endif
diff --git a/src/abd/abd_api.c b/src/abd/abd_api.c
deleted file mode 100644
index 3682f41ba..000000000
--- a/src/abd/abd_api.c
+++ /dev/null
@@ -1,563 +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 abd/abd_api.c
22 * @brief library to access the ABD 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_protocols.h"
30#include "gnunet_signatures.h"
31#include "abd.h"
32#include "abd_serialization.h"
33#include "gnunet_abd_service.h"
34#include "gnunet_identity_service.h"
35
36
37#define LOG(kind, ...) GNUNET_log_from (kind, "abd-api", __VA_ARGS__)
38
39/**
40 * Handle to a verify request
41 */
42struct GNUNET_ABD_Request
43{
44
45 /**
46 * DLL
47 */
48 struct GNUNET_ABD_Request *next;
49
50 /**
51 * DLL
52 */
53 struct GNUNET_ABD_Request *prev;
54
55 /**
56 * handle to abd service
57 */
58 struct GNUNET_ABD_Handle *abd_handle;
59
60 /**
61 * processor to call on verify result
62 */
63 GNUNET_ABD_CredentialResultProcessor verify_proc;
64
65 /**
66 * @e verify_proc closure
67 */
68 void *proc_cls;
69
70 /**
71 * processor to call on intermediate result
72 */
73 GNUNET_ABD_IntermediateResultProcessor int_proc;
74
75 /**
76 * @e verify_proc2 closure
77 */
78 void *proc2_cls;
79
80 /**
81 * Envelope with the message for this queue entry.
82 */
83 struct GNUNET_MQ_Envelope *env;
84
85 /**
86 * request id
87 */
88 uint32_t r_id;
89};
90
91
92/**
93 * Connection to the ABD service.
94 */
95struct GNUNET_ABD_Handle
96{
97
98 /**
99 * Configuration to use.
100 */
101 const struct GNUNET_CONFIGURATION_Handle *cfg;
102
103 /**
104 * Connection to service (if available).
105 */
106 struct GNUNET_MQ_Handle *mq;
107
108 /**
109 * Head of linked list of active verify requests.
110 */
111 struct GNUNET_ABD_Request *request_head;
112
113 /**
114 * Tail of linked list of active verify requests.
115 */
116 struct GNUNET_ABD_Request *request_tail;
117
118 /**
119 * Reconnect task
120 */
121 struct GNUNET_SCHEDULER_Task *reconnect_task;
122
123 /**
124 * How long do we wait until we try to reconnect?
125 */
126 struct GNUNET_TIME_Relative reconnect_backoff;
127
128 /**
129 * Request Id generator. Incremented by one for each request.
130 */
131 uint32_t r_id_gen;
132};
133
134
135/**
136 * Reconnect to ABD service.
137 *
138 * @param handle the handle to the ABD service
139 */
140static void
141reconnect (struct GNUNET_ABD_Handle *handle);
142
143
144/**
145 * Reconnect to ABD
146 *
147 * @param cls the handle
148 */
149static void
150reconnect_task (void *cls)
151{
152 struct GNUNET_ABD_Handle *handle = cls;
153
154 handle->reconnect_task = NULL;
155 reconnect (handle);
156}
157
158
159/**
160 * Disconnect from service and then reconnect.
161 *
162 * @param handle our handle
163 */
164static void
165force_reconnect (struct GNUNET_ABD_Handle *handle)
166{
167 GNUNET_MQ_destroy (handle->mq);
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,
173 &reconnect_task,
174 handle);
175}
176
177
178/**
179 * Generic error handler, called with the appropriate error code and
180 * the same closure specified at the creation of the message queue.
181 * Not every message queue implementation supports an error handler.
182 *
183 * @param cls closure with the `struct GNUNET_ABD_Handle *`
184 * @param error error code
185 */
186static void
187mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
188{
189 struct GNUNET_ABD_Handle *handle = cls;
190
191 force_reconnect (handle);
192}
193
194
195/**
196 * Check validity of message received from the ABD service
197 *
198 * @param cls the `struct GNUNET_ABD_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 ABD service
211 *
212 * @param cls the `struct GNUNET_ABD_Handle *`
213 * @param vr_msg the incoming message
214 */
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];
226 GNUNET_ABD_CredentialResultProcessor proc;
227 void *proc_cls;
228
229 LOG (GNUNET_ERROR_TYPE_DEBUG,
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);
239 GNUNET_MQ_discard (vr->env);
240 GNUNET_free (vr);
241 GNUNET_assert (
242 GNUNET_OK ==
243 GNUNET_ABD_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
260
261static int
262check_intermediate (void *cls, const struct
263 DelegationChainIntermediateMessage *vr_msg)
264{
265 // TODO
266 return GNUNET_OK;
267}
268
269
270static void
271handle_intermediate (void *cls, const struct
272 DelegationChainIntermediateMessage *vr_msg)
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;
279 GNUNET_ABD_IntermediateResultProcessor proc;
280 void *proc_cls;
281 struct GNUNET_ABD_Delegation *dd;
282
283
284 LOG (GNUNET_ERROR_TYPE_DEBUG,
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);
297 GNUNET_assert (
298 GNUNET_OK ==
299 GNUNET_ABD_delegation_chain_deserialize (size,
300 (const char *) &vr_msg[1],
301 1,
302 dd,
303 0,
304 NULL));
305 proc (proc_cls, dd, is_bw);
306}
307
308
309/**
310 * Reconnect to ABD service.
311 *
312 * @param handle the handle to the ABD service
313 */
314static void
315reconnect (struct GNUNET_ABD_Handle *handle)
316{
317 struct GNUNET_MQ_MessageHandler handlers[] =
318 {GNUNET_MQ_hd_var_size (result,
319 GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT,
320 struct DelegationChainResultMessage,
321 handle),
322 GNUNET_MQ_hd_var_size (result,
323 GNUNET_MESSAGE_TYPE_ABD_COLLECT_RESULT,
324 struct DelegationChainResultMessage,
325 handle),
326 GNUNET_MQ_hd_var_size (intermediate,
327 GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT,
328 struct DelegationChainIntermediateMessage,
329 handle),
330 GNUNET_MQ_handler_end ()};
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");
335 handle->mq = GNUNET_CLIENT_connect (handle->cfg,
336 "abd",
337 handlers,
338 &mq_error_handler,
339 handle);
340 if (NULL == handle->mq)
341 return;
342 for (vr = handle->request_head; NULL != vr; vr = vr->next)
343 GNUNET_MQ_send_copy (handle->mq, vr->env);
344}
345
346
347/**
348 * Initialize the connection with the ABD service.
349 *
350 * @param cfg configuration to use
351 * @return handle to the ABD service, or NULL on error
352 */
353struct GNUNET_ABD_Handle *
354GNUNET_ABD_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
355{
356 struct GNUNET_ABD_Handle *handle;
357
358 handle = GNUNET_new (struct GNUNET_ABD_Handle);
359 handle->cfg = cfg;
360 reconnect (handle);
361 if (NULL == handle->mq)
362 {
363 GNUNET_free (handle);
364 return NULL;
365 }
366 return handle;
367}
368
369
370/**
371 * Shutdown connection with the ABD service.
372 *
373 * @param handle handle of the ABD connection to stop
374 */
375void
376GNUNET_ABD_disconnect (struct GNUNET_ABD_Handle *handle)
377{
378 if (NULL != handle->mq)
379 {
380 GNUNET_MQ_destroy (handle->mq);
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);
389 GNUNET_free (handle);
390}
391
392
393/**
394 * Cancel pending verify request
395 *
396 * @param lr the verify request to cancel
397 */
398void
399GNUNET_ABD_request_cancel (struct GNUNET_ABD_Request *lr)
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
409/**
410 * Performs attribute collection.
411 * Collects all abds of subject to fulfill the
412 * attribute, if possible
413 *
414 * @param handle handle to the Credential service
415 * @param issuer_key the issuer public key
416 * @param issuer_attribute the issuer attribute
417 * @param subject_key the subject public key
418 * @param proc function to call on result
419 * @param proc_cls closure for processor
420 * @return handle to the queued request
421 */
422struct GNUNET_ABD_Request *
423GNUNET_ABD_collect (
424 struct GNUNET_ABD_Handle *handle,
425 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
426 const char *issuer_attribute,
427 const struct GNUNET_CRYPTO_PrivateKey *subject_key,
428 enum GNUNET_ABD_AlgoDirectionFlags direction,
429 GNUNET_ABD_CredentialResultProcessor proc,
430 void *proc_cls,
431 GNUNET_ABD_IntermediateResultProcessor proc2,
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
446 LOG (GNUNET_ERROR_TYPE_DEBUG,
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 =
463 GNUNET_MQ_msg_extra (c_msg, nlen, GNUNET_MESSAGE_TYPE_ABD_COLLECT);
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)
473 GNUNET_MQ_send_copy (handle->mq, vr->env);
474 return vr;
475}
476
477
478/**
479 * Performs attribute verification.
480 * Checks if there is a delegation chain from
481 * attribute ``issuer_attribute'' issued by the issuer
482 * with public key ``issuer_key'' maps to the attribute
483 * ``subject_attribute'' claimed by the subject with key
484 * ``subject_key''
485 *
486 * @param handle handle to the Credential service
487 * @param issuer_key the issuer public key
488 * @param issuer_attribute the issuer attribute
489 * @param subject_key the subject public key
490 * @param delegate_count number of delegates provided
491 * @param delegates subject delegates
492 * @param proc function to call on result
493 * @param proc_cls closure for processor
494 * @return handle to the queued request
495 */
496struct GNUNET_ABD_Request *
497GNUNET_ABD_verify (
498 struct GNUNET_ABD_Handle *handle,
499 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
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,
504 enum GNUNET_ABD_AlgoDirectionFlags direction,
505 GNUNET_ABD_CredentialResultProcessor proc,
506 void *proc_cls,
507 GNUNET_ABD_IntermediateResultProcessor proc2,
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
525 LOG (GNUNET_ERROR_TYPE_DEBUG,
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 =
542 GNUNET_MQ_msg_extra (v_msg, nlen, GNUNET_MESSAGE_TYPE_ABD_VERIFY);
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)
558 GNUNET_MQ_send_copy (handle->mq, vr->env);
559 return vr;
560}
561
562
563/* end of abd_api.c */
diff --git a/src/abd/abd_serialization.c b/src/abd/abd_serialization.c
deleted file mode 100644
index 14960e804..000000000
--- a/src/abd/abd_serialization.c
+++ /dev/null
@@ -1,516 +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 abd/abd_serialization.c
24 * @brief API to serialize and deserialize delegation chains
25 * and abds
26 * @author Martin Schanzenbach
27 */
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_constants.h"
31#include "gnunet_abd_service.h"
32#include "gnunet_signatures.h"
33#include "abd.h"
34
35/**
36 * Calculate how many bytes we will need to serialize
37 * the given delegation chain
38 *
39 * @param ds_count number of delegation chain entries
40 * @param dsr array of #GNUNET_ABD_DelegationSet
41 * @return the required size to serialize
42 */
43size_t
44GNUNET_ABD_delegation_set_get_size (
45 unsigned int ds_count,
46 const struct GNUNET_ABD_DelegationSet *dsr)
47{
48 unsigned int i;
49 size_t ret;
50
51 ret = sizeof (struct DelegationRecordData) * (ds_count);
52
53 for (i = 0; i < ds_count; i++)
54 {
55 GNUNET_assert ((ret + dsr[i].subject_attribute_len) >= ret);
56 ret += dsr[i].subject_attribute_len;
57 }
58 return ret;
59}
60
61
62/**
63 * Serizalize the given delegation chain entries and abd
64 *
65 * @param d_count number of delegation chain entries
66 * @param dsr array of #GNUNET_ABD_DelegationSet
67 * @param dest_size size of the destination
68 * @param dest where to store the result
69 * @return the size of the data, -1 on failure
70 */
71ssize_t
72GNUNET_ABD_delegation_set_serialize (
73 unsigned int d_count,
74 const struct GNUNET_ABD_DelegationSet *dsr,
75 size_t dest_size,
76 char *dest)
77{
78 struct DelegationRecordData rec;
79 unsigned int i;
80 size_t off;
81
82 off = 0;
83 for (i = 0; i < d_count; i++)
84 {
85 rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len);
86 rec.subject_key = dsr[i].subject_key;
87 if (off + sizeof (rec) > dest_size)
88 return -1;
89 GNUNET_memcpy (&dest[off], &rec, sizeof (rec));
90 off += sizeof (rec);
91 if (0 == dsr[i].subject_attribute_len)
92 continue;
93 if (off + dsr[i].subject_attribute_len > dest_size)
94 return -1;
95 GNUNET_memcpy (&dest[off],
96 dsr[i].subject_attribute,
97 dsr[i].subject_attribute_len);
98 off += dsr[i].subject_attribute_len;
99 }
100 return off;
101}
102
103
104/**
105 * Deserialize the given destination
106 *
107 * @param len size of the serialized delegation chain and cred
108 * @param src the serialized data
109 * @param d_count the number of delegation chain entries
110 * @param dsr where to put the delegation chain entries
111 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
112 */
113int
114GNUNET_ABD_delegation_set_deserialize (
115 size_t len,
116 const char *src,
117 unsigned int d_count,
118 struct GNUNET_ABD_DelegationSet *dsr)
119{
120 struct DelegationRecordData rec;
121 unsigned int i;
122 size_t off;
123
124 off = 0;
125 for (i = 0; i < d_count; i++)
126 {
127 if (off + sizeof (rec) > len)
128 return GNUNET_SYSERR;
129 GNUNET_memcpy (&rec, &src[off], sizeof (rec));
130 dsr[i].subject_key = rec.subject_key;
131 off += sizeof (rec);
132 dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len);
133 if (off + dsr[i].subject_attribute_len > len)
134 return GNUNET_SYSERR;
135 dsr[i].subject_attribute = (char *) &src[off];
136 off += dsr[i].subject_attribute_len;
137 }
138 return GNUNET_OK;
139}
140
141
142/**
143 * Calculate how many bytes we will need to serialize
144 * the abds
145 *
146 * @param c_count number of abd entries
147 * @param cd a #GNUNET_ABD_Credential
148 * @return the required size to serialize
149 */
150size_t
151GNUNET_ABD_delegates_get_size (
152 unsigned int c_count,
153 const struct GNUNET_ABD_Delegate *cd)
154{
155 unsigned int i;
156 size_t ret;
157
158 ret = sizeof (struct DelegateEntry) * (c_count);
159
160 for (i = 0; i < c_count; i++)
161 {
162 GNUNET_assert ((ret + cd[i].issuer_attribute_len
163 + cd[i].subject_attribute_len) >= ret);
164 // subject_attribute_len should be 0
165 ret += cd[i].issuer_attribute_len + cd[i].subject_attribute_len;
166 }
167 return ret;
168}
169
170
171/**
172 * Serizalize the given abds
173 *
174 * @param c_count number of abd entries
175 * @param cd a #GNUNET_ABD_Credential
176 * @param dest_size size of the destination
177 * @param dest where to store the result
178 * @return the size of the data, -1 on failure
179 */
180ssize_t
181GNUNET_ABD_delegates_serialize (
182 unsigned int c_count,
183 const struct GNUNET_ABD_Delegate *cd,
184 size_t dest_size,
185 char *dest)
186{
187 struct DelegateEntry c_rec;
188 unsigned int i;
189 size_t off;
190
191 off = 0;
192 for (i = 0; i < c_count; i++)
193 {
194 c_rec.subject_attribute_len = htonl (cd[i].subject_attribute_len);
195 c_rec.issuer_attribute_len = htonl (cd[i].issuer_attribute_len);
196 c_rec.issuer_key = cd[i].issuer_key;
197 c_rec.subject_key = cd[i].subject_key;
198 c_rec.signature = cd[i].signature;
199 c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE);
200 c_rec.purpose.size =
201 htonl ((sizeof (struct DelegateEntry) + cd[i].issuer_attribute_len)
202 - sizeof (struct GNUNET_CRYPTO_Signature));
203 c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us);
204 if (off + sizeof (c_rec) > dest_size)
205 return -1;
206 GNUNET_memcpy (&dest[off], &c_rec, sizeof (c_rec));
207 off += sizeof (c_rec);
208 if (off + cd[i].issuer_attribute_len > dest_size)
209 return -1;
210 GNUNET_memcpy (&dest[off],
211 cd[i].issuer_attribute,
212 cd[i].issuer_attribute_len);
213 off += cd[i].issuer_attribute_len;
214 }
215
216 return off;
217}
218
219
220/**
221 * Deserialize the given destination
222 *
223 * @param len size of the serialized creds
224 * @param src the serialized data
225 * @param c_count the number of abd entries
226 * @param cd where to put the abd data
227 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
228 */
229int
230GNUNET_ABD_delegates_deserialize (size_t len,
231 const char *src,
232 unsigned int c_count,
233 struct GNUNET_ABD_Delegate *cd)
234{
235 struct DelegateEntry c_rec;
236 unsigned int i;
237 size_t off;
238
239 off = 0;
240 for (i = 0; i < c_count; i++)
241 {
242 if (off + sizeof (c_rec) > len)
243 return GNUNET_SYSERR;
244 GNUNET_memcpy (&c_rec, &src[off], sizeof (c_rec));
245 cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len);
246 cd[i].issuer_key = c_rec.issuer_key;
247 cd[i].subject_key = c_rec.subject_key;
248 cd[i].signature = c_rec.signature;
249 cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration);
250 off += sizeof (c_rec);
251 if (off + cd[i].issuer_attribute_len > len)
252 return GNUNET_SYSERR;
253 cd[i].issuer_attribute = &src[off];
254 off += cd[i].issuer_attribute_len;
255 cd[i].subject_attribute_len = 0;
256 }
257 return GNUNET_OK;
258}
259
260
261/**
262 * Calculate how many bytes we will need to serialize
263 * the given delegation chain and abd
264 *
265 * @param d_count number of delegation chain entries
266 * @param dd array of #GNUNET_ABD_Delegation
267 * @param c_count number of abd entries
268 * @param cd a #GNUNET_ABD_Credential
269 * @return the required size to serialize
270 */
271size_t
272GNUNET_ABD_delegation_chain_get_size (
273 unsigned int d_count,
274 const struct GNUNET_ABD_Delegation *dd,
275 unsigned int c_count,
276 const struct GNUNET_ABD_Delegate *cd)
277{
278 unsigned int i;
279 size_t ret;
280
281 ret = sizeof (struct ChainEntry) * (d_count);
282
283 for (i = 0; i < d_count; i++)
284 {
285 GNUNET_assert (
286 (ret + dd[i].issuer_attribute_len + dd[i].subject_attribute_len) >= ret);
287 ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len;
288 }
289 return ret + GNUNET_ABD_delegates_get_size (c_count, cd);
290}
291
292
293/**
294 * Serizalize the given delegation chain entries and abd
295 *
296 * @param d_count number of delegation chain entries
297 * @param dd array of #GNUNET_ABD_Delegation
298 * @param c_count number of abd entries
299 * @param cd a #GNUNET_ABD_Credential
300 * @param dest_size size of the destination
301 * @param dest where to store the result
302 * @return the size of the data, -1 on failure
303 */
304ssize_t
305GNUNET_ABD_delegation_chain_serialize (
306 unsigned int d_count,
307 const struct GNUNET_ABD_Delegation *dd,
308 unsigned int c_count,
309 const struct GNUNET_ABD_Delegate *cd,
310 size_t dest_size,
311 char *dest)
312{
313 struct ChainEntry rec;
314 unsigned int i;
315 size_t off;
316
317 off = 0;
318 for (i = 0; i < d_count; i++)
319 {
320 rec.issuer_attribute_len = htonl ((uint32_t) dd[i].issuer_attribute_len);
321 rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len);
322 rec.issuer_key = dd[i].issuer_key;
323 rec.subject_key = dd[i].subject_key;
324 if (off + sizeof (rec) > dest_size)
325 return -1;
326 GNUNET_memcpy (&dest[off], &rec, sizeof (rec));
327 off += sizeof (rec);
328 if (off + dd[i].issuer_attribute_len > dest_size)
329 return -1;
330 GNUNET_memcpy (&dest[off],
331 dd[i].issuer_attribute,
332 dd[i].issuer_attribute_len);
333 off += dd[i].issuer_attribute_len;
334 if (0 == dd[i].subject_attribute_len)
335 continue;
336 if (off + dd[i].subject_attribute_len > dest_size)
337 return -1;
338 GNUNET_memcpy (&dest[off],
339 dd[i].subject_attribute,
340 dd[i].subject_attribute_len);
341 off += dd[i].subject_attribute_len;
342 }
343 return off + GNUNET_ABD_delegates_serialize (c_count,
344 cd,
345 dest_size - off,
346 &dest[off]);
347}
348
349
350/**
351 * Deserialize the given destination
352 *
353 * @param len size of the serialized delegation chain and cred
354 * @param src the serialized data
355 * @param d_count the number of delegation chain entries
356 * @param dd where to put the delegation chain entries
357 * @param c_count the number of abd entries
358 * @param cd where to put the abd data
359 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
360 */
361int
362GNUNET_ABD_delegation_chain_deserialize (
363 size_t len,
364 const char *src,
365 unsigned int d_count,
366 struct GNUNET_ABD_Delegation *dd,
367 unsigned int c_count,
368 struct GNUNET_ABD_Delegate *cd)
369{
370 struct ChainEntry rec;
371 unsigned int i;
372 size_t off;
373
374 off = 0;
375 for (i = 0; i < d_count; i++)
376 {
377 if (off + sizeof (rec) > len)
378 return GNUNET_SYSERR;
379 GNUNET_memcpy (&rec, &src[off], sizeof (rec));
380 dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len);
381 dd[i].issuer_key = rec.issuer_key;
382 dd[i].subject_key = rec.subject_key;
383 off += sizeof (rec);
384 if (off + dd[i].issuer_attribute_len > len)
385 return GNUNET_SYSERR;
386 dd[i].issuer_attribute = &src[off];
387 off += dd[i].issuer_attribute_len;
388 dd[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len);
389 if (off + dd[i].subject_attribute_len > len)
390 return GNUNET_SYSERR;
391 dd[i].subject_attribute = &src[off];
392 off += dd[i].subject_attribute_len;
393 }
394 return GNUNET_ABD_delegates_deserialize (len - off,
395 &src[off],
396 c_count,
397 cd);
398}
399
400
401int
402GNUNET_ABD_delegate_serialize (struct GNUNET_ABD_Delegate *dele,
403 char **data)
404{
405 size_t size;
406 struct DelegateEntry *cdata;
407 int attr_len;
408
409 // +1 for \0
410 if (0 == dele->subject_attribute_len)
411 {
412 attr_len = dele->issuer_attribute_len + 1;
413 }
414 else
415 {
416 attr_len = dele->issuer_attribute_len + dele->subject_attribute_len + 2;
417 }
418 size = sizeof (struct DelegateEntry) + attr_len;
419
420 char tmp_str[attr_len];
421 GNUNET_memcpy (tmp_str, dele->issuer_attribute, dele->issuer_attribute_len);
422 if (0 != dele->subject_attribute_len)
423 {
424 tmp_str[dele->issuer_attribute_len] = '\0';
425 GNUNET_memcpy (tmp_str + dele->issuer_attribute_len + 1,
426 dele->subject_attribute,
427 dele->subject_attribute_len);
428 }
429 tmp_str[attr_len - 1] = '\0';
430
431 *data = GNUNET_malloc (size);
432 cdata = (struct DelegateEntry *) *data;
433 cdata->subject_key = dele->subject_key;
434 cdata->issuer_key = dele->issuer_key;
435 cdata->expiration = GNUNET_htonll (dele->expiration.abs_value_us);
436 cdata->signature = dele->signature;
437 cdata->issuer_attribute_len = htonl (dele->issuer_attribute_len + 1);
438 if (0 == dele->subject_attribute_len)
439 {
440 cdata->subject_attribute_len = htonl (0);
441 }
442 else
443 {
444 cdata->subject_attribute_len = htonl (dele->subject_attribute_len + 1);
445 }
446 cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE);
447 cdata->purpose.size =
448 htonl (size - sizeof (struct GNUNET_CRYPTO_Signature));
449
450 GNUNET_memcpy (&cdata[1], tmp_str, attr_len);
451
452 if (GNUNET_OK !=
453 GNUNET_CRYPTO_signature_verify_ (GNUNET_SIGNATURE_PURPOSE_DELEGATE,
454 &cdata->purpose,
455 &cdata->signature,
456 &cdata->issuer_key))
457 {
458 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Serialize: Invalid delegate\n");
459 return 0;
460 }
461 return size;
462}
463
464
465struct GNUNET_ABD_Delegate *
466GNUNET_ABD_delegate_deserialize (const char *data, size_t data_size)
467{
468 struct GNUNET_ABD_Delegate *dele;
469 struct DelegateEntry *cdata;
470 char *attr_combo_str;
471
472 if (data_size < sizeof (struct DelegateEntry))
473 return NULL;
474 cdata = (struct DelegateEntry *) data;
475 if (GNUNET_OK !=
476 GNUNET_CRYPTO_signature_verify_ (GNUNET_SIGNATURE_PURPOSE_DELEGATE,
477 &cdata->purpose,
478 &cdata->signature,
479 &cdata->issuer_key))
480 {
481 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deserialize: Invalid delegate\n");
482 return NULL;
483 }
484 attr_combo_str = (char *) &cdata[1];
485 int iss_len = ntohl (cdata->issuer_attribute_len);
486 int sub_len = ntohl (cdata->subject_attribute_len);
487 int attr_combo_len = iss_len + sub_len;
488
489 dele =
490 GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_combo_len);
491
492 dele->issuer_key = cdata->issuer_key;
493 dele->subject_key = cdata->subject_key;
494 GNUNET_memcpy (&dele[1], attr_combo_str, attr_combo_len);
495 dele->signature = cdata->signature;
496
497 // Set the pointers for the attributes
498 dele->issuer_attribute = (char *) &dele[1];
499 dele->issuer_attribute_len = iss_len;
500 dele->subject_attribute_len = sub_len;
501 if (0 == sub_len)
502 {
503 dele->subject_attribute = NULL;
504 }
505 else
506 {
507 dele->subject_attribute = (char *) &dele[1] + iss_len;
508 }
509
510 dele->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration);
511
512 return dele;
513}
514
515
516/* end of abd_serialization.c */
diff --git a/src/abd/abd_serialization.h b/src/abd/abd_serialization.h
deleted file mode 100644
index 21dc45a7b..000000000
--- a/src/abd/abd_serialization.h
+++ /dev/null
@@ -1,167 +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 abd/abd_serialization.h
24 * @brief API to serialize and deserialize delegation chains
25 * and abds
26 * @author Martin Schanzenbach
27 */
28#ifndef ABD_SERIALIZATION_H
29#define ABD_SERIALIZATION_H
30
31#include "platform.h"
32#include "gnunet_util_lib.h"
33#include "gnunet_constants.h"
34#include "gnunet_abd_service.h"
35
36/**
37 * Calculate how many bytes we will need to serialize
38 * the given delegation record
39 *
40 * @param ds_count number of delegation chain entries
41 * @param dsr array of #GNUNET_ABD_Delegation
42 * @return the required size to serialize
43 */
44size_t
45GNUNET_ABD_delegation_set_get_size (
46 unsigned int ds_count,
47 const struct GNUNET_ABD_DelegationSet *dsr);
48
49/**
50 * Serizalize the given delegation record entries
51 *
52 * @param d_count number of delegation chain entries
53 * @param dsr array of #GNUNET_ABD_Delegation
54 * @param dest_size size of the destination
55 * @param dest where to store the result
56 * @return the size of the data, -1 on failure
57 */
58ssize_t
59GNUNET_ABD_delegation_set_serialize (
60 unsigned int d_count,
61 const struct GNUNET_ABD_DelegationSet *dsr,
62 size_t dest_size,
63 char *dest);
64
65
66/**
67 * Deserialize the given destination
68 *
69 * @param len size of the serialized delegation recird
70 * @param src the serialized data
71 * @param d_count the number of delegation chain entries
72 * @param dsr where to put the delegation chain entries
73 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
74 */
75int
76GNUNET_ABD_delegation_set_deserialize (
77 size_t len,
78 const char *src,
79 unsigned int d_count,
80 struct GNUNET_ABD_DelegationSet *dsr);
81
82/**
83 * Calculate how many bytes we will need to serialize
84 * the given delegation chain and abd
85 *
86 * @param d_count number of delegation chain entries
87 * @param dd array of #GNUNET_ABD_Delegation
88 * @param c_count number of abd entries
89 * @param cd a #GNUNET_ABD_Delegate
90 * @return the required size to serialize
91 */
92size_t
93GNUNET_ABD_delegation_chain_get_size (
94 unsigned int d_count,
95 const struct GNUNET_ABD_Delegation *dd,
96 unsigned int c_count,
97 const struct GNUNET_ABD_Delegate *cd);
98
99/**
100 * Serizalize the given delegation chain entries and abd
101 *
102 * @param d_count number of delegation chain entries
103 * @param dd array of #GNUNET_ABD_Delegation
104 * @param c_count number of abd entries
105 * @param cd a #GNUNET_ABD_Delegate
106 * @param dest_size size of the destination
107 * @param dest where to store the result
108 * @return the size of the data, -1 on failure
109 */
110ssize_t
111GNUNET_ABD_delegation_chain_serialize (
112 unsigned int d_count,
113 const struct GNUNET_ABD_Delegation *dd,
114 unsigned int c_count,
115 const struct GNUNET_ABD_Delegate *cd,
116 size_t dest_size,
117 char *dest);
118
119
120/**
121 * Deserialize the given destination
122 *
123 * @param len size of the serialized delegation chain and cred
124 * @param src the serialized data
125 * @param d_count the number of delegation chain entries
126 * @param dd where to put the delegation chain entries
127 * @param c_count number of abd entries
128 * @param cd where to put the abd data
129 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
130 */
131int
132GNUNET_ABD_delegation_chain_deserialize (
133 size_t len,
134 const char *src,
135 unsigned int d_count,
136 struct GNUNET_ABD_Delegation *dd,
137 unsigned int c_count,
138 struct GNUNET_ABD_Delegate *cd);
139
140size_t
141GNUNET_ABD_delegates_get_size (
142 unsigned int c_count,
143 const struct GNUNET_ABD_Delegate *cd);
144
145ssize_t
146GNUNET_ABD_delegates_serialize (
147 unsigned int c_count,
148 const struct GNUNET_ABD_Delegate *cd,
149 size_t dest_size,
150 char *dest);
151
152
153int
154GNUNET_ABD_delegates_deserialize (size_t len,
155 const char *src,
156 unsigned int c_count,
157 struct GNUNET_ABD_Delegate *cd);
158
159int
160GNUNET_ABD_delegate_serialize (struct GNUNET_ABD_Delegate *cred,
161 char **data);
162
163struct GNUNET_ABD_Delegate *
164GNUNET_ABD_delegate_deserialize (const char *data, size_t data_size);
165
166#endif
167/* end of abd_serialization.h */
diff --git a/src/abd/delegate_misc.c b/src/abd/delegate_misc.c
deleted file mode 100644
index 446c0b8d2..000000000
--- a/src/abd/delegate_misc.c
+++ /dev/null
@@ -1,279 +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 abd/delegate_misc.c
24 * @brief Misc API for delegate
25 *
26 * @author Martin Schanzenbach
27 */
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_constants.h"
31#include "gnunet_abd_service.h"
32#include "gnunet_signatures.h"
33#include "abd.h"
34#include <inttypes.h>
35
36char *
37GNUNET_ABD_delegate_to_string (
38 const struct GNUNET_ABD_Delegate *cred)
39{
40 char *cred_str;
41 char *subject_pkey;
42 char *issuer_pkey;
43 char *signature;
44
45 subject_pkey = GNUNET_CRYPTO_public_key_to_string (&cred->subject_key);
46 issuer_pkey = GNUNET_CRYPTO_public_key_to_string (&cred->issuer_key);
47 GNUNET_STRINGS_base64_encode ((char *) &cred->signature,
48 sizeof (struct GNUNET_CRYPTO_Signature),
49 &signature);
50 if (0 == cred->subject_attribute_len)
51 {
52 GNUNET_asprintf (&cred_str,
53 "%s.%s -> %s | %s | %" SCNu64,
54 issuer_pkey,
55 cred->issuer_attribute,
56 subject_pkey,
57 signature,
58 cred->expiration.abs_value_us);
59 }
60 else
61 {
62 GNUNET_asprintf (&cred_str,
63 "%s.%s -> %s.%s | %s | %" SCNu64,
64 issuer_pkey,
65 cred->issuer_attribute,
66 subject_pkey,
67 cred->subject_attribute,
68 signature,
69 cred->expiration.abs_value_us);
70 }
71 GNUNET_free (subject_pkey);
72 GNUNET_free (issuer_pkey);
73 GNUNET_free (signature);
74
75 return cred_str;
76}
77
78
79struct GNUNET_ABD_Delegate *
80GNUNET_ABD_delegate_from_string (const char *s)
81{
82 struct GNUNET_ABD_Delegate *dele;
83 size_t enclen = (sizeof (struct GNUNET_CRYPTO_PublicKey)) * 8;
84 if (enclen % 5 > 0)
85 enclen += 5 - enclen % 5;
86 enclen /= 5; /* 260/5 = 52 */
87 char subject_pkey[enclen + 1];
88 char issuer_pkey[enclen + 1];
89 char iss_attr[253 + 1];
90 // Needs to be initialized, in case of Type 1 credential (A.a <- B)
91 char sub_attr[253 + 1] = "";
92 char signature[256]; // TODO max payload size
93
94 struct GNUNET_CRYPTO_Signature *sig;
95 struct GNUNET_TIME_Absolute etime_abs;
96
97 // If it's A.a <- B.b...
98 if (6 != sscanf (s,
99 "%58s.%253s -> %58s.%253s | %s | %" SCNu64,
100 issuer_pkey,
101 iss_attr,
102 subject_pkey,
103 sub_attr,
104 signature,
105 &etime_abs.abs_value_us))
106 {
107 // Try if it's A.a <- B
108 if (5 != sscanf (s,
109 "%58s.%253s -> %58s | %s | %" SCNu64,
110 issuer_pkey,
111 iss_attr,
112 subject_pkey,
113 signature,
114 &etime_abs.abs_value_us))
115 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 "Unable to parse DEL record string `%s'\n",
118 s);
119 return NULL;
120 }
121 }
122
123 // +1 for \0
124 int attr_len;
125 if (strcmp (sub_attr, "") == 0)
126 {
127 attr_len = strlen (iss_attr) + 1;
128 }
129 else
130 {
131 attr_len = strlen (iss_attr) + strlen (sub_attr) + 2;
132 }
133 dele = GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_len);
134
135 char tmp_str[attr_len];
136 GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr));
137 if (strcmp (sub_attr, "") != 0)
138 {
139 tmp_str[strlen (iss_attr)] = '\0';
140 GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1,
141 sub_attr,
142 strlen (sub_attr));
143 }
144 tmp_str[attr_len - 1] = '\0';
145
146 if (GNUNET_SYSERR ==
147 GNUNET_CRYPTO_public_key_from_string (subject_pkey,
148 &dele->subject_key))
149 {
150 GNUNET_free (dele);
151 return NULL;
152 }
153 if (GNUNET_SYSERR ==
154 GNUNET_CRYPTO_public_key_from_string (issuer_pkey,
155 &dele->issuer_key))
156 {
157 GNUNET_free (dele);
158 return NULL;
159 }
160 GNUNET_assert (sizeof (struct GNUNET_CRYPTO_Signature) ==
161 GNUNET_STRINGS_base64_decode (signature,
162 strlen (signature),
163 (void **) &sig));
164 dele->signature = *sig;
165 dele->expiration = etime_abs;
166 GNUNET_free (sig);
167
168 GNUNET_memcpy (&dele[1], tmp_str, attr_len);
169
170 dele->issuer_attribute = (char *) &dele[1];
171 dele->issuer_attribute_len = strlen (iss_attr);
172 if (strcmp (sub_attr, "") == 0)
173 {
174 dele->subject_attribute = NULL;
175 dele->subject_attribute_len = 0;
176 }
177 else
178 {
179 dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1;
180 dele->subject_attribute_len = strlen (sub_attr);
181 }
182
183 return dele;
184}
185
186
187/**
188 * Issue an attribute to a subject
189 *
190 * @param issuer the ego that should be used to issue the attribute
191 * @param subject the subject of the attribute
192 * @param iss_attr the name of the attribute
193 * @param expiration the TTL of the credential
194 * @return handle to the queued request
195 */
196
197struct GNUNET_ABD_Delegate *
198GNUNET_ABD_delegate_issue (
199 const struct GNUNET_CRYPTO_PrivateKey *issuer,
200 struct GNUNET_CRYPTO_PublicKey *subject,
201 const char *iss_attr,
202 const char *sub_attr,
203 struct GNUNET_TIME_Absolute *expiration)
204{
205 struct DelegateEntry *del;
206 struct GNUNET_ABD_Delegate *dele;
207 size_t size;
208 int attr_len;
209
210 if (NULL == sub_attr)
211 {
212 // +1 for \0
213 attr_len = strlen (iss_attr) + 1;
214 }
215 else
216 {
217 // +2 for both strings need to be terminated with \0
218 attr_len = strlen (iss_attr) + strlen (sub_attr) + 2;
219 }
220 size = sizeof (struct DelegateEntry) + attr_len;
221
222 char tmp_str[attr_len];
223 GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr));
224 if (NULL != sub_attr)
225 {
226 tmp_str[strlen (iss_attr)] = '\0';
227 GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1,
228 sub_attr,
229 strlen (sub_attr));
230 }
231 tmp_str[attr_len - 1] = '\0';
232
233 del = GNUNET_malloc (size);
234 del->purpose.size =
235 htonl (size - sizeof (struct GNUNET_CRYPTO_Signature));
236 del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE);
237 GNUNET_CRYPTO_key_get_public (issuer, &del->issuer_key);
238 del->subject_key = *subject;
239 del->expiration = GNUNET_htonll (expiration->abs_value_us);
240 del->issuer_attribute_len = htonl (strlen (iss_attr) + 1);
241 if (NULL == sub_attr)
242 {
243 del->subject_attribute_len = htonl (0);
244 }
245 else
246 {
247 del->subject_attribute_len = htonl (strlen (sub_attr) + 1);
248 }
249
250 GNUNET_memcpy (&del[1], tmp_str, attr_len);
251
252 GNUNET_CRYPTO_sign_ (issuer, &del->purpose, &del->signature);
253
254 dele = GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_len);
255 dele->signature = del->signature;
256 dele->expiration = *expiration;
257 GNUNET_CRYPTO_key_get_public (issuer, &dele->issuer_key);
258
259 dele->subject_key = *subject;
260
261 // Copy the combined string at the part in the memory where the struct ends
262 GNUNET_memcpy (&dele[1], tmp_str, attr_len);
263
264 dele->issuer_attribute = (char *) &dele[1];
265 dele->issuer_attribute_len = strlen (iss_attr);
266 if (NULL == sub_attr)
267 {
268 dele->subject_attribute = NULL;
269 dele->subject_attribute_len = 0;
270 }
271 else
272 {
273 dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1;
274 dele->subject_attribute_len = strlen (sub_attr);
275 }
276
277 GNUNET_free (del);
278 return dele;
279}
diff --git a/src/abd/delegate_misc.h b/src/abd/delegate_misc.h
deleted file mode 100644
index 0a4ddd9eb..000000000
--- a/src/abd/delegate_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 abd/delegate_misc.h
22 * @brief Delegate helper functions
23 */
24#ifndef DELEGATE_MISC_H
25#define DELEGATE_MISC_H
26
27#include "gnunet_abd_service.h"
28
29char *
30GNUNET_ABD_delegate_to_string (
31 const struct GNUNET_ABD_Delegate *cred);
32
33struct GNUNET_ABD_Delegate *
34GNUNET_ABD_delegate_from_string (const char *str);
35
36#endif
diff --git a/src/abd/gnunet-abd.c b/src/abd/gnunet-abd.c
deleted file mode 100644
index 1ed1adbe7..000000000
--- a/src/abd/gnunet-abd.c
+++ /dev/null
@@ -1,1108 +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 gnunet-abd.c
22 * @brief command line tool to access command line Credential service
23 * @author Martin Schanzenbach
24 */
25#include "platform.h"
26#include <gnunet_util_lib.h>
27#include <gnunet_abd_service.h>
28#include <gnunet_gnsrecord_lib.h>
29#include <gnunet_namestore_service.h>
30#include "delegate_misc.h"
31#include "abd_serialization.h"
32
33/**
34 * Configuration we are using.
35 */
36static const struct GNUNET_CONFIGURATION_Handle *cfg;
37
38/**
39 * Handle to the namestore.
40 */
41static struct GNUNET_NAMESTORE_Handle *ns;
42
43/**
44 * Private key for the our zone.
45 */
46static struct GNUNET_CRYPTO_PrivateKey zone_pkey;
47
48/**
49 * EgoLookup
50 */
51static struct GNUNET_IDENTITY_EgoLookup *el;
52
53/**
54 * Handle to Credential service.
55 */
56static struct GNUNET_ABD_Handle *abd;
57
58/**
59 * Desired timeout for the lookup (default is no timeout).
60 */
61static struct GNUNET_TIME_Relative timeout;
62
63/**
64 * Handle to verify request
65 */
66static struct GNUNET_ABD_Request *verify_request;
67
68/**
69 * Handle to collect request
70 */
71static struct GNUNET_ABD_Request *collect_request;
72
73/**
74 * Task scheduled to handle timeout.
75 */
76static struct GNUNET_SCHEDULER_Task *tt;
77
78/**
79 * Return value of the commandline.
80 */
81static int ret = 0;
82
83/**
84 * Subject pubkey string
85 */
86static char *subject;
87
88/**
89 * Subject delegate string
90 */
91static char *subject_delegate;
92
93/**
94 * Credential TTL
95 */
96static char *expiration;
97
98/**
99 * Subject key
100 */
101struct GNUNET_CRYPTO_PublicKey subject_pkey;
102
103/**
104 * Issuer key
105 */
106struct GNUNET_CRYPTO_PublicKey issuer_pkey;
107
108
109/**
110 * Issuer pubkey string
111 */
112static char *issuer_key;
113
114/**
115 * ego
116 */
117static char *ego_name;
118
119/**
120 * Issuer attribute
121 */
122static char *issuer_attr;
123
124/**
125 * Verify mode
126 */
127static int verify;
128
129/**
130 * Collect mode
131 */
132static int collect;
133
134/**
135 * Create mode
136 */
137static int create_is;
138
139/**
140 * Create mode
141 */
142static int create_ss;
143
144/**
145 * Create mode
146 */
147static int sign_ss;
148
149/**
150 * Signed issue credentials
151 */
152static char *import;
153
154/**
155 * Is record private
156 */
157static int is_private;
158
159/**
160 * Search direction: forward
161 */
162static int forward;
163
164/**
165 * Search direction: backward
166 */
167static int backward;
168
169/**
170 * API enum, filled and passed for collect/verify
171 */
172enum GNUNET_ABD_AlgoDirectionFlags direction = 0;
173
174/**
175 * Queue entry for the 'add' operation.
176 */
177static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
178
179/**
180 * Value in binary format.
181 */
182static void *data;
183
184/**
185 * Number of bytes in #data.
186 */
187static size_t data_size;
188
189/**
190 * Type string converted to DNS type value.
191 */
192static uint32_t type;
193
194/**
195 * Type of the record to add/remove, NULL to remove all.
196 */
197static char *typestring;
198/**
199 * Expiration string converted to numeric value.
200 */
201static uint64_t etime;
202
203/**
204 * Is expiration time relative or absolute time?
205 */
206static int etime_is_rel = GNUNET_SYSERR;
207
208/**
209 * Record label for storing delegations
210 */
211static char *record_label;
212
213/**
214 * Task run on shutdown. Cleans up everything.
215 *
216 * @param cls unused
217 */
218static void
219do_shutdown (void *cls)
220{
221 if (NULL != verify_request)
222 {
223 GNUNET_ABD_request_cancel (verify_request);
224 verify_request = NULL;
225 }
226 if (NULL != abd)
227 {
228 GNUNET_ABD_disconnect (abd);
229 abd = NULL;
230 }
231 if (NULL != tt)
232 {
233 GNUNET_SCHEDULER_cancel (tt);
234 tt = NULL;
235 }
236 if (NULL != el)
237 {
238 GNUNET_IDENTITY_ego_lookup_cancel (el);
239 el = NULL;
240 }
241 if (NULL != add_qe)
242 {
243 GNUNET_NAMESTORE_cancel (add_qe);
244 add_qe = NULL;
245 }
246 if (NULL != ns)
247 {
248 GNUNET_NAMESTORE_disconnect (ns);
249 ns = NULL;
250 }
251}
252
253
254/**
255 * Task run on timeout. Triggers shutdown.
256 *
257 * @param cls unused
258 */
259static void
260do_timeout (void *cls)
261{
262 tt = NULL;
263 GNUNET_SCHEDULER_shutdown ();
264}
265
266
267static void
268handle_intermediate_result (void *cls,
269 struct GNUNET_ABD_Delegation *dd,
270 bool is_bw)
271{
272 char *prefix = "";
273 if (is_bw)
274 prefix = "Backward -";
275 else
276 prefix = "Forward -";
277
278 printf ("%s Intermediate result: %s.%s <- %s.%s\n",
279 prefix,
280 GNUNET_CRYPTO_public_key_to_string (&dd->issuer_key),
281 dd->issuer_attribute,
282 GNUNET_CRYPTO_public_key_to_string (&dd->subject_key),
283 dd->subject_attribute);
284}
285
286
287static void
288handle_collect_result (void *cls,
289 unsigned int d_count,
290 struct GNUNET_ABD_Delegation *dc,
291 unsigned int c_count,
292 struct GNUNET_ABD_Delegate *dele)
293{
294 int i;
295 char *line;
296
297 verify_request = NULL;
298 if (NULL != dele)
299 {
300 for (i = 0; i < c_count; i++)
301 {
302 line = GNUNET_ABD_delegate_to_string (&dele[i]);
303 printf ("%s\n", line);
304 GNUNET_free (line);
305 }
306 }
307 else
308 {
309 printf ("Received NULL\n");
310 }
311
312 GNUNET_SCHEDULER_shutdown ();
313}
314
315
316static void
317handle_verify_result (void *cls,
318 unsigned int d_count,
319 struct GNUNET_ABD_Delegation *dc,
320 unsigned int c_count,
321 struct GNUNET_ABD_Delegate *dele)
322{
323 int i;
324 char *iss_key;
325 char *sub_key;
326
327 verify_request = NULL;
328 if (NULL == dele)
329 ret = 1;
330 else
331 {
332 printf ("Delegation Chain:\n");
333 for (i = 0; i < d_count; i++)
334 {
335 iss_key = GNUNET_CRYPTO_public_key_to_string (&dc[i].issuer_key);
336 sub_key = GNUNET_CRYPTO_public_key_to_string (&dc[i].subject_key);
337
338 if (0 != dc[i].subject_attribute_len)
339 {
340 printf ("(%d) %s.%s <- %s.%s\n",
341 i,
342 iss_key,
343 dc[i].issuer_attribute,
344 sub_key,
345 dc[i].subject_attribute);
346 }
347 else
348 {
349 printf ("(%d) %s.%s <- %s\n",
350 i,
351 iss_key,
352 dc[i].issuer_attribute,
353 sub_key);
354 }
355 GNUNET_free (iss_key);
356 GNUNET_free (sub_key);
357 }
358 printf ("\nDelegate(s):\n");
359 for (i = 0; i < c_count; i++)
360 {
361 iss_key = GNUNET_CRYPTO_public_key_to_string (&dele[i].issuer_key);
362 sub_key = GNUNET_CRYPTO_public_key_to_string (&dele[i].subject_key);
363 printf ("%s.%s <- %s\n", iss_key, dele[i].issuer_attribute, sub_key);
364 GNUNET_free (iss_key);
365 GNUNET_free (sub_key);
366 }
367 printf ("Successful.\n");
368 }
369
370 GNUNET_SCHEDULER_shutdown ();
371}
372
373
374/**
375 * Callback invoked from identity service with ego information.
376 * An @a ego of NULL means the ego was not found.
377 *
378 * @param cls closure with the configuration
379 * @param ego an ego known to identity service, or NULL
380 */
381static void
382identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
383{
384 const struct GNUNET_CRYPTO_PrivateKey *privkey;
385
386 el = NULL;
387 if (NULL == ego)
388 {
389 if (NULL != ego_name)
390 {
391 fprintf (stderr,
392 _ ("Ego `%s' not known to identity service\n"),
393 ego_name);
394 }
395 GNUNET_SCHEDULER_shutdown ();
396 return;
397 }
398
399 if (GNUNET_YES == collect)
400 {
401
402 if (GNUNET_OK !=
403 GNUNET_CRYPTO_public_key_from_string (issuer_key,
404 &issuer_pkey))
405 {
406 fprintf (stderr,
407 _ ("Issuer public key `%s' is not well-formed\n"),
408 issuer_key);
409 GNUNET_SCHEDULER_shutdown ();
410 }
411 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
412
413 collect_request = GNUNET_ABD_collect (abd,
414 &issuer_pkey,
415 issuer_attr,
416 privkey,
417 direction,
418 &handle_collect_result,
419 NULL,
420 &handle_intermediate_result,
421 NULL);
422 return;
423 }
424 GNUNET_SCHEDULER_shutdown ();
425}
426
427
428/**
429 * Parse expiration time.
430 *
431 * @param expirationstring text to parse
432 * @param[out] etime_is_rel set to #GNUNET_YES if time is relative
433 * @param[out] etime set to expiration time (abs or rel)
434 * @return #GNUNET_OK on success
435 */
436static int
437parse_expiration (const char *expirationstring,
438 int *etime_is_rel,
439 uint64_t *etime)
440{
441 // copied from namestore/gnunet-namestore.c
442 struct GNUNET_TIME_Relative etime_rel;
443 struct GNUNET_TIME_Absolute etime_abs;
444
445 if (0 == strcmp (expirationstring, "never"))
446 {
447 *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
448 *etime_is_rel = GNUNET_NO;
449 return GNUNET_OK;
450 }
451 if (GNUNET_OK ==
452 GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel))
453 {
454 *etime_is_rel = GNUNET_YES;
455 *etime = etime_rel.rel_value_us;
456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
457 "Storing record with relative expiration time of %s\n",
458 GNUNET_STRINGS_relative_time_to_string (etime_rel, GNUNET_NO));
459 return GNUNET_OK;
460 }
461 if (GNUNET_OK ==
462 GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs))
463 {
464 *etime_is_rel = GNUNET_NO;
465 *etime = etime_abs.abs_value_us;
466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "Storing record with absolute expiration time of %s\n",
468 GNUNET_STRINGS_absolute_time_to_string (etime_abs));
469 return GNUNET_OK;
470 }
471 return GNUNET_SYSERR;
472}
473
474
475/**
476 * Function called if lookup fails.
477 */
478static void
479error_cb (void *cls)
480{
481 fprintf (stderr, "Error occurred during lookup, shutting down.\n");
482 GNUNET_SCHEDULER_shutdown ();
483 return;
484}
485
486
487static void
488add_continuation (void *cls, int32_t success, const char *emsg)
489{
490 struct GNUNET_NAMESTORE_QueueEntry **qe = cls;
491 *qe = NULL;
492
493 if (GNUNET_OK == success)
494 printf ("Adding successful.\n");
495 else
496 fprintf (stderr, "Error occurred during adding, shutting down.\n");
497
498 GNUNET_SCHEDULER_shutdown ();
499}
500
501
502static void
503get_existing_record (void *cls,
504 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
505 const char *rec_name,
506 unsigned int rd_count,
507 const struct GNUNET_GNSRECORD_Data *rd)
508{
509 struct GNUNET_GNSRECORD_Data *rde;
510 struct GNUNET_GNSRECORD_Data*rdn =
511 GNUNET_malloc (sizeof(*rdn) * (rd_count + 1));
512
513 memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data));
514 GNUNET_memcpy (&rdn[1], rd,
515 rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
516 rde = &rdn[0];
517 rde->data = data;
518 rde->data_size = data_size;
519 rde->record_type = type;
520
521 // Set flags
522 if (GNUNET_YES == is_private)
523 rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
524 rde->expiration_time = etime;
525 if (GNUNET_YES == etime_is_rel)
526 rde->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
527 else if (GNUNET_NO != etime_is_rel)
528 rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
529
530 GNUNET_assert (NULL != rec_name);
531 add_qe = GNUNET_NAMESTORE_records_store (ns,
532 &zone_pkey,
533 rec_name,
534 rd_count + 1,
535 rde,
536 &add_continuation,
537 &add_qe);
538 GNUNET_free (rdn);
539 return;
540}
541
542
543static void
544store_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
545{
546 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
547 struct GNUNET_ABD_Delegate *cred;
548 struct GNUNET_CRYPTO_PublicKey zone_pubkey;
549 char *subject_pubkey_str;
550 char *zone_pubkey_str;
551
552 el = NULL;
553
554 ns = GNUNET_NAMESTORE_connect (cfg);
555 if (NULL == ns)
556 {
557 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
558 _ ("Failed to connect to namestore\n"));
559 GNUNET_SCHEDULER_shutdown ();
560 return;
561 }
562
563 if (NULL == ego)
564 {
565 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
566 _("Ego does not exist!\n"));
567 GNUNET_SCHEDULER_shutdown ();
568 return;
569 }
570
571 // Key handling
572 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
573
574 if (GNUNET_GNSRECORD_TYPE_DELEGATE == type)
575 {
576 // Parse import
577 cred = GNUNET_ABD_delegate_from_string (import);
578
579 if (NULL == cred)
580 {
581 fprintf (stderr,
582 "%s is not a valid credential\n", import);
583 GNUNET_SCHEDULER_shutdown();
584 return;
585 }
586
587 // Get import subject public key string
588 subject_pubkey_str =
589 GNUNET_CRYPTO_public_key_to_string (&cred->subject_key);
590
591 // Get zone public key string
592 GNUNET_IDENTITY_ego_get_public_key (ego, &zone_pubkey);
593 zone_pubkey_str =
594 GNUNET_CRYPTO_public_key_to_string (&zone_pubkey);
595
596 // Check if the subject key in the signed import matches the zone's key it is issued to
597 if (strcmp (zone_pubkey_str, subject_pubkey_str) != 0)
598 {
599 fprintf (stderr,
600 "Import signed delegate does not match this ego's public key.\n");
601 GNUNET_free (cred);
602 GNUNET_SCHEDULER_shutdown ();
603 return;
604 }
605
606 // Expiration
607 etime = cred->expiration.abs_value_us;
608 etime_is_rel = GNUNET_NO;
609
610 // Prepare the data to be store in the record
611 data_size = GNUNET_ABD_delegate_serialize (cred, (char **) &data);
612 GNUNET_free (cred);
613 }
614 else
615 {
616 // For all other types e.g. GNUNET_GNSRECORD_TYPE_ATTRIBUTE
617 if (GNUNET_OK !=
618 GNUNET_GNSRECORD_string_to_value (type, subject, &data, &data_size))
619 {
620 if (typestring == NULL)
621 {
622 fputs ("Value for unknown record type not well-formed.\n", stderr);
623 }
624 else if (subject == NULL)
625 {
626 fprintf (stderr,
627 "Value for record type `%s' not well-formed.\n",
628 typestring);
629 }
630 else
631 {
632 fprintf (stderr,
633 "Value `%s' invalid for record type `%s'\n",
634 subject,
635 typestring);
636 }
637 GNUNET_SCHEDULER_shutdown ();
638 return;
639 }
640
641 // Take care of expiration
642 if (NULL == expiration)
643 {
644 fprintf (stderr, "Missing option -e for operation 'create'\n");
645 GNUNET_SCHEDULER_shutdown ();
646 return;
647 }
648 if (GNUNET_OK != parse_expiration (expiration, &etime_is_rel, &etime))
649 {
650 fprintf (stderr, "Invalid time format `%s'\n", expiration);
651 GNUNET_SCHEDULER_shutdown ();
652 return;
653 }
654 }
655
656 // Start lookup
657 add_qe = GNUNET_NAMESTORE_records_lookup (ns,
658 &zone_pkey,
659 record_label,
660 &error_cb,
661 NULL,
662 &get_existing_record,
663 NULL);
664 return;
665}
666
667
668static void
669sign_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
670{
671 const struct GNUNET_CRYPTO_PrivateKey *privkey;
672 struct GNUNET_ABD_Delegate *dele;
673 struct GNUNET_TIME_Absolute etime_abs;
674 char *res;
675
676 el = NULL;
677
678 // work on expiration time
679 if (NULL == expiration)
680 {
681 fprintf (stderr, "Please specify a TTL\n");
682 GNUNET_SCHEDULER_shutdown ();
683 return;
684 }
685 else if (GNUNET_OK !=
686 GNUNET_STRINGS_fancy_time_to_absolute (expiration, &etime_abs))
687 {
688 fprintf (stderr,
689 "%s is not a valid ttl! Only absolute times are accepted!\n",
690 expiration);
691 GNUNET_SCHEDULER_shutdown ();
692 return;
693 }
694
695 // If contains a space - split it by the first space only - assume first entry is subject followed by attribute(s)
696 char *subject_pubkey_str;
697 char *subject_attr = NULL;
698 char *token;
699
700 // Subject Public Key
701 token = strtok (subject, " ");
702 subject_pubkey_str = token;
703 // Subject Attribute(s)
704 token = strtok (NULL, " ");
705 if (NULL != token)
706 {
707 subject_attr = token;
708 }
709
710 // work on keys
711 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
712
713 if (NULL == subject_pubkey_str)
714 {
715 fprintf (stderr,
716 "Subject pubkey not given\n");
717 GNUNET_SCHEDULER_shutdown ();
718 return;
719 }
720 if (GNUNET_OK !=
721 GNUNET_CRYPTO_public_key_from_string (subject_pubkey_str,
722 &subject_pkey))
723 {
724 fprintf (stderr,
725 "Subject public key `%s' is not well-formed\n",
726 subject_pubkey_str);
727 GNUNET_SCHEDULER_shutdown ();
728 return;
729 }
730
731 // Sign delegate
732 dele = GNUNET_ABD_delegate_issue (privkey,
733 &subject_pkey,
734 issuer_attr,
735 subject_attr,
736 &etime_abs);
737 res = GNUNET_ABD_delegate_to_string (dele);
738 GNUNET_free (dele);
739 printf ("%s\n", res);
740
741 GNUNET_free (ego_name);
742 ego_name = NULL;
743
744 GNUNET_SCHEDULER_shutdown ();
745}
746
747
748/**
749 * Main function that will be run.
750 *
751 * @param cls closure
752 * @param args remaining command-line arguments
753 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
754 * @param c configuration
755 */
756static void
757run (void *cls,
758 char *const *args,
759 const char *cfgfile,
760 const struct GNUNET_CONFIGURATION_Handle *c)
761{
762 cfg = c;
763
764 tt = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, NULL);
765 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
766
767 // Check relevant cmdline parameters
768 if (GNUNET_YES == create_is)
769 {
770 if (NULL == ego_name)
771 {
772 fprintf (stderr, "Missing option '-ego'\n");
773 GNUNET_SCHEDULER_shutdown ();
774 return;
775 }
776 if (NULL == issuer_attr)
777 {
778 fprintf (stderr, "Missing option '-attribute' for issuer attribute\n");
779 GNUNET_SCHEDULER_shutdown ();
780 return;
781 }
782 if (NULL == subject)
783 {
784 fprintf (stderr, "Missing option -subject for operation 'create'.'\n");
785 GNUNET_SCHEDULER_shutdown ();
786 return;
787 }
788
789 // Lookup ego, on success call store_cb and store as ATTRIBUTE type
790 type = GNUNET_GNSRECORD_TYPE_ATTRIBUTE;
791 record_label = issuer_attr;
792 el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &store_cb, (void *) cfg);
793 return;
794 }
795
796 if (GNUNET_YES == create_ss)
797 {
798
799 // check if signed parameter has been passed in cmd line call
800 if (NULL == import)
801 {
802 fprintf (stderr, "'import' required\n");
803 GNUNET_SCHEDULER_shutdown ();
804 return;
805 }
806
807 type = GNUNET_GNSRECORD_TYPE_DELEGATE;
808 record_label = GNUNET_GNS_EMPTY_LABEL_AT;
809 // Store subject side
810 el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &store_cb, (void *) cfg);
811
812 return;
813 }
814
815 if (GNUNET_YES == sign_ss)
816 {
817 if (NULL == ego_name)
818 {
819 fprintf (stderr, "ego required\n");
820 GNUNET_SCHEDULER_shutdown ();
821 return;
822 }
823 if (NULL == subject)
824 {
825 fprintf (stderr, "Subject public key needed\n");
826 GNUNET_SCHEDULER_shutdown ();
827 return;
828 }
829
830 // lookup ego and call function sign_cb on success
831 el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &sign_cb, (void *) cfg);
832 return;
833 }
834
835 if ((GNUNET_NO == forward) && (GNUNET_NO == backward))
836 {
837 // set default: bidirectional
838 forward = GNUNET_YES;
839 backward = GNUNET_YES;
840 }
841 if (GNUNET_YES == forward)
842 direction |= GNUNET_ABD_FLAG_FORWARD;
843 if (GNUNET_YES == backward)
844 direction |= GNUNET_ABD_FLAG_BACKWARD;
845
846 if (GNUNET_YES == collect)
847 {
848 if (NULL == issuer_key)
849 {
850 fprintf (stderr, _ ("Issuer public key not well-formed\n"));
851 GNUNET_SCHEDULER_shutdown ();
852 return;
853 }
854
855 abd = GNUNET_ABD_connect (cfg);
856
857 if (NULL == abd)
858 {
859 fprintf (stderr, _ ("Failed to connect to ABD\n"));
860 GNUNET_SCHEDULER_shutdown ();
861 return;
862 }
863 if (NULL == issuer_attr)
864 {
865 fprintf (stderr, _ ("You must provide issuer the attribute\n"));
866 GNUNET_SCHEDULER_shutdown ();
867 return;
868 }
869
870 if (NULL == ego_name)
871 {
872 fprintf (stderr, _ ("ego required\n"));
873 GNUNET_SCHEDULER_shutdown ();
874 return;
875 }
876 el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg);
877 return;
878 }
879
880 if (NULL == subject)
881 {
882 fprintf (stderr, _ ("Subject public key needed\n"));
883 GNUNET_SCHEDULER_shutdown ();
884 return;
885 }
886 if (GNUNET_OK != GNUNET_CRYPTO_public_key_from_string (subject,
887 &subject_pkey))
888 {
889 fprintf (stderr,
890 _ ("Subject public key `%s' is not well-formed\n"),
891 subject);
892 GNUNET_SCHEDULER_shutdown ();
893 return;
894 }
895
896 if (GNUNET_YES == verify)
897 {
898 if (NULL == issuer_key)
899 {
900 fprintf (stderr, _ ("Issuer public key not well-formed\n"));
901 GNUNET_SCHEDULER_shutdown ();
902 return;
903 }
904 if (GNUNET_OK !=
905 GNUNET_CRYPTO_public_key_from_string (issuer_key,
906 &issuer_pkey))
907 {
908 fprintf (stderr,
909 _ ("Issuer public key `%s' is not well-formed\n"),
910 issuer_key);
911 GNUNET_SCHEDULER_shutdown ();
912 return;
913 }
914 abd = GNUNET_ABD_connect (cfg);
915
916 if (NULL == abd)
917 {
918 fprintf (stderr, _ ("Failed to connect to ABD\n"));
919 GNUNET_SCHEDULER_shutdown ();
920 return;
921 }
922 if ((NULL == issuer_attr) || (NULL == subject_delegate))
923 {
924 fprintf (stderr, _ ("You must provide issuer and subject attributes\n"));
925 GNUNET_SCHEDULER_shutdown ();
926 return;
927 }
928
929 // Subject credentials are comma separated
930 char *tmp = GNUNET_strdup (subject_delegate);
931 char *tok = strtok (tmp, ",");
932 if (NULL == tok)
933 {
934 fprintf (stderr, "Invalid subject credentials\n");
935 GNUNET_free (tmp);
936 GNUNET_SCHEDULER_shutdown ();
937 return;
938 }
939 int count = 1;
940 int i;
941 while (NULL != (tok = strtok (NULL, ",")))
942 count++;
943 struct GNUNET_ABD_Delegate*delegates =
944 GNUNET_malloc (sizeof(*delegates) * count);
945 struct GNUNET_ABD_Delegate *dele;
946 GNUNET_free (tmp);
947 tmp = GNUNET_strdup (subject_delegate);
948 tok = strtok (tmp, ",");
949 for (i = 0; i < count; i++)
950 {
951 dele = GNUNET_ABD_delegate_from_string (tok);
952 GNUNET_memcpy (&delegates[i],
953 dele,
954 sizeof (struct GNUNET_ABD_Delegate));
955 delegates[i].issuer_attribute = GNUNET_strdup (dele->issuer_attribute);
956 tok = strtok (NULL, ",");
957 GNUNET_free (dele);
958 }
959
960 verify_request = GNUNET_ABD_verify (abd,
961 &issuer_pkey,
962 issuer_attr,
963 &subject_pkey,
964 count,
965 delegates,
966 direction,
967 &handle_verify_result,
968 NULL,
969 &handle_intermediate_result,
970 NULL);
971 for (i = 0; i < count; i++)
972 {
973 GNUNET_free_nz ((char *) delegates[i].issuer_attribute);
974 delegates[i].issuer_attribute = NULL;
975 }
976 GNUNET_free (tmp);
977 GNUNET_free (delegates);
978 }
979 else
980 {
981 fprintf (stderr,
982 _ (
983 "Please specify name to lookup, subject key and issuer key!\n"));
984 GNUNET_SCHEDULER_shutdown ();
985 }
986 return;
987}
988
989
990/**
991 * The main function for gnunet-gns.
992 *
993 * @param argc number of arguments from the command line
994 * @param argv command line arguments
995 * @return 0 ok, 1 on error
996 */
997int
998main (int argc, char *const *argv)
999{
1000 struct GNUNET_GETOPT_CommandLineOption options[] =
1001 {GNUNET_GETOPT_option_flag ('V',
1002 "verify",
1003 gettext_noop (
1004 "verify credential against attribute"),
1005 &verify),
1006 GNUNET_GETOPT_option_string (
1007 's',
1008 "subject",
1009 "PKEY",
1010 gettext_noop (
1011 "The public key of the subject to lookup the"
1012 "credential for, or for issuer side storage: subject and its attributes"),
1013 &subject),
1014 GNUNET_GETOPT_option_string (
1015 'd',
1016 "delegate",
1017 "DELE",
1018 gettext_noop ("The private, signed delegate presented by the subject"),
1019 &subject_delegate),
1020 GNUNET_GETOPT_option_string (
1021 'i',
1022 "issuer",
1023 "PKEY",
1024 gettext_noop (
1025 "The public key of the authority to verify the credential against"),
1026 &issuer_key),
1027 GNUNET_GETOPT_option_string ('e',
1028 "ego",
1029 "EGO",
1030 gettext_noop ("The ego/zone name to use"),
1031 &ego_name),
1032 GNUNET_GETOPT_option_string (
1033 'a',
1034 "attribute",
1035 "ATTR",
1036 gettext_noop ("The issuer attribute to verify against or to issue"),
1037 &issuer_attr),
1038 GNUNET_GETOPT_option_string ('T',
1039 "ttl",
1040 "EXP",
1041 gettext_noop (
1042 "The time to live for the credential."
1043 "e.g. 5m, 6h, \"1990-12-30 12:00:00\""),
1044 &expiration),
1045 GNUNET_GETOPT_option_flag ('g',
1046 "collect",
1047 gettext_noop ("collect credentials"),
1048 &collect),
1049 GNUNET_GETOPT_option_flag ('U',
1050 "createIssuerSide",
1051 gettext_noop (
1052 "Create and issue a credential issuer side."),
1053 &create_is),
1054 GNUNET_GETOPT_option_flag ('C',
1055 "createSubjectSide",
1056 gettext_noop (
1057 "Issue a credential subject side."),
1058 &create_ss),
1059 GNUNET_GETOPT_option_flag (
1060 'S',
1061 "signSubjectSide",
1062 gettext_noop ("Create, sign and return a credential subject side."),
1063 &sign_ss),
1064 GNUNET_GETOPT_option_string (
1065 'x',
1066 "import",
1067 "IMP",
1068 gettext_noop (
1069 "Import signed credentials that should be issued to a zone/ego"),
1070 &import),
1071 GNUNET_GETOPT_option_flag ('P',
1072 "private",
1073 gettext_noop ("Create private record entry."),
1074 &is_private),
1075 GNUNET_GETOPT_option_flag (
1076 'F',
1077 "forward",
1078 gettext_noop (
1079 "Indicates that the collect/verify process is done via forward search."),
1080 &forward),
1081 GNUNET_GETOPT_option_flag (
1082 'B',
1083 "backward",
1084 gettext_noop (
1085 "Indicates that the collect/verify process is done via forward search."),
1086 &backward),
1087 GNUNET_GETOPT_OPTION_END};
1088
1089
1090 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1091 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1092 return 2;
1093
1094 GNUNET_log_setup ("gnunet-abd", "WARNING", NULL);
1095 if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
1096 argv,
1097 "gnunet-abd",
1098 _ ("GNUnet abd resolver tool"),
1099 options,
1100 &run,
1101 NULL))
1102 ret = 1;
1103 GNUNET_free_nz ((void *) argv);
1104 return ret;
1105}
1106
1107
1108/* end of gnunet-abd.c */
diff --git a/src/abd/gnunet-service-abd.c b/src/abd/gnunet-service-abd.c
deleted file mode 100644
index 5cbc105f6..000000000
--- a/src/abd/gnunet-service-abd.c
+++ /dev/null
@@ -1,1778 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011-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 abd/gnunet-service-abd.c
22 * @brief GNUnet Credential Service (main service)
23 * @author Martin Schanzenbach
24 */
25#include "platform.h"
26
27#include "gnunet_util_lib.h"
28
29#include "abd.h"
30#include "abd_serialization.h"
31#include "gnunet_abd_service.h"
32#include "gnunet_protocols.h"
33#include "gnunet_signatures.h"
34#include "gnunet_statistics_service.h"
35#include <gnunet_gns_service.h>
36#include <gnunet_gnsrecord_lib.h>
37#include <gnunet_identity_service.h>
38#include <gnunet_namestore_service.h>
39
40
41#define GNUNET_ABD_MAX_LENGTH 255
42
43struct VerifyRequestHandle;
44
45struct DelegationSetQueueEntry;
46
47
48struct DelegationChainEntry
49{
50 /**
51 * DLL
52 */
53 struct DelegationChainEntry *next;
54
55 /**
56 * DLL
57 */
58 struct DelegationChainEntry *prev;
59
60 /**
61 * The issuer
62 */
63 struct GNUNET_CRYPTO_PublicKey issuer_key;
64
65 /**
66 * The subject
67 */
68 struct GNUNET_CRYPTO_PublicKey subject_key;
69
70 /**
71 * The issued attribute
72 */
73 char *issuer_attribute;
74
75 /**
76 * The delegated attribute
77 */
78 char *subject_attribute;
79};
80
81/**
82 * DLL for record
83 */
84struct DelegateRecordEntry
85{
86 /**
87 * DLL
88 */
89 struct DelegateRecordEntry *next;
90
91 /**
92 * DLL
93 */
94 struct DelegateRecordEntry *prev;
95
96 /**
97 * Number of references in delegation chains
98 */
99 uint32_t refcount;
100
101 /**
102 * Payload
103 */
104 struct GNUNET_ABD_Delegate *delegate;
105};
106
107/**
108 * DLL used for delegations
109 * Used for OR delegations
110 */
111struct DelegationQueueEntry
112{
113 /**
114 * DLL
115 */
116 struct DelegationQueueEntry *next;
117
118 /**
119 * DLL
120 */
121 struct DelegationQueueEntry *prev;
122
123 /**
124 * Parent set
125 */
126 struct DelegationSetQueueEntry *parent_set;
127
128 /**
129 * Required solutions
130 */
131 uint32_t required_solutions;
132};
133
134/**
135 * DLL for delegation sets
136 * Used for AND delegation set
137 */
138struct DelegationSetQueueEntry
139{
140 /**
141 * DLL
142 */
143 struct DelegationSetQueueEntry *next;
144
145 /**
146 * DLL
147 */
148 struct DelegationSetQueueEntry *prev;
149
150 /**
151 * GNS handle
152 */
153 struct GNUNET_GNS_LookupRequest *lookup_request;
154
155 /**
156 * Verify handle
157 */
158 struct VerifyRequestHandle *handle;
159
160 /**
161 * Parent attribute delegation
162 */
163 struct DelegationQueueEntry *parent;
164
165 /**
166 * Issuer key
167 */
168 struct GNUNET_CRYPTO_PublicKey *issuer_key;
169
170 /**
171 * Queue entries of this set
172 */
173 struct DelegationQueueEntry *queue_entries_head;
174
175 /**
176 * Queue entries of this set
177 */
178 struct DelegationQueueEntry *queue_entries_tail;
179
180 /**
181 * Parent QueueEntry
182 */
183 struct DelegationQueueEntry *parent_queue_entry;
184
185 /**
186 * Issuer attribute delegated to
187 */
188 char *issuer_attribute;
189
190 /**
191 * The current attribute to look up
192 */
193 char *lookup_attribute;
194
195 /**
196 * Trailing attribute context
197 */
198 char *attr_trailer;
199
200 /**
201 * Still to resolve delegation as string
202 */
203 char *unresolved_attribute_delegation;
204
205 /**
206 * The delegation chain entry
207 */
208 struct DelegationChainEntry *delegation_chain_entry;
209
210 /**
211 * True if added by backward resolution
212 */
213 bool from_bw;
214};
215
216
217/**
218 * Handle to a lookup operation from api
219 */
220struct VerifyRequestHandle
221{
222 /**
223 * True if created by a collect request.
224 */
225 bool is_collect;
226 /**
227 * We keep these in a DLL.
228 */
229 struct VerifyRequestHandle *next;
230
231 /**
232 * We keep these in a DLL.
233 */
234 struct VerifyRequestHandle *prev;
235
236 /**
237 * Handle to the requesting client
238 */
239 struct GNUNET_SERVICE_Client *client;
240
241 /**
242 * Size of delegation tree
243 */
244 uint32_t delegation_chain_size;
245
246 /**
247 * Children of this attribute
248 */
249 struct DelegationChainEntry *delegation_chain_head;
250
251 /**
252 * Children of this attribute
253 */
254 struct DelegationChainEntry *delegation_chain_tail;
255
256 /**
257 * List for bidirectional matching
258 */
259 struct DelegationSetQueueEntry *dsq_head;
260
261 /**
262 * List for bidirectional matching
263 */
264 struct DelegationSetQueueEntry *dsq_tail;
265
266 /**
267 * Issuer public key
268 */
269 struct GNUNET_CRYPTO_PublicKey issuer_key;
270
271 /**
272 * Issuer attribute
273 */
274 char *issuer_attribute;
275
276 /**
277 * Subject public key
278 */
279 struct GNUNET_CRYPTO_PublicKey subject_key;
280
281 /**
282 * Delegate DLL
283 */
284 struct DelegateRecordEntry *del_chain_head;
285
286 /**
287 * Delegate DLL
288 */
289 struct DelegateRecordEntry *del_chain_tail;
290
291 /**
292 * Delegate DLL size
293 */
294 uint32_t del_chain_size;
295
296 /**
297 * Current Delegation Pointer
298 */
299 struct DelegationQueueEntry *current_delegation;
300
301 /**
302 * request id
303 */
304 uint32_t request_id;
305
306 /**
307 * Pending lookups
308 */
309 uint64_t pending_lookups;
310
311 /**
312 * Direction of the resolution algo
313 */
314 enum GNUNET_ABD_AlgoDirectionFlags resolution_algo;
315
316 /**
317 * Delegate iterator for lookup
318 */
319 struct GNUNET_NAMESTORE_QueueEntry *dele_qe;
320};
321
322
323/**
324 * Head of the DLL.
325 */
326static struct VerifyRequestHandle *vrh_head = NULL;
327
328/**
329 * Tail of the DLL.
330 */
331static struct VerifyRequestHandle *vrh_tail = NULL;
332
333/**
334 * Handle to the statistics service
335 */
336static struct GNUNET_STATISTICS_Handle *statistics;
337
338/**
339 * Handle to GNS service.
340 */
341static struct GNUNET_GNS_Handle *gns;
342
343/**
344 * Handle to namestore service
345 */
346static struct GNUNET_NAMESTORE_Handle *namestore;
347
348static void
349print_deleset (struct DelegationSetQueueEntry *dsentry, char *text)
350{
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
352 "%s %s.%s <- %s.%s\n",
353 text,
354 GNUNET_CRYPTO_public_key_to_string (
355 &dsentry->delegation_chain_entry->issuer_key),
356 dsentry->delegation_chain_entry->issuer_attribute,
357 GNUNET_CRYPTO_public_key_to_string (
358 &dsentry->delegation_chain_entry->subject_key),
359 dsentry->delegation_chain_entry->subject_attribute);
360}
361
362
363static void
364cleanup_dsq_entry (struct DelegationSetQueueEntry *ds_entry)
365{
366 GNUNET_free (ds_entry->issuer_key);
367 GNUNET_free (ds_entry->issuer_attribute);
368 GNUNET_free (ds_entry->attr_trailer);
369 // those fields are only set/used in bw search
370 if (ds_entry->from_bw)
371 {
372 GNUNET_free (ds_entry->lookup_attribute);
373 GNUNET_free (ds_entry->unresolved_attribute_delegation);
374 }
375 if (NULL != ds_entry->lookup_request)
376 {
377 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
378 ds_entry->lookup_request = NULL;
379 }
380 if (NULL != ds_entry->delegation_chain_entry)
381 {
382 GNUNET_free (
383 ds_entry->delegation_chain_entry->subject_attribute);
384 GNUNET_free (ds_entry->delegation_chain_entry->issuer_attribute);
385 GNUNET_free (ds_entry->delegation_chain_entry);
386 }
387 // Free DQ entries
388 for (struct DelegationQueueEntry *dq_entry = ds_entry->queue_entries_head;
389 NULL != ds_entry->queue_entries_head;
390 dq_entry = ds_entry->queue_entries_head)
391 {
392 GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head,
393 ds_entry->queue_entries_tail,
394 dq_entry);
395 GNUNET_free (dq_entry);
396 }
397 GNUNET_free (ds_entry);
398}
399
400
401static void
402cleanup_handle (struct VerifyRequestHandle *vrh)
403{
404 struct DelegateRecordEntry *del_entry;
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
406
407 if (NULL != vrh->dsq_head)
408 {
409 for (struct DelegationSetQueueEntry *ds_entry = vrh->dsq_head; NULL !=
410 vrh->dsq_head;
411 ds_entry = vrh->dsq_head)
412 {
413 GNUNET_CONTAINER_DLL_remove (vrh->dsq_head, vrh->dsq_tail, ds_entry);
414 cleanup_dsq_entry (ds_entry);
415 }
416 }
417 if (NULL != vrh->del_chain_head)
418 {
419 for (del_entry = vrh->del_chain_head; NULL != vrh->del_chain_head;
420 del_entry = vrh->del_chain_head)
421 {
422 GNUNET_CONTAINER_DLL_remove (vrh->del_chain_head,
423 vrh->del_chain_tail,
424 del_entry);
425 GNUNET_free (del_entry->delegate);
426 GNUNET_free (del_entry);
427 }
428 }
429 GNUNET_free (vrh->issuer_attribute);
430 GNUNET_free (vrh);
431}
432
433
434static void
435shutdown_task (void *cls)
436{
437 struct VerifyRequestHandle *vrh;
438
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
440
441 while (NULL != (vrh = vrh_head))
442 {
443 // ABD_resolver_lookup_cancel (clh->lookup);
444 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
445 cleanup_handle (vrh);
446 }
447
448 if (NULL != gns)
449 {
450 GNUNET_GNS_disconnect (gns);
451 gns = NULL;
452 }
453 if (NULL != namestore)
454 {
455 GNUNET_NAMESTORE_disconnect (namestore);
456 namestore = NULL;
457 }
458 if (NULL != statistics)
459 {
460 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
461 statistics = NULL;
462 }
463}
464
465
466static void
467send_intermediate_response (struct VerifyRequestHandle *vrh, struct
468 DelegationChainEntry *ch_entry, bool is_bw)
469{
470 struct DelegationChainIntermediateMessage *rmsg;
471 struct GNUNET_MQ_Envelope *env;
472 struct GNUNET_ABD_Delegation *dd;
473 size_t size;
474
475 // Don't report immediate results during collect
476 if (vrh->is_collect)
477 return;
478
479 dd = GNUNET_new (struct GNUNET_ABD_Delegation);
480 dd->issuer_key = ch_entry->issuer_key;
481 dd->subject_key = ch_entry->subject_key;
482 dd->issuer_attribute = ch_entry->issuer_attribute;
483 dd->issuer_attribute_len = strlen (ch_entry->issuer_attribute) + 1;
484 dd->subject_attribute_len = 0;
485 dd->subject_attribute = NULL;
486 if (NULL != ch_entry->subject_attribute)
487 {
488 dd->subject_attribute = ch_entry->subject_attribute;
489 dd->subject_attribute_len = strlen (ch_entry->subject_attribute) + 1;
490 }
491
492
493 size = GNUNET_ABD_delegation_chain_get_size (1,
494 dd,
495 0,
496 NULL);
497
498 env = GNUNET_MQ_msg_extra (rmsg,
499 size,
500 GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT);
501 // Assign id so that client can find associated request
502 rmsg->id = vrh->request_id;
503 rmsg->is_bw = htons (is_bw);
504 rmsg->size = htonl (size);
505
506 GNUNET_assert (
507 -1 != GNUNET_ABD_delegation_chain_serialize (1,
508 dd,
509 0,
510 NULL,
511 size,
512 (char *) &rmsg[1]));
513 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env);
514
515 GNUNET_free (dd);
516}
517
518
519static void
520send_lookup_response (struct VerifyRequestHandle *vrh)
521{
522 struct GNUNET_MQ_Envelope *env;
523 struct DelegationChainResultMessage *rmsg;
524 struct DelegationChainEntry *dce;
525 struct GNUNET_ABD_Delegation dd[vrh->delegation_chain_size];
526 struct GNUNET_ABD_Delegate dele[vrh->del_chain_size];
527 struct DelegateRecordEntry *del;
528 struct DelegateRecordEntry *tmp;
529 size_t size;
530
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
532 dce = vrh->delegation_chain_head;
533 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++)
534 {
535 dd[i].issuer_key = dce->issuer_key;
536 dd[i].subject_key = dce->subject_key;
537 dd[i].issuer_attribute = dce->issuer_attribute;
538 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1;
539 dd[i].subject_attribute_len = 0;
540 dd[i].subject_attribute = NULL;
541 if (NULL != dce->subject_attribute)
542 {
543 dd[i].subject_attribute = dce->subject_attribute;
544 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1;
545 }
546 dce = dce->next;
547 }
548
549 // Remove all not needed credentials
550 for (del = vrh->del_chain_head; NULL != del;)
551 {
552 if (del->refcount > 0)
553 {
554 del = del->next;
555 continue;
556 }
557 tmp = del;
558 del = del->next;
559 GNUNET_CONTAINER_DLL_remove (vrh->del_chain_head, vrh->del_chain_tail, tmp);
560 GNUNET_free (tmp->delegate);
561 GNUNET_free (tmp);
562 vrh->del_chain_size--;
563 }
564
565 // Get serialized record data
566 // Append at the end of rmsg
567 del = vrh->del_chain_head;
568 for (uint32_t i = 0; i < vrh->del_chain_size; i++)
569 {
570 dele[i].issuer_key = del->delegate->issuer_key;
571 dele[i].subject_key = del->delegate->subject_key;
572 dele[i].issuer_attribute_len = strlen (del->delegate->issuer_attribute) + 1;
573 dele[i].issuer_attribute = del->delegate->issuer_attribute;
574 dele[i].subject_attribute_len = del->delegate->subject_attribute_len;
575 dele[i].subject_attribute = del->delegate->subject_attribute;
576 dele[i].expiration = del->delegate->expiration;
577 dele[i].signature = del->delegate->signature;
578 del = del->next;
579 }
580 size =
581 GNUNET_ABD_delegation_chain_get_size (vrh->delegation_chain_size,
582 dd,
583 vrh->del_chain_size,
584 dele);
585 env = GNUNET_MQ_msg_extra (rmsg,
586 size,
587 GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT);
588 // Assign id so that client can find associated request
589 rmsg->id = vrh->request_id;
590 rmsg->d_count = htonl (vrh->delegation_chain_size);
591 rmsg->c_count = htonl (vrh->del_chain_size);
592
593 if (0 < vrh->del_chain_size)
594 rmsg->del_found = htonl (GNUNET_YES);
595 else
596 rmsg->del_found = htonl (GNUNET_NO);
597
598 GNUNET_assert (
599 -1 !=
600 GNUNET_ABD_delegation_chain_serialize (vrh->delegation_chain_size,
601 dd,
602 vrh->del_chain_size,
603 dele,
604 size,
605 (char *) &rmsg[1]));
606
607 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env);
608 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
609 cleanup_handle (vrh);
610 GNUNET_STATISTICS_update (statistics,
611 "Completed verifications",
612 1,
613 GNUNET_NO);
614}
615
616
617static char *
618partial_match (char *tmp_trail,
619 char *tmp_subattr,
620 char *parent_trail,
621 char *issuer_attribute)
622{
623 char *saveptr1, *saveptr2;
624 char *trail_token;
625 char *sub_token;
626 char *attr_trailer;
627
628 // tok both, parent->attr_trailer and del->sub_attr to see how far they match,
629 // take rest of parent trailer (only when del->sub_attr token is null), and
630 // create new/actual trailer with del->iss_attr
631 trail_token = strtok_r (tmp_trail, ".", &saveptr1);
632 sub_token = strtok_r (tmp_subattr, ".", &saveptr2);
633 while (NULL != trail_token && NULL != sub_token)
634 {
635 if (0 == strcmp (trail_token, sub_token))
636 {
637 // good, matches, remove
638 }
639 else
640 {
641 // not relevant for solving the chain, end for iteration here
642 return NULL;
643 }
644
645 trail_token = strtok_r (NULL, ".", &saveptr1);
646 sub_token = strtok_r (NULL, ".", &saveptr2);
647 }
648 // skip this entry and go to next for if:
649 // 1. at some point the attr of the trailer and the subject dont match
650 // 2. the trailer is NULL, but the subject has more attributes
651 // Reason: This will lead to "startzone.attribute" but we're looking for a solution
652 // for "<- startzone"
653 if (NULL == trail_token)
654 {
655 return NULL;
656 }
657
658 // do not have to check sub_token == NULL, if both would be NULL
659 // at the same time, the complete match part above should have triggered already
660
661 // otherwise, above while only ends when sub_token == NULL
662 GNUNET_asprintf (&attr_trailer, "%s", trail_token);
663 trail_token = strtok_r (NULL, ".", &saveptr1);
664 while (NULL != trail_token)
665 {
666 GNUNET_asprintf (&attr_trailer, "%s.%s", parent_trail, trail_token);
667 trail_token = strtok_r (NULL, ".", &saveptr1);
668 }
669 GNUNET_asprintf (&attr_trailer, "%s.%s", issuer_attribute, attr_trailer);
670 return attr_trailer;
671}
672
673
674static int
675handle_bidirectional_match (struct DelegationSetQueueEntry *actual_entry,
676 struct DelegationSetQueueEntry *match_entry,
677 struct VerifyRequestHandle *vrh)
678{
679 struct DelegationSetQueueEntry *old_fw_parent;
680 struct DelegationSetQueueEntry *fw_entry = actual_entry;
681 struct DelegationSetQueueEntry *last_entry = match_entry;
682 // parent fixing, combine backward and forward chain parts
683 while (NULL != fw_entry->parent_queue_entry)
684 {
685 old_fw_parent = fw_entry->parent_queue_entry->parent_set;
686 // set parent
687 fw_entry->parent_queue_entry->parent_set = last_entry;
688
689 last_entry = fw_entry;
690 fw_entry = old_fw_parent;
691 }
692 // set last entry of chain as actual_entry
693 // actual_entry = last_entry;
694 // set refcount, loop all delegations
695 for (struct DelegateRecordEntry *del_entry = vrh->del_chain_head;
696 del_entry != NULL;
697 del_entry = del_entry->next)
698 {
699 if (0 != memcmp (&last_entry->delegation_chain_entry->subject_key,
700 &del_entry->delegate->issuer_key,
701 sizeof (struct GNUNET_CRYPTO_PublicKey)))
702 continue;
703 if (0 != strcmp (last_entry->delegation_chain_entry->subject_attribute,
704 del_entry->delegate->issuer_attribute))
705 continue;
706
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found delegate.\n");
708 // increase refcount of the start delegation
709 del_entry->refcount++;
710 }
711 // backtrack
712 for (struct DelegationSetQueueEntry *tmp_set = last_entry;
713 NULL != tmp_set->parent_queue_entry;
714 tmp_set = tmp_set->parent_queue_entry->parent_set)
715 {
716 tmp_set->parent_queue_entry->required_solutions--;
717
718 // add new found entry to vrh
719 vrh->delegation_chain_size++;
720 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
721 vrh->delegation_chain_tail,
722 tmp_set->delegation_chain_entry);
723
724 // if one node on the path still needs solutions, this current
725 // patch cannot fulfill the conditions and therefore stops here
726 // however, it is in the vrh and can be used by the other paths
727 // related to this path/collection/verification
728 if (0 < tmp_set->parent_queue_entry->required_solutions)
729 {
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
731 "Chain requires more solutions, waiting...\n");
732 return GNUNET_NO;
733 }
734 }
735 return GNUNET_YES;
736}
737
738
739static void
740forward_resolution (void *cls,
741 uint32_t rd_count,
742 const struct GNUNET_GNSRECORD_Data *rd)
743{
744 struct VerifyRequestHandle *vrh;
745 struct DelegationSetQueueEntry *current_set;
746 struct DelegationSetQueueEntry *ds_entry;
747 struct DelegationQueueEntry *dq_entry;
748 struct GNUNET_ABD_Delegate *del;
749
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %d entries.\n", rd_count);
751
752 current_set = cls;
753 // set handle to NULL (as el = NULL)
754 current_set->lookup_request = NULL;
755 vrh = current_set->handle;
756 vrh->pending_lookups--;
757
758 // Loop record entries
759 for (uint32_t i = 0; i < rd_count; i++)
760 {
761 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type)
762 continue;
763
764 // Start deserialize into Delegate
765 del = GNUNET_ABD_delegate_deserialize (rd[i].data, rd[i].data_size);
766
767 if (NULL == del)
768 continue;
769
770 // Start: Create DQ Entry
771 dq_entry = GNUNET_new (struct DelegationQueueEntry);
772 // AND delegations are not possible, only 1 solution
773 dq_entry->required_solutions = 1;
774 dq_entry->parent_set = current_set;
775
776 // Insert it into the current set
777 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
778 current_set->queue_entries_tail,
779 dq_entry);
780
781 // Start: Create DS Entry
782 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
783 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
784 ds_entry->from_bw = false;
785
786 // (1) A.a <- A.b.c
787 // (2) A.b <- D.d
788 // (3) D.d <- E
789 // (4) E.c <- F.c
790 // (5) F.c <- G
791 // Possibilities:
792 // 1. complete match: trailer = 0, validate
793 // 2. partial match: replace
794 // 3. new solution: replace, add trailer
795
796 // At resolution chain start trailer of parent is NULL
797 if (NULL == current_set->attr_trailer)
798 {
799 // for (5) F.c <- G, remember .c when going upwards
800 ds_entry->attr_trailer = GNUNET_strdup (del->issuer_attribute);
801 }
802 else
803 {
804 if (0 == del->subject_attribute_len)
805 {
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: New solution\n");
807 // new solution
808 // create new trailer del->issuer_attribute, ds_entry->attr_trailer
809 GNUNET_asprintf (&ds_entry->attr_trailer,
810 "%s.%s",
811 del->issuer_attribute,
812 current_set->attr_trailer);
813 }
814 else if (0 == strcmp (del->subject_attribute, current_set->attr_trailer))
815 {
816 // complete match
817 // new trailer == issuer attribute (e.g. (5) to (4))
818 ds_entry->attr_trailer = GNUNET_strdup (del->issuer_attribute);
819 }
820 else
821 {
822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Partial match\n");
823 // partial match
824
825 char *trail = partial_match (GNUNET_strdup (current_set->attr_trailer),
826 GNUNET_strdup (del->subject_attribute),
827 current_set->attr_trailer,
828 GNUNET_strdup (del->issuer_attribute));
829
830 // if null: skip this record entry (reasons: mismatch or overmatch, both not relevant)
831 if (NULL == trail)
832 {
833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
834 "Entry not relevant, discarding: %s.%s <- %s.%s\n",
835 GNUNET_CRYPTO_public_key_to_string (
836 &del->issuer_key),
837 del->issuer_attribute,
838 GNUNET_CRYPTO_public_key_to_string (
839 &del->subject_key),
840 del->subject_attribute);
841 GNUNET_free (del);
842 continue;
843 }
844 else
845 ds_entry->attr_trailer = trail;
846 }
847 }
848
849
850 // Start: Credential Chain Entry
851 // issuer key is subject key, who needs to be contacted to resolve this (forward, therefore subject)
852 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
853 GNUNET_memcpy (ds_entry->issuer_key,
854 &del->subject_key,
855 sizeof (struct GNUNET_CRYPTO_PublicKey));
856
857 ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry);
858 ds_entry->delegation_chain_entry->subject_key = del->subject_key;
859 if (0 < del->subject_attribute_len)
860 ds_entry->delegation_chain_entry->subject_attribute =
861 GNUNET_strdup (del->subject_attribute);
862 ds_entry->delegation_chain_entry->issuer_key = del->issuer_key;
863 ds_entry->delegation_chain_entry->issuer_attribute =
864 GNUNET_strdup (del->issuer_attribute);
865
866 // Found new entry, repoting intermediate result
867 send_intermediate_response (vrh, ds_entry->delegation_chain_entry, false);
868
869 // current delegation as parent
870 ds_entry->parent_queue_entry = dq_entry;
871
872 // Check for solution
873 // if: issuer key we looking for
874 if (0 == memcmp (&del->issuer_key,
875 &vrh->issuer_key,
876 sizeof (struct GNUNET_CRYPTO_PublicKey)))
877 {
878 // if: issuer attr we looking for
879 if (0 == strcmp (del->issuer_attribute, vrh->issuer_attribute))
880 {
881 // if: complete match, meaning new trailer == issuer attr
882 if (0 == strcmp (vrh->issuer_attribute, ds_entry->attr_trailer))
883 {
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Solution\n");
885
886 // Add found solution into delegation_chain
887 struct DelegationSetQueueEntry *tmp_set;
888 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
889 tmp_set = tmp_set->parent_queue_entry->parent_set)
890 {
891 if (NULL != tmp_set->delegation_chain_entry)
892 {
893 vrh->delegation_chain_size++;
894 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
895 vrh->delegation_chain_tail,
896 tmp_set->delegation_chain_entry);
897 }
898 }
899
900 // Increase refcount for this delegate
901 for (struct DelegateRecordEntry *del_entry = vrh->del_chain_head;
902 del_entry != NULL;
903 del_entry = del_entry->next)
904 {
905 if (0 == memcmp (&del_entry->delegate->issuer_key,
906 &vrh->delegation_chain_head->subject_key,
907 sizeof (struct GNUNET_CRYPTO_PublicKey)))
908 {
909 if (0 == strcmp (del_entry->delegate->issuer_attribute,
910 vrh->delegation_chain_head->subject_attribute))
911 {
912 del_entry->refcount++;
913 }
914 }
915 }
916
917 send_lookup_response (vrh);
918 GNUNET_free (del);
919 return;
920 }
921 }
922 }
923
924 // Check for bidirectional crossmatch
925 for (struct DelegationSetQueueEntry *del_entry = vrh->dsq_head;
926 del_entry != NULL;
927 del_entry = del_entry->next)
928 {
929 // only check entries not by backward algorithm
930 if (del_entry->from_bw)
931 {
932 // key of list entry matches actual key
933 if (0 == memcmp (&del_entry->delegation_chain_entry->subject_key,
934 &ds_entry->delegation_chain_entry->issuer_key,
935 sizeof (struct GNUNET_CRYPTO_PublicKey)))
936 {
937 // compare entry subject attributes to this trailer (iss attr + old trailer)
938 if (0 == strcmp (del_entry->unresolved_attribute_delegation,
939 ds_entry->attr_trailer))
940 {
941 print_deleset (del_entry, "Forward:");
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 "Forward: Found match with above!\n");
944
945 GNUNET_free (del);
946 // one node on the path still needs solutions: return
947 if (GNUNET_NO ==
948 handle_bidirectional_match (ds_entry, del_entry, vrh))
949 return;
950
951 send_lookup_response (vrh);
952 return;
953 }
954 }
955 }
956 }
957
958 // Starting a new GNS lookup
959 vrh->pending_lookups++;
960 ds_entry->handle = vrh;
961
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "Starting to look up trailer %s in zone %s\n",
964 ds_entry->attr_trailer,
965 GNUNET_CRYPTO_public_key_to_string (&del->issuer_key));
966
967 ds_entry->lookup_request =
968 GNUNET_GNS_lookup (gns,
969 GNUNET_GNS_EMPTY_LABEL_AT,
970 &del->issuer_key,
971 GNUNET_GNSRECORD_TYPE_DELEGATE,
972 GNUNET_GNS_LO_DEFAULT,
973 &forward_resolution,
974 ds_entry);
975 GNUNET_free (del);
976 }
977
978 if (0 == vrh->pending_lookups)
979 {
980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
981 send_lookup_response (vrh);
982 return;
983 }
984}
985
986
987static void
988backward_resolution (void *cls,
989 uint32_t rd_count,
990 const struct GNUNET_GNSRECORD_Data *rd)
991{
992 struct VerifyRequestHandle *vrh;
993 const struct GNUNET_ABD_DelegationRecord *sets;
994 struct DelegateRecordEntry *del_pointer;
995 struct DelegationSetQueueEntry *current_set;
996 struct DelegationSetQueueEntry *ds_entry;
997 struct DelegationSetQueueEntry *tmp_set;
998 struct DelegationQueueEntry *dq_entry;
999 char *expanded_attr;
1000 char *lookup_attribute;
1001
1002 current_set = cls;
1003 current_set->lookup_request = NULL;
1004 vrh = current_set->handle;
1005 vrh->pending_lookups--;
1006
1007 // Each OR
1008 for (uint32_t i = 0; i < rd_count; i++)
1009 {
1010 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
1011 continue;
1012
1013 sets = rd[i].data;
1014 struct GNUNET_ABD_DelegationSet set[ntohl (sets->set_count)];
1015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1016 "Found new attribute delegation with %d sets. Creating new Job...\n",
1017 ntohl (sets->set_count));
1018
1019 if (GNUNET_OK !=
1020 GNUNET_ABD_delegation_set_deserialize (GNUNET_ntohll (
1021 sets->data_size),
1022 (const char *) &sets[1],
1023 ntohl (sets->set_count),
1024 set))
1025 {
1026 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
1027 continue;
1028 }
1029 dq_entry = GNUNET_new (struct DelegationQueueEntry);
1030 dq_entry->required_solutions = ntohl (sets->set_count);
1031 dq_entry->parent_set = current_set;
1032
1033 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
1034 current_set->queue_entries_tail,
1035 dq_entry);
1036 // Each AND
1037 for (uint32_t j = 0; j < ntohl (sets->set_count); j++)
1038 {
1039 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
1040 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
1041 ds_entry->from_bw = true;
1042
1043 if (NULL != current_set->attr_trailer)
1044 {
1045 if (0 == set[j].subject_attribute_len)
1046 {
1047 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
1048 }
1049 else
1050 {
1051 GNUNET_asprintf (&expanded_attr,
1052 "%s.%s",
1053 set[j].subject_attribute,
1054 current_set->attr_trailer);
1055 }
1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
1057 ds_entry->unresolved_attribute_delegation = expanded_attr;
1058 }
1059 else
1060 {
1061 if (0 != set[j].subject_attribute_len)
1062 {
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1064 "Not Expanding %s\n",
1065 set[j].subject_attribute);
1066 ds_entry->unresolved_attribute_delegation =
1067 GNUNET_strdup (set[j].subject_attribute);
1068 }
1069 }
1070
1071 // Add a credential chain entry
1072 ds_entry->delegation_chain_entry =
1073 GNUNET_new (struct DelegationChainEntry);
1074 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
1075 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
1076 GNUNET_memcpy (ds_entry->issuer_key,
1077 &set[j].subject_key,
1078 sizeof (struct GNUNET_CRYPTO_PublicKey));
1079 if (0 < set[j].subject_attribute_len)
1080 ds_entry->delegation_chain_entry->subject_attribute =
1081 GNUNET_strdup (set[j].subject_attribute);
1082 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
1083 ds_entry->delegation_chain_entry->issuer_attribute =
1084 GNUNET_strdup (current_set->lookup_attribute);
1085
1086 // Found new entry, repoting intermediate result
1087 send_intermediate_response (vrh, ds_entry->delegation_chain_entry, true);
1088
1089 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
1090
1091 /**
1092 * Check if this delegation already matches one of our credentials
1093 */
1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
1095
1096 for (del_pointer = vrh->del_chain_head; del_pointer != NULL;
1097 del_pointer = del_pointer->next)
1098 {
1099 // If key and attribute match credential: continue and backtrack
1100 if (0 != memcmp (&set[j].subject_key,
1101 &del_pointer->delegate->issuer_key,
1102 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1103 continue;
1104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1105 "Checking if %s matches %s\n",
1106 ds_entry->unresolved_attribute_delegation,
1107 del_pointer->delegate->issuer_attribute);
1108
1109 if (0 != strcmp (ds_entry->unresolved_attribute_delegation,
1110 del_pointer->delegate->issuer_attribute))
1111 continue;
1112
1113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
1114 // increase refcount of the start delegation
1115 del_pointer->refcount++;
1116
1117 // Backtrack
1118 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
1119 tmp_set = tmp_set->parent_queue_entry->parent_set)
1120 {
1121 tmp_set->parent_queue_entry->required_solutions--;
1122 if (NULL != tmp_set->delegation_chain_entry)
1123 {
1124 vrh->delegation_chain_size++;
1125 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
1126 vrh->delegation_chain_tail,
1127 tmp_set->delegation_chain_entry);
1128 }
1129 if (0 < tmp_set->parent_queue_entry->required_solutions)
1130 break;
1131 }
1132
1133 // if the break above is not called the condition of the for is met
1134 if (NULL == tmp_set->parent_queue_entry)
1135 {
1136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All solutions found\n");
1137 // Found match
1138 send_lookup_response (vrh);
1139 return;
1140 }
1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not all solutions found yet.\n");
1142 continue;
1143 }
1144
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1146 "Building new lookup request from %s\n",
1147 ds_entry->unresolved_attribute_delegation);
1148 // Continue with next/new backward resolution
1149 char issuer_attribute_name[strlen (
1150 ds_entry->unresolved_attribute_delegation)
1151 + 1];
1152 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
1153 char *next_attr = strtok (issuer_attribute_name, ".");
1154 if (NULL == next_attr)
1155 {
1156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1157 "Failed to parse next attribute\n");
1158 continue;
1159 }
1160 GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
1161 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
1162 if (strlen (next_attr) ==
1163 strlen (ds_entry->unresolved_attribute_delegation))
1164 {
1165 ds_entry->attr_trailer = NULL;
1166 }
1167 else
1168 {
1169 next_attr += strlen (next_attr) + 1;
1170 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
1171 }
1172
1173 // Check for bidirectional crossmatch
1174 for (struct DelegationSetQueueEntry *del_entry = vrh->dsq_head;
1175 del_entry != NULL;
1176 del_entry = del_entry->next)
1177 {
1178 // only check entries added by forward algorithm
1179 if (! del_entry->from_bw)
1180 {
1181 // key of list entry matches actual key
1182 if (0 == memcmp (&del_entry->delegation_chain_entry->issuer_key,
1183 &ds_entry->delegation_chain_entry->subject_key,
1184 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1185 {
1186 // compare entry subject attributes to this trailer (iss attr + old trailer)
1187 if (0 == strcmp (del_entry->attr_trailer,
1188 ds_entry->unresolved_attribute_delegation))
1189 {
1190 print_deleset (del_entry, "Backward:");
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1192 "Backward: Found match with above!\n");
1193
1194 // if one node on the path still needs solutions: return
1195 if (GNUNET_NO ==
1196 handle_bidirectional_match (del_entry, ds_entry, vrh))
1197 break;
1198
1199 // Send lookup response
1200 send_lookup_response (vrh);
1201 return;
1202 }
1203 }
1204 }
1205 }
1206
1207 // Starting a new GNS lookup
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1209 "Looking up %s\n",
1210 ds_entry->lookup_attribute);
1211 if (NULL != ds_entry->attr_trailer)
1212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1213 "%s still to go...\n",
1214 ds_entry->attr_trailer);
1215
1216 vrh->pending_lookups++;
1217 ds_entry->handle = vrh;
1218 ds_entry->lookup_request =
1219 GNUNET_GNS_lookup (gns,
1220 lookup_attribute,
1221 ds_entry->issuer_key, // issuer_key,
1222 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
1223 GNUNET_GNS_LO_DEFAULT,
1224 &backward_resolution,
1225 ds_entry);
1226
1227 GNUNET_free (lookup_attribute);
1228 }
1229 }
1230
1231 if (0 == vrh->pending_lookups)
1232 {
1233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
1234 send_lookup_response (vrh);
1235 return;
1236 }
1237}
1238
1239
1240/**
1241 * Result from GNS lookup.
1242 *
1243 * @param cls the closure (our client lookup handle)
1244 */
1245static int
1246delegation_chain_bw_resolution_start (void *cls)
1247{
1248 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Start Backward Resolution...\n");
1249
1250 struct VerifyRequestHandle *vrh = cls;
1251 struct DelegationSetQueueEntry *ds_entry;
1252 struct DelegateRecordEntry *del_entry;
1253
1254 if (0 == vrh->del_chain_size)
1255 {
1256 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegates found\n");
1257 send_lookup_response (vrh);
1258 return 1;
1259 }
1260
1261 // Pre-check with vrh->dele_chain_.. if match issuer_key
1262 // Backward: check every cred entry if match issuer key
1263 // otherwise: start at issuer and go down till match
1264 // A.a <- ...
1265 // X.x <- C
1266 // Y.y <- C
1267 // if not X.x or Y.y == A.a start at A
1268 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1269 del_entry = del_entry->next)
1270 {
1271 if (0 != memcmp (&del_entry->delegate->issuer_key,
1272 &vrh->issuer_key,
1273 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1274 continue;
1275 if (0 !=
1276 strcmp (del_entry->delegate->issuer_attribute, vrh->issuer_attribute))
1277 continue;
1278 del_entry->refcount++;
1279 // Found match prematurely
1280 send_lookup_response (vrh);
1281 return 1;
1282 }
1283
1284
1285 // Check for attributes from the issuer and follow the chain
1286 // till you get the required subject's attributes
1287 char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1];
1288 strcpy (issuer_attribute_name, vrh->issuer_attribute);
1289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1290 "Looking up %s\n",
1291 issuer_attribute_name);
1292 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
1293 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
1294 ds_entry->from_bw = true;
1295 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
1296 GNUNET_memcpy (ds_entry->issuer_key,
1297 &vrh->issuer_key,
1298 sizeof (struct GNUNET_CRYPTO_PublicKey));
1299 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
1300
1301 ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry);
1302 ds_entry->delegation_chain_entry->issuer_key = vrh->issuer_key;
1303 ds_entry->delegation_chain_entry->issuer_attribute =
1304 GNUNET_strdup (vrh->issuer_attribute);
1305
1306 ds_entry->handle = vrh;
1307 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
1308 ds_entry->unresolved_attribute_delegation = NULL;
1309 vrh->pending_lookups = 1;
1310
1311 // Start with backward resolution
1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start Backward Resolution\n");
1313
1314 ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
1315 issuer_attribute_name,
1316 &vrh->issuer_key, // issuer_key,
1317 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
1318 GNUNET_GNS_LO_DEFAULT,
1319 &backward_resolution,
1320 ds_entry);
1321 return 0;
1322}
1323
1324
1325static int
1326delegation_chain_fw_resolution_start (void *cls)
1327{
1328 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Start Forward Resolution...\n");
1329
1330 struct VerifyRequestHandle *vrh = cls;
1331 struct DelegationSetQueueEntry *ds_entry;
1332 struct DelegateRecordEntry *del_entry;
1333
1334 // set to 0 and increase on each lookup: for fw multiple lookups (may be) started
1335 vrh->pending_lookups = 0;
1336
1337 if (0 == vrh->del_chain_size)
1338 {
1339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegations found\n");
1340 send_lookup_response (vrh);
1341 return 1;
1342 }
1343
1344 // Pre-check with vrh->dele_chain_.. if match issuer_key
1345 // otherwise FW: start multiple lookups for each vrh->dele_chain
1346 // A.a <- ...
1347 // X.x <- C
1348 // Y.y <- C
1349 // if not X.x or Y.y == A.a start at X and at Y
1350 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1351 del_entry = del_entry->next)
1352 {
1353 if (0 != memcmp (&del_entry->delegate->issuer_key,
1354 &vrh->issuer_key,
1355 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1356 continue;
1357 if (0 !=
1358 strcmp (del_entry->delegate->issuer_attribute, vrh->issuer_attribute))
1359 continue;
1360 del_entry->refcount++;
1361 // Found match prematurely
1362 send_lookup_response (vrh);
1363 return 1;
1364 }
1365
1366 // None match, therefore start for every delegation found a lookup chain
1367 // Return and end collect process on first chain iss <-> sub found
1368
1369 // ds_entry created belongs to the first lookup, vrh still has the
1370 // issuer+attr we look for
1371 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1372 del_entry = del_entry->next)
1373 {
1374
1375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1376 "Looking for %s.%s\n",
1377 GNUNET_CRYPTO_public_key_to_string (
1378 &del_entry->delegate->issuer_key),
1379 del_entry->delegate->issuer_attribute);
1380
1381 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
1382 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
1383 ds_entry->from_bw = false;
1384 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
1385 GNUNET_memcpy (ds_entry->issuer_key,
1386 &del_entry->delegate->subject_key,
1387 sizeof (struct GNUNET_CRYPTO_PublicKey));
1388
1389 ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry);
1390 ds_entry->delegation_chain_entry->subject_key =
1391 del_entry->delegate->subject_key;
1392 ds_entry->delegation_chain_entry->subject_attribute = NULL;
1393 ds_entry->delegation_chain_entry->issuer_key =
1394 del_entry->delegate->issuer_key;
1395 ds_entry->delegation_chain_entry->issuer_attribute =
1396 GNUNET_strdup (del_entry->delegate->issuer_attribute);
1397
1398 ds_entry->attr_trailer =
1399 GNUNET_strdup (del_entry->delegate->issuer_attribute);
1400 ds_entry->handle = vrh;
1401
1402 vrh->pending_lookups++;
1403 // Start with forward resolution
1404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start Forward Resolution\n");
1405
1406 ds_entry->lookup_request =
1407 GNUNET_GNS_lookup (gns,
1408 GNUNET_GNS_EMPTY_LABEL_AT,
1409 &del_entry->delegate->issuer_key, // issuer_key,
1410 GNUNET_GNSRECORD_TYPE_DELEGATE,
1411 GNUNET_GNS_LO_DEFAULT,
1412 &forward_resolution,
1413 ds_entry);
1414 }
1415 return 0;
1416}
1417
1418
1419static int
1420check_verify (void *cls, const struct VerifyMessage *v_msg)
1421{
1422 size_t msg_size;
1423 const char *attr;
1424
1425 msg_size = ntohs (v_msg->header.size);
1426 if (msg_size < sizeof (struct VerifyMessage))
1427 {
1428 GNUNET_break (0);
1429 return GNUNET_SYSERR;
1430 }
1431 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_ABD_MAX_LENGTH)
1432 {
1433 GNUNET_break (0);
1434 return GNUNET_SYSERR;
1435 }
1436 attr = (const char *) &v_msg[1];
1437
1438 if (strlen (attr) > GNUNET_ABD_MAX_LENGTH)
1439 {
1440 GNUNET_break (0);
1441 return GNUNET_SYSERR;
1442 }
1443 return GNUNET_OK;
1444}
1445
1446
1447static void
1448handle_verify (void *cls, const struct VerifyMessage *v_msg)
1449{
1450 struct VerifyRequestHandle *vrh;
1451 struct GNUNET_SERVICE_Client *client = cls;
1452 struct DelegateRecordEntry *del_entry;
1453 uint32_t delegate_count;
1454 uint32_t delegate_data_size;
1455 char attr[GNUNET_ABD_MAX_LENGTH + 1];
1456 char issuer_attribute[GNUNET_ABD_MAX_LENGTH + 1];
1457 char *attrptr = attr;
1458 char *delegate_data;
1459 const char *utf_in;
1460
1461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
1462 utf_in = (const char *) &v_msg[1];
1463 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1464 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
1465 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
1466 vrh = GNUNET_new (struct VerifyRequestHandle);
1467 vrh->is_collect = false;
1468 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
1469 vrh->client = client;
1470 vrh->request_id = v_msg->id;
1471 vrh->issuer_key = v_msg->issuer_key;
1472 vrh->subject_key = v_msg->subject_key;
1473 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1474 vrh->resolution_algo = ntohs (v_msg->resolution_algo);
1475
1476 vrh->del_chain_head = NULL;
1477 vrh->del_chain_tail = NULL;
1478 vrh->dsq_head = NULL;
1479 vrh->dsq_tail = NULL;
1480 vrh->del_chain_head = NULL;
1481 vrh->del_chain_tail = NULL;
1482
1483 GNUNET_SERVICE_client_continue (vrh->client);
1484 if (0 == strlen (issuer_attribute))
1485 {
1486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1487 send_lookup_response (vrh);
1488 return;
1489 }
1490
1491 // Parse delegates from verifaction message
1492 delegate_count = ntohl (v_msg->d_count);
1493 delegate_data_size = ntohs (v_msg->header.size)
1494 - sizeof (struct VerifyMessage)
1495 - ntohs (v_msg->issuer_attribute_len) - 1;
1496 struct GNUNET_ABD_Delegate delegates[delegate_count];
1497 memset (delegates,
1498 0,
1499 sizeof (struct GNUNET_ABD_Delegate) * delegate_count);
1500 delegate_data = (char *) &v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1;
1501 if (GNUNET_OK != GNUNET_ABD_delegates_deserialize (delegate_data_size,
1502 delegate_data,
1503 delegate_count,
1504 delegates))
1505 {
1506 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize delegates!\n");
1507 send_lookup_response (vrh);
1508 return;
1509 }
1510
1511 // Prepare vrh delegation chain for later validation
1512 for (uint32_t i = 0; i < delegate_count; i++)
1513 {
1514 del_entry = GNUNET_new (struct DelegateRecordEntry);
1515 del_entry->delegate =
1516 GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate)
1517 + delegates[i].issuer_attribute_len + 1);
1518 GNUNET_memcpy (del_entry->delegate,
1519 &delegates[i],
1520 sizeof (struct GNUNET_ABD_Delegate));
1521 GNUNET_memcpy (&del_entry->delegate[1],
1522 delegates[i].issuer_attribute,
1523 delegates[i].issuer_attribute_len);
1524 del_entry->delegate->issuer_attribute_len =
1525 delegates[i].issuer_attribute_len;
1526 del_entry->delegate->issuer_attribute = (char *) &del_entry->delegate[1];
1527 GNUNET_CONTAINER_DLL_insert_tail (vrh->del_chain_head,
1528 vrh->del_chain_tail,
1529 del_entry);
1530 vrh->del_chain_size++;
1531 }
1532
1533 // Switch resolution algo
1534 if (GNUNET_ABD_FLAG_BACKWARD & vrh->resolution_algo &&
1535 GNUNET_ABD_FLAG_FORWARD & vrh->resolution_algo)
1536 {
1537 if (1 == delegation_chain_fw_resolution_start (vrh))
1538 return;
1539 delegation_chain_bw_resolution_start (vrh);
1540 }
1541 else if (GNUNET_ABD_FLAG_BACKWARD & vrh->resolution_algo)
1542 {
1543 delegation_chain_bw_resolution_start (vrh);
1544 }
1545 else if (GNUNET_ABD_FLAG_FORWARD & vrh->resolution_algo)
1546 {
1547 delegation_chain_fw_resolution_start (vrh);
1548 }
1549}
1550
1551
1552static void
1553handle_delegate_collection_error_cb (void *cls)
1554{
1555 struct VerifyRequestHandle *vrh = cls;
1556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1557 "Got disconnected from namestore database.\n");
1558 vrh->dele_qe = NULL;
1559 send_lookup_response (vrh);
1560}
1561
1562
1563static void
1564delegate_collection_finished (void *cls)
1565{
1566 struct VerifyRequestHandle *vrh = cls;
1567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting delegates.\n");
1568
1569 // if both are set: bidirectional search, meaning start both chain resolutions
1570 if (GNUNET_ABD_FLAG_BACKWARD & vrh->resolution_algo &&
1571 GNUNET_ABD_FLAG_FORWARD & vrh->resolution_algo)
1572 {
1573 // if premature match found don't start bw resolution
1574 if (1 == delegation_chain_fw_resolution_start (vrh))
1575 return;
1576 delegation_chain_bw_resolution_start (vrh);
1577 }
1578 else if (GNUNET_ABD_FLAG_BACKWARD & vrh->resolution_algo)
1579 {
1580 delegation_chain_bw_resolution_start (vrh);
1581 }
1582 else if (GNUNET_ABD_FLAG_FORWARD & vrh->resolution_algo)
1583 {
1584 delegation_chain_fw_resolution_start (vrh);
1585 }
1586}
1587
1588
1589static void
1590handle_delegate_collection_cb (void *cls,
1591 const struct GNUNET_CRYPTO_PrivateKey *key,
1592 const char *label,
1593 unsigned int rd_count,
1594 const struct GNUNET_GNSRECORD_Data *rd)
1595{
1596 struct VerifyRequestHandle *vrh = cls;
1597 struct DelegateRecordEntry *del_entry;
1598 vrh->dele_qe = NULL;
1599
1600 for (uint32_t i = 0; i < rd_count; i++)
1601 {
1602 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type)
1603 continue;
1604 // only add the entries that are explicitly marked as private
1605 // and therefore symbolize the end of a chain
1606 if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
1607 continue;
1608 del_entry = GNUNET_new (struct DelegateRecordEntry);
1609 del_entry->delegate = GNUNET_ABD_delegate_deserialize (rd[i].data, rd[i].data_size);
1610 if (NULL == del_entry->delegate)
1611 {
1612 GNUNET_free (del_entry);
1613 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid delegate found\n");
1614 continue;
1615 }
1616 GNUNET_CONTAINER_DLL_insert_tail (vrh->del_chain_head,
1617 vrh->del_chain_tail,
1618 del_entry);
1619 vrh->del_chain_size++;
1620 }
1621
1622 delegate_collection_finished (vrh);
1623}
1624
1625
1626static void
1627handle_collect (void *cls, const struct CollectMessage *c_msg)
1628{
1629 char attr[GNUNET_ABD_MAX_LENGTH + 1];
1630 char issuer_attribute[GNUNET_ABD_MAX_LENGTH + 1];
1631 struct VerifyRequestHandle *vrh;
1632 struct GNUNET_SERVICE_Client *client = cls;
1633 char *attrptr = attr;
1634 const char *utf_in;
1635
1636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
1637
1638 utf_in = (const char *) &c_msg[1];
1639 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1640
1641 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
1642 issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
1643 vrh = GNUNET_new (struct VerifyRequestHandle);
1644 vrh->is_collect = true;
1645 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
1646 vrh->client = client;
1647 vrh->request_id = c_msg->id;
1648 vrh->issuer_key = c_msg->issuer_key;
1649 GNUNET_CRYPTO_key_get_public (&c_msg->subject_key, &vrh->subject_key);
1650 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1651 vrh->resolution_algo = ntohs (c_msg->resolution_algo);
1652
1653 vrh->del_chain_head = NULL;
1654 vrh->del_chain_tail = NULL;
1655 vrh->dsq_head = NULL;
1656 vrh->dsq_tail = NULL;
1657 vrh->del_chain_head = NULL;
1658 vrh->del_chain_tail = NULL;
1659
1660 if (0 == strlen (issuer_attribute))
1661 {
1662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1663 send_lookup_response (vrh);
1664 return;
1665 }
1666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting delegates for subject\n");
1667
1668 // Get all delegates from subject
1669 vrh->dele_qe =
1670 GNUNET_NAMESTORE_records_lookup (namestore,
1671 &c_msg->subject_key,
1672 GNUNET_GNS_EMPTY_LABEL_AT,
1673 &handle_delegate_collection_error_cb,
1674 vrh,
1675 &handle_delegate_collection_cb,
1676 vrh);
1677 GNUNET_SERVICE_client_continue (vrh->client);
1678}
1679
1680
1681static int
1682check_collect (void *cls, const struct CollectMessage *c_msg)
1683{
1684 size_t msg_size;
1685 const char *attr;
1686
1687 msg_size = ntohs (c_msg->header.size);
1688 if (msg_size < sizeof (struct CollectMessage))
1689 {
1690 GNUNET_break (0);
1691 return GNUNET_SYSERR;
1692 }
1693 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_ABD_MAX_LENGTH)
1694 {
1695 GNUNET_break (0);
1696 return GNUNET_SYSERR;
1697 }
1698 attr = (const char *) &c_msg[1];
1699
1700 if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) ||
1701 (strlen (attr) > GNUNET_ABD_MAX_LENGTH))
1702 {
1703 GNUNET_break (0);
1704 return GNUNET_SYSERR;
1705 }
1706 return GNUNET_OK;
1707}
1708
1709
1710static void
1711client_disconnect_cb (void *cls,
1712 struct GNUNET_SERVICE_Client *client,
1713 void *app_ctx)
1714{
1715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
1716}
1717
1718
1719static void *
1720client_connect_cb (void *cls,
1721 struct GNUNET_SERVICE_Client *client,
1722 struct GNUNET_MQ_Handle *mq)
1723{
1724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1725 return client;
1726}
1727
1728
1729/**
1730 * Process Credential requests.
1731 *
1732 * @param cls closure
1733 * @param c configuration to use
1734 * @param handle service handle
1735 */
1736static void
1737run (void *cls,
1738 const struct GNUNET_CONFIGURATION_Handle *c,
1739 struct GNUNET_SERVICE_Handle *handle)
1740{
1741
1742 gns = GNUNET_GNS_connect (c);
1743 if (NULL == gns)
1744 {
1745 fprintf (stderr, _ ("Failed to connect to GNS\n"));
1746 }
1747 namestore = GNUNET_NAMESTORE_connect (c);
1748 if (NULL == namestore)
1749 {
1750 fprintf (stderr, _ ("Failed to connect to namestore\n"));
1751 }
1752
1753 statistics = GNUNET_STATISTICS_create ("abd", c);
1754 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1755}
1756
1757
1758/**
1759 * Define "main" method using service macro
1760 */
1761GNUNET_SERVICE_MAIN (
1762 "abd",
1763 GNUNET_SERVICE_OPTION_NONE,
1764 &run,
1765 &client_connect_cb,
1766 &client_disconnect_cb,
1767 NULL,
1768 GNUNET_MQ_hd_var_size (verify,
1769 GNUNET_MESSAGE_TYPE_ABD_VERIFY,
1770 struct VerifyMessage,
1771 NULL),
1772 GNUNET_MQ_hd_var_size (collect,
1773 GNUNET_MESSAGE_TYPE_ABD_COLLECT,
1774 struct CollectMessage,
1775 NULL),
1776 GNUNET_MQ_handler_end ());
1777
1778/* end of gnunet-service-abd.c */
diff --git a/src/abd/plugin_gnsrecord_abd.c b/src/abd/plugin_gnsrecord_abd.c
deleted file mode 100644
index 43abe578f..000000000
--- a/src/abd/plugin_gnsrecord_abd.c
+++ /dev/null
@@ -1,357 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 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/**
22 * @file abd/plugin_gnsrecord_abd.c
23 * @brief gnsrecord plugin to provide the API for ABD records
24 * @author Martin Schanzenbach
25 */
26#include "platform.h"
27
28#include "gnunet_util_lib.h"
29
30#include "delegate_misc.h"
31#include "abd_serialization.h"
32#include "gnunet_abd_service.h"
33#include "gnunet_gnsrecord_lib.h"
34#include "gnunet_gnsrecord_plugin.h"
35#include "gnunet_signatures.h"
36/**
37 * Convert the 'value' of a record to a string.
38 *
39 * @param cls closure, unused
40 * @param type type of the record
41 * @param data value in binary encoding
42 * @param data_size number of bytes in @a data
43 * @return NULL on error, otherwise human-readable representation of the value
44 */
45static char *
46abd_value_to_string (void *cls,
47 uint32_t type,
48 const void *data,
49 size_t data_size)
50{
51 const char *cdata;
52
53 switch (type)
54 {
55 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
56 {
57 struct GNUNET_ABD_DelegationRecord sets;
58 char *attr_str;
59 char *subject_pkey;
60 char *tmp_str;
61 int i;
62 if (data_size < sizeof (struct GNUNET_ABD_DelegationRecord))
63 return NULL; /* malformed */
64
65 GNUNET_memcpy (&sets, data, sizeof (sets));
66 cdata = data;
67
68 struct GNUNET_ABD_DelegationSet set[ntohl (sets.set_count)];
69 if (GNUNET_OK !=
70 GNUNET_ABD_delegation_set_deserialize (GNUNET_ntohll (
71 sets.data_size),
72 &cdata[sizeof (sets)],
73 ntohl (sets.set_count),
74 set))
75 return NULL;
76
77 for (i = 0; i < ntohl (sets.set_count); i++)
78 {
79 subject_pkey =
80 GNUNET_CRYPTO_public_key_to_string (&set[i].subject_key);
81
82 if (0 == set[i].subject_attribute_len)
83 {
84 if (0 == i)
85 {
86 GNUNET_asprintf (&attr_str, "%s", subject_pkey);
87 }
88 else
89 {
90 GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey);
91 GNUNET_free (attr_str);
92 attr_str = tmp_str;
93 }
94 }
95 else
96 {
97 if (0 == i)
98 {
99 GNUNET_asprintf (&attr_str,
100 "%s %s",
101 subject_pkey,
102 set[i].subject_attribute);
103 }
104 else
105 {
106 GNUNET_asprintf (&tmp_str,
107 "%s,%s %s",
108 attr_str,
109 subject_pkey,
110 set[i].subject_attribute);
111 GNUNET_free (attr_str);
112 attr_str = tmp_str;
113 }
114 }
115 GNUNET_free (subject_pkey);
116 }
117 return attr_str;
118 }
119 case GNUNET_GNSRECORD_TYPE_DELEGATE:
120 {
121 struct GNUNET_ABD_Delegate *cred;
122 char *cred_str;
123
124 cred = GNUNET_ABD_delegate_deserialize (data, data_size);
125 cred_str = GNUNET_ABD_delegate_to_string (cred);
126 GNUNET_free (cred);
127 return cred_str;
128 }
129 default:
130 return NULL;
131 }
132}
133
134
135/**
136 * Convert human-readable version of a 'value' of a record to the binary
137 * representation.
138 *
139 * @param cls closure, unused
140 * @param type type of the record
141 * @param s human-readable string
142 * @param data set to value in binary encoding (will be allocated)
143 * @param data_size set to number of bytes in @a data
144 * @return #GNUNET_OK on success
145 */
146static int
147abd_string_to_value (void *cls,
148 uint32_t type,
149 const char *s,
150 void **data,
151 size_t *data_size)
152{
153 if (NULL == s)
154 return GNUNET_SYSERR;
155 switch (type)
156 {
157 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
158 {
159 struct GNUNET_ABD_DelegationRecord *sets;
160 char attr_str[253 + 1];
161 char subject_pkey[58 + 1];
162 char *token;
163 char *tmp_str;
164 int matches = 0;
165 int entries;
166 size_t tmp_data_size;
167 int i;
168
169 tmp_str = GNUNET_strdup (s);
170 token = strtok (tmp_str, ",");
171 entries = 0;
172 tmp_data_size = 0;
173 *data_size = sizeof (struct GNUNET_ABD_DelegationRecord);
174 while (NULL != token)
175 {
176 // also fills the variables subject_pley and attr_str if "regex"-like match
177 matches = sscanf (token, "%s %s", subject_pkey, attr_str);
178
179 if (0 == matches)
180 {
181 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
182 _ ("Unable to parse ATTR record string `%s'\n"),
183 s);
184 GNUNET_free (tmp_str);
185 return GNUNET_SYSERR;
186 }
187
188 entries++;
189 token = strtok (NULL, ",");
190 }
191 GNUNET_free (tmp_str);
192
193 tmp_str = GNUNET_strdup (s);
194 token = strtok (tmp_str, ",");
195 if (NULL == token)
196 {
197 GNUNET_free (tmp_str);
198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
199 return GNUNET_SYSERR;
200 }
201
202 struct GNUNET_ABD_DelegationSet set[entries];
203 // sets memory to be 0, starting at *set for the size of struct * entries
204 memset (set, 0, sizeof (struct GNUNET_ABD_DelegationSet) * entries);
205 for (i = 0; i < entries; i++)
206 {
207 matches = sscanf (token, "%s %s", subject_pkey, attr_str);
208
209 // sets the public key for the set entry
210 if (GNUNET_SYSERR ==
211 GNUNET_CRYPTO_public_key_from_string (subject_pkey,
212 &set[i].subject_key))
213 {
214 GNUNET_free (tmp_str);
215 return GNUNET_SYSERR;
216 }
217
218 // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b)
219 if (2 == matches)
220 {
221 set[i].subject_attribute_len = strlen (attr_str) + 1;
222 set[i].subject_attribute = GNUNET_strdup (attr_str);
223 }
224 // If more entries, then token string can take the next entry (separated by ',') by calling strtok again
225 token = strtok (NULL, ",");
226 }
227 tmp_data_size = GNUNET_ABD_delegation_set_get_size (entries, set);
228
229 if (-1 == tmp_data_size)
230 {
231 GNUNET_free (tmp_str);
232 return GNUNET_SYSERR;
233 }
234 *data_size += tmp_data_size;
235 *data = sets = GNUNET_malloc (*data_size);
236 GNUNET_ABD_delegation_set_serialize (entries,
237 set,
238 tmp_data_size,
239 (char *) &sets[1]);
240 for (i = 0; i < entries; i++)
241 {
242 if (0 != set[i].subject_attribute_len)
243 {
244 GNUNET_free_nz ((char *) set[i].subject_attribute);
245 set[i].subject_attribute = NULL;
246 }
247 }
248 sets->set_count = htonl (entries);
249 sets->data_size = GNUNET_htonll (tmp_data_size);
250
251 GNUNET_free (tmp_str);
252 return GNUNET_OK;
253 }
254 case GNUNET_GNSRECORD_TYPE_DELEGATE:
255 {
256 struct GNUNET_ABD_Delegate *cred;
257 cred = GNUNET_ABD_delegate_from_string (s);
258
259 *data_size = GNUNET_ABD_delegate_serialize (cred, (char **) data);
260 GNUNET_free (cred);
261 return GNUNET_OK;
262 }
263 default:
264 return GNUNET_SYSERR;
265 }
266}
267
268
269/**
270 * Mapping of record type numbers to human-readable
271 * record type names.
272 */
273static struct
274{
275 const char *name;
276 uint32_t number;
277} name_map[] = {{"ATTR", GNUNET_GNSRECORD_TYPE_ATTRIBUTE},
278 {"DEL", GNUNET_GNSRECORD_TYPE_DELEGATE},
279 {NULL, UINT32_MAX}};
280
281
282/**
283 * Convert a type name (e.g. "AAAA") to the corresponding number.
284 *
285 * @param cls closure, unused
286 * @param gns_typename name to convert
287 * @return corresponding number, UINT32_MAX on error
288 */
289static uint32_t
290abd_typename_to_number (void *cls, const char *gns_typename)
291{
292 unsigned int i;
293
294 i = 0;
295 while ((name_map[i].name != NULL) &&
296 (0 != strcasecmp (gns_typename, name_map[i].name)))
297 i++;
298 return name_map[i].number;
299}
300
301
302/**
303 * Convert a type number to the corresponding type string (e.g. 1 to "A")
304 *
305 * @param cls closure, unused
306 * @param type number of a type to convert
307 * @return corresponding typestring, NULL on error
308 */
309static const char *
310abd_number_to_typename (void *cls, uint32_t type)
311{
312 unsigned int i;
313
314 i = 0;
315 while ((name_map[i].name != NULL) && (type != name_map[i].number))
316 i++;
317 return name_map[i].name;
318}
319
320
321/**
322 * Entry point for the plugin.
323 *
324 * @param cls NULL
325 * @return the exported block API
326 */
327void *
328libgnunet_plugin_gnsrecord_abd_init (void *cls)
329{
330 struct GNUNET_GNSRECORD_PluginFunctions *api;
331
332 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
333 api->value_to_string = &abd_value_to_string;
334 api->string_to_value = &abd_string_to_value;
335 api->typename_to_number = &abd_typename_to_number;
336 api->number_to_typename = &abd_number_to_typename;
337 return api;
338}
339
340
341/**
342 * Exit point from the plugin.
343 *
344 * @param cls the return value from #libgnunet_plugin_block_test_init
345 * @return NULL
346 */
347void *
348libgnunet_plugin_gnsrecord_abd_done (void *cls)
349{
350 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
351
352 GNUNET_free (api);
353 return NULL;
354}
355
356
357/* end of plugin_gnsrecord_abd.c */
diff --git a/src/abd/test_abd_bi_and.sh b/src/abd/test_abd_bi_and.sh
deleted file mode 100755
index 99c89a344..000000000
--- a/src/abd/test_abd_bi_and.sh
+++ /dev/null
@@ -1,98 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
22gnunet-arm -s -c test_abd_lookup.conf
23
24gnunet-identity -C a -c test_abd_lookup.conf
25gnunet-identity -C b -c test_abd_lookup.conf
26gnunet-identity -C c -c test_abd_lookup.conf
27gnunet-identity -C d -c test_abd_lookup.conf
28gnunet-identity -C e -c test_abd_lookup.conf
29gnunet-identity -C f -c test_abd_lookup.conf
30gnunet-identity -C g -c test_abd_lookup.conf
31gnunet-identity -C h -c test_abd_lookup.conf
32AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
33BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
34CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
35DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
36EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
37FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
38GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
39HKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep h | awk '{print $3}')
40gnunet-identity -d
41
42# (1) (A.a) <- B.b
43# (2) (B.b) <- C.c AND G.g
44# (3) C.c <- (D.D)
45# (4) D.d <- (E.e)
46# (5) E.e <- (F) priv
47# (6) (G.g) <- H.h
48# (7) H.h <- (F) priv
49
50# BIDIRECTIONAL
51gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
52gnunet-namestore -D -z a
53gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$CKEY c, $GKEY g" --ttl=5m -c test_abd_lookup.conf
54gnunet-namestore -D -z b
55gnunet-abd --createIssuerSide --ego=g --attribute="g" --subject="$HKEY h" --ttl=5m -c test_abd_lookup.conf
56gnunet-namestore -D -z b
57
58SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$DKEY d" --ttl="2049-12-12 10:00:00"`
59gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
60gnunet-namestore -D -z d
61SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY e" --ttl="2049-12-12 10:00:00"`
62gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
63gnunet-namestore -D -z e
64SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="e" --subject="$FKEY" --ttl="2049-12-12 10:00:00"`
65gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
66gnunet-namestore -D -z f
67SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=h --attribute="h" --subject="$FKEY" --ttl="2049-12-12 10:00:00"`
68gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
69gnunet-namestore -D -z h
70
71# Starting to resolve
72echo "+++ Starting to Resolve +++"
73
74DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=f --forward --backward -c test_abd_lookup.conf | paste -d, -s - -`
75echo $DELS
76echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate=\'$DELS\' --forward --backward -c test_abd_lookup.conf
77gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate="$DELS" --forward --backward -c test_abd_lookup.conf
78
79RES=$?
80
81# Cleanup properly
82gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
83gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
84gnunet-namestore -z g -d -n "g" -t ATTR -c test_abd_lookup.conf
85gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
86gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
87gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
88
89gnunet-arm -e -c test_abd_lookup.conf
90
91if [ "$RES" == 0 ]
92then
93 exit 0
94else
95 echo "FAIL: Failed to verify credential."
96 exit 1
97fi
98
diff --git a/src/abd/test_abd_bi_and2.sh b/src/abd/test_abd_bi_and2.sh
deleted file mode 100755
index 8d1601ef4..000000000
--- a/src/abd/test_abd_bi_and2.sh
+++ /dev/null
@@ -1,94 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
22gnunet-arm -s -c test_abd_lookup.conf
23
24gnunet-identity -C a -c test_abd_lookup.conf
25gnunet-identity -C b -c test_abd_lookup.conf
26gnunet-identity -C c -c test_abd_lookup.conf
27gnunet-identity -C d -c test_abd_lookup.conf
28gnunet-identity -C e -c test_abd_lookup.conf
29gnunet-identity -C f -c test_abd_lookup.conf
30gnunet-identity -C g -c test_abd_lookup.conf
31gnunet-identity -C h -c test_abd_lookup.conf
32AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
33BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
34CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
35DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
36EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
37FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
38GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
39HKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep h | awk '{print $3}')
40gnunet-identity -d
41
42# (1) (A.a) <- B.b
43# (2) (B.b) <- C.c AND G.g
44# (3) C.c <- (D.D)
45# (4) D.d <- (E.e)
46# (5) E.e <- (F) priv
47# (6) G.g <- (F) priv
48
49# BIDIRECTIONAL
50gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
51gnunet-namestore -D -z a
52gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$CKEY c, $GKEY g" --ttl=5m -c test_abd_lookup.conf
53gnunet-namestore -D -z b
54
55SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"`
56gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
57gnunet-namestore -D -z d
58SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY e" --ttl="2019-12-12 10:00:00"`
59gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
60gnunet-namestore -D -z e
61SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="e" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
62gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
63gnunet-namestore -D -z f
64SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=g --attribute="g" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
65gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
66gnunet-namestore -D -z h
67
68# Starting to resolve
69echo "+++ Starting to Resolve +++"
70
71DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=f -c test_abd_lookup.conf | paste -d, -s - -`
72echo $DELS
73echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate=\'$DELS\' -c test_abd_lookup.conf
74gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate="$DELS" -c test_abd_lookup.conf
75
76RES=$?
77
78# Cleanup properly
79gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
80gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
81gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
82gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
83gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
84
85gnunet-arm -e -c test_abd_lookup.conf
86
87if [ "$RES" == 0 ]
88then
89 exit 0
90else
91 echo "FAIL: Failed to verify credential."
92 exit 1
93fi
94
diff --git a/src/abd/test_abd_bi_and3.sh b/src/abd/test_abd_bi_and3.sh
deleted file mode 100755
index cde2a020b..000000000
--- a/src/abd/test_abd_bi_and3.sh
+++ /dev/null
@@ -1,96 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
21gnunet-arm -s -c test_abd_lookup.conf
22
23gnunet-identity -C a -c test_abd_lookup.conf
24gnunet-identity -C b -c test_abd_lookup.conf
25gnunet-identity -C c -c test_abd_lookup.conf
26gnunet-identity -C d -c test_abd_lookup.conf
27gnunet-identity -C e -c test_abd_lookup.conf
28gnunet-identity -C f -c test_abd_lookup.conf
29gnunet-identity -C g -c test_abd_lookup.conf
30gnunet-identity -C h -c test_abd_lookup.conf
31AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
32BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
33CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
34DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
35EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
36FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
37GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
38HKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep h | awk '{print $3}')
39gnunet-identity -d
40
41# (1) (A.a) <- B.b
42# (2) (B.b) <- C.c AND G.g
43# (3) C.c <- (D.d)
44# (4) D.d <- (E.e)
45# (5) E.e <- (F) priv
46# (6) G.g <- (H.h)
47# (7) H.h <- (F) priv
48
49# BIDIRECTIONAL
50gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
51gnunet-namestore -D -z a
52gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$CKEY c, $GKEY g" --ttl=5m -c test_abd_lookup.conf
53gnunet-namestore -D -z b
54
55SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"`
56gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
57gnunet-namestore -D -z d
58SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY e" --ttl="2019-12-12 10:00:00"`
59gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
60gnunet-namestore -D -z e
61SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=g --attribute="g" --subject="$HKEY h" --ttl="2019-12-12 10:00:00"`
62gnunet-abd --createSubjectSide --ego=h --import="$SIGNED"
63gnunet-namestore -D -z h
64SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="e" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
65gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
66SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=h --attribute="h" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
67gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
68gnunet-namestore -D -z f
69
70# Starting to resolve
71echo "+++ Starting to Resolve +++"
72
73DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=f -c test_abd_lookup.conf | paste -d, -s - -`
74echo $DELS
75echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate=\'$DELS\' -c test_abd_lookup.conf
76gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate="$DELS" -c test_abd_lookup.conf
77
78RES=$?
79
80# Cleanup properly
81gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
82gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
83gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
84gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
85gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
86gnunet-namestore -z h -d -n "@" -t DEL -c test_abd_lookup.conf
87
88gnunet-arm -e -c test_abd_lookup.conf
89
90if [ "$RES" == 0 ]
91then
92 exit 0
93else
94 echo "FAIL: Failed to verify credential."
95 exit 1
96fi
diff --git a/src/abd/test_abd_bi_and4.sh b/src/abd/test_abd_bi_and4.sh
deleted file mode 100755
index e8cd6efd6..000000000
--- a/src/abd/test_abd_bi_and4.sh
+++ /dev/null
@@ -1,83 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
22gnunet-arm -s -c test_abd_lookup.conf
23
24gnunet-identity -C a -c test_abd_lookup.conf
25gnunet-identity -C b -c test_abd_lookup.conf
26gnunet-identity -C c -c test_abd_lookup.conf
27gnunet-identity -C d -c test_abd_lookup.conf
28gnunet-identity -C e -c test_abd_lookup.conf
29gnunet-identity -C f -c test_abd_lookup.conf
30gnunet-identity -C g -c test_abd_lookup.conf
31gnunet-identity -C h -c test_abd_lookup.conf
32AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
33BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
34CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
35DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
36EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
37FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
38GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
39HKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep h | awk '{print $3}')
40gnunet-identity -d
41
42# (1) (A.a) <- B.b
43# (2) (B.b) <- C.c AND G.g
44# (3) C.c <- (F) priv
45# (4) G.g <- (F) priv
46
47# BIDIRECTIONAL
48gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
49gnunet-namestore -D -z a
50gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$CKEY c, $GKEY g" --ttl=5m -c test_abd_lookup.conf
51gnunet-namestore -D -z b
52
53SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=g --attribute="g" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
54gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
55SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
56gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
57gnunet-namestore -D -z f
58
59# Starting to resolve
60echo "+++ Starting to Resolve +++"
61
62DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=f --backward -c test_abd_lookup.conf | paste -d, -s - -`
63echo $DELS
64echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate=\'$DELS\' --backward -c test_abd_lookup.conf
65gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate="$DELS" --backward -c test_abd_lookup.conf
66
67RES=$?
68
69# Cleanup properly
70gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
71gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
72gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
73
74gnunet-arm -e -c test_abd_lookup.conf
75
76if [ "$RES" == 0 ]
77then
78 exit 0
79else
80 echo "FAIL: Failed to verify credential."
81 exit 1
82fi
83
diff --git a/src/abd/test_abd_bi_bw.sh b/src/abd/test_abd_bi_bw.sh
deleted file mode 100755
index 6b0e51722..000000000
--- a/src/abd/test_abd_bi_bw.sh
+++ /dev/null
@@ -1,87 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
22gnunet-arm -s -c test_abd_lookup.conf
23
24gnunet-identity -C a -c test_abd_lookup.conf
25gnunet-identity -C b -c test_abd_lookup.conf
26gnunet-identity -C c -c test_abd_lookup.conf
27gnunet-identity -C d -c test_abd_lookup.conf
28gnunet-identity -C e -c test_abd_lookup.conf
29gnunet-identity -C f -c test_abd_lookup.conf
30gnunet-identity -C g -c test_abd_lookup.conf
31AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
32BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
33CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
34DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
35EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
36FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
37GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
38gnunet-identity -d
39
40# (1) (A.a) <- B.b
41# (2) (B.b) <- C.c
42# (3) C.c <- (D.D)
43# (4) D.d <- (E.e)
44# (5) E.e <- (F)
45
46# BIDIRECTIONAL
47gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
48gnunet-namestore -D -z a
49gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$CKEY c" --ttl=5m -c test_abd_lookup.conf
50gnunet-namestore -D -z b
51
52SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"`
53gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
54gnunet-namestore -D -z d
55SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY e" --ttl="2019-12-12 10:00:00"`
56gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
57gnunet-namestore -D -z e
58SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="e" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
59gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
60gnunet-namestore -D -z f
61
62# Starting to resolve
63echo "+++ Starting to Resolve +++"
64
65DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=f --forward --backward -c test_abd_lookup.conf | paste -d, -s - -`
66echo $DELS
67echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate=\'$DELS\' --forward --backward -c test_abd_lookup.conf
68gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate="$DELS" --forward --backward -c test_abd_lookup.conf
69
70RES=$?
71
72# Cleanup properly
73gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
74gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
75gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
76gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
77gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
78
79gnunet-arm -e -c test_abd_lookup.conf
80
81if [ "$RES" == 0 ]
82then
83 exit 0
84else
85 echo "FAIL: Failed to verify credential."
86 exit 1
87fi
diff --git a/src/abd/test_abd_bi_bw_link.sh b/src/abd/test_abd_bi_bw_link.sh
deleted file mode 100755
index f60f78827..000000000
--- a/src/abd/test_abd_bi_bw_link.sh
+++ /dev/null
@@ -1,92 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
22gnunet-arm -s -c test_abd_lookup.conf
23
24gnunet-identity -C a -c test_abd_lookup.conf
25gnunet-identity -C b -c test_abd_lookup.conf
26gnunet-identity -C c -c test_abd_lookup.conf
27gnunet-identity -C d -c test_abd_lookup.conf
28gnunet-identity -C e -c test_abd_lookup.conf
29gnunet-identity -C f -c test_abd_lookup.conf
30gnunet-identity -C g -c test_abd_lookup.conf
31AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
32BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
33CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
34DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
35EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
36FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
37GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
38gnunet-identity -d
39
40# (1) (A.a) <- B.b
41# (2) (B.b) <- G.g.c
42# (3) (G.g) <- C
43# (3) C.c <- (D.D)
44# (4) D.d <- (E.e)
45# (5) E.e <- (F)
46
47# BIDIRECTIONAL
48gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
49gnunet-namestore -D -z a
50gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$GKEY g.c" --ttl=5m -c test_abd_lookup.conf
51gnunet-namestore -D -z b
52gnunet-abd --createIssuerSide --ego=g --attribute="g" --subject="$CKEY" --ttl=5m -c test_abd_lookup.conf
53gnunet-namestore -D -z b
54
55SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"`
56gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
57gnunet-namestore -D -z d
58SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY e" --ttl="2019-12-12 10:00:00"`
59gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
60gnunet-namestore -D -z e
61SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="e" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
62gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
63gnunet-namestore -D -z f
64
65# Starting to resolve
66echo "+++ Starting to Resolve +++"
67
68DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=f --forward --backward -c test_abd_lookup.conf | paste -d, -s - -`
69echo $DELS
70echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate=\'$DELS\' --forward --backward -c test_abd_lookup.conf
71gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate="$DELS" --forward --backward -c test_abd_lookup.conf
72
73RES=$?
74
75# Cleanup properly
76gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
77gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
78gnunet-namestore -z g -d -n "g" -t ATTR -c test_abd_lookup.conf
79gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
80gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
81gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
82
83gnunet-arm -e -c test_abd_lookup.conf
84
85if [ "$RES" == 0 ]
86then
87 exit 0
88else
89 echo "FAIL: Failed to verify credential."
90 exit 1
91fi
92
diff --git a/src/abd/test_abd_bi_bw_link2.sh b/src/abd/test_abd_bi_bw_link2.sh
deleted file mode 100755
index b0fb49b8e..000000000
--- a/src/abd/test_abd_bi_bw_link2.sh
+++ /dev/null
@@ -1,93 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
22gnunet-arm -s -c test_abd_lookup.conf
23
24gnunet-identity -C a -c test_abd_lookup.conf
25gnunet-identity -C b -c test_abd_lookup.conf
26gnunet-identity -C c -c test_abd_lookup.conf
27gnunet-identity -C d -c test_abd_lookup.conf
28gnunet-identity -C e -c test_abd_lookup.conf
29gnunet-identity -C f -c test_abd_lookup.conf
30gnunet-identity -C g -c test_abd_lookup.conf
31AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
32BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
33CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
34DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
35EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
36FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
37GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
38gnunet-identity -d
39
40# (1) (A.a) <- B.b
41# (2) (B.b) <- G.g.c
42# (3) G.g <- (C)
43# (3) C.c <- (D.d)
44# (4) D.d <- (E.e)
45# (5) E.e <- (F)
46
47# BIDIRECTIONAL
48gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
49gnunet-namestore -D -z a
50gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$GKEY g.c" --ttl=5m -c test_abd_lookup.conf
51gnunet-namestore -D -z b
52
53SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=g --attribute="g" --subject="$CKEY" --ttl="2019-12-12 10:00:00"`
54gnunet-abd --createSubjectSide --ego=c --import="$SIGNED"
55gnunet-namestore -D -z c
56SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"`
57gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
58gnunet-namestore -D -z d
59SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY e" --ttl="2019-12-12 10:00:00"`
60gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
61gnunet-namestore -D -z e
62SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="e" --subject="$FKEY" --ttl="2019-12-12 10:00:00"`
63gnunet-abd --createSubjectSide --ego=f --import="$SIGNED" --private
64gnunet-namestore -D -z f
65
66# Starting to resolve
67echo "+++ Starting to Resolve +++"
68
69DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=f --forward --backward -c test_abd_lookup.conf | paste -d, -s - -`
70echo $DELS
71echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate=\'$DELS\' --forward --backward -c test_abd_lookup.conf
72gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$FKEY --delegate="$DELS" --forward --backward -c test_abd_lookup.conf
73
74RES=$?
75
76# Cleanup properly
77gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
78gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
79gnunet-namestore -z c -d -n "@" -t DEL -c test_abd_lookup.conf
80gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
81gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
82gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
83
84gnunet-arm -e -c test_abd_lookup.conf
85
86if [ "$RES" == 0 ]
87then
88 exit 0
89else
90 echo "FAIL: Failed to verify credential."
91 exit 1
92fi
93
diff --git a/src/abd/test_abd_bi_fw.sh b/src/abd/test_abd_bi_fw.sh
deleted file mode 100755
index 75a940fbe..000000000
--- a/src/abd/test_abd_bi_fw.sh
+++ /dev/null
@@ -1,92 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
22gnunet-arm -s -c test_abd_lookup.conf
23
24gnunet-identity -C a -c test_abd_lookup.conf
25gnunet-identity -C b -c test_abd_lookup.conf
26gnunet-identity -C c -c test_abd_lookup.conf
27gnunet-identity -C d -c test_abd_lookup.conf
28gnunet-identity -C e -c test_abd_lookup.conf
29gnunet-identity -C f -c test_abd_lookup.conf
30gnunet-identity -C g -c test_abd_lookup.conf
31AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
32BKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep b | awk '{print $3}')
33CKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep c | awk '{print $3}')
34DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
35EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
36FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
37GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
38gnunet-identity -d
39
40# (1) (A.a) <- B.b
41# (2) (B.b) <- C.c
42# (3) C.c <- (D.D)
43# (4) D.d <- (E.e)
44# (5) E.e <- (F.f)
45# (6) F.f <- (G)
46
47# BIDIRECTIONAL
48gnunet-abd --createIssuerSide --ego=a --attribute="a" --subject="$BKEY b" --ttl=5m -c test_abd_lookup.conf
49gnunet-namestore -D -z a
50gnunet-abd --createIssuerSide --ego=b --attribute="b" --subject="$CKEY c" --ttl=5m -c test_abd_lookup.conf
51gnunet-namestore -D -z b
52
53SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=c --attribute="c" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"`
54gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
55gnunet-namestore -D -z d
56SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY e" --ttl="2019-12-12 10:00:00"`
57gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
58gnunet-namestore -D -z e
59SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="e" --subject="$FKEY f" --ttl="2019-12-12 10:00:00"`
60gnunet-abd --createSubjectSide --ego=f --import="$SIGNED"
61gnunet-namestore -D -z f
62SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=f --attribute="f" --subject="$GKEY" --ttl="2019-12-12 10:00:00"`
63gnunet-abd --createSubjectSide --ego=g --import="$SIGNED" --private
64gnunet-namestore -D -z g
65
66# Starting to resolve
67echo "+++ Starting to Resolve +++"
68
69DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=g --forward --backward -c test_abd_lookup.conf | paste -d, -s - -`
70echo $DELS
71echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --delegate=\'$DELS\' --forward --backward -c test_abd_lookup.conf
72gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --delegate="$DELS" --forward --backward -c test_abd_lookup.conf
73
74RES=$?
75
76# Cleanup properly
77gnunet-namestore -z a -d -n "a" -t ATTR -c test_abd_lookup.conf
78gnunet-namestore -z b -d -n "b" -t ATTR -c test_abd_lookup.conf
79gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
80gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
81gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
82gnunet-namestore -z g -d -n "@" -t DEL -c test_abd_lookup.conf
83
84gnunet-arm -e -c test_abd_lookup.conf
85
86if [ "$RES" == 0 ]
87then
88 exit 0
89else
90 echo "FAIL: Failed to verify credential."
91 exit 1
92fi
diff --git a/src/abd/test_abd_defaults.conf b/src/abd/test_abd_defaults.conf
deleted file mode 100644
index 7b4cb576d..000000000
--- a/src/abd/test_abd_defaults.conf
+++ /dev/null
@@ -1,24 +0,0 @@
1@INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf
2
3[PATHS]
4GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-abd-testing/
5
6[namestore-sqlite]
7FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
8
9[namecache-sqlite]
10FILENAME=$GNUNET_TEST_HOME/namecache/namecache.db
11
12[identity]
13# Directory where we store information about our egos
14EGODIR = $GNUNET_TEST_HOME/identity/egos/
15
16[dhtcache]
17DATABASE = heap
18
19[transport]
20PLUGINS = tcp
21
22[transport-tcp]
23BINDTO = 127.0.0.1
24
diff --git a/src/abd/test_abd_issue.sh b/src/abd/test_abd_issue.sh
deleted file mode 100755
index 8076aa921..000000000
--- a/src/abd/test_abd_issue.sh
+++ /dev/null
@@ -1,46 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_abd_lookup.conf
27gnunet-identity -C testissuer -c test_abd_lookup.conf
28gnunet-identity -C testsubject -c test_abd_lookup.conf
29SUBJECT_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep testsubject | awk '{print $3}')
30ISSUER_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep testissuer | awk '{print $3}')
31
32# Get abd and store it with subject (3)
33SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=testissuer --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf`
34
35STATUS=$?
36
37if test $? != 0
38then
39 echo "Error issuing..."
40 exit 1
41fi
42#Try import
43$DO_TIMEOUT gnunet-abd --createSubjectSide --ego=testsubject --import="$SIGNED" --private -c test_abd_lookup.conf
44RES=$?
45gnunet-arm -e -c test_abd_lookup.conf
46exit $RES
diff --git a/src/abd/test_abd_lookup.conf b/src/abd/test_abd_lookup.conf
deleted file mode 100644
index 4072ba23b..000000000
--- a/src/abd/test_abd_lookup.conf
+++ /dev/null
@@ -1,28 +0,0 @@
1@INLINE@ test_abd_defaults.conf
2
3[PATHS]
4GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-abd-peer-1/
5
6[dht]
7START_ON_DEMAND = YES
8
9[transport]
10PLUGINS =
11
12[abd]
13START_ON_DEMAND = YES
14#PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/credlog
15
16[rest]
17PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/restlog
18
19[gns]
20#PREFIX = valgrind --leak-check=full --track-origins=yes
21START_ON_DEMAND = YES
22AUTO_IMPORT_PKEY = YES
23MAX_PARALLEL_BACKGROUND_QUERIES = 10
24DEFAULT_LOOKUP_TIMEOUT = 15 s
25RECORD_PUT_INTERVAL = 1 h
26ZONE_PUBLISH_TIME_WINDOW = 1 h
27DNS_ROOT=PD67SGHF3E0447TU9HADIVU9OM7V4QHTOG0EBU69TFRI2LG63DR0
28
diff --git a/src/abd/test_abd_own.sh b/src/abd/test_abd_own.sh
deleted file mode 100755
index 3fc210284..000000000
--- a/src/abd/test_abd_own.sh
+++ /dev/null
@@ -1,139 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18
19
20which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10"
21gnunet-arm -s -c test_abd_lookup.conf
22
23gnunet-identity -C a -c test_abd_lookup.conf
24gnunet-identity -C d -c test_abd_lookup.conf
25gnunet-identity -C e -c test_abd_lookup.conf
26gnunet-identity -C f -c test_abd_lookup.conf
27gnunet-identity -C g -c test_abd_lookup.conf
28AKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep a | awk '{print $3}')
29DKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep d | awk '{print $3}')
30EKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep e | awk '{print $3}')
31FKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep f | awk '{print $3}')
32GKEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep g | awk '{print $3}')
33
34############################################################################################
35# (1) EPub.discount <- EOrg.preferred
36# (2) EOrg.preferred <- StateU.student
37# (3) StateU.student <- RegistrarB.student
38# (4) RegistrarB.student <- Alice
39
40gnunet-identity -C epub -c test_abd_lookup.conf
41gnunet-identity -C eorg -c test_abd_lookup.conf
42gnunet-identity -C stateu -c test_abd_lookup.conf
43gnunet-identity -C registrarb -c test_abd_lookup.conf
44gnunet-identity -C alice -c test_abd_lookup.conf
45
46EPUB_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep epub | awk '{print $3}')
47EORG_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep eorg | awk '{print $3}')
48STATEU_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep stateu | awk '{print $3}')
49REGISTRARB_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep registrarb | awk '{print $3}')
50ALICE_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep alice | awk '{print $3}')
51
52
53DISC_ATTR="discount"
54PREF_ATTR="preferred"
55STATE_STUD_ATTR="student"
56REG_STUD_ATTR="student"
57END_ATTR="end"
58
59gnunet-identity -d
60
61# FORWARD, subject side stored (different constellations)
62SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=a --attribute="a" --subject="$AKEY b.c" --ttl="2019-12-12 10:00:00"`
63gnunet-abd --createSubjectSide --ego=a --import="$SIGNED"
64gnunet-namestore -D -z a
65
66SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=a --attribute="b" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"`
67gnunet-abd --createSubjectSide --ego=d --import="$SIGNED"
68gnunet-namestore -D -z d
69
70SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="d" --subject="$EKEY" --ttl="2019-12-12 10:00:00"`
71gnunet-abd --createSubjectSide --ego=e --import="$SIGNED"
72gnunet-namestore -D -z e
73
74SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="c" --subject="$FKEY c" --ttl="2019-12-12 10:00:00"`
75gnunet-abd --createSubjectSide --ego=f --import="$SIGNED"
76SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=e --attribute="k" --subject="$FKEY c.k" --ttl="2019-12-12 10:00:00"`
77gnunet-abd --createSubjectSide --ego=f --import="$SIGNED"
78gnunet-namestore -D -z f
79
80SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=f --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"`
81gnunet-abd --createSubjectSide --ego=g --import="$SIGNED" --private
82SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=a --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"`
83gnunet-abd --createSubjectSide --ego=g --import="$SIGNED" --private
84SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=d --attribute="h.o" --subject="$GKEY" --ttl="2019-12-12 10:00:00"`
85gnunet-abd --createSubjectSide --ego=g --import="$SIGNED"
86gnunet-namestore -D -z g
87
88
89# BACKWARD, issuer side stored
90# (1) EPub assigns the attribute "discount" to all entities that have been assigned "preferred" by EOrg
91gnunet-abd --createIssuerSide --ego=epub --attribute=$DISC_ATTR --subject="$EORG_KEY $PREF_ATTR" --ttl=5m -c test_abd_lookup.conf
92
93# (2) EOrg assigns the attribute "preferred" to all entities that have been assigned "student" by StateU
94gnunet-abd --createIssuerSide --ego=eorg --attribute=$PREF_ATTR --subject="$STATEU_KEY $STATE_STUD_ATTR" --ttl=5m -c test_abd_lookup.conf
95
96# (3) StateU assigns the attribute "student" to all entities that have been asssigned "student" by RegistrarB
97gnunet-abd --createIssuerSide --ego=stateu --attribute=$STATE_STUD_ATTR --subject="$REGISTRARB_KEY $REG_STUD_ATTR" --ttl=5m -c test_abd_lookup.conf
98
99# (4) RegistrarB issues Alice the credential "student"
100SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=registrarb --attribute="$REG_STUD_ATTR" --subject="$ALICE_KEY" --ttl="2019-12-12 10:00:00"`
101gnunet-abd --createSubjectSide --ego=alice --import="$SIGNED" --private
102
103# Starting to resolve
104echo "+++ Starting to Resolve +++"
105
106# FORWARD
107#DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$AKEY --attribute="a" --ego=g --forward -c test_abd_lookup.conf | paste -d, -s - -`
108#echo $DELS
109#echo gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --delegate=\'$DELS\' --forward -c test_abd_lookup.conf
110#RES_DELS=`gnunet-abd --verify --issuer=$AKEY --attribute="a" --subject=$GKEY --delegate="$DELS" --forward -c test_abd_lookup.conf`
111
112# BACKWARD
113DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$EPUB_KEY --attribute=$DISC_ATTR --ego=alice --backward -c test_abd_lookup.conf | paste -d, -s - -`
114echo $DELS
115echo gnunet-abd --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --delegate=\'$DELS\' --backward -c test_abd_lookup.conf
116gnunet-abd --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --delegate="$DELS" --backward -c test_abd_lookup.conf
117
118RES=$?
119
120# Cleanup properly
121gnunet-namestore -z epub -d -n $DISC_ATTR -t ATTR -c test_abd_lookup.conf
122gnunet-namestore -z eorg -d -n $PREF_ATTR -t ATTR -c test_abd_lookup.conf
123gnunet-namestore -z stateu -d -n $STATE_STUD_ATTR -t ATTR -c test_abd_lookup.conf
124#gnunet-namestore -z a -d -n "@" -t DEL -c test_abd_lookup.conf
125#gnunet-namestore -z d -d -n "@" -t DEL -c test_abd_lookup.conf
126#gnunet-namestore -z e -d -n "@" -t DEL -c test_abd_lookup.conf
127#gnunet-namestore -z f -d -n "@" -t DEL -c test_abd_lookup.conf
128#gnunet-namestore -z g -d -n "@" -t DEL -c test_abd_lookup.conf
129
130
131gnunet-arm -e -c test_abd_lookup.conf
132
133if [ "$RES" == 0 ]
134then
135 exit 0
136else
137 echo "FAIL: Failed to verify credential."
138 exit 1
139fi
diff --git a/src/abd/test_abd_verify.sh b/src/abd/test_abd_verify.sh
deleted file mode 100755
index 9ece91c62..000000000
--- a/src/abd/test_abd_verify.sh
+++ /dev/null
@@ -1,87 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) Service.user -> GNU.project.member
19# (2) GNU.project -> GNUnet
20# (3) GNUnet.member -> GNUnet.developer
21# (4) GNUnet.member -> GNUnet.user
22# (5) GNUnet.developer -> Alice
23
24
25which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
26gnunet-arm -s -c test_abd_lookup.conf
27gnunet-identity -C service -c test_abd_lookup.conf
28gnunet-identity -C alice -c test_abd_lookup.conf
29gnunet-identity -C gnu -c test_abd_lookup.conf
30gnunet-identity -C gnunet -c test_abd_lookup.conf
31
32GNU_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep gnu | grep -v gnunet | awk '{print $3}')
33ALICE_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep alice | awk '{print $3}')
34GNUNET_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep gnunet | awk '{print $3}')
35SERVICE_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep service | awk '{print $3}')
36
37USER_ATTR="user"
38GNU_PROJECT_ATTR="project"
39MEMBER_ATTR="member"
40DEVELOPER_ATTR="developer"
41DEV_ATTR="developer"
42TEST_CREDENTIAL="mygnunetcreds"
43
44gnunet-identity -d
45
46# (1) A service assigns the attribute "user" to all entities that have been assigned "member" by entities that werde assigned "project" from GNU
47gnunet-abd --createIssuerSide --ego=service --attribute="$USER_ATTR" --subject="$GNU_KEY $GNU_PROJECT_ATTR.$MEMBER_ATTR" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
48gnunet-namestore -D -z service
49
50# (2) GNU recognized GNUnet as a GNU project and delegates the "project" attribute
51gnunet-abd --createIssuerSide --ego=gnu --attribute="$GNU_PROJECT_ATTR" --subject="$GNUNET_KEY" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
52gnunet-namestore -D -z gnu
53
54# (3+4) GNUnet assigns the attribute "member" to all entities gnunet has also assigned "developer" or "user"
55gnunet-abd --createIssuerSide --ego=gnunet --attribute="$MEMBER_ATTR" --subject="$GNUNET_KEY $DEVELOPER_ATTR" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
56gnunet-abd --createIssuerSide --ego=gnunet --attribute="$MEMBER_ATTR" --subject="$GNUNET_KEY $USER_ATTR" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
57gnunet-namestore -D -z gnunet
58
59# (5) GNUnet signes the delegate and Alice stores it
60SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=gnunet --attribute=$DEV_ATTR --subject=$ALICE_KEY --ttl="2019-12-12 10:00:00"`
61gnunet-abd --createSubjectSide --ego=alice --import="$SIGNED" --private
62gnunet-namestore -D -z alice
63
64# Starting to resolve
65echo "+++ Starting to Resolve +++"
66
67DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$SERVICE_KEY --attribute=$USER_ATTR --ego=alice --backward -c test_abd_lookup.conf | paste -d, -s - -`
68echo $DELS
69echo gnunet-abd --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate=\'$DELS\' --backward -c test_abd_lookup.conf
70gnunet-abd --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate="$DELS" --backward -c test_abd_lookup.conf
71
72RES=$?
73
74# Cleanup properly
75gnunet-namestore -z alice -d -n "@" -t DEL -c test_abd_lookup.conf
76gnunet-namestore -z gnu -d -n $GNU_PROJECT_ATTR -t ATTR -c test_abd_lookup.conf
77gnunet-namestore -z gnunet -d -n $MEMBER_ATTR -t ATTR -c test_abd_lookup.conf
78gnunet-namestore -z service -d -n $USER_ATTR -t ATTR -c test_abd_lookup.conf
79gnunet-arm -e -c test_abd_lookup.conf
80
81if [ "$RES" == 0 ]
82then
83 exit 0
84else
85 echo "FAIL: Failed to verify credential."
86 exit 1
87fi
diff --git a/src/abd/test_abd_verify_and.sh b/src/abd/test_abd_verify_and.sh
deleted file mode 100755
index c6287055e..000000000
--- a/src/abd/test_abd_verify_and.sh
+++ /dev/null
@@ -1,86 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) Service.user -> GNU.project.member
19# (2) GNU.project -> GNUnet
20# (3) GNUnet.member -> GNUnet.developer AND GNUnet.user
21# (4) GNUnet.developer -> Alice
22
23
24which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
25gnunet-arm -s -c test_abd_lookup.conf
26gnunet-identity -C service -c test_abd_lookup.conf
27gnunet-identity -C alice -c test_abd_lookup.conf
28gnunet-identity -C gnu -c test_abd_lookup.conf
29gnunet-identity -C gnunet -c test_abd_lookup.conf
30
31GNU_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep gnu | grep -v gnunet | awk '{print $3}')
32ALICE_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep alice | awk '{print $3}')
33GNUNET_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep gnunet | awk '{print $3}')
34SERVICE_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep service | awk '{print $3}')
35
36USER_ATTR="user"
37GNU_PROJECT_ATTR="project"
38MEMBER_ATTR="member"
39DEVELOPER_ATTR="developer"
40DEV_ATTR="developer"
41
42gnunet-identity -d
43
44# (1) A service assigns the attribute "user" to all entities that have been assigned "member" by entities that werde assigned "project" from GNU
45gnunet-abd --createIssuerSide --ego=service --attribute="$USER_ATTR" --subject="$GNU_KEY $GNU_PROJECT_ATTR.$MEMBER_ATTR" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
46gnunet-namestore -D -z service
47
48# (2) GNU recognized GNUnet as a GNU project and delegates the "project" attribute
49gnunet-abd --createIssuerSide --ego=gnu --attribute="$GNU_PROJECT_ATTR" --subject="$GNUNET_KEY" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
50gnunet-namestore -D -z gnu
51
52# (3+4) GNUnet assigns the attribute "member" to all entities gnunet has also assigned "developer" or "user"
53gnunet-abd --createIssuerSide --ego=gnunet --attribute="$MEMBER_ATTR" --subject="$GNUNET_KEY $DEVELOPER_ATTR, $GNUNET_KEY $USER_ATTR" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
54gnunet-namestore -D -z gnunet
55
56# (5) GNUnet signes the delegates and Alice stores it
57SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=gnunet --attribute=$DEV_ATTR --subject=$ALICE_KEY --ttl="2019-12-12 10:00:00"`
58gnunet-abd --createSubjectSide --ego=alice --import="$SIGNED" --private
59SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=gnunet --attribute=$USER_ATTR --subject=$ALICE_KEY --ttl="2019-12-12 10:00:00"`
60gnunet-abd --createSubjectSide --ego=alice --import="$SIGNED" --private
61gnunet-namestore -D -z alice
62
63# Starting to resolve
64echo "+++ Starting to Resolve +++"
65
66DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$SERVICE_KEY --attribute=$USER_ATTR --ego=alice --backward -c test_abd_lookup.conf | paste -d, -s - -`
67echo $DELS
68echo gnunet-abd --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate=\'$DELS\' --backward -c test_abd_lookup.conf
69gnunet-abd --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate="$DELS" --backward -c test_abd_lookup.conf
70
71RES=$?
72
73# Cleanup properly
74gnunet-namestore -z alice -d -n "@" -t DEL -c test_abd_lookup.conf
75gnunet-namestore -z gnu -d -n $GNU_PROJECT_ATTR -t ATTR -c test_abd_lookup.conf
76gnunet-namestore -z gnunet -d -n $MEMBER_ATTR -t ATTR -c test_abd_lookup.conf
77gnunet-namestore -z service -d -n $USER_ATTR -t ATTR -c test_abd_lookup.conf
78gnunet-arm -e -c test_abd_lookup.conf
79
80if [ "$RES" == 0 ]
81then
82 exit 0
83else
84 echo "FAIL: Failed to verify credentials."
85 exit 1
86fi
diff --git a/src/abd/test_abd_verify_simple.sh b/src/abd/test_abd_verify_simple.sh
deleted file mode 100755
index e917f8793..000000000
--- a/src/abd/test_abd_verify_simple.sh
+++ /dev/null
@@ -1,56 +0,0 @@
1#!/usr/bin/env bash
2trap "gnunet-arm -e -c test_abd_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) Issuer.user -> Subject
19
20
21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
22gnunet-arm -s -c test_abd_lookup.conf
23gnunet-identity -C testissuer -c test_abd_lookup.conf
24gnunet-identity -C testsubject -c test_abd_lookup.conf
25
26TEST_ATTR="user"
27SUBJECT_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep testsubject | awk '{print $3}')
28ISSUER_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep testissuer | awk '{print $3}')
29
30gnunet-identity -d
31
32# Create delegate (1)
33SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=testissuer --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf`
34gnunet-abd --createSubjectSide --ego=testsubject --import="$SIGNED" --private
35gnunet-namestore -D -z testsubject
36
37# Starting to resolve
38echo "+++ Starting to Resolve +++"
39
40DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --ego=testsubject -c test_abd_lookup.conf | paste -d, -s - -`
41echo $DELS
42gnunet-abd --verify --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --delegate="$DELS" -c test_abd_lookup.conf
43
44RES=$?
45
46# Cleanup properly
47gnunet-namestore -z testsubject -d -n "@" -t DEL -c test_abd_lookup.conf
48gnunet-arm -e -c test_abd_lookup.conf
49
50if [ "$RES" == 0 ]
51then
52 exit 0
53else
54 echo "FAIL: Failed to verify credential."
55 exit 1
56fi \ No newline at end of file