From 475644e049436c49de7620a1539515479ad2aa4f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 19 Mar 2021 18:28:00 +0100 Subject: [PATCH] card: Support OpenPGP.1 and OpenPGP.2 for readcert and writecert. * tools/gpg-card.c (cmd_writecert): Allow the other key references. (cmd_readcert): Ditto. -- See previous commit for testing info. Signed-off-by: Werner Koch --- tools/gpg-card.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/gpg-card.c b/tools/gpg-card.c index 9257bc78f..0b6acc27d 100644 --- a/tools/gpg-card.c +++ b/tools/gpg-card.c @@ -1970,13 +1970,20 @@ cmd_writecert (card_info_t info, char *argstr) if (info->apptype == APP_TYPE_OPENPGP) { - if (ascii_strcasecmp (certref, "OPENPGP.3") && strcmp (certref, "3")) + if (!ascii_strcasecmp (certref, "OPENPGP.3") || !strcmp (certref, "3")) + certref_buffer = xstrdup ("OPENPGP.3"); + else if (!ascii_strcasecmp (certref, "OPENPGP.2")||!strcmp (certref,"2")) + certref_buffer = xstrdup ("OPENPGP.2"); + else if (!ascii_strcasecmp (certref, "OPENPGP.1")||!strcmp (certref,"1")) + certref_buffer = xstrdup ("OPENPGP.1"); + else { err = gpg_error (GPG_ERR_INV_ID); - log_error ("Error: CERTREF must be \"3\" or \"OPENPGP.3\"\n"); + log_error ("Error: CERTREF must be OPENPGP.N or just N" + " with N being 1..3\""); goto leave; } - certref = certref_buffer = xstrdup ("OPENPGP.3"); + certref = certref_buffer; } else /* Upcase the certref; prepend cardtype if needed. */ { @@ -2108,13 +2115,20 @@ cmd_readcert (card_info_t info, char *argstr) if (info->apptype == APP_TYPE_OPENPGP) { - if (ascii_strcasecmp (certref, "OPENPGP.3") && strcmp (certref, "3")) + if (!ascii_strcasecmp (certref, "OPENPGP.3") || !strcmp (certref, "3")) + certref_buffer = xstrdup ("OPENPGP.3"); + else if (!ascii_strcasecmp (certref, "OPENPGP.2")||!strcmp (certref,"2")) + certref_buffer = xstrdup ("OPENPGP.2"); + else if (!ascii_strcasecmp (certref, "OPENPGP.1")||!strcmp (certref,"1")) + certref_buffer = xstrdup ("OPENPGP.1"); + else { err = gpg_error (GPG_ERR_INV_ID); - log_error ("Error: CERTREF must be \"3\" or \"OPENPGP.3\"\n"); + log_error ("Error: CERTREF must be OPENPGP.N or just N" + " with N being 1..3\""); goto leave; } - certref = certref_buffer = xstrdup ("OPENPGP.3"); + certref = certref_buffer; } if (*argstr == '>') /* Write it to a file */