[network-manager-applet/lr/pkcs11: 7/9] WIP libnma: add a certificate picker interace



commit 98f25d6da4ca582254dccba0a7f17a8c76930329
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Sat Oct 3 16:22:43 2015 +0200

    WIP libnma: add a certificate picker interace

 Makefile.am                   |    6 +-
 src/libnma/libnma.ver         |   10 ++
 src/libnma/nma-cert-chooser.c |  221 +++++++++++++++++++++++++++++++++++++++++
 src/libnma/nma-cert-chooser.h |   84 ++++++++++++++++
 4 files changed, 319 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 48334b5..4056095 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -476,7 +476,8 @@ libnma_h_pub = \
        src/libnma/nma-mobile-wizard.h \
        src/libnma/nma-mobile-providers.h \
        src/libnma/nma-vpn-password-dialog.h \
-       src/libnma/nma-ui-utils.h
+       src/libnma/nma-ui-utils.h \
+       src/libnma/nma-cert-chooser.h
 
 libnma_c_real = \
        src/libnma/nma-wifi-dialog.c \
@@ -484,7 +485,8 @@ libnma_c_real = \
        src/libnma/nma-mobile-providers.c \
        src/libnma/nma-vpn-password-dialog.c \
        src/libnma/nma-ui-utils.c \
-       src/libnma/init.c
+       src/libnma/init.c \
+       src/libnma/nma-cert-chooser.c
 
 src_libnma_libnmadir = $(includedir)/libnma
 
diff --git a/src/libnma/libnma.ver b/src/libnma/libnma.ver
index 30ea6b9..1ccc946 100644
--- a/src/libnma/libnma.ver
+++ b/src/libnma/libnma.ver
@@ -69,3 +69,13 @@ global:
 local:
        *;
 };
+
+libnma_1_8_0 {
+global:
+       nma_cert_chooser_get_type;
+       nma_cert_chooser_set_value;
+       nma_cert_chooser_get_value;
+       nma_cert_chooser_set_password;
+       nma_cert_chooser_get_password;
+       nma_cert_chooser_new;
+} libnma_1_2_0;
diff --git a/src/libnma/nma-cert-chooser.c b/src/libnma/nma-cert-chooser.c
new file mode 100644
index 0000000..5a5eaa8
--- /dev/null
+++ b/src/libnma/nma-cert-chooser.c
@@ -0,0 +1,221 @@
+/*
+ * 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 Red Hat, Inc.
+ */
+
+#include <config.h>
+
+#include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
+#include <gtk/gtk.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "nma-cert-chooser.h"
+
+G_DEFINE_INTERFACE (NMACertChooser, nma_cert_chooser, G_TYPE_OBJECT)
+
+static void
+nma_cert_chooser_default_init (NMACertChooserInterface *cert_chooser_iface)
+{
+}
+
+/**
+ * nma_cert_chooser_set_cert:
+ * @cert_chooser: certificate chooser button instance
+ * @value: the path or URI of a certificate
+ * @scheme: the scheme of the certificate path
+ *
+ * Sets the certificate location for the chooser button.
+ *
+ * Since: 1.8.0
+ */
+
+void
+nma_cert_chooser_set_cert (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme scheme)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       if (!iface->set_cert)
+               return;
+       iface->set_cert (cert_chooser, value, scheme);
+}
+
+/**
+ * nma_cert_chooser_get_cert:
+ * @cert_chooser: certificate chooser button instance
+ * @scheme: (out): the scheme of the returned certificate path
+ *
+ * Gets the real certificate location from the chooser button along with the scheme.
+ *
+ * Returns: the certificate path
+ *
+ * Since: 1.8.0
+ */
+
+gchar *
+nma_cert_chooser_get_cert (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       g_return_val_if_fail (iface->get_cert, NULL);
+       return iface->get_cert (cert_chooser, scheme);
+}
+
+/**
+ * nma_cert_chooser_set_cert_password:
+ * @cert_chooser: certificate chooser button instance
+ * @password: the certificate PIN or password
+ *
+ * Sets the password or a PIN that might be required to access the certificate.
+ *
+ * Since: 1.8.0
+ */
+
+void
+nma_cert_chooser_set_cert_password (NMACertChooser *cert_chooser, const gchar *password)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       g_return_if_fail (iface->set_cert_password);
+       iface->set_cert_password (cert_chooser, password);
+}
+
+/**
+ * nma_cert_chooser_get_cert_password:
+ * @cert_chooser: certificate chooser button instance
+ *
+ * Obtains the password or a PIN that was be required to access the certificate.
+ *
+ * Returns: the certificate PIN or password
+ *
+ * Since: 1.8.0
+ */
+
+gchar *
+nma_cert_chooser_get_cert_password (NMACertChooser *cert_chooser)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       if (!iface->get_cert_password)
+               return NULL;
+       return iface->get_cert_password (cert_chooser);
+}
+
+
+/**
+ * nma_cert_chooser_set_key:
+ * @cert_chooser: key chooser button instance
+ * @value: the path or URI of a key
+ * @scheme: the scheme of the key path
+ *
+ * Sets the key location for the chooser button.
+ *
+ * Since: 1.8.0
+ */
+
+void
+nma_cert_chooser_set_key (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme scheme)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       if (!iface->set_key)
+               return;
+       iface->set_key (cert_chooser, value, scheme);
+}
+
+/**
+ * nma_cert_chooser_get_key:
+ * @cert_chooser: key chooser button instance
+ * @scheme: (out): the scheme of the returned key path
+ *
+ * Gets the real key location from the chooser button along with the scheme.
+ *
+ * Returns: the key path
+ *
+ * Since: 1.8.0
+ */
+
+gchar *
+nma_cert_chooser_get_key (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       g_return_val_if_fail (iface->get_key, NULL);
+       return iface->get_key (cert_chooser, scheme);
+}
+
+/**
+ * nma_cert_chooser_set_key_password:
+ * @cert_chooser: key chooser button instance
+ * @password: the key PIN or password
+ *
+ * Sets the password or a PIN that might be required to access the key.
+ *
+ * Since: 1.8.0
+ */
+
+void
+nma_cert_chooser_set_key_password (NMACertChooser *cert_chooser, const gchar *password)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       g_return_if_fail (iface->set_key_password);
+       iface->set_key_password (cert_chooser, password);
+}
+
+/**
+ * nma_cert_chooser_get_key_password:
+ * @cert_chooser: key chooser button instance
+ *
+ * Obtains the password or a PIN that was be required to access the key.
+ *
+ * Returns: the key PIN or password
+ *
+ * Since: 1.8.0
+ */
+
+gchar *
+nma_cert_chooser_get_key_password (NMACertChooser *cert_chooser)
+{
+       NMACertChooserInterface *iface = NMA_CERT_CHOOSER_GET_INTERFACE (cert_chooser);
+
+       if (!iface->get_key_password)
+               return NULL;
+       return iface->get_key_password (cert_chooser);
+}
+
+/**
+ * nma_cert_chooser_new:
+ * @title: title of the certificate chooser dialog
+ * @flags: the flags that configure the capabilities of the button
+ *
+ * Constructs the button that is capable of selecting a certificate
+ * and a key.
+ *
+ * Returns: (transfer full): the certificate chooser button instance
+ *
+ * Since: 1.8.0
+ */
+
+GtkWidget *
+nma_cert_chooser_new (const gchar *title, NMACertChooserFlags flags)
+{
+       g_return_val_if_reached (NULL);
+}
diff --git a/src/libnma/nma-cert-chooser.h b/src/libnma/nma-cert-chooser.h
new file mode 100644
index 0000000..a67f625
--- /dev/null
+++ b/src/libnma/nma-cert-chooser.h
@@ -0,0 +1,84 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * 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_CERT_CHOOSER_H
+#define NMA_CERT_CHOOSER_H
+
+#include <gtk/gtk.h>
+#include <NetworkManager.h>
+
+G_BEGIN_DECLS
+
+#define NMA_TYPE_CERT_CHOOSER                   (nma_cert_chooser_get_type ())
+#define NMA_CERT_CHOOSER(obj)                   (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMA_TYPE_CERT_CHOOSER, 
NMACertChooser))
+#define NMA_IS_CERT_CHOOSER(obj)                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMA_TYPE_CERT_CHOOSER))
+#define NMA_CERT_CHOOSER_GET_INTERFACE(obj)     (G_TYPE_INSTANCE_GET_INTERFACE ((obj), 
NMA_TYPE_CERT_CHOOSER, NMACertChooserInterface))
+
+typedef struct _NMACertChooser NMACertChooser;
+
+/**
+ * NMACertChooser:
+ *
+ * This is a certificate chooser button. It should be used when picking
+ * certificate files and keys for use with NetworkManager.
+ */
+
+typedef struct {
+       GTypeInterface parent_iface;
+
+       void   (*set_cert)          (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme 
scheme);
+       gchar *(*get_cert)          (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme);
+       void   (*set_cert_password) (NMACertChooser *cert_chooser, const gchar *password);
+       gchar *(*get_cert_password) (NMACertChooser *cert_chooser);
+       void   (*set_key)           (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme 
scheme);
+       gchar *(*get_key)           (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme);
+       void   (*set_key_password)  (NMACertChooser *cert_chooser, const gchar *password);
+       gchar *(*get_key_password)  (NMACertChooser *cert_chooser);
+} NMACertChooserInterface;
+
+/**
+ * NMACertChooserFlags:
+ * @NMA_CERT_CHOOSER_FLAG_CERT: Only pick a certificate, not a key
+ * @NMA_CERT_CHOOSER_FLAG_PEM: Ensure the chooser only selects regular PEM files
+ *
+ * Flags that controls what is the certificate chooser button able to pick.
+ * Currently only local files are supported, but might be extended to use URIs,
+ * such as PKCS#11 certificate URIs in future as well.
+ */
+
+typedef enum {
+       NMA_CERT_CHOOSER_FLAG_CERT = 0x1,
+       NMA_CERT_CHOOSER_FLAG_PEM  = 0x2,
+} NMACertChooserFlags;
+
+GType      nma_cert_chooser_get_type          (void);
+void       nma_cert_chooser_set_cert          (NMACertChooser *cert_chooser, const gchar *value, 
NMSetting8021xCKScheme scheme);
+gchar     *nma_cert_chooser_get_cert          (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme);
+void       nma_cert_chooser_set_cert_password (NMACertChooser *cert_chooser, const gchar *password);
+gchar     *nma_cert_chooser_get_cert_password (NMACertChooser *cert_chooser);
+void       nma_cert_chooser_set_key           (NMACertChooser *cert_chooser, const gchar *value, 
NMSetting8021xCKScheme scheme);
+gchar     *nma_cert_chooser_get_key           (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme);
+void       nma_cert_chooser_set_key_password  (NMACertChooser *cert_chooser, const gchar *password);
+gchar     *nma_cert_chooser_get_key_password  (NMACertChooser *cert_chooser);
+GtkWidget *nma_cert_chooser_new               (const gchar *title, NMACertChooserFlags flags);
+
+G_END_DECLS
+
+#endif /* NMA_CERT_CHOOSER_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]