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.c115
1 files changed, 24 insertions, 91 deletions
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 1358afdb1..5c3c03832 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -31,7 +31,7 @@
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#include "credential_serialization.h"
34 34#include "credential_misc.h"
35 35
36/** 36/**
37 * Convert the 'value' of a record to a string. 37 * Convert the 'value' of a record to a string.
@@ -55,18 +55,18 @@ credential_value_to_string (void *cls,
55 { 55 {
56 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: 56 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
57 { 57 {
58 struct GNUNET_CREDENTIAL_DelegationRecordData sets; 58 struct GNUNET_CREDENTIAL_DelegationRecord sets;
59 char *attr_str; 59 char *attr_str;
60 char *subject_pkey; 60 char *subject_pkey;
61 char *tmp_str; 61 char *tmp_str;
62 int i; 62 int i;
63 if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecordData)) 63 if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord))
64 return NULL; /* malformed */ 64 return NULL; /* malformed */
65 memcpy (&sets, 65 memcpy (&sets,
66 data, 66 data,
67 sizeof (sets)); 67 sizeof (sets));
68 cdata = data; 68 cdata = data;
69 struct GNUNET_CREDENTIAL_DelegationSetRecord set[ntohl(sets.set_count)]; 69 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
70 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size), 70 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size),
71 &cdata[sizeof (sets)], 71 &cdata[sizeof (sets)],
72 ntohl (sets.set_count), 72 ntohl (sets.set_count),
@@ -116,38 +116,13 @@ credential_value_to_string (void *cls,
116 } 116 }
117 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: 117 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
118 { 118 {
119 struct GNUNET_CREDENTIAL_CredentialRecordData cred; 119 struct GNUNET_CREDENTIAL_Credential *cred;
120 struct GNUNET_TIME_Absolute etime_abs;
121 char *cred_str; 120 char *cred_str;
122 char *subject_pkey;
123 char *issuer_pkey;
124 char *signature;
125 const char *expiration;
126
127 121
128 if (data_size < sizeof (struct GNUNET_CREDENTIAL_CredentialRecordData)) 122 cred = GNUNET_CREDENTIAL_credential_deserialize (data,
129 return NULL; /* malformed */ 123 data_size);
130 memcpy (&cred, 124 cred_str = GNUNET_CREDENTIAL_credential_to_string (cred);
131 data, 125 GNUNET_free (cred);
132 sizeof (cred));
133 cdata = data;
134 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.subject_key);
135 issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.issuer_key);
136 etime_abs.abs_value_us = GNUNET_ntohll(cred.expiration);
137 expiration = GNUNET_STRINGS_absolute_time_to_string (etime_abs);
138 GNUNET_STRINGS_base64_encode ((char*)&cred.signature,
139 sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
140 &signature);
141 GNUNET_asprintf (&cred_str,
142 "%s.%s -> %s | %s | %s",
143 issuer_pkey,
144 &cdata[sizeof (cred)],
145 subject_pkey,
146 signature,
147 expiration);
148 GNUNET_free (subject_pkey);
149 GNUNET_free (issuer_pkey);
150 GNUNET_free (signature);
151 return cred_str; 126 return cred_str;
152 } 127 }
153 default: 128 default:
@@ -180,7 +155,7 @@ credential_string_to_value (void *cls,
180 { 155 {
181 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: 156 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
182 { 157 {
183 struct GNUNET_CREDENTIAL_DelegationRecordData *sets; 158 struct GNUNET_CREDENTIAL_DelegationRecord *sets;
184 char attr_str[253 + 1]; 159 char attr_str[253 + 1];
185 char subject_pkey[52 + 1]; 160 char subject_pkey[52 + 1];
186 char *token; 161 char *token;
@@ -194,7 +169,7 @@ credential_string_to_value (void *cls,
194 token = strtok (tmp_str, ","); 169 token = strtok (tmp_str, ",");
195 entries = 0; 170 entries = 0;
196 tmp_data_size = 0; 171 tmp_data_size = 0;
197 *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecordData); 172 *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord);
198 while (NULL != token) 173 while (NULL != token)
199 { 174 {
200 matches = SSCANF (token, 175 matches = SSCANF (token,
@@ -210,9 +185,9 @@ credential_string_to_value (void *cls,
210 return GNUNET_SYSERR; 185 return GNUNET_SYSERR;
211 } 186 }
212 if (1 == matches) { 187 if (1 == matches) {
213 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationSetRecord); 188 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet);
214 } else if (2 == matches) { 189 } else if (2 == matches) {
215 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationSetRecord) + strlen (attr_str) + 1; 190 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet) + strlen (attr_str) + 1;
216 } 191 }
217 entries++; 192 entries++;
218 token = strtok (NULL, ","); 193 token = strtok (NULL, ",");
@@ -220,8 +195,7 @@ credential_string_to_value (void *cls,
220 GNUNET_free (tmp_str); 195 GNUNET_free (tmp_str);
221 tmp_str = GNUNET_strdup (s); 196 tmp_str = GNUNET_strdup (s);
222 token = strtok (tmp_str, ","); 197 token = strtok (tmp_str, ",");
223 struct GNUNET_CREDENTIAL_DelegationSetRecord *set; 198 struct GNUNET_CREDENTIAL_DelegationSet set[entries];
224 set = GNUNET_malloc (entries * sizeof (struct GNUNET_CREDENTIAL_DelegationSetRecord));
225 for (i=0;i<entries;i++) 199 for (i=0;i<entries;i++)
226 { 200 {
227 matches = SSCANF (token, 201 matches = SSCANF (token,
@@ -239,6 +213,7 @@ credential_string_to_value (void *cls,
239 } 213 }
240 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, 214 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries,
241 set); 215 set);
216
242 if (-1 == tmp_data_size) 217 if (-1 == tmp_data_size)
243 return GNUNET_SYSERR; 218 return GNUNET_SYSERR;
244 *data_size += tmp_data_size; 219 *data_size += tmp_data_size;
@@ -247,6 +222,11 @@ credential_string_to_value (void *cls,
247 set, 222 set,
248 tmp_data_size, 223 tmp_data_size,
249 (char*)&sets[1]); 224 (char*)&sets[1]);
225 for (i=0;i<entries;i++)
226 {
227 if (0 != set[i].subject_attribute_len)
228 GNUNET_free ((char*)set[i].subject_attribute);
229 }
250 sets->set_count = htonl (entries); 230 sets->set_count = htonl (entries);
251 sets->data_size = GNUNET_htonll (tmp_data_size); 231 sets->data_size = GNUNET_htonll (tmp_data_size);
252 232
@@ -255,58 +235,11 @@ credential_string_to_value (void *cls,
255 } 235 }
256 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: 236 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
257 { 237 {
258 struct GNUNET_CREDENTIAL_CredentialRecordData *cred; 238 struct GNUNET_CREDENTIAL_Credential *cred;
259 239 cred = GNUNET_CREDENTIAL_credential_from_string (s);
260 size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
261 if (enclen % 5 > 0)
262 enclen += 5 - enclen % 5;
263 enclen /= 5; /* 260/5 = 52 */
264 char subject_pkey[enclen + 1];
265 char issuer_pkey[enclen + 1];
266 char name[253 + 1];
267 char signature[128]; //TODO max payload size
268 char expiration[256];
269
270 struct GNUNET_CRYPTO_EcdsaSignature *sig;
271 struct GNUNET_TIME_Absolute etime_abs;
272
273 if (5 != SSCANF (s,
274 "%52s.%253s -> %52s | %s | %255[0-9a-zA-Z: ]",
275 issuer_pkey,
276 name,
277 subject_pkey,
278 signature,
279 expiration))
280 {
281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
282 _("Unable to parse CRED record string `%s'\n"),
283 s);
284 return GNUNET_SYSERR;
285 }
286 *data_size = sizeof (struct GNUNET_CREDENTIAL_CredentialRecordData) + strlen (name) + 1;
287 *data = cred = GNUNET_malloc (*data_size);
288 GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey,
289 strlen (subject_pkey),
290 &cred->subject_key);
291 GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey,
292 strlen (issuer_pkey),
293 &cred->issuer_key);
294 GNUNET_STRINGS_fancy_time_to_absolute (expiration,
295 &etime_abs);
296 GNUNET_STRINGS_base64_decode (signature,
297 strlen (signature),
298 (char**)&sig);
299 cred->signature = *sig;
300 cred->expiration = GNUNET_htonll (etime_abs.abs_value_us);
301 cred->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
302 cred->purpose.size = htonl (strlen (name) + 1 + sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
303 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + sizeof (uint64_t));
304 GNUNET_free (sig);
305 GNUNET_memcpy (&cred[1],
306 name,
307 strlen (name));
308
309 240
241 *data_size = GNUNET_CREDENTIAL_credential_serialize (cred,
242 (char**)data);
310 return GNUNET_OK; 243 return GNUNET_OK;
311 } 244 }
312 default: 245 default: