Commit Graph

393 Commits

Author SHA1 Message Date
Ingo Klöcker
34d9defc42 core: Allow specifying an expiration date for key signatures
* src/context.h (struct gpgme_context): Add 'cert_expire'.
* src/engine-gpg.c (append_args_from_cert_expire): New.
(gpg_edit): Set option according to the new flag.
* src/gpgme.c (gpgme_release): Free 'cert_expire'.
(gpgme_set_ctx_flag, gpgme_get_ctx_flag): Add "cert-expire".

* tests/gpg/Makefile.am (c_tests): Add new test.
(gpg.conf): Write "allow-weak-key-signatures" to gpg.conf.
* tests/gpg/t-edit-sign.c: New.
--

The new context flag "cert-expire" allows setting the expiration date
for key signatures created with gpgme_op_interact.

GnuPG-bug-id: 5336, 5505
2021-06-22 16:35:03 +02:00
Werner Koch
fde20940b5
core: New data flags "io-buffer-size" and "sensitive".
* src/data.c (_gpgme_data_release): Free buffers.
(gpgme_data_seek): Adjust from renamed fields.
(gpgme_data_set_flag): Implement new flags.
(_gpgme_data_inbound_handler): Allow the use of a malloced buffer.
(_gpgme_data_outbound_handler): Ditto.
* src/data.h (BUFFER_SIZE): Move out of the struct definition.
(struct gpgme_data): Remove pending filed and introduce inbound and
outbound fields.

* src/conversion.c (_gpgme_wipememory): New.  Taken from GnuPG.
* src/cJSON.c (wipememory): Use this here too.

* tests/run-decrypt.c (main): Add options "--large-buffers" and
"--sensitive".
--

GnuPG-bug-id: 5478
Signed-off-by: Werner Koch <wk@gnupg.org>
2021-06-14 19:51:28 +02:00
Werner Koch
31eb45f016
tests: Improve the output of the run-keylist helper.
* tests/run-keylist.c (main): Print all infos from the primary key.
--

The test tool printed only the computed infos for the key and not the
detailed one fro the primary key.  The new output better reflects the
data structure.

Related to
GnuPG-bug-id: 5454
2021-05-28 18:31:43 +02:00
Werner Koch
aa98081356
core: Allow for older compilers.
* tests/run-verify.c (main): Remove C99-only syntax.
* tests/run-threaded.c (start_keylistings): Ditto.
--

Older gcc's do not grok this and there is no real need for it.

  run-verify.c:324: error: ‘for’ loop initial declarations are only
  allowed in C99 mode
  run-verify.c:324: note: use option -std=c99 or -std=gnu99 to compile
  your code

Reported-by: Lars Hecking
2021-05-12 08:50:04 +02:00
Ingo Klöcker
276187f6b6 core: Extend gpgme_key_sig_t with trust signature members.
* src/gpgme.h.in (struct _gpgme_key_sig): Add fields 'trust_depth',
'trust_value', and 'trust_scope'.
* src/key.c (gpgme_key_unref): Free trust_scope.
* src/keylist.c (keylist_colon_handler): Set the fields.
* tests/run-keylist.c (main): Print the fields.
--

The trust signature values are part of gpg's output since the year 2003.
This now adds support to gpgme.

GnuPG-bug-id: 5245, 5419
2021-05-05 19:23:48 +02:00
Werner Koch
0821e2b149
core: New flag GPGME_KEYSIGN_FORCE.
* src/gpgme.h.in (GPGME_KEYSIGN_FORCE): New.
* src/engine-gpg.c (gpg_keysign): Implement.

* tests/run-keysign.c (show_usage): Add option --force
--

GnuPG-bug-id: 4584
2021-03-11 11:49:07 +01:00
Ingo Klöcker
5137d7fc21 core: Make listing of signatures work if only secret keys are listed
* src/engine-gpg.c (gpg_keylist_build_options): Add "--with-sig-check"
argument if signatures shall be listed.
* tests/gpg/t-keylist-secret-sig.c: New.
* tests/gpg/Makefile.am (c_tests): Add new test.
--

GnuPG-bug-id: 3580
2021-01-05 17:44:16 +01:00
Ingo Klöcker
f3407d0ee4 core: New function gpgme_op_revsig.
* src/gpgme.h.in (gpgme_op_revsig_start, gpgme_op_revsig): New.
(GPGME_REVSIG_LFSEP): New.
* src/context.h (ctx_op_data_id_t): Add OPDATA_REVSIG.
* src/revsig.c: New.
* src/Makefile.am (main_sources): Add revsig.
* src/libgpgme.vers, src/gpgme.def: Add gpgme_op_revsig and
gpgme_op_revsig_start.
* src/engine.h, src/engine.c: (_gpgme_engine_op_revsig): New.
* src/engine-backend.h (engine_ops): Add 'revsig' and adjust all
engine initializers.
* src/engine-gpg.c (gpg_revsig): New.
(_gpgme_engine_ops_gpg): Set revsig to gpg_revsig.
* doc/gpgme.texi: Document new functions.
* tests/run-keysign.c: Add option --revoke.
--

This extends GPGME to support the --quick-revoke-sig command
added by GnuPG 2.2.24. This allows revoking key signatures.

GnuPG-bug-id: 5094
2020-10-29 12:57:10 +01:00
Werner Koch
25e2d717f4
tests: Fix gcc incompatibility
* tests/json/t-json.c: Remove var definitions inside a for statement.
--

This useful C99 feature seems to work only in recent gcc versions.  We
can't use it; see gnupg/doc/HACKING.

GnuPG-bug-id: 5088
2020-10-03 19:54:00 +02:00
Werner Koch
e4ee706e27
core: Fully implement the inquire callback for assuan_transact
* src/engine-assuan.c (inquire_cb): Implement returning data.

* tests/opassuan/t-command.c (inq_cb): Send some test data.
--

The old code only allowed to send an empty response which was good
enough for scdaemon's KNOWNCARDP inquire but not to send actual data.
A quick test using a test smartcard might be

 ./t-command 'scd setattr --inquire PRIVATE-DO-1'

and then reading the data back using

  gpg-connect-agent 'scd getattr PRIVATE-DO-1' /bye

Signed-off-by: Werner Koch <wk@gnupg.org>
2020-09-09 12:13:20 +02:00
Ingo Klöcker
db82e99a8a core: New function gpgme_op_setexpire.
* src/gpgme.h.in (gpgme_op_setexpire_start, gpgme_op_setexpire): New.
* src/libgpgme.vers, src/gpgme.def: Add new functions.
* src/genkey.c (setexpire): New.
(gpgme_op_setexpire_start, gpgme_op_setexpire): New.
* src/engine.h, src/engine.c: (_gpgme_engine_op_setexpire): New.
* src/engine-backend.h (engine_ops): Add 'setexpire' and adjust all
engine initializers.
* src/engine-gpg.c (gpg_setexpire): New.
(_gpgme_engine_ops_gpg): Set setexpire to gpg_setexpire.
* doc/gpgme.texi: Document new functions.
* tests/run-genkey.c: Add option --setexpire.
--

This extends GPGME to support the --quick-set-expire command
added by GnuPG 2.1.22. This allows changing subkeys expiry
date without going through the editinteractor interface.

Co-authored-by: Andre Heinecke <aheinecke@gnupg.org>
GnuPG-bug-id: 4999
2020-08-04 16:51:56 +02:00
Werner Koch
7f9e0ca57b
core: New export mode to export as OpenSSH public key.
* src/gpgme.h.in (GPGME_EXPORT_MODE_SSH): New.
* src/export.c (export_ext_start): Allow for new mode.
* src/engine-gpg.c (export_common): Implement.
* tests/run-export.c (status_cb): New.
(main): New options --status and --ssh.
--

GnuPG-bug-id: 4310
Signed-off-by: Werner Koch <wk@gnupg.org>
2020-07-16 12:00:46 +02:00
Werner Koch
8589091682
core: Deprecate the non-working trustlist functions.
* src/gpgme.h.in: Clarify that the trustlist function should not be
used.
* src/engine.c (_gpgme_engine_op_trustlist): Always return an error.
* src/engine-backend.h (struct engine_ops): Remove trustlist member.
* src/engine-gpg.c (gpg_trustlist): Remove.
(struct engine_ops): Remove that member.  Also in all other engines.
* tests/gpg/t-trustlist.c: Remove.
* lang/python/tests/t-trustlist.py: Remove.
--

This never worked in reality because the required feature has been
removed from GnuPG version 1.3.2 soon after introduction of this
feature in gpgme - 17 years ago.  It was anyway marked as
experimental.  We keep the API and ABI, though.

GnuPG-bug-id: 4834
Signed-off-by: Werner Koch <wk@gnupg.org>
2020-07-15 16:34:24 +02:00
NIIBE Yutaka
0cc040e82f tests: Remove/change tests for GnuPG 2.3 with no gpg.keyserver.
* lang/qt/tests/t-config.cpp (testKeyserver): Remove.
* tests/gpg/t-gpgconf.c (main): Test with dirmngr.keyserver.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2020-05-11 14:20:48 +09:00
Andre Heinecke
5c0d1c7f76
tests, json: Do not check for keygrip of pubkeys
* tests/json/t-keylist-secret.out.json: Do not check for keygrip
of bravo key.

--
Since GnuPG 2.2.19 the keygrip is not emitted for public keys
in a keylisting --with-secret.

As the GPGME test suite should pass with several versions
the json test cannot test this as the suite does not allow
version checks for different output.

What the intended behavior is might still be up for discussion,
always adding --with-keygip is not a good solution because
it slows down keylistings for large keyrings.

GnuPG-Bug-Id: T4820
2020-05-08 10:30:53 +02:00
NIIBE Yutaka
3658e2df65 tests: Add ECC key generation for tests/gpgsm.
* tests/gpgsm/t-genkey.c (check_result): New.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2020-03-27 19:50:24 +09:00
Werner Koch
3afa534645
core: New context flags "include-key-block" and "auto-key-import".
* src/gpgme.c (gpgme_set_ctx_flag): Add flags "include-key-block" and
"auto-key-import".
(gpgme_get_ctx_flag): Ditto.
* src/context.h (struct gpgme_context): Add flags include_key_block
and auto_key_import.
* src/engine-gpg.c (struct engine_gpg): Likewise.
(gpg_set_engine_flags): Set the flags for gpg versions >= 2.2.20.
(gpg_decrypt): Set option according to the new flags.
(gpg_encrypt): Ditto.
(gpg_encrypt_sign): Ditto.
(gpg_sign): Ditto.
(gpg_verify): Ditto.

tests/run-verify: Add option --auto-key-import.
tests/run-sign: add option --include-key-block.
--

GnuPG-bug-id: 4856
Signed-off-by: Werner Koch <wk@gnupg.org>
2020-03-17 17:24:21 +01:00
Andre Heinecke
cff600f1f6
Do not test for a bug in older GnuPG versions
* tests/json/t-keylist-secret.out.json

--
Since at least 2.2.19 GnuPG no longer emits secret = true
for keys where it does not have a secret. To avoid
failures with older versions we remove the check altogether.

GnuPG-Bug-Id: T4820
2020-01-29 11:01:10 +01:00
Werner Koch
5eeae535ee
core: Extend gpgme_user_id_t with uidhash member.
* src/gpgme.h.in (struct _gpgme_user_id): Add field 'uidhash'.
* src/key.c (gpgme_key_unref): Free it.
* src/keylist.c (keylist_colon_handler): Set it.
* tests/run-keylist.c (main): Print it.
--

The uidhash value is part of gpg's output since the year 2005.  This
now adds support to gpgme.  The application for uidhash is to select
a user id in an edit interactor: Instead of giving the number of the
user id, the uidhash value can be be used to avoid tracking the user
id numbers.

Signed-off-by: Werner Koch <wk@gnupg.org>
2019-12-13 15:11:00 +01:00
NIIBE Yutaka
b97434fbf0 json: Fix t-decrypt-verify.out for GnuPG >= 2.3.
* tests/json/t-decrypt-verify.out.json: Remove check with key of
04071FB807287134.

--

GnuPG 2.3 changes how public key decryption works; It collects list of
PUBKEY_ENC packets and then processes an ENCRYPTED* packet.  At the
stage of processing an ENCRYPTED* packet, it checks if private keys
can decrypt any of PUBKEY_ENC packets.  It does not necessarily
examine all of PUBKEY_ENC packets.  Only when it finds a PUBKEY_ENC
packet cannot be decrypted, it reports STATUS_NO_SECKEY with keyid of
that packet.

GnuPG 2.2 or older tries PUBKEY_ENC packets in order, and the first
successful PUBKEY_ENC packet is used.  Rest of PUBKEY_ENC packets are
not examined, but STATUS_NO_SECKEY with keyid is reported even when
there is a valid private key.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2019-08-06 11:19:59 +09:00
Werner Koch
f6fd90c99a
tests: Minor fix to run-threaded.c.
* tests/run-threaded.c (random_data_close): Correct FD test.
--

An invalid DS is -1 and not 0; this fix is for correctness and does
not chnage anything in the real world.

Signed-off-by: Werner Koch <wk@gnupg.org>
2019-06-06 18:59:16 +02:00
Andre Heinecke
e6f2827306
tests: Add option "allow-del" to run-threaded
* tests/run-threaded.c (main): Handle allow-del.
(allow-del): New. Variable to allow deletion of keys.
(import): Delete key after import if allow-del is set.
(delete_impres): Delete keys from an import result.
(delete_fpr): Delete a key by fingerprint.

--
This is intended to test write access and locking of the
keyring by repeatedly importing and deleting pubkeys.

It is an option because it might cause keyring corruption
etc. so it should be explicitly enabled.
2019-06-06 09:19:02 +02:00
Andre Heinecke
024a7f75d4
tests: Implement import in run-threaded
* tests/run-threaded.c (import): New.
(do_data_op): Call it.
2019-06-05 17:23:59 +02:00
Andre Heinecke
3a3648e3a5
tests: Use synced output for error in run-threaded
* tests/run-threaded.c (do_data_op): Use synced out macro.
2019-06-05 16:20:31 +02:00
Andre Heinecke
3a11421d0f
tests: Avoid variable named the same as a macro
* tests/run-threaded.c (decrypt, verify): Don't use a variable name
that is also a macro.

--
It just looks confusing and strange at first glance.
2019-06-05 16:20:31 +02:00
Andre Heinecke
9bbe15ebbc
tests,w32: Fix thread creation in run-threaded
* tests/run-threaded.c (create_thread): Check proper return
value and not return value of CloseHandle.
2019-06-05 16:20:31 +02:00
Daniel Kahn Gillmor
c5c3a9d10b tests: add two new types of encrypted data
* tests/gpg/cipher-3.asc: add an encrypted file containing signatures
(one from a known key, and one from an unknown key)
* tests/gpg/cipher-no-sig.asc: add an encrypted file containing no
signatures at all

--

We currently aren't using these files yet, but they should be useful
for exercising the library in unusual circumstances (where the bugs
are).

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-05-02 22:23:28 -04:00
Andre Heinecke
4746c5c9e2
tests: Add cms mode to run-import
* tests/run-import.c (show_usage): Add doc for cms / openpgp.
(main): Handle protocol.
2019-05-02 10:26:44 +02:00
Werner Koch
b159b2eddd
tests: Let run-verify print the de-vs flag.
* tests/run-verify.c (print_result): Chack is_de_vs.
* tests/run-import.c (main): Fix bad parameter for format string.

Signed-off-by: Werner Koch <wk@gnupg.org>
2019-02-28 14:01:47 +01:00
Andre Heinecke
f8312d7c33
tests: Fix memleak in run-threaded
* tests/run-threaded.c (verify): Free msg.
2019-02-11 15:33:34 +01:00
NIIBE Yutaka
66bcb8acb2 build: With LD_LIBRARY_PATH defined, use --disable-new-dtags.
* configure.ac (LDADD_FOR_TESTS_KLUDGE): New for --disable-new-dtags.
* tests/Makefile.am (LDADD): Use LDADD_FOR_TESTS_KLUDGE.
* lang/cpp/tests/Makefile.am, lang/qt/tests/Makefile.am: Likewise.
* tests/gpg/Makefile.am, tests/gpgsm/Makefile.am: Likewise.
* tests/json/Makefile.am, tests/opassuan/Makefile.am: Likewise.

--

GnuPG-bug-id: 4298
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2019-01-16 10:59:25 +09:00
Andre Heinecke
ce327f994a
tests: Add diagnostic example to run-import.c
* tests/run-import.c (main): Show diagnostics in verbose mode.
2019-01-15 08:36:26 +01:00
Andre Heinecke
a9cfb6dad8
tests, json: Make them run on debian stable
* tests/json/t-json.c (main): Relax version check a bit.
2018-11-28 10:45:27 +01:00
Werner Koch
8d91c0f4cd
Add SPDX identifiers to most source files
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-16 13:27:33 +01:00
Andre Heinecke
d0402f886b
tests: Add run-threaded for multithread tests
* tests/Makefile.am (run-threaded): Add.
* tests/run-threaded.c: New.

--
This test is intended to help detect race conditions
or other multithread problems. It can also be used
to put the whole GnuPG system under extreme load.
2018-11-15 11:57:27 +01:00
Andre Heinecke
004e2cad2f
tests,json: Clean openpgp-revocs.d
* tests/json/clean-local: Remove revocs.d
2018-11-15 10:33:35 +01:00
Andre Heinecke
40d962b43a
tests,json: Move version check into t-json
* tests/gpg/t-support.h (check_gpg_version, compare_versions),
(parse_version_string, parse_version_number): Remove version
check code.
* tests/json/t-json.c (check_gpg_version, compare_versions),
(parse_version_string, parse_version_number): Add.
--

t-support header was not a good place for this. It should
go into a library e.g. gpgrt in the future. For now we
can keep it close to where it is needed.
2018-11-15 10:31:22 +01:00
Andre Heinecke
d3dae4a445
tests,json: Add sig-notations test
* tests/json/t-sig-notations.in.json,
tests/json/t-sig-notations.out.json: New
* tests/json/Makefile.am (EXTRA_DIST): Add files.
* tests/json/t-json.c: Register it.
2018-11-14 17:56:23 +01:00
Andre Heinecke
def030e843
tests,json: Fix distcheck
* tests/json/Makefile.am (EXTRA_DIST): Add inital and final scripts.
(t_json_SOURCES): Don't use cJSON.o as source.
2018-11-14 17:21:24 +01:00
Andre Heinecke
d0087d45f0
tests,json: Add more tests
* t-config-opt.in.json,
 t-config-opt.out.json,
 t-import.in.json,
 t-import.out.json,
 t-sign.in.json,
 t-sign.out.json: New.
--
These should actually have been in a previous commit as
they are already registered.
2018-11-14 17:05:25 +01:00
Andre Heinecke
88b7221eb7
tests,json: Add missing files and chunking test
* tests/json/Makefile.am, tests/json/final.test,
tests/json/initial.test: New.
* tests/json/t-chunking.in.json, tests/json/t-chunking.out.json:
New test.
* tests/json/t-json.c: Register new test.

--
Oops..
2018-11-14 15:55:02 +01:00
Andre Heinecke
27ca12e815
tests,json: Fix match if the first child differs
* tests/json/t-json.c (test_contains): Try all siblings of
the haystack child.

--
This fixes the case where we don't match against the
first child because the order might have changed or
a new element was inserted at the top. Then we
have to try out also all the siblings.
2018-11-14 15:17:18 +01:00
Andre Heinecke
dd4b80a5f6
tests,json: Add the bulk of tests
* t-json.c (tests): Register new tests.
* t-createkey.in.json,
  t-createkey.out.json,
  t-decrypt-verify.in.json,
  t-decrypt-verify.out.json,
  t-decrypt.in.json,
  t-decrypt.out.json,
  t-delete.in.json,
  t-delete.out.json,
  t-encrypt-sign.in.json,
  t-encrypt-sign.out.json,
  t-encrypt.in.json,
  t-encrypt.out.json,
  t-export-secret-info.in.json,
  t-export-secret-info.out.json,
  t-export.in.json,
  t-export.out.json,
  t-json.c,
  t-keylist-secret.in.json,
  t-keylist-secret.out.json,
  t-keylist.in.json,
  t-keylist.out.json,
  t-verify.in.json,
  t-verify.out.json,
  t-version.in.json,
  t-version.out.json: New.

--
Except for help and getmore there is now a test for each command.
2018-11-14 15:15:21 +01:00
Andre Heinecke
9a31fdcb11
tests,json: Add wildcard string matching
* tests/json/t-json.c (test_contains): When searching for "*" accept
every string.

--
This allows it to write tests that check for the existence of
a string value but don't care about the contents. E.g. for Data.
2018-11-14 14:57:40 +01:00
Andre Heinecke
e55e467d5f
tests,json: Skip tests for older GnuPG versions
* tests/json/t-json.c (main): Skip if version is not at least
2.2.0

--
In the past new tests often failed when a modern GPGME was
used with old GnuPG's.
This should avoid the hassle for packagers without the
requirement that we test against old versions.
2018-11-14 14:55:09 +01:00
Andre Heinecke
ca2e2b3d69
tests,json: Suffix .json to test pattern
* tests/json/t-config.in, tests/json/t-config.out: Renamed.
* t-json.c (run_test): Use new naming pattern.
2018-11-14 14:53:28 +01:00
Andre Heinecke
5b61c092e7
tests,gpg: Add version check hlp to t-support
* t-support.h (parse_version_number, parse_version_string)
(compare_versions): New. Copy&Paste from src/version.c
(check_gpg_version): New helper to check for a gpg version.

--
This should make it easier to write tests that e.g.
rely on modern gnupg features.
2018-11-14 14:50:57 +01:00
Andre Heinecke
9933641cce
tests,json: Improve verbose mode and add verbose 2
* tests/json/t-json.c (main): Handle multiple verbose args.
(test-contains): Improve verbose output
2018-11-14 13:14:52 +01:00
Andre Heinecke
3e5684d99b
tests,json: Fix and improve t-json
* tests/json/t-json.c (run_test): Terminate argv array correctly.
(run_test): Note and handle empty response.
2018-11-14 13:05:36 +01:00
Andre Heinecke
0c31837766
tests: Add json testrunner
* configure.ac: Configure makefile.
* tests/Makefile.am: Run json tests if gpg tests are run.
* tests/json/t-json.c: New testrunner for json tests.
* tests/json/t-config.in, tests/json/t-config.out: First test.
--
The idea of this test runner is that it only looks for parts
in the output. This should allow it to write robust tests
that check for the basics in the output but don't fail when
the output is extended or slightly changed.
2018-11-14 11:51:08 +01:00