netkitty
Version:
Network tools kit
155 lines (154 loc) • 7.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TLS_ChangeCipherSpec = void 0;
const BaseHeader_1 = require("../abstracts/BaseHeader");
const BufferToNumber_1 = require("../../helper/BufferToNumber");
const BufferToHex_1 = require("../../helper/BufferToHex");
const NumberToBuffer_1 = require("../../helper/NumberToBuffer");
const HexToBuffer_1 = require("../../helper/HexToBuffer");
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_ChangeCipherSpec 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.BufferToInt8)(this.readBytes(0, 1)));
},
encode: () => {
const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
this.writeBytes(0, contentType);
}
},
version: {
type: 'string',
label: 'Legacy 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:
{
const version = (0, NumberToBuffer_1.UInt16ToBuffer)(768);
this.writeBytes(1, version);
}
break;
case TLSver.TLS_1_0:
{
const version = (0, NumberToBuffer_1.UInt16ToBuffer)(769);
this.writeBytes(1, version);
}
break;
case TLSver.TLS_1_1:
{
const version = (0, NumberToBuffer_1.UInt16ToBuffer)(770);
this.writeBytes(1, version);
}
break;
case TLSver.TLS_1_2:
{
const version = (0, NumberToBuffer_1.UInt16ToBuffer)(771);
this.writeBytes(1, version);
}
break;
case TLSver.TLS_1_3:
{
const version = (0, NumberToBuffer_1.UInt16ToBuffer)(772);
this.writeBytes(1, version);
}
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 = (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
this.writeBytes(3, length);
}
},
change_cipher_spec_message: {
type: 'string',
label: 'Change Cipher Spec Message',
decode: () => {
const length = this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
this.instance.change_cipher_spec_message.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(5, length)));
},
encode: () => {
const message = (0, HexToBuffer_1.HexToBuffer)(this.instance.change_cipher_spec_message.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found')));
this.writeBytes(5, message);
}
}
}
};
this.id = 'tls-ccsp';
this.name = 'Transport Layer Security(ChangeCipherSpec Protocol)';
this.nickname = 'TLS-ChangeCipherSpec';
}
match() {
if (!this.prevCodecModule)
return false;
if ((0, BufferToHex_1.BufferToHex)(this.readBytes(0, 1)) != '14')
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_ChangeCipherSpec = TLS_ChangeCipherSpec;