aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2022-01-03 11:53:41 +0100
committerTristan Schwieren <tristan.schwieren@tum.de>2022-01-03 11:53:41 +0100
commit6b8bb25580f25953b3393d37876bcaab144b77b6 (patch)
tree4e293a2a7ab955dc73e2056e407f5460ad9c0bf4
parente97ac989225d0b8b96cc393e90b20937928d579a (diff)
downloadgnunet-6b8bb25580f25953b3393d37876bcaab144b77b6.tar.gz
gnunet-6b8bb25580f25953b3393d37876bcaab144b77b6.zip
-w3cvc basic plugin functions
-rw-r--r--src/reclaim/plugin_reclaim_credential_vc.c87
-rw-r--r--vc.json3
2 files changed, 74 insertions, 16 deletions
diff --git a/src/reclaim/plugin_reclaim_credential_vc.c b/src/reclaim/plugin_reclaim_credential_vc.c
index d05601263..b58af5595 100644
--- a/src/reclaim/plugin_reclaim_credential_vc.c
+++ b/src/reclaim/plugin_reclaim_credential_vc.c
@@ -49,7 +49,6 @@ vc_value_to_string (void *cls,
49 switch (type) 49 switch (type)
50 { 50 {
51 case GNUNET_RECLAIM_CREDENTIAL_TYPE_VC: 51 case GNUNET_RECLAIM_CREDENTIAL_TYPE_VC:
52 printf("DEBUG: vc_value_to_string: %s\n", (char *) data);
53 return GNUNET_strndup (data, data_size); 52 return GNUNET_strndup (data, data_size);
54 //return "A super cool verifiable credential\n"; 53 //return "A super cool verifiable credential\n";
55 default: 54 default:
@@ -82,7 +81,6 @@ vc_string_to_value (void *cls,
82 switch (type) 81 switch (type)
83 { 82 {
84 case GNUNET_RECLAIM_CREDENTIAL_TYPE_VC: 83 case GNUNET_RECLAIM_CREDENTIAL_TYPE_VC:
85 printf("DEBUG: vc_string_to_value: %s\n", s);
86 *data = GNUNET_strdup (s); 84 *data = GNUNET_strdup (s);
87 *data_size = strlen (s) + 1; 85 *data_size = strlen (s) + 1;
88 return GNUNET_OK; 86 return GNUNET_OK;
@@ -147,6 +145,7 @@ vc_number_to_typename (void *cls, uint32_t type)
147 145
148/** 146/**
149 * Parse a W3C Verifiable Credential and return the respective claim value as Attribute 147 * Parse a W3C Verifiable Credential and return the respective claim value as Attribute
148 * Only Works for single subject verifiable credentials
150 * 149 *
151 * @param cls the plugin 150 * @param cls the plugin
152 * @param cred the W3C Verifiable credential 151 * @param cred the W3C Verifiable credential
@@ -154,19 +153,39 @@ vc_number_to_typename (void *cls, uint32_t type)
154 */ 153 */
155struct GNUNET_RECLAIM_AttributeList * 154struct GNUNET_RECLAIM_AttributeList *
156vc_parse_attributes (void *cls, 155vc_parse_attributes (void *cls,
157 const char *data, 156 const char *cred,
158 size_t data_size) 157 size_t data_size)
159{ 158{
160 struct GNUNET_RECLAIM_AttributeList *attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 159 struct GNUNET_RECLAIM_AttributeList *attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
161 160
162 printf("DEBUG: vc_parse_attributes: %s\n", data); 161 json_t * root;
162 json_t * subject;
163 const char * key;
164 json_t * value;
165 const char * value_str;
163 166
164 GNUNET_RECLAIM_attribute_list_add (attrs, 167 root = json_loads(cred, JSON_DECODE_ANY, NULL);
165 "astring", 168 subject = json_object_get(root, "credentialSubject");
166 NULL, 169
167 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, 170 if(subject == NULL)
168 data, 171 {
169 (strlen(data) + 1)); 172 printf("The verifiable credential has to contain a Subject\n");
173 return NULL;
174 }
175
176 json_object_foreach(subject, key, value) {
177 if (json_is_string(value))
178 {
179 value_str = json_string_value(value);
180
181 GNUNET_RECLAIM_attribute_list_add (attrs,
182 key,
183 NULL,
184 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
185 value_str,
186 (strlen(value_str) + 1));
187 }
188 }
170 189
171 return attrs; 190 return attrs;
172} 191}
@@ -208,6 +227,7 @@ vc_parse_attributes_p (void *cls,
208 227
209/** 228/**
210 * Parse a VC and return the issuer 229 * Parse a VC and return the issuer
230 * Does not work for URI Issuer. https://www.w3.org/TR/vc-data-model/#issuer
211 * 231 *
212 * @param cls the plugin 232 * @param cls the plugin
213 * @param cred the verifiable credential 233 * @param cred the verifiable credential
@@ -215,11 +235,32 @@ vc_parse_attributes_p (void *cls,
215 */ 235 */
216char * 236char *
217vc_get_issuer (void *cls, 237vc_get_issuer (void *cls,
218 const char *data, 238 const char *cred,
219 size_t data_size) 239 size_t data_size)
220{ 240{
221 char * string = "some cool boi"; 241 json_t * root;
222 return GNUNET_strndup(string, strlen(string)); 242 json_t * issuer;
243 json_t * issuer_id;
244 char * issuer_id_str;
245
246 root = json_loads(cred, JSON_DECODE_ANY, NULL);
247 issuer = json_object_get(root, "credentialSubject");
248
249 if(issuer == NULL)
250 {
251 printf("The verifiable credential has to contain an issuer\n");
252 return NULL;
253 }
254
255 issuer_id = json_object_get(issuer, "id");
256
257 if(issuer_id == NULL){
258 printf("The issuer object of the verifiable credential has to contain an id\n");
259 return NULL;
260 }
261
262 issuer_id_str = json_string_value(issuer_id);
263 return GNUNET_strndup(issuer_id_str, strlen(issuer_id_str));
223} 264}
224 265
225 266
@@ -241,7 +282,7 @@ vc_get_issuer_c (void *cls,
241 282
242 283
243/** 284/**
244 * Parse a Verifiable Credential and return the issuer 285 * Parse a Verifiable Presentation and return the issuer
245 * 286 *
246 * @param cls the plugin 287 * @param cls the plugin
247 * @param cred the w3cvc credential 288 * @param cred the w3cvc credential
@@ -266,10 +307,26 @@ vc_get_issuer_p (void *cls,
266 */ 307 */
267enum GNUNET_GenericReturnValue 308enum GNUNET_GenericReturnValue
268vc_get_expiration (void *cls, 309vc_get_expiration (void *cls,
269 const char *data, 310 const char *cred,
270 size_t data_size, 311 size_t data_size,
271 struct GNUNET_TIME_Absolute *exp) 312 struct GNUNET_TIME_Absolute *exp)
272{ 313{
314 json_t * root;
315 json_t * expiration_date_json;
316 char * expiration_date_str;
317
318 root = json_loads(cred, JSON_DECODE_ANY, NULL);
319 expiration_date_json = json_object_get(root, "issuanceDate");
320
321 if(expiration_date_json == NULL)
322 {
323 return GNUNET_NO;
324 }
325
326 // TODO: Cacluate GNUNET_TIME based on W3C datetime
327 // expiration_date_str = json_string_value(expiration_date_json);
328 // return GNUNET_strndup(expiration_date_str, strlen(expiration_date_str));
329
273 exp->abs_value_us = UINT64_MAX; 330 exp->abs_value_us = UINT64_MAX;
274 return GNUNET_OK; 331 return GNUNET_OK;
275} 332}
diff --git a/vc.json b/vc.json
index dbc4d5d6d..dad6efb44 100644
--- a/vc.json
+++ b/vc.json
@@ -3,9 +3,10 @@
3 "https://www.w3.org/2018/credentials/v1", 3 "https://www.w3.org/2018/credentials/v1",
4 "https://www.w3.org/2018/credentials/examples/v1" 4 "https://www.w3.org/2018/credentials/examples/v1"
5 ], 5 ],
6 "type": ["VerifiableCredential"], 6 "type": "VerifiableCredential",
7 "issuer": "did:reclaim:1234", 7 "issuer": "did:reclaim:1234",
8 "issuanceDate": "2018-02-24T05:28:04Z", 8 "issuanceDate": "2018-02-24T05:28:04Z",
9 "expirationDate": "2025-02-24T00:00:00Z",
9 "credentialSubject": { 10 "credentialSubject": {
10 "id": "did:example:abcdef1234567", 11 "id": "did:example:abcdef1234567",
11 "name": "Jane Doe" 12 "name": "Jane Doe"