knxultimate
Version:
KNX IP protocol implementation for Node. This is the ENGINE of Node-Red KNX-Ultimate node.
50 lines • 2.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const KNXPacket_1 = __importDefault(require("./KNXPacket"));
const HPAI_1 = __importDefault(require("./HPAI"));
const CRIFactory_1 = __importDefault(require("./CRIFactory"));
const KNXConstants_1 = require("./KNXConstants");
const Curve25519_1 = require("../Curve25519");
class KNXSecureSessionRequest extends KNXPacket_1.default {
constructor(cri, hpaiData = HPAI_1.default.NULLHPAI, _jKNXSecureKeyring = {}) {
super(KNXConstants_1.KNX_CONSTANTS.SECURE_SESSION_REQUEST, hpaiData.length + 32);
this._jKNXSecureKeyring = _jKNXSecureKeyring;
this.cri = cri;
this.hpaiData = hpaiData;
this.diffieHellmanClientPublicValue = Buffer.alloc(32).toString();
let authenticationPassword = _jKNXSecureKeyring.Devices[0].authenticationPassword;
authenticationPassword =
authenticationPassword.length === 0
? '00000000000000000000000000000000'
: authenticationPassword;
let _key = authenticationPassword;
_key += new Array(32 + 1 - _key.length).join('\0');
const authenticationPasswordHEX = Buffer.from(_key).toString('hex');
const authenticationPasswordUint8Array = Uint8Array.from(Buffer.from(authenticationPasswordHEX, 'hex'));
const secret = (0, Curve25519_1.generateKeyPair)(authenticationPasswordUint8Array);
this.diffieHellmanClientPublicValue = Buffer.from(secret.public).toString('hex');
}
static createFromBuffer(buffer, offset = 0) {
if (offset >= buffer.length) {
throw new Error('Buffer too short');
}
const hpaiControl = HPAI_1.default.createFromBuffer(buffer, offset);
offset += hpaiControl.length;
const hpaiData = HPAI_1.default.createFromBuffer(buffer, offset);
offset += hpaiData.length;
const cri = CRIFactory_1.default.createFromBuffer(buffer, offset);
return new KNXSecureSessionRequest(cri, hpaiControl, hpaiData);
}
toBuffer() {
return Buffer.concat([
this.header.toBuffer(),
this.hpaiData.toBuffer(),
Buffer.from(this.diffieHellmanClientPublicValue, 'hex'),
]);
}
}
exports.default = KNXSecureSessionRequest;
//# sourceMappingURL=KNXSecureSessionRequest.js.map