aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpgme.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-11-15 09:29:48 +0000
committerWerner Koch <[email protected]>2016-11-15 09:34:13 +0000
commit7659d42468b604db2936b021425683f407eba4a7 (patch)
tree71ee551bdd948598d0e9015ae2ec10366c0be373 /src/gpgme.c
parentcore: Add public function gpgme_get_ctx_flag. (diff)
downloadgpgme-7659d42468b604db2936b021425683f407eba4a7.tar.gz
gpgme-7659d42468b604db2936b021425683f407eba4a7.zip
core: Implement context flag "override-session-key".
* src/gpgme.c (gpgme_set_ctx_flag): Add flags "export-session-key" and "override-session-key". (gpgme_get_ctx_flag): Ditto. (gpgme_set_export_session_keys): Remove. (gpgme_get_export_session_keys): Remove. * src/gpgme.def, src/libgpgme.vers: Remove them. * src/context.h (struct gpgme_context): Add field override_session_key. * src/decrypt-verify.c (decrypt_verify_start): Pass override_session_key value to the engine. * src/decrypt.c (decrypt_start): Ditto. * src/engine.c (_gpgme_engine_op_decrypt): Ditto. (_gpgme_engine_op_decrypt_verify): Ditto. * src/engine-backend.h (struct engine_ops): Extend DECRYPT and DECRYPT_VERIFY_START with override_session_key. * src/engine-uiserver.c (_uiserver_decrypt): Add stub arg override_session_key. (uiserver_decrypt): Ditto. (uiserver_decrypt_verify): Ditto. * src/engine-gpgsm.c (gpgsm_decrypt): Ditto. * src/engine-gpg.c (gpg_decrypt): Add arg override_session_key and set corresponding gpg option. * tests/run-decrypt.c (print_result): Print the session key if available. (main): Add options --export-session-key and --override-session-key. -- To keep the number of context manipulation functions at bay, this patches removes the just added gpgme_set_export_session_keys and gpgme_get_export_session_keys by flags for the generic context function. The patch also implements the --override-session-key feature. GnuPG-bug-id: 2754 Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/gpgme.c')
-rw-r--r--src/gpgme.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/gpgme.c b/src/gpgme.c
index 32abc282..1a10fd91 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -247,6 +247,7 @@ gpgme_release (gpgme_ctx_t ctx)
free (ctx->signers);
free (ctx->lc_ctype);
free (ctx->lc_messages);
+ free (ctx->override_session_key);
_gpgme_engine_info_release (ctx->engine_info);
ctx->engine_info = NULL;
DESTROY_LOCK (ctx->lock);
@@ -515,6 +516,17 @@ gpgme_set_ctx_flag (gpgme_ctx_t ctx, const char *name, const char *value)
{
ctx->raw_description = abool;
}
+ else if (!strcmp (name, "export-session-key"))
+ {
+ ctx->export_session_keys = abool;
+ }
+ else if (!strcmp (name, "override-session-key"))
+ {
+ free (ctx->override_session_key);
+ ctx->override_session_key = strdup (value);
+ if (!ctx->override_session_key)
+ err = gpg_error_from_syserror ();
+ }
else
err = gpg_error (GPG_ERR_UNKNOWN_NAME);
@@ -526,7 +538,7 @@ gpgme_set_ctx_flag (gpgme_ctx_t ctx, const char *name, const char *value)
* of valid names. If the NAME is unknown NULL is returned. For a
* boolean flag an empty string is returned for False and the string
* "1" for True; thus either atoi or a simple string test can be
- * used. */
+ * used. */
const char *
gpgme_get_ctx_flag (gpgme_ctx_t ctx, const char *name)
{
@@ -540,35 +552,19 @@ gpgme_get_ctx_flag (gpgme_ctx_t ctx, const char *name)
{
return ctx->raw_description? "1":"";
}
+ else if (!strcmp (name, "export-session-key"))
+ {
+ return ctx->export_session_keys? "1":"";
+ }
+ else if (!strcmp (name, "override-session-key"))
+ {
+ return ctx->override_session_key? ctx->override_session_key : "";
+ }
else
return NULL;
}
-/* Enable or disable the exporting session keys upon decryption. */
-void
-gpgme_set_export_session_keys (gpgme_ctx_t ctx, int export_session_keys)
-{
- TRACE2 (DEBUG_CTX, "gpgme_set_export_session_keys", ctx, "export_session_keys=%i (%s)",
- export_session_keys, export_session_keys ? "yes" : "no");
-
- if (!ctx)
- return;
-
- ctx->export_session_keys = !!export_session_keys;
-}
-
-
-/* Return whether this context will export session keys upon decryption. */
-int
-gpgme_get_export_session_keys (gpgme_ctx_t ctx)
-{
- TRACE2 (DEBUG_CTX, "gpgme_get_export_session_keys", ctx, "ctx->export_session_keys=%i (%s)",
- ctx->export_session_keys, ctx->export_session_keys ? "yes" : "no");
- return ctx->export_session_keys;
-}
-
-
/* Enable or disable the use of the special textmode. Textmode is for
example used for the RFC2015 signatures; note that the updated RFC
3156 mandates that the MUA does some preparations so that textmode