(packet)
| 58 | } |
| 59 | |
| 60 | function validateSession (packet) { |
| 61 | try { |
| 62 | const unwrapped = pending.unwrap(packet.offset, packet.acknowledged) |
| 63 | |
| 64 | const length = Buffer.byteLength(packet.message, 'utf8') |
| 65 | const acknowledgements = unwrapped.length > 0 ? ['i32', unwrapped.length, 'buffer', Buffer.concat(...unwrapped)] : ['i32', 0] |
| 66 | |
| 67 | const signable = concat('i32', 1, 'UUID', client.uuid, 'UUID', client._session.uuid, 'i32', client._session.index++, 'i64', packet.salt, 'i64', packet.timestamp / 1000n, 'i32', length, 'pstring', packet.message, ...acknowledgements) |
| 68 | const valid = crypto.verify('RSA-SHA256', signable, client.profileKeys.public, packet.signature) |
| 69 | if (!valid) throw VerificationError('Invalid or missing message signature') |
| 70 | } catch (e) { |
| 71 | if (e instanceof VerificationError) { |
| 72 | raise('multiplayer.disconnect.chat_validation_failed') |
| 73 | if (!options.hideErrors) console.error(client.address, 'disconnected because', e) |
| 74 | } else { |
| 75 | client.emit('error', e) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | client.on('chat_session_update', (packet) => { |
| 81 | client._session = { |
no test coverage detected