1 /* t-verify.c - Regression test.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* We need to include config.h so that we know whether we are building
23 with large file system (LFS) support. */
34 #include "t-support.h"
37 static int got_errors;
39 static const char test_text1[] = "Hallo Leute!\n";
40 static const char test_text1f[]= "Hallo Leute?\n";
41 static const char test_sig1[] =
42 "-----BEGIN CMS OBJECT-----\n"
43 "MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAA\n"
44 "MYIBOTCCATUCAQEwcDBrMQswCQYDVQQGEwJERTETMBEGA1UEBxQKRPxzc2VsZG9y\n"
45 "ZjEWMBQGA1UEChMNZzEwIENvZGUgR21iSDEZMBcGA1UECxMQQWVneXB0ZW4gUHJv\n"
46 "amVjdDEUMBIGA1UEAxMLdGVzdCBjZXJ0IDECAQAwBwYFKw4DAhqgJTAjBgkqhkiG\n"
47 "9w0BCQQxFgQU7FC/ibH3lC9GE24RJJxa8zqP7wEwCwYJKoZIhvcNAQEBBIGAA3oC\n"
48 "DUmKERmD1eoJYFw38y/qnncS/6ZPjWINDIphZeK8mzAANpvpIaRPf3sNBznb89QF\n"
49 "mRgCXIWcjlHT0DTRLBf192Ve22IyKH00L52CqFsSN3a2sajqRUlXH8RY2D+Al71e\n"
50 "MYdRclgjObCcoilA8fZ13VR4DiMJVFCxJL4qVWI=\n"
51 "-----END CMS OBJECT-----\n";
55 check_result (gpgme_verify_result_t result, int summary, char *fpr,
56 gpgme_error_t status, gpgme_validity_t validity)
58 gpgme_signature_t sig;
60 sig = result->signatures;
61 if (!sig || sig->next)
63 fprintf (stderr, "%s:%i: Unexpected number of signatures\n",
67 if (sig->summary != summary)
69 fprintf (stderr, "%s:%i: Unexpected signature summary: "
70 "want=0x%x have=0x%x\n",
71 __FILE__, __LINE__, summary, sig->summary);
74 if (strcmp (sig->fpr, fpr))
76 fprintf (stderr, "%s:%i: Unexpected fingerprint: %s\n",
77 __FILE__, __LINE__, sig->fpr);
80 if (gpgme_err_code (sig->status) != status)
82 fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
83 __FILE__, __LINE__, gpgme_strerror (sig->status));
88 fprintf (stderr, "%s:%i: Unexpected notation data\n",
92 if (sig->wrong_key_usage)
94 fprintf (stderr, "%s:%i: Unexpectedly wrong key usage\n",
98 if (sig->validity != validity)
100 fprintf (stderr, "%s:%i: Unexpected validity: %i\n",
101 __FILE__, __LINE__, sig->validity);
104 if (gpgme_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR)
106 fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n",
107 __FILE__, __LINE__, gpgme_strerror (sig->validity_reason));
114 show_auditlog (gpgme_ctx_t ctx)
119 err = gpgme_data_new (&data);
121 err = gpgme_op_getauditlog (ctx, data, GPGME_AUDITLOG_HTML);
124 fprintf (stderr, "%s:%i: Can't get audit log: %s\n",
125 __FILE__, __LINE__, gpgme_strerror (err));
126 if (gpgme_err_code (err) != GPG_ERR_ASS_UNKNOWN_CMD)
130 gpgme_data_release (data);
136 main (int argc, char **argv)
140 gpgme_data_t sig, text;
141 gpgme_verify_result_t result;
143 init_gpgme (GPGME_PROTOCOL_CMS);
145 err = gpgme_new (&ctx);
147 gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
149 /* Checking a valid message. */
150 err = gpgme_data_new_from_mem (&text, test_text1, strlen (test_text1), 0);
152 err = gpgme_data_new_from_mem (&sig, test_sig1, strlen (test_sig1), 0);
155 err = gpgme_op_verify (ctx, sig, text, NULL);
157 result = gpgme_op_verify_result (ctx);
158 check_result (result, GPGME_SIGSUM_VALID | GPGME_SIGSUM_GREEN,
159 "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E",
160 GPG_ERR_NO_ERROR, GPGME_VALIDITY_FULL);
164 /* Checking a manipulated message. */
165 gpgme_data_release (text);
166 err = gpgme_data_new_from_mem (&text, test_text1f, strlen (test_text1f), 0);
168 gpgme_data_seek (sig, 0, SEEK_SET);
169 err = gpgme_op_verify (ctx, sig, text, NULL);
171 result = gpgme_op_verify_result (ctx);
172 check_result (result, GPGME_SIGSUM_RED,
173 "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E",
174 GPG_ERR_BAD_SIGNATURE, GPGME_VALIDITY_UNKNOWN);
178 gpgme_data_release (text);
179 gpgme_data_release (sig);
181 return got_errors? 1 : 0;