1997-11-24 11:04:11 +00:00
|
|
|
/* encode.c - encode data
|
2003-05-21 08:48:26 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002,
|
|
|
|
* 2003 Free Software Foundation, Inc.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* This file is part of GnuPG.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1997-11-18 14:06:00 +00: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 12:41:40 +00:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1997-11-18 14:06:00 +00: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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 "iobuf.h"
|
|
|
|
#include "keydb.h"
|
2002-06-29 13:46:34 +00:00
|
|
|
#include "memory.h"
|
1997-11-18 14:06:00 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "main.h"
|
1997-11-21 14:53:57 +00:00
|
|
|
#include "filter.h"
|
1998-08-05 16:51:59 +00:00
|
|
|
#include "trustdb.h"
|
1998-07-06 10:23:57 +00:00
|
|
|
#include "i18n.h"
|
2002-06-29 13:46:34 +00:00
|
|
|
#include "status.h"
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2003-10-01 15:15:58 +00:00
|
|
|
static int encode_simple( const char *filename, int mode, int use_seskey );
|
1998-06-29 12:30:57 +00:00
|
|
|
static int write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/****************
|
1998-04-14 17:51:16 +00:00
|
|
|
* Encode FILENAME with only the symmetric cipher. Take input from
|
1997-11-18 14:06:00 +00:00
|
|
|
* stdin if FILENAME is NULL.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
encode_symmetric( const char *filename )
|
|
|
|
{
|
2003-10-01 15:15:58 +00:00
|
|
|
return encode_simple( filename, 1, 0 );
|
1997-11-18 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************
|
1998-04-14 17:51:16 +00:00
|
|
|
* Encode FILENAME as a literal data packet only. Take input from
|
1997-11-18 14:06:00 +00:00
|
|
|
* stdin if FILENAME is NULL.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
encode_store( const char *filename )
|
|
|
|
{
|
2003-10-01 15:15:58 +00:00
|
|
|
return encode_simple( filename, 0, 0 );
|
1997-11-18 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
static void
|
2003-10-26 03:26:14 +00:00
|
|
|
encode_seskey( DEK *dek, DEK **seskey, byte *enckey )
|
2002-06-29 13:46:34 +00:00
|
|
|
{
|
|
|
|
CIPHER_HANDLE hd;
|
|
|
|
byte buf[33];
|
|
|
|
|
2003-10-01 15:15:58 +00:00
|
|
|
assert ( dek->keylen <= 32 );
|
2003-10-26 03:26:14 +00:00
|
|
|
if(!*seskey)
|
|
|
|
{
|
|
|
|
*seskey=m_alloc_clear(sizeof(DEK));
|
|
|
|
(*seskey)->keylen=dek->keylen;
|
|
|
|
(*seskey)->algo=dek->algo;
|
|
|
|
make_session_key(*seskey);
|
|
|
|
/*log_hexdump( "thekey", c->key, c->keylen );*/
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = (*seskey)->algo;
|
|
|
|
memcpy( buf + 1, (*seskey)->key, (*seskey)->keylen );
|
2002-06-29 13:46:34 +00:00
|
|
|
|
|
|
|
hd = cipher_open( dek->algo, CIPHER_MODE_CFB, 1 );
|
|
|
|
cipher_setkey( hd, dek->key, dek->keylen );
|
|
|
|
cipher_setiv( hd, NULL, 0 );
|
2003-10-26 03:26:14 +00:00
|
|
|
cipher_encrypt( hd, buf, buf, (*seskey)->keylen + 1 );
|
2002-06-29 13:46:34 +00:00
|
|
|
cipher_close( hd );
|
|
|
|
|
2003-10-26 03:26:14 +00:00
|
|
|
memcpy( enckey, buf, (*seskey)->keylen + 1 );
|
2002-10-31 15:40:42 +00:00
|
|
|
wipememory( buf, sizeof buf ); /* burn key */
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
1999-05-17 20:03:24 +00:00
|
|
|
|
2002-08-13 19:00:23 +00:00
|
|
|
/* We try very hard to use a MDC */
|
|
|
|
static int
|
|
|
|
use_mdc(PK_LIST pk_list,int algo)
|
|
|
|
{
|
2003-09-09 00:25:53 +00:00
|
|
|
/* RFC-1991 and 2440 don't have MDC */
|
|
|
|
if(RFC1991 || RFC2440)
|
|
|
|
return 0;
|
|
|
|
|
2002-08-13 19:00:23 +00:00
|
|
|
/* --force-mdc overrides --disable-mdc */
|
|
|
|
if(opt.force_mdc)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if(opt.disable_mdc)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Do the keys really support MDC? */
|
|
|
|
|
|
|
|
if(select_mdc_from_pklist(pk_list))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* The keys don't support MDC, so now we do a bit of a hack - if any
|
|
|
|
of the AESes or TWOFISH are in the prefs, we assume that the user
|
|
|
|
can handle a MDC. This is valid for PGP 7, which can handle MDCs
|
|
|
|
though it will not generate them. 2440bis allows this, by the
|
|
|
|
way. */
|
|
|
|
|
|
|
|
if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
|
|
|
|
CIPHER_ALGO_AES,NULL)==CIPHER_ALGO_AES)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
|
|
|
|
CIPHER_ALGO_AES192,NULL)==CIPHER_ALGO_AES192)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
|
|
|
|
CIPHER_ALGO_AES256,NULL)==CIPHER_ALGO_AES256)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if(select_algo_from_prefs(pk_list,PREFTYPE_SYM,
|
|
|
|
CIPHER_ALGO_TWOFISH,NULL)==CIPHER_ALGO_TWOFISH)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Last try. Use MDC for the modern ciphers. */
|
|
|
|
|
|
|
|
if(cipher_get_blocksize(algo)!=8)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0; /* No MDC */
|
|
|
|
}
|
|
|
|
|
2003-10-01 15:15:58 +00:00
|
|
|
/* We don't want to use use_seskey yet because older gnupg versions
|
|
|
|
can't handle it, and there isn't really any point unless we're
|
|
|
|
making a message that can be decrypted by a public key or
|
|
|
|
passphrase. */
|
1997-11-18 14:06:00 +00:00
|
|
|
static int
|
2003-10-01 15:15:58 +00:00
|
|
|
encode_simple( const char *filename, int mode, int use_seskey )
|
1997-11-18 14:06:00 +00:00
|
|
|
{
|
|
|
|
IOBUF inp, out;
|
|
|
|
PACKET pkt;
|
1999-07-26 07:44:46 +00:00
|
|
|
PKT_plaintext *pt = NULL;
|
1998-05-04 18:49:26 +00:00
|
|
|
STRING2KEY *s2k = NULL;
|
2002-06-29 13:46:34 +00:00
|
|
|
byte enckey[33];
|
1997-11-18 14:06:00 +00:00
|
|
|
int rc = 0;
|
2002-06-29 13:46:34 +00:00
|
|
|
int seskeylen = 0;
|
1997-11-18 14:06:00 +00:00
|
|
|
u32 filesize;
|
|
|
|
cipher_filter_context_t cfx;
|
1997-11-19 13:12:23 +00:00
|
|
|
armor_filter_context_t afx;
|
1997-11-23 15:38:27 +00:00
|
|
|
compress_filter_context_t zfx;
|
1999-03-17 12:13:04 +00:00
|
|
|
text_filter_context_t tfx;
|
2003-04-15 15:46:13 +00:00
|
|
|
progress_filter_context_t pfx;
|
2003-11-15 15:38:43 +00:00
|
|
|
int do_compress = !RFC1991 && default_compress_algo();
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
memset( &cfx, 0, sizeof cfx);
|
1997-11-19 13:12:23 +00:00
|
|
|
memset( &afx, 0, sizeof afx);
|
1997-11-23 15:38:27 +00:00
|
|
|
memset( &zfx, 0, sizeof zfx);
|
1999-03-17 12:13:04 +00:00
|
|
|
memset( &tfx, 0, sizeof tfx);
|
1998-08-11 17:29:34 +00:00
|
|
|
init_packet(&pkt);
|
2002-06-29 13:46:34 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/* prepare iobufs */
|
|
|
|
if( !(inp = iobuf_open(filename)) ) {
|
1998-07-06 10:23:57 +00:00
|
|
|
log_error(_("%s: can't open: %s\n"), filename? filename: "[stdin]",
|
1997-11-18 14:06:00 +00:00
|
|
|
strerror(errno) );
|
2002-06-29 13:46:34 +00:00
|
|
|
return G10ERR_OPEN_FILE;
|
1997-11-18 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-15 15:46:13 +00:00
|
|
|
handle_progress (&pfx, inp, filename);
|
|
|
|
|
1999-03-17 12:13:04 +00:00
|
|
|
if( opt.textmode )
|
|
|
|
iobuf_push_filter( inp, text_filter, &tfx );
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
/* Due the the fact that we use don't use an IV to encrypt the
|
|
|
|
session key we can't use the new mode with RFC1991 because
|
|
|
|
it has no S2K salt. RFC1991 always uses simple S2K. */
|
2003-10-01 15:15:58 +00:00
|
|
|
if ( RFC1991 && use_seskey )
|
|
|
|
use_seskey = 0;
|
2002-06-29 13:46:34 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
cfx.dek = NULL;
|
|
|
|
if( mode ) {
|
2002-06-29 13:46:34 +00:00
|
|
|
s2k = m_alloc_clear( sizeof *s2k );
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
s2k->mode = RFC1991? 0:opt.s2k_mode;
|
2002-11-24 00:50:14 +00:00
|
|
|
s2k->hash_algo = opt.s2k_digest_algo;
|
1999-07-01 10:53:35 +00:00
|
|
|
cfx.dek = passphrase_to_dek( NULL, 0,
|
2003-04-10 09:56:47 +00:00
|
|
|
default_cipher_algo(), s2k, 2,
|
|
|
|
NULL, NULL);
|
1998-05-04 18:49:26 +00:00
|
|
|
if( !cfx.dek || !cfx.dek->keylen ) {
|
2002-06-29 13:46:34 +00:00
|
|
|
rc = G10ERR_PASSPHRASE;
|
|
|
|
m_free(cfx.dek);
|
|
|
|
m_free(s2k);
|
1997-11-18 14:06:00 +00:00
|
|
|
iobuf_close(inp);
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error(_("error creating passphrase: %s\n"), g10_errstr(rc) );
|
1997-11-18 14:06:00 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2003-10-01 15:15:58 +00:00
|
|
|
if (use_seskey && s2k->mode != 1 && s2k->mode != 3) {
|
|
|
|
use_seskey = 0;
|
2002-09-10 08:40:12 +00:00
|
|
|
log_info (_("can't use a symmetric ESK packet "
|
|
|
|
"due to the S2K mode\n"));
|
|
|
|
}
|
|
|
|
|
2003-10-26 03:26:14 +00:00
|
|
|
if ( use_seskey )
|
|
|
|
{
|
|
|
|
DEK *dek = NULL;
|
|
|
|
seskeylen = cipher_get_keylen( default_cipher_algo() ) / 8;
|
|
|
|
encode_seskey( cfx.dek, &dek, enckey );
|
2002-06-29 13:46:34 +00:00
|
|
|
m_free( cfx.dek ); cfx.dek = dek;
|
2003-10-26 03:26:14 +00:00
|
|
|
}
|
2002-08-13 19:00:23 +00:00
|
|
|
|
|
|
|
cfx.dek->use_mdc=use_mdc(NULL,cfx.dek->algo);
|
1997-11-18 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
2003-11-15 22:31:58 +00:00
|
|
|
if (do_compress && cfx.dek && cfx.dek->use_mdc
|
|
|
|
&& is_file_compressed(filename, &rc))
|
2002-08-13 19:00:23 +00:00
|
|
|
{
|
|
|
|
if (opt.verbose)
|
|
|
|
log_info(_("`%s' already compressed\n"), filename);
|
|
|
|
do_compress = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( rc || (rc = open_outfile( filename, opt.armor? 1:0, &out )) ) {
|
2000-07-14 17:34:53 +00:00
|
|
|
iobuf_cancel(inp);
|
2002-06-29 13:46:34 +00:00
|
|
|
m_free(cfx.dek);
|
|
|
|
m_free(s2k);
|
1998-08-11 17:29:34 +00:00
|
|
|
return rc;
|
1997-11-18 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( opt.armor )
|
1997-11-19 13:12:23 +00:00
|
|
|
iobuf_push_filter( out, armor_filter, &afx );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef ENABLE_COMMENT_PACKETS
|
1998-08-11 17:29:34 +00:00
|
|
|
else {
|
1998-05-26 13:38:00 +00:00
|
|
|
write_comment( out, "#created by GNUPG v" VERSION " ("
|
1998-02-16 20:05:02 +00:00
|
|
|
PRINTABLE_OS_NAME ")");
|
1998-08-11 17:29:34 +00:00
|
|
|
if( opt.comment_string )
|
|
|
|
write_comment( out, opt.comment_string );
|
|
|
|
}
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
if( s2k && !RFC1991 ) {
|
2002-06-29 13:46:34 +00:00
|
|
|
PKT_symkey_enc *enc = m_alloc_clear( sizeof *enc + seskeylen + 1 );
|
1998-05-04 18:49:26 +00:00
|
|
|
enc->version = 4;
|
|
|
|
enc->cipher_algo = cfx.dek->algo;
|
|
|
|
enc->s2k = *s2k;
|
2003-10-01 15:15:58 +00:00
|
|
|
if ( use_seskey && seskeylen ) {
|
2002-06-29 13:46:34 +00:00
|
|
|
enc->seskeylen = seskeylen + 1; /* algo id */
|
|
|
|
memcpy( enc->seskey, enckey, seskeylen + 1 );
|
|
|
|
}
|
1998-05-04 18:49:26 +00:00
|
|
|
pkt.pkttype = PKT_SYMKEY_ENC;
|
|
|
|
pkt.pkt.symkey_enc = enc;
|
|
|
|
if( (rc = build_packet( out, &pkt )) )
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error("build symkey packet failed: %s\n", g10_errstr(rc) );
|
|
|
|
m_free(enc);
|
1998-05-04 18:49:26 +00:00
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1999-07-26 07:44:46 +00:00
|
|
|
if (!opt.no_literal) {
|
|
|
|
/* setup the inner packet */
|
|
|
|
if( filename || opt.set_filename ) {
|
|
|
|
char *s = make_basename( opt.set_filename ? opt.set_filename
|
2002-10-29 14:37:12 +00:00
|
|
|
: filename,
|
|
|
|
iobuf_get_real_fname( inp ) );
|
2002-06-29 13:46:34 +00:00
|
|
|
pt = m_alloc( sizeof *pt + strlen(s) - 1 );
|
1999-07-26 07:44:46 +00:00
|
|
|
pt->namelen = strlen(s);
|
|
|
|
memcpy(pt->name, s, pt->namelen );
|
2002-06-29 13:46:34 +00:00
|
|
|
m_free(s);
|
1999-07-26 07:44:46 +00:00
|
|
|
}
|
|
|
|
else { /* no filename */
|
2002-06-29 13:46:34 +00:00
|
|
|
pt = m_alloc( sizeof *pt - 1 );
|
1999-07-26 07:44:46 +00:00
|
|
|
pt->namelen = 0;
|
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
}
|
1999-07-26 07:44:46 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
/* Note that PGP 5 has problems decrypting symmetrically encrypted
|
|
|
|
data if the file length is in the inner packet. It works when
|
|
|
|
only partial length headers are use. In the past, we always
|
|
|
|
used partial body length here, but since PGP 2, PGP 6, and PGP
|
|
|
|
7 need the file length, and nobody should be using PGP 5
|
|
|
|
nowadays anyway, this is now set to the file length. Note also
|
|
|
|
that this only applies to the RFC-1991 style symmetric
|
|
|
|
messages, and not the RFC-2440 style. PGP 6 and 7 work with
|
|
|
|
either partial length or fixed length with the new style
|
|
|
|
messages. */
|
|
|
|
|
2003-05-21 08:48:26 +00:00
|
|
|
if (filename && *filename && !(*filename == '-' && !filename[1])
|
|
|
|
&& !opt.textmode ) {
|
2002-11-13 17:43:27 +00:00
|
|
|
off_t tmpsize;
|
|
|
|
|
|
|
|
if ( !(tmpsize = iobuf_get_filelength(inp)) )
|
|
|
|
log_info(_("%s: WARNING: empty file\n"), filename );
|
|
|
|
/* We can't encode the length of very large files because
|
|
|
|
OpenPGP uses only 32 bit for file sizes. So if the the
|
|
|
|
size of a file is larger than 2^32 minus some bytes for
|
|
|
|
packet headers, we switch to partial length encoding. */
|
|
|
|
if ( tmpsize < (IOBUF_FILELENGTH_LIMIT - 65536) )
|
|
|
|
filesize = tmpsize;
|
|
|
|
else
|
|
|
|
filesize = 0;
|
1998-08-11 17:29:34 +00:00
|
|
|
}
|
|
|
|
else
|
1999-07-26 07:44:46 +00:00
|
|
|
filesize = opt.set_filesize ? opt.set_filesize : 0; /* stdin */
|
|
|
|
|
|
|
|
if (!opt.no_literal) {
|
|
|
|
pt->timestamp = make_timestamp();
|
|
|
|
pt->mode = opt.textmode? 't' : 'b';
|
|
|
|
pt->len = filesize;
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
pt->new_ctb = !pt->len && !RFC1991;
|
1999-07-26 07:44:46 +00:00
|
|
|
pt->buf = inp;
|
|
|
|
pkt.pkttype = PKT_PLAINTEXT;
|
|
|
|
pkt.pkt.plaintext = pt;
|
|
|
|
cfx.datalen = filesize && !do_compress ? calc_packet_length( &pkt ) : 0;
|
|
|
|
}
|
|
|
|
else
|
2002-06-29 13:46:34 +00:00
|
|
|
{
|
|
|
|
cfx.datalen = filesize && !do_compress ? filesize : 0;
|
|
|
|
pkt.pkttype = 0;
|
|
|
|
pkt.pkt.generic = NULL;
|
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/* register the cipher filter */
|
|
|
|
if( mode )
|
|
|
|
iobuf_push_filter( out, cipher_filter, &cfx );
|
1998-05-26 13:38:00 +00:00
|
|
|
/* register the compress filter */
|
1998-09-28 19:25:31 +00:00
|
|
|
if( do_compress )
|
2002-08-13 19:00:23 +00:00
|
|
|
{
|
2002-08-30 16:34:13 +00:00
|
|
|
if (cfx.dek && cfx.dek->use_mdc)
|
|
|
|
zfx.new_ctb = 1;
|
2003-11-15 15:38:43 +00:00
|
|
|
push_compress_filter(out,&zfx,default_compress_algo());
|
2002-08-13 19:00:23 +00:00
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/* do the work */
|
1999-07-26 07:44:46 +00:00
|
|
|
if (!opt.no_literal) {
|
|
|
|
if( (rc = build_packet( out, &pkt )) )
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error("build_packet failed: %s\n", g10_errstr(rc) );
|
1999-07-26 07:44:46 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* user requested not to create a literal packet,
|
|
|
|
* so we copy the plain data */
|
|
|
|
byte copy_buffer[4096];
|
|
|
|
int bytes_copied;
|
|
|
|
while ((bytes_copied = iobuf_read(inp, copy_buffer, 4096)) != -1)
|
|
|
|
if (iobuf_write(out, copy_buffer, bytes_copied) == -1) {
|
2002-06-29 13:46:34 +00:00
|
|
|
rc = G10ERR_WRITE_FILE;
|
|
|
|
log_error("copying input to output failed: %s\n", g10_errstr(rc) );
|
1999-07-26 07:44:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-10-31 15:40:42 +00:00
|
|
|
wipememory(copy_buffer, 4096); /* burn buffer */
|
1999-07-26 07:44:46 +00:00
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/* finish the stuff */
|
|
|
|
iobuf_close(inp);
|
1999-07-26 07:44:46 +00:00
|
|
|
if (rc)
|
|
|
|
iobuf_cancel(out);
|
2002-06-29 13:46:34 +00:00
|
|
|
else {
|
1999-07-26 07:44:46 +00:00
|
|
|
iobuf_close(out); /* fixme: check returncode */
|
2002-06-29 13:46:34 +00:00
|
|
|
if (mode)
|
|
|
|
write_status( STATUS_END_ENCRYPTION );
|
|
|
|
}
|
1999-07-26 07:44:46 +00:00
|
|
|
if (pt)
|
|
|
|
pt->buf = NULL;
|
1997-11-18 14:06:00 +00:00
|
|
|
free_packet(&pkt);
|
2002-06-29 13:46:34 +00:00
|
|
|
m_free(cfx.dek);
|
|
|
|
m_free(s2k);
|
1997-11-18 14:06:00 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2003-11-13 02:54:12 +00:00
|
|
|
int
|
|
|
|
setup_symkey(STRING2KEY **symkey_s2k,DEK **symkey_dek)
|
|
|
|
{
|
|
|
|
*symkey_s2k=m_alloc_clear(sizeof(STRING2KEY));
|
|
|
|
(*symkey_s2k)->mode = opt.s2k_mode;
|
|
|
|
(*symkey_s2k)->hash_algo = opt.s2k_digest_algo;
|
|
|
|
|
|
|
|
*symkey_dek=passphrase_to_dek(NULL,0,opt.s2k_cipher_algo,
|
|
|
|
*symkey_s2k,2,NULL,NULL);
|
|
|
|
if(!*symkey_dek || !(*symkey_dek)->keylen)
|
|
|
|
{
|
|
|
|
m_free(*symkey_dek);
|
|
|
|
m_free(*symkey_s2k);
|
|
|
|
return G10ERR_PASSPHRASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
write_symkey_enc(STRING2KEY *symkey_s2k,DEK *symkey_dek,DEK *dek,IOBUF out)
|
|
|
|
{
|
|
|
|
int rc,seskeylen=cipher_get_keylen(dek->algo)/8;
|
|
|
|
|
|
|
|
PKT_symkey_enc *enc;
|
|
|
|
byte enckey[33];
|
|
|
|
PACKET pkt;
|
|
|
|
|
|
|
|
enc=m_alloc_clear(sizeof(PKT_symkey_enc)+seskeylen+1);
|
|
|
|
encode_seskey(symkey_dek,&dek,enckey);
|
|
|
|
|
|
|
|
enc->version = 4;
|
|
|
|
enc->cipher_algo = opt.s2k_cipher_algo;
|
|
|
|
enc->s2k = *symkey_s2k;
|
|
|
|
enc->seskeylen = seskeylen + 1; /* algo id */
|
|
|
|
memcpy( enc->seskey, enckey, seskeylen + 1 );
|
|
|
|
|
|
|
|
pkt.pkttype = PKT_SYMKEY_ENC;
|
|
|
|
pkt.pkt.symkey_enc = enc;
|
|
|
|
|
|
|
|
if((rc=build_packet(out,&pkt)))
|
|
|
|
log_error("build symkey_enc packet failed: %s\n",g10_errstr(rc));
|
|
|
|
|
|
|
|
m_free(enc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/****************
|
|
|
|
* Encrypt the file with the given userids (or ask if none
|
|
|
|
* is supplied).
|
|
|
|
*/
|
|
|
|
int
|
2003-10-26 03:26:14 +00:00
|
|
|
encode_crypt( const char *filename, STRLIST remusr, int use_symkey )
|
1997-11-18 14:06:00 +00:00
|
|
|
{
|
1997-12-31 12:32:54 +00:00
|
|
|
IOBUF inp = NULL, out = NULL;
|
1997-11-18 14:06:00 +00:00
|
|
|
PACKET pkt;
|
1998-01-13 19:04:23 +00:00
|
|
|
PKT_plaintext *pt = NULL;
|
2003-10-26 03:26:14 +00:00
|
|
|
DEK *symkey_dek = NULL;
|
|
|
|
STRING2KEY *symkey_s2k = NULL;
|
2002-06-29 13:46:34 +00:00
|
|
|
int rc = 0, rc2 = 0;
|
1997-11-18 14:06:00 +00:00
|
|
|
u32 filesize;
|
2002-06-29 13:46:34 +00:00
|
|
|
cipher_filter_context_t cfx;
|
1997-11-19 13:12:23 +00:00
|
|
|
armor_filter_context_t afx;
|
1997-11-23 15:38:27 +00:00
|
|
|
compress_filter_context_t zfx;
|
1999-03-17 12:13:04 +00:00
|
|
|
text_filter_context_t tfx;
|
2003-04-15 15:46:13 +00:00
|
|
|
progress_filter_context_t pfx;
|
2002-06-29 13:46:34 +00:00
|
|
|
PK_LIST pk_list,work_list;
|
2003-11-15 22:31:58 +00:00
|
|
|
int do_compress = opt.compress_algo && !RFC1991;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
memset( &cfx, 0, sizeof cfx);
|
1997-11-19 13:12:23 +00:00
|
|
|
memset( &afx, 0, sizeof afx);
|
1997-11-23 15:38:27 +00:00
|
|
|
memset( &zfx, 0, sizeof zfx);
|
1999-03-17 12:13:04 +00:00
|
|
|
memset( &tfx, 0, sizeof tfx);
|
1998-08-11 17:29:34 +00:00
|
|
|
init_packet(&pkt);
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2003-11-13 02:54:12 +00:00
|
|
|
if(use_symkey
|
|
|
|
&& (rc=setup_symkey(&symkey_s2k,&symkey_dek)))
|
|
|
|
return rc;
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
if( (rc=build_pk_list( remusr, &pk_list, PUBKEY_USAGE_ENC)) )
|
1997-12-31 12:32:54 +00:00
|
|
|
return rc;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
if(PGP2) {
|
2002-06-29 13:46:34 +00:00
|
|
|
for(work_list=pk_list; work_list; work_list=work_list->next)
|
|
|
|
if(!(is_RSA(work_list->pk->pubkey_algo) &&
|
|
|
|
nbits_from_pk(work_list->pk)<=2048))
|
|
|
|
{
|
|
|
|
log_info(_("you can only encrypt to RSA keys of 2048 bits or "
|
|
|
|
"less in --pgp2 mode\n"));
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
compliance_failure();
|
2002-06-29 13:46:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/* prepare iobufs */
|
|
|
|
if( !(inp = iobuf_open(filename)) ) {
|
1998-07-06 10:23:57 +00:00
|
|
|
log_error(_("can't open %s: %s\n"), filename? filename: "[stdin]",
|
1997-11-18 14:06:00 +00:00
|
|
|
strerror(errno) );
|
2002-06-29 13:46:34 +00:00
|
|
|
rc = G10ERR_OPEN_FILE;
|
1997-12-31 12:32:54 +00:00
|
|
|
goto leave;
|
1997-11-18 14:06:00 +00:00
|
|
|
}
|
|
|
|
else if( opt.verbose )
|
1998-12-29 13:47:31 +00:00
|
|
|
log_info(_("reading from `%s'\n"), filename? filename: "[stdin]");
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2003-04-15 15:46:13 +00:00
|
|
|
handle_progress (&pfx, inp, filename);
|
|
|
|
|
1999-03-17 12:13:04 +00:00
|
|
|
if( opt.textmode )
|
|
|
|
iobuf_push_filter( inp, text_filter, &tfx );
|
|
|
|
|
1998-08-11 17:29:34 +00:00
|
|
|
if( (rc = open_outfile( filename, opt.armor? 1:0, &out )) )
|
1997-12-31 12:32:54 +00:00
|
|
|
goto leave;
|
1998-08-11 17:29:34 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
if( opt.armor )
|
1997-11-19 13:12:23 +00:00
|
|
|
iobuf_push_filter( out, armor_filter, &afx );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef ENABLE_COMMENT_PACKETS
|
2002-06-29 13:46:34 +00:00
|
|
|
else {
|
|
|
|
write_comment( out, "#created by GNUPG v" VERSION " ("
|
|
|
|
PRINTABLE_OS_NAME ")");
|
|
|
|
if( opt.comment_string )
|
|
|
|
write_comment( out, opt.comment_string );
|
|
|
|
}
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
2002-06-29 13:46:34 +00:00
|
|
|
/* create a session key */
|
|
|
|
cfx.dek = m_alloc_secure_clear (sizeof *cfx.dek);
|
|
|
|
if( !opt.def_cipher_algo ) { /* try to get it from the prefs */
|
|
|
|
cfx.dek->algo = select_algo_from_prefs(pk_list,PREFTYPE_SYM,-1,NULL);
|
|
|
|
/* The only way select_algo_from_prefs can fail here is when
|
|
|
|
mixing v3 and v4 keys, as v4 keys have an implicit
|
|
|
|
preference entry for 3DES, and the pk_list cannot be empty.
|
|
|
|
In this case, use 3DES anyway as it's the safest choice -
|
|
|
|
perhaps the v3 key is being used in an OpenPGP
|
|
|
|
implementation and we know that the implementation behind
|
|
|
|
any v4 key can handle 3DES. */
|
|
|
|
if( cfx.dek->algo == -1 ) {
|
|
|
|
cfx.dek->algo = CIPHER_ALGO_3DES;
|
|
|
|
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
if( PGP2 ) {
|
2002-06-29 13:46:34 +00:00
|
|
|
log_info(_("unable to use the IDEA cipher for all of the keys "
|
|
|
|
"you are encrypting to.\n"));
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
compliance_failure();
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(!opt.expert &&
|
|
|
|
select_algo_from_prefs(pk_list,PREFTYPE_SYM,
|
|
|
|
opt.def_cipher_algo,NULL)!=opt.def_cipher_algo)
|
|
|
|
log_info(_("forcing symmetric cipher %s (%d) "
|
|
|
|
"violates recipient preferences\n"),
|
|
|
|
cipher_algo_to_string(opt.def_cipher_algo),
|
|
|
|
opt.def_cipher_algo);
|
|
|
|
|
|
|
|
cfx.dek->algo = opt.def_cipher_algo;
|
|
|
|
}
|
2002-08-13 19:00:23 +00:00
|
|
|
|
|
|
|
cfx.dek->use_mdc=use_mdc(pk_list,cfx.dek->algo);
|
|
|
|
|
|
|
|
/* Only do the is-file-already-compressed check if we are using a
|
|
|
|
MDC. This forces compressed files to be re-compressed if we do
|
|
|
|
not have a MDC to give some protection against chosen
|
|
|
|
ciphertext attacks. */
|
|
|
|
|
2003-11-15 22:31:58 +00:00
|
|
|
if (do_compress && cfx.dek->use_mdc && is_file_compressed(filename, &rc2) )
|
2002-08-13 19:00:23 +00:00
|
|
|
{
|
|
|
|
if (opt.verbose)
|
|
|
|
log_info(_("`%s' already compressed\n"), filename);
|
|
|
|
do_compress = 0;
|
|
|
|
}
|
|
|
|
if (rc2)
|
|
|
|
{
|
|
|
|
rc = rc2;
|
|
|
|
goto leave;
|
|
|
|
}
|
1999-07-26 07:44:46 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
make_session_key( cfx.dek );
|
|
|
|
if( DBG_CIPHER )
|
|
|
|
log_hexdump("DEK is: ", cfx.dek->key, cfx.dek->keylen );
|
|
|
|
|
|
|
|
rc = write_pubkey_enc_from_list( pk_list, cfx.dek, out );
|
|
|
|
if( rc )
|
|
|
|
goto leave;
|
|
|
|
|
2003-10-26 03:26:14 +00:00
|
|
|
/* We put the passphrase (if any) after any public keys as this
|
|
|
|
seems to be the most useful on the recipient side - there is no
|
|
|
|
point in prompting a user for a passphrase if they have the
|
|
|
|
secret key needed to decrypt. */
|
2003-11-13 02:54:12 +00:00
|
|
|
if(use_symkey && (rc=write_symkey_enc(symkey_s2k,symkey_dek,cfx.dek,out)))
|
|
|
|
goto leave;
|
2003-10-26 03:26:14 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
if (!opt.no_literal) {
|
|
|
|
/* setup the inner packet */
|
|
|
|
if( filename || opt.set_filename ) {
|
2002-10-29 14:37:12 +00:00
|
|
|
char *s = make_basename( opt.set_filename ? opt.set_filename
|
|
|
|
: filename,
|
|
|
|
iobuf_get_real_fname( inp ) );
|
2002-06-29 13:46:34 +00:00
|
|
|
pt = m_alloc( sizeof *pt + strlen(s) - 1 );
|
|
|
|
pt->namelen = strlen(s);
|
|
|
|
memcpy(pt->name, s, pt->namelen );
|
|
|
|
m_free(s);
|
|
|
|
}
|
|
|
|
else { /* no filename */
|
|
|
|
pt = m_alloc( sizeof *pt - 1 );
|
|
|
|
pt->namelen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-21 08:48:26 +00:00
|
|
|
if (filename && *filename && !(*filename == '-' && !filename[1])
|
|
|
|
&& !opt.textmode ) {
|
2002-11-13 17:43:27 +00:00
|
|
|
off_t tmpsize;
|
|
|
|
|
|
|
|
if ( !(tmpsize = iobuf_get_filelength(inp)) )
|
|
|
|
log_info(_("%s: WARNING: empty file\n"), filename );
|
|
|
|
/* We can't encode the length of very large files because
|
|
|
|
OpenPGP uses only 32 bit for file sizes. So if the the
|
|
|
|
size of a file is larger than 2^32 minus some bytes for
|
|
|
|
packet headers, we switch to partial length encoding. */
|
|
|
|
if ( tmpsize < (IOBUF_FILELENGTH_LIMIT - 65536) )
|
|
|
|
filesize = tmpsize;
|
|
|
|
else
|
|
|
|
filesize = 0;
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
filesize = opt.set_filesize ? opt.set_filesize : 0; /* stdin */
|
|
|
|
|
|
|
|
if (!opt.no_literal) {
|
|
|
|
pt->timestamp = make_timestamp();
|
|
|
|
pt->mode = opt.textmode ? 't' : 'b';
|
|
|
|
pt->len = filesize;
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
pt->new_ctb = !pt->len && !RFC1991;
|
2002-06-29 13:46:34 +00:00
|
|
|
pt->buf = inp;
|
|
|
|
pkt.pkttype = PKT_PLAINTEXT;
|
|
|
|
pkt.pkt.plaintext = pt;
|
|
|
|
cfx.datalen = filesize && !do_compress? calc_packet_length( &pkt ) : 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cfx.datalen = filesize && !do_compress ? filesize : 0;
|
|
|
|
|
|
|
|
/* register the cipher filter */
|
|
|
|
iobuf_push_filter( out, cipher_filter, &cfx );
|
|
|
|
|
|
|
|
/* register the compress filter */
|
1998-09-28 19:25:31 +00:00
|
|
|
if( do_compress ) {
|
2003-11-15 22:31:58 +00:00
|
|
|
int compr_algo = opt.compress_algo;
|
2002-06-29 13:46:34 +00:00
|
|
|
|
|
|
|
if(compr_algo==-1)
|
|
|
|
{
|
|
|
|
if((compr_algo=
|
|
|
|
select_algo_from_prefs(pk_list,PREFTYPE_ZIP,-1,NULL))==-1)
|
|
|
|
compr_algo=DEFAULT_COMPRESS_ALGO;
|
2002-11-25 04:24:41 +00:00
|
|
|
/* Theoretically impossible to get here since uncompressed
|
|
|
|
is implicit. */
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
|
|
|
else if(!opt.expert &&
|
|
|
|
select_algo_from_prefs(pk_list,PREFTYPE_ZIP,
|
|
|
|
compr_algo,NULL)!=compr_algo)
|
|
|
|
log_info(_("forcing compression algorithm %s (%d) "
|
|
|
|
"violates recipient preferences\n"),
|
|
|
|
compress_algo_to_string(compr_algo),compr_algo);
|
|
|
|
|
|
|
|
/* algo 0 means no compression */
|
|
|
|
if( compr_algo )
|
|
|
|
{
|
2002-08-30 16:34:13 +00:00
|
|
|
if (cfx.dek && cfx.dek->use_mdc)
|
|
|
|
zfx.new_ctb = 1;
|
* 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 05:39:02 +00:00
|
|
|
push_compress_filter(out,&zfx,compr_algo);
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
1998-08-05 16:51:59 +00:00
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/* do the work */
|
1999-07-26 07:44:46 +00:00
|
|
|
if (!opt.no_literal) {
|
|
|
|
if( (rc = build_packet( out, &pkt )) )
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error("build_packet failed: %s\n", g10_errstr(rc) );
|
1999-07-26 07:44:46 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-08-30 16:34:13 +00:00
|
|
|
/* user requested not to create a literal packet, so we copy
|
|
|
|
the plain data */
|
1999-07-26 07:44:46 +00:00
|
|
|
byte copy_buffer[4096];
|
|
|
|
int bytes_copied;
|
|
|
|
while ((bytes_copied = iobuf_read(inp, copy_buffer, 4096)) != -1)
|
|
|
|
if (iobuf_write(out, copy_buffer, bytes_copied) == -1) {
|
2002-06-29 13:46:34 +00:00
|
|
|
rc = G10ERR_WRITE_FILE;
|
2002-08-30 16:34:13 +00:00
|
|
|
log_error("copying input to output failed: %s\n",
|
|
|
|
g10_errstr(rc) );
|
1999-07-26 07:44:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-10-31 15:40:42 +00:00
|
|
|
wipememory(copy_buffer, 4096); /* burn buffer */
|
1999-07-26 07:44:46 +00:00
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/* finish the stuff */
|
1997-12-31 12:32:54 +00:00
|
|
|
leave:
|
1997-11-18 14:06:00 +00:00
|
|
|
iobuf_close(inp);
|
1997-12-31 12:32:54 +00:00
|
|
|
if( rc )
|
|
|
|
iobuf_cancel(out);
|
2002-06-29 13:46:34 +00:00
|
|
|
else {
|
1997-12-31 12:32:54 +00:00
|
|
|
iobuf_close(out); /* fixme: check returncode */
|
2002-06-29 13:46:34 +00:00
|
|
|
write_status( STATUS_END_ENCRYPTION );
|
|
|
|
}
|
1998-01-13 19:04:23 +00:00
|
|
|
if( pt )
|
|
|
|
pt->buf = NULL;
|
1997-11-18 14:06:00 +00:00
|
|
|
free_packet(&pkt);
|
2002-06-29 13:46:34 +00:00
|
|
|
m_free(cfx.dek);
|
2003-10-26 03:26:14 +00:00
|
|
|
m_free(symkey_dek);
|
|
|
|
m_free(symkey_s2k);
|
1998-06-29 12:30:57 +00:00
|
|
|
release_pk_list( pk_list );
|
1997-11-18 14:06:00 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-26 15:53:01 +00:00
|
|
|
|
|
|
|
|
1997-12-31 12:32:54 +00:00
|
|
|
/****************
|
2002-06-29 13:46:34 +00:00
|
|
|
* Filter to do a complete public key encryption.
|
1997-12-31 12:32:54 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
encrypt_filter( void *opaque, int control,
|
|
|
|
IOBUF a, byte *buf, size_t *ret_len)
|
|
|
|
{
|
|
|
|
size_t size = *ret_len;
|
|
|
|
encrypt_filter_context_t *efx = opaque;
|
|
|
|
int rc=0;
|
|
|
|
|
|
|
|
if( control == IOBUFCTRL_UNDERFLOW ) { /* decrypt */
|
1998-01-16 21:15:24 +00:00
|
|
|
BUG(); /* not used */
|
1997-12-31 12:32:54 +00:00
|
|
|
}
|
|
|
|
else if( control == IOBUFCTRL_FLUSH ) { /* encrypt */
|
1998-01-02 20:40:10 +00:00
|
|
|
if( !efx->header_okay ) {
|
2002-06-29 13:46:34 +00:00
|
|
|
efx->cfx.dek = m_alloc_secure_clear( sizeof *efx->cfx.dek );
|
1998-08-05 16:51:59 +00:00
|
|
|
|
|
|
|
if( !opt.def_cipher_algo ) { /* try to get it from the prefs */
|
|
|
|
efx->cfx.dek->algo =
|
2002-06-29 13:46:34 +00:00
|
|
|
select_algo_from_prefs(efx->pk_list,PREFTYPE_SYM,-1,NULL);
|
|
|
|
if( efx->cfx.dek->algo == -1 ) {
|
|
|
|
/* because 3DES is implicitly in the prefs, this can only
|
|
|
|
* happen if we do not have any public keys in the list */
|
1998-08-05 16:51:59 +00:00
|
|
|
efx->cfx.dek->algo = DEFAULT_CIPHER_ALGO;
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(!opt.expert &&
|
|
|
|
select_algo_from_prefs(efx->pk_list,PREFTYPE_SYM,
|
|
|
|
opt.def_cipher_algo,
|
|
|
|
NULL)!=opt.def_cipher_algo)
|
|
|
|
log_info(_("forcing symmetric cipher %s (%d) "
|
|
|
|
"violates recipient preferences\n"),
|
|
|
|
cipher_algo_to_string(opt.def_cipher_algo),
|
|
|
|
opt.def_cipher_algo);
|
|
|
|
|
|
|
|
efx->cfx.dek->algo = opt.def_cipher_algo;
|
1998-08-05 16:51:59 +00:00
|
|
|
}
|
2002-06-29 13:46:34 +00:00
|
|
|
|
2002-08-13 19:00:23 +00:00
|
|
|
efx->cfx.dek->use_mdc = use_mdc(efx->pk_list,efx->cfx.dek->algo);
|
2002-06-29 13:46:34 +00:00
|
|
|
|
1998-01-02 20:40:10 +00:00
|
|
|
make_session_key( efx->cfx.dek );
|
|
|
|
if( DBG_CIPHER )
|
|
|
|
log_hexdump("DEK is: ",
|
|
|
|
efx->cfx.dek->key, efx->cfx.dek->keylen );
|
|
|
|
|
1998-06-29 12:30:57 +00:00
|
|
|
rc = write_pubkey_enc_from_list( efx->pk_list, efx->cfx.dek, a );
|
1998-01-02 20:40:10 +00:00
|
|
|
if( rc )
|
|
|
|
return rc;
|
|
|
|
|
2003-11-13 02:54:12 +00:00
|
|
|
if(efx->symkey_s2k && efx->symkey_dek)
|
|
|
|
{
|
|
|
|
rc=write_symkey_enc(efx->symkey_s2k,efx->symkey_dek,
|
|
|
|
efx->cfx.dek,a);
|
|
|
|
if(rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1998-01-02 20:40:10 +00:00
|
|
|
iobuf_push_filter( a, cipher_filter, &efx->cfx );
|
|
|
|
|
|
|
|
efx->header_okay = 1;
|
|
|
|
}
|
|
|
|
rc = iobuf_write( a, buf, size );
|
|
|
|
|
1997-12-31 12:32:54 +00:00
|
|
|
}
|
2003-11-13 02:54:12 +00:00
|
|
|
else if( control == IOBUFCTRL_FREE )
|
|
|
|
{
|
|
|
|
m_free(efx->symkey_dek);
|
|
|
|
m_free(efx->symkey_s2k);
|
|
|
|
}
|
1997-12-31 12:32:54 +00:00
|
|
|
else if( control == IOBUFCTRL_DESC ) {
|
|
|
|
*(char**)buf = "encrypt_filter";
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
1998-01-02 20:40:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/****************
|
1998-06-29 12:30:57 +00:00
|
|
|
* Write pubkey-enc packets from the list of PKs to OUT.
|
1998-01-02 20:40:10 +00:00
|
|
|
*/
|
|
|
|
static int
|
1998-06-29 12:30:57 +00:00
|
|
|
write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out )
|
1998-01-02 20:40:10 +00:00
|
|
|
{
|
|
|
|
PACKET pkt;
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_public_key *pk;
|
1998-01-02 20:40:10 +00:00
|
|
|
PKT_pubkey_enc *enc;
|
|
|
|
int rc;
|
|
|
|
|
1998-06-29 12:30:57 +00:00
|
|
|
for( ; pk_list; pk_list = pk_list->next ) {
|
1998-06-13 06:59:14 +00:00
|
|
|
MPI frame;
|
1998-01-02 20:40:10 +00:00
|
|
|
|
1998-06-29 12:30:57 +00:00
|
|
|
pk = pk_list->pk;
|
1998-12-10 19:20:47 +00:00
|
|
|
|
|
|
|
print_pubkey_algo_note( pk->pubkey_algo );
|
2002-06-29 13:46:34 +00:00
|
|
|
enc = m_alloc_clear( sizeof *enc );
|
1998-06-29 12:30:57 +00:00
|
|
|
enc->pubkey_algo = pk->pubkey_algo;
|
|
|
|
keyid_from_pk( pk, enc->keyid );
|
2002-11-01 16:15:45 +00:00
|
|
|
enc->throw_keyid = (opt.throw_keyid || (pk_list->flags&1));
|
1999-06-15 12:31:07 +00:00
|
|
|
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
if(opt.throw_keyid && (PGP2 || PGP6 || PGP7 || PGP8))
|
2002-08-06 17:38:04 +00:00
|
|
|
{
|
|
|
|
log_info(_("you may not use %s while in %s mode\n"),
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 04:07:45 +00:00
|
|
|
"--throw-keyid",compliance_option_string());
|
|
|
|
compliance_failure();
|
2002-08-06 17:38:04 +00:00
|
|
|
}
|
|
|
|
|
1999-06-15 12:31:07 +00:00
|
|
|
/* Okay, what's going on: We have the session key somewhere in
|
|
|
|
* the structure DEK and want to encode this session key in
|
|
|
|
* an integer value of n bits. pubkey_nbits gives us the
|
|
|
|
* number of bits we have to use. We then encode the session
|
|
|
|
* key in some way and we get it back in the big intger value
|
|
|
|
* FRAME. Then we use FRAME, the public key PK->PKEY and the
|
2000-07-14 17:34:53 +00:00
|
|
|
* algorithm number PK->PUBKEY_ALGO and pass it to pubkey_encrypt
|
1999-06-15 12:31:07 +00:00
|
|
|
* which returns the encrypted value in the array ENC->DATA.
|
|
|
|
* This array has a size which depends on the used algorithm
|
|
|
|
* (e.g. 2 for ElGamal). We don't need frame anymore because we
|
|
|
|
* have everything now in enc->data which is the passed to
|
|
|
|
* build_packet()
|
|
|
|
*/
|
1998-06-29 12:30:57 +00:00
|
|
|
frame = encode_session_key( dek, pubkey_nbits( pk->pubkey_algo,
|
|
|
|
pk->pkey ) );
|
2002-06-29 13:46:34 +00:00
|
|
|
rc = pubkey_encrypt( pk->pubkey_algo, enc->data, frame, pk->pkey );
|
|
|
|
mpi_free( frame );
|
1998-06-13 06:59:14 +00:00
|
|
|
if( rc )
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error("pubkey_encrypt failed: %s\n", g10_errstr(rc) );
|
1998-06-13 06:59:14 +00:00
|
|
|
else {
|
|
|
|
if( opt.verbose ) {
|
2002-08-19 08:28:00 +00:00
|
|
|
char *ustr = get_user_id_string_printable (enc->keyid);
|
|
|
|
log_info(_("%s/%s encrypted for: \"%s\"\n"),
|
2002-06-29 13:46:34 +00:00
|
|
|
pubkey_algo_to_string(enc->pubkey_algo),
|
|
|
|
cipher_algo_to_string(dek->algo), ustr );
|
|
|
|
m_free(ustr);
|
1998-06-13 06:59:14 +00:00
|
|
|
}
|
|
|
|
/* and write it */
|
|
|
|
init_packet(&pkt);
|
|
|
|
pkt.pkttype = PKT_PUBKEY_ENC;
|
|
|
|
pkt.pkt.pubkey_enc = enc;
|
|
|
|
rc = build_packet( out, &pkt );
|
|
|
|
if( rc )
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error("build_packet(pubkey_enc) failed: %s\n", g10_errstr(rc));
|
1998-06-13 06:59:14 +00:00
|
|
|
}
|
1998-01-02 20:40:10 +00:00
|
|
|
free_pubkey_enc(enc);
|
1998-06-13 06:59:14 +00:00
|
|
|
if( rc )
|
1998-01-02 20:40:10 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
void
|
|
|
|
encode_crypt_files(int nfiles, char **files, STRLIST remusr)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (opt.outfile)
|
|
|
|
{
|
|
|
|
log_error(_("--output doesn't work for this command\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nfiles)
|
|
|
|
{
|
|
|
|
char line[2048];
|
|
|
|
unsigned int lno = 0;
|
|
|
|
while ( fgets(line, DIM(line), stdin) )
|
|
|
|
{
|
|
|
|
lno++;
|
|
|
|
if (!*line || line[strlen(line)-1] != '\n')
|
|
|
|
{
|
|
|
|
log_error("input line %u too long or missing LF\n", lno);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
line[strlen(line)-1] = '\0';
|
|
|
|
print_file_status(STATUS_FILE_START, line, 2);
|
2003-10-26 03:26:14 +00:00
|
|
|
if ( (rc = encode_crypt(line, remusr, 0)) )
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error("%s: encryption failed: %s\n",
|
|
|
|
print_fname_stdin(line), g10_errstr(rc) );
|
|
|
|
write_status( STATUS_FILE_DONE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (nfiles--)
|
|
|
|
{
|
|
|
|
print_file_status(STATUS_FILE_START, *files, 2);
|
2003-10-26 03:26:14 +00:00
|
|
|
if ( (rc = encode_crypt(*files, remusr, 0)) )
|
2002-06-29 13:46:34 +00:00
|
|
|
log_error("%s: encryption failed: %s\n",
|
|
|
|
print_fname_stdin(*files), g10_errstr(rc) );
|
|
|
|
write_status( STATUS_FILE_DONE );
|
|
|
|
files++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|