/[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 260 by twoaday, Wed Aug 16 10:01:30 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 344  keycache_prepare2 (gpg_keycache_t ctx, c Line 351  keycache_prepare2 (gpg_keycache_t ctx, c
351      gpg_iobuf_t inp;      gpg_iobuf_t inp;
352      PACKET *pkt;      PACKET *pkt;
353      struct keycache_s *c;      struct keycache_s *c;
354      const byte *sym_prefs;      const BYTE *sym_prefs;
355      char keyid[16+1];      char keyid[16+1];
356      int key_seen = 0;      int key_seen = 0;
357      size_t nsym =0;      size_t nsym =0;
# 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 756  gpg_keycache_delete_key (gpg_keycache_t Line 762  gpg_keycache_delete_key (gpg_keycache_t
762          return rc;          return rc;
763            
764      c = ctx->item;      c = ctx->item;
765      if (c->next == NULL) {      if (!c) /* empty */
766            return 0;
767        else if (c->next == NULL) {
768          if (itm->key)          if (itm->key)
769              gpgme_key_release (itm->key);              gpgme_key_release (itm->key);
770          itm->key = NULL;          itm->key = NULL;
771          free_if_alloc (itm);          free_if_alloc (itm);
772            /* the cache has no other items, so we set the context to NULL
773               to indicate that the entire cache is empty. */
774            ctx->item = NULL;
775      }      }
776      else {      else {
777          for (; c != NULL; c = c->next) {          for (; c != NULL; c = c->next) {
# Line 817  gpg_keycache_init (gpg_keycache_t ctx, c Line 828  gpg_keycache_init (gpg_keycache_t ctx, c
828  }  }
829    
830    
831  /* XXX: kludge to see if the key is stored on a card. */  /* Return 1 if we can assume that the actual private key is
832       stored on a smart card. This is not bullet proof, but the
833       card provides 3 keys (RSA) and each key for a different purpose. */
834  static int  static int
835  key_divert_to_card (gpgme_key_t key)  key_divert_to_card (gpgme_key_t key)
836  {  {
837      gpgme_subkey_t k;      gpgme_subkey_t k;
838      int n=0, n_alg=0, can_auth = 0;      int n=0;
839        int can_auth = 0, can_encr = 0;
840    
841      for (k = key->subkeys; k; k = k->next) {      for (k = key->subkeys; k; k = k->next) {
842          n++;          n++;
843          if (k->pubkey_algo == GPGME_PK_RSA && k->length == 1024)          if (k->pubkey_algo != GPGME_PK_RSA || k->length != 1024) {
844              n_alg++;              return 0;
845                break;
846            }
847          if (k->can_authenticate)          if (k->can_authenticate)
848              can_auth++;              can_auth++;
849            if (k->can_encrypt)
850                can_encr++;
851      }      }
852      if (n == 3 && n_alg == 3 && can_auth == 1)      if (n >= 3 && can_auth >= 1 && can_encr >= 1)
853          return 1;          return 1;
854      return 0;      return 0;
855  }  }
# Line 845  copy_uid_prefs (const unsigned char *pre Line 863  copy_uid_prefs (const unsigned char *pre
863    
864      while (prefs[pos] != 0)      while (prefs[pos] != 0)
865          pos++;          pos++;
866      p = new unsigned char[pos+1];      p = safe_uchar_alloc (pos+1);
     if (!p)  
         BUG (0);  
867      memset (p, 0, pos+1);      memset (p, 0, pos+1);
868      memcpy (p, prefs, pos);      memcpy (p, prefs, pos);
869      return p;      return p;
# Line 865  gpg_keycache_sync (gpg_keycache_t pub, g Line 881  gpg_keycache_sync (gpg_keycache_t pub, g
881          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
882            
883      for (c=sec->item; c; c=c->next) {      for (c=sec->item; c; c=c->next) {
884          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,
885                                         &key, &c_sec)) {
886              c_sec->gloflags.is_protected = c->gloflags.is_protected;              c_sec->gloflags.is_protected = c->gloflags.is_protected;
887              c_sec->gloflags.divert_to_card = c->gloflags.divert_to_card;              c_sec->gloflags.divert_to_card = c->gloflags.divert_to_card;
888              if (!c->gloflags.divert_to_card)              if (!c->gloflags.divert_to_card)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26