diff options
author | Andreas Ebner <pansy007@googlemail.com> | 2019-07-24 16:29:32 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-10-07 12:15:32 +0200 |
commit | 40624873cbd2eaf3a94185995b14899ea6ab36bf (patch) | |
tree | 0bcc45fc8ba74c7b218ed2b32fc8b7482a42a37c | |
parent | 5091edcec16455febee99afec20e0ffe6cc59c21 (diff) | |
download | gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.tar.gz gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.zip |
Run clang format over some files, experimental implementation of forward algorithm
-rw-r--r-- | src/credential/credential_serialization.c | 310 | ||||
-rw-r--r-- | src/credential/delegate_misc.c | 188 | ||||
-rw-r--r-- | src/credential/gnunet-credential.c | 412 | ||||
-rw-r--r-- | src/credential/gnunet-service-credential.c | 206 | ||||
-rw-r--r-- | src/credential/plugin_gnsrecord_credential.c | 129 | ||||
-rwxr-xr-x | src/credential/test_credential_own.sh | 74 |
6 files changed, 801 insertions, 518 deletions
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c index 4e461c654..b14ec26f2 100644 --- a/src/credential/credential_serialization.c +++ b/src/credential/credential_serialization.c | |||
@@ -11,17 +11,17 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
23 | * @file credential/credential_serialization.c | 23 | * @file credential/credential_serialization.c |
24 | * @brief API to serialize and deserialize delegation chains | 24 | * @brief API to serialize and deserialize delegation chains |
25 | * and credentials | 25 | * and credentials |
26 | * @author Martin Schanzenbach | 26 | * @author Martin Schanzenbach |
27 | */ | 27 | */ |
@@ -41,14 +41,14 @@ | |||
41 | * @return the required size to serialize | 41 | * @return the required size to serialize |
42 | */ | 42 | */ |
43 | size_t | 43 | size_t |
44 | GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, | 44 | GNUNET_CREDENTIAL_delegation_set_get_size ( |
45 | const struct | 45 | unsigned int ds_count, |
46 | GNUNET_CREDENTIAL_DelegationSet *dsr) | 46 | const struct GNUNET_CREDENTIAL_DelegationSet *dsr) |
47 | { | 47 | { |
48 | unsigned int i; | 48 | unsigned int i; |
49 | size_t ret; | 49 | size_t ret; |
50 | 50 | ||
51 | ret = sizeof(struct DelegationRecordData) * (ds_count); | 51 | ret = sizeof (struct DelegationRecordData) * (ds_count); |
52 | 52 | ||
53 | for (i = 0; i < ds_count; i++) | 53 | for (i = 0; i < ds_count; i++) |
54 | { | 54 | { |
@@ -68,11 +68,11 @@ GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, | |||
68 | * @return the size of the data, -1 on failure | 68 | * @return the size of the data, -1 on failure |
69 | */ | 69 | */ |
70 | ssize_t | 70 | ssize_t |
71 | GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, | 71 | GNUNET_CREDENTIAL_delegation_set_serialize ( |
72 | const struct | 72 | unsigned int d_count, |
73 | GNUNET_CREDENTIAL_DelegationSet *dsr, | 73 | const struct GNUNET_CREDENTIAL_DelegationSet *dsr, |
74 | size_t dest_size, | 74 | size_t dest_size, |
75 | char *dest) | 75 | char *dest) |
76 | { | 76 | { |
77 | struct DelegationRecordData rec; | 77 | struct DelegationRecordData rec; |
78 | unsigned int i; | 78 | unsigned int i; |
@@ -83,12 +83,10 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, | |||
83 | { | 83 | { |
84 | rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len); | 84 | rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len); |
85 | rec.subject_key = dsr[i].subject_key; | 85 | rec.subject_key = dsr[i].subject_key; |
86 | if (off + sizeof(rec) > dest_size) | 86 | if (off + sizeof (rec) > dest_size) |
87 | return -1; | 87 | return -1; |
88 | GNUNET_memcpy (&dest[off], | 88 | GNUNET_memcpy (&dest[off], &rec, sizeof (rec)); |
89 | &rec, | 89 | off += sizeof (rec); |
90 | sizeof(rec)); | ||
91 | off += sizeof(rec); | ||
92 | if (0 == dsr[i].subject_attribute_len) | 90 | if (0 == dsr[i].subject_attribute_len) |
93 | continue; | 91 | continue; |
94 | if (off + dsr[i].subject_attribute_len > dest_size) | 92 | if (off + dsr[i].subject_attribute_len > dest_size) |
@@ -112,12 +110,11 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, | |||
112 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 110 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
113 | */ | 111 | */ |
114 | int | 112 | int |
115 | GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, | 113 | GNUNET_CREDENTIAL_delegation_set_deserialize ( |
116 | const char *src, | 114 | size_t len, |
117 | unsigned int d_count, | 115 | const char *src, |
118 | struct | 116 | unsigned int d_count, |
119 | GNUNET_CREDENTIAL_DelegationSet * | 117 | struct GNUNET_CREDENTIAL_DelegationSet *dsr) |
120 | dsr) | ||
121 | { | 118 | { |
122 | struct DelegationRecordData rec; | 119 | struct DelegationRecordData rec; |
123 | unsigned int i; | 120 | unsigned int i; |
@@ -126,15 +123,15 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, | |||
126 | off = 0; | 123 | off = 0; |
127 | for (i = 0; i < d_count; i++) | 124 | for (i = 0; i < d_count; i++) |
128 | { | 125 | { |
129 | if (off + sizeof(rec) > len) | 126 | if (off + sizeof (rec) > len) |
130 | return GNUNET_SYSERR; | 127 | return GNUNET_SYSERR; |
131 | GNUNET_memcpy (&rec, &src[off], sizeof(rec)); | 128 | GNUNET_memcpy (&rec, &src[off], sizeof (rec)); |
132 | dsr[i].subject_key = rec.subject_key; | 129 | dsr[i].subject_key = rec.subject_key; |
133 | off += sizeof(rec); | 130 | off += sizeof (rec); |
134 | dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); | 131 | dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); |
135 | if (off + dsr[i].subject_attribute_len > len) | 132 | if (off + dsr[i].subject_attribute_len > len) |
136 | return GNUNET_SYSERR; | 133 | return GNUNET_SYSERR; |
137 | dsr[i].subject_attribute = (char*) &src[off]; | 134 | dsr[i].subject_attribute = (char *) &src[off]; |
138 | off += dsr[i].subject_attribute_len; | 135 | off += dsr[i].subject_attribute_len; |
139 | } | 136 | } |
140 | return GNUNET_OK; | 137 | return GNUNET_OK; |
@@ -150,14 +147,14 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, | |||
150 | * @return the required size to serialize | 147 | * @return the required size to serialize |
151 | */ | 148 | */ |
152 | size_t | 149 | size_t |
153 | GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, | 150 | GNUNET_CREDENTIAL_credentials_get_size ( |
154 | const struct | 151 | unsigned int c_count, |
155 | GNUNET_CREDENTIAL_Credential *cd) | 152 | const struct GNUNET_CREDENTIAL_Credential *cd) |
156 | { | 153 | { |
157 | unsigned int i; | 154 | unsigned int i; |
158 | size_t ret; | 155 | size_t ret; |
159 | 156 | ||
160 | ret = sizeof(struct CredentialEntry) * (c_count); | 157 | ret = sizeof (struct CredentialEntry) * (c_count); |
161 | 158 | ||
162 | for (i = 0; i < c_count; i++) | 159 | for (i = 0; i < c_count; i++) |
163 | { | 160 | { |
@@ -176,11 +173,11 @@ GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, | |||
176 | * @return the size of the data, -1 on failure | 173 | * @return the size of the data, -1 on failure |
177 | */ | 174 | */ |
178 | ssize_t | 175 | ssize_t |
179 | GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | 176 | GNUNET_CREDENTIAL_credentials_serialize ( |
180 | const struct | 177 | unsigned int c_count, |
181 | GNUNET_CREDENTIAL_Credential *cd, | 178 | const struct GNUNET_CREDENTIAL_Credential *cd, |
182 | size_t dest_size, | 179 | size_t dest_size, |
183 | char *dest) | 180 | char *dest) |
184 | { | 181 | { |
185 | struct CredentialEntry c_rec; | 182 | struct CredentialEntry c_rec; |
186 | unsigned int i; | 183 | unsigned int i; |
@@ -194,16 +191,14 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | |||
194 | c_rec.subject_key = cd[i].subject_key; | 191 | c_rec.subject_key = cd[i].subject_key; |
195 | c_rec.signature = cd[i].signature; | 192 | c_rec.signature = cd[i].signature; |
196 | c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 193 | c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
197 | c_rec.purpose.size = htonl ((sizeof(struct CredentialEntry) | 194 | c_rec.purpose.size = |
198 | + cd[i].issuer_attribute_len) - sizeof(struct | 195 | htonl ((sizeof (struct CredentialEntry) + cd[i].issuer_attribute_len) - |
199 | GNUNET_CRYPTO_EcdsaSignature)); | 196 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); |
200 | c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); | 197 | c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); |
201 | if (off + sizeof(c_rec) > dest_size) | 198 | if (off + sizeof (c_rec) > dest_size) |
202 | return -1; | 199 | return -1; |
203 | GNUNET_memcpy (&dest[off], | 200 | GNUNET_memcpy (&dest[off], &c_rec, sizeof (c_rec)); |
204 | &c_rec, | 201 | off += sizeof (c_rec); |
205 | sizeof(c_rec)); | ||
206 | off += sizeof(c_rec); | ||
207 | if (off + cd[i].issuer_attribute_len > dest_size) | 202 | if (off + cd[i].issuer_attribute_len > dest_size) |
208 | return -1; | 203 | return -1; |
209 | GNUNET_memcpy (&dest[off], | 204 | GNUNET_memcpy (&dest[off], |
@@ -216,7 +211,6 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | |||
216 | } | 211 | } |
217 | 212 | ||
218 | 213 | ||
219 | |||
220 | /** | 214 | /** |
221 | * Deserialize the given destination | 215 | * Deserialize the given destination |
222 | * | 216 | * |
@@ -227,11 +221,11 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, | |||
227 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 221 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
228 | */ | 222 | */ |
229 | int | 223 | int |
230 | GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | 224 | GNUNET_CREDENTIAL_credentials_deserialize ( |
231 | const char *src, | 225 | size_t len, |
232 | unsigned int c_count, | 226 | const char *src, |
233 | struct GNUNET_CREDENTIAL_Credential * | 227 | unsigned int c_count, |
234 | cd) | 228 | struct GNUNET_CREDENTIAL_Credential *cd) |
235 | { | 229 | { |
236 | struct CredentialEntry c_rec; | 230 | struct CredentialEntry c_rec; |
237 | unsigned int i; | 231 | unsigned int i; |
@@ -240,15 +234,15 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | |||
240 | off = 0; | 234 | off = 0; |
241 | for (i = 0; i < c_count; i++) | 235 | for (i = 0; i < c_count; i++) |
242 | { | 236 | { |
243 | if (off + sizeof(c_rec) > len) | 237 | if (off + sizeof (c_rec) > len) |
244 | return GNUNET_SYSERR; | 238 | return GNUNET_SYSERR; |
245 | GNUNET_memcpy (&c_rec, &src[off], sizeof(c_rec)); | 239 | GNUNET_memcpy (&c_rec, &src[off], sizeof (c_rec)); |
246 | cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len); | 240 | cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len); |
247 | cd[i].issuer_key = c_rec.issuer_key; | 241 | cd[i].issuer_key = c_rec.issuer_key; |
248 | cd[i].subject_key = c_rec.subject_key; | 242 | cd[i].subject_key = c_rec.subject_key; |
249 | cd[i].signature = c_rec.signature; | 243 | cd[i].signature = c_rec.signature; |
250 | cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration); | 244 | cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration); |
251 | off += sizeof(c_rec); | 245 | off += sizeof (c_rec); |
252 | if (off + cd[i].issuer_attribute_len > len) | 246 | if (off + cd[i].issuer_attribute_len > len) |
253 | return GNUNET_SYSERR; | 247 | return GNUNET_SYSERR; |
254 | cd[i].issuer_attribute = &src[off]; | 248 | cd[i].issuer_attribute = &src[off]; |
@@ -258,7 +252,6 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | |||
258 | } | 252 | } |
259 | 253 | ||
260 | 254 | ||
261 | |||
262 | /** | 255 | /** |
263 | * Calculate how many bytes we will need to serialize | 256 | * Calculate how many bytes we will need to serialize |
264 | * the given delegation chain and credential | 257 | * the given delegation chain and credential |
@@ -270,23 +263,21 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, | |||
270 | * @return the required size to serialize | 263 | * @return the required size to serialize |
271 | */ | 264 | */ |
272 | size_t | 265 | size_t |
273 | GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, | 266 | GNUNET_CREDENTIAL_delegation_chain_get_size ( |
274 | const struct | 267 | unsigned int d_count, |
275 | GNUNET_CREDENTIAL_Delegation *dd, | 268 | const struct GNUNET_CREDENTIAL_Delegation *dd, |
276 | unsigned int c_count, | 269 | unsigned int c_count, |
277 | const struct | 270 | const struct GNUNET_CREDENTIAL_Credential *cd) |
278 | GNUNET_CREDENTIAL_Credential *cd) | ||
279 | { | 271 | { |
280 | unsigned int i; | 272 | unsigned int i; |
281 | size_t ret; | 273 | size_t ret; |
282 | 274 | ||
283 | ret = sizeof(struct ChainEntry) * (d_count); | 275 | ret = sizeof (struct ChainEntry) * (d_count); |
284 | 276 | ||
285 | for (i = 0; i < d_count; i++) | 277 | for (i = 0; i < d_count; i++) |
286 | { | 278 | { |
287 | GNUNET_assert ((ret | 279 | GNUNET_assert ( |
288 | + dd[i].issuer_attribute_len | 280 | (ret + dd[i].issuer_attribute_len + dd[i].subject_attribute_len) >= ret); |
289 | + dd[i].subject_attribute_len) >= ret); | ||
290 | ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; | 281 | ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; |
291 | } | 282 | } |
292 | return ret + GNUNET_CREDENTIAL_credentials_get_size (c_count, cd); | 283 | return ret + GNUNET_CREDENTIAL_credentials_get_size (c_count, cd); |
@@ -304,14 +295,13 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, | |||
304 | * @return the size of the data, -1 on failure | 295 | * @return the size of the data, -1 on failure |
305 | */ | 296 | */ |
306 | ssize_t | 297 | ssize_t |
307 | GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, | 298 | GNUNET_CREDENTIAL_delegation_chain_serialize ( |
308 | const struct | 299 | unsigned int d_count, |
309 | GNUNET_CREDENTIAL_Delegation *dd, | 300 | const struct GNUNET_CREDENTIAL_Delegation *dd, |
310 | unsigned int c_count, | 301 | unsigned int c_count, |
311 | const struct | 302 | const struct GNUNET_CREDENTIAL_Credential *cd, |
312 | GNUNET_CREDENTIAL_Credential *cd, | 303 | size_t dest_size, |
313 | size_t dest_size, | 304 | char *dest) |
314 | char *dest) | ||
315 | { | 305 | { |
316 | struct ChainEntry rec; | 306 | struct ChainEntry rec; |
317 | unsigned int i; | 307 | unsigned int i; |
@@ -324,12 +314,10 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, | |||
324 | rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len); | 314 | rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len); |
325 | rec.issuer_key = dd[i].issuer_key; | 315 | rec.issuer_key = dd[i].issuer_key; |
326 | rec.subject_key = dd[i].subject_key; | 316 | rec.subject_key = dd[i].subject_key; |
327 | if (off + sizeof(rec) > dest_size) | 317 | if (off + sizeof (rec) > dest_size) |
328 | return -1; | 318 | return -1; |
329 | GNUNET_memcpy (&dest[off], | 319 | GNUNET_memcpy (&dest[off], &rec, sizeof (rec)); |
330 | &rec, | 320 | off += sizeof (rec); |
331 | sizeof(rec)); | ||
332 | off += sizeof(rec); | ||
333 | if (off + dd[i].issuer_attribute_len > dest_size) | 321 | if (off + dd[i].issuer_attribute_len > dest_size) |
334 | return -1; | 322 | return -1; |
335 | GNUNET_memcpy (&dest[off], | 323 | GNUNET_memcpy (&dest[off], |
@@ -364,14 +352,13 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, | |||
364 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 352 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
365 | */ | 353 | */ |
366 | int | 354 | int |
367 | GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, | 355 | GNUNET_CREDENTIAL_delegation_chain_deserialize ( |
368 | const char *src, | 356 | size_t len, |
369 | unsigned int d_count, | 357 | const char *src, |
370 | struct | 358 | unsigned int d_count, |
371 | GNUNET_CREDENTIAL_Delegation *dd, | 359 | struct GNUNET_CREDENTIAL_Delegation *dd, |
372 | unsigned int c_count, | 360 | unsigned int c_count, |
373 | struct | 361 | struct GNUNET_CREDENTIAL_Credential *cd) |
374 | GNUNET_CREDENTIAL_Credential *cd) | ||
375 | { | 362 | { |
376 | struct ChainEntry rec; | 363 | struct ChainEntry rec; |
377 | unsigned int i; | 364 | unsigned int i; |
@@ -380,13 +367,13 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, | |||
380 | off = 0; | 367 | off = 0; |
381 | for (i = 0; i < d_count; i++) | 368 | for (i = 0; i < d_count; i++) |
382 | { | 369 | { |
383 | if (off + sizeof(rec) > len) | 370 | if (off + sizeof (rec) > len) |
384 | return GNUNET_SYSERR; | 371 | return GNUNET_SYSERR; |
385 | GNUNET_memcpy (&rec, &src[off], sizeof(rec)); | 372 | GNUNET_memcpy (&rec, &src[off], sizeof (rec)); |
386 | dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); | 373 | dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); |
387 | dd[i].issuer_key = rec.issuer_key; | 374 | dd[i].issuer_key = rec.issuer_key; |
388 | dd[i].subject_key = rec.subject_key; | 375 | dd[i].subject_key = rec.subject_key; |
389 | off += sizeof(rec); | 376 | off += sizeof (rec); |
390 | if (off + dd[i].issuer_attribute_len > len) | 377 | if (off + dd[i].issuer_attribute_len > len) |
391 | return GNUNET_SYSERR; | 378 | return GNUNET_SYSERR; |
392 | dd[i].issuer_attribute = &src[off]; | 379 | dd[i].issuer_attribute = &src[off]; |
@@ -404,66 +391,63 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, | |||
404 | } | 391 | } |
405 | 392 | ||
406 | int | 393 | int |
407 | GNUNET_CREDENTIAL_credential_serialize (struct | 394 | GNUNET_CREDENTIAL_credential_serialize ( |
408 | GNUNET_CREDENTIAL_Credential *cred, | 395 | struct GNUNET_CREDENTIAL_Credential *cred, |
409 | char **data) | 396 | char **data) |
410 | { | 397 | { |
411 | size_t size; | 398 | size_t size; |
412 | struct CredentialEntry *cdata; | 399 | struct CredentialEntry *cdata; |
413 | 400 | ||
414 | size = sizeof(struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; | 401 | size = sizeof (struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; |
415 | *data = GNUNET_malloc (size); | 402 | *data = GNUNET_malloc (size); |
416 | cdata = (struct CredentialEntry*) *data; | 403 | cdata = (struct CredentialEntry *) *data; |
417 | cdata->subject_key = cred->subject_key; | 404 | cdata->subject_key = cred->subject_key; |
418 | cdata->issuer_key = cred->issuer_key; | 405 | cdata->issuer_key = cred->issuer_key; |
419 | cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); | 406 | cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); |
420 | cdata->signature = cred->signature; | 407 | cdata->signature = cred->signature; |
421 | cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); | 408 | cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); |
422 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 409 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
423 | cdata->purpose.size = htonl (size - sizeof(struct | 410 | cdata->purpose.size = |
424 | GNUNET_CRYPTO_EcdsaSignature)); | 411 | htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); |
425 | GNUNET_memcpy (&cdata[1], | 412 | GNUNET_memcpy (&cdata[1], |
426 | cred->issuer_attribute, | 413 | cred->issuer_attribute, |
427 | strlen (cred->issuer_attribute)); | 414 | strlen (cred->issuer_attribute)); |
428 | 415 | ||
429 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( | 416 | if (GNUNET_OK != |
430 | GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | 417 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, |
431 | &cdata->purpose, | 418 | &cdata->purpose, |
432 | &cdata->signature, | 419 | &cdata->signature, |
433 | &cdata->issuer_key)) | 420 | &cdata->issuer_key)) |
434 | { | 421 | { |
435 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 422 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); |
436 | "Invalid credential\n"); | 423 | //return NULL; |
437 | // return NULL; | ||
438 | } | 424 | } |
439 | return size; | 425 | return size; |
440 | } | 426 | } |
441 | 427 | ||
442 | struct GNUNET_CREDENTIAL_Credential* | 428 | struct GNUNET_CREDENTIAL_Credential * |
443 | GNUNET_CREDENTIAL_credential_deserialize (const char*data, | 429 | GNUNET_CREDENTIAL_credential_deserialize (const char *data, size_t data_size) |
444 | size_t data_size) | ||
445 | { | 430 | { |
446 | struct GNUNET_CREDENTIAL_Credential *cred; | 431 | struct GNUNET_CREDENTIAL_Credential *cred; |
447 | struct CredentialEntry *cdata; | 432 | struct CredentialEntry *cdata; |
448 | char *issuer_attribute; | 433 | char *issuer_attribute; |
449 | 434 | ||
450 | if (data_size < sizeof(struct CredentialEntry)) | 435 | if (data_size < sizeof (struct CredentialEntry)) |
451 | return NULL; | 436 | return NULL; |
452 | cdata = (struct CredentialEntry*) data; | 437 | cdata = (struct CredentialEntry *) data; |
453 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( | 438 | if (GNUNET_OK != |
454 | GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | 439 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, |
455 | &cdata->purpose, | 440 | &cdata->purpose, |
456 | &cdata->signature, | 441 | &cdata->signature, |
457 | &cdata->issuer_key)) | 442 | &cdata->issuer_key)) |
458 | { | 443 | { |
459 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 444 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); |
460 | "Invalid credential\n"); | 445 | //return NULL; |
461 | // return NULL; | ||
462 | } | 446 | } |
463 | issuer_attribute = (char*) &cdata[1]; | 447 | issuer_attribute = (char *) &cdata[1]; |
464 | 448 | ||
465 | cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl ( | 449 | cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + |
466 | cdata->issuer_attribute_len)); | 450 | ntohl (cdata->issuer_attribute_len)); |
467 | 451 | ||
468 | cred->issuer_key = cdata->issuer_key; | 452 | cred->issuer_key = cdata->issuer_key; |
469 | cred->subject_key = cdata->subject_key; | 453 | cred->subject_key = cdata->subject_key; |
@@ -471,7 +455,7 @@ GNUNET_CREDENTIAL_credential_deserialize (const char*data, | |||
471 | issuer_attribute, | 455 | issuer_attribute, |
472 | ntohl (cdata->issuer_attribute_len)); | 456 | ntohl (cdata->issuer_attribute_len)); |
473 | cred->signature = cdata->signature; | 457 | cred->signature = cdata->signature; |
474 | cred->issuer_attribute = (char*) &cred[1]; | 458 | cred->issuer_attribute = (char *) &cred[1]; |
475 | cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); | 459 | cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); |
476 | return cred; | 460 | return cred; |
477 | } | 461 | } |
@@ -480,51 +464,60 @@ GNUNET_CREDENTIAL_credential_deserialize (const char*data, | |||
480 | 464 | ||
481 | int | 465 | int |
482 | GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, | 466 | GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, |
483 | char **data) | 467 | char **data) |
484 | { | 468 | { |
485 | size_t size; | 469 | size_t size; |
486 | struct DelegateEntry *cdata; | 470 | struct DelegateEntry *cdata; |
487 | int attr_len; | 471 | int attr_len; |
488 | 472 | ||
489 | // +1 for \0 | 473 | // +1 for \0 |
490 | if (0 == dele->subject_attribute_len){ | 474 | if (0 == dele->subject_attribute_len) |
475 | { | ||
491 | attr_len = dele->issuer_attribute_len + 1; | 476 | attr_len = dele->issuer_attribute_len + 1; |
492 | } else { | 477 | } |
478 | else | ||
479 | { | ||
493 | attr_len = dele->issuer_attribute_len + dele->subject_attribute_len + 2; | 480 | attr_len = dele->issuer_attribute_len + dele->subject_attribute_len + 2; |
494 | } | 481 | } |
495 | size = sizeof (struct DelegateEntry) + attr_len; | 482 | size = sizeof (struct DelegateEntry) + attr_len; |
496 | 483 | ||
497 | char tmp_str[attr_len]; | 484 | char tmp_str[attr_len]; |
498 | GNUNET_memcpy(tmp_str, dele->issuer_attribute, dele->issuer_attribute_len); | 485 | GNUNET_memcpy (tmp_str, dele->issuer_attribute, dele->issuer_attribute_len); |
499 | if (0 != dele->subject_attribute_len){ | 486 | if (0 != dele->subject_attribute_len) |
487 | { | ||
500 | tmp_str[dele->issuer_attribute_len] = '\0'; | 488 | tmp_str[dele->issuer_attribute_len] = '\0'; |
501 | GNUNET_memcpy(tmp_str + dele->issuer_attribute_len + 1, dele->subject_attribute, dele->subject_attribute_len); | 489 | GNUNET_memcpy (tmp_str + dele->issuer_attribute_len + 1, |
490 | dele->subject_attribute, | ||
491 | dele->subject_attribute_len); | ||
502 | } | 492 | } |
503 | tmp_str[attr_len - 1] = '\0'; | 493 | tmp_str[attr_len - 1] = '\0'; |
504 | 494 | ||
505 | *data = GNUNET_malloc (size); | 495 | *data = GNUNET_malloc (size); |
506 | cdata = (struct DelegateEntry*)*data; | 496 | cdata = (struct DelegateEntry *) *data; |
507 | cdata->subject_key = dele->subject_key; | 497 | cdata->subject_key = dele->subject_key; |
508 | cdata->issuer_key = dele->issuer_key; | 498 | cdata->issuer_key = dele->issuer_key; |
509 | cdata->expiration = GNUNET_htonll (dele->expiration.abs_value_us); | 499 | cdata->expiration = GNUNET_htonll (dele->expiration.abs_value_us); |
510 | cdata->signature = dele->signature; | 500 | cdata->signature = dele->signature; |
511 | cdata->issuer_attribute_len = htonl (dele->issuer_attribute_len + 1); | 501 | cdata->issuer_attribute_len = htonl (dele->issuer_attribute_len + 1); |
512 | if (0 == dele->subject_attribute_len){ | 502 | if (0 == dele->subject_attribute_len) |
503 | { | ||
513 | cdata->subject_attribute_len = htonl (0); | 504 | cdata->subject_attribute_len = htonl (0); |
514 | } else { | 505 | } |
506 | else | ||
507 | { | ||
515 | cdata->subject_attribute_len = htonl (dele->subject_attribute_len + 1); | 508 | cdata->subject_attribute_len = htonl (dele->subject_attribute_len + 1); |
516 | } | 509 | } |
517 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); | 510 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); |
518 | cdata->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 511 | cdata->purpose.size = |
512 | htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | ||
519 | 513 | ||
520 | GNUNET_memcpy (&cdata[1], | 514 | GNUNET_memcpy (&cdata[1], tmp_str, attr_len); |
521 | tmp_str, | ||
522 | attr_len); | ||
523 | 515 | ||
524 | if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_DELEGATE, | 516 | if (GNUNET_OK != |
525 | &cdata->purpose, | 517 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_DELEGATE, |
526 | &cdata->signature, | 518 | &cdata->purpose, |
527 | &cdata->issuer_key)) | 519 | &cdata->signature, |
520 | &cdata->issuer_key)) | ||
528 | { | 521 | { |
529 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Serialize: Invalid delegate\n"); | 522 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Serialize: Invalid delegate\n"); |
530 | return 0; | 523 | return 0; |
@@ -532,9 +525,8 @@ GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, | |||
532 | return size; | 525 | return size; |
533 | } | 526 | } |
534 | 527 | ||
535 | struct GNUNET_CREDENTIAL_Delegate* | 528 | struct GNUNET_CREDENTIAL_Delegate * |
536 | GNUNET_CREDENTIAL_delegate_deserialize (const char* data, | 529 | GNUNET_CREDENTIAL_delegate_deserialize (const char *data, size_t data_size) |
537 | size_t data_size) | ||
538 | { | 530 | { |
539 | struct GNUNET_CREDENTIAL_Delegate *dele; | 531 | struct GNUNET_CREDENTIAL_Delegate *dele; |
540 | struct DelegateEntry *cdata; | 532 | struct DelegateEntry *cdata; |
@@ -542,38 +534,40 @@ GNUNET_CREDENTIAL_delegate_deserialize (const char* data, | |||
542 | 534 | ||
543 | if (data_size < sizeof (struct DelegateEntry)) | 535 | if (data_size < sizeof (struct DelegateEntry)) |
544 | return NULL; | 536 | return NULL; |
545 | cdata = (struct DelegateEntry*)data; | 537 | cdata = (struct DelegateEntry *) data; |
546 | if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_DELEGATE, | 538 | if (GNUNET_OK != |
547 | &cdata->purpose, | 539 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_DELEGATE, |
548 | &cdata->signature, | 540 | &cdata->purpose, |
549 | &cdata->issuer_key)) | 541 | &cdata->signature, |
542 | &cdata->issuer_key)) | ||
550 | { | 543 | { |
551 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deserialize: Invalid delegate\n"); | 544 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deserialize: Invalid delegate\n"); |
552 | return NULL; | 545 | return NULL; |
553 | } | 546 | } |
554 | attr_combo_str = (char*)&cdata[1]; | 547 | attr_combo_str = (char *) &cdata[1]; |
555 | int iss_len = ntohl(cdata->issuer_attribute_len); | 548 | int iss_len = ntohl (cdata->issuer_attribute_len); |
556 | int sub_len = ntohl(cdata->subject_attribute_len); | 549 | int sub_len = ntohl (cdata->subject_attribute_len); |
557 | int attr_combo_len = iss_len + sub_len; | 550 | int attr_combo_len = iss_len + sub_len; |
558 | 551 | ||
559 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_combo_len); | 552 | dele = |
553 | GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_combo_len); | ||
560 | 554 | ||
561 | dele->issuer_key = cdata->issuer_key; | 555 | dele->issuer_key = cdata->issuer_key; |
562 | dele->subject_key = cdata->subject_key; | 556 | dele->subject_key = cdata->subject_key; |
563 | GNUNET_memcpy (&dele[1], | 557 | GNUNET_memcpy (&dele[1], attr_combo_str, attr_combo_len); |
564 | attr_combo_str, | ||
565 | attr_combo_len); | ||
566 | dele->signature = cdata->signature; | 558 | dele->signature = cdata->signature; |
567 | 559 | ||
568 | // Set the pointers for the attributes | 560 | // Set the pointers for the attributes |
569 | dele->issuer_attribute = (char*)&dele[1]; | 561 | dele->issuer_attribute = (char *) &dele[1]; |
570 | dele->issuer_attribute_len = iss_len; | 562 | dele->issuer_attribute_len = iss_len; |
571 | dele->subject_attribute_len = sub_len; | 563 | dele->subject_attribute_len = sub_len; |
572 | if(0 == sub_len){ | 564 | if (0 == sub_len) |
565 | { | ||
573 | dele->subject_attribute = NULL; | 566 | dele->subject_attribute = NULL; |
574 | } else { | 567 | } |
575 | dele->subject_attribute = (char*)&dele[1] + iss_len; | 568 | else |
576 | 569 | { | |
570 | dele->subject_attribute = (char *) &dele[1] + iss_len; | ||
577 | } | 571 | } |
578 | 572 | ||
579 | dele->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); | 573 | dele->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); |
diff --git a/src/credential/delegate_misc.c b/src/credential/delegate_misc.c index 5dd8609d6..e29859e8c 100644 --- a/src/credential/delegate_misc.c +++ b/src/credential/delegate_misc.c | |||
@@ -33,8 +33,9 @@ | |||
33 | #include "credential.h" | 33 | #include "credential.h" |
34 | #include <inttypes.h> | 34 | #include <inttypes.h> |
35 | 35 | ||
36 | char* | 36 | char * |
37 | GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *cred) | 37 | GNUNET_CREDENTIAL_delegate_to_string ( |
38 | const struct GNUNET_CREDENTIAL_Delegate *cred) | ||
38 | { | 39 | { |
39 | char *cred_str; | 40 | char *cred_str; |
40 | char *subject_pkey; | 41 | char *subject_pkey; |
@@ -43,26 +44,29 @@ GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *c | |||
43 | 44 | ||
44 | subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); | 45 | subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); |
45 | issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); | 46 | issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); |
46 | GNUNET_STRINGS_base64_encode ((char*)&cred->signature, | 47 | GNUNET_STRINGS_base64_encode ((char *) &cred->signature, |
47 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature), | 48 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature), |
48 | &signature); | 49 | &signature); |
49 | if(0 == cred->subject_attribute_len){ | 50 | if (0 == cred->subject_attribute_len) |
51 | { | ||
50 | GNUNET_asprintf (&cred_str, | 52 | GNUNET_asprintf (&cred_str, |
51 | "%s.%s -> %s | %s | %"SCNu64, | 53 | "%s.%s -> %s | %s | %" SCNu64, |
52 | issuer_pkey, | 54 | issuer_pkey, |
53 | cred->issuer_attribute, | 55 | cred->issuer_attribute, |
54 | subject_pkey, | 56 | subject_pkey, |
55 | signature, | 57 | signature, |
56 | cred->expiration.abs_value_us); | 58 | cred->expiration.abs_value_us); |
57 | } else { | 59 | } |
60 | else | ||
61 | { | ||
58 | GNUNET_asprintf (&cred_str, | 62 | GNUNET_asprintf (&cred_str, |
59 | "%s.%s -> %s.%s | %s | %"SCNu64, | 63 | "%s.%s -> %s.%s | %s | %" SCNu64, |
60 | issuer_pkey, | 64 | issuer_pkey, |
61 | cred->issuer_attribute, | 65 | cred->issuer_attribute, |
62 | subject_pkey, | 66 | subject_pkey, |
63 | cred->subject_attribute, | 67 | cred->subject_attribute, |
64 | signature, | 68 | signature, |
65 | cred->expiration.abs_value_us); | 69 | cred->expiration.abs_value_us); |
66 | } | 70 | } |
67 | GNUNET_free (subject_pkey); | 71 | GNUNET_free (subject_pkey); |
68 | GNUNET_free (issuer_pkey); | 72 | GNUNET_free (issuer_pkey); |
@@ -71,8 +75,8 @@ GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *c | |||
71 | return cred_str; | 75 | return cred_str; |
72 | } | 76 | } |
73 | 77 | ||
74 | struct GNUNET_CREDENTIAL_Delegate* | 78 | struct GNUNET_CREDENTIAL_Delegate * |
75 | GNUNET_CREDENTIAL_delegate_from_string (const char* s) | 79 | GNUNET_CREDENTIAL_delegate_from_string (const char *s) |
76 | { | 80 | { |
77 | struct GNUNET_CREDENTIAL_Delegate *dele; | 81 | struct GNUNET_CREDENTIAL_Delegate *dele; |
78 | size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; | 82 | size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; |
@@ -91,7 +95,7 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
91 | 95 | ||
92 | // If it's A.a <- B.b... | 96 | // If it's A.a <- B.b... |
93 | if (6 != SSCANF (s, | 97 | if (6 != SSCANF (s, |
94 | "%52s.%253s -> %52s.%253s | %s | %"SCNu64, | 98 | "%52s.%253s -> %52s.%253s | %s | %" SCNu64, |
95 | issuer_pkey, | 99 | issuer_pkey, |
96 | iss_attr, | 100 | iss_attr, |
97 | subject_pkey, | 101 | subject_pkey, |
@@ -101,59 +105,69 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
101 | { | 105 | { |
102 | // Try if it's A.a <- B | 106 | // Try if it's A.a <- B |
103 | if (5 != SSCANF (s, | 107 | if (5 != SSCANF (s, |
104 | "%52s.%253s -> %52s | %s | %"SCNu64, | 108 | "%52s.%253s -> %52s | %s | %" SCNu64, |
105 | issuer_pkey, | 109 | issuer_pkey, |
106 | iss_attr, | 110 | iss_attr, |
107 | subject_pkey, | 111 | subject_pkey, |
108 | signature, | 112 | signature, |
109 | &etime_abs.abs_value_us)) | 113 | &etime_abs.abs_value_us)) |
110 | { | 114 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to parse DEL record string `%s'\n", s); | 115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
116 | "Unable to parse DEL record string `%s'\n", | ||
117 | s); | ||
112 | return NULL; | 118 | return NULL; |
113 | } | 119 | } |
114 | } | 120 | } |
115 | 121 | ||
116 | // +1 for \0 | 122 | // +1 for \0 |
117 | int attr_len; | 123 | int attr_len; |
118 | if(strcmp(sub_attr,"") == 0) { | 124 | if (strcmp (sub_attr, "") == 0) |
125 | { | ||
119 | attr_len = strlen (iss_attr) + 1; | 126 | attr_len = strlen (iss_attr) + 1; |
120 | } else { | 127 | } |
121 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; | 128 | else |
129 | { | ||
130 | attr_len = strlen (iss_attr) + strlen (sub_attr) + 2; | ||
122 | } | 131 | } |
123 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); | 132 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); |
124 | 133 | ||
125 | char tmp_str[attr_len]; | 134 | char tmp_str[attr_len]; |
126 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); | 135 | GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr)); |
127 | if(strcmp(sub_attr,"") != 0) { | 136 | if (strcmp (sub_attr, "") != 0) |
128 | tmp_str[strlen(iss_attr)] = '\0'; | 137 | { |
129 | GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); | 138 | tmp_str[strlen (iss_attr)] = '\0'; |
139 | GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1, | ||
140 | sub_attr, | ||
141 | strlen (sub_attr)); | ||
130 | } | 142 | } |
131 | tmp_str[attr_len - 1] = '\0'; | 143 | tmp_str[attr_len - 1] = '\0'; |
132 | 144 | ||
133 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, | 145 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, |
134 | strlen (subject_pkey), | 146 | strlen (subject_pkey), |
135 | &dele->subject_key); | 147 | &dele->subject_key); |
136 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, | 148 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, |
137 | strlen (issuer_pkey), | 149 | strlen (issuer_pkey), |
138 | &dele->issuer_key); | 150 | &dele->issuer_key); |
139 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature, | 151 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == |
140 | strlen (signature), | 152 | GNUNET_STRINGS_base64_decode (signature, |
141 | (char**)&sig)); | 153 | strlen (signature), |
154 | (char **) &sig)); | ||
142 | dele->signature = *sig; | 155 | dele->signature = *sig; |
143 | dele->expiration = etime_abs; | 156 | dele->expiration = etime_abs; |
144 | GNUNET_free (sig); | 157 | GNUNET_free (sig); |
145 | 158 | ||
146 | GNUNET_memcpy (&dele[1], | 159 | GNUNET_memcpy (&dele[1], tmp_str, attr_len); |
147 | tmp_str, | ||
148 | attr_len); | ||
149 | 160 | ||
150 | dele->issuer_attribute = (char*)&dele[1]; | 161 | dele->issuer_attribute = (char *) &dele[1]; |
151 | dele->issuer_attribute_len = strlen (iss_attr); | 162 | dele->issuer_attribute_len = strlen (iss_attr); |
152 | if(strcmp(sub_attr,"") == 0) { | 163 | if (strcmp (sub_attr, "") == 0) |
164 | { | ||
153 | dele->subject_attribute = NULL; | 165 | dele->subject_attribute = NULL; |
154 | dele->subject_attribute_len = 0; | 166 | dele->subject_attribute_len = 0; |
155 | } else { | 167 | } |
156 | dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; | 168 | else |
169 | { | ||
170 | dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1; | ||
157 | dele->subject_attribute_len = strlen (sub_attr); | 171 | dele->subject_attribute_len = strlen (sub_attr); |
158 | } | 172 | } |
159 | 173 | ||
@@ -170,56 +184,62 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
170 | */ | 184 | */ |
171 | 185 | ||
172 | struct GNUNET_CREDENTIAL_Delegate * | 186 | struct GNUNET_CREDENTIAL_Delegate * |
173 | GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | 187 | GNUNET_CREDENTIAL_delegate_issue ( |
174 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, | 188 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, |
175 | const char *iss_attr, | 189 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, |
176 | const char *sub_attr, | 190 | const char *iss_attr, |
177 | struct GNUNET_TIME_Absolute *expiration) | 191 | const char *sub_attr, |
192 | struct GNUNET_TIME_Absolute *expiration) | ||
178 | { | 193 | { |
179 | struct DelegateEntry *del; | 194 | struct DelegateEntry *del; |
180 | struct GNUNET_CREDENTIAL_Delegate *dele; | 195 | struct GNUNET_CREDENTIAL_Delegate *dele; |
181 | size_t size; | 196 | size_t size; |
182 | int attr_len; | 197 | int attr_len; |
183 | 198 | ||
184 | if (NULL == sub_attr){ | 199 | if (NULL == sub_attr) |
200 | { | ||
185 | // +1 for \0 | 201 | // +1 for \0 |
186 | attr_len = strlen (iss_attr) + 1; | 202 | attr_len = strlen (iss_attr) + 1; |
187 | } else { | 203 | } |
204 | else | ||
205 | { | ||
188 | // +2 for both strings need to be terminated with \0 | 206 | // +2 for both strings need to be terminated with \0 |
189 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; | 207 | attr_len = strlen (iss_attr) + strlen (sub_attr) + 2; |
190 | } | 208 | } |
191 | size = sizeof (struct DelegateEntry) + attr_len; | 209 | size = sizeof (struct DelegateEntry) + attr_len; |
192 | 210 | ||
193 | char tmp_str[attr_len]; | 211 | char tmp_str[attr_len]; |
194 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); | 212 | GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr)); |
195 | if (NULL != sub_attr){ | 213 | if (NULL != sub_attr) |
196 | tmp_str[strlen(iss_attr)] = '\0'; | 214 | { |
197 | GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); | 215 | tmp_str[strlen (iss_attr)] = '\0'; |
216 | GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1, | ||
217 | sub_attr, | ||
218 | strlen (sub_attr)); | ||
198 | } | 219 | } |
199 | tmp_str[attr_len - 1] = '\0'; | 220 | tmp_str[attr_len - 1] = '\0'; |
200 | 221 | ||
201 | del = GNUNET_malloc (size); | 222 | del = GNUNET_malloc (size); |
202 | del->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 223 | del->purpose.size = |
224 | htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | ||
203 | del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); | 225 | del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); |
204 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 226 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, &del->issuer_key); |
205 | &del->issuer_key); | ||
206 | del->subject_key = *subject; | 227 | del->subject_key = *subject; |
207 | del->expiration = GNUNET_htonll (expiration->abs_value_us); | 228 | del->expiration = GNUNET_htonll (expiration->abs_value_us); |
208 | del->issuer_attribute_len = htonl (strlen (iss_attr) + 1); | 229 | del->issuer_attribute_len = htonl (strlen (iss_attr) + 1); |
209 | if (NULL == sub_attr){ | 230 | if (NULL == sub_attr) |
231 | { | ||
210 | del->subject_attribute_len = htonl (0); | 232 | del->subject_attribute_len = htonl (0); |
211 | } else { | 233 | } |
234 | else | ||
235 | { | ||
212 | del->subject_attribute_len = htonl (strlen (sub_attr) + 1); | 236 | del->subject_attribute_len = htonl (strlen (sub_attr) + 1); |
213 | } | 237 | } |
214 | 238 | ||
215 | GNUNET_memcpy (&del[1], | 239 | GNUNET_memcpy (&del[1], tmp_str, attr_len); |
216 | tmp_str, | 240 | |
217 | attr_len); | ||
218 | |||
219 | if (GNUNET_OK != | 241 | if (GNUNET_OK != |
220 | GNUNET_CRYPTO_ecdsa_sign (issuer, | 242 | GNUNET_CRYPTO_ecdsa_sign (issuer, &del->purpose, &del->signature)) |
221 | &del->purpose, | ||
222 | &del->signature)) | ||
223 | { | 243 | { |
224 | GNUNET_break (0); | 244 | GNUNET_break (0); |
225 | GNUNET_free (del); | 245 | GNUNET_free (del); |
@@ -229,24 +249,24 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is | |||
229 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); | 249 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); |
230 | dele->signature = del->signature; | 250 | dele->signature = del->signature; |
231 | dele->expiration = *expiration; | 251 | dele->expiration = *expiration; |
232 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 252 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, &dele->issuer_key); |
233 | &dele->issuer_key); | ||
234 | 253 | ||
235 | dele->subject_key = *subject; | 254 | dele->subject_key = *subject; |
236 | 255 | ||
237 | // Copy the combined string at the part in the memory where the struct ends | 256 | // Copy the combined string at the part in the memory where the struct ends |
238 | GNUNET_memcpy (&dele[1], | 257 | GNUNET_memcpy (&dele[1], tmp_str, attr_len); |
239 | tmp_str, | ||
240 | attr_len); | ||
241 | 258 | ||
242 | dele->issuer_attribute = (char*)&dele[1]; | 259 | dele->issuer_attribute = (char *) &dele[1]; |
243 | dele->issuer_attribute_len = strlen(iss_attr); | 260 | dele->issuer_attribute_len = strlen (iss_attr); |
244 | if (NULL == sub_attr){ | 261 | if (NULL == sub_attr) |
262 | { | ||
245 | dele->subject_attribute = NULL; | 263 | dele->subject_attribute = NULL; |
246 | dele->subject_attribute_len = 0; | 264 | dele->subject_attribute_len = 0; |
247 | } else { | 265 | } |
248 | dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; | 266 | else |
249 | dele->subject_attribute_len = strlen(sub_attr); | 267 | { |
268 | dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1; | ||
269 | dele->subject_attribute_len = strlen (sub_attr); | ||
250 | } | 270 | } |
251 | 271 | ||
252 | GNUNET_free (del); | 272 | GNUNET_free (del); |
@@ -256,5 +276,3 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is | |||
256 | // oder: pointer auf cred[1], aber nach jedem string im combined string ein EOS <- besser | 276 | // oder: pointer auf cred[1], aber nach jedem string im combined string ein EOS <- besser |
257 | // function comment: cred must be freed by caller, (add missing sub_iss) | 277 | // function comment: cred must be freed by caller, (add missing sub_iss) |
258 | } | 278 | } |
259 | |||
260 | |||
diff --git a/src/credential/gnunet-credential.c b/src/credential/gnunet-credential.c index 3d20e7082..55a4653fb 100644 --- a/src/credential/gnunet-credential.c +++ b/src/credential/gnunet-credential.c | |||
@@ -251,22 +251,21 @@ do_timeout (void *cls) | |||
251 | 251 | ||
252 | static void | 252 | static void |
253 | handle_collect_result (void *cls, | 253 | handle_collect_result (void *cls, |
254 | unsigned int d_count, | 254 | unsigned int d_count, |
255 | struct GNUNET_CREDENTIAL_Delegation *dc, | 255 | struct GNUNET_CREDENTIAL_Delegation *dc, |
256 | unsigned int c_count, | 256 | unsigned int c_count, |
257 | struct GNUNET_CREDENTIAL_Credential *cred) | 257 | struct GNUNET_CREDENTIAL_Credential *cred) |
258 | { | 258 | { |
259 | int i; | 259 | int i; |
260 | char* line; | 260 | char *line; |
261 | 261 | ||
262 | verify_request = NULL; | 262 | verify_request = NULL; |
263 | if (NULL != cred) | 263 | if (NULL != cred) |
264 | { | 264 | { |
265 | for (i=0;i<c_count;i++) | 265 | for (i = 0; i < c_count; i++) |
266 | { | 266 | { |
267 | line = GNUNET_CREDENTIAL_credential_to_string (&cred[i]); | 267 | line = GNUNET_CREDENTIAL_credential_to_string (&cred[i]); |
268 | printf ("%s\n", | 268 | printf ("%s\n", line); |
269 | line); | ||
270 | GNUNET_free (line); | 269 | GNUNET_free (line); |
271 | } | 270 | } |
272 | } | 271 | } |
@@ -284,44 +283,48 @@ handle_verify_result (void *cls, | |||
284 | struct GNUNET_CREDENTIAL_Credential *cred) | 283 | struct GNUNET_CREDENTIAL_Credential *cred) |
285 | { | 284 | { |
286 | int i; | 285 | int i; |
287 | char* iss_key; | 286 | char *iss_key; |
288 | char* sub_key; | 287 | char *sub_key; |
289 | 288 | ||
290 | verify_request = NULL; | 289 | verify_request = NULL; |
291 | if (NULL == cred) | 290 | if (NULL == cred) |
292 | printf ("Failed.\n"); | 291 | printf ("Failed.\n"); |
293 | else | 292 | else |
294 | { | 293 | { |
295 | printf("Delegation Chain:\n"); | 294 | printf ("Delegation Chain:\n"); |
296 | for (i=0;i<d_count;i++) | 295 | for (i = 0; i < d_count; i++) |
297 | { | 296 | { |
298 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].issuer_key); | 297 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].issuer_key); |
299 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].subject_key); | 298 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].subject_key); |
300 | 299 | ||
301 | if (0 != dc[i].subject_attribute_len) | 300 | if (0 != dc[i].subject_attribute_len) |
302 | { | 301 | { |
303 | printf ("(%d) %s.%s <- %s.%s\n", i, | 302 | printf ("(%d) %s.%s <- %s.%s\n", |
304 | iss_key, dc[i].issuer_attribute, | 303 | i, |
305 | sub_key, dc[i].subject_attribute); | 304 | iss_key, |
306 | } else { | 305 | dc[i].issuer_attribute, |
307 | printf ("(%d) %s.%s <- %s\n", i, | 306 | sub_key, |
308 | iss_key, dc[i].issuer_attribute, | 307 | dc[i].subject_attribute); |
308 | } | ||
309 | else | ||
310 | { | ||
311 | printf ("(%d) %s.%s <- %s\n", | ||
312 | i, | ||
313 | iss_key, | ||
314 | dc[i].issuer_attribute, | ||
309 | sub_key); | 315 | sub_key); |
310 | } | 316 | } |
311 | GNUNET_free (iss_key); | 317 | GNUNET_free (iss_key); |
312 | GNUNET_free (sub_key); | 318 | GNUNET_free (sub_key); |
313 | } | 319 | } |
314 | printf("\nCredentials:\n"); | 320 | printf ("\nCredentials:\n"); |
315 | for (i=0;i<c_count;i++) | 321 | for (i = 0; i < c_count; i++) |
316 | { | 322 | { |
317 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].issuer_key); | 323 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].issuer_key); |
318 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].subject_key); | 324 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].subject_key); |
319 | printf ("%s.%s <- %s\n", | 325 | printf ("%s.%s <- %s\n", iss_key, cred[i].issuer_attribute, sub_key); |
320 | iss_key, cred[i].issuer_attribute, | ||
321 | sub_key); | ||
322 | GNUNET_free (iss_key); | 326 | GNUNET_free (iss_key); |
323 | GNUNET_free (sub_key); | 327 | GNUNET_free (sub_key); |
324 | |||
325 | } | 328 | } |
326 | printf ("Successful.\n"); | 329 | printf ("Successful.\n"); |
327 | } | 330 | } |
@@ -338,8 +341,7 @@ handle_verify_result (void *cls, | |||
338 | * @param ego an ego known to identity service, or NULL | 341 | * @param ego an ego known to identity service, or NULL |
339 | */ | 342 | */ |
340 | static void | 343 | static void |
341 | identity_cb (void *cls, | 344 | identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
342 | const struct GNUNET_IDENTITY_Ego *ego) | ||
343 | { | 345 | { |
344 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 346 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
345 | struct GNUNET_CREDENTIAL_Credential *cred; | 347 | struct GNUNET_CREDENTIAL_Credential *cred; |
@@ -353,7 +355,7 @@ identity_cb (void *cls, | |||
353 | if (NULL != ego_name) | 355 | if (NULL != ego_name) |
354 | { | 356 | { |
355 | fprintf (stderr, | 357 | fprintf (stderr, |
356 | _("Ego `%s' not known to identity service\n"), | 358 | _ ("Ego `%s' not known to identity service\n"), |
357 | ego_name); | 359 | ego_name); |
358 | } | 360 | } |
359 | GNUNET_SCHEDULER_shutdown (); | 361 | GNUNET_SCHEDULER_shutdown (); |
@@ -362,25 +364,25 @@ identity_cb (void *cls, | |||
362 | 364 | ||
363 | if (GNUNET_YES == collect) | 365 | if (GNUNET_YES == collect) |
364 | { | 366 | { |
365 | 367 | ||
366 | if (GNUNET_OK != | 368 | if (GNUNET_OK != |
367 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key, | 369 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key, |
368 | strlen (issuer_key), | 370 | strlen (issuer_key), |
369 | &issuer_pkey)) | 371 | &issuer_pkey)) |
370 | { | 372 | { |
371 | fprintf (stderr, | 373 | fprintf (stderr, |
372 | _("Issuer public key `%s' is not well-formed\n"), | 374 | _ ("Issuer public key `%s' is not well-formed\n"), |
373 | issuer_key); | 375 | issuer_key); |
374 | GNUNET_SCHEDULER_shutdown (); | 376 | GNUNET_SCHEDULER_shutdown (); |
375 | } | 377 | } |
376 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 378 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
377 | 379 | ||
378 | collect_request = GNUNET_CREDENTIAL_collect(credential, | 380 | collect_request = GNUNET_CREDENTIAL_collect (credential, |
379 | &issuer_pkey, | 381 | &issuer_pkey, |
380 | issuer_attr, //TODO argument | 382 | issuer_attr, //TODO argument |
381 | privkey, | 383 | privkey, |
382 | &handle_collect_result, | 384 | &handle_collect_result, |
383 | NULL); | 385 | NULL); |
384 | return; | 386 | return; |
385 | } | 387 | } |
386 | 388 | ||
@@ -388,20 +390,19 @@ identity_cb (void *cls, | |||
388 | 390 | ||
389 | if (NULL == expiration) | 391 | if (NULL == expiration) |
390 | { | 392 | { |
391 | fprintf (stderr, | 393 | fprintf (stderr, "Please specify a TTL\n"); |
392 | "Please specify a TTL\n"); | ||
393 | GNUNET_SCHEDULER_shutdown (); | 394 | GNUNET_SCHEDULER_shutdown (); |
394 | return; | 395 | return; |
395 | } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration, | 396 | } |
396 | &etime_rel)) | 397 | else if (GNUNET_OK == |
398 | GNUNET_STRINGS_fancy_time_to_relative (expiration, &etime_rel)) | ||
397 | { | 399 | { |
398 | etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel); | 400 | etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel); |
399 | } else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration, | 401 | } |
400 | &etime_abs)) | 402 | else if (GNUNET_OK != |
403 | GNUNET_STRINGS_fancy_time_to_absolute (expiration, &etime_abs)) | ||
401 | { | 404 | { |
402 | fprintf (stderr, | 405 | fprintf (stderr, "%s is not a valid ttl!\n", expiration); |
403 | "%s is not a valid ttl!\n", | ||
404 | expiration); | ||
405 | GNUNET_SCHEDULER_shutdown (); | 406 | GNUNET_SCHEDULER_shutdown (); |
406 | return; | 407 | return; |
407 | } | 408 | } |
@@ -411,9 +412,9 @@ identity_cb (void *cls, | |||
411 | GNUNET_free_non_null (ego_name); | 412 | GNUNET_free_non_null (ego_name); |
412 | ego_name = NULL; | 413 | ego_name = NULL; |
413 | cred = GNUNET_CREDENTIAL_credential_issue (privkey, | 414 | cred = GNUNET_CREDENTIAL_credential_issue (privkey, |
414 | &subject_pkey, | 415 | &subject_pkey, |
415 | issuer_attr, | 416 | issuer_attr, |
416 | &etime_abs); | 417 | &etime_abs); |
417 | 418 | ||
418 | res = GNUNET_CREDENTIAL_credential_to_string (cred); | 419 | res = GNUNET_CREDENTIAL_credential_to_string (cred); |
419 | GNUNET_free (cred); | 420 | GNUNET_free (cred); |
@@ -431,41 +432,37 @@ identity_cb (void *cls, | |||
431 | */ | 432 | */ |
432 | static int | 433 | static int |
433 | parse_expiration (const char *expirationstring, | 434 | parse_expiration (const char *expirationstring, |
434 | int *etime_is_rel, | 435 | int *etime_is_rel, |
435 | uint64_t *etime) | 436 | uint64_t *etime) |
436 | { | 437 | { |
437 | // copied from namestore/gnunet-namestore.c | 438 | // copied from namestore/gnunet-namestore.c |
438 | struct GNUNET_TIME_Relative etime_rel; | 439 | struct GNUNET_TIME_Relative etime_rel; |
439 | struct GNUNET_TIME_Absolute etime_abs; | 440 | struct GNUNET_TIME_Absolute etime_abs; |
440 | 441 | ||
441 | if (0 == strcmp (expirationstring, | 442 | if (0 == strcmp (expirationstring, "never")) |
442 | "never")) | ||
443 | { | 443 | { |
444 | *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 444 | *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
445 | *etime_is_rel = GNUNET_NO; | 445 | *etime_is_rel = GNUNET_NO; |
446 | return GNUNET_OK; | 446 | return GNUNET_OK; |
447 | } | 447 | } |
448 | if (GNUNET_OK == | 448 | if (GNUNET_OK == |
449 | GNUNET_STRINGS_fancy_time_to_relative (expirationstring, | 449 | GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel)) |
450 | &etime_rel)) | ||
451 | { | 450 | { |
452 | *etime_is_rel = GNUNET_YES; | 451 | *etime_is_rel = GNUNET_YES; |
453 | *etime = etime_rel.rel_value_us; | 452 | *etime = etime_rel.rel_value_us; |
454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
455 | "Storing record with relative expiration time of %s\n", | 454 | "Storing record with relative expiration time of %s\n", |
456 | GNUNET_STRINGS_relative_time_to_string (etime_rel, | 455 | GNUNET_STRINGS_relative_time_to_string (etime_rel, GNUNET_NO)); |
457 | GNUNET_NO)); | ||
458 | return GNUNET_OK; | 456 | return GNUNET_OK; |
459 | } | 457 | } |
460 | if (GNUNET_OK == | 458 | if (GNUNET_OK == |
461 | GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, | 459 | GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs)) |
462 | &etime_abs)) | ||
463 | { | 460 | { |
464 | *etime_is_rel = GNUNET_NO; | 461 | *etime_is_rel = GNUNET_NO; |
465 | *etime = etime_abs.abs_value_us; | 462 | *etime = etime_abs.abs_value_us; |
466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
467 | "Storing record with absolute expiration time of %s\n", | 464 | "Storing record with absolute expiration time of %s\n", |
468 | GNUNET_STRINGS_absolute_time_to_string (etime_abs)); | 465 | GNUNET_STRINGS_absolute_time_to_string (etime_abs)); |
469 | return GNUNET_OK; | 466 | return GNUNET_OK; |
470 | } | 467 | } |
471 | return GNUNET_SYSERR; | 468 | return GNUNET_SYSERR; |
@@ -477,14 +474,12 @@ parse_expiration (const char *expirationstring, | |||
477 | static void | 474 | static void |
478 | error_cb (void *cls) | 475 | error_cb (void *cls) |
479 | { | 476 | { |
480 | fprintf(stderr, "Error occured during lookup, shutting down.\n"); | 477 | fprintf (stderr, "Error occured during lookup, shutting down.\n"); |
481 | GNUNET_SCHEDULER_shutdown (); | 478 | GNUNET_SCHEDULER_shutdown (); |
482 | return; | 479 | return; |
483 | } | 480 | } |
484 | static void | 481 | static void |
485 | add_continuation (void *cls, | 482 | add_continuation (void *cls, int32_t success, const char *emsg) |
486 | int32_t success, | ||
487 | const char *emsg) | ||
488 | { | 483 | { |
489 | // TODO what does that do, can I somehow parse an empty callback on success or do I have to set the qe* to NULL? | 484 | // TODO what does that do, can I somehow parse an empty callback on success or do I have to set the qe* to NULL? |
490 | struct GNUNET_NAMESTORE_QueueEntry **qe = cls; | 485 | struct GNUNET_NAMESTORE_QueueEntry **qe = cls; |
@@ -495,18 +490,16 @@ add_continuation (void *cls, | |||
495 | 490 | ||
496 | static void | 491 | static void |
497 | get_existing_record (void *cls, | 492 | get_existing_record (void *cls, |
498 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 493 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
499 | const char *rec_name, | 494 | const char *rec_name, |
500 | unsigned int rd_count, | 495 | unsigned int rd_count, |
501 | const struct GNUNET_GNSRECORD_Data *rd) | 496 | const struct GNUNET_GNSRECORD_Data *rd) |
502 | { | 497 | { |
503 | struct GNUNET_GNSRECORD_Data rdn[rd_count + 1]; | 498 | struct GNUNET_GNSRECORD_Data rdn[rd_count + 1]; |
504 | struct GNUNET_GNSRECORD_Data *rde; | 499 | struct GNUNET_GNSRECORD_Data *rde; |
505 | 500 | ||
506 | memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data)); | 501 | memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data)); |
507 | GNUNET_memcpy (&rdn[1], | 502 | GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_GNSRECORD_Data)); |
508 | rd, | ||
509 | rd_count * sizeof (struct GNUNET_GNSRECORD_Data)); | ||
510 | rde = &rdn[0]; | 503 | rde = &rdn[0]; |
511 | rde->data = data; | 504 | rde->data = data; |
512 | rde->data_size = data_size; | 505 | rde->data_size = data_size; |
@@ -523,29 +516,28 @@ get_existing_record (void *cls, | |||
523 | rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 516 | rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
524 | GNUNET_assert (NULL != rec_name); | 517 | GNUNET_assert (NULL != rec_name); |
525 | add_qe = GNUNET_NAMESTORE_records_store (ns, | 518 | add_qe = GNUNET_NAMESTORE_records_store (ns, |
526 | &zone_pkey, | 519 | &zone_pkey, |
527 | rec_name, | 520 | rec_name, |
528 | rd_count + 1, | 521 | rd_count + 1, |
529 | rde, | 522 | rde, |
530 | &add_continuation, | 523 | &add_continuation, |
531 | &add_qe); | 524 | &add_qe); |
532 | 525 | ||
533 | return; | 526 | return; |
534 | } | 527 | } |
535 | 528 | ||
536 | static void | 529 | static void |
537 | store_cb (void *cls, | 530 | store_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
538 | const struct GNUNET_IDENTITY_Ego *ego) | ||
539 | { | 531 | { |
540 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 532 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
541 | 533 | ||
542 | el = NULL; | 534 | el = NULL; |
543 | 535 | ||
544 | ns = GNUNET_NAMESTORE_connect (cfg); | 536 | ns = GNUNET_NAMESTORE_connect (cfg); |
545 | if (NULL == ns) | 537 | if (NULL == ns) |
546 | { | 538 | { |
547 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 539 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
548 | _("Failed to connect to namestore\n")); | 540 | _ ("Failed to connect to namestore\n")); |
549 | GNUNET_SCHEDULER_shutdown (); | 541 | GNUNET_SCHEDULER_shutdown (); |
550 | return; | 542 | return; |
551 | } | 543 | } |
@@ -554,23 +546,27 @@ store_cb (void *cls, | |||
554 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | 546 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); |
555 | 547 | ||
556 | // TODO maybe dont have to set subject, if only used in if/else can use import here instead!! | 548 | // TODO maybe dont have to set subject, if only used in if/else can use import here instead!! |
557 | if( GNUNET_GNSRECORD_TYPE_DELEGATE == type){ | 549 | if (GNUNET_GNSRECORD_TYPE_DELEGATE == type) |
550 | { | ||
558 | // Parse import | 551 | // Parse import |
559 | struct GNUNET_CREDENTIAL_Delegate *cred; | 552 | struct GNUNET_CREDENTIAL_Delegate *cred; |
560 | cred = GNUNET_CREDENTIAL_delegate_from_string (import); | 553 | cred = GNUNET_CREDENTIAL_delegate_from_string (import); |
561 | 554 | ||
562 | // Get import subject public key string | 555 | // Get import subject public key string |
563 | char *subject_pubkey_str = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key); | 556 | char *subject_pubkey_str = |
557 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); | ||
564 | 558 | ||
565 | // Get zone public key string | 559 | // Get zone public key string |
566 | struct GNUNET_CRYPTO_EcdsaPublicKey zone_pubkey; | 560 | struct GNUNET_CRYPTO_EcdsaPublicKey zone_pubkey; |
567 | GNUNET_IDENTITY_ego_get_public_key (ego, &zone_pubkey); | 561 | GNUNET_IDENTITY_ego_get_public_key (ego, &zone_pubkey); |
568 | char *zone_pubkey_str = GNUNET_CRYPTO_ecdsa_public_key_to_string(&zone_pubkey); | 562 | char *zone_pubkey_str = |
563 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&zone_pubkey); | ||
569 | 564 | ||
570 | // Check if the subject key in the signed import matches the zone's key it is issued to | 565 | // Check if the subject key in the signed import matches the zone's key it is issued to |
571 | if(strcmp(zone_pubkey_str, subject_pubkey_str) != 0) | 566 | if (strcmp (zone_pubkey_str, subject_pubkey_str) != 0) |
572 | { | 567 | { |
573 | fprintf (stderr, "Import signed delegate does not match this ego's public key.\n"); | 568 | fprintf (stderr, |
569 | "Import signed delegate does not match this ego's public key.\n"); | ||
574 | GNUNET_SCHEDULER_shutdown (); | 570 | GNUNET_SCHEDULER_shutdown (); |
575 | return; | 571 | return; |
576 | } | 572 | } |
@@ -580,18 +576,19 @@ store_cb (void *cls, | |||
580 | etime_is_rel = GNUNET_NO; | 576 | etime_is_rel = GNUNET_NO; |
581 | 577 | ||
582 | // Prepare the data to be store in the record | 578 | // Prepare the data to be store in the record |
583 | data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **)&data); | 579 | data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **) &data); |
584 | GNUNET_free(cred); | 580 | GNUNET_free (cred); |
585 | } else { | 581 | } |
582 | else | ||
583 | { | ||
586 | // For all other types e.g. GNUNET_GNSRECORD_TYPE_ATTRIBUTE | 584 | // For all other types e.g. GNUNET_GNSRECORD_TYPE_ATTRIBUTE |
587 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (type, | 585 | if (GNUNET_OK != |
588 | subject, | 586 | GNUNET_GNSRECORD_string_to_value (type, subject, &data, &data_size)) |
589 | &data, | ||
590 | &data_size)) | ||
591 | { | 587 | { |
592 | fprintf (stderr, "Value `%s' invalid for record type `%s'\n", | 588 | fprintf (stderr, |
593 | subject, | 589 | "Value `%s' invalid for record type `%s'\n", |
594 | typestring); | 590 | subject, |
591 | typestring); | ||
595 | GNUNET_SCHEDULER_shutdown (); | 592 | GNUNET_SCHEDULER_shutdown (); |
596 | return; | 593 | return; |
597 | } | 594 | } |
@@ -603,12 +600,9 @@ store_cb (void *cls, | |||
603 | GNUNET_SCHEDULER_shutdown (); | 600 | GNUNET_SCHEDULER_shutdown (); |
604 | return; | 601 | return; |
605 | } | 602 | } |
606 | if (GNUNET_OK != parse_expiration (expiration, | 603 | if (GNUNET_OK != parse_expiration (expiration, &etime_is_rel, &etime)) |
607 | &etime_is_rel, | ||
608 | &etime)) | ||
609 | { | 604 | { |
610 | fprintf (stderr, "Invalid time format `%s'\n", | 605 | fprintf (stderr, "Invalid time format `%s'\n", expiration); |
611 | expiration); | ||
612 | GNUNET_SCHEDULER_shutdown (); | 606 | GNUNET_SCHEDULER_shutdown (); |
613 | return; | 607 | return; |
614 | } | 608 | } |
@@ -616,18 +610,17 @@ store_cb (void *cls, | |||
616 | 610 | ||
617 | // Start lookup | 611 | // Start lookup |
618 | add_qe = GNUNET_NAMESTORE_records_lookup (ns, | 612 | add_qe = GNUNET_NAMESTORE_records_lookup (ns, |
619 | &zone_pkey, | 613 | &zone_pkey, |
620 | record_label, | 614 | record_label, |
621 | &error_cb, | 615 | &error_cb, |
622 | NULL, | 616 | NULL, |
623 | &get_existing_record, | 617 | &get_existing_record, |
624 | NULL); | 618 | NULL); |
625 | return; | 619 | return; |
626 | } | 620 | } |
627 | 621 | ||
628 | static void | 622 | static void |
629 | sign_cb (void *cls, | 623 | sign_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
630 | const struct GNUNET_IDENTITY_Ego *ego) | ||
631 | { | 624 | { |
632 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 625 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
633 | struct GNUNET_CREDENTIAL_Delegate *dele; | 626 | struct GNUNET_CREDENTIAL_Delegate *dele; |
@@ -642,9 +635,13 @@ sign_cb (void *cls, | |||
642 | fprintf (stderr, "Please specify a TTL\n"); | 635 | fprintf (stderr, "Please specify a TTL\n"); |
643 | GNUNET_SCHEDULER_shutdown (); | 636 | GNUNET_SCHEDULER_shutdown (); |
644 | return; | 637 | return; |
645 | } else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration, &etime_abs)) | 638 | } |
639 | else if (GNUNET_OK != | ||
640 | GNUNET_STRINGS_fancy_time_to_absolute (expiration, &etime_abs)) | ||
646 | { | 641 | { |
647 | fprintf (stderr, "%s is not a valid ttl! Only absolute times are accepted!\n", expiration); | 642 | fprintf (stderr, |
643 | "%s is not a valid ttl! Only absolute times are accepted!\n", | ||
644 | expiration); | ||
648 | GNUNET_SCHEDULER_shutdown (); | 645 | GNUNET_SCHEDULER_shutdown (); |
649 | return; | 646 | return; |
650 | } | 647 | } |
@@ -656,17 +653,19 @@ sign_cb (void *cls, | |||
656 | 653 | ||
657 | // Subject Public Key | 654 | // Subject Public Key |
658 | token = strtok (subject, " "); | 655 | token = strtok (subject, " "); |
659 | if (key_length == strlen(token)) | 656 | if (key_length == strlen (token)) |
660 | { | 657 | { |
661 | subject_pubkey_str = token; | 658 | subject_pubkey_str = token; |
662 | } else { | 659 | } |
663 | fprintf (stderr, "Key error, wrong length: %ld!\n", strlen(token)); | 660 | else |
661 | { | ||
662 | fprintf (stderr, "Key error, wrong length: %ld!\n", strlen (token)); | ||
664 | GNUNET_SCHEDULER_shutdown (); | 663 | GNUNET_SCHEDULER_shutdown (); |
665 | return; | 664 | return; |
666 | } | 665 | } |
667 | // Subject Attribute(s) | 666 | // Subject Attribute(s) |
668 | token = strtok (NULL, " "); | 667 | token = strtok (NULL, " "); |
669 | if(NULL != token) | 668 | if (NULL != token) |
670 | { | 669 | { |
671 | subject_attr = token; | 670 | subject_attr = token; |
672 | } | 671 | } |
@@ -674,21 +673,24 @@ sign_cb (void *cls, | |||
674 | // work on keys | 673 | // work on keys |
675 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 674 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
676 | 675 | ||
677 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pubkey_str, | 676 | if (GNUNET_OK != |
677 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pubkey_str, | ||
678 | strlen (subject_pubkey_str), | 678 | strlen (subject_pubkey_str), |
679 | &subject_pkey)) | 679 | &subject_pkey)) |
680 | { | 680 | { |
681 | fprintf (stderr, "Subject public key `%s' is not well-formed\n", subject_pubkey_str); | 681 | fprintf (stderr, |
682 | "Subject public key `%s' is not well-formed\n", | ||
683 | subject_pubkey_str); | ||
682 | GNUNET_SCHEDULER_shutdown (); | 684 | GNUNET_SCHEDULER_shutdown (); |
683 | return; | 685 | return; |
684 | } | 686 | } |
685 | 687 | ||
686 | // Sign delegate | 688 | // Sign delegate |
687 | dele = GNUNET_CREDENTIAL_delegate_issue (privkey, | 689 | dele = GNUNET_CREDENTIAL_delegate_issue (privkey, |
688 | &subject_pkey, | 690 | &subject_pkey, |
689 | issuer_attr, | 691 | issuer_attr, |
690 | subject_attr, | 692 | subject_attr, |
691 | &etime_abs); | 693 | &etime_abs); |
692 | res = GNUNET_CREDENTIAL_delegate_to_string (dele); | 694 | res = GNUNET_CREDENTIAL_delegate_to_string (dele); |
693 | GNUNET_free (dele); | 695 | GNUNET_free (dele); |
694 | printf ("%s\n", res); | 696 | printf ("%s\n", res); |
@@ -715,18 +717,20 @@ run (void *cls, | |||
715 | { | 717 | { |
716 | cfg = c; | 718 | cfg = c; |
717 | 719 | ||
718 | tt = GNUNET_SCHEDULER_add_delayed (timeout, | 720 | tt = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, NULL); |
719 | &do_timeout, NULL); | ||
720 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 721 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
721 | 722 | ||
722 | // Check relevant cmdline parameters | 723 | // Check relevant cmdline parameters |
723 | if (GNUNET_YES == create_is) { | 724 | if (GNUNET_YES == create_is) |
724 | if (NULL == ego_name) { | 725 | { |
726 | if (NULL == ego_name) | ||
727 | { | ||
725 | fprintf (stderr, "Missing option '-ego'\n"); | 728 | fprintf (stderr, "Missing option '-ego'\n"); |
726 | GNUNET_SCHEDULER_shutdown (); | 729 | GNUNET_SCHEDULER_shutdown (); |
727 | return; | 730 | return; |
728 | } | 731 | } |
729 | if (NULL == issuer_attr) { | 732 | if (NULL == issuer_attr) |
733 | { | ||
730 | fprintf (stderr, "Missing option '-attribute' for issuer attribute\n"); | 734 | fprintf (stderr, "Missing option '-attribute' for issuer attribute\n"); |
731 | GNUNET_SCHEDULER_shutdown (); | 735 | GNUNET_SCHEDULER_shutdown (); |
732 | return; | 736 | return; |
@@ -741,16 +745,15 @@ run (void *cls, | |||
741 | // Lookup ego, on success call store_cb and store as ATTRIBUTE type | 745 | // Lookup ego, on success call store_cb and store as ATTRIBUTE type |
742 | type = GNUNET_GNSRECORD_TYPE_ATTRIBUTE; | 746 | type = GNUNET_GNSRECORD_TYPE_ATTRIBUTE; |
743 | record_label = issuer_attr; | 747 | record_label = issuer_attr; |
744 | el = GNUNET_IDENTITY_ego_lookup (cfg, | 748 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &store_cb, (void *) cfg); |
745 | ego_name, | ||
746 | &store_cb, | ||
747 | (void *) cfg); | ||
748 | return; | 749 | return; |
749 | } | 750 | } |
750 | 751 | ||
751 | if (GNUNET_YES == create_ss) { | 752 | if (GNUNET_YES == create_ss) |
753 | { | ||
752 | // check if signed parameter has been passed in cmd line call | 754 | // check if signed parameter has been passed in cmd line call |
753 | if (NULL == import) { | 755 | if (NULL == import) |
756 | { | ||
754 | fprintf (stderr, "'import' required\n"); | 757 | fprintf (stderr, "'import' required\n"); |
755 | GNUNET_SCHEDULER_shutdown (); | 758 | GNUNET_SCHEDULER_shutdown (); |
756 | return; | 759 | return; |
@@ -759,16 +762,15 @@ run (void *cls, | |||
759 | type = GNUNET_GNSRECORD_TYPE_DELEGATE; | 762 | type = GNUNET_GNSRECORD_TYPE_DELEGATE; |
760 | record_label = GNUNET_GNS_EMPTY_LABEL_AT; | 763 | record_label = GNUNET_GNS_EMPTY_LABEL_AT; |
761 | // Store subject side | 764 | // Store subject side |
762 | el = GNUNET_IDENTITY_ego_lookup (cfg, | 765 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &store_cb, (void *) cfg); |
763 | ego_name, | ||
764 | &store_cb, | ||
765 | (void *) cfg); | ||
766 | 766 | ||
767 | return; | 767 | return; |
768 | } | 768 | } |
769 | 769 | ||
770 | if (GNUNET_YES == sign_ss) { | 770 | if (GNUNET_YES == sign_ss) |
771 | if (NULL == ego_name) { | 771 | { |
772 | if (NULL == ego_name) | ||
773 | { | ||
772 | fprintf (stderr, "ego required\n"); | 774 | fprintf (stderr, "ego required\n"); |
773 | GNUNET_SCHEDULER_shutdown (); | 775 | GNUNET_SCHEDULER_shutdown (); |
774 | return; | 776 | return; |
@@ -781,82 +783,68 @@ run (void *cls, | |||
781 | } | 783 | } |
782 | 784 | ||
783 | // lookup ego and call function sign_cb on success | 785 | // lookup ego and call function sign_cb on success |
784 | el = GNUNET_IDENTITY_ego_lookup (cfg, | 786 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &sign_cb, (void *) cfg); |
785 | ego_name, | ||
786 | &sign_cb, | ||
787 | (void *) cfg); | ||
788 | return; | 787 | return; |
789 | } | 788 | } |
790 | 789 | ||
791 | if (GNUNET_YES == collect) { | 790 | if (GNUNET_YES == collect) |
791 | { | ||
792 | if (NULL == issuer_key) | 792 | if (NULL == issuer_key) |
793 | { | 793 | { |
794 | fprintf (stderr, | 794 | fprintf (stderr, _ ("Issuer public key not well-formed\n")); |
795 | _("Issuer public key not well-formed\n")); | ||
796 | GNUNET_SCHEDULER_shutdown (); | 795 | GNUNET_SCHEDULER_shutdown (); |
797 | return; | 796 | return; |
798 | |||
799 | } | 797 | } |
800 | 798 | ||
801 | credential = GNUNET_CREDENTIAL_connect (cfg); | 799 | credential = GNUNET_CREDENTIAL_connect (cfg); |
802 | 800 | ||
803 | if (NULL == credential) | 801 | if (NULL == credential) |
804 | { | 802 | { |
805 | fprintf (stderr, | 803 | fprintf (stderr, _ ("Failed to connect to CREDENTIAL\n")); |
806 | _("Failed to connect to CREDENTIAL\n")); | ||
807 | GNUNET_SCHEDULER_shutdown (); | 804 | GNUNET_SCHEDULER_shutdown (); |
808 | return; | 805 | return; |
809 | } | 806 | } |
810 | if (NULL == issuer_attr) | 807 | if (NULL == issuer_attr) |
811 | { | 808 | { |
812 | fprintf (stderr, | 809 | fprintf (stderr, _ ("You must provide issuer the attribute\n")); |
813 | _("You must provide issuer the attribute\n")); | ||
814 | GNUNET_SCHEDULER_shutdown (); | 810 | GNUNET_SCHEDULER_shutdown (); |
815 | return; | 811 | return; |
816 | } | 812 | } |
817 | 813 | ||
818 | if (NULL == ego_name) { | 814 | if (NULL == ego_name) |
819 | fprintf (stderr, | 815 | { |
820 | _("ego required\n")); | 816 | fprintf (stderr, _ ("ego required\n")); |
821 | GNUNET_SCHEDULER_shutdown (); | 817 | GNUNET_SCHEDULER_shutdown (); |
822 | return; | 818 | return; |
823 | } | 819 | } |
824 | el = GNUNET_IDENTITY_ego_lookup (cfg, | 820 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); |
825 | ego_name, | ||
826 | &identity_cb, | ||
827 | (void *) cfg); | ||
828 | return; | 821 | return; |
829 | 822 | } | |
830 | } | ||
831 | 823 | ||
832 | if (NULL == subject) | 824 | if (NULL == subject) |
833 | { | 825 | { |
834 | fprintf (stderr, | 826 | fprintf (stderr, _ ("Subject public key needed\n")); |
835 | _("Subject public key needed\n")); | ||
836 | GNUNET_SCHEDULER_shutdown (); | 827 | GNUNET_SCHEDULER_shutdown (); |
837 | return; | 828 | return; |
838 | |||
839 | } | 829 | } |
840 | if (GNUNET_OK != | 830 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (subject, |
841 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject, | 831 | strlen (subject), |
842 | strlen (subject), | 832 | &subject_pkey)) |
843 | &subject_pkey)) | ||
844 | { | 833 | { |
845 | fprintf (stderr, | 834 | fprintf (stderr, |
846 | _("Subject public key `%s' is not well-formed\n"), | 835 | _ ("Subject public key `%s' is not well-formed\n"), |
847 | subject); | 836 | subject); |
848 | GNUNET_SCHEDULER_shutdown (); | 837 | GNUNET_SCHEDULER_shutdown (); |
849 | return; | 838 | return; |
850 | } | 839 | } |
851 | 840 | ||
852 | if (GNUNET_YES == verify) { | 841 | if (GNUNET_YES == verify) |
842 | { | ||
853 | if (NULL == issuer_key) | 843 | if (NULL == issuer_key) |
854 | { | 844 | { |
855 | fprintf (stderr, | 845 | fprintf (stderr, _ ("Issuer public key not well-formed\n")); |
856 | _("Issuer public key not well-formed\n")); | ||
857 | GNUNET_SCHEDULER_shutdown (); | 846 | GNUNET_SCHEDULER_shutdown (); |
858 | return; | 847 | return; |
859 | |||
860 | } | 848 | } |
861 | if (GNUNET_OK != | 849 | if (GNUNET_OK != |
862 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key, | 850 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key, |
@@ -864,7 +852,7 @@ run (void *cls, | |||
864 | &issuer_pkey)) | 852 | &issuer_pkey)) |
865 | { | 853 | { |
866 | fprintf (stderr, | 854 | fprintf (stderr, |
867 | _("Issuer public key `%s' is not well-formed\n"), | 855 | _ ("Issuer public key `%s' is not well-formed\n"), |
868 | issuer_key); | 856 | issuer_key); |
869 | GNUNET_SCHEDULER_shutdown (); | 857 | GNUNET_SCHEDULER_shutdown (); |
870 | return; | 858 | return; |
@@ -873,15 +861,13 @@ run (void *cls, | |||
873 | 861 | ||
874 | if (NULL == credential) | 862 | if (NULL == credential) |
875 | { | 863 | { |
876 | fprintf (stderr, | 864 | fprintf (stderr, _ ("Failed to connect to CREDENTIAL\n")); |
877 | _("Failed to connect to CREDENTIAL\n")); | ||
878 | GNUNET_SCHEDULER_shutdown (); | 865 | GNUNET_SCHEDULER_shutdown (); |
879 | return; | 866 | return; |
880 | } | 867 | } |
881 | if (NULL == issuer_attr || NULL == subject_credential) | 868 | if (NULL == issuer_attr || NULL == subject_credential) |
882 | { | 869 | { |
883 | fprintf (stderr, | 870 | fprintf (stderr, _ ("You must provide issuer and subject attributes\n")); |
884 | _("You must provide issuer and subject attributes\n")); | ||
885 | GNUNET_SCHEDULER_shutdown (); | 871 | GNUNET_SCHEDULER_shutdown (); |
886 | return; | 872 | return; |
887 | } | 873 | } |
@@ -891,63 +877,62 @@ run (void *cls, | |||
891 | char *tok = strtok (tmp, ","); | 877 | char *tok = strtok (tmp, ","); |
892 | if (NULL == tok) | 878 | if (NULL == tok) |
893 | { | 879 | { |
894 | fprintf (stderr, | 880 | fprintf (stderr, "Invalid subject credentials\n"); |
895 | "Invalid subject credentials\n"); | ||
896 | GNUNET_free (tmp); | 881 | GNUNET_free (tmp); |
897 | GNUNET_SCHEDULER_shutdown (); | 882 | GNUNET_SCHEDULER_shutdown (); |
898 | return; | 883 | return; |
899 | } | 884 | } |
900 | int count = 1; | 885 | int count = 1; |
901 | int i; | 886 | int i; |
902 | while (NULL != (tok = strtok(NULL, ","))) | 887 | while (NULL != (tok = strtok (NULL, ","))) |
903 | count++; | 888 | count++; |
904 | struct GNUNET_CREDENTIAL_Credential credentials[count]; | 889 | struct GNUNET_CREDENTIAL_Credential credentials[count]; |
905 | struct GNUNET_CREDENTIAL_Credential *cred; | 890 | struct GNUNET_CREDENTIAL_Credential *cred; |
906 | GNUNET_free (tmp); | 891 | GNUNET_free (tmp); |
907 | tmp = GNUNET_strdup (subject_credential); | 892 | tmp = GNUNET_strdup (subject_credential); |
908 | tok = strtok (tmp, ","); | 893 | tok = strtok (tmp, ","); |
909 | for (i=0;i<count;i++) | 894 | for (i = 0; i < count; i++) |
910 | { | 895 | { |
911 | cred = GNUNET_CREDENTIAL_credential_from_string (tok); | 896 | cred = GNUNET_CREDENTIAL_credential_from_string (tok); |
912 | GNUNET_memcpy (&credentials[i], | 897 | GNUNET_memcpy (&credentials[i], |
913 | cred, | 898 | cred, |
914 | sizeof (struct GNUNET_CREDENTIAL_Credential)); | 899 | sizeof (struct GNUNET_CREDENTIAL_Credential)); |
915 | credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute); | 900 | credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute); |
916 | tok = strtok(NULL, ","); | 901 | tok = strtok (NULL, ","); |
917 | GNUNET_free (cred); | 902 | GNUNET_free (cred); |
918 | } | 903 | } |
919 | 904 | ||
920 | verify_request = GNUNET_CREDENTIAL_verify(credential, | 905 | verify_request = GNUNET_CREDENTIAL_verify (credential, |
921 | &issuer_pkey, | 906 | &issuer_pkey, |
922 | issuer_attr, //TODO argument | 907 | issuer_attr, //TODO argument |
923 | &subject_pkey, | 908 | &subject_pkey, |
924 | count, | 909 | count, |
925 | credentials, | 910 | credentials, |
926 | &handle_verify_result, | 911 | &handle_verify_result, |
927 | NULL); | 912 | NULL); |
928 | for (i=0;i<count;i++) | 913 | for (i = 0; i < count; i++) |
929 | { | 914 | { |
930 | GNUNET_free ((char*)credentials[i].issuer_attribute); | 915 | GNUNET_free ((char *) credentials[i].issuer_attribute); |
931 | } | 916 | } |
932 | GNUNET_free (tmp); | 917 | GNUNET_free (tmp); |
933 | } else if (GNUNET_YES == create_cred) { | 918 | } |
919 | else if (GNUNET_YES == create_cred) | ||
920 | { | ||
934 | if (NULL == ego_name) | 921 | if (NULL == ego_name) |
935 | { | 922 | { |
936 | fprintf (stderr, | 923 | fprintf (stderr, _ ("Issuer ego required\n")); |
937 | _("Issuer ego required\n")); | ||
938 | GNUNET_SCHEDULER_shutdown (); | 924 | GNUNET_SCHEDULER_shutdown (); |
939 | return; | 925 | return; |
940 | |||
941 | } | 926 | } |
942 | el = GNUNET_IDENTITY_ego_lookup (cfg, | 927 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); |
943 | ego_name, | ||
944 | &identity_cb, | ||
945 | (void *) cfg); | ||
946 | 928 | ||
947 | return; | 929 | return; |
948 | } else { | 930 | } |
931 | else | ||
932 | { | ||
949 | fprintf (stderr, | 933 | fprintf (stderr, |
950 | _("Please specify name to lookup, subject key and issuer key!\n")); | 934 | _ ( |
935 | "Please specify name to lookup, subject key and issuer key!\n")); | ||
951 | GNUNET_SCHEDULER_shutdown (); | 936 | GNUNET_SCHEDULER_shutdown (); |
952 | } | 937 | } |
953 | return; | 938 | return; |
@@ -976,7 +961,8 @@ main (int argc, char *const *argv) | |||
976 | GNUNET_GETOPT_option_string ('s', | 961 | GNUNET_GETOPT_option_string ('s', |
977 | "subject", | 962 | "subject", |
978 | "PKEY", | 963 | "PKEY", |
979 | gettext_noop ("The public key of the subject to lookup the credential for, or for issuer side storage: subject and its attributes"), | 964 | gettext_noop ("The public key of the subject to lookup the" |
965 | "credential for, or for issuer side storage: subject and its attributes"), | ||
980 | &subject), | 966 | &subject), |
981 | GNUNET_GETOPT_option_string ('b', | 967 | GNUNET_GETOPT_option_string ('b', |
982 | "credential", | 968 | "credential", |
@@ -1001,7 +987,8 @@ main (int argc, char *const *argv) | |||
1001 | GNUNET_GETOPT_option_string ('T', | 987 | GNUNET_GETOPT_option_string ('T', |
1002 | "ttl", | 988 | "ttl", |
1003 | "EXP", | 989 | "EXP", |
1004 | gettext_noop ("The time to live for the credential. e.g. 5m, 6h, \"1990-12-30 12:00:00\""), | 990 | gettext_noop ("The time to live for the credential." |
991 | "e.g. 5m, 6h, \"1990-12-30 12:00:00\""), | ||
1005 | &expiration), | 992 | &expiration), |
1006 | GNUNET_GETOPT_option_flag ('g', | 993 | GNUNET_GETOPT_option_flag ('g', |
1007 | "collect", | 994 | "collect", |
@@ -1033,13 +1020,16 @@ main (int argc, char *const *argv) | |||
1033 | return 2; | 1020 | return 2; |
1034 | 1021 | ||
1035 | GNUNET_log_setup ("gnunet-credential", "WARNING", NULL); | 1022 | GNUNET_log_setup ("gnunet-credential", "WARNING", NULL); |
1036 | ret = | 1023 | ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, |
1037 | (GNUNET_OK == | 1024 | argv, |
1038 | GNUNET_PROGRAM_run (argc, argv, "gnunet-credential", | 1025 | "gnunet-credential", |
1039 | _("GNUnet credential resolver tool"), | 1026 | _ ("GNUnet credential resolver tool"), |
1040 | options, | 1027 | options, |
1041 | &run, NULL)) ? 0 : 1; | 1028 | &run, |
1042 | GNUNET_free ((void*) argv); | 1029 | NULL)) |
1030 | ? 0 | ||
1031 | : 1; | ||
1032 | GNUNET_free ((void *) argv); | ||
1043 | return ret; | 1033 | return ret; |
1044 | } | 1034 | } |
1045 | 1035 | ||
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c index a3c066444..d7f6e34d5 100644 --- a/src/credential/gnunet-service-credential.c +++ b/src/credential/gnunet-service-credential.c | |||
@@ -542,7 +542,185 @@ test_resolution (void *cls, | |||
542 | uint32_t rd_count, | 542 | uint32_t rd_count, |
543 | const struct GNUNET_GNSRECORD_Data *rd) | 543 | const struct GNUNET_GNSRECORD_Data *rd) |
544 | { | 544 | { |
545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Yo, im Test und so\n"); | 545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:Got %d entries\n", rd_count); |
546 | |||
547 | struct VerifyRequestHandle *vrh; | ||
548 | struct DelegationSetQueueEntry *current_set; | ||
549 | struct DelegationSetQueueEntry *ds_entry; | ||
550 | struct DelegationQueueEntry *dq_entry; | ||
551 | |||
552 | current_set = cls; | ||
553 | // set handle to NULL (as el = NULL) | ||
554 | current_set->lookup_request = NULL; | ||
555 | vrh = current_set->handle; | ||
556 | vrh->pending_lookups--; | ||
557 | //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:current set %s\n", current_set->issuer_attribute); | ||
558 | |||
559 | |||
560 | // Loop record entries | ||
561 | for (uint32_t i = 0; i < rd_count; i++) { | ||
562 | if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type) | ||
563 | continue; | ||
564 | |||
565 | // Start deserialize into Delegate | ||
566 | struct GNUNET_CREDENTIAL_Delegate *del; | ||
567 | del = GNUNET_CREDENTIAL_delegate_deserialize(rd[i].data, rd[i].data_size); | ||
568 | |||
569 | // TODO parse subject and issuer attributes which are required for algo solving | ||
570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:iss %s %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key), del->issuer_attribute); | ||
571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:sub %s %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->subject_key), del->subject_attribute); | ||
572 | |||
573 | // Start: Create DQ Entry | ||
574 | dq_entry = GNUNET_new (struct DelegationQueueEntry); | ||
575 | // AND delegations are not possible, only 1 solution | ||
576 | dq_entry->required_solutions = 1; | ||
577 | dq_entry->parent_set = current_set; | ||
578 | |||
579 | // Insert it into the current set | ||
580 | GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, | ||
581 | current_set->queue_entries_tail, | ||
582 | dq_entry); | ||
583 | |||
584 | // Start: Create DS Entry | ||
585 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); | ||
586 | |||
587 | // (1) A.a <- A.b.c | ||
588 | // (2) A.b <- D.d | ||
589 | // (3) D.d <- E | ||
590 | // (4) E.c <- F.c | ||
591 | // (5) F.c <- G | ||
592 | // Possibilities: | ||
593 | // 1. complete match: trailer = 0, validate | ||
594 | // 2. partial match: replace | ||
595 | // 3. new solution: replace, add trailer | ||
596 | |||
597 | //GNUNET_assert(NULL != current_set->attr_trailer); | ||
598 | // TODO only during test | ||
599 | if (NULL == current_set->attr_trailer) { | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: trailer null\n"); | ||
601 | // for (5) F.c <- G, remember .c when going upwards | ||
602 | ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute); | ||
603 | } else { | ||
604 | if (0 == del->subject_attribute_len){ | ||
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: new solution\n"); | ||
606 | // new solution | ||
607 | // create new trailer del->issuer_attribute, ds_entry->attr_trailer | ||
608 | GNUNET_asprintf (&ds_entry->attr_trailer, | ||
609 | "%s.%s", | ||
610 | del->issuer_attribute, | ||
611 | current_set->attr_trailer); | ||
612 | } else if(0 == strcmp(del->subject_attribute, current_set->attr_trailer)){ | ||
613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: complete match\n"); | ||
614 | // complete match | ||
615 | // new trailer == issuer attribute (e.g. (5) to (4)) | ||
616 | // TODO memleak, free trailer before | ||
617 | ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute); | ||
618 | } else { | ||
619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: partial match\n"); | ||
620 | // partial match | ||
621 | |||
622 | // TODO problem when checking with contains: attr = disco or attr = disc both say success | ||
623 | // ==> therefore: split and check the single attributes | ||
624 | // replace/remove partial match trailer and add the new one | ||
625 | |||
626 | char *saveptr1, *saveptr2; | ||
627 | char *trail_token; | ||
628 | char *sub_token; | ||
629 | char *tmp_trail = GNUNET_strdup (current_set->attr_trailer); | ||
630 | char *tmp_subattr = GNUNET_strdup (del->subject_attribute); | ||
631 | |||
632 | // tok both, parent->attr_trailer and del->sub_attr to see how far they match, | ||
633 | // take rest of parent trailer (only when del->sub_attr token is null), and | ||
634 | // create new/actual trailer with del->iss_attr | ||
635 | trail_token = strtok_r (tmp_trail, ".", &saveptr1); | ||
636 | sub_token = strtok_r (tmp_subattr, ".", &saveptr2); | ||
637 | while (NULL != trail_token && NULL != sub_token) | ||
638 | { | ||
639 | if(0 == strcmp(trail_token,sub_token)) | ||
640 | { | ||
641 | // good, matches, remove | ||
642 | } else { | ||
643 | // not relevant for solving the chain, end function here | ||
644 | // TODO how to end this correctly? just return? | ||
645 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:throwing %s %s\n", trail_token, sub_token); | ||
646 | |||
647 | // TODO break zum nächsten for | ||
648 | //return; | ||
649 | } | ||
650 | |||
651 | trail_token = strtok_r (NULL, ".", &saveptr1); | ||
652 | sub_token = strtok_r (NULL, ".", &saveptr2); | ||
653 | } | ||
654 | if(NULL == trail_token) | ||
655 | { | ||
656 | //TODO error, can't happen | ||
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 (&ds_entry->attr_trailer, | ||
663 | "%s", | ||
664 | trail_token); | ||
665 | trail_token = strtok_r (NULL, ".", &saveptr1); | ||
666 | while(NULL != trail_token) | ||
667 | { | ||
668 | GNUNET_asprintf (&ds_entry->attr_trailer, | ||
669 | "%s.%s", | ||
670 | current_set->attr_trailer, | ||
671 | trail_token); | ||
672 | trail_token = strtok_r (NULL, ".", &saveptr1); | ||
673 | |||
674 | } | ||
675 | GNUNET_asprintf (&ds_entry->attr_trailer, | ||
676 | "%s.%s", | ||
677 | del->issuer_attribute, | ||
678 | ds_entry->attr_trailer); | ||
679 | |||
680 | } | ||
681 | } | ||
682 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: new tailer %s\n", ds_entry->attr_trailer); | ||
683 | |||
684 | // Start: Credential Chain Entry | ||
685 | // issuer key is subject key, who needs to be contacted to resolve this (forward, therefore subject) | ||
686 | // TODO: new ds_entry struct with subject_key (or one for both with contact_key or sth) | ||
687 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
688 | GNUNET_memcpy (ds_entry->issuer_key, | ||
689 | &del->subject_key, | ||
690 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
691 | |||
692 | ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry); | ||
693 | ds_entry->delegation_chain_entry->subject_key = del->subject_key; | ||
694 | if (0 < del->subject_attribute_len) | ||
695 | ds_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup (del->subject_attribute); | ||
696 | ds_entry->delegation_chain_entry->issuer_key = del->issuer_key; | ||
697 | ds_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (del->issuer_attribute); | ||
698 | |||
699 | // current delegation as parent | ||
700 | ds_entry->parent_queue_entry = dq_entry; | ||
701 | |||
702 | // TODO verify if end is reached: | ||
703 | // what is required? Only issuer key/attr and attr_trailer new == 0 | ||
704 | |||
705 | // TODO until good verify check: fixed number of lookups | ||
706 | //vrh->pending_lookups++; | ||
707 | ds_entry->handle = vrh; | ||
708 | |||
709 | const struct GNUNET_CRYPTO_EcdsaPublicKey *kkey = &del->issuer_key; | ||
710 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "-----------FW: Starting AGAIN %s\n",GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key)); | ||
711 | if (0 == vrh->pending_lookups) { | ||
712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); | ||
713 | return; | ||
714 | } | ||
715 | GNUNET_GNS_lookup (gns, | ||
716 | GNUNET_GNS_EMPTY_LABEL_AT, | ||
717 | kkey, // subject_key, | ||
718 | GNUNET_GNSRECORD_TYPE_DELEGATE, | ||
719 | GNUNET_GNS_LO_DEFAULT, | ||
720 | &test_resolution, | ||
721 | ds_entry); | ||
722 | |||
723 | } | ||
546 | } | 724 | } |
547 | 725 | ||
548 | static void | 726 | static void |
@@ -732,22 +910,24 @@ backward_resolution (void *cls, | |||
732 | 910 | ||
733 | vrh->pending_lookups++; | 911 | vrh->pending_lookups++; |
734 | ds_entry->handle = vrh; | 912 | ds_entry->handle = vrh; |
735 | ds_entry->lookup_request | 913 | /*ds_entry->lookup_request |
736 | = GNUNET_GNS_lookup (gns, | 914 | = GNUNET_GNS_lookup (gns, |
737 | lookup_attribute, | 915 | lookup_attribute, |
738 | ds_entry->issuer_key, // issuer_key, | 916 | ds_entry->issuer_key, // issuer_key, |
739 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, | 917 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, |
740 | GNUNET_GNS_LO_DEFAULT, | 918 | GNUNET_GNS_LO_DEFAULT, |
741 | &backward_resolution, | 919 | &backward_resolution, |
742 | ds_entry); | 920 | ds_entry);*/ |
743 | /*GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting\n"); | 921 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(ds_entry->issuer_key)); |
744 | GNUNET_GNS_lookup (gns, | 922 | vrh->pending_lookups = 5; |
923 | ds_entry->lookup_request | ||
924 | = GNUNET_GNS_lookup (gns, | ||
745 | GNUNET_GNS_EMPTY_LABEL_AT, | 925 | GNUNET_GNS_EMPTY_LABEL_AT, |
746 | ds_entry->issuer_key, // subject_key, | 926 | ds_entry->issuer_key, // issuer_key, |
747 | GNUNET_GNSRECORD_TYPE_DELEGATE, | 927 | GNUNET_GNSRECORD_TYPE_DELEGATE, |
748 | GNUNET_GNS_LO_DEFAULT, | 928 | GNUNET_GNS_LO_DEFAULT, |
749 | &test_resolution, | 929 | &test_resolution, |
750 | ds_entry);*/ | 930 | ds_entry); |
751 | GNUNET_free (lookup_attribute); | 931 | GNUNET_free (lookup_attribute); |
752 | } | 932 | } |
753 | } | 933 | } |
@@ -825,6 +1005,18 @@ delegation_chain_resolution_start (void *cls) | |||
825 | GNUNET_GNS_LO_DEFAULT, | 1005 | GNUNET_GNS_LO_DEFAULT, |
826 | &backward_resolution, | 1006 | &backward_resolution, |
827 | ds_entry); | 1007 | ds_entry); |
1008 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&vrh->issuer_key)); | ||
1009 | |||
1010 | // TODO we start with example (5) F.c <- G | ||
1011 | // => attr_trailer = c | ||
1012 | //ds_entry->attr_trailer = "c"; | ||
1013 | /*ds_entry->lookup_request = GNUNET_GNS_lookup (gns, | ||
1014 | GNUNET_GNS_EMPTY_LABEL_AT, | ||
1015 | &vrh->issuer_key, // subject_key, | ||
1016 | GNUNET_GNSRECORD_TYPE_DELEGATE, | ||
1017 | GNUNET_GNS_LO_DEFAULT, | ||
1018 | &test_resolution, | ||
1019 | ds_entry);*/ | ||
828 | } | 1020 | } |
829 | 1021 | ||
830 | static int | 1022 | static int |
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c index f2fb0b1a6..90cd2f46a 100644 --- a/src/credential/plugin_gnsrecord_credential.c +++ b/src/credential/plugin_gnsrecord_credential.c | |||
@@ -44,13 +44,17 @@ | |||
44 | * @return NULL on error, otherwise human-readable representation of the value | 44 | * @return NULL on error, otherwise human-readable representation of the value |
45 | */ | 45 | */ |
46 | static char * | 46 | static char * |
47 | credential_value_to_string (void *cls, uint32_t type, const void *data, | 47 | credential_value_to_string (void *cls, |
48 | uint32_t type, | ||
49 | const void *data, | ||
48 | size_t data_size) | 50 | size_t data_size) |
49 | { | 51 | { |
50 | const char *cdata; | 52 | const char *cdata; |
51 | 53 | ||
52 | switch (type) { | 54 | switch (type) |
53 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { | 55 | { |
56 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: | ||
57 | { | ||
54 | struct GNUNET_CREDENTIAL_DelegationRecord sets; | 58 | struct GNUNET_CREDENTIAL_DelegationRecord sets; |
55 | char *attr_str; | 59 | char *attr_str; |
56 | char *subject_pkey; | 60 | char *subject_pkey; |
@@ -63,30 +67,49 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
63 | cdata = data; | 67 | cdata = data; |
64 | 68 | ||
65 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)]; | 69 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)]; |
66 | if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize ( | 70 | if (GNUNET_OK != |
67 | GNUNET_ntohll (sets.data_size), &cdata[sizeof (sets)], | 71 | GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll ( |
68 | ntohl (sets.set_count), set)) | 72 | sets.data_size), |
73 | &cdata[sizeof (sets)], | ||
74 | ntohl (sets.set_count), | ||
75 | set)) | ||
69 | return NULL; | 76 | return NULL; |
70 | 77 | ||
71 | for (i = 0; i < ntohl (sets.set_count); i++) { | 78 | for (i = 0; i < ntohl (sets.set_count); i++) |
79 | { | ||
72 | subject_pkey = | 80 | subject_pkey = |
73 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); | 81 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); |
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n", | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
83 | "%d len attr\n", | ||
75 | set[i].subject_attribute_len); | 84 | set[i].subject_attribute_len); |
76 | if (0 == set[i].subject_attribute_len) { | 85 | if (0 == set[i].subject_attribute_len) |
77 | if (0 == i) { | 86 | { |
87 | if (0 == i) | ||
88 | { | ||
78 | GNUNET_asprintf (&attr_str, "%s", subject_pkey); | 89 | GNUNET_asprintf (&attr_str, "%s", subject_pkey); |
79 | } else { | 90 | } |
91 | else | ||
92 | { | ||
80 | GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); | 93 | GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); |
81 | GNUNET_free (attr_str); | 94 | GNUNET_free (attr_str); |
82 | attr_str = tmp_str; | 95 | attr_str = tmp_str; |
83 | } | 96 | } |
84 | } else { | 97 | } |
85 | if (0 == i) { | 98 | else |
86 | GNUNET_asprintf (&attr_str, "%s %s", subject_pkey, | 99 | { |
100 | if (0 == i) | ||
101 | { | ||
102 | GNUNET_asprintf (&attr_str, | ||
103 | "%s %s", | ||
104 | subject_pkey, | ||
87 | set[i].subject_attribute); | 105 | set[i].subject_attribute); |
88 | } else { | 106 | } |
89 | GNUNET_asprintf (&tmp_str, "%s,%s %s", attr_str, subject_pkey, | 107 | else |
108 | { | ||
109 | GNUNET_asprintf (&tmp_str, | ||
110 | "%s,%s %s", | ||
111 | attr_str, | ||
112 | subject_pkey, | ||
90 | set[i].subject_attribute); | 113 | set[i].subject_attribute); |
91 | GNUNET_free (attr_str); | 114 | GNUNET_free (attr_str); |
92 | attr_str = tmp_str; | 115 | attr_str = tmp_str; |
@@ -96,7 +119,8 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
96 | } | 119 | } |
97 | return attr_str; | 120 | return attr_str; |
98 | } | 121 | } |
99 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { | 122 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: |
123 | { | ||
100 | struct GNUNET_CREDENTIAL_Credential *cred; | 124 | struct GNUNET_CREDENTIAL_Credential *cred; |
101 | char *cred_str; | 125 | char *cred_str; |
102 | 126 | ||
@@ -105,10 +129,11 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
105 | GNUNET_free (cred); | 129 | GNUNET_free (cred); |
106 | return cred_str; | 130 | return cred_str; |
107 | } | 131 | } |
108 | case GNUNET_GNSRECORD_TYPE_DELEGATE: { | 132 | case GNUNET_GNSRECORD_TYPE_DELEGATE: |
133 | { | ||
109 | struct GNUNET_CREDENTIAL_Delegate *cred; | 134 | struct GNUNET_CREDENTIAL_Delegate *cred; |
110 | char *cred_str; | 135 | char *cred_str; |
111 | 136 | ||
112 | cred = GNUNET_CREDENTIAL_delegate_deserialize (data, data_size); | 137 | cred = GNUNET_CREDENTIAL_delegate_deserialize (data, data_size); |
113 | cred_str = GNUNET_CREDENTIAL_delegate_to_string (cred); | 138 | cred_str = GNUNET_CREDENTIAL_delegate_to_string (cred); |
114 | GNUNET_free (cred); | 139 | GNUNET_free (cred); |
@@ -132,13 +157,18 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, | |||
132 | * @return #GNUNET_OK on success | 157 | * @return #GNUNET_OK on success |
133 | */ | 158 | */ |
134 | static int | 159 | static int |
135 | credential_string_to_value (void *cls, uint32_t type, const char *s, | 160 | credential_string_to_value (void *cls, |
136 | void **data, size_t *data_size) | 161 | uint32_t type, |
162 | const char *s, | ||
163 | void **data, | ||
164 | size_t *data_size) | ||
137 | { | 165 | { |
138 | if (NULL == s) | 166 | if (NULL == s) |
139 | return GNUNET_SYSERR; | 167 | return GNUNET_SYSERR; |
140 | switch (type) { | 168 | switch (type) |
141 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { | 169 | { |
170 | case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: | ||
171 | { | ||
142 | struct GNUNET_CREDENTIAL_DelegationRecord *sets; | 172 | struct GNUNET_CREDENTIAL_DelegationRecord *sets; |
143 | char attr_str[253 + 1]; | 173 | char attr_str[253 + 1]; |
144 | char subject_pkey[52 + 1]; | 174 | char subject_pkey[52 + 1]; |
@@ -154,17 +184,20 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
154 | entries = 0; | 184 | entries = 0; |
155 | tmp_data_size = 0; | 185 | tmp_data_size = 0; |
156 | *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord); | 186 | *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord); |
157 | while (NULL != token) { | 187 | while (NULL != token) |
188 | { | ||
158 | // also fills the variables subject_pley and attr_str if "regex"-like match | 189 | // also fills the variables subject_pley and attr_str if "regex"-like match |
159 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); | 190 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); |
160 | 191 | ||
161 | if (0 == matches) { | 192 | if (0 == matches) |
193 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
163 | _ ("Unable to parse ATTR record string `%s'\n"), s); | 195 | _ ("Unable to parse ATTR record string `%s'\n"), |
196 | s); | ||
164 | GNUNET_free (tmp_str); | 197 | GNUNET_free (tmp_str); |
165 | return GNUNET_SYSERR; | 198 | return GNUNET_SYSERR; |
166 | } | 199 | } |
167 | 200 | ||
168 | entries++; | 201 | entries++; |
169 | token = strtok (NULL, ","); | 202 | token = strtok (NULL, ","); |
170 | } | 203 | } |
@@ -172,7 +205,8 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
172 | 205 | ||
173 | tmp_str = GNUNET_strdup (s); | 206 | tmp_str = GNUNET_strdup (s); |
174 | token = strtok (tmp_str, ","); | 207 | token = strtok (tmp_str, ","); |
175 | if (NULL == token) { | 208 | if (NULL == token) |
209 | { | ||
176 | GNUNET_free (tmp_str); | 210 | GNUNET_free (tmp_str); |
177 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); | 211 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); |
178 | return GNUNET_SYSERR; | 212 | return GNUNET_SYSERR; |
@@ -181,15 +215,18 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
181 | struct GNUNET_CREDENTIAL_DelegationSet set[entries]; | 215 | struct GNUNET_CREDENTIAL_DelegationSet set[entries]; |
182 | // sets memory to be 0, starting at *set for the size of struct * entries | 216 | // sets memory to be 0, starting at *set for the size of struct * entries |
183 | memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries); | 217 | memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries); |
184 | for (i = 0; i < entries; i++) { | 218 | for (i = 0; i < entries; i++) |
219 | { | ||
185 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); | 220 | matches = SSCANF (token, "%s %s", subject_pkey, attr_str); |
186 | 221 | ||
187 | // sets the public key for the set entry | 222 | // sets the public key for the set entry |
188 | GNUNET_CRYPTO_ecdsa_public_key_from_string ( | 223 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, |
189 | subject_pkey, strlen (subject_pkey), &set[i].subject_key); | 224 | strlen (subject_pkey), |
225 | &set[i].subject_key); | ||
190 | 226 | ||
191 | // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b) | 227 | // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b) |
192 | if (2 == matches) { | 228 | if (2 == matches) |
229 | { | ||
193 | set[i].subject_attribute_len = strlen (attr_str) + 1; | 230 | set[i].subject_attribute_len = strlen (attr_str) + 1; |
194 | set[i].subject_attribute = GNUNET_strdup (attr_str); | 231 | set[i].subject_attribute = GNUNET_strdup (attr_str); |
195 | } | 232 | } |
@@ -198,17 +235,21 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
198 | } | 235 | } |
199 | tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set); | 236 | tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set); |
200 | 237 | ||
201 | if (-1 == tmp_data_size) { | 238 | if (-1 == tmp_data_size) |
239 | { | ||
202 | GNUNET_free (tmp_str); | 240 | GNUNET_free (tmp_str); |
203 | return GNUNET_SYSERR; | 241 | return GNUNET_SYSERR; |
204 | } | 242 | } |
205 | *data_size += tmp_data_size; | 243 | *data_size += tmp_data_size; |
206 | *data = sets = GNUNET_malloc (*data_size); | 244 | *data = sets = GNUNET_malloc (*data_size); |
207 | GNUNET_CREDENTIAL_delegation_set_serialize (entries, set, tmp_data_size, | 245 | GNUNET_CREDENTIAL_delegation_set_serialize (entries, |
208 | (char *)&sets[1]); | 246 | set, |
209 | for (i = 0; i < entries; i++) { | 247 | tmp_data_size, |
248 | (char *) &sets[1]); | ||
249 | for (i = 0; i < entries; i++) | ||
250 | { | ||
210 | if (0 != set[i].subject_attribute_len) | 251 | if (0 != set[i].subject_attribute_len) |
211 | GNUNET_free ((char *)set[i].subject_attribute); | 252 | GNUNET_free ((char *) set[i].subject_attribute); |
212 | } | 253 | } |
213 | sets->set_count = htonl (entries); | 254 | sets->set_count = htonl (entries); |
214 | sets->data_size = GNUNET_htonll (tmp_data_size); | 255 | sets->data_size = GNUNET_htonll (tmp_data_size); |
@@ -216,18 +257,20 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, | |||
216 | GNUNET_free (tmp_str); | 257 | GNUNET_free (tmp_str); |
217 | return GNUNET_OK; | 258 | return GNUNET_OK; |
218 | } | 259 | } |
219 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { | 260 | case GNUNET_GNSRECORD_TYPE_CREDENTIAL: |
261 | { | ||
220 | struct GNUNET_CREDENTIAL_Credential *cred; | 262 | struct GNUNET_CREDENTIAL_Credential *cred; |
221 | cred = GNUNET_CREDENTIAL_credential_from_string (s); | 263 | cred = GNUNET_CREDENTIAL_credential_from_string (s); |
222 | 264 | ||
223 | *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **)data); | 265 | *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **) data); |
224 | return GNUNET_OK; | 266 | return GNUNET_OK; |
225 | } | 267 | } |
226 | case GNUNET_GNSRECORD_TYPE_DELEGATE: { | 268 | case GNUNET_GNSRECORD_TYPE_DELEGATE: |
269 | { | ||
227 | struct GNUNET_CREDENTIAL_Delegate *cred; | 270 | struct GNUNET_CREDENTIAL_Delegate *cred; |
228 | cred = GNUNET_CREDENTIAL_delegate_from_string (s); | 271 | cred = GNUNET_CREDENTIAL_delegate_from_string (s); |
229 | 272 | ||
230 | *data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **)data); | 273 | *data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **) data); |
231 | 274 | ||
232 | return GNUNET_OK; | 275 | return GNUNET_OK; |
233 | } | 276 | } |
diff --git a/src/credential/test_credential_own.sh b/src/credential/test_credential_own.sh index b53825d1b..23935c75a 100755 --- a/src/credential/test_credential_own.sh +++ b/src/credential/test_credential_own.sh | |||
@@ -21,8 +21,20 @@ rm -rf `gnunet-config -c test_credential_lookup.conf -s PATHS -o GNUNET_HOME -f` | |||
21 | # (4) RegistrarB.student <- Alice | 21 | # (4) RegistrarB.student <- Alice |
22 | 22 | ||
23 | 23 | ||
24 | which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30" | 24 | which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10" |
25 | gnunet-arm -s -c test_credential_lookup.conf | 25 | gnunet-arm -s -c test_credential_lookup.conf |
26 | |||
27 | gnunet-identity -C a -c test_credential_lookup.conf | ||
28 | gnunet-identity -C d -c test_credential_lookup.conf | ||
29 | gnunet-identity -C e -c test_credential_lookup.conf | ||
30 | gnunet-identity -C f -c test_credential_lookup.conf | ||
31 | gnunet-identity -C g -c test_credential_lookup.conf | ||
32 | AKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep a | awk '{print $3}') | ||
33 | DKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep d | awk '{print $3}') | ||
34 | EKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep e | awk '{print $3}') | ||
35 | FKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep f | awk '{print $3}') | ||
36 | GKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep g | awk '{print $3}') | ||
37 | |||
26 | gnunet-identity -C epub -c test_credential_lookup.conf | 38 | gnunet-identity -C epub -c test_credential_lookup.conf |
27 | gnunet-identity -C eorg -c test_credential_lookup.conf | 39 | gnunet-identity -C eorg -c test_credential_lookup.conf |
28 | gnunet-identity -C stateu -c test_credential_lookup.conf | 40 | gnunet-identity -C stateu -c test_credential_lookup.conf |
@@ -42,29 +54,55 @@ STATE_STUD_ATTR="student" | |||
42 | REG_STUD_ATTR="student" | 54 | REG_STUD_ATTR="student" |
43 | END_ATTR="end" | 55 | END_ATTR="end" |
44 | 56 | ||
57 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=a --attribute="a" --subject="$AKEY b.c" --ttl="2019-12-12 10:00:00"` | ||
58 | gnunet-credential --createSubjectSide --ego=a --import "$SIGNED" | ||
59 | gnunet-namestore -D -z a | ||
60 | |||
61 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=a --attribute="b" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"` | ||
62 | gnunet-credential --createSubjectSide --ego=d --import "$SIGNED" | ||
63 | gnunet-namestore -D -z d | ||
64 | |||
65 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=d --attribute="d" --subject="$EKEY" --ttl="2019-12-12 10:00:00"` | ||
66 | gnunet-credential --createSubjectSide --ego=e --import "$SIGNED" | ||
67 | gnunet-namestore -D -z e | ||
68 | |||
69 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=e --attribute="c" --subject="$FKEY c" --ttl="2019-12-12 10:00:00"` | ||
70 | gnunet-credential --createSubjectSide --ego=f --import "$SIGNED" | ||
71 | gnunet-namestore -D -z f | ||
72 | |||
73 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=f --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"` | ||
74 | gnunet-credential --createSubjectSide --ego=g --import "$SIGNED" | ||
75 | gnunet-namestore -D -z g | ||
76 | |||
77 | |||
78 | |||
45 | TEST_CREDENTIAL="mygnunetcreds" | 79 | TEST_CREDENTIAL="mygnunetcreds" |
46 | # Own issuer side storage: | 80 | # Own issuer side storage: |
47 | gnunet-credential --createIssuerSide --ego=epub --attribute="issside" --subject="$EORG_KEY asd" --ttl=5m | 81 | #gnunet-credential --createIssuerSide --ego=epub --attribute="issside" --subject="$EORG_KEY asd" --ttl=5m |
48 | 82 | ||
49 | gnunet-namestore -D -z epub | 83 | #gnunet-namestore -D -z epub |
50 | 84 | ||
51 | # Own subject side storage: | 85 | # Own subject side storage: |
52 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY" --ttl="2019-12-12 10:00:00"` | 86 | #SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY" --ttl="2019-12-12 10:00:00"` |
53 | gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" | 87 | #gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" |
54 | 88 | ||
55 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno" --ttl="2019-12-12 10:00:00"` | 89 | #SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno" --ttl="2019-12-12 10:00:00"` |
56 | gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" | 90 | #gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" |
57 | 91 | ||
58 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` | 92 | #SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` |
59 | gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" | 93 | #gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" |
60 | 94 | ||
61 | SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd.stu" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` | 95 | #SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd.stu" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` |
62 | gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" | 96 | #gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" |
63 | 97 | ||
64 | gnunet-namestore -D -z eorg | 98 | #SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=stateu --attribute="aaa" --subject="$EPUB_KEY bbbb" --ttl="2019-12-12 10:00:00"` |
99 | #gnunet-credential --createSubjectSide --ego=epub --import "$SIGNED" | ||
100 | |||
101 | #gnunet-namestore -D -z eorg | ||
65 | 102 | ||
66 | # (1) EPub assigns the attribute "discount" to all entities that have been assigned "preferred" by EOrg | 103 | # (1) EPub assigns the attribute "discount" to all entities that have been assigned "preferred" by EOrg |
67 | gnunet-namestore -p -z epub -a -n $DISC_ATTR -t ATTR -V "$EORG_KEY $PREF_ATTR" -e 5m -c test_credential_lookup.conf | 104 | gnunet-namestore -p -z epub -a -n $DISC_ATTR -t ATTR -V "$EORG_KEY $PREF_ATTR" -e 5m -c test_credential_lookup.conf |
105 | gnunet-namestore -p -z epub -a -n "random" -t ATTR -V "$GKEY random" -e 5m -c test_credential_lookup.conf | ||
68 | 106 | ||
69 | # (2) EOrg assigns the attribute "preferred" to all entities that have been assigned "student" by StateU | 107 | # (2) EOrg assigns the attribute "preferred" to all entities that have been assigned "student" by StateU |
70 | gnunet-namestore -p -z eorg -a -n $PREF_ATTR -t ATTR -V "$STATEU_KEY $STATE_STUD_ATTR" -e 5m -c test_credential_lookup.conf | 108 | gnunet-namestore -p -z eorg -a -n $PREF_ATTR -t ATTR -V "$STATEU_KEY $STATE_STUD_ATTR" -e 5m -c test_credential_lookup.conf |
@@ -81,11 +119,13 @@ gnunet-namestore -p -z alice -a -n $TEST_CREDENTIAL -t CRED -V "$CRED" -e 5m -c | |||
81 | # Starting to resolve | 119 | # Starting to resolve |
82 | echo "+++++Starting Collect" | 120 | echo "+++++Starting Collect" |
83 | 121 | ||
84 | CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute=$DISC_ATTR --ego=alice -c test_credential_lookup.conf | paste -d, -s` | 122 | CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute="random" --ego=alice -c test_credential_lookup.conf | paste -d, -s` |
123 | #CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute=$DISC_ATTR --ego=alice -c test_credential_lookup.conf | paste -d, -s` | ||
85 | echo $CREDS | 124 | echo $CREDS |
86 | echo gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential=\'$CREDS\' -c test_credential_lookup.conf | 125 | echo gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential=\'$CREDS\' -c test_credential_lookup.conf |
87 | 126 | ||
88 | RES_CRED=`gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf` | 127 | RES_CRED=`gnunet-credential --verify --issuer=$EPUB_KEY --attribute="random" --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf` |
128 | #RES_CRED=`gnunet-credential --verify --issuer=$GKEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf` | ||
89 | 129 | ||
90 | 130 | ||
91 | # Cleanup properly | 131 | # Cleanup properly |
@@ -93,6 +133,12 @@ gnunet-namestore -z alice -d -n $TEST_CREDENTIAL -t CRED -e never -c test_creden | |||
93 | gnunet-namestore -z epub -d -n $DISC_ATTR -t ATTR -c test_credential_lookup.conf | 133 | gnunet-namestore -z epub -d -n $DISC_ATTR -t ATTR -c test_credential_lookup.conf |
94 | gnunet-namestore -z eorg -d -n $PREF_ATTR -t ATTR -c test_credential_lookup.conf | 134 | gnunet-namestore -z eorg -d -n $PREF_ATTR -t ATTR -c test_credential_lookup.conf |
95 | gnunet-namestore -z stateu -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf | 135 | gnunet-namestore -z stateu -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf |
136 | #gnunet-namestore -z a -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf | ||
137 | #gnunet-namestore -z d -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf | ||
138 | #gnunet-namestore -z e -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf | ||
139 | #gnunet-namestore -z f -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf | ||
140 | #gnunet-namestore -z g -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf | ||
141 | |||
96 | gnunet-arm -e -c test_credential_lookup.conf | 142 | gnunet-arm -e -c test_credential_lookup.conf |
97 | 143 | ||
98 | if [ "$RES_CRED" != "Failed." ] | 144 | if [ "$RES_CRED" != "Failed." ] |