Maemo: Do not store the password in the config file, ask the user for it on demand.
authorTobias Brunner <tobias@strongswan.org>
Fri, 24 Sep 2010 11:27:44 +0000 (13:27 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 14 Oct 2010 15:36:19 +0000 (17:36 +0200)
src/frontends/maemo/src/strongswan-connection.c
src/frontends/maemo/src/strongswan-settings.c
src/frontends/maemo/src/strongswan-status.c

index 28c8f13..977c0f5 100644 (file)
@@ -29,7 +29,6 @@ struct _StrongswanConnectionPrivate
        gchar *host;
        gchar *cert;
        gchar *user;
-       gchar *pass;
 };
 
 enum
@@ -39,7 +38,6 @@ enum
        PROP_HOST,
        PROP_CERT,
        PROP_USER,
-       PROP_PASS,
 };
 
 #ifndef USE_DYNAMIC_TYPES
@@ -73,9 +71,6 @@ strongswan_connection_get_property (GObject           *object,
                case PROP_USER:
                        g_value_set_string (value, priv->user);
                        break;
-               case PROP_PASS:
-                       g_value_set_string (value, priv->pass);
-                       break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -106,10 +101,6 @@ strongswan_connection_set_property (GObject                        *object,
                        g_free (priv->user);
                        priv->user = g_value_dup_string (value);
                        break;
-               case PROP_PASS:
-                       g_free (priv->pass);
-                       priv->pass = g_value_dup_string (value);
-                       break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -137,7 +128,6 @@ strongswan_connection_finalize (GObject *object)
        g_free (priv->host);
        g_free (priv->cert);
        g_free (priv->user);
-       g_free (priv->pass);
        G_OBJECT_CLASS (strongswan_connection_parent_class)->finalize (object);
 }
 
@@ -175,12 +165,6 @@ strongswan_connection_class_init (StrongswanConnectionClass *klass)
                                                                 NULL,
                                                                 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
-       g_object_class_install_property (object_class, PROP_PASS,
-                       g_param_spec_string ("pass", "Password",
-                                                                "The password for EAP authentication",
-                                                                NULL,
-                                                                G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
        g_type_class_add_private (klass, sizeof (StrongswanConnectionPrivate));
 }
 
@@ -219,7 +203,6 @@ strongswan_connection_update_from_key_file (GKeyFile *key_file,
        priv->host = get_string_from_key_file (key_file, name, "host");
        priv->cert = get_string_from_key_file (key_file, name, "cert");
        priv->user = get_string_from_key_file (key_file, name, "user");
-       priv->pass = get_string_from_key_file (key_file, name, "pass");
 }
 
 StrongswanConnection *
@@ -269,9 +252,5 @@ strongswan_connection_save_to_key_file (GKeyFile *key_file,
        {
                g_key_file_set_string (key_file, name, "user", priv->user);
        }
-       if (priv->pass)
-       {
-               g_key_file_set_string (key_file, name, "pass", priv->pass);
-       }
 }
 
index 5462450..07f58dc 100644 (file)
@@ -120,44 +120,29 @@ edit_connection (gpointer *parent, StrongswanConnection *conn)
                                                                                  HILDON_CAPTION_OPTIONAL);
        gtk_box_pack_start (GTK_BOX (vbox), ucap, TRUE, TRUE, 0);
 
-       GtkWidget *pass = hildon_entry_new (HILDON_SIZE_AUTO);
-       hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (pass), "Password");
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (pass),
-                                                                        HILDON_GTK_INPUT_MODE_FULL |
-                                                                        HILDON_GTK_INPUT_MODE_INVISIBLE);
-       GtkWidget *pcap = hildon_caption_new (group,
-                                                                                 "Password",
-                                                                                 pass,
-                                                                                 NULL,
-                                                                                 HILDON_CAPTION_OPTIONAL);
-       gtk_box_pack_start (GTK_BOX (vbox), pcap, TRUE, TRUE, 0);
-
        if (conn)
        {
-               gchar *c_name, *c_host, *c_cert, *c_user, *c_pass;
+               gchar *c_name, *c_host, *c_cert, *c_user;
                g_object_get (conn,
                                          "name", &c_name,
                                          "host", &c_host,
                                          "cert", &c_cert,
                                          "user", &c_user,
-                                         "pass", &c_pass,
                                          NULL);
                gtk_entry_set_text (GTK_ENTRY (name), c_name);
                gtk_entry_set_text (GTK_ENTRY (host), c_host);
                hildon_button_set_value (HILDON_BUTTON (cert),
                                                                 c_cert ? c_cert : "None");
                gtk_entry_set_text (GTK_ENTRY (user), c_user);
-               gtk_entry_set_text (GTK_ENTRY (pass), c_pass);
                g_free (c_name);
                g_free (c_host);
                g_free (c_cert);
                g_free (c_user);
-               g_free (c_pass);
        }
 
-       gtk_widget_show_all(dialog);
+       gtk_widget_show_all (dialog);
 
-       guint retval = gtk_dialog_run (GTK_DIALOG (dialog));
+       gint retval = gtk_dialog_run (GTK_DIALOG (dialog));
        if (retval == GTK_RESPONSE_OK)
        {
                const gchar *c_name, *c_cert;
@@ -173,7 +158,6 @@ edit_connection (gpointer *parent, StrongswanConnection *conn)
                                          "host", gtk_entry_get_text (GTK_ENTRY (host)),
                                          "cert", c_cert,
                                          "user", gtk_entry_get_text (GTK_ENTRY (user)),
-                                         "pass", gtk_entry_get_text (GTK_ENTRY (pass)),
                                          NULL);
                strongswan_connections_save_connection (ListDialog.conns, conn);
        }
index 21ca651..9a4ce78 100644 (file)
@@ -107,6 +107,24 @@ update_status_menu (StrongswanStatus *plugin)
 }
 
 static void
+update_dialog_connecting (StrongswanStatus *plugin)
+{
+       StrongswanStatusPrivate *priv = plugin->priv;
+
+       gtk_widget_set_sensitive (priv->box, FALSE);
+       hildon_gtk_window_set_progress_indicator (GTK_WINDOW (priv->dialog), 1);
+}
+
+static void
+update_dialog_default (StrongswanStatus *plugin)
+{
+       StrongswanStatusPrivate *priv = plugin->priv;
+
+       gtk_widget_set_sensitive (priv->box, TRUE);
+       hildon_gtk_window_set_progress_indicator (GTK_WINDOW (priv->dialog), 0);
+}
+
+static void
 dialog_response (GtkDialog *dialog, gint response_id, StrongswanStatus *plugin)
 {
        StrongswanStatusPrivate *priv = plugin->priv;
@@ -155,20 +173,50 @@ connect_callback (const gchar* interface, const gchar* method,
 
        if (priv->dialog)
        {
-               gtk_widget_set_sensitive (priv->box, TRUE);
-               hildon_gtk_window_set_progress_indicator (GTK_WINDOW (priv->dialog), 0);
-
+               update_dialog_default (plugin);
                gtk_dialog_response (GTK_DIALOG (priv->dialog), GTK_RESPONSE_OK);
        }
 }
 
-static void
-update_dialog_connecting (StrongswanStatus *plugin)
+static gboolean
+get_password (StrongswanStatus *plugin, gchar **password)
 {
        StrongswanStatusPrivate *priv = plugin->priv;
-
-       gtk_widget_set_sensitive (priv->box, FALSE);
-       hildon_gtk_window_set_progress_indicator (GTK_WINDOW (priv->dialog), 1);
+       gboolean result = FALSE;
+
+       GtkWidget *dialog = gtk_dialog_new_with_buttons (
+                                                                       "Connecting...",
+                                                                       GTK_WINDOW(priv->dialog),
+                                                                       GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
+                                                                       GTK_STOCK_CANCEL,
+                                                                       GTK_RESPONSE_CANCEL,
+                                                                       GTK_STOCK_OK,
+                                                                       GTK_RESPONSE_OK,
+                                                                       NULL);
+       GtkWidget *vbox = GTK_DIALOG (dialog)->vbox;
+       GtkSizeGroup *group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+       GtkWidget *pass = hildon_entry_new (HILDON_SIZE_AUTO);
+       hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (pass), "Password");
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (pass),
+                                                                        HILDON_GTK_INPUT_MODE_FULL |
+                                                                        HILDON_GTK_INPUT_MODE_INVISIBLE);
+       GtkWidget *pcap = hildon_caption_new (group,
+                                                                                 "Password",
+                                                                                 pass,
+                                                                                 NULL,
+                                                                                 HILDON_CAPTION_OPTIONAL);
+       gtk_box_pack_start (GTK_BOX (vbox), pcap, TRUE, TRUE, 0);
+       gtk_widget_show_all (dialog);
+
+       gint retval = gtk_dialog_run (GTK_DIALOG (dialog));
+       if (retval == GTK_RESPONSE_OK)
+       {
+               *password = g_strdup (gtk_entry_get_text (GTK_ENTRY (pass)));
+               result = TRUE;
+       }
+       gtk_widget_destroy (dialog);
+       return result;
 }
 
 static void
@@ -216,11 +264,17 @@ connect_clicked (HildonButton *button, StrongswanStatus *plugin)
        }
 
        gchar *c_host, *c_cert, *c_user, *c_pass;
+
+       if (!get_password (plugin, &c_pass))
+       {
+               update_dialog_default (plugin);
+               return;
+       }
+
        g_object_get (conn,
                                  "host", &c_host,
                                  "cert", &c_cert,
                                  "user", &c_user,
-                                 "pass", &c_pass,
                                  NULL);
 
        osso_rpc_async_run (priv->context,