aboutsummaryrefslogtreecommitdiff
path: root/src/credential/plugin_gnsrecord_credential.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/plugin_gnsrecord_credential.c')
-rw-r--r--src/credential/plugin_gnsrecord_credential.c168
1 files changed, 129 insertions, 39 deletions
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 281113a34..d21185981 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -30,6 +30,7 @@
30#include "gnunet_credential_service.h" 30#include "gnunet_credential_service.h"
31#include "gnunet_gnsrecord_plugin.h" 31#include "gnunet_gnsrecord_plugin.h"
32#include "gnunet_signatures.h" 32#include "gnunet_signatures.h"
33#include "credential_serialization.h"
33 34
34 35
35/** 36/**
@@ -54,27 +55,69 @@ credential_value_to_string (void *cls,
54 { 55 {
55 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: 56 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
56 { 57 {
57 struct GNUNET_CREDENTIAL_AttributeRecordData attr; 58 struct GNUNET_CREDENTIAL_DelegationRecordData sets;
58 char *attr_str; 59 char *attr_str;
59 char *subject_pkey; 60 char *subject_pkey;
60 61 char *tmp_str;
61 if (data_size < sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) 62 int i;
63 if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecordData))
62 return NULL; /* malformed */ 64 return NULL; /* malformed */
63 memcpy (&attr, 65 memcpy (&sets,
64 data, 66 data,
65 sizeof (attr)); 67 sizeof (sets));
68 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
69 "SIZE %llu needed: %llu + %llu\n",
70 data_size,
71 GNUNET_ntohll (sets.data_size),
72 sizeof (sets));
73
66 cdata = data; 74 cdata = data;
67 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&attr.subject_key); 75 struct GNUNET_CREDENTIAL_DelegationSetRecord set[ntohl(sets.set_count)];
68 if (data_size == sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) 76 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size),
77 &cdata[sizeof (sets)],
78 ntohl (sets.set_count),
79 set))
80 return NULL;
81
82 for (i=0;i<ntohl(sets.set_count);i++)
69 { 83 {
70 return subject_pkey; 84 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key);
71 } else { 85 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
72 GNUNET_asprintf (&attr_str, 86 "%d len attr\n", set[i].subject_attribute_len);
73 "%s %s", 87 if (0 == set[i].subject_attribute_len)
74 subject_pkey, 88 {
75 &cdata[sizeof (attr)]); 89 if (0 == i)
90 {
91 GNUNET_asprintf (&attr_str,
92 "%s",
93 subject_pkey);
94 } else {
95 GNUNET_asprintf (&tmp_str,
96 "%s,%s",
97 attr_str,
98 subject_pkey);
99 GNUNET_free (attr_str);
100 attr_str = tmp_str;
101 }
102 } else {
103 if (0 == i)
104 {
105 GNUNET_asprintf (&attr_str,
106 "%s %s",
107 subject_pkey,
108 set[i].subject_attribute);
109 } else {
110 GNUNET_asprintf (&tmp_str,
111 "%s,%s %s",
112 attr_str,
113 subject_pkey,
114 set[i].subject_attribute);
115 GNUNET_free (attr_str);
116 attr_str = tmp_str;
117 }
118 }
119 GNUNET_free (subject_pkey);
76 } 120 }
77 GNUNET_free (subject_pkey);
78 return attr_str; 121 return attr_str;
79 } 122 }
80 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: 123 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
@@ -143,37 +186,84 @@ credential_string_to_value (void *cls,
143 { 186 {
144 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: 187 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
145 { 188 {
146 struct GNUNET_CREDENTIAL_AttributeRecordData *attr; 189 struct GNUNET_CREDENTIAL_DelegationRecordData *sets;
147 char attr_str[253 + 1]; 190 char attr_str[253 + 1];
148 char subject_pkey[52 + 1]; 191 char subject_pkey[52 + 1];
192 char *token;
193 char *tmp_str;
149 int matches = 0; 194 int matches = 0;
150 matches = SSCANF (s, 195 int entries;
151 "%s %s", 196 size_t tmp_data_size;
152 subject_pkey, 197 int i;
153 attr_str); 198
154 if (0 == matches) 199 tmp_str = GNUNET_strdup (s);
200 token = strtok (tmp_str, ",");
201 entries = 0;
202 tmp_data_size = 0;
203 *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecordData);
204 while (NULL != token)
155 { 205 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 206 matches = SSCANF (token,
157 _("Unable to parse ATTR record string `%s'\n"), 207 "%s %s",
158 s); 208 subject_pkey,
159 return GNUNET_SYSERR; 209 attr_str);
160 210 if (0 == matches)
211 {
212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
213 _("Unable to parse ATTR record string `%s'\n"),
214 s);
215 GNUNET_free (tmp_str);
216 return GNUNET_SYSERR;
217 }
218 if (1 == matches) {
219 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationSetRecord);
220 } else if (2 == matches) {
221 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationSetRecord) + strlen (attr_str) + 1;
222 }
223 entries++;
224 token = strtok (NULL, ",");
161 } 225 }
162 if (1 == matches) { 226 GNUNET_free (tmp_str);
163 *data_size = sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData); 227 tmp_str = GNUNET_strdup (s);
164 } else if (2 == matches) { 228 token = strtok (tmp_str, ",");
165 *data_size = sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData) + strlen (attr_str) + 1; 229 struct GNUNET_CREDENTIAL_DelegationSetRecord *set;
230 set = GNUNET_malloc (entries * sizeof (struct GNUNET_CREDENTIAL_DelegationSetRecord));
231 for (i=0;i<entries;i++)
232 {
233 matches = SSCANF (token,
234 "%s %s",
235 subject_pkey,
236 attr_str);
237 GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey,
238 strlen (subject_pkey),
239 &set[i].subject_key);
240 if (2 == matches) {
241 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
242 "Adding %s (data size %llu)\n",
243 attr_str,
244 tmp_data_size);
245 /*GNUNET_memcpy (&set[1],
246 attr_str,
247 strlen (attr_str)+1);*/
248 set[i].subject_attribute_len = strlen (attr_str) + 1;
249 set[i].subject_attribute = GNUNET_strdup (attr_str);//(const char*)&set[1];
250 }
251 token = strtok (NULL , ",");
166 } 252 }
167 *data = attr = GNUNET_malloc (*data_size); 253 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries,
168 GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, 254 set);
169 strlen (subject_pkey), 255 if (-1 == tmp_data_size)
170 &attr->subject_key); 256 return GNUNET_SYSERR;
171 if (NULL != attr_str) 257 *data_size += tmp_data_size;
172 GNUNET_memcpy (&attr[1], 258 *data = sets = GNUNET_malloc (*data_size);
173 attr_str, 259 GNUNET_CREDENTIAL_delegation_set_serialize (entries,
174 strlen (attr_str)); 260 set,
175 261 tmp_data_size,
176 262 (char*)&sets[1]);
263 sets->set_count = htonl (entries);
264 sets->data_size = GNUNET_htonll (tmp_data_size);
265
266 GNUNET_free (tmp_str);
177 return GNUNET_OK; 267 return GNUNET_OK;
178 } 268 }
179 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: 269 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: