From de45df09e71ac2dc16d50296087e53cca1dd685b Mon Sep 17 00:00:00 2001 From: pbailie Date: Mon, 6 Aug 2018 13:48:54 -0400 Subject: [PATCH 1/5] Ugly Password Script Generates a randomly generated long ugly password. Uses /dev/random to ensure reliable entropy. Could be used to password protect Submitty system accounts. --- sample_bin/ugly_password.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 sample_bin/ugly_password.pl diff --git a/sample_bin/ugly_password.pl b/sample_bin/ugly_password.pl new file mode 100755 index 0000000..3dd1baf --- /dev/null +++ b/sample_bin/ugly_password.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl -l + +# File: ugly_password.pl +# Date: August 6, 2018 +# Author: Peter Bailie +# +# This will output to STDOUT a randomly generated 32 character ugly password +# using the printable ASCII character range of 33 - 126. Passwords are based +# on /dev/random to ensure reliable pseudo-random entropy. +# +# /dev/random is blocking, so there may be a delay in output when the seed pool +# needs to be refreshed. + +use strict; +use warnings; +use autodie; + +# Get 32 random bytes from /dev/random +open my $fh, '<:raw', '/dev/random'; +read $fh, my $bytes, 32; +close $fh; + +#Convert each byte to a printable ascii char (ascii 33 - 126). +my $output = ""; +foreach my $i (0..(length $bytes) - 1) { + $output .= chr((unpack 'C', substr $bytes, $i, 1) % 94 + 33); +} + +print STDOUT $output; From b020fc47c5df93b8f97b1544fc831dfc2709fa37 Mon Sep 17 00:00:00 2001 From: pbailie Date: Mon, 6 Aug 2018 13:52:29 -0400 Subject: [PATCH 2/5] Fix Comment /sample_bin/ugly_password.pl Fix comment style line 23 --- sample_bin/ugly_password.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample_bin/ugly_password.pl b/sample_bin/ugly_password.pl index 3dd1baf..2daf3ea 100755 --- a/sample_bin/ugly_password.pl +++ b/sample_bin/ugly_password.pl @@ -20,7 +20,7 @@ read $fh, my $bytes, 32; close $fh; -#Convert each byte to a printable ascii char (ascii 33 - 126). +# Convert each byte to a printable ascii char (ascii 33 - 126). my $output = ""; foreach my $i (0..(length $bytes) - 1) { $output .= chr((unpack 'C', substr $bytes, $i, 1) % 94 + 33); From da9bcc043f63f8fc9498fa20ae5ca0516535607f Mon Sep 17 00:00:00 2001 From: pbailie Date: Mon, 6 Aug 2018 16:57:35 -0400 Subject: [PATCH 3/5] Ugly Password Fix sample_bin/ugly_password.pl Bugfix/refactor to disqualify certain printable chars that could confuse psql or possibly cli. --- sample_bin/ugly_password.pl | 39 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/sample_bin/ugly_password.pl b/sample_bin/ugly_password.pl index 2daf3ea..3a100ce 100755 --- a/sample_bin/ugly_password.pl +++ b/sample_bin/ugly_password.pl @@ -4,9 +4,9 @@ # Date: August 6, 2018 # Author: Peter Bailie # -# This will output to STDOUT a randomly generated 32 character ugly password -# using the printable ASCII character range of 33 - 126. Passwords are based -# on /dev/random to ensure reliable pseudo-random entropy. +# This will output to STDOUT a randomly generated ugly password using the +# printable ASCII character range of 33 - 126. Passwords are based on +# /dev/random to ensure reliable pseudo-random entropy. # # /dev/random is blocking, so there may be a delay in output when the seed pool # needs to be refreshed. @@ -15,15 +15,30 @@ use warnings; use autodie; -# Get 32 random bytes from /dev/random -open my $fh, '<:raw', '/dev/random'; -read $fh, my $bytes, 32; +my $PW_LENGTH = 32; # length of the ugly password in characters. +my ($fh, $byte, $val, $output); + +$output = ""; # password output +open $fh, '<:raw', '/dev/random'; +build_ugly_password(); close $fh; +print STDOUT $output; +exit 0; -# Convert each byte to a printable ascii char (ascii 33 - 126). -my $output = ""; -foreach my $i (0..(length $bytes) - 1) { - $output .= chr((unpack 'C', substr $bytes, $i, 1) % 94 + 33); -} +# Recursive subroutine to generate a random char and build the ugly password. +sub build_ugly_password { + read $fh, $byte, 1; + $val = (unpack 'C', $byte) % 94 + 33; -print STDOUT $output; + # Single quote, double quote, and backtick chars are disqualified. + # Prevents edge cases for copy/pasting ugly passwords to cli. + if ($val != 34 && $val != 39 && $val != 96) { + # Character qualifies, append it to password. + $output .= chr $val; + } + + # Go again, if needed. + if (length $output < $PW_LENGTH) { + build_ugly_password(); + } +} From 02a546bc70b2feb55244f43dd6a9c14af1dff686 Mon Sep 17 00:00:00 2001 From: pbailie Date: Mon, 6 Aug 2018 17:00:03 -0400 Subject: [PATCH 4/5] Ugly Password Comment Update sample_bin/ugly_password.pl Some comments didn't make it to last commit. --- sample_bin/ugly_password.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sample_bin/ugly_password.pl b/sample_bin/ugly_password.pl index 3a100ce..d041f86 100755 --- a/sample_bin/ugly_password.pl +++ b/sample_bin/ugly_password.pl @@ -27,11 +27,12 @@ # Recursive subroutine to generate a random char and build the ugly password. sub build_ugly_password { + # Read a random byte and scale it to range 33 - 126. read $fh, $byte, 1; $val = (unpack 'C', $byte) % 94 + 33; # Single quote, double quote, and backtick chars are disqualified. - # Prevents edge cases for copy/pasting ugly passwords to cli. + # Prevents some edge cases for copy/pasting ugly passwords to psql or cli. if ($val != 34 && $val != 39 && $val != 96) { # Character qualifies, append it to password. $output .= chr $val; From 34108db167534bcb7c6c5f19a26d6398560aa22d Mon Sep 17 00:00:00 2001 From: pbailie Date: Tue, 7 Aug 2018 15:51:26 -0400 Subject: [PATCH 5/5] Ugly Password Script Changes to be committed: modified: sample_bin/ugly_password.pl --- sample_bin/ugly_password.pl | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/sample_bin/ugly_password.pl b/sample_bin/ugly_password.pl index d041f86..5e585d9 100755 --- a/sample_bin/ugly_password.pl +++ b/sample_bin/ugly_password.pl @@ -1,15 +1,15 @@ -#!/usr/bin/env perl -l +#!/usr/bin/env perl # File: ugly_password.pl -# Date: August 6, 2018 +# Date: August 7, 2018 # Author: Peter Bailie # # This will output to STDOUT a randomly generated ugly password using the # printable ASCII character range of 33 - 126. Passwords are based on # /dev/random to ensure reliable pseudo-random entropy. # -# /dev/random is blocking, so there may be a delay in output when the seed pool -# needs to be refreshed. +# /dev/random is blocking, so there may be a (possibly lengthy) delay in +# output when the seed pool needs to be refreshed. use strict; use warnings; @@ -18,15 +18,9 @@ my $PW_LENGTH = 32; # length of the ugly password in characters. my ($fh, $byte, $val, $output); -$output = ""; # password output open $fh, '<:raw', '/dev/random'; -build_ugly_password(); -close $fh; -print STDOUT $output; -exit 0; - -# Recursive subroutine to generate a random char and build the ugly password. -sub build_ugly_password { +$output = ""; # password output +while (length $output < $PW_LENGTH) { # Read a random byte and scale it to range 33 - 126. read $fh, $byte, 1; $val = (unpack 'C', $byte) % 94 + 33; @@ -37,9 +31,6 @@ sub build_ugly_password { # Character qualifies, append it to password. $output .= chr $val; } - - # Go again, if needed. - if (length $output < $PW_LENGTH) { - build_ugly_password(); - } } +close $fh; +print STDOUT $output . "\n";