1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-16 00:29:50 +02:00

gpg: Add option --weak-digest to gpg and gpgv.

* g10/options.h: Add weak_digests linked list to opts.
* g10/main.h: Declare weakhash linked list struct and
additional_weak_digest() function to insert newly-declared weak
digests into opts.
* g10/misc.c: (additional_weak_digest): New function.
(print_digest_algo_note): Check for deprecated digests.
* g10/sig-check.c: (do_check): Reject all weak digests.
* g10/gpg.c: Add --weak-digest option to gpg.
* doc/gpg.texi: Document gpg --weak-digest option.
* g10/gpgv.c: Add --weak-digest option to gpgv.
* doc/gpgv.texi: Document gpgv --weak-digest option.

--
gpg and gpgv treat signatures made over MD5 as unreliable, unless the
user supplies --allow-weak-digests to gpg.  Signatures over any other
digest are considered acceptable.

Despite SHA-1 being a mandatory-to-implement digest algorithm in RFC
4880, the collision-resistance of SHA-1 is weaker than anyone would
like it to be.

Some operators of high-value targets that depend on OpenPGP signatures
may wish to require their signers to use a stronger digest algorithm
than SHA1, even if the OpenPGP ecosystem at large cannot deprecate
SHA1 entirely today.

This changeset adds a new "--weak-digest DIGEST" option for both gpg
and gpgv, which makes it straightforward for anyone to treat any
signature or certification made over the specified digest as
unreliable.

This option can be supplied multiple times if the operator wishes to
deprecate multiple digest algorithms, and will be ignored completely
if the operator supplies --allow-weak-digests (as before).

MD5 is always considered weak, regardless of any further
--weak-digest options supplied.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>

(this is a rough cherry-pick of applying the following commits to
 STABLE-BRANCH-1-4:
  76afaed65e
  b98939812a
  91015d021b
)
This commit is contained in:
Daniel Kahn Gillmor 2015-10-27 00:01:32 -04:00 committed by Werner Koch
parent 43e5d28c6d
commit 924518b10d
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
8 changed files with 92 additions and 18 deletions

View File

@ -2610,9 +2610,20 @@ message was tampered with intentionally by an attacker.
@item --allow-weak-digest-algos @item --allow-weak-digest-algos
@opindex allow-weak-digest-algos @opindex allow-weak-digest-algos
Signatures made with the broken MD5 algorithm are normally rejected Signatures made with known-weak digest algorithms are normally
with an ``invalid digest algorithm'' message. This option allows the rejected with an ``invalid digest algorithm'' message. This option
verification of signatures made with such weak algorithms. allows the verification of signatures made with such weak algorithms.
MD5 is the only digest algorithm considered weak by default. See also
@option{--weak-digest} to reject other digest algorithms.
@item --weak-digest @code{name}
@opindex weak-digest
Treat the specified digest algorithm as weak. Signatures made over
weak digests algorithms are normally rejected. This option can be
supplied multiple times if multiple algorithms should be considered
weak. See also @option{--allow-weak-digest-algos} to disable
rejection of weak digests. MD5 is always considered weak, and does
not need to be listed explicitly.
@item --no-default-keyring @item --no-default-keyring

View File

@ -115,6 +115,14 @@ checks into warnings.
@include opt-homedir.texi @include opt-homedir.texi
@item --weak-digest @code{name}
@opindex weak-digest
Treat the specified digest algorithm as weak. Signatures made over
weak digests algorithms are normally rejected. This option can be
supplied multiple times if multiple algorithms should be considered
weak. MD5 is always considered weak, and does not need to be listed
explicitly.
@end table @end table
@mansect return value @mansect return value

View File

@ -377,6 +377,7 @@ enum cmd_and_opt_values
oAllowMultipleMessages, oAllowMultipleMessages,
oNoAllowMultipleMessages, oNoAllowMultipleMessages,
oAllowWeakDigestAlgos, oAllowWeakDigestAlgos,
oWeakDigest,
oNoop oNoop
}; };
@ -689,6 +690,7 @@ static ARGPARSE_OPTS opts[] = {
{ oPersonalCipherPreferences, "personal-cipher-preferences", 2, "@"}, { oPersonalCipherPreferences, "personal-cipher-preferences", 2, "@"},
{ oPersonalDigestPreferences, "personal-digest-preferences", 2, "@"}, { oPersonalDigestPreferences, "personal-digest-preferences", 2, "@"},
{ oPersonalCompressPreferences, "personal-compress-preferences", 2, "@"}, { oPersonalCompressPreferences, "personal-compress-preferences", 2, "@"},
{ oWeakDigest, "weak-digest", 2, "@"},
/* Aliases. I constantly mistype these, and assume other people /* Aliases. I constantly mistype these, and assume other people
do as well. */ do as well. */
{ oPersonalCipherPreferences, "personal-cipher-prefs", 2, "@"}, { oPersonalCipherPreferences, "personal-cipher-prefs", 2, "@"},
@ -1923,6 +1925,8 @@ main (int argc, char **argv )
#endif #endif
opt.disable_keypad = 1; /* No keypad support; use gpg2 instead. */ opt.disable_keypad = 1; /* No keypad support; use gpg2 instead. */
#endif /*ENABLE_CARD_SUPPORT*/ #endif /*ENABLE_CARD_SUPPORT*/
opt.weak_digests = NULL;
additional_weak_digest("MD5");
/* check whether we have a config file on the commandline */ /* check whether we have a config file on the commandline */
orig_argc = argc; orig_argc = argc;
@ -2793,6 +2797,9 @@ main (int argc, char **argv )
case oDisplay: opt.display = pargs.r.ret_str; break; case oDisplay: opt.display = pargs.r.ret_str; break;
case oTTYname: opt.ttyname = pargs.r.ret_str; break; case oTTYname: opt.ttyname = pargs.r.ret_str; break;
case oTTYtype: opt.ttytype = pargs.r.ret_str; break; case oTTYtype: opt.ttytype = pargs.r.ret_str; break;
case oWeakDigest:
additional_weak_digest(pargs.r.ret_str);
break;
case oLCctype: opt.lc_ctype = pargs.r.ret_str; break; case oLCctype: opt.lc_ctype = pargs.r.ret_str; break;
case oLCmessages: opt.lc_messages = pargs.r.ret_str; break; case oLCmessages: opt.lc_messages = pargs.r.ret_str; break;
case oGroup: add_group(pargs.r.ret_str); break; case oGroup: add_group(pargs.r.ret_str); break;

View File

@ -60,6 +60,7 @@ enum cmd_and_opt_values { aNull = 0,
oStatusFD, oStatusFD,
oLoggerFD, oLoggerFD,
oHomedir, oHomedir,
oWeakDigest,
aTest }; aTest };
@ -75,6 +76,7 @@ static ARGPARSE_OPTS opts[] = {
{ oStatusFD, "status-fd" ,1, N_("|FD|write status info to this FD") }, { oStatusFD, "status-fd" ,1, N_("|FD|write status info to this FD") },
{ oLoggerFD, "logger-fd",1, "@" }, { oLoggerFD, "logger-fd",1, "@" },
{ oHomedir, "homedir", 2, "@" }, /* defaults to "~/.gnupg" */ { oHomedir, "homedir", 2, "@" }, /* defaults to "~/.gnupg" */
{ oWeakDigest, "weak-digest", 2, "@" }, /* defaults to "~/.gnupg" */
{0} }; {0} };
@ -143,6 +145,7 @@ main( int argc, char **argv )
opt.keyserver_options.options|=KEYSERVER_AUTO_KEY_RETRIEVE; opt.keyserver_options.options|=KEYSERVER_AUTO_KEY_RETRIEVE;
opt.trust_model = TM_ALWAYS; opt.trust_model = TM_ALWAYS;
opt.batch = 1; opt.batch = 1;
opt.weak_digests = NULL;
opt.homedir = default_homedir (); opt.homedir = default_homedir ();
@ -151,6 +154,7 @@ main( int argc, char **argv )
dotlock_disable (); dotlock_disable ();
set_native_charset (NULL); /* Try to auto set the character set */ set_native_charset (NULL); /* Try to auto set the character set */
additional_weak_digest("MD5");
pargs.argc = &argc; pargs.argc = &argc;
pargs.argv = &argv; pargs.argv = &argv;
@ -164,6 +168,7 @@ main( int argc, char **argv )
case oStatusFD: set_status_fd( pargs.r.ret_int ); break; case oStatusFD: set_status_fd( pargs.r.ret_int ); break;
case oLoggerFD: log_set_logfile( NULL, pargs.r.ret_int ); break; case oLoggerFD: log_set_logfile( NULL, pargs.r.ret_int ); break;
case oHomedir: opt.homedir = pargs.r.ret_str; break; case oHomedir: opt.homedir = pargs.r.ret_str; break;
case oWeakDigest: additional_weak_digest(pargs.r.ret_str); break;
case oIgnoreTimeConflict: opt.ignore_time_conflict = 1; break; case oIgnoreTimeConflict: opt.ignore_time_conflict = 1; break;
default : pargs.err = 2; break; default : pargs.err = 2; break;
} }

View File

@ -60,6 +60,14 @@ struct groupitem
struct groupitem *next; struct groupitem *next;
}; };
struct weakhash
{
int algo;
int rejection_shown;
struct weakhash *next;
};
/*-- gpg.c --*/ /*-- gpg.c --*/
extern int g10_errors_seen; extern int g10_errors_seen;
@ -71,6 +79,7 @@ extern int g10_errors_seen;
void print_pubkey_algo_note( int algo ); void print_pubkey_algo_note( int algo );
void print_cipher_algo_note( int algo ); void print_cipher_algo_note( int algo );
void print_digest_algo_note( int algo ); void print_digest_algo_note( int algo );
void additional_weak_digest (const char* digestname);
/*-- armor.c --*/ /*-- armor.c --*/
char *make_radix64_string( const byte *data, size_t len ); char *make_radix64_string( const byte *data, size_t len );

View File

@ -332,6 +332,8 @@ print_cipher_algo_note( int algo )
void void
print_digest_algo_note( int algo ) print_digest_algo_note( int algo )
{ {
const struct weakhash *weak;
if(algo >= 100 && algo <= 110) if(algo >= 100 && algo <= 110)
{ {
static int warn=0; static int warn=0;
@ -342,8 +344,11 @@ print_digest_algo_note( int algo )
digest_algo_to_string(algo)); digest_algo_to_string(algo));
} }
} }
else if(algo==DIGEST_ALGO_MD5) else
md5_digest_warn (1); for (weak = opt.weak_digests; weak; weak = weak->next)
if (weak->algo == algo)
log_info (_("WARNING: digest algorithm %s is deprecated\n"),
digest_algo_to_string(algo));
} }
/* Return a string which is used as a kind of process ID */ /* Return a string which is used as a kind of process ID */
@ -1310,3 +1315,32 @@ path_access(const char *file,int mode)
} }
#endif /*ndef __VMS*/ #endif /*ndef __VMS*/
/* Ignore signatures and certifications made over certain digest
* algorithms. This allows users to deprecate support for algorithms
* they are not willing to rely on.
*/
void
additional_weak_digest (const char* digestname)
{
struct weakhash *weak = NULL;
const int algo = string_to_digest_algo(digestname);
if (algo == 0)
{
log_error(_("Unknown weak digest '%s'\n"), digestname);
return;
}
/* Check to ensure it's not already present. */
for (weak = opt.weak_digests; weak != NULL; weak = weak->next)
if (algo == weak->algo)
return;
/* Add it to the head of the list. */
weak = xmalloc(sizeof(*weak));
weak->algo = algo;
weak->rejection_shown = 0;
weak->next = opt.weak_digests;
opt.weak_digests = weak;
}

View File

@ -164,6 +164,7 @@ struct
prefitem_t *personal_cipher_prefs; prefitem_t *personal_cipher_prefs;
prefitem_t *personal_digest_prefs; prefitem_t *personal_digest_prefs;
prefitem_t *personal_compress_prefs; prefitem_t *personal_compress_prefs;
struct weakhash *weak_digests;
int no_perm_warn; int no_perm_warn;
int no_mdc_warn; int no_mdc_warn;
char *temp_dir; char *temp_dir;

View File

@ -239,26 +239,25 @@ do_check( PKT_public_key *pk, PKT_signature *sig, MD_HANDLE digest,
{ {
MPI result = NULL; MPI result = NULL;
int rc=0; int rc=0;
struct weakhash *weak;
if( (rc=do_check_messages(pk,sig,r_expired,r_revoked)) ) if( (rc=do_check_messages(pk,sig,r_expired,r_revoked)) )
return rc; return rc;
if (sig->digest_algo == DIGEST_ALGO_MD5 if (!opt.flags.allow_weak_digest_algos)
&& !opt.flags.allow_weak_digest_algos) for (weak = opt.weak_digests; weak; weak = weak->next)
{ if (sig->digest_algo == weak->algo)
static int shown;
if (!shown)
{ {
log_info if (!weak->rejection_shown)
(_("Note: signatures using the %s algorithm are rejected\n"), {
"MD5"); log_info
shown = 1; (_("Note: signatures using the %s algorithm are rejected\n"),
digest_algo_to_string(sig->digest_algo));
weak->rejection_shown = 1;
}
return G10ERR_DIGEST_ALGO;
} }
return G10ERR_DIGEST_ALGO;
}
/* make sure the digest algo is enabled (in case of a detached signature)*/ /* make sure the digest algo is enabled (in case of a detached signature)*/
md_enable( digest, sig->digest_algo ); md_enable( digest, sig->digest_algo );