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

Diff of /trunk/Src/wptKeyCache.cpp

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

revision 41 by twoaday, Fri Oct 28 07:15:26 2005 UTC revision 123 by twoaday, Wed Dec 14 09:01:45 2005 UTC
# Line 17  Line 17 
17   * along with this program; if not, write to the Free Software   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    
21    #ifdef HAVE_CONFIG_H
22    #include <config.h>
23    #endif
24    
25  #include <windows.h>  #include <windows.h>
26  #include <stdio.h>  #include <stdio.h>
27  #include <string.h>  #include <string.h>
28  #include <malloc.h>  #include <malloc.h>
29  #include <ctype.h>  #include <ctype.h>
30  #include <assert.h>  #include <assert.h>
31    #include <gpgme.h>
32    
 #include "w32gpgme.h"  
33  #include "wptKeyCache.h"  #include "wptKeyCache.h"
34  #include "openpgp.h"  #include "openpgp.h"
35  #include "wptNLS.h"  #include "wptNLS.h"
# Line 32  Line 37 
37  #include "wptW32API.h"  #include "wptW32API.h"
38    
39    
40    #if 0
41  /* convert a binary buffer into its hex representation. */  /* convert a binary buffer into its hex representation. */
42  static void  static void
43  buffer_to_string (char *dst, size_t dlen, const byte *buf, size_t nbytes)  buffer_to_string (char *dst, size_t dlen, const byte *buf, size_t nbytes)
# Line 46  buffer_to_string (char *dst, size_t dlen Line 52  buffer_to_string (char *dst, size_t dlen
52          dlen -= 2;          dlen -= 2;
53      }      }
54  }  }
55    #endif
56    
57    
58  /* Parse the secret keyring and retrieve some additional information  /* Parse the secret keyring and retrieve some additional information
# Line 100  gpgme_error_t Line 107  gpgme_error_t
107  keycache_prepare2 (gpg_keycache_t ctx, const char *kid,  keycache_prepare2 (gpg_keycache_t ctx, const char *kid,
108                     const char *pubring, const char *secring)                     const char *pubring, const char *secring)
109  {  {
110      gpgme_error_t err;      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
111      gpgme_key_t key = NULL;      gpgme_key_t key = NULL;
112      gpg_iobuf_t inp;      gpg_iobuf_t inp;
113      PACKET *pkt = (PACKET*)calloc (1, sizeof * pkt);      PACKET *pkt = (PACKET*)calloc (1, sizeof * pkt);
# Line 108  keycache_prepare2 (gpg_keycache_t ctx, c Line 115  keycache_prepare2 (gpg_keycache_t ctx, c
115      const byte *sym_prefs;      const byte *sym_prefs;
116      char keyid[16+1], *id = NULL;      char keyid[16+1], *id = NULL;
117      int key_seen = 0;      int key_seen = 0;
118      size_t nbytes = 0, nsym =0;      size_t nsym =0;
119    
120      if (secring) {      if (secring) {
121          parse_secring (ctx, kid, secring);          parse_secring (ctx, kid, secring);
122          if (!pubring) {          if (!pubring) {
123              safe_free(pkt);              safe_free (pkt);
124              return 0;              return 0;
125          }          }
126      }      }
127      inp = gpg_iobuf_open (pubring);      inp = gpg_iobuf_open (pubring);
128      if (!inp) {      if (!inp) {
129          safe_free( pkt );          safe_free (pkt);
130          return gpg_error (GPG_ERR_KEYRING_OPEN);          return gpg_error (GPG_ERR_KEYRING_OPEN);
131      }      }
132      gpg_iobuf_ioctl( inp, 3, 1, NULL ); /* disable cache */      gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */
133    
134      gpg_init_packet( pkt );      gpg_init_packet (pkt);
135      while (gpg_parse_packet (inp, pkt) != -1) {      while (gpg_parse_packet (inp, pkt) != -1) {
136          if (pkt->pkttype == PKT_PUBLIC_KEY) {          if (pkt->pkttype == PKT_PUBLIC_KEY) {
137              strcpy (keyid, "");              strcpy (keyid, "");
# Line 171  keycache_prepare2 (gpg_keycache_t ctx, c Line 178  keycache_prepare2 (gpg_keycache_t ctx, c
178          }          }
179          if ((pkt->pkttype == PKT_USER_ID || pkt->pkttype == PKT_ATTRIBUTE)          if ((pkt->pkttype == PKT_USER_ID || pkt->pkttype == PKT_ATTRIBUTE)
180              && pkt->pkt.user_id->attrib_data && key) {              && pkt->pkt.user_id->attrib_data && key) {
181              PKT_user_id *id = pkt->pkt.user_id;              PKT_user_id *uid = pkt->pkt.user_id;
182              c->attrib.used = 1;              c->attrib.used = 1;
183              c->attrib.len = id->attrib_len;              c->attrib.len = uid->attrib_len;
184              c->attrib.d = (unsigned char*)calloc (1, id->attrib_len + 1);              c->attrib.d = (unsigned char*)calloc (1, uid->attrib_len + 1);
185              if (!c->attrib.d) {              if (!c->attrib.d) {
186                  err = gpg_error (GPG_ERR_ENOMEM);                  err = gpg_error (GPG_ERR_ENOMEM);
187                  goto fail;                  goto fail;
188              }              }
189              memcpy (c->attrib.d, id->attrib_data, id->attrib_len);              memcpy (c->attrib.d, uid->attrib_data, uid->attrib_len);
190              key = NULL;              key = NULL;
191              c = NULL;              c = NULL;
192          }          }
# Line 510  key_divert_to_card (gpgme_key_t key) Line 517  key_divert_to_card (gpgme_key_t key)
517  }  }
518    
519    
520    static unsigned char*
521    copy_uid_prefs (const unsigned char *prefs)
522    {
523        unsigned char *p;
524        size_t pos=0;
525    
526        while (prefs[pos] != 0)
527            pos++;
528        p = (unsigned char*)calloc (1, pos+1);
529        if (!p)
530            abort ();
531        memcpy (p, prefs, pos);
532        return p;
533    }
534    
535    
536  gpgme_error_t  gpgme_error_t
537  gpg_keycache_sync (gpg_keycache_t pub, gpg_keycache_t sec)  gpg_keycache_sync (gpg_keycache_t pub, gpg_keycache_t sec)
538  {  {
# Line 525  gpg_keycache_sync (gpg_keycache_t pub, g Line 548  gpg_keycache_sync (gpg_keycache_t pub, g
548              c_sec->gloflags.divert_to_card = c->gloflags.divert_to_card;              c_sec->gloflags.divert_to_card = c->gloflags.divert_to_card;
549              if (!c->gloflags.divert_to_card)              if (!c->gloflags.divert_to_card)
550                  c->gloflags.divert_to_card = key_divert_to_card (key);                  c->gloflags.divert_to_card = key_divert_to_card (key);
551                c->sym_prefs = copy_uid_prefs (c_sec->sym_prefs);
552              c->pubpart = c_sec;              c->pubpart = c_sec;
553              c->pubpart->key = key;              c->pubpart->key = key;
554          }          }

Legend:
Removed from v.41  
changed lines
  Added in v.123

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26