MCPcopy Create free account
hub / github.com/PrismarineJS/node-minecraft-protocol / validateSession

Function validateSession

src/server/chat.js:60–78  ·  view source on GitHub ↗
(packet)

Source from the content-addressed store, hash-verified

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 = {

Callers 1

chat.jsFile · 0.85

Calls 4

concatFunction · 0.85
VerificationErrorClass · 0.85
unwrapMethod · 0.80
raiseFunction · 0.70

Tested by

no test coverage detected