Skip to content

Commit

Permalink
Remove support for comments and embedded filenames, and output all li…
Browse files Browse the repository at this point in the history
…teral data packets without filename and with zero timestamp.
  • Loading branch information
lambdafu committed Oct 12, 2017
1 parent 1755d47 commit d572606
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 119 deletions.
20 changes: 0 additions & 20 deletions gnupg/g10/armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,6 @@ armor_filter( void *opaque, int control,
else if( control == IOBUFCTRL_FLUSH && !afx->cancel ) {
if( !afx->status ) { /* write the header line */
const char *s;
strlist_t comment=opt.comments;

if( afx->what >= DIM(head_strings) )
log_bug("afx->what=%d", afx->what);
Expand All @@ -1127,25 +1126,6 @@ armor_filter( void *opaque, int control,
iobuf_writestr(a, "-----" );
iobuf_writestr(a,(const char*) (afx->eol));

/* write the comment strings */
for(s=comment->d;comment;comment=comment->next,s=comment->d)
{
iobuf_writestr(a, "Comment: " );
for( ; *s; s++ )
{
if( *s == '\n' )
iobuf_writestr(a, "\\n" );
else if( *s == '\r' )
iobuf_writestr(a, "\\r" );
else if( *s == '\v' )
iobuf_writestr(a, "\\v" );
else
iobuf_put(a, *s );
}

iobuf_writestr(a,(const char*) (afx->eol));
}

if ( afx->hdrlines ) {
for ( s = afx->hdrlines; *s; s++ ) {
#ifdef HAVE_DOSISH_SYSTEM
Expand Down
15 changes: 4 additions & 11 deletions gnupg/g10/build-packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +701,8 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc )
static u32
calc_plaintext( PKT_plaintext *pt )
{
/* Truncate namelen to the maximum 255 characters. Note this means
that a function that calls build_packet with an illegal literal
packet will get it back legalized. */

if(pt->namelen>255)
pt->namelen=255;

return pt->len? (1 + 1 + pt->namelen + 4 + pt->len) : 0;
/* mode, namelen=0, timestamp=0, data */
return pt->len? (1 + 1 + 4 + pt->len) : 0;
}

/* Serialize the plaintext packet (RFC 4880, 5.9) described by PT and
Expand Down Expand Up @@ -738,9 +732,8 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
|| pt->mode == 'm'
|| pt->mode == 'l' || pt->mode == '1');
iobuf_put(out, pt->mode );
iobuf_put(out, pt->namelen );
iobuf_write (out, pt->name, pt->namelen);
rc = write_32(out, pt->timestamp );
iobuf_put(out, 0 ); /* Length of nonsense filename. */
rc = write_32(out, 0 ); /* Nonsense timestamp. */
if (rc)
return rc;

Expand Down
2 changes: 1 addition & 1 deletion gnupg/g10/decrypt-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ decrypt_data (ctrl_t ctrl, void *procctx, PKT_encrypted *ed, DEK *dek)
{
char *filename = NULL;
estream_t fp;
rc = get_output_file ((const byte*) (""), 0, ed->buf, &filename, &fp);
rc = get_output_file (ed->buf, &filename, &fp);
if (! rc)
{
iobuf_t output = iobuf_esopen (fp, "w", 0);
Expand Down
2 changes: 0 additions & 2 deletions gnupg/g10/encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ encrypt_simple (const char *filename, int mode, int use_seskey)
filesize = 0; /* stdin */

{
pt->timestamp = make_timestamp();
pt->mode = opt.mimemode? 'm' : opt.textmode? 't' : 'b';
pt->len = filesize;
pt->new_ctb = !pt->len;
Expand Down Expand Up @@ -630,7 +629,6 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
else
filesize = 0; /* stdin */

pt->timestamp = make_timestamp();
pt->mode = opt.mimemode? 'm' : opt.textmode ? 't' : 'b';
pt->len = filesize;
pt->new_ctb = !pt->len;
Expand Down
28 changes: 0 additions & 28 deletions gnupg/g10/gpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ enum cmd_and_opt_values
oSigPolicyURL,
oCertPolicyURL,
oSigKeyserverURL,
oUseEmbeddedFilename,
oNoUseEmbeddedFilename,
oComment,
oDefaultComment,
oNoComments,
Expand Down Expand Up @@ -717,8 +715,6 @@ static ARGPARSE_OPTS opts[] = {
ARGPARSE_s_i (oLoggerFD, "logger-fd", "@"),
ARGPARSE_s_s (oLoggerFile, "log-file", "@"),
ARGPARSE_s_s (oLoggerFile, "logger-file", "@"), /* 1.4 compatibility. */
ARGPARSE_s_n (oUseEmbeddedFilename, "use-embedded-filename", "@"),
ARGPARSE_s_n (oNoUseEmbeddedFilename, "no-use-embedded-filename", "@"),
ARGPARSE_s_n (oUtf8Strings, "utf8-strings", "@"),
ARGPARSE_s_n (oNoUtf8Strings, "no-utf8-strings", "@"),
ARGPARSE_s_n (oWithFingerprint, "with-fingerprint", "@"),
Expand Down Expand Up @@ -2700,37 +2696,13 @@ gpg_main (int argc, char **argv)
case oRFC2440Text: opt.rfc2440_text=1; break;
case oNoRFC2440Text: opt.rfc2440_text=0; break;

case oSetFilename:
if(utf8_strings)
opt.set_filename = pargs.r.ret_str;
else
opt.set_filename = native_to_utf8(pargs.r.ret_str);
break;
case oSetPolicyURL:
add_policy_url(pargs.r.ret_str,0);
add_policy_url(pargs.r.ret_str,1);
break;
case oSigPolicyURL: add_policy_url(pargs.r.ret_str,0); break;
case oCertPolicyURL: add_policy_url(pargs.r.ret_str,1); break;
case oSigKeyserverURL: add_keyserver_url(pargs.r.ret_str,0); break;
case oUseEmbeddedFilename:
opt.flags.use_embedded_filename=1;
break;
case oNoUseEmbeddedFilename:
opt.flags.use_embedded_filename=0;
break;
case oComment:
if(pargs.r.ret_str[0])
append_to_strlist(&opt.comments,pargs.r.ret_str);
break;
case oDefaultComment:
deprecated_warning(configname,configlineno,
"--default-comment","--no-comments","");
/* fall through */
case oNoComments:
free_strlist(opt.comments);
opt.comments=NULL;
break;
case oThrowKeyids: opt.throw_keyids = 1; break;
case oNoThrowKeyids: opt.throw_keyids = 0; break;

Expand Down
5 changes: 0 additions & 5 deletions gnupg/g10/mainproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,6 @@ proc_plaintext( CTX c, PACKET *pkt )

literals_seen++;

if (pt->namelen == 8 && !memcmp( pt->name, "_CONSOLE", 8))
log_info (_("Note: sender requested \"for-your-eyes-only\"\n"));
else if (opt.verbose)
log_info (_("original file name='%.*s'\n"), pt->namelen, pt->name);

free_md_filter_context (&c->mfx);
if (gcry_md_open (&c->mfx.md, 0, 0))
BUG ();
Expand Down
3 changes: 0 additions & 3 deletions gnupg/g10/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ struct options
int force_ownertrust;
enum gnupg_compliance_mode compliance;
int keyid_format;
const char *set_filename;
strlist_t comments;
int throw_keyids;
int s2k_mode;
int s2k_digest_algo;
Expand Down Expand Up @@ -227,7 +225,6 @@ struct options
an error (but an invalid backsig still is). */
unsigned int require_cross_cert:1;

unsigned int use_embedded_filename:1;
unsigned int utf8_filename:1;
unsigned int dsa2:1;
unsigned int allow_multiple_messages:1;
Expand Down
3 changes: 1 addition & 2 deletions gnupg/g10/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,7 @@ int handle_compressed (ctrl_t ctrl, void *ctx, PKT_compressed *cd,
int decrypt_data (ctrl_t ctrl, void *ctx, PKT_encrypted *ed, DEK *dek );

/*-- plaintext.c --*/
gpg_error_t get_output_file (const byte *embedded_name, int embedded_namelen,
iobuf_t data, char **fnamep, estream_t *fpp);
gpg_error_t get_output_file (iobuf_t data, char **fnamep, estream_t *fpp);
int handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
int nooutput, int clearsig );
int ask_for_detached_datafile( gcry_md_hd_t md, gcry_md_hd_t md2,
Expand Down
54 changes: 8 additions & 46 deletions gnupg/g10/plaintext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@
/* Get the output filename. On success, the actual filename that is
used is set in *FNAMEP and a filepointer is returned in *FP.
EMBEDDED_NAME AND EMBEDDED_NAMELEN are normally stored in a
plaintext packet. EMBEDDED_NAMELEN should not include any NUL
terminator (EMBEDDED_NAME does not need to be NUL terminated).
DATA is the iobuf containing the input data. We just use it to get
the input file's filename.
On success, the caller is responsible for calling xfree on *FNAMEP
and calling es_close on *FPP. */
gpg_error_t
get_output_file (const byte *embedded_name, int embedded_namelen,
iobuf_t data, char **fnamep, estream_t *fpp)
get_output_file (iobuf_t data, char **fnamep, estream_t *fpp)
{
gpg_error_t err = 0;
char *fname = NULL;
Expand All @@ -79,25 +74,18 @@ get_output_file (const byte *embedded_name, int embedded_namelen,
goto leave;
}
}
else if (embedded_namelen == 8 && !memcmp (embedded_name, "_CONSOLE", 8))
{
log_info (_("data not saved; use option \"--output\" to save it\n"));
nooutput = 1;
}
else if (!opt.flags.use_embedded_filename)
else
{
if (data)
fname = make_outfile_name (iobuf_get_real_fname (data));
if (!fname)
fname = ask_outfile_name ((const char*) (embedded_name), embedded_namelen);
fname = ask_outfile_name (NULL, 0);
if (!fname)
{
err = GPG_ERR_GENERAL; /* Can't create file. */
goto leave;
}
}
else
fname = utf8_to_native ((const char*) (embedded_name), embedded_namelen, 0);

if (nooutput)
;
Expand Down Expand Up @@ -215,9 +203,8 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
es_fflush (es_stdout);

snprintf (status, sizeof status,
"%X %lu ", (byte) pt->mode, (unsigned long) pt->timestamp);
write_status_text_and_buffer (STATUS_PLAINTEXT,
status, pt->name, pt->namelen, 0);
"%X ", (byte) pt->mode);
write_status_text (STATUS_PLAINTEXT, status);

if (!pt->is_partial)
{
Expand All @@ -228,7 +215,7 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,

if (! nooutput)
{
err = get_output_file ((const byte*) (pt->name), pt->namelen, pt->buf, &fname, &fp);
err = get_output_file (pt->buf, &fname, &fp);
if (err)
goto leave;
}
Expand Down Expand Up @@ -739,33 +726,8 @@ setup_plaintext_name (const char *filename, IOBUF iobuf)
{
PKT_plaintext *pt;

if ((filename && !iobuf_is_pipe_filename (filename))
|| (opt.set_filename && !iobuf_is_pipe_filename (opt.set_filename)))
{
char *s;

if (opt.set_filename)
s = make_basename (opt.set_filename);
else if (filename && !opt.flags.utf8_filename)
{
char *tmp = native_to_utf8 (filename);
s = make_basename (tmp);
xfree (tmp);
}
else
s = make_basename (filename);

pt = (PKT_plaintext*) xmalloc (sizeof *pt + strlen (s) - 1);
pt->namelen = strlen (s);
memcpy (pt->name, s, pt->namelen);
xfree (s);
}
else
{
/* no filename */
pt = (PKT_plaintext*) xmalloc (sizeof *pt - 1);
pt->namelen = 0;
}
/* no filename */
pt = (PKT_plaintext*) xmalloc (sizeof *pt);

return pt;
}
1 change: 0 additions & 1 deletion gnupg/g10/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ write_plaintext_packet (IOBUF out, IOBUF inp, const char *fname, int ptmode)
{
PACKET pkt;

pt->timestamp = make_timestamp ();
pt->mode = ptmode;
pt->len = filesize;
pt->new_ctb = !pt->len;
Expand Down

0 comments on commit d572606

Please sign in to comment.