@@ -17,24 +17,24 @@ const STATE_FINAL = -1;
1717
1818function sha256 ( msg ) {
1919 const hash = crypto . createHash ( 'sha256' ) ;
20- hash . update ( msg , 'binary' ) ;
21- return hash . digest ( 'binary' ) ;
20+ hash . update ( msg ) ;
21+ return hash . digest ( ) ;
2222}
2323
2424function calculateToken ( password , scramble ) {
2525 if ( ! password ) {
2626 return Buffer . alloc ( 0 ) ;
2727 }
28- const stage1 = sha256 ( Buffer . from ( password , 'utf8' ) . toString ( 'binary' ) ) ;
28+ const stage1 = sha256 ( Buffer . from ( password ) ) ;
2929 const stage2 = sha256 ( stage1 ) ;
30- const stage3 = sha256 ( stage2 + scramble . toString ( 'binary' ) ) ;
30+ const stage3 = sha256 ( Buffer . concat ( [ stage2 , scramble ] ) ) ;
3131 return xor ( stage1 , stage3 ) ;
3232}
3333
3434function encrypt ( password , scramble , key ) {
3535 const stage1 = xorRotating (
36- Buffer . from ( `${ password } \0` , 'utf8' ) . toString ( 'binary' ) ,
37- scramble . toString ( 'binary' )
36+ Buffer . from ( `${ password } \0` , 'utf8' ) ,
37+ scramble
3838 ) ;
3939 return crypto . publicEncrypt ( key , stage1 ) ;
4040}
@@ -86,6 +86,7 @@ module.exports = (pluginOptions = {}) => ({ connection }) => {
8686 `Invalid AuthMoreData packet received by ${ PLUGIN_NAME } plugin in STATE_TOKEN_SENT state.`
8787 ) ;
8888 case STATE_WAIT_SERVER_KEY :
89+ console . log ( 'Server pub key:' , data ) ;
8990 if ( pluginOptions . onServerPublicKey ) {
9091 pluginOptions . onServerPublicKey ( data ) ;
9192 }
0 commit comments