Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34307529
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
58 KB
Subscribers
None
View Options
diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am
index a70c7a7b..170b1a7e 100644
--- a/tests/gpg/Makefile.am
+++ b/tests/gpg/Makefile.am
@@ -1,128 +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 <https://gnu.org/licenses/>.
# 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 \
t-setownertrust \
$(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 ownertrust.txt
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 @GPG_ERROR_LIBS@ @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
echo x > ./gpg-sample.stamp
pubring-stamp: $(srcdir)/pubdemo.asc gpg-sample.stamp
$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--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
-$(TESTS_ENVIRONMENT) gpgconf --kill all
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
+# disable-scdaemon is required so that we don't try using a key from a
+# smartcard reader (error might be: Unusable secret key)
echo disable-scdaemon >> ./gpg-agent.conf
# end-of-file
diff --git a/tests/gpg/t-decrypt-verify.c b/tests/gpg/t-decrypt-verify.c
index 424cc817..b548aa93 100644
--- a/tests/gpg/t-decrypt-verify.c
+++ b/tests/gpg/t-decrypt-verify.c
@@ -1,177 +1,180 @@
/* 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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <gpgme.h>
#include "t-support.h"
static const char normal_signed_message[] =
"-----BEGIN PGP MESSAGE-----\n"
"\n"
"owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n"
"GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n"
"y1kvP4y+8D5a11ang0udywsA\n"
"=Crq6\n"
"-----END PGP MESSAGE-----\n";
static void
check_verify_result (gpgme_verify_result_t result, unsigned int summary,
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 != 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);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ 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, GPGME_SIGSUM_VALID|GPGME_SIGSUM_GREEN,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
GPG_ERR_NO_ERROR, GPGME_VALIDITY_FULL);
gpgme_data_release (in);
gpgme_data_release (out);
/* Checking a signed, but not encrypted message. */
err = gpgme_data_new_from_mem (&in, normal_signed_message, strlen (normal_signed_message), 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_decrypt_verify (ctx, in, out);
/* should have returned "no data" because the message is not encrypted */
if (gpgme_err_code (err) != GPG_ERR_NO_DATA)
{
fprintf (stderr, "%s:%i: Unexpected result of gpgme_op_decrypt_verify: %s\n",
__FILE__, __LINE__, gpgme_strerror (err));
}
verify_result = gpgme_op_verify_result (ctx);
check_verify_result (verify_result, GPGME_SIGSUM_VALID|GPGME_SIGSUM_GREEN,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
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-decrypt.c b/tests/gpg/t-decrypt.c
index 408564d7..4128a148 100644
--- a/tests/gpg/t-decrypt.c
+++ b/tests/gpg/t-decrypt.c
@@ -1,83 +1,86 @@
/* t-decrypt.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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <gpgme.h>
#include "t-support.h"
int
main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_decrypt_result_t result;
char *cipher_1_asc = make_filename ("cipher-1.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);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
err = gpgme_data_new_from_file (&in, cipher_1_asc, 1);
free (cipher_1_asc);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_decrypt (ctx, in, out);
fail_if_err (err);
result = gpgme_op_decrypt_result (ctx);
if (result->unsupported_algorithm)
{
fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
__FILE__, __LINE__, result->unsupported_algorithm);
exit (1);
}
print_data (out);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-edit-sign.c b/tests/gpg/t-edit-sign.c
index 059a912b..a2f33354 100644
--- a/tests/gpg/t-edit-sign.c
+++ b/tests/gpg/t-edit-sign.c
@@ -1,272 +1,275 @@
/* t-edit-sign.c - Regression test.
* Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001, 2002, 2003, 2004, 2021 g10 Code GmbH
* Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
*
* 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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <errno.h>
#include <gpgme.h>
#include "t-support.h"
static const char *test_key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
"\n"
"mDMEY+NyJBYJKwYBBAHaRw8BAQdA4VfyC5sa6T3xVSus55LjyqQetFuE1shtu/71\n"
"pHLxg8W0KFNpZ24gbWUgKGRlbW8ga2V5KSA8c2lnbi1tZUBleGFtcGxlLm5ldD6I\n"
"kwQTFgoAOxYhBPPHuA+qbf/jPmLyYnJg+w/EtKy+BQJj43IkAhsDBQsJCAcCAiIC\n"
"BhUKCQgLAgQWAgMBAh4HAheAAAoJEHJg+w/EtKy+26gBAMhaI/lYA9BK35525kQT\n"
"OhvpQwgThJxQp8AOQk3UMgkGAP0ahV9lFXwv9ZnoeHEhjECsNpAFbj9fxBlzNmMZ\n"
"Z92+AA==\n"
"=Koy1\n"
"-----END PGP PUBLIC KEY BLOCK-----\n";
static const char *test_key_fpr = "F3C7B80FAA6DFFE33E62F2627260FB0FC4B4ACBE";
static void
import_key (const char *keydata)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in;
err = gpgme_new (&ctx);
fail_if_err (err);
err = gpgme_data_new_from_mem (&in, keydata, strlen(keydata), 0);
fail_if_err (err);
err = gpgme_op_import (ctx, in);
fail_if_err (err);
gpgme_data_release (in);
gpgme_release (ctx);
}
static void
delete_key (const char *fpr)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_key_t key = NULL;
err = gpgme_new (&ctx);
fail_if_err (err);
err = gpgme_get_key (ctx, fpr, &key, 0);
fail_if_err (err);
err = gpgme_op_delete_ext (ctx, key, GPGME_DELETE_FORCE);
fail_if_err (err);
gpgme_key_unref (key);
gpgme_release (ctx);
}
static void
flush_data (gpgme_data_t dh)
{
char buf[100];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (gpgme_error_from_errno (errno));
while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (gpgme_error_from_errno (errno));
}
gpgme_error_t
interact_fnc (void *opaque, const char *status, const char *args, int fd)
{
const char *result = NULL;
gpgme_data_t out = (gpgme_data_t) opaque;
fputs ("[-- Response --]\n", stdout);
flush_data (out);
fprintf (stdout, "[-- Code: %s, %s --]\n", status, args);
if (fd >= 0)
{
if (!strcmp (args, "keyedit.prompt"))
{
static int step = 0;
switch (step)
{
case 0:
result = "fpr";
break;
case 1:
/* This fixes the primary user ID so the keylisting
tests will have predictable output. */
result = "1";
break;
case 2:
result = "sign";
break;
default:
result = "quit";
break;
}
step++;
}
else if (!strcmp (args, "keyedit.save.okay"))
result = "Y";
else if (!strcmp (args, "sign_uid.okay"))
result = "Y";
}
if (result)
gpgme_io_writen (fd, result, strlen (result));
gpgme_io_writen (fd, "\n", 1);
return 0;
}
void
sign_key (const char *key_fpr, const char *signer_fpr)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t out = NULL;
gpgme_key_t signing_key = NULL;
gpgme_key_t key = NULL;
char *agent_info;
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, 0);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, 0);
+ }
err = gpgme_get_key (ctx, signer_fpr, &signing_key, 1);
fail_if_err (err);
err = gpgme_signers_add (ctx, signing_key);
fail_if_err (err);
err = gpgme_set_ctx_flag (ctx, "cert-expire", "42d");
fail_if_err (err);
err = gpgme_get_key (ctx, key_fpr, &key, 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_interact (ctx, key, 0, interact_fnc, out, out);
fail_if_err (err);
fputs ("[-- Last response --]\n", stdout);
flush_data (out);
gpgme_data_release (out);
gpgme_key_unref (key);
gpgme_key_unref (signing_key);
gpgme_release (ctx);
}
void
verify_key_signature (const char *key_fpr, const char *signer_keyid)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_key_t signed_key = NULL;
gpgme_user_id_t signed_uid = NULL;
gpgme_key_sig_t key_sig = NULL;
int mode;
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_get_key (ctx, key_fpr, &signed_key, 0);
fail_if_err (err);
signed_uid = signed_key->uids;
if (!signed_uid)
{
fprintf (stderr, "Signed key has no user IDs\n");
exit (1);
}
if (!signed_uid->signatures || !signed_uid->signatures->next)
{
fprintf (stderr, "Signed user ID has less signatures than expected\n");
exit (1);
}
key_sig = signed_uid->signatures->next;
if (strcmp (signer_keyid, key_sig->keyid))
{
fprintf (stderr, "Unexpected key ID in second user ID sig: %s\n",
key_sig->keyid);
exit (1);
}
if (key_sig->expires != key_sig->timestamp + 42*86400L)
{
fprintf (stderr, "Key signature unexpectedly does not expire in 42 days\n");
fprintf (stderr, "signature date: %ld, expiration date: %ld\n",
key_sig->timestamp, key_sig->expires);
exit (1);
}
gpgme_key_unref (signed_key);
gpgme_release (ctx);
}
int
main (int argc, char **argv)
{
const char *signer_fpr = "A0FF4590BB6122EDEF6E3C542D727CC768697734"; /* Alpha Test */
const char *signer_keyid = signer_fpr + strlen(signer_fpr) - 16;
(void)argc;
(void)argv;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
import_key (test_key);
sign_key (test_key_fpr, signer_fpr);
verify_key_signature (test_key_fpr, signer_keyid);
delete_key (test_key_fpr);
return 0;
}
diff --git a/tests/gpg/t-edit.c b/tests/gpg/t-edit.c
index b34ee3f7..e18e0386 100644
--- a/tests/gpg/t-edit.c
+++ b/tests/gpg/t-edit.c
@@ -1,155 +1,158 @@
/* t-edit.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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <errno.h>
#include <gpgme.h>
#include "t-support.h"
static void
flush_data (gpgme_data_t dh)
{
char buf[100];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (gpgme_error_from_errno (errno));
while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (gpgme_error_from_errno (errno));
}
gpgme_error_t
interact_fnc (void *opaque, const char *status, const char *args, int fd)
{
const char *result = NULL;
gpgme_data_t out = (gpgme_data_t) opaque;
fputs ("[-- Response --]\n", stdout);
flush_data (out);
fprintf (stdout, "[-- Code: %s, %s --]\n", status, args);
if (fd >= 0)
{
if (!strcmp (args, "keyedit.prompt"))
{
static int step = 0;
switch (step)
{
case 0:
result = "fpr";
break;
case 1:
result = "expire";
break;
/* This fixes the primary user ID so the keylisting
tests will have predictable output. */
case 2:
result = "1";
break;
case 3:
result = "primary";
break;
default:
result = "quit";
break;
}
step++;
}
else if (!strcmp (args, "keyedit.save.okay"))
result = "Y";
else if (!strcmp (args, "keygen.valid"))
result = "0";
}
if (result)
{
gpgme_io_writen (fd, result, strlen (result));
gpgme_io_writen (fd, "\n", 1);
}
return 0;
}
int
main (int argc, char **argv)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t out = NULL;
gpgme_key_t key = NULL;
const char *pattern = "Alpha";
char *agent_info;
(void)argc;
(void)argv;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
err = gpgme_new (&ctx);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
agent_info = getenv("GPG_AGENT_INFO");
if (!(agent_info && strchr (agent_info, ':')))
- gpgme_set_passphrase_cb (ctx, passphrase_cb, 0);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, 0);
+ }
err = gpgme_op_keylist_start (ctx, pattern, 0);
fail_if_err (err);
err = gpgme_op_keylist_next (ctx, &key);
fail_if_err (err);
err = gpgme_op_keylist_end (ctx);
fail_if_err (err);
err = gpgme_op_interact (ctx, key, 0, interact_fnc, out, out);
fail_if_err (err);
fputs ("[-- Last response --]\n", stdout);
flush_data (out);
gpgme_data_release (out);
gpgme_key_unref (key);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-encrypt-mixed.c b/tests/gpg/t-encrypt-mixed.c
index 4cc9d6a6..5040148c 100644
--- a/tests/gpg/t-encrypt-mixed.c
+++ b/tests/gpg/t-encrypt-mixed.c
@@ -1,130 +1,131 @@
/* t-encrypt-mixed.c - Regression test.
* Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik
* Software engineering by Intevation 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 <https://gnu.org/licenses/>.
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gpgme.h>
#include "t-support.h"
/* Tests mixed symmetric and asymmetric decryption. Verifies
that an encrypted message can be decrypted without the
secret key but that the recipient is also set correctly. */
int
main (void)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_key_t key[2] = { NULL, NULL };
gpgme_encrypt_result_t result;
gpgme_decrypt_result_t dec_result;
gpgme_recipient_t recipient;
const char *text = "Hallo Leute\n";
char *text2;
size_t len;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_armor (ctx, 1);
err = gpgme_data_new_from_mem (&in, text, strlen (text), 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
/* A recipient for which we don't have a secret key */
err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
&key[0], 0);
fail_if_err (err);
err = gpgme_op_encrypt (ctx, key,
GPGME_ENCRYPT_ALWAYS_TRUST | GPGME_ENCRYPT_SYMMETRIC,
in, out);
fail_if_err (err);
result = gpgme_op_encrypt_result (ctx);
if (result->invalid_recipients)
{
fprintf (stderr, "Invalid recipient encountered: %s\n",
result->invalid_recipients->fpr);
exit (1);
}
print_data (out);
/* Now try to decrypt */
gpgme_data_seek (out, 0, SEEK_SET);
gpgme_data_release (in);
err = gpgme_data_new (&in);
fail_if_err (err);
err = gpgme_op_decrypt (ctx, out, in);
fail_if_err (err);
fputs ("Begin Result Decryption:\n", stdout);
print_data (in);
fputs ("End Result.\n", stdout);
dec_result = gpgme_op_decrypt_result (ctx);
if (dec_result->unsupported_algorithm || dec_result->wrong_key_usage)
{
fprintf (stderr, "%s:%d: Decryption failed\n", __FILE__, __LINE__);
exit (1);
}
text2 = gpgme_data_release_and_get_mem (in, &len);
if (strncmp (text, text2, len))
{
fprintf (stderr, "%s:%d: Wrong plaintext\n", __FILE__, __LINE__);
exit (1);
}
recipient = dec_result->recipients;
if (!recipient || recipient->next)
{
fprintf (stderr, "%s:%d: Invalid recipients \n", __FILE__, __LINE__);
exit (1);
}
if (strncmp (recipient->keyid, "5381EA4EE29BA37F", 16))
{
fprintf (stderr, "%s:%d: Not encrypted to recipient's subkey \n", __FILE__, __LINE__);
exit (1);
}
gpgme_key_unref (key[0]);
free (text2);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-encrypt-sign.c b/tests/gpg/t-encrypt-sign.c
index dbdae0b6..4dda4faa 100644
--- a/tests/gpg/t-encrypt-sign.c
+++ b/tests/gpg/t-encrypt-sign.c
@@ -1,161 +1,164 @@
/* t-encrypt-sign.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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <gpgme.h>
#include "t-support.h"
static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{
if (result->invalid_signers)
{
fprintf (stderr, "Invalid signer found: %s\n",
result->invalid_signers->fpr);
exit (1);
}
if (!result->signatures || result->signatures->next)
{
fprintf (stderr, "Unexpected number of signatures created\n");
exit (1);
}
if (result->signatures->type != type)
{
fprintf (stderr, "Wrong type of signature created\n");
exit (1);
}
if (result->signatures->pubkey_algo != GPGME_PK_DSA)
{
fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
result->signatures->pubkey_algo);
exit (1);
}
if (result->signatures->hash_algo != GPGME_MD_SHA1
&& result->signatures->hash_algo != GPGME_MD_RMD160)
{
fprintf (stderr, "Wrong hash algorithm reported: %i\n",
result->signatures->hash_algo);
exit (1);
}
if (result->signatures->sig_class != 0)
{
fprintf (stderr, "Wrong signature class reported: %u\n",
result->signatures->sig_class);
exit (1);
}
if (strcmp ("A0FF4590BB6122EDEF6E3C542D727CC768697734",
result->signatures->fpr))
{
fprintf (stderr, "Wrong fingerprint reported: %s\n",
result->signatures->fpr);
exit (1);
}
}
int
main (int argc, char **argv)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_key_t key[3] = { NULL, NULL, NULL };
gpgme_encrypt_result_t result;
gpgme_sign_result_t sign_result;
char *agent_info;
(void)argc;
(void)argv;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_textmode (ctx, 1);
gpgme_set_armor (ctx, 1);
agent_info = getenv("GPG_AGENT_INFO");
if (!(agent_info && strchr (agent_info, ':')))
- gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
&key[0], 0);
fail_if_err (err);
err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
&key[1], 0);
fail_if_err (err);
err = gpgme_op_encrypt_sign (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
fail_if_err (err);
result = gpgme_op_encrypt_result (ctx);
if (result->invalid_recipients)
{
fprintf (stderr, "Invalid recipient encountered: %s\n",
result->invalid_recipients->fpr);
exit (1);
}
sign_result = gpgme_op_sign_result (ctx);
check_result (sign_result, GPGME_SIG_MODE_NORMAL);
print_data (out);
gpgme_key_unref (key[0]);
gpgme_key_unref (key[1]);
gpgme_data_release (in);
gpgme_data_release (out);
/* Now a second time using symmetric encryption. */
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_encrypt_sign (ctx, NULL, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
fail_if_err (err);
sign_result = gpgme_op_sign_result (ctx);
check_result (sign_result, GPGME_SIG_MODE_NORMAL);
print_data (out);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-encrypt-sym.c b/tests/gpg/t-encrypt-sym.c
index 127bac60..d10a9606 100644
--- a/tests/gpg/t-encrypt-sym.c
+++ b/tests/gpg/t-encrypt-sym.c
@@ -1,99 +1,102 @@
/* t-encrypt-sym.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.
*
*/
/* 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 <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <gpgme.h>
#include "t-support.h"
int
main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t plain, cipher;
const char *text = "Hallo Leute\n";
char *text2;
char *p;
size_t len;
(void)argc;
(void)argv;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_armor (ctx, 1);
p = getenv("GPG_AGENT_INFO");
if (!(p && strchr (p, ':')))
- gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
err = gpgme_data_new_from_mem (&plain, text, strlen (text), 0);
fail_if_err (err);
err = gpgme_data_new (&cipher);
fail_if_err (err);
err = gpgme_op_encrypt (ctx, 0, 0, plain, cipher);
fail_if_err (err);
fflush (NULL);
fputs ("Begin Result Encryption:\n", stdout);
print_data (cipher);
fputs ("End Result.\n", stdout);
gpgme_data_seek (cipher, 0, SEEK_SET);
gpgme_data_release (plain);
err = gpgme_data_new (&plain);
fail_if_err (err);
err = gpgme_op_decrypt (ctx, cipher, plain);
fail_if_err (err);
fputs ("Begin Result Decryption:\n", stdout);
print_data (plain);
fputs ("End Result.\n", stdout);
text2 = gpgme_data_release_and_get_mem (plain, &len);
if (strncmp (text, text2, len))
{
fprintf (stderr, "%s:%d: Wrong plaintext\n", __FILE__, __LINE__);
exit (1);
}
gpgme_data_release (cipher);
free (text2);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-file-name.c b/tests/gpg/t-file-name.c
index 3b29e4f1..a1d1e597 100644
--- a/tests/gpg/t-file-name.c
+++ b/tests/gpg/t-file-name.c
@@ -1,99 +1,102 @@
/* t-file-name.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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gpgme.h>
#include "t-support.h"
#define TESTNAME "abcde12345"
int
main (void)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_key_t key[2] = { NULL, NULL };
gpgme_decrypt_result_t result;
char *agent_info;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_armor (ctx, 1);
agent_info = getenv("GPG_AGENT_INFO");
if (!(agent_info && strchr (agent_info, ':')))
- gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
err = gpgme_data_set_file_name (in, TESTNAME);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
&key[0], 0);
fail_if_err (err);
err = gpgme_op_encrypt (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
fail_if_err (err);
gpgme_data_release (in);
err = gpgme_data_new (&in);
fail_if_err (err);
err = gpgme_data_seek (out, 0, SEEK_SET);
fail_if_err (err);
err = gpgme_op_decrypt (ctx, out, in);
fail_if_err (err);
result = gpgme_op_decrypt_result (ctx);
if (strcmp (TESTNAME, result->file_name))
{
fprintf (stderr, "%s:%i: Unexpected result file name: %s\n",
__FILE__, __LINE__,
result->file_name ? result->file_name : "(null)");
exit (1);
}
gpgme_key_unref (key[0]);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-sig-notation.c b/tests/gpg/t-sig-notation.c
index df45cfd5..95da481b 100644
--- a/tests/gpg/t-sig-notation.c
+++ b/tests/gpg/t-sig-notation.c
@@ -1,198 +1,201 @@
/* t-sig-notation.c - Regression test.
* Copyright (C) 2005 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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gpgme.h>
#include "t-support.h"
/* GnuPG prior to 2.1.13 did not report the critical flag
correctly. */
int have_correct_sig_data;
static struct {
const char *name;
const char *value;
gpgme_sig_notation_flags_t flags;
int seen;
} expected_notations[] = {
{ "laughing@me",
"Just Squeeze Me",
GPGME_SIG_NOTATION_HUMAN_READABLE },
{ "preferred-email-encoding@pgp.com",
"pgpmime",
GPGME_SIG_NOTATION_HUMAN_READABLE | GPGME_SIG_NOTATION_CRITICAL },
{ NULL,
"https://www.gnu.org/policy/",
0 }
};
static void
check_result (gpgme_verify_result_t result)
{
int i;
gpgme_sig_notation_t r;
gpgme_signature_t sig;
sig = result->signatures;
if (!sig || sig->next)
{
fprintf (stderr, "%s:%i: Unexpected number of signatures\n",
__FILE__, __LINE__);
exit (1);
}
for (i=0; i < DIM(expected_notations); i++ )
expected_notations[i].seen = 0;
for (r = result->signatures->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)
&& r->flags
== (have_correct_sig_data
? expected_notations[i].flags
: expected_notations[i].flags
& ~GPGME_SIG_NOTATION_CRITICAL)
&& r->human_readable
== !!(r->flags & GPGME_SIG_NOTATION_HUMAN_READABLE)
&& r->critical
== (have_correct_sig_data
? !!(r->flags & GPGME_SIG_NOTATION_CRITICAL)
: 0))
{
expected_notations[i].seen++;
any++;
}
}
if (!any)
{
fprintf (stderr, "%s:%i: Unexpected notation data\n",
__FILE__, __LINE__);
exit (1);
}
}
for (i=0; i < DIM(expected_notations); i++ )
{
if (expected_notations[i].seen != 1)
{
fprintf (stderr, "%s:%i: Missing or duplicate notation data\n",
__FILE__, __LINE__);
exit (1);
}
}
}
int
main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_verify_result_t result;
char *agent_info;
int i;
gpgme_engine_info_t engine_info;
(void)argc;
(void)argv;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
err = gpgme_get_engine_info (&engine_info);
fail_if_err (err);
for (; engine_info; engine_info = engine_info->next)
if (engine_info->protocol == GPGME_PROTOCOL_OpenPGP)
break;
assert (engine_info);
/* GnuPG prior to 2.1.13 did not report the critical flag
correctly. */
have_correct_sig_data =
! (strncmp ("1.", engine_info->version, 2) == 0
|| strncmp ("2.0.", engine_info->version, 4) == 0
|| (strncmp ("2.1.1", engine_info->version, 5) == 0
&& (engine_info->version[5] == 0
|| engine_info->version[5] < '3')));
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);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
for (i = 0; i < sizeof (expected_notations) / sizeof (expected_notations[0]);
i++)
{
err = gpgme_sig_notation_add (ctx, expected_notations[i].name,
expected_notations[i].value,
expected_notations[i].flags);
fail_if_err (err);
}
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
fail_if_err (err);
gpgme_data_release (in);
err = gpgme_data_new (&in);
fail_if_err (err);
gpgme_data_seek (out, 0, SEEK_SET);
err = gpgme_op_verify (ctx, out, NULL, in);
fail_if_err (err);
result = gpgme_op_verify_result (ctx);
check_result (result);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-sign.c b/tests/gpg/t-sign.c
index 54138241..76e85659 100644
--- a/tests/gpg/t-sign.c
+++ b/tests/gpg/t-sign.c
@@ -1,158 +1,161 @@
/* t-sign.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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <gpgme.h>
#include "t-support.h"
static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{
if (result->invalid_signers)
{
fprintf (stderr, "Invalid signer found: %s\n",
result->invalid_signers->fpr);
exit (1);
}
if (!result->signatures || result->signatures->next)
{
fprintf (stderr, "Unexpected number of signatures created\n");
exit (1);
}
if (result->signatures->type != type)
{
fprintf (stderr, "Wrong type of signature created\n");
exit (1);
}
if (result->signatures->pubkey_algo != GPGME_PK_DSA)
{
fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
result->signatures->pubkey_algo);
exit (1);
}
if (result->signatures->hash_algo != GPGME_MD_SHA1)
{
fprintf (stderr, "Wrong hash algorithm reported: %i\n",
result->signatures->hash_algo);
exit (1);
}
if (result->signatures->sig_class != 1)
{
fprintf (stderr, "Wrong signature class reported: %u\n",
result->signatures->sig_class);
exit (1);
}
if (strcmp ("A0FF4590BB6122EDEF6E3C542D727CC768697734",
result->signatures->fpr))
{
fprintf (stderr, "Wrong fingerprint reported: %s\n",
result->signatures->fpr);
exit (1);
}
}
int
main (int argc, char **argv)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_sign_result_t result;
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);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
gpgme_set_textmode (ctx, 1);
gpgme_set_armor (ctx, 1);
#if 0
{
gpgme_key_t akey;
err = gpgme_get_key (ctx, "0x68697734", &akey, 0);
fail_if_err (err);
err = gpgme_signers_add (ctx, akey);
fail_if_err (err);
gpgme_key_unref (akey);
}
#endif
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
/* First a normal signature. */
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
fail_if_err (err);
result = gpgme_op_sign_result (ctx);
check_result (result, GPGME_SIG_MODE_NORMAL);
print_data (out);
gpgme_data_release (out);
/* Now a detached signature. */
gpgme_data_seek (in, 0, SEEK_SET);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH);
fail_if_err (err);
result = gpgme_op_sign_result (ctx);
check_result (result, GPGME_SIG_MODE_DETACH);
print_data (out);
gpgme_data_release (out);
/* And finally a cleartext signature. */
gpgme_data_seek (in, 0, SEEK_SET);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_CLEAR);
fail_if_err (err);
result = gpgme_op_sign_result (ctx);
check_result (result, GPGME_SIG_MODE_CLEAR);
print_data (out);
gpgme_data_release (out);
gpgme_data_release (in);
gpgme_release (ctx);
return 0;
}
diff --git a/tests/gpg/t-signers.c b/tests/gpg/t-signers.c
index cc8609a9..26c2db2e 100644
--- a/tests/gpg/t-signers.c
+++ b/tests/gpg/t-signers.c
@@ -1,177 +1,180 @@
/* t-signers.c - Regression tests for the multiple signers interface.
* 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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <gpgme.h>
#include "t-support.h"
static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{
gpgme_new_signature_t signature;
if (result->invalid_signers)
{
fprintf (stderr, "Invalid signer found: %s\n",
result->invalid_signers->fpr);
exit (1);
}
if (!result->signatures || !result->signatures->next
|| result->signatures->next->next)
{
fprintf (stderr, "Unexpected number of signatures created\n");
exit (1);
}
signature = result->signatures;
while (signature)
{
if (signature->type != type)
{
fprintf (stderr, "Wrong type of signature created\n");
exit (1);
}
if (signature->pubkey_algo != GPGME_PK_DSA)
{
fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
signature->pubkey_algo);
exit (1);
}
if (signature->hash_algo != GPGME_MD_SHA1)
{
fprintf (stderr, "Wrong hash algorithm reported: %i\n",
signature->hash_algo);
exit (1);
}
if (signature->sig_class != 1)
{
fprintf (stderr, "Wrong signature class reported: %u\n",
signature->sig_class);
exit (1);
}
if (strcmp ("A0FF4590BB6122EDEF6E3C542D727CC768697734",
signature->fpr)
&& strcmp ("23FD347A419429BACCD5E72D6BC4778054ACD246",
signature->fpr))
{
fprintf (stderr, "Wrong fingerprint reported: %s\n",
signature->fpr);
exit (1);
}
signature = signature->next;
}
}
int
main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_key_t key[2];
gpgme_sign_result_t result;
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);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
gpgme_set_textmode (ctx, 1);
gpgme_set_armor (ctx, 1);
err = gpgme_op_keylist_start (ctx, NULL, 1);
fail_if_err (err);
err = gpgme_op_keylist_next (ctx, &key[0]);
fail_if_err (err);
err = gpgme_op_keylist_next (ctx, &key[1]);
fail_if_err (err);
err = gpgme_op_keylist_end (ctx);
fail_if_err (err);
err = gpgme_signers_add (ctx, key[0]);
fail_if_err (err);
err = gpgme_signers_add (ctx, key[1]);
fail_if_err (err);
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
/* First a normal signature. */
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
fail_if_err (err);
result = gpgme_op_sign_result (ctx);
check_result (result, GPGME_SIG_MODE_NORMAL);
print_data (out);
gpgme_data_release (out);
/* Now a detached signature. */
gpgme_data_seek (in, 0, SEEK_SET);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH);
fail_if_err (err);
result = gpgme_op_sign_result (ctx);
check_result (result, GPGME_SIG_MODE_DETACH);
print_data (out);
gpgme_data_release (out);
/* And finally a cleartext signature. */
gpgme_data_seek (in, 0, SEEK_SET);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_CLEAR);
fail_if_err (err);
result = gpgme_op_sign_result (ctx);
check_result (result, GPGME_SIG_MODE_CLEAR);
print_data (out);
gpgme_data_release (out);
gpgme_data_seek (in, 0, SEEK_SET);
gpgme_data_release (in);
gpgme_release (ctx);
gpgme_key_unref (key[0]);
gpgme_key_unref (key[1]);
return 0;
}
diff --git a/tests/gpg/t-thread1.c b/tests/gpg/t-thread1.c
index 57d00502..3c64ec24 100644
--- a/tests/gpg/t-thread1.c
+++ b/tests/gpg/t-thread1.c
@@ -1,159 +1,162 @@
/* t-thread1.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 <https://gnu.org/licenses/>.
* 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 <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>
#include <gpgme.h>
#include "t-support.h"
#define ROUNDS 20
void *
thread_one (void *name)
{
int i;
for (i = 0; i < ROUNDS; i++)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_key_t key[3] = { NULL, NULL, NULL };
gpgme_encrypt_result_t result;
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_armor (ctx, 1);
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
&key[0], 0);
fail_if_err (err);
err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
&key[1], 0);
fail_if_err (err);
err = gpgme_op_encrypt (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
fail_if_err (err);
result = gpgme_op_encrypt_result (ctx);
if (result->invalid_recipients)
{
fprintf (stderr, "Invalid recipient encountered: %s\n",
result->invalid_recipients->fpr);
exit (1);
}
printf ("Encrypt %s %i\n", (char *) name, i);
gpgme_key_unref (key[0]);
gpgme_key_unref (key[1]);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
}
return NULL;
}
void *
thread_two (void *name)
{
int i;
char *cipher_1_asc = make_filename ("cipher-1.asc");
char *agent_info;
agent_info = getenv("GPG_AGENT_INFO");
for (i = 0; i < ROUNDS; i++)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_decrypt_result_t result;
init_gpgme (GPGME_PROTOCOL_OpenPGP);
err = gpgme_new (&ctx);
fail_if_err (err);
if (!(agent_info && strchr (agent_info, ':')))
- gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ {
+ gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
+ gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
+ }
err = gpgme_data_new_from_file (&in, cipher_1_asc, 1);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_op_decrypt (ctx, in, out);
fail_if_err (err);
result = gpgme_op_decrypt_result (ctx);
if (result->unsupported_algorithm)
{
fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
__FILE__, __LINE__, result->unsupported_algorithm);
exit (1);
}
printf ("Decrypt %s %i\n", (char *) name, i);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
}
free (cipher_1_asc);
return NULL;
}
int
main (void)
{
pthread_t tone;
pthread_t ttwo;
char arg_A[] = "A";
char arg_B[] = "B";
init_gpgme (GPGME_PROTOCOL_OpenPGP);
pthread_create (&tone, NULL, thread_one, arg_A);
pthread_create (&ttwo, NULL, thread_two, arg_B);
pthread_join (tone, NULL);
pthread_join (ttwo, NULL);
return 0;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Dec 28, 11:10 PM (1 d, 8 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a5/84/36ca31958a24b0c08356c2567d37
Attached To
rM GPGME
Event Timeline
Log In to Comment