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

Diff of /trunk/Src/wptPassphraseCB.cpp

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

revision 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC
# Line 39  Line 39 
39  #define item_ctrl_id( cmd ) \  #define item_ctrl_id( cmd ) \
40      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)
41    
42    #define item_ctrl_id2(cmd) \
43        ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_HIDE : IDC_DECRYPT_SIGN_HIDE)
44    
45    
46  BOOL CALLBACK  BOOL CALLBACK
47  passphrase_callback_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  passphrase_callback_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
48  {      {    
49      static passphrase_cb_s * c;      static passphrase_cb_s * c;
     static int yes = 1;  
50      gpgme_key_t key;      gpgme_key_t key;
51      const char * s, * id;      const char * s, * id;
52      char info[768] = {0};      char info[768] = {0};
# Line 54  passphrase_callback_proc( HWND dlg, UINT Line 56  passphrase_callback_proc( HWND dlg, UINT
56      switch( msg )  {      switch( msg )  {
57      case WM_INITDIALOG:      case WM_INITDIALOG:
58          c = (passphrase_cb_s *)lparam;          c = (passphrase_cb_s *)lparam;
59          if( !c )          if (!c)
60              BUG( NULL );              BUG (0);
61          SetWindowText( dlg, c->title );          SetWindowText (dlg, c->title);
62          if( c->gpg_cmd == GPG_CMD_DECRYPT ) {          if (c->gpg_cmd == GPG_CMD_DECRYPT) {
63              SetDlgItemText( dlg, IDC_DECRYPT_LISTINF,              SetDlgItemText( dlg, IDC_DECRYPT_LISTINF,
64                  _("Encrypted with the following public key(s)") );                  _("Encrypted with the following public key(s)") );
65              CheckDlgButton( dlg, IDC_DECRYPT_HIDE, BST_CHECKED );              CheckDlgButton( dlg, IDC_DECRYPT_HIDE, BST_CHECKED );
# Line 116  passphrase_callback_proc( HWND dlg, UINT Line 118  passphrase_callback_proc( HWND dlg, UINT
118                  if ( LOWORD( wparam ) == IDC_DECRYPT_HIDE                  if ( LOWORD( wparam ) == IDC_DECRYPT_HIDE
119                      || LOWORD( wparam ) == IDC_DECRYPT_SIGN_HIDE ) {                      || LOWORD( wparam ) == IDC_DECRYPT_SIGN_HIDE ) {
120                      HWND hwnd;                      HWND hwnd;
121                      yes ^= 1;                      int hide = IsDlgButtonChecked (dlg, item_ctrl_id2 (c->gpg_cmd));
122                      hwnd = GetDlgItem( dlg, item_ctrl_id( c->gpg_cmd ) );                      hwnd = GetDlgItem (dlg, item_ctrl_id (c->gpg_cmd));
123                      SendMessage( hwnd, EM_SETPASSWORDCHAR, yes? '*' : 0, 0 );                      SendMessage( hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0 );
124                      SetFocus( hwnd );                      SetFocus (hwnd);
125                  }                  }
126              }              }
127    
128              switch( LOWORD( wparam ) ) {              switch (LOWORD (wparam)) {
129              case IDOK:              case IDOK:  
130                  /* fixme: the item is even cached when the passphrase is not                  /* fixme: the item is even cached when the passphrase is not
131                            correct, which means that the user needs to delete all                            correct, which means that the user needs to delete all
132                            cached entries to continue. */                            cached entries to continue. */
133                  GetDlgItemText( dlg, item_ctrl_id( c->gpg_cmd ), c->pwd, sizeof c->pwd -1 );                  GetDlgItemText (dlg, item_ctrl_id (c->gpg_cmd), c->pwd, sizeof (c->pwd) -1);
134                  if( reg_prefs.cache_time > 0 && !c->is_card ) {                  if (reg_prefs.cache_time > 0 && !c->is_card && !strstr (c->keyid, "missing")) {
135                      if( agent_get_cache( c->keyid, &item ) )                                          if (agent_get_cache (c->keyid, &item))
136                          agent_unlock_cache_entry( &item );                          agent_unlock_cache_entry (&item);
137                      else                      else
138                          agent_put_cache( c->keyid, c->pwd, reg_prefs.cache_time );                          agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);
139                  }                  }
140                  EndDialog( dlg, TRUE );                  EndDialog (dlg, TRUE);
141                  return TRUE;                  return TRUE;
142                                    
143              case IDCANCEL:              case IDCANCEL:
144                  SetDlgItemText( dlg, item_ctrl_id( c->gpg_cmd ), ""  );                  SetDlgItemText (dlg, item_ctrl_id (c->gpg_cmd), "" );
145                  c->cancel = 1;                  c->cancel = 1;
146                  EndDialog( dlg, FALSE );                  EndDialog (dlg, FALSE);
147                  return FALSE;                  return FALSE;
148              }              }
149              break;              break;
# Line 152  passphrase_callback_proc( HWND dlg, UINT Line 154  passphrase_callback_proc( HWND dlg, UINT
154    
155    
156  static const char *  static const char *
157  parse_gpg_keyid( const char * desc )  parse_gpg_keyid (const char * desc)
158  {  {
159      static char keyid[16+1];      static char keyid[16+1];
160      char * p;      char * p;
161            
162      p = strrchr( desc, '\n' );      p = strrchr (desc, '\n');
163      if( !p )      if( !p )
164          return NULL;          return NULL;
165      /* the format of the desc buffer looks like this:      /* the format of the desc buffer looks like this:
166         request_keyid[16] main_keyid[16] keytype[1] keylength[4]         request_keyid[16] main_keyid[16] keytype[1] keylength[4]
167         we use the main keyid to use only one cache entry. */         we use the main keyid to use only one cache entry. */
168      strncpy( keyid, desc+(p-desc+1+17), 16 );      strncpy (keyid, desc+(p-desc+1+17), 16);
169      return keyid;      return keyid;
170  } /* parse_gpg_keyid */  } /* parse_gpg_keyid */
171    
# Line 262  passphrase_cb( void * opaque, const char Line 264  passphrase_cb( void * opaque, const char
264          return NULL;          return NULL;
265    
266      if( desc ) {      if( desc ) {
267          keyid = parse_gpg_keyid( desc );          keyid = parse_gpg_keyid (desc);
268          pass = agent_get_cache( keyid, &item );          pass = agent_get_cache( keyid, &item );
269          if( pass ) {          if( pass ) {
270              agent_unlock_cache_entry( &item );              agent_unlock_cache_entry( &item );
# Line 285  passphrase_cb( void * opaque, const char Line 287  passphrase_cb( void * opaque, const char
287                        "Card: %s"), buf );                        "Card: %s"), buf );
288              c->is_card = 1;              c->is_card = 1;
289          }          }
290          else if( desc ) {          else if(desc) {
291              strcpy( c->info, desc );              strcpy (c->info, desc);
292              parse_gpg_description( c->info, sizeof c->info - 1 );              parse_gpg_description (c->info, sizeof c->info - 1);
293          }          }
294          if( c->gpg_cmd == GPG_CMD_DECRYPT ) {          if( c->gpg_cmd == GPG_CMD_DECRYPT ) {
295              rc = DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_DECRYPT,              rc = DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_DECRYPT,
# Line 312  passphrase_cb( void * opaque, const char Line 314  passphrase_cb( void * opaque, const char
314    
315    
316  void  void
317  set_gpg_passphrase_cb( gpgme_ctx_t c, passphrase_cb_s * ctx, int cmd,  set_gpg_passphrase_cb (gpgme_ctx_t c, passphrase_cb_s *ctx, int cmd,
318                         HWND hwnd, const char * title )                         HWND hwnd, const char *title)
319  {  {
320      ctx->gpg_cmd = cmd;      ctx->gpg_cmd = cmd;
321      ctx->is_card = 0;      ctx->is_card = 0;
322      ctx->cancel = 0;      ctx->cancel = 0;
323      ctx->hwnd = hwnd;      ctx->hwnd = hwnd;
324      ctx->pwd_init = 1;      ctx->pwd_init = 1;
325      if( strlen( title ) > 256 )      if (strlen (title) > 256)
326          BUG( NULL ); /* check bounds */          BUG (NULL); /* check bounds */
327      strcpy( ctx->title, title );      strcpy (ctx->title, title);
328      gpgme_set_passphrase_cb( c, passphrase_cb, ctx );      gpgme_set_passphrase_cb (c, passphrase_cb, ctx);
329  } /* set_gpg_passphrase_cb */  } /* set_gpg_passphrase_cb */
330    
331    
332    int
333    check_passwd_quality (const char *pass, int strict)
334    {
335        int i, nd=0, nc=0, n;
336    
337        n = strlen (pass);
338        if (n < 8)
339            return -1;
340    
341        for (i=0; i < n; i++) {
342            if (isdigit (pass[i])) nd++;
343            if (isalpha (pass[i])) nc++;
344        }
345    
346        if (nd == n || nc == n)
347            return -1;
348    
349        return 0;
350    }

Legend:
Removed from v.2  
changed lines
  Added in v.22

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26