2006-04-06 [mones] 2.1.0cvs7
[claws.git] / src / plugins / pgpmime / pgpmime.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto & the Sylpheed-Claws team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #ifdef USE_GPGME
25
26 #include "defs.h"
27 #include <glib.h>
28 #include <gpgme.h>
29 #include <ctype.h>
30
31 #include "utils.h"
32 #include "privacy.h"
33 #include "procmime.h"
34
35 #include "pgpmime.h"
36 #include <plugins/pgpcore/sgpgme.h>
37 #include <plugins/pgpcore/prefs_gpg.h>
38 #include <plugins/pgpcore/passphrase.h>
39
40 #include "prefs_common.h"
41
42 typedef struct _PrivacyDataPGP PrivacyDataPGP;
43
44 struct _PrivacyDataPGP
45 {
46         PrivacyData     data;
47         
48         gboolean        done_sigtest;
49         gboolean        is_signed;
50         gpgme_verify_result_t   sigstatus;
51         gpgme_ctx_t     ctx;
52 };
53
54 static PrivacySystem pgpmime_system;
55
56 static gint pgpmime_check_signature(MimeInfo *mimeinfo);
57
58 static PrivacyDataPGP *pgpmime_new_privacydata()
59 {
60         PrivacyDataPGP *data;
61
62         data = g_new0(PrivacyDataPGP, 1);
63         data->data.system = &pgpmime_system;
64         data->done_sigtest = FALSE;
65         data->is_signed = FALSE;
66         data->sigstatus = NULL;
67         gpgme_new(&data->ctx);
68         
69         return data;
70 }
71
72 static void pgpmime_free_privacydata(PrivacyData *_data)
73 {
74         PrivacyDataPGP *data = (PrivacyDataPGP *) _data;
75         gpgme_release(data->ctx);
76         g_free(data);
77 }
78
79 static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
80 {
81         MimeInfo *parent;
82         MimeInfo *signature;
83         const gchar *protocol;
84         PrivacyDataPGP *data = NULL;
85         
86         g_return_val_if_fail(mimeinfo != NULL, FALSE);
87         if (mimeinfo->privacy != NULL) {
88                 data = (PrivacyDataPGP *) mimeinfo->privacy;
89                 if (data->done_sigtest)
90                         return data->is_signed;
91         }
92         
93         /* check parent */
94         parent = procmime_mimeinfo_parent(mimeinfo);
95         if (parent == NULL)
96                 return FALSE;
97         if ((parent->type != MIMETYPE_MULTIPART) ||
98             g_ascii_strcasecmp(parent->subtype, "signed"))
99                 return FALSE;
100         protocol = procmime_mimeinfo_get_parameter(parent, "protocol");
101         if ((protocol == NULL) || 
102             (g_ascii_strcasecmp(protocol, "application/pgp-signature")))
103                 return FALSE;
104
105         /* check if mimeinfo is the first child */
106         if (parent->node->children->data != mimeinfo)
107                 return FALSE;
108
109         /* check signature */
110         signature = parent->node->children->next != NULL ? 
111             (MimeInfo *) parent->node->children->next->data : NULL;
112         if (signature == NULL)
113                 return FALSE;
114         if ((signature->type != MIMETYPE_APPLICATION) ||
115             (g_ascii_strcasecmp(signature->subtype, "pgp-signature")))
116                 return FALSE;
117
118         if (data == NULL) {
119                 data = pgpmime_new_privacydata();
120                 mimeinfo->privacy = (PrivacyData *) data;
121         }
122         
123         data->done_sigtest = TRUE;
124         data->is_signed = TRUE;
125
126         return TRUE;
127 }
128
129 static gchar *get_canonical_content(FILE *fp, const gchar *boundary)
130 {
131         gchar *ret;
132         GString *textbuffer;
133         guint boundary_len;
134         gchar buf[BUFFSIZE];
135
136         boundary_len = strlen(boundary);
137         while (fgets(buf, sizeof(buf), fp) != NULL)
138                 if (IS_BOUNDARY(buf, boundary, boundary_len))
139                         break;
140
141         textbuffer = g_string_new("");
142         while (fgets(buf, sizeof(buf), fp) != NULL) {
143                 gchar *buf2;
144
145                 if (IS_BOUNDARY(buf, boundary, boundary_len))
146                         break;
147                 
148                 buf2 = canonicalize_str(buf);
149                 g_string_append(textbuffer, buf2);
150                 g_free(buf2);
151         }
152         g_string_truncate(textbuffer, textbuffer->len - 2);
153                 
154         ret = textbuffer->str;
155         g_string_free(textbuffer, FALSE);
156
157         return ret;
158 }
159
160 static gint pgpmime_check_signature(MimeInfo *mimeinfo)
161 {
162         PrivacyDataPGP *data;
163         MimeInfo *parent, *signature;
164         FILE *fp;
165         gchar *boundary;
166         gchar *textstr;
167         gpgme_data_t sigdata = NULL, textdata = NULL;
168         gpgme_error_t err;
169         g_return_val_if_fail(mimeinfo != NULL, -1);
170         g_return_val_if_fail(mimeinfo->privacy != NULL, -1);
171         data = (PrivacyDataPGP *) mimeinfo->privacy;
172         gpgme_new(&data->ctx);
173         
174         debug_print("Checking PGP/MIME signature\n");
175
176         err = gpgme_set_protocol(data->ctx, GPGME_PROTOCOL_OpenPGP);
177
178         if (err) {
179                 debug_print ("gpgme_set_protocol failed: %s\n",
180                    gpgme_strerror (err));
181         }
182         parent = procmime_mimeinfo_parent(mimeinfo);
183
184         fp = g_fopen(parent->data.filename, "rb");
185         g_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
186         
187         boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
188         if (!boundary)
189                 return 0;
190
191         textstr = get_canonical_content(fp, boundary);
192
193         err = gpgme_data_new_from_mem(&textdata, textstr, strlen(textstr), 0);
194         if (err) {
195                 debug_print ("gpgme_data_new_from_mem failed: %s\n",
196                    gpgme_strerror (err));
197         }
198         signature = (MimeInfo *) mimeinfo->node->next->data;
199         sigdata = sgpgme_data_from_mimeinfo(signature);
200
201         err = 0;
202         if (signature->encoding_type == ENC_BASE64) {
203                 err = gpgme_data_set_encoding (sigdata, GPGME_DATA_ENCODING_BASE64);
204         }
205         
206         if (err) {
207                 debug_print ("gpgme_data_set_encoding failed: %s\n",
208                         gpgme_strerror (err));
209         }
210
211         data->sigstatus =
212                 sgpgme_verify_signature (data->ctx, sigdata, textdata, NULL);
213
214         gpgme_data_release(sigdata);
215         gpgme_data_release(textdata);
216         g_free(textstr);
217         fclose(fp);
218         
219         return 0;
220 }
221
222 static SignatureStatus pgpmime_get_sig_status(MimeInfo *mimeinfo)
223 {
224         PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
225         
226         g_return_val_if_fail(data != NULL, SIGNATURE_INVALID);
227
228         if (data->sigstatus == NULL && 
229             prefs_gpg_get_config()->auto_check_signatures)
230                 pgpmime_check_signature(mimeinfo);
231         
232         return sgpgme_sigstat_gpgme_to_privacy(data->ctx, data->sigstatus);
233 }
234
235 static gchar *pgpmime_get_sig_info_short(MimeInfo *mimeinfo)
236 {
237         PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
238         
239         g_return_val_if_fail(data != NULL, g_strdup("Error"));
240
241         if (data->sigstatus == NULL && 
242             prefs_gpg_get_config()->auto_check_signatures)
243                 pgpmime_check_signature(mimeinfo);
244         
245         return sgpgme_sigstat_info_short(data->ctx, data->sigstatus);
246 }
247
248 static gchar *pgpmime_get_sig_info_full(MimeInfo *mimeinfo)
249 {
250         PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
251         
252         g_return_val_if_fail(data != NULL, g_strdup("Error"));
253
254         if (data->sigstatus == NULL && 
255             prefs_gpg_get_config()->auto_check_signatures)
256                 pgpmime_check_signature(mimeinfo);
257         
258         return sgpgme_sigstat_info_full(data->ctx, data->sigstatus);
259 }
260
261 static gboolean pgpmime_is_encrypted(MimeInfo *mimeinfo)
262 {
263         MimeInfo *tmpinfo;
264         const gchar *tmpstr;
265         
266         if (mimeinfo->type != MIMETYPE_MULTIPART)
267                 return FALSE;
268         if (g_ascii_strcasecmp(mimeinfo->subtype, "encrypted"))
269                 return FALSE;
270         tmpstr = procmime_mimeinfo_get_parameter(mimeinfo, "protocol");
271         if ((tmpstr == NULL) || g_ascii_strcasecmp(tmpstr, "application/pgp-encrypted"))
272                 return FALSE;
273         if (g_node_n_children(mimeinfo->node) != 2)
274                 return FALSE;
275         
276         tmpinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 0)->data;
277         if (tmpinfo->type != MIMETYPE_APPLICATION)
278                 return FALSE;
279         if (g_ascii_strcasecmp(tmpinfo->subtype, "pgp-encrypted"))
280                 return FALSE;
281         
282         tmpinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 1)->data;
283         if (tmpinfo->type != MIMETYPE_APPLICATION)
284                 return FALSE;
285         if (g_ascii_strcasecmp(tmpinfo->subtype, "octet-stream"))
286                 return FALSE;
287         
288         return TRUE;
289 }
290
291 static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
292 {
293         MimeInfo *encinfo, *decinfo, *parseinfo;
294         gpgme_data_t cipher = NULL, plain = NULL;
295         static gint id = 0;
296         FILE *dstfp;
297         gchar *fname;
298         gpgme_verify_result_t sigstat = NULL;
299         PrivacyDataPGP *data = NULL;
300         gpgme_ctx_t ctx;
301         gchar *chars;
302         size_t len;
303
304         if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR)
305                 return NULL;
306
307         
308         g_return_val_if_fail(pgpmime_is_encrypted(mimeinfo), NULL);
309         
310         encinfo = (MimeInfo *) g_node_nth_child(mimeinfo->node, 1)->data;
311
312         cipher = sgpgme_data_from_mimeinfo(encinfo);
313         plain = sgpgme_decrypt_verify(cipher, &sigstat, ctx);
314
315         gpgme_data_release(cipher);
316         if (plain == NULL) {
317                 debug_print("plain is null!\n");
318                 gpgme_release(ctx);
319                 return NULL;
320         }
321
322         fname = g_strdup_printf("%s%cplaintext.%08x",
323                 get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
324
325         if ((dstfp = g_fopen(fname, "wb")) == NULL) {
326                 FILE_OP_ERROR(fname, "fopen");
327                 g_free(fname);
328                 gpgme_data_release(plain);
329                 gpgme_release(ctx);
330                 debug_print("can't open!\n");
331                 return NULL;
332         }
333
334         fprintf(dstfp, "MIME-Version: 1.0\n");
335
336         chars = gpgme_data_release_and_get_mem(plain, &len);
337         if (len > 0)
338                 fwrite(chars, len, 1, dstfp);
339         fclose(dstfp);
340
341         parseinfo = procmime_scan_file(fname);
342         g_free(fname);
343         if (parseinfo == NULL) {
344                 gpgme_release(ctx);
345                 return NULL;
346         }
347         decinfo = g_node_first_child(parseinfo->node) != NULL ?
348                 g_node_first_child(parseinfo->node)->data : NULL;
349         if (decinfo == NULL) {
350                 gpgme_release(ctx);
351                 return NULL;
352         }
353
354         g_node_unlink(decinfo->node);
355         procmime_mimeinfo_free_all(parseinfo);
356
357         decinfo->tmp = TRUE;
358
359         if (sigstat != NULL && sigstat->signatures != NULL) {
360                 if (decinfo->privacy != NULL) {
361                         data = (PrivacyDataPGP *) decinfo->privacy;
362                 } else {
363                         data = pgpmime_new_privacydata();
364                         decinfo->privacy = (PrivacyData *) data;        
365                 }
366                 data->done_sigtest = TRUE;
367                 data->is_signed = TRUE;
368                 data->sigstatus = sigstat;
369                 if (data->ctx)
370                         gpgme_release(data->ctx);
371                 data->ctx = ctx;
372         } else
373                 gpgme_release(ctx);
374
375         return decinfo;
376 }
377
378 gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
379 {
380         MimeInfo *msgcontent, *sigmultipart, *newinfo;
381         gchar *textstr, *micalg;
382         FILE *fp;
383         gchar *boundary = NULL;
384         gchar *sigcontent;
385         gpgme_ctx_t ctx;
386         gpgme_data_t gpgtext, gpgsig;
387         gpgme_error_t err;
388         size_t len;
389         struct passphrase_cb_info_s info;
390         gpgme_sign_result_t result = NULL;
391         gchar *test_msg;
392         
393         fp = my_tmpfile();
394         if (fp == NULL) {
395                 perror("my_tmpfile");
396                 return FALSE;
397         }
398         procmime_write_mimeinfo(mimeinfo, fp);
399         rewind(fp);
400
401         /* read temporary file into memory */
402         test_msg = file_read_stream_to_str(fp);
403         fclose(fp);
404         
405         memset (&info, 0, sizeof info);
406
407         /* remove content node from message */
408         msgcontent = (MimeInfo *) mimeinfo->node->children->data;
409         g_node_unlink(msgcontent->node);
410
411         /* create temporary multipart for content */
412         sigmultipart = procmime_mimeinfo_new();
413         sigmultipart->type = MIMETYPE_MULTIPART;
414         sigmultipart->subtype = g_strdup("signed");
415         
416         do {
417                 g_free(boundary);
418                 boundary = generate_mime_boundary("Sig");
419         } while (strstr(test_msg, boundary) != NULL);
420         
421         g_free(test_msg);
422
423         g_hash_table_insert(sigmultipart->typeparameters, g_strdup("boundary"),
424                             g_strdup(boundary));
425         g_hash_table_insert(sigmultipart->typeparameters, g_strdup("protocol"),
426                             g_strdup("application/pgp-signature"));
427         g_node_append(sigmultipart->node, msgcontent->node);
428         g_node_append(mimeinfo->node, sigmultipart->node);
429
430         /* write message content to temporary file */
431         fp = my_tmpfile();
432         if (fp == NULL) {
433                 perror("my_tmpfile");
434                 return FALSE;
435         }
436         procmime_write_mimeinfo(sigmultipart, fp);
437         rewind(fp);
438
439         /* read temporary file into memory */
440         textstr = get_canonical_content(fp, boundary);
441
442         fclose(fp);
443
444         gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
445         gpgme_data_new(&gpgsig);
446         gpgme_new(&ctx);
447         gpgme_set_textmode(ctx, 1);
448         gpgme_set_armor(ctx, 1);
449         gpgme_signers_clear (ctx);
450
451         if (!sgpgme_setup_signers(ctx, account)) {
452                 gpgme_release(ctx);
453                 return FALSE;
454         }
455
456         if (getenv("GPG_AGENT_INFO")) {
457                 debug_print("GPG_AGENT_INFO environment defined, running without passphrase callback\n");
458         } else {
459                 info.c = ctx;
460                 gpgme_set_passphrase_cb (ctx, gpgmegtk_passphrase_cb, &info);
461         }
462
463         err = gpgme_op_sign(ctx, gpgtext, gpgsig, GPGME_SIG_MODE_DETACH);
464         if (err != GPG_ERR_NO_ERROR) {
465                 debug_print("gpgme_op_sign error : %x\n", err);
466                 gpgme_release(ctx);
467                 return FALSE;
468         }
469         result = gpgme_op_sign_result(ctx);
470         if (result && result->signatures) {
471             if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP) {
472                 micalg = g_strdup_printf("PGP-%s", gpgme_hash_algo_name(
473                             result->signatures->hash_algo));
474             } else {
475                 micalg = g_strdup(gpgme_hash_algo_name(
476                             result->signatures->hash_algo));
477             }
478         } else {
479             /* can't get result (maybe no signing key?) */
480             debug_print("gpgme_op_sign_result error\n");
481             return FALSE;
482         }
483
484         gpgme_release(ctx);
485         sigcontent = gpgme_data_release_and_get_mem(gpgsig, &len);
486         gpgme_data_release(gpgtext);
487         g_free(textstr);
488
489         /* add signature */
490         g_hash_table_insert(sigmultipart->typeparameters, g_strdup("micalg"),
491                             micalg);
492
493         newinfo = procmime_mimeinfo_new();
494         newinfo->type = MIMETYPE_APPLICATION;
495         newinfo->subtype = g_strdup("pgp-signature");
496         g_hash_table_insert(newinfo->typeparameters, g_strdup("name"),
497                              g_strdup("signature.asc"));
498         newinfo->content = MIMECONTENT_MEM;
499         newinfo->disposition = DISPOSITIONTYPE_ATTACHMENT;
500         g_hash_table_insert(newinfo->dispositionparameters, g_strdup("filename"),
501                             g_strdup("signature.asc"));
502         newinfo->data.mem = g_malloc(len + 1);
503         g_memmove(newinfo->data.mem, sigcontent, len);
504         newinfo->data.mem[len] = '\0';
505         g_node_append(sigmultipart->node, newinfo->node);
506
507         g_free(sigcontent);
508
509         return TRUE;
510 }
511 gchar *pgpmime_get_encrypt_data(GSList *recp_names)
512 {
513         return sgpgme_get_encrypt_data(recp_names, GPGME_PROTOCOL_OpenPGP);
514 }
515
516 gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
517 {
518         MimeInfo *msgcontent, *encmultipart, *newinfo;
519         FILE *fp;
520         gchar *boundary, *enccontent;
521         size_t len;
522         gchar *textstr;
523         gpgme_data_t gpgtext = NULL, gpgenc = NULL;
524         gpgme_ctx_t ctx = NULL;
525         gpgme_key_t *kset = NULL;
526         gchar **fprs = g_strsplit(encrypt_data, " ", -1);
527         gint i = 0;
528         while (fprs[i] && strlen(fprs[i])) {
529                 i++;
530         }
531         
532         kset = g_malloc(sizeof(gpgme_key_t)*(i+1));
533         memset(kset, 0, sizeof(gpgme_key_t)*(i+1));
534         gpgme_new(&ctx);
535         i = 0;
536         while (fprs[i] && strlen(fprs[i])) {
537                 gpgme_key_t key;
538                 gpgme_error_t err;
539                 err = gpgme_get_key(ctx, fprs[i], &key, 0);
540                 if (err) {
541                         debug_print("can't add key '%s'[%d] (%s)\n", fprs[i],i, gpgme_strerror(err));
542                         break;
543                 }
544                 debug_print("found %s at %d\n", fprs[i], i);
545                 kset[i] = key;
546                 i++;
547         }
548         
549         debug_print("Encrypting message content\n");
550
551         /* remove content node from message */
552         msgcontent = (MimeInfo *) mimeinfo->node->children->data;
553         g_node_unlink(msgcontent->node);
554
555         /* create temporary multipart for content */
556         encmultipart = procmime_mimeinfo_new();
557         encmultipart->type = MIMETYPE_MULTIPART;
558         encmultipart->subtype = g_strdup("encrypted");
559         boundary = generate_mime_boundary("Encrypt");
560         g_hash_table_insert(encmultipart->typeparameters, g_strdup("boundary"),
561                             g_strdup(boundary));
562         g_hash_table_insert(encmultipart->typeparameters, g_strdup("protocol"),
563                             g_strdup("application/pgp-encrypted"));
564         g_node_append(encmultipart->node, msgcontent->node);
565
566         /* write message content to temporary file */
567         fp = my_tmpfile();
568         if (fp == NULL) {
569                 perror("my_tmpfile");
570                 return FALSE;
571         }
572         procmime_write_mimeinfo(encmultipart, fp);
573         rewind(fp);
574
575         /* read temporary file into memory */
576         textstr = get_canonical_content(fp, boundary);
577
578         fclose(fp);
579
580         /* encrypt data */
581         gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
582         gpgme_data_new(&gpgenc);
583         gpgme_set_armor(ctx, 1);
584         gpgme_data_rewind(gpgtext);
585         
586         gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
587
588         gpgme_release(ctx);
589         enccontent = gpgme_data_release_and_get_mem(gpgenc, &len);
590         gpgme_data_release(gpgtext);
591         g_free(textstr);
592
593         /* create encrypted multipart */
594         g_node_unlink(msgcontent->node);
595         procmime_mimeinfo_free_all(msgcontent);
596         g_node_append(mimeinfo->node, encmultipart->node);
597
598         newinfo = procmime_mimeinfo_new();
599         newinfo->type = MIMETYPE_APPLICATION;
600         newinfo->subtype = g_strdup("pgp-encrypted");
601         newinfo->content = MIMECONTENT_MEM;
602         newinfo->data.mem = g_strdup("Version: 1\n");
603         g_node_append(encmultipart->node, newinfo->node);
604
605         newinfo = procmime_mimeinfo_new();
606         newinfo->type = MIMETYPE_APPLICATION;
607         newinfo->subtype = g_strdup("octet-stream");
608         newinfo->content = MIMECONTENT_MEM;
609         newinfo->data.mem = g_malloc(len + 1);
610         g_memmove(newinfo->data.mem, enccontent, len);
611         newinfo->data.mem[len] = '\0';
612         g_node_append(encmultipart->node, newinfo->node);
613
614         g_free(enccontent);
615
616         return TRUE;
617 }
618
619 static PrivacySystem pgpmime_system = {
620         "pgpmime",                      /* id */
621         "PGP MIME",                     /* name */
622
623         pgpmime_free_privacydata,       /* free_privacydata */
624
625         pgpmime_is_signed,              /* is_signed(MimeInfo *) */
626         pgpmime_check_signature,        /* check_signature(MimeInfo *) */
627         pgpmime_get_sig_status,         /* get_sig_status(MimeInfo *) */
628         pgpmime_get_sig_info_short,     /* get_sig_info_short(MimeInfo *) */
629         pgpmime_get_sig_info_full,      /* get_sig_info_full(MimeInfo *) */
630
631         pgpmime_is_encrypted,           /* is_encrypted(MimeInfo *) */
632         pgpmime_decrypt,                /* decrypt(MimeInfo *) */
633
634         TRUE,
635         pgpmime_sign,
636
637         TRUE,
638         pgpmime_get_encrypt_data,
639         pgpmime_encrypt,
640 };
641
642 void pgpmime_init()
643 {
644         privacy_register_system(&pgpmime_system);
645 }
646
647 void pgpmime_done()
648 {
649         privacy_unregister_system(&pgpmime_system);
650 }
651
652 #endif /* USE_GPGME */