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

Diff of /trunk/Src/wptCardDlg.cpp

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

revision 185 by twoaday, Mon Mar 20 12:48:52 2006 UTC revision 278 by twoaday, Mon Jan 15 22:02:04 2007 UTC
# Line 1  Line 1 
1  /* wptCardDlg.cpp - Smart Card support  /* wptCardDlg.cpp - Smart Card support
2   *      Copyright (C) 2003, 2004, 2005 Timo Schulz   *      Copyright (C) 2003-2006 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 13  Line 13 
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.   * GNU General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  
16   */   */
17    
18  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 41  Line 37 
37  #include "wptCardEdit.h"  #include "wptCardEdit.h"
38  #include "wptCard.h"  #include "wptCard.h"
39  #include "wptContext.h"  #include "wptContext.h"
40    #include "StringBuffer.h"
41    
42  int keygen_check_date (SYSTEMTIME * st);  int keygen_check_date (SYSTEMTIME * st);
43    
44  static const char * sex[] = {"Male", "Female", "Undefined", NULL};  
45  static const char * lang[] = {"Undefined", "cs", "de", "en", "es", "fr", "hu",  #define OPENPGP_APPID "D276000124"
46    
47    /* Possible values for the sex field. */
48    static const char *sex[] = {"Male", "Female", "Undefined", NULL};
49    
50    /* Predefined languages. */
51    static const char *lang[] = {"Undefined", "cs", "de", "en", "es", "fr", "hu",
52                                "it", "nl", "pt", "ro", "ru", "zh", "at",                                "it", "nl", "pt", "ro", "ru", "zh", "at",
53                                NULL};                                NULL};
54    
55    /* PIN callback context. */
56  static pin_cb_ctx_s pincb;  static pin_cb_ctx_s pincb;
57    
58    /* Attribute table. */
59  struct {  struct {
60      int ctlid;      int ctlid;
61      const char * err;      const char *err;
62  } attr_tab[] = {  } attr_tab[] = {
63      {IDC_CEDIT_AID,    ""},      {IDC_CEDIT_AID,    ""},
64      {IDC_CEDIT_VENDOR, "No Vendor"},      {IDC_CEDIT_VENDOR, "No Vendor"},
# Line 68  struct { Line 73  struct {
73    
74    
75    
 /* XXX: simplify code. */  
 char*  
 get_printable_version (const char *version)  
 {  
     static char buf[16];  
     char tmp_maj[3]={0}, tmp_min[3]={0};  
   
     strncpy (tmp_maj, version, 2);  
     strncpy (tmp_min, version+2, 2);  
     sprintf (buf, "%d.%d", atoi (tmp_maj), atoi (tmp_min));  
     return buf;  
 }  
   
76  /* Return all card attributes from @card. @n contains  /* Return all card attributes from @card. @n contains
77     the number of items which were returned. */     the number of items which were returned. */
78  char**  char**
79  card_get_items (gpg_card_t card, int *n)  card_get_items (gpg_card_t card, int *n)
80  {  {
81        static char printver[16];
82      char **p;      char **p;
83    
84      *n= 8;      *n= 8;
85      p = (char **)calloc (*n+1, sizeof (char*));      p = (char **)calloc (*n+1, sizeof (char*));
86      if (!p)      if (!p)
87          BUG (0);          BUG (0);
88        _snprintf (printver, sizeof (printver)-1, "%d.%d",
89                    card->ver[0], card->ver[1]);
90      p[0] = card->aid;      p[0] = card->aid;
91      p[1] = card->vendor;      p[1] = card->vendor;
92      p[2] = get_printable_version (card->version);      p[2] = printver;
93      p[3] = card->serial;      p[3] = card->serial;
94      p[4] = card->givenname;      p[4] = card->givenname;
95      p[5] = card->surname;      p[5] = card->surname;
# Line 105  card_get_items (gpg_card_t card, int *n) Line 100  card_get_items (gpg_card_t card, int *n)
100    
101    
102  static int  static int
103  idx_from_lang (const char * _lang)  idx_from_lang (const char *_lang)
104  {  {
105      const char * s;      const char *s;
106      int i;      int i;
107    
108      if (!_lang)      if (!_lang)
109          return 0;          return 0;
110      for (i=0; (s = lang[i]); i++) {      for (i=0; (s = lang[i]); i++) {
111          if (!strcmp (_lang, s ))          if (!strcmp (_lang, s))
112              return i;              return i;
113      }      }
114      return 0;      return 0;
115  }  }
116    
117    
118  #if 0 /* @unused@ */  static GpgCardEdit*
119  int  create_GpgCardEdit (void)
120  show_card_status (void)  {
121  {      GpgCardEdit *ce;
122      int rc = 0;  
123      int cardstat;      ce = new GpgCardEdit ();
124        if (!ce)
125      cardstat = pcsc_get_card_status ();          BUG (0);
126      if ((cardstat & CARD_STATE_UNAWARE) || (cardstat & CARD_STATE_UNAVAIL))      return ce;
127          rc = WPTERR_NOREADER;  }
128      else if (cardstat & CARD_STATE_EMPTY)  
         rc = WPTERR_NOCARD;      
     if (rc) {  
         msg_box (NULL, winpt_strerror (rc), _("Card Manager"), MB_ERR);  
         return -1;  
     }  
     return 0;  
 } /* show_card_status */  
 #endif  
129    
130  /* Check if there is a card in the reader and analyze the  /* Check if there is a card in the reader and analyze the
131     returned information.     returned information.
# Line 151  gpg_card_load (void) Line 138  gpg_card_load (void)
138      gpg_card_t card = NULL;      gpg_card_t card = NULL;
139      struct card_cb_s cb = {0};      struct card_cb_s cb = {0};
140            
141      ce = new GpgCardEdit ();      ce = create_GpgCardEdit ();
     if (!ce)  
         BUG (0);  
142      memset (&cb, 0, sizeof (cb));      memset (&cb, 0, sizeof (cb));
143      ce->setCallback (card_callback, &cb);      ce->setCallback (card_callback, &cb);
144      err = ce->getCardStatus (&card);      err = ce->getCardStatus (&card);
# Line 162  gpg_card_load (void) Line 147  gpg_card_load (void)
147          goto leave;          goto leave;
148      }      }
149    
150      if (!card->aid || strncmp (card->aid, "D276000124", 10)) {      if (!card->aid ||
151            strncmp (card->aid, OPENPGP_APPID, strlen (OPENPGP_APPID))) {
152          msg_box (NULL, winpt_strerror (WPTERR_NOPGPCARD), "WinPT", MB_ERR);          msg_box (NULL, winpt_strerror (WPTERR_NOPGPCARD), "WinPT", MB_ERR);
153          gpg_card_release (card);          gpg_card_release (card);
154          card = NULL;          card = NULL;
155      }      }
156      else {      else {
157          struct winpt_key_s key;          struct winpt_key_s key;
158    
159          memset (&key, 0, sizeof (key));          memset (&key, 0, sizeof (key));
160          winpt_get_pubkey (card->fpr[1]+32, &key);          winpt_get_pubkey (card->fpr[1]+32, &key);
161          if (key.ext) {          if (key.ext) {
162              key.ext->card_type = strdup (card->card_type);              key.ext->card_type = m_strdup (card->card_type);
             if (!key.ext->card_type)  
                 BUG (NULL);  
163              /* memory will be released in gpg_keycache_release (). */              /* memory will be released in gpg_keycache_release (). */
164          }          }
165      }      }
# Line 197  print_fpr (HWND dlg, int id, const char Line 182  print_fpr (HWND dlg, int id, const char
182          strcpy (buf, _("No Fingerprint"));          strcpy (buf, _("No Fingerprint"));
183      else {      else {
184          memset (buf, 0, sizeof (buf));          memset (buf, 0, sizeof (buf));
185          for( i=0, c=0; i < strlen (fpr); i++) {          for (i=0, c=0; i < strlen (fpr); i++) {
186              dig[0] = fpr[i]; dig[1] = 0;              dig[0] = fpr[i]; dig[1] = 0;
187              strcat (buf, dig);              strcat (buf, dig);
188              if (++c == 4) {              if (++c == 4) {
# Line 217  static int Line 202  static int
202  card_status (HWND dlg, gpg_card_t card)  card_status (HWND dlg, gpg_card_t card)
203  {  {
204      static int fprbuf[] = {IDC_CEDIT_FPR1, IDC_CEDIT_FPR2, IDC_CEDIT_FPR3, 0};      static int fprbuf[] = {IDC_CEDIT_FPR1, IDC_CEDIT_FPR2, IDC_CEDIT_FPR3, 0};
205      static int fprtime[] = {IDC_CEDIT_SIG_FPRTIME, IDC_CEDIT_DEC_FPRTIME, IDC_CEDIT_AUTH_FPRTIME, 0};      static int fprtime[] = {IDC_CEDIT_SIG_FPRTIME, IDC_CEDIT_DEC_FPRTIME,
206                                IDC_CEDIT_AUTH_FPRTIME, 0};
207      const char *s;      const char *s;
208      char **attrs;      char **attrs;
209      char cardinf[128];      char cardinf[128];
210      int idx=0, n=0;      int idx=0, n=0;
211    
212      if (!card->aid) {      if (!card->aid) {
213          msg_box( dlg, _("No OpenPGP smart card detected."), "WinPT", MB_ERR );          msg_box (dlg, _("No OpenPGP smart card detected."), "WinPT", MB_ERR);
214          return -1;          return -1;
215      }      }
216      SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid);      SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid);
# Line 232  card_status (HWND dlg, gpg_card_t card) Line 218  card_status (HWND dlg, gpg_card_t card)
218    
219      for (idx=0; fprbuf[idx]; idx++) {      for (idx=0; fprbuf[idx]; idx++) {
220          print_fpr (dlg, fprbuf[idx], card->fpr[idx]);          print_fpr (dlg, fprbuf[idx], card->fpr[idx]);
221          SetDlgItemText (dlg, fprtime[idx], card->fpr_created_str[idx]);          s = card->fpr_created_str[idx];
222            if (!s) /* no keys on the card. */
223                s = "";
224            SetDlgItemText (dlg, fprtime[idx], s);
225      }      }
226    
227      attrs = card_get_items (card, &n);      attrs = card_get_items (card, &n);
228      for (idx=1; attr_tab[idx].ctlid; idx++) {      for (idx=1; attr_tab[idx].ctlid; idx++) {
229          s = attrs[idx];          s = attrs[idx];
230          SetDlgItemText (dlg, attr_tab[idx].ctlid, s && *s? s : attr_tab[idx].err);          SetDlgItemText (dlg, attr_tab[idx].ctlid,
231                            s && *s? s : attr_tab[idx].err);
232      }      }
233      free (attrs);      safe_free (attrs);
234    
235      idx = idx_from_lang (card->lang);          idx = idx_from_lang (card->lang);    
236      SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_SETCURSEL, (WPARAM)idx, 0);      SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_SETCURSEL, (WPARAM)idx, 0);
# Line 255  card_status (HWND dlg, gpg_card_t card) Line 245  card_status (HWND dlg, gpg_card_t card)
245    
246      s = card->serial;      s = card->serial;
247      while (s && *s == '0') s++;      while (s && *s == '0') s++;
248      _snprintf (cardinf, sizeof (cardinf)-1,      _snprintf (cardinf, sizeof (cardinf)-1,
249                 "Card Edit - %s serial no. %s version %s",                 "Card Edit - %s serial no. %s version %d.%d",
250                 card->card_type, s, get_printable_version (card->version));                 card->card_type, s, card->ver[0], card->ver[1]);
251      SetWindowText (dlg, cardinf);      SetWindowText (dlg, cardinf);
252    
253      return 0;      return 0;
# Line 285  static int Line 275  static int
275  check_string (const char *str, int flags)  check_string (const char *str, int flags)
276  {  {
277      size_t i;      size_t i;
278    
279      for (i=0; i < strlen (str); i++) {      for (i=0; i < strlen (str); i++) {
280          if (flags & 0x02 && !isalpha (str[i]))          if (flags & 0x02 && !isalpha (str[i]))
281              return -1;              return -1;
# Line 347  do_proc_card_cmds (HWND dlg, struct pin_ Line 338  do_proc_card_cmds (HWND dlg, struct pin_
338          return 0;          return 0;
339      }      }
340            
341      ce = new GpgCardEdit ();      ce = create_GpgCardEdit ();
     if (!ce)  
         BUG (NULL);  
342      ce->setAdminPIN (cb->apin);      ce->setAdminPIN (cb->apin);
     /*ce->setPIN (cb->upin);*/  
343      for( i=0; idctl[i].id; i++ ) {      for( i=0; idctl[i].id; i++ ) {
344          if( idctl[i].changed ) {          if( idctl[i].changed ) {
345              GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 );              GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 );
# Line 400  do_proc_card_cmds (HWND dlg, struct pin_ Line 388  do_proc_card_cmds (HWND dlg, struct pin_
388      }      }
389      delete ce;      delete ce;
390      return errc;      return errc;
391  } /* do_proc_card_cmds */  }
392    
393    
394  /* Cleanup pin callback @ctx. */  /* Cleanup pin callback @ctx. */
# Line 424  static int Line 412  static int
412  do_askpin (HWND dlg, int which, gpg_card_t card,  do_askpin (HWND dlg, int which, gpg_card_t card,
413             struct pin_cb_ctx_s *cb)             struct pin_cb_ctx_s *cb)
414  {  {
415      const char * s, * fmt;      const char *s;
416      const char * n1, * n2, * serial;      char *p;
     char * p;  
     size_t n;  
417    
418      if( (which == CARD_ADMIN_PIN && cb->apin) ||      if( (which == CARD_ADMIN_PIN && cb->apin) ||
419          (which == CARD_USER_PIN && cb->upin) )          (which == CARD_USER_PIN && cb->upin) )
# Line 440  do_askpin (HWND dlg, int which, gpg_card Line 426  do_askpin (HWND dlg, int which, gpg_card
426      else      else
427          s = _("Please enter the PIN");          s = _("Please enter the PIN");
428      cb->which = which;      cb->which = which;
429      free_if_alloc( cb->info_text );      free_if_alloc (cb->info_text);
430      if( card ) {      if (card) {
431          fmt = _("%s\nName: %s %s\nSerial-No: %s\n");          StringBuffer buf;
432          n1 = card->givenname;  
433          n2 = card->surname;          buf = s;
434          if( !n1 || !n2 ) {          buf = buf + "\nName: " + (card->givenname?card->givenname: "No");
435              n1 = "No"; n2 = "Name";          buf = buf + " " + (card->surname?card->surname : "Name");
436          }              buf = buf + "\nSerial-No:" + card->serial;
437          serial = card->serial;          p = buf.getBufferCopy ();
         if (!serial)  
             serial = "No Serial ID";  
         n = strlen( n1 ) + strlen( n2 ) + strlen( fmt ) + strlen( serial ) + 3;  
         p = cb->info_text = new char[strlen( s )+n+1 ];  
         if( !p )  
             BUG (0);  
         sprintf( p, fmt, s, n1, n2, serial );  
438      }      }
439      else {      else
440          p = cb->info_text = m_strdup (s);          p = cb->info_text = m_strdup (s);
         if (!p)  
             BUG (0);  
     }  
441      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg,      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg,
442                      pin_cb_dlg_proc, (LPARAM)cb);                      pin_cb_dlg_proc, (LPARAM)cb);
443      if (!cb->apin && !cb->upin) {      if (!cb->apin && !cb->upin) {
# Line 488  card_edit_dlg_proc (HWND dlg, UINT msg, Line 464  card_edit_dlg_proc (HWND dlg, UINT msg,
464          prepare_dialog (dlg);          prepare_dialog (dlg);
465          if (card_status (dlg, card ))          if (card_status (dlg, card ))
466              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
467            SetDlgItemText (dlg, IDC_CEDIT_NAMEINF, _("&Name"));
468            SetDlgItemText (dlg, IDC_CEDIT_LANGINF, _("&Language"));
469            SetDlgItemText (dlg, IDC_CEDIT_KURLINF, _("&Key-URL"));
470            SetDlgItemText (dlg, IDC_CEDIT_LOGINF, _("&Login"));
471            SetDlgItemText (dlg, IDC_CEDIT_SEXINF, _("&Sex"));
472            SetDlgItemText (dlg, IDOK, _("&OK"));
473            SetDlgItemText (dlg, IDCANCEL, _("&Exit"));
474            SetDlgItemText (dlg, IDC_CEDIT_NEWKEYS, _("&New keys"));
475            SetDlgItemText (dlg, IDC_CEDIT_CHPIN, _("Change &PIN"));
476          center_window (dlg, NULL);          center_window (dlg, NULL);
477          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
478          return TRUE;          return TRUE;
# Line 498  card_edit_dlg_proc (HWND dlg, UINT msg, Line 483  card_edit_dlg_proc (HWND dlg, UINT msg,
483          break;          break;
484    
485      case WM_COMMAND:      case WM_COMMAND:
486          switch( HIWORD( wparam ) ) {          switch (HIWORD (wparam)) {
487          case CBN_KILLFOCUS:          case CBN_KILLFOCUS:
488          case CBN_EDITCHANGE:          case CBN_EDITCHANGE:
489          case CBN_EDITUPDATE:          case CBN_EDITUPDATE:
490              int ctlid = GetDlgCtrlID( (HWND)lparam );              int ctlid = GetDlgCtrlID ((HWND)lparam);
491              int dstid = 0;              int dstid = 0;
492    
493              switch (ctlid) {              switch (ctlid) {
# Line 523  card_edit_dlg_proc (HWND dlg, UINT msg, Line 508  card_edit_dlg_proc (HWND dlg, UINT msg,
508              if (item_get_text_length (dlg, IDC_CEDIT_FPR1) > 0) {              if (item_get_text_length (dlg, IDC_CEDIT_FPR1) > 0) {
509                  int id = msg_box (dlg,                  int id = msg_box (dlg,
510                      _("This operation will override the keys on the card.\n"                      _("This operation will override the keys on the card.\n"
511                        "Still proceed?"), _("Card Edit"), MB_WARN|MB_YESNO);                        "Continue?"), _("Card Edit"), MB_WARN|MB_YESNO);
512                  if (id == IDNO)                  if (id == IDNO)
513                      return TRUE;                      return TRUE;
514              }              }
# Line 544  card_edit_dlg_proc (HWND dlg, UINT msg, Line 529  card_edit_dlg_proc (HWND dlg, UINT msg,
529              break;              break;
530    
531          case IDCANCEL:          case IDCANCEL:
532              EndDialog( dlg, FALSE );              EndDialog (dlg, FALSE);
533              break;              break;
534          }          }
535          break;          break;
# Line 587  card_keygen_dlg_proc (HWND dlg, UINT msg Line 572  card_keygen_dlg_proc (HWND dlg, UINT msg
572    
573      switch (msg) {      switch (msg) {
574      case WM_INITDIALOG:      case WM_INITDIALOG:
         center_window (dlg, NULL);  
575          CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED);          CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED);
576          CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED);          CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED);
577          CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED);          CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED);
# Line 595  card_keygen_dlg_proc (HWND dlg, UINT msg Line 579  card_keygen_dlg_proc (HWND dlg, UINT msg
579          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0,          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0,
580                              (LPARAM)(const char*)"RSA");                              (LPARAM)(const char*)"RSA");
581          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0);          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0);
582          SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME));          SetDlgItemText (dlg, IDC_CKEYGEN_PKINF, _("Pubkey algorithm"));
         SetForegroundWindow (dlg);  
583          SetDlgItemText (dlg, IDC_CKEYGEN_NAMEINF, _("&Name"));          SetDlgItemText (dlg, IDC_CKEYGEN_NAMEINF, _("&Name"));
584          SetDlgItemText (dlg, IDC_CKEYGEN_CMTINF, _("&Comment (optional)"));          SetDlgItemText (dlg, IDC_CKEYGEN_CMTINF, _("&Comment (optional)"));
585          SetDlgItemText (dlg, IDC_CKEYGEN_EXPDATEINF, _("&Expire date"));          SetDlgItemText (dlg, IDC_CKEYGEN_EXPDATEINF, _("&Expire date"));
# Line 606  card_keygen_dlg_proc (HWND dlg, UINT msg Line 589  card_keygen_dlg_proc (HWND dlg, UINT msg
589          SetDlgItemText (dlg, IDC_CKEYGEN_REPLACE, _("Overwrite old keys on the card"));          SetDlgItemText (dlg, IDC_CKEYGEN_REPLACE, _("Overwrite old keys on the card"));
590          SetDlgItemText (dlg, IDC_CKEYGEN_BACKUP, _("Make off-card backup of encryption key"));          SetDlgItemText (dlg, IDC_CKEYGEN_BACKUP, _("Make off-card backup of encryption key"));
591          SetWindowText (dlg, _("Card Key Generation"));          SetWindowText (dlg, _("Card Key Generation"));
592          return FALSE;          center_window (dlg, NULL);
593            SetForegroundWindow (dlg);
594      case WM_SYSCOMMAND:          SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME));
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, TRUE);  
595          return FALSE;          return FALSE;
596    
597      case WM_COMMAND:      case WM_COMMAND:
# Line 644  card_keygen_dlg_proc (HWND dlg, UINT msg Line 625  card_keygen_dlg_proc (HWND dlg, UINT msg
625              }              }
626              GetDlgItemText (dlg, IDC_CKEYGEN_NAME, name, sizeof (name)-1);              GetDlgItemText (dlg, IDC_CKEYGEN_NAME, name, sizeof (name)-1);
627              GetDlgItemText (dlg, IDC_CKEYGEN_EMAIL, email, sizeof (email)-1);              GetDlgItemText (dlg, IDC_CKEYGEN_EMAIL, email, sizeof (email)-1);
628              if (!strchr (email, '@') || n < 3) {              if (check_email_address (email) || n < 3) {
629                  msg_box (dlg, _("Please enter a valid e-mail address."),                  msg_box (dlg, _("Please enter a valid e-mail address."),
630                           _("Card Edit"), MB_ERR);                           _("Card Edit"), MB_ERR);
631                  return TRUE;                  return TRUE;
632              }              }
633              n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1);              n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1);
634              if (!n && IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)) {              if (!n && IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)) {
635                  msg_box (dlg, _("Please enter an off-card passphrase."), _("Card Edit"), MB_ERR);                  msg_box (dlg, _("Please enter an off-card passphrase."),
636                             _("Card Edit"), MB_ERR);
637                  return TRUE;                  return TRUE;
638              }              }
639              n = item_get_text_length (dlg, IDC_CKEYGEN_COMMENT);              n = item_get_text_length (dlg, IDC_CKEYGEN_COMMENT);
# Line 671  card_keygen_dlg_proc (HWND dlg, UINT msg Line 653  card_keygen_dlg_proc (HWND dlg, UINT msg
653                  free_pincb (&pincb);                  free_pincb (&pincb);
654                  return TRUE;                  return TRUE;
655              }              }
656              ce = new GpgCardEdit ();              ce = create_GpgCardEdit ();
657              if (!ce)  
                 BUG (0);  
               
658              expires = !IsDlgButtonChecked (dlg, IDC_CKEYGEN_NEVER);              expires = !IsDlgButtonChecked (dlg, IDC_CKEYGEN_NEVER);
659              if (expires) {              if (expires) {
660                  SYSTEMTIME st, ct;                  SYSTEMTIME st, ct;
661    
662                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_CKEYGEN_VALID), &st);                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_CKEYGEN_VALID), &st);
663                  if (!keygen_check_date (&st)) {                  if (!keygen_check_date (&st)) {
664                      msg_box (dlg, _("The date you have chosen lies in the past."),                      msg_box (dlg, _("The date you have chosen has already passed."),
665                               _("Card Edit"), MB_ERR);                               _("Card Edit"), MB_ERR);
666                      free_pincb (&pincb);                      free_pincb (&pincb);
667                      delete ce;                      delete ce;
# Line 702  card_keygen_dlg_proc (HWND dlg, UINT msg Line 683  card_keygen_dlg_proc (HWND dlg, UINT msg
683              SetCursor (LoadCursor (NULL, IDC_WAIT));              SetCursor (LoadCursor (NULL, IDC_WAIT));
684              err = ce->genKey (card_flags, name, email, n? comment: NULL,              err = ce->genKey (card_flags, name, email, n? comment: NULL,
685                                expires? valid : 0, NULL);                                expires? valid : 0, NULL);
               
686              SetCursor (LoadCursor (NULL, IDC_ARROW));              SetCursor (LoadCursor (NULL, IDC_ARROW));
687                            
688              if (gpgme_err_code (err) == GPG_ERR_CANCELED)              if (gpgme_err_code (err) == GPG_ERR_CANCELED)
# Line 720  card_keygen_dlg_proc (HWND dlg, UINT msg Line 700  card_keygen_dlg_proc (HWND dlg, UINT msg
700              wipememory (pass, sizeof (pass));              wipememory (pass, sizeof (pass));
701              free_pincb (&pincb);              free_pincb (&pincb);
702              delete ce;              delete ce;
703                EndDialog (dlg, TRUE);
704              return TRUE;              return TRUE;
705    
706          case IDCANCEL:          case IDCANCEL:
707              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
708              return FALSE;              return TRUE;
709          }          }
710          break;          break;
711      }      }
# Line 748  check_pin_len (int which, int flag, int Line 729  check_pin_len (int which, int flag, int
729      }      }
730      if (which == CARD_ADMIN_PIN      if (which == CARD_ADMIN_PIN
731          && pinlen < 8) {          && pinlen < 8) {
732          msg_box (NULL, _("Admin PIN must be minimal 8 characters."), _("Card Edit"), MB_ERR);          msg_box (NULL, _("Admin PIN must be at least 8 characters."), _("Card Edit"), MB_ERR);
733          return -1;          return -1;
734      }      }
735      if (which == CARD_USER_PIN      if (which == CARD_USER_PIN
736          && pinlen < 6) {          && pinlen < 6) {
737          msg_box (NULL, _("PIN must be minimal 6 characters."), _("Card Edit"), MB_ERR);          msg_box (NULL, _("PIN must be at least 6 characters."), _("Card Edit"), MB_ERR);
738          return -1;          return -1;
739      }      }
740      return 0;      return 0;
# Line 821  card_changepin_dlg_proc (HWND dlg, UINT Line 802  card_changepin_dlg_proc (HWND dlg, UINT
802                  return TRUE;                  return TRUE;
803              }              }
804    
805              ce = new GpgCardEdit ();              ce = create_GpgCardEdit ();
             if (!ce)  
                 BUG (0);  
806              if (which == CARD_ADMIN_PIN)              if (which == CARD_ADMIN_PIN)
807                  ce->setAdminPIN (pold);                  ce->setAdminPIN (pold);
808              else              else

Legend:
Removed from v.185  
changed lines
  Added in v.278

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26