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

Function updateAndValidateChat

src/client/chat.js:81–107  ·  view source on GitHub ↗
(uuid, previousSignature, currentSignature, payload)

Source from the content-addressed store, hash-verified

79 }
80
81 function updateAndValidateChat (uuid, previousSignature, currentSignature, payload) {
82 // Get the player information
83 const player = client._players[uuid]
84 if (player && player.hasChainIntegrity) {
85 if (!player.lastSignature) {
86 // First time client is handling a chat message from this player, allow
87 player.lastSignature = currentSignature
88 } else if (player.lastSignature.equals(previousSignature)) {
89 player.lastSignature = currentSignature
90 } else {
91 // Not valid, client can no longer authenticate messages until player quits and reconnects
92 player.hasChainIntegrity = false
93 }
94
95 if (player.hasChainIntegrity) {
96 const verifier = crypto.createVerify('RSA-SHA256')
97 if (previousSignature) verifier.update(previousSignature)
98 verifier.update(concat('UUID', uuid))
99 verifier.update(payload)
100 player.hasChainIntegrity = verifier.verify(player.publicKey, currentSignature)
101 }
102
103 return player.hasChainIntegrity
104 }
105
106 return false
107 }
108
109 client.on('player_remove', (packet) => {
110 for (const player of packet.players) {

Callers 1

chat.jsFile · 0.85

Calls 1

concatFunction · 0.85

Tested by

no test coverage detected