[PATCH] Only removing the encryption envelope during decryption
Florian Weimer
Florian.Weimer@rus.uni-stuttgart.de
25 Apr 2000 18:24:39 +0200
--=-=-=
The patch included below adds new functionally to the "--no-literal"
option (I chose it because the new functionally complements the
existing one): During OpenPGP message processing, when a decryption
packet is encountered, the OpenPGP data contained in it is not
processed by GnuPG, but simply dumped to the output file requested on
the command line. (Following the tradition of the "--no-literal"
option, no further documentation is provided. ;)
Example usage: decrypt with "--no-literal --decrypt", and encrypt the
resulting OpenPGP data with "--no-literal --encrypt" for another
public key. As a result, the message is encrypted to a new recipient,
but a signature which is perhaps present has been presevered (which
was impossible without this patch, I think). I've already written a
tool which automates this process; it will be released shortly. If
you want to test it, drop me a line. But be warned: It requires
POSIX.5 support. ;)
I hope the names and placement of the new functions are acceptable.
--
Florian Weimer Florian.Weimer@RUS.Uni-Stuttgart.DE
University of Stuttgart http://cert.uni-stuttgart.de/
RUS-CERT +49-711-685-5973/fax +49-711-685-5898
http://ca.uni-stuttgart.de:11371/pks/lookup?op=get&search=0xC06EC3B5
--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=gnupg-reencrypt.diff
Index: g10/encr-data.c
===================================================================
RCS file: /home/koch/cvs/gnupg/g10/encr-data.c,v
retrieving revision 1.20
diff -u -r1.20 encr-data.c
--- g10/encr-data.c 1999/05/31 17:49:29 1.20
+++ g10/encr-data.c 2000/04/16 08:35:24
@@ -120,7 +120,7 @@
iobuf_push_filter( ed->buf, mdc_decode_filter, &dfx );
else
iobuf_push_filter( ed->buf, decode_filter, &dfx );
- proc_packets( procctx, ed->buf);
+ proc_descend_into_encryption_packet( procctx, ed->buf);
ed->buf = NULL;
if( ed->mdc_method && dfx.eof_seen == 2 )
rc = G10ERR_INVALID_PACKET;
Index: g10/mainproc.c
===================================================================
RCS file: /home/koch/cvs/gnupg/g10/mainproc.c,v
retrieving revision 1.98.2.8
diff -u -r1.98.2.8 mainproc.c
--- g10/mainproc.c 2000/03/22 12:45:03 1.98.2.8
+++ g10/mainproc.c 2000/04/16 08:35:25
@@ -925,6 +925,17 @@
return rc;
}
+int
+proc_descend_into_encryption_packet( void *anchor, IOBUF a )
+{
+ if( opt.no_literal && !opt.list_packets ) {
+ /* literally output the contents of this packet */
+ return dump_packet_literally (a);
+ }
+
+ return proc_packets( anchor, a);
+}
+
int
do_proc_packets( CTX c, IOBUF a )
Index: g10/packet.h
===================================================================
RCS file: /home/koch/cvs/gnupg/g10/packet.h,v
retrieving revision 1.56.2.3
diff -u -r1.56.2.3 packet.h
--- g10/packet.h 2000/02/17 12:41:57 1.56.2.3
+++ g10/packet.h 2000/04/16 08:35:26
@@ -251,6 +251,7 @@
int proc_signature_packets( void *ctx, IOBUF a,
STRLIST signedfiles, const char *sigfile );
int proc_encryption_packets( void *ctx, IOBUF a );
+int proc_descend_into_encryption_packet( void *ctx, IOBUF a );
int list_packets( IOBUF a );
/*-- parse-packet.c --*/
@@ -340,6 +341,7 @@
int nooutput, int clearsig );
int ask_for_detached_datafile( MD_HANDLE md, MD_HANDLE md2,
const char *inname, int textmode );
+int dump_packet_literally( IOBUF a );
/*-- comment.c --*/
int write_comment( IOBUF out, const char *s );
Index: g10/plaintext.c
===================================================================
RCS file: /home/koch/cvs/gnupg/g10/plaintext.c,v
retrieving revision 1.33.2.2
diff -u -r1.33.2.2 plaintext.c
--- g10/plaintext.c 1999/12/19 14:23:18 1.33.2.2
+++ g10/plaintext.c 2000/04/16 08:35:26
@@ -398,3 +398,81 @@
}
+/****************
+ * Dump a packet to the output file.
+ */
+
+int
+dump_packet_literally( IOBUF a )
+{
+ char *fname = NULL;
+ FILE *fp = NULL;
+ int rc = 0;
+ byte *buffer = NULL;
+
+ if( opt.outfile ) {
+ fname = m_alloc( strlen( opt.outfile ) + 1);
+ strcpy(fname, opt.outfile );
+ }
+ if( !fname ) {
+ rc = G10ERR_CREATE_FILE;
+ goto leave;
+ }
+
+ if( !*fname || (*fname=='-' && !fname[1])) {
+ /* no filename or "-" given; write to stdout */
+ fp = stdout;
+ }
+ else if( !overwrite_filep( fname ) ) {
+ rc = G10ERR_CREATE_FILE;
+ goto leave;
+ }
+
+ if( fp )
+ ;
+ else if( !(fp = fopen(fname,"wb")) ) {
+ log_error("Error creating `%s': %s\n", fname, strerror(errno) );
+ rc = G10ERR_CREATE_FILE;
+ goto leave;
+ }
+
+#define BUFSIZE (32768)
+ buffer = m_alloc( BUFSIZE );
+ for (;;) {
+ int len = iobuf_read( a, buffer, BUFSIZE );
+ if( len == -1 ) {
+ log_error("Problem reading source\n");
+ rc = G10ERR_READ_FILE;
+ m_free( buffer );
+ goto leave;
+ }
+ if( fp ) {
+ if( fwrite( buffer, 1, len, fp ) != len ) {
+ log_error("Error writing to `%s': %s\n",
+ fname, strerror(errno) );
+ rc = G10ERR_WRITE_FILE;
+ m_free( buffer );
+ goto leave;
+ }
+ }
+ if ( len != BUFSIZE )
+ break;
+ }
+ m_free( buffer );
+#undef BUFSIZE
+
+ if( fp && fp != stdout && fclose(fp) ) {
+ log_error("Error closing `%s': %s\n", fname, strerror(errno) );
+ fp = NULL;
+ rc = G10ERR_WRITE_FILE;
+ goto leave;
+ }
+ fp = NULL;
+
+ leave:
+ if( fp && fp != stdout )
+ fclose(fp);
+ m_free(fname);
+ return rc;
+}
+
--=-=-=--