()
| 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 | } |
no test coverage detected