mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
uses node-rsa instead of keypair
package is a bit bigger but still pure js same package used by ursa purejs
This commit is contained in:
parent
01c3c95cb4
commit
80f103d2f0
2 changed files with 7 additions and 7 deletions
|
@ -39,10 +39,10 @@
|
||||||
"buffer-equal": "^1.0.0",
|
"buffer-equal": "^1.0.0",
|
||||||
"debug": "^2.2.0",
|
"debug": "^2.2.0",
|
||||||
"endian-toggle": "^0.0.0",
|
"endian-toggle": "^0.0.0",
|
||||||
"keypair": "^1.0.1",
|
|
||||||
"lodash.get": "^4.1.2",
|
"lodash.get": "^4.1.2",
|
||||||
"lodash.merge": "^4.3.0",
|
"lodash.merge": "^4.3.0",
|
||||||
"minecraft-data": "^2.17.0",
|
"minecraft-data": "^2.17.0",
|
||||||
|
"node-rsa": "^0.4.2",
|
||||||
"prismarine-nbt": "^1.0.0",
|
"prismarine-nbt": "^1.0.0",
|
||||||
"protodef": "^1.5.1",
|
"protodef": "^1.5.1",
|
||||||
"readable-stream": "^2.0.5",
|
"readable-stream": "^2.0.5",
|
||||||
|
|
|
@ -8,7 +8,7 @@ const Server = require('./server');
|
||||||
const UUID = require('uuid-1345');
|
const UUID = require('uuid-1345');
|
||||||
const endianToggle = require('endian-toggle');
|
const endianToggle = require('endian-toggle');
|
||||||
const pluginChannels = require('./client/pluginChannels');
|
const pluginChannels = require('./client/pluginChannels');
|
||||||
const keypair = require('keypair');
|
const NodeRSA = require('node-rsa');
|
||||||
|
|
||||||
module.exports=createServer;
|
module.exports=createServer;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ function createServer(options) {
|
||||||
const mcData=require("minecraft-data")(optVersion);
|
const mcData=require("minecraft-data")(optVersion);
|
||||||
const version = mcData.version;
|
const version = mcData.version;
|
||||||
|
|
||||||
const serverKey = keypair({bits:1024});
|
const serverKey = new NodeRSA({b: 1024});
|
||||||
|
|
||||||
const server = new Server(version.minecraftVersion,options.customPackets);
|
const server = new Server(version.minecraftVersion,options.customPackets);
|
||||||
server.motd = options.motd || "A Minecraft server";
|
server.motd = options.motd || "A Minecraft server";
|
||||||
|
@ -175,9 +175,9 @@ function createServer(options) {
|
||||||
if(needToVerify) {
|
if(needToVerify) {
|
||||||
serverId = crypto.randomBytes(4).toString('hex');
|
serverId = crypto.randomBytes(4).toString('hex');
|
||||||
client.verifyToken = crypto.randomBytes(4);
|
client.verifyToken = crypto.randomBytes(4);
|
||||||
const publicKeyStrArr = serverKey.public.split("\n");
|
const publicKeyStrArr = serverKey.exportKey('pkcs8-public-pem').split("\n");
|
||||||
let publicKeyStr = "";
|
let publicKeyStr = "";
|
||||||
for(let i = 1; i < publicKeyStrArr.length - 2; i++) {
|
for(let i = 1; i < publicKeyStrArr.length - 1; i++) {
|
||||||
publicKeyStr += publicKeyStrArr[i]
|
publicKeyStr += publicKeyStrArr[i]
|
||||||
}
|
}
|
||||||
client.publicKey = new Buffer(publicKeyStr, 'base64');
|
client.publicKey = new Buffer(publicKeyStr, 'base64');
|
||||||
|
@ -210,12 +210,12 @@ function createServer(options) {
|
||||||
function onEncryptionKeyResponse(packet) {
|
function onEncryptionKeyResponse(packet) {
|
||||||
let sharedSecret;
|
let sharedSecret;
|
||||||
try {
|
try {
|
||||||
const verifyToken = crypto.privateDecrypt({key:serverKey.private,padding:crypto.constants.RSA_PKCS1_PADDING},packet.verifyToken);
|
const verifyToken = crypto.privateDecrypt({key:serverKey.exportKey(),padding:crypto.constants.RSA_PKCS1_PADDING},packet.verifyToken);
|
||||||
if(!bufferEqual(client.verifyToken, verifyToken)) {
|
if(!bufferEqual(client.verifyToken, verifyToken)) {
|
||||||
client.end('DidNotEncryptVerifyTokenProperly');
|
client.end('DidNotEncryptVerifyTokenProperly');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sharedSecret = crypto.privateDecrypt({key:serverKey.private,padding:crypto.constants.RSA_PKCS1_PADDING},packet.sharedSecret);
|
sharedSecret = crypto.privateDecrypt({key:serverKey.exportKey(),padding:crypto.constants.RSA_PKCS1_PADDING},packet.sharedSecret);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
client.end('DidNotEncryptVerifyTokenProperly');
|
client.end('DidNotEncryptVerifyTokenProperly');
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue