summaryrefslogtreecommitdiff
path: root/src/credential/plugin_gnsrecord_credential.c
diff options
context:
space:
mode:
authorAndreas Ebner <pansy007@googlemail.com>2019-07-07 15:04:40 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-10-07 12:15:06 +0200
commitfc58d9d4241ed2dcd4b492b4f922ba959449a697 (patch)
tree812713718d2d93d70a3ee1a22b20d55e65969873 /src/credential/plugin_gnsrecord_credential.c
parentd2634b1f96dfd55ae4daef294bb6c05d687354c8 (diff)
downloadgnunet-fc58d9d4241ed2dcd4b492b4f922ba959449a697.tar.gz
gnunet-fc58d9d4241ed2dcd4b492b4f922ba959449a697.zip
Implemented delegate sign and store function for GNS entries:
- functions to store and sign delegates (all types) including serialization/string_to_value/.. - solved (almost) all TODOs - some renaming and cleanup in gnunet-credential.c - valgrind checked - test file adapted accordingly
Diffstat (limited to 'src/credential/plugin_gnsrecord_credential.c')
-rw-r--r--src/credential/plugin_gnsrecord_credential.c125
1 files changed, 12 insertions, 113 deletions
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index a4c3a94e8..f2fb0b1a6 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -28,6 +28,7 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29 29
30#include "credential_misc.h" 30#include "credential_misc.h"
31#include "delegate_misc.h"
31#include "credential_serialization.h" 32#include "credential_serialization.h"
32#include "gnunet_credential_service.h" 33#include "gnunet_credential_service.h"
33#include "gnunet_gnsrecord_lib.h" 34#include "gnunet_gnsrecord_lib.h"
@@ -46,7 +47,6 @@ static char *
46credential_value_to_string (void *cls, uint32_t type, const void *data, 47credential_value_to_string (void *cls, uint32_t type, const void *data,
47 size_t data_size) 48 size_t data_size)
48{ 49{
49
50 const char *cdata; 50 const char *cdata;
51 51
52 switch (type) { 52 switch (type) {
@@ -94,8 +94,6 @@ credential_value_to_string (void *cls, uint32_t type, const void *data,
94 } 94 }
95 GNUNET_free (subject_pkey); 95 GNUNET_free (subject_pkey);
96 } 96 }
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "############### attr str: %s \n", attr_str);
98 //DEBUG ############### attr str: BKX50FK9QYNTFGPR6647CDASM63G21NEJC02QP58NHN7B7M8TKT0 student
99 return attr_str; 97 return attr_str;
100 } 98 }
101 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { 99 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
@@ -107,10 +105,14 @@ credential_value_to_string (void *cls, uint32_t type, const void *data,
107 GNUNET_free (cred); 105 GNUNET_free (cred);
108 return cred_str; 106 return cred_str;
109 } 107 }
110 case GNUNET_GNSRECORD_TYPE_DELEGATE: { 108 case GNUNET_GNSRECORD_TYPE_DELEGATE: {
111 printf("####################################vts\n"); 109 struct GNUNET_CREDENTIAL_Delegate *cred;
112 110 char *cred_str;
113 return GNUNET_strndup (data, data_size); 111
112 cred = GNUNET_CREDENTIAL_delegate_deserialize (data, data_size);
113 cred_str = GNUNET_CREDENTIAL_delegate_to_string (cred);
114 GNUNET_free (cred);
115 return cred_str;
114 } 116 }
115 default: 117 default:
116 return NULL; 118 return NULL;
@@ -137,8 +139,6 @@ credential_string_to_value (void *cls, uint32_t type, const char *s,
137 return GNUNET_SYSERR; 139 return GNUNET_SYSERR;
138 switch (type) { 140 switch (type) {
139 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { 141 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: {
140 printf ("Start: string_to_value attribute\n");
141
142 struct GNUNET_CREDENTIAL_DelegationRecord *sets; 142 struct GNUNET_CREDENTIAL_DelegationRecord *sets;
143 char attr_str[253 + 1]; 143 char attr_str[253 + 1];
144 char subject_pkey[52 + 1]; 144 char subject_pkey[52 + 1];
@@ -217,8 +217,6 @@ credential_string_to_value (void *cls, uint32_t type, const char *s,
217 return GNUNET_OK; 217 return GNUNET_OK;
218 } 218 }
219 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { 219 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
220 printf ("Start: string_to_value credential\n");
221
222 struct GNUNET_CREDENTIAL_Credential *cred; 220 struct GNUNET_CREDENTIAL_Credential *cred;
223 cred = GNUNET_CREDENTIAL_credential_from_string (s); 221 cred = GNUNET_CREDENTIAL_credential_from_string (s);
224 222
@@ -226,110 +224,11 @@ credential_string_to_value (void *cls, uint32_t type, const char *s,
226 return GNUNET_OK; 224 return GNUNET_OK;
227 } 225 }
228 case GNUNET_GNSRECORD_TYPE_DELEGATE: { 226 case GNUNET_GNSRECORD_TYPE_DELEGATE: {
229 printf ("Start: string_to_value delegate\n"); 227 struct GNUNET_CREDENTIAL_Delegate *cred;
230 228 cred = GNUNET_CREDENTIAL_delegate_from_string (s);
231 char* tmp_str;
232 char* token;
233 int matches = 0;
234 int entries = 0;
235 size_t tmp_data_size = 0;
236 char issuer_attr_str[253 + 1], subject_attr_str[253 + 1];
237 char issuer_pkey[52 + 1], subject_pkey[52 + 1];
238 int i;
239
240 // Split AND
241 tmp_str = GNUNET_strdup (s);
242 // Split string by ',' and first entry stored in token
243 token = strtok (tmp_str, ",");
244 // TODO: Use of this except for entry counting and format checking (why tmp_data size in the function above?)
245 while(NULL != token) {
246 printf("DEL############### tokenX %s\n", token);
247
248 // TODO: only for type A.a <- B.b, missing other types, especially with multiple roles on the right side
249 // Alles splitten mit "%s %s <- %s %s ..." oder lieber "%s %s <- %s" und das dem lookup überlassen? Dann aber feld größe unknown
250
251 // Match with string and fill variables
252 matches = SSCANF (token, "%s %s <- %s %s", issuer_pkey, issuer_attr_str, subject_pkey, subject_attr_str);
253 printf("DEL############### issuerpkey %s, issueratt %s, subjectpkey %s, subjectattr %s\n",
254 issuer_pkey, issuer_attr_str, subject_pkey, subject_attr_str);
255
256 // Doesn't match string, DEL record string wrong formatted, throw error
257 if (2 >= matches) {
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
259 _ ("Unable to parse DEL record string `%s'\n"), s);
260 GNUNET_free (tmp_str);
261 return GNUNET_SYSERR;
262 }
263
264 printf("DEL############### matches %d\n", matches);
265 if (3 == matches) {
266 // Type A.a <- B
267 printf("DEL############### A.a <-B found\n");
268 }
269 if (4 == matches) {
270 printf("DEL############### A.a <- B.b found\n");
271 }
272
273 // Get next entry of tmp_str (pointer still saved), store entry in token, NULL if no more entries
274 token = strtok(NULL, ",");
275 entries++;
276 }
277 // TODO fill tmp_data_size (but what's that)
278
279 tmp_str = GNUNET_strdup (s);
280 token = strtok (tmp_str, ",");
281 if (NULL == token) {
282 GNUNET_free (tmp_str);
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
284 return GNUNET_SYSERR;
285 }
286
287 // TODO own GNUNET_CREDENTIAL_Delegation struct (when I know the format)
288 struct GNUNET_CREDENTIAL_Delegation set[entries];
289 // sets memory to be 0, starting at *set for the size of struct * entries
290 memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_Delegation) * entries);
291
292 for (i = 0; i < entries; i++) {
293 matches = SSCANF (token, "%s %s <- %s %s", issuer_pkey, issuer_attr_str, subject_pkey, subject_attr_str);
294
295 // Set public keys of issuer and subject
296 GNUNET_CRYPTO_ecdsa_public_key_from_string (
297 issuer_pkey, strlen (issuer_pkey), &set[i].issuer_key);
298 GNUNET_CRYPTO_ecdsa_public_key_from_string (
299 subject_pkey, strlen (subject_pkey), &set[i].subject_key);
300
301 // Set issuer attribute, always present
302 set[i].issuer_attribute_len = strlen (issuer_attr_str) + 1;
303 set[i].issuer_attribute = GNUNET_strdup (issuer_attr_str);
304
305 if (4 == matches) {
306 // A.a <- B.b
307 set[i].subject_attribute_len = strlen (subject_attr_str) + 1;
308 set[i].subject_attribute = GNUNET_strdup (subject_attr_str);
309 }
310
311 // If more entries, then token string can take the next entry (separated by ',') by calling strtok again
312 token = strtok (NULL, ",");
313 }
314 //TODO: own method
315 //tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set);
316
317 if (-1 == tmp_data_size) {
318 GNUNET_free (tmp_str);
319 return GNUNET_SYSERR;
320 }
321
322 //TODO: serialize
323
324
325
326
327
328
329 229
230 *data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **)data);
330 231
331 *data_size = strlen (s);
332 *data = GNUNET_strdup (s);
333 return GNUNET_OK; 232 return GNUNET_OK;
334 } 233 }
335 default: 234 default: