mirror of
git://git.gnupg.org/gnupg.git
synced 2024-11-11 21:48:50 +01:00
Fix listing keys.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
22f945cf30
commit
395bcbc0ff
136
tkd/pkcs11.c
136
tkd/pkcs11.c
@ -437,8 +437,9 @@ examine_public_key (struct token *token, struct key *k, unsigned long keytype,
|
|||||||
templ[0].ulValueLen = sizeof (supported);
|
templ[0].ulValueLen = sizeof (supported);
|
||||||
|
|
||||||
err = ck->f->C_GetAttributeValue (token->session, obj, templ, 1);
|
err = ck->f->C_GetAttributeValue (token->session, obj, templ, 1);
|
||||||
if (!err && supported)
|
if (!err)
|
||||||
{
|
{
|
||||||
|
/* XXX: Scute has the attribute, but not set. */
|
||||||
k->flags |= KEY_FLAGS_USAGE_SIGN;
|
k->flags |= KEY_FLAGS_USAGE_SIGN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,6 +740,9 @@ find_key (struct cryptoki *ck, const char *keygrip, struct key **r_key)
|
|||||||
{
|
{
|
||||||
struct token *token = &ck->token_list[i];
|
struct token *token = &ck->token_list[i];
|
||||||
|
|
||||||
|
if (!token->valid)
|
||||||
|
continue;
|
||||||
|
|
||||||
for (j = 0; j < token->num_keys; j++)
|
for (j = 0; j < token->num_keys; j++)
|
||||||
{
|
{
|
||||||
struct key *k = &token->key_list[j];
|
struct key *k = &token->key_list[j];
|
||||||
@ -763,38 +767,77 @@ struct iter_key {
|
|||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
unsigned long mask;
|
unsigned long mask;
|
||||||
|
int st;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
iter_find_key_setup (struct iter_key *iter, struct cryptoki *ck, int cap)
|
||||||
|
{
|
||||||
|
iter->st = 0;
|
||||||
|
iter->ck = ck;
|
||||||
|
iter->i = 0;
|
||||||
|
iter->j = 0;
|
||||||
|
iter->mask = 0;
|
||||||
|
if (cap == GCRY_PK_USAGE_SIGN)
|
||||||
|
iter->mask |= KEY_FLAGS_USAGE_SIGN;
|
||||||
|
else if (cap == GCRY_PK_USAGE_ENCR)
|
||||||
|
iter->mask = KEY_FLAGS_USAGE_DECRYPT;
|
||||||
|
else
|
||||||
|
iter->mask = KEY_FLAGS_USAGE_SIGN | KEY_FLAGS_USAGE_DECRYPT;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
iter_find_key (struct iter_key *iter, struct key **r_key)
|
iter_find_key (struct iter_key *iter, struct key **r_key)
|
||||||
{
|
{
|
||||||
struct cryptoki *ck = iter->ck;
|
struct cryptoki *ck = iter->ck;
|
||||||
struct token *token = &ck->token_list[iter->i];
|
struct token *token;
|
||||||
struct key *k;
|
struct key *k;
|
||||||
|
|
||||||
*r_key = NULL;
|
*r_key = NULL;
|
||||||
|
|
||||||
again:
|
if (iter->i < ck->num_slots)
|
||||||
|
token = &ck->token_list[iter->i];
|
||||||
if (iter->j < token->num_keys)
|
|
||||||
iter->j++;
|
|
||||||
else if (iter->i < ck->num_slots)
|
|
||||||
{
|
|
||||||
iter->i++;
|
|
||||||
iter->j = 0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return 0;
|
token = NULL;
|
||||||
|
|
||||||
k = &token->key_list[iter->j];
|
switch (iter->st)
|
||||||
if ((k->flags & KEY_FLAGS_VALID) == 0)
|
while (1)
|
||||||
goto again;
|
{
|
||||||
|
case 0:
|
||||||
|
if (iter->i < ck->num_slots)
|
||||||
|
{
|
||||||
|
token = &ck->token_list[iter->i++];
|
||||||
|
if (!token->valid)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iter->st = 2;
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ((k->flags & iter->mask) == 0)
|
iter->j = 0;
|
||||||
goto again;
|
while (1)
|
||||||
|
{
|
||||||
*r_key = k;
|
/*FALLTHROUGH*/
|
||||||
return 1;
|
case 1:
|
||||||
|
if (token && iter->j < token->num_keys)
|
||||||
|
{
|
||||||
|
k = &token->key_list[iter->j++];
|
||||||
|
if ((k->flags & KEY_FLAGS_VALID) && (k->flags & iter->mask))
|
||||||
|
{
|
||||||
|
/* Found */
|
||||||
|
*r_key = k;
|
||||||
|
iter->st = 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
@ -907,11 +950,11 @@ token_slotlist (ctrl_t ctrl, assuan_context_t ctx)
|
|||||||
int i;
|
int i;
|
||||||
int num_tokens = 0;
|
int num_tokens = 0;
|
||||||
|
|
||||||
char *module_name;
|
const char *module_name;
|
||||||
|
|
||||||
(void)ctrl;
|
(void)ctrl;
|
||||||
(void)ctx;
|
(void)ctx;
|
||||||
module_name = getenv (ENVNAME);
|
module_name = opt.pkcs11_driver;
|
||||||
if (!module_name)
|
if (!module_name)
|
||||||
return gpg_error (GPG_ERR_NO_NAME);
|
return gpg_error (GPG_ERR_NO_NAME);
|
||||||
|
|
||||||
@ -1057,36 +1100,29 @@ token_keyinfo (ctrl_t ctrl, const char *keygrip, int opt_data, int cap)
|
|||||||
{
|
{
|
||||||
struct iter_key iter;
|
struct iter_key iter;
|
||||||
|
|
||||||
iter.ck = ck;
|
iter_find_key_setup (&iter, ck, cap);
|
||||||
iter.i = iter.j = 0;
|
|
||||||
iter.mask = 0;
|
|
||||||
if (cap == GCRY_PK_USAGE_SIGN)
|
|
||||||
iter.mask |= KEY_FLAGS_USAGE_SIGN;
|
|
||||||
else if (cap == GCRY_PK_USAGE_ENCR)
|
|
||||||
iter.mask |= KEY_FLAGS_USAGE_DECRYPT;
|
|
||||||
|
|
||||||
while (iter_find_key (&iter, &k))
|
while (iter_find_key (&iter, &k))
|
||||||
{
|
{
|
||||||
if ((k->flags & KEY_FLAGS_USAGE_SIGN))
|
if ((k->flags & KEY_FLAGS_USAGE_SIGN))
|
||||||
{
|
{
|
||||||
if ((k->flags & KEY_FLAGS_USAGE_DECRYPT))
|
if ((k->flags & KEY_FLAGS_USAGE_DECRYPT))
|
||||||
usage = "se";
|
usage = "se";
|
||||||
else
|
else
|
||||||
usage = "s";
|
usage = "s";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((k->flags & KEY_FLAGS_USAGE_DECRYPT))
|
if ((k->flags & KEY_FLAGS_USAGE_DECRYPT))
|
||||||
usage = "e";
|
usage = "e";
|
||||||
else
|
else
|
||||||
usage = "-";
|
usage = "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
send_keyinfo (ctrl, opt_data, k->keygrip,
|
send_keyinfo (ctrl, opt_data, k->keygrip,
|
||||||
k->label_len ? (const char *)k->label : "-",
|
k->label_len ? (const char *)k->label : "-",
|
||||||
k->id_len ? (const char *)k->id : "-",
|
k->id_len ? (const char *)k->id : "-",
|
||||||
usage);
|
usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -101,8 +101,6 @@ static gpgrt_opt_t opts[] = {
|
|||||||
N_("run in multi server mode (foreground)")),
|
N_("run in multi server mode (foreground)")),
|
||||||
ARGPARSE_s_n (oDaemon, "daemon", N_("run in daemon mode (background)")),
|
ARGPARSE_s_n (oDaemon, "daemon", N_("run in daemon mode (background)")),
|
||||||
ARGPARSE_s_n (oNoDetach, "no-detach", N_("do not detach from the console")),
|
ARGPARSE_s_n (oNoDetach, "no-detach", N_("do not detach from the console")),
|
||||||
ARGPARSE_s_n (oSh, "sh", N_("sh-style command output")),
|
|
||||||
ARGPARSE_s_n (oCsh, "csh", N_("csh-style command output")),
|
|
||||||
ARGPARSE_s_s (oHomedir, "homedir", "@"),
|
ARGPARSE_s_s (oHomedir, "homedir", "@"),
|
||||||
ARGPARSE_conffile (oOptions, "options", N_("|FILE|read options from FILE")),
|
ARGPARSE_conffile (oOptions, "options", N_("|FILE|read options from FILE")),
|
||||||
ARGPARSE_noconffile (oNoOptions, "no-options", "@"),
|
ARGPARSE_noconffile (oNoOptions, "no-options", "@"),
|
||||||
|
Loading…
Reference in New Issue
Block a user