From 3b5809bcf0c071eaaaeaee2a15e2b87c32202235 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 26 Sep 2021 15:52:46 +0200 Subject: add dialog to answer TOTP challenges --- src/anastasis/anastasis-gtk_action.c | 73 +++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) (limited to 'src/anastasis/anastasis-gtk_action.c') diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c index 5d4b461..87e06bc 100644 --- a/src/anastasis/anastasis-gtk_action.c +++ b/src/anastasis/anastasis-gtk_action.c @@ -2533,6 +2533,15 @@ action_challenge_paying (void) * Render challenge feedback for challenge @a uuid_str in a dialog of * @a builder in the label under @a target_widget. * + * Useful in case the operation previously failed at the + * server and we have some useful information to return + * to the user. + * + * FIXME: only do it AFTER the first attempt of the + * user to enter a code, and/or change what the + * server returns so we do NOT render a confusing + * error message on first use! + * * @param builder a builder to get widgets from * @param target_widget the widget to upate * @param uuid_str the UUID to render feedback for @@ -2735,7 +2744,6 @@ diag_question (const json_t *details) uuid_str = json_string_value (json_object_get (details, "uuid")); - /* Why do we do this? */ render_feedback (builder, "anastasis_gtk_c_question_error_label", uuid_str); @@ -2794,7 +2802,6 @@ diag_code (const json_t *details) "anastasis_gtk_c_challenge_label")); gtk_label_set_text (label, uuid_str); - /* Why do we do this? */ render_feedback (builder, "anastasis_gtk_c_code_error_label", uuid_str); @@ -2809,6 +2816,66 @@ diag_code (const json_t *details) } +/** + * Create a dialog for the user to enter an TOTP code. + * + * @param details details about the dialog to render + * @return dialog object + */ +static GtkDialog * +diag_totp (const json_t *details) +{ + GtkBuilder *builder; + const char *instructions; + const char *uuid_str; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_string ("instructions", + &instructions), + GNUNET_JSON_spec_string ("uuid", + &uuid_str), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (details, + spec, + NULL, NULL)) + { + GNUNET_break (0); + json_dumpf (details, + stderr, + JSON_INDENT (2)); + return NULL; + } + + builder = GNUNET_GTK_get_new_builder ("anastasis_gtk_challenge_totp.glade", + NULL); + if (NULL == builder) + { + GNUNET_break (0); + return NULL; + } + { + GtkLabel *label; + + label = GTK_LABEL (gtk_builder_get_object (builder, + "challenge_instructions_label")); + gtk_label_set_text (label, + instructions); + } + render_feedback (builder, + "anastasis_gtk_c_totp_error_label", + uuid_str); + { + GtkDialog *ad; + + ad = GTK_DIALOG (gtk_builder_get_object (builder, + "anastasis_gtk_c_totp_dialog")); + return ad; + } +} + + /** * Create a dialog for the user to make an IBAN transfer. * @@ -2941,6 +3008,8 @@ action_challenge_solving (void) .ctor = &diag_code }, { .type = gettext_noop ("iban"), .ctor = &diag_iban }, + { .type = gettext_noop ("totp"), + .ctor = &diag_totp }, { .type = NULL, .ctor = NULL } }; -- cgit v1.2.3