From 7bc90da59974d99f9a1272ac378f925cb5894ac2 Mon Sep 17 00:00:00 2001 From: Cal Henderson Date: Wed, 1 Sep 2010 19:44:22 -0500 Subject: [PATCH] cleanup and more tests --- lib/mysql/auth.js | 9 +++++---- test/fixture/libmysql_password.c | 15 ++++++--------- test/simple/test-auth-old.js | 14 +++++++++++--- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/mysql/auth.js b/lib/mysql/auth.js index 27a7be726..f8f47e2dd 100644 --- a/lib/mysql/auth.js +++ b/lib/mysql/auth.js @@ -94,18 +94,19 @@ exports.scramble323 = function(message, password) { var hash_pass = this.hashPassword(password); var hash_message = this.hashPassword(message.slice(0, 8)); -console.log(hash_pass); -console.log(hash_message); var seed1 = this.int32Read(hash_pass, 0) ^ this.int32Read(hash_message, 0); var seed2 = this.int32Read(hash_pass, 4) ^ this.int32Read(hash_message, 4); var r = this.randomInit(seed1, seed2); -console.log(r); - for (var i=0; i<8; i++){ to[i] = Math.floor(this.myRnd(r)*31) + 64; } + var extra = (Math.floor(this.myRnd(r)*31)); + + for (var i=0; i<8; i++){ + to[i] ^= extra; + } return to; }; diff --git a/test/fixture/libmysql_password.c b/test/fixture/libmysql_password.c index 9c26d0ca8..3e19c83eb 100644 --- a/test/fixture/libmysql_password.c +++ b/test/fixture/libmysql_password.c @@ -60,16 +60,8 @@ void scramble_323(char *to, const char *message, const char *password) const char *message_end= message + SCRAMBLE_LENGTH_323; hash_password(hash_pass,password, (uint) strlen(password)); hash_password(hash_message, message, SCRAMBLE_LENGTH_323); - -printf("hash_pass = %08x%08x\n", hash_pass[0], hash_pass[1]); -printf("hash_message = %08x%08x\n", hash_message[0], hash_message[1]); - randominit(&rand_st,hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1]); - -printf("rs.seed1: %d\n", rand_st.seed1); -printf("rs.seed2: %d\n", rand_st.seed2); - for (; message < message_end; message++) *to++= (char) (floor(my_rnd(&rand_st)*31)+64); extra=(char) (floor(my_rnd(&rand_st)*31)); @@ -123,7 +115,12 @@ int main() { // test scramble_323 scramble_323(scrm, "8bytesofstuff", "root"); - printf("scramble: %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]); + printf("scramble323(8bytesofstuff, root): %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", + scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]); + + scramble_323(scrm, "e8cf00cec9ec825af22", "saf789yasfbsd"); + printf("scramble323(e8cf00cec9ec825af22, saf789yasfbsd): %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", + scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]); return 23; } diff --git a/test/simple/test-auth-old.js b/test/simple/test-auth-old.js index a383a1c54..6c26e1bd4 100644 --- a/test/simple/test-auth-old.js +++ b/test/simple/test-auth-old.js @@ -40,6 +40,15 @@ function test_myrnd_sequence(seed1, seed2, expected){ } } +function test_scramble323(message, password, bytes){ + var expected = new Buffer(bytes); + var actual = auth.scramble323(new Buffer(message), password); + + sys.print('test_scramble323('+message+', '+password+')...'); + assert.deepEqual(actual, expected); + sys.print('ok\n'); +} + test_hash_password('root', [0x67, 0x45, 0x7E, 0x22, 0x6a, 0x1a, 0x15, 0xbd]); test_hash_password('long password test', [0x6c, 0x24, 0x68, 0x41, 0x2c, 0xa6, 0x86, 0x56]); test_hash_password('saf789yasfbsd89f', [0x6c, 0x9b, 0x2f, 0x07, 0x17, 0xeb, 0x95, 0xc6]); @@ -63,6 +72,5 @@ test_myrnd_sequence(3252345, 7149734, [ 0.9215386229767824, ]); - -var b = auth.scramble323(new Buffer("8bytesofstuff"), "root"); -console.log(b); +test_scramble323("8bytesofstuff", "root", [0x5a, 0x4d, 0x46, 0x47, 0x43, 0x53, 0x58, 0x5f]); +test_scramble323("e8cf00cec9ec825af22", "saf789yasfbsd", [0x4d, 0x54, 0x5b, 0x47, 0x5f, 0x52, 0x4d, 0x45]);