aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run-decrypt.c26
-rw-r--r--tests/run-encrypt.c187
-rw-r--r--tests/run-sign.c69
-rw-r--r--tests/run-verify.c70
-rw-r--r--tests/t-engine-info.c1
5 files changed, 302 insertions, 51 deletions
diff --git a/tests/run-decrypt.c b/tests/run-decrypt.c
index cf719925..ee49ead6 100644
--- a/tests/run-decrypt.c
+++ b/tests/run-decrypt.c
@@ -91,6 +91,8 @@ show_usage (int ex)
" --unwrap remove only the encryption layer\n"
" --large-buffers use large I/O buffer\n"
" --sensitive mark data objects as sensitive\n"
+ " --archive extract files from an encrypted archive\n"
+ " --directory DIR extract the files into the directory DIR\n"
" --diagnostics print diagnostics\n"
, stderr);
exit (ex);
@@ -113,6 +115,7 @@ main (int argc, char **argv)
int export_session_key = 0;
const char *override_session_key = NULL;
const char *request_origin = NULL;
+ const char *directory = NULL;
int no_symkey_cache = 0;
int ignore_mdc_error = 0;
int raw_output = 0;
@@ -205,6 +208,19 @@ main (int argc, char **argv)
raw_output = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--archive"))
+ {
+ flags |= GPGME_DECRYPT_ARCHIVE;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--directory"))
+ {
+ argc--; argv++;
+ if (!argc)
+ show_usage (1);
+ directory = *argv;
+ argc--; argv++;
+ }
else if (!strncmp (*argv, "--", 2))
show_usage (1);
@@ -302,6 +318,16 @@ main (int argc, char **argv)
gpgme_strerror (err));
exit (1);
}
+ if (directory && (flags & GPGME_DECRYPT_ARCHIVE))
+ {
+ 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);
+ }
+ }
if (large_buffers)
{
err = gpgme_data_set_flag (out, "io-buffer-size", "1000000");
diff --git a/tests/run-encrypt.c b/tests/run-encrypt.c
index 7b0e29a7..2d1c6e9d 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"
@@ -107,6 +133,9 @@ show_usage (int ex)
" --no-symkey-cache disable the use of that cache\n"
" --wrap assume input is valid OpenPGP message\n"
" --symmetric encrypt symmetric (OpenPGP only)\n"
+ " --archive encrypt given file or directory into an archive\n"
+ " --directory DIR switch to directory DIR before encrypting into an archive\n"
+ " --diagnostics print diagnostics\n"
, stderr);
exit (ex);
}
@@ -120,7 +149,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;
@@ -128,10 +158,13 @@ main (int argc, char **argv)
gpgme_key_t keys[10+1];
int keycount = 0;
char *keystring = NULL;
+ const char *directory = NULL;
int i;
gpgme_encrypt_flags_t flags = GPGME_ENCRYPT_ALWAYS_TRUST;
gpgme_off_t offset;
int no_symkey_cache = 0;
+ int diagnostics = 0;
+ int sign = 0;
if (argc)
{ argc--; argv++; }
@@ -154,6 +187,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;
@@ -225,6 +263,24 @@ main (int argc, char **argv)
no_symkey_cache = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--archive"))
+ {
+ flags |= GPGME_ENCRYPT_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);
@@ -269,57 +325,100 @@ main (int argc, char **argv)
}
keys[i] = NULL;
- err = gpgme_data_new_from_file (&in, *argv, 1);
- if (err)
- {
- fprintf (stderr, PGM ": error reading `%s': %s\n",
- *argv, gpg_strerror (err));
- exit (1);
- }
- offset = gpgme_data_seek (in, 0, SEEK_END);
- if (offset == (gpgme_off_t)(-1))
+ if (flags & GPGME_ENCRYPT_ARCHIVE)
{
- err = gpg_error_from_syserror ();
- fprintf (stderr, PGM ": error seeking `%s': %s\n",
- *argv, gpg_strerror (err));
- exit (1);
+ const char *path = *argv;
+ err = gpgme_data_new_from_mem (&in, path, strlen (path), 0);
+ fail_if_err (err);
+ if (directory)
+ {
+ err = gpgme_data_set_file_name (in, directory);
+ fail_if_err (err);
+ }
}
- if (gpgme_data_seek (in, 0, SEEK_SET) == (gpgme_off_t)(-1))
+ else
{
- err = gpg_error_from_syserror ();
- fprintf (stderr, PGM ": error seeking `%s': %s\n",
- *argv, gpg_strerror (err));
- exit (1);
- }
- {
- char numbuf[50];
- char *p;
-
- p = numbuf + sizeof numbuf;
- *--p = 0;
- do
- {
- *--p = '0' + (offset % 10);
- offset /= 10;
- }
- while (offset);
- err = gpgme_data_set_flag (in, "size-hint", p);
- if (err)
+ err = gpgme_data_new_from_file (&in, *argv, 1);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error reading `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
+ offset = gpgme_data_seek (in, 0, SEEK_END);
+ if (offset == (gpgme_off_t)(-1))
+ {
+ err = gpg_error_from_syserror ();
+ fprintf (stderr, PGM ": error seeking `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
+ if (gpgme_data_seek (in, 0, SEEK_SET) == (gpgme_off_t)(-1))
+ {
+ err = gpg_error_from_syserror ();
+ fprintf (stderr, PGM ": error seeking `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
{
- fprintf (stderr, PGM ": error setting size-hint for `%s': %s\n",
- *argv, gpg_strerror (err));
- exit (1);
+ char numbuf[50];
+ char *p;
+
+ p = numbuf + sizeof numbuf;
+ *--p = 0;
+ do
+ {
+ *--p = '0' + (offset % 10);
+ offset /= 10;
+ }
+ while (offset);
+ err = gpgme_data_set_flag (in, "size-hint", p);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting size-hint for `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
}
- }
+ }
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 (result)
- print_result (result);
+ 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)
+ {
+ 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);
+ }
+
+ 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));
diff --git a/tests/run-sign.c b/tests/run-sign.c
index 37211d72..84d7c070 100644
--- a/tests/run-sign.c
+++ b/tests/run-sign.c
@@ -87,6 +87,9 @@ show_usage (int ex)
" --sender MBOX use MBOX as sender address\n"
" --include-key-block use this option with gpg\n"
" --clear create a clear text signature\n"
+ " --archive create a signed archive with the given file or directory\n"
+ " --directory DIR switch to directory DIR before creating the archive\n"
+ " --diagnostics print diagnostics\n"
, stderr);
exit (ex);
}
@@ -99,6 +102,7 @@ main (int argc, char **argv)
gpgme_error_t err;
gpgme_ctx_t ctx;
const char *key_string = NULL;
+ const char *directory = NULL;
gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP;
gpgme_sig_mode_t sigmode = GPGME_SIG_MODE_NORMAL;
gpgme_data_t in, out;
@@ -106,6 +110,7 @@ main (int argc, char **argv)
int print_status = 0;
int use_loopback = 0;
int include_key_block = 0;
+ int diagnostics = 0;
const char *sender = NULL;
const char *s;
@@ -178,6 +183,24 @@ main (int argc, char **argv)
sigmode = GPGME_SIG_MODE_CLEAR;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--archive"))
+ {
+ sigmode = GPGME_SIG_MODE_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);
@@ -236,12 +259,26 @@ main (int argc, char **argv)
}
}
- err = gpgme_data_new_from_file (&in, *argv, 1);
- if (err)
+ if (sigmode == GPGME_SIG_MODE_ARCHIVE)
{
- fprintf (stderr, PGM ": error reading `%s': %s\n",
- *argv, gpg_strerror (err));
- exit (1);
+ const char *path = *argv;
+ err = gpgme_data_new_from_mem (&in, path, strlen (path), 0);
+ fail_if_err (err);
+ if (directory)
+ {
+ err = gpgme_data_set_file_name (in, directory);
+ fail_if_err (err);
+ }
+ }
+ else
+ {
+ err = gpgme_data_new_from_file (&in, *argv, 1);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error reading `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
}
err = gpgme_data_new (&out);
@@ -249,6 +286,28 @@ main (int argc, char **argv)
err = gpgme_op_sign (ctx, in, out, sigmode);
result = gpgme_op_sign_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, sigmode);
if (err)
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);
diff --git a/tests/t-engine-info.c b/tests/t-engine-info.c
index 3f8d0037..1a351391 100644
--- a/tests/t-engine-info.c
+++ b/tests/t-engine-info.c
@@ -133,6 +133,7 @@ main (int argc, char **argv )
"dirmngr-name",
"pinentry-name",
"gpg-wks-client-name",
+ "gpgtar-name",
NULL };
const char *s;
int i;