mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Implement unattended OpenPGP secret key import.
* agent/command.c (cmd_import_key): Add option --unattended. * agent/cvt-openpgp.c (convert_transfer_key): New. (do_unprotect): Factor some code out to ... (prepare_unprotect): new function. (convert_from_openpgp): Factor all code out to ... (convert_from_openpgp_main): this. Add arg 'passphrase'. Implement openpgp-native protection modes. (convert_from_openpgp_native): New. * agent/t-protect.c (convert_from_openpgp_native): New dummy fucntion * agent/protect-tool.c (convert_from_openpgp_native): Ditto. * agent/protect.c (agent_unprotect): Add arg CTRL. Adjust all callers. Support openpgp-native protection. * g10/call-agent.c (agent_import_key): Add arg 'unattended'. * g10/import.c (transfer_secret_keys): Use unattended in batch mode. -- With the gpg-agent taking care of the secret keys, the user needs to migrate existing keys from secring.gpg to the agent. This and also the standard import of secret keys required the user to unprotect the secret keys first, so that gpg-agent was able to re-protected them using its own scheme. With many secret keys this is quite some usability hurdle. In particular if a passphrase is not instantly available. To make this migration smoother, this patch implements an unattended key import/migration which delays the conversion to the gpg-agent format until the key is actually used. For example: gpg2 --batch --import mysecretkey.gpg works without any user interaction due to the use of --batch. Now if a key is used (e.g. "gpg2 -su USERID_FROM_MYSECRETKEY foo"), gpg-agent has to ask for the passphrase anyway, converts the key from the openpgp format to the internal format, signs, re-encrypts the key and tries to store it in the gpg-agent format to the disk. The next time, the internal format of the key is used. This patch has only been tested with the old demo keys, more tests with other protection formats and no protection are needed. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
cb6a64bb78
commit
7777e68d04
13 changed files with 475 additions and 171 deletions
|
@ -1998,7 +1998,7 @@ inq_import_key_parms (void *opaque, const char *line)
|
|||
/* Call the agent to import a key into the agent. */
|
||||
gpg_error_t
|
||||
agent_import_key (ctrl_t ctrl, const char *desc, char **cache_nonce_addr,
|
||||
const void *key, size_t keylen)
|
||||
const void *key, size_t keylen, int unattended)
|
||||
{
|
||||
gpg_error_t err;
|
||||
struct import_key_parm_s parm;
|
||||
|
@ -2028,7 +2028,8 @@ agent_import_key (ctrl_t ctrl, const char *desc, char **cache_nonce_addr,
|
|||
parm.key = key;
|
||||
parm.keylen = keylen;
|
||||
|
||||
snprintf (line, sizeof line, "IMPORT_KEY%s%s",
|
||||
snprintf (line, sizeof line, "IMPORT_KEY%s%s%s",
|
||||
unattended? " --unattended":"",
|
||||
cache_nonce_addr && *cache_nonce_addr? " ":"",
|
||||
cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:"");
|
||||
cn_parm.cache_nonce_addr = cache_nonce_addr;
|
||||
|
|
|
@ -177,7 +177,7 @@ gpg_error_t agent_keywrap_key (ctrl_t ctrl, int forexport,
|
|||
/* Send a key to the agent. */
|
||||
gpg_error_t agent_import_key (ctrl_t ctrl, const char *desc,
|
||||
char **cache_nonce_addr,
|
||||
const void *key, size_t keylen);
|
||||
const void *key, size_t keylen, int unattended);
|
||||
|
||||
/* Receive a key from the agent. */
|
||||
gpg_error_t agent_export_key (ctrl_t ctrl, const char *keygrip,
|
||||
|
|
|
@ -1432,7 +1432,7 @@ transfer_secret_keys (ctrl_t ctrl, struct stats_s *stats, kbnode_t sec_keyblock)
|
|||
{
|
||||
char *desc = gpg_format_keydesc (pk, 1, 1);
|
||||
err = agent_import_key (ctrl, desc, &cache_nonce,
|
||||
wrappedkey, wrappedkeylen);
|
||||
wrappedkey, wrappedkeylen, opt.batch);
|
||||
xfree (desc);
|
||||
}
|
||||
if (!err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue