/[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 25 by twoaday, Wed Oct 12 10:04:26 2005 UTC revision 28 by twoaday, Thu Oct 20 12:35:59 2005 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, 2004, 2005 Timo Schulz
3     *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
# Line 35  Line 36 
36  #include "wptUTF8.h"  #include "wptUTF8.h"
37  #include "wptCardEdit.h"  #include "wptCardEdit.h"
38  #include "wptCard.h"  #include "wptCard.h"
39    #include "wptContext.h"
40    
41  int keygen_check_date (SYSTEMTIME * st);  int keygen_check_date (SYSTEMTIME * st);
42    
# Line 56  struct { Line 58  struct {
58      {IDC_CEDIT_NAME,   "No Name"},      {IDC_CEDIT_NAME,   "No Name"},
59      {IDC_CEDIT_NAME2,  "No Surname"},      {IDC_CEDIT_NAME2,  "No Surname"},
60      {IDC_CEDIT_KEYURL, "No Key-URL"},      {IDC_CEDIT_KEYURL, "No Key-URL"},
61      {IDC_CEDIT_LOGIN,  "No Login name"},      {IDC_CEDIT_LOGIN,  "No Login name"},    
62      {0},      {0},
63  };  };
64    
65    
66    
67    /* XXX: simplify code. */
68    char*
69    get_printable_version (const char *version)
70    {
71        static char buf[16];
72        char tmp_maj[3]={0}, tmp_min[3]={0};
73    
74        strncpy (tmp_maj, version, 2);
75        strncpy (tmp_min, version+2, 2);
76        sprintf (buf, "%d.%d", atoi (tmp_maj), atoi (tmp_min));
77        return buf;
78    }
79    
80  /* Return all card attributes from @card. @n contains  /* Return all card attributes from @card. @n contains
81     the number of items which were returned. */     the number of items which were returned. */
82  char**  char**
# Line 74  card_get_items (gpg_card_t card, int *n) Line 90  card_get_items (gpg_card_t card, int *n)
90          BUG (0);          BUG (0);
91      p[0] = card->aid;      p[0] = card->aid;
92      p[1] = card->vendor;      p[1] = card->vendor;
93      p[2] = card->ver;      p[2] = get_printable_version (card->version);
94      p[3] = card->serial;      p[3] = card->serial;
95      p[4] = card->givenname;      p[4] = card->givenname;
96      p[5] = card->surname;      p[5] = card->surname;
# Line 93  idx_from_lang (const char * _lang) Line 109  idx_from_lang (const char * _lang)
109      if (!_lang)      if (!_lang)
110          return 0;          return 0;
111      for (i=0; (s = lang[i]); i++) {      for (i=0; (s = lang[i]); i++) {
112          if (!strcmp( _lang, s ))          if (!strcmp (_lang, s ))
113              return i;              return i;
114      }      }
115      return 0;      return 0;
# Line 124  show_card_status (void) Line 140  show_card_status (void)
140     returned information.     returned information.
141     Return value: card context or NULL on error. */     Return value: card context or NULL on error. */
142  gpg_card_t  gpg_card_t
143  gpg_load_scard (void)  gpg_card_load (void)
144  {  {
145      gpgme_error_t err;      gpgme_error_t err;
146      GpgCardEdit *ce;      GpgCardEdit *ce;
# Line 147  gpg_load_scard (void) Line 163  gpg_load_scard (void)
163          gpg_card_release (card);          gpg_card_release (card);
164          card = NULL;          card = NULL;
165      }      }
166        else {
167            struct winpt_key_s key;
168            memset (&key, 0, sizeof (key));
169            winpt_get_pubkey (card->fpr[1]+32, &key);
170            if (key.ext) {
171                key.ext->card_type = strdup (card->card_type);
172                if (!key.ext->card_type)
173                    BUG (NULL);
174                /* memory will be released in gpg_keycache_release (). */
175            }
176        }
177    
178  leave:  leave:
179      delete ce;      delete ce;
# Line 186  static int Line 213  static int
213  card_status (HWND dlg, gpg_card_t card)  card_status (HWND dlg, gpg_card_t card)
214  {  {
215      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};
216      const char * s;      static int fprtime[] = {IDC_CEDIT_SIG_FPRTIME, IDC_CEDIT_DEC_FPRTIME, IDC_CEDIT_AUTH_FPRTIME, 0};
217        const char *s;
218      char **attrs;      char **attrs;
219        char cardinf[128];
220      int idx=0, n=0;      int idx=0, n=0;
221    
222      if (!card->aid) {      if (!card->aid) {
# Line 197  card_status (HWND dlg, gpg_card_t card) Line 226  card_status (HWND dlg, gpg_card_t card)
226      SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid);      SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid);
227      SetDlgItemInt (dlg, IDC_CEDIT_SIGCOUNT, card->sig_count, TRUE);      SetDlgItemInt (dlg, IDC_CEDIT_SIGCOUNT, card->sig_count, TRUE);
228    
229      for( idx=0; fprbuf[idx]; idx++ )      for (idx=0; fprbuf[idx]; idx++) {
230          print_fpr (dlg, fprbuf[idx], card->fpr[idx]);          print_fpr (dlg, fprbuf[idx], card->fpr[idx]);
231            SetDlgItemText (dlg, fprtime[idx], card->fpr_created_str[idx]);
232        }
233    
234      attrs = card_get_items (card, &n);      attrs = card_get_items (card, &n);
     /* XXX: show version as 1.1 not 0101 */  
235      for (idx=1; attr_tab[idx].ctlid; idx++) {      for (idx=1; attr_tab[idx].ctlid; idx++) {
236          s = attrs[idx];          s = attrs[idx];
237          SetDlgItemText (dlg, attr_tab[idx].ctlid, s && *s? s : attr_tab[idx].err);          SetDlgItemText (dlg, attr_tab[idx].ctlid, s && *s? s : attr_tab[idx].err);
# Line 219  card_status (HWND dlg, gpg_card_t card) Line 249  card_status (HWND dlg, gpg_card_t card)
249      }      }
250      SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, (WPARAM)idx, 0);      SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, (WPARAM)idx, 0);
251    
252        s = card->serial;
253        while (s && *s == '0') s++;
254        _snprintf (cardinf, sizeof (cardinf)-1,
255                   "Card Edit - %s serial no. %s version %s",
256                   card->card_type, s, get_printable_version (card->version));
257        SetWindowText (dlg, cardinf);
258    
259      return 0;      return 0;
260  }  }
261    
# Line 230  prepare_dialog (HWND dlg) Line 267  prepare_dialog (HWND dlg)
267      const char * s;      const char * s;
268      int i;      int i;
269    
270      for( i=0; (s = sex[i]); i++ )      for (i=0; (s = sex[i]); i++)
271          SendDlgItemMessage( dlg, IDC_CEDIT_SEX, CB_ADDSTRING, 0, (LPARAM) s );          SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_ADDSTRING, 0, (LPARAM) s);
272      SendDlgItemMessage( dlg, IDC_CEDIT_SEX, CB_SETCURSEL, 0, 0 );      SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, 0, 0);
273      for( i=0; (s = lang[i]); i++ )      for (i=0; (s = lang[i]); i++)
274          SendDlgItemMessage( dlg, IDC_CEDIT_LANG, CB_ADDSTRING, 0, (LPARAM)s );          SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_ADDSTRING, 0, (LPARAM)s);
275      SendDlgItemMessage( dlg, IDC_CEDIT_LANG, CB_SETCURSEL, 0, 0 );      SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_SETCURSEL, 0, 0);
276  }  }
277    
278    
   
279  /* Return 0 if the given string @str has the proper format. */  /* Return 0 if the given string @str has the proper format. */
280  static int  static int
281  check_string (const char *str, int flags)  check_string (const char *str, int flags)
282  {  {
283      size_t i;      size_t i;
284      for( i=0; i < strlen( str ); i++ ) {      for (i=0; i < strlen (str); i++) {
285          if( flags & 0x02 && !isalpha( str[i] ) )          if (flags & 0x02 && !isalpha (str[i]))
286              return -1;              return -1;
287      }      }
288      return 0;      return 0;
# Line 254  check_string (const char *str, int flags Line 290  check_string (const char *str, int flags
290    
291    
292  static int  static int
293  do_proc_card_cmds (HWND dlg, struct pin_cb_ctx_s * pincb, gpg_card_t card)  do_proc_card_cmds (HWND dlg, struct pin_cb_ctx_s *pincb, gpg_card_t card)
294  {  {
295      static struct {      static struct {
296          int id;          int id;
# Line 265  do_proc_card_cmds (HWND dlg, struct pin_ Line 301  do_proc_card_cmds (HWND dlg, struct pin_
301          {IDC_CEDIT_NAME,  GPG_EDITCARD_NAME,  1,  0},          {IDC_CEDIT_NAME,  GPG_EDITCARD_NAME,  1,  0},
302          {IDC_CEDIT_LANG2, GPG_EDITCARD_LANG,  1,  0},          {IDC_CEDIT_LANG2, GPG_EDITCARD_LANG,  1,  0},
303          {IDC_CEDIT_SEX2,  GPG_EDITCARD_SEX,   1|1,0},          {IDC_CEDIT_SEX2,  GPG_EDITCARD_SEX,   1|1,0},
304          {IDC_CEDIT_KEYURL,GPG_EDITCARD_KEYURL,1,  0},          {IDC_CEDIT_KEYURL,GPG_EDITCARD_KEYURL,1|4,0},
305          {IDC_CEDIT_LOGIN, GPG_EDITCARD_LOGIN, 1,  0},          {IDC_CEDIT_LOGIN, GPG_EDITCARD_LOGIN, 1,  0},
306          {0}          {0}
307      };          };    
# Line 298  do_proc_card_cmds (HWND dlg, struct pin_ Line 334  do_proc_card_cmds (HWND dlg, struct pin_
334              n++;              n++;
335          }          }
336      }      }
337      if( !pincb || !card ) /* just return the changed elements */      if (!pincb || !card) /* just return the changed elements */
338          return n;          return n;
339      if( !n )      if (!n)
340            return 0;
341        if (!pincb->apin) {
342            msg_box (dlg, _("No PINs found."), _("Card Edit"), MB_ERR);
343          return 0;          return 0;
344        }
345            
346      ce = new GpgCardEdit ();      ce = new GpgCardEdit ();
347      if (!ce)      if (!ce)
348          BUG( NULL );          BUG (NULL);
349      ce->setAdminPIN (pincb->apin);      ce->setAdminPIN (pincb->apin);
350      ce->setPIN (pincb->upin);      /*ce->setPIN (pincb->upin);*/
351      for( i=0; idctl[i].id; i++ ) {      for( i=0; idctl[i].id; i++ ) {
352          if( idctl[i].changed ) {          if( idctl[i].changed ) {
353              GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 );              GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 );
# Line 321  do_proc_card_cmds (HWND dlg, struct pin_ Line 361  do_proc_card_cmds (HWND dlg, struct pin_
361                           _("Card Edit"), MB_ERR );                           _("Card Edit"), MB_ERR );
362                  errc--; continue;                  errc--; continue;
363              }              }
364                if ((idctl[i].us_ascii & 4) &&
365                    (!strchr (buf, ':') || !strstr (buf, "//"))) {
366                    /* XXX: better URL check. */
367                    msg_box (dlg, _("Invalid URL."), _("Card Edit"), MB_ERR);
368                    errc--; continue;
369                }
370              if( idctl[i].cmd == GPG_EDITCARD_NAME ) {              if( idctl[i].cmd == GPG_EDITCARD_NAME ) {
371                  /* The "name" command actually needs two fields */                  /* The "name" command actually needs two fields */
372                  GetDlgItemText( dlg, IDC_CEDIT_NAME2, tmp, sizeof tmp-1 );                  GetDlgItemText( dlg, IDC_CEDIT_NAME2, tmp, sizeof tmp-1 );
# Line 330  do_proc_card_cmds (HWND dlg, struct pin_ Line 376  do_proc_card_cmds (HWND dlg, struct pin_
376                  use_arg2 = 0;                  use_arg2 = 0;
377              err = ce->doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL);              err = ce->doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL);
378              if (err) {              if (err) {
379                  msg_box( dlg, _("Could not modify card attribute."),                  log_box (_("Card Edit"), MB_ERR,
380                           _("Card Edit"), MB_ERR );                           _("Could not modify card attribute: %s"),
381                             gpgme_strerror (err));
382                  errc--;                  errc--;
383                    /* If no card is inserted, we leave the loop. */
384                    if (gpgme_err_code (err) == GPG_ERR_CARD_NOT_PRESENT)
385                        break;
386              }              }
387          }          }
388      }      }
389      if( !errc ) {      if (!errc) {
390          /* if the operation(s) succeeded, reset the modify flag for each control */          /* if the operation(s) succeeded, reset the modify flag for each control */
391          for( i = 0; idctl[i].id; i++ )          for( i = 0; idctl[i].id; i++ )
392              SendDlgItemMessage( dlg, idctl[i].id, EM_SETMODIFY, (WPARAM)(UINT)FALSE, 0 );              SendDlgItemMessage( dlg, idctl[i].id, EM_SETMODIFY, (WPARAM)(UINT)FALSE, 0 );
# Line 375  do_askpin (HWND dlg, int which, gpg_card Line 425  do_askpin (HWND dlg, int which, gpg_card
425      char * p;      char * p;
426      size_t n;      size_t n;
427    
428      if( (which == GPG_EDITCARD_CHAPIN && pincb->apin) ||      if( (which == CARD_ADMIN_PIN && pincb->apin) ||
429          (which == GPG_EDITCARD_CHUPIN && pincb->upin) )          (which == CARD_USER_PIN && pincb->upin) )
430          return 0;          return 0;
431            
432      if( which == GPG_EDITCARD_CHAPIN )      if (which == CARD_ADMIN_PIN)
433          s = _("Please enter the 'Admin PIN'");          s = _("Please enter the 'Admin PIN'");
434      else if( which == GPG_EDITCARD_CHUPIN )      else if (which == CARD_USER_PIN)
435          s = _("Please enter the 'User PIN'");          s = _("Please enter the 'User PIN'");
436      else      else
437          s = _("Please enter the PIN");          s = _("Please enter the PIN");
# Line 409  do_askpin (HWND dlg, int which, gpg_card Line 459  do_askpin (HWND dlg, int which, gpg_card
459              BUG (0);              BUG (0);
460      }      }
461      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg,      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg,
462                      pin_cb_dlg_proc, (LPARAM)pincb);                      pin_cb_dlg_proc, (LPARAM)pincb);
463      if (!pincb->apin && !pincb->upin) {      if (!pincb->apin && !pincb->upin) {
464          safe_free (pincb->info_text);          safe_free (pincb->info_text);
465          return -1;          return -1;
# Line 439  card_edit_dlg_proc (HWND dlg, UINT msg, Line 489  card_edit_dlg_proc (HWND dlg, UINT msg,
489          return TRUE;          return TRUE;
490    
491      case WM_DESTROY:      case WM_DESTROY:
492          free_if_alloc (pincb.info_text);          free_pincb (&pincb);
         sfree_if_alloc (pincb.apin);  
         sfree_if_alloc (pincb.upin);  
493          memset (&pincb, 0, sizeof pincb);          memset (&pincb, 0, sizeof pincb);
494          break;          break;
495    
# Line 457  card_edit_dlg_proc (HWND dlg, UINT msg, Line 505  card_edit_dlg_proc (HWND dlg, UINT msg,
505              case IDC_CEDIT_LANG: dstid = IDC_CEDIT_LANG2; break;              case IDC_CEDIT_LANG: dstid = IDC_CEDIT_LANG2; break;
506              case IDC_CEDIT_SEX:  dstid = IDC_CEDIT_SEX2; break;              case IDC_CEDIT_SEX:  dstid = IDC_CEDIT_SEX2; break;
507              }                    }      
508              GetDlgItemText (dlg, ctlid, tmp, 127);              GetDlgItemText (dlg, ctlid, tmp, sizeof (tmp)-1);
509              SetDlgItemText (dlg, dstid, tmp);              SetDlgItemText (dlg, dstid, tmp);
510              break;              break;
511          }          }
512          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
513          case IDC_CEDIT_CHPIN:          case IDC_CEDIT_CHPIN:
514              DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_CARD_CHPIN, dlg,              DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_CARD_CHPIN, dlg,
515                              card_changepin_dlg_proc, NULL );                              card_changepin_dlg_proc, NULL );
# Line 480  card_edit_dlg_proc (HWND dlg, UINT msg, Line 528  card_edit_dlg_proc (HWND dlg, UINT msg,
528              break;              break;
529    
530          case IDOK:          case IDOK:
531              n = do_proc_card_cmds( dlg, NULL, NULL );              n = do_proc_card_cmds (dlg, NULL, NULL);
532              if( n ) {              if (n) {
533                  if( do_askpin( dlg, GPG_EDITCARD_CHAPIN, card, &pincb ) )                  if (do_askpin (dlg, CARD_ADMIN_PIN, card, &pincb))
534                      EndDialog( dlg, FALSE );                      EndDialog (dlg, FALSE);
535                  if( do_askpin( dlg, GPG_EDITCARD_CHUPIN, card, &pincb ) )              }
536                      EndDialog( dlg, FALSE );              do_proc_card_cmds (dlg, &pincb, card);
537              }              free_pincb (&pincb);
538              do_proc_card_cmds( dlg, &pincb, card );              if (!n)
539              free_pincb( &pincb );                  EndDialog (dlg, TRUE);
             if( !n )  
                 EndDialog( dlg, TRUE );  
540              break;              break;
541    
542          case IDCANCEL:          case IDCANCEL:
# Line 527  calc_days (int y2, int m2, int d2, Line 573  calc_days (int y2, int m2, int d2,
573  BOOL CALLBACK  BOOL CALLBACK
574  card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
575  {  {
     static int state = 0;  
     static int pwd_state = 0;  
576      gpgme_error_t err;      gpgme_error_t err;
577      GpgCardEdit *ce;      GpgCardEdit *ce;
578      char name[128], email[128], comment[128];      char name[128], email[128], comment[128];
# Line 539  card_keygen_dlg_proc (HWND dlg, UINT msg Line 583  card_keygen_dlg_proc (HWND dlg, UINT msg
583    
584      switch (msg) {      switch (msg) {
585      case WM_INITDIALOG:      case WM_INITDIALOG:
         state = 0;  
         pwd_state = 1;  
586          center_window (dlg, NULL);          center_window (dlg, NULL);
587          CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED);          CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED);
588          CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED);          CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED);
589          CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED);          CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED);
590          EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), FALSE);          EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), FALSE);
591          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0, (LPARAM)(const char*)"RSA");          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0,
592                                (LPARAM)(const char*)"RSA");
593          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0);          SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0);
594          SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME));          SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME));
595          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
596          return FALSE;          return FALSE;
597    
598        case WM_SYSCOMMAND:
599            if (LOWORD (wparam) == SC_CLOSE)
600                EndDialog (dlg, TRUE);
601            return FALSE;
602    
603      case WM_COMMAND:      case WM_COMMAND:
604          if (HIWORD (wparam) == BN_CLICKED) {          if (HIWORD (wparam) == BN_CLICKED &&
605              switch (LOWORD (wparam)) {              (LOWORD (wparam) == IDC_CKEYGEN_BACKUP) ||
606              case IDC_CKEYGEN_NEVER:                       LOWORD (wparam) == IDC_CKEYGEN_NEVER) {
607                  state ^= 1;              EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID),
608                  EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), state);                            IsDlgButtonChecked (dlg, IDC_CKEYGEN_NEVER)? 0: 1);
609                  break;              EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_PASS),
610                              IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)? 1 : 0);
611              case IDC_CKEYGEN_BACKUP:              return TRUE;
612                  pwd_state ^= 1;          }      
                 EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_PASS), pwd_state);  
                 break;  
             }  
         }  
613    
614          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
615          case IDOK:          case IDOK:
# Line 593  card_keygen_dlg_proc (HWND dlg, UINT msg Line 637  card_keygen_dlg_proc (HWND dlg, UINT msg
637                  return TRUE;                  return TRUE;
638              }              }
639              n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1);              n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1);
640              if (!n && pwd_state == 1) {              if (!n && IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)) {
641                  msg_box (dlg, _("Please enter an off-card passphrase."), _("Card Edit"), MB_ERR);                  msg_box (dlg, _("Please enter an off-card passphrase."), _("Card Edit"), MB_ERR);
642                  return TRUE;                  return TRUE;
643              }              }
644              n = item_get_text_length (dlg, IDC_CKEYGEN_COMMENT);              n = item_get_text_length (dlg, IDC_CKEYGEN_COMMENT);
645              if (n > 0)              if (n > 0)
646                  GetDlgItemText (dlg, IDC_CKEYGEN_COMMENT, comment, sizeof (comment)-1);                  GetDlgItemText (dlg, IDC_CKEYGEN_COMMENT, comment, sizeof (comment)-1);
647              if (is_8bit_string (name) ||is_8bit_string (comment)) {              if (is_8bit_string (name) || n > 0 && is_8bit_string (comment)) {
648                  msg_box (dlg, _("Please use plain ASCII charset for the fields."),                  msg_box (dlg, _("Please use plain ASCII charset for the fields."),
649                           _("Card Edit"), MB_INFO);                           _("Card Edit"), MB_INFO);
650                  return TRUE;                  return TRUE;
651              }              }
652              memset (&pincb, 0, sizeof (pincb));              memset (&pincb, 0, sizeof (pincb));
653              if (do_askpin (dlg, GPG_EDITCARD_CHAPIN, NULL, &pincb)) {              if (do_askpin (dlg, CARD_ADMIN_PIN, NULL, &pincb)) {
654                  free_pincb (&pincb);                  free_pincb (&pincb);
655                  return TRUE;                  return TRUE;
656              }              }
657              if (do_askpin (dlg, GPG_EDITCARD_CHUPIN, NULL, &pincb)) {              if (do_askpin (dlg, CARD_USER_PIN, NULL, &pincb)) {
658                  free_pincb (&pincb);                  free_pincb (&pincb);
659                  return TRUE;                  return TRUE;
660              }              }
# Line 625  card_keygen_dlg_proc (HWND dlg, UINT msg Line 669  card_keygen_dlg_proc (HWND dlg, UINT msg
669                  if (!keygen_check_date (&st)) {                  if (!keygen_check_date (&st)) {
670                      msg_box (dlg, _("The date you have chosen lies in the past."),                      msg_box (dlg, _("The date you have chosen lies in the past."),
671                               _("Card Edit"), MB_ERR);                               _("Card Edit"), MB_ERR);
672                        free_pincb (&pincb);
673                      delete ce;                      delete ce;
674                      return TRUE;                      return TRUE;
675                  }                  }
# Line 641  card_keygen_dlg_proc (HWND dlg, UINT msg Line 686  card_keygen_dlg_proc (HWND dlg, UINT msg
686              ce->setPIN (pincb.upin);              ce->setPIN (pincb.upin);
687              ce->setAdminPIN (pincb.apin);              ce->setAdminPIN (pincb.apin);
688                            
689              SetCursor( LoadCursor (NULL, IDC_WAIT));              SetCursor (LoadCursor (NULL, IDC_WAIT));
690              err = ce->genKey (card_flags, name, email, n? comment: NULL,              err = ce->genKey (card_flags, name, email, n? comment: NULL,
691                                expires? valid : 0);                                expires? valid : 0, NULL);
692                            
693              SetCursor (LoadCursor (NULL, IDC_ARROW));              SetCursor (LoadCursor (NULL, IDC_ARROW));
694              /*              
695              if (gpgme_err_code (err) == GPG_ERR_CANCELLED)              if (gpgme_err_code (err) == GPG_ERR_CANCELED)
696                  msg_box (dlg, _("Operation was canceled. It seems that there are "                  msg_box (dlg, _("Operation was canceled. It seems that there are "
697                                  "existing\nkeys on the cards. You need to mark the "                                  "existing\nkeys on the cards. You need to mark the "
698                                  "'Overwrite' flag."), _("Card Edit"), MB_INFO);                                  "'Overwrite' flag."), _("Card Edit"), MB_INFO);
699              else */              else
700              if (err)              if (err)
701                  msg_box (dlg, "The operation does not succeed.\n"                  msg_box (dlg, "The operation does not succeed.\n"
702                                "Please make sure you entered the right PIN's."                                "Please make sure you entered the right PIN's."
# Line 662  card_keygen_dlg_proc (HWND dlg, UINT msg Line 707  card_keygen_dlg_proc (HWND dlg, UINT msg
707              memset (pass, 0, sizeof (pass));              memset (pass, 0, sizeof (pass));
708              free_pincb (&pincb);              free_pincb (&pincb);
709              delete ce;              delete ce;
710              break;              return TRUE;
711    
712          case IDCANCEL:          case IDCANCEL:
713              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
# Line 688  check_pin_len (int which, int flag, int Line 733  check_pin_len (int which, int flag, int
733              msg_box (NULL, _("Please enter the new card PIN."), _("Card Edit"), MB_ERR);              msg_box (NULL, _("Please enter the new card PIN."), _("Card Edit"), MB_ERR);
734          return -1;          return -1;
735      }      }
736      if (which == GPG_EDITCARD_CHAPIN      if (which == CARD_ADMIN_PIN
737          && pinlen < 8) {          && pinlen < 8) {
738          msg_box (NULL, _("Admin PIN must be minimal 8 characters."), _("Card Edit"), MB_ERR);          msg_box (NULL, _("Admin PIN must be minimal 8 characters."), _("Card Edit"), MB_ERR);
739          return -1;          return -1;
740      }      }
741      if (which == GPG_EDITCARD_CHUPIN      if (which == CARD_USER_PIN
742          && pinlen < 6) {          && pinlen < 6) {
743          msg_box (NULL, _("PIN must be minimal 6 characters."), _("Card Edit"), MB_ERR);          msg_box (NULL, _("PIN must be minimal 6 characters."), _("Card Edit"), MB_ERR);
744          return -1;          return -1;
# Line 725  card_changepin_dlg_proc (HWND dlg, UINT Line 770  card_changepin_dlg_proc (HWND dlg, UINT
770          if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_CHPIN_HIDE) {                    if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_CHPIN_HIDE) {          
771              HWND hwnd;              HWND hwnd;
772              hide ^= 1;              hide ^= 1;
773                hwnd = GetDlgItem (dlg, IDC_CHPIN_OLDPIN);
774                SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
775                SetFocus (hwnd);
776              hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN);              hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN);
777              SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);              SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
778              SetFocus (hwnd);              SetFocus (hwnd);
# Line 735  card_changepin_dlg_proc (HWND dlg, UINT Line 783  card_changepin_dlg_proc (HWND dlg, UINT
783          switch( LOWORD( wparam ) ) {          switch( LOWORD( wparam ) ) {
784          case IDOK:          case IDOK:
785              if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISADMIN))              if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISADMIN))
786                  which = GPG_EDITCARD_CHAPIN;                  which = CARD_ADMIN_PIN;
787              else if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISWORK))              else if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISWORK))
788                  which = GPG_EDITCARD_CHUPIN;                  which = CARD_USER_PIN;
             else  
                 BUG (0);  
789    
790              n = item_get_text_length (dlg, IDC_CHPIN_OLDPIN);              n = item_get_text_length (dlg, IDC_CHPIN_OLDPIN);
791              if (check_pin_len (which, 1, n))              if (check_pin_len (which, 1, n))
# Line 754  card_changepin_dlg_proc (HWND dlg, UINT Line 800  card_changepin_dlg_proc (HWND dlg, UINT
800              GetDlgItemText (dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1);              GetDlgItemText (dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1);
801              GetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, pnew2, sizeof (pnew2)-1);              GetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, pnew2, sizeof (pnew2)-1);
802              if (strcmp (pnew, pnew2)) {              if (strcmp (pnew, pnew2)) {
803                  msg_box (dlg, _("Passphrases do not match. Please try again."), _("Card Edit"), MB_ERR);                  msg_box (dlg, _("Passphrases do not match. Please try again."),
804                             _("Card Edit"), MB_ERR);
805                  return TRUE;                  return TRUE;
806              }              }
807    
808              ce = new GpgCardEdit ();              ce = new GpgCardEdit ();
809              if (!ce)              if (!ce)
810                  BUG (0);                  BUG (0);
811              ce->setPIN (pold);              if (which == CARD_ADMIN_PIN)
812                    ce->setAdminPIN (pold);
813                else
814                    ce->setPIN (pold);
815              ce->setNewPIN (pnew);              ce->setNewPIN (pnew);
816              ce->setType (which);              err = ce->changePIN (which == CARD_ADMIN_PIN? GPG_EDITCARD_CHAPIN :
817                                     GPG_EDITCARD_CHUPIN);
             err = ce->changePIN ();  
818              if (err)              if (err)
819                  msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR);
820              else {              else {
821                  msg_box( dlg, _("PIN successfully changed."), _("Card Edit"), MB_OK );                  msg_box (dlg, _("PIN successfully changed."),
822                             _("Card Edit"), MB_OK);
823                  SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, "");                  SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, "");
824                  SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, "");                  SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, "");
825                  SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, "");                  SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, "");
826              }              }
827                memset (pold, 0, sizeof (pold));
828                memset (pnew, 0, sizeof (pnew));
829                memset (pnew2, 0, sizeof (pnew2));
830              delete ce;              delete ce;
831              break;              break;
832    
# Line 781  card_changepin_dlg_proc (HWND dlg, UINT Line 834  card_changepin_dlg_proc (HWND dlg, UINT
834              SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, "");              SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, "");
835              SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, "");              SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, "");
836              SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, "");              SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, "");
837              EndDialog( dlg, FALSE );              EndDialog (dlg, FALSE);
838              break;              break;
839          }          }
840          break;          break;

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26