mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 10:55:05 -05:00
Merge cd8f06e3ee
into 590dc33fed
This commit is contained in:
commit
ffad0afbd0
1 changed files with 6 additions and 9 deletions
|
@ -7,6 +7,7 @@ const chatPlugin = require('./chat')
|
|||
const { concat } = require('../transforms/binaryStream')
|
||||
const { mojangPublicKeyPem } = require('./constants')
|
||||
const debug = require('debug')('minecraft-protocol')
|
||||
const NodeRSA = require('node-rsa')
|
||||
|
||||
module.exports = function (client, server, options) {
|
||||
const mojangPubKey = crypto.createPublicKey(mojangPublicKeyPem)
|
||||
|
@ -106,6 +107,9 @@ module.exports = function (client, server, options) {
|
|||
}
|
||||
}
|
||||
|
||||
const keyRsa = new NodeRSA(server.serverKey.exportKey('pkcs1'), 'private', { encryptionScheme: 'pkcs1' })
|
||||
keyRsa.setOptions({ environment: 'browser' })
|
||||
|
||||
if (packet.hasVerifyToken === false) {
|
||||
// 1.19, hasVerifyToken is set and equal to false IF chat signing is enabled
|
||||
// This is the default action starting in 1.19.1.
|
||||
|
@ -117,10 +121,7 @@ module.exports = function (client, server, options) {
|
|||
} else {
|
||||
const encryptedToken = packet.hasVerifyToken ? packet.crypto.verifyToken : packet.verifyToken
|
||||
try {
|
||||
const decryptedToken = crypto.privateDecrypt({
|
||||
key: server.serverKey.exportKey(),
|
||||
padding: crypto.constants.RSA_PKCS1_PADDING
|
||||
}, encryptedToken)
|
||||
const decryptedToken = keyRsa.decrypt(encryptedToken)
|
||||
|
||||
if (!client.verifyToken.equals(decryptedToken)) {
|
||||
client.end('DidNotEncryptVerifyTokenProperly')
|
||||
|
@ -131,13 +132,9 @@ module.exports = function (client, server, options) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
let sharedSecret
|
||||
try {
|
||||
sharedSecret = crypto.privateDecrypt({
|
||||
key: server.serverKey.exportKey(),
|
||||
padding: crypto.constants.RSA_PKCS1_PADDING
|
||||
}, packet.sharedSecret)
|
||||
sharedSecret = keyRsa.decrypt(packet.sharedSecret)
|
||||
} catch (e) {
|
||||
client.end('DidNotEncryptVerifyTokenProperly')
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue