diff options
Diffstat (limited to 'branches/gpgme-0-3-branch/tests/gpgsm')
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 | 18 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/Makefile.am | 59 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca01.der | bin | 0 -> 1224 bytes | |||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca15.der | bin | 0 -> 1560 bytes | |||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/cert_g10code_test1.der | bin | 0 -> 793 bytes | |||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-decrypt.c | 103 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-encrypt.c | 139 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-export.c | 91 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-genkey.c | 85 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-import.c | 111 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-keylist.c | 184 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-sign.c | 118 | ||||
-rw-r--r-- | branches/gpgme-0-3-branch/tests/gpgsm/t-verify.c | 222 |
13 files changed, 1130 insertions, 0 deletions
diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 b/branches/gpgme-0-3-branch/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 new file mode 100644 index 00000000..cf0535ff --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/32100C27173EF6E9C4E9A25D3D69F86D37A4F939 @@ -0,0 +1,18 @@ +(private-key + (oid.1.2.840.113549.1.1.1 + (n #00e0ce96f90b6c9e02f3922beada93fe50a875eac6bcc18bb9a9cf2e84965caa2d1ff95a7f542465c6c0c19d276e4526ce048868a7a914fd343cc3a87dd74291ffc565506d5bbb25cbac6a0e2dd1f8bcaab0d4a29c2f37c950f363484bf269f7891440464baf79827e03a36e70b814938eebdc63e964247be75dc58b014b7ea251#) + (e #010001#) + (d #046129F2489D71579BE0A75FE029BD6CDB574EBF57EA8A5B0FDA942CAB943B117D7BB95E5D28875E0F9FC5FCC06A72F6D502464DABDED78EF6B716177B83D5BDC543DC5D3FED932E59F5897E92E6F58A0F33424106A3B6FA2CBF877510E4AC21C3EE47851E97D12996222AC3566D4CCB0B83D164074ABF7DE655FC2446DA1781#) + (p #00e861b700e17e8afe6837e7512e35b6ca11d0ae47d8b85161c67baf64377213fe52d772f2035b3ca830af41d8a4120e1c1c70d12cc22f00d28d31dd48a8d424f1#) + (q #00f7a7ca5367c661f8e62df34f0d05c10c88e5492348dd7bddc942c9a8f369f935a07785d2db805215ed786e4285df1658eed3ce84f469b81b50d358407b4ad361#) + (u #304559a9ead56d2309d203811a641bb1a09626bc8eb36fffa23c968ec5bd891eebbafc73ae666e01ba7c8990bae06cc2bbe10b75e69fcacb353a6473079d8e9b#) + ) +) + + + + + + + + diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/Makefile.am b/branches/gpgme-0-3-branch/tests/gpgsm/Makefile.am new file mode 100644 index 00000000..b8f966b1 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/Makefile.am @@ -0,0 +1,59 @@ +# Copyright (C) 2000 Werner Koch (dd9jn) +# Copyright (C) 2001 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 General Public License as published by +# the Free Software Foundation; either version 2 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +## Process this file with automake to produce Makefile.in + +GPGSM = @GPGSM@ + +TESTS_ENVIRONMENT = GNUPGHOME=. + +TESTS = t-import t-keylist t-encrypt t-verify t-decrypt t-sign t-export + +EXTRA_DIST = cert_dfn_pca01.der cert_dfn_pca15.der cert_g10code_test1.der $(key_id) + +INCLUDES = -I$(top_srcdir)/gpgme + +LDADD = ../../gpgme/libgpgme.la + +noinst_PROGRAMS = $(TESTS) + +key_id := 32100C27173EF6E9C4E9A25D3D69F86D37A4F939 + +DISTCLEANFILES = pubring.kbx pubring.kbx~ gpgsm.conf trustlist.txt \ + private-keys-v1.d/$(key_id).key + + +all-local: ./pubring.kbx ./gpgsm.conf ./private-keys-v1.d/$(key_id).key ./trustlist.txt + +./pubring.kbx: $(srcdir)/cert_g10code_test1.der + $(GPGSM) --homedir . --import $(srcdir)/cert_g10code_test1.der + +./gpgsm.conf: + echo disable-crl-checks > ./gpgsm.conf + +./private-keys-v1.d/$(key_id).key: $(srcdir)/$(key_id) + test -d ./private-keys-v1.d || mkdir ./private-keys-v1.d + cp $(srcdir)/$(key_id) private-keys-v1.d/$(key_id).key + +./trustlist.txt: + echo $(key_id) > ./trustlist.txt + echo >> ./trustlist.txt + echo "# CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=Düsseldorf,C=DE" >> ./trustlist.txt + echo "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E S" >> ./trustlist.txt + diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca01.der b/branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca01.der Binary files differnew file mode 100644 index 00000000..f8b61d33 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca01.der diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca15.der b/branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca15.der Binary files differnew file mode 100644 index 00000000..8d966506 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/cert_dfn_pca15.der diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/cert_g10code_test1.der b/branches/gpgme-0-3-branch/tests/gpgsm/cert_g10code_test1.der Binary files differnew file mode 100644 index 00000000..a2199d27 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/cert_g10code_test1.der diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-decrypt.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-decrypt.c new file mode 100644 index 00000000..212fcf8f --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-decrypt.c @@ -0,0 +1,103 @@ +/* t-encrypt.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <errno.h> + +#include <gpgme.h> + +static const char test_text1[] = "Hallo Leute!\n"; +static const char test_cip1[] = +"-----BEGIN CMS OBJECT-----\n" +"MIAGCSqGSIb3DQEHA6CAMIACAQAxggEJMIIBBQIBADBwMGsxCzAJBgNVBAYTAkRF\n" +"MRMwEQYDVQQHFApE/HNzZWxkb3JmMRYwFAYDVQQKEw1nMTAgQ29kZSBHbWJIMRkw\n" +"FwYDVQQLExBBZWd5cHRlbiBQcm9qZWN0MRQwEgYDVQQDEwt0ZXN0IGNlcnQgMQIB\n" +"ADALBgkqhkiG9w0BAQEEgYBOFcOfUtAav+XjKGM1RJtF+8JLkbnu46S3T3709Iok\n" +"u+Z9dwpOyfHwxXOmjzkSKQSBBxxi6ar+sKjU/KfPIvaMpARwT+NfIVSCZRWIJ27z\n" +"wbSrav/kcRRDDA0wXV7dHVmSLPUJNCpiFMNZbkYtI+ai15g0PVeDw+szYd9zdsjJ\n" +"2zCABgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECA8gPQY2NtJToIAECAeoY3MIcz9h\n" +"BAiiytWtOSmqnwAA\n" +"-----END CMS OBJECT-----\n"; + +#define fail_if_err(a) do { if(a) { int my_errno = errno; \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + if ((a) == GPGME_File_Error) \ + fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \ + exit (1); } \ + } while(0) + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out, pwdata = NULL; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + err = gpgme_data_new_from_mem ( &in, + test_cip1, strlen (test_cip1), 0 ); + fail_if_err (err); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_op_decrypt (ctx, in, out ); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_data_release (pwdata); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-encrypt.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-encrypt.c new file mode 100644 index 00000000..9a7358c2 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-encrypt.c @@ -0,0 +1,139 @@ +/* t-encrypt.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <gpgme.h> + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts ("<!-- no operation info available -->"); + else { + puts (s); + free (s); + } +} + + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + GpgmeRecipients rset; + int loop = 0; + + /* simple option parser; ignoring unknown options */ + if (argc) + { + argc--; + argv++; + } + while (argc && **argv == '-' ) + { + if (!strcmp (*argv, "--loop")) + loop++; + + argc--; + argv++; + if (!strcmp (argv[-1], "--")) + break; + } + + + err = gpgme_engine_check_version (GPGME_PROTOCOL_CMS); + fail_if_err (err); + puts ( gpgme_get_engine_info() ); + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + 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_recipients_new (&rset); + fail_if_err (err); + if (argc) + err = gpgme_recipients_add_name_with_validity (rset, *argv, + GPGME_VALIDITY_FULL); + else + err = gpgme_recipients_add_name_with_validity (rset, + "/CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=Düsseldorf,C=DE", + GPGME_VALIDITY_FULL); + fail_if_err (err); + + err = gpgme_op_encrypt (ctx, rset, in, out ); + print_op_info (ctx); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_recipients_release (rset); + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_release (ctx); + } while (loop); + + return 0; +} + + diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-export.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-export.c new file mode 100644 index 00000000..a5f9e731 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-export.c @@ -0,0 +1,91 @@ +/* t-export.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <gpgme.h> + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData out; + GpgmeRecipients rset; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + err = gpgme_data_new ( &out ); + fail_if_err (err); + + err = gpgme_recipients_new (&rset); + fail_if_err (err); + err = gpgme_recipients_add_name (rset, "DFN Top Level Certification Authority"); + fail_if_err (err); + + gpgme_set_armor (ctx, 1 ); + err = gpgme_op_export (ctx, rset, out ); + fail_if_err (err); + + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + + gpgme_recipients_release (rset); + gpgme_data_release (out); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-genkey.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-genkey.c new file mode 100644 index 00000000..3849f9e4 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-genkey.c @@ -0,0 +1,85 @@ +/* t-genkey.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <gpgme.h> + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + + +static void +progress ( void *self, const char *what, int type, int current, int total) +{ + fprintf (stderr, "progress `%s' %d %d %d\n", what, type, current, total); +} + + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData pub; + char *result; + const char *format; + char *parms; + int count = 0; + int len, i; + + do { + err = gpgme_data_new (&pub); + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + gpgme_set_armor (ctx, 1); + gpgme_set_progress_cb (ctx, progress, NULL); + + format = "<GnupgKeyParms format=\"internal\">\n" + "Key-Type: RSA\n" + "Key-Length: 1024\n" + "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe %d Tester\n" + "Name-Email: [email protected]\n" + "</GnupgKeyParms>\n"; + parms = malloc ( strlen (format) + 1 + 20 ); + if (!parms) + exit (8); + sprintf (parms, format, ++count ); + err = gpgme_op_genkey (ctx, parms, pub, NULL ); + fail_if_err (err); + free (parms); + + gpgme_release (ctx); + result = gpgme_data_release_and_get_mem (pub, &len); + for (i = 0; i < len; i++) + printf ("%c", result[i]); + free (result); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-import.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-import.c new file mode 100644 index 00000000..974cdd93 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-import.c @@ -0,0 +1,111 @@ +/* t-import.c - regression test + * Copyright (C) 2000 Werner Koch + * Copyright (C) 2001 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <errno.h> + +#include <gpgme.h> + + +#define fail_if_err(a) do { if(a) { int my_errno = errno; \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + if ((a) == GPGME_File_Error) \ + fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \ + exit (1); } \ + } while(0) + +static char * +make_filename (const char *fname) +{ + const char *srcdir = getenv ("srcdir"); + char *buf; + + if (!srcdir) + srcdir = "."; + buf = malloc (strlen(srcdir) + strlen(fname) + 2 ); + if (!buf) + { + fprintf (stderr, "%s:%d: could not allocate string: %s\n", + __FILE__, __LINE__, strerror (errno)); + exit (1); + } + strcpy (buf, srcdir); + strcat (buf, "/"); + strcat (buf, fname); + return buf; +} + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts ("<!-- no operation info available -->"); + else { + puts (s); + free (s); + } +} + + +int +main (int argc, char **argv) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in; + const char *cert_1 = make_filename ("cert_dfn_pca01.der"); + const char *cert_2 = make_filename ("cert_dfn_pca15.der"); + + do + { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + err = gpgme_data_new_from_file (&in, cert_1, 1); + fail_if_err (err); + + err = gpgme_op_import (ctx, in); + print_op_info (ctx); + fail_if_err (err); + + gpgme_data_release (in); + + err = gpgme_data_new_from_file (&in, cert_2, 1); + fail_if_err (err); + + err = gpgme_op_import (ctx, in); + print_op_info (ctx); + fail_if_err (err); + + gpgme_data_release (in); + gpgme_release (ctx); + } + while (argc > 1 && !strcmp (argv[1], "--loop")); + + return 0; +} diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-keylist.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-keylist.c new file mode 100644 index 00000000..2307ad67 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-keylist.c @@ -0,0 +1,184 @@ +/* t-keylist.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <gpgme.h> + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +doit ( GpgmeCtx ctx, const char *pattern, int secret ) +{ + GpgmeError err; + GpgmeKey key; + + err = gpgme_op_keylist_start (ctx, pattern, secret ); + fail_if_err (err); + + while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) { + char *p; + const char *s; + int i; + + printf ("<!-- Begin key object (%p) -->\n", key ); + p = gpgme_key_get_as_xml ( key ); + if ( p ) { + fputs ( p, stdout ); + free (p); + } + else + fputs("<!-- Ooops: gpgme_key_get_as_xml failed -->\n", stdout ); + + + for (i=0; ; i++ ) { + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, i ); + if (!s) + break; + printf ("<!-- keyid.%d=%s -->\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, i ); + printf ("<!-- algo.%d=%s -->\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEY_CAPS, NULL, i ); + printf ("<!-- caps.%d=%s -->\n", i, s ); + } + for (i=0; ; i++ ) { + s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i ); + if (!s) + break; + printf ("<!-- name.%d=%s -->\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, i ); + printf ("<!-- email.%d=%s -->\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_COMMENT, NULL, i ); + printf ("<!-- comment.%d=%s -->\n", i, s ); + } + + fputs ("<!-- usable for:", stdout ); + if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_ENCRYPT, NULL, 0 )) + fputs (" encryption", stdout); + if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_SIGN, NULL, 0 )) + fputs (" signing", stdout); + if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_CERTIFY, NULL, 0 )) + fputs (" certification", stdout); + fputs (" -->\n", stdout ); + + printf ("<!-- End key object (%p) -->\n", key ); + gpgme_key_release (key); + } + if ( err != GPGME_EOF ) + fail_if_err (err); + + { + char *p; + + p = gpgme_get_op_info (ctx, 0); + if (p) + { + fputs ("<!-- begin operation info -->\n", stdout); + fputs (p, stdout); + fputs ("<!-- end operation info -->\n", stdout); + free (p); + } + } +} + + +/* + * Check that there are no problems when we are using two context for + * listing keys. + */ +static void +check_two_contexts (void) +{ + GpgmeError err; + GpgmeCtx ctx1, ctx2; + GpgmeKey key; + + err = gpgme_new(&ctx1); + fail_if_err (err); + gpgme_set_protocol (ctx1, GPGME_PROTOCOL_CMS); + + err = gpgme_op_keylist_start(ctx1, "", 1); + fail_if_err (err); + err = gpgme_new(&ctx2); fail_if_err (err); + gpgme_set_protocol (ctx2, GPGME_PROTOCOL_CMS); + err = gpgme_op_keylist_start(ctx2, "", 1); + fail_if_err (err); + + while ( (err=gpgme_op_keylist_next(ctx2, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); + while ( (err=gpgme_op_keylist_next(ctx1, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + int loop = 0; + int secret = 0; + const char *pattern; + + if( argc ) { + argc--; argv++; + } + + if (argc && !strcmp( *argv, "--loop" ) ) { + loop = 1; + argc--; argv++; + } + if (argc && !strcmp( *argv, "--secret" ) ) { + secret = 1; + argc--; argv++; + } + pattern = argc? *argv : NULL; + + err = gpgme_engine_check_version (GPGME_PROTOCOL_CMS); + fail_if_err (err); + + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */ + do { + fprintf (stderr, "** pattern=`%s'\n", pattern ); + doit ( ctx, pattern, secret ); + } while ( loop ); + gpgme_release (ctx); + + check_two_contexts (); + + return 0; +} diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-sign.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-sign.c new file mode 100644 index 00000000..5d544755 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-sign.c @@ -0,0 +1,118 @@ +/* t-sign.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <gpgme.h> + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts ("<!-- no operation info available -->"); + else { + puts (s); + free (s); + } +} + +static void +print_data ( GpgmeData dh ) +{ + char buf[100]; + size_t nread; + GpgmeError err; + + err = gpgme_data_rewind ( dh ); + fail_if_err (err); + while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { + fwrite ( buf, nread, 1, stdout ); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + + do { + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + gpgme_set_textmode (ctx, 1); + gpgme_set_armor (ctx, 1); + + err = gpgme_data_new_from_mem ( &in, "Hallo Leute!\n", 13, 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); + fflush (NULL); + fputs ("Begin Result:\n", stdout ); + print_op_info (ctx); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); + + /* now a detached signature */ + err = gpgme_data_new ( &out ); + fail_if_err (err); + err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH ); + fail_if_err (err); + fflush (NULL); + print_op_info (ctx); + fputs ("Begin Result:\n", stdout ); + print_data (out); + fputs ("End Result.\n", stdout ); + gpgme_data_release (out); + gpgme_data_rewind (in); + + + /* ready */ + gpgme_data_release (in); + gpgme_release (ctx); + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); + + return 0; +} + + + + diff --git a/branches/gpgme-0-3-branch/tests/gpgsm/t-verify.c b/branches/gpgme-0-3-branch/tests/gpgsm/t-verify.c new file mode 100644 index 00000000..f65a83b6 --- /dev/null +++ b/branches/gpgme-0-3-branch/tests/gpgsm/t-verify.c @@ -0,0 +1,222 @@ +/* t-verify.c - regression test + * Copyright (C) 2000 Werner Koch (dd9jn) + * Copyright (C) 2001, 2002 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <gpgme.h> + +static const char test_text1[] = "Hallo Leute!\n"; +static const char test_text1f[]= "Hallo Leute?\n"; +static const char test_sig1[] = +"-----BEGIN CMS OBJECT-----\n" +"MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAA\n" +"MYIBOTCCATUCAQEwcDBrMQswCQYDVQQGEwJERTETMBEGA1UEBxQKRPxzc2VsZG9y\n" +"ZjEWMBQGA1UEChMNZzEwIENvZGUgR21iSDEZMBcGA1UECxMQQWVneXB0ZW4gUHJv\n" +"amVjdDEUMBIGA1UEAxMLdGVzdCBjZXJ0IDECAQAwBwYFKw4DAhqgJTAjBgkqhkiG\n" +"9w0BCQQxFgQU7FC/ibH3lC9GE24RJJxa8zqP7wEwCwYJKoZIhvcNAQEBBIGAA3oC\n" +"DUmKERmD1eoJYFw38y/qnncS/6ZPjWINDIphZeK8mzAANpvpIaRPf3sNBznb89QF\n" +"mRgCXIWcjlHT0DTRLBf192Ve22IyKH00L52CqFsSN3a2sajqRUlXH8RY2D+Al71e\n" +"MYdRclgjObCcoilA8fZ13VR4DiMJVFCxJL4qVWI=\n" +"-----END CMS OBJECT-----\n"; + +#define fail_if_err(a) do { if(a) { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror(a)); \ + exit (1); } \ + } while(0) + + +static const char * +status_string (GpgmeSigStat status) +{ + const char *s = "?"; + + switch ( status ) { + case GPGME_SIG_STAT_NONE: + s = "None"; + break; + case GPGME_SIG_STAT_NOSIG: + s = "No Signature"; + break; + case GPGME_SIG_STAT_GOOD: + s = "Good"; + break; + case GPGME_SIG_STAT_GOOD_EXP: + s = "Good but expired"; + break; + case GPGME_SIG_STAT_GOOD_EXPKEY: + s = "Good but key exipired"; + break; + case GPGME_SIG_STAT_BAD: + s = "Bad"; + break; + case GPGME_SIG_STAT_NOKEY: + s = "No Key"; + break; + case GPGME_SIG_STAT_ERROR: + s = "Error"; + break; + case GPGME_SIG_STAT_DIFF: + s = "More than one signature"; + break; + } + return s; +} + +static const char * +validity_string (GpgmeValidity val) +{ + const char *s = "?"; + + switch (val) + { + case GPGME_VALIDITY_UNKNOWN: s = "unknown"; break; + case GPGME_VALIDITY_NEVER: s = "not trusted"; break; + case GPGME_VALIDITY_MARGINAL:s = "marginal trusted"; break; + case GPGME_VALIDITY_FULL: s = "fully trusted"; break; + case GPGME_VALIDITY_UNDEFINED: + case GPGME_VALIDITY_ULTIMATE: + break; + } + return s; +} + + +static void +print_sig_stat ( GpgmeCtx ctx, GpgmeSigStat status ) +{ + const char *s; + time_t created; + int idx; + GpgmeKey key; + + printf ("Verification Status: %s\n", status_string (status)); + + for (idx=0; (s=gpgme_get_sig_status (ctx, idx, &status, &created)); idx++ ) + { + unsigned long sum; + + printf ("sig %d: created: %lu expires: %lu status: %s\n", + idx, (unsigned long)created, + gpgme_get_sig_ulong_attr (ctx, idx, GPGME_ATTR_EXPIRE, 0), + status_string(status) ); + printf ("sig %d: fpr/keyid: `%s' exterr: `%s' validity: %s\n", + idx, s, + gpgme_get_sig_string_attr (ctx, idx, GPGME_ATTR_ERRTOK, 0), + validity_string (gpgme_get_sig_ulong_attr + (ctx, idx, GPGME_ATTR_VALIDITY, 0)) ); + + sum = gpgme_get_sig_ulong_attr (ctx, idx, GPGME_ATTR_SIG_SUMMARY, 0); + fputs ("summary:", stdout); + if ((sum & GPGME_SIGSUM_VALID)) + fputs (" valid", stdout); + if ((sum & GPGME_SIGSUM_GREEN)) + fputs (" green", stdout); + if ((sum & GPGME_SIGSUM_RED)) + fputs (" red", stdout); + if ((sum & GPGME_SIGSUM_KEY_REVOKED)) + fputs (" keyRevoked", stdout); + if ((sum & GPGME_SIGSUM_KEY_EXPIRED)) + fputs (" keyExpired", stdout); + if ((sum & GPGME_SIGSUM_SIG_EXPIRED)) + fputs (" sigExpired", stdout); + if ((sum & GPGME_SIGSUM_KEY_MISSING)) + fputs (" keyMissing", stdout); + if ((sum & GPGME_SIGSUM_CRL_MISSING)) + fputs (" crlMissing", stdout); + if ((sum & GPGME_SIGSUM_CRL_TOO_OLD)) + fputs (" crlTooOld", stdout); + if ((sum & GPGME_SIGSUM_BAD_POLICY)) + fputs (" badPolicy", stdout); + if ((sum & GPGME_SIGSUM_SYS_ERROR)) + fputs (" sysError", stdout); + putchar ('\n'); + + if ( !gpgme_get_sig_key (ctx, idx, &key) ) + { + char *p = gpgme_key_get_as_xml ( key ); + printf ("sig %d: key object:\n%s\n", idx, p ); + free (p); + gpgme_key_release (key); + } + } +} + +int +main (int argc, char **argv ) +{ + GpgmeCtx ctx; + GpgmeError err; + GpgmeData sig, text; + GpgmeSigStat status; + char *nota; + int n = 0; + + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + + do { + 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); + + puts ("checking a valid message:\n"); + err = gpgme_op_verify (ctx, sig, text, &status ); + print_sig_stat ( ctx, status ); + print_sig_stat ( ctx, status ); + print_sig_stat ( ctx, status ); + print_sig_stat ( ctx, status ); + fail_if_err (err); + + if ( (nota=gpgme_get_notation (ctx)) ) + printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + + puts ("checking a manipulated message:\n"); + gpgme_data_release (text); + err = gpgme_data_new_from_mem ( &text, + test_text1f, strlen (test_text1f), 0 ); + fail_if_err (err); + gpgme_data_rewind ( sig ); + err = gpgme_op_verify (ctx, sig, text, &status ); + + print_sig_stat ( ctx, status ); + fail_if_err (err); + if ( (nota=gpgme_get_notation (ctx)) ) + printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + + gpgme_data_release (sig); + gpgme_data_release (text); + +} while ( argc > 1 && !strcmp( argv[1], "--loop" ) && ++n < 20 ); + gpgme_release (ctx); + + return 0; +} + + + |