33 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
34 |
#include "wptErrors.h" |
#include "wptErrors.h" |
35 |
#include "wptW32API.h" |
#include "wptW32API.h" |
36 |
|
#include "wptCrypto.h" |
37 |
|
|
38 |
#define GPG_CONF "gpg.conf" |
#define GPG_CONF "gpg.conf" |
39 |
|
|
71 |
return m_strdup (buf); |
return m_strdup (buf); |
72 |
} |
} |
73 |
|
|
74 |
/* |
/* Return the full path of the GnuPG application. First the registry is scanned |
75 |
* Return the full path of the GnuPG application. First the registry is scanned |
for the entry 'HomeDir'. If it wasn't set, the default dir C:\GNUPG is used. |
|
* for the entry 'HomeDir'. If it wasn't set, the default dir C:\GNUPG is used. |
|
76 |
*/ |
*/ |
77 |
char* |
char* |
78 |
get_gnupg_path (void) |
get_gnupg_path (void) |
88 |
else |
else |
89 |
return multi_gnupg_path (); |
return multi_gnupg_path (); |
90 |
return m_strdup ("c:\\gnupg"); |
return m_strdup ("c:\\gnupg"); |
91 |
} /* get_gnupg_path */ |
} |
92 |
|
|
93 |
|
|
94 |
char* |
char* |
183 |
|
|
184 |
|
|
185 |
static char * |
static char * |
186 |
default_key_from_cache (int * ret_no_useable) |
default_key_from_cache (int *ret_no_useable) |
187 |
{ |
{ |
188 |
const char * s; |
const char * s; |
189 |
char * keyid = NULL; |
char * keyid = NULL; |
190 |
gpgme_key_t key; |
gpgme_key_t key; |
191 |
gpgme_keycache_t sec = keycache_get_ctx (0); |
gpg_keycache_t sec = keycache_get_ctx (0); |
192 |
|
|
193 |
if (!sec) |
if (!sec) |
194 |
BUG (0); |
BUG (0); |
195 |
gpgme_keycache_rewind (sec); |
gpg_keycache_rewind (sec); |
196 |
while (!gpgme_keycache_next_key (sec, 1, &key)) { |
while (!gpg_keycache_next_key (sec, 1, &key)) { |
197 |
if (key_is_useable (key)) { |
if (key_is_useable (key)) { |
198 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
199 |
if (s) |
if (s) |
246 |
return keyid; |
return keyid; |
247 |
} /* get_gnupg_default_key */ |
} /* get_gnupg_default_key */ |
248 |
|
|
249 |
/* |
|
250 |
* Check if the gpg application (exe file) is available. |
/* Check if the gpg application (exe file) is available. */ |
|
*/ |
|
251 |
int |
int |
252 |
check_gnupg_prog( void ) |
check_gnupg_prog (void) |
253 |
{ |
{ |
254 |
char *pgm = NULL; |
char *pgm = NULL; |
255 |
int rc = 0; |
int rc = 0; |
256 |
|
|
257 |
pgm = get_gnupg_prog( ); |
pgm = get_gnupg_prog (); |
258 |
if( pgm == NULL ) |
if (!pgm) |
259 |
rc = WPTERR_GPG_EXEFILE; |
rc = WPTERR_GPG_EXEFILE; |
260 |
if( file_exist_check( pgm ) ) |
if (file_exist_check (pgm)) |
261 |
rc = WPTERR_GPG_EXEFILE; |
rc = WPTERR_GPG_EXEFILE; |
262 |
free_if_alloc( pgm ); |
free_if_alloc (pgm); |
263 |
return rc; |
return rc; |
264 |
} /* check_gpg_prog */ |
} |
265 |
|
|
266 |
|
|
267 |
static int |
static int |
289 |
} |
} |
290 |
|
|
291 |
|
|
292 |
|
/* Check if the gnupg engine fullfills the minimum requirement |
293 |
|
version given in @r_major.@r_minor.@r_patch. On success these |
294 |
|
variables contain the GPG version which is installed. */ |
295 |
int |
int |
296 |
check_gnupg_engine (int * r_major, int * r_minor, int * r_patch) |
check_gnupg_engine (int *r_major, int *r_minor, int *r_patch) |
297 |
{ |
{ |
298 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
299 |
gpgme_engine_info_t inf; |
gpgme_engine_info_t inf; |
329 |
*r_minor = minor; |
*r_minor = minor; |
330 |
*r_patch = patch; |
*r_patch = patch; |
331 |
return rc; |
return rc; |
332 |
} /* check_gnupg_engine */ |
} |
333 |
|
|
334 |
|
|
335 |
int |
int |
651 |
} /* keyring_check_last_access */ |
} /* keyring_check_last_access */ |
652 |
|
|
653 |
|
|
654 |
const char * |
const char* |
655 |
gnupg_check_file_ext (const char * fname) |
gnupg_check_file_ext (const char *fname, int *r_type) |
656 |
{ |
{ |
657 |
char file_ext[5]; |
char file_ext[5]; |
658 |
|
|
659 |
if (!strchr( fname, '.' )) |
if (r_type) *r_type = PGP_NONE; |
660 |
|
if (!strchr (fname, '.' )) |
661 |
return "UNKNOWN"; |
return "UNKNOWN"; |
662 |
|
|
663 |
strncpy (file_ext, fname + strlen (fname) - 4, 4); |
strncpy (file_ext, fname + strlen (fname) - 4, 4); |
664 |
file_ext[4] = '\0'; |
file_ext[4] = '\0'; |
665 |
if (!stricmp (file_ext, ".asc")) |
if (!stricmp (file_ext, ".asc")) |
666 |
return "ARMORED"; |
return "ARMORED"; |
667 |
else if (!stricmp (file_ext, ".sig")) |
else if (!stricmp (file_ext, ".sig")) { |
668 |
|
if (r_type) |
669 |
|
*r_type = PGP_SIG; |
670 |
return "SIGNED"; |
return "SIGNED"; |
671 |
else if (!stricmp (file_ext, ".gpg") |
} |
672 |
|| !stricmp (file_ext, ".pgp")) |
else if (!stricmp (file_ext, ".gpg") || !stricmp (file_ext, ".pgp")) { |
673 |
|
if (r_type) |
674 |
|
*r_type = PGP_MESSAGE; |
675 |
return "ENCRYPTED"; |
return "ENCRYPTED"; |
676 |
else |
} |
|
return "UNKNOWN"; |
|
|
|
|
677 |
return "UNKNOWN"; |
return "UNKNOWN"; |
678 |
} /* gnupg_check_file_ext */ |
} |
679 |
|
|
680 |
|
|
681 |
char * |
char * |