1 |
/* wptGPG.h - GnuPG interface |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* WinPT is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU General Public License |
8 |
* as published by the Free Software Foundation; either version 2 |
9 |
* of the License, or (at your option) any later version. |
10 |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#ifndef WPT_GPG_H |
22 |
#define WPT_GPG_H |
23 |
|
24 |
#include "wptNLS.h" |
25 |
#include "gpgme.h" |
26 |
|
27 |
#define NO_STRICT 0 |
28 |
|
29 |
enum { |
30 |
SETUP_KEYGEN = 1, |
31 |
SETUP_IMPORT = 2, |
32 |
SETUP_EXISTING = 3 |
33 |
}; |
34 |
|
35 |
enum { |
36 |
GPG_CMD_DECRYPT = 0, |
37 |
GPG_CMD_SIGN = 1 |
38 |
}; |
39 |
|
40 |
enum { |
41 |
KEYCACHE_PRV = 0, |
42 |
KEYCACHE_PUB = 1 |
43 |
}; |
44 |
|
45 |
enum { |
46 |
ENTRY_OPAQUE = 1, |
47 |
ENTRY_SINGLE = 2, |
48 |
ENTRY_MULTI = 3, |
49 |
ENTRY_GROUP = 4, |
50 |
}; |
51 |
|
52 |
struct gpg_filetype { |
53 |
const char *descr; |
54 |
const char *ext; |
55 |
int nicon; |
56 |
}; |
57 |
|
58 |
struct refresh_cache_s { |
59 |
int kr_reload; |
60 |
int kr_update; |
61 |
int tr_update; |
62 |
}; |
63 |
|
64 |
struct gpg_option_s { |
65 |
struct gpg_option_s * next; |
66 |
char * name; |
67 |
char * val; |
68 |
unsigned int used:1; |
69 |
int type; |
70 |
}; |
71 |
typedef struct gpg_option_s * gpg_option_t; |
72 |
|
73 |
struct gpg_member_s { |
74 |
struct gpg_member_s * next; |
75 |
char * name; |
76 |
unsigned int used:1; |
77 |
}; |
78 |
typedef struct gpg_member_s * gpg_member_t; |
79 |
|
80 |
struct gpg_group_s { |
81 |
struct gpg_group_s * next; |
82 |
struct gpg_member_s * list; |
83 |
char * name; |
84 |
unsigned int used:1; |
85 |
}; |
86 |
typedef struct gpg_group_s * gpg_group_t; |
87 |
|
88 |
struct gpg_optfile_s { |
89 |
struct gpg_option_s * list; |
90 |
struct gpg_group_s * grp; |
91 |
}; |
92 |
typedef struct gpg_optfile_s * gpg_optfile_t; |
93 |
|
94 |
static gpg_filetype gpg_filetypes[] = { |
95 |
{"GPG Detached Signature", ".sig", 1}, |
96 |
{"GPG Encrypted Data", ".gpg", 2}, |
97 |
{"GPG Armored Data", ".asc", 2}, |
98 |
{0} |
99 |
}; |
100 |
|
101 |
struct passphrase_cb_s { |
102 |
int gpg_cmd; |
103 |
gpgme_recipients_t enc_to; |
104 |
int pwd_init; |
105 |
char pwd[256]; |
106 |
char info[1024]; /* hold up the info message */ |
107 |
char title[256]; |
108 |
const char * keyid; |
109 |
HWND hwnd; |
110 |
int cancel; |
111 |
int is_card; |
112 |
}; |
113 |
|
114 |
static const char * gpg_sigstat[] = { |
115 |
_("Error during verification process."), |
116 |
_("The signature is good."), |
117 |
_("The signature is BAD!"), |
118 |
_("The signature could not be checked due to a missing key."), |
119 |
_("No valid OpenPGP signature."), |
120 |
_("Signature Error"), |
121 |
_("Good Signature (Expired Key)"), |
122 |
_("Good Signature (Revoked Key)"), |
123 |
NULL |
124 |
}; |
125 |
|
126 |
#define SIGSTAT_MASK 8 |
127 |
|
128 |
extern int idea_available; |
129 |
|
130 |
/*-- wptGPG.cpp --*/ |
131 |
char* get_gnupg_default_key( void ); |
132 |
int set_gnupg_default_key( const char *key ); |
133 |
char* get_gnupg_config (void); |
134 |
char* get_gnupg_keyring_from_options( const char *fname, int pub ); |
135 |
int check_gnupg_config (const char *fname, int *secrings, int *pubrings); |
136 |
char* get_gnupg_path( void ); |
137 |
int check_gnupg_prog( void ); |
138 |
int gnupg_access_files (void); |
139 |
char* get_gnupg_prog( void ); |
140 |
char* get_gnupg_keyring (int pub, int strict); |
141 |
char* get_gnupg_cfgfile (void); |
142 |
int set_gnupg_options( const char *buf, size_t buflen ); |
143 |
|
144 |
int check_gnupg_options (const char *buf); |
145 |
void init_gnupg_table (void); |
146 |
void free_gnupg_table (void); |
147 |
int keyring_check_last_access (void); |
148 |
const char* gnupg_check_file_ext (const char * fname); |
149 |
int gpg_check_permissions (int showmsg); |
150 |
int gnupg_check_homedir (void); |
151 |
int gnupg_access_keyring (int _pub); |
152 |
void gnupg_backup_options (int keep); |
153 |
void gnupg_backup_keyrings (void); |
154 |
void gnupg_display_error (void); |
155 |
int gnupg_copy_keyrings (void); |
156 |
int check_gnupg_engine (int *r_major, int *r_minor, int *r_patch); |
157 |
|
158 |
gpgme_card_t smartcard_init (void); |
159 |
|
160 |
/*-- wptGPGME.cpp --*/ |
161 |
const char * get_signature_status( gpgme_sigstat_t sigstat ); |
162 |
void keycache_reload( HWND dlg ); |
163 |
|
164 |
int get_pubkey( const char *keyid, gpgme_key_t *ret_key ); |
165 |
int get_seckey( const char *keyid, gpgme_key_t *ret_skey ); |
166 |
|
167 |
void keycache_reload( HWND dlg ); |
168 |
void keycache_release( void ); |
169 |
gpgme_error_t keycache_update (const char *keyid); |
170 |
gpgme_error_t keycache_init( const char *pubring, const char * secring ); |
171 |
void keycache_set_reload( int yes ); |
172 |
int keycache_get_reload( void ); |
173 |
gpgme_keycache_t keycache_get_ctx( int _pub ); |
174 |
|
175 |
int count_insecure_elgkeys( void ); |
176 |
|
177 |
int gpgme_encrypt_symmetric( void ); |
178 |
|
179 |
#define gpgme_enable_logging( ctx ) \ |
180 |
gpgme_control( (ctx), GPGME_CTRL_LOGGING, 1 ) |
181 |
|
182 |
#define gpgme_show_error( hwnd, rc, ctx, title, mode ) \ |
183 |
do { \ |
184 |
if( (rc) == GPGME_Internal_GPG_Problem && ctx ) { \ |
185 |
char * strerr = gpgme_get_logging( (ctx) ); \ |
186 |
msg_box( (hwnd), (strerr)? (strerr) : \ |
187 |
_("No GPG error description available."), title, mode );\ |
188 |
safe_free( strerr ); \ |
189 |
} \ |
190 |
else { \ |
191 |
msg_box( (hwnd), gpgme_strerror( (rc) ), \ |
192 |
title, mode ); \ |
193 |
} \ |
194 |
} while ( 0 ) |
195 |
|
196 |
/*-- wptGPGParser.cpp --*/ |
197 |
/* find */ |
198 |
gpg_group_t find_group( gpg_optfile_t opt, const char *str ); |
199 |
gpg_option_t find_option( gpg_optfile_t opt, const char *str ); |
200 |
gpg_member_t find_member( gpg_optfile_t opt, const char *grp, const char *str ); |
201 |
/* delete */ |
202 |
int delete_group( gpg_optfile_t opt, const char *str ); |
203 |
int delete_member( gpg_optfile_t opt, const char *grp, const char *str ); |
204 |
int delete_option( gpg_optfile_t opt, const char *str ); |
205 |
/* add */ |
206 |
int modify_entry( gpg_optfile_t opt, int type, const char *name, const char *val ); |
207 |
int add_entry( gpg_optfile_t opt, int type, const char *name, const char *val ); |
208 |
int add_member( gpg_optfile_t opt, const char *grp, const char *str ); |
209 |
int add_group( gpg_optfile_t opt, const char *str ); |
210 |
/* high-level */ |
211 |
int parse_gpg_options( const char *file, gpg_optfile_t *r_opt ); |
212 |
int commit_gpg_options( const char *file, gpg_optfile_t opt ); |
213 |
void release_gpg_options( gpg_optfile_t opt ); |
214 |
/* memory */ |
215 |
void release_group( gpg_group_t grp ); |
216 |
|
217 |
/*-- wptPassphraseCB.cpp --*/ |
218 |
void set_gpg_passphrase_cb( gpgme_ctx_t c, passphrase_cb_s * ctx, int cmd, |
219 |
HWND hwnd, const char * title ); |
220 |
char * request_passphrase( const char * title, int init, int * ret_cancel ); |
221 |
char * request_passphrase2 (const char * title, int * ret_cancel); |
222 |
const char * passphrase_cb( void * opaque, const char * desc, void * r_hd ); |
223 |
char * get_key_userid( const char * keyid ); |
224 |
|
225 |
#endif /* WPT_GPG_H */ |