]> eyrie.org Git - kerberos/krb5-strength.git/commitdiff
Support a maximum word length in cdbmake-wordlist
authorRuss Allbery <eagle@eyrie.org>
Mon, 4 Nov 2013 18:59:19 +0000 (10:59 -0800)
committerRuss Allbery <eagle@eyrie.org>
Mon, 4 Nov 2013 18:59:19 +0000 (10:59 -0800)
Add a new -L (--max-length) option that filters out words longer
than a particular length.

tests/tools/cdbmake-wordlist-t
tools/cdbmake-wordlist

index f2c63ac53fc39fde308f5192bf631f47c01f49f9..e22587dd1fa1fdad90fa65e9b5e16c925d500b56 100755 (executable)
@@ -17,7 +17,7 @@ if ! command -v cdb >/dev/null 2>&1 ; then
 fi
 
 # Output the test plan.
-plan 11
+plan 14
 
 # Create a temporary directory and wordlist and ensure it's writable.
 tmpdir=`test_tmpdir`
@@ -61,6 +61,14 @@ ok_program 'Database still contains password' 0 '1' \
 ok_program 'Database does not contain non-ASCII password' 100 '' \
     cdb -q "$tmpdir/wordlist.cdb" 'عربى'
 
+# Regenerate the database, filtering out long passwords.
+ok_program 'Database generation with no long passwords' 0 '' \
+    "$cdbmake" -L 10 "$tmpdir/wordlist"
+ok_program 'Database still contains bitterbane' 0 '1' \
+    cdb -q "$tmpdir/wordlist.cdb" bitterbane
+ok_program 'Database does not contain happenstance' 100 '' \
+    cdb -q "$tmpdir/wordlist.cdb" happenstance
+
 # Clean up.
 rm -f "$tmpdir/wordlist.cdb"
 rm -f "$tmpdir/wordlist"
index 557ca60fd1f70eb0dd4c01f02a4fce90bdf60be6..c0ca0c4f2559b0fb68c015d8c1bd0bfefb7f9995 100755 (executable)
@@ -42,10 +42,11 @@ my $fullpath = $0;
 local $0 = basename($0);
 
 # Parse the argument list.
-my ($ascii, $min_length, $manual);
+my ($ascii, $max_length, $min_length, $manual);
 Getopt::Long::config('bundling', 'no_ignore_case');
 GetOptions(
     'ascii|a'        => \$ascii,
+    'max-length|L=i' => \$max_length,
     'min-length|l=i' => \$min_length,
     'manual|man|m'   => \$manual
 );
@@ -75,6 +76,7 @@ while (defined(my $word = <$in>)) {
     chomp($word);
     my $length = length($word);
     next if (defined($min_length) && $length < $min_length);
+    next if (defined($max_length) && $length > $max_length);
     if ($ascii) {
         next if $word =~ m{ [^[:ascii:]] }xms;
         next if $word =~ m{ [[:cntrl:]] }xms;
@@ -106,7 +108,8 @@ cdbmake-wordlist - Create a cdb database from a wordlist
 
 =head1 SYNOPSIS
 
-B<cdbmake-wordlist> [B<-am>] [B<-l> I<length>] I<wordlist>
+B<cdbmake-wordlist> [B<-am>] [B<-l> I<min-length>] [B<-L> I<max-length>]
+    I<wordlist>
 
 =head1 DESCRIPTION
 
@@ -133,6 +136,17 @@ Filter all words that contain non-ASCII characters or control characters
 from the resulting cdb file, leaving only words that consist solely of
 ASCII non-control characters.
 
+=item B<-L> I<maximum>, B<--max-length>=I<maximum>
+
+Filter all words of length greater than I<maximum> from the resulting cdb
+database.  The length of each line (minus the separating newline) in the
+input wordlist will be checked against I<minimum> and will be filtered out
+of the resulting database if it is shorter.  Useful for generating
+password dictionaries from word lists that contain random noise that's
+highly unlikely to be used as a password.
+
+The default is to not filter out any words for maximum length.
+
 =item B<-l> I<minimum>, B<--min-length>=I<minimum>
 
 Filter all words of length less than I<minimum> from the resulting cdb