2017-04-24 15:34:09 +00:00
|
|
|
diff -up gnupg-2.1.20/g10/gpg.c.file-is-digest gnupg-2.1.20/g10/gpg.c
|
|
|
|
--- gnupg-2.1.20/g10/gpg.c.file-is-digest 2017-04-24 15:39:44.279999738 +0200
|
|
|
|
+++ gnupg-2.1.20/g10/gpg.c 2017-04-24 15:39:44.281999785 +0200
|
|
|
|
@@ -374,6 +374,7 @@ enum cmd_and_opt_values
|
2014-09-27 18:55:11 +00:00
|
|
|
oTTYtype,
|
|
|
|
oLCctype,
|
|
|
|
oLCmessages,
|
|
|
|
+ oFileIsDigest,
|
|
|
|
oXauthority,
|
|
|
|
oGroup,
|
|
|
|
oUnGroup,
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -817,6 +818,7 @@ static ARGPARSE_OPTS opts[] = {
|
2014-09-27 18:55:11 +00:00
|
|
|
ARGPARSE_s_s (oPersonalCompressPreferences,
|
|
|
|
"personal-compress-preferences", "@"),
|
2015-01-29 17:00:00 +00:00
|
|
|
ARGPARSE_s_s (oFakedSystemTime, "faked-system-time", "@"),
|
2014-09-27 18:55:11 +00:00
|
|
|
+ ARGPARSE_s_n (oFileIsDigest, "file-is-digest", "@"),
|
2015-12-07 15:47:21 +00:00
|
|
|
ARGPARSE_s_s (oWeakDigest, "weak-digest","@"),
|
|
|
|
ARGPARSE_s_n (oUnwrap, "unwrap", "@"),
|
|
|
|
ARGPARSE_s_n (oOnlySignTextIDs, "only-sign-text-ids", "@"),
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -2394,6 +2396,7 @@ main (int argc, char **argv)
|
2016-07-12 09:41:59 +00:00
|
|
|
gnupg_set_homedir (NULL);
|
2015-01-29 17:00:00 +00:00
|
|
|
opt.passphrase_repeat = 1;
|
2016-11-28 14:10:25 +00:00
|
|
|
opt.emit_version = 0;
|
|
|
|
+ opt.file_is_digest = 0;
|
2015-12-07 15:47:21 +00:00
|
|
|
opt.weak_digests = NULL;
|
|
|
|
additional_weak_digest("MD5");
|
2014-09-27 18:55:11 +00:00
|
|
|
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -2942,6 +2945,7 @@ main (int argc, char **argv)
|
2015-01-29 17:00:00 +00:00
|
|
|
opt.verify_options&=~VERIFY_SHOW_PHOTOS;
|
|
|
|
break;
|
2014-09-27 18:55:11 +00:00
|
|
|
case oPhotoViewer: opt.photo_viewer = pargs.r.ret_str; break;
|
|
|
|
+ case oFileIsDigest: opt.file_is_digest = 1; break;
|
2015-01-29 17:00:00 +00:00
|
|
|
|
2014-09-27 18:55:11 +00:00
|
|
|
case oForceMDC: opt.force_mdc = 1; break;
|
2015-01-29 17:00:00 +00:00
|
|
|
case oNoForceMDC: opt.force_mdc = 0; break;
|
2017-04-24 15:34:09 +00:00
|
|
|
diff -up gnupg-2.1.20/g10/options.h.file-is-digest gnupg-2.1.20/g10/options.h
|
|
|
|
--- gnupg-2.1.20/g10/options.h.file-is-digest 2017-04-03 17:13:56.000000000 +0200
|
|
|
|
+++ gnupg-2.1.20/g10/options.h 2017-04-24 15:39:44.281999785 +0200
|
|
|
|
@@ -214,6 +214,7 @@ struct
|
2014-09-27 18:55:11 +00:00
|
|
|
int no_auto_check_trustdb;
|
|
|
|
int preserve_permissions;
|
|
|
|
int no_homedir_creation;
|
|
|
|
+ int file_is_digest;
|
|
|
|
struct groupitem *grouplist;
|
|
|
|
int mangle_dos_filenames;
|
|
|
|
int enable_progress_filter;
|
2017-04-24 15:34:09 +00:00
|
|
|
diff -up gnupg-2.1.20/g10/sign.c.file-is-digest gnupg-2.1.20/g10/sign.c
|
|
|
|
--- gnupg-2.1.20/g10/sign.c.file-is-digest 2017-04-03 17:13:56.000000000 +0200
|
|
|
|
+++ gnupg-2.1.20/g10/sign.c 2017-04-24 15:43:51.475847998 +0200
|
2016-07-12 09:41:59 +00:00
|
|
|
@@ -40,6 +40,7 @@
|
2015-02-18 18:40:27 +00:00
|
|
|
#include "pkglue.h"
|
2017-04-24 15:34:09 +00:00
|
|
|
#include "../common/sysutils.h"
|
2015-02-18 18:40:27 +00:00
|
|
|
#include "call-agent.h"
|
2017-04-24 15:34:09 +00:00
|
|
|
+#include "../common/host2net.h"
|
|
|
|
#include "../common/mbox-util.h"
|
2015-02-18 18:40:27 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_DOSISH_SYSTEM
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -695,6 +696,8 @@ write_signature_packets (ctrl_t ctrl,
|
2016-02-16 12:44:26 +00:00
|
|
|
if (duration || opt.sig_policy_url
|
|
|
|
|| opt.sig_notations || opt.sig_keyserver_url)
|
|
|
|
sig->version = 4;
|
|
|
|
+ else if (opt.file_is_digest)
|
|
|
|
+ sig->version = 3;
|
|
|
|
else
|
|
|
|
sig->version = pk->version;
|
|
|
|
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -718,8 +721,10 @@ write_signature_packets (ctrl_t ctrl,
|
2015-01-29 17:00:00 +00:00
|
|
|
mk_notation_policy_etc (sig, NULL, pk);
|
|
|
|
}
|
2014-09-27 18:55:11 +00:00
|
|
|
|
2015-01-29 17:00:00 +00:00
|
|
|
- hash_sigversion_to_magic (md, sig);
|
|
|
|
- gcry_md_final (md);
|
|
|
|
+ if (!opt.file_is_digest) {
|
|
|
|
+ hash_sigversion_to_magic (md, sig);
|
|
|
|
+ gcry_md_final (md);
|
|
|
|
+ }
|
2014-09-27 18:55:11 +00:00
|
|
|
|
2017-04-24 15:34:09 +00:00
|
|
|
rc = do_sign (ctrl, pk, sig, md, hash_for (pk), cache_nonce);
|
2015-01-29 17:00:00 +00:00
|
|
|
gcry_md_close (md);
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -781,6 +786,8 @@ sign_file (ctrl_t ctrl, strlist_t filena
|
2014-09-27 18:55:11 +00:00
|
|
|
SK_LIST sk_rover = NULL;
|
|
|
|
int multifile = 0;
|
|
|
|
u32 duration=0;
|
|
|
|
+ int sigclass = 0x00;
|
|
|
|
+ u32 timestamp = 0;
|
|
|
|
|
|
|
|
pfx = new_progress_context ();
|
|
|
|
afx = new_armor_context ();
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -798,7 +805,16 @@ sign_file (ctrl_t ctrl, strlist_t filena
|
2014-09-27 18:55:11 +00:00
|
|
|
fname = NULL;
|
|
|
|
|
|
|
|
if( fname && filenames->next && (!detached || encryptflag) )
|
|
|
|
- log_bug("multiple files can only be detached signed");
|
|
|
|
+ log_bug("multiple files can only be detached signed\n");
|
|
|
|
+
|
|
|
|
+ if (opt.file_is_digest && (multifile || !fname))
|
|
|
|
+ log_bug("file-is-digest only works with one file\n");
|
|
|
|
+ if (opt.file_is_digest && !detached)
|
|
|
|
+ log_bug("file-is-digest can only write detached signatures\n");
|
|
|
|
+ if (opt.file_is_digest && !opt.def_digest_algo)
|
|
|
|
+ log_bug("file-is-digest needs --digest-algo\n");
|
|
|
|
+ if (opt.file_is_digest && opt.textmode)
|
|
|
|
+ log_bug("file-is-digest doesn't work with --textmode\n");
|
|
|
|
|
|
|
|
if(encryptflag==2
|
|
|
|
&& (rc=setup_symkey(&efx.symkey_s2k,&efx.symkey_dek)))
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -819,7 +835,7 @@ sign_file (ctrl_t ctrl, strlist_t filena
|
2014-09-27 18:55:11 +00:00
|
|
|
goto leave;
|
|
|
|
|
|
|
|
/* prepare iobufs */
|
|
|
|
- if( multifile ) /* have list of filenames */
|
|
|
|
+ if( multifile || opt.file_is_digest) /* have list of filenames */
|
|
|
|
inp = NULL; /* we do it later */
|
|
|
|
else {
|
|
|
|
inp = iobuf_open(fname);
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -957,7 +973,7 @@ sign_file (ctrl_t ctrl, strlist_t filena
|
2015-01-29 17:00:00 +00:00
|
|
|
for (sk_rover = sk_list; sk_rover; sk_rover = sk_rover->next)
|
|
|
|
gcry_md_enable (mfx.md, hash_for (sk_rover->pk));
|
2014-09-27 18:55:11 +00:00
|
|
|
|
|
|
|
- if( !multifile )
|
|
|
|
+ if( !multifile && !opt.file_is_digest )
|
|
|
|
iobuf_push_filter( inp, md_filter, &mfx );
|
|
|
|
|
2015-01-29 17:00:00 +00:00
|
|
|
if( detached && !encryptflag)
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -1012,6 +1028,8 @@ sign_file (ctrl_t ctrl, strlist_t filena
|
2014-09-27 18:55:11 +00:00
|
|
|
|
|
|
|
write_status_begin_signing (mfx.md);
|
|
|
|
|
|
|
|
+ sigclass = opt.textmode && !outfile? 0x01 : 0x00;
|
|
|
|
+
|
|
|
|
/* Setup the inner packet. */
|
|
|
|
if( detached ) {
|
|
|
|
if( multifile ) {
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -1052,6 +1070,45 @@ sign_file (ctrl_t ctrl, strlist_t filena
|
2014-09-27 18:55:11 +00:00
|
|
|
if( opt.verbose )
|
2015-04-16 16:06:21 +00:00
|
|
|
log_printf ("\n");
|
2014-09-27 18:55:11 +00:00
|
|
|
}
|
|
|
|
+ else if (opt.file_is_digest) {
|
|
|
|
+ byte *mdb, ts[5];
|
|
|
|
+ size_t mdlen;
|
|
|
|
+ const char *fp;
|
|
|
|
+ int c, d;
|
|
|
|
+
|
|
|
|
+ gcry_md_final(mfx.md);
|
|
|
|
+ /* this assumes gcry_md_read returns the same buffer */
|
|
|
|
+ mdb = gcry_md_read(mfx.md, opt.def_digest_algo);
|
|
|
|
+ mdlen = gcry_md_get_algo_dlen(opt.def_digest_algo);
|
|
|
|
+ if (strlen(fname) != mdlen * 2 + 11)
|
|
|
|
+ log_bug("digests must be %zu + @ + 5 bytes\n", mdlen);
|
|
|
|
+ d = -1;
|
|
|
|
+ for (fp = fname ; *fp; ) {
|
|
|
|
+ c = *fp++;
|
|
|
|
+ if (c >= '0' && c <= '9')
|
|
|
|
+ c -= '0';
|
|
|
|
+ else if (c >= 'a' && c <= 'f')
|
|
|
|
+ c -= 'a' - 10;
|
|
|
|
+ else if (c >= 'A' && c <= 'F')
|
|
|
|
+ c -= 'A' - 10;
|
|
|
|
+ else
|
|
|
|
+ log_bug("filename is not hex\n");
|
|
|
|
+ if (d >= 0) {
|
|
|
|
+ *mdb++ = d << 4 | c;
|
|
|
|
+ c = -1;
|
|
|
|
+ if (--mdlen == 0) {
|
|
|
|
+ mdb = ts;
|
|
|
|
+ if (*fp++ != '@')
|
|
|
|
+ log_bug("missing time separator\n");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ d = c;
|
|
|
|
+ }
|
|
|
|
+ sigclass = ts[0];
|
|
|
|
+ if (sigclass != 0x00 && sigclass != 0x01)
|
|
|
|
+ log_bug("bad cipher class\n");
|
2015-02-18 18:40:27 +00:00
|
|
|
+ timestamp = buf32_to_u32(ts + 1);
|
2014-09-27 18:55:11 +00:00
|
|
|
+ }
|
|
|
|
else {
|
|
|
|
/* read, so that the filter can calculate the digest */
|
|
|
|
while( iobuf_get(inp) != -1 )
|
2017-04-24 15:34:09 +00:00
|
|
|
@@ -1070,8 +1127,8 @@ sign_file (ctrl_t ctrl, strlist_t filena
|
2014-09-27 18:55:11 +00:00
|
|
|
|
|
|
|
/* write the signatures */
|
2017-04-24 15:34:09 +00:00
|
|
|
rc = write_signature_packets (ctrl, sk_list, out, mfx.md,
|
2014-09-27 18:55:11 +00:00
|
|
|
- opt.textmode && !outfile? 0x01 : 0x00,
|
2015-01-29 17:00:00 +00:00
|
|
|
- 0, duration, detached ? 'D':'S', NULL);
|
2014-09-27 18:55:11 +00:00
|
|
|
+ sigclass,
|
2015-01-29 17:00:00 +00:00
|
|
|
+ timestamp, duration, detached ? 'D':'S', NULL);
|
2014-09-27 18:55:11 +00:00
|
|
|
if( rc )
|
|
|
|
goto leave;
|
|
|
|
|