mirror of
git://git.gnupg.org/gnupg.git
synced 2025-05-24 16:43:28 +02:00
tools:gpg-auth: Show SSH key comment when asking PIN.
* tools/gpg-auth.c (authenticate): Put key_list->comment to assuan user's pointer. (getpin): Show SSH key comment if any. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
3e5f99e648
commit
7a22f764d5
@ -187,6 +187,7 @@ struct ga_key_list {
|
|||||||
char keygrip[41]; /* Keygrip to identify a key. */
|
char keygrip[41]; /* Keygrip to identify a key. */
|
||||||
size_t pubkey_len;
|
size_t pubkey_len;
|
||||||
char *pubkey; /* Public key in SSH format. */
|
char *pubkey; /* Public key in SSH format. */
|
||||||
|
char *comment;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Local prototypes. */
|
/* Local prototypes. */
|
||||||
@ -198,7 +199,7 @@ static gpg_error_t ga_filter_by_authorized_keys (struct ga_key_list **r_key_list
|
|||||||
static void ga_release_auth_keys (struct ga_key_list *key_list);
|
static void ga_release_auth_keys (struct ga_key_list *key_list);
|
||||||
static gpg_error_t scd_pkauth (assuan_context_t ctx, const char *keygrip);
|
static gpg_error_t scd_pkauth (assuan_context_t ctx, const char *keygrip);
|
||||||
static gpg_error_t authenticate (assuan_context_t ctx, struct ga_key_list *key_list);
|
static gpg_error_t authenticate (assuan_context_t ctx, struct ga_key_list *key_list);
|
||||||
static int getpin (const char *info, char *buf, size_t *r_len);
|
static int getpin (assuan_context_t ctx, const char *info, char *buf, size_t *r_len);
|
||||||
|
|
||||||
/* gpg-auth main. */
|
/* gpg-auth main. */
|
||||||
int
|
int
|
||||||
@ -269,6 +270,7 @@ authenticate (assuan_context_t ctx, struct ga_key_list *key_list)
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
assuan_set_pointer (ctx, key_list->comment);
|
||||||
err = scd_pkauth (ctx, key_list->keygrip);
|
err = scd_pkauth (ctx, key_list->keygrip);
|
||||||
if (!err)
|
if (!err)
|
||||||
/* Success! */
|
/* Success! */
|
||||||
@ -517,7 +519,7 @@ inq_needpin (void *opaque, const char *line)
|
|||||||
if (!pin)
|
if (!pin)
|
||||||
return out_of_core ();
|
return out_of_core ();
|
||||||
|
|
||||||
rc = getpin (line, pin, &pinlen);
|
rc = getpin (ctx, line, pin, &pinlen);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
assuan_begin_confidential (ctx);
|
assuan_begin_confidential (ctx);
|
||||||
@ -735,6 +737,7 @@ ga_scd_get_auth_keys (assuan_context_t ctx, struct ga_key_list **r_key_list)
|
|||||||
struct ssh_key_list {
|
struct ssh_key_list {
|
||||||
struct ssh_key_list *next;
|
struct ssh_key_list *next;
|
||||||
char *pubkey; /* Public key in SSH format. */
|
char *pubkey; /* Public key in SSH format. */
|
||||||
|
char *comment;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -747,6 +750,7 @@ release_ssh_key_list (struct ssh_key_list *key_list)
|
|||||||
key = key_list;
|
key = key_list;
|
||||||
key_list = key_list->next;
|
key_list = key_list->next;
|
||||||
xfree (key->pubkey);
|
xfree (key->pubkey);
|
||||||
|
xfree (key->comment);
|
||||||
xfree (key);
|
xfree (key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -793,6 +797,7 @@ ssh_authorized_keys (struct ssh_key_list **r_ssh_key_list)
|
|||||||
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
|
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
|
||||||
line[--len] = '\0';
|
line[--len] = '\0';
|
||||||
|
|
||||||
|
fields[2] = NULL;
|
||||||
if (split_fields (line, fields, DIM (fields)) < 2)
|
if (split_fields (line, fields, DIM (fields)) < 2)
|
||||||
continue; /* Skip empty lines or line with only a field. */
|
continue; /* Skip empty lines or line with only a field. */
|
||||||
if (*fields[0] == '#')
|
if (*fields[0] == '#')
|
||||||
@ -807,6 +812,7 @@ ssh_authorized_keys (struct ssh_key_list **r_ssh_key_list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssh_key->pubkey = strdup (fields[1]);
|
ssh_key->pubkey = strdup (fields[1]);
|
||||||
|
ssh_key->comment = strdup (fields[2]);
|
||||||
if (ssh_key_list)
|
if (ssh_key_list)
|
||||||
ssh_key_prev->next = ssh_key;
|
ssh_key_prev->next = ssh_key;
|
||||||
else
|
else
|
||||||
@ -856,6 +862,8 @@ ga_filter_by_authorized_keys (struct ga_key_list **r_key_list)
|
|||||||
prev->next = cur;
|
prev->next = cur;
|
||||||
else
|
else
|
||||||
key_list = cur;
|
key_list = cur;
|
||||||
|
cur->comment = skl->comment;
|
||||||
|
skl->comment = NULL;
|
||||||
prev = cur;
|
prev = cur;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
@ -892,14 +900,24 @@ ga_release_auth_keys (struct ga_key_list *key_list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
getpin (const char *info, char *buf, size_t *r_len)
|
getpin (assuan_context_t ctx, const char *info, char *buf, size_t *r_len)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char line[ASSUAN_LINELENGTH];
|
char line[ASSUAN_LINELENGTH];
|
||||||
const char *fields[2];
|
const char *fields[2];
|
||||||
|
const char *comment;
|
||||||
|
|
||||||
(void)info;
|
(void)info;
|
||||||
|
|
||||||
|
comment = assuan_get_pointer (ctx);
|
||||||
|
if (comment)
|
||||||
|
{
|
||||||
|
int msg_len = 5 + strlen (comment);
|
||||||
|
fprintf (stdout, "i %d\n", msg_len);
|
||||||
|
fprintf (stdout, "KEY: %s\n", comment);
|
||||||
|
fflush (stdout);
|
||||||
|
}
|
||||||
|
|
||||||
fputs ("P 18\n", stdout);
|
fputs ("P 18\n", stdout);
|
||||||
fputs ("Please input PIN: \n", stdout);
|
fputs ("Please input PIN: \n", stdout);
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user