[network-manager-applet/lr/pkcs11: 21/24] fixup! libnma: add a certificate picker interface



commit 0af1507a0d3ab61b24ebb22c1db793759e20370e
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Wed Mar 8 15:11:40 2017 +0100

    fixup! libnma: add a certificate picker interface
    
    Add URI setters/getters.

 src/libnm-gtk/libnm-gtk.ver   |    4 +
 src/libnma/libnma.ver         |    4 +
 src/libnma/nma-cert-chooser.c |  178 ++++++++++++++++++++++++++++++++++++++---
 src/libnma/nma-cert-chooser.h |   38 ++++++---
 4 files changed, 197 insertions(+), 27 deletions(-)
---
diff --git a/src/libnm-gtk/libnm-gtk.ver b/src/libnm-gtk/libnm-gtk.ver
index d99536f..6e9d3b1 100644
--- a/src/libnm-gtk/libnm-gtk.ver
+++ b/src/libnm-gtk/libnm-gtk.ver
@@ -21,15 +21,19 @@ global:
        nma_cert_chooser_get_cert;
        nma_cert_chooser_get_cert_password;
        nma_cert_chooser_get_cert_password_flags;
+       nma_cert_chooser_get_cert_uri;
        nma_cert_chooser_get_key;
        nma_cert_chooser_get_key_password;
        nma_cert_chooser_get_key_password_flags;
+       nma_cert_chooser_get_key_uri;
        nma_cert_chooser_get_type;
        nma_cert_chooser_new;
        nma_cert_chooser_set_cert;
        nma_cert_chooser_set_cert_password;
+       nma_cert_chooser_set_cert_uri;
        nma_cert_chooser_set_key;
        nma_cert_chooser_set_key_password;
+       nma_cert_chooser_set_key_uri;
        nma_cert_chooser_setup_cert_password_storage;
        nma_cert_chooser_setup_key_password_storage;
        nma_cert_chooser_update_cert_password_storage;
diff --git a/src/libnma/libnma.ver b/src/libnma/libnma.ver
index 90b89f3..b1efa74 100644
--- a/src/libnma/libnma.ver
+++ b/src/libnma/libnma.ver
@@ -76,15 +76,19 @@ global:
        nma_cert_chooser_get_cert;
        nma_cert_chooser_get_cert_password;
        nma_cert_chooser_get_cert_password_flags;
+       nma_cert_chooser_get_cert_uri;
        nma_cert_chooser_get_key;
        nma_cert_chooser_get_key_password;
        nma_cert_chooser_get_key_password_flags;
+       nma_cert_chooser_get_key_uri;
        nma_cert_chooser_get_type;
        nma_cert_chooser_new;
        nma_cert_chooser_set_cert;
        nma_cert_chooser_set_cert_password;
+       nma_cert_chooser_set_cert_uri;
        nma_cert_chooser_set_key;
        nma_cert_chooser_set_key_password;
+       nma_cert_chooser_set_key_uri;
        nma_cert_chooser_setup_cert_password_storage;
        nma_cert_chooser_setup_key_password_storage;
        nma_cert_chooser_update_cert_password_storage;
diff --git a/src/libnma/nma-cert-chooser.c b/src/libnma/nma-cert-chooser.c
index 95888be..da35a66 100644
--- a/src/libnma/nma-cert-chooser.c
+++ b/src/libnma/nma-cert-chooser.c
@@ -74,6 +74,87 @@ accu_validation_error (GSignalInvocationHint *ihint,
        return TRUE;
 }
 
+#ifdef NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11
+
+static gchar *
+value_with_scheme_to_uri (const gchar *value, NMSetting8021xCKScheme scheme)
+{
+       switch (scheme) {
+       case NM_SETTING_802_1X_CK_SCHEME_PATH:
+               return g_strdup_printf (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH "%s", value);
+       case NM_SETTING_802_1X_CK_SCHEME_PKCS11:
+               return g_strdup (value);
+       default:
+               g_warning ("The key '%s' uses an unknown scheme %d\n", value, scheme);
+               return NULL;
+       }
+}
+
+static gchar *
+uri_to_value_with_scheme (const gchar *uri, NMSetting8021xCKScheme *scheme)
+{
+       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;
+       }
+}
+
+#else
+
+/* libnm-glib only supports certificates in files. */
+
+static gchar *
+value_with_scheme_to_uri (const gchar *value, NMSetting8021xCKScheme scheme)
+{
+       g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH, NULL);
+       return g_strdup_printf ("file://%s", value);
+}
+
+static gchar *
+uri_to_value_with_scheme (const gchar *uri, NMSetting8021xCKScheme *scheme)
+{
+       if (!uri) {
+               *scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN;
+               return NULL;
+       }
+
+       g_return_val_if_fail (g_str_has_prefix (uri, "file://"), NULL);
+       return g_strdup (uri + 7);
+}
+
+#endif
+
+/**
+ * nma_cert_chooser_set_cert_uri:
+ * @cert_chooser: certificate chooser button instance
+ * @uri: the path or URI of a certificate
+ *
+ * Sets the certificate URI for the chooser button.
+ *
+ * Since: 1.8.0
+ */
+void
+nma_cert_chooser_set_cert_uri (NMACertChooser *cert_chooser,
+                               const gchar *uri)
+{
+       NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+
+       g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
+
+       if (!klass->set_cert_uri)
+               return;
+       klass->set_cert_uri (cert_chooser, uri);
+}
+
 /**
  * nma_cert_chooser_set_cert:
  * @cert_chooser: certificate chooser button instance
@@ -85,15 +166,40 @@ accu_validation_error (GSignalInvocationHint *ihint,
  * Since: 1.8.0
  */
 void
-nma_cert_chooser_set_cert (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme scheme)
+nma_cert_chooser_set_cert (NMACertChooser *cert_chooser,
+                           const gchar *value,
+                           NMSetting8021xCKScheme scheme)
 {
-       NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+       gs_free gchar *uri = NULL;
 
        g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
 
-       if (!klass->set_cert)
+       if (!value)
                return;
-       klass->set_cert (cert_chooser, value, scheme);
+
+       uri = value_with_scheme_to_uri (value, scheme);
+       nma_cert_chooser_set_cert_uri (cert_chooser, uri);
+}
+
+/**
+ * nma_cert_chooser_get_cert_uri:
+ * @cert_chooser: certificate chooser button instance
+ *
+ * Gets the real certificate URI from the chooser button along with the scheme.
+ *
+ * Returns: the certificate URI
+ *
+ * Since: 1.8.0
+ */
+gchar *
+nma_cert_chooser_get_cert_uri (NMACertChooser *cert_chooser)
+{
+       NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+
+       g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
+       g_return_val_if_fail (klass->get_cert_uri, NULL);
+
+       return klass->get_cert_uri (cert_chooser);
 }
 
 /**
@@ -110,12 +216,12 @@ nma_cert_chooser_set_cert (NMACertChooser *cert_chooser, const gchar *value, NMS
 gchar *
 nma_cert_chooser_get_cert (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme)
 {
-       NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+       gs_free gchar *uri = NULL;
 
        g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
-       g_return_val_if_fail (klass->get_cert, NULL);
 
-       return klass->get_cert (cert_chooser, scheme);
+       uri = nma_cert_chooser_get_cert_uri (cert_chooser);
+       return uri_to_value_with_scheme (uri, scheme);
 }
 
 /**
@@ -162,6 +268,27 @@ nma_cert_chooser_get_cert_password (NMACertChooser *cert_chooser)
        return klass->get_cert_password (cert_chooser);
 }
 
+/**
+ * nma_cert_chooser_set_key_uri:
+ * @cert_chooser: certificate chooser button instance
+ * @uri: the URI of a key
+ *
+ * Sets the key URI for the chooser button.
+ *
+ * Since: 1.8.0
+ */
+void
+nma_cert_chooser_set_key_uri (NMACertChooser *cert_chooser,
+                              const gchar *uri)
+{
+       NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+
+       g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
+
+       if (!klass->set_key_uri)
+               return;
+       klass->set_key_uri (cert_chooser, uri);
+}
 
 /**
  * nma_cert_chooser_set_key:
@@ -174,15 +301,19 @@ nma_cert_chooser_get_cert_password (NMACertChooser *cert_chooser)
  * Since: 1.8.0
  */
 void
-nma_cert_chooser_set_key (NMACertChooser *cert_chooser, const gchar *value, NMSetting8021xCKScheme scheme)
+nma_cert_chooser_set_key (NMACertChooser *cert_chooser,
+                          const gchar *value,
+                          NMSetting8021xCKScheme scheme)
 {
-       NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+       gs_free gchar *uri = NULL;
 
        g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
 
-       if (!klass->set_key)
+       if (!value)
                return;
-       klass->set_key (cert_chooser, value, scheme);
+
+       uri = value_with_scheme_to_uri (value, scheme);
+       nma_cert_chooser_set_key_uri (cert_chooser, uri);
 }
 
 /**
@@ -199,12 +330,33 @@ nma_cert_chooser_set_key (NMACertChooser *cert_chooser, const gchar *value, NMSe
 gchar *
 nma_cert_chooser_get_key (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *scheme)
 {
+       gs_free gchar *uri = NULL;
+
+       g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
+
+       uri = nma_cert_chooser_get_key_uri (cert_chooser);
+       return uri_to_value_with_scheme (uri, scheme);
+}
+
+/**
+ * nma_cert_chooser_get_key_uri:
+ * @cert_chooser: certificate chooser button instance
+ *
+ * Gets the real key URI from the chooser button along with the scheme.
+ *
+ * Returns: the key URI
+ *
+ * Since: 1.8.0
+ */
+gchar *
+nma_cert_chooser_get_key_uri (NMACertChooser *cert_chooser)
+{
        NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
 
        g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
-       g_return_val_if_fail (klass->get_key, NULL);
+       g_return_val_if_fail (klass->get_key_uri, NULL);
 
-       return klass->get_key (cert_chooser, scheme);
+       return klass->get_key_uri (cert_chooser);
 }
 
 /**
diff --git a/src/libnma/nma-cert-chooser.h b/src/libnma/nma-cert-chooser.h
index d46b5d2..d2ce2ed 100644
--- a/src/libnma/nma-cert-chooser.h
+++ b/src/libnma/nma-cert-chooser.h
@@ -66,15 +66,15 @@ typedef enum {
 /**
  * NMACertChooserClass:
  * @parent_class: The parent class.
- * @set_cert: Set the certificate location for the chooser button.
- * @get_cert: Get the real certificate location from the chooser button along
+ * @set_cert_uri: Set the certificate location for the chooser button.
+ * @get_cert_uri: Get the real certificate location from the chooser button along
  *   with the scheme.
  * @set_cert_password: Set the password or a PIN that might be required to
  *   access the certificate.
  * @get_cert_password: Obtain the password or a PIN that was be required to
  *   access the certificate.
- * @set_key: Set the key location for the chooser button.
- * @get_key: Get the real key location from the chooser button along with the
+ * @set_key_uri: Set the key location for the chooser button.
+ * @get_key_uri: Get the real key location from the chooser button along with the
  *   scheme.
  * @set_key_password: Set the password or a PIN that might be required to
  *   access the key.
@@ -105,19 +105,15 @@ typedef struct {
        GtkGridClass parent_class;
 
        /* virtual methods */
-       void                 (*set_cert)                     (NMACertChooser *cert_chooser,
-                                                             const gchar *value,
-                                                             NMSetting8021xCKScheme scheme);
-       gchar               *(*get_cert)                     (NMACertChooser *cert_chooser,
-                                                             NMSetting8021xCKScheme *scheme);
+       void                 (*set_cert_uri)                 (NMACertChooser *cert_chooser,
+                                                             const gchar *uri);
+       gchar               *(*get_cert_uri)                 (NMACertChooser *cert_chooser);
        void                 (*set_cert_password)            (NMACertChooser *cert_chooser,
                                                              const gchar *password);
        const 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_uri)                  (NMACertChooser *cert_chooser,
+                                                             const gchar *uri);
+       gchar               *(*get_key_uri)                  (NMACertChooser *cert_chooser);
        void                 (*set_key_password)             (NMACertChooser *cert_chooser,
                                                              const gchar *password);
        const gchar         *(*get_key_password)             (NMACertChooser *cert_chooser);
@@ -173,10 +169,17 @@ void                 nma_cert_chooser_set_cert                     (NMACertChoos
                                                                     NMSetting8021xCKScheme scheme);
 
 NMA_AVAILABLE_IN_1_8
+void                 nma_cert_chooser_set_cert_uri                 (NMACertChooser *cert_chooser,
+                                                                    const gchar *uri);
+
+NMA_AVAILABLE_IN_1_8
 gchar               *nma_cert_chooser_get_cert                     (NMACertChooser *cert_chooser,
                                                                     NMSetting8021xCKScheme *scheme);
 
 NMA_AVAILABLE_IN_1_8
+gchar               *nma_cert_chooser_get_cert_uri                 (NMACertChooser *cert_chooser);
+
+NMA_AVAILABLE_IN_1_8
 void                 nma_cert_chooser_set_cert_password            (NMACertChooser *cert_chooser,
                                                                     const gchar *password);
 
@@ -189,10 +192,17 @@ void                 nma_cert_chooser_set_key                      (NMACertChoos
                                                                     NMSetting8021xCKScheme scheme);
 
 NMA_AVAILABLE_IN_1_8
+void                 nma_cert_chooser_set_key_uri                  (NMACertChooser *cert_chooser,
+                                                                    const gchar *uri);
+
+NMA_AVAILABLE_IN_1_8
 gchar               *nma_cert_chooser_get_key                      (NMACertChooser *cert_chooser,
                                                                     NMSetting8021xCKScheme *scheme);
 
 NMA_AVAILABLE_IN_1_8
+gchar               *nma_cert_chooser_get_key_uri                  (NMACertChooser *cert_chooser);
+
+NMA_AVAILABLE_IN_1_8
 void                 nma_cert_chooser_set_key_password             (NMACertChooser *cert_chooser,
                                                                     const gchar *password);
 


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