Skip to content

Commit fb9eae1

Browse files
fix: fix sha256_password to work correctly over a TLS connection (#3809)
* fix: handle case with sha256_authentication over tls connection * fix: lint * fix: ensure tls over the stream instance * fix: variable name --------- Co-authored-by: Weslley Araújo <[email protected]>
1 parent 234901d commit fb9eae1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/auth_plugins/sha256_password.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const PLUGIN_NAME = 'sha256_password';
44
const crypto = require('crypto');
55
const { xorRotating } = require('../auth_41');
6+
const Tls = require('tls');
67

78
const REQUEST_SERVER_KEY_PACKET = Buffer.from([1]);
89

@@ -32,6 +33,14 @@ module.exports =
3233
return (data) => {
3334
switch (state) {
3435
case STATE_INITIAL:
36+
if (
37+
connection.stream instanceof Tls.TLSSocket &&
38+
connection.stream.encrypted === true
39+
) {
40+
// We don't need to encrypt passwords over TLS connection
41+
return Buffer.from(`${password}\0`, 'utf8');
42+
}
43+
3544
scramble = data.slice(0, 20);
3645
// if client provides key we can save one extra roundrip on first connection
3746
if (pluginOptions.serverPublicKey) {

0 commit comments

Comments
 (0)