2008-11-18 11:12:36 +00:00
|
|
|
/* cms-decrypt.c - Helper to debug the decrupt operation.
|
2018-11-16 12:27:33 +00:00
|
|
|
* Copyright (C) 2008 g10 Code GmbH
|
|
|
|
*
|
|
|
|
* This file is part of GPGME.
|
|
|
|
*
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GPGME is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, see <https://gnu.org/licenses/>.
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*/
|
2008-11-18 11:12:36 +00:00
|
|
|
|
|
|
|
/* We need to include config.h so that we know whether we are building
|
|
|
|
with large file system (LFS) support. */
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gpgme.h>
|
|
|
|
|
|
|
|
#define PGM "cms-decrypt"
|
|
|
|
|
|
|
|
#include "t-support.h"
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
nonnull (const char *s)
|
|
|
|
{
|
|
|
|
return s? s :"[none]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-16 12:27:33 +00:00
|
|
|
int
|
2008-11-18 11:12:36 +00:00
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
gpgme_error_t err;
|
|
|
|
gpgme_ctx_t ctx;
|
|
|
|
gpgme_data_t in, out;
|
|
|
|
gpgme_decrypt_result_t result;
|
|
|
|
gpgme_recipient_t recp;
|
|
|
|
|
|
|
|
if (argc)
|
|
|
|
{ argc--; argv++; }
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
{
|
|
|
|
fputs ("usage: " PGM " FILE\n", stderr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
init_gpgme (GPGME_PROTOCOL_CMS);
|
|
|
|
|
|
|
|
err = gpgme_new (&ctx);
|
|
|
|
fail_if_err (err);
|
|
|
|
gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
|
|
|
|
|
|
|
|
|
|
|
|
err = gpgme_data_new_from_file (&in, *argv, 1);
|
|
|
|
fail_if_err (err);
|
|
|
|
|
|
|
|
err = gpgme_data_new (&out);
|
|
|
|
fail_if_err (err);
|
|
|
|
|
|
|
|
err = gpgme_op_decrypt (ctx, in, out);
|
|
|
|
printf ("gpgme_op_decrypt: %s <%s> (%u)\n",
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
gpgme_strerror (err), gpgme_strsource (err), err);
|
2008-11-18 11:12:36 +00:00
|
|
|
result = gpgme_op_decrypt_result (ctx);
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
fputs (PGM ": error: decryption result missing\n", stderr);
|
|
|
|
exit (1);
|
|
|
|
}
|
2018-11-16 12:27:33 +00:00
|
|
|
|
|
|
|
printf ("unsupported_algorithm: %s\n",
|
2008-11-18 11:12:36 +00:00
|
|
|
nonnull (result->unsupported_algorithm));
|
|
|
|
printf ("wrong_key_usage: %u\n", result->wrong_key_usage);
|
|
|
|
printf ("file_name: %s\n", nonnull (result->file_name));
|
|
|
|
for (recp = result->recipients; recp; recp = recp->next)
|
|
|
|
{
|
|
|
|
printf ("recipient.status: %s <%s> (%u)\n",
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
gpgme_strerror (recp->status), gpgme_strsource (recp->status),
|
2008-11-18 11:12:36 +00:00
|
|
|
recp->status);
|
|
|
|
printf ("recipient.pkalgo: %d\n", recp->pubkey_algo);
|
|
|
|
printf ("recipient.keyid : %s\n", nonnull (recp->keyid));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
{
|
|
|
|
puts ("plaintext:");
|
|
|
|
print_data (out);
|
|
|
|
gpgme_data_release (out);
|
|
|
|
}
|
|
|
|
|
|
|
|
gpgme_data_release (in);
|
|
|
|
|
|
|
|
gpgme_release (ctx);
|
|
|
|
return 0;
|
|
|
|
}
|