From ac5bcd89faae74da3c98142f6f1ecec290a0b94d Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 17 Feb 2019 15:49:57 +0100 Subject: [PATCH] Add -m 8500 unit test --- tools/test_modules/m08500.pm | 79 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/tools/test_modules/m08500.pm b/tools/test_modules/m08500.pm index d245c6b97..6b018ee4a 100644 --- a/tools/test_modules/m08500.pm +++ b/tools/test_modules/m08500.pm @@ -11,7 +11,38 @@ use warnings; use Convert::EBCDIC qw (ascii2ebcdic); use Crypt::DES; -sub module_constraints { [[1, 8], [1, 8], [-1, -1], [-1, -1], [-1, -1]] } +sub module_constraints { [[0, 8], [1, 8], [-1, -1], [-1, -1], [-1, -1]] } + +sub racf_hash +{ + my ($username, $password) = @_; + + $username = substr ($username . " " x 8, 0, 8); + $password = substr ($password . " " x 8, 0, 8); + + my $username_ebc = ascii2ebcdic ($username); + my $password_ebc = ascii2ebcdic ($password); + + my @pw = split ("", $password_ebc); + + for (my $i = 0; $i < 8; $i++) + { + $pw[$i] = unpack ("C", $pw[$i]); + $pw[$i] ^= 0x55; + $pw[$i] <<= 1; + $pw[$i] = pack ("C", $pw[$i] & 0xff); + } + + my $key = join ("", @pw); + + my $cipher = new Crypt::DES $key; + + my $ciphertext = $cipher->encrypt ($username_ebc); + + my $ct = unpack ("H16", $ciphertext); + + return $ct; +} sub module_generate_hash { @@ -20,9 +51,9 @@ sub module_generate_hash my $hash_buf = racf_hash (uc $salt, $word); - my $tmp_hash = sprintf ('$racf$*%s*%s', uc $salt, uc $hash_buf); + my $hash = sprintf ('$racf$*%s*%s', uc $salt, uc $hash_buf); - return $tmp_hash; + return $hash; } sub module_verify_hash @@ -33,13 +64,11 @@ sub module_verify_hash return if scalar @line_elements < 2; - # get hash and word - my $hash_in = shift @line_elements; my $word = join (":", @line_elements); - # get signature + # check signature my @hash_elements = split ('\*', $hash_in); @@ -47,42 +76,14 @@ sub module_verify_hash my $salt = $hash_elements[1]; - my $word_packed = pack_if_HEX_notation ($word); + return unless defined $salt; + return unless defined $word; - my $new_hash = module_generate_hash ($word_packed, $salt); + $word = pack_if_HEX_notation ($word); - return ($new_hash, $word); -} - -sub racf_hash -{ - my ($username, $password) = @_; - - $username = substr ($username . " " x 8, 0, 8); - $password = substr ($password . " " x 8, 0, 8); - - my $username_ebc = ascii2ebcdic ($username); - my $password_ebc = ascii2ebcdic ($password); - - my @pw = split ("", $password_ebc); - - for (my $i = 0; $i < 8; $i++) - { - $pw[$i] = unpack ("C", $pw[$i]); - $pw[$i] ^= 0x55; - $pw[$i] <<= 1; - $pw[$i] = pack ("C", $pw[$i] & 0xff); - } - - my $key = join ("", @pw); + my $new_hash = module_generate_hash ($word, $salt); - my $cipher = new Crypt::DES $key; - - my $ciphertext = $cipher->encrypt ($username_ebc); - - my $ct = unpack ("H16", $ciphertext); - - return $ct; + return ($new_hash, $word); } 1;