Mercurial > ~mikael > mcabber > hg
annotate mcabber/mcabber/pgp.c @ 2202:ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
This patch fixes another issue reported in #134.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 12 Oct 2015 11:41:34 +0200 |
parents | fec172dbacc7 |
children | 7c843b29571b |
rev | line source |
---|---|
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
1 /* |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
2 * pgp.c -- PGP utility functions |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
3 * |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
4 * Copyright (C) 2006-2015 Mikael Berthe <mikael@lilotux.net> |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
5 * Some parts inspired by centericq (impgp.cc) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
6 * |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or (at |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
10 * your option) any later version. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
11 * |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
15 * General Public License for more details. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
16 * |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
18 * along with this program; if not, write to the Free Software |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
20 * USA |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
21 */ |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
22 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
23 #include <config.h> |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
24 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
25 #ifdef HAVE_GPGME |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
26 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 #include <stdlib.h> |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
28 #include <string.h> |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
29 #include <unistd.h> |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
30 #include <locale.h> |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
31 #include <sys/mman.h> |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
32 #include <glib.h> |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
33 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
34 #include "pgp.h" |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
35 #include "logprint.h" |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
36 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
37 #define MIN_GPGME_VERSION "1.0.0" |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
38 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
39 static struct gpg_struct |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
40 { |
2196
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
41 int enabled; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
42 int version1; |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
43 char *private_key; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
44 char *passphrase; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
45 } gpg; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
46 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
47 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
48 // gpg_init(priv_key, passphrase) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
49 // Initialize the GPG sub-systems. This function must be invoked early. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
50 // Note: priv_key & passphrase are optional, they can be set later. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
51 // This function returns 0 if gpgme is available and initialized; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
52 // if not it returns the gpgme error code. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
53 int gpg_init(const char *priv_key, const char *passphrase) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
54 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
55 gpgme_error_t err; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
56 |
2196
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
57 gpgme_ctx_t ctx; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
58 gpgme_engine_info_t info; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
59 |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
60 // Check for version and OpenPGP protocol support. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
61 if (!gpgme_check_version(MIN_GPGME_VERSION)) { |
1057
4cdf19d9c74e
PGP: Fix a small bug in initialization
Mikael Berthe <mikael@lilotux.net>
parents:
1054
diff
changeset
|
62 scr_LogPrint(LPRINT_LOGNORM, |
4cdf19d9c74e
PGP: Fix a small bug in initialization
Mikael Berthe <mikael@lilotux.net>
parents:
1054
diff
changeset
|
63 "GPGME initialization error: Bad library version"); |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
64 return -1; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
65 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
66 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
67 err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
68 if (err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
69 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
70 "GPGME initialization error: %s", gpgme_strerror(err)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
71 return err; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
72 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
73 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
74 // Set the locale information. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
75 gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
76 gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
77 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
78 // Store private data. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
79 gpg_set_private_key(priv_key); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
80 gpg_set_passphrase(passphrase); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
81 |
2196
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
82 err = gpgme_new(&ctx); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
83 if (err) return -1; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
84 |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
85 // Check OpenPGP engine version; with version 2+ the agent is mandatory |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
86 // and we do not manage the passphrase. |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
87 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
88 if (err) return -1; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
89 |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
90 err = gpgme_get_engine_info (&info); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
91 if (!err) { |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
92 while (info && info->protocol != gpgme_get_protocol (ctx)) |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
93 info = info->next; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
94 |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
95 if (info && info->version) { |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
96 if (!strncmp(info->version, "1.", 2)) |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
97 gpg.version1 = TRUE; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
98 scr_log_print(LPRINT_DEBUG, "GPGME: Engine version is '%s'.", |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
99 info->version); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
100 } |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
101 } |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
102 |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
103 gpg.enabled = 1; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
104 return 0; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
105 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
106 |
2196
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
107 // gpg_is_version1() |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
108 // Return TRUE if the GnuPG OpenPGP engine version is 1.x |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
109 int gpg_is_version1(void) |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
110 { |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
111 return gpg.version1; |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
112 } |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
113 |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
114 // gpg_terminate() |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
115 // Destroy data and free memory. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
116 void gpg_terminate(void) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
117 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
118 gpg.enabled = 0; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
119 gpg_set_passphrase(NULL); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
120 gpg_set_private_key(NULL); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
121 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
122 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
123 // gpg_set_passphrase(passphrase) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
124 // Set the current passphrase (use NULL to erase it). |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
125 void gpg_set_passphrase(const char *passphrase) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
126 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
127 // Remove current passphrase |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
128 if (gpg.passphrase) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
129 ssize_t len = strlen(gpg.passphrase); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
130 memset(gpg.passphrase, 0, len); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
131 munlock(gpg.passphrase, len); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
132 g_free(gpg.passphrase); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
133 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
134 if (passphrase) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
135 gpg.passphrase = g_strdup(passphrase); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
136 mlock(gpg.passphrase, strlen(gpg.passphrase)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
137 } else { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
138 gpg.passphrase = NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
139 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
140 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
141 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
142 // gpg_set_private_key(keyid) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
143 // Set the current private key id (use NULL to unset it). |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
144 void gpg_set_private_key(const char *priv_keyid) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
145 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
146 g_free(gpg.private_key); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
147 if (priv_keyid) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
148 gpg.private_key = g_strdup(priv_keyid); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
149 else |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
150 gpg.private_key = NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
151 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
152 |
2188
84252c616919
PGP: Encrypt messages with our own PGP key when carbons are enabled
Mikael Berthe <mikael@lilotux.net>
parents:
2187
diff
changeset
|
153 // gpg_get_private_key_id() |
84252c616919
PGP: Encrypt messages with our own PGP key when carbons are enabled
Mikael Berthe <mikael@lilotux.net>
parents:
2187
diff
changeset
|
154 // Return the current private key id (static string). |
84252c616919
PGP: Encrypt messages with our own PGP key when carbons are enabled
Mikael Berthe <mikael@lilotux.net>
parents:
2187
diff
changeset
|
155 const char *gpg_get_private_key_id(void) |
84252c616919
PGP: Encrypt messages with our own PGP key when carbons are enabled
Mikael Berthe <mikael@lilotux.net>
parents:
2187
diff
changeset
|
156 { |
84252c616919
PGP: Encrypt messages with our own PGP key when carbons are enabled
Mikael Berthe <mikael@lilotux.net>
parents:
2187
diff
changeset
|
157 return gpg.private_key; |
84252c616919
PGP: Encrypt messages with our own PGP key when carbons are enabled
Mikael Berthe <mikael@lilotux.net>
parents:
2187
diff
changeset
|
158 } |
84252c616919
PGP: Encrypt messages with our own PGP key when carbons are enabled
Mikael Berthe <mikael@lilotux.net>
parents:
2187
diff
changeset
|
159 |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
160 // strip_header_footer(data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
161 // Remove PGP header & footer from data. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
162 // Return a new string, or NULL. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
163 // The string must be freed by the caller with g_free() when no longer needed. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
164 static char *strip_header_footer(const char *data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
165 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
166 char *p, *q; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
167 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
168 if (!data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
169 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
170 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
171 // p: beginning of real data |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
172 // q: end of real data |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
173 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
174 // Strip header (to the first empty line) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
175 p = strstr(data, "\n\n"); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
176 if (!p) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
177 return g_strdup(data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
178 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
179 // Strip footer |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
180 // We want to remove the last lines, until the line beginning with a '-' |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
181 p += 2; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
182 for (q = p ; *q; q++) ; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
183 // (q is at the end of data now) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
184 for (q--; q > p && (*q != '\n' || *(q+1) != '-'); q--) ; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
185 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
186 if (q <= p) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
187 return NULL; // Shouldn't happen... |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
188 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
189 return g_strndup(p, q-p); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
190 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
191 |
1598 | 192 // GCC ignores casts to void, thus we need to hack around that |
193 static inline void ignore(void*x) {} | |
194 | |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
195 // passphrase_cb() |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
196 // GPGME passphrase callback function. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
197 static gpgme_error_t passphrase_cb(void *hook, const char *uid_hint, |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
198 const char *passphrase_info, int prev_was_bad, int fd) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
199 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
200 ssize_t len; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
201 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
202 // Abort if we do not have the password. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
203 if (!gpg.passphrase) { |
1598 | 204 ignore((void*)write(fd, "\n", 1)); // We have an error anyway, thus it does |
205 // not matter if we fail again. | |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
206 return gpg_error(GPG_ERR_CANCELED); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
207 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
208 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
209 // Write the passphrase to the file descriptor. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
210 len = strlen(gpg.passphrase); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
211 if (write(fd, gpg.passphrase, len) != len) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
212 return gpg_error(GPG_ERR_CANCELED); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
213 if (write(fd, "\n", 1) != 1) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
214 return gpg_error(GPG_ERR_CANCELED); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
215 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
216 return 0; // Success |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
217 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
218 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
219 // gpg_verify(gpg_data, text, *sigsum) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
220 // Verify that gpg_data is a correct signature for text. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
221 // Return the key id (or fingerprint), and set *sigsum to |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
222 // the gpgme signature summary value. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
223 // The returned string must be freed with g_free() after use. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
224 char *gpg_verify(const char *gpg_data, const char *text, |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
225 gpgme_sigsum_t *sigsum) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
226 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
227 gpgme_ctx_t ctx; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
228 gpgme_data_t data_sign, data_text; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
229 char *data; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
230 char *verified_key = NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
231 gpgme_key_t key; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
232 gpgme_error_t err; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
233 const char prefix[] = "-----BEGIN PGP SIGNATURE-----\n\n"; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
234 const char suffix[] = "\n-----END PGP SIGNATURE-----\n"; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
235 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
236 // Reset the summary. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
237 *sigsum = 0; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
238 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
239 if (!gpg.enabled) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
240 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
241 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
242 err = gpgme_new(&ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
243 if (err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
244 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
245 "GPGME error: %s", gpgme_strerror(err)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
246 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
247 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
248 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
249 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
250 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
251 // Surround the given data with the prefix & suffix |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
252 data = g_new(char, sizeof(prefix) + sizeof(suffix) + strlen(gpg_data)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
253 strcpy(data, prefix); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
254 strcat(data, gpg_data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
255 strcat(data, suffix); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
256 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
257 err = gpgme_data_new_from_mem(&data_sign, data, strlen(data), 0); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
258 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
259 err = gpgme_data_new_from_mem(&data_text, text, strlen(text), 0); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
260 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
261 err = gpgme_op_verify(ctx, data_sign, data_text, 0); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
262 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
263 gpgme_verify_result_t vr = gpgme_op_verify_result(ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
264 if (vr && vr->signatures) { |
2200
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
265 gpgme_signature_t s = NULL; |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
266 // check all signatures and stop if the first could be verified |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
267 for (s = vr->signatures; |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
268 (s != NULL) && (verified_key != NULL); |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
269 s = s->next) { |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
270 // Found the fingerprint. Let's try to get the key id. |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
271 if (NULL != s->fpr) { |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
272 if (!gpgme_get_key(ctx, s->fpr, &key, 0)) { |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
273 if (key) { |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
274 verified_key = g_strdup(key->subkeys->keyid); |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
275 gpgme_key_release(key); |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
276 } |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
277 } |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
278 } |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
279 *sigsum = s->summary; |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
280 // For some reason summary could be 0 when status is 0 too, |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
281 // which means the signature is valid... |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
282 if ((!*sigsum) && (!s->status)) |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
283 *sigsum = GPGME_SIGSUM_GREEN; |
fec172dbacc7
Check all signatures and stop immediately if one could be verified
Sven Gaerner <sgaerner@gmx.net>
parents:
2196
diff
changeset
|
284 } |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
285 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
286 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
287 gpgme_data_release(data_text); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
288 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
289 gpgme_data_release(data_sign); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
290 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
291 if (err) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
292 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
1047
0dc104d51dce
PGP: Better error messages
Mikael Berthe <mikael@lilotux.net>
parents:
1041
diff
changeset
|
293 "GPGME verification error: %s", gpgme_strerror(err)); |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
294 gpgme_release(ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
295 g_free(data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
296 return verified_key; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
297 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
298 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
299 // gpg_sign(gpg_data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
300 // Return a signature of gpg_data (or NULL). |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
301 // The returned string must be freed with g_free() after use. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
302 char *gpg_sign(const char *gpg_data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
303 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
304 gpgme_ctx_t ctx; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
305 gpgme_data_t in, out; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
306 char *signed_data = NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
307 size_t nread; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
308 gpgme_key_t key; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
309 gpgme_error_t err; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
310 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
311 if (!gpg.enabled || !gpg.private_key) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
312 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
313 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
314 err = gpgme_new(&ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
315 if (err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
316 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
317 "GPGME error: %s", gpgme_strerror(err)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
318 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
319 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
320 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
321 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
322 gpgme_set_textmode(ctx, 0); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
323 gpgme_set_armor(ctx, 1); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
324 |
2196
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
325 if (gpg.version1) { |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
326 // GPG_AGENT_INFO isn't used by GnuPG version 2+ |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
327 char *p = getenv("GPG_AGENT_INFO"); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
328 if (!(p && strchr(p, ':'))) |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
329 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
330 } |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
331 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
332 err = gpgme_get_key(ctx, gpg.private_key, &key, 1); |
1105
265e1d873d3e
PGP: Improve checks for missing keys
Mikael Berthe <mikael@lilotux.net>
parents:
1057
diff
changeset
|
333 if (err || !key) { |
1049
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
334 scr_LogPrint(LPRINT_LOGNORM, "GPGME error: private key not found"); |
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
335 gpgme_release(ctx); |
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
336 return NULL; |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
337 } |
1049
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
338 |
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
339 gpgme_signers_clear(ctx); |
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
340 gpgme_signers_add(ctx, key); |
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
341 gpgme_key_release(key); |
ad5de4d1ee56
PGP: Give a more useful error message when the private key isn't found
Mikael Berthe <mikael@lilotux.net>
parents:
1047
diff
changeset
|
342 err = gpgme_data_new_from_mem(&in, gpg_data, strlen(gpg_data), 0); |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
343 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
344 err = gpgme_data_new(&out); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
345 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
346 err = gpgme_op_sign(ctx, in, out, GPGME_SIG_MODE_DETACH); |
2202
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
347 if (err) { |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
348 gpgme_data_release(out); |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
349 } else { |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
350 signed_data = gpgme_data_release_and_get_mem(out, &nread); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
351 if (signed_data) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
352 // We need to add a trailing NULL |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
353 char *dd = g_strndup(signed_data, nread); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
354 free(signed_data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
355 signed_data = strip_header_footer(dd); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
356 g_free(dd); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
357 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
358 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
359 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
360 gpgme_data_release(in); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
361 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
362 if (err && err != GPG_ERR_CANCELED) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
363 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
1047
0dc104d51dce
PGP: Better error messages
Mikael Berthe <mikael@lilotux.net>
parents:
1041
diff
changeset
|
364 "GPGME signature error: %s", gpgme_strerror(err)); |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
365 gpgme_release(ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
366 return signed_data; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
367 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
368 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
369 // gpg_decrypt(gpg_data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
370 // Return decrypted gpg_data (or NULL). |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
371 // The returned string must be freed with g_free() after use. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
372 char *gpg_decrypt(const char *gpg_data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
373 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
374 gpgme_ctx_t ctx; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
375 gpgme_data_t in, out; |
2196
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
376 char *data; |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
377 char *decrypted_data = NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
378 size_t nread; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
379 gpgme_error_t err; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
380 const char prefix[] = "-----BEGIN PGP MESSAGE-----\n\n"; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
381 const char suffix[] = "\n-----END PGP MESSAGE-----\n"; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
382 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
383 if (!gpg.enabled) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
384 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
385 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
386 err = gpgme_new(&ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
387 if (err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
388 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
389 "GPGME error: %s", gpgme_strerror(err)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
390 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
391 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
392 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
393 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
394 |
2196
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
395 if (gpg.version1) { |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
396 // GPG_AGENT_INFO isn't used by GnuPG version 2+ |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
397 char *p = getenv("GPG_AGENT_INFO"); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
398 if (!(p && strchr(p, ':'))) |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
399 gpgme_set_passphrase_cb(ctx, passphrase_cb, 0); |
8811fe9d6ef0
Improve support for GnuPG v2+
Mikael Berthe <mikael@lilotux.net>
parents:
2195
diff
changeset
|
400 } |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
401 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
402 // Surround the given data with the prefix & suffix |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
403 data = g_new(char, sizeof(prefix) + sizeof(suffix) + strlen(gpg_data)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
404 strcpy(data, prefix); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
405 strcat(data, gpg_data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
406 strcat(data, suffix); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
407 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
408 err = gpgme_data_new_from_mem(&in, data, strlen(data), 0); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
409 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
410 err = gpgme_data_new(&out); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
411 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
412 err = gpgme_op_decrypt(ctx, in, out); |
2202
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
413 if (err) { |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
414 gpgme_data_release(out); |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
415 } else { |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
416 decrypted_data = gpgme_data_release_and_get_mem(out, &nread); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
417 if (decrypted_data) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
418 // We need to add a trailing NULL |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
419 char *dd = g_strndup(decrypted_data, nread); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
420 free(decrypted_data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
421 decrypted_data = dd; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
422 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
423 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
424 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
425 gpgme_data_release(in); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
426 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
427 if (err && err != GPG_ERR_CANCELED) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
428 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
1047
0dc104d51dce
PGP: Better error messages
Mikael Berthe <mikael@lilotux.net>
parents:
1041
diff
changeset
|
429 "GPGME decryption error: %s", gpgme_strerror(err)); |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
430 gpgme_release(ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
431 g_free(data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
432 return decrypted_data; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
433 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
434 |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
435 // gpg_encrypt(gpg_data, keyids[], n) |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
436 // Return encrypted gpg_data with the n keys from the keyids array (or NULL). |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
437 // The returned string must be freed with g_free() after use. |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
438 char *gpg_encrypt(const char *gpg_data, const char *keyids[], size_t nkeys) |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
439 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
440 gpgme_ctx_t ctx; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
441 gpgme_data_t in, out; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
442 char *encrypted_data = NULL, *edata; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
443 size_t nread; |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
444 gpgme_key_t *keys; |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
445 gpgme_error_t err; |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
446 unsigned i; |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
447 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
448 if (!gpg.enabled) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
449 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
450 |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
451 if (!keyids || !nkeys) { |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
452 return NULL; |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
453 } |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
454 |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
455 err = gpgme_new(&ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
456 if (err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
457 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
458 "GPGME error: %s", gpgme_strerror(err)); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
459 return NULL; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
460 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
461 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
462 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
463 gpgme_set_textmode(ctx, 0); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
464 gpgme_set_armor(ctx, 1); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
465 |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
466 keys = g_new0(gpgme_key_t, 1+nkeys); |
2195
40ddaebeb81e
PGP: Add a memory allocation check and compilation directives
Mikael Berthe <mikael@lilotux.net>
parents:
2188
diff
changeset
|
467 if (!keys) { |
40ddaebeb81e
PGP: Add a memory allocation check and compilation directives
Mikael Berthe <mikael@lilotux.net>
parents:
2188
diff
changeset
|
468 gpgme_release(ctx); |
40ddaebeb81e
PGP: Add a memory allocation check and compilation directives
Mikael Berthe <mikael@lilotux.net>
parents:
2188
diff
changeset
|
469 return NULL; |
40ddaebeb81e
PGP: Add a memory allocation check and compilation directives
Mikael Berthe <mikael@lilotux.net>
parents:
2188
diff
changeset
|
470 } |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
471 |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
472 for (i = 0; i < nkeys; i++) { |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
473 err = gpgme_get_key(ctx, keyids[i], &keys[i], 0); |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
474 if (err || !keys[i]) { |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
475 scr_LogPrint(LPRINT_LOGNORM, "GPGME encryption error: cannot use key %s", |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
476 keyids[i]); |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
477 // We need to have err not null to ensure we won't try to encrypt |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
478 // without this key. |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
479 if (!err) err = GPG_ERR_UNKNOWN_ERRNO; |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
480 break; |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
481 } |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
482 } |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
483 |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
484 if (!err) { |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
485 err = gpgme_data_new_from_mem(&in, gpg_data, strlen(gpg_data), 0); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
486 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
487 err = gpgme_data_new(&out); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
488 if (!err) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
489 err = gpgme_op_encrypt(ctx, keys, GPGME_ENCRYPT_ALWAYS_TRUST, in, out); |
2202
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
490 if (err) { |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
491 gpgme_data_release(out); |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
492 } else { |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
493 encrypted_data = gpgme_data_release_and_get_mem(out, &nread); |
2202
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
494 if (encrypted_data) { |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
495 // We need to add a trailing NULL |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
496 char *dd = g_strndup(encrypted_data, nread); |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
497 free(encrypted_data); |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
498 encrypted_data = dd; |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
499 } |
ff18feb75a6d
PGP: Add a trailing NULL after a message is PGP-encrypted
Mikael Berthe <mikael@lilotux.net>
parents:
2200
diff
changeset
|
500 } |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
501 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
502 gpgme_data_release(in); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
503 } |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
504 |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
505 if (err && err != GPG_ERR_CANCELED) { |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
506 scr_LogPrint(LPRINT_LOGNORM|LPRINT_NOTUTF8, |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
507 "GPGME encryption error: %s", gpgme_strerror(err)); |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
508 } |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
509 } |
2187
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
510 |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
511 for (i = 0; keys[i]; i++) |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
512 gpgme_key_release(keys[i]); |
e3b66c8ead4f
PGP: Change gpg_encrypt() so that several encryption keys can be used
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
513 g_free(keys); |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
514 gpgme_release(ctx); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
515 edata = strip_header_footer(encrypted_data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
516 if (encrypted_data) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
517 free(encrypted_data); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
518 return edata; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
519 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
520 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
521 // gpg_test_passphrase() |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
522 // Test the current gpg.passphrase with gpg.private_key. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
523 // If the test doesn't succeed, the passphrase is cleared and a non-null |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
524 // value is returned. |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
525 int gpg_test_passphrase(void) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
526 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
527 char *s; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
528 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
529 if (!gpg.private_key) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
530 return -1; // No private key... |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
531 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
532 s = gpg_sign("test"); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
533 if (s) { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
534 free(s); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
535 return 0; // Ok, test successful |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
536 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
537 // The passphrase is wrong (if provided) |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
538 gpg_set_passphrase(NULL); |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
539 return -1; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
540 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
541 |
1413 | 542 int gpg_enabled(void) |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
543 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
544 return gpg.enabled; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
545 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
546 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
547 #else /* not HAVE_GPGME */ |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
548 |
1413 | 549 int gpg_enabled(void) |
1041
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
550 { |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
551 return 0; |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
552 } |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
553 |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
554 #endif /* HAVE_GPGME */ |
d4b97a2423eb
Introduce PGP utility functions
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
555 |
1811 | 556 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ |