diff options
author | Ingo Klöcker <[email protected]> | 2023-01-19 10:08:42 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2023-01-19 10:08:42 +0000 |
commit | 29cfcd316d1bfc98ca663369a9503cc169dd3447 (patch) | |
tree | f93320b3453b058ded50874fd32f54d0ee7446df /tests | |
parent | core: Support usage of gpgtar for creating a signed archive (diff) | |
download | gpgme-29cfcd316d1bfc98ca663369a9503cc169dd3447.tar.gz gpgme-29cfcd316d1bfc98ca663369a9503cc169dd3447.zip |
core: Support usage of gpgtar for creating an encrypted signed archive
* src/engine-gpg.c (gpg_encrypt_sign): Set use_gpgtar engine flag if
GPGME_ENCRYPT_ARCHIVE mode is set. Check for new enough gpg. Use
add_gpg_arg_with_value for gpg-only options with a value and
add_gpg_arg for gpg-only options without a value. Set extra options for
gpgtar and pass input data to stdin when using gpgtar.
* tests/run-encrypt.c (print_result): Rename to print_encrypt_result.
Print header.
(print_sign_result): New.
(show_usage): New option --sign.
(main): Parse new option. Sign and encrypt --sign is given.
Print results of signing additionally to results of encryption.
--
With this change the gpgme_op_encrypt_sign* functions get support for
creating an encrypted and signed archive from files and/or directories
passed as NUL-separated list in the "plain" data with gpgtar.
GnuPG-bug-id: 6342
Diffstat (limited to 'tests')
-rw-r--r-- | tests/run-encrypt.c | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/tests/run-encrypt.c b/tests/run-encrypt.c index a38dabcb..82a2cead 100644 --- a/tests/run-encrypt.c +++ b/tests/run-encrypt.c @@ -77,10 +77,11 @@ progress_cb (void *opaque, const char *what, int type, int current, int total) static void -print_result (gpgme_encrypt_result_t result) +print_encrypt_result (gpgme_encrypt_result_t result) { gpgme_invalid_key_t invkey; + printf ("\nEncryption results\n"); for (invkey = result->invalid_recipients; invkey; invkey = invkey->next) printf ("Encryption key `%s' not used: %s <%s>\n", nonnull (invkey->fpr), @@ -88,6 +89,30 @@ print_result (gpgme_encrypt_result_t result) } +static void +print_sign_result (gpgme_sign_result_t result) +{ + gpgme_invalid_key_t invkey; + gpgme_new_signature_t sig; + + printf ("\nSigning results\n"); + for (invkey = result->invalid_signers; invkey; invkey = invkey->next) + printf ("Signing key `%s' not used: %s <%s>\n", + nonnull (invkey->fpr), + gpg_strerror (invkey->reason), gpg_strsource (invkey->reason)); + + for (sig = result->signatures; sig; sig = sig->next) + { + printf ("Key fingerprint: %s\n", nonnull (sig->fpr)); + printf ("Signature type : %d\n", sig->type); + printf ("Public key algo: %d\n", sig->pubkey_algo); + printf ("Hash algo .....: %d\n", sig->hash_algo); + printf ("Creation time .: %ld\n", sig->timestamp); + printf ("Sig class .....: 0x%u\n", sig->sig_class); + } +} + + static int show_usage (int ex) @@ -95,6 +120,7 @@ show_usage (int ex) fputs ("usage: " PGM " [options] FILE\n\n" "Options:\n" " --verbose run in verbose mode\n" + " --sign sign data before encryption\n" " --status print status lines from the backend\n" " --progress print progress info\n" " --openpgp use the OpenPGP protocol (default)\n" @@ -122,7 +148,8 @@ main (int argc, char **argv) gpgme_ctx_t ctx; gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; gpgme_data_t in, out; - gpgme_encrypt_result_t result; + gpgme_encrypt_result_t encrypt_result; + gpgme_sign_result_t sign_result; int print_status = 0; int print_progress = 0; int use_loopback = 0; @@ -135,6 +162,7 @@ main (int argc, char **argv) gpgme_off_t offset; int no_symkey_cache = 0; int diagnostics = 0; + int sign = 0; if (argc) { argc--; argv++; } @@ -157,6 +185,11 @@ main (int argc, char **argv) verbose = 1; argc--; argv++; } + else if (!strcmp (*argv, "--sign")) + { + sign = 1; + argc--; argv++; + } else if (!strcmp (*argv, "--status")) { print_status = 1; @@ -336,9 +369,12 @@ main (int argc, char **argv) err = gpgme_data_new (&out); fail_if_err (err); - err = gpgme_op_encrypt_ext (ctx, keycount ? keys : NULL, keystring, - flags, in, out); - result = gpgme_op_encrypt_result (ctx); + if (sign) + err = gpgme_op_encrypt_sign_ext (ctx, keycount ? keys : NULL, keystring, + flags, in, out); + else + err = gpgme_op_encrypt_ext (ctx, keycount ? keys : NULL, keystring, + flags, in, out); if (diagnostics) { @@ -361,8 +397,12 @@ main (int argc, char **argv) gpgme_data_release (diag); } - if (result) - print_result (result); + sign_result = gpgme_op_sign_result (ctx); + if (sign_result) + print_sign_result (sign_result); + encrypt_result = gpgme_op_encrypt_result (ctx); + if (encrypt_result) + print_encrypt_result (encrypt_result); if (err) { fprintf (stderr, PGM ": encrypting failed: %s\n", gpg_strerror (err)); |