From 46210dd177440507a12dbdb8aebf0e183e89d25a Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 10 Dec 2020 03:11:31 +0100 Subject: [PATCH] Added test module --- tools/test_modules/m21501.pm | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tools/test_modules/m21501.pm diff --git a/tools/test_modules/m21501.pm b/tools/test_modules/m21501.pm new file mode 100644 index 000000000..f636f2e71 --- /dev/null +++ b/tools/test_modules/m21501.pm @@ -0,0 +1,74 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use MIME::Base64 qw (encode_base64 decode_base64); +use Crypt::PBKDF2; +use Digest::SHA qw (sha512); +use Encode; + +sub module_constraints { [[0, 256], [16, 16], [-1, -1], [-1, -1], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $kdf = Crypt::PBKDF2->new + ( + hash_class => 'HMACSHA1', + iterations => 1000, + output_len => 1024 + ); + + my $salt_b64 = encode_base64 ($salt, ""); + + my $key = $kdf->PBKDF2 ($salt, $word); + + my $key_b64 = encode_base64 (sha512 ($key), ""); + + my $hash = sprintf ("\$solarwinds\$1\$%s\$%s", $salt_b64, $key_b64); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $word; + + my @data = split ('\$', $hash); + + return unless scalar @data == 5; + + shift @data; + + my $signature = shift @data; + my $sig_dec = shift @data; + my $salt = shift @data; + my $digest = shift @data; + + return unless ($signature eq "solarwinds"); + return unless ($sig_dec eq "1"); + + return unless length ($salt) == 24; + return unless length ($digest) == 88; + + my $word_packed = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word_packed, $salt); + + return ($new_hash, $word); +} + +1;