aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2023-01-25 10:21:39 +0000
committerIngo Klöcker <[email protected]>2023-01-25 10:26:34 +0000
commit5b79b323971cb0794c45791851d85f8a66f0a441 (patch)
treee3f4788ad6c8b581f776863b9011b305bd8a3ceb /tests
parentcore: Support usage of gpgtar for decrypting an encrypted archive (diff)
downloadgpgme-5b79b323971cb0794c45791851d85f8a66f0a441.tar.gz
gpgme-5b79b323971cb0794c45791851d85f8a66f0a441.zip
core: Support usage of gpgtar for verifying a signed archive
* src/gpgme.h.in (gpgme_verify_flags_t): New enum. (GPGME_VERIFY_ARCHIVE): New const. (gpgme_op_verify_ext_start): New func. (gpgme_op_verify_ext): New func. * src/gpgme.def, src/libgpgme.vers: Add new functions. * src/verify.c (gpgme_op_verify_ext_start): New. (gpgme_op_verify_ext): New. (verify_start): Add arg FLAGS. Pass the flags to _gpgme_engine_op_verify. (gpgme_op_verify_start): Call gpgme_op_verify_ext_start with 0 for FLAGS. (gpgme_op_verify): Call gpgme_op_verify_ext with 0 for FLAGS. * src/engine.c, src/engine.h (_gpgme_engine_op_verify): Add arg FLAGS. * src/engine-backend.h (struct engine_ops): Add FLAGS to 'verify'. * src/engine-gpg.c (gpg_verify): Add arg FLAGS. Set use_gpgtar engine flag if GPGME_VERIFY_ARCHIVE flag is set. Check for new enough gpg. Use add_gpg_arg for gpg-only options without a value. Set extra options for gpgtar and pass input data to stdin when using gpgtar. * src/engine-gpgsm.c (gpgsm_verify): Add arg FLAGS. Return error if GPGME_VERIFY_ARCHIVE flag is set. * src/engine-uiserver.c (uiserver_verify): Ditto. * tests/run-verify.c (show_usage): New options --archive, --directory, and --diagnostics. (main): Parse new options. Verify and extract with gpgtar if --archive is given. Set file name of output data to value of --directory option. Print stderr of gpg/gpgtar if --diagnostics is given. -- GnuPG-bug-id: 6342
Diffstat (limited to 'tests')
-rw-r--r--tests/run-verify.c70
1 files changed, 68 insertions, 2 deletions
diff --git a/tests/run-verify.c b/tests/run-verify.c
index f131f491..831c4614 100644
--- a/tests/run-verify.c
+++ b/tests/run-verify.c
@@ -235,6 +235,9 @@ show_usage (int ex)
" --repeat N repeat the operation N times\n"
" --auto-key-retrieve\n"
" --auto-key-import\n"
+ " --archive extract files from a signed archive FILE\n"
+ " --directory DIR extract the files into the directory DIR\n"
+ " --diagnostics print diagnostics\n"
, stderr);
exit (ex);
}
@@ -246,10 +249,13 @@ main (int argc, char **argv)
int last_argc = -1;
const char *s;
gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP;
+ gpgme_verify_flags_t flags = 0;
int print_status = 0;
const char *sender = NULL;
+ const char *directory = NULL;
int auto_key_retrieve = 0;
int auto_key_import = 0;
+ int diagnostics = 0;
int repeats = 1;
int i;
@@ -312,12 +318,30 @@ main (int argc, char **argv)
auto_key_import = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--archive"))
+ {
+ flags |= GPGME_VERIFY_ARCHIVE;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--directory"))
+ {
+ argc--; argv++;
+ if (!argc)
+ show_usage (1);
+ directory = *argv;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--diagnostics"))
+ {
+ diagnostics = 1;
+ argc--; argv++;
+ }
else if (!strncmp (*argv, "--", 2))
show_usage (1);
}
- if (argc < 1 || argc > 2)
+ if (argc < 1 || argc > 2 || (argc > 1 && (flags & GPGME_VERIFY_ARCHIVE)))
show_usage (1);
init_gpgme (protocol);
@@ -330,6 +354,7 @@ main (int argc, char **argv)
gpgme_data_t sig = NULL;
FILE *fp_msg = NULL;
gpgme_data_t msg = NULL;
+ gpgme_data_t out = NULL;
gpgme_verify_result_t result;
if (repeats > 1)
@@ -415,8 +440,48 @@ main (int argc, char **argv)
}
}
- err = gpgme_op_verify (ctx, sig, msg, NULL);
+ if (directory && (flags & GPGME_VERIFY_ARCHIVE))
+ {
+ err = gpgme_data_new (&out);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error allocating data object: %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ err = gpgme_data_set_file_name (out, directory);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting file name (out): %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ }
+
+ err = gpgme_op_verify_ext (ctx, flags, sig, msg, out);
result = gpgme_op_verify_result (ctx);
+
+ if (diagnostics)
+ {
+ gpgme_data_t diag;
+ gpgme_error_t diag_err;
+
+ gpgme_data_new (&diag);
+ diag_err = gpgme_op_getauditlog (ctx, diag, GPGME_AUDITLOG_DIAG);
+ if (diag_err)
+ {
+ fprintf (stderr, PGM ": getting diagnostics failed: %s\n",
+ gpgme_strerror (diag_err));
+ }
+ else
+ {
+ fputs ("Begin Diagnostics:\n", stdout);
+ print_data (diag);
+ fputs ("End Diagnostics.\n", stdout);
+ }
+ gpgme_data_release (diag);
+ }
+
if (result)
print_result (result);
if (err)
@@ -425,6 +490,7 @@ main (int argc, char **argv)
exit (1);
}
+ gpgme_data_release (out);
gpgme_data_release (msg);
gpgme_data_release (sig);