[evolution-data-server] Bug 749385 - [GOA] Fails to work with ownCloud with invalid certificate
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 749385 - [GOA] Fails to work with ownCloud with invalid certificate
- Date: Fri, 22 May 2015 14:52:21 +0000 (UTC)
commit ed11a0f304debbc28e6c67b4d00c6eceabcffcc7
Author: Milan Crha <mcrha redhat com>
Date: Fri May 22 16:51:56 2015 +0200
Bug 749385 - [GOA] Fails to work with ownCloud with invalid certificate
libebackend/e-server-side-source.c | 32 +++++++++++++++++-
libedataserver/e-data-server-util.c | 64 +++++++++++++++++++++++++++++++++++
libedataserver/e-data-server-util.h | 5 +++
libedataserverui/e-trust-prompt.c | 49 ++++++++++++++++++++++++++-
4 files changed, 148 insertions(+), 2 deletions(-)
---
diff --git a/libebackend/e-server-side-source.c b/libebackend/e-server-side-source.c
index ffa0bc9..f1a017e 100644
--- a/libebackend/e-server-side-source.c
+++ b/libebackend/e-server-side-source.c
@@ -359,8 +359,38 @@ server_side_source_invoke_authenticate_cb (EDBusSource *dbus_interface,
last_credentials_strv = e_named_parameters_to_strv (source->priv->last_credentials);
arg_credentials = (const gchar * const *) last_credentials_strv;
} else if (arg_credentials && arg_credentials[0]) {
+ ENamedParameters *credentials = e_named_parameters_new_strv (arg_credentials);
+
+ /* If only one credential value is passed in, and it's the SSL Trust,
+ and there was any credentials already tried, then merge the previous
+ credentials with the SSL Trust, to inherit the password, if any. */
+ if (source->priv->last_credentials &&
+ e_named_parameters_count (credentials) == 1 &&
+ e_named_parameters_exists (credentials, E_SOURCE_CREDENTIAL_SSL_TRUST)) {
+ gint ii, count;
+
+ count = e_named_parameters_count (source->priv->last_credentials);
+ for (ii = 0; ii < count; ii++) {
+ gchar *name;
+
+ name = e_named_parameters_get_name (source->priv->last_credentials, ii);
+ if (!name)
+ continue;
+
+ if (*name && !e_named_parameters_exists (credentials, name)) {
+ e_named_parameters_set (credentials, name,
+ e_named_parameters_get (source->priv->last_credentials,
name));
+ }
+
+ g_free (name);
+ }
+
+ last_credentials_strv = e_named_parameters_to_strv (credentials);
+ arg_credentials = (const gchar * const *) last_credentials_strv;
+ }
+
e_named_parameters_free (source->priv->last_credentials);
- source->priv->last_credentials = e_named_parameters_new_strv (arg_credentials);
+ source->priv->last_credentials = credentials;
}
g_free (source->priv->last_reason);
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index fb43e5c..79a5cf2 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -2362,6 +2362,70 @@ e_named_parameters_to_strv (const ENamedParameters *parameters)
return (gchar **) g_ptr_array_free (ret, FALSE);
}
+/**
+ * e_named_parameters_exists:
+ * @parameters: an #ENamedParameters
+ * @name: name of the parameter whose existence to check
+ *
+ * Returns: Whether @parameters holds a parameter named @name
+ *
+ * Since: 3.18
+ **/
+gboolean
+e_named_parameters_exists (const ENamedParameters *parameters,
+ const gchar *name)
+{
+ g_return_val_if_fail (parameters != NULL, FALSE);
+ g_return_val_if_fail (name != NULL, FALSE);
+
+ return get_parameter_index (parameters, name) != -1;
+}
+
+/**
+ * e_named_parameters_count:
+ * @parameters: an #ENamedParameters
+ *
+ * Returns: The number of stored named parameters in @parameters
+ *
+ * Since: 3.18
+ **/
+guint
+e_named_parameters_count (const ENamedParameters *parameters)
+{
+ g_return_val_if_fail (parameters != NULL, 0);
+
+ return ((GPtrArray *) parameters)->len;
+}
+
+/**
+ * e_named_parameters_get_name:
+ * @parameters: an #ENamedParameters
+ * @index: an index of the parameter whose name to retrieve
+ *
+ * Returns: (transfer full): The name of the parameters at index @index,
+ * or %NULL, of the @index is out of bounds or other error. The returned
+ * string should be freed with g_free() when done with it.
+ *
+ * Since: 3.18
+ **/
+gchar *
+e_named_parameters_get_name (const ENamedParameters *parameters,
+ gint index)
+{
+ const gchar *name_and_value, *colon;
+
+ g_return_val_if_fail (parameters != NULL, NULL);
+ g_return_val_if_fail (index >= 0 && index < e_named_parameters_count (parameters), NULL);
+
+ name_and_value = g_ptr_array_index ((GPtrArray *) parameters, index);
+ colon = name_and_value ? strchr (name_and_value, ':') : NULL;
+
+ if (!colon || colon == name_and_value)
+ return NULL;
+
+ return g_strndup (name_and_value, colon - name_and_value);
+}
+
static ENamedParameters *
e_named_parameters_ref (ENamedParameters *params)
{
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index 2608ec5..0d2aec7 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -190,6 +190,11 @@ gboolean e_named_parameters_test (const ENamedParameters *parameters,
const gchar *name,
const gchar *value,
gboolean case_sensitively);
+gboolean e_named_parameters_exists (const ENamedParameters *parameters,
+ const gchar *name);
+guint e_named_parameters_count (const ENamedParameters *parameters);
+gchar * e_named_parameters_get_name (const ENamedParameters *parameters,
+ gint index);
#define e_named_timeout_add(interval, function, data) \
(e_timeout_add_with_name ( \
diff --git a/libedataserverui/e-trust-prompt.c b/libedataserverui/e-trust-prompt.c
index 0ff6e17..37b3cc6 100644
--- a/libedataserverui/e-trust-prompt.c
+++ b/libedataserverui/e-trust-prompt.c
@@ -486,6 +486,31 @@ save_source_thread (GTask *task,
}
}
+static gchar *
+trust_prompt_get_host_from_url (const gchar *url)
+{
+ SoupURI *suri;
+ gchar *host;
+
+ if (!url || !*url)
+ return NULL;
+
+ suri = soup_uri_new (url);
+ if (!suri)
+ return NULL;
+
+ host = g_strdup (soup_uri_get_host (suri));
+
+ if (!host || !*host) {
+ g_free (host);
+ host = NULL;
+ }
+
+ soup_uri_free (suri);
+
+ return host;
+}
+
/**
* e_trust_prompt_run_for_source:
* @parent: A #GtkWindow to use as a parent for the trust prompt dialog
@@ -544,11 +569,33 @@ e_trust_prompt_run_for_source (GtkWindow *parent,
save_data->response = E_TRUST_PROMPT_RESPONSE_UNKNOWN;
save_data->call_save = FALSE;
+ /* Lookup used host name */
host = e_source_authentication_dup_host (extension_authentication);
+ if (!host || !*host) {
+ g_free (host);
+ host = NULL;
+
+ if (e_source_has_extension (source, E_SOURCE_EXTENSION_GOA)) {
+ ESourceGoa *goa_extension;
+ gchar *url;
+
+ goa_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_GOA);
+
+ url = e_source_goa_dup_calendar_url (goa_extension);
+ host = trust_prompt_get_host_from_url (url);
+ g_free (url);
+
+ if (!host) {
+ url = e_source_goa_dup_contacts_url (goa_extension);
+ host = trust_prompt_get_host_from_url (url);
+ g_free (url);
+ }
+ }
+ }
certificate = g_tls_certificate_new_from_pem (certificate_pem, -1, &save_data->error);
if (certificate) {
- if (extension_webdav)
+ if (extension_webdav && host)
save_data->response = e_source_webdav_verify_ssl_trust (extension_webdav, host,
certificate, 0);
else
save_data->response = E_TRUST_PROMPT_RESPONSE_REJECT_TEMPORARILY;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]