card: Allow PEM encoded certificates in "writecert".
authorWerner Koch <wk@gnupg.org>
Wed, 6 Mar 2019 11:40:45 +0000 (12:40 +0100)
committerWerner Koch <wk@gnupg.org>
Wed, 6 Mar 2019 11:40:45 +0000 (12:40 +0100)
* tools/gpg-card.c (cmd_writecert): Convert from base64.

Signed-off-by: Werner Koch <wk@gnupg.org>
tools/gpg-card.c

index c9b8380..e2d728d 100644 (file)
@@ -1647,6 +1647,20 @@ cmd_writecert (card_info_t info, char *argstr)
       err = get_data_from_file (argstr, &data, &datalen);
       if (err)
         goto leave;
+      if (ascii_memistr (data, datalen, "-----BEGIN CERTIFICATE-----")
+          && ascii_memistr (data, datalen, "-----END CERTIFICATE-----")
+          && !memchr (data, 0, datalen) && !memchr (data, 1, datalen))
+        {
+          struct b64state b64;
+
+          err = b64dec_start (&b64, "");
+          if (!err)
+            err = b64dec_proc (&b64, data, datalen, &datalen);
+          if (!err)
+            err = b64dec_finish (&b64);
+          if (err)
+            goto leave;
+        }
     }
   else
     {