@@ -17,24 +17,24 @@ const STATE_FINAL = -1;
17
17
18
18
function sha256 ( msg ) {
19
19
const hash = crypto . createHash ( 'sha256' ) ;
20
- hash . update ( msg , 'binary' ) ;
21
- return hash . digest ( 'binary' ) ;
20
+ hash . update ( msg ) ;
21
+ return hash . digest ( ) ;
22
22
}
23
23
24
24
function calculateToken ( password , scramble ) {
25
25
if ( ! password ) {
26
26
return Buffer . alloc ( 0 ) ;
27
27
}
28
- const stage1 = sha256 ( Buffer . from ( password , 'utf8' ) . toString ( 'binary' ) ) ;
28
+ const stage1 = sha256 ( Buffer . from ( password ) ) ;
29
29
const stage2 = sha256 ( stage1 ) ;
30
- const stage3 = sha256 ( stage2 + scramble . toString ( 'binary' ) ) ;
30
+ const stage3 = sha256 ( Buffer . concat ( [ stage2 , scramble ] ) ) ;
31
31
return xor ( stage1 , stage3 ) ;
32
32
}
33
33
34
34
function encrypt ( password , scramble , key ) {
35
35
const stage1 = xorRotating (
36
- Buffer . from ( `${ password } \0` , 'utf8' ) . toString ( 'binary' ) ,
37
- scramble . toString ( 'binary' )
36
+ Buffer . from ( `${ password } \0` , 'utf8' ) ,
37
+ scramble
38
38
) ;
39
39
return crypto . publicEncrypt ( key , stage1 ) ;
40
40
}
@@ -86,6 +86,7 @@ module.exports = (pluginOptions = {}) => ({ connection }) => {
86
86
`Invalid AuthMoreData packet received by ${ PLUGIN_NAME } plugin in STATE_TOKEN_SENT state.`
87
87
) ;
88
88
case STATE_WAIT_SERVER_KEY :
89
+ console . log ( 'Server pub key:' , data ) ;
89
90
if ( pluginOptions . onServerPublicKey ) {
90
91
pluginOptions . onServerPublicKey ( data ) ;
91
92
}
0 commit comments