aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/plugin_escrow_plaintext.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r--src/escrow/plugin_escrow_plaintext.c196
1 files changed, 156 insertions, 40 deletions
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c
index 39f605262..86f49955f 100644
--- a/src/escrow/plugin_escrow_plaintext.c
+++ b/src/escrow/plugin_escrow_plaintext.c
@@ -29,7 +29,6 @@
29#include "gnunet_escrow_plugin.h" 29#include "gnunet_escrow_plugin.h"
30#include "escrow_plugin_helper.h" 30#include "escrow_plugin_helper.h"
31#include "gnunet_identity_service.h" 31#include "gnunet_identity_service.h"
32#include "../identity/identity.h"
33#include "escrow.h" 32#include "escrow.h"
34#include <inttypes.h> 33#include <inttypes.h>
35 34
@@ -57,6 +56,21 @@ struct ESCROW_PlaintextPluginOperation
57 struct GNUNET_CRYPTO_EcdsaPrivateKey pk; 56 struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
58 57
59 /** 58 /**
59 * The ego
60 */
61 struct GNUNET_IDENTITY_Ego *ego;
62
63 /**
64 * The anchor
65 */
66 const struct GNUNET_ESCROW_Anchor *anchor;
67
68 /**
69 * Name of the ego
70 */
71 char *egoName;
72
73 /**
60 * Continuation for a plugin operation (e.g. used for restore, as this 74 * Continuation for a plugin operation (e.g. used for restore, as this
61 * callback has to be called from the IDENTITY service after finishing) 75 * callback has to be called from the IDENTITY service after finishing)
62 */ 76 */
@@ -109,6 +123,8 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
109 GNUNET_free (p_op->ego_wrap); 123 GNUNET_free (p_op->ego_wrap);
110 if (NULL != p_op->verify_wrap) 124 if (NULL != p_op->verify_wrap)
111 GNUNET_free (p_op->verify_wrap); 125 GNUNET_free (p_op->verify_wrap);
126 if (NULL != p_op->egoName)
127 GNUNET_free (p_op->egoName);
112 GNUNET_free (p_op); 128 GNUNET_free (p_op);
113 GNUNET_free (plugin_op_wrap); 129 GNUNET_free (plugin_op_wrap);
114} 130}
@@ -128,6 +144,59 @@ start_cont (void *cls)
128} 144}
129 145
130 146
147static void
148continue_start (void *cls)
149{
150 struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls;
151 struct ESCROW_PlaintextPluginOperation *p_op;
152 struct GNUNET_TIME_Relative delay;
153 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub;
154 struct EgoEntry *ego_entry;
155 char *pub_keystring;
156 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
157 char *pkString;
158
159 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op;
160
161 if (ESCROW_PLUGIN_STATE_POST_INIT != ph.state)
162 {
163 delay.rel_value_us = 100 * GNUNET_TIME_relative_get_millisecond_().rel_value_us;
164 GNUNET_SCHEDULER_add_delayed (delay, &continue_start, plugin_op_wrap);
165 return;
166 }
167
168 GNUNET_IDENTITY_ego_get_public_key (p_op->ego, &ego_pub);
169 pub_keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&ego_pub);
170 for (ego_entry = ph.ego_head; NULL != ego_entry; ego_entry = ego_entry->next)
171 if (0 == strcmp (pub_keystring, ego_entry->keystring))
172 break;
173
174 GNUNET_free (pub_keystring);
175 if (NULL == ego_entry)
176 {
177 p_op->anchor_wrap->anchor = NULL;
178 p_op->anchor_wrap->emsg = _ ("Identity was not found in plugin!\n");
179 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
180 return;
181 }
182
183 p_op->egoName = GNUNET_strdup (ego_entry->identifier);
184
185 pk = GNUNET_IDENTITY_ego_get_private_key (p_op->ego);
186 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
187
188 p_op->anchor_wrap->anchor = ESCROW_build_anchor (GNUNET_ESCROW_KEY_PLAINTEXT,
189 p_op->egoName,
190 pkString,
191 strlen (pkString));
192
193 /* update escrow status, i.e. set the last escrow method */
194 ESCROW_update_escrow_status_put (p_op->h, p_op->ego, "plaintext");
195
196 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
197}
198
199
131/** 200/**
132 * Start the plaintext escrow of the key, i.e. simply hand out the key 201 * Start the plaintext escrow of the key, i.e. simply hand out the key
133 * 202 *
@@ -146,13 +215,10 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
146 ESCROW_Plugin_Continuation cb, 215 ESCROW_Plugin_Continuation cb,
147 uint32_t op_id) 216 uint32_t op_id)
148{ 217{
149 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
150 struct GNUNET_ESCROW_Anchor *anchor;
151 char *pkString;
152 uint32_t anchorDataSize;
153 struct ESCROW_PluginOperationWrapper *plugin_op_wrap; 218 struct ESCROW_PluginOperationWrapper *plugin_op_wrap;
154 struct ESCROW_PlaintextPluginOperation *p_op; 219 struct ESCROW_PlaintextPluginOperation *p_op;
155 struct ESCROW_Plugin_AnchorContinuationWrapper *w; 220 struct ESCROW_Plugin_AnchorContinuationWrapper *w;
221 struct GNUNET_TIME_Relative delay;
156 222
157 // create a new plaintext plugin operation (in a wrapper) and insert it into the DLL 223 // create a new plaintext plugin operation (in a wrapper) and insert it into the DLL
158 plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper); 224 plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper);
@@ -164,6 +230,7 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
164 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op; 230 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op;
165 p_op->h = h; 231 p_op->h = h;
166 p_op->cont = cb; 232 p_op->cont = cb;
233 p_op->ego = ego;
167 234
168 w = GNUNET_new (struct ESCROW_Plugin_AnchorContinuationWrapper); 235 w = GNUNET_new (struct ESCROW_Plugin_AnchorContinuationWrapper);
169 w->h = h; 236 w->h = h;
@@ -177,22 +244,17 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
177 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); 244 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
178 return plugin_op_wrap; 245 return plugin_op_wrap;
179 } 246 }
180 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
181 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
182
183 anchorDataSize = strlen (pkString) + 1;
184 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize);
185 anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT;
186 anchor->egoName = GNUNET_strdup (ego->name);
187 anchor->size = anchorDataSize;
188 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize);
189 247
190 w->anchor = anchor; 248 if (ESCROW_PLUGIN_STATE_POST_INIT == ph.state)
191 249 {
192 /* update escrow status, i.e. set the last escrow method */ 250 continue_start (plugin_op_wrap);
193 ESCROW_update_escrow_status_put (h, ego, "plaintext"); 251 }
252 else
253 {
254 delay.rel_value_us = 200 * GNUNET_TIME_relative_get_millisecond_().rel_value_us;
255 GNUNET_SCHEDULER_add_delayed (delay, &continue_start, plugin_op_wrap);
256 }
194 257
195 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
196 return plugin_op_wrap; 258 return plugin_op_wrap;
197} 259}
198 260
@@ -211,6 +273,68 @@ verify_cont (void *cls)
211} 273}
212 274
213 275
276static void
277continue_verify (void *cls)
278{
279 struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls;
280 struct ESCROW_PlaintextPluginOperation *p_op;
281 struct GNUNET_TIME_Relative delay;
282 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
283 char *pkString;
284 int verificationResult;
285 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub;
286 struct EgoEntry *ego_entry;
287 char *pub_keystring;
288
289 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op;
290
291 if (ESCROW_PLUGIN_STATE_POST_INIT != ph.state)
292 {
293 delay.rel_value_us = 100 * GNUNET_TIME_relative_get_millisecond_().rel_value_us;
294 GNUNET_SCHEDULER_add_delayed (delay, &continue_verify, plugin_op_wrap);
295 return;
296 }
297
298 GNUNET_IDENTITY_ego_get_public_key (p_op->ego, &ego_pub);
299 pub_keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&ego_pub);
300 for (ego_entry = ph.ego_head; NULL != ego_entry; ego_entry = ego_entry->next)
301 if (0 == strcmp (pub_keystring, ego_entry->keystring))
302 break;
303
304 GNUNET_free (pub_keystring);
305 if (NULL == ego_entry)
306 {
307 p_op->anchor_wrap->anchor = NULL;
308 p_op->anchor_wrap->emsg = _ ("Identity was not found in plugin!\n");
309 p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
310 return;
311 }
312
313 p_op->egoName = GNUNET_strdup (ego_entry->identifier);
314
315 if (0 != strcmp (p_op->egoName, p_op->anchor->egoName))
316 {
317 p_op->verify_wrap->verificationResult = GNUNET_ESCROW_INVALID;
318 p_op->verify_wrap->emsg = _ ("This anchor was not created when putting that ego in escrow!\n");
319 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap);
320 return;
321 }
322 pk = GNUNET_IDENTITY_ego_get_private_key (p_op->ego);
323 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
324 verificationResult = strncmp (pkString,
325 (char *)&p_op->anchor[1],
326 p_op->anchor->size) == 0 ?
327 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID;
328
329 /* update the escrow status if valid */
330 if (GNUNET_ESCROW_VALID == verificationResult)
331 ESCROW_update_escrow_status_verify (p_op->h, p_op->ego, "plaintext");
332
333 p_op->verify_wrap->verificationResult = verificationResult;
334 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap);
335}
336
337
214/** 338/**
215 * Verify the plaintext escrow of the key 339 * Verify the plaintext escrow of the key
216 * 340 *
@@ -229,12 +353,10 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
229 ESCROW_Plugin_Continuation cb, 353 ESCROW_Plugin_Continuation cb,
230 uint32_t op_id) 354 uint32_t op_id)
231{ 355{
232 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
233 char *pkString;
234 int verificationResult;
235 struct ESCROW_PluginOperationWrapper *plugin_op_wrap; 356 struct ESCROW_PluginOperationWrapper *plugin_op_wrap;
236 struct ESCROW_PlaintextPluginOperation *p_op; 357 struct ESCROW_PlaintextPluginOperation *p_op;
237 struct ESCROW_Plugin_VerifyContinuationWrapper *w; 358 struct ESCROW_Plugin_VerifyContinuationWrapper *w;
359 struct GNUNET_TIME_Relative delay;
238 360
239 // create a new plaintext plugin operation (in a wrapper) and insert it into the DLL 361 // create a new plaintext plugin operation (in a wrapper) and insert it into the DLL
240 plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper); 362 plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper);
@@ -246,6 +368,8 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
246 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op; 368 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op;
247 p_op->h = h; 369 p_op->h = h;
248 p_op->cont = cb; 370 p_op->cont = cb;
371 p_op->ego = ego;
372 p_op->anchor = anchor;
249 373
250 w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); 374 w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper);
251 w->h = h; 375 w->h = h;
@@ -266,26 +390,17 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
266 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); 390 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap);
267 return plugin_op_wrap; 391 return plugin_op_wrap;
268 } 392 }
269 if (0 != strcmp (ego->name, anchor->egoName)) 393
394 if (ESCROW_PLUGIN_STATE_POST_INIT == ph.state)
270 { 395 {
271 w->verificationResult = GNUNET_ESCROW_INVALID; 396 continue_verify (plugin_op_wrap);
272 w->emsg = _ ("This anchor was not created when putting that ego in escrow!\n"); 397 }
273 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); 398 else
274 return plugin_op_wrap; 399 {
400 delay.rel_value_us = 200 * GNUNET_TIME_relative_get_millisecond_().rel_value_us;
401 GNUNET_SCHEDULER_add_delayed (delay, &continue_verify, plugin_op_wrap);
275 } 402 }
276 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
277 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
278 verificationResult = strncmp (pkString,
279 (char *)&anchor[1],
280 anchor->size) == 0 ?
281 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID;
282
283 /* update the escrow status if valid */
284 if (GNUNET_ESCROW_VALID == verificationResult)
285 ESCROW_update_escrow_status_verify (h, ego, "plaintext");
286 403
287 w->verificationResult = verificationResult;
288 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap);
289 return plugin_op_wrap; 404 return plugin_op_wrap;
290} 405}
291 406
@@ -297,7 +412,8 @@ ego_created (struct GNUNET_IDENTITY_Ego *ego)
297 struct ESCROW_PlaintextPluginOperation *curr_p_op; 412 struct ESCROW_PlaintextPluginOperation *curr_p_op;
298 char *ego_pk_string, *curr_pk_string; 413 char *ego_pk_string, *curr_pk_string;
299 414
300 ego_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string (&ego->pk); 415 ego_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string (
416 GNUNET_IDENTITY_ego_get_private_key(ego));
301 417
302 for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next) 418 for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next)
303 { 419 {