/[gpgoe]/trunk/src/OEPassphraseCBDlg.c
ViewVC logotype

Diff of /trunk/src/OEPassphraseCBDlg.c

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

revision 22 by twoaday, Sun Jun 4 10:12:47 2006 UTC revision 23 by twoaday, Sat Aug 18 10:55:14 2007 UTC
# Line 12  Line 12 
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
  *  
  * You should have received a copy of the GNU Lesser General Public License  
  * along with GPGOE; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA7 USA  
15   */   */
16    
17  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 40  struct pass_cb_s { Line 36  struct pass_cb_s {
36  };  };
37    
38    
39    /* Reference to the passphrase cache. */
40  extern char gpgoe_pass_cache[HASH_BUCKETS][256];  extern char gpgoe_pass_cache[HASH_BUCKETS][256];
41    
42    
# Line 51  static void Line 48  static void
48  passphrase_put (char ctx[HASH_BUCKETS][256], const char *keyid, const char *pass)  passphrase_put (char ctx[HASH_BUCKETS][256], const char *keyid, const char *pass)
49  {  {
50      int pos = hash_string (keyid) % HASH_BUCKETS;      int pos = hash_string (keyid) % HASH_BUCKETS;
51      int n = 0;      int n, passlen;
52    
53        /* We cannot store passphrase of that size. */
54        passlen = strlen (pass);
55        if (passlen > 255)
56            return;
57        
58        n = 0;
59      while (n < HASH_BUCKETS) {      while (n < HASH_BUCKETS) {
60          if (strlen (ctx[(pos+n) % HASH_BUCKETS]) == 0) {          if (strlen (ctx[(pos+n) % HASH_BUCKETS]) != 0) {
61              memcpy (ctx[(pos+n) % HASH_BUCKETS], keyid, strlen (keyid));              n++;
62              strncpy (ctx[(pos+n) % HASH_BUCKETS]+strlen (keyid), pass, 240);              continue;
             break;  
63          }          }
64          n++;          memcpy (ctx[(pos+n) % HASH_BUCKETS], keyid, strlen (keyid));
65            strncpy (ctx[(pos+n) % HASH_BUCKETS]+strlen (keyid), pass, passlen);
66            break;
67      }      }
68  }  }
69    
# Line 72  passphrase_get (char ctx[HASH_BUCKETS][2 Line 76  passphrase_get (char ctx[HASH_BUCKETS][2
76  {  {
77      const char *item;      const char *item;
78      int pos = hash_string (keyid) % HASH_BUCKETS;      int pos = hash_string (keyid) % HASH_BUCKETS;
79      int n=0;      int n;
80    
81        n = 0;
82      item = gpgoe_pass_cache[pos];      item = gpgoe_pass_cache[pos];
83      while (strncmp (item, keyid, strlen (keyid)) &&      while (n < HASH_BUCKETS) {
             n < HASH_BUCKETS) {  
84          item = ctx[(pos+n) % HASH_BUCKETS];          item = ctx[(pos+n) % HASH_BUCKETS];
85            if (!strncmp (item, keyid, strlen (keyid)))
86                break;
87          n++;          n++;
88      }      }
89        
90      if (strlen (item) > 0 && !strncmp (item, keyid, strlen (keyid)))      if (strlen (item) > 0 && !strncmp (item, keyid, strlen (keyid)))
91          return item+strlen (keyid);          return item + strlen (keyid);
92        /* Return NULL to indicate no matching entry. */
93      return NULL;      return NULL;
94  }  }
95    
# Line 99  get_pubkey_algo (const char *passphrase_ Line 106  get_pubkey_algo (const char *passphrase_
106      case  1: return "RSA";      case  1: return "RSA";
107      case 17: return "DSA";      case 17: return "DSA";
108      case 16: return "ELG";      case 16: return "ELG";
109        default: break;
110      }      }
111      return "???";      return "???";
112  }  }
# Line 115  pass_cb_dlg_proc (HWND dlg, UINT msg, WP Line 123  pass_cb_dlg_proc (HWND dlg, UINT msg, WP
123      switch (msg) {      switch (msg) {
124      case WM_INITDIALOG:      case WM_INITDIALOG:
125          ctx = (pass_cb_t)lparam;          ctx = (pass_cb_t)lparam;
126          assert (ctx);          assert (ctx != NULL);
127          if (ctx->uid_hint && ctx->passphrase_info) {          if (ctx->uid_hint && ctx->passphrase_info) {
128              char *utf8_uid = utf8_to_native (ctx->uid_hint+17);              char *utf8_uid = utf8_to_native (ctx->uid_hint+17);
129              info = xcalloc (1, strlen (utf8_uid) +  strlen (ctx->keyid) + 32);              info = xcalloc (1, strlen (utf8_uid) +  strlen (ctx->keyid) + 32);
130              sprintf (info, _("%s\n%s key, ID %s"), utf8_uid,              sprintf (info, _("%s\n%s key, ID %s"), utf8_uid,
131                              get_pubkey_algo (ctx->passphrase_info), ctx->keyid);                       get_pubkey_algo (ctx->passphrase_info), ctx->keyid);
132              SetDlgItemText (dlg, IDC_DECRYPT_MSG, info);              SetDlgItemText (dlg, IDC_DECRYPT_MSG, info);
133              free_if_alloc (utf8_uid);              free_if_alloc (utf8_uid);
134              free_if_alloc (info);              free_if_alloc (info);
# Line 169  pass_cb_dlg_proc (HWND dlg, UINT msg, WP Line 177  pass_cb_dlg_proc (HWND dlg, UINT msg, WP
177                              _("GPG Plug-in Info"), MB_ICONINFORMATION|MB_OK);                              _("GPG Plug-in Info"), MB_ICONINFORMATION|MB_OK);
178                  return FALSE;                  return FALSE;
179              }              }
180                /* Make sure we reset the cancel flag. */
181              ctx->cancel = 0;              ctx->cancel = 0;
182              ctx->pass = xcalloc (1, n+2);              ctx->pass = xcalloc (1, n+2);
183              GetDlgItemText (dlg, IDC_DECRYPT_PWD, ctx->pass, n+1);              GetDlgItemText (dlg, IDC_DECRYPT_PWD, ctx->pass, n+1);
# Line 194  passphrase_cb (void *hook, Line 203  passphrase_cb (void *hook,
203      pass_cb_t cb = (pass_cb_t)hook;      pass_cb_t cb = (pass_cb_t)hook;
204      HANDLE fp = (HANDLE)fd;      HANDLE fp = (HANDLE)fd;
205      const char *pass;      const char *pass;
206      DWORD nwritten = 0;      DWORD nwritten;
207            
208      assert (cb);      assert (cb != NULL);
209      cb->prev_was_bad = prev_was_bad;      cb->prev_was_bad = prev_was_bad;
210      if (prev_was_bad && !cb->cancel) {      if (prev_was_bad && !cb->cancel) {
211          wipememory (cb->pass, strlen (cb->pass));          wipememory (cb->pass, strlen (cb->pass));
# Line 252  free_pass_cb (pass_cb_t cb) Line 261  free_pass_cb (pass_cb_t cb)
261  }  }
262    
263    
264    /* Return 1 if the passphrase dialog were cancelled. */
265  int  int
266  pass_cb_cancelled (pass_cb_t cb)  pass_cb_cancelled (pass_cb_t cb)
267  {  {
# Line 259  pass_cb_cancelled (pass_cb_t cb) Line 269  pass_cb_cancelled (pass_cb_t cb)
269  }  }
270    
271    
272  /* Reset the passphrase cache. */  /* Reset the passphrase cache by overwritting each items with zeroes */
273  void  void
274  reset_pass_cache (void)  reset_pass_cache (void)
275  {  {
276      int i;      int i;
277    
278      for (i=0; i < HASH_BUCKETS; i++)      for (i=0; i < HASH_BUCKETS; i++)
279          wipememory (gpgoe_pass_cache[i], 256);          wipememory (gpgoe_pass_cache[i], DIM (gpgoe_pass_cache[i]));
280  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26