Line data Source code
1 : /* t-thread-verify.c - Regression test.
2 : Copyright (C) 2015 Intevation GmbH
3 :
4 : This file is part of GPGME.
5 :
6 : GPGME is free software; you can redistribute it and/or modify it
7 : under the terms of the GNU Lesser General Public License as
8 : published by the Free Software Foundation; either version 2.1 of
9 : the License, or (at your option) any later version.
10 :
11 : GPGME is distributed in the hope that it will be useful, but
12 : WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : Lesser General Public License for more details.
15 :
16 : You should have received a copy of the GNU Lesser General Public
17 : License along with this program; if not, write to the Free Software
18 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 : 02111-1307, USA. */
20 :
21 : #ifdef HAVE_CONFIG_H
22 : #include <config.h>
23 : #endif
24 :
25 : #include <stdlib.h>
26 : #include <stdio.h>
27 : #include <string.h>
28 :
29 : #include <gpgme.h>
30 :
31 : #include <pthread.h>
32 :
33 : #include "t-support.h"
34 :
35 : #define THREAD_COUNT 10
36 :
37 : static const char test_text1[] = "Just GNU it!\n";
38 : static const char test_sig1[] =
39 : "-----BEGIN PGP SIGNATURE-----\n"
40 : "\n"
41 : "iN0EABECAJ0FAjoS+i9FFIAAAAAAAwA5YmFyw7bDpMO8w58gZGFzIHdhcmVuIFVt\n"
42 : "bGF1dGUgdW5kIGpldHp0IGVpbiBwcm96ZW50JS1aZWljaGVuNRSAAAAAAAgAJGZv\n"
43 : "b2Jhci4xdGhpcyBpcyBhIG5vdGF0aW9uIGRhdGEgd2l0aCAyIGxpbmVzGhpodHRw\n"
44 : "Oi8vd3d3Lmd1Lm9yZy9wb2xpY3kvAAoJEC1yfMdoaXc0JBIAoIiLlUsvpMDOyGEc\n"
45 : "dADGKXF/Hcb+AKCJWPphZCphduxSvrzH0hgzHdeQaA==\n"
46 : "=nts1\n"
47 : "-----END PGP SIGNATURE-----\n";
48 :
49 : void *
50 10 : start_keylist (void *arg)
51 : {
52 : gpgme_error_t err;
53 : gpgme_ctx_t ctx;
54 : gpgme_key_t key;
55 :
56 : (void)arg;
57 10 : err = gpgme_new (&ctx);
58 10 : fail_if_err (err);
59 :
60 10 : err = gpgme_op_keylist_start (ctx, NULL, 0);
61 10 : fail_if_err (err);
62 :
63 290 : while (!(err = gpgme_op_keylist_next (ctx, &key)))
64 : {
65 270 : gpgme_key_unref (key);
66 : }
67 :
68 10 : gpgme_release (ctx);
69 10 : return NULL;
70 : }
71 :
72 : void *
73 10 : start_verify (void *arg)
74 : {
75 : gpgme_ctx_t ctx;
76 : gpgme_error_t err;
77 : gpgme_data_t sig, text;
78 : gpgme_verify_result_t result;
79 : gpgme_signature_t signature;
80 :
81 : (void)arg;
82 :
83 10 : err = gpgme_new (&ctx);
84 10 : fail_if_err (err);
85 :
86 : /* Checking a valid message. */
87 10 : err = gpgme_data_new_from_mem (&text, test_text1, strlen (test_text1), 0);
88 10 : fail_if_err (err);
89 10 : err = gpgme_data_new_from_mem (&sig, test_sig1, strlen (test_sig1), 0);
90 10 : fail_if_err (err);
91 10 : err = gpgme_op_verify (ctx, sig, text, NULL);
92 10 : fail_if_err (err);
93 10 : result = gpgme_op_verify_result (ctx);
94 :
95 10 : signature = result->signatures;
96 :
97 10 : if (strcmp (signature->fpr, "A0FF4590BB6122EDEF6E3C542D727CC768697734"))
98 : {
99 0 : fprintf (stderr, "%s:%i: Unexpected fingerprint: %s\n",
100 : __FILE__, __LINE__, signature->fpr);
101 0 : exit (1);
102 : }
103 10 : if (gpgme_err_code (signature->status) != GPG_ERR_NO_ERROR)
104 : {
105 0 : fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
106 : __FILE__, __LINE__, gpgme_strerror (signature->status));
107 0 : exit (1);
108 : }
109 10 : gpgme_free (text);
110 10 : gpgme_free (sig);
111 10 : gpgme_release (ctx);
112 10 : return NULL;
113 : }
114 :
115 : int
116 1 : main (int argc, char *argv[])
117 : {
118 : int i;
119 : pthread_t verify_threads[THREAD_COUNT];
120 : pthread_t keylist_threads[THREAD_COUNT];
121 1 : init_gpgme (GPGME_PROTOCOL_OpenPGP);
122 :
123 : (void)argc;
124 : (void)argv;
125 :
126 11 : for (i = 0; i < THREAD_COUNT; i++)
127 : {
128 20 : if (pthread_create(&verify_threads[i], NULL, start_verify, NULL) ||
129 10 : pthread_create(&keylist_threads[i], NULL, start_keylist, NULL))
130 : {
131 0 : fprintf(stderr, "%s:%i: failed to create threads \n",
132 : __FILE__, __LINE__);
133 0 : exit(1);
134 : }
135 : }
136 11 : for (i = 0; i < THREAD_COUNT; i++)
137 : {
138 10 : pthread_join (verify_threads[i], NULL);
139 10 : pthread_join (keylist_threads[i], NULL);
140 : }
141 1 : return 0;
142 : }
|