1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-02-07 17:33:02 +01:00

(print_isoname,card_status): Handle opt.with_colons.

(print_sha1_fpr_colon): New.
This commit is contained in:
Werner Koch 2003-09-24 08:31:16 +00:00
parent 4c66e94ff9
commit 791e69e3e9
2 changed files with 154 additions and 49 deletions

View File

@ -1,3 +1,8 @@
2003-09-24 Werner Koch <wk@gnupg.org>
* card-util.c (print_isoname,card_status): Handle opt.with_colons.
(print_sha1_fpr_colon): New.
2003-09-23 Werner Koch <wk@gnupg.org> 2003-09-23 Werner Koch <wk@gnupg.org>
Merged most of David Shaw's changes in 1.3 since 2003-06-03. Merged most of David Shaw's changes in 1.3 since 2003-06-03.

View File

@ -117,6 +117,7 @@ change_pin (int chvno)
static const char * static const char *
get_manufacturer (unsigned int no) get_manufacturer (unsigned int no)
{ {
/* Note: Make sure that there is no colon or linefeed in the string. */
switch (no) switch (no)
{ {
case 0: case 0:
@ -147,13 +148,27 @@ print_sha1_fpr (FILE *fp, const unsigned char *fpr)
} }
static void
print_sha1_fpr_colon (FILE *fp, const unsigned char *fpr)
{
int i;
if (fpr)
{
for (i=0; i < 20 ; i++, fpr++)
fprintf (fp, "%02X", *fpr);
}
putc (':', fp);
}
static void static void
print_name (FILE *fp, const char *text, const char *name) print_name (FILE *fp, const char *text, const char *name)
{ {
tty_fprintf (fp, text); tty_fprintf (fp, text);
/* FIXME: tty_printf_utf8_string2 east everything after and /* FIXME: tty_printf_utf8_string2 eats everything after and
including an @ - e.g. when printing an url. */ including an @ - e.g. when printing an url. */
if (name && *name) if (name && *name)
{ {
@ -168,8 +183,11 @@ print_name (FILE *fp, const char *text, const char *name)
} }
static void static void
print_isoname (FILE *fp, const char *text, const char *name) print_isoname (FILE *fp, const char *text, const char *tag, const char *name)
{ {
if (opt.with_colons)
fprintf (fp, "%s:", tag);
else
tty_fprintf (fp, text); tty_fprintf (fp, text);
if (name && *name) if (name && *name)
@ -184,21 +202,38 @@ print_isoname (FILE *fp, const char *text, const char *name)
{ {
*given = 0; *given = 0;
given += 2; given += 2;
if (fp) if (opt.with_colons)
print_string (fp, given, strlen (given), ':');
else if (fp)
print_utf8_string2 (fp, given, strlen (given), '\n'); print_utf8_string2 (fp, given, strlen (given), '\n');
else else
tty_print_utf8_string2 (given, strlen (given), '\n'); tty_print_utf8_string2 (given, strlen (given), '\n');
if (*buf)
if (opt.with_colons)
putc (':', fp);
else if (*buf)
tty_fprintf (fp, " "); tty_fprintf (fp, " ");
} }
if (fp)
if (opt.with_colons)
print_string (fp, buf, strlen (buf), ':');
else if (fp)
print_utf8_string2 (fp, buf, strlen (buf), '\n'); print_utf8_string2 (fp, buf, strlen (buf), '\n');
else else
tty_print_utf8_string2 (buf, strlen (buf), '\n'); tty_print_utf8_string2 (buf, strlen (buf), '\n');
xfree (buf); xfree (buf);
} }
else
{
if (opt.with_colons)
putc (':', fp);
else else
tty_fprintf (fp, _("[not set]")); tty_fprintf (fp, _("[not set]"));
}
if (opt.with_colons)
fputs (":\n", fp);
else
tty_fprintf (fp, "\n"); tty_fprintf (fp, "\n");
} }
@ -210,26 +245,82 @@ card_status (FILE *fp)
struct agent_card_info_s info; struct agent_card_info_s info;
PKT_public_key *pk = xcalloc (1, sizeof *pk); PKT_public_key *pk = xcalloc (1, sizeof *pk);
int rc; int rc;
unsigned int uval;
rc = agent_learn (&info); rc = agent_learn (&info);
if (rc) if (rc)
{ {
if (opt.with_colons)
fputs ("AID:::\n", fp);
log_error (_("OpenPGP card not available: %s\n"), log_error (_("OpenPGP card not available: %s\n"),
gpg_strerror (rc)); gpg_strerror (rc));
xfree (pk); xfree (pk);
return; return;
} }
if (opt.with_colons)
fprintf (fp, "AID:%s:", info.serialno? info.serialno : "");
else
tty_fprintf (fp, "Application ID ...: %s\n", tty_fprintf (fp, "Application ID ...: %s\n",
info.serialno? info.serialno : "[none]"); info.serialno? info.serialno : "[none]");
if (!info.serialno || strncmp (info.serialno, "D27600012401", 12) if (!info.serialno || strncmp (info.serialno, "D27600012401", 12)
|| strlen (info.serialno) != 32 ) || strlen (info.serialno) != 32 )
{ {
if (opt.with_colons)
fputs ("unknown:\n", fp);
log_info ("not an OpenPGP card\n"); log_info ("not an OpenPGP card\n");
agent_release_card_info (&info); agent_release_card_info (&info);
xfree (pk); xfree (pk);
return; return;
} }
if (opt.with_colons)
fputs ("openpgp-card:\n", fp);
if (opt.with_colons)
{
fprintf (fp, "version:%.4s:\n", info.serialno+12);
uval = xtoi_2(info.serialno+16)*256 + xtoi_2 (info.serialno+18);
fprintf (fp, "vendor:%04x:%s:\n", uval, get_manufacturer (uval));
fprintf (fp, "serial:%.8s:\n", info.serialno+20);
print_isoname (fp, "Name of cardholder: ", "name", info.disp_name);
fputs ("lang:", fp);
if (info.disp_lang)
print_string (fp, info.disp_lang, strlen (info.disp_lang), ':');
fputs (":\n", fp);
fprintf (fp, "sex:%c:\n", (info.disp_sex == 1? 'm':
info.disp_sex == 2? 'f' : 'u'));
fputs ("url:", fp);
if (info.pubkey_url)
print_string (fp, info.pubkey_url, strlen (info.pubkey_url), ':');
fputs (":\n", fp);
fputs ("login:", fp);
if (info.login_data)
print_string (fp, info.login_data, strlen (info.login_data), ':');
fputs (":\n", fp);
fprintf (fp, "forcepin:%d:::\n", !info.chv1_cached);
fprintf (fp, "maxpinlen:%d:%d:%d:\n",
info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]);
fprintf (fp, "pinretry:%d:%d:%d:\n",
info.chvretry[0], info.chvretry[1], info.chvretry[2]);
fprintf (fp, "sigcount:%lu:::\n", info.sig_counter);
fputs ("fpr:", fp);
print_sha1_fpr_colon (fp, info.fpr1valid? info.fpr1:NULL);
print_sha1_fpr_colon (fp, info.fpr2valid? info.fpr2:NULL);
print_sha1_fpr_colon (fp, info.fpr3valid? info.fpr3:NULL);
putc ('\n', fp);
}
else
{
tty_fprintf (fp, "Version ..........: %.1s%c.%.1s%c\n", tty_fprintf (fp, "Version ..........: %.1s%c.%.1s%c\n",
info.serialno[12] == '0'?"":info.serialno+12, info.serialno[12] == '0'?"":info.serialno+12,
info.serialno[13], info.serialno[13],
@ -240,7 +331,7 @@ card_status (FILE *fp)
+ xtoi_2 (info.serialno+18))); + xtoi_2 (info.serialno+18)));
tty_fprintf (fp, "Serial number ....: %.8s\n", info.serialno+20); tty_fprintf (fp, "Serial number ....: %.8s\n", info.serialno+20);
print_isoname (fp, "Name of cardholder: ", info.disp_name); print_isoname (fp, "Name of cardholder: ", "name", info.disp_name);
print_name (fp, "Language prefs ...: ", info.disp_lang); print_name (fp, "Language prefs ...: ", info.disp_lang);
tty_fprintf (fp, "Sex ..............: %s\n", tty_fprintf (fp, "Sex ..............: %s\n",
info.disp_sex == 1? _("male"): info.disp_sex == 1? _("male"):
@ -253,6 +344,7 @@ card_status (FILE *fp)
info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]); info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]);
tty_fprintf (fp, "PIN retry counter : %d %d %d\n", tty_fprintf (fp, "PIN retry counter : %d %d %d\n",
info.chvretry[0], info.chvretry[1], info.chvretry[2]); info.chvretry[0], info.chvretry[1], info.chvretry[2]);
tty_fprintf (fp, "Signature counter : %lu\n", info.sig_counter);
tty_fprintf (fp, "Signature key ....:"); tty_fprintf (fp, "Signature key ....:");
print_sha1_fpr (fp, info.fpr1valid? info.fpr1:NULL); print_sha1_fpr (fp, info.fpr1valid? info.fpr1:NULL);
tty_fprintf (fp, "Encryption key....:"); tty_fprintf (fp, "Encryption key....:");
@ -264,7 +356,7 @@ card_status (FILE *fp)
print_pubkey_info (fp, pk); print_pubkey_info (fp, pk);
else else
fputs ("[none]\n", fp); fputs ("[none]\n", fp);
tty_fprintf (fp, "Signature counter : %lu\n", info.sig_counter); }
free_public_key (pk); free_public_key (pk);
agent_release_card_info (&info); agent_release_card_info (&info);
@ -505,9 +597,17 @@ card_edit (STRLIST commands)
tty_printf("\n"); tty_printf("\n");
if (redisplay ) if (redisplay )
{
if (opt.with_colons)
{
card_status (stdout);
fflush (stdout);
}
else
{ {
card_status (NULL); card_status (NULL);
tty_printf("\n"); tty_printf("\n");
}
redisplay = 0; redisplay = 0;
} }