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

Function sendEncryptionKeyResponse

src/client/encrypt.js:45–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43 }
44
45 function sendEncryptionKeyResponse () {
46 const mcData = require('minecraft-data')(client.version)
47
48 const pubKey = mcPubKeyToPem(packet.publicKey)
49 const encryptedSharedSecretBuffer = crypto.publicEncrypt({ key: pubKey, padding: crypto.constants.RSA_PKCS1_PADDING }, sharedSecret)
50 const encryptedVerifyTokenBuffer = crypto.publicEncrypt({ key: pubKey, padding: crypto.constants.RSA_PKCS1_PADDING }, packet.verifyToken)
51
52 if (mcData.supportFeature('signatureEncryption')) {
53 const salt = BigInt(Date.now())
54 client.write('encryption_begin', {
55 sharedSecret: encryptedSharedSecretBuffer,
56 hasVerifyToken: client.profileKeys == null,
57 crypto: client.profileKeys
58 ? {
59 salt,
60 messageSignature: crypto.sign('sha256WithRSAEncryption',
61 concat('buffer', packet.verifyToken, 'i64', salt), client.profileKeys.private)
62 }
63 : {
64 verifyToken: encryptedVerifyTokenBuffer
65 }
66 })
67 } else {
68 client.write('encryption_begin', {
69 sharedSecret: encryptedSharedSecretBuffer,
70 verifyToken: encryptedVerifyTokenBuffer
71 })
72 }
73 client.setEncryption(sharedSecret)
74 }
75 }
76 }
77}

Callers 2

gotSharedSecretFunction · 0.85
onJoinServerResponseFunction · 0.85

Calls 4

concatFunction · 0.85
writeMethod · 0.80
setEncryptionMethod · 0.80
mcPubKeyToPemFunction · 0.70

Tested by

no test coverage detected