anastasis-gtk_handle-method-iban.c (5020B)
1 /* 2 This file is part of anastasis-gtk. 3 Copyright (C) 2021 Anastasis SARL 4 5 Anastasis is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 Anastasis is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with Anastasis; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 21 /** 22 * @file src/anastasis/anastasis-gtk_handle-method-iban.c 23 * @brief Handle dialogs for security iban 24 * @author Christian Grothoff 25 */ 26 #include <gnunet/gnunet_util_lib.h> 27 #include "anastasis_gtk_util.h" 28 #include "anastasis-gtk_action.h" 29 #include "anastasis-gtk_helper.h" 30 #include "anastasis-gtk_handle-identity-changed.h" 31 #include <jansson.h> 32 33 34 /** 35 * Return obfuscated variant of an IBAN. 36 * 37 * @param iban input address 38 * @return obfuscated version, NULL on errors 39 */ 40 static char * 41 mask_iban (const char *iban) 42 { 43 size_t slen = strlen (iban); 44 char *result; 45 46 GNUNET_assert (slen > 5); 47 GNUNET_asprintf (&result, 48 "%.*s...%s", 49 (int) 5, 50 iban, 51 &iban[slen - 5]); 52 return result; 53 } 54 55 56 /** 57 * Function called from the security-iban dialog upon completion. 58 * 59 * @param dialog the pseudonym selection dialog 60 * @param response_id response code from the dialog 61 * @param user_data the builder of the dialog 62 */ 63 void 64 anastasis_gtk_b_iban_dialog_response_cb (GtkDialog *dialog, 65 gint response_id, 66 gpointer user_data) 67 { 68 GtkBuilder *builder = GTK_BUILDER (user_data); 69 GtkEntry *q; 70 const char *qs; 71 json_t *args; 72 char *ins; 73 char *pe; 74 75 if (GTK_RESPONSE_OK != response_id) 76 { 77 gtk_widget_destroy (GTK_WIDGET (dialog)); 78 g_object_unref (G_OBJECT (builder)); 79 return; 80 } 81 q = GTK_ENTRY (gtk_builder_get_object (builder, 82 "anastasis_gtk_b_iban_dialog_iban_entry")); 83 qs = gtk_entry_get_text (q); 84 pe = mask_iban (qs); 85 GNUNET_asprintf (&ins, 86 _ ("IBAN %s"), 87 pe); 88 GNUNET_free (pe); 89 args = json_pack ("{ s:{s:s, s:o, s:s}}", 90 "authentication_method", 91 "type", 92 "iban", 93 "challenge", 94 GNUNET_JSON_from_data (qs, 95 strlen (qs)), 96 "instructions", 97 ins); 98 GNUNET_free (ins); 99 gtk_widget_destroy (GTK_WIDGET (dialog)); 100 g_object_unref (G_OBJECT (builder)); 101 AG_freeze (); 102 AG_ra = ANASTASIS_redux_action (AG_redux_state, 103 "add_authentication", 104 args, 105 &AG_action_cb, 106 NULL); 107 json_decref (args); 108 } 109 110 111 void 112 anastasis_gtk_b_iban_dialog_iban_entry_changed_cb (GtkEntry *entry, 113 gpointer user_data) 114 { 115 GtkBuilder *builder = GTK_BUILDER (user_data); 116 GtkEntry *q; 117 const char *qs; 118 char *err; 119 120 q = GTK_ENTRY (gtk_builder_get_object (builder, 121 "anastasis_gtk_b_iban_dialog_iban_entry")); 122 qs = gtk_entry_get_text (q); 123 err = TALER_iban_validate (qs); 124 gtk_widget_set_sensitive ( 125 GTK_WIDGET (gtk_builder_get_object (builder, 126 "anastasis_gtk_b_iban_dialog_btn_ok")), 127 NULL == err); 128 if (NULL != err) 129 { 130 /* FIXME: show _inside_ the dialog instead of in logs... */ 131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 132 "IBAN `%s' invalid: %s\n", 133 qs, 134 err); 135 } 136 GNUNET_free (err); 137 } 138 139 140 /** 141 * Callback invoked if the the "secure iban"-button is clicked. 142 * 143 * @param object 144 * @param user_data unused 145 */ 146 void 147 anastasis_gtk_btn_add_auth_iban_clicked_cb (GObject *object, 148 gpointer user_data) 149 { 150 GtkWidget *ad; 151 GtkBuilder *builder; 152 153 builder = ANASTASIS_GTK_get_new_builder ( 154 ANASTASIS_GTK_project_data (), 155 "anastasis_gtk_auth_add_iban.glade", 156 NULL); 157 if (NULL == builder) 158 { 159 GNUNET_break (0); 160 return; 161 } 162 ad = GTK_WIDGET (gtk_builder_get_object (builder, 163 "anastasis_gtk_b_iban_dialog")); 164 { 165 GtkWidget *toplevel; 166 167 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (object)); 168 gtk_window_set_transient_for (GTK_WINDOW (ad), 169 GTK_WINDOW (toplevel)); 170 gtk_window_present (GTK_WINDOW (ad)); 171 } 172 }