[network-manager-applet/lr/pkcs11: 14/15] libnma: add the PKCS#11 capable certificate chooser
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/lr/pkcs11: 14/15] libnma: add the PKCS#11 capable certificate chooser
- Date: Fri, 3 Mar 2017 15:40:45 +0000 (UTC)
commit a809c3030eef44ba10ade69b5d93bae59b6686f0
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Mon Feb 27 08:57:29 2017 +0100
libnma: add the PKCS#11 capable certificate chooser
Default to it unless Gcr support is unavailable or an application
indicateas it only supports certificates in plain files.
This one is libnma only. The libnm-gtk can still utilize the
NMAFileCertChooser. Since libnm-glib doesn't support PKCS#11 tokens it
wouldn't make too much sense anyway.
Makefile.am | 13 +-
po/POTFILES.in | 1 +
src/libnma/nma-cert-chooser.c | 5 +
src/libnma/nma-pkcs11-cert-chooser.c | 578 ++++++++++++++++++++++++++++++++++
src/libnma/nma-pkcs11-cert-chooser.h | 50 +++
5 files changed, 643 insertions(+), 4 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 5cbaf21..22692ae 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -497,12 +497,14 @@ if WITH_GCR
libnma_h_priv_real += \
src/libnma/nma-pkcs11-token-login-dialog.h \
src/libnma/nma-pkcs11-cert-chooser-dialog.h \
- src/libnma/nma-cert-chooser-button.h
+ src/libnma/nma-cert-chooser-button.h \
+ src/libnma/nma-pkcs11-cert-chooser.h
libnma_c_real += \
src/libnma/nma-pkcs11-token-login-dialog.c \
src/libnma/nma-pkcs11-cert-chooser-dialog.c \
- src/libnma/nma-cert-chooser-button.c
+ src/libnma/nma-cert-chooser-button.c \
+ src/libnma/nma-pkcs11-cert-chooser.c
endif
src_libnma_libnmadir = $(includedir)/libnma
@@ -573,6 +575,7 @@ EXTRA_DIST += \
src/libnma/libnma.ver \
src/libnma/wifi.ui \
src/libnma/nma-pkcs11-token-login-dialog.ui \
+ src/libnma/nma-pkcs11-cert-chooser-dialog.ui \
src/libnma/nma.gresource.xml
###############################################################################
@@ -873,14 +876,16 @@ IGNORE_HFILES = \
nma-file-cert-chooser.h \
nma-pkcs11-token-login-dialog.h \
nma-pkcs11-cert-chooser-dialog.h \
- nma-cert-chooser-button.h
+ nma-cert-chooser-button.h \
+ nma-pkcs11-cert-chooser.h
mkdb_ignore_c_files = \
nma-resources.c \
nma-file-cert-chooser.c \
nma-pkcs11-token-login-dialog.c \
nma-pkcs11-cert-chooser-dialog.c \
- nma-cert-chooser-button.c
+ nma-cert-chooser-button.c \
+ nma-pkcs11-cert-chooser.c
MKDB_OPTIONS = --ignore-files "$(IGNORE_HFILES) $(mkdb_ignore_c_files)"
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 90109b2..1ac9a33 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -79,6 +79,7 @@ src/libnma/nma-file-cert-chooser.c
src/libnma/nma-mobile-providers.c
src/libnma/nma-mobile-wizard.c
src/libnma/nma-cert-chooser-button.c
+src/libnma/nma-pkcs11-cert-chooser.c
src/libnma/nma-pkcs11-cert-chooser-dialog.c
[type: gettext/glade]src/libnma/nma-pkcs11-cert-chooser-dialog.ui
src/libnma/nma-pkcs11-token-login-dialog.c
diff --git a/src/libnma/nma-cert-chooser.c b/src/libnma/nma-cert-chooser.c
index 625abe1..48a67b3 100644
--- a/src/libnma/nma-cert-chooser.c
+++ b/src/libnma/nma-cert-chooser.c
@@ -23,6 +23,7 @@
#include "nm-default.h"
#include "nma-cert-chooser.h"
#include "nma-file-cert-chooser.h"
+#include "nma-pkcs11-cert-chooser.h"
#include <glib/gstdio.h>
#include <sys/stat.h>
@@ -587,8 +588,12 @@ nma_cert_chooser_get_key_password_flags (NMACertChooser *cert_chooser)
GtkWidget *
nma_cert_chooser_new (const gchar *title, NMACertChooserFlags flags)
{
+#if LIBNM_BUILD && WITH_GCR
if (flags & NMA_CERT_CHOOSER_FLAG_PEM)
return nma_file_cert_chooser_new (title, flags);
+ return nma_pkcs11_cert_chooser_new (title, flags);
+#else
return nma_file_cert_chooser_new (title, flags);
+#endif
}
diff --git a/src/libnma/nma-pkcs11-cert-chooser.c b/src/libnma/nma-pkcs11-cert-chooser.c
new file mode 100644
index 0000000..2c77fa0
--- /dev/null
+++ b/src/libnma/nma-pkcs11-cert-chooser.c
@@ -0,0 +1,578 @@
+/* NetworkManager Applet -- allow user control over networking
+ *
+ * Lubomir Rintel <lkundrak v3 sk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2017 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+#include "nma-pkcs11-cert-chooser.h"
+#include "nma-cert-chooser-button.h"
+#include "nma-ui-utils.h"
+#include "utils.h"
+
+#include <glib/gstdio.h>
+#include <gck/gck.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static void nma_cert_chooser_interface_init (NMACertChooserInterface *iface);
+
+typedef struct {
+ GtkWidget *key_button_label;
+ GtkWidget *key_password_label;
+ GtkWidget *cert_button_label;
+ GtkWidget *cert_password_label;
+ GtkWidget *key_button;
+ GtkWidget *key_password;
+ GtkWidget *cert_button;
+ GtkWidget *cert_password;
+} NMAPkcs11CertChooserPrivate;
+
+#define NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),
NMA_TYPE_PKCS11_CERT_CHOOSER, NMAPkcs11CertChooserPrivate))
+
+G_DEFINE_TYPE_WITH_CODE (NMAPkcs11CertChooser, nma_pkcs11_cert_chooser, GTK_TYPE_GRID,
+ G_IMPLEMENT_INTERFACE (NMA_TYPE_CERT_CHOOSER,
+ nma_cert_chooser_interface_init))
+
+static void
+set_key_password (NMACertChooser *cert_chooser, const gchar *password)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ g_return_if_fail (priv->key_password != NULL);
+ if (password)
+ gtk_entry_set_text (GTK_ENTRY (priv->key_password), password);
+}
+
+static const gchar *
+get_key_password (NMACertChooser *cert_chooser)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ g_return_val_if_fail (priv->key_password != NULL, NULL);
+ return gtk_entry_get_text (GTK_ENTRY (priv->key_password));
+}
+
+static void
+set_key (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme scheme)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+ gs_free gchar *uri = NULL;
+
+ if (!value)
+ return;
+
+ switch (scheme) {
+ case NM_SETTING_802_1X_CK_SCHEME_PATH:
+ uri = g_strdup_printf (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH "%s", value);
+ break;
+ case NM_SETTING_802_1X_CK_SCHEME_PKCS11:
+ uri = g_strdup (value);
+ break;
+ default:
+ g_warning ("The key '%s' uses an unknown scheme %d\n", value, scheme);
+ return;
+ }
+
+ gtk_widget_set_sensitive (priv->key_button, TRUE);
+ gtk_widget_set_sensitive (priv->key_button_label, TRUE);
+ gtk_widget_set_sensitive (priv->key_password, TRUE);
+ gtk_widget_set_sensitive (priv->key_password_label, TRUE);
+ nma_cert_chooser_button_set_uri (NMA_CERT_CHOOSER_BUTTON (priv->key_button), uri);
+}
+
+static gchar *
+get_key (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+ const gchar *uri = NULL;
+
+ uri = nma_cert_chooser_button_get_uri (NMA_CERT_CHOOSER_BUTTON (priv->key_button));
+ if (!uri) {
+ *scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN;
+ return NULL;
+ } else if (g_str_has_prefix (uri, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH)) {
+ *scheme = NM_SETTING_802_1X_CK_SCHEME_PATH;
+ return g_strdup (uri + sizeof (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH) - 1);
+ } else if (g_str_has_prefix (uri, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11)) {
+ *scheme = NM_SETTING_802_1X_CK_SCHEME_PKCS11;
+ return g_strdup (uri);
+ } else {
+ g_warning ("The dialog returned URI of unknown scheme: '%s'\n", uri);
+ return NULL;
+ }
+}
+
+static void
+set_cert_password (NMACertChooser *cert_chooser, const gchar *password)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ g_return_if_fail (priv->cert_password != NULL);
+ if (password)
+ gtk_entry_set_text (GTK_ENTRY (priv->cert_password), password);
+}
+
+static const gchar *
+get_cert_password (NMACertChooser *cert_chooser)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ g_return_val_if_fail (priv->cert_password != NULL, NULL);
+ return gtk_entry_get_text (GTK_ENTRY (priv->cert_password));
+}
+
+static void
+set_cert (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme scheme)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+ gs_free gchar *uri = NULL;
+
+ if (!value)
+ return;
+
+ switch (scheme) {
+ case NM_SETTING_802_1X_CK_SCHEME_PATH:
+ uri = g_strdup_printf (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH "%s", value);
+ gtk_widget_set_sensitive (priv->cert_password, FALSE);
+ gtk_widget_set_sensitive (priv->cert_password_label, FALSE);
+ break;
+ case NM_SETTING_802_1X_CK_SCHEME_PKCS11:
+ uri = g_strdup (value);
+ gtk_widget_set_sensitive (priv->cert_password, TRUE);
+ gtk_widget_set_sensitive (priv->cert_password_label, TRUE);
+ break;
+ default:
+ g_warning ("The certificate '%s' uses an unknown scheme %d\n", value, scheme);
+ return;
+ }
+
+ nma_cert_chooser_button_set_uri (NMA_CERT_CHOOSER_BUTTON (priv->cert_button), uri);
+}
+
+static gchar *
+get_cert (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+ const gchar *uri = NULL;
+
+ uri = nma_cert_chooser_button_get_uri (NMA_CERT_CHOOSER_BUTTON (priv->cert_button));
+ if (!uri) {
+ *scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN;
+ return NULL;
+ } else if (g_str_has_prefix (uri, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH)) {
+ *scheme = NM_SETTING_802_1X_CK_SCHEME_PATH;
+ return g_strdup (uri + sizeof (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH) -1);
+ } else if (g_str_has_prefix (uri, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11)) {
+ *scheme = NM_SETTING_802_1X_CK_SCHEME_PKCS11;
+ return g_strdup (uri);
+ } else {
+ g_warning ("The dialog returned URI of unknown scheme: '%s'\n", uri);
+ return NULL;
+ }
+}
+
+static void
+add_to_size_group (NMACertChooser *cert_chooser, GtkSizeGroup *group)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ gtk_size_group_add_widget (group, priv->cert_button_label);
+ gtk_size_group_add_widget (group, priv->cert_password_label);
+ if (priv->key_button_label)
+ gtk_size_group_add_widget (group, priv->key_button_label);
+ if (priv->key_password_label)
+ gtk_size_group_add_widget (group, priv->key_password_label);
+}
+
+static gboolean
+validate (NMACertChooser *cert_chooser, GError **error)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+ GError *local = NULL;
+
+ g_signal_emit_by_name (cert_chooser, "cert-validate", &local);
+ if (local) {
+ widget_set_error (priv->cert_button);
+ g_propagate_error (error, local);
+ return FALSE;
+ } else {
+ widget_unset_error (priv->cert_button);
+ }
+
+ g_signal_emit_by_name (cert_chooser, "cert-password-validate", &local);
+ if (local) {
+ widget_set_error (priv->cert_password);
+ g_propagate_error (error, local);
+ return FALSE;
+ } else {
+ widget_unset_error (priv->cert_password);
+ }
+
+ if (priv->key_button) {
+ g_signal_emit_by_name (cert_chooser, "key-validate", &local);
+ if (local) {
+ widget_set_error (priv->key_button);
+ g_propagate_error (error, local);
+ return FALSE;
+ } else {
+ widget_unset_error (priv->key_button);
+ }
+
+ g_signal_emit_by_name (cert_chooser, "key-password-validate", &local);
+ if (local) {
+ widget_set_error (priv->key_password);
+ g_propagate_error (error, local);
+ return FALSE;
+ } else {
+ widget_unset_error (priv->key_password);
+ }
+ }
+
+ return TRUE;
+}
+
+static void
+setup_key_password_storage (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags initial_flags,
+ NMSetting *setting,
+ const char *password_flags_name,
+ gboolean with_not_required,
+ gboolean ask_mode)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ nma_utils_setup_password_storage (priv->key_password,
+ initial_flags,
+ setting,
+ password_flags_name,
+ with_not_required,
+ ask_mode);
+}
+
+static void
+update_key_password_storage (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags secret_flags,
+ NMSetting *setting,
+ const char *password_flags_name)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ nma_utils_update_password_storage (priv->key_password,
+ secret_flags,
+ setting,
+ password_flags_name);
+}
+
+static NMSettingSecretFlags
+get_key_password_flags (NMACertChooser *cert_chooser)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ return nma_utils_menu_to_secret_flags (priv->key_password);
+}
+
+static void
+setup_cert_password_storage (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags initial_flags,
+ NMSetting *setting,
+ const char *password_flags_name,
+ gboolean with_not_required,
+ gboolean ask_mode)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ nma_utils_setup_password_storage (priv->cert_password,
+ initial_flags,
+ setting,
+ password_flags_name,
+ with_not_required,
+ ask_mode);
+}
+
+static void
+update_cert_password_storage (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags secret_flags,
+ NMSetting *setting,
+ const char *password_flags_name)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ nma_utils_update_password_storage (priv->cert_password,
+ secret_flags,
+ setting,
+ password_flags_name);
+}
+
+static NMSettingSecretFlags
+get_cert_password_flags (NMACertChooser *cert_chooser)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ return nma_utils_menu_to_secret_flags (priv->cert_password);
+}
+
+static void
+nma_cert_chooser_interface_init (NMACertChooserInterface *iface)
+{
+ iface->set_cert = set_cert;
+ iface->get_cert = get_cert;
+ iface->set_cert_password = set_cert_password;
+ iface->get_cert_password = get_cert_password;
+ iface->set_key = set_key;
+ iface->get_key = get_key;
+ iface->set_key_password = set_key_password;
+ iface->get_key_password = get_key_password;
+
+ iface->add_to_size_group = add_to_size_group;
+ iface->validate = validate;
+
+ iface->setup_key_password_storage = setup_key_password_storage;
+ iface->update_key_password_storage = update_key_password_storage;
+ iface->get_key_password_flags = get_key_password_flags;
+ iface->setup_cert_password_storage = setup_cert_password_storage;
+ iface->update_cert_password_storage = update_cert_password_storage;
+ iface->get_cert_password_flags = get_cert_password_flags;
+}
+
+static void
+cert_changed_cb (NMACertChooserButton *button, gpointer user_data)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (user_data);
+ GckUriData *uri_data;
+ gchar *pin = NULL;
+ const gchar *uri;
+
+ uri = nma_cert_chooser_button_get_uri (button);
+ if (!uri)
+ return;
+ uri_data = gck_uri_parse (uri, GCK_URI_FOR_OBJECT, NULL);
+
+ if (nma_cert_chooser_button_get_remember_pin (button))
+ pin = nma_cert_chooser_button_get_pin (button);
+ if (pin)
+ gtk_entry_set_text (GTK_ENTRY (priv->cert_password), pin);
+
+ gtk_widget_set_sensitive (priv->cert_password, uri_data != NULL);
+ gtk_widget_set_sensitive (priv->cert_password_label, uri_data != NULL);
+
+ if (priv->key_button && !gtk_widget_get_sensitive (priv->key_button)) {
+ gtk_widget_set_sensitive (priv->key_button, TRUE);
+ gtk_widget_set_sensitive (priv->key_button_label, TRUE);
+
+ if (uri_data) {
+ /* URI that is good both for a certificate and for a key. */
+ if (!gck_attributes_find (uri_data->attributes, CKA_CLASS)) {
+ nma_cert_chooser_button_set_uri (NMA_CERT_CHOOSER_BUTTON (priv->key_button),
uri);
+ gtk_widget_set_sensitive (priv->key_password, TRUE);
+ gtk_widget_set_sensitive (priv->key_password_label, TRUE);
+ if (pin)
+ gtk_entry_set_text (GTK_ENTRY (priv->key_password), pin);
+ }
+ }
+ }
+
+ if (uri_data)
+ gck_uri_data_free (uri_data);
+ if (pin)
+ g_free (pin);
+
+ g_signal_emit_by_name (user_data, "changed");
+}
+
+static void
+key_changed_cb (NMACertChooserButton *button, gpointer user_data)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (user_data);
+ gchar *pin = NULL;
+
+ if (nma_cert_chooser_button_get_remember_pin (button))
+ pin = nma_cert_chooser_button_get_pin (button);
+ if (pin) {
+ gtk_entry_set_text (GTK_ENTRY (priv->key_password), pin);
+ g_free (pin);
+ }
+
+ gtk_widget_set_sensitive (priv->key_password, TRUE);
+ gtk_widget_set_sensitive (priv->key_password_label, TRUE);
+ g_signal_emit_by_name (user_data, "changed");
+}
+
+static void
+key_password_changed_cb (GtkEntry *entry, gpointer user_data)
+{
+ g_signal_emit_by_name (user_data, "changed");
+}
+
+static void
+cert_password_changed_cb (GtkEntry *entry, gpointer user_data)
+{
+ g_signal_emit_by_name (user_data, "changed");
+}
+
+
+static void
+show_toggled_cb (GtkCheckButton *button, gpointer user_data)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (user_data);
+ gboolean active;
+
+ active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ gtk_entry_set_visibility (GTK_ENTRY (priv->cert_password), active);
+ if (priv->key_password)
+ gtk_entry_set_visibility (GTK_ENTRY (priv->key_password), active);
+}
+
+GtkWidget *
+nma_pkcs11_cert_chooser_new (const gchar *title, NMACertChooserFlags flags)
+{
+ GtkWidget *self;
+ NMAPkcs11CertChooserPrivate *priv;
+ gchar *text;
+ GtkWidget *show_password;
+
+ self = g_object_new (NMA_TYPE_PKCS11_CERT_CHOOSER, NULL);
+ priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (self);
+
+ gtk_grid_insert_column (GTK_GRID (self), 2);
+ gtk_grid_set_row_spacing (GTK_GRID (self), 6);
+ gtk_grid_set_column_spacing (GTK_GRID (self), 12);
+
+ /* Show password */
+ gtk_grid_insert_row (GTK_GRID (self), 0);
+ show_password = gtk_check_button_new_with_mnemonic ("Sho_w passwords");
+ gtk_grid_attach (GTK_GRID (self), show_password, 1, 2, 1, 1);
+ gtk_widget_show (show_password);
+ g_signal_connect (show_password, "toggled",
+ G_CALLBACK (show_toggled_cb), self);
+
+ if ((flags & NMA_CERT_CHOOSER_FLAG_CERT) == 0) {
+ /* The key chooser */
+ gtk_grid_insert_row (GTK_GRID (self), 0);
+
+ text = g_strdup_printf (_("Choose a key for %s certificate"), title);
+ priv->key_button = nma_cert_chooser_button_new (text,
+ NMA_CERT_CHOOSER_BUTTON_FLAG_KEY);
+ g_free (text);
+
+ gtk_grid_attach (GTK_GRID (self), priv->key_button, 1, 0, 1, 1);
+ gtk_widget_set_hexpand (priv->key_button, TRUE);
+ gtk_widget_set_sensitive (priv->key_button, FALSE);
+ if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
+ gtk_widget_show (priv->key_button);
+
+ g_signal_connect (priv->key_button, "changed",
+ G_CALLBACK (key_changed_cb), self);
+
+ text = g_strdup_printf (_("%s private _key:"), title);
+ priv->key_button_label = gtk_label_new_with_mnemonic (text);
+ g_object_set (priv->key_button_label, "xalign", (gfloat) 0, NULL);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (priv->key_button_label), priv->key_button);
+ gtk_grid_attach (GTK_GRID (self), priv->key_button_label, 0, 0, 1, 1);
+ gtk_widget_set_sensitive (priv->key_button_label, FALSE);
+ if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
+ gtk_widget_show (priv->key_button_label);
+ g_free (text);
+
+ /* The key password entry */
+ gtk_grid_insert_row (GTK_GRID (self), 1);
+
+ priv->key_password = gtk_entry_new ();
+ gtk_entry_set_visibility (GTK_ENTRY (priv->key_password), FALSE);
+ gtk_grid_attach (GTK_GRID (self), priv->key_password, 1, 1, 1, 1);
+ gtk_widget_set_hexpand (priv->key_password, TRUE);
+ gtk_widget_set_sensitive (priv->key_password, FALSE);
+ gtk_widget_show (priv->key_password);
+
+ g_signal_connect (priv->key_password, "changed",
+ G_CALLBACK (key_password_changed_cb), self);
+
+ text = g_strdup_printf (_("%s key _password:"), title);
+ priv->key_password_label = gtk_label_new_with_mnemonic (text);
+ g_object_set (priv->key_password_label, "xalign", (gfloat) 0, NULL);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (priv->key_password_label), priv->key_password);
+ gtk_grid_attach (GTK_GRID (self), priv->key_password_label, 0, 1, 1, 1);
+ gtk_widget_set_sensitive (priv->key_password_label, FALSE);
+ gtk_widget_show (priv->key_password_label);
+ g_free (text);
+ }
+
+ /* The certificate chooser */
+ gtk_grid_insert_row (GTK_GRID (self), 0);
+
+ text = g_strdup_printf (_("Choose %s certificate"), title);
+ priv->cert_button = nma_cert_chooser_button_new (text,
+ NMA_CERT_CHOOSER_BUTTON_FLAG_NONE);
+ g_free (text);
+
+ gtk_grid_attach (GTK_GRID (self), priv->cert_button, 1, 0, 1, 1);
+ gtk_widget_set_hexpand (priv->cert_button, TRUE);
+ if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
+ gtk_widget_show (priv->cert_button);
+
+ g_signal_connect (priv->cert_button, "changed",
+ G_CALLBACK (cert_changed_cb), self);
+
+ text = g_strdup_printf (_("%s _certificate:"), title);
+ priv->cert_button_label = gtk_label_new_with_mnemonic (text);
+ g_object_set (priv->cert_button_label, "xalign", (gfloat) 0, NULL);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (priv->cert_button_label), priv->cert_button);
+ gtk_grid_attach (GTK_GRID (self), priv->cert_button_label, 0, 0, 1, 1);
+ if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
+ gtk_widget_show (priv->cert_button_label);
+ g_free (text);
+
+ /* The cert password entry */
+ gtk_grid_insert_row (GTK_GRID (self), 1);
+
+ priv->cert_password = gtk_entry_new ();
+ gtk_entry_set_visibility (GTK_ENTRY (priv->cert_password), FALSE);
+ gtk_grid_attach (GTK_GRID (self), priv->cert_password, 1, 1, 1, 1);
+ gtk_widget_set_hexpand (priv->cert_password, TRUE);
+ gtk_widget_set_sensitive (priv->cert_password, FALSE);
+ gtk_widget_show (priv->cert_password);
+
+ g_signal_connect (priv->cert_password, "changed",
+ G_CALLBACK (cert_password_changed_cb), self);
+
+ text = g_strdup_printf (_("%s certificate _password:"), title);
+ priv->cert_password_label = gtk_label_new_with_mnemonic (text);
+ g_object_set (priv->cert_password_label, "xalign", (gfloat) 0, NULL);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (priv->cert_password_label), priv->cert_password);
+ gtk_grid_attach (GTK_GRID (self), priv->cert_password_label, 0, 1, 1, 1);
+ gtk_widget_set_sensitive (priv->cert_password_label, FALSE);
+ gtk_widget_show (priv->cert_password_label);
+ g_free (text);
+
+ return self;
+}
+
+static void
+nma_pkcs11_cert_chooser_class_init (NMAPkcs11CertChooserClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (NMAPkcs11CertChooserPrivate));
+}
+
+static void
+nma_pkcs11_cert_chooser_init (NMAPkcs11CertChooser *pkcs11_cert_chooser)
+{
+}
diff --git a/src/libnma/nma-pkcs11-cert-chooser.h b/src/libnma/nma-pkcs11-cert-chooser.h
new file mode 100644
index 0000000..0472dd5
--- /dev/null
+++ b/src/libnma/nma-pkcs11-cert-chooser.h
@@ -0,0 +1,50 @@
+/* NetworkManager Applet -- allow user control over networking
+ *
+ * Lubomir Rintel <lkundrak v3 sk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2015,2017 Red Hat, Inc.
+ */
+
+#ifndef NMA_PKCS11_CERT_CHOOSER_H
+#define NMA_PKCS11_CERT_CHOOSER_H
+
+#include <gtk/gtk.h>
+#include "nma-cert-chooser.h"
+
+G_BEGIN_DECLS
+
+#define NMA_TYPE_PKCS11_CERT_CHOOSER (nma_pkcs11_cert_chooser_get_type ())
+#define NMA_PKCS11_CERT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
NMA_TYPE_PKCS11_CERT_CHOOSER, NMACertChooser))
+#define NMA_IS_PKCS11_CERT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
NMA_TYPE_PKCS11_CERT_CHOOSER))
+#define NMA_PKCS11_CERT_CHOOSER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj),
NMA_TYPE_PKCS11_CERT_CHOOSER, NMACertChooserInterface))
+
+typedef struct {
+ GtkGrid parent;
+} NMAPkcs11CertChooser;
+
+typedef struct {
+ GtkGridClass parent_class;
+} NMAPkcs11CertChooserClass;
+
+GType nma_pkcs11_cert_chooser_get_type (void);
+
+GtkWidget *nma_pkcs11_cert_chooser_new (const gchar *title, NMACertChooserFlags flags);
+
+G_END_DECLS
+
+#endif /* NMA_PKCS11_CERT_CHOOSER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]