summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-09-04 21:08:25 +0200
committerjospaeth <spaethj@in.tum.de>2020-09-04 21:08:25 +0200
commita889768a2ffaa033ae36e6fc26d78203cfd84569 (patch)
tree38da3a3c53296da2b1455dd2ed42523f1945ac5f
parent4456a5db60bea8a878f3fe822aa388c0d20c755a (diff)
fix implementation of escrow STATUS
-rw-r--r--src/escrow/escrow_plugin_helper.c154
-rw-r--r--src/escrow/escrow_plugin_helper.h24
-rw-r--r--src/escrow/gnunet-escrow.c8
-rw-r--r--src/escrow/plugin_escrow_gns.c8
-rw-r--r--src/escrow/plugin_escrow_plaintext.c8
-rw-r--r--src/include/gnunet_escrow_lib.h11
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)
}
+static int
+write_config (struct GNUNET_ESCROW_Handle *h)
+{
+ char *conf_file;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (h->cfg,
+ "PATHS",
+ "DEFAULTCONFIG",
+ &conf_file));
+ if (GNUNET_OK != GNUNET_CONFIGURATION_write (h->cfg, conf_file))
+ {
+ fprintf (stderr, "unable to write config file\n");
+ GNUNET_free (conf_file);
+ return GNUNET_NO;
+ }
+
+ GNUNET_free (conf_file);
+
+ return GNUNET_OK;
+}
+
+
+static char *
+get_config_section (struct GNUNET_IDENTITY_Ego *ego)
+{
+ struct GNUNET_CRYPTO_EcdsaPublicKey *pub;
+ char *config_section, *pubkey_string;
+
+ pub = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
+ GNUNET_IDENTITY_ego_get_public_key (ego, pub);
+ pubkey_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (pub);
+
+ // allocate enough space for "escrow-PUBKEY"
+ config_section = GNUNET_malloc (7 + strlen (pubkey_string) + 1);
+ sprintf (config_section, "escrow-%s", pubkey_string);
+
+ GNUNET_free (pubkey_string);
+
+ return config_section;
+}
+
+
/**
- * Update the status of an escrow in the configuration.
+ * Update the status of an escrow in the configuration after a successful
+ * VERIFY operation.
*
* @param h handle for the escrow component
* @param ego the ego of which the escrow status is updated
@@ -208,81 +252,89 @@ string_to_upper (const char *str)
* @return GNUNET_OK on success
*/
int
-ESCROW_update_escrow_status (struct GNUNET_ESCROW_Handle *h,
- struct GNUNET_IDENTITY_Ego *ego,
- const char *plugin_name)
+ESCROW_update_escrow_status_verify (struct GNUNET_ESCROW_Handle *h,
+ struct GNUNET_IDENTITY_Ego *ego,
+ const char *plugin_name)
{
- struct GNUNET_CRYPTO_EcdsaPublicKey *pub;
- char *config_section, *pubkey_string, *config_option, *plugin_name_upper;
- struct GNUNET_TIME_Absolute now, next_escrow;
+ char *config_section, *config_option, *plugin_name_upper;
+ struct GNUNET_TIME_Absolute now, next_verification;
struct GNUNET_TIME_Relative escrow_interval;
- char *conf_file;
- pub = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
- GNUNET_IDENTITY_ego_get_public_key (ego, pub);
- pubkey_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (pub);
-
- // allocate enough space for "escrow-PUBKEY"
- config_section = GNUNET_malloc (7 + strlen (pubkey_string) + 1);
- sprintf (config_section, "escrow-%s", pubkey_string);
+ config_section = get_config_section (ego);
// allocate enough space for "<plugin_name>_INTERVAL"
config_option = GNUNET_malloc (strlen (plugin_name) + 9 + 1);
plugin_name_upper = string_to_upper (plugin_name);
- sprintf (config_option, "%s_INTERVAL", plugin_name_upper);
+ sprintf (config_option, "%s_VERIFY_INTERVAL", plugin_name_upper);
now = GNUNET_TIME_absolute_get ();
GNUNET_CONFIGURATION_set_value_number (h->cfg,
config_section,
- "LAST_ESCROW_TIME",
+ "LAST_SUCCESSFUL_VERIFICATION_TIME",
(unsigned long long)now.abs_value_us);
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (h->cfg,
"escrow",
config_option,
&escrow_interval))
{
- fprintf (stderr, "could not find config value for escrow interval\n");
- GNUNET_free (pub);
+ fprintf (stderr, "could not find config value for verification interval\n");
GNUNET_free (config_section);
- GNUNET_free (pubkey_string);
GNUNET_free (config_option);
GNUNET_free (plugin_name_upper);
return GNUNET_NO;
}
- next_escrow = GNUNET_TIME_absolute_add (now, escrow_interval);
+ next_verification = GNUNET_TIME_absolute_add (now, escrow_interval);
GNUNET_CONFIGURATION_set_value_number (h->cfg,
config_section,
- "NEXT_RECOMMENDED_ESCROW_TIME",
- (unsigned long long)next_escrow.abs_value_us);
+ "NEXT_RECOMMENDED_VERIFICATION_TIME",
+ (unsigned long long)next_verification.abs_value_us);
+
+ if (GNUNET_OK != write_config (h))
+ {
+ GNUNET_free (config_section);
+ GNUNET_free (config_option);
+ GNUNET_free (plugin_name_upper);
+ return GNUNET_NO;
+ }
+
+ GNUNET_free (config_section);
+ GNUNET_free (config_option);
+ GNUNET_free (plugin_name_upper);
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Update the status of an escrow in the configuration after a PUT operation.
+ *
+ * @param h handle for the escrow component
+ * @param ego the ego of which the escrow status is updated
+ * @param plugin_name the name of the used plugin
+ *
+ * @return GNUNET_OK on success
+ */
+int
+ESCROW_update_escrow_status_put (struct GNUNET_ESCROW_Handle *h,
+ struct GNUNET_IDENTITY_Ego *ego,
+ const char *plugin_name)
+{
+ char *config_section;
+
+ config_section = get_config_section (ego);
GNUNET_CONFIGURATION_set_value_string (h->cfg,
config_section,
"ESCROW_METHOD",
plugin_name);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (h->cfg,
- "PATHS",
- "DEFAULTCONFIG",
- &conf_file));
- if (GNUNET_OK != GNUNET_CONFIGURATION_write (h->cfg, conf_file))
+ if (GNUNET_OK != write_config (h))
{
- fprintf (stderr, "unable to write config file\n");
- GNUNET_free (pub);
GNUNET_free (config_section);
- GNUNET_free (pubkey_string);
- GNUNET_free (config_option);
- GNUNET_free (plugin_name_upper);
- GNUNET_free (conf_file);
return GNUNET_NO;
}
- GNUNET_free (pub);
GNUNET_free (config_section);
- GNUNET_free (pubkey_string);
- GNUNET_free (config_option);
- GNUNET_free (plugin_name_upper);
- GNUNET_free (conf_file);
return GNUNET_OK;
}
@@ -301,7 +353,7 @@ ESCROW_get_escrow_status (struct GNUNET_ESCROW_Handle *h,
struct GNUNET_IDENTITY_Ego *ego)
{
struct GNUNET_ESCROW_Status *status;
- unsigned long long conf_last_escrow, conf_next_escrow;
+ unsigned long long conf_last_verification, conf_next_verification;
struct GNUNET_CRYPTO_EcdsaPublicKey *pub;
char *config_section, *pubkey_string, *conf_escrow_method;
@@ -316,25 +368,25 @@ ESCROW_get_escrow_status (struct GNUNET_ESCROW_Handle *h,
status = GNUNET_new (struct GNUNET_ESCROW_Status);
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg,
config_section,
- "LAST_ESCROW_TIME",
- &conf_last_escrow))
+ "LAST_SUCCESSFUL_VERIFICATION_TIME",
+ &conf_last_verification))
{
- /* failed to get value from config, set last escrow time to zero */
- status->last_escrow_time = GNUNET_TIME_absolute_get_zero_();
+ /* failed to get value from config, set last verification time to zero */
+ status->last_successful_verification_time = GNUNET_TIME_absolute_get_zero_();
}
else
- status->last_escrow_time.abs_value_us = (uint64_t)conf_last_escrow;
+ status->last_successful_verification_time.abs_value_us = (uint64_t)conf_last_verification;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg,
config_section,
- "NEXT_RECOMMENDED_ESCROW_TIME",
- &conf_next_escrow))
+ "NEXT_RECOMMENDED_VERIFICATION_TIME",
+ &conf_next_verification))
{
- /* failed to get value from config, set next recommended escrow to now */
- status->next_recommended_escrow_time = GNUNET_TIME_absolute_get ();
+ /* failed to get value from config, set next recommended verification to now */
+ status->next_recommended_verification_time = GNUNET_TIME_absolute_get ();
}
else
- status->next_recommended_escrow_time.abs_value_us = (uint64_t)conf_next_escrow;
+ status->next_recommended_verification_time.abs_value_us = (uint64_t)conf_next_verification;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
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);
/**
- * Update the status of an escrow in the configuration.
+ * Update the status of an escrow in the configuration after a VERIFY operation.
*
* @param h handle for the escrow component
* @param ego the ego of which the escrow status is updated
@@ -91,9 +91,25 @@ ESCROW_cleanup_ego_list (struct ESCROW_PluginHandle *ph);
* @return GNUNET_OK on success
*/
int
-ESCROW_update_escrow_status (struct GNUNET_ESCROW_Handle *h,
- struct GNUNET_IDENTITY_Ego *ego,
- const char *plugin_name);
+ESCROW_update_escrow_status_verify (struct GNUNET_ESCROW_Handle *h,
+ struct GNUNET_IDENTITY_Ego *ego,
+ const char *plugin_name);
+
+
+/**
+ * Update the status of an escrow in the configuration after a PUT operation.
+ *
+ * @param h handle for the escrow component
+ * @param ego the ego of which the escrow status is updated
+ * @param plugin_name the name of the used plugin
+ *
+ * @return GNUNET_OK on success
+ */
+int
+ESCROW_update_escrow_status_put (struct GNUNET_ESCROW_Handle *h,
+ struct GNUNET_IDENTITY_Ego *ego,
+ const char *plugin_name);
+
/**
* 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 ()
ego,
method);
// TODO: formatting/interpretation
- fprintf (stdout, "Last escrow:\t\t\t%s\n",
- GNUNET_STRINGS_absolute_time_to_string (escrow_status->last_escrow_time));
- fprintf (stdout, "Next recommended escrow:\t%s\n",
- GNUNET_STRINGS_absolute_time_to_string (escrow_status->next_recommended_escrow_time));
+ fprintf (stdout, "Last successful verification:\t%s\n",
+ GNUNET_STRINGS_absolute_time_to_string (escrow_status->last_successful_verification_time));
+ fprintf (stdout, "Next recommended verification:\t%s\n",
+ GNUNET_STRINGS_absolute_time_to_string (escrow_status->next_recommended_verification_time));
fprintf (stdout, "Last method:\t\t\t");
switch (escrow_status->last_method)
{
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)
p_op->anchor_wrap->anchor = anchor;
- /* set the last escrow time */
- ESCROW_update_escrow_status (p_op->h, p_op->ego, "gns");
+ /* update escrow status, i.e. set the last escrow method */
+ ESCROW_update_escrow_status_put (p_op->h, p_op->ego, "gns");
/* call the continuation */
start_cont (plugin_op_wrap);
@@ -1422,6 +1422,10 @@ verify_restored_pk (void *cls,
count_keyshares (p_op->restored_keyshares, p_op->shares) < p_op->shares)
verificationResult = GNUNET_ESCROW_SHARES_MISSING;
+ /* update the escrow status if valid */
+ if (GNUNET_ESCROW_VALID == verificationResult)
+ ESCROW_update_escrow_status_verify (p_op->h, p_op->ego, "gns");
+
p_op->verify_wrap->verificationResult = verificationResult;
verify_cont (plugin_op_wrap);
}
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,
w->anchor = anchor;
- /* set the last escrow time */
- ESCROW_update_escrow_status (h, ego, "plaintext");
+ /* update escrow status, i.e. set the last escrow method */
+ ESCROW_update_escrow_status_put (h, ego, "plaintext");
p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap);
return plugin_op_wrap;
@@ -280,6 +280,10 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
anchor->size) == 0 ?
GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID;
+ /* update the escrow status if valid */
+ if (GNUNET_ESCROW_VALID == verificationResult)
+ ESCROW_update_escrow_status_verify (h, ego, "plaintext");
+
w->verificationResult = verificationResult;
p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap);
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
struct GNUNET_ESCROW_Status
{
/**
- * The time of the last successful escrow.
+ * The time of the last successful verification.
*/
- struct GNUNET_TIME_Absolute last_escrow_time;
+ struct GNUNET_TIME_Absolute last_successful_verification_time;
/**
- * The time of the next recommended escrow.
+ * The time of the next recommended verification.
*/
- struct GNUNET_TIME_Absolute next_recommended_escrow_time;
+ struct GNUNET_TIME_Absolute next_recommended_verification_time;
/**
- * The used escrow method.
+ * The escrow method used for the last escrow of the identity,
+ * GNUNET_ESCROW_KEY_NONE if no escrow has been performed.
*/
enum GNUNET_ESCROW_Key_Escrow_Method last_method;
};