json: Fix detached verify

* src/gpgme-json.c (op_verify): Only create output and
use it for clearsigned and opaque signed.

--
Just passing output to gpgme_op_verify changes the behavior to
no longer do a verify of the signature.
This commit is contained in:
Andre Heinecke 2018-08-29 14:32:36 +02:00
parent f7e5ae7f16
commit 1420c3bd68
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C

View File

@ -2173,24 +2173,24 @@ op_verify (cjson_t request, cjson_t result)
if (err && err != gpg_error (GPG_ERR_NO_DATA)) if (err && err != gpg_error (GPG_ERR_NO_DATA))
goto leave; goto leave;
/* Create an output data object. */ if (!signature)
{
/* Verify opaque or clearsigned we need an output data object. */
err = gpgme_data_new (&output); err = gpgme_data_new (&output);
if (err) if (err)
{ {
gpg_error_object (result, err, "Error creating output data object: %s", gpg_error_object (result, err,
"Error creating output data object: %s",
gpg_strerror (err)); gpg_strerror (err));
goto leave; goto leave;
} }
err = gpgme_op_verify (ctx, input, 0, output);
/* Verify. */
if (signature)
{
err = gpgme_op_verify (ctx, signature, input, output);
} }
else else
{ {
err = gpgme_op_verify (ctx, input, 0, output); err = gpgme_op_verify (ctx, signature, input, NULL);
} }
if (err) if (err)
{ {
gpg_error_object (result, err, "Verify failed: %s", gpg_strerror (err)); gpg_error_object (result, err, "Verify failed: %s", gpg_strerror (err));
@ -2208,6 +2208,8 @@ op_verify (cjson_t request, cjson_t result)
verify_result_to_json (verify_result)); verify_result_to_json (verify_result));
} }
if (output)
{
err = make_data_object (result, output, "plaintext", -1); err = make_data_object (result, output, "plaintext", -1);
output = NULL; output = NULL;
@ -2217,6 +2219,7 @@ op_verify (cjson_t request, cjson_t result)
gpg_strerror (err)); gpg_strerror (err));
goto leave; goto leave;
} }
}
leave: leave:
release_context (ctx); release_context (ctx);