diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-02-09 16:00:04 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-02-09 16:00:04 +0900 |
commit | a96eb3d6fb24d0f4430469d6f7224345df4d5570 (patch) | |
tree | 245128281599d185257e1edf0bc2fde60604107e /sm | |
parent | 7f297dd64af2a4fe4397d5bdaba00fe68f49390d (diff) | |
download | gpg2-a96eb3d6fb24d0f4430469d6f7224345df4d5570.tar.gz gpg2-a96eb3d6fb24d0f4430469d6f7224345df4d5570.tar.bz2 gpg2-a96eb3d6fb24d0f4430469d6f7224345df4d5570.zip |
Imported Upstream version 2.1.8upstream/2.1.8
Diffstat (limited to 'sm')
-rw-r--r-- | sm/Makefile.am | 4 | ||||
-rw-r--r-- | sm/server.c | 36 |
2 files changed, 33 insertions, 7 deletions
diff --git a/sm/Makefile.am b/sm/Makefile.am index dda3eb8..43e3598 100644 --- a/sm/Makefile.am +++ b/sm/Makefile.am @@ -23,7 +23,7 @@ bin_PROGRAMS = gpgsm AM_CFLAGS = $(LIBGCRYPT_CFLAGS) $(KSBA_CFLAGS) $(LIBASSUAN_CFLAGS) -AM_CPPFLAGS = -I$(top_srcdir)/common +AM_CPPFLAGS = -I$(top_srcdir)/common -DKEYBOX_WITH_X509=1 include $(top_srcdir)/am/cmacros.am if HAVE_W32_SYSTEM @@ -57,7 +57,7 @@ gpgsm_SOURCES = \ qualified.c -common_libs = ../kbx/libkeybox.a $(libcommon) +common_libs = ../kbx/libkeybox509.a $(libcommon) gpgsm_LDADD = $(common_libs) ../common/libgpgrl.a \ $(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(LIBASSUAN_LIBS) \ diff --git a/sm/server.c b/sm/server.c index 571b079..cdf4a6e 100644 --- a/sm/server.c +++ b/sm/server.c @@ -681,13 +681,15 @@ cmd_import (assuan_context_t ctx, char *line) static const char hlp_export[] = - "EXPORT [--data [--armor|--base64]] [--] <pattern>\n" + "EXPORT [--data [--armor|--base64]] [--secret [--(raw|pkcs12)] [--] <pattern>\n" "\n" "Export the certificates selected by PATTERN. With --data the output\n" "is returned using Assuan D lines; the default is to use the sink given\n" "by the last \"OUTPUT\" command. The options --armor or --base64 encode \n" "the output using the PEM respective a plain base-64 format; the default\n" - "is a binary format which is only suitable for a single certificate."; + "is a binary format which is only suitable for a single certificate.\n" + "With --secret the secret key is exported using the PKCS#8 format,\n" + "with --raw using PKCS#1, and with --pkcs12 as full PKCS#12 container."; static gpg_error_t cmd_export (assuan_context_t ctx, char *line) { @@ -695,15 +697,23 @@ cmd_export (assuan_context_t ctx, char *line) char *p; strlist_t list, sl; int use_data; + int opt_secret; + int opt_raw = 0; + int opt_pkcs12 = 0; use_data = has_option (line, "--data"); - if (use_data) { /* We need to override any possible setting done by an OUTPUT command. */ ctrl->create_pem = has_option (line, "--armor"); ctrl->create_base64 = has_option (line, "--base64"); } + opt_secret = has_option (line, "--secret"); + if (opt_secret) + { + opt_raw = has_option (line, "--raw"); + opt_pkcs12 = has_option (line, "--pkcs12"); + } line = skip_options (line); @@ -730,6 +740,14 @@ cmd_export (assuan_context_t ctx, char *line) } } + if (opt_secret) + { + if (!list || !*list->d) + return set_error (GPG_ERR_NO_DATA, "No key given"); + if (list->next) + return set_error (GPG_ERR_TOO_MANY, "Only one key allowed"); + } + if (use_data) { estream_t stream; @@ -741,7 +759,11 @@ cmd_export (assuan_context_t ctx, char *line) return set_error (GPG_ERR_ASS_GENERAL, "error setting up a data stream"); } - gpgsm_export (ctrl, list, stream); + if (opt_secret) + gpgsm_p12_export (ctrl, list->d, stream, + opt_raw? 2 : opt_pkcs12 ? 0 : 1); + else + gpgsm_export (ctrl, list, stream); es_fclose (stream); } else @@ -761,7 +783,11 @@ cmd_export (assuan_context_t ctx, char *line) return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); } - gpgsm_export (ctrl, list, out_fp); + if (opt_secret) + gpgsm_p12_export (ctrl, list->d, out_fp, + opt_raw? 2 : opt_pkcs12 ? 0 : 1); + else + gpgsm_export (ctrl, list, out_fp); es_fclose (out_fp); } |