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)
err = gpgme_data_new (&output);
if (err)
{ {
gpg_error_object (result, err, "Error creating output data object: %s", /* Verify opaque or clearsigned we need an output data object. */
gpg_strerror (err)); err = gpgme_data_new (&output);
goto leave; if (err)
} {
gpg_error_object (result, err,
/* Verify. */ "Error creating output data object: %s",
if (signature) gpg_strerror (err));
{ goto leave;
err = gpgme_op_verify (ctx, signature, input, output); }
err = gpgme_op_verify (ctx, input, 0, 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,14 +2208,17 @@ op_verify (cjson_t request, cjson_t result)
verify_result_to_json (verify_result)); verify_result_to_json (verify_result));
} }
err = make_data_object (result, output, "plaintext", -1); if (output)
output = NULL;
if (err)
{ {
gpg_error_object (result, err, "Plaintext output failed: %s", err = make_data_object (result, output, "plaintext", -1);
gpg_strerror (err)); output = NULL;
goto leave;
if (err)
{
gpg_error_object (result, err, "Plaintext output failed: %s",
gpg_strerror (err));
goto leave;
}
} }
leave: leave: