/[winpt]/trunk/Src/WinPT.cpp
ViewVC logotype

Diff of /trunk/Src/WinPT.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by twoaday, Mon Mar 7 13:21:36 2005 UTC revision 28 by twoaday, Thu Oct 20 12:35:59 2005 UTC
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
   
20  #include <windows.h>  #include <windows.h>
21    
22  #include "../resource.h"  #include "../resource.h"
# Line 34  Line 33 
33  #include "wptCard.h"  #include "wptCard.h"
34  #include "wptFileManager.h"  #include "wptFileManager.h"
35  #include "wptContext.h"  #include "wptContext.h"
36    #include "wptCardEdit.h"
37    
38    #define MIN_GPG_VER "1.4.3"
39    
40  HINSTANCE glob_hinst; /* global instance for the dialogs */  HINSTANCE glob_hinst;   /* global instance for the dialogs */
41  HWND glob_hwnd; /* global window handle for the dialogs */  HWND glob_hwnd;         /* global window handle for the dialogs */
42  HWND activ_hwnd;  HWND activ_hwnd;
43  LOCK mo_file;  LOCK mo_file;
44  int scard_support = 0;  int scard_support = 0;
45  int debug = 0;  int debug = 0;
46    int mobile = 0;
47  int gpg_read_only = 0;  int gpg_read_only = 0;
48  char gpgver[3];  char gpgver[3];
49    
50    
51    /* Load the key cache and rebuild the signature cache. */
52  static void  static void
53  update_keycache (HWND hwnd)  update_keycache (HWND hwnd)
54  {  {
# Line 54  update_keycache (HWND hwnd) Line 58  update_keycache (HWND hwnd)
58      rcs.tr_update = 1;      rcs.tr_update = 1;
59      DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd,      DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd,
60                      keycache_dlg_proc, (LPARAM)&rcs);                      keycache_dlg_proc, (LPARAM)&rcs);
61  } /* update_keycache */  }
62    
63    
64    /* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */
65    void
66    gpg_set_debug_mode (int val)
67    {      
68        if (val)
69            putenv ("GPGME_DEBUG=5:gpgme.dbg");
70        else
71            putenv ("GPGME_DEBUG=");
72    }
73    
74  static char *  static char *
75  get_gettext_lang (void)  get_gettext_lang (void)
76  {      {    
# Line 71  get_gettext_lang (void) Line 85  get_gettext_lang (void)
85  static void  static void
86  load_gettext (void)  load_gettext (void)
87  {  {
88      char * nls = NULL;      char *nls = NULL;
89      char * file = NULL;      char *file = NULL;
90    
91      nls = get_gettext_lang ();      nls = get_gettext_lang ();
92      if (nls) {      if (nls) {
# Line 92  load_gettext (void) Line 106  load_gettext (void)
106  /* check if the default key from the gpg.conf file is available in the  /* check if the default key from the gpg.conf file is available in the
107     keyring. if not, bail out because encryption won't work properly then. */     keyring. if not, bail out because encryption won't work properly then. */
108  static int  static int
109  check_default_key (gpgme_keycache_t kc)  check_default_key (gpg_keycache_t kc)
110  {  {
111      gpgme_key_t key;      gpgme_key_t key;
112      gpgme_error_t err = GPGME_No_Error;      gpgme_error_t err = GPG_ERR_NO_ERROR;
113      char * defkey;      char * defkey;
114    
115      defkey = get_gnupg_default_key ();      defkey = get_gnupg_default_key ();
116      if (defkey)      if (defkey)
117          err = gpgme_keycache_find_key (kc, defkey, 0, &key);          err = gpg_keycache_find_key (kc, defkey, 0, &key);
118      free_if_alloc (defkey);      free_if_alloc (defkey);
119      return err? -1 : 0;      return err? -1 : 0;
120  } /* check_default_key */  } /* check_default_key */
# Line 141  get_prog_part (const char * fname, int u Line 155  get_prog_part (const char * fname, int u
155  static int  static int
156  check_crypto_engine (void)  check_crypto_engine (void)
157  {  {
158      int ma=1, mi=2, pa=4; /* GPG 1.2.4 */      int ma=1, mi=4, pa=3; /* GPG 1.4.3 */
159      int rc;      int rc;
160    
161      rc = check_gnupg_engine (&ma, &mi, &pa);      rc = check_gnupg_engine (&ma, &mi, &pa);
# Line 152  check_crypto_engine (void) Line 166  check_crypto_engine (void)
166      else if (rc) {      else if (rc) {
167          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
168                   _("Sorry, you need a newer GPG version.\n"                   _("Sorry, you need a newer GPG version.\n"
169                     "GPG version %d.%d.%d requred GPG version 1.2.4"),                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),
170                     ma, mi, pa);                     ma, mi, pa);
171          return rc;          return rc;
172      }      }
173      /* We enable smartcard support for GPG: 1.9.x and >= 1.3.90 */      /* We enable smartcard support for GPG: 1.9.x or >= 1.4.0 */
174      if (ma > 1 || mi >= 9 || mi > 3)      if (ma >= 1 && mi >= 4)
175          scard_support = 1;          scard_support = 1;
176    
177      gpgver[0] = ma;      gpgver[0] = ma;
# Line 186  load_keyserver_conf (int quiet) Line 200  load_keyserver_conf (int quiet)
200  }  }
201    
202    
203    static void
204    enable_mobile_mode (void)
205    {
206        memset (&reg_prefs, 0, sizeof (reg_prefs));
207        reg_prefs.always_trust = 0;
208        reg_prefs.auto_backup = 0;
209        reg_prefs.cache_time = 0;
210        reg_prefs.expert = 0;
211        reg_prefs.keylist_mode = 1;
212        reg_prefs.kserv_conf = m_strdup ("keyserver.conf");
213        reg_prefs.no_zip_mmedia = 1;
214        reg_prefs.use_tmpfiles = 1;
215        reg_prefs.word_wrap = 80;
216        reg_prefs.use_viewer = 0; /* XXX */
217    }
218    
219    char* get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid);
220    
221    
222  int WINAPI  int WINAPI
223  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
224  {  {
# Line 195  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 228  WinMain (HINSTANCE hinst, HINSTANCE hpre
228      int first_start = 0, start_gpgprefs = 0;      int first_start = 0, start_gpgprefs = 0;
229      const char * s;      const char * s;
230      MSG msg;      MSG msg;
231      HWND hwnd;      HWND hwnd = NULL;
232    
233      glob_hinst = hinst;      glob_hinst = hinst;
234        
     gpgme_lib_init ();  
235      #ifdef _DEBUG      #ifdef _DEBUG
236      gpgme_set_debug_mode (1);      gpg_set_debug_mode (1);
237        debug = 1;
238      #endif      #endif
     gpgme_set_pgm_string ("WinPT "PGM_VERSION);  
239    
240      s = PTD_get_version ();      s = PTD_get_version ();
241      if (strcmp (s, "0.8.0")) {      if (strcmp (s, "0.8.0")) {
# Line 219  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 251  WinMain (HINSTANCE hinst, HINSTANCE hpre
251          return 0;          return 0;
252      }      }
253    
254        s = gpgme_check_version ("1.1.0");
255        if (!s || !*s) {
256            msg_box (NULL, _("A newer GPGME version is needed."), "WinPT Error", MB_ERR);
257            return 0;
258        }
259    
260        if (cmdline && stristr (cmdline, "--mobile")) {
261            msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",
262                     "WinPT", MB_INFO);
263            mobile = 1;
264        }
265    
266      set_default_kserver ();      set_default_kserver ();
267      regist_inst_gnupg (1);  
268      regist_inst_winpt (1, &created);      if (!mobile) {
269            regist_inst_gnupg (1);
270            regist_inst_winpt (1, &created);
271        }
272        else {
273            enable_mobile_mode ();
274            /* XXX: ask for GPG path */
275            created = 1; /* Disable registry writing */
276        }
277    
278      if (!created) {      if (!created) {
279          memset (&reg_prefs, 0, sizeof (reg_prefs));          memset (&reg_prefs, 0, sizeof (reg_prefs));
280          reg_prefs.use_tmpfiles = 1; /* default */          reg_prefs.use_tmpfiles = 1; /* default */
# Line 237  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 290  WinMain (HINSTANCE hinst, HINSTANCE hpre
290                   _("GPG home directory is not set correctly.\n"                   _("GPG home directory is not set correctly.\n"
291                     "Please check the GPG registry settings:\n%s."),                     "Please check the GPG registry settings:\n%s."),
292                   winpt_strerror (rc));                   winpt_strerror (rc));
293          const char * s = get_filename_dlg (GetActiveWindow (), FILE_OPEN,          const char * s = get_fileopen_dlg (GetActiveWindow (),
294                                             _("Select GPG Public Keyring"),                                             _("Select GPG Public Keyring"),
295                                             _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),                                             _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),
296                                             NULL);                                             NULL);
297          if (s && !file_exist_check (s))          if (s != NULL) {
         {  
298              size_t n;              size_t n;
299              char * p = strrchr (s, '\\');              char * p = strrchr (s, '\\');
300              if (!p)              if (!p)
# Line 327  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 379  WinMain (HINSTANCE hinst, HINSTANCE hpre
379      }      }
380    
381      load_keyserver_conf (cmdline? 1 : 0);      load_keyserver_conf (cmdline? 1 : 0);
382    
383      if (cmdline && (stristr (cmdline, "--keymanager")      if (cmdline && (stristr (cmdline, "--keymanager")
384                  || stristr (cmdline, "--cardmanager"))) {                  || stristr (cmdline, "--cardmanager"))) {
385          update_keycache (GetDesktopWindow ());          update_keycache (GetDesktopWindow ());
386          if (stristr (cmdline, "keymanager"))          if (stristr (cmdline, "keymanager"))
387              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,
388                              GetDesktopWindow(), keymanager_dlg_proc, NULL,                              GetDesktopWindow(), keymanager_dlg_proc, NULL,
389                              _("Key Manager"), IDS_WINPT_KEYMISC);                              _("Key Manager"), IDS_WINPT_KEYMISC);  
390          else {          else {
391              gpgme_card_t crd = smartcard_init ();              gpg_card_t crd = gpg_card_load ();
392              if (crd)              if (crd)
393                  dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT,                  dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT,
394                                    GetDesktopWindow(), card_edit_dlg_proc,                                    GetDesktopWindow(), card_edit_dlg_proc,
395                                    (LPARAM)crd, _("Card Manager"),                                    (LPARAM)crd, _("Card Manager"),
396                                    IDS_WINPT_CARD_EDIT);                                    IDS_WINPT_CARD_EDIT);
397              gpgme_card_release (crd);              gpg_card_release (crd);
398          }          }
399          keycache_release ();          keycache_release (0);
400          free_gnupg_table ();          free_gnupg_table ();
401          return 0;          return 0;
402      }      }
# Line 354  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 407  WinMain (HINSTANCE hinst, HINSTANCE hpre
407          return 0;          return 0;
408      }      }
409    
410      /*if (file_exist_check ("loadimage.exe"))      if (cmdline) {
411          PTD_create_loadimage (NULL);*/          if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) {
412                        gpg_set_debug_mode (1);
413      if (cmdline && stristr (cmdline, "--enable-debug")) {              winpt_debug_msg ();
414          gpgme_set_debug_mode (1);              debug = 1;
415          winpt_debug_msg ();          }
         debug = 1;  
416      }      }
417    
418      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
# Line 387  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 439  WinMain (HINSTANCE hinst, HINSTANCE hpre
439      UpdateWindow (hwnd);      UpdateWindow (hwnd);
440    
441      if (!first_start && !start_gpgprefs) {      if (!first_start && !start_gpgprefs) {
442          gnupg_backup_options (1);          gnupg_backup_options ();        
         gnupg_backup_options (0);  
           
443          rc = check_crypto_engine ();          rc = check_crypto_engine ();
444          if (rc) {          if (rc) {
445              DestroyWindow (hwnd);              DestroyWindow (hwnd);
# Line 397  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 447  WinMain (HINSTANCE hinst, HINSTANCE hpre
447              return 0;              return 0;
448          }          }
449      }      }
450        
451      if (start_gpgprefs)      if (start_gpgprefs) {
     {  
452          char *ring;          char *ring;
453          size_t size = 0;          size_t size = 0;
454          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
# Line 411  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 460  WinMain (HINSTANCE hinst, HINSTANCE hpre
460      }      }
461    
462      if (first_start) {      if (first_start) {
463          struct key_wizard_s c, dummy;          struct first_start_s fs;
464            struct genkey_s c;
465            HWND h;
466  start:  start:
467          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, hwnd,          h = GetDesktopWindow ();
468                          first_run_dlg_proc, (LPARAM)&dummy);          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,
469          switch (dummy.interactive)                              gpgprefs_dlg_proc, NULL);
470          {          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,
471                            first_run_dlg_proc, (LPARAM)&fs);
472            switch (fs.choice) {
473          case SETUP_KEYGEN:          case SETUP_KEYGEN:
474              c.interactive = 1;              c.interactive = 1;
475                c.first_start = 1;
476              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,
477                                   hwnd, keygen_wizard_dlg_proc, (LPARAM)&c);                                   h, keygen_wizard_dlg_proc, (LPARAM)&c);
478              if (!rc)              if (!rc)
479                  goto start;                  goto start;
480              break;              break;
# Line 433  start: Line 487  start:
487              }              }
488              break;              break;
489    
         case SETUP_EXISTING:  
             DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,  
                             gpgprefs_dlg_proc, NULL);  
             break;  
   
490          case -1:          case -1:
491              DestroyWindow (hwnd);              DestroyWindow (hwnd);
492              free_gnupg_table ();              free_gnupg_table ();
# Line 447  start: Line 496  start:
496          check_crypto_engine ();          check_crypto_engine ();
497      }      }
498      else {      else {
499          gpgme_keycache_t c;          gpg_keycache_t c;
500          update_keycache (hwnd);          update_keycache (hwnd);
501          c = keycache_get_ctx (1);          c = keycache_get_ctx (1);
502          if (!c || !gpgme_keycache_count (c)) {          if (!c || !gpg_keycache_get_size (c)) {
503              gnupg_display_error ();              gnupg_display_error ();
504              msg_box (hwnd, _("The keycache was not initialized or is empty.\n"              msg_box (hwnd, _("The keycache was not initialized or is empty.\n"
505                               "Please check your GPG config (keyrings, pathes...)"),                               "Please check your GPG config (keyrings, pathes...)"),

Legend:
Removed from v.5  
changed lines
  Added in v.28

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26