aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2024-10-29 10:59:51 +0000
committerWerner Koch <[email protected]>2024-10-29 11:00:11 +0000
commita304ec0ede937e21df5b4a311cbaf8d89f13ef59 (patch)
tree846889cf9b17748eef4977269a36e060d7e9d1fd /src
parentcore: Add new helper _gpgme_strtokenize. (diff)
downloadgpgme-a304ec0ede937e21df5b4a311cbaf8d89f13ef59.tar.gz
gpgme-a304ec0ede937e21df5b4a311cbaf8d89f13ef59.zip
core: New context flags "known-notations".
* src/gpgme.c (gpgme_set_ctx_flag): Add "known-notations". (gpgme_get_ctx_flag): Ditto. (gpgme_release): Free variable. * src/context.h (struct gpgme_context): Add "known_notations". * src/engine-gpg.c (struct engine_gpg): Add "known_notations". (gpg_release): Free variable. (gpg_set_engine_flags): Set variable. (add_known_notations): New. (gpg_decrypt, gpg_verify): Call function. * tests/run-decrypt.c (main): Add option --known-notations. * tests/run-verify.c (main): Ditto. -- GnuPG-bug-id: 4060
Diffstat (limited to 'src')
-rw-r--r--src/context.h4
-rw-r--r--src/engine-gpg.c38
-rw-r--r--src/gpgme.c12
3 files changed, 54 insertions, 0 deletions
diff --git a/src/context.h b/src/context.h
index 9cfd8653..ba9b83ef 100644
--- a/src/context.h
+++ b/src/context.h
@@ -192,6 +192,10 @@ struct gpgme_context
/* The optional import options. */
char *import_options;
+ /* A comma or space delimited list to create gpg --known-notations
+ * options. */
+ char *known_notations;
+
/* The operation data hooked into the context. */
ctx_op_data_t op_data;
diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index 318c0e35..0768ea74 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -144,6 +144,7 @@ struct engine_gpg
char request_origin[10];
char *auto_key_locate;
char *trust_model;
+ char **known_notations;
struct {
unsigned int use_gpgtar : 1;
@@ -577,6 +578,7 @@ gpg_release (void *engine)
free (gpg->cmd.keyword);
free (gpg->auto_key_locate);
free (gpg->trust_model);
+ free (gpg->known_notations);
gpgme_data_release (gpg->override_session_key);
gpgme_data_release (gpg->diagnostics);
@@ -763,6 +765,18 @@ gpg_set_engine_flags (void *engine, const gpgme_ctx_t ctx)
ctx->trust_model, NULL);
}
+ if (ctx->known_notations)
+ {
+ free (gpg->known_notations);
+ gpg->known_notations = _gpgme_strtokenize (ctx->known_notations,
+ " \t,", 1);
+ /* Fixme: We have no way to return an error. However in this
+ * case one would just get the usual verification error as if
+ * that option has not been used. I think this is acceptable
+ * for now. */
+ }
+
+
gpg->flags.no_symkey_cache = (ctx->no_symkey_cache
&& have_gpg_version (gpg, "2.2.7"));
gpg->flags.offline = (ctx->offline && have_gpg_version (gpg, "2.1.23"));
@@ -1892,6 +1906,24 @@ add_input_size_hint (engine_gpg_t gpg, gpgme_data_t data)
}
+/* Add the --known_notations option if requested. */
+static gpgme_error_t
+add_known_notations (engine_gpg_t gpg)
+{
+ gpg_error_t err = 0;
+ int i;
+ const char *s;
+
+ if (gpg->known_notations)
+ {
+ for (i=0; !err && (s=gpg->known_notations[i]); i++)
+ if (*s)
+ err = add_gpg_arg_with_value (gpg, "--known-notation=", s, 0);
+ }
+ return err;
+}
+
+
static gpgme_error_t
gpg_decrypt (void *engine,
gpgme_decrypt_flags_t flags,
@@ -1929,6 +1961,9 @@ gpg_decrypt (void *engine,
if (!err && gpg->flags.auto_key_import)
err = add_gpg_arg (gpg, "--auto-key-import");
+ if (!err)
+ err = add_known_notations (gpg);
+
if (!err && override_session_key && *override_session_key)
{
if (have_gpg_version (gpg, "2.1.16") && !gpg->flags.use_gpgtar)
@@ -3927,6 +3962,9 @@ gpg_verify (void *engine, gpgme_verify_flags_t flags, gpgme_data_t sig,
if (!err && ctx->auto_key_retrieve)
err = add_gpg_arg (gpg, "--auto-key-retrieve");
+ if (!err)
+ err = add_known_notations (gpg);
+
if (err)
;
else if (gpg->flags.use_gpgtar)
diff --git a/src/gpgme.c b/src/gpgme.c
index 086e680b..4f63cc4f 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -262,6 +262,7 @@ gpgme_release (gpgme_ctx_t ctx)
free (ctx->key_origin);
free (ctx->import_filter);
free (ctx->import_options);
+ free (ctx->known_notations);
_gpgme_engine_info_release (ctx->engine_info);
ctx->engine_info = NULL;
DESTROY_LOCK (ctx->lock);
@@ -623,6 +624,13 @@ gpgme_set_ctx_flag (gpgme_ctx_t ctx, const char *name, const char *value)
{
ctx->proc_all_sigs = abool;
}
+ else if (!strcmp (name, "known-notations"))
+ {
+ free (ctx->known_notations);
+ ctx->known_notations = strdup (value);
+ if (!ctx->known_notations)
+ err = gpg_error_from_syserror ();
+ }
else
err = gpg_error (GPG_ERR_UNKNOWN_NAME);
@@ -716,6 +724,10 @@ gpgme_get_ctx_flag (gpgme_ctx_t ctx, const char *name)
{
return ctx->proc_all_sigs? "1":"";
}
+ else if (!strcmp (name, "known-notations"))
+ {
+ return ctx->known_notations? ctx->known_notations: "";
+ }
else
return NULL;
}