1998-01-26 23:09:01 +01:00
|
|
|
/* export.c
|
2005-06-08 05:31:48 +02:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
|
|
* 2005 Free Software Foundation, Inc.
|
1998-01-26 23:09:01 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* This file is part of GnuPG.
|
1998-01-26 23:09:01 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1998-01-26 23:09:01 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1998-01-26 23:09:01 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-05-31 10:39:18 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
1998-01-26 23:09:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "options.h"
|
|
|
|
#include "packet.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "keydb.h"
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "memory.h"
|
1998-01-26 23:09:01 +01:00
|
|
|
#include "util.h"
|
1998-02-13 21:58:50 +01:00
|
|
|
#include "main.h"
|
1998-11-10 13:59:59 +01:00
|
|
|
#include "i18n.h"
|
2005-06-08 05:31:48 +02:00
|
|
|
#include "trustdb.h"
|
1998-01-26 23:09:01 +01:00
|
|
|
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
static int do_export( STRLIST users, int secret, unsigned int options );
|
2003-02-26 18:11:24 +01:00
|
|
|
static int do_export_stream( IOBUF out, STRLIST users, int secret,
|
|
|
|
KBNODE *keyblock_out, unsigned int options,
|
|
|
|
int *any );
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
|
|
|
|
int
|
2003-12-28 04:46:43 +01:00
|
|
|
parse_export_options(char *str,unsigned int *options,int noisy)
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
{
|
2003-05-31 23:52:16 +02:00
|
|
|
struct parse_options export_opts[]=
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
{
|
2005-09-15 00:31:21 +02:00
|
|
|
{"export-local-sigs",EXPORT_LOCAL_SIGS,NULL,
|
|
|
|
N_("export signatures that are marked as local-only")},
|
|
|
|
{"export-attributes",EXPORT_ATTRIBUTES,NULL,
|
|
|
|
N_("export attribute user IDs (generally photo IDs)")},
|
|
|
|
{"export-sensitive-revkeys",EXPORT_SENSITIVE_REVKEYS,NULL,
|
|
|
|
N_("export revocation keys that are marked as \"sensitive\"")},
|
|
|
|
{"export-clean-sigs",EXPORT_CLEAN_SIGS,NULL,
|
|
|
|
N_("remove unusable signatures during export")},
|
|
|
|
{"export-clean-uids",EXPORT_CLEAN_UIDS,NULL,
|
|
|
|
N_("remove unusable user IDs during export")},
|
|
|
|
{"export-clean",EXPORT_CLEAN_SIGS|EXPORT_CLEAN_UIDS,NULL,
|
|
|
|
N_("all export-clean-* options from above")},
|
|
|
|
{"export-minimal",
|
|
|
|
EXPORT_MINIMAL|EXPORT_CLEAN_SIGS|EXPORT_CLEAN_UIDS,NULL,
|
|
|
|
N_("export the smallest key possible")},
|
|
|
|
{"export-reset-subkey-passwd",EXPORT_RESET_SUBKEY_PASSWD,NULL,
|
|
|
|
N_("remove the passphrase from exported subkeys")},
|
2004-11-26 16:51:37 +01:00
|
|
|
/* Aliases for backward compatibility */
|
2005-09-15 00:31:21 +02:00
|
|
|
{"include-local-sigs",EXPORT_LOCAL_SIGS,NULL,NULL},
|
|
|
|
{"include-attributes",EXPORT_ATTRIBUTES,NULL,NULL},
|
|
|
|
{"include-sensitive-revkeys",EXPORT_SENSITIVE_REVKEYS,NULL,NULL},
|
2005-06-08 05:31:48 +02:00
|
|
|
/* dummy */
|
2005-09-15 00:31:21 +02:00
|
|
|
{"export-unusable-sigs",0,NULL,NULL},
|
|
|
|
{NULL,0,NULL,NULL}
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
/* add tags for include revoked and disabled? */
|
|
|
|
};
|
|
|
|
|
2003-12-28 04:46:43 +01:00
|
|
|
return parse_options(str,options,export_opts,noisy);
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
}
|
1998-01-26 23:09:01 +01:00
|
|
|
|
|
|
|
/****************
|
1998-04-14 19:51:16 +02:00
|
|
|
* Export the public keys (to standard out or --output).
|
1998-02-13 21:58:50 +01:00
|
|
|
* Depending on opt.armor the output is armored.
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
* options are defined in main.h.
|
2002-07-17 21:48:19 +02:00
|
|
|
* If USERS is NULL, the complete ring will be exported. */
|
1998-01-26 23:09:01 +01:00
|
|
|
int
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
export_pubkeys( STRLIST users, unsigned int options )
|
1998-06-29 14:30:57 +02:00
|
|
|
{
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
return do_export( users, 0, options );
|
1998-06-29 14:30:57 +02:00
|
|
|
}
|
|
|
|
|
1999-01-19 19:37:41 +01:00
|
|
|
/****************
|
|
|
|
* Export to an already opened stream; return -1 if no keys have
|
|
|
|
* been exported
|
|
|
|
*/
|
|
|
|
int
|
2003-02-26 18:11:24 +01:00
|
|
|
export_pubkeys_stream( IOBUF out, STRLIST users,
|
|
|
|
KBNODE *keyblock_out, unsigned int options )
|
1999-01-19 19:37:41 +01:00
|
|
|
{
|
|
|
|
int any, rc;
|
|
|
|
|
2003-02-26 18:11:24 +01:00
|
|
|
rc = do_export_stream( out, users, 0, keyblock_out, options, &any );
|
1999-01-19 19:37:41 +01:00
|
|
|
if( !rc && !any )
|
|
|
|
rc = -1;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1998-06-29 14:30:57 +02:00
|
|
|
int
|
|
|
|
export_seckeys( STRLIST users )
|
|
|
|
{
|
1998-12-10 20:20:47 +01:00
|
|
|
return do_export( users, 1, 0 );
|
1998-06-29 14:30:57 +02:00
|
|
|
}
|
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
int
|
|
|
|
export_secsubkeys( STRLIST users )
|
|
|
|
{
|
|
|
|
return do_export( users, 2, 0 );
|
|
|
|
}
|
|
|
|
|
1998-06-29 14:30:57 +02:00
|
|
|
static int
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
do_export( STRLIST users, int secret, unsigned int options )
|
1998-01-26 23:09:01 +01:00
|
|
|
{
|
1999-01-19 19:37:41 +01:00
|
|
|
IOBUF out = NULL;
|
|
|
|
int any, rc;
|
1998-02-13 21:58:50 +01:00
|
|
|
armor_filter_context_t afx;
|
2002-06-29 15:46:34 +02:00
|
|
|
compress_filter_context_t zfx;
|
1999-01-19 19:37:41 +01:00
|
|
|
|
|
|
|
memset( &afx, 0, sizeof afx);
|
2002-06-29 15:46:34 +02:00
|
|
|
memset( &zfx, 0, sizeof zfx);
|
1999-01-19 19:37:41 +01:00
|
|
|
|
|
|
|
rc = open_outfile( NULL, 0, &out );
|
|
|
|
if( rc )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if( opt.armor ) {
|
|
|
|
afx.what = secret?5:1;
|
|
|
|
iobuf_push_filter( out, armor_filter, &afx );
|
|
|
|
}
|
2003-11-15 23:31:58 +01:00
|
|
|
if( opt.compress_keys )
|
|
|
|
push_compress_filter(out,&zfx,default_compress_algo());
|
1999-01-19 19:37:41 +01:00
|
|
|
|
* misc.c (compress_algo_to_string, string_to_compress_algo,
check_compress_algo): Add bzip2.
* compress.c (compress_filter): Make static to help force the use of
push_compress_filter. Remove default algorithm setting since that is done
in push_compress_filter now.
* main.h: Use named algorithm.
* filter.h, compress.c (push_compress_filter, push_compress_filter2): New.
Figure out which is the appropriate compression filter to use, and push it
into place.
* compress.c (handle_compressed), encode.c (encode_simple, encode_crypt),
sign.c (sign_file, sign_symencrypt_file), import.c (read_block), export.c
(do_export): Use push_compress_filter instead of pushing the compression
filter ourselves.
* compress-bz2.c: New. Bzlib versions of the compression filter routines.
* Makefile.am: Include compress-bz2.c if bz2lib is available.
2003-10-31 06:39:02 +01:00
|
|
|
rc = do_export_stream( out, users, secret, NULL, options, &any );
|
1999-01-19 19:37:41 +01:00
|
|
|
if( rc || !any )
|
|
|
|
iobuf_cancel(out);
|
|
|
|
else
|
|
|
|
iobuf_close(out);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-26 18:11:24 +01:00
|
|
|
/* If keyblock_out is non-NULL, AND the exit code is zero, then it
|
|
|
|
contains a pointer to the first keyblock found and exported. No
|
|
|
|
other keyblocks are exported. The caller must free it. */
|
1999-01-19 19:37:41 +01:00
|
|
|
static int
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
do_export_stream( IOBUF out, STRLIST users, int secret,
|
2003-02-26 18:11:24 +01:00
|
|
|
KBNODE *keyblock_out, unsigned int options, int *any )
|
1999-01-19 19:37:41 +01:00
|
|
|
{
|
|
|
|
int rc = 0;
|
1998-02-13 21:58:50 +01:00
|
|
|
PACKET pkt;
|
|
|
|
KBNODE keyblock = NULL;
|
|
|
|
KBNODE kbctx, node;
|
2003-02-12 19:43:44 +01:00
|
|
|
size_t ndesc, descindex;
|
2002-06-29 15:46:34 +02:00
|
|
|
KEYDB_SEARCH_DESC *desc = NULL;
|
|
|
|
KEYDB_HANDLE kdbhd;
|
1998-02-13 21:58:50 +01:00
|
|
|
STRLIST sl;
|
2004-11-26 17:48:05 +01:00
|
|
|
u32 keyid[2];
|
1998-02-13 21:58:50 +01:00
|
|
|
|
1999-01-19 19:37:41 +01:00
|
|
|
*any = 0;
|
1998-02-13 21:58:50 +01:00
|
|
|
init_packet( &pkt );
|
2002-06-29 15:46:34 +02:00
|
|
|
kdbhd = keydb_new (secret);
|
1998-02-13 21:58:50 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if (!users) {
|
|
|
|
ndesc = 1;
|
2005-07-27 20:10:56 +02:00
|
|
|
desc = xmalloc_clear ( ndesc * sizeof *desc);
|
2002-06-29 15:46:34 +02:00
|
|
|
desc[0].mode = KEYDB_SEARCH_MODE_FIRST;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (ndesc=0, sl=users; sl; sl = sl->next, ndesc++)
|
|
|
|
;
|
2005-07-27 20:10:56 +02:00
|
|
|
desc = xmalloc ( ndesc * sizeof *desc);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
for (ndesc=0, sl=users; sl; sl = sl->next) {
|
|
|
|
if (classify_user_id (sl->d, desc+ndesc))
|
|
|
|
ndesc++;
|
|
|
|
else
|
2004-10-28 03:58:01 +02:00
|
|
|
log_error (_("key \"%s\" not found: %s\n"),
|
2002-06-29 15:46:34 +02:00
|
|
|
sl->d, g10_errstr (G10ERR_INV_USER_ID));
|
|
|
|
}
|
1998-02-13 21:58:50 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/* it would be nice to see which of the given users did
|
|
|
|
actually match one in the keyring. To implement this we
|
|
|
|
need to have a found flag for each entry in desc and to set
|
|
|
|
this we must check all those entries after a match to mark
|
|
|
|
all matched one - currently we stop at the first match. To
|
|
|
|
do this we need an extra flag to enable this feature so */
|
1998-02-13 21:58:50 +01:00
|
|
|
}
|
|
|
|
|
2004-10-14 12:48:15 +02:00
|
|
|
#ifdef ENABLE_SELINUX_HACKS
|
|
|
|
if (secret) {
|
|
|
|
log_error (_("exporting secret keys not allowed\n"));
|
|
|
|
rc = G10ERR_GENERAL;
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-02-12 19:43:44 +01:00
|
|
|
while (!(rc = keydb_search2 (kdbhd, desc, ndesc, &descindex))) {
|
|
|
|
int sha1_warned=0,skip_until_subkey=0;
|
2002-06-29 15:46:34 +02:00
|
|
|
u32 sk_keyid[2];
|
|
|
|
|
|
|
|
if (!users)
|
|
|
|
desc[0].mode = KEYDB_SEARCH_MODE_NEXT;
|
|
|
|
|
|
|
|
/* read the keyblock */
|
|
|
|
rc = keydb_get_keyblock (kdbhd, &keyblock );
|
|
|
|
if( rc ) {
|
|
|
|
log_error (_("error reading keyblock: %s\n"), g10_errstr(rc) );
|
|
|
|
goto leave;
|
|
|
|
}
|
1998-12-10 20:20:47 +01:00
|
|
|
|
2004-11-25 04:58:42 +01:00
|
|
|
if((node=find_kbnode(keyblock,PKT_SECRET_KEY)))
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
PKT_secret_key *sk=node->pkt->pkt.secret_key;
|
|
|
|
|
|
|
|
keyid_from_sk(sk,sk_keyid);
|
|
|
|
|
|
|
|
/* we can't apply GNU mode 1001 on an unprotected key */
|
|
|
|
if( secret == 2 && !sk->is_protected )
|
|
|
|
{
|
2004-03-05 01:01:25 +01:00
|
|
|
log_info(_("key %s: not protected - skipped\n"),
|
|
|
|
keystr(sk_keyid));
|
2002-06-29 15:46:34 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no v3 keys with GNU mode 1001 */
|
|
|
|
if( secret == 2 && sk->version == 3 )
|
|
|
|
{
|
2004-03-05 01:01:25 +01:00
|
|
|
log_info(_("key %s: PGP 2.x style key - skipped\n"),
|
|
|
|
keystr(sk_keyid));
|
2002-06-29 15:46:34 +02:00
|
|
|
continue;
|
|
|
|
}
|
2005-08-04 11:53:21 +02:00
|
|
|
|
|
|
|
/* It does not make sense to export a key with a primary
|
|
|
|
key on card using a non-key stub. We simply skip those
|
|
|
|
keys when used with --export-secret-subkeys. */
|
|
|
|
if (secret == 2 && sk->is_protected
|
|
|
|
&& sk->protect.s2k.mode == 1002 )
|
|
|
|
{
|
|
|
|
log_info(_("key %s: key material on-card - skipped\n"),
|
|
|
|
keystr(sk_keyid));
|
|
|
|
continue;
|
|
|
|
}
|
2005-06-08 05:31:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It's a public key export */
|
|
|
|
if((options&EXPORT_MINIMAL)
|
|
|
|
&& (node=find_kbnode(keyblock,PKT_PUBLIC_KEY)))
|
|
|
|
keyid_from_pk(node->pkt->pkt.public_key,keyid);
|
|
|
|
|
|
|
|
if(options&EXPORT_CLEAN_UIDS)
|
|
|
|
clean_uids_from_key(keyblock,opt.verbose);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2000-07-14 19:34:53 +02:00
|
|
|
|
1998-02-13 21:58:50 +01:00
|
|
|
/* and write it */
|
|
|
|
for( kbctx=NULL; (node = walk_kbnode( keyblock, &kbctx, 0 )); ) {
|
2003-02-12 19:43:44 +01:00
|
|
|
if( skip_until_subkey )
|
|
|
|
{
|
|
|
|
if(node->pkt->pkttype==PKT_PUBLIC_SUBKEY
|
|
|
|
|| node->pkt->pkttype==PKT_SECRET_SUBKEY)
|
|
|
|
skip_until_subkey=0;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-05-14 04:38:31 +02:00
|
|
|
/* We used to use comment packets, but not any longer. In
|
|
|
|
case we still have comments on a key, strip them here
|
|
|
|
before we call build_packet(). */
|
|
|
|
if( node->pkt->pkttype == PKT_COMMENT )
|
|
|
|
continue;
|
2003-02-12 19:43:44 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/* make sure that ring_trust packets never get exported */
|
|
|
|
if (node->pkt->pkttype == PKT_RING_TRUST)
|
|
|
|
continue;
|
|
|
|
|
2003-02-12 19:43:44 +01:00
|
|
|
/* If exact is set, then we only export what was requested
|
|
|
|
(plus the primary key, if the user didn't specifically
|
|
|
|
request it) */
|
|
|
|
if(desc[descindex].exact
|
|
|
|
&& (node->pkt->pkttype==PKT_PUBLIC_SUBKEY
|
|
|
|
|| node->pkt->pkttype==PKT_SECRET_SUBKEY))
|
|
|
|
{
|
|
|
|
u32 kid[2];
|
|
|
|
byte fpr[MAX_FINGERPRINT_LEN];
|
|
|
|
size_t fprlen;
|
|
|
|
|
|
|
|
switch(desc[descindex].mode)
|
|
|
|
{
|
|
|
|
case KEYDB_SEARCH_MODE_SHORT_KID:
|
|
|
|
case KEYDB_SEARCH_MODE_LONG_KID:
|
|
|
|
if(node->pkt->pkttype==PKT_PUBLIC_SUBKEY)
|
|
|
|
keyid_from_pk(node->pkt->pkt.public_key,kid);
|
|
|
|
else
|
|
|
|
keyid_from_sk(node->pkt->pkt.secret_key,kid);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYDB_SEARCH_MODE_FPR16:
|
|
|
|
case KEYDB_SEARCH_MODE_FPR20:
|
|
|
|
case KEYDB_SEARCH_MODE_FPR:
|
|
|
|
if(node->pkt->pkttype==PKT_PUBLIC_SUBKEY)
|
|
|
|
fingerprint_from_pk(node->pkt->pkt.public_key,
|
|
|
|
fpr,&fprlen);
|
|
|
|
else
|
|
|
|
fingerprint_from_sk(node->pkt->pkt.secret_key,
|
|
|
|
fpr,&fprlen);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(desc[descindex].mode)
|
|
|
|
{
|
|
|
|
case KEYDB_SEARCH_MODE_SHORT_KID:
|
|
|
|
if (desc[descindex].u.kid[1] != kid[1])
|
|
|
|
skip_until_subkey=1;
|
|
|
|
break;
|
|
|
|
case KEYDB_SEARCH_MODE_LONG_KID:
|
|
|
|
if (desc[descindex].u.kid[0] != kid[0]
|
|
|
|
|| desc[descindex].u.kid[1] != kid[1])
|
|
|
|
skip_until_subkey=1;
|
|
|
|
break;
|
|
|
|
case KEYDB_SEARCH_MODE_FPR16:
|
|
|
|
if (memcmp (desc[descindex].u.fpr, fpr, 16))
|
|
|
|
skip_until_subkey=1;
|
|
|
|
break;
|
|
|
|
case KEYDB_SEARCH_MODE_FPR20:
|
|
|
|
case KEYDB_SEARCH_MODE_FPR:
|
|
|
|
if (memcmp (desc[descindex].u.fpr, fpr, 20))
|
|
|
|
skip_until_subkey=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-10-06 12:38:23 +02:00
|
|
|
|
|
|
|
/* XXX: before skipping a subkey, check whether any
|
|
|
|
other description wants an exact macth on a subkey
|
|
|
|
and include that subkey into the output too. Need
|
|
|
|
to add this subkey to a list so that it won't get
|
|
|
|
processed a second time.
|
|
|
|
|
|
|
|
So the first step here is to check that list and
|
|
|
|
skip in any case if the key is in that list.
|
|
|
|
|
|
|
|
We need this whole mess becuase the import fnction
|
|
|
|
is not able to merge secret key and thus it is not
|
|
|
|
possible to output them as two keys and have import
|
|
|
|
merge them.
|
|
|
|
*/
|
2003-02-12 19:43:44 +01:00
|
|
|
|
|
|
|
if(skip_until_subkey)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-06-08 05:31:48 +02:00
|
|
|
if(node->pkt->pkttype==PKT_USER_ID)
|
|
|
|
{
|
|
|
|
/* Run clean_sigs_from_uid against each uid if
|
|
|
|
export-clean-sigs is on. */
|
|
|
|
if(options&EXPORT_CLEAN_SIGS)
|
|
|
|
clean_sigs_from_uid(keyblock,node,opt.verbose);
|
|
|
|
}
|
|
|
|
else if(node->pkt->pkttype==PKT_SIGNATURE)
|
2004-11-25 04:58:42 +01:00
|
|
|
{
|
2005-01-01 22:21:11 +01:00
|
|
|
/* If we have export-minimal turned on, do not include
|
2004-11-25 04:58:42 +01:00
|
|
|
any signature that isn't a selfsig. Note that this
|
|
|
|
only applies to uid sigs (0x10, 0x11, 0x12, and
|
|
|
|
0x13). A designated revocation is not stripped. */
|
|
|
|
if((options&EXPORT_MINIMAL)
|
|
|
|
&& IS_UID_SIG(node->pkt->pkt.signature)
|
2004-11-26 17:48:05 +01:00
|
|
|
&& (node->pkt->pkt.signature->keyid[0]!=keyid[0]
|
|
|
|
|| node->pkt->pkt.signature->keyid[1]!=keyid[1]))
|
2002-08-20 14:45:57 +02:00
|
|
|
continue;
|
2004-11-25 04:58:42 +01:00
|
|
|
|
2005-05-14 04:38:31 +02:00
|
|
|
/* do not export packets which are marked as not
|
|
|
|
exportable */
|
2004-11-26 16:51:37 +01:00
|
|
|
if(!(options&EXPORT_LOCAL_SIGS)
|
2004-11-25 04:58:42 +01:00
|
|
|
&& !node->pkt->pkt.signature->flags.exportable)
|
|
|
|
continue; /* not exportable */
|
|
|
|
|
|
|
|
/* Do not export packets with a "sensitive" revocation
|
|
|
|
key unless the user wants us to. Note that we do
|
|
|
|
export these when issuing the actual revocation
|
|
|
|
(see revoke.c). */
|
2004-11-26 16:51:37 +01:00
|
|
|
if(!(options&EXPORT_SENSITIVE_REVKEYS)
|
2004-11-25 04:58:42 +01:00
|
|
|
&& node->pkt->pkt.signature->revkey)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0;i<node->pkt->pkt.signature->numrevkeys;i++)
|
|
|
|
if(node->pkt->pkt.signature->revkey[i]->class & 0x40)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(i<node->pkt->pkt.signature->numrevkeys)
|
|
|
|
continue;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
1998-11-03 20:38:58 +01:00
|
|
|
|
2002-07-17 21:48:19 +02:00
|
|
|
/* Don't export attribs? */
|
2004-11-26 16:51:37 +01:00
|
|
|
if( !(options&EXPORT_ATTRIBUTES) &&
|
2002-07-17 21:48:19 +02:00
|
|
|
node->pkt->pkttype == PKT_USER_ID &&
|
|
|
|
node->pkt->pkt.user_id->attrib_data ) {
|
|
|
|
/* Skip until we get to something that is not an attrib
|
|
|
|
or a signature on an attrib */
|
|
|
|
while(kbctx->next && kbctx->next->pkt->pkttype==PKT_SIGNATURE) {
|
|
|
|
kbctx=kbctx->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-03-05 01:01:25 +01:00
|
|
|
if( secret == 2 && node->pkt->pkttype == PKT_SECRET_KEY )
|
|
|
|
{
|
2005-07-19 10:50:28 +02:00
|
|
|
/* We don't want to export the secret parts of the
|
2000-07-14 19:34:53 +02:00
|
|
|
* primary key, this is done by using GNU protection mode 1001
|
|
|
|
*/
|
|
|
|
int save_mode = node->pkt->pkt.secret_key->protect.s2k.mode;
|
|
|
|
node->pkt->pkt.secret_key->protect.s2k.mode = 1001;
|
|
|
|
rc = build_packet( out, node->pkt );
|
|
|
|
node->pkt->pkt.secret_key->protect.s2k.mode = save_mode;
|
2004-03-05 01:01:25 +01:00
|
|
|
}
|
2005-07-19 10:50:28 +02:00
|
|
|
else if (secret == 2 && node->pkt->pkttype == PKT_SECRET_SUBKEY
|
|
|
|
&& (opt.export_options&EXPORT_RESET_SUBKEY_PASSWD))
|
|
|
|
{
|
|
|
|
/* If the subkey is protected reset the passphrase to
|
|
|
|
export an unprotected subkey. This feature is
|
|
|
|
useful in cases of a subkey copied to an unattended
|
|
|
|
machine where a passphrase is not required. */
|
|
|
|
PKT_secret_key *sk_save, *sk;
|
|
|
|
|
|
|
|
sk_save = node->pkt->pkt.secret_key;
|
|
|
|
sk = copy_secret_key (NULL, sk_save);
|
|
|
|
node->pkt->pkt.secret_key = sk;
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
log_info (_("about to export an unprotected subkey\n"));
|
2005-07-19 10:50:28 +02:00
|
|
|
switch (is_secret_key_protected (sk))
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
rc = G10ERR_PUBKEY_ALGO;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (sk->protect.s2k.mode == 1001)
|
|
|
|
; /* No secret parts. */
|
|
|
|
else if( sk->protect.s2k.mode == 1002 )
|
|
|
|
; /* Card key stub. */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rc = check_secret_key( sk, 0 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
node->pkt->pkt.secret_key = sk_save;
|
|
|
|
free_secret_key (sk);
|
2005-07-27 20:10:56 +02:00
|
|
|
log_error (_("failed to unprotect the subkey: %s\n"),
|
2005-07-19 10:50:28 +02:00
|
|
|
g10_errstr (rc));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = build_packet (out, node->pkt);
|
|
|
|
|
|
|
|
node->pkt->pkt.secret_key = sk_save;
|
|
|
|
free_secret_key (sk);
|
|
|
|
}
|
2004-03-05 01:01:25 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Warn the user if the secret key or any of the secret
|
|
|
|
subkeys are protected with SHA1 and we have
|
|
|
|
simple_sk_checksum set. */
|
|
|
|
if(!sha1_warned && opt.simple_sk_checksum &&
|
|
|
|
(node->pkt->pkttype==PKT_SECRET_KEY ||
|
|
|
|
node->pkt->pkttype==PKT_SECRET_SUBKEY) &&
|
|
|
|
node->pkt->pkt.secret_key->protect.sha1chk)
|
|
|
|
{
|
|
|
|
/* I hope this warning doesn't confuse people. */
|
|
|
|
log_info(_("WARNING: secret key %s does not have a "
|
|
|
|
"simple SK checksum\n"),keystr(sk_keyid));
|
|
|
|
|
|
|
|
sha1_warned=1;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
rc = build_packet( out, node->pkt );
|
2004-03-05 01:01:25 +01:00
|
|
|
}
|
2000-07-14 19:34:53 +02:00
|
|
|
|
|
|
|
if( rc ) {
|
1998-02-13 21:58:50 +01:00
|
|
|
log_error("build_packet(%d) failed: %s\n",
|
2002-06-29 15:46:34 +02:00
|
|
|
node->pkt->pkttype, g10_errstr(rc) );
|
|
|
|
rc = G10ERR_WRITE_FILE;
|
1998-02-13 21:58:50 +01:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
}
|
1999-01-19 19:37:41 +01:00
|
|
|
++*any;
|
2003-02-26 18:11:24 +01:00
|
|
|
if(keyblock_out)
|
|
|
|
{
|
|
|
|
*keyblock_out=keyblock;
|
|
|
|
break;
|
|
|
|
}
|
1998-02-13 21:58:50 +01:00
|
|
|
}
|
|
|
|
if( rc == -1 )
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
leave:
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(desc);
|
2002-06-29 15:46:34 +02:00
|
|
|
keydb_release (kdbhd);
|
2003-02-26 18:11:24 +01:00
|
|
|
if(rc || keyblock_out==NULL)
|
|
|
|
release_kbnode( keyblock );
|
1999-01-19 19:37:41 +01:00
|
|
|
if( !*any )
|
1998-11-10 13:59:59 +01:00
|
|
|
log_info(_("WARNING: nothing exported\n"));
|
1998-02-13 21:58:50 +01:00
|
|
|
return rc;
|
1998-01-26 23:09:01 +01:00
|
|
|
}
|