summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2022-09-05 07:42:06 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2022-09-05 07:42:06 +0200
commit7a22f764d51881d0dd2151633b7615c8db664a61 (patch)
tree8ce598d2a413b5094264a0b2a7d1395cd86afc01 /tools
parenttools: Fix gpg-auth. (diff)
downloadgnupg2-7a22f764d51881d0dd2151633b7615c8db664a61.tar.xz
gnupg2-7a22f764d51881d0dd2151633b7615c8db664a61.zip
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/gpg-auth.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/tools/gpg-auth.c b/tools/gpg-auth.c
index eafe125bf..cc8cc3943 100644
--- a/tools/gpg-auth.c
+++ b/tools/gpg-auth.c
@@ -187,6 +187,7 @@ struct ga_key_list {
char keygrip[41]; /* Keygrip to identify a key. */
size_t pubkey_len;
char *pubkey; /* Public key in SSH format. */
+ char *comment;
};
/* 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 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 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. */
int
@@ -269,6 +270,7 @@ authenticate (assuan_context_t ctx, struct ga_key_list *key_list)
if (err)
return err;
+ assuan_set_pointer (ctx, key_list->comment);
err = scd_pkauth (ctx, key_list->keygrip);
if (!err)
/* Success! */
@@ -517,7 +519,7 @@ inq_needpin (void *opaque, const char *line)
if (!pin)
return out_of_core ();
- rc = getpin (line, pin, &pinlen);
+ rc = getpin (ctx, line, pin, &pinlen);
if (!rc)
{
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 *next;
char *pubkey; /* Public key in SSH format. */
+ char *comment;
};
static void
@@ -747,6 +750,7 @@ release_ssh_key_list (struct ssh_key_list *key_list)
key = key_list;
key_list = key_list->next;
xfree (key->pubkey);
+ xfree (key->comment);
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'))
line[--len] = '\0';
+ fields[2] = NULL;
if (split_fields (line, fields, DIM (fields)) < 2)
continue; /* Skip empty lines or line with only a field. */
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->comment = strdup (fields[2]);
if (ssh_key_list)
ssh_key_prev->next = ssh_key;
else
@@ -856,6 +862,8 @@ ga_filter_by_authorized_keys (struct ga_key_list **r_key_list)
prev->next = cur;
else
key_list = cur;
+ cur->comment = skl->comment;
+ skl->comment = NULL;
prev = cur;
cur = cur->next;
}
@@ -892,14 +900,24 @@ ga_release_auth_keys (struct ga_key_list *key_list)
}
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;
char line[ASSUAN_LINELENGTH];
const char *fields[2];
+ const char *comment;
(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 ("Please input PIN: \n", stdout);
fflush (stdout);