/[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 24 by twoaday, Sat Oct 8 10:43:08 2005 UTC revision 25 by twoaday, Wed Oct 12 10:04:26 2005 UTC
# Line 37  Line 37 
37  #include "wptAgent.h"  #include "wptAgent.h"
38  #include "wptRegistry.h"  #include "wptRegistry.h"
39    
40    const char* get_symkey_algo (int algo);
41    
42  #define item_ctrl_id( cmd ) \  #define item_ctrl_id( cmd ) \
43      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)
# Line 53  passphrase_callback_proc (HWND dlg, UINT Line 54  passphrase_callback_proc (HWND dlg, UINT
54      gpgme_decrypt_result_t res;      gpgme_decrypt_result_t res;
55      gpgme_sign_result_t res_sig;      gpgme_sign_result_t res_sig;
56      gpgme_key_t key;      gpgme_key_t key;
57        void *ctx = NULL, *item;
58      const char *id;      const char *id;
59      char *info;      char *info;
     void *ctx = NULL, *item;  
60      int n;      int n;
61    
62      switch (msg) {      switch (msg) {
# Line 69  passphrase_callback_proc (HWND dlg, UINT Line 70  passphrase_callback_proc (HWND dlg, UINT
70                  _("Encrypted with the following public key(s)") );                  _("Encrypted with the following public key(s)") );
71              CheckDlgButton( dlg, IDC_DECRYPT_HIDE, BST_CHECKED );              CheckDlgButton( dlg, IDC_DECRYPT_HIDE, BST_CHECKED );
72          }          }
73          else if( c->gpg_cmd == GPG_CMD_SIGN )          else if (c->gpg_cmd == GPG_CMD_SIGN)
74              CheckDlgButton (dlg, IDC_DECRYPT_SIGN_HIDE, BST_CHECKED);              CheckDlgButton (dlg, IDC_DECRYPT_SIGN_HIDE, BST_CHECKED);
75          res = gpgme_op_decrypt_result (c->gpg);          res = gpgme_op_decrypt_result (c->gpg);
76          if (res != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) {          if (res != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) {
77              gpgme_recipient_t r;              gpgme_recipient_t r;
78    
79                /* XXX: not all ENCRYPT_TO entries are listed here. */
80              for (r = res->recipients; r; r = r->next) {              for (r = res->recipients; r; r = r->next) {
81                  get_pubkey (r->keyid, &key);                  get_pubkey (r->keyid, &key);
82                  if (key) {                  if (key) {
# Line 83  passphrase_callback_proc (HWND dlg, UINT Line 85  passphrase_callback_proc (HWND dlg, UINT
85                      if (!id)                      if (!id)
86                          id = _("Invalid User ID");                          id = _("Invalid User ID");
87                      uid = utf8_to_wincp (id, strlen (id));                      uid = utf8_to_wincp (id, strlen (id));
88                      info = new char [16+strlen (uid) + 4 + strlen (r->keyid) + strlen (key->uids->email) +  3];                      info = new char [32+strlen (uid)+1 + 4 + strlen (r->keyid)+1
89                                         + strlen (key->uids->email)+1];
90                      if (!info)                      if (!info)
91                          BUG (NULL);                          BUG (NULL);
92                      sprintf (info, "%s <%s> (%s, 0x%s)", uid, key->uids->email,                      sprintf (info, "%s <%s> (%s, 0x%s)", uid, key->uids->email,
# Line 92  passphrase_callback_proc (HWND dlg, UINT Line 95  passphrase_callback_proc (HWND dlg, UINT
95                                            
96                  }                  }
97                  else {                  else {
98                      info = new char [32 + strlen (r->keyid) + 2];                      info = new char [32 + strlen (r->keyid)+1 + 4];
99                      if (!info)                      if (!info)
100                          BUG (NULL);                          BUG (NULL);
101                      sprintf (info, _("Unknown (key ID 0x%s)"),                      sprintf (info, _("Unknown key ID (%s, 0x%s)"),
102                               r->keyid? r->keyid+8 : "????????");                               get_key_pubalgo (r->pubkey_algo), r->keyid+8);
103                  }                  }
104                  listbox_add_string (GetDlgItem (dlg, IDC_DECRYPT_LIST), info);                  listbox_add_string (GetDlgItem (dlg, IDC_DECRYPT_LIST), info);
105                  free (info);                  free_if_alloc (info);
106              }              }
107          }          }
108          else if (c->gpg_cmd == GPG_CMD_DECRYPT)          else if (c->gpg_cmd == GPG_CMD_DECRYPT)
109              EnableWindow (GetDlgItem (dlg, IDC_DECRYPT_LIST), FALSE);              EnableWindow (GetDlgItem (dlg, IDC_DECRYPT_LIST), FALSE);
110          SetDlgItemText( dlg, c->gpg_cmd == GPG_CMD_DECRYPT?          SetDlgItemText (dlg, c->gpg_cmd == GPG_CMD_DECRYPT?
111                          IDC_DECRYPT_PWDINFO : IDC_DECRYPT_SIGN_PWDINFO,                          IDC_DECRYPT_PWDINFO : IDC_DECRYPT_SIGN_PWDINFO,
112                          _("Please enter your passphrase") );                          _("Please enter your passphrase"));
113          if (c->gpg_cmd == GPG_CMD_DECRYPT) {          if (c->gpg_cmd == GPG_CMD_DECRYPT) {
114              SetFocus (GetDlgItem (dlg, IDC_DECRYPT_PWD));              SetFocus (GetDlgItem (dlg, IDC_DECRYPT_PWD));
115              if (res && !res->recipients)              if (res && !res->recipients) {
116                  SetDlgItemText (dlg, IDC_DECRYPT_MSG, _("Symmetric encryption.\n"));                                                                      const char *s = _("Symmetric encryption.\n"
117                                      "%s encrypted data.");
118                    const char *alg = get_symkey_algo (c->sym.sym_algo);
119                    info = new char[strlen (s) + strlen (alg) + 2];
120                    if (!info)
121                        BUG (NULL);
122                    sprintf (info, s, alg);
123                    SetDlgItemText (dlg, IDC_DECRYPT_MSG, info);
124                    free_if_alloc (info);
125                }
126              else              else
127                  SetDlgItemText (dlg, IDC_DECRYPT_MSG, c->info);                  SetDlgItemText (dlg, IDC_DECRYPT_MSG, c->info);
128          }          }
# Line 139  passphrase_callback_proc (HWND dlg, UINT Line 151  passphrase_callback_proc (HWND dlg, UINT
151                      HWND hwnd;                      HWND hwnd;
152                      int hide = IsDlgButtonChecked (dlg, item_ctrl_id2 (c->gpg_cmd));                      int hide = IsDlgButtonChecked (dlg, item_ctrl_id2 (c->gpg_cmd));
153                      hwnd = GetDlgItem (dlg, item_ctrl_id (c->gpg_cmd));                      hwnd = GetDlgItem (dlg, item_ctrl_id (c->gpg_cmd));
154                      SendMessage( hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0 );                      SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
155                      SetFocus (hwnd);                      SetFocus (hwnd);
156                  }                  }
157              }              }
# Line 279  passphrase_cb (void *hook, const char *u Line 291  passphrase_cb (void *hook, const char *u
291          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
292    
293      if (passphrase_info) {      if (passphrase_info) {
294            if (strlen (passphrase_info) < 16) {/* assume symetric encryption. */
295                int n=2;
296                c->sym.sym_algo = atoi (passphrase_info);
297                if (c->sym.sym_algo > 9)
298                    n++;
299                /* XXX: be more strict. */
300                c->sym.s2k_mode = atoi (passphrase_info+n);
301                c->sym.s2k_hash = atoi (passphrase_info+n+2);
302            }
303    
304          keyid = parse_gpg_keyid (passphrase_info);          keyid = parse_gpg_keyid (passphrase_info);
305          pass = agent_get_cache (keyid+8, &item);          pass = agent_get_cache (keyid+8, &item);
306          if (pass) {          if (pass) {

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26