disable some logging
This commit is contained in:
parent
7b00432c7b
commit
b6f8fff01e
6 changed files with 28 additions and 50 deletions
|
|
@ -1,11 +1,7 @@
|
|||
const JWT = require('jsonwebtoken')
|
||||
const constants = require('./constants')
|
||||
const fs = require('fs')
|
||||
const { decode } = require('jwt-simple')
|
||||
// import jwt from 'jwt-simple';
|
||||
// const jwt = require('jwt-simple')
|
||||
|
||||
// 💗 web archive
|
||||
// Refer to the docs:
|
||||
// https://web.archive.org/web/20180917171505if_/https://confluence.yawk.at/display/PEPROTOCOL/Game+Packets#GamePackets-Login
|
||||
|
||||
function mcPubKeyToPem(mcPubKeyBuffer) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
module.exports = {
|
||||
PUBLIC_KEY: 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE8ELkixyLcwlZryUQcu1TvPOmI2B7vX83ndnWRUaXm74wFfa5f/lwQNTfrLVHa2PmenpGI6JhIMUJaWZrjmMj90NoKNFSNBuKdm8rYiXsfaz3K36x/1U26HpG0ZxK/V1V',
|
||||
secret_key: 'nwOn35gXIfEfgZPIrjNJ+cAxODD/XIpjs3YG7FO1pmwbzpRSlac',
|
||||
PUBLIC_KEY: 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE8ELkixyLcwlZryUQcu1TvPOmI2B7vX83ndnWRUaXm74wFfa5f/lwQNTfrLVHa2PmenpGI6JhIMUJaWZrjmMj90NoKNFSNBuKdm8rYiXsfaz3K36x/1U26HpG0ZxK/V1V'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,10 @@ function Encrypt(client, server, options) {
|
|||
const secretHash = crypto.createHash('sha256')
|
||||
secretHash.update(SALT)
|
||||
secretHash.update(client.sharedSecret)
|
||||
console.log('---- SHARED SECRET', client.sharedSecret)
|
||||
|
||||
console.log('[encrypt] Shared secret', client.sharedSecret)
|
||||
|
||||
client.secretKeyBytes = secretHash.digest()
|
||||
console.log('Hash', client.secretKeyBytes)
|
||||
console.log('[encrypt] Shared hash', client.secretKeyBytes)
|
||||
const x509 = writeX509PublicKey(alice.getPublicKey())
|
||||
const token = JWT.sign({
|
||||
salt: toBase64(SALT),
|
||||
|
|
@ -54,7 +53,7 @@ function Encrypt(client, server, options) {
|
|||
}
|
||||
|
||||
function startServerboundEncryption(token) {
|
||||
console.warn('Starting serverbound encryption', token)
|
||||
console.warn('[encrypt] Starting serverbound encryption', token)
|
||||
const jwt = token?.token
|
||||
if (!jwt) {
|
||||
// TODO: allow connecting to servers without encryption
|
||||
|
|
@ -67,7 +66,7 @@ function Encrypt(client, server, options) {
|
|||
const body = JSON.parse(String(payload))
|
||||
const serverPublicKey = readX509PublicKey(head.x5u)
|
||||
client.sharedSecret = alice.computeSecret(serverPublicKey)
|
||||
console.log('------ SHARED SECRET', client.sharedSecret)
|
||||
console.log('[encrypt] Shared secret', client.sharedSecret)
|
||||
|
||||
const salt = Buffer.from(body.salt, 'base64')
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ function Encrypt(client, server, options) {
|
|||
secretHash.update(client.sharedSecret)
|
||||
|
||||
client.secretKeyBytes = secretHash.digest()
|
||||
console.log('Hash', client.secretKeyBytes)
|
||||
console.log('[encrypt] Shared hash', client.secretKeyBytes)
|
||||
const initial = client.secretKeyBytes.slice(0, 16)
|
||||
client.startEncryption(initial)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Client extends Connection {
|
|||
}
|
||||
|
||||
onEncapsulated = (encapsulated, inetAddr) => {
|
||||
log(inetAddr.address, ': Encapsulated', encapsulated)
|
||||
// log(inetAddr.address, ': Encapsulated', encapsulated)
|
||||
const buffer = encapsulated.buffer
|
||||
this.handle(buffer)
|
||||
}
|
||||
|
|
@ -102,9 +102,11 @@ class Client extends Connection {
|
|||
}
|
||||
|
||||
readPacket(packet) {
|
||||
console.log('packet', packet)
|
||||
// console.log('packet', packet)
|
||||
const des = this.deserializer.parsePacketBuffer(packet)
|
||||
console.info('->', des)
|
||||
console.log('->',des)
|
||||
const pakData = { name: des.data.name, params: des.data.params }
|
||||
// console.info('->', JSON.stringify(pakData, (k,v) => typeof v == 'bigint' ? v.toString() : v))
|
||||
switch (des.data.name) {
|
||||
case 'server_to_client_handshake':
|
||||
this.emit('client.server_handshake', des.data.params)
|
||||
|
|
@ -118,7 +120,7 @@ class Client extends Connection {
|
|||
case 'start_game':
|
||||
fs.writeFileSync('start_game.json', JSON.stringify(des.data.params, (k,v) => typeof v == 'bigint' ? v.toString() : v))
|
||||
default:
|
||||
console.log('Sending to listeners')
|
||||
// console.log('Sending to listeners')
|
||||
}
|
||||
this.emit(des.data.name, des.data.params)
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class Connection extends EventEmitter {
|
|||
handle(buffer) { // handle encapsulated
|
||||
if (buffer[0] == 0xfe) { // wrapper
|
||||
if (this.encryptionEnabled) {
|
||||
// console.log('READING ENCRYPTED PACKET', buffer)
|
||||
console.log('Reading encrypted packet', buffer)
|
||||
this.decrypt(buffer.slice(1))
|
||||
} else {
|
||||
const stream = new BinaryStream(buffer)
|
||||
|
|
@ -100,6 +100,7 @@ class Connection extends EventEmitter {
|
|||
}
|
||||
}
|
||||
}
|
||||
console.log('[client] procesed ', buffer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,47 +126,28 @@ function createDecryptor(client, iv) {
|
|||
// console.log(computedCheckSum2, computedCheckSum3)
|
||||
console.assert(checksum.toString("hex") == computedCheckSum.toString("hex"), 'checksum mismatch')
|
||||
client.receiveCounter++
|
||||
// if (checksum.toString("hex") == computedCheckSum.toString("hex")) {
|
||||
this.push(packet)
|
||||
// console.log('🔵 Decriphered', checksum)
|
||||
|
||||
// const inflated = Zlib.inflateRawSync(chunk, {
|
||||
// chunkSize: 1024 * 1024 * 2
|
||||
// })
|
||||
// console.log('🔵 Inflated')
|
||||
// client.onDecryptedPacket(inflated)
|
||||
// } else {
|
||||
// // console.log('🔴 Not OK')
|
||||
// throw Error(`Checksum mismatch ${checksum.toString("hex")} != ${computedCheckSum.toString("hex")}`)
|
||||
// }
|
||||
cb()
|
||||
}
|
||||
})
|
||||
|
||||
const inflator = new Transform({
|
||||
transform(chunk, enc, cb) {
|
||||
console.log('🔵 Inflating')
|
||||
const inflated = Zlib.inflateRawSync(chunk, {
|
||||
chunkSize: 1024 * 1024 * 2
|
||||
})
|
||||
console.log('🔵 Inflated')
|
||||
this.push(inflated)
|
||||
cb()
|
||||
|
||||
// Zlib.inflateRaw(chunk, { chunkSize: 1024 * 1024 * 2 }, (err, buf) => {
|
||||
// console.log('🔵 INF')
|
||||
// if (err) throw err
|
||||
// this.push(buf)
|
||||
// cb()
|
||||
// })
|
||||
if (checksum.toString("hex") == computedCheckSum.toString("hex")) {
|
||||
this.push(packet)
|
||||
console.log('🔵 Decriphered', checksum)
|
||||
|
||||
console.log('🔵 Inflated')
|
||||
client.onDecryptedPacket(inflated)
|
||||
} else {
|
||||
console.log(`🔴 Checksum mismatch ${checksum.toString("hex")} != ${computedCheckSum.toString("hex")}`)
|
||||
client.onDecryptedPacket(inflated) // allow it anyway
|
||||
// throw Error(`Checksum mismatch ${checksum.toString("hex")} != ${computedCheckSum.toString("hex")}`)
|
||||
}
|
||||
cb()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
client.decipher.pipe(verifyChecksum)
|
||||
.pipe(inflator)
|
||||
// .pipe(Zlib.createInflateRaw({ chunkSize: 1024 * 1024 * 2 }))
|
||||
.on('data', (...args) => client.onDecryptedPacket(...args))
|
||||
// .on('end', () => console.log('Decryptor: finish pipeline'))
|
||||
|
||||
// Not sure why, but sending two packets to the decryption pipe before
|
||||
// the other is completed breaks the checksum check.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue