diff options
-rw-r--r-- | src/escrow/escrow_plugin_helper.c | 154 | ||||
-rw-r--r-- | src/escrow/escrow_plugin_helper.h | 24 | ||||
-rw-r--r-- | src/escrow/gnunet-escrow.c | 8 | ||||
-rw-r--r-- | src/escrow/plugin_escrow_gns.c | 8 | ||||
-rw-r--r-- | src/escrow/plugin_escrow_plaintext.c | 8 | ||||
-rw-r--r-- | src/include/gnunet_escrow_lib.h | 11 |
6 files changed, 145 insertions, 68 deletions
diff --git a/src/escrow/escrow_plugin_helper.c b/src/escrow/escrow_plugin_helper.c index 25648dfa1..3ed5ddabe 100644 --- a/src/escrow/escrow_plugin_helper.c +++ b/src/escrow/escrow_plugin_helper.c | |||
@@ -198,8 +198,52 @@ string_to_upper (const char *str) | |||
198 | } | 198 | } |
199 | 199 | ||
200 | 200 | ||
201 | static int | ||
202 | write_config (struct GNUNET_ESCROW_Handle *h) | ||
203 | { | ||
204 | char *conf_file; | ||
205 | |||
206 | GNUNET_assert (GNUNET_OK == | ||
207 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, | ||
208 | "PATHS", | ||
209 | "DEFAULTCONFIG", | ||
210 | &conf_file)); | ||
211 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (h->cfg, conf_file)) | ||
212 | { | ||
213 | fprintf (stderr, "unable to write config file\n"); | ||
214 | GNUNET_free (conf_file); | ||
215 | return GNUNET_NO; | ||
216 | } | ||
217 | |||
218 | GNUNET_free (conf_file); | ||
219 | |||
220 | return GNUNET_OK; | ||
221 | } | ||
222 | |||
223 | |||
224 | static char * | ||
225 | get_config_section (struct GNUNET_IDENTITY_Ego *ego) | ||
226 | { | ||
227 | struct GNUNET_CRYPTO_EcdsaPublicKey *pub; | ||
228 | char *config_section, *pubkey_string; | ||
229 | |||
230 | pub = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
231 | GNUNET_IDENTITY_ego_get_public_key (ego, pub); | ||
232 | pubkey_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (pub); | ||
233 | |||
234 | // allocate enough space for "escrow-PUBKEY" | ||
235 | config_section = GNUNET_malloc (7 + strlen (pubkey_string) + 1); | ||
236 | sprintf (config_section, "escrow-%s", pubkey_string); | ||
237 | |||
238 | GNUNET_free (pubkey_string); | ||
239 | |||
240 | return config_section; | ||
241 | } | ||
242 | |||
243 | |||
201 | /** | 244 | /** |
202 | * Update the status of an escrow in the configuration. | 245 | * Update the status of an escrow in the configuration after a successful |
246 | * VERIFY operation. | ||
203 | * | 247 | * |
204 | * @param h handle for the escrow component | 248 | * @param h handle for the escrow component |
205 | * @param ego the ego of which the escrow status is updated | 249 | * @param ego the ego of which the escrow status is updated |
@@ -208,81 +252,89 @@ string_to_upper (const char *str) | |||
208 | * @return GNUNET_OK on success | 252 | * @return GNUNET_OK on success |
209 | */ | 253 | */ |
210 | int | 254 | int |
211 | ESCROW_update_escrow_status (struct GNUNET_ESCROW_Handle *h, | 255 | ESCROW_update_escrow_status_verify (struct GNUNET_ESCROW_Handle *h, |
212 | struct GNUNET_IDENTITY_Ego *ego, | 256 | struct GNUNET_IDENTITY_Ego *ego, |
213 | const char *plugin_name) | 257 | const char *plugin_name) |
214 | { | 258 | { |
215 | struct GNUNET_CRYPTO_EcdsaPublicKey *pub; | 259 | char *config_section, *config_option, *plugin_name_upper; |
216 | char *config_section, *pubkey_string, *config_option, *plugin_name_upper; | 260 | struct GNUNET_TIME_Absolute now, next_verification; |
217 | struct GNUNET_TIME_Absolute now, next_escrow; | ||
218 | struct GNUNET_TIME_Relative escrow_interval; | 261 | struct GNUNET_TIME_Relative escrow_interval; |
219 | char *conf_file; | ||
220 | 262 | ||
221 | pub = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | 263 | config_section = get_config_section (ego); |
222 | GNUNET_IDENTITY_ego_get_public_key (ego, pub); | ||
223 | pubkey_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (pub); | ||
224 | |||
225 | // allocate enough space for "escrow-PUBKEY" | ||
226 | config_section = GNUNET_malloc (7 + strlen (pubkey_string) + 1); | ||
227 | sprintf (config_section, "escrow-%s", pubkey_string); | ||
228 | 264 | ||
229 | // allocate enough space for "<plugin_name>_INTERVAL" | 265 | // allocate enough space for "<plugin_name>_INTERVAL" |
230 | config_option = GNUNET_malloc (strlen (plugin_name) + 9 + 1); | 266 | config_option = GNUNET_malloc (strlen (plugin_name) + 9 + 1); |
231 | plugin_name_upper = string_to_upper (plugin_name); | 267 | plugin_name_upper = string_to_upper (plugin_name); |
232 | sprintf (config_option, "%s_INTERVAL", plugin_name_upper); | 268 | sprintf (config_option, "%s_VERIFY_INTERVAL", plugin_name_upper); |
233 | 269 | ||
234 | now = GNUNET_TIME_absolute_get (); | 270 | now = GNUNET_TIME_absolute_get (); |
235 | GNUNET_CONFIGURATION_set_value_number (h->cfg, | 271 | GNUNET_CONFIGURATION_set_value_number (h->cfg, |
236 | config_section, | 272 | config_section, |
237 | "LAST_ESCROW_TIME", | 273 | "LAST_SUCCESSFUL_VERIFICATION_TIME", |
238 | (unsigned long long)now.abs_value_us); | 274 | (unsigned long long)now.abs_value_us); |
239 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (h->cfg, | 275 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (h->cfg, |
240 | "escrow", | 276 | "escrow", |
241 | config_option, | 277 | config_option, |
242 | &escrow_interval)) | 278 | &escrow_interval)) |
243 | { | 279 | { |
244 | fprintf (stderr, "could not find config value for escrow interval\n"); | 280 | fprintf (stderr, "could not find config value for verification interval\n"); |
245 | GNUNET_free (pub); | ||
246 | GNUNET_free (config_section); | 281 | GNUNET_free (config_section); |
247 | GNUNET_free (pubkey_string); | ||
248 | GNUNET_free (config_option); | 282 | GNUNET_free (config_option); |
249 | GNUNET_free (plugin_name_upper); | 283 | GNUNET_free (plugin_name_upper); |
250 | return GNUNET_NO; | 284 | return GNUNET_NO; |
251 | } | 285 | } |
252 | next_escrow = GNUNET_TIME_absolute_add (now, escrow_interval); | 286 | next_verification = GNUNET_TIME_absolute_add (now, escrow_interval); |
253 | GNUNET_CONFIGURATION_set_value_number (h->cfg, | 287 | GNUNET_CONFIGURATION_set_value_number (h->cfg, |
254 | config_section, | 288 | config_section, |
255 | "NEXT_RECOMMENDED_ESCROW_TIME", | 289 | "NEXT_RECOMMENDED_VERIFICATION_TIME", |
256 | (unsigned long long)next_escrow.abs_value_us); | 290 | (unsigned long long)next_verification.abs_value_us); |
291 | |||
292 | if (GNUNET_OK != write_config (h)) | ||
293 | { | ||
294 | GNUNET_free (config_section); | ||
295 | GNUNET_free (config_option); | ||
296 | GNUNET_free (plugin_name_upper); | ||
297 | return GNUNET_NO; | ||
298 | } | ||
299 | |||
300 | GNUNET_free (config_section); | ||
301 | GNUNET_free (config_option); | ||
302 | GNUNET_free (plugin_name_upper); | ||
303 | |||
304 | return GNUNET_OK; | ||
305 | } | ||
306 | |||
307 | |||
308 | /** | ||
309 | * Update the status of an escrow in the configuration after a PUT operation. | ||
310 | * | ||
311 | * @param h handle for the escrow component | ||
312 | * @param ego the ego of which the escrow status is updated | ||
313 | * @param plugin_name the name of the used plugin | ||
314 | * | ||
315 | * @return GNUNET_OK on success | ||
316 | */ | ||
317 | int | ||
318 | ESCROW_update_escrow_status_put (struct GNUNET_ESCROW_Handle *h, | ||
319 | struct GNUNET_IDENTITY_Ego *ego, | ||
320 | const char *plugin_name) | ||
321 | { | ||
322 | char *config_section; | ||
323 | |||
324 | config_section = get_config_section (ego); | ||
257 | 325 | ||
258 | GNUNET_CONFIGURATION_set_value_string (h->cfg, | 326 | GNUNET_CONFIGURATION_set_value_string (h->cfg, |
259 | config_section, | 327 | config_section, |
260 | "ESCROW_METHOD", | 328 | "ESCROW_METHOD", |
261 | plugin_name); | 329 | plugin_name); |
262 | 330 | ||
263 | GNUNET_assert (GNUNET_OK == | 331 | if (GNUNET_OK != write_config (h)) |
264 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, | ||
265 | "PATHS", | ||
266 | "DEFAULTCONFIG", | ||
267 | &conf_file)); | ||
268 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (h->cfg, conf_file)) | ||
269 | { | 332 | { |
270 | fprintf (stderr, "unable to write config file\n"); | ||
271 | GNUNET_free (pub); | ||
272 | GNUNET_free (config_section); | 333 | GNUNET_free (config_section); |
273 | GNUNET_free (pubkey_string); | ||
274 | GNUNET_free (config_option); | ||
275 | GNUNET_free (plugin_name_upper); | ||
276 | GNUNET_free (conf_file); | ||
277 | return GNUNET_NO; | 334 | return GNUNET_NO; |
278 | } | 335 | } |
279 | 336 | ||
280 | GNUNET_free (pub); | ||
281 | GNUNET_free (config_section); | 337 | GNUNET_free (config_section); |
282 | GNUNET_free (pubkey_string); | ||
283 | GNUNET_free (config_option); | ||
284 | GNUNET_free (plugin_name_upper); | ||
285 | GNUNET_free (conf_file); | ||
286 | 338 | ||
287 | return GNUNET_OK; | 339 | return GNUNET_OK; |
288 | } | 340 | } |
@@ -301,7 +353,7 @@ ESCROW_get_escrow_status (struct GNUNET_ESCROW_Handle *h, | |||
301 | struct GNUNET_IDENTITY_Ego *ego) | 353 | struct GNUNET_IDENTITY_Ego *ego) |
302 | { | 354 | { |
303 | struct GNUNET_ESCROW_Status *status; | 355 | struct GNUNET_ESCROW_Status *status; |
304 | unsigned long long conf_last_escrow, conf_next_escrow; | 356 | unsigned long long conf_last_verification, conf_next_verification; |
305 | struct GNUNET_CRYPTO_EcdsaPublicKey *pub; | 357 | struct GNUNET_CRYPTO_EcdsaPublicKey *pub; |
306 | char *config_section, *pubkey_string, *conf_escrow_method; | 358 | char *config_section, *pubkey_string, *conf_escrow_method; |
307 | 359 | ||
@@ -316,25 +368,25 @@ ESCROW_get_escrow_status (struct GNUNET_ESCROW_Handle *h, | |||
316 | status = GNUNET_new (struct GNUNET_ESCROW_Status); | 368 | status = GNUNET_new (struct GNUNET_ESCROW_Status); |
317 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, | 369 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, |
318 | config_section, | 370 | config_section, |
319 | "LAST_ESCROW_TIME", | 371 | "LAST_SUCCESSFUL_VERIFICATION_TIME", |
320 | &conf_last_escrow)) | 372 | &conf_last_verification)) |
321 | { | 373 | { |
322 | /* failed to get value from config, set last escrow time to zero */ | 374 | /* failed to get value from config, set last verification time to zero */ |
323 | status->last_escrow_time = GNUNET_TIME_absolute_get_zero_(); | 375 | status->last_successful_verification_time = GNUNET_TIME_absolute_get_zero_(); |
324 | } | 376 | } |
325 | else | 377 | else |
326 | status->last_escrow_time.abs_value_us = (uint64_t)conf_last_escrow; | 378 | status->last_successful_verification_time.abs_value_us = (uint64_t)conf_last_verification; |
327 | 379 | ||
328 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, | 380 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, |
329 | config_section, | 381 | config_section, |
330 | "NEXT_RECOMMENDED_ESCROW_TIME", | 382 | "NEXT_RECOMMENDED_VERIFICATION_TIME", |
331 | &conf_next_escrow)) | 383 | &conf_next_verification)) |
332 | { | 384 | { |
333 | /* failed to get value from config, set next recommended escrow to now */ | 385 | /* failed to get value from config, set next recommended verification to now */ |
334 | status->next_recommended_escrow_time = GNUNET_TIME_absolute_get (); | 386 | status->next_recommended_verification_time = GNUNET_TIME_absolute_get (); |
335 | } | 387 | } |
336 | else | 388 | else |
337 | status->next_recommended_escrow_time.abs_value_us = (uint64_t)conf_next_escrow; | 389 | status->next_recommended_verification_time.abs_value_us = (uint64_t)conf_next_verification; |
338 | 390 | ||
339 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, | 391 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, |
340 | config_section, | 392 | config_section, |
diff --git a/src/escrow/escrow_plugin_helper.h b/src/escrow/escrow_plugin_helper.h index f2a54eb6b..b7764edd5 100644 --- a/src/escrow/escrow_plugin_helper.h +++ b/src/escrow/escrow_plugin_helper.h | |||
@@ -82,7 +82,7 @@ ESCROW_cleanup_ego_list (struct ESCROW_PluginHandle *ph); | |||
82 | 82 | ||
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Update the status of an escrow in the configuration. | 85 | * Update the status of an escrow in the configuration after a VERIFY operation. |
86 | * | 86 | * |
87 | * @param h handle for the escrow component | 87 | * @param h handle for the escrow component |
88 | * @param ego the ego of which the escrow status is updated | 88 | * @param ego the ego of which the escrow status is updated |
@@ -91,9 +91,25 @@ ESCROW_cleanup_ego_list (struct ESCROW_PluginHandle *ph); | |||
91 | * @return GNUNET_OK on success | 91 | * @return GNUNET_OK on success |
92 | */ | 92 | */ |
93 | int | 93 | int |
94 | ESCROW_update_escrow_status (struct GNUNET_ESCROW_Handle *h, | 94 | ESCROW_update_escrow_status_verify (struct GNUNET_ESCROW_Handle *h, |
95 | struct GNUNET_IDENTITY_Ego *ego, | 95 | struct GNUNET_IDENTITY_Ego *ego, |
96 | const char *plugin_name); | 96 | const char *plugin_name); |
97 | |||
98 | |||
99 | /** | ||
100 | * Update the status of an escrow in the configuration after a PUT operation. | ||
101 | * | ||
102 | * @param h handle for the escrow component | ||
103 | * @param ego the ego of which the escrow status is updated | ||
104 | * @param plugin_name the name of the used plugin | ||
105 | * | ||
106 | * @return GNUNET_OK on success | ||
107 | */ | ||
108 | int | ||
109 | ESCROW_update_escrow_status_put (struct GNUNET_ESCROW_Handle *h, | ||
110 | struct GNUNET_IDENTITY_Ego *ego, | ||
111 | const char *plugin_name); | ||
112 | |||
97 | 113 | ||
98 | /** | 114 | /** |
99 | * Get the status of an escrow from the configuration. | 115 | * Get the status of an escrow from the configuration. |
diff --git a/src/escrow/gnunet-escrow.c b/src/escrow/gnunet-escrow.c index 705d09d11..9b8b1a176 100644 --- a/src/escrow/gnunet-escrow.c +++ b/src/escrow/gnunet-escrow.c | |||
@@ -329,10 +329,10 @@ start_process () | |||
329 | ego, | 329 | ego, |
330 | method); | 330 | method); |
331 | // TODO: formatting/interpretation | 331 | // TODO: formatting/interpretation |
332 | fprintf (stdout, "Last escrow:\t\t\t%s\n", | 332 | fprintf (stdout, "Last successful verification:\t%s\n", |
333 | GNUNET_STRINGS_absolute_time_to_string (escrow_status->last_escrow_time)); | 333 | GNUNET_STRINGS_absolute_time_to_string (escrow_status->last_successful_verification_time)); |
334 | fprintf (stdout, "Next recommended escrow:\t%s\n", | 334 | fprintf (stdout, "Next recommended verification:\t%s\n", |
335 | GNUNET_STRINGS_absolute_time_to_string (escrow_status->next_recommended_escrow_time)); | 335 | GNUNET_STRINGS_absolute_time_to_string (escrow_status->next_recommended_verification_time)); |
336 | fprintf (stdout, "Last method:\t\t\t"); | 336 | fprintf (stdout, "Last method:\t\t\t"); |
337 | switch (escrow_status->last_method) | 337 | switch (escrow_status->last_method) |
338 | { | 338 | { |
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index eb37f75b3..96a7252ec 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c | |||
@@ -542,8 +542,8 @@ keyshare_distribution_finished (void *cls) | |||
542 | 542 | ||
543 | p_op->anchor_wrap->anchor = anchor; | 543 | p_op->anchor_wrap->anchor = anchor; |
544 | 544 | ||
545 | /* set the last escrow time */ | 545 | /* update escrow status, i.e. set the last escrow method */ |
546 | ESCROW_update_escrow_status (p_op->h, p_op->ego, "gns"); | 546 | ESCROW_update_escrow_status_put (p_op->h, p_op->ego, "gns"); |
547 | 547 | ||
548 | /* call the continuation */ | 548 | /* call the continuation */ |
549 | start_cont (plugin_op_wrap); | 549 | start_cont (plugin_op_wrap); |
@@ -1422,6 +1422,10 @@ verify_restored_pk (void *cls, | |||
1422 | count_keyshares (p_op->restored_keyshares, p_op->shares) < p_op->shares) | 1422 | count_keyshares (p_op->restored_keyshares, p_op->shares) < p_op->shares) |
1423 | verificationResult = GNUNET_ESCROW_SHARES_MISSING; | 1423 | verificationResult = GNUNET_ESCROW_SHARES_MISSING; |
1424 | 1424 | ||
1425 | /* update the escrow status if valid */ | ||
1426 | if (GNUNET_ESCROW_VALID == verificationResult) | ||
1427 | ESCROW_update_escrow_status_verify (p_op->h, p_op->ego, "gns"); | ||
1428 | |||
1425 | p_op->verify_wrap->verificationResult = verificationResult; | 1429 | p_op->verify_wrap->verificationResult = verificationResult; |
1426 | verify_cont (plugin_op_wrap); | 1430 | verify_cont (plugin_op_wrap); |
1427 | } | 1431 | } |
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c index 36c275a6b..41523a906 100644 --- a/src/escrow/plugin_escrow_plaintext.c +++ b/src/escrow/plugin_escrow_plaintext.c | |||
@@ -189,8 +189,8 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
189 | 189 | ||
190 | w->anchor = anchor; | 190 | w->anchor = anchor; |
191 | 191 | ||
192 | /* set the last escrow time */ | 192 | /* update escrow status, i.e. set the last escrow method */ |
193 | ESCROW_update_escrow_status (h, ego, "plaintext"); | 193 | ESCROW_update_escrow_status_put (h, ego, "plaintext"); |
194 | 194 | ||
195 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); | 195 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); |
196 | return plugin_op_wrap; | 196 | return plugin_op_wrap; |
@@ -280,6 +280,10 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
280 | anchor->size) == 0 ? | 280 | anchor->size) == 0 ? |
281 | GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; | 281 | GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; |
282 | 282 | ||
283 | /* update the escrow status if valid */ | ||
284 | if (GNUNET_ESCROW_VALID == verificationResult) | ||
285 | ESCROW_update_escrow_status_verify (h, ego, "plaintext"); | ||
286 | |||
283 | w->verificationResult = verificationResult; | 287 | w->verificationResult = verificationResult; |
284 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | 288 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); |
285 | return plugin_op_wrap; | 289 | return plugin_op_wrap; |
diff --git a/src/include/gnunet_escrow_lib.h b/src/include/gnunet_escrow_lib.h index 1ede355d0..864d6356d 100644 --- a/src/include/gnunet_escrow_lib.h +++ b/src/include/gnunet_escrow_lib.h | |||
@@ -92,17 +92,18 @@ struct GNUNET_ESCROW_Anchor | |||
92 | struct GNUNET_ESCROW_Status | 92 | struct GNUNET_ESCROW_Status |
93 | { | 93 | { |
94 | /** | 94 | /** |
95 | * The time of the last successful escrow. | 95 | * The time of the last successful verification. |
96 | */ | 96 | */ |
97 | struct GNUNET_TIME_Absolute last_escrow_time; | 97 | struct GNUNET_TIME_Absolute last_successful_verification_time; |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * The time of the next recommended escrow. | 100 | * The time of the next recommended verification. |
101 | */ | 101 | */ |
102 | struct GNUNET_TIME_Absolute next_recommended_escrow_time; | 102 | struct GNUNET_TIME_Absolute next_recommended_verification_time; |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * The used escrow method. | 105 | * The escrow method used for the last escrow of the identity, |
106 | * GNUNET_ESCROW_KEY_NONE if no escrow has been performed. | ||
106 | */ | 107 | */ |
107 | enum GNUNET_ESCROW_Key_Escrow_Method last_method; | 108 | enum GNUNET_ESCROW_Key_Escrow_Method last_method; |
108 | }; | 109 | }; |