Remove old tests, lint tests

This commit is contained in:
extremeheat 2021-03-23 01:07:26 -04:00
commit 184de537f5
7 changed files with 3 additions and 419 deletions

View file

@ -1 +0,0 @@
test/

4
.gitignore vendored
View file

@ -4,10 +4,8 @@ package-lock.json
__*
src/**/*.json
# Runtime generated data
data/*/sample
data/**/sample
data/**/read.js
data/**/write.js
data/**/size.js
samples/*.txt
samples/*.json
tools/bds*

View file

@ -1,33 +0,0 @@
const crypto=require("crypto");
const assert=require("assert");
const bufferEqual=require("buffer-equal");
function writeLI64(value, buffer, offset) {
buffer.writeInt32LE(value[0], offset+4);
buffer.writeInt32LE(value[1], offset);
return offset + 8;
}
// based on https://s.yawk.at/QADm and https://confluence.yawk.at/display/PEPROTOCOL/Encryption
describe("checksum",() => {
it("generate hash and checksum",() => {
let packetPlaintext = new Buffer("3C00000008","hex");
let sendCounter = [0,1];
let secretKeyBytes = new Buffer("ZOBpyzki/M8UZv5tiBih048eYOBVPkQE3r5Fl0gmUP4=","base64");
/////
let digest = crypto.createHash('sha256');
// sendCounter to little-endian byte array
let counter=new Buffer(8);
writeLI64(sendCounter,counter,0);
digest.update(counter);
digest.update(packetPlaintext);
digest.update(secretKeyBytes);
let hash = digest.digest();
assert(bufferEqual(hash, new Buffer("WkRtEcDHqlqesU6wdSnIz7cU3OCNKVMIsX3aXZMLRjQ=","base64")),hash.toString("base64"));
let checksum = hash.slice(0,8);
assert(bufferEqual(checksum, new Buffer("5A446D11C0C7AA5A","hex")));
})
});

View file

@ -1,41 +0,0 @@
const crypto=require("crypto");
const assert=require("assert");
const bufferEqual=require("buffer-equal");
// based on https://s.yawk.at/8W5U and https://confluence.yawk.at/display/PEPROTOCOL/Encryption
describe("decryption",() => {
let decipher;
before(() => {
let secretKeyBytes = new Buffer("ZOBpyzki/M8UZv5tiBih048eYOBVPkQE3r5Fl0gmUP4=","base64");
/////
let iv = secretKeyBytes.slice(0,16);
assert(bufferEqual(iv, new Buffer("ZOBpyzki/M8UZv5tiBih0w==","base64")));
decipher = crypto.createDecipheriv('aes-256-cfb8', secretKeyBytes, iv);
});
it("decrypt 1",cb => {
let packet1Encrypted = new Buffer("4B4FCA0C2A4114155D67F8092154AAA5EF","hex");
decipher.once('data', packet1Decrypted => {
assert(bufferEqual(packet1Decrypted, new Buffer("0400000000499602D2FC2FCB233F34D5DD", "hex")));
cb();
});
decipher.write(packet1Encrypted);
});
it("decrypt 2",cb => {
let packet2Encrypted = new Buffer("DF53B9764DB48252FA1AE3AEE4","hex");
decipher.once('data', packet2Decrypted => {
assert(bufferEqual(packet2Decrypted,new Buffer("3C000000085A446D11C0C7AA5A","hex")));
cb();
});
decipher.write(packet2Encrypted);
})
});

View file

@ -1,43 +0,0 @@
const crypto=require("crypto");
var Ber = require('asn1').Ber;
const assert=require("assert");
const bufferEqual=require("buffer-equal");
// based on https://s.yawk.at/VZSf and https://confluence.yawk.at/display/PEPROTOCOL/Encryption
// and https://github.com/PrismarineJS/bedrock-protocol/issues/15
describe("ecdh key exchange",() => {
it("generate the secret",() => {
const pubKeyStr = "MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEDEKneqEvcqUqqFMM1HM1A4zWjJC+I8Y+aKzG5dl+6wNOHHQ4NmG2PEXRJYhujyodFH+wO0dEr4GM1WoaWog8xsYQ6mQJAC0eVpBM96spUB1eMN56+BwlJ4H3Qx4TAvAs";
var reader = new Ber.Reader(new Buffer(pubKeyStr, "base64"));
reader.readSequence();
reader.readSequence();
reader.readOID(); // Hey, I'm an elliptic curve
reader.readOID(); // This contains the curve type, could be useful
// The first byte is unused, it contains the "number of unused bits in last octet"
// The pubKey should start at "04" which signifies it is an "uncompressed" public key.
var pubKey = new Buffer(reader.readString(Ber.BitString, true)).slice(1);
// It'd be better to get this from the curve type OID
var server = crypto.createECDH('secp384r1');
//server.generateKeys();
server.setPrivateKey("oH53xXsdMRt6VbjlUUggn/QTcUQUqOHcvHl+U1jaGAUe8TP9H3XdKeoqSAKrKBGG", "base64");
let secret = server.computeSecret(pubKey);
assert(bufferEqual(secret, new Buffer("sM5HvG6efG0RwRe7S+Er9ingxuVzC6HIXmQ1DITVkh4GmX7pboSzbLtaTTNKE8bJ", "base64")));
});
it("create the secret key",() => {
let secret=new Buffer("sM5HvG6efG0RwRe7S+Er9ingxuVzC6HIXmQ1DITVkh4GmX7pboSzbLtaTTNKE8bJ", "base64");
let hash = crypto.createHash('sha256');
hash.update("SO SECRET VERY SECURE");
hash.update(secret);
let secretKey = hash.digest();
let expected=new Buffer("PN/4NCtRswMTwfpOKRecbMncwxa91Fx4QSUlad46jrc","base64");
assert(bufferEqual(secretKey,expected),secretKey.toString("base64")+"!="+expected.toString("base64"));
})
});

File diff suppressed because one or more lines are too long

View file

@ -3,7 +3,7 @@
const { clientTest } = require('./vanilla')
const { Versions } = require('../src/options')
describe ('vanilla server test', function () {
describe('vanilla server test', function () {
this.timeout(120 * 1000)
for (const version in Versions) {
@ -11,4 +11,4 @@ describe ('vanilla server test', function () {
await clientTest(version)
})
}
})
})