summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-07-16 12:00:46 +0200
committerWerner Koch <wk@gnupg.org>2020-07-16 12:00:46 +0200
commit7f9e0ca57b29cc96bd1ca717d891c11db7435c5a (patch)
tree626649d39737ff25e85c035e64777b8898cf03fe /tests
parent858909168298e8c6fb6f9f9009be2ee2d0d9f0ec (diff)
downloadgpgme-7f9e0ca57b29cc96bd1ca717d891c11db7435c5a.tar.gz
core: New export mode to export as OpenSSH public key.
* src/gpgme.h.in (GPGME_EXPORT_MODE_SSH): New. * src/export.c (export_ext_start): Allow for new mode. * src/engine-gpg.c (export_common): Implement. * tests/run-export.c (status_cb): New. (main): New options --status and --ssh. -- GnuPG-bug-id: 4310 Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/run-export.c110
1 files changed, 74 insertions, 36 deletions
diff --git a/tests/run-export.c b/tests/run-export.c
index ecce80dc..623c7331 100644
--- a/tests/run-export.c
+++ b/tests/run-export.c
@@ -38,14 +38,25 @@
static int verbose;
+static gpg_error_t
+status_cb (void *opaque, const char *keyword, const char *value)
+{
+ (void)opaque;
+ fprintf (stderr, "status_cb: %s %s\n", keyword, value);
+ return 0;
+}
+
+
static int
show_usage (int ex)
{
fputs ("usage: " PGM " [options] USERIDS\n\n"
"Options:\n"
" --verbose run in verbose mode\n"
+ " --status print status lines from the backend\n"
" --openpgp use OpenPGP protocol (default)\n"
" --cms use X.509 protocol\n"
+ " --ssh export as ssh public key\n"
" --extern send keys to the keyserver (TAKE CARE!)\n"
" --secret export secret keys instead of public keys\n"
" --raw use PKCS#1 as secret key format\n"
@@ -67,6 +78,7 @@ main (int argc, char **argv)
gpgme_data_t out;
gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP;
gpgme_export_mode_t mode = 0;
+ int print_status = 0;
if (argc)
{ argc--; argv++; }
@@ -86,6 +98,11 @@ main (int argc, char **argv)
verbose = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--status"))
+ {
+ print_status = 1;
+ argc--; argv++;
+ }
else if (!strcmp (*argv, "--openpgp"))
{
protocol = GPGME_PROTOCOL_OpenPGP;
@@ -101,6 +118,11 @@ main (int argc, char **argv)
mode |= GPGME_EXPORT_MODE_EXTERN;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--ssh"))
+ {
+ mode |= GPGME_EXPORT_MODE_SSH;
+ argc--; argv++;
+ }
else if (!strcmp (*argv, "--secret"))
{
mode |= GPGME_EXPORT_MODE_SECRET;
@@ -129,52 +151,68 @@ main (int argc, char **argv)
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_protocol (ctx, protocol);
+ if (print_status)
+ {
+ gpgme_set_status_cb (ctx, status_cb, NULL);
+ gpgme_set_ctx_flag (ctx, "full-status", "1");
+ }
- /* Lookup the keys. */
- err = gpgme_op_keylist_ext_start (ctx, (const char**)argv, 0, 0);
+ err = gpgme_data_new (&out);
fail_if_err (err);
- while (!(err = gpgme_op_keylist_next (ctx, &key)))
+ if ((mode & GPGME_EXPORT_MODE_SSH))
{
- printf ("keyid: %s (fpr: %s)\n",
- key->subkeys?nonnull (key->subkeys->keyid):"?",
- key->subkeys?nonnull (key->subkeys->fpr):"?");
+ mode = GPGME_EXPORT_MODE_SSH; /* Set only this bit for this test. */
+ keyarray[0] = NULL;
- if (keyidx < DIM (keyarray)-1)
- keyarray[keyidx++] = key;
- else
- {
- fprintf (stderr, PGM": too many keys"
- "- skipping this key\n");
- gpgme_key_unref (key);
- }
+ err = gpgme_op_export_ext (ctx, (const char**)argv, mode, out);
+ fail_if_err (err);
}
- if (gpgme_err_code (err) != GPG_ERR_EOF)
- fail_if_err (err);
- err = gpgme_op_keylist_end (ctx);
- fail_if_err (err);
- keyarray[keyidx] = NULL;
-
- result = gpgme_op_keylist_result (ctx);
- if (result->truncated)
+ else
{
- fprintf (stderr, PGM ": key listing unexpectedly truncated\n");
- exit (1);
- }
+ /* Lookup the keys as required by the export_keys function. */
+ err = gpgme_op_keylist_ext_start (ctx, (const char**)argv, 0, 0);
+ fail_if_err (err);
- /* Now for the actual export. */
- if ((mode & GPGME_EXPORT_MODE_EXTERN))
- printf ("sending keys to keyserver\n");
- if ((mode & GPGME_EXPORT_MODE_SECRET))
- printf ("exporting secret keys!\n");
+ while (!(err = gpgme_op_keylist_next (ctx, &key)))
+ {
+ printf ("keyid: %s (fpr: %s)\n",
+ key->subkeys?nonnull (key->subkeys->keyid):"?",
+ key->subkeys?nonnull (key->subkeys->fpr):"?");
+
+ if (keyidx < DIM (keyarray)-1)
+ keyarray[keyidx++] = key;
+ else
+ {
+ fprintf (stderr, PGM": too many keys"
+ "- skipping this key\n");
+ gpgme_key_unref (key);
+ }
+ }
+ if (gpgme_err_code (err) != GPG_ERR_EOF)
+ fail_if_err (err);
+ err = gpgme_op_keylist_end (ctx);
+ fail_if_err (err);
+ keyarray[keyidx] = NULL;
+
+ result = gpgme_op_keylist_result (ctx);
+ if (result->truncated)
+ {
+ fprintf (stderr, PGM ": key listing unexpectedly truncated\n");
+ exit (1);
+ }
- err = gpgme_data_new (&out);
- fail_if_err (err);
+ /* Now for the actual export. */
+ if ((mode & GPGME_EXPORT_MODE_EXTERN))
+ printf ("sending keys to keyserver\n");
+ if ((mode & GPGME_EXPORT_MODE_SECRET))
+ printf ("exporting secret keys!\n");
- gpgme_set_armor (ctx, 1);
- err = gpgme_op_export_keys (ctx, keyarray, mode,
- (mode & GPGME_KEYLIST_MODE_EXTERN)? NULL:out);
- fail_if_err (err);
+ gpgme_set_armor (ctx, 1);
+ err = gpgme_op_export_keys (ctx, keyarray, mode,
+ (mode & GPGME_KEYLIST_MODE_EXTERN)? NULL:out);
+ fail_if_err (err);
+ }
fflush (NULL);
if (!(mode & GPGME_KEYLIST_MODE_EXTERN))