diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am index 6d995391..c4a4ce42 100644 --- a/tests/gpg/Makefile.am +++ b/tests/gpg/Makefile.am @@ -1,124 +1,126 @@ # Copyright (C) 2000 Werner Koch (dd9jn) # Copyright (C) 2001, 2004, 2005, 2009 g10 Code GmbH # # This file is part of GPGME. # # GPGME is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # GPGME 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 Lesser General # Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, see . # SPDX-License-Identifier: LGPL-2.1-or-later ## Process this file with automake to produce Makefile.in GPG = gpg GPG_AGENT = gpg-agent GNUPGHOME=$(abs_builddir) TESTS_ENVIRONMENT = GNUPGHOME=$(GNUPGHOME) LC_ALL=C GPG_AGENT_INFO= \ top_srcdir=$(top_srcdir) # The keylist tests must come after the import and the edit test. noinst_HEADERS = t-support.h if HAVE_W32_SYSTEM tests_unix = else tests_unix = t-eventloop t-thread1 t-thread-keylist t-thread-keylist-verify endif c_tests = \ t-encrypt t-encrypt-sym t-encrypt-sign t-sign t-signers \ t-decrypt t-verify t-decrypt-verify t-sig-notation t-export \ t-import t-edit t-keylist t-keylist-sig t-keylist-secret-sig t-wait \ t-encrypt-large t-file-name t-gpgconf t-encrypt-mixed t-edit-sign \ $(tests_unix) TESTS = initial.test $(c_tests) final.test CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \ gpg-agent.conf pubring.kbx~ S.gpg-agent gpg.conf pubring.gpg~ \ random_seed S.gpg-agent .gpg-v21-migrated pubring-stamp \ gpg-sample.stamp tofu.db *.conf.gpgconf.bak private_keys = \ 13CD0F3BDF24BE53FE192D62F18737256FF6E4FD \ 76F7E2B35832976B50A27A282D9B87E44577EB66 \ A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD \ 13CBE3758AFE42B5E5E2AE4CED27AFA455E3F87F \ 7A030357C0F253A5BBCD282FFC4E521B37558F5C EXTRA_DIST = initial.test final.test \ pubdemo.asc secdemo.asc cipher-1.asc cipher-2.asc \ cipher-3.asc cipher-no-sig.asc \ geheim.txt pubkey-1.asc seckey-1.asc pinentry $(private_keys) \ gpg.conf.in BUILT_SOURCES = gpg.conf gpg-agent.conf pubring-stamp \ gpg-sample.stamp AM_CPPFLAGS = -I$(top_builddir)/src @GPG_ERROR_CFLAGS@ AM_LDFLAGS = -no-install LDADD = ../../src/libgpgme.la @LDADD_FOR_TESTS_KLUDGE@ WITH_THREAD_CPPFLAGS = -I$(top_builddir)/src @GPG_ERROR_MT_CFLAGS@ WITH_THREAD_LDADD = ../../src/libgpgme.la \ @GPG_ERROR_MT_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ t_thread1_CPPFLAGS = $(WITH_THREAD_CPPFLAGS) t_thread1_LDADD = $(WITH_THREAD_LDADD) t_thread_keylist_CPPFLAGS = $(WITH_THREAD_CPPFLAGS) t_thread_keylist_LDADD = $(WITH_THREAD_LDADD) t_thread_keylist_verify_CPPFLAGS = $(WITH_THREAD_CPPFLAGS) t_thread_keylist_verify_LDADD = $(WITH_THREAD_LDADD) t_cancel_CPPFLAGS = $(WITH_THREAD_CPPFLAGS) t_cancel_LDADD = $(WITH_THREAD_LDADD) # We don't run t-genkey and t-cancel in the test suite, because it # takes too long tests_skipped = t-genkey if !HAVE_W32_SYSTEM tests_skipped += t-cancel endif noinst_PROGRAMS = $(c_tests) $(tests_skipped) clean-local: -$(TESTS_ENVIRONMENT) $(top_srcdir)/tests/start-stop-agent --stop -rm -fR private-keys-v1.d gpg-sample.stamp: $(srcdir)/$(private_keys) -$(TESTS_ENVIRONMENT) gpgconf --kill all $(MKDIR_P) ./private-keys-v1.d for k in $(private_keys); do \ - cp $(srcdir)/$$k private-keys-v1.d/$$k.key; \ - done + cp $(srcdir)/$$k private-keys-v1.d/$$k.key; \ + done echo x > ./gpg-sample.stamp pubring-stamp: $(srcdir)/pubdemo.asc gpg-sample.stamp $(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \ - --import $(srcdir)/pubdemo.asc + --import $(srcdir)/pubdemo.asc -$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \ --import $(srcdir)/secdemo.asc + -$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \ + --import-ownertrust $(srcdir)/ownertrust.txt echo x > ./pubring-stamp gpg.conf: $(srcdir)/gpg.conf.in cp $(srcdir)/gpg.conf.in gpg.conf gpg-agent.conf: # This is required for gpg2, which does not support command fd for the # passphrase. disable-scdaemon is required so that we don't try using # a key from a smartcard reader (error might be: Unusable secret key) echo pinentry-program $(abs_srcdir)/pinentry > ./gpg-agent.conf echo disable-scdaemon >> ./gpg-agent.conf # end-of-file diff --git a/tests/gpg/ownertrust.txt b/tests/gpg/ownertrust.txt new file mode 100644 index 00000000..0f31f9e4 --- /dev/null +++ b/tests/gpg/ownertrust.txt @@ -0,0 +1,3 @@ +# List of assigned trustvalues, created Mi 08 Feb 2023 09:52:04 CET +# (Use "gpg --import-ownertrust" to restore them) +A0FF4590BB6122EDEF6E3C542D727CC768697734:6: diff --git a/tests/gpg/t-decrypt-verify.c b/tests/gpg/t-decrypt-verify.c index cbd6cc70..211f8129 100644 --- a/tests/gpg/t-decrypt-verify.c +++ b/tests/gpg/t-decrypt-verify.c @@ -1,145 +1,146 @@ /* t-decrypt-verify.c - Regression test. * Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH * * This file is part of GPGME. * * GPGME is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * GPGME 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . * SPDX-License-Identifier: LGPL-2.1-or-later */ /* We need to include config.h so that we know whether we are building with large file system (LFS) support. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "t-support.h" static void check_verify_result (gpgme_verify_result_t result, unsigned int summary, - const char *fpr, gpgme_error_t status) + const char *fpr, gpgme_error_t status, int validity) { gpgme_signature_t sig; sig = result->signatures; if (!sig || sig->next) { fprintf (stderr, "%s:%i: Unexpected number of signatures\n", __FILE__, __LINE__); exit (1); } if (sig->summary != summary) { fprintf (stderr, "%s:%i: Unexpected signature summary: 0x%x\n", __FILE__, __LINE__, sig->summary); exit (1); } if (strcmp (sig->fpr, fpr)) { fprintf (stderr, "%s:%i: Unexpected fingerprint: %s\n", __FILE__, __LINE__, sig->fpr); exit (1); } if (gpgme_err_code (sig->status) != status) { fprintf (stderr, "%s:%i: Unexpected signature status: %s\n", __FILE__, __LINE__, gpgme_strerror (sig->status)); exit (1); } if (sig->notations) { fprintf (stderr, "%s:%i: Unexpected notation data\n", __FILE__, __LINE__); exit (1); } if (sig->wrong_key_usage) { fprintf (stderr, "%s:%i: Unexpectedly wrong key usage\n", __FILE__, __LINE__); exit (1); } - if (sig->validity != GPGME_VALIDITY_UNKNOWN) + if (sig->validity != validity) { - fprintf (stderr, "%s:%i: Unexpected validity: %i\n", - __FILE__, __LINE__, sig->validity); + fprintf (stderr, "%s:%i: Unexpected validity: " + "want=%i have=%i\n", + __FILE__, __LINE__, validity, sig->validity); exit (1); } if (gpgme_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR) { fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n", __FILE__, __LINE__, gpgme_strerror (sig->validity_reason)); exit (1); } } int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in, out; gpgme_decrypt_result_t decrypt_result; gpgme_verify_result_t verify_result; char *cipher_2_asc = make_filename ("cipher-2.asc"); char *agent_info; (void)argc; (void)argv; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); agent_info = getenv("GPG_AGENT_INFO"); if (!(agent_info && strchr (agent_info, ':'))) gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); err = gpgme_data_new_from_file (&in, cipher_2_asc, 1); free (cipher_2_asc); fail_if_err (err); err = gpgme_data_new (&out); fail_if_err (err); err = gpgme_op_decrypt_verify (ctx, in, out); fail_if_err (err); decrypt_result = gpgme_op_decrypt_result (ctx); if (decrypt_result->unsupported_algorithm) { fprintf (stderr, "%s:%i: unsupported algorithm: %s\n", __FILE__, __LINE__, decrypt_result->unsupported_algorithm); exit (1); } print_data (out); verify_result = gpgme_op_verify_result (ctx); - check_verify_result (verify_result, 0, + check_verify_result (verify_result, GPGME_SIGSUM_VALID|GPGME_SIGSUM_GREEN, "A0FF4590BB6122EDEF6E3C542D727CC768697734", - GPG_ERR_NO_ERROR); + GPG_ERR_NO_ERROR, GPGME_VALIDITY_FULL); gpgme_data_release (in); gpgme_data_release (out); gpgme_release (ctx); return 0; } diff --git a/tests/gpg/t-keylist-secret-sig.c b/tests/gpg/t-keylist-secret-sig.c index c0ef5c0c..d9c88eaf 100644 --- a/tests/gpg/t-keylist-secret-sig.c +++ b/tests/gpg/t-keylist-secret-sig.c @@ -1,628 +1,628 @@ /* t-keylist-secret-sig.c - Regression test. * Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2001, 2003, 2004 g10 Code GmbH * * This file is part of GPGME. * * GPGME is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * GPGME 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . * SPDX-License-Identifier: LGPL-2.1-or-later */ /* We need to include config.h so that we know whether we are building with large file system (LFS) support. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "t-support.h" struct { const char *fpr; const char *sec_keyid; struct { const char *name; const char *comment; const char *email; struct { gpgme_pubkey_algo_t algo; const char *keyid; const char *name; const char *comment; const char *email; unsigned int sig_class; int exportable; } sig; } uid[3]; } keys[] = { { "A0FF4590BB6122EDEF6E3C542D727CC768697734", "6AE6D7EE46A871F8", { { "Alfa Test", "demo key", "alfa@example.net", { GPGME_PK_DSA, "2D727CC768697734", "Alfa Test", "demo key", "alfa@example.net", 19, 1 } }, { "Alpha Test", "demo key", "alpha@example.net", { GPGME_PK_DSA, "2D727CC768697734", "Alfa Test", "demo key", "alfa@example.net", 19, 1 } }, { "Alice", "demo key", NULL, { GPGME_PK_DSA, "2D727CC768697734", "Alfa Test", "demo key", "alfa@example.net", 19, 1 } } } }, { NULL } }; int main (void) { gpgme_error_t err; gpgme_ctx_t ctx; gpgme_key_t key; gpgme_keylist_result_t result; int mode; int i = 0; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); mode = gpgme_get_keylist_mode (ctx); mode |= GPGME_KEYLIST_MODE_SIGS; err = gpgme_set_keylist_mode (ctx, mode); fail_if_err (err); err = gpgme_op_keylist_start (ctx, "Alpha", 1); fail_if_err (err); while (!(err = gpgme_op_keylist_next (ctx, &key))) { if (!keys[i].fpr) { fprintf (stderr, "More keys returned than expected\n"); exit (1); } /* Global key flags. */ if (key->revoked) { fprintf (stderr, "Key unexpectedly revoked\n"); exit (1); } if (key->expired) { fprintf (stderr, "Key unexpectedly expired\n"); exit (1); } if (key->disabled) { fprintf (stderr, "Key unexpectedly disabled\n"); exit (1); } if (key->invalid) { fprintf (stderr, "Key unexpectedly invalid\n"); exit (1); } if (!key->can_encrypt) { fprintf (stderr, "Key unexpectedly unusable for encryption\n"); exit (1); } if (!key->can_sign) { fprintf (stderr, "Key unexpectedly unusable for signing\n"); exit (1); } if (!key->can_certify) { fprintf (stderr, "Key unexpectedly unusable for certifications\n"); exit (1); } if (!key->secret) { fprintf (stderr, "Key unexpectedly not secret\n"); exit (1); } if (key->protocol != GPGME_PROTOCOL_OpenPGP) { fprintf (stderr, "Key has unexpected protocol: %s\n", gpgme_get_protocol_name (key->protocol)); exit (1); } if (key->issuer_serial) { fprintf (stderr, "Key unexpectedly carries issuer serial: %s\n", key->issuer_serial); exit (1); } if (key->issuer_name) { fprintf (stderr, "Key unexpectedly carries issuer name: %s\n", key->issuer_name); exit (1); } if (key->chain_id) { fprintf (stderr, "Key unexpectedly carries chain ID: %s\n", key->chain_id); exit (1); } - if (key->owner_trust != GPGME_VALIDITY_UNKNOWN) + if (key->owner_trust != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "Key has unexpected owner trust: %i\n", key->owner_trust); exit (1); } if (!key->subkeys || !key->subkeys->next || key->subkeys->next->next) { fprintf (stderr, "Key has unexpected number of subkeys\n"); exit (1); } /* Primary key. */ if (key->subkeys->revoked) { fprintf (stderr, "Primary key unexpectedly revoked\n"); exit (1); } if (key->subkeys->expired) { fprintf (stderr, "Primary key unexpectedly expired\n"); exit (1); } if (key->subkeys->disabled) { fprintf (stderr, "Primary key unexpectedly disabled\n"); exit (1); } if (key->subkeys->invalid) { fprintf (stderr, "Primary key unexpectedly invalid\n"); exit (1); } if (key->subkeys->can_encrypt) { fprintf (stderr, "Primary key unexpectedly usable for encryption\n"); exit (1); } if (!key->subkeys->can_sign) { fprintf (stderr, "Primary key unexpectedly unusable for signing\n"); exit (1); } if (!key->subkeys->can_certify) { fprintf (stderr, "Primary key unexpectedly unusable for certifications\n"); exit (1); } if (!key->subkeys->secret) { fprintf (stderr, "Primary key unexpectedly not secret\n"); exit (1); } if (key->subkeys->pubkey_algo != GPGME_PK_DSA) { fprintf (stderr, "Primary key has unexpected public key algo: %s\n", gpgme_pubkey_algo_name (key->subkeys->pubkey_algo)); exit (1); } if (key->subkeys->length != 1024) { fprintf (stderr, "Primary key has unexpected length: %i\n", key->subkeys->length); exit (1); } if (strcmp (key->subkeys->keyid, &keys[i].fpr[40 - 16])) { fprintf (stderr, "Primary key has unexpected key ID: %s\n", key->subkeys->keyid); exit (1); } if (strcmp (key->subkeys->fpr, keys[i].fpr)) { fprintf (stderr, "Primary key has unexpected fingerprint: %s\n", key->subkeys->fpr); exit (1); } if (key->subkeys->expires) { fprintf (stderr, "Primary key unexpectedly expires: %lu\n", key->subkeys->expires); exit (1); } /* Secondary key. */ if (key->subkeys->next->revoked) { fprintf (stderr, "Secondary key unexpectedly revoked\n"); exit (1); } if (key->subkeys->next->expired) { fprintf (stderr, "Secondary key unexpectedly expired\n"); exit (1); } if (key->subkeys->next->disabled) { fprintf (stderr, "Secondary key unexpectedly disabled\n"); exit (1); } if (key->subkeys->next->invalid) { fprintf (stderr, "Secondary key unexpectedly invalid\n"); exit (1); } if (!key->subkeys->next->can_encrypt) { fprintf (stderr, "Secondary key unexpectedly unusable for encryption\n"); exit (1); } if (key->subkeys->next->can_sign) { fprintf (stderr, "Secondary key unexpectedly usable for signing\n"); exit (1); } if (key->subkeys->next->can_certify) { fprintf (stderr, "Secondary key unexpectedly usable for certifications\n"); exit (1); } if (!key->subkeys->next->secret) { fprintf (stderr, "Secondary key unexpectedly not secret\n"); exit (1); } if (key->subkeys->next->pubkey_algo != GPGME_PK_ELG_E) { fprintf (stderr, "Secondary key has unexpected public key algo: %s\n", gpgme_pubkey_algo_name (key->subkeys->next->pubkey_algo)); exit (1); } if (key->subkeys->next->length != 1024) { fprintf (stderr, "Secondary key has unexpected length: %i\n", key->subkeys->next->length); exit (1); } if (strcmp (key->subkeys->next->keyid, keys[i].sec_keyid)) { fprintf (stderr, "Secondary key has unexpected key ID: %s\n", key->subkeys->next->keyid); exit (1); } if (!key->subkeys->next->fpr) { fprintf (stderr, "Secondary key has unexpectedly no fingerprint\n"); exit (1); } if (key->subkeys->next->expires) { fprintf (stderr, "Secondary key unexpectedly expires: %lu\n", key->subkeys->next->expires); exit (1); } /* FIXME: The below test will crash if we want to check for a name, comment or email that doesn't exist in the key's user IDs. */ if (!((!keys[i].uid[0].name && !key->uids) || (keys[i].uid[0].name && !keys[i].uid[1].name && key->uids && !key->uids->next) || (keys[i].uid[0].name && keys[i].uid[1].name && !keys[i].uid[2].name && key->uids && key->uids->next && !key->uids->next->next) || (keys[i].uid[0].name && keys[i].uid[1].name && keys[i].uid[2].name && key->uids && key->uids->next && key->uids->next->next && !key->uids->next->next->next))) { fprintf (stderr, "Key has unexpected number of user IDs\n"); exit (1); } if (key->uids && key->uids->revoked) { fprintf (stderr, "First user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->invalid) { fprintf (stderr, "First user ID unexpectedly invalid\n"); exit (1); } - if (key->uids && key->uids->validity != GPGME_VALIDITY_UNKNOWN) + if (key->uids && key->uids->validity != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "First user ID has unexpectedly validity: %i\n", key->uids->validity); exit (1); } if (keys[i].uid[0].name && strcmp (keys[i].uid[0].name, key->uids->name)) { fprintf (stderr, "Unexpected name in first user ID: %s\n", key->uids->name); exit (1); } if (keys[i].uid[0].comment && strcmp (keys[i].uid[0].comment, key->uids->comment)) { fprintf (stderr, "Unexpected comment in first user ID: %s\n", key->uids->comment); exit (1); } if (keys[i].uid[0].email && strcmp (keys[i].uid[0].email, key->uids->email)) { fprintf (stderr, "Unexpected email in first user ID: %s\n", key->uids->email); exit (1); } if (key->uids && (!key->uids->signatures || key->uids->signatures->next)) { fprintf (stderr, "First user ID unexpected number of signatures\n"); exit (1); } if (keys[i].uid[0].sig.algo != key->uids->signatures->pubkey_algo) { fprintf (stderr, "Unexpected algorithm in first user ID sig: %s\n", gpgme_pubkey_algo_name (key->uids->signatures->pubkey_algo)); exit (1); } if (strcmp (keys[i].uid[0].sig.keyid, key->uids->signatures->keyid)) { fprintf (stderr, "Unexpected key ID in first user ID sig: %s\n", key->uids->signatures->keyid); exit (1); } if (strcmp (keys[i].uid[0].sig.name, key->uids->signatures->name)) { fprintf (stderr, "Unexpected name in first user ID sig: %s\n", key->uids->signatures->name); exit (1); } if (strcmp (keys[i].uid[0].sig.comment, key->uids->signatures->comment)) { fprintf (stderr, "Unexpected comment in first user ID sig: %s\n", key->uids->signatures->comment); exit (1); } if (strcmp (keys[i].uid[0].sig.email, key->uids->signatures->email)) { fprintf (stderr, "Unexpected email in first user ID sig: %s\n", key->uids->signatures->email); exit (1); } if (keys[i].uid[0].sig.sig_class != key->uids->signatures->sig_class) { fprintf (stderr, "Unexpected class in first user ID sig: %i\n", key->uids->signatures->sig_class); exit (1); } if (keys[i].uid[0].sig.exportable != key->uids->signatures->exportable) { fprintf (stderr, "Unexpected exportable stat in first user ID sig: %i\n", key->uids->signatures->exportable); exit (1); } if (key->uids && key->uids->next && key->uids->next->revoked) { fprintf (stderr, "Second user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->invalid) { fprintf (stderr, "Second user ID unexpectedly invalid\n"); exit (1); } if (key->uids && key->uids->next - && key->uids->next->validity != GPGME_VALIDITY_UNKNOWN) + && key->uids->next->validity != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "Second user ID has unexpectedly validity: %i\n", key->uids->next->validity); exit (1); } if (keys[i].uid[1].name && strcmp (keys[i].uid[1].name, key->uids->next->name)) { fprintf (stderr, "Unexpected name in second user ID: %s\n", key->uids->next->name); exit (1); } if (keys[i].uid[1].comment && strcmp (keys[i].uid[1].comment, key->uids->next->comment)) { fprintf (stderr, "Unexpected comment in second user ID: %s\n", key->uids->next->comment); exit (1); } if (keys[i].uid[1].email && strcmp (keys[i].uid[1].email, key->uids->next->email)) { fprintf (stderr, "Unexpected email in second user ID: %s\n", key->uids->next->email); exit (1); } /* Note: There is a bug in gpg 1.3.4 which duplicates a signature after importing the secret key. Thus we disable the second part of the check. */ if (key->uids && (!key->uids->next->signatures /*|| key->uids->next->signatures->next*/)) { fprintf (stderr, "Second user ID unexpected number of signatures\n"); exit (1); } if (keys[i].uid[1].sig.algo != key->uids->next->signatures->pubkey_algo) { fprintf (stderr, "Unexpected algorithm in second user ID sig: %s\n", gpgme_pubkey_algo_name (key->uids->next->signatures->pubkey_algo)); exit (1); } if (strcmp (keys[i].uid[1].sig.keyid, key->uids->next->signatures->keyid)) { fprintf (stderr, "Unexpected key ID in second user ID sig: %s\n", key->uids->next->signatures->keyid); exit (1); } if (strcmp (keys[i].uid[1].sig.name, key->uids->next->signatures->name)) { fprintf (stderr, "Unexpected name in second user ID sig: %s\n", key->uids->next->signatures->name); exit (1); } if (strcmp (keys[i].uid[1].sig.comment, key->uids->next->signatures->comment)) { fprintf (stderr, "Unexpected comment in second user ID sig: %s\n", key->uids->next->signatures->comment); exit (1); } if (strcmp (keys[i].uid[1].sig.email, key->uids->next->signatures->email)) { fprintf (stderr, "Unexpected email in second user ID sig: %s\n", key->uids->next->signatures->email); exit (1); } if (keys[i].uid[1].sig.sig_class != key->uids->next->signatures->sig_class) { fprintf (stderr, "Unexpected class in second user ID sig: %i\n", key->uids->next->signatures->sig_class); exit (1); } if (keys[i].uid[1].sig.exportable != key->uids->next->signatures->exportable) { fprintf (stderr, "Unexpected exportable stat in second user ID sig: %i\n", key->uids->next->signatures->exportable); exit (1); } if (key->uids && key->uids->next && key->uids->next->next && key->uids->next->next->revoked) { fprintf (stderr, "Third user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->next && key->uids->next->next->invalid) { fprintf (stderr, "Third user ID unexpectedly invalid\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->next - && key->uids->next->next->validity != GPGME_VALIDITY_UNKNOWN) + && key->uids->next->next->validity != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "Third user ID has unexpectedly validity: %i\n", key->uids->next->next->validity); exit (1); } if (keys[i].uid[2].name && strcmp (keys[i].uid[2].name, key->uids->next->next->name)) { fprintf (stderr, "Unexpected name in third user ID: %s\n", key->uids->next->next->name); exit (1); } if (keys[i].uid[2].comment && strcmp (keys[i].uid[2].comment, key->uids->next->next->comment)) { fprintf (stderr, "Unexpected comment in third user ID: %s\n", key->uids->next->next->comment); exit (1); } if (keys[i].uid[2].email && strcmp (keys[i].uid[2].email, key->uids->next->next->email)) { fprintf (stderr, "Unexpected email in third user ID: %s\n", key->uids->next->next->email); exit (1); } if (key->uids && (!key->uids->next->next->signatures || key->uids->next->next->signatures->next)) { fprintf (stderr, "Third user ID unexpected number of signatures\n"); exit (1); } if (keys[i].uid[2].sig.algo != key->uids->next->next->signatures->pubkey_algo) { fprintf (stderr, "Unexpected algorithm in third user ID sig: %s\n", gpgme_pubkey_algo_name (key->uids->next->next->signatures->pubkey_algo)); exit (1); } if (strcmp (keys[i].uid[2].sig.keyid, key->uids->next->next->signatures->keyid)) { fprintf (stderr, "Unexpected key ID in third user ID sig: %s\n", key->uids->next->next->signatures->keyid); exit (1); } if (strcmp (keys[i].uid[2].sig.name, key->uids->next->next->signatures->name)) { fprintf (stderr, "Unexpected name in third user ID sig: %s\n", key->uids->next->next->signatures->name); exit (1); } if (strcmp (keys[i].uid[2].sig.comment, key->uids->next->next->signatures->comment)) { fprintf (stderr, "Unexpected comment in third user ID sig: %s\n", key->uids->next->next->signatures->comment); exit (1); } if (strcmp (keys[i].uid[2].sig.email, key->uids->next->next->signatures->email)) { fprintf (stderr, "Unexpected email in third user ID sig: %s\n", key->uids->next->next->signatures->email); exit (1); } if (keys[i].uid[2].sig.sig_class != key->uids->next->next->signatures->sig_class) { fprintf (stderr, "Unexpected class in third user ID sig: %i\n", key->uids->next->next->signatures->sig_class); exit (1); } if (keys[i].uid[2].sig.exportable != key->uids->next->next->signatures->exportable) { fprintf (stderr, "Unexpected exportable stat in third user ID sig: %i\n", key->uids->next->next->signatures->exportable); exit (1); } gpgme_key_unref (key); i++; } if (gpgme_err_code (err) != GPG_ERR_EOF) fail_if_err (err); err = gpgme_op_keylist_end (ctx); fail_if_err (err); result = gpgme_op_keylist_result (ctx); if (result->truncated) { fprintf (stderr, "Key listing unexpectedly truncated\n"); exit (1); } if (keys[i].fpr) { fprintf (stderr, "Less keys returned than expected\n"); exit (1); } gpgme_release (ctx); return 0; } diff --git a/tests/gpg/t-keylist-sig.c b/tests/gpg/t-keylist-sig.c index 390ff41a..250214c1 100644 --- a/tests/gpg/t-keylist-sig.c +++ b/tests/gpg/t-keylist-sig.c @@ -1,628 +1,628 @@ /* t-keylist-sig.c - Regression test. * Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2001, 2003, 2004 g10 Code GmbH * * This file is part of GPGME. * * GPGME is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * GPGME 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . * SPDX-License-Identifier: LGPL-2.1-or-later */ /* We need to include config.h so that we know whether we are building with large file system (LFS) support. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "t-support.h" struct { const char *fpr; const char *sec_keyid; struct { const char *name; const char *comment; const char *email; struct { gpgme_pubkey_algo_t algo; const char *keyid; const char *name; const char *comment; const char *email; unsigned int sig_class; int exportable; } sig; } uid[3]; } keys[] = { { "A0FF4590BB6122EDEF6E3C542D727CC768697734", "6AE6D7EE46A871F8", { { "Alfa Test", "demo key", "alfa@example.net", { GPGME_PK_DSA, "2D727CC768697734", "Alfa Test", "demo key", "alfa@example.net", 19, 1 } }, { "Alpha Test", "demo key", "alpha@example.net", { GPGME_PK_DSA, "2D727CC768697734", "Alfa Test", "demo key", "alfa@example.net", 19, 1 } }, { "Alice", "demo key", NULL, { GPGME_PK_DSA, "2D727CC768697734", "Alfa Test", "demo key", "alfa@example.net", 19, 1 } } } }, { NULL } }; int main (void) { gpgme_error_t err; gpgme_ctx_t ctx; gpgme_key_t key; gpgme_keylist_result_t result; int mode; int i = 0; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); mode = gpgme_get_keylist_mode (ctx); mode |= GPGME_KEYLIST_MODE_SIGS; err = gpgme_set_keylist_mode (ctx, mode); fail_if_err (err); err = gpgme_op_keylist_start (ctx, "Alpha", 0); fail_if_err (err); while (!(err = gpgme_op_keylist_next (ctx, &key))) { if (!keys[i].fpr) { fprintf (stderr, "More keys returned than expected\n"); exit (1); } /* Global key flags. */ if (key->revoked) { fprintf (stderr, "Key unexpectedly revoked\n"); exit (1); } if (key->expired) { fprintf (stderr, "Key unexpectedly expired\n"); exit (1); } if (key->disabled) { fprintf (stderr, "Key unexpectedly disabled\n"); exit (1); } if (key->invalid) { fprintf (stderr, "Key unexpectedly invalid\n"); exit (1); } if (!key->can_encrypt) { fprintf (stderr, "Key unexpectedly unusable for encryption\n"); exit (1); } if (!key->can_sign) { fprintf (stderr, "Key unexpectedly unusable for signing\n"); exit (1); } if (!key->can_certify) { fprintf (stderr, "Key unexpectedly unusable for certifications\n"); exit (1); } if (key->secret) { fprintf (stderr, "Key unexpectedly secret\n"); exit (1); } if (key->protocol != GPGME_PROTOCOL_OpenPGP) { fprintf (stderr, "Key has unexpected protocol: %s\n", gpgme_get_protocol_name (key->protocol)); exit (1); } if (key->issuer_serial) { fprintf (stderr, "Key unexpectedly carries issuer serial: %s\n", key->issuer_serial); exit (1); } if (key->issuer_name) { fprintf (stderr, "Key unexpectedly carries issuer name: %s\n", key->issuer_name); exit (1); } if (key->chain_id) { fprintf (stderr, "Key unexpectedly carries chain ID: %s\n", key->chain_id); exit (1); } - if (key->owner_trust != GPGME_VALIDITY_UNKNOWN) + if (key->owner_trust != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "Key has unexpected owner trust: %i\n", key->owner_trust); exit (1); } if (!key->subkeys || !key->subkeys->next || key->subkeys->next->next) { fprintf (stderr, "Key has unexpected number of subkeys\n"); exit (1); } /* Primary key. */ if (key->subkeys->revoked) { fprintf (stderr, "Primary key unexpectedly revoked\n"); exit (1); } if (key->subkeys->expired) { fprintf (stderr, "Primary key unexpectedly expired\n"); exit (1); } if (key->subkeys->disabled) { fprintf (stderr, "Primary key unexpectedly disabled\n"); exit (1); } if (key->subkeys->invalid) { fprintf (stderr, "Primary key unexpectedly invalid\n"); exit (1); } if (key->subkeys->can_encrypt) { fprintf (stderr, "Primary key unexpectedly usable for encryption\n"); exit (1); } if (!key->subkeys->can_sign) { fprintf (stderr, "Primary key unexpectedly unusable for signing\n"); exit (1); } if (!key->subkeys->can_certify) { fprintf (stderr, "Primary key unexpectedly unusable for certifications\n"); exit (1); } if (key->subkeys->secret) { fprintf (stderr, "Primary key unexpectedly secret\n"); exit (1); } if (key->subkeys->pubkey_algo != GPGME_PK_DSA) { fprintf (stderr, "Primary key has unexpected public key algo: %s\n", gpgme_pubkey_algo_name (key->subkeys->pubkey_algo)); exit (1); } if (key->subkeys->length != 1024) { fprintf (stderr, "Primary key has unexpected length: %i\n", key->subkeys->length); exit (1); } if (strcmp (key->subkeys->keyid, &keys[i].fpr[40 - 16])) { fprintf (stderr, "Primary key has unexpected key ID: %s\n", key->subkeys->keyid); exit (1); } if (strcmp (key->subkeys->fpr, keys[i].fpr)) { fprintf (stderr, "Primary key has unexpected fingerprint: %s\n", key->subkeys->fpr); exit (1); } if (key->subkeys->expires) { fprintf (stderr, "Primary key unexpectedly expires: %lu\n", key->subkeys->expires); exit (1); } /* Secondary key. */ if (key->subkeys->next->revoked) { fprintf (stderr, "Secondary key unexpectedly revoked\n"); exit (1); } if (key->subkeys->next->expired) { fprintf (stderr, "Secondary key unexpectedly expired\n"); exit (1); } if (key->subkeys->next->disabled) { fprintf (stderr, "Secondary key unexpectedly disabled\n"); exit (1); } if (key->subkeys->next->invalid) { fprintf (stderr, "Secondary key unexpectedly invalid\n"); exit (1); } if (!key->subkeys->next->can_encrypt) { fprintf (stderr, "Secondary key unexpectedly unusable for encryption\n"); exit (1); } if (key->subkeys->next->can_sign) { fprintf (stderr, "Secondary key unexpectedly usable for signing\n"); exit (1); } if (key->subkeys->next->can_certify) { fprintf (stderr, "Secondary key unexpectedly usable for certifications\n"); exit (1); } if (key->subkeys->next->secret) { fprintf (stderr, "Secondary key unexpectedly secret\n"); exit (1); } if (key->subkeys->next->pubkey_algo != GPGME_PK_ELG_E) { fprintf (stderr, "Secondary key has unexpected public key algo: %s\n", gpgme_pubkey_algo_name (key->subkeys->next->pubkey_algo)); exit (1); } if (key->subkeys->next->length != 1024) { fprintf (stderr, "Secondary key has unexpected length: %i\n", key->subkeys->next->length); exit (1); } if (strcmp (key->subkeys->next->keyid, keys[i].sec_keyid)) { fprintf (stderr, "Secondary key has unexpected key ID: %s\n", key->subkeys->next->keyid); exit (1); } if (!key->subkeys->next->fpr) { fprintf (stderr, "Secondary key has unexpectedly no fingerprint\n"); exit (1); } if (key->subkeys->next->expires) { fprintf (stderr, "Secondary key unexpectedly expires: %lu\n", key->subkeys->next->expires); exit (1); } /* FIXME: The below test will crash if we want to check for a name, comment or email that doesn't exist in the key's user IDs. */ if (!((!keys[i].uid[0].name && !key->uids) || (keys[i].uid[0].name && !keys[i].uid[1].name && key->uids && !key->uids->next) || (keys[i].uid[0].name && keys[i].uid[1].name && !keys[i].uid[2].name && key->uids && key->uids->next && !key->uids->next->next) || (keys[i].uid[0].name && keys[i].uid[1].name && keys[i].uid[2].name && key->uids && key->uids->next && key->uids->next->next && !key->uids->next->next->next))) { fprintf (stderr, "Key has unexpected number of user IDs\n"); exit (1); } if (key->uids && key->uids->revoked) { fprintf (stderr, "First user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->invalid) { fprintf (stderr, "First user ID unexpectedly invalid\n"); exit (1); } - if (key->uids && key->uids->validity != GPGME_VALIDITY_UNKNOWN) + if (key->uids && key->uids->validity != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "First user ID has unexpectedly validity: %i\n", key->uids->validity); exit (1); } if (keys[i].uid[0].name && strcmp (keys[i].uid[0].name, key->uids->name)) { fprintf (stderr, "Unexpected name in first user ID: %s\n", key->uids->name); exit (1); } if (keys[i].uid[0].comment && strcmp (keys[i].uid[0].comment, key->uids->comment)) { fprintf (stderr, "Unexpected comment in first user ID: %s\n", key->uids->comment); exit (1); } if (keys[i].uid[0].email && strcmp (keys[i].uid[0].email, key->uids->email)) { fprintf (stderr, "Unexpected email in first user ID: %s\n", key->uids->email); exit (1); } if (key->uids && (!key->uids->signatures || key->uids->signatures->next)) { fprintf (stderr, "First user ID unexpected number of signatures\n"); exit (1); } if (keys[i].uid[0].sig.algo != key->uids->signatures->pubkey_algo) { fprintf (stderr, "Unexpected algorithm in first user ID sig: %s\n", gpgme_pubkey_algo_name (key->uids->signatures->pubkey_algo)); exit (1); } if (strcmp (keys[i].uid[0].sig.keyid, key->uids->signatures->keyid)) { fprintf (stderr, "Unexpected key ID in first user ID sig: %s\n", key->uids->signatures->keyid); exit (1); } if (strcmp (keys[i].uid[0].sig.name, key->uids->signatures->name)) { fprintf (stderr, "Unexpected name in first user ID sig: %s\n", key->uids->signatures->name); exit (1); } if (strcmp (keys[i].uid[0].sig.comment, key->uids->signatures->comment)) { fprintf (stderr, "Unexpected comment in first user ID sig: %s\n", key->uids->signatures->comment); exit (1); } if (strcmp (keys[i].uid[0].sig.email, key->uids->signatures->email)) { fprintf (stderr, "Unexpected email in first user ID sig: %s\n", key->uids->signatures->email); exit (1); } if (keys[i].uid[0].sig.sig_class != key->uids->signatures->sig_class) { fprintf (stderr, "Unexpected class in first user ID sig: %i\n", key->uids->signatures->sig_class); exit (1); } if (keys[i].uid[0].sig.exportable != key->uids->signatures->exportable) { fprintf (stderr, "Unexpected exportable stat in first user ID sig: %i\n", key->uids->signatures->exportable); exit (1); } if (key->uids && key->uids->next && key->uids->next->revoked) { fprintf (stderr, "Second user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->invalid) { fprintf (stderr, "Second user ID unexpectedly invalid\n"); exit (1); } if (key->uids && key->uids->next - && key->uids->next->validity != GPGME_VALIDITY_UNKNOWN) + && key->uids->next->validity != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "Second user ID has unexpectedly validity: %i\n", key->uids->next->validity); exit (1); } if (keys[i].uid[1].name && strcmp (keys[i].uid[1].name, key->uids->next->name)) { fprintf (stderr, "Unexpected name in second user ID: %s\n", key->uids->next->name); exit (1); } if (keys[i].uid[1].comment && strcmp (keys[i].uid[1].comment, key->uids->next->comment)) { fprintf (stderr, "Unexpected comment in second user ID: %s\n", key->uids->next->comment); exit (1); } if (keys[i].uid[1].email && strcmp (keys[i].uid[1].email, key->uids->next->email)) { fprintf (stderr, "Unexpected email in second user ID: %s\n", key->uids->next->email); exit (1); } /* Note: There is a bug in gpg 1.3.4 which duplicates a signature after importing the secret key. Thus we disable the second part of the check. */ if (key->uids && (!key->uids->next->signatures /*|| key->uids->next->signatures->next*/)) { fprintf (stderr, "Second user ID unexpected number of signatures\n"); exit (1); } if (keys[i].uid[1].sig.algo != key->uids->next->signatures->pubkey_algo) { fprintf (stderr, "Unexpected algorithm in second user ID sig: %s\n", gpgme_pubkey_algo_name (key->uids->next->signatures->pubkey_algo)); exit (1); } if (strcmp (keys[i].uid[1].sig.keyid, key->uids->next->signatures->keyid)) { fprintf (stderr, "Unexpected key ID in second user ID sig: %s\n", key->uids->next->signatures->keyid); exit (1); } if (strcmp (keys[i].uid[1].sig.name, key->uids->next->signatures->name)) { fprintf (stderr, "Unexpected name in second user ID sig: %s\n", key->uids->next->signatures->name); exit (1); } if (strcmp (keys[i].uid[1].sig.comment, key->uids->next->signatures->comment)) { fprintf (stderr, "Unexpected comment in second user ID sig: %s\n", key->uids->next->signatures->comment); exit (1); } if (strcmp (keys[i].uid[1].sig.email, key->uids->next->signatures->email)) { fprintf (stderr, "Unexpected email in second user ID sig: %s\n", key->uids->next->signatures->email); exit (1); } if (keys[i].uid[1].sig.sig_class != key->uids->next->signatures->sig_class) { fprintf (stderr, "Unexpected class in second user ID sig: %i\n", key->uids->next->signatures->sig_class); exit (1); } if (keys[i].uid[1].sig.exportable != key->uids->next->signatures->exportable) { fprintf (stderr, "Unexpected exportable stat in second user ID sig: %i\n", key->uids->next->signatures->exportable); exit (1); } if (key->uids && key->uids->next && key->uids->next->next && key->uids->next->next->revoked) { fprintf (stderr, "Third user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->next && key->uids->next->next->invalid) { fprintf (stderr, "Third user ID unexpectedly invalid\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->next - && key->uids->next->next->validity != GPGME_VALIDITY_UNKNOWN) + && key->uids->next->next->validity != GPGME_VALIDITY_ULTIMATE) { fprintf (stderr, "Third user ID has unexpectedly validity: %i\n", key->uids->next->next->validity); exit (1); } if (keys[i].uid[2].name && strcmp (keys[i].uid[2].name, key->uids->next->next->name)) { fprintf (stderr, "Unexpected name in third user ID: %s\n", key->uids->next->next->name); exit (1); } if (keys[i].uid[2].comment && strcmp (keys[i].uid[2].comment, key->uids->next->next->comment)) { fprintf (stderr, "Unexpected comment in third user ID: %s\n", key->uids->next->next->comment); exit (1); } if (keys[i].uid[2].email && strcmp (keys[i].uid[2].email, key->uids->next->next->email)) { fprintf (stderr, "Unexpected email in third user ID: %s\n", key->uids->next->next->email); exit (1); } if (key->uids && (!key->uids->next->next->signatures || key->uids->next->next->signatures->next)) { fprintf (stderr, "Third user ID unexpected number of signatures\n"); exit (1); } if (keys[i].uid[2].sig.algo != key->uids->next->next->signatures->pubkey_algo) { fprintf (stderr, "Unexpected algorithm in third user ID sig: %s\n", gpgme_pubkey_algo_name (key->uids->next->next->signatures->pubkey_algo)); exit (1); } if (strcmp (keys[i].uid[2].sig.keyid, key->uids->next->next->signatures->keyid)) { fprintf (stderr, "Unexpected key ID in third user ID sig: %s\n", key->uids->next->next->signatures->keyid); exit (1); } if (strcmp (keys[i].uid[2].sig.name, key->uids->next->next->signatures->name)) { fprintf (stderr, "Unexpected name in third user ID sig: %s\n", key->uids->next->next->signatures->name); exit (1); } if (strcmp (keys[i].uid[2].sig.comment, key->uids->next->next->signatures->comment)) { fprintf (stderr, "Unexpected comment in third user ID sig: %s\n", key->uids->next->next->signatures->comment); exit (1); } if (strcmp (keys[i].uid[2].sig.email, key->uids->next->next->signatures->email)) { fprintf (stderr, "Unexpected email in third user ID sig: %s\n", key->uids->next->next->signatures->email); exit (1); } if (keys[i].uid[2].sig.sig_class != key->uids->next->next->signatures->sig_class) { fprintf (stderr, "Unexpected class in third user ID sig: %i\n", key->uids->next->next->signatures->sig_class); exit (1); } if (keys[i].uid[2].sig.exportable != key->uids->next->next->signatures->exportable) { fprintf (stderr, "Unexpected exportable stat in third user ID sig: %i\n", key->uids->next->next->signatures->exportable); exit (1); } gpgme_key_unref (key); i++; } if (gpgme_err_code (err) != GPG_ERR_EOF) fail_if_err (err); err = gpgme_op_keylist_end (ctx); fail_if_err (err); result = gpgme_op_keylist_result (ctx); if (result->truncated) { fprintf (stderr, "Key listing unexpectedly truncated\n"); exit (1); } if (keys[i].fpr) { fprintf (stderr, "Less keys returned than expected\n"); exit (1); } gpgme_release (ctx); return 0; } diff --git a/tests/gpg/t-keylist.c b/tests/gpg/t-keylist.c index 3b4fea18..fc9fc1b7 100644 --- a/tests/gpg/t-keylist.c +++ b/tests/gpg/t-keylist.c @@ -1,606 +1,611 @@ /* t-keylist.c - regression test * Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2001, 2003, 2004 g10 Code GmbH * * This file is part of GPGME. * * GPGME is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * GPGME 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . * SPDX-License-Identifier: LGPL-2.1-or-later */ /* We need to include config.h so that we know whether we are building with large file system (LFS) support. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "t-support.h" struct key_info_s { const char *fpr; const char *sec_keyid; struct { const char *name; const char *comment; const char *email; + gpgme_validity_t validity; } uid[3]; int n_subkeys; + gpgme_validity_t owner_trust; void (*misc_check)(struct key_info_s *keyinfo, gpgme_key_t key); }; static void check_whisky (struct key_info_s *keyinfo, gpgme_key_t key); struct key_info_s keys[] = { { "A0FF4590BB6122EDEF6E3C542D727CC768697734", "6AE6D7EE46A871F8", - { { "Alfa Test", "demo key", "alfa@example.net" }, - { "Alpha Test", "demo key", "alpha@example.net" }, - { "Alice", "demo key", NULL } }, 1 }, + { { "Alfa Test", "demo key", "alfa@example.net", + GPGME_VALIDITY_ULTIMATE }, + { "Alpha Test", "demo key", "alpha@example.net", + GPGME_VALIDITY_ULTIMATE }, + { "Alice", "demo key", NULL, GPGME_VALIDITY_ULTIMATE } }, 1, + GPGME_VALIDITY_ULTIMATE }, { "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", "5381EA4EE29BA37F", { { "Bob", "demo key", NULL }, { "Bravo Test", "demo key", "bravo@example.net" } }, 1 }, { "61EE841A2A27EB983B3B3C26413F4AF31AFDAB6C", "E71E72ACBC43DA60", { { "Charlie Test", "demo key", "charlie@example.net" } }, 1 }, { "6560C59C43D031C54D7C588EEBA9F240EB9DC9E6", "06F22880B0C45424", { { "Delta Test", "demo key", "delta@example.net" } }, 1 }, { "3531152DE293E26A07F504BC318C1FAEFAEF6D1B", "B5C79E1A7272144D", { { "Echelon", "demo key", NULL }, { "Echo Test", "demo key", "echo@example.net" }, { "Eve", "demo key", NULL } }, 1 }, { "56D33268F7FE693FBB594762D4BF57F37372E243", "0A32EE79EE45198E", { { "Foxtrot Test", "demo key", "foxtrot@example.net" } }, 1 }, { "C9C07DCC6621B9FB8D071B1D168410A48FC282E6", "247491CC9DCAD354", { { "Golf Test", "demo key", "golf@example.net" } }, 1 }, { "9E91CBB11E4D4135583EF90513DB965534C6E3F1", "76E26537D622AD0A", { { "Hotel Test", "demo key", "hotel@example.net" } }, 1 }, { "CD538D6CC9FB3D745ECDA5201FE8FC6F04259677", "C1C8EFDE61F76C73", { { "India Test", "demo key", "india@example.net" } }, 1 }, { "F8F1EDC73995AB739AD54B380C820C71D2699313", "BD0B108735F8F136", { { "Juliet Test", "demo key", "juliet@example.net" } }, 1 }, { "3FD11083779196C2ECDD9594AD1B0FAD43C2D0C7", "86CBB34A9AF64D02", { { "Kilo Test", "demo key", "kilo@example.net" } }, 1 }, { "1DDD28CEF714F5B03B8C246937CAB51FB79103F8", "0363B449FE56350C", { { "Lima Test", "demo key", "lima@example.net" } }, 1 }, { "2686AA191A278013992C72EBBE794852BE5CF886", "5F600A834F31EAE8", { { "Mallory", "demo key", NULL }, { "Mike Test", "demo key", "mike@example.net" } }, 1 }, { "5AB9D6D7BAA1C95B3BAA3D9425B00FD430CEC684", "4C1D63308B70E472", { { "November Test", "demo key", "november@example.net" } }, 1 }, { "43929E89F8F79381678CAE515F6356BA6D9732AC", "FF0785712681619F", { { "Oscar Test", "demo key", "oscar@example.net" } }, 1 }, { "6FAA9C201E5E26DCBAEC39FD5D15E01D3FF13206", "2764E18263330D9C", { { "Papa test", "demo key", "papa@example.net" } }, 1 }, { "A7969DA1C3297AA96D49843F1C67EC133C661C84", "6CDCFC44A029ACF4", { { "Quebec Test", "demo key", "quebec@example.net" } }, 1 }, { "38FBE1E4BF6A5E1242C8F6A13BDBEDB1777FBED3", "9FAB805A11D102EA", { { "Romeo Test", "demo key", "romeo@example.net" } }, 1 }, { "045B2334ADD69FC221076841A5E67F7FA3AE3EA1", "93B88B0F0F1B50B4", { { "Sierra Test", "demo key", "sierra@example.net" } }, 1 }, { "ECAC774F4EEEB0620767044A58CB9A4C85A81F38", "97B60E01101C0402", { { "Tango Test", "demo key", "tango@example.net" } }, 1 }, { "0DBCAD3F08843B9557C6C4D4A94C0F75653244D6", "93079B915522BDB9", { { "Uniform Test", "demo key", "uniform@example.net" } }, 1 }, { "E8143C489C8D41124DC40D0B47AF4B6961F04784", "04071FB807287134", { { "Victor Test", "demo key", "victor@example.org" } }, 1 }, { "E8D6C90B683B0982BD557A99DEF0F7B8EC67DBDE", "D7FBB421FD6E27F6", { { "Whisky Test", "demo key", "whisky@example.net" } }, 3, - check_whisky }, + GPGME_VALIDITY_UNKNOWN, check_whisky }, { "04C1DF62EFA0EBB00519B06A8979A6C5567FB34A", "5CC6F87F41E408BE", { { "XRay Test", "demo key", "xray@example.net" } }, 1 }, { "ED9B316F78644A58D042655A9EEF34CD4B11B25F", "5ADFD255F7B080AD", { { "Yankee Test", "demo key", "yankee@example.net" } }, 1 }, { "23FD347A419429BACCD5E72D6BC4778054ACD246", "EF9DC276A172C881", { { "Zulu Test", "demo key", "zulu@example.net" } }, 1 }, { "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", "087DD7E0381701C4", { { "Joe Random Hacker", "test key with passphrase \"abc\"", "joe@example.com" } }, 1 }, { NULL } }; int main (int argc, char **argv) { gpgme_error_t err; gpgme_ctx_t ctx; gpgme_key_t key; gpgme_keylist_result_t result; int i = 0; int n; gpgme_subkey_t subkey; (void)argc; (void)argv; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); err = gpgme_op_keylist_start (ctx, NULL, 0); fail_if_err (err); while (!(err = gpgme_op_keylist_next (ctx, &key))) { if (!keys[i].fpr) { fprintf (stderr, "More keys returned than expected\n"); exit (1); } /* Global key flags. */ if (key->revoked) { fprintf (stderr, "Key unexpectedly revoked\n"); exit (1); } if (key->expired) { fprintf (stderr, "Key unexpectedly expired\n"); exit (1); } if (key->disabled) { fprintf (stderr, "Key unexpectedly disabled\n"); exit (1); } if (key->invalid) { fprintf (stderr, "Key unexpectedly invalid\n"); exit (1); } #if 0 /* GnuPG 2.1+ have a different subkey for encryption. */ if (!key->can_encrypt) { fprintf (stderr, "Key unexpectedly unusable for encryption\n"); exit (1); } #endif if (!key->can_sign) { fprintf (stderr, "Key unexpectedly unusable for signing\n"); exit (1); } if (!key->can_certify) { fprintf (stderr, "Key unexpectedly unusable for certifications\n"); exit (1); } if (key->secret) { fprintf (stderr, "Key unexpectedly secret\n"); exit (1); } if (key->protocol != GPGME_PROTOCOL_OpenPGP) { fprintf (stderr, "Key has unexpected protocol: %s\n", gpgme_get_protocol_name (key->protocol)); exit (1); } if (key->issuer_serial) { fprintf (stderr, "Key unexpectedly carries issuer serial: %s\n", key->issuer_serial); exit (1); } if (key->issuer_name) { fprintf (stderr, "Key unexpectedly carries issuer name: %s\n", key->issuer_name); exit (1); } if (key->chain_id) { fprintf (stderr, "Key unexpectedly carries chain ID: %s\n", key->chain_id); exit (1); } - if (key->owner_trust != GPGME_VALIDITY_UNKNOWN) + if (key->owner_trust != keys[i].owner_trust) { - fprintf (stderr, "Key has unexpected owner trust: %i\n", - key->owner_trust); + fprintf (stderr, "Key `%s' has unexpected owner trust: %i\n", + keys[i].uid[0].name, key->owner_trust); exit (1); } for (n=0, subkey = key->subkeys; subkey; subkey = subkey->next) n++; if (!n || n-1 != keys[i].n_subkeys) { fprintf (stderr, "Key `%s' has unexpected number of subkeys\n", keys[i].uid[0].name); exit (1); } /* Primary key. */ if (key->subkeys->revoked) { fprintf (stderr, "Primary key unexpectedly revoked\n"); exit (1); } if (key->subkeys->expired) { fprintf (stderr, "Primary key unexpectedly expired\n"); exit (1); } if (key->subkeys->disabled) { fprintf (stderr, "Primary key unexpectedly disabled\n"); exit (1); } if (key->subkeys->invalid) { fprintf (stderr, "Primary key unexpectedly invalid\n"); exit (1); } if (key->subkeys->can_encrypt) { fprintf (stderr, "Primary key unexpectedly usable for encryption\n"); exit (1); } if (!key->subkeys->can_sign) { fprintf (stderr, "Primary key unexpectedly unusable for signing\n"); exit (1); } if (!key->subkeys->can_certify) { fprintf (stderr, "Primary key unexpectedly unusable for certifications\n"); exit (1); } if (key->subkeys->secret) { fprintf (stderr, "Primary key unexpectedly secret\n"); exit (1); } if (key->subkeys->is_cardkey) { fprintf (stderr, "Public key marked as card key\n"); exit (1); } if (key->subkeys->card_number) { fprintf (stderr, "Public key with card number set\n"); exit (1); } if (key->subkeys->pubkey_algo != GPGME_PK_DSA) { fprintf (stderr, "Primary key has unexpected public key algo: %s\n", gpgme_pubkey_algo_name (key->subkeys->pubkey_algo)); exit (1); } if (key->subkeys->length != 1024) { fprintf (stderr, "Primary key has unexpected length: %i\n", key->subkeys->length); exit (1); } if (strcmp (key->subkeys->keyid, &keys[i].fpr[40 - 16])) { fprintf (stderr, "Primary key `%s' has unexpected key ID: %s\n", keys[i].uid[0].name, key->subkeys->keyid); exit (1); } if (strcmp (key->subkeys->fpr, keys[i].fpr)) { fprintf (stderr, "Primary key has unexpected fingerprint: %s\n", key->subkeys->fpr); exit (1); } if (key->subkeys->expires) { fprintf (stderr, "Primary key `%s' unexpectedly expires: %lu\n", keys[i].uid[0].name, key->subkeys->expires); exit (1); } /* Secondary key. */ if (key->subkeys->next->revoked) { fprintf (stderr, "Secondary key unexpectedly revoked\n"); exit (1); } if (key->subkeys->next->expired) { fprintf (stderr, "Secondary key unexpectedly expired\n"); exit (1); } if (key->subkeys->next->disabled) { fprintf (stderr, "Secondary key unexpectedly disabled\n"); exit (1); } if (key->subkeys->next->invalid) { fprintf (stderr, "Secondary key unexpectedly invalid\n"); exit (1); } if (!key->subkeys->next->can_encrypt) { fprintf (stderr, "Secondary key unexpectedly unusable for encryption\n"); exit (1); } if (key->subkeys->next->can_sign) { fprintf (stderr, "Secondary key unexpectedly usable for signing\n"); exit (1); } if (key->subkeys->next->can_certify) { fprintf (stderr, "Secondary key unexpectedly usable for certifications\n"); exit (1); } if (key->subkeys->next->secret) { fprintf (stderr, "Secondary key unexpectedly secret\n"); exit (1); } if (key->subkeys->next->is_cardkey) { fprintf (stderr, "Secondary public key marked as card key\n"); exit (1); } if (key->subkeys->next->card_number) { fprintf (stderr, "Secondary public key with card number set\n"); exit (1); } if (key->subkeys->next->pubkey_algo != GPGME_PK_ELG_E) { fprintf (stderr, "Secondary key has unexpected public key algo: %s\n", gpgme_pubkey_algo_name (key->subkeys->next->pubkey_algo)); exit (1); } if (key->subkeys->next->length != 1024) { fprintf (stderr, "Secondary key has unexpected length: %i\n", key->subkeys->next->length); exit (1); } if (strcmp (key->subkeys->next->keyid, keys[i].sec_keyid)) { fprintf (stderr, "Secondary key `%s' has unexpected key ID: %s/%s\n", keys[i].uid[0].name, key->subkeys->next->keyid, keys[i].sec_keyid ); exit (1); } if (!key->subkeys->next->fpr) { fprintf (stderr, "Secondary key has unexpectedly no fingerprint\n"); exit (1); } if (key->subkeys->next->expires) { fprintf (stderr, "Secondary key unexpectedly expires: %lu\n", key->subkeys->next->expires); exit (1); } /* FIXME: The below test will crash if we want to check for a name, comment or email that doesn't exist in the key's user IDs. */ if (!((!keys[i].uid[0].name && !key->uids) || (keys[i].uid[0].name && !keys[i].uid[1].name && key->uids && !key->uids->next) || (keys[i].uid[0].name && keys[i].uid[1].name && !keys[i].uid[2].name && key->uids && key->uids->next && !key->uids->next->next) || (keys[i].uid[0].name && keys[i].uid[1].name && keys[i].uid[2].name && key->uids && key->uids->next && key->uids->next->next && !key->uids->next->next->next))) { fprintf (stderr, "Key has unexpected number of user IDs\n"); exit (1); } if (key->uids && key->uids->revoked) { fprintf (stderr, "First user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->invalid) { fprintf (stderr, "First user ID unexpectedly invalid\n"); exit (1); } - if (key->uids && key->uids->validity != GPGME_VALIDITY_UNKNOWN) + if (key->uids && key->uids->validity != keys[i].uid[0].validity) { - fprintf (stderr, "First user ID has unexpectedly validity: %i\n", - key->uids->validity); + fprintf (stderr, "First user ID `%s' has unexpectedly validity: %i\n", + key->uids->name, key->uids->validity); exit (1); } if (key->uids && key->uids->signatures) { fprintf (stderr, "First user ID unexpectedly signed\n"); exit (1); } if (keys[i].uid[0].name && strcmp (keys[i].uid[0].name, key->uids->name)) { fprintf (stderr, "Unexpected name in first user ID: %s\n", key->uids->name); exit (1); } if (keys[i].uid[0].comment && strcmp (keys[i].uid[0].comment, key->uids->comment)) { fprintf (stderr, "Unexpected comment in first user ID: %s\n", key->uids->comment); exit (1); } if (keys[i].uid[0].email && strcmp (keys[i].uid[0].email, key->uids->email)) { fprintf (stderr, "Unexpected email in first user ID: %s\n", key->uids->email); exit (1); } if (key->uids && key->uids->next && key->uids->next->revoked) { fprintf (stderr, "Second user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->invalid) { fprintf (stderr, "Second user ID unexpectedly invalid\n"); exit (1); } if (key->uids && key->uids->next - && key->uids->next->validity != GPGME_VALIDITY_UNKNOWN) + && key->uids->next->validity != keys[i].uid[1].validity) { fprintf (stderr, "Second user ID has unexpectedly validity: %i\n", key->uids->next->validity); exit (1); } if (key->uids && key->uids->next && key->uids->next->signatures) { fprintf (stderr, "Second user ID unexpectedly signed\n"); exit (1); } if (keys[i].uid[1].name && strcmp (keys[i].uid[1].name, key->uids->next->name)) { fprintf (stderr, "Unexpected name in second user ID: %s\n", key->uids->next->name); exit (1); } if (keys[i].uid[1].comment && strcmp (keys[i].uid[1].comment, key->uids->next->comment)) { fprintf (stderr, "Unexpected comment in second user ID: %s\n", key->uids->next->comment); exit (1); } if (keys[i].uid[1].email && strcmp (keys[i].uid[1].email, key->uids->next->email)) { fprintf (stderr, "Unexpected email in second user ID: %s\n", key->uids->next->email); exit (1); } if (key->uids && key->uids->next && key->uids->next->next && key->uids->next->next->revoked) { fprintf (stderr, "Third user ID unexpectedly revoked\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->next && key->uids->next->next->invalid) { fprintf (stderr, "Third user ID unexpectedly invalid\n"); exit (1); } if (key->uids && key->uids->next && key->uids->next->next - && key->uids->next->next->validity != GPGME_VALIDITY_UNKNOWN) + && key->uids->next->next->validity != keys[i].uid[2].validity) { fprintf (stderr, "Third user ID has unexpectedly validity: %i\n", key->uids->next->next->validity); exit (1); } if (key->uids && key->uids->next && key->uids->next->next && key->uids->next->next->signatures) { fprintf (stderr, "Third user ID unexpectedly signed\n"); exit (1); } if (keys[i].uid[2].name && strcmp (keys[i].uid[2].name, key->uids->next->next->name)) { fprintf (stderr, "Unexpected name in third user ID: %s\n", key->uids->next->next->name); exit (1); } if (keys[i].uid[2].comment && strcmp (keys[i].uid[2].comment, key->uids->next->next->comment)) { fprintf (stderr, "Unexpected comment in third user ID: %s\n", key->uids->next->next->comment); exit (1); } if (keys[i].uid[2].email && strcmp (keys[i].uid[2].email, key->uids->next->next->email)) { fprintf (stderr, "Unexpected email in third user ID: %s\n", key->uids->next->next->email); exit (1); } if (keys[i].misc_check) keys[i].misc_check (keys+i, key); gpgme_key_unref (key); i++; } if (gpgme_err_code (err) != GPG_ERR_EOF) fail_if_err (err); err = gpgme_op_keylist_end (ctx); fail_if_err (err); result = gpgme_op_keylist_result (ctx); if (result->truncated) { fprintf (stderr, "Key listing unexpectedly truncated\n"); exit (1); } if (keys[i].fpr) { fprintf (stderr, "Less keys (%d) returned than expected (%d)\n", i, (int)(DIM (keys) - 1)); exit (1); } gpgme_release (ctx); return 0; } /* Check expration of keys. This test assumes three subkeys of which 2 are expired; it is used with the "Whisky" test key. It has already been checked that these 3 subkeys are available. */ static void check_whisky (struct key_info_s *keyinfo, gpgme_key_t key) { const char *name = keyinfo->uid[0].name; gpgme_subkey_t sub1, sub2; sub1 = key->subkeys->next->next; sub2 = sub1->next; if (!sub1->expired || !sub2->expired) { fprintf (stderr, "Subkey of `%s' not flagged as expired\n", name); exit (1); } if (sub1->expires != 1129636886 || sub2->expires != 1129636939) { fprintf (stderr, "Subkey of `%s' has wrong expiration date\n", name); exit (1); } } diff --git a/tests/gpg/t-verify.c b/tests/gpg/t-verify.c index 695a994e..c89e4973 100644 --- a/tests/gpg/t-verify.c +++ b/tests/gpg/t-verify.c @@ -1,366 +1,369 @@ /* t-verify.c - Regression test. * Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH * * This file is part of GPGME. * * GPGME is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * GPGME 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . * SPDX-License-Identifier: LGPL-2.1-or-later */ /* We need to include config.h so that we know whether we are building with large file system (LFS) support. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #define PGM "t-verify" #include "t-support.h" static const char test_text1[] = "Just GNU it!\n"; static const char test_text1f[]= "Just GNU it?\n"; static const char test_sig1[] = "-----BEGIN PGP SIGNATURE-----\n" "\n" "iN0EABECAJ0FAjoS+i9FFIAAAAAAAwA5YmFyw7bDpMO8w58gZGFzIHdhcmVuIFVt\n" "bGF1dGUgdW5kIGpldHp0IGVpbiBwcm96ZW50JS1aZWljaGVuNRSAAAAAAAgAJGZv\n" "b2Jhci4xdGhpcyBpcyBhIG5vdGF0aW9uIGRhdGEgd2l0aCAyIGxpbmVzGhpodHRw\n" "Oi8vd3d3Lmd1Lm9yZy9wb2xpY3kvAAoJEC1yfMdoaXc0JBIAoIiLlUsvpMDOyGEc\n" "dADGKXF/Hcb+AKCJWPphZCphduxSvrzH0hgzHdeQaA==\n" "=nts1\n" "-----END PGP SIGNATURE-----\n"; /* The same as test_sig1 but with a second signature for which we do * not have the public key (deleted after signature creation). */ static const char test_sig1_plus_unknown_key[] = "-----BEGIN PGP SIGNATURE-----\n" "\n" "iN0EABECAJ0FAjoS+i9FFIAAAAAAAwA5YmFyw7bDpMO8w58gZGFzIHdhcmVuIFVt\n" "bGF1dGUgdW5kIGpldHp0IGVpbiBwcm96ZW50JS1aZWljaGVuNRSAAAAAAAgAJGZv\n" "b2Jhci4xdGhpcyBpcyBhIG5vdGF0aW9uIGRhdGEgd2l0aCAyIGxpbmVzGhpodHRw\n" "Oi8vd3d3Lmd1Lm9yZy9wb2xpY3kvAAoJEC1yfMdoaXc0JBIAoIiLlUsvpMDOyGEc\n" "dADGKXF/Hcb+AKCJWPphZCphduxSvrzH0hgzHdeQaIh1BAAWCAAdFiEENuwqcMZC\n" "brD85btN+RyY8EnUIEwFAlrPR4cACgkQ+RyY8EnUIEyiuAEAm41LJTGUFDzhavRm\n" "jNwqUZxGGOySduW+u/X1lEfV+MYA/2lJOo75rHtD1EG+tkFVWt4Ukj0rjhR132vZ\n" "IOtrYAcG\n" "=yYwZ\n" "-----END PGP SIGNATURE-----\n"; static const char test_sig2[] = "-----BEGIN PGP MESSAGE-----\n" "\n" "owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n" "GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n" "y1kvP4y+8D5a11ang0udywsA\n" "=Crq6\n" "-----END PGP MESSAGE-----\n"; /* A message with a prepended but unsigned plaintext packet. */ static const char double_plaintext_sig[] = "-----BEGIN PGP MESSAGE-----\n" "\n" "rDRiCmZvb2Jhci50eHRF4pxNVGhpcyBpcyBteSBzbmVha3kgcGxhaW50ZXh0IG1l\n" "c3NhZ2UKowGbwMvMwCSoW1RzPCOz3IRxTWISa6JebnG666MFD1wzSzJSixQ81XMV\n" "UlITUxTyixRyKxXKE0uSMxQyEosVikvyCwpSU/S4FNCArq6Ce1F+aXJGvoJvYlGF\n" "erFCTmJxiUJ5flFKMVeHGwuDIBMDGysTyA4GLk4BmO036xgWzMgzt9V85jCtfDFn\n" "UqVooWlGXHwNw/xg/fVzt9VNbtjtJ/fhUqYo0/LyCGEA\n" "=6+AK\n" "-----END PGP MESSAGE-----\n"; /* NO_OF_SIGS is the expected number of signatures. SKIP_SKIPS is * which of these signatures to check (0 based). */ static void check_result (gpgme_verify_result_t result, int no_of_sigs, int skip_sigs, unsigned int summary, const char *fpr, - gpgme_error_t status, int notation) + gpgme_error_t status, int notation, int validity) { gpgme_signature_t sig; int n; sig = result->signatures; for (n=0; sig; sig = sig->next) n++; if (n != no_of_sigs) { fprintf (stderr, "%s:%i: Unexpected number of signatures" " (got %d expected %d)\n", PGM, __LINE__, n, no_of_sigs); exit (1); } if (skip_sigs >= n) { fprintf (stderr, "%s:%i: oops SKIPP_SIGS to high\n", PGM, __LINE__); exit (1); } for (n=0, sig = result->signatures; n < skip_sigs; sig = sig->next, n++) ; if (sig->summary != summary) { fprintf (stderr, "%s:%i:sig-%d: Unexpected signature summary: " "want=0x%x have=0x%x\n", PGM, __LINE__, skip_sigs, summary, sig->summary); exit (1); } if (strcmp (sig->fpr, fpr)) { if (strlen (sig->fpr) == 16 && strlen (fpr) == 40 && !strncmp (sig->fpr, fpr + 24, 16)) ; /* okay because gnupg < 2.2.6 only shows the keyid. */ else { fprintf (stderr, "%s:%i:sig-%d: Unexpected fingerprint: %s\n", PGM, __LINE__, skip_sigs, sig->fpr); exit (1); } } if (gpgme_err_code (sig->status) != status) { fprintf (stderr, "%s:%i:sig-%d: Unexpected signature status: %s\n", PGM, __LINE__, skip_sigs, gpgme_strerror (sig->status)); exit (1); } if (notation) { static struct { const char *name; const char *value; int seen; } expected_notations[] = { { "bar", "\xc3\xb6\xc3\xa4\xc3\xbc\xc3\x9f" " das waren Umlaute und jetzt ein prozent%-Zeichen" }, { "foobar.1", "this is a notation data with 2 lines" }, { NULL, "http://www.gu.org/policy/" } }; int i; gpgme_sig_notation_t r; for (i=0; i < DIM(expected_notations); i++ ) expected_notations[i].seen = 0; for (r = sig->notations; r; r = r->next) { int any = 0; for (i=0; i < DIM(expected_notations); i++) { if ( ((r->name && expected_notations[i].name && !strcmp (r->name, expected_notations[i].name) && r->name_len == strlen (expected_notations[i].name)) || (!r->name && !expected_notations[i].name && r->name_len == 0)) && r->value && !strcmp (r->value, expected_notations[i].value) && r->value_len == strlen (expected_notations[i].value)) { expected_notations[i].seen++; any++; } } if (!any) { fprintf (stderr, "%s:%i:sig-%d: Unexpected notation data\n", PGM, __LINE__, skip_sigs); exit (1); } } for (i=0; i < DIM(expected_notations); i++ ) { if (expected_notations[i].seen != 1) { fprintf (stderr, "%s:%i:sig-%d: " "Missing or duplicate notation data\n", PGM, __LINE__, skip_sigs); exit (1); } } } if (sig->wrong_key_usage) { fprintf (stderr, "%s:%i:sig-%d: Unexpectedly wrong key usage\n", PGM, __LINE__, skip_sigs); exit (1); } - if (sig->validity != GPGME_VALIDITY_UNKNOWN) + if (sig->validity != validity) { - fprintf (stderr, "%s:%i:sig-%d: Unexpected validity: %i\n", - PGM, __LINE__, skip_sigs, sig->validity); + fprintf (stderr, "%s:%i:sig-%d: Unexpected validity: " + "want=%i have=%i\n", + PGM, __LINE__, skip_sigs, validity, sig->validity); exit (1); } if (gpgme_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR) { fprintf (stderr, "%s:%i:sig-%d: Unexpected validity reason: %s\n", PGM, __LINE__, skip_sigs, gpgme_strerror (sig->validity_reason)); exit (1); } } int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t sig, text; gpgme_verify_result_t result; const char *s; (void)argc; (void)argv; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); /* Checking a valid message. */ err = gpgme_data_new_from_mem (&text, test_text1, strlen (test_text1), 0); fail_if_err (err); err = gpgme_data_new_from_mem (&sig, test_sig1, strlen (test_sig1), 0); fail_if_err (err); err = gpgme_op_verify (ctx, sig, text, NULL); fail_if_err (err); result = gpgme_op_verify_result (ctx); - check_result (result, 1, 0, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", - GPG_ERR_NO_ERROR, 1); + check_result (result, 1, 0, GPGME_SIGSUM_VALID|GPGME_SIGSUM_GREEN, + "A0FF4590BB6122EDEF6E3C542D727CC768697734", + GPG_ERR_NO_ERROR, 1, GPGME_VALIDITY_FULL); /* Checking a manipulated message. */ gpgme_data_release (text); err = gpgme_data_new_from_mem (&text, test_text1f, strlen (test_text1f), 0); fail_if_err (err); gpgme_data_seek (sig, 0, SEEK_SET); err = gpgme_op_verify (ctx, sig, text, NULL); fail_if_err (err); result = gpgme_op_verify_result (ctx); check_result (result, 1, 0, GPGME_SIGSUM_RED, "2D727CC768697734", - GPG_ERR_BAD_SIGNATURE, 0); + GPG_ERR_BAD_SIGNATURE, 0, GPGME_VALIDITY_UNKNOWN); - /* Checking a valid message. Bu that one has a second signature + /* Checking a valid message. But that one has a second signature * made by an unknown key. */ gpgme_data_release (text); gpgme_data_release (sig); err = gpgme_data_new_from_mem (&text, test_text1, strlen (test_text1), 0); fail_if_err (err); err = gpgme_data_new_from_mem (&sig, test_sig1_plus_unknown_key, strlen (test_sig1_plus_unknown_key), 0); fail_if_err (err); err = gpgme_op_verify (ctx, sig, text, NULL); fail_if_err (err); result = gpgme_op_verify_result (ctx); - check_result (result, 2, 0, 0, + check_result (result, 2, 0, GPGME_SIGSUM_VALID|GPGME_SIGSUM_GREEN, "A0FF4590BB6122EDEF6E3C542D727CC768697734", - GPG_ERR_NO_ERROR, 1); + GPG_ERR_NO_ERROR, 1, GPGME_VALIDITY_FULL); check_result (result, 2, 1, GPGME_SIGSUM_KEY_MISSING, "36EC2A70C6426EB0FCE5BB4DF91C98F049D4204C", - GPG_ERR_NO_PUBKEY, 0); + GPG_ERR_NO_PUBKEY, 0, GPGME_VALIDITY_UNKNOWN); /* Checking a normal signature. */ gpgme_data_release (sig); gpgme_data_release (text); err = gpgme_data_new_from_mem (&sig, test_sig2, strlen (test_sig2), 0); fail_if_err (err); err = gpgme_data_new (&text); fail_if_err (err); err = gpgme_op_verify (ctx, sig, NULL, text); fail_if_err (err); result = gpgme_op_verify_result (ctx); - check_result (result, 1, 0, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", - GPG_ERR_NO_ERROR, 0); + check_result (result, 1, 0, GPGME_SIGSUM_VALID|GPGME_SIGSUM_GREEN, + "A0FF4590BB6122EDEF6E3C542D727CC768697734", + GPG_ERR_NO_ERROR, 0, GPGME_VALIDITY_FULL); /* Checking an invalid message. */ gpgme_data_release (sig); gpgme_data_release (text); err = gpgme_data_new_from_mem (&sig, double_plaintext_sig, strlen (double_plaintext_sig), 0); fail_if_err (err); err = gpgme_data_new (&text); fail_if_err (err); err = gpgme_op_verify (ctx, sig, NULL, text); if (gpgme_err_code (err) != GPG_ERR_BAD_DATA) { fprintf (stderr, "%s:%i: Double plaintext message not detected\n", PGM, __LINE__); exit (1); } /* Checking that set/get_sernder works. */ err = gpgme_set_sender (ctx, "foo@example.org"); fail_if_err (err); s = gpgme_get_sender (ctx); if (!s || strcmp (s, "foo@example.org")) { fprintf (stderr, "%s:%i: gpgme_{set,get}_sender mismatch\n", PGM, __LINE__); exit (1); } err = gpgme_set_sender (ctx, ""); fail_if_err (err); s = gpgme_get_sender (ctx); if (!s || strcmp (s, "bar@example.org")) { fprintf (stderr, "%s:%i: gpgme_{set,get}_sender mismatch\n", PGM, __LINE__); exit (1); } err = gpgme_set_sender (ctx, "Foo bar (comment) "); fail_if_err (err); s = gpgme_get_sender (ctx); if (!s || strcmp (s, "foo@example.org")) { fprintf (stderr, "%s:%i: gpgme_{set,get}_sender mismatch\n", PGM, __LINE__); exit (1); } err = gpgme_set_sender (ctx, "foo"); if (gpgme_err_code (err) != GPG_ERR_INV_VALUE) { fprintf (stderr, "%s:%i: gpgme_set_sender didn't detect bogus address\n", PGM, __LINE__); exit (1); } /* (the former address should still be there.) */ s = gpgme_get_sender (ctx); if (!s || strcmp (s, "foo@example.org")) { fprintf (stderr, "%s:%i: gpgme_{set,get}_sender mismatch\n", PGM, __LINE__); exit (1); } gpgme_data_release (sig); gpgme_data_release (text); gpgme_release (ctx); return 0; }