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) |
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; |
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 |
} |
} |
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 |
} |
} |
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 |
{ |
{ |
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++; |
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 |
} |
} |
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; |
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) |