From 4f57d8010a90fe1221c351f695d15d29a9cdc37f Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 3 Oct 2012 16:59:46 +0200 Subject: calculate verifiers and multiplier just like in py srp Some other parts are still missing. Main issue was using hashes of hex representation rather that hashes of byte arrays --- test/client_test.rb | 29 +++++++++++++++++++++++++++++ test/util_test.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 test/client_test.rb create mode 100644 test/util_test.rb (limited to 'test') diff --git a/test/client_test.rb b/test/client_test.rb new file mode 100644 index 0000000..8ef53aa --- /dev/null +++ b/test/client_test.rb @@ -0,0 +1,29 @@ +require File.expand_path(File.dirname(__FILE__) + '/test_helper') + +class ClientTest < Test::Unit::TestCase + + def setup + @login = "testuser" + @password = "password" + @salt = "7686acb8" + @client = SRP::Client.new("testuser", "password", "7686acb8") + end + + def test_calculation_of_x + assert_equal "84d6bb567ddf584b1d8c8728289644d45dbfbb02deedd05c0f64db96740f0398", + "%x" % @client.send(:calculate_x) + end + + # using python srp: + # s,V = pysrp.create_salted_verification_key("testuser", "password", pysrp.SHA256, pysrp.NG_1024) + + def test_verifier + s = '4c78c3f8' + v = '474c26aa42d11f20544a00f7bf9711c4b5cf7aab95ed448df82b95521b96668e7480b16efce81c861870302560ddf6604c67df54f1d04b99d5bb9d0f02c6051ada5dc9d594f0d4314e12f876cfca3dcd99fc9c98c2e6a5e04298b11061fb8549a22cde0564e91514080df79bca1c38c682214d65d590f66b3719f954b078b83c' + @client = SRP::Client.new(@login, @password, s) + assert_equal v, "%x" % @client.verifier + end +end + + + diff --git a/test/util_test.rb b/test/util_test.rb new file mode 100644 index 0000000..9b1d09b --- /dev/null +++ b/test/util_test.rb @@ -0,0 +1,33 @@ +require File.expand_path(File.dirname(__FILE__) + '/test_helper') + +class UtilTest < Test::Unit::TestCase + + include SRP::Util + + # comparing to the hash created with python srp lib to make sure + # we use the same constants and hash the same way. + def test_sha256_of_prime + n = BIG_PRIME_N + nhex = '%x' % [n] + assert_equal "494b6a801b379f37c9ee25d5db7cd70ffcfe53d01b7c9e4470eaca46bda24b39", + sha256_hex(nhex) + end + + def test_hashing + x = sha256_str("testuser:password") + assert_equal 'a5376a27a385bcd791d76cbd6484e1bde130129210e4647a4583e49f45de107f', + x + end + + def test_packing_hex_to_byte_string + shex = "7686acb8" + assert_equal [118, 134, 172, 184].pack('C*'), [shex].pack('H*') + end + + def test_multiplier + # >>> "%x" % pysrp.H(sha, N, g) + assert_equal 'bf66c44a428916cad64aa7c679f3fd897ad4c375e9bbb4cbf2f5de241d618ef0', + "%x" % multiplier + end + +end -- cgit v1.2.3