diff --git a/common/t-exechelp.c b/common/t-exechelp.c
index 19079d331..3a47dc8ef 100644
--- a/common/t-exechelp.c
+++ b/common/t-exechelp.c
@@ -1,187 +1,188 @@
/* t-exechelp.c - Module test for exechelp.c
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
* GnuPG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GnuPG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see .
*/
#include
#include
#include
#include
#include
#include
#include "util.h"
#include "exechelp.h"
static int verbose;
static void
print_open_fds (int *array)
{
int n;
+ if (!verbose)
+ return;
+
for (n=0; array[n] != -1; n++)
;
printf ("open file descriptors: %d", n);
- if (verbose)
- {
- putchar (' ');
- putchar (' ');
- putchar ('(');
- for (n=0; array[n] != -1; n++)
- printf ("%d%s", array[n], array[n+1] == -1?"":" ");
- putchar (')');
- }
+ putchar (' ');
+ putchar (' ');
+ putchar ('(');
+ for (n=0; array[n] != -1; n++)
+ printf ("%d%s", array[n], array[n+1] == -1?"":" ");
+ putchar (')');
putchar ('\n');
}
static int *
xget_all_open_fds (void)
{
int *array;
array = get_all_open_fds ();
if (!array)
{
fprintf (stderr, "%s:%d: get_all_open_fds failed: %s\n",
__FILE__, __LINE__, strerror (errno));
exit (1);
}
return array;
}
/* That is a very crude test. To do a proper test we would need to
fork a test process and best return information by some other means
than file descriptors. */
static void
test_close_all_fds (void)
{
int max_fd = get_max_fds ();
int *array;
int fd;
int initial_count, count, n;
#if 0
char buffer[100];
snprintf (buffer, sizeof buffer, "/bin/ls -l /proc/%d/fd", (int)getpid ());
system (buffer);
#endif
- printf ("max. file descriptors: %d\n", max_fd);
+ if (verbose)
+ printf ("max. file descriptors: %d\n", max_fd);
array = xget_all_open_fds ();
print_open_fds (array);
for (initial_count=n=0; array[n] != -1; n++)
initial_count++;
free (array);
/* Some dups to get more file descriptors and close one. */
dup (1);
dup (1);
fd = dup (1);
dup (1);
close (fd);
array = xget_all_open_fds ();
if (verbose)
print_open_fds (array);
for (count=n=0; array[n] != -1; n++)
count++;
if (count != initial_count+3)
{
fprintf (stderr, "%s:%d: dup or close failed\n",
__FILE__, __LINE__);
exit (1);
}
free (array);
/* Close the non standard ones. */
close_all_fds (3, NULL);
/* Get a list to check whether they are all closed. */
array = xget_all_open_fds ();
if (verbose)
print_open_fds (array);
for (count=n=0; array[n] != -1; n++)
count++;
if (count > initial_count)
{
fprintf (stderr, "%s:%d: not all files were closed\n",
__FILE__, __LINE__);
exit (1);
}
initial_count = count;
free (array);
/* Now let's check the realloc we use. We do this and the next
tests only if we are allowed to open enought descriptors. */
if (get_max_fds () > 32)
{
int except[] = { 20, 23, 24, -1 };
for (n=initial_count; n < 31; n++)
dup (1);
array = xget_all_open_fds ();
if (verbose)
print_open_fds (array);
free (array);
for (n=0; n < 5; n++)
{
dup (1);
array = xget_all_open_fds ();
if (verbose)
print_open_fds (array);
free (array);
}
/* Check whether the except list works. */
close_all_fds (3, except);
array = xget_all_open_fds ();
if (verbose)
print_open_fds (array);
for (count=n=0; array[n] != -1; n++)
count++;
free (array);
if (count != initial_count + DIM(except)-1)
{
fprintf (stderr, "%s:%d: close_all_fds failed\n",
__FILE__, __LINE__);
exit (1);
}
}
}
int
main (int argc, char **argv)
{
if (argc)
{ argc--; argv++; }
if (argc && !strcmp (argv[0], "--verbose"))
{
verbose = 1;
argc--; argv++;
}
test_close_all_fds ();
return 0;
}
diff --git a/common/t-session-env.c b/common/t-session-env.c
index 46c655229..c5c7b0e3b 100644
--- a/common/t-session-env.c
+++ b/common/t-session-env.c
@@ -1,293 +1,304 @@
/* t-session-env.c - Module test for session-env.c
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
* GnuPG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GnuPG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see .
*/
#include
#include
#include
#include
#include
#include "util.h"
#include "session-env.h"
#define pass() do { ; } while(0)
#define fail(e) do { fprintf (stderr, "%s:%d: function failed: %s\n", \
__FILE__,__LINE__, gpg_strerror (e)); \
exit (1); \
} while(0)
static int verbose;
static void
listall (session_env_t se)
{
int iterator = 0;
const char *name, *value;
int def;
if (verbose)
printf ("environment of %p\n", se);
while ( (name = session_env_listenv (se, &iterator, &value, &def)) )
if (verbose)
printf (" %s%s=%s\n", def? "[def] ":" ", name, value);
}
static void
show_stdnames (void)
{
const char *name, *assname;
int iterator = 0;
+ int count;
- printf ("Known envvars:");
+ printf (" > Known envvars:");
+ count = 20;
while ((name = session_env_list_stdenvnames (&iterator, &assname)))
{
+ if (count > 60)
+ {
+ printf ("\n >");
+ count = 7;
+ }
printf ( " %s", name);
+ count += strlen (name) + 1;
if (assname)
- printf ( "(%s)", assname);
+ {
+ printf ( "(%s)", assname);
+ count += strlen (assname) + 2;
+ }
}
putchar('\n');
}
static void
test_all (void)
{
gpg_error_t err;
session_env_t se_0, se;
const char *s, *s2;
int idx;
se_0 = session_env_new ();
if (!se_0)
fail (gpg_error_from_syserror ());
se = session_env_new ();
if (!se)
fail (gpg_error_from_syserror ());
err = session_env_putenv (se, NULL);
if (gpg_err_code (err) != GPG_ERR_INV_VALUE)
fail (err);
err = session_env_putenv (se, "");
if (gpg_err_code (err) != GPG_ERR_INV_VALUE)
fail (err);
err = session_env_putenv (se, "=");
if (gpg_err_code (err) != GPG_ERR_INV_VALUE)
fail (err);
/* Delete some nonexistant variables. */
err = session_env_putenv (se, "A");
if (err)
fail (err);
err = session_env_putenv (se, "a");
if (err)
fail (err);
err = session_env_putenv (se, "_aaaa aaaaaasssssssssssss\nddd");
if (err)
fail (err);
/* Create a few variables. */
err = session_env_putenv (se, "EMPTY=");
if (err)
fail (err);
err = session_env_putenv (se, "foo=value_of_foo");
if (err)
fail (err);
err = session_env_putenv (se, "bar=the value_of_bar");
if (err)
fail (err);
err = session_env_putenv (se, "baz=this-is-baz");
if (err)
fail (err);
err = session_env_putenv (se, "BAZ=this-is-big-baz");
if (err)
fail (err);
listall (se);
/* Update one. */
err = session_env_putenv (se, "baz=this-is-another-baz");
if (err)
fail (err);
listall (se);
/* Delete one. */
err = session_env_putenv (se, "bar");
if (err)
fail (err);
listall (se);
/* Insert a new one. */
err = session_env_putenv (se, "FOO=value_of_foo");
if (err)
fail (err);
listall (se);
/* Retrieve a default one. */
s = session_env_getenv_or_default (se, "HOME", NULL);
if (!s)
{
fprintf (stderr, "failed to get default of HOME\n");
exit (1);
}
s = session_env_getenv (se, "HOME");
if (s)
fail(0); /* This is a default value, thus we should not see it. */
s = session_env_getenv_or_default (se, "HOME", NULL);
if (!s)
fail(0); /* But here we should see it. */
/* Add a few more. */
err = session_env_putenv (se, "X1=A value");
if (err)
fail (err);
err = session_env_putenv (se, "X2=Another value");
if (err)
fail (err);
err = session_env_putenv (se, "X3=A value");
if (err)
fail (err);
listall (se);
/* Check that we can overwrite a default value. */
err = session_env_putenv (se, "HOME=/this/is/my/new/home");
if (err)
fail (err);
/* And that we get this string back. */
s = session_env_getenv (se, "HOME");
if (!s)
fail (0);
if (strcmp (s, "/this/is/my/new/home"))
fail (0);
/* A new get default should return the very same string. */
s2 = session_env_getenv_or_default (se, "HOME", NULL);
if (!s2)
fail (0);
if (s2 != s)
fail (0);
listall (se);
/* Check that the other object is clean. */
{
int iterator = 0;
if (session_env_listenv (se_0, &iterator, NULL, NULL))
fail (0);
}
session_env_release (se);
/* Use a new session for quick mass test. */
se = session_env_new ();
if (!se)
fail (gpg_error_from_syserror ());
/* Create. */
for (idx=0; idx < 500; idx++)
{
char buf[100];
snprintf (buf, sizeof buf, "FOO_%d=Value for %x", idx, idx);
err = session_env_putenv (se, buf);
if (err)
fail (err);
}
err = session_env_setenv (se, "TEST1", "value1");
if (err)
fail (err);
err = session_env_setenv (se, "TEST1", "value1-updated");
if (err)
fail (err);
listall (se);
/* Delete all. */
for (idx=0; idx < 500; idx++)
{
char buf[100];
snprintf (buf, sizeof buf, "FOO_%d", idx);
err = session_env_putenv (se, buf);
if (err)
fail (err);
}
err = session_env_setenv (se, "TEST1", NULL);
if (err)
fail (err);
/* Check that all are deleted. */
{
int iterator = 0;
if (session_env_listenv (se, &iterator, NULL, NULL))
fail (0);
}
/* Add a few strings again. */
for (idx=0; idx < 500; idx++)
{
char buf[100];
if (!(idx % 10))
{
if ( !(idx % 3))
snprintf (buf, sizeof buf, "FOO_%d=", idx);
else
snprintf (buf, sizeof buf, "FOO_%d=new value for %x", idx, idx);
err = session_env_putenv (se, buf);
if (err)
fail (err);
}
}
listall (se);
session_env_release (se);
session_env_release (se_0);
}
int
main (int argc, char **argv)
{
if (argc)
{ argc--; argv++; }
if (argc && !strcmp (argv[0], "--verbose"))
{
verbose = 1;
argc--; argv++;
}
show_stdnames ();
test_all ();
return 0;
}
diff --git a/g10/test.c b/g10/test.c
index 39d594594..e9e2074d3 100644
--- a/g10/test.c
+++ b/g10/test.c
@@ -1,187 +1,191 @@
/* test.c - Infrastructure for unit tests.
* Copyright (C) 2015 g10 Code GmbH
*
* This file is part of GnuPG.
*
* GnuPG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GnuPG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see .
*/
#include
#include
#include
#include
#include "gpg.h"
/* A unit test consists of one or more tests. Tests can be broken
into groups and each group can consist of one or more tests. */
/* The number of test groups. */
static int test_groups;
/* The current test group. */
static char *test_group;
/* Whether there was already a failure in the current test group. */
static int current_test_group_failed;
/* The number of test groups with a failure. */
static int test_groups_failed;
/* The total number of tests. */
static int tests;
/* The total number of tests that failed. */
static int tests_failed;
/* Flag to request verbose diagnostics. This is set if the envvar
"verbose" exists and is not the empty string. */
static int verbose;
#define TEST_GROUP(description) \
do { \
test_group = (description); \
test_groups ++; \
current_test_group_failed = 0; \
} while (0)
#define STRINGIFY2(x) #x
#define STRINGIFY(x) STRINGIFY2(x)
/* Execute a test. */
#define TEST(description, test, expected) \
do { \
int test_result; \
int expected_result; \
\
tests ++; \
if (verbose) \
{ \
printf ("%d. Checking %s...", \
tests, (description) ?: ""); \
fflush (stdout); \
} \
test_result = (test); \
expected_result = (expected); \
\
if (test_result == expected_result) \
{ \
- printf (" ok.\n"); \
+ if (verbose) printf (" ok.\n"); \
} \
else \
{ \
+ if (!verbose) \
+ printf ("%d. Checking %s...", \
+ tests, (description) ?: ""); \
printf (" failed.\n"); \
printf (" %s == %s failed.\n", \
STRINGIFY(test), \
STRINGIFY(expected)); \
tests_failed ++; \
if (! current_test_group_failed) \
{ \
current_test_group_failed = 1; \
test_groups_failed ++; \
} \
} \
} while (0)
/* Test that a condition evaluates to true. */
#define TEST_P(description, test) \
TEST(description, !!(test), 1)
/* Like CHECK, but if the test fails, abort the program. */
#define ASSERT(description, test, expected) \
do { \
int tests_failed_pre = tests_failed; \
CHECK(description, test, expected); \
if (tests_failed_pre != tests_failed) \
exit_tests (1); \
} while (0)
/* Call this if something went wrong. */
#define ABORT(message) \
do { \
printf ("aborting..."); \
if (message) \
printf (" %s\n", (message)); \
\
exit_tests (1); \
} while (0)
/* You need to fill this function in. */
static void do_test (int argc, char *argv[]);
/* Print stats and call the real exit. If FORCE is set use
EXIT_FAILURE even if no test has failed. */
static void
exit_tests (int force)
{
if (tests_failed == 0)
{
- printf ("All %d tests passed.\n", tests);
+ if (verbose)
+ printf ("All %d tests passed.\n", tests);
exit (!!force);
}
else
{
printf ("%d of %d tests failed",
tests_failed, tests);
if (test_groups > 1)
printf (" (%d of %d groups)",
test_groups_failed, test_groups);
printf ("\n");
exit (1);
}
}
/* Prepend FNAME with the srcdir environment variable's value and
return a malloced filename. Caller must release the returned
string using test_free. */
char *
prepend_srcdir (const char *fname)
{
static const char *srcdir;
char *result;
if (!srcdir && !(srcdir = getenv ("srcdir")))
srcdir = ".";
result = malloc (strlen (srcdir) + 1 + strlen (fname) + 1);
strcpy (result, srcdir);
strcat (result, "/");
strcat (result, fname);
return result;
}
void
test_free (void *a)
{
if (a)
free (a);
}
int
main (int argc, char *argv[])
{
const char *s;
(void) test_group;
s = getenv ("verbose");
if (s && *s)
verbose = 1;
do_test (argc, argv);
exit_tests (0);
return !!tests_failed;
}
diff --git a/tests/openpgp/gpgtar.test b/tests/openpgp/gpgtar.test
index 63bed7025..2f33f75c9 100755
--- a/tests/openpgp/gpgtar.test
+++ b/tests/openpgp/gpgtar.test
@@ -1,126 +1,126 @@
#!/bin/sh
#set -x
# Make sure $srcdir is set.
if test "x$srcdir" = x
then
echo srcdir environment variable not set!
exit 1
fi
. $srcdir/defs.inc || exit 3
set -e
# Make sure $GNUPGHOME is set.
if test "x$GNUPGHOME" = x
then
echo "GNUPGHOME not set."
exit 1
fi
TESTFILES="$plain_files $data_files"
TESTDIR=gpgtar.d
FILELIST="${TESTDIR}/filelist"
PPFILE="${TESTDIR}/passphrase"
PPFLAGS="--gpg-args --passphrase-file=$PPFILE"
GPG=../../g10/gpg
GPGARGS="$opt_always --no-permission-warning"
GPGTAR="../../tools/gpgtar"
GPGZIP="sh ../../tools/gpg-zip"
# Skip test if gpgtar has not been built.
if ! test -x "$GPGTAR"
then
exit 77
fi
# Create, inspect, and extract an archive with the given options.
#
# $1 the tool to test
# $2 options used to create the archive
# $3 options used to inspect the archive
# $4 options used to extract the archive
do_test()
{
(
TOOL="$1"
CREATE_FLAGS="$2"
INSPECT_FLAGS="$3"
EXTRACT_FLAGS="$4"
rm -rf -- "${TESTDIR}"
mkdir "${TESTDIR}"
echo frob >"$PPFILE"
$TOOL --gpg "$GPG" --gpg-args "$GPGARGS" $CREATE_FLAGS \
--output "${TESTDIR}/test.tar.pgp" $TESTFILES
$TOOL --gpg "$GPG" --gpg-args "$GPGARGS" $INSPECT_FLAGS \
"${TESTDIR}/test.tar.pgp" \
>"$FILELIST"
for F in $TESTFILES
do
awk '{print $NF}' "$FILELIST" | grep "^${F}$" >/dev/null
done
- $TOOL --gpg "$GPG" --gpg-args "$GPGARGS" $EXTRACT_FLAGS \
+ $TOOL --gpg "$GPG" --gpg-args "$GPGARGS" $EXTRACT_FLAGS --quiet \
--tar-args --directory="${TESTDIR}" \
"${TESTDIR}/test.tar.pgp"
for F in $TESTFILES
do
cmp "$F" "${TESTDIR}/$F"
done
)
}
for TOOL in "$GPGTAR" "$GPGZIP"
#for TOOL in "$GPGZIP"
do
# Asymmetric encryption.
do_test "$TOOL" \
"--encrypt --recipient $usrname2" \
"--list-archive" \
"--decrypt"
# Asymmetric encryption and signing.
do_test "$TOOL" \
"--encrypt --recipient $usrname2 --sign --local-user $usrname3" \
"--list-archive" \
"--decrypt"
# Signing only.
do_test "$TOOL" \
"--sign --local-user $usrname3" \
"--list-archive" \
"--decrypt"
# Symmetric encryption.
do_test "$TOOL" \
"${PPFLAGS} --symmetric" \
"${PPFLAGS} --list-archive" \
"${PPFLAGS} --decrypt"
# Symmetric encryption, explicitly choose cipher.
for a in `all_cipher_algos`; do
do_test "$TOOL" \
"${PPFLAGS} --gpg-args --cipher=$a --symmetric" \
"${PPFLAGS} --list-archive" \
"${PPFLAGS} --decrypt"
break
done
# Asymmetric and symmetric encryption, and signing.
do_test "$TOOL" \
"${PPFLAGS} --encrypt --symmetric --recipient $usrname2 --sign --local-user $usrname3" \
"${PPFLAGS} --list-archive" \
"${PPFLAGS} --decrypt"
done
# Success!
exit 0
diff --git a/tests/openpgp/mds.test b/tests/openpgp/mds.test
index 944f535cd..bb7331269 100755
--- a/tests/openpgp/mds.test
+++ b/tests/openpgp/mds.test
@@ -1,89 +1,89 @@
#!/bin/sh
# Copyright 1998,1999,2000,2001,2002,2003,2004,2005,2006,
# 2007 Free Software Foundation, Inc.
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved. This file is
# distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY, to the extent permitted by law; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
. $srcdir/defs.inc || exit 3
test_one () {
if [ "`grep $1 y | sed -e 's/:[^:]*:\(.*\):/\1/'`" != "$2" ]; then
failed="$failed $1"
fi
}
failed=""
#info Checking message digests
cat /dev/null | $GPG --with-colons --print-mds >y
# MD5
if have_hash_algo "MD5"; then
test_one ":1:" "D41D8CD98F00B204E9800998ECF8427E"
else
- echo "Hash algorithm MD5 is not installed (not an error)"
+ echo " > Hash algorithm MD5 is not installed (not an error)"
fi
# SHA-1
test_one ":2:" "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"
# RMD160
if have_hash_algo "RIPEMD160"; then
test_one ":3:" "9C1185A5C5E9FC54612808977EE8F548B2258D31"
else
echo "Hash algorithm RIPEMD160 is not installed (not an error)"
fi
# SHA-224
if have_hash_algo "SHA224"; then
test_one ":11:" "D14A028C2A3A2BC9476102BB288234C415A2B01F828EA62AC5B3E42F"
else
echo "Hash algorithm SHA-224 is not installed (not an error)"
fi
# SHA-256
if have_hash_algo "SHA256"; then
test_one ":8:" "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
else
echo "Hash algorithm SHA-256 is not installed (not an error)"
fi
# SHA-384
if have_hash_algo "SHA384"; then
test_one ":9:" "38B060A751AC96384CD9327EB1B1E36A21FDB71114BE07434C0CC7BF63F6E1DA274EDEBFE76F65FBD51AD2F14898B95B"
else
echo "Hash algorithm SHA-384 is not installed (not an error)"
fi
# SHA-512
if have_hash_algo "SHA512"; then
test_one ":10:" "CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E"
else
echo "Hash algorithm SHA-512 is not installed (not an error)"
fi
[ "$failed" != "" ] && error "$failed failed for empty string"
echo_n "abcdefghijklmnopqrstuvwxyz" | $GPG --with-colons --print-mds >y
if have_hash_algo "MD5"; then
test_one ":1:" "C3FCD3D76192E4007DFB496CCA67E13B"
fi
test_one ":2:" "32D10C7B8CF96570CA04CE37F2A19D84240D3A89"
if have_hash_algo "RIPEMD160"; then
test_one ":3:" "F71C27109C692C1B56BBDCEB5B9D2865B3708DBC"
fi
if have_hash_algo "SHA224"; then
test_one ":11:" "45A5F72C39C5CFF2522EB3429799E49E5F44B356EF926BCF390DCCC2"
fi
if have_hash_algo "SHA256"; then
test_one ":8:" "71C480DF93D6AE2F1EFAD1447C66C9525E316218CF51FC8D9ED832F2DAF18B73"
fi
if have_hash_algo "SHA384"; then
test_one ":9:" "FEB67349DF3DB6F5924815D6C3DC133F091809213731FE5C7B5F4999E463479FF2877F5F2936FA63BB43784B12F3EBB4"
fi
if have_hash_algo "SHA512"; then
test_one ":10:" "4DBFF86CC2CA1BAE1E16468A05CB9881C97F1753BCE3619034898FAA1AABE429955A1BF8EC483D7421FE3C1646613A59ED5441FB0F321389F77F48A879C7B1F1"
fi
[ "$failed" != "" ] && error "$failed failed for a..z"
exit 0
diff --git a/tests/openpgp/version.test b/tests/openpgp/version.test
index be565fb6f..9d265ad06 100755
--- a/tests/openpgp/version.test
+++ b/tests/openpgp/version.test
@@ -1,110 +1,110 @@
#!/bin/sh
# Copyright 1998,1999,2000,2001,2002,2003,2004,2005,2006,
# 2007 Free Software Foundation, Inc.
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved. This file is
# distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY, to the extent permitted by law; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
. $srcdir/defs.inc || exit 3
# This is the first test run by "make check". First kill a possible
# gpg-agent process from a previous test run.
if $GPG_AGENT --quiet; then
echo "$pgmname: killing leftover gpg-agent process" >&2
$GPG_CONNECT_AGENT killagent /bye >/dev/null
sleep 2
fi
info "Deleting old files"
if [ -f Makefile -a -f $srcdir/decrypt-dsa.test ]; then
:
else
fatal "not running in the test directory"
exit 1
fi
if [ -d private-keys-v1.d ]; then
rm private-keys-v1.d/* 2>/dev/null || true
rmdir private-keys-v1.d
fi
for i in pubring.gpg pubring.gpg~ trustdb.gpg trustdb.gpg~ ; do
[ -f "$i" ] && rm "$i"
done
# Now start the agent right away, so that there is only one place
# where starting the agent may fail. To speed up key generation we
# create a faked random seed file. Note that we need to set the
# agent-program so that gpg-connect-agent is able to start the agent
# we are currently testing and not an already installed one.
# The "|--debug-quick-random" is a hack to start gpg-agent with
# that option on the command line.
info "Starting the agent"
$MKTDATA 600 >random_seed
if $GPG_CONNECT_AGENT -v \
--agent-program="${GPG_AGENT}|--debug-quick-random" /bye; then
:
else
error "starting the gpg-agent failed"
exit 1
fi
info "Creating sample data files"
for i in 500 9000 32000 80000; do
$MKTDATA $i >data-$i
done
info "Unpacking samples"
$GPG --dearmor < $srcdir/plain-1o.asc > ./plain-1
$GPG --dearmor < $srcdir/plain-2o.asc > ./plain-2
$GPG --dearmor < $srcdir/plain-3o.asc > ./plain-3
$GPG --dearmor < $srcdir/plain-largeo.asc > ./plain-large
info "Storing private keys"
for i in 50B2D4FA4122C212611048BC5FC31BD44393626E \
7E201E28B6FEB2927B321F443205F4724EBE637E \
13FDB8809B17C5547779F9D205C45F47CE0217CE \
343D8AF79796EE107D645A2787A9D9252F924E6F \
8B5ABF3EF9EB8D96B91A0B8C2C4401C91C834C34 \
0D6F6AD4C4C803B25470F9104E9F4E6A4CA64255 \
FD692BD59D6640A84C8422573D469F84F3B98E53 \
76F7E2B35832976B50A27A282D9B87E44577EB66 \
A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD \
00FE67F28A52A8AA08FFAED20AF832DA916D1985 \
1DF48228FEFF3EC2481B106E0ACA8C465C662CC5 \
A2832820DC9F40751BDCD375BB0945BA33EC6B4C \
ADE710D74409777B7729A7653373D820F67892E0 \
CEFC51AF91F68A2904FBFF62C4F075A4785B803F; do
$GPG --dearmor < $srcdir/privkeys/$i.asc > private-keys-v1.d/$i.key
done
info "Importing public demo and test keys"
$GPG --yes --import $srcdir/pubdemo.asc $srcdir/pubring.asc
$GPG --dearmor < $srcdir/pubring.pkr.asc | $GPG --yes --import
info "Preset passphrases"
# one@example.com
$GPG_PRESET_PASSPHRASE --preset -P def 50B2D4FA4122C212611048BC5FC31BD44393626E
$GPG_PRESET_PASSPHRASE --preset -P def 7E201E28B6FEB2927B321F443205F4724EBE637E
# alpha@example.net
$GPG_PRESET_PASSPHRASE --preset -P abc 76F7E2B35832976B50A27A282D9B87E44577EB66
$GPG_PRESET_PASSPHRASE --preset -P abc A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD
# Note: secring.asc and secring.skr.asc are the original secrings for
# our test files. We don't support this as storage format anymore but
# keep the files here for reference. The actual keys have been
# extracted and put in gpg-agent's format unter privkeys/. Because
# the current gpg's import feature does not support storing of
# unprotected keys in the new gpg-agent format, we had to resort to
# some trickery to convert them.
info "Printing the GPG version"
-$GPG --version
+$GPG --version | awk '{print " > " $0}'
#fixme: check that the output is as expected
diff --git a/tools/gpg-zip.in b/tools/gpg-zip.in
index a6b423877..48c4766b1 100644
--- a/tools/gpg-zip.in
+++ b/tools/gpg-zip.in
@@ -1,142 +1,148 @@
#!/bin/sh
# gpg-archive - gpg-ized tar using the same format as PGP's PGP Zip.
# Copyright (C) 2005 Free Software Foundation, Inc.
#
# This file is part of GnuPG.
#
# GnuPG is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GnuPG 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see .
# Despite the name, PGP Zip format is actually an OpenPGP-wrapped tar
# file. To be compatible with PGP itself, this must be a USTAR format
# tar file. Unclear on whether there is a distinction here between
# the GNU or POSIX variant of USTAR.
VERSION=@VERSION@
TAR=@TAR@
GPG=gpg
usage="\
Usage: gpg-zip [--help] [--version] [--encrypt] [--decrypt] [--symmetric]
[--list-archive] [--output FILE] [--gpg GPG] [--gpg-args ARGS]
[--tar TAR] [--tar-args ARGS] filename1 [filename2, ...]
directory1 [directory2, ...]
Encrypt or sign files into an archive."
+tar_verbose_opt="v"
+
while test $# -gt 0 ; do
case $1 in
-h | --help | --h*)
echo "$usage"
exit 0
;;
--list-archive)
list=yes
create=no
unpack=no
shift
;;
--encrypt | -e)
gpg_args="$gpg_args --encrypt"
list=no
create=yes
unpack=no
shift
;;
--decrypt | -d)
gpg_args="$gpg_args --decrypt"
list=no
create=no
unpack=yes
shift
;;
--symmetric | -c)
gpg_args="$gpg_args --symmetric"
list=no
create=yes
unpack=no
shift
;;
--sign | -s)
gpg_args="$gpg_args --sign"
list=no
create=yes
unpack=no
shift
;;
--recipient | -r)
gpg_args="$gpg_args --recipient $2"
shift
shift
;;
--local-user | -u)
gpg_args="$gpg_args --local-user $2"
shift
shift
;;
--output | -o)
gpg_args="$gpg_args --output $2"
shift
shift
;;
--version)
echo "gpg-zip (GnuPG) $VERSION"
exit 0
;;
--gpg)
GPG=$2
shift
shift
;;
--gpg-args)
gpg_args="$gpg_args $2"
shift
shift
;;
--tar)
TAR=$2
shift
shift
;;
--tar-args)
tar_args="$tar_args $2"
shift
shift
;;
+ --quiet)
+ tar_verbose_opt=""
+ shift
+ ;;
--)
shift
break
;;
-*)
echo "$usage" 1>&2
exit 1
;;
*)
break
;;
esac
done
if test x$create = xyes ; then
# echo "$TAR $tar_args -cf - "$@" | $GPG --set-filename x.tar $gpg_args" 1>&2
$TAR $tar_args -cf - "$@" | $GPG --set-filename x.tar $gpg_args
elif test x$list = xyes ; then
# echo "cat \"$1\" | $GPG $gpg_args | $TAR $tar_args -tf -" 1>&2
cat "$1" | $GPG $gpg_args | $TAR $tar_args -tf -
elif test x$unpack = xyes ; then
# echo "cat \"$1\" | $GPG $gpg_args | $TAR $tar_args -xvf -" 1>&2
- cat "$1" | $GPG $gpg_args | $TAR $tar_args -xvf -
+ cat "$1" | $GPG $gpg_args | $TAR $tar_args -x${tar_verbose_opt}f -
else
echo "$usage" 1>&2
exit 1
fi