summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2022-06-28 13:31:48 +0200
committerMilan Crha <mcrha@redhat.com>2022-06-28 13:31:48 +0200
commitab825489f51dfa5172233c572c3435d26efaf5d0 (patch)
treee6bcbd2a96bd3e37d7ab637d4a75b8f1306d33c2
parent5d731c9e2188b82b0bc248f42f8e47a5fb75d442 (diff)
downloadevolution-data-server-ab825489f51dfa5172233c572c3435d26efaf5d0.tar.gz
I#39 - Add Web Key Directory (WKD) support for OpenPGP
Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/39
-rw-r--r--src/camel/camel-gpg-context.c88
-rw-r--r--src/camel/camel-gpg-context.h5
-rw-r--r--src/libedataserver/e-source-openpgp.c77
-rw-r--r--src/libedataserver/e-source-openpgp.h3
4 files changed, 171 insertions, 2 deletions
diff --git a/src/camel/camel-gpg-context.c b/src/camel/camel-gpg-context.c
index 34f5821ad..205372e42 100644
--- a/src/camel/camel-gpg-context.c
+++ b/src/camel/camel-gpg-context.c
@@ -80,12 +80,14 @@ static gint logid;
struct _CamelGpgContextPrivate {
gboolean always_trust;
gboolean prefer_inline;
+ gboolean locate_keys;
};
enum {
PROP_0,
PROP_ALWAYS_TRUST,
- PROP_PREFER_INLINE
+ PROP_PREFER_INLINE,
+ PROP_LOCATE_KEYS,
};
G_DEFINE_TYPE_WITH_PRIVATE (CamelGpgContext, camel_gpg_context, CAMEL_TYPE_CIPHER_CONTEXT)
@@ -171,6 +173,7 @@ struct _GpgCtx {
guint seen_eof2 : 1;
guint always_trust : 1;
guint prefer_inline : 1;
+ guint locate_keys : 1;
guint armor : 1;
guint need_passwd : 1;
guint send_passwd : 1;
@@ -231,6 +234,7 @@ gpg_ctx_new (CamelCipherContext *context,
gpg->hash = CAMEL_CIPHER_HASH_DEFAULT;
gpg->always_trust = FALSE;
gpg->prefer_inline = FALSE;
+ gpg->locate_keys = FALSE;
gpg->armor = FALSE;
gpg->load_photos = FALSE;
gpg->photos_filename = NULL;
@@ -331,6 +335,13 @@ gpg_ctx_set_prefer_inline (struct _GpgCtx *gpg,
}
static void
+gpg_ctx_set_locate_keys (struct _GpgCtx *gpg,
+ gboolean locate_keys)
+{
+ gpg->locate_keys = locate_keys;
+}
+
+static void
gpg_ctx_set_userid (struct _GpgCtx *gpg,
const gchar *userid)
{
@@ -733,6 +744,10 @@ gpg_ctx_get_argv (struct _GpgCtx *gpg,
g_ptr_array_add (argv, (guint8 *) "--armor");
if (gpg->always_trust)
g_ptr_array_add (argv, (guint8 *) "--always-trust");
+ if (gpg->locate_keys && camel_session_get_online (gpg->session)) {
+ g_ptr_array_add (argv, (guint8 *) "--auto-key-locate");
+ g_ptr_array_add (argv, (guint8 *) "local,wkd");
+ }
if (gpg->userids) {
GSList *uiter;
@@ -2082,6 +2097,12 @@ gpg_context_set_property (GObject *object,
g_value_get_boolean (value));
return;
+ case PROP_LOCATE_KEYS:
+ camel_gpg_context_set_locate_keys (
+ CAMEL_GPG_CONTEXT (object),
+ g_value_get_boolean (value));
+ return;
+
case PROP_PREFER_INLINE:
camel_gpg_context_set_prefer_inline (
CAMEL_GPG_CONTEXT (object),
@@ -2106,6 +2127,13 @@ gpg_context_get_property (GObject *object,
CAMEL_GPG_CONTEXT (object)));
return;
+ case PROP_LOCATE_KEYS:
+ g_value_set_boolean (
+ value,
+ camel_gpg_context_get_locate_keys (
+ CAMEL_GPG_CONTEXT (object)));
+ return;
+
case PROP_PREFER_INLINE:
g_value_set_boolean (
value,
@@ -2635,6 +2663,7 @@ gpg_encrypt_sync (CamelCipherContext *context,
gpg_ctx_set_ostream (gpg, ostream);
gpg_ctx_set_always_trust (gpg, ctx->priv->always_trust);
gpg_ctx_set_prefer_inline (gpg, prefer_inline);
+ gpg_ctx_set_locate_keys (gpg, ctx->priv->locate_keys);
if (gathered_keys && g_slist_length (gathered_keys) != recipients->len) {
g_slist_free_full (gathered_keys, g_free);
@@ -2968,6 +2997,18 @@ camel_gpg_context_class_init (CamelGpgContextClass *class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_EXPLICIT_NOTIFY));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_LOCATE_KEYS,
+ g_param_spec_boolean (
+ "locate-keys",
+ "Locate Keys",
+ NULL,
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_EXPLICIT_NOTIFY));
}
static void
@@ -3068,3 +3109,48 @@ camel_gpg_context_set_prefer_inline (CamelGpgContext *context,
g_object_notify (G_OBJECT (context), "prefer-inline");
}
+
+/**
+ * camel_gpg_context_get_locate_keys:
+ * @context: a #CamelGpgContext
+ *
+ * Returns, whether gpg can locate keys using Web Key Directory (WKD) lookup
+ * when encrypting messages. The default is %TRUE.
+ *
+ * Returns: whether gpg can locate keys using Web Key Directory (WKD) lookup
+ * when encrypting messages.
+ *
+ * Since: 3.46
+ **/
+gboolean
+camel_gpg_context_get_locate_keys (CamelGpgContext *context)
+{
+ g_return_val_if_fail (CAMEL_IS_GPG_CONTEXT (context), FALSE);
+
+ return context->priv->locate_keys;
+}
+
+/**
+ * camel_gpg_context_set_locate_keys:
+ * @context: gpg context
+ * @locate_keys: value to set
+ *
+ * Sets the @locate_keys on the gpg context which is used to instruct
+ * gpg to locate keys using Web Key Directory (WKD) lookup when encrypting
+ * messages.
+ *
+ * Since: 3.46
+ **/
+void
+camel_gpg_context_set_locate_keys (CamelGpgContext *context,
+ gboolean locate_keys)
+{
+ g_return_if_fail (CAMEL_IS_GPG_CONTEXT (context));
+
+ if (!context->priv->locate_keys == !locate_keys)
+ return;
+
+ context->priv->locate_keys = locate_keys;
+
+ g_object_notify (G_OBJECT (context), "locate-keys");
+}
diff --git a/src/camel/camel-gpg-context.h b/src/camel/camel-gpg-context.h
index 667f74e4a..7b3345cab 100644
--- a/src/camel/camel-gpg-context.h
+++ b/src/camel/camel-gpg-context.h
@@ -77,6 +77,11 @@ gboolean camel_gpg_context_get_prefer_inline
void camel_gpg_context_set_prefer_inline
(CamelGpgContext *context,
gboolean prefer_inline);
+gboolean camel_gpg_context_get_locate_keys
+ (CamelGpgContext *context);
+void camel_gpg_context_set_locate_keys
+ (CamelGpgContext *context,
+ gboolean locate_keys);
G_END_DECLS
diff --git a/src/libedataserver/e-source-openpgp.c b/src/libedataserver/e-source-openpgp.c
index a9ac320c6..0a70ae482 100644
--- a/src/libedataserver/e-source-openpgp.c
+++ b/src/libedataserver/e-source-openpgp.c
@@ -47,6 +47,7 @@ struct _ESourceOpenPGPPrivate {
gboolean sign_by_default;
gboolean encrypt_by_default;
gboolean prefer_inline;
+ gboolean locate_keys;
};
enum {
@@ -57,7 +58,8 @@ enum {
PROP_SIGNING_ALGORITHM,
PROP_SIGN_BY_DEFAULT,
PROP_ENCRYPT_BY_DEFAULT,
- PROP_PREFER_INLINE
+ PROP_PREFER_INLINE,
+ PROP_LOCATE_KEYS
};
G_DEFINE_TYPE_WITH_PRIVATE (
@@ -113,6 +115,12 @@ source_openpgp_set_property (GObject *object,
E_SOURCE_OPENPGP (object),
g_value_get_boolean (value));
return;
+
+ case PROP_LOCATE_KEYS:
+ e_source_openpgp_set_locate_keys (
+ E_SOURCE_OPENPGP (object),
+ g_value_get_boolean (value));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -173,6 +181,13 @@ source_openpgp_get_property (GObject *object,
e_source_openpgp_get_prefer_inline (
E_SOURCE_OPENPGP (object)));
return;
+
+ case PROP_LOCATE_KEYS:
+ g_value_set_boolean (
+ value,
+ e_source_openpgp_get_locate_keys (
+ E_SOURCE_OPENPGP (object)));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -303,6 +318,20 @@ e_source_openpgp_class_init (ESourceOpenPGPClass *class)
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS |
E_SOURCE_PARAM_SETTING));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_LOCATE_KEYS,
+ g_param_spec_boolean (
+ "locate-keys",
+ "Locate Keys",
+ "Locate keys in WKD for encryption",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_EXPLICIT_NOTIFY |
+ G_PARAM_STATIC_STRINGS |
+ E_SOURCE_PARAM_SETTING));
}
static void
@@ -690,3 +719,49 @@ e_source_openpgp_set_prefer_inline (ESourceOpenPGP *extension,
g_object_notify (G_OBJECT (extension), "prefer-inline");
}
+
+/**
+ * e_source_openpgp_get_locate_keys:
+ * @extension: an #ESourceOpenPGP
+ *
+ * Returns, whether gpg can locate keys using Web Key Directory (WKD) lookup
+ * when encrypting messages. The default is %TRUE.
+ *
+ * Returns: whether gpg can locate keys using Web Key Directory (WKD) lookup
+ * when encrypting messages.
+ *
+ * Since: 3.46
+ **/
+
+gboolean
+e_source_openpgp_get_locate_keys (ESourceOpenPGP *extension)
+{
+ g_return_val_if_fail (E_IS_SOURCE_OPENPGP (extension), FALSE);
+
+ return extension->priv->locate_keys;
+}
+
+/**
+ * e_source_openpgp_set_locate_keys:
+ * @extension: an #ESourceOpenPGP
+ * @locate_keys: value to set
+ *
+ * Sets the @locate_keys on the @extension, which is used to instruct
+ * gpg to locate keys using Web Key Directory (WKD) lookup when encrypting
+ * messages.
+ *
+ * Since: 3.46
+ **/
+void
+e_source_openpgp_set_locate_keys (ESourceOpenPGP *extension,
+ gboolean locate_keys)
+{
+ g_return_if_fail (E_IS_SOURCE_OPENPGP (extension));
+
+ if (!extension->priv->locate_keys == !locate_keys)
+ return;
+
+ extension->priv->locate_keys = locate_keys;
+
+ g_object_notify (G_OBJECT (extension), "locate-keys");
+}
diff --git a/src/libedataserver/e-source-openpgp.h b/src/libedataserver/e-source-openpgp.h
index 4c8091aae..22a07e46f 100644
--- a/src/libedataserver/e-source-openpgp.h
+++ b/src/libedataserver/e-source-openpgp.h
@@ -114,6 +114,9 @@ gboolean e_source_openpgp_get_prefer_inline
void e_source_openpgp_set_prefer_inline
(ESourceOpenPGP *extension,
gboolean prefer_inline);
+gboolean e_source_openpgp_get_locate_keys(ESourceOpenPGP *extension);
+void e_source_openpgp_set_locate_keys(ESourceOpenPGP *extension,
+ gboolean locate_keys);
G_END_DECLS