-
-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cleanup buffer/string conversions in hashing/xor helpers that w…
…ere failing in Bun
- Loading branch information
Showing
6 changed files
with
17 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,24 +17,24 @@ const STATE_FINAL = -1; | |
|
||
function sha256(msg) { | ||
const hash = crypto.createHash('sha256'); | ||
hash.update(msg, 'binary'); | ||
return hash.digest('binary'); | ||
hash.update(msg); | ||
return hash.digest(); | ||
} | ||
|
||
function calculateToken(password, scramble) { | ||
if (!password) { | ||
return Buffer.alloc(0); | ||
} | ||
const stage1 = sha256(Buffer.from(password, 'utf8').toString('binary')); | ||
const stage1 = sha256(Buffer.from(password)); | ||
const stage2 = sha256(stage1); | ||
const stage3 = sha256(stage2 + scramble.toString('binary')); | ||
const stage3 = sha256(Buffer.concat([stage2, scramble])); | ||
return xor(stage1, stage3); | ||
} | ||
|
||
function encrypt(password, scramble, key) { | ||
const stage1 = xorRotating( | ||
Buffer.from(`${password}\0`, 'utf8').toString('binary'), | ||
scramble.toString('binary') | ||
Buffer.from(`${password}\0`, 'utf8'), | ||
scramble | ||
); | ||
return crypto.publicEncrypt(key, stage1); | ||
} | ||
|
@@ -86,6 +86,7 @@ module.exports = (pluginOptions = {}) => ({ connection }) => { | |
`Invalid AuthMoreData packet received by ${PLUGIN_NAME} plugin in STATE_TOKEN_SENT state.` | ||
); | ||
case STATE_WAIT_SERVER_KEY: | ||
console.log('Server pub key:', data); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sidorares
Author
Owner
|
||
if (pluginOptions.onServerPublicKey) { | ||
pluginOptions.onServerPublicKey(data); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,13 @@ | ||
'use strict'; | ||
|
||
console.log('Hello from bun test', typeof Bun); | ||
|
||
const assert = require('assert'); | ||
const common = require('../../common'); | ||
|
||
console.log('after import'); | ||
|
||
const connection = common.createConnection(); | ||
connection.on('connect', function(hello) { | ||
console.log('connect', hello.serverVersion, hello.protocolVersion); | ||
}) | ||
console.log('after create connection'); | ||
//const assert = require('assert'); | ||
connection.query('SELECT 1', (err, _rows, _fields) => { | ||
console.log('query callback', err, _rows, _fields); | ||
connection.end(); | ||
console.log('after end connection'); | ||
}); | ||
|
||
|
||
/* | ||
|
||
let rows = undefined; | ||
let fields = undefined; | ||
connection.query('SELECT 1', (err, _rows, _fields) => { | ||
if (err) { | ||
throw err; | ||
} | ||
rows = _rows; | ||
fields = _fields; | ||
connection.end(); | ||
}); | ||
process.on('exit', () => { | ||
connection.query('SELECT 1', (err, rows, fields) => { | ||
console.log('query callback', err, rows, fields); | ||
assert.ifError(err); | ||
assert.deepEqual(rows, [{ 1: 1 }]); | ||
assert.equal(fields[0].name, '1'); | ||
}); | ||
*/ | ||
connection.end(); | ||
}); |
@sidorares
is this console.log intentional?