aboutsummaryrefslogtreecommitdiff
path: root/src/credential/plugin_rest_credential.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/plugin_rest_credential.c')
-rw-r--r--src/credential/plugin_rest_credential.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/src/credential/plugin_rest_credential.c b/src/credential/plugin_rest_credential.c
index 137f55c47..798f76049 100644
--- a/src/credential/plugin_rest_credential.c
+++ b/src/credential/plugin_rest_credential.c
@@ -186,22 +186,45 @@ do_error (void *cls)
186 * @return JSON, NULL if failed 186 * @return JSON, NULL if failed
187 */ 187 */
188static json_t* 188static json_t*
189attribute_delegation_to_json (struct GNUNET_CREDENTIAL_AttributeRecordData *attr) 189attribute_delegation_to_json (struct GNUNET_CREDENTIAL_Delegation *delegation_chain_entry)
190{ 190{
191 char *subject; 191 char *subject;
192 char *attribute; 192 char *issuer;
193 char iss_attribute[delegation_chain_entry->issuer_attribute_len];
194 char sub_attribute[delegation_chain_entry->subject_attribute_len];
193 json_t *attr_obj; 195 json_t *attr_obj;
194 196
195 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&attr->subject_key); 197 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&delegation_chain_entry->issuer_key);
198 {
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
200 "Issuer in delegation malformed\n");
201 return NULL;
202 }
203 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&delegation_chain_entry->subject_key);
196 { 204 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 "Subject in credential malformed\n"); 206 "Subject in credential malformed\n");
207 GNUNET_free (issuer);
199 return NULL; 208 return NULL;
200 } 209 }
201 attribute = (char*)&attr[1];
202 attr_obj = json_object (); 210 attr_obj = json_object ();
211 memcpy (iss_attribute,
212 delegation_chain_entry->issuer_attribute,
213 delegation_chain_entry->issuer_attribute_len);
214 iss_attribute[delegation_chain_entry->issuer_attribute_len] = '\0';
215
203 json_object_set_new (attr_obj, "subject", json_string (subject)); 216 json_object_set_new (attr_obj, "subject", json_string (subject));
204 json_object_set_new (attr_obj, "attribute", json_string (attribute)); 217 json_object_set_new (attr_obj, "issuer", json_string (issuer));
218 json_object_set_new (attr_obj, "issuer_attribute", json_string (iss_attribute));
219
220 if (0 < delegation_chain_entry->subject_attribute_len)
221 {
222 memcpy (sub_attribute,
223 delegation_chain_entry->subject_attribute,
224 delegation_chain_entry->subject_attribute_len);
225 sub_attribute[delegation_chain_entry->subject_attribute_len] = '\0';
226 json_object_set_new (attr_obj, "subject_attribute", json_string (sub_attribute));
227 }
205 GNUNET_free (subject); 228 GNUNET_free (subject);
206 return attr_obj; 229 return attr_obj;
207} 230}
@@ -212,14 +235,11 @@ attribute_delegation_to_json (struct GNUNET_CREDENTIAL_AttributeRecordData *attr
212 * @return the resulting json, NULL if failed 235 * @return the resulting json, NULL if failed
213 */ 236 */
214static json_t* 237static json_t*
215credential_to_json (struct GNUNET_CREDENTIAL_CredentialRecordData *cred) 238credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
216{ 239{
217 struct GNUNET_TIME_Absolute exp;
218 const char* exp_str;
219 char *issuer; 240 char *issuer;
220 char *subject; 241 char *subject;
221 char *attribute; 242 char attribute[cred->issuer_attribute_len + 1];
222 char *signature;
223 json_t *cred_obj; 243 json_t *cred_obj;
224 244
225 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); 245 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key);
@@ -237,21 +257,16 @@ credential_to_json (struct GNUNET_CREDENTIAL_CredentialRecordData *cred)
237 GNUNET_free (issuer); 257 GNUNET_free (issuer);
238 return NULL; 258 return NULL;
239 } 259 }
240 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 260 memcpy (attribute,
241 sizeof (struct GNUNET_CRYPTO_EcdsaSignature), 261 cred->issuer_attribute,
242 &signature); 262 cred->issuer_attribute_len);
243 attribute = (char*)&cred[1]; 263 attribute[cred->issuer_attribute_len] = '\0';
244 exp.abs_value_us = ntohs (cred->expiration);
245 exp_str = GNUNET_STRINGS_absolute_time_to_string (exp);
246 cred_obj = json_object (); 264 cred_obj = json_object ();
247 json_object_set_new (cred_obj, "issuer", json_string (issuer)); 265 json_object_set_new (cred_obj, "issuer", json_string (issuer));
248 json_object_set_new (cred_obj, "subject", json_string (subject)); 266 json_object_set_new (cred_obj, "subject", json_string (subject));
249 json_object_set_new (cred_obj, "attribute", json_string (attribute)); 267 json_object_set_new (cred_obj, "attribute", json_string (attribute));
250 json_object_set_new (cred_obj, "signature", json_string (signature));
251 json_object_set_new (cred_obj, "expiration", json_string (exp_str));
252 GNUNET_free (issuer); 268 GNUNET_free (issuer);
253 GNUNET_free (subject); 269 GNUNET_free (subject);
254 GNUNET_free (signature);
255 return cred_obj; 270 return cred_obj;
256} 271}
257 272
@@ -264,9 +279,9 @@ credential_to_json (struct GNUNET_CREDENTIAL_CredentialRecordData *cred)
264 */ 279 */
265static void 280static void
266handle_verify_response (void *cls, 281handle_verify_response (void *cls,
267 struct GNUNET_CREDENTIAL_CredentialRecordData *cred, 282 unsigned int d_count,
268 uint32_t delegation_count, 283 struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
269 struct GNUNET_CREDENTIAL_AttributeRecordData *deleg) 284 struct GNUNET_CREDENTIAL_Credential *cred)
270{ 285{
271 286
272 struct VerifyHandle *handle = cls; 287 struct VerifyHandle *handle = cls;
@@ -292,9 +307,9 @@ handle_verify_response (void *cls,
292 handle->issuer_attr); 307 handle->issuer_attr);
293 cred_obj = credential_to_json (cred); 308 cred_obj = credential_to_json (cred);
294 result_array = json_array (); 309 result_array = json_array ();
295 for (i = 0; i < delegation_count; i++) 310 for (i = 0; i < d_count; i++)
296 { 311 {
297 attr_obj = attribute_delegation_to_json (&(deleg[i])); 312 attr_obj = attribute_delegation_to_json (&delegation_chain[i]);
298 json_array_append (result_array, attr_obj); 313 json_array_append (result_array, attr_obj);
299 json_decref (attr_obj); 314 json_decref (attr_obj);
300 } 315 }