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

Diff of /trunk/Src/wptGPGME.cpp

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

revision 19 by twoaday, Fri May 20 08:39:15 2005 UTC revision 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC
# Line 1  Line 1 
1  /* wptGPGME.cpp - WinPT GPGME interface  /* wptGPGME.cpp - WinPT GPGME interface
2   *      Copyright (C) 2001-2004 Timo Schulz   *      Copyright (C) 2001-2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 41  void progress_cleanup (progress_filter_s Line 41  void progress_cleanup (progress_filter_s
41  static gpgme_keycache_t pub = NULL;  static gpgme_keycache_t pub = NULL;
42  static gpgme_keycache_t sec = NULL;  static gpgme_keycache_t sec = NULL;
43  static unsigned int reload = 0;  static unsigned int reload = 0;
44    static char *gpg_secring = NULL;
45    
46  void  void
47  keycache_reload (HWND dlg)  keycache_reload (HWND dlg)
48  {        {      
49      refresh_cache_s rcs = {0};      refresh_cache_s rcs;
50    
51        memset (&rcs, 0, sizeof rcs);
52      rcs.kr_reload = rcs.kr_update = 1;      rcs.kr_reload = rcs.kr_update = 1;
53      rcs.tr_update = 1;      rcs.tr_update = 0;
54      DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,                                              DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,                                        
55                      keycache_dlg_proc, (LPARAM)&rcs );                      keycache_dlg_proc, (LPARAM)&rcs);
56  } /* keycache_reload */  } /* keycache_reload */
57    
58  void  void
# Line 60  keycache_release (void) Line 61  keycache_release (void)
61      int n = gpgme_keycache_count (pub);      int n = gpgme_keycache_count (pub);
62      char tmpbuf[64];      char tmpbuf[64];
63    
64        /* XXX: update the value when the cache has changed. */
65      sprintf (tmpbuf, "%d", n);      sprintf (tmpbuf, "%d", n);
66      set_reg_key (HKEY_CURRENT_USER, "Software\\WinPT", "nKeys", tmpbuf);      set_reg_key (HKEY_CURRENT_USER, "Software\\WinPT", "nKeys", tmpbuf);
67    
68      if (pub) {      if (pub) {
69          gpgme_keycache_release( pub );          gpgme_keycache_release (pub);
70          pub = NULL;          pub = NULL;
71      }      }
72      if (sec) {      if (sec) {
73          gpgme_keycache_release( sec );          gpgme_keycache_release (sec);
74          sec = NULL;          sec = NULL;
75      }      }
76  } /* keycache_release */  } /* keycache_release */
77    
78    
79  gpgme_error_t  gpgme_error_t
80  keycache_update (const char *keyid)  keycache_update (int is_sec, const char *keyid)
81  {  {
82      return gpgme_keycache_update_key (pub, keyid);      gpgme_keycache_t ctx = pub;
83        gpgme_error_t err;
84    
85        if (is_sec)
86            ctx = sec;
87        err =  gpgme_keycache_update_key (ctx, is_sec, pub, keyid);
88        if (is_sec)
89            gpgme_keycache_prepare_single (ctx, keyid, NULL, gpg_secring);
90        return err;
91  }  }
92    
93    /* XXX: cache_keyring_names must be called then the GPG homedir changes! */
94    
95  gpgme_error_t  gpgme_error_t
96  keycache_init (const char *pubring, const char * secring)  keycache_init (const char *pubring, const char * secring)
# Line 89  keycache_init (const char *pubring, cons Line 100  keycache_init (const char *pubring, cons
100      int val = 0;      int val = 0;
101      char * p;      char * p;
102    
103        if (secring != NULL) {
104            free_if_alloc (gpg_secring);
105            gpg_secring = get_gnupg_keyring (0, NO_STRICT);
106        }
107    
108      if (reload) {      if (reload) {
109          keycache_release ();          keycache_release ();
110          reload = 0;          reload = 0;
# Line 97  keycache_init (const char *pubring, cons Line 113  keycache_init (const char *pubring, cons
113      if (p && *p != ' ') {      if (p && *p != ' ') {
114          val = atoi (p);          val = atoi (p);
115          free_if_alloc (p);          free_if_alloc (p);
116          memset (&pfx, 0, sizeof pfx);          memset (&pfx, 0, sizeof (pfx));
117      }      }
118    
119      err = gpgme_keycache_new (&pub);      err = gpgme_keycache_new (&pub);
# Line 137  keycache_get_reload( void ) Line 153  keycache_get_reload( void )
153    
154    
155  gpgme_keycache_t  gpgme_keycache_t
156  keycache_get_ctx( int is_pub )  keycache_get_ctx (int is_pub)
157  {  {
158      return is_pub? pub : sec;      return is_pub? pub : sec;
159  } /* keycache_get_ctx */  } /* keycache_get_ctx */
160    
161    
162  static int  static int
163  get_key( const char *keyid, gpgme_key_t *r_key, int secret )  get_key (const char *keyid, gpgme_key_t *r_key, struct keycache_s **c, int secret)
164  {  {
165      gpgme_keycache_t cache;      gpgme_keycache_t cache;
166      gpgme_error_t err;      gpgme_error_t err;
# Line 154  get_key( const char *keyid, gpgme_key_t Line 170  get_key( const char *keyid, gpgme_key_t
170          return WPTERR_GENERAL;          return WPTERR_GENERAL;
171      if( r_key )      if( r_key )
172          *r_key = NULL;          *r_key = NULL;
173      cache = keycache_get_ctx( mode );      cache = keycache_get_ctx (mode);
174      if( !cache )      if( !cache )
175          BUG( NULL );          BUG( NULL );
176      err = gpgme_keycache_find_key( cache, keyid, 0, r_key );      if (!c)
177            err = gpgme_keycache_find_key( cache, keyid, 0, r_key );
178        else
179            err = gpgme_keycache_find_key2 (cache, keyid, 0, r_key, c);
180      if( err )      if( err )
181          return WPTERR_GENERAL;          return WPTERR_GENERAL;
182      return 0;      return 0;
# Line 192  get_key2( const char * keyid, gpgme_key_ Line 211  get_key2( const char * keyid, gpgme_key_
211    
212    
213  int  int
214  get_pubkey( const char *keyid, gpgme_key_t *ret_key )  winpt_get_pubkey (const char *keyid, winpt_key_s *k)
215    {
216        int rc;
217        
218        rc = get_key (keyid, &k->ctx, &k->ext, 0);
219        if (rc)
220            return rc;
221        k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && strlen (k->ctx->subkeys->fpr) == 32;
222        k->is_protected = k->ext->gloflags.is_protected;
223        k->keyid = k->ctx->subkeys->keyid;
224        k->uid = k->ctx->uids->uid;
225        return rc;
226    }
227    
228    
229    int
230    winpt_get_seckey (const char *keyid, winpt_key_s *k)
231    {
232        int rc;
233        rc = get_key (keyid, &k->ctx, &k->ext, 1);
234        if (rc)
235            return rc;
236        k->is_v3 = k->ctx->subkeys->pubkey_algo == GPGME_PK_RSA && strlen (k->ctx->subkeys->fpr) == 32;
237        k->is_protected = k->ext->gloflags.is_protected;
238        k->keyid = k->ctx->subkeys->keyid;
239        k->uid = k->ctx->uids->uid;
240        return rc;
241    }
242    
243    
244    int
245    get_pubkey (const char *keyid, gpgme_key_t *ret_key)
246  {  {
247      int rc = 0;      int rc = 0;
248    
249      if( pub && sec )      if (pub && sec)
250          rc = get_key( keyid, ret_key, 0 );          rc = get_key (keyid, ret_key, NULL, 0);
251      else      else
252          rc = get_key2( keyid, ret_key, 0 );          rc = get_key2 (keyid, ret_key, 0);
253      return rc;      return rc;
254  } /* get_pubkey */  } /* get_pubkey */
255    
# Line 210  get_seckey( const char *keyid, gpgme_key Line 260  get_seckey( const char *keyid, gpgme_key
260      int rc = 0;      int rc = 0;
261    
262      if( pub && sec )      if( pub && sec )
263          rc = get_key( keyid, ret_skey, 1 );          rc = get_key( keyid, ret_skey, NULL, 1 );
264      else      else
265          rc = get_key2( keyid, ret_skey, 1 );          rc = get_key2( keyid, ret_skey, 1 );
266      return rc;      return rc;
# Line 228  count_insecure_elgkeys (void) Line 278  count_insecure_elgkeys (void)
278      if (!pc)      if (!pc)
279          BUG (0);          BUG (0);
280      while (!gpgme_keycache_next_key (pc, 0, &key)) {      while (!gpgme_keycache_next_key (pc, 0, &key)) {
281          if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_ALGO, NULL, 0)          if (key->subkeys->pubkey_algo == GPGME_PK_ELG)
             == GPGME_PK_ELG_ES)  
282              n++;              n++;
283      }      }
284      gpgme_keycache_rewind (pc);      gpgme_keycache_rewind (pc);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26