Commit Graph

488 Commits

Author SHA1 Message Date
Justus Winter c9c3fe8832
gpgscm: Make global data constant when possible.
* tests/gpgscm/scheme-private.h (struct scheme): Make 'vptr' const.
* tests/gpgscm/scheme.c (num_zero): Statically initialize and turn
into constant.
(num_one): Likewise.
(charnames): Change type so that it can be stored in rodata.
(is_ascii_name): Adapt slightly.
(assign_proc): Make argument const char *.
(op_code_info): Make some fields const char *.
(tests): Make const.
(dispatch_table): Make const.  At least it can be made read-only after
relocation.
(Eval_Cycle): Adapt slightly.
(vtbl): Make const.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-07 13:11:31 +02:00
Justus Winter 56638c28ad
gpgscm: Remove arbitrary limit on number of cell segments.
* tests/gpgscm/scheme-private.h (struct scheme): Remove fixed-size
arrays for cell segments, replace them with a pointer to the new
'struct cell_segment' instead.
* tests/gpgscm/scheme.c (struct cell_segment): New definition.
(_alloc_cellseg): Allocate the header within the segment, return a
pointer to the header.
(_dealloc_cellseg): New function.
(alloc_cellseg): Insert the segments into a list.
(_get_cell): Allocate a new segment if less than a quarter of
CELL_SIGSIZE is recovered during garbage collection.
(initialize_small_integers): Adapt callsite.
(gc): Walk the list of segments.
(scheme_init_custom_alloc): Remove initialization of removed field.
(scheme_deinit): Adapt deallocation.
--

Previously the number of cells that could be allocated was a
compile-time limit.  Remove this limit.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-07 13:11:30 +02:00
Justus Winter bf8b5e9042
gpgscm: Fix compact vector encoding.
* tests/gpgscm/scheme-private.h (struct cell): Use uintptr_t for
'_flags'.  This way, '_flags' has the size of a machine word.
--

The compact vector representation introduced in 49e2ae65 requires that
we can tell apart pointers and type flags.  This did not work on
64-bit big-endian architectures.

Fixes a crash on 64-bit big-endian architectures.

Hat-tip-to: gniibe
Fixes-commit: 49e2ae65e8
Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-07 12:27:47 +02:00
Justus Winter f1dc34f502
gpgscm: Avoid mutating integer.
* tests/gpgscm/scheme.c (opexe_5): Do not modify the integer in-place
while printing an vector.  Integer objects may be shared, so they must
not be mutated.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-06 16:24:49 +02:00
Justus Winter b83903f59e
gpgscm: Initialize unused slots in vectors.
* tests/gpgscm/scheme.c (get_vector_object): Initialize unused slots
at the end of vectors.
--

They should not be used for anything, but let's just initialize them
to something benign to be sure.

GnuPG-bug-id: 3014
Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-06 16:21:48 +02:00
Justus Winter 23f00f109d
tests: Fix distcheck.
* tests/Makefile.am (SUBDIRS): Add 'pkits' again.  Simply dropping it
makes 'make distcheck' unhappy.
* tests/pkits/Makefile.am (TESTS): Remove all tests.
--

Disable the 'pkits' tests in a way that keeps 'make distcheck' happy.
To run tests individually, do

  make -Ctests/pkits check TESTS=some-test

GnuPG-bug-id: 3067
Fixes-commit: af1c1a57e4
Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-06 15:20:43 +02:00
Justus Winter af1c1a57e4
tests: Disable 'pkits' test suite.
* tests/Makefile.am (SUBDIRS): Drop 'pkits'.
* tests/pkits/common.sh: Fix locating 'PKITS_data.tar.bz2'.
* tests/pkits/inittests: Likewise.
--

These tests are unmaintained and broken, and were previously only run
when doing in-tree builds, hence nobody noticed that they were badly
broken.

GnuPG-bug-id: 3067
Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-06 14:31:54 +02:00
Justus Winter 94645311f8
tests: Make test more robust.
* tests/openpgp/4gb-packet.scm: Skip if we do not have BZIP2.
* tests/openpgp/defs.scm (have-compression-algo?): New function.

GnuPG-bug-id: 3028
Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-06 12:36:00 +02:00
Justus Winter 01e84d429a
tests: Fix setup of ephemeral home directories.
* tests/openpgp/defs.scm (with-ephemeral-home-directory): Set
GNUPGHOME and cwd to the ephemeral directory before calling the setup
function.

GnuPG-bug-id: 3047
Fixes-commit: 32b75fb774
Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-05 15:22:42 +02:00
Justus Winter 32b75fb774
tests: Fix setup of ephemeral home directories.
* tests/openpgp/defs.scm (with-ephemeral-home-directory): Create
configuration files when we enter the context.
* tests/openpgp/setup.scm: Do not use an ephemeral home directory.
Tests should always use the cwd.
* tests/gpgsm/setup.scm: Likewise.
* tests/gpgsm/export.scm: Add explicit constructor function.
* tests/openpgp/decrypt-session-key.scm: Likewise.
* tests/openpgp/decrypt-unwrap-verify.scm: Likewise.
--

Previously, ephemeral homedirectories lacked a configuration, hence
GnuPG tried to start backend daemons using their installed locations.
Fix this by explicitly creating a suitable configuration.

GnuPG-bug-id: 3047
Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-04 18:52:06 +02:00
Justus Winter 6261611d37
gpgscm: Fix copying values.
* tests/gpgscm/scheme.c (copy_value): New function.
(mk_tagged_value): Use new function.
(opexe_4): Likewise for OP_SAVE_FORCED.
--

Occasionally, we need to copy a value from one location in the storage
to another.  Scheme objects are fine.  Some primitive objects,
however, require finalization, usually to free resources.

For these values, we either make a copy or acquire a reference.

Fixes e.g. a double free if a delayed expression evaluating to a
string is forced.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-04 18:48:51 +02:00
Justus Winter a80d4a9b50
gpgscm: Simplify get-output-string operation.
* tests/gpgscm/scheme.c (opexe_4): Simplify 'get-output-string'.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-04 18:19:35 +02:00
Justus Winter d858096c99
gpgscm: Simplify substring operation.
* tests/gpgscm/scheme.c (opexe_2): Simplify 'substring'.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-04 15:04:42 +02:00
Justus Winter 90932bdad6
gpgscm: Slightly improve the procedure dispatch.
* tests/gpgscm/scheme.c (procnum): Procedures always have an integer
number, so we can safely use the cheaper 'ivalue_unchecked'.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-03 11:53:19 +02:00
Justus Winter b20780658e
tests,w32: Fix importing the extra key for GPGME's keylist test.
* tests/gpgme/wrap.scm: Qualify the tests name with the extension for
executables (if any).

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-28 16:51:18 +02:00
Justus Winter 5128cd74c0
tests: Fix distcheck.
* tests/openpgp/Makefile.am (sample_msgs): Add all missing sample
messages.

Fixes-commit: 211d71f19c
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-28 12:22:18 +02:00
Justus Winter 211d71f19c
tests: Add test for '--decrypt --unwrap'.
* tests/openpgp/Makefile.am (XTESTS): Add new test.
* tests/openpgp/decrypt-unwrap-verify.scm: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-28 12:11:03 +02:00
Werner Koch 2c9d9ac55e
tests: Use gpgconf to stop the agent.
* tests/openpgp/defs.scm (stop-agent): Swap order of actions.  Kill
all daemons using gpgconf.
* tools/gpgconf.c (main) <aRemoveSocketDir>: Try to remove known
socketfails on rmdir failure.  Do no fail for ENONET.
--

Killing all daemons is not really required but it does not harm to be
prepared for the future.

Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-23 17:55:21 +01:00
Justus Winter 178b6314ab
gpgscm: Make test cleanup more robust.
* tests/gpgscm/tests.scm (mkdtemp-autoremove): New function that
cleans up at interpreter shutdown.
(run-tests-parallel): Use the new function.
(run-tests-sequential): Likewise.
(make-environment-cache): Execute setup with an temporary working
directory.
--

Make sure to remove all resources created in the filesystem even if
the test runner is interrupted.  Make sure to remove anything that the
setup script creates.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-23 15:56:34 +01:00
Justus Winter fde885bbc4
tests: Test '--quick-set-primary-uid'.
* tests/openpgp/quick-key-manipulation.scm: Test
'--quick-set-primary-uid'.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-21 16:21:49 +01:00
Justus Winter d17840c3f4
tests,w32: Use GetTempPath to get the path for temporary files.
* tests/gpgscm/ffi.c (do_get_temp_path): New function.
(ffi_init): Make function available.
* tests/gpgscm/tests.scm (mkdtemp): Use the new function.

Fixes-commit: 06f1f163e9
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-21 15:52:47 +01:00
Justus Winter 06f1f163e9
tests: Create temporary directories in '/tmp'.
* tests/gpgscm/tests.scm (mkdtemp): Create temporary directories in
'/tmp' on UNIX, or in '%Temp' on Windows.
* tests/migrations/common.scm (run-test): Turn error into a warning.
* tests/openpgp/defs.scm (start-agent): Likewise.
--

This fixes the problem of GnuPG components being unable to communicate
because of too long GnuPG home directories in important build
environments like the Debian build servers despite the use of socket
directories.

This reverts d75d20909d.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-21 13:15:38 +01:00
Justus Winter ceb4b24575
tests: Remove debugging remnants.
* tests/gpgme/gpgme-defs.scm (run-python-tests?): Remove 'trace's.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-20 14:36:36 +01:00
Justus Winter d75d20909d
tests: Fail if we cannot create the socket directory.
* tests/migrations/common.scm (run-test): Turn warning into an error.
* tests/openpgp/defs.scm (start-agent): Likewise.
--

We use separate directories to create the sockets in so that the
absolute path to the every socket fits into sun_path.

Fixes-commit: 7e19786a5d
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-20 14:09:13 +01:00
Neal H. Walfield fb9d68d636
tests: Add test for issue 2959.
* tests/openpgp/tofu.scm: Add test for --tofu-default-policy=ask.

Signed-off-by: Neal H. Walfield <neal@g10code.com>
2017-03-17 19:31:09 +01:00
Justus Winter 6a3f857224
gpgscm: Simplify hash tables.
* tests/gpgscm/scheme.c (oblist_add_by_name): We now always get a
slot.  Simplify accordingly.
(oblist_find_by_name): Always return the slot.
(vector_elem_slot): New function.
(new_slot_spec_in_env): We now always get a slot.  Remove parameter
'env'.  Simplify accordingly.
(find_slot_spec_in_env): Always return a slot.
(new_slot_in_env): Adapt callsite.
(opexe_0): Likewise.
(opexe_1): Likewise.
(scheme_define): Likewise.
--

Now that the ill-devised immediate values framework is gone, there is
no need to tag the pointers in vectors anymore.  Therefore, we can
always return a pointer to the slot in the hash table lookup
functions.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-17 10:35:25 +01:00
Justus Winter 38c955599f
gpgscm: Remove framework for immediate values.
* tests/gpgscm/scheme.c (IMMEDIATE_TAG): Remove macro.
(is_immediate): Likewise.
(set_immediate): Likewise.
(clr_immediate): Likewise.
(enum scheme_types): Set the LSB in every value.
(fill_vector): Adapt.
(vector_elem): Likewise.
(set_vector_elem): Likewise.
(mark): Likewise.
(gc): Test for the LSB to tell typeflags apart from pointers stored in
the same memory location.
--

Supporting immediate values would require invasive changes to the
interpreter and is likely not worth the trouble.  On the other hand,
tagging pointers in vectors complicated the hash table implementation
needlessly.  Therefore, I remove this again.

This fixes a crash on big endian architectures.

GnuPG-bug-id: 2996
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-17 10:34:15 +01:00
Justus Winter a98459d3f4
tests: Fix using tools from the build directory.
* tests/openpgp/defs.scm (gpg-conf'): Explicitly pass the build prefix
to gpgconf here...
(gpg-components): ... instead of only here.
--

Previously, gpgconf was not invoked with '--build-prefix' when
changing the configuration.  This made tests using this facility fail
(e.g. the TOFU test).  This only affected release builds, because in
development builds gpgconf picks up the build prefix from the
environment.

GnuPG-bug-id: 2979
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-15 14:36:27 +01:00
Justus Winter c7833eca38
tests: Dump the tools that the tests are going to use.
* tests/openpgp/setup.scm: Dump the tools that the tests are going to
use.  This will help us diagnose problems with the tests picking the
wrong paths in the future.

GnuPG-bug-id: 2979
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-15 12:34:04 +01:00
NIIBE Yutaka a672ddec03 tests: Fix running python condition.
* tests/gpgme/gpgme-defs.scm (run-python-tests?): We need Python.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-03-15 16:45:18 +09:00
Justus Winter d82abbb1b6
tests: Skip Python tests if the bindings are not built.
* tests/gpgme/wrap.scm (python): Move variable...
* tests/gpgme/gpgme-defs.scm (python): ... here.
(run-python-tests?): New function.
* tests/gpgme/run-tests.scm: Only run Python tests if the bindings can
be located in GPGME's build directory.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-14 12:45:29 +01:00
Justus Winter 046a15a88c
tests: Run the tests for the Python bindings of GPGME.
* tests/gpgme/gpgme-defs.scm (create-file): Write lines.
(create-gpgmehome): Extend function to create the right environment
for the Python tests.
* tests/gpgme/run-tests.scm: Make an environment cache for the Python
tests and enable them.
* tests/gpgme/wrap.scm: Do not hardcode the path of the Python
interpreter.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-09 14:33:02 +01:00
Justus Winter cca91a3f8f
tests: Rework environment setup.
* tests/gpgscm/tests.scm (test::scm): Add a setup argument.
(test::binary): Likewise.
(run-tests-parallel): Remove setup parameter.
(run-tests-sequential): Likewise.
(make-environment-cache): New function that handles the cache
protocol.
* tests/gpgme/run-tests.scm: Adapt accordingly.
* tests/gpgsm/run-tests.scm: Likewise.
* tests/migrations/run-tests.scm: Likewise.
* tests/openpgp/run-tests.scm: Likewise.
--
This change allows us to have different environments for tests.  This
is needed to run more GPGME tests, and to increase concurrency while
running all tests.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-09 13:26:06 +01:00
Michael Haubenwallner c22a2a89d3
gpgscm: Use system strlwr if available.
* tests/gpgscm/scheme.c: Define local strlwr only when HAVE_STRLWR is
not defined in config.h.
* tests/gpgscm/scheme-config.h: Remove hack.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-07 14:33:27 +01:00
Justus Winter 591b6a9d87
gpg: Do not allow the user to revoke the last valid UID.
* g10/keyedit.c (keyedit_quick_revuid): Merge self signatures, then
make sure that we do not revoke the last valid UID.
(menu_revuid): Make sure that we do not revoke the last valid UID.
* tests/openpgp/quick-key-manipulation.scm: Demonstrate that
'--quick-revoke-uid' can not be used to revoke the last valid UID.

GnuPG-bug-id: 2960
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-07 13:46:20 +01:00
NIIBE Yutaka d6c7bf1f8a More change for common.
* g10, scd, test, tools: Follow the change of removal of -Icommon.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-03-07 20:32:09 +09:00
Justus Winter de3838372a
tests: Avoid overflowing signed 32 bit time_t.
* tests/openpgp/quick-key-manipulation.scm: Use expiration times in
the year 2038 instead of 2105 to avoid overflowing 32 bit time_t.
time_t is used internally to parse the expiraton time from the iso
timestamp.

GnuPG-bug-id: 2988
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-07 12:23:47 +01:00
Justus Winter 7e19786a5d
tests: Harmonize temporary and socket directory handling.
* tests/gpgscm/tests.scm (mkdtemp): Do not magically obey the
environment variable 'TMP', make sure to always return an absolute
path.
* tests/gpgme/Makefile.am (TMP): Drop variable.
(TESTS_ENVIRONMENT): Drop 'TMP'.
* tests/gpgme/gpgme-defs.scm (create-gpgmehome): Start the agent.  Do
not create private key store, the agent does that for us.
* tests/gpgsm/Makefile.am (TMP): Drop variable.
(TESTS_ENVIRONMENT): Drop 'TMP'.
* tests/gpgme/gpgme-defs.scm (create-gpgsmhome): Start the agent.  Do
not create private key store, the agent does that for us.
* tests/migrations/Makefile.am (TMP): Drop variable.
(TESTS_ENVIRONMENT): Drop 'TMP'.
* tests/migrations/common.scm (gpgconf): New variable.
(run-test): Create and remove socket directory.
* tests/migrations/extended-pkf.scm (src-tarball): Remove variable.
(setup): Remove function.
(trigger-migration): Likewise.
Use 'run-test' to execute the test.
* tests/migrations/from-classic.scm (src-tarball): Remove variable.
(setup): Remove function.
Use 'run-test' to execute the tests.
* tests/openpgp/Makefile.am (TMP): Drop variable.
(TESTS_ENVIRONMENT): Drop 'TMP'.
* tests/openpgp/README: Do not mention 'TMP'.
* tests/openpgp/defs.scm (with-home-directory): New macro.
(create-legacy-gpghome): Do not create private key store, the agent
does that for us.
(start-agent): Make sure to terminate the right agent with 'atexit'.
--

Previously, the test suite relied upon creating home directories in
'/tmp'.  This has been problematic in some build environments,
although POSIX mandates that '/tmp' must be available.

We now rely on 'gpgconf --create-socketdir' to create a suitable
socket directory for us.  This allows us to get rid of some cruft.  It
also aligns the environment the tests are run in closer with the
environment that we intend that GnuPG runs in.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-06 18:10:10 +01:00
Justus Winter 171e4314eb
gpgscm: Fix creation of temporary directories.
* tests/gpgscm/ffi.c (do_mkdtemp): Use a larger buffer for the
template.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-06 18:10:08 +01:00
Justus Winter 4735ab96aa
gpg: Fix (quick) key generation with --always-trust.
* g10/keygen.c (do_generate_keypair): Only update the ownertrust if we
do have a trust database.
* g10/trustdb.c (have_trustdb): New function.
* g10/trustdb.h (have_trustdb): New prototype.
* tests/openpgp/quick-key-manipulation.scm: Remove workaround.

GnuPG-bug-id: 2695
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-02 14:50:23 +01:00
Justus Winter 62d21a4ab4
g10: Signal an error when trying to revoke non-existant UID.
* g10/keyedit.c (keyedit_quick_revuid): Signal an error when trying to
revoke non-existant UID.
* tests/openpgp/quick-key-manipulation.scm: Test that.

GnuPG-bug-id: 2962
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-02 11:39:00 +01:00
Justus Winter 74cb3b230c
tests: Log information about ssh, add comments to test.
* tests/openpgp/ssh-import.scm (ssh-version-string): New variable, and
log the binary and version used in the test.
(ssh-supports?): Document how we test what algorithms are supported by
ssh, and log ssh-keygen's replies.
--
We have some trouble with this test on macOS, and adding some more
information in verbose mode will hopefully make tracking down these
problems easier in the future.

GnuPG-bug-id: 2980
Signed-off-by: Justus Winter <justus@g10code.com>
2017-03-02 10:41:03 +01:00
Justus Winter e4583ae14e
gpgscm: Improve parsing.
* tests/gpgscm/scheme.c (port_increment_current_line): Avoid creating
the same integer if the delta is zero.  This happens a lot during
parsing, and puts pressure on the memory allocator.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-28 16:19:18 +01:00
Justus Winter 058c97f9fc
gpgscm: Fix calculating the line number.
* tests/gpgscm/scheme.c (opexe_5): Only increment the line number on
newlines.

Fixes-commit: 7cc57e2c63
Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-28 16:17:33 +01:00
Justus Winter 41900175cf
tests: Improve support for gpgconf.
* tests/openpgp/defs.scm: Improve high-level inteface to gpgconf.
* tests/openpgp/gpgconf.scm: Adapt.
* tests/openpgp/tofu.scm: Use it to select the trust model.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-28 13:26:26 +01:00
Justus Winter 7cc57e2c63
gpgscm: Track source locations in every kind of ports.
* tests/gpgscm/scheme-private.h (struct port): Move location
information out of the union.
* tests/gpgscm/scheme.c (mark): All ports need marking now.
(gc): Likewise all ports on the load stack.
(port_clear_location): Adapt accordingly.  Also, add an empty function
for !SHOW_ERROR_LINE.
(port_increment_current_line): Likewise.
(port_reset_current_line): Drop function in favor of...
(port_init_location): ... this new function.
(file_push): Simplify.
(file_pop): Likewise.
(port_rep_from_filename): Likewise.
(port_rep_from_file): Likewise.
(port_rep_from_string): Also initialize the location.
(port_rep_from_scratch): Likewise.
(port_close): Simplify and generalize.
(skipspace): Likewise.
(token): Likewise.
(_Error_1): Generalize.
(opexe_5): Likewise.
(scheme_deinit): Simplify and generalize.
(scheme_load_named_file): Likewise.
(scheme_load_string): Also initialize the location.
--
This change tracks the location of source code loaded from non-file
ports that is used in error messages.  It also simplifies the code
quite a bit.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-28 10:00:29 +01:00
NIIBE Yutaka ef424353f3 tests: No spelling fix for test text.
* tests/openpgp/verify.scm (msg_ed25519_rshort): Revert the spelling
fix.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-02-22 13:03:33 +09:00
Yuri Chornoivan 24cf0606b4 Clean up word replication.
--

This fixes extra word repetitions (like "the the" or "is is") in the
code and docs.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2017-02-21 13:11:46 -05:00
Justus Winter aab6ba0bb6
gpgscm: Guard use of tagged expressions.
* tests/gpgscm/init.scm (vm-history-print): Check that the tag added
to expressions when parsing source files matches the expected format.
* tests/gpgscm/lib.scm (assert): Likewise.
--

This makes the error handling more robust.  We saw the assumption
about the format of the tags being violated on one build system, and
it obscured the view on the underlying problem.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-17 10:43:20 +01:00
Justus Winter 2f7b6cb279
tests,build: Fix distcheck.
* tests/gpgscm/Makefile.am (EXTRA_DIST): Add 'time.scm'.

Fixes-commit: 127e1e532d
Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-15 16:03:12 +01:00
Justus Winter 90d383f1eb
tests: Test and document other ways to create keys.
* doc/gpg.texi: Clarify usage and expiration arguments for key
generation.
* tests/openpgp/quick-key-manipulation.scm: Test all variants.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-15 15:51:09 +01:00
Justus Winter 127e1e532d
tests: Check expiration times of created keys.
* tests/gpgscm/ffi.c (do_get_time): New function.
(ffi_init): Expose new function.
* tests/gpgscm/ffi.scm (get-time): Document new function.
* tests/gpgscm/time.scm: New file.
* tests/openpgp/quick-key-manipulation.scm: Use the new facilities to
check the expiration times of created keys.
* tests/openpgp/tofu.scm: Use the new module.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-15 14:53:07 +01:00
Werner Koch b456e5be91
gpg: Make --export-ssh-key work for the primary key.
* g10/export.c (export_ssh_key): Also check the primary key.
--

If no suitable subkey was found for export, we now check whether the
primary key is suitable for export and export this one.  Without this
change it was only possible to export the primary key by using the '!'
suffix in the key specification.

Also added a sample key for testing this.

GnuPG-bug-id: 2957
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-02-14 10:55:13 +01:00
Justus Winter 6823ed4658
gpg,common: Make sure that all fd given are valid.
* common/sysutils.c (gnupg_fd_valid): New function.
* common/sysutils.h (gnupg_fd_valid): New declaration.
* common/logging.c (log_set_file): Use the new function.
* g10/cpr.c (set_status_fd): Likewise.
* g10/gpg.c (main): Likewise.
* g10/keylist.c (read_sessionkey_from_fd): Likewise.
* g10/passphrase.c (set_attrib_fd): Likewise.
* tests/openpgp/Makefile.am (XTESTS): Add the new test.
* tests/openpgp/issue2941.scm: New file.
--

Consider a situation where the user passes "--status-fd 3" but file
descriptor 3 is not open.

During the course of executing the rest of the commands, it's possible
that gpg itself will open some files, and file descriptor 3 will get
allocated.

In this situation, the status information will be appended directly to
whatever file happens to have landed on fd 3 (the trustdb? the
keyring?).

This is a potential data destruction issue for all writable file
descriptor options:

   --status-fd
   --attribute-fd
   --logger-fd

It's also a potential issue for readable file descriptor options, but
the risk is merely weird behavior, and not data corruption:

   --override-session-key-fd
   --passphrase-fd
   --command-fd

Fixes this by checking whether the fd is valid early on before using
it.

GnuPG-bug-id: 2941
Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-08 14:28:49 +01:00
Justus Winter 56aa85f88f tests: Skip key types not supported by OpenSSH.
* tests/openpgp/ssh-import.scm (path): New variable.
(ssh,ssh-keygen,ssh-version,ssh-supports?): Likewise.
--

Skip algorithms not supported by the OpenSSH in the ssh import test.
This notably fixes the test on macOS when the stock ssh version is
used.

GnuPG-bug-id: 2847
GnuPG-bug-id: 2947
Signed-off-by: Justus Winter <justus@g10code.com>
2017-02-07 18:08:33 +01:00
Neal H. Walfield 64be8e1e86 tests: Improve description of test.
* tests/openpgp/issue2929.scm: Improve description of test.

Signed-off-by: Neal H. Walfield <neal@g10code.com>
2017-02-02 14:47:34 +01:00
Neal H. Walfield e596b21f4b Revert "Revert "tests: Add test demonstrating issue2929.""
This reverts commit 59048b0f1a.
2017-02-02 14:43:15 +01:00
Justus Winter 2e78aa6ff7 gpgscm: Tune the hash tables.
* tests/gpgscm/scheme.c (oblist_initial_value): Increase the size of
the hash table based on the number of symbols used after initializing
the interpreter.
(new_frame_in_env): Increase the size of the hash table based on the
number of variables in the global environement.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter b85d509a8f gpgscm: Optimize environment lookups and insertions.
* tests/gpgscm/scheme.c (pointercmp): New function.
(new_slot_spec_in_env): Add and use slot for insertions.
(find_slot_spec_in_env): New variant of 'find_slot_in_env' that
returns the slot on failures.
(find_slot_in_env): Express using the new function.
(new_slot_in_env): Update callsite.
(opexe_0): Optimize lookup-or-insert.
(opexe_1): Likewise.
(scheme_define): Likewise.
--
Optimize environment lookups by keeping the lists in the hash table or
the list sorted.  Optimize the insertions by passing the slot computed
by the lookup to the insertion.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter 874424ee3c gpgscm: Fix build with list environments.
* tests/gpgscm/scheme.c (new_slot_spec_in_env): Provide preallocation
inforomation if USE_ALIST_ENV.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter cea6d114b6 gpgscm: Optimize symbol lookups and insertions.
* tests/gpgscm/scheme.c (oblist_find_by_name): Keep the list of
symbols sorted, return the slot where a new symbol must be inserted on
lookup failures.
(oblist_add_by_name): Add the new symbol at the given slot.
(mk_symbol): Adjust callsite.
(gensym): Likewise.
(assign_syntax): Likewise.
--
Optimize symbol lookups by keeping the lists in the hash table (or the
list if compiled with USE_OBJECT_LIST) sorted by the symbol names.
Optimize the insertions by passing the slot computed by the lookup to
the insertion.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter 8f0ecb16cb gpgscm: Fix build with object list.
* tests/gpgscm/scheme.c (oblist_add_by_name): Provide preallocation
information if USE_OBJECT_LIST.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter 2076cdaf6b gpgscm: Remove unused functions.
* tests/gpgscm/scheme.c (check_cell_alloced): Remove function.
(check_range_alloced): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter 49e2ae65e8 gpgscm: Use a compact vector representation.
* tests/gpgscm/scheme-private.h (struct cell): Add a compact vector
representation.
* tests/gpgscm/scheme.c (vector_length): Use new representation.
(vector_size): New macro.
(get_vector_object): Use the new representation.
(fill_vector): Likewise.
(vector_elem): Likewise.
(set_vector_elem): Likewise.
(mark): Likewise.
(gc): Likewise.  Be careful not to confuse immediate values for type
flags.
(finalize_cell): Vectors now require finalization.
--

Previously, vectors were represented using consecutive cons cells,
wasting one word per cell for the type information.  Fix that by using
a flat array.

Previously, a vector of size N required 1 + (n + 1) / 2 cells.  Now it
uses 1 + (n - 1 + 2) / 3 cells.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 18:21:24 +01:00
Justus Winter e343984fc5 gpgscm: Provide framework for immediate values.
* tests/gpgscm/scheme.c (IMMEDIATE_TAG): New macro.
({is,set,clr}_immediate): Likewise.
(enum scheme_types): Make type tags disjoint from immediate values.
(TYPE_BITS): We need one more bit now.
(ADJ,T_MASKTYPE): Compute values.
--
Immediate values are disjoint from all type tags and pointers,
allowing us to store immediate values in all memory locations.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 17:09:41 +01:00
Justus Winter d27a4435bd gpgscm: Fix setting the line of the first gc reservation.
* tests/gpgscm/scheme.c (_gc_disable): Negate guard.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 17:09:41 +01:00
Justus Winter 489edf84c9 gpgscm: Introduce macro for the vector length.
* tests/gpgscm/scheme.c (vector_length): New macro.
(get_vector_object): Use the new macro.
(oblist_add_by_name): Likewise.
(oblist_find_by_name): Likewise.
(oblist_all_symbols): Likewise.
(mk_vector): Likewise.
(mark): Likewise.
(new_slot_spec_in_env): Likewise.
(find_slot_spec_in_env): Likewise.
(opexe_2): Likewise.
(opexe_5): Likewise.
--

Introducing an abstraction reduces the coupling between code using
vectors and the implementation of vectors.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 16:24:01 +01:00
Justus Winter 59048b0f1a Revert "tests: Add test demonstrating issue2929."
This reverts commit 5aafa56dff.
2017-01-30 13:25:32 +01:00
Justus Winter 02a39f0d1e tests,w32: Fix GPGME tests requiring a pinentry.
* tests/gpgme/gpgme-defs.scm: Use our fake pinentry, and configure it
to supply the correct passphrase.
--
Previously, the GPGME tests used the fake pinentry distributed with
GPGME which is a Bourne shell script.  Use the fake pinentry from
GnuPG instead.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-25 16:58:46 +01:00
Justus Winter 7d5a0ed792 tests,w32: Fix gpgsm signature verification test.
* tests/gpgsm/verify.scm: Use 'call-with-binary-output-file' to avoid
automatic line-ending conversion.
--
Previously, Windows' automatic line-ending conversion turned '\n' into
'\r\n' when writing the sample to a file, making the signature
invalid.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-25 15:39:30 +01:00
Justus Winter 5f2da5d439 tests: Skip GPGME tests that are not built.
* tests/gpgme/wrap.scm: Skip tests that are not built.
--
Previously, all tests from GPGME's test suite that were not built
(e.g. because GPGME was not configured with QT) were marked as
failures.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-25 11:18:23 +01:00
Justus Winter 6ecd8b3e71 tests,w32: Fix locating GPGME's tests on Windows.
* tests/gpgme/run-tests.scm: Qualify the test with the executable
extension.
--
Previously, the test suite could not locate the test executables on
Windows because the Windows-specific file extension was missing.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-25 11:16:23 +01:00
Justus Winter 5aafa56dff tests: Add test demonstrating issue2929.
* tests/openpgp/Makefile.am (XTESTS): Add new test.
* tests/openpgp/issue2929.scm: New file.
--
This test demonstrates a problem with the TOFU trust model when a new
key is created.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-24 14:28:36 +01:00
Justus Winter 628ff84346 tests: Enable gpgconf test.
* tests/openpgp/Makefile.am (XTESTS): Re-add gpgconf.scm.
--
This partially reverts 25e0298238.

That change was not sufficiently motivated, and our continuous
integration server shows no recent distcheck failures.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-24 14:20:36 +01:00
Werner Koch 25e0298238
build: Change make distcheck configure and temp. remove gpgconf.scm.
* Makefile.am (DISTCHECK_CONFIGURE_FLAGS): Also test gpgtar and
wks-tools.  Disable ntbtls.
* tests/openpgp/Makefile.am (XTESTS): Temporary remove gpgconf.scm.

Signed-off-by: Werner Koch <wk@gnupg.org>
2017-01-23 21:14:32 +01:00
Justus Winter 8b1611a960 tests: Improve GPGHOME handling.
* tests/openpgp/defs.scm (GPGHOME): New variable.
* tests/openpgp/ssh-import.scm: Remove redundant code, use 'path-join'.
* tests/openpgp/tofu.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-16 13:59:56 +01:00
Justus Winter 88e42ef08d tests: Improve gpgconf test.
* tests/openpgp/defs.scm (valgrind): New variable.
(gpg-config): Fix clearing an option.
* tests/openpgp/gpgconf.scm: Also toggle 'quiet'.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-10 15:50:57 +01:00
Justus Winter c8cfc62125 tests: Add test for gpgconf.
* tests/openpgp/Makefile.am (XTESTS): Add new test.
* tests/openpgp/defs.scm (percent-encode): New function.
(gpg-conf): Generalize so that we can feed stdin.
(gpg-config): New function.
* tests/openpgp/gpgconf.scm: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-10 12:40:52 +01:00
Justus Winter 168c8c9d79 tests: New test for --{show,override}-session-key.
* tests/openpgp/Makefile.am (XTESTS): Add new test.
* tests/openpgp/decrypt-session-key.scm: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-05 17:05:59 +01:00
Justus Winter 4ded213698 tests: Fix macro.
* tests/openpgp/defs.scm (with-ephemeral-home-directory): Make
hygienic, use define-macro, do not change to the ephemeral home
directory.
* tests/gpgsm/setup.scm: Change to the ephemeral home directory.
* tests/openpgp/setup.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-05 17:00:36 +01:00
Justus Winter 28e149609d tests,w32: Fix locating the components.
* tests/openpgp/defs.scm (percent-decode): New function.
(bin-prefix): New variable.
(installed?): Likewise.
(tool-hardcoded): Use the new variables.
(gpg-conf): Use the new function to decode the values.
(gpg-components): Do not use '--build-prefix' when 'installed?'.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-04 16:54:41 +01:00
Justus Winter 6d06519833 tests: Fix faked time in the TOFU test.
* tests/openpgp/tofu.scm (GPG): Fix time delta.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-02 18:23:34 +01:00
Justus Winter b0e14bd6ff gpgscm: Fail if too many arguments are given.
* tests/gpgscm/scheme.c (opexe_0): Enable check.
* tests/gpgscm/tests.scm (test::report): Remove superfluous argument.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-02 11:02:34 +01:00
Justus Winter b79274a3b7 gpgscm: Add 'finally', rework all macros.
* tests/gpgscm/init.scm (finally): New macro.
* tests/gpgscm/tests.scm (letfd): Rewrite.
(with-working-directory): Likewise.
(with-temporary-working-directory): Likewise.
(lettmp): Likewise.
--

Rewrite all our macros using 'define-macro'. Use the new control flow
mechanism 'finally', or 'dynamic-wind' where appropriate.  Make sure
the macros are hygienic.  Reduce code duplication.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-02 11:02:34 +01:00
Justus Winter e8b843508d gpgscm: Use boxed values for source locations.
* tests/gpgscm/scheme-private.h (struct port): Use boxed values for
filename and current line.  This allows us to use the same Scheme
object for labeling all expressions in a file.
* tests/gpgscm/scheme.c (file_push): Use boxed type for filename.
(mark): Mark location objects of port objects.
(gc): Mark location objects in the load stack.
(port_clear_location): New function.
(port_reset_current_line): Likewise.
(port_increment_current_line): Likewise.
(file_pop): Adapt accordingly.
(port_rep_from_filename): Likewise.
(port_rep_from_file): Likewise.
(port_close): Likewise.
(skipspace): Likewise.
(token): Likewise.
(_Error_1): Likewise.
(opexe_0): Likewise.
(opexe_5): Likewise.
(scheme_deinit): Likewise.
(scheme_load_file): Likewise.
(scheme_load_named_file): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-02 11:02:34 +01:00
Justus Winter 6e96cdd41a gpgscm: Guard use of union member.
* tests/gpgscm/scheme.c (opexe_5): Check that we have a file port
before accessing filename.  Fixes a crash on 32-bit architectures.

Fixes-commit: e7429b1ced
Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-21 16:14:45 +01:00
Justus Winter 36c1413928 tests: Add test suite for gpgsm.
* configure.ac (AC_CONFIG_FILES): Add new file.
* tests/Makefile.am (SUBDIRS): Add new directory.
* tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939: New file.
* tests/gpgsm/Makefile.am: Likewise.
* tests/gpgsm/cert_dfn_pca01.der: Likewise.
* tests/gpgsm/cert_dfn_pca15.der: Likewise.
* tests/gpgsm/cert_g10code_test1.der: Likewise.
* tests/gpgsm/decrypt.scm: Likewise.
* tests/gpgsm/encrypt.scm: Likewise.
* tests/gpgsm/export.scm: Likewise.
* tests/gpgsm/gpgsm-defs.scm: Likewise.
* tests/gpgsm/import.scm: Likewise.
* tests/gpgsm/plain-1.cms.asc: Likewise.
* tests/gpgsm/plain-2.cms.asc: Likewise.
* tests/gpgsm/plain-3.cms.asc: Likewise.
* tests/gpgsm/plain-large.cms.asc: Likewise.
* tests/gpgsm/run-tests.scm: Likewise.
* tests/gpgsm/setup.scm: Likewise.
* tests/gpgsm/shell.scm: Likewise.
* tests/gpgsm/sign.scm: Likewise.
* tests/gpgsm/verify.scm: Likewise.
--
The certificates and keys are taken from GPGME's test suite.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-20 16:51:38 +01:00
Justus Winter c067a012c7 tests: Add macro managing ephemeral home directories.
* tests/openpgp/defs.scm (with-ephemeral-home-directory): New macro.
* tests/openpgp/setup.scm: Use the new macro.
2016-12-20 16:49:05 +01:00
Justus Winter a30c0a6972 tests: Move argument parser.
* tests/gpgme/gpgme-defs.scm (flag): Move...
* tests/gpgscm/tests.scm: ... over here.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-20 16:25:35 +01:00
Justus Winter e2ed3c1597 tests: Add missing encrypted sample, cleanup samples handling.
* tests/openpgp/Makefile.am (TEST_FILES): Add new file.
* tests/openpgp/defs.scm (plain-files): Add 'plain-large'.
(all-files): New variable.
(create-sample-files): New function.
(create-legacy-gpghome): Use new function.
* tests/openpgp/plain-large.asc: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-20 16:25:35 +01:00
Justus Winter 65a0d6a24e tests: Use the common test framework for the migration tests.
* tests/migrations/Makefile.am (reqired_pgms): Add 'gpgscm'.
(TESTS_ENVIRONMENT): Populate.
(TESTS): Rename to 'XTESTS'.
(xcheck): New target.
(EXTRA_DIST): Add new files.
(CLEANFILES): Remove log files.
* tests/migrations/common.scm: Honor 'verbose', fix paths.
* tests/migrations/run-tests.scm: New file.
* tests/migrations/setup.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 17:47:10 +01:00
Justus Winter 0bf16d7026 tests: Use sequential test runner if only one test is given.
* tests/openpgp/run-tests.scm: Use sequential test runner if only one
test is given.
--

This allows one to set the environment variable TESTFLAGS to
'--parallel' and enjoy faster test execution times without interfering
with stdio when one works on a single test.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 17:23:56 +01:00
Neal H. Walfield aec89a7297 test: Extend TOFU tests to also check the days with signatures.
* tests/openpgp/tofu.scm (GPGTIME): Define the "standard" base time.
(faketime): New function.
(days->seconds): Likewise.
(GPG): Use faketime.
(check-counts): Also check the number of expected days with signatures
and encryptions.  Update callers.  Extend tests.

Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-12-19 16:01:39 +01:00
Justus Winter a1afc450e1 tests: New test for --delete-[secret-]keys.
* tests/openpgp/Makefile.am (XTESTS): Add new test.
* tests/openpgp/defs.scm (keys): New variable.
(have-public-key?): New function.
(have-secret-key?): Likewise.
(have-secret-key-file?): Likewise.
* tests/openpgp/delete-keys.scm: New file.
* tests/openpgp/quick-key-manipulation.scm: Move the accessors to
'defs.scm'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 15:42:35 +01:00
Justus Winter a45dc0849d gpgscm: Change associativity of ::.
* tests/gpgscm/scheme.c (mk_atom): Change associativity of the ::
infix-operator.  This makes it possible to naturally express accessing
nested structures (e.g. a:🅱️:c).

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 15:42:35 +01:00
Justus Winter 3949cbd112 gpgscm: Display location when assertions fail.
* tests/gpgscm/lib.scm (assert): Use location information if
available.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 15:42:35 +01:00
Justus Winter df00745d6e gpgscm: Make exception handling more robust.
* tests/gpgscm/init.scm (throw'): Check that args is a list.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 15:42:35 +01:00
Justus Winter 41ad04d403 g10: Rework the --quick-* interface.
* g10/gpg.c (opts): Rename options.
(main): Update errors.
* doc/gpg.texi: Update accordingly.
--
I decided not to keep the old versions as aliases in the documentation
because the interface is a fairly recent addition.

GnuPG-bug-id: 2700
Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-15 15:32:51 +01:00
Justus Winter 0e2055c7d3 build: Fix distcheck.
* tests/gpgme/Makefile.am (CLEANFILES): New variable, clean test logs.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-15 11:02:24 +01:00
Justus Winter 948cca9c99 tests: Reuse GPGME's tests.
* configure.ac (AC_CONFIG_FILES): Add new Makefile.
* tests/Makefile.am (SUBDIRS): Add new directory.
* tests/gpgme/Makefile.am: New file.
* tests/gpgme/gpgme-defs.scm: Likewise.
* tests/gpgme/run-tests.scm: Likewise.
* tests/gpgme/setup.scm: Likewise.
* tests/gpgme/wrap.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-14 16:50:44 +01:00