netkitty
Version:
Network tools kit
207 lines (206 loc) • 9.72 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TLS_Heartbeat = void 0;
const BaseHeader_1 = require("../abstracts/BaseHeader");
const BufferToNumber_1 = require("../../helper/BufferToNumber");
const HexToBuffer_1 = require("../../helper/HexToBuffer");
const BufferToHex_1 = require("../../helper/BufferToHex");
const NumberToBuffer_1 = require("../../helper/NumberToBuffer");
var TLSver;
(function (TLSver) {
TLSver["SSL_3_0"] = "SSL3.0";
TLSver["TLS_1_0"] = "TLS1.0";
TLSver["TLS_1_1"] = "TLS1.1";
TLSver["TLS_1_2"] = "TLS1.2";
TLSver["TLS_1_3"] = "TLS1.3";
})(TLSver || (TLSver = {}));
class TLS_Heartbeat extends BaseHeader_1.BaseHeader {
constructor() {
super(...arguments);
this.SCHEMA = {
type: 'object',
properties: {
contentType: {
type: 'integer',
label: 'Content Type',
minimum: 0,
maximum: 255,
decode: () => {
this.instance.contentType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
},
encode: () => {
const contentType = this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(contentType));
}
},
version: {
type: 'string',
label: 'Version',
minimum: 0,
maximum: 65535,
decode: () => {
const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2));
switch (version) {
case 768:
{
this.instance.version.setValue(TLSver.SSL_3_0);
}
break;
case 769:
{
this.instance.version.setValue(TLSver.TLS_1_0);
}
break;
case 770:
{
this.instance.version.setValue(TLSver.TLS_1_1);
}
break;
case 771:
{
this.instance.version.setValue(TLSver.TLS_1_2);
}
break;
case 772:
{
this.instance.version.setValue(TLSver.TLS_1_3);
}
break;
default: {
this.instance.version.setValue(0);
}
}
},
encode: () => {
const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
switch (version) {
case TLSver.SSL_3_0:
{
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(768));
}
break;
case TLSver.TLS_1_0:
{
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(769));
}
break;
case TLSver.TLS_1_1:
{
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(770));
}
break;
case TLSver.TLS_1_2:
{
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(771));
}
break;
case TLSver.TLS_1_3:
{
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(772));
}
break;
default: {
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
}
}
}
},
length: {
type: 'integer',
label: 'Length',
minimum: 0,
maximum: 65535,
decode: () => {
this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(3, 2)));
},
encode: () => {
const length = this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
}
},
heartbeatType: {
type: 'string',
label: 'Heartbeat Type',
minimum: 0,
maximum: 255,
decode: () => {
const heartbeatType = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1));
switch (heartbeatType) {
case 1:
{
this.instance.heartbeatType.setValue('HeartbeatRequest');
}
break;
case 2:
{
this.instance.heartbeatType.setValue('HeartbeatResponse');
}
break;
default: {
this.instance.heartbeatType.setValue(heartbeatType);
}
}
},
encode: () => {
const heartbeatType = this.instance.heartbeatType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
switch (heartbeatType) {
case 'HeartbeatRequest':
{
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(1));
}
break;
case 'HeartbeatResponse':
{
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(2));
}
break;
default: {
const heartbeatType1 = parseInt(heartbeatType);
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(heartbeatType1));
}
}
}
},
payloadLength: {
type: 'integer',
label: 'Payload Length',
minimum: 0,
maximum: 65535,
decode: () => {
this.instance.payloadLength.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(6, 2)));
},
encode: () => {
const payloadLength = this.instance.payloadLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.writeBytes(6, (0, NumberToBuffer_1.UInt16ToBuffer)(payloadLength));
}
},
payloadMessage: {
type: 'string',
label: 'Payload Message',
decode: () => {
const payloadLength = this.instance.payloadLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
const payloadMessage = (0, BufferToHex_1.BufferToHex)(this.readBytes(8, payloadLength));
this.instance.payloadMessage.setValue(payloadMessage);
},
encode: () => {
const payloadMessage = this.instance.payloadMessage.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
this.writeBytes(8, (0, HexToBuffer_1.HexToBuffer)(payloadMessage));
}
}
}
};
this.id = 'tls-heartbeat';
this.name = 'Transport Layer Security(Heartbeat Protocol)';
this.nickname = 'TLS-Heartbeat';
}
match() {
if (!this.prevCodecModule)
return false;
if ((0, BufferToHex_1.BufferToHex)(this.readBytes(0, 1)) != '18')
return false;
const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2));
const validVersions = [768, 769, 770, 771, 772];
return validVersions.includes(version);
}
}
exports.TLS_Heartbeat = TLS_Heartbeat;