/[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 217 by twoaday, Mon May 22 14:21:39 2006 UTC revision 226 by twoaday, Mon Jun 12 13:40:21 2006 UTC
# Line 55  struct attr_list_s { Line 55  struct attr_list_s {
55  typedef struct attr_list_s *attr_list_t;  typedef struct attr_list_s *attr_list_t;
56    
57    
58    /* XXX: convert it to an inline function and place it in a header file. */
59    static unsigned char*
60    safe_uchar_alloc (size_t n)
61    {
62        unsigned char *p = new unsigned char[n];
63        if (!p)
64            BUG (0);
65        return p;
66    }
67    
68    
69  /* Free attribute list @ctx. */  /* Free attribute list @ctx. */
70  void  void
71  free_attr_list (attr_list_t ctx)  free_attr_list (attr_list_t ctx)
# Line 122  parse_attr_list (FILE *fp, const BYTE *d Line 133  parse_attr_list (FILE *fp, const BYTE *d
133                  ;                  ;
134              t->next = c;              t->next = c;
135          }          }
136          c->d = new unsigned char[c->octets];          c->d = safe_uchar_alloc (c->octets);
         if (!c->d)  
             BUG (0);  
137          memcpy (c->d, data, c->octets);          memcpy (c->d, data, c->octets);
138          data += c->octets;          data += c->octets;
139          datlen -= c->octets;          datlen -= c->octets;
# Line 231  keycache_update_photo (gpg_keycache_t ct Line 240  keycache_update_photo (gpg_keycache_t ct
240      free_if_alloc (fnd->attrib.d);      free_if_alloc (fnd->attrib.d);
241      fnd->attrib.flags = dat->flags;      fnd->attrib.flags = dat->flags;
242      fnd->attrib.len = dat->octets;      fnd->attrib.len = dat->octets;
243      fnd->attrib.d = new unsigned char[dat->octets];      fnd->attrib.d = safe_uchar_alloc (dat->octets);
     if (!fnd->attrib.d)  
         BUG (0);  
244      memcpy (fnd->attrib.d, dat->d, dat->octets);      memcpy (fnd->attrib.d, dat->d, dat->octets);
245      return 0;      return 0;
246  }  }
# Line 393  keycache_prepare2 (gpg_keycache_t ctx, c Line 400  keycache_prepare2 (gpg_keycache_t ctx, c
400              err = gpg_keycache_find_key2 (ctx, keyid, 0, &key, &c);              err = gpg_keycache_find_key2 (ctx, keyid, 0, &key, &c);
401              if (err || !c)              if (err || !c)
402                  goto next;                  goto next;
403              if (c->sym_prefs) /* only use the prefs from the primary uid. */              if (c->sym_prefs) // only use the prefs from the primary uid.
404                  goto next;                  goto next;
405              else if (nsym > 0) {              else if (nsym > 0) {
406                  c->sym_prefs = new unsigned char[nsym+1];                  c->sym_prefs = safe_uchar_alloc (nsym+1);
                 if (!c->sym_prefs)  
                     BUG (0);  
407                  memset (c->sym_prefs, 0, nsym+1);                  memset (c->sym_prefs, 0, nsym+1);
408                  memcpy (c->sym_prefs, sym_prefs, nsym);                  memcpy (c->sym_prefs, sym_prefs, nsym);
409              }              }
# Line 638  gpg_keycache_next_updated_key (gpg_keyca Line 643  gpg_keycache_next_updated_key (gpg_keyca
643  }  }
644    
645    
646    /* Helper to retrieve a GPG key. */
647  static gpgme_error_t  static gpgme_error_t
648  get_gpg_key (const char *keyid, int is_sec, gpgme_key_t *r_key)  get_gpg_key (const char *keyid, int is_sec, gpgme_key_t *r_key)
649  {  {
# Line 817  gpg_keycache_init (gpg_keycache_t ctx, c Line 823  gpg_keycache_init (gpg_keycache_t ctx, c
823  }  }
824    
825    
826  /* XXX: kludge to see if the key is stored on a card. */  /* Return 1 if we can assume that the actual private key is
827       stored on a smart card. This is not bullet proof, but the
828       card provides 3 keys (RSA) and each key for a different purpose. */
829  static int  static int
830  key_divert_to_card (gpgme_key_t key)  key_divert_to_card (gpgme_key_t key)
831  {  {
832      gpgme_subkey_t k;      gpgme_subkey_t k;
833      int n=0, n_alg=0, can_auth = 0;      int n=0, n_alg=0;
834        int can_auth = 0, can_encr = 0;
835    
836      for (k = key->subkeys; k; k = k->next) {      for (k = key->subkeys; k; k = k->next) {
837          n++;          n++;
# Line 830  key_divert_to_card (gpgme_key_t key) Line 839  key_divert_to_card (gpgme_key_t key)
839              n_alg++;              n_alg++;
840          if (k->can_authenticate)          if (k->can_authenticate)
841              can_auth++;              can_auth++;
842            if (k->can_encrypt)
843                can_encr++;
844      }      }
845      if (n == 3 && n_alg == 3 && can_auth == 1)      if (n == 3 && n_alg == 3 && can_auth == 1 && can_encr == 1)
846          return 1;          return 1;
847      return 0;      return 0;
848  }  }
# Line 845  copy_uid_prefs (const unsigned char *pre Line 856  copy_uid_prefs (const unsigned char *pre
856    
857      while (prefs[pos] != 0)      while (prefs[pos] != 0)
858          pos++;          pos++;
859      p = new unsigned char[pos+1];      p = safe_uchar_alloc (pos+1);
     if (!p)  
         BUG (0);  
860      memset (p, 0, pos+1);      memset (p, 0, pos+1);
861      memcpy (p, prefs, pos);      memcpy (p, prefs, pos);
862      return p;      return p;
# Line 865  gpg_keycache_sync (gpg_keycache_t pub, g Line 874  gpg_keycache_sync (gpg_keycache_t pub, g
874          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
875            
876      for (c=sec->item; c; c=c->next) {      for (c=sec->item; c; c=c->next) {
877          if (!gpg_keycache_find_key2 (pub, c->key->subkeys->keyid, 0, &key, &c_sec)) {          if (!gpg_keycache_find_key2 (pub, c->key->subkeys->keyid, 0,
878                                         &key, &c_sec)) {
879              c_sec->gloflags.is_protected = c->gloflags.is_protected;              c_sec->gloflags.is_protected = c->gloflags.is_protected;
880              c_sec->gloflags.divert_to_card = c->gloflags.divert_to_card;              c_sec->gloflags.divert_to_card = c->gloflags.divert_to_card;
881              if (!c->gloflags.divert_to_card)              if (!c->gloflags.divert_to_card)

Legend:
Removed from v.217  
changed lines
  Added in v.226

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26