certificate based gateway authentication
prototype PSK user authentication with auth-dialog
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
SUBDIRS = properties po
|
||||
SUBDIRS = properties auth-dialog po
|
||||
|
||||
dbusservicedir = $(sysconfdir)/dbus-1/system.d
|
||||
dbusservice_DATA = nm-strongswan-service.conf
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
libexec_PROGRAMS = nm-strongswan-auth-dialog
|
||||
|
||||
nm_strongswan_auth_dialog_CPPFLAGS = \
|
||||
$(GTHREAD_CFLAGS) \
|
||||
$(GTK_CFLAGS) \
|
||||
$(LIBGNOMEUI_CFLAGS) \
|
||||
$(GNOMEKEYRING_CFLAGS) \
|
||||
$(NETWORK_MANAGER_CFLAGS) \
|
||||
-DICONDIR=\""$(datadir)/pixmaps"\" \
|
||||
-DGLADEDIR=\""$(gladedir)"\" \
|
||||
-DBINDIR=\""$(bindir)"\" \
|
||||
-DDBUS_API_SUBJECT_TO_CHANGE \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DGDK_DISABLE_DEPRECATED \
|
||||
-DGNOME_DISABLE_DEPRECATED \
|
||||
-DGNOMELOCALEDIR=\"$(datadir)/locale\" \
|
||||
-DVERSION=\"$(VERSION)\"
|
||||
|
||||
nm_strongswan_auth_dialog_SOURCES = \
|
||||
main.c
|
||||
|
||||
nm_strongswan_auth_dialog_LDADD = \
|
||||
$(GTK_LIBS) \
|
||||
$(LIBGNOMEUI_LIBS) \
|
||||
$(GNOMEKEYRING_LIBS)
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gnome-keyring.h>
|
||||
#include <libgnomeui/libgnomeui.h>
|
||||
|
||||
#define NM_DBUS_SERVICE_STRONGSWAN "org.freedesktop.NetworkManager.strongswan"
|
||||
|
||||
static char *lookup(char *name, char *service)
|
||||
{
|
||||
GList *list;
|
||||
GList *iter;
|
||||
char *pass = NULL;
|
||||
|
||||
if (gnome_keyring_find_network_password_sync(g_get_user_name(), NULL, name,
|
||||
NULL, service, NULL, 0, &list) != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (iter = list; iter; iter = iter->next)
|
||||
{
|
||||
GnomeKeyringNetworkPasswordData *data = iter->data;
|
||||
|
||||
if (strcmp(data->object, "password") == 0 && data->password)
|
||||
{
|
||||
pass = g_strdup(data->password);
|
||||
break;
|
||||
}
|
||||
}
|
||||
gnome_keyring_network_password_list_free(list);
|
||||
return pass;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
static gboolean retry = FALSE;
|
||||
static gchar *name = NULL, *id = NULL, *service = NULL, *keyring = NULL, *pass;
|
||||
GOptionContext *context;
|
||||
GnomeProgram *program = NULL;
|
||||
int exit_status = 1;
|
||||
guint32 itemid;
|
||||
GtkWidget *dialog;
|
||||
GOptionEntry entries[] = {
|
||||
{ "reprompt", 'r', 0, G_OPTION_ARG_NONE, &retry, "Reprompt for passwords", NULL},
|
||||
{ "id", 'i', 0, G_OPTION_ARG_STRING, &id, "ID of VPN connection", NULL},
|
||||
{ "name", 'n', 0, G_OPTION_ARG_STRING, &name, "Name of VPN connection", NULL},
|
||||
{ "service", 's', 0, G_OPTION_ARG_STRING, &service, "VPN service type", NULL},
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
bindtextdomain(GETTEXT_PACKAGE, NULL);
|
||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
|
||||
context = g_option_context_new ("- strongswan auth dialog");
|
||||
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||
|
||||
program = gnome_program_init ("nm-strongswan-auth-dialog", VERSION,
|
||||
LIBGNOMEUI_MODULE,
|
||||
argc, argv,
|
||||
GNOME_PARAM_GOPTION_CONTEXT, context,
|
||||
GNOME_PARAM_NONE);
|
||||
|
||||
if (id == NULL || name == NULL || service == NULL)
|
||||
{
|
||||
fprintf (stderr, "Have to supply ID, name, and service\n");
|
||||
g_object_unref (program);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(service, NM_DBUS_SERVICE_STRONGSWAN) != 0)
|
||||
{
|
||||
fprintf(stderr, "This dialog only works with the '%s' service\n",
|
||||
NM_DBUS_SERVICE_STRONGSWAN);
|
||||
g_object_unref (program);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pass = lookup(name, service);
|
||||
if (!pass || retry)
|
||||
{
|
||||
dialog = gnome_password_dialog_new(_("VPN password required"),
|
||||
_("Password required to establish VPN connection:"),
|
||||
NULL, NULL, TRUE);
|
||||
gnome_password_dialog_set_show_remember(GNOME_PASSWORD_DIALOG(dialog), TRUE);
|
||||
gnome_password_dialog_set_show_username(GNOME_PASSWORD_DIALOG(dialog), FALSE);
|
||||
if (pass)
|
||||
{
|
||||
gnome_password_dialog_set_password(GNOME_PASSWORD_DIALOG(dialog), pass);
|
||||
}
|
||||
if (!gnome_password_dialog_run_and_block(GNOME_PASSWORD_DIALOG(dialog)))
|
||||
{
|
||||
g_object_unref (program);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pass = gnome_password_dialog_get_password(GNOME_PASSWORD_DIALOG(dialog));
|
||||
switch (gnome_password_dialog_get_remember(GNOME_PASSWORD_DIALOG(dialog)))
|
||||
{
|
||||
case GNOME_PASSWORD_DIALOG_REMEMBER_NOTHING:
|
||||
break;
|
||||
case GNOME_PASSWORD_DIALOG_REMEMBER_SESSION:
|
||||
keyring = "session";
|
||||
/* FALL */
|
||||
case GNOME_PASSWORD_DIALOG_REMEMBER_FOREVER:
|
||||
if (gnome_keyring_set_network_password_sync(keyring,
|
||||
g_get_user_name(), NULL, name, "password", service, NULL, 0,
|
||||
pass, &itemid) != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
g_warning ("storing password in keyring failed");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("password\n%s\n\n\n", pass);
|
||||
g_object_unref(program);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -116,5 +116,6 @@ fi
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
properties/Makefile
|
||||
auth-dialog/Makefile
|
||||
po/Makefile.in
|
||||
])
|
||||
|
||||
@@ -78,21 +78,14 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="certificate-button">
|
||||
<widget class="GtkFileChooserButton" id="certificate-button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="has_tooltip">True</property>
|
||||
<property name="tooltip_text">A trusted certificate to use to authenticate the Gateway.</property>
|
||||
<property name="label" translatable="yes">(none)</property>
|
||||
<property name="response_id">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
@@ -165,7 +158,6 @@
|
||||
<child>
|
||||
<widget class="GtkComboBox" id="method-combo">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="has_tooltip">True</property>
|
||||
<property name="tooltip_text">Authentication Method to use for authentication against the Gateway. </property>
|
||||
<property name="items"></property>
|
||||
|
||||
@@ -159,6 +159,14 @@ init_plugin_ui (StrongswanPluginUiWidget *self, NMConnection *connection, GError
|
||||
gtk_entry_set_text (GTK_ENTRY (widget), value);
|
||||
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "certificate-button");
|
||||
if (!widget)
|
||||
return FALSE;
|
||||
value = g_hash_table_lookup (settings->data, "certificate");
|
||||
if (value)
|
||||
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
|
||||
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (stuff_changed_cb), self);
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "user-entry");
|
||||
if (!widget)
|
||||
return FALSE;
|
||||
@@ -166,6 +174,22 @@ init_plugin_ui (StrongswanPluginUiWidget *self, NMConnection *connection, GError
|
||||
if (value)
|
||||
gtk_entry_set_text (GTK_ENTRY (widget), value);
|
||||
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "method-combo");
|
||||
if (!widget)
|
||||
return FALSE;
|
||||
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "EAP");
|
||||
value = g_hash_table_lookup (settings->data, "method");
|
||||
if (value) {
|
||||
if (g_strcasecmp (value, "EAP") == 0) {
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
||||
}
|
||||
}
|
||||
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
|
||||
if (gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) == -1)
|
||||
{ /* default to EAP */
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
||||
}
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "virtual-check");
|
||||
if (!widget)
|
||||
@@ -235,12 +259,24 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
|
||||
g_hash_table_insert (settings->data, g_strdup ("address"), g_strdup(str));
|
||||
}
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "certificate-button");
|
||||
str = (char *) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
|
||||
if (str) {
|
||||
g_hash_table_insert (settings->data, g_strdup ("certificate"), g_strdup(str));
|
||||
}
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "user-entry");
|
||||
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
|
||||
if (str && strlen (str)) {
|
||||
g_hash_table_insert (settings->data, g_strdup ("user"), g_strdup(str));
|
||||
}
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "method-combo");
|
||||
str = (char *) gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
|
||||
if (str) {
|
||||
g_hash_table_insert (settings->data, g_strdup ("method"), g_strdup(str));
|
||||
}
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "virtual-check");
|
||||
active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
||||
g_hash_table_insert (settings->data, g_strdup ("virtual"),
|
||||
|
||||
Reference in New Issue
Block a user