netkitty
Version:
Network tools kit
625 lines (624 loc) • 31.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TLS_Alert = void 0;
const BaseHeader_1 = require("../abstracts/BaseHeader");
const BufferToNumber_1 = require("../../helper/BufferToNumber");
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 = {}));
var Description_type;
(function (Description_type) {
Description_type["code_0"] = "Close notify";
Description_type["code_10"] = "Unexpected message";
Description_type["code_20"] = "Bad record MAC";
Description_type["code_21"] = "Decryption failed";
Description_type["code_22"] = "Record overflow";
Description_type["code_30"] = "Decompression failure";
Description_type["code_40"] = "Handshake failure";
Description_type["code_41"] = "No certificate";
Description_type["code_42"] = "Bad certificate";
Description_type["code_43"] = "Unsupported certificate";
Description_type["code_44"] = "Certificate revoked";
Description_type["code_45"] = "Certificate expired";
Description_type["code_46"] = "Certificate unknown";
Description_type["code_47"] = "Illegal parameter";
Description_type["code_48"] = "Unknown CA (Certificate authority)";
Description_type["code_49"] = "Access denied";
Description_type["code_50"] = "Decode error";
Description_type["code_51"] = "Decrypt error";
Description_type["code_60"] = "Export restriction";
Description_type["code_70"] = "Protocol version";
Description_type["code_71"] = "Insufficient security";
Description_type["code_80"] = "Internal error";
Description_type["code_86"] = "Inappropriate fallback";
Description_type["code_90"] = "User canceled";
Description_type["code_100"] = "No renegotiation";
Description_type["code_110"] = "Unsupported extension";
Description_type["code_111"] = "Certificate unobtainable";
Description_type["code_112"] = "Unrecognized name";
Description_type["code_113"] = "Bad certificate status response";
Description_type["code_114"] = "Bad certificate hash value\t ";
Description_type["code_115"] = "Unknown PSK identity (used in TLS-PSK and TLS-SRP)";
Description_type["code_116"] = "Certificate required";
Description_type["code_120"] = "No application protocol";
Description_type["code_255"] = "No application protocol";
})(Description_type || (Description_type = {}));
class TLS_Alert extends BaseHeader_1.BaseHeader {
constructor() {
super(...arguments);
this.SCHEMA = {
type: 'object',
properties: {
contentType: {
type: 'integer',
label: 'Content Type',
minimum: 0,
maximum: 65535,
decode: () => {
this.instance.contentType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
},
encode: () => {
const contentTyppe = this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(contentTyppe));
}
},
version: {
type: 'string',
label: 'Legacy Version',
minimum: 0,
maximum: 65535,
decode: () => {
this.instance.version.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2)));
const version = this.instance.version.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
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: 'Legacy Version',
minimum: 0,
maximum: 255,
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);
}
},
levelType: {
type: 'string',
label: 'Alert Level Type ',
minimum: 0,
maximum: 255,
decode: () => {
this.instance.levelType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1)));
const type = this.instance.levelType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
switch (type) {
case 1:
{
this.instance.levelType.setValue('Warning');
}
break;
case 2:
{
this.instance.levelType.setValue('Fatal');
}
break;
default: {
this.instance.levelType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1)));
}
}
},
encode: () => {
const type = this.instance.levelType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
switch (type) {
case 'Warning':
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(1);
this.writeBytes(5, type);
}
break;
case 'Fatal':
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(2);
this.writeBytes(5, type);
}
break;
default: {
const type1 = parseInt(type, 10);
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(type1));
}
}
}
},
descriptionType: {
type: 'string',
label: 'Alert Description Types',
minimum: 0,
maximum: 255,
decode: () => {
this.instance.descriptionType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(6, 1)));
const type = this.instance.descriptionType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
switch (type) {
case 0:
{
this.instance.descriptionType.setValue(Description_type.code_0);
}
break;
case 10:
{
this.instance.descriptionType.setValue(Description_type.code_10);
}
break;
case 20:
{
this.instance.descriptionType.setValue(Description_type.code_20);
}
break;
case 21:
{
this.instance.descriptionType.setValue(Description_type.code_21);
}
break;
case 22:
{
this.instance.descriptionType.setValue(Description_type.code_22);
}
break;
case 30:
{
this.instance.descriptionType.setValue(Description_type.code_30);
}
break;
case 40:
{
this.instance.descriptionType.setValue(Description_type.code_40);
}
break;
case 41:
{
this.instance.descriptionType.setValue(Description_type.code_41);
}
break;
case 42:
{
this.instance.descriptionType.setValue(Description_type.code_42);
}
break;
case 43:
{
this.instance.descriptionType.setValue(Description_type.code_43);
}
break;
case 44:
{
this.instance.descriptionType.setValue(Description_type.code_44);
}
break;
case 45:
{
this.instance.descriptionType.setValue(Description_type.code_45);
}
break;
case 46:
{
this.instance.descriptionType.setValue(Description_type.code_46);
}
break;
case 47:
{
this.instance.descriptionType.setValue(Description_type.code_47);
}
break;
case 48:
{
this.instance.descriptionType.setValue(Description_type.code_48);
}
break;
case 49:
{
this.instance.descriptionType.setValue(Description_type.code_49);
}
break;
case 50:
{
this.instance.descriptionType.setValue(Description_type.code_50);
}
break;
case 51:
{
this.instance.descriptionType.setValue(Description_type.code_51);
}
break;
case 60:
{
this.instance.descriptionType.setValue(Description_type.code_60);
}
break;
case 70:
{
this.instance.descriptionType.setValue(Description_type.code_70);
}
break;
case 71:
{
this.instance.descriptionType.setValue(Description_type.code_71);
}
break;
case 80:
{
this.instance.descriptionType.setValue(Description_type.code_80);
}
break;
case 86:
{
this.instance.descriptionType.setValue(Description_type.code_86);
}
break;
case 90:
{
this.instance.descriptionType.setValue(Description_type.code_90);
}
break;
case 100:
{
this.instance.descriptionType.setValue(Description_type.code_100);
}
break;
case 110:
{
this.instance.descriptionType.setValue(Description_type.code_110);
}
break;
case 111:
{
this.instance.descriptionType.setValue(Description_type.code_111);
}
break;
case 112:
{
this.instance.descriptionType.setValue(Description_type.code_112);
}
break;
case 113:
{
this.instance.descriptionType.setValue(Description_type.code_113);
}
break;
case 114:
{
this.instance.descriptionType.setValue(Description_type.code_114);
}
break;
case 115:
{
this.instance.descriptionType.setValue(Description_type.code_115);
}
break;
case 116:
{
this.instance.descriptionType.setValue(Description_type.code_116);
}
break;
case 120:
{
this.instance.descriptionType.setValue(Description_type.code_120);
}
break;
case 255:
{
this.instance.descriptionType.setValue(Description_type.code_255);
}
break;
default: {
this.instance.descriptionType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(6, 1)));
}
}
},
encode: () => {
const type = this.instance.descriptionType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
switch (type) {
case Description_type.code_0:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(0);
this.writeBytes(6, type);
}
break;
case Description_type.code_10:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(10);
this.writeBytes(6, type);
}
break;
case Description_type.code_20:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(20);
this.writeBytes(6, type);
}
break;
case Description_type.code_21:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(21);
this.writeBytes(6, type);
}
break;
case Description_type.code_22:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(22);
this.writeBytes(6, type);
}
break;
case Description_type.code_30:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(30);
this.writeBytes(6, type);
}
break;
case Description_type.code_40:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(40);
this.writeBytes(6, type);
}
break;
case Description_type.code_41:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(41);
this.writeBytes(6, type);
}
break;
case Description_type.code_42:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(42);
this.writeBytes(6, type);
}
break;
case Description_type.code_43:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(43);
this.writeBytes(6, type);
}
break;
case Description_type.code_44:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(44);
this.writeBytes(6, type);
}
break;
case Description_type.code_45:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(45);
this.writeBytes(6, type);
}
break;
case Description_type.code_46:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(46);
this.writeBytes(6, type);
}
break;
case Description_type.code_47:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(47);
this.writeBytes(6, type);
}
break;
case Description_type.code_48:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(48);
this.writeBytes(6, type);
}
break;
case Description_type.code_49:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(49);
this.writeBytes(6, type);
}
break;
case Description_type.code_50:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(50);
this.writeBytes(6, type);
}
break;
case Description_type.code_51:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(51);
this.writeBytes(6, type);
}
break;
case Description_type.code_60:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(60);
this.writeBytes(6, type);
}
break;
case Description_type.code_70:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(70);
this.writeBytes(6, type);
}
break;
case Description_type.code_71:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(71);
this.writeBytes(6, type);
}
break;
case Description_type.code_80:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(80);
this.writeBytes(6, type);
}
break;
case Description_type.code_86:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(86);
this.writeBytes(6, type);
}
break;
case Description_type.code_90:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(90);
this.writeBytes(6, type);
}
break;
case Description_type.code_100:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(100);
this.writeBytes(6, type);
}
break;
case Description_type.code_110:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(110);
this.writeBytes(6, type);
}
break;
case Description_type.code_111:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(111);
this.writeBytes(6, type);
}
break;
case Description_type.code_112:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(112);
this.writeBytes(6, type);
}
break;
case Description_type.code_113:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(113);
this.writeBytes(6, type);
}
break;
case Description_type.code_114:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(114);
this.writeBytes(6, type);
}
break;
case Description_type.code_115:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(115);
this.writeBytes(6, type);
}
break;
case Description_type.code_116:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(116);
this.writeBytes(6, type);
}
break;
case Description_type.code_120:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(120);
this.writeBytes(6, type);
}
break;
case Description_type.code_255:
{
const type = (0, NumberToBuffer_1.UInt8ToBuffer)(255);
this.writeBytes(6, type);
}
break;
default: {
const type1 = parseInt(type, 10);
const type2 = (0, NumberToBuffer_1.UInt8ToBuffer)(type1);
this.writeBytes(6, type2);
}
}
}
}
}
};
this.id = 'tls-alert';
this.name = 'Transport Layer Security(Alert Protocol)';
this.nickname = 'TLS-Alert';
}
match() {
if (!this.prevCodecModule)
return false;
const type = (0, BufferToNumber_1.BufferToInt8)(this.readBytes(0, 1));
if (type != 21)
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_Alert = TLS_Alert;