diff options
| author | Werner Koch <[email protected]> | 2022-12-02 09:03:36 +0000 |
|---|---|---|
| committer | Werner Koch <[email protected]> | 2022-12-02 09:09:58 +0000 |
| commit | 1a85ee9a431bd2243e0ad79ce5eefa78e274a491 (patch) | |
| tree | 9b2e33d41d5c373110efd33e00aafba723ca2308 /agent/command.c | |
| parent | gpg: Remove a mostly duplicated function. (diff) | |
| download | gnupg-1a85ee9a431bd2243e0ad79ce5eefa78e274a491.tar.gz gnupg-1a85ee9a431bd2243e0ad79ce5eefa78e274a491.zip | |
gpg: New export option "mode1003".
* agent/command.c (cmd_export_key): Add option --mode1003.
(command_has_option): Ditto.
* g10/build-packet.c (do_key): Implement mode 1003.
* g10/parse-packet.c (parse_key): Ditto.
* g10/options.h (EXPORT_MODE1003): New.o
* g10/call-agent.c (agent_export_key): Add arg mode1003.
* g10/export.c (parse_export_options): Add "mode1003"
(secret_key_to_mode1003): New.
(receive_seckey_from_agent): Add arg mode1003.
(do_export_one_keyblock): Pass option down.
--
This option allows to export a secret key in GnuPG's native format.
Thus no re-encryption is required and further the public key parameters
are also authenticated if a protection passphrase has been used.
Note that --import is not yet able to handle this new mode. Although
old version of GnuPG will bail out with "invalid packet" if a mode1003
exported secret key is seen.
Diffstat (limited to 'agent/command.c')
| -rw-r--r-- | agent/command.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/agent/command.c b/agent/command.c index 840f9f38e..8b5434bfb 100644 --- a/agent/command.c +++ b/agent/command.c @@ -2935,7 +2935,7 @@ cmd_import_key (assuan_context_t ctx, char *line) static const char hlp_export_key[] = - "EXPORT_KEY [--cache-nonce=<nonce>] [--openpgp] <hexstring_with_keygrip>\n" + "EXPORT_KEY [--cache-nonce=<nonce>] [--openpgp|--mode1003] <hexkeygrip>\n" "\n" "Export a secret key from the key store. The key will be encrypted\n" "using the current session's key wrapping key (cf. command KEYWRAP_KEY)\n" @@ -2943,9 +2943,10 @@ static const char hlp_export_key[] = "prior to using this command. The function takes the keygrip as argument.\n" "\n" "If --openpgp is used, the secret key material will be exported in RFC 4880\n" - "compatible passphrase-protected form. Without --openpgp, the secret key\n" - "material will be exported in the clear (after prompting the user to unlock\n" - "it, if needed).\n"; + "compatible passphrase-protected form. If --mode1003 is use the secret key\n" + "is exported as s-expression as storred locally. Without those options,\n" + "the secret key material will be exported in the clear (after prompting\n" + "the user to unlock it, if needed).\n"; static gpg_error_t cmd_export_key (assuan_context_t ctx, char *line) { @@ -2958,7 +2959,7 @@ cmd_export_key (assuan_context_t ctx, char *line) gcry_cipher_hd_t cipherhd = NULL; unsigned char *wrappedkey = NULL; size_t wrappedkeylen; - int openpgp; + int openpgp, mode1003; char *cache_nonce; char *passphrase = NULL; unsigned char *shadow_info = NULL; @@ -2969,6 +2970,10 @@ cmd_export_key (assuan_context_t ctx, char *line) return leave_cmd (ctx, gpg_error (GPG_ERR_FORBIDDEN)); openpgp = has_option (line, "--openpgp"); + mode1003 = has_option (line, "--mode1003"); + if (mode1003) + openpgp = 0; + cache_nonce = option_value (line, "--cache-nonce"); if (cache_nonce) { @@ -3003,11 +3008,17 @@ cmd_export_key (assuan_context_t ctx, char *line) } /* Get the key from the file. With the openpgp flag we also ask for - the passphrase so that we can use it to re-encrypt it. */ - err = agent_key_from_file (ctrl, cache_nonce, - ctrl->server_local->keydesc, grip, - &shadow_info, CACHE_MODE_IGNORE, NULL, &s_skey, - openpgp ? &passphrase : NULL, NULL); + * the passphrase so that we can use it to re-encrypt it. In + * mode1003 we return the key as-is. FIXME: if the key is still in + * OpenPGP-native mode we should first convert it to our internal + * protection. */ + if (mode1003) + err = agent_raw_key_from_file (ctrl, grip, &s_skey, NULL); + else + err = agent_key_from_file (ctrl, cache_nonce, + ctrl->server_local->keydesc, grip, + &shadow_info, CACHE_MODE_IGNORE, NULL, &s_skey, + openpgp ? &passphrase : NULL, NULL); if (err) goto leave; if (shadow_info) @@ -4150,6 +4161,11 @@ command_has_option (const char *cmd, const char *cmdopt) if (!strcmp (cmdopt, "newsymkey")) return 1; } + else if (!strcmp (cmd, "EXPORT_KEY")) + { + if (!strcmp (cmdopt, "mode1003")) + return 1; + } return 0; } |
