mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
gpg: New options --recipient-file and --hidden-recipient-file.
* g10/gpg.c (oRecipientFile, oHiddenRecipientFile): New. (opts): Add options --recipient-file and --hidden-recipient-file. (main): Implement them. Also remove duplicate code from similar options. * g10/keydb.h (PK_LIST_FROM_FILE): New. (PK_LIST_SHIFT): Bump up. * g10/pkclist.c (expand_group): Take care of PK_LIST_FROM_FILE. (find_and_check_key): Add and implement arg FROM_FILE. (build_pk_list): Pass new value for new arg. * g10/getkey.c (get_pubkey_fromfile): New. * g10/gpgv.c (read_key_from_file): New stub. * g10/test-stubs.c (read_key_from_file): New stub. * g10/server.c (cmd_recipient): Add flag --file. * g10/import.c (read_key_from_file): New. * tests/openpgp/defs.scm (key-file1): New. (key-file2): New. * tests/openpgp/setup.scm: Add their private keys and import the key-file1. * tests/openpgp/encrypt.scm: Add new test. -- Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
073be51a86
commit
a479804c86
13 changed files with 330 additions and 82 deletions
107
g10/import.c
107
g10/import.c
|
@ -220,6 +220,113 @@ import_release_stats_handle (import_stats_t p)
|
|||
}
|
||||
|
||||
|
||||
/* Read a key from a file. Only the first key in the file is
|
||||
* considered and stored at R_KEYBLOCK. FNAME is the name of the
|
||||
* file.
|
||||
*/
|
||||
gpg_error_t
|
||||
read_key_from_file (ctrl_t ctrl, const char *fname, kbnode_t *r_keyblock)
|
||||
{
|
||||
gpg_error_t err;
|
||||
iobuf_t inp;
|
||||
PACKET *pending_pkt = NULL;
|
||||
kbnode_t keyblock = NULL;
|
||||
u32 keyid[2];
|
||||
int v3keys; /* Dummy */
|
||||
int non_self; /* Dummy */
|
||||
|
||||
(void)ctrl;
|
||||
|
||||
*r_keyblock = NULL;
|
||||
|
||||
inp = iobuf_open (fname);
|
||||
if (!inp)
|
||||
err = gpg_error_from_syserror ();
|
||||
else if (is_secured_file (iobuf_get_fd (inp)))
|
||||
{
|
||||
iobuf_close (inp);
|
||||
inp = NULL;
|
||||
err = gpg_error (GPG_ERR_EPERM);
|
||||
}
|
||||
else
|
||||
err = 0;
|
||||
if (err)
|
||||
{
|
||||
log_error (_("can't open '%s': %s\n"),
|
||||
iobuf_is_pipe_filename (fname)? "[stdin]": fname,
|
||||
gpg_strerror (err));
|
||||
if (gpg_err_code (err) == GPG_ERR_ENOENT)
|
||||
err = gpg_error (GPG_ERR_NO_PUBKEY);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Push the armor filter. */
|
||||
{
|
||||
armor_filter_context_t *afx;
|
||||
afx = new_armor_context ();
|
||||
afx->only_keyblocks = 1;
|
||||
push_armor_filter (afx, inp);
|
||||
release_armor_context (afx);
|
||||
}
|
||||
|
||||
/* Read the first non-v3 keyblock. */
|
||||
while (!(err = read_block (inp, &pending_pkt, &keyblock, &v3keys)))
|
||||
{
|
||||
if (keyblock->pkt->pkttype == PKT_PUBLIC_KEY)
|
||||
break;
|
||||
log_info (_("skipping block of type %d\n"), keyblock->pkt->pkttype);
|
||||
release_kbnode (keyblock);
|
||||
keyblock = NULL;
|
||||
}
|
||||
if (err)
|
||||
{
|
||||
if (gpg_err_code (err) != GPG_ERR_INV_KEYRING)
|
||||
log_error (_("error reading '%s': %s\n"),
|
||||
iobuf_is_pipe_filename (fname)? "[stdin]": fname,
|
||||
gpg_strerror (err));
|
||||
goto leave;
|
||||
}
|
||||
|
||||
keyid_from_pk (keyblock->pkt->pkt.public_key, keyid);
|
||||
|
||||
if (!find_next_kbnode (keyblock, PKT_USER_ID))
|
||||
{
|
||||
err = gpg_error (GPG_ERR_NO_USER_ID);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
collapse_uids (&keyblock);
|
||||
|
||||
clear_kbnode_flags (keyblock);
|
||||
if (chk_self_sigs (keyblock, keyid, &non_self))
|
||||
{
|
||||
err = gpg_error (GPG_ERR_INV_KEYRING);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if (!delete_inv_parts (keyblock, keyid, 0) )
|
||||
{
|
||||
err = gpg_error (GPG_ERR_NO_USER_ID);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
*r_keyblock = keyblock;
|
||||
keyblock = NULL;
|
||||
|
||||
leave:
|
||||
if (inp)
|
||||
{
|
||||
iobuf_close (inp);
|
||||
/* Must invalidate that ugly cache to actually close the file. */
|
||||
iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname);
|
||||
}
|
||||
release_kbnode (keyblock);
|
||||
/* FIXME: Do we need to free PENDING_PKT ? */
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Import the public keys from the given filename. Input may be armored.
|
||||
* This function rejects all keys which are not validly self signed on at
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue