diff options
author | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-07-08 12:25:45 +0200 |
---|---|---|
committer | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-07-08 12:25:45 +0200 |
commit | 3b4032ef5138bf630d830218a0f29c9032cc35d4 (patch) | |
tree | 13212b6840277bc532f340241b205629bba1c0fe /src/reclaim | |
parent | 9c008dbed86125e74286f4a9c7da0f586fc7e04d (diff) | |
download | gnunet-3b4032ef5138bf630d830218a0f29c9032cc35d4.tar.gz gnunet-3b4032ef5138bf630d830218a0f29c9032cc35d4.zip |
-m DID lib; added check for existing DID document
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/did_core.c | 128 | ||||
-rw-r--r-- | src/reclaim/gnunet-did.c | 5 |
2 files changed, 98 insertions, 35 deletions
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c index f43b7e7eb..645ba0cd4 100644 --- a/src/reclaim/did_core.c +++ b/src/reclaim/did_core.c | |||
@@ -24,12 +24,7 @@ | |||
24 | * @author Tristan Schwieren | 24 | * @author Tristan Schwieren |
25 | */ | 25 | */ |
26 | 26 | ||
27 | // DO: Expiration time missing in create | 27 | // TODO: DID documents do not have an expiration date. Still we add one |
28 | // Add Expiration TIME to json DID document | ||
29 | |||
30 | // TODO: Check if ego already has a DID document in create | ||
31 | // TODO: Store DID document as compact JSON in GNS but resolve it with newlines | ||
32 | |||
33 | // TODO: Store DID document with empty label and own type (maybe DID-Document or JSON??) | 28 | // TODO: Store DID document with empty label and own type (maybe DID-Document or JSON??) |
34 | 29 | ||
35 | #include "did_core.h" | 30 | #include "did_core.h" |
@@ -87,7 +82,7 @@ DID_resolve_gns_lookup_cb ( | |||
87 | * Calls the given callback function with the resolved DID Document and the given closure. | 82 | * Calls the given callback function with the resolved DID Document and the given closure. |
88 | * If the did can not be resolved did_document is NULL. | 83 | * If the did can not be resolved did_document is NULL. |
89 | * | 84 | * |
90 | * @param did DID that is resolved000G055PGJ4RJSS4G8HWCP86AWF1C6TF2DW2K3BW05HHRKSJG38NT2Z3JGe | 85 | * @param did DID that is resolve |
91 | */ | 86 | */ |
92 | enum GNUNET_GenericReturnValue | 87 | enum GNUNET_GenericReturnValue |
93 | DID_resolve (const char *did, | 88 | DID_resolve (const char *did, |
@@ -141,6 +136,84 @@ DID_create_did_store_cb (void *cls, | |||
141 | } | 136 | } |
142 | } | 137 | } |
143 | 138 | ||
139 | struct DID_create_namestore_lookup_closure | ||
140 | { | ||
141 | const char *did_document; | ||
142 | struct GNUNET_TIME_Relative expire_time; | ||
143 | struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
144 | DID_action_callback *cont; | ||
145 | void *cls; | ||
146 | }; | ||
147 | |||
148 | static void | ||
149 | DID_create_namestore_lookup_cb (void *cls, | ||
150 | const struct | ||
151 | GNUNET_IDENTITY_PrivateKey *zone, | ||
152 | const char *label, | ||
153 | unsigned int rd_count, | ||
154 | const struct GNUNET_GNSRECORD_Data *rd) | ||
155 | { | ||
156 | struct GNUNET_GNSRECORD_Data record_data; | ||
157 | struct GNUNET_IDENTITY_PublicKey pkey; | ||
158 | |||
159 | const char *did_document | ||
160 | = ((struct DID_create_namestore_lookup_closure *) cls)->did_document; | ||
161 | |||
162 | const struct GNUNET_TIME_Relative expire_time | ||
163 | = ((struct DID_create_namestore_lookup_closure *) cls)->expire_time; | ||
164 | |||
165 | struct GNUNET_NAMESTORE_Handle *namestore_handle | ||
166 | = ((struct DID_create_namestore_lookup_closure *) cls)->namestore_handle; | ||
167 | |||
168 | DID_action_callback *cont | ||
169 | = ((struct DID_create_namestore_lookup_closure *) cls)->cont; | ||
170 | |||
171 | void *cls1 | ||
172 | = ((struct DID_create_namestore_lookup_closure *) cls)->cls; | ||
173 | |||
174 | if (rd_count > 0) | ||
175 | { | ||
176 | printf ("Ego already has a DID Document. Abort.\n"); | ||
177 | cont (GNUNET_NO, cls1); | ||
178 | return; | ||
179 | } | ||
180 | else { | ||
181 | // Get public key | ||
182 | GNUNET_IDENTITY_key_get_public (zone, &pkey); | ||
183 | |||
184 | // No DID Document is given a default one is created | ||
185 | if (did_document != NULL) | ||
186 | printf ( | ||
187 | "DID Docuement is read from \"DID-document\" argument (EXPERIMENTAL)\n"); | ||
188 | else | ||
189 | did_document = DID_pkey_to_did_document (&pkey); | ||
190 | |||
191 | // Create record | ||
192 | record_data.data = did_document; | ||
193 | record_data.expiration_time = expire_time.rel_value_us; | ||
194 | record_data.data_size = strlen (did_document) + 1; | ||
195 | record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), | ||
196 | record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
197 | |||
198 | // Create closure for record store callback | ||
199 | struct DID_action_return *cls2 = malloc (sizeof(struct DID_action_return)); | ||
200 | cls2->cb = cont; | ||
201 | cls2->cls = cls1; | ||
202 | |||
203 | // Store record | ||
204 | GNUNET_NAMESTORE_records_store (namestore_handle, | ||
205 | zone, | ||
206 | DID_DOCUMENT_LABEL, | ||
207 | 1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records | ||
208 | &record_data, | ||
209 | &DID_create_did_store_cb, | ||
210 | (void *) cls2); | ||
211 | |||
212 | free(cls); | ||
213 | } | ||
214 | |||
215 | } | ||
216 | |||
144 | /** | 217 | /** |
145 | * @brief Creates a DID and saves DID Document in Namestore. | 218 | * @brief Creates a DID and saves DID Document in Namestore. |
146 | * | 219 | * |
@@ -162,8 +235,6 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego, | |||
162 | void *cls) | 235 | void *cls) |
163 | { | 236 | { |
164 | struct GNUNET_IDENTITY_PublicKey pkey; | 237 | struct GNUNET_IDENTITY_PublicKey pkey; |
165 | // struct GNUNET_TIME_Relative expire_time; | ||
166 | struct GNUNET_GNSRECORD_Data record_data; | ||
167 | 238 | ||
168 | // Ego, namestore_handle and cont must be set | 239 | // Ego, namestore_handle and cont must be set |
169 | if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL)) | 240 | if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL)) |
@@ -178,33 +249,22 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego, | |||
178 | return GNUNET_NO; | 249 | return GNUNET_NO; |
179 | } | 250 | } |
180 | 251 | ||
181 | // No DID Document is given a default one is created | 252 | struct DID_create_namestore_lookup_closure *cls2 |
182 | if (did_document != NULL) | 253 | = malloc (sizeof(struct DID_create_namestore_lookup_closure)); |
183 | printf ( | 254 | cls2->did_document = did_document; |
184 | "DID Docuement is read from \"DID-document\" argument (EXPERIMENTAL)\n"); | 255 | cls2->expire_time = (*expire_time); |
185 | else | 256 | cls2->namestore_handle = namestore_handle; |
186 | did_document = DID_pkey_to_did_document (&pkey); | 257 | cls2->cont = cont; |
187 | |||
188 | // Create record | ||
189 | record_data.data = did_document; | ||
190 | record_data.expiration_time = expire_time->rel_value_us; | ||
191 | record_data.data_size = strlen (did_document) + 1; | ||
192 | record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), | ||
193 | record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
194 | |||
195 | // Create closure for record store callback | ||
196 | struct DID_action_return *cls2 = malloc (sizeof(struct DID_action_return)); | ||
197 | cls2->cb = cont; | ||
198 | cls2->cls = cls; | 258 | cls2->cls = cls; |
199 | 259 | ||
200 | // Store record | 260 | // Check if ego already has a DID Document |
201 | GNUNET_NAMESTORE_records_store (namestore_handle, | 261 | GNUNET_NAMESTORE_records_lookup (namestore_handle, |
202 | GNUNET_IDENTITY_ego_get_private_key (ego), | 262 | GNUNET_IDENTITY_ego_get_private_key (ego), |
203 | DID_DOCUMENT_LABEL, | 263 | DID_DOCUMENT_LABEL, |
204 | 1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records | 264 | NULL, |
205 | &record_data, | 265 | NULL, |
206 | &DID_create_did_store_cb, | 266 | DID_create_namestore_lookup_cb, |
207 | (void *) cls2); | 267 | (void *) cls2); |
208 | 268 | ||
209 | return GNUNET_OK; | 269 | return GNUNET_OK; |
210 | } | 270 | } |
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c index fb9a8e9a1..c0f81c3e2 100644 --- a/src/reclaim/gnunet-did.c +++ b/src/reclaim/gnunet-did.c | |||
@@ -446,7 +446,10 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
446 | 446 | ||
447 | strcpy (cls, did); | 447 | strcpy (cls, did); |
448 | // TODO: Add DID_document argument | 448 | // TODO: Add DID_document argument |
449 | if (GNUNET_OK != DID_create (ego, NULL, &expire_relative, namestore_handle, | 449 | if (GNUNET_OK != DID_create (ego, |
450 | NULL, | ||
451 | &expire_relative, | ||
452 | namestore_handle, | ||
450 | create_did_cb, | 453 | create_did_cb, |
451 | cls)) | 454 | cls)) |
452 | { | 455 | { |