Skip to content

Commit

Permalink
cleanup and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcal authored and felixge committed Sep 2, 2010
1 parent f920b2b commit 7bc90da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
9 changes: 5 additions & 4 deletions lib/mysql/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
15 changes: 6 additions & 9 deletions test/fixture/libmysql_password.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 11 additions & 3 deletions test/simple/test-auth-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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]);

0 comments on commit 7bc90da

Please sign in to comment.