UNPKG

netkitty

Version:
340 lines (339 loc) 16.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TLS_Handshake = 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 = {})); var HandshakeType; (function (HandshakeType) { HandshakeType["Handshake_1"] = "HelloRequest"; HandshakeType["Handshake_2"] = "ClientHello"; HandshakeType["Handshake_3"] = "ServerHello"; HandshakeType["Handshake_4"] = "NewSessionTicket"; HandshakeType["Handshake_5"] = "EncryptedExtensions"; HandshakeType["Handshake_6"] = "Certificate"; HandshakeType["Handshake_7"] = "ServerKeyExchange"; HandshakeType["Handshake_8"] = "CertificateRequest"; HandshakeType["Handshake_9"] = "ServerHelloDone"; HandshakeType["Handshake_10"] = "CertificateVerify"; HandshakeType["Handshake_11"] = "ClientKeyExchange"; HandshakeType["Handshake_12"] = "Finished"; })(HandshakeType || (HandshakeType = {})); class TLS_Handshake 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); } }, handshakeType: { type: 'string', label: 'Handshake Type', minimum: 0, maximum: 65535, decode: () => { const handshakeType = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1)); switch (handshakeType) { case 0: { this.instance.handshakeType.setValue(HandshakeType.Handshake_1); } break; case 1: { this.instance.handshakeType.setValue(HandshakeType.Handshake_2); } break; case 2: { this.instance.handshakeType.setValue(HandshakeType.Handshake_3); } break; case 4: { this.instance.handshakeType.setValue(HandshakeType.Handshake_4); } break; case 8: { this.instance.handshakeType.setValue(HandshakeType.Handshake_5); } break; case 11: { this.instance.handshakeType.setValue(HandshakeType.Handshake_6); } break; case 12: { this.instance.handshakeType.setValue(HandshakeType.Handshake_7); } break; case 13: { this.instance.handshakeType.setValue(HandshakeType.Handshake_8); } break; case 14: { this.instance.handshakeType.setValue(HandshakeType.Handshake_9); } break; case 15: { this.instance.handshakeType.setValue(HandshakeType.Handshake_10); } break; case 16: { this.instance.handshakeType.setValue(HandshakeType.Handshake_11); } break; case 20: { this.instance.handshakeType.setValue(HandshakeType.Handshake_12); } break; default: { this.instance.handshakeType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1))); } } }, encode: () => { const handshakeType = this.instance.handshakeType.getValue('0'); switch (handshakeType) { case HandshakeType.Handshake_1: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(0); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_2: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(1); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_3: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(2); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_4: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(4); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_5: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(8); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_6: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(11); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_7: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(12); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_8: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(13); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_9: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(14); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_10: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(15); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_11: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(16); this.writeBytes(5, handshakeType); } break; case HandshakeType.Handshake_12: { const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(20); this.writeBytes(5, handshakeType); } break; default: { const handshakeType1 = parseInt(handshakeType); this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(handshakeType1)); } } } }, handshakeLength: { type: 'integer', label: 'Length', minimum: 0, maximum: 1118481, decode: () => { this.instance.handshakeLength.setValue((0, BufferToNumber_1.BufferToUInt32)(this.readBytes(6, 3))); }, encode: () => { const length1 = (this.instance.handshakeLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'))); const length2 = length1.toString(16).padStart(6, '0'); const length3 = (0, HexToBuffer_1.HexToBuffer)(length2); this.writeBytes(6, length3); } }, messagedata: { type: 'string', label: 'Messagedata', decode: () => { const length = (this.instance.handshakeLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'))); this.instance.messagedata.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(9, length))); }, encode: () => { const message = (0, HexToBuffer_1.HexToBuffer)(this.instance.messagedata.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'))); this.writeBytes(9, message); } } } }; this.id = 'tls-handshake'; this.name = 'Transport Layer Security(Handshake Protocol)'; this.nickname = 'TLS-Handshake'; } match() { if (!this.prevCodecModule) return false; if ((0, BufferToHex_1.BufferToHex)(this.readBytes(0, 1)) != '16') 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_Handshake = TLS_Handshake;