@netkitty/codec 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +352 -0
  4. package/README.zh-CN.md +342 -0
  5. package/dist/Codec.d.ts +133 -0
  6. package/dist/Codec.js +632 -0
  7. package/dist/PacketHeaders.d.ts +189 -0
  8. package/dist/PacketHeaders.js +384 -0
  9. package/dist/abstracts/BaseHeader.d.ts +325 -0
  10. package/dist/abstracts/BaseHeader.js +734 -0
  11. package/dist/errors/CodecSchemaValidateError.d.ts +4 -0
  12. package/dist/errors/CodecSchemaValidateError.js +11 -0
  13. package/dist/headers/ADSAMS.d.ts +33 -0
  14. package/dist/headers/ADSAMS.js +208 -0
  15. package/dist/headers/AH.d.ts +28 -0
  16. package/dist/headers/AH.js +137 -0
  17. package/dist/headers/AMQP.d.ts +31 -0
  18. package/dist/headers/AMQP.js +316 -0
  19. package/dist/headers/ARP.d.ts +26 -0
  20. package/dist/headers/ARP.js +243 -0
  21. package/dist/headers/BACnetIP.d.ts +27 -0
  22. package/dist/headers/BACnetIP.js +97 -0
  23. package/dist/headers/BFD.d.ts +28 -0
  24. package/dist/headers/BFD.js +155 -0
  25. package/dist/headers/BGP.d.ts +27 -0
  26. package/dist/headers/BGP.js +111 -0
  27. package/dist/headers/BSAPIP.d.ts +33 -0
  28. package/dist/headers/BSAPIP.js +78 -0
  29. package/dist/headers/Babel.d.ts +32 -0
  30. package/dist/headers/Babel.js +224 -0
  31. package/dist/headers/BitTorrent.d.ts +28 -0
  32. package/dist/headers/BitTorrent.js +72 -0
  33. package/dist/headers/C37118.d.ts +26 -0
  34. package/dist/headers/C37118.js +147 -0
  35. package/dist/headers/CAPWAP.d.ts +38 -0
  36. package/dist/headers/CAPWAP.js +275 -0
  37. package/dist/headers/CDP.d.ts +25 -0
  38. package/dist/headers/CDP.js +117 -0
  39. package/dist/headers/CMS.d.ts +33 -0
  40. package/dist/headers/CMS.js +238 -0
  41. package/dist/headers/COTP.d.ts +30 -0
  42. package/dist/headers/COTP.js +193 -0
  43. package/dist/headers/CassandraCQL.d.ts +28 -0
  44. package/dist/headers/CassandraCQL.js +117 -0
  45. package/dist/headers/CoAP.d.ts +29 -0
  46. package/dist/headers/CoAP.js +140 -0
  47. package/dist/headers/Codesys.d.ts +32 -0
  48. package/dist/headers/Codesys.js +119 -0
  49. package/dist/headers/Collectd.d.ts +29 -0
  50. package/dist/headers/Collectd.js +154 -0
  51. package/dist/headers/DCCP.d.ts +30 -0
  52. package/dist/headers/DCCP.js +204 -0
  53. package/dist/headers/DHCP.d.ts +26 -0
  54. package/dist/headers/DHCP.js +148 -0
  55. package/dist/headers/DHCPFailover.d.ts +30 -0
  56. package/dist/headers/DHCPFailover.js +104 -0
  57. package/dist/headers/DHCPv6.d.ts +25 -0
  58. package/dist/headers/DHCPv6.js +145 -0
  59. package/dist/headers/DNP3.d.ts +27 -0
  60. package/dist/headers/DNP3.js +150 -0
  61. package/dist/headers/DNS.d.ts +55 -0
  62. package/dist/headers/DNS.js +309 -0
  63. package/dist/headers/DTLS.d.ts +33 -0
  64. package/dist/headers/DTLS.js +142 -0
  65. package/dist/headers/Diameter.d.ts +34 -0
  66. package/dist/headers/Diameter.js +229 -0
  67. package/dist/headers/EAPOL.d.ts +32 -0
  68. package/dist/headers/EAPOL.js +135 -0
  69. package/dist/headers/EIGRP.d.ts +28 -0
  70. package/dist/headers/EIGRP.js +165 -0
  71. package/dist/headers/ENIP.d.ts +31 -0
  72. package/dist/headers/ENIP.js +164 -0
  73. package/dist/headers/ESP.d.ts +27 -0
  74. package/dist/headers/ESP.js +140 -0
  75. package/dist/headers/Elasticsearch.d.ts +30 -0
  76. package/dist/headers/Elasticsearch.js +125 -0
  77. package/dist/headers/EtherCAT.d.ts +35 -0
  78. package/dist/headers/EtherCAT.js +150 -0
  79. package/dist/headers/EthernetII.d.ts +28 -0
  80. package/dist/headers/EthernetII.js +117 -0
  81. package/dist/headers/FCoE.d.ts +38 -0
  82. package/dist/headers/FCoE.js +210 -0
  83. package/dist/headers/FTP.d.ts +34 -0
  84. package/dist/headers/FTP.js +158 -0
  85. package/dist/headers/Finger.d.ts +41 -0
  86. package/dist/headers/Finger.js +135 -0
  87. package/dist/headers/FoundationFieldbusHSE.d.ts +43 -0
  88. package/dist/headers/FoundationFieldbusHSE.js +163 -0
  89. package/dist/headers/GELF.d.ts +35 -0
  90. package/dist/headers/GELF.js +261 -0
  91. package/dist/headers/GENEVE.d.ts +26 -0
  92. package/dist/headers/GENEVE.js +209 -0
  93. package/dist/headers/GESRTP.d.ts +32 -0
  94. package/dist/headers/GESRTP.js +141 -0
  95. package/dist/headers/GLBP.d.ts +29 -0
  96. package/dist/headers/GLBP.js +159 -0
  97. package/dist/headers/GRE.d.ts +27 -0
  98. package/dist/headers/GRE.js +181 -0
  99. package/dist/headers/GTPU.d.ts +25 -0
  100. package/dist/headers/GTPU.js +203 -0
  101. package/dist/headers/GTPv2C.d.ts +30 -0
  102. package/dist/headers/GTPv2C.js +281 -0
  103. package/dist/headers/GitProtocol.d.ts +34 -0
  104. package/dist/headers/GitProtocol.js +141 -0
  105. package/dist/headers/Goose.d.ts +115 -0
  106. package/dist/headers/Goose.js +1067 -0
  107. package/dist/headers/Gopher.d.ts +43 -0
  108. package/dist/headers/Gopher.js +182 -0
  109. package/dist/headers/HARTIP.d.ts +30 -0
  110. package/dist/headers/HARTIP.js +145 -0
  111. package/dist/headers/HSR.d.ts +27 -0
  112. package/dist/headers/HSR.js +105 -0
  113. package/dist/headers/HSRP.d.ts +26 -0
  114. package/dist/headers/HSRP.js +173 -0
  115. package/dist/headers/HTTP.d.ts +32 -0
  116. package/dist/headers/HTTP.js +153 -0
  117. package/dist/headers/HTTP2.d.ts +34 -0
  118. package/dist/headers/HTTP2.js +190 -0
  119. package/dist/headers/IAX2.d.ts +33 -0
  120. package/dist/headers/IAX2.js +274 -0
  121. package/dist/headers/ICMP.d.ts +15 -0
  122. package/dist/headers/ICMP.js +148 -0
  123. package/dist/headers/ICMPv6.d.ts +15 -0
  124. package/dist/headers/ICMPv6.js +129 -0
  125. package/dist/headers/IEC104_I_Frame.d.ts +23 -0
  126. package/dist/headers/IEC104_I_Frame.js +6489 -0
  127. package/dist/headers/IEC104_S_Frame.d.ts +26 -0
  128. package/dist/headers/IEC104_S_Frame.js +135 -0
  129. package/dist/headers/IEC104_U_Frame.d.ts +27 -0
  130. package/dist/headers/IEC104_U_Frame.js +176 -0
  131. package/dist/headers/IEC61850SampledValues.d.ts +20 -0
  132. package/dist/headers/IEC61850SampledValues.js +420 -0
  133. package/dist/headers/IGMP.d.ts +31 -0
  134. package/dist/headers/IGMP.js +274 -0
  135. package/dist/headers/IMAP.d.ts +32 -0
  136. package/dist/headers/IMAP.js +185 -0
  137. package/dist/headers/IPFIX.d.ts +29 -0
  138. package/dist/headers/IPFIX.js +156 -0
  139. package/dist/headers/IPv4.d.ts +20 -0
  140. package/dist/headers/IPv4.js +370 -0
  141. package/dist/headers/IPv6.d.ts +29 -0
  142. package/dist/headers/IPv6.js +209 -0
  143. package/dist/headers/IPv6HopByHopOptions.d.ts +81 -0
  144. package/dist/headers/IPv6HopByHopOptions.js +495 -0
  145. package/dist/headers/IRC.d.ts +34 -0
  146. package/dist/headers/IRC.js +175 -0
  147. package/dist/headers/ISAKMP.d.ts +29 -0
  148. package/dist/headers/ISAKMP.js +197 -0
  149. package/dist/headers/ISCSI.d.ts +39 -0
  150. package/dist/headers/ISCSI.js +289 -0
  151. package/dist/headers/ISIS.d.ts +25 -0
  152. package/dist/headers/ISIS.js +79 -0
  153. package/dist/headers/ISOSession.d.ts +27 -0
  154. package/dist/headers/ISOSession.js +343 -0
  155. package/dist/headers/Ident.d.ts +42 -0
  156. package/dist/headers/Ident.js +184 -0
  157. package/dist/headers/KNXnetIP.d.ts +30 -0
  158. package/dist/headers/KNXnetIP.js +135 -0
  159. package/dist/headers/Kafka.d.ts +35 -0
  160. package/dist/headers/Kafka.js +128 -0
  161. package/dist/headers/Kerberos.d.ts +30 -0
  162. package/dist/headers/Kerberos.js +217 -0
  163. package/dist/headers/L2TP.d.ts +26 -0
  164. package/dist/headers/L2TP.js +297 -0
  165. package/dist/headers/LACP.d.ts +31 -0
  166. package/dist/headers/LACP.js +151 -0
  167. package/dist/headers/LDAP.d.ts +31 -0
  168. package/dist/headers/LDAP.js +226 -0
  169. package/dist/headers/LDP.d.ts +31 -0
  170. package/dist/headers/LDP.js +138 -0
  171. package/dist/headers/LISP.d.ts +30 -0
  172. package/dist/headers/LISP.js +103 -0
  173. package/dist/headers/LLC.d.ts +27 -0
  174. package/dist/headers/LLC.js +81 -0
  175. package/dist/headers/LLDP.d.ts +26 -0
  176. package/dist/headers/LLDP.js +126 -0
  177. package/dist/headers/LLMNR.d.ts +23 -0
  178. package/dist/headers/LLMNR.js +40 -0
  179. package/dist/headers/LPD.d.ts +31 -0
  180. package/dist/headers/LPD.js +159 -0
  181. package/dist/headers/MACsec.d.ts +34 -0
  182. package/dist/headers/MACsec.js +178 -0
  183. package/dist/headers/MDNS.d.ts +26 -0
  184. package/dist/headers/MDNS.js +45 -0
  185. package/dist/headers/MGCP.d.ts +30 -0
  186. package/dist/headers/MGCP.js +155 -0
  187. package/dist/headers/MMS.d.ts +29 -0
  188. package/dist/headers/MMS.js +243 -0
  189. package/dist/headers/MPLS.d.ts +31 -0
  190. package/dist/headers/MPLS.js +145 -0
  191. package/dist/headers/MQTT.d.ts +30 -0
  192. package/dist/headers/MQTT.js +173 -0
  193. package/dist/headers/MQTTSN.d.ts +34 -0
  194. package/dist/headers/MQTTSN.js +177 -0
  195. package/dist/headers/MarkerProtocol.d.ts +32 -0
  196. package/dist/headers/MarkerProtocol.js +153 -0
  197. package/dist/headers/Megaco.d.ts +32 -0
  198. package/dist/headers/Megaco.js +144 -0
  199. package/dist/headers/Memcached.d.ts +44 -0
  200. package/dist/headers/Memcached.js +285 -0
  201. package/dist/headers/ModbusTCP.d.ts +25 -0
  202. package/dist/headers/ModbusTCP.js +99 -0
  203. package/dist/headers/ModbusUDP.d.ts +26 -0
  204. package/dist/headers/ModbusUDP.js +100 -0
  205. package/dist/headers/MongoDB.d.ts +33 -0
  206. package/dist/headers/MongoDB.js +143 -0
  207. package/dist/headers/MySQL.d.ts +30 -0
  208. package/dist/headers/MySQL.js +114 -0
  209. package/dist/headers/NATS.d.ts +29 -0
  210. package/dist/headers/NATS.js +135 -0
  211. package/dist/headers/NBDS.d.ts +34 -0
  212. package/dist/headers/NBDS.js +176 -0
  213. package/dist/headers/NBNS.d.ts +34 -0
  214. package/dist/headers/NBNS.js +78 -0
  215. package/dist/headers/NBSS.d.ts +36 -0
  216. package/dist/headers/NBSS.js +137 -0
  217. package/dist/headers/NFS.d.ts +36 -0
  218. package/dist/headers/NFS.js +273 -0
  219. package/dist/headers/NHRP.d.ts +32 -0
  220. package/dist/headers/NHRP.js +154 -0
  221. package/dist/headers/NNTP.d.ts +35 -0
  222. package/dist/headers/NNTP.js +162 -0
  223. package/dist/headers/NTP.d.ts +18 -0
  224. package/dist/headers/NTP.js +73 -0
  225. package/dist/headers/NetFlowV5.d.ts +28 -0
  226. package/dist/headers/NetFlowV5.js +205 -0
  227. package/dist/headers/OLSR.d.ts +31 -0
  228. package/dist/headers/OLSR.js +213 -0
  229. package/dist/headers/OPCUA.d.ts +33 -0
  230. package/dist/headers/OPCUA.js +165 -0
  231. package/dist/headers/OPCUAPubSub.d.ts +33 -0
  232. package/dist/headers/OPCUAPubSub.js +144 -0
  233. package/dist/headers/OSPF.d.ts +31 -0
  234. package/dist/headers/OSPF.js +365 -0
  235. package/dist/headers/OmronFINS.d.ts +31 -0
  236. package/dist/headers/OmronFINS.js +90 -0
  237. package/dist/headers/OpenFlow.d.ts +30 -0
  238. package/dist/headers/OpenFlow.js +113 -0
  239. package/dist/headers/OpenVPN.d.ts +35 -0
  240. package/dist/headers/OpenVPN.js +214 -0
  241. package/dist/headers/PCWorx.d.ts +35 -0
  242. package/dist/headers/PCWorx.js +115 -0
  243. package/dist/headers/PIM.d.ts +27 -0
  244. package/dist/headers/PIM.js +129 -0
  245. package/dist/headers/POP3.d.ts +31 -0
  246. package/dist/headers/POP3.js +152 -0
  247. package/dist/headers/POWERLINK.d.ts +28 -0
  248. package/dist/headers/POWERLINK.js +116 -0
  249. package/dist/headers/PPPoEDiscovery.d.ts +29 -0
  250. package/dist/headers/PPPoEDiscovery.js +198 -0
  251. package/dist/headers/PPPoESession.d.ts +28 -0
  252. package/dist/headers/PPPoESession.js +125 -0
  253. package/dist/headers/PPTP.d.ts +30 -0
  254. package/dist/headers/PPTP.js +122 -0
  255. package/dist/headers/PROFINETRT.d.ts +28 -0
  256. package/dist/headers/PROFINETRT.js +74 -0
  257. package/dist/headers/PTP.d.ts +34 -0
  258. package/dist/headers/PTP.js +213 -0
  259. package/dist/headers/PostgreSQL.d.ts +40 -0
  260. package/dist/headers/PostgreSQL.js +236 -0
  261. package/dist/headers/QUIC.d.ts +34 -0
  262. package/dist/headers/QUIC.js +308 -0
  263. package/dist/headers/RADIUS.d.ts +24 -0
  264. package/dist/headers/RADIUS.js +138 -0
  265. package/dist/headers/RDP.d.ts +27 -0
  266. package/dist/headers/RDP.js +93 -0
  267. package/dist/headers/RFB.d.ts +39 -0
  268. package/dist/headers/RFB.js +151 -0
  269. package/dist/headers/RGoose.d.ts +72 -0
  270. package/dist/headers/RGoose.js +340 -0
  271. package/dist/headers/RIP.d.ts +29 -0
  272. package/dist/headers/RIP.js +133 -0
  273. package/dist/headers/RIPng.d.ts +26 -0
  274. package/dist/headers/RIPng.js +140 -0
  275. package/dist/headers/RMCP.d.ts +26 -0
  276. package/dist/headers/RMCP.js +155 -0
  277. package/dist/headers/RSVP.d.ts +31 -0
  278. package/dist/headers/RSVP.js +263 -0
  279. package/dist/headers/RTCP.d.ts +34 -0
  280. package/dist/headers/RTCP.js +217 -0
  281. package/dist/headers/RTP.d.ts +33 -0
  282. package/dist/headers/RTP.js +291 -0
  283. package/dist/headers/RTPS.d.ts +33 -0
  284. package/dist/headers/RTPS.js +182 -0
  285. package/dist/headers/RTSP.d.ts +36 -0
  286. package/dist/headers/RTSP.js +184 -0
  287. package/dist/headers/RawData.d.ts +17 -0
  288. package/dist/headers/RawData.js +43 -0
  289. package/dist/headers/Redis.d.ts +32 -0
  290. package/dist/headers/Redis.js +202 -0
  291. package/dist/headers/Rlogin.d.ts +42 -0
  292. package/dist/headers/Rlogin.js +139 -0
  293. package/dist/headers/Rsync.d.ts +28 -0
  294. package/dist/headers/Rsync.js +117 -0
  295. package/dist/headers/S7comm.d.ts +36 -0
  296. package/dist/headers/S7comm.js +244 -0
  297. package/dist/headers/SCTP.d.ts +35 -0
  298. package/dist/headers/SCTP.js +174 -0
  299. package/dist/headers/SFlow.d.ts +29 -0
  300. package/dist/headers/SFlow.js +242 -0
  301. package/dist/headers/SIP.d.ts +27 -0
  302. package/dist/headers/SIP.js +146 -0
  303. package/dist/headers/SLMP.d.ts +36 -0
  304. package/dist/headers/SLMP.js +154 -0
  305. package/dist/headers/SLP.d.ts +30 -0
  306. package/dist/headers/SLP.js +207 -0
  307. package/dist/headers/SLPv1.d.ts +32 -0
  308. package/dist/headers/SLPv1.js +138 -0
  309. package/dist/headers/SMB1.d.ts +37 -0
  310. package/dist/headers/SMB1.js +200 -0
  311. package/dist/headers/SMB2.d.ts +36 -0
  312. package/dist/headers/SMB2.js +203 -0
  313. package/dist/headers/SMPP.d.ts +33 -0
  314. package/dist/headers/SMPP.js +119 -0
  315. package/dist/headers/SMTP.d.ts +33 -0
  316. package/dist/headers/SMTP.js +157 -0
  317. package/dist/headers/SNAP.d.ts +22 -0
  318. package/dist/headers/SNAP.js +68 -0
  319. package/dist/headers/SNMP.d.ts +28 -0
  320. package/dist/headers/SNMP.js +302 -0
  321. package/dist/headers/SOCKS4.d.ts +42 -0
  322. package/dist/headers/SOCKS4.js +302 -0
  323. package/dist/headers/SOCKS5.d.ts +45 -0
  324. package/dist/headers/SOCKS5.js +223 -0
  325. package/dist/headers/SSDP.d.ts +27 -0
  326. package/dist/headers/SSDP.js +161 -0
  327. package/dist/headers/SSH.d.ts +44 -0
  328. package/dist/headers/SSH.js +274 -0
  329. package/dist/headers/STOMP.d.ts +48 -0
  330. package/dist/headers/STOMP.js +177 -0
  331. package/dist/headers/STP.d.ts +26 -0
  332. package/dist/headers/STP.js +150 -0
  333. package/dist/headers/STUN.d.ts +25 -0
  334. package/dist/headers/STUN.js +183 -0
  335. package/dist/headers/SercosIII.d.ts +43 -0
  336. package/dist/headers/SercosIII.js +199 -0
  337. package/dist/headers/Skinny.d.ts +32 -0
  338. package/dist/headers/Skinny.js +139 -0
  339. package/dist/headers/StatsD.d.ts +27 -0
  340. package/dist/headers/StatsD.js +134 -0
  341. package/dist/headers/SunRPC.d.ts +34 -0
  342. package/dist/headers/SunRPC.js +268 -0
  343. package/dist/headers/Syslog.d.ts +21 -0
  344. package/dist/headers/Syslog.js +91 -0
  345. package/dist/headers/TCP.d.ts +19 -0
  346. package/dist/headers/TCP.js +905 -0
  347. package/dist/headers/TFTP.d.ts +28 -0
  348. package/dist/headers/TFTP.js +224 -0
  349. package/dist/headers/TLS_Alert.d.ts +24 -0
  350. package/dist/headers/TLS_Alert.js +639 -0
  351. package/dist/headers/TLS_ApplicationData.d.ts +24 -0
  352. package/dist/headers/TLS_ApplicationData.js +170 -0
  353. package/dist/headers/TLS_ChangeCipherSpec.d.ts +23 -0
  354. package/dist/headers/TLS_ChangeCipherSpec.js +168 -0
  355. package/dist/headers/TLS_Handshake.d.ts +65 -0
  356. package/dist/headers/TLS_Handshake.js +860 -0
  357. package/dist/headers/TLS_Heartbeat.d.ts +27 -0
  358. package/dist/headers/TLS_Heartbeat.js +247 -0
  359. package/dist/headers/TPKT.d.ts +26 -0
  360. package/dist/headers/TPKT.js +99 -0
  361. package/dist/headers/TacacsPlus.d.ts +27 -0
  362. package/dist/headers/TacacsPlus.js +133 -0
  363. package/dist/headers/Telnet.d.ts +40 -0
  364. package/dist/headers/Telnet.js +193 -0
  365. package/dist/headers/Teredo.d.ts +40 -0
  366. package/dist/headers/Teredo.js +251 -0
  367. package/dist/headers/TimeProtocol.d.ts +25 -0
  368. package/dist/headers/TimeProtocol.js +53 -0
  369. package/dist/headers/UDP.d.ts +19 -0
  370. package/dist/headers/UDP.js +171 -0
  371. package/dist/headers/VLAN_802dot1Q.d.ts +24 -0
  372. package/dist/headers/VLAN_802dot1Q.js +96 -0
  373. package/dist/headers/VRRP.d.ts +26 -0
  374. package/dist/headers/VRRP.js +309 -0
  375. package/dist/headers/VXLAN.d.ts +24 -0
  376. package/dist/headers/VXLAN.js +75 -0
  377. package/dist/headers/WCCP.d.ts +29 -0
  378. package/dist/headers/WCCP.js +117 -0
  379. package/dist/headers/WHOIS.d.ts +37 -0
  380. package/dist/headers/WHOIS.js +126 -0
  381. package/dist/headers/WSDiscovery.d.ts +29 -0
  382. package/dist/headers/WSDiscovery.js +118 -0
  383. package/dist/headers/WakeOnLAN.d.ts +30 -0
  384. package/dist/headers/WakeOnLAN.js +126 -0
  385. package/dist/headers/WebSocket.d.ts +26 -0
  386. package/dist/headers/WebSocket.js +173 -0
  387. package/dist/headers/WireGuard.d.ts +38 -0
  388. package/dist/headers/WireGuard.js +216 -0
  389. package/dist/headers/XMPP.d.ts +37 -0
  390. package/dist/headers/XMPP.js +149 -0
  391. package/dist/headers/Zabbix.d.ts +35 -0
  392. package/dist/headers/Zabbix.js +153 -0
  393. package/dist/headers/cms/AcsiPdu.d.ts +45 -0
  394. package/dist/headers/cms/AcsiPdu.js +112 -0
  395. package/dist/headers/cms/PerDecoder.d.ts +68 -0
  396. package/dist/headers/cms/PerDecoder.js +211 -0
  397. package/dist/headers/cms/PerReader.d.ts +64 -0
  398. package/dist/headers/cms/PerReader.js +155 -0
  399. package/dist/helper/BufferToHex.d.ts +5 -0
  400. package/dist/helper/BufferToHex.js +10 -0
  401. package/dist/helper/BufferToIP.d.ts +12 -0
  402. package/dist/helper/BufferToIP.js +23 -0
  403. package/dist/helper/BufferToNumber.d.ts +18 -0
  404. package/dist/helper/BufferToNumber.js +47 -0
  405. package/dist/helper/HexToBuffer.d.ts +7 -0
  406. package/dist/helper/HexToBuffer.js +27 -0
  407. package/dist/helper/HexToNumber.d.ts +18 -0
  408. package/dist/helper/HexToNumber.js +48 -0
  409. package/dist/helper/IPToBuffer.d.ts +12 -0
  410. package/dist/helper/IPToBuffer.js +34 -0
  411. package/dist/helper/NumberToBERBuffer.d.ts +18 -0
  412. package/dist/helper/NumberToBERBuffer.js +31 -0
  413. package/dist/helper/NumberToBERHex.d.ts +18 -0
  414. package/dist/helper/NumberToBERHex.js +52 -0
  415. package/dist/helper/NumberToBuffer.d.ts +18 -0
  416. package/dist/helper/NumberToBuffer.js +38 -0
  417. package/dist/helper/NumberToHex.d.ts +18 -0
  418. package/dist/helper/NumberToHex.js +35 -0
  419. package/dist/index.d.ts +52 -0
  420. package/dist/index.js +113 -0
  421. package/dist/lib/FlexibleObject.d.ts +27 -0
  422. package/dist/lib/FlexibleObject.js +113 -0
  423. package/dist/lib/GetBERIntegerLengthFromBuffer.d.ts +6 -0
  424. package/dist/lib/GetBERIntegerLengthFromBuffer.js +16 -0
  425. package/dist/lib/ProcessPacketPostHandlers.d.ts +13 -0
  426. package/dist/lib/ProcessPacketPostHandlers.js +53 -0
  427. package/dist/lib/SortPostHandlers.d.ts +7 -0
  428. package/dist/lib/SortPostHandlers.js +11 -0
  429. package/dist/lib/StringContentEncodingEnum.d.ts +10 -0
  430. package/dist/lib/StringContentEncodingEnum.js +14 -0
  431. package/dist/schema/ProtocolFieldJSONSchema.d.ts +35 -0
  432. package/dist/schema/ProtocolFieldJSONSchema.js +2 -0
  433. package/dist/schema/ProtocolFieldJSONSchemaDefinition.d.ts +2 -0
  434. package/dist/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
  435. package/dist/schema/ProtocolJSONSchema.d.ts +32 -0
  436. package/dist/schema/ProtocolJSONSchema.js +2 -0
  437. package/dist/types/CodecData.d.ts +7 -0
  438. package/dist/types/CodecData.js +2 -0
  439. package/dist/types/CodecDecodeResult.d.ts +10 -0
  440. package/dist/types/CodecDecodeResult.js +2 -0
  441. package/dist/types/CodecEncodeInput.d.ts +2 -0
  442. package/dist/types/CodecEncodeInput.js +2 -0
  443. package/dist/types/CodecEncodeResult.d.ts +5 -0
  444. package/dist/types/CodecEncodeResult.js +2 -0
  445. package/dist/types/CodecErrorInfo.d.ts +5 -0
  446. package/dist/types/CodecErrorInfo.js +2 -0
  447. package/dist/types/CodecModule.d.ts +2 -0
  448. package/dist/types/CodecModule.js +2 -0
  449. package/dist/types/CodecModuleConstructor.d.ts +2 -0
  450. package/dist/types/CodecModuleConstructor.js +2 -0
  451. package/dist/types/CodecSchema.d.ts +6 -0
  452. package/dist/types/CodecSchema.js +2 -0
  453. package/dist/types/DemuxProducer.d.ts +23 -0
  454. package/dist/types/DemuxProducer.js +2 -0
  455. package/dist/types/Dissection.d.ts +23 -0
  456. package/dist/types/Dissection.js +2 -0
  457. package/dist/types/HeaderTreeNode.d.ts +4 -0
  458. package/dist/types/HeaderTreeNode.js +2 -0
  459. package/dist/types/LayerGraph.d.ts +32 -0
  460. package/dist/types/LayerGraph.js +2 -0
  461. package/dist/types/PostHandlerItem.d.ts +4 -0
  462. package/dist/types/PostHandlerItem.js +2 -0
  463. package/package.json +141 -0
@@ -0,0 +1,860 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TLS_Handshake = void 0;
4
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
5
+ const BufferToNumber_1 = require("../helper/BufferToNumber");
6
+ const BufferToHex_1 = require("../helper/BufferToHex");
7
+ const NumberToBuffer_1 = require("../helper/NumberToBuffer");
8
+ const HexToBuffer_1 = require("../helper/HexToBuffer");
9
+ var TLSver;
10
+ (function (TLSver) {
11
+ TLSver["SSL_3_0"] = "SSL3.0";
12
+ TLSver["TLS_1_0"] = "TLS1.0";
13
+ TLSver["TLS_1_1"] = "TLS1.1";
14
+ TLSver["TLS_1_2"] = "TLS1.2";
15
+ TLSver["TLS_1_3"] = "TLS1.3";
16
+ })(TLSver || (TLSver = {}));
17
+ var HandshakeType;
18
+ (function (HandshakeType) {
19
+ HandshakeType["Handshake_1"] = "HelloRequest";
20
+ HandshakeType["Handshake_2"] = "ClientHello";
21
+ HandshakeType["Handshake_3"] = "ServerHello";
22
+ HandshakeType["Handshake_4"] = "NewSessionTicket";
23
+ HandshakeType["Handshake_5"] = "EncryptedExtensions";
24
+ HandshakeType["Handshake_6"] = "Certificate";
25
+ HandshakeType["Handshake_7"] = "ServerKeyExchange";
26
+ HandshakeType["Handshake_8"] = "CertificateRequest";
27
+ HandshakeType["Handshake_9"] = "ServerHelloDone";
28
+ HandshakeType["Handshake_10"] = "CertificateVerify";
29
+ HandshakeType["Handshake_11"] = "ClientKeyExchange";
30
+ HandshakeType["Handshake_12"] = "Finished";
31
+ })(HandshakeType || (HandshakeType = {}));
32
+ class TLS_Handshake extends BaseHeader_1.BaseHeader {
33
+ constructor() {
34
+ super(...arguments);
35
+ this.SCHEMA = {
36
+ type: 'object',
37
+ properties: {
38
+ contentType: {
39
+ type: 'integer',
40
+ label: 'Content Type',
41
+ minimum: 0,
42
+ maximum: 255,
43
+ decode: () => {
44
+ this.instance.contentType.setValue((0, BufferToNumber_1.BufferToInt8)(this.readBytes(0, 1)));
45
+ },
46
+ encode: () => {
47
+ const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
48
+ this.writeBytes(0, contentType);
49
+ }
50
+ },
51
+ version: {
52
+ type: 'string',
53
+ label: 'Legacy Version',
54
+ minimum: 0,
55
+ maximum: 65535,
56
+ decode: () => {
57
+ const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2));
58
+ switch (version) {
59
+ case 768:
60
+ {
61
+ this.instance.version.setValue(TLSver.SSL_3_0);
62
+ }
63
+ break;
64
+ case 769:
65
+ {
66
+ this.instance.version.setValue(TLSver.TLS_1_0);
67
+ }
68
+ break;
69
+ case 770:
70
+ {
71
+ this.instance.version.setValue(TLSver.TLS_1_1);
72
+ }
73
+ break;
74
+ case 771:
75
+ {
76
+ this.instance.version.setValue(TLSver.TLS_1_2);
77
+ }
78
+ break;
79
+ case 772:
80
+ {
81
+ this.instance.version.setValue(TLSver.TLS_1_3);
82
+ }
83
+ break;
84
+ default: {
85
+ this.instance.version.setValue('0');
86
+ }
87
+ }
88
+ },
89
+ encode: () => {
90
+ const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
91
+ switch (version) {
92
+ case TLSver.SSL_3_0:
93
+ {
94
+ const version = (0, NumberToBuffer_1.UInt16ToBuffer)(768);
95
+ this.writeBytes(1, version);
96
+ }
97
+ break;
98
+ case TLSver.TLS_1_0:
99
+ {
100
+ const version = (0, NumberToBuffer_1.UInt16ToBuffer)(769);
101
+ this.writeBytes(1, version);
102
+ }
103
+ break;
104
+ case TLSver.TLS_1_1:
105
+ {
106
+ const version = (0, NumberToBuffer_1.UInt16ToBuffer)(770);
107
+ this.writeBytes(1, version);
108
+ }
109
+ break;
110
+ case TLSver.TLS_1_2:
111
+ {
112
+ const version = (0, NumberToBuffer_1.UInt16ToBuffer)(771);
113
+ this.writeBytes(1, version);
114
+ }
115
+ break;
116
+ case TLSver.TLS_1_3:
117
+ {
118
+ const version = (0, NumberToBuffer_1.UInt16ToBuffer)(772);
119
+ this.writeBytes(1, version);
120
+ }
121
+ break;
122
+ default: {
123
+ this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
124
+ }
125
+ }
126
+ }
127
+ },
128
+ length: {
129
+ type: 'integer',
130
+ label: 'Length',
131
+ minimum: 0,
132
+ maximum: 65535,
133
+ decode: () => {
134
+ this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(3, 2)));
135
+ },
136
+ encode: () => {
137
+ const length = (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
138
+ this.writeBytes(3, length);
139
+ }
140
+ },
141
+ handshakeType: {
142
+ type: 'string',
143
+ label: 'Handshake Type',
144
+ minimum: 0,
145
+ maximum: 65535,
146
+ decode: () => {
147
+ const handshakeType = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1));
148
+ switch (handshakeType) {
149
+ case 0:
150
+ {
151
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_1);
152
+ }
153
+ break;
154
+ case 1:
155
+ {
156
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_2);
157
+ }
158
+ break;
159
+ case 2:
160
+ {
161
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_3);
162
+ }
163
+ break;
164
+ case 4:
165
+ {
166
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_4);
167
+ }
168
+ break;
169
+ case 8:
170
+ {
171
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_5);
172
+ }
173
+ break;
174
+ case 11:
175
+ {
176
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_6);
177
+ }
178
+ break;
179
+ case 12:
180
+ {
181
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_7);
182
+ }
183
+ break;
184
+ case 13:
185
+ {
186
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_8);
187
+ }
188
+ break;
189
+ case 14:
190
+ {
191
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_9);
192
+ }
193
+ break;
194
+ case 15:
195
+ {
196
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_10);
197
+ }
198
+ break;
199
+ case 16:
200
+ {
201
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_11);
202
+ }
203
+ break;
204
+ case 20:
205
+ {
206
+ this.instance.handshakeType.setValue(HandshakeType.Handshake_12);
207
+ }
208
+ break;
209
+ default: {
210
+ this.instance.handshakeType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1)));
211
+ }
212
+ }
213
+ },
214
+ encode: () => {
215
+ const handshakeType = this.instance.handshakeType.getValue('0');
216
+ switch (handshakeType) {
217
+ case HandshakeType.Handshake_1:
218
+ {
219
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(0);
220
+ this.writeBytes(5, handshakeType);
221
+ }
222
+ break;
223
+ case HandshakeType.Handshake_2:
224
+ {
225
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(1);
226
+ this.writeBytes(5, handshakeType);
227
+ }
228
+ break;
229
+ case HandshakeType.Handshake_3:
230
+ {
231
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(2);
232
+ this.writeBytes(5, handshakeType);
233
+ }
234
+ break;
235
+ case HandshakeType.Handshake_4:
236
+ {
237
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(4);
238
+ this.writeBytes(5, handshakeType);
239
+ }
240
+ break;
241
+ case HandshakeType.Handshake_5:
242
+ {
243
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(8);
244
+ this.writeBytes(5, handshakeType);
245
+ }
246
+ break;
247
+ case HandshakeType.Handshake_6:
248
+ {
249
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(11);
250
+ this.writeBytes(5, handshakeType);
251
+ }
252
+ break;
253
+ case HandshakeType.Handshake_7:
254
+ {
255
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(12);
256
+ this.writeBytes(5, handshakeType);
257
+ }
258
+ break;
259
+ case HandshakeType.Handshake_8:
260
+ {
261
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(13);
262
+ this.writeBytes(5, handshakeType);
263
+ }
264
+ break;
265
+ case HandshakeType.Handshake_9:
266
+ {
267
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(14);
268
+ this.writeBytes(5, handshakeType);
269
+ }
270
+ break;
271
+ case HandshakeType.Handshake_10:
272
+ {
273
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(15);
274
+ this.writeBytes(5, handshakeType);
275
+ }
276
+ break;
277
+ case HandshakeType.Handshake_11:
278
+ {
279
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(16);
280
+ this.writeBytes(5, handshakeType);
281
+ }
282
+ break;
283
+ case HandshakeType.Handshake_12:
284
+ {
285
+ const handshakeType = (0, NumberToBuffer_1.UInt8ToBuffer)(20);
286
+ this.writeBytes(5, handshakeType);
287
+ }
288
+ break;
289
+ default: {
290
+ const handshakeType1 = parseInt(handshakeType);
291
+ this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(handshakeType1));
292
+ }
293
+ }
294
+ }
295
+ },
296
+ handshakeLength: {
297
+ type: 'integer',
298
+ label: 'Length',
299
+ minimum: 0,
300
+ maximum: 1118481,
301
+ decode: () => {
302
+ this.instance.handshakeLength.setValue((0, BufferToNumber_1.BufferToUInt32)(this.readBytes(6, 3)));
303
+ },
304
+ encode: () => {
305
+ const length1 = (this.instance.handshakeLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
306
+ const length2 = length1.toString(16).padStart(6, '0');
307
+ const length3 = (0, HexToBuffer_1.HexToBuffer)(length2);
308
+ this.writeBytes(6, length3);
309
+ }
310
+ },
311
+ messagedata: {
312
+ type: 'object',
313
+ label: 'Message Data',
314
+ properties: {
315
+ version: { type: 'string', label: 'Version' },
316
+ random: { type: 'string', contentEncoding: 'hex', label: 'Random' },
317
+ sessionId: { type: 'string', contentEncoding: 'hex', label: 'Session ID' },
318
+ cipherSuites: { type: 'array', label: 'Cipher Suites', items: { type: 'string' } },
319
+ cipherSuite: { type: 'string', label: 'Cipher Suite' },
320
+ compressionMethods: { type: 'array', label: 'Compression Methods', items: { type: 'string' } },
321
+ compressionMethod: { type: 'string', label: 'Compression Method' },
322
+ extensions: {
323
+ type: 'array',
324
+ label: 'Extensions',
325
+ items: {
326
+ type: 'object',
327
+ properties: {
328
+ type: { type: 'string', label: 'Type' },
329
+ name: { type: 'string', label: 'Name' },
330
+ //Present only for extensions we cannot structure (unknown type or
331
+ //malformed): the raw extension data, kept as hex so it round-trips.
332
+ data: { type: 'string', contentEncoding: 'hex', label: 'Data' },
333
+ //Structured forms (present per extension type instead of `data`).
334
+ serverNames: {
335
+ type: 'array', label: 'Server Names',
336
+ items: { type: 'object', properties: { nameType: { type: 'string', label: 'Name Type' }, hostName: { type: 'string', label: 'Host Name' } } }
337
+ },
338
+ groups: { type: 'array', label: 'Supported Groups', items: { type: 'string' } },
339
+ signatureAlgorithms: { type: 'array', label: 'Signature Algorithms', items: { type: 'string' } },
340
+ ecPointFormats: { type: 'array', label: 'EC Point Formats', items: { type: 'string' } },
341
+ modes: { type: 'array', label: 'PSK Key Exchange Modes', items: { type: 'string' } },
342
+ protocols: { type: 'array', label: 'ALPN Protocols', items: { type: 'string' } },
343
+ versions: { type: 'array', label: 'Supported Versions', items: { type: 'string' } },
344
+ selectedVersion: { type: 'string', label: 'Selected Version' },
345
+ keyShares: {
346
+ type: 'array', label: 'Key Shares',
347
+ items: { type: 'object', properties: { group: { type: 'string', label: 'Group' }, keyExchange: { type: 'string', contentEncoding: 'hex', label: 'Key Exchange' } } }
348
+ },
349
+ keyShare: {
350
+ type: 'object', label: 'Key Share',
351
+ properties: { group: { type: 'string', label: 'Group' }, keyExchange: { type: 'string', contentEncoding: 'hex', label: 'Key Exchange' } }
352
+ }
353
+ }
354
+ }
355
+ },
356
+ raw: { type: 'string', contentEncoding: 'hex', label: 'Unparsed Body' }
357
+ },
358
+ decode: () => {
359
+ const handshakeLength = (this.instance.handshakeLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
360
+ //handshakeLength describes the whole (possibly reassembled) message, which may
361
+ //span multiple TLS records. The body carried by THIS record is bounded by the
362
+ //record-layer length minus the 4-byte handshake header (type + 3-byte length);
363
+ //reading handshakeLength bytes would cross the record boundary and swallow the
364
+ //following record.
365
+ const recordLength = this.instance.length.getValue(0);
366
+ const bodyLength = recordLength > 4 ? Math.min(handshakeLength, recordLength - 4) : handshakeLength;
367
+ this.instance.messagedata.setValue({});
368
+ const handshakeType = this.instance.handshakeType.getValue();
369
+ try {
370
+ if (handshakeType === HandshakeType.Handshake_2)
371
+ this.decodeClientHello(bodyLength);
372
+ else if (handshakeType === HandshakeType.Handshake_3)
373
+ this.decodeServerHello(bodyLength);
374
+ else
375
+ throw new Error('unstructured');
376
+ }
377
+ catch (e) {
378
+ //Unsupported message type or a malformed Hello: keep the whole body as a
379
+ //visible raw field so the analyst sees it and encode reproduces it verbatim.
380
+ this.instance.messagedata.raw.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(9, bodyLength)));
381
+ if (e.message !== 'unstructured') {
382
+ this.recordError(this.instance.messagedata.getPath(), `Failed to parse handshake body: ${e.message}`);
383
+ }
384
+ }
385
+ },
386
+ encode: () => {
387
+ const md = this.instance.messagedata;
388
+ if (this.messagedataRawFallbackActive()) {
389
+ this.writeBytes(9, (0, HexToBuffer_1.HexToBuffer)(md.raw.getValue().toString()));
390
+ return;
391
+ }
392
+ const handshakeType = this.instance.handshakeType.getValue();
393
+ const parts = [];
394
+ parts.push(this.tlsVersionStringToBuffer(md.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'))));
395
+ parts.push((0, HexToBuffer_1.HexToBuffer)(md.random.getValue('')));
396
+ const sessionId = (0, HexToBuffer_1.HexToBuffer)(md.sessionId.getValue(''));
397
+ parts.push((0, NumberToBuffer_1.UInt8ToBuffer)(sessionId.length), sessionId);
398
+ if (handshakeType === HandshakeType.Handshake_3) {
399
+ parts.push((0, HexToBuffer_1.HexToBuffer)(md.cipherSuite.getValue('')));
400
+ parts.push((0, HexToBuffer_1.HexToBuffer)(md.compressionMethod.getValue('')));
401
+ }
402
+ else {
403
+ const cipherSuites = Buffer.concat(md.cipherSuites.getValue([]).map((code) => (0, HexToBuffer_1.HexToBuffer)(code)));
404
+ parts.push((0, NumberToBuffer_1.UInt16ToBuffer)(cipherSuites.length), cipherSuites);
405
+ const compressionMethods = Buffer.concat(md.compressionMethods.getValue([]).map((code) => (0, HexToBuffer_1.HexToBuffer)(code)));
406
+ parts.push((0, NumberToBuffer_1.UInt8ToBuffer)(compressionMethods.length), compressionMethods);
407
+ }
408
+ if (!md.extensions.isUndefined()) {
409
+ const extensionList = md.extensions.getValue([]);
410
+ const extensions = Buffer.concat(extensionList.map((extension) => {
411
+ //Structurally decoded extensions carry their specific fields (no `data`);
412
+ //rebuild those from the fields. Hex-preserved extensions carry `data`.
413
+ const data = extension.data !== undefined ? (0, HexToBuffer_1.HexToBuffer)(extension.data) : this.encodeExtensionData(extension, handshakeType);
414
+ return Buffer.concat([(0, HexToBuffer_1.HexToBuffer)(extension.type), (0, NumberToBuffer_1.UInt16ToBuffer)(data.length), data]);
415
+ }));
416
+ parts.push((0, NumberToBuffer_1.UInt16ToBuffer)(extensions.length), extensions);
417
+ }
418
+ this.writeBytes(9, Buffer.concat(parts));
419
+ }
420
+ }
421
+ }
422
+ };
423
+ this.id = 'tls-handshake';
424
+ //Fast-path bucket on the well-known HTTPS port; heuristicFallback keeps it matched on any other
425
+ //port by its record content (0x16 + version), so TLS on e.g. tcp:8443 still decodes.
426
+ this.matchKeys = ['tcpport:443'];
427
+ this.heuristicFallback = true;
428
+ this.name = 'Transport Layer Security(Handshake Protocol)';
429
+ this.nickname = 'TLS-Handshake';
430
+ }
431
+ /**
432
+ * Map a 2-byte TLS version to a friendly string, or its 4-hex form when unknown.
433
+ */
434
+ tlsVersionToString(version) {
435
+ switch (version) {
436
+ case 768: return TLSver.SSL_3_0;
437
+ case 769: return TLSver.TLS_1_0;
438
+ case 770: return TLSver.TLS_1_1;
439
+ case 771: return TLSver.TLS_1_2;
440
+ case 772: return TLSver.TLS_1_3;
441
+ default: return version.toString(16).padStart(4, '0');
442
+ }
443
+ }
444
+ /**
445
+ * Inverse of tlsVersionToString: a friendly string or 4-hex back to 2 bytes.
446
+ */
447
+ tlsVersionStringToBuffer(version) {
448
+ switch (version) {
449
+ case TLSver.SSL_3_0: return (0, NumberToBuffer_1.UInt16ToBuffer)(768);
450
+ case TLSver.TLS_1_0: return (0, NumberToBuffer_1.UInt16ToBuffer)(769);
451
+ case TLSver.TLS_1_1: return (0, NumberToBuffer_1.UInt16ToBuffer)(770);
452
+ case TLSver.TLS_1_2: return (0, NumberToBuffer_1.UInt16ToBuffer)(771);
453
+ case TLSver.TLS_1_3: return (0, NumberToBuffer_1.UInt16ToBuffer)(772);
454
+ default: return (0, HexToBuffer_1.HexToBuffer)(version.padStart(4, '0'));
455
+ }
456
+ }
457
+ /**
458
+ * True when the handshake body could not be structured (unsupported message type or a
459
+ * parse failure) and was preserved as messagedata.raw. Encode then re-emits those bytes
460
+ * verbatim; a structured Hello (messagedata.version set) turns this false.
461
+ */
462
+ messagedataRawFallbackActive() {
463
+ const md = this.instance.messagedata;
464
+ if (md.raw.isUndefined())
465
+ return false;
466
+ if (!md.raw.getValue(''))
467
+ return false;
468
+ return md.version.isUndefined();
469
+ }
470
+ /**
471
+ * Structurally decode a ClientHello (handshake type 1) body starting at record offset 9.
472
+ * Throws on any bound overrun / trailing bytes so the caller can fall back to raw.
473
+ */
474
+ decodeClientHello(bodyLength) {
475
+ let p = 9;
476
+ const end = 9 + bodyLength;
477
+ const need = (n) => {
478
+ if (n < 0 || p + n > end)
479
+ throw new Error('handshake body overrun');
480
+ };
481
+ need(2);
482
+ const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(p, 2));
483
+ p += 2;
484
+ need(32);
485
+ const random = (0, BufferToHex_1.BufferToHex)(this.readBytes(p, 32));
486
+ p += 32;
487
+ need(1);
488
+ const sidLen = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(p, 1));
489
+ p += 1;
490
+ need(sidLen);
491
+ const sessionId = (0, BufferToHex_1.BufferToHex)(this.readBytes(p, sidLen));
492
+ p += sidLen;
493
+ need(2);
494
+ const csLen = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(p, 2));
495
+ p += 2;
496
+ need(csLen);
497
+ const csBuf = this.readBytes(p, csLen);
498
+ p += csLen;
499
+ need(1);
500
+ const cmLen = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(p, 1));
501
+ p += 1;
502
+ need(cmLen);
503
+ const cmBuf = this.readBytes(p, cmLen);
504
+ p += cmLen;
505
+ let extensions = undefined;
506
+ if (p < end) {
507
+ need(2);
508
+ const extLen = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(p, 2));
509
+ p += 2;
510
+ need(extLen);
511
+ extensions = this.parseTLSExtensions(this.readBytes(p, extLen));
512
+ p += extLen;
513
+ }
514
+ if (p !== end)
515
+ throw new Error('trailing bytes in handshake body');
516
+ if (csLen % 2 !== 0)
517
+ throw new Error('odd cipher-suites length');
518
+ const cipherSuites = [];
519
+ for (let i = 0; i < csLen; i += 2)
520
+ cipherSuites.push((0, BufferToHex_1.BufferToHex)(csBuf.subarray(i, i + 2)));
521
+ const compressionMethods = [];
522
+ for (let i = 0; i < cmLen; i++)
523
+ compressionMethods.push((0, BufferToHex_1.BufferToHex)(cmBuf.subarray(i, i + 1)));
524
+ const md = this.instance.messagedata;
525
+ md.version.setValue(this.tlsVersionToString(version));
526
+ md.random.setValue(random);
527
+ md.sessionId.setValue(sessionId);
528
+ md.cipherSuites.setValue(cipherSuites);
529
+ md.compressionMethods.setValue(compressionMethods);
530
+ if (extensions !== undefined)
531
+ md.extensions.setValue(extensions);
532
+ }
533
+ /**
534
+ * Structurally decode a ServerHello (handshake type 2) body starting at record offset 9.
535
+ * Throws on any bound overrun / trailing bytes so the caller can fall back to raw.
536
+ */
537
+ decodeServerHello(bodyLength) {
538
+ let p = 9;
539
+ const end = 9 + bodyLength;
540
+ const need = (n) => {
541
+ if (n < 0 || p + n > end)
542
+ throw new Error('handshake body overrun');
543
+ };
544
+ need(2);
545
+ const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(p, 2));
546
+ p += 2;
547
+ need(32);
548
+ const random = (0, BufferToHex_1.BufferToHex)(this.readBytes(p, 32));
549
+ p += 32;
550
+ need(1);
551
+ const sidLen = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(p, 1));
552
+ p += 1;
553
+ need(sidLen);
554
+ const sessionId = (0, BufferToHex_1.BufferToHex)(this.readBytes(p, sidLen));
555
+ p += sidLen;
556
+ need(2);
557
+ const cipherSuite = (0, BufferToHex_1.BufferToHex)(this.readBytes(p, 2));
558
+ p += 2;
559
+ need(1);
560
+ const compressionMethod = (0, BufferToHex_1.BufferToHex)(this.readBytes(p, 1));
561
+ p += 1;
562
+ let extensions = undefined;
563
+ if (p < end) {
564
+ need(2);
565
+ const extLen = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(p, 2));
566
+ p += 2;
567
+ need(extLen);
568
+ extensions = this.parseTLSExtensions(this.readBytes(p, extLen));
569
+ p += extLen;
570
+ }
571
+ if (p !== end)
572
+ throw new Error('trailing bytes in handshake body');
573
+ const md = this.instance.messagedata;
574
+ md.version.setValue(this.tlsVersionToString(version));
575
+ md.random.setValue(random);
576
+ md.sessionId.setValue(sessionId);
577
+ md.cipherSuite.setValue(cipherSuite);
578
+ md.compressionMethod.setValue(compressionMethod);
579
+ if (extensions !== undefined)
580
+ md.extensions.setValue(extensions);
581
+ }
582
+ /**
583
+ * Friendly name for a 2-byte TLS extension type (IANA registry), or its 4-hex form.
584
+ */
585
+ tlsExtensionName(type) {
586
+ const names = {
587
+ '0000': 'server_name',
588
+ '0001': 'max_fragment_length',
589
+ '0005': 'status_request',
590
+ '000a': 'supported_groups',
591
+ '000b': 'ec_point_formats',
592
+ '000d': 'signature_algorithms',
593
+ '000f': 'heartbeat',
594
+ '0010': 'application_layer_protocol_negotiation',
595
+ '0012': 'signed_certificate_timestamp',
596
+ '0015': 'padding',
597
+ '0016': 'encrypt_then_mac',
598
+ '0017': 'extended_master_secret',
599
+ '001b': 'compress_certificate',
600
+ '0023': 'session_ticket',
601
+ '002a': 'early_data',
602
+ '002b': 'supported_versions',
603
+ '002c': 'cookie',
604
+ '002d': 'psk_key_exchange_modes',
605
+ '0031': 'post_handshake_auth',
606
+ '0032': 'signature_algorithms_cert',
607
+ '0033': 'key_share',
608
+ 'ff01': 'renegotiation_info'
609
+ };
610
+ return names[type.toLowerCase()] ? names[type.toLowerCase()] : `unknown_${type}`;
611
+ }
612
+ /**
613
+ * Split a TLS extensions block into its individual extensions. Each extension is a
614
+ * type(2) + length(2) + data(length) triple; data is kept as hex (authoritative for
615
+ * re-encode). Throws on any overrun so the caller can fall back to raw.
616
+ */
617
+ parseTLSExtensions(buffer) {
618
+ const handshakeType = this.instance.handshakeType.getValue();
619
+ const extensions = [];
620
+ let q = 0;
621
+ while (q < buffer.length) {
622
+ if (q + 4 > buffer.length)
623
+ throw new Error('extension header overrun');
624
+ const type = (0, BufferToHex_1.BufferToHex)(buffer.subarray(q, q + 2));
625
+ q += 2;
626
+ const length = (0, BufferToNumber_1.BufferToUInt16)(buffer.subarray(q, q + 2));
627
+ q += 2;
628
+ if (q + length > buffer.length)
629
+ throw new Error('extension data overrun');
630
+ const dataBuffer = buffer.subarray(q, q + length);
631
+ q += length;
632
+ const name = this.tlsExtensionName(type);
633
+ //Decode the inner structure for extensions we have a spec for; on any malformation
634
+ //(or an unknown type) keep the extension data as hex so it still round-trips.
635
+ let structured = null;
636
+ try {
637
+ structured = this.decodeExtensionData(type, dataBuffer, handshakeType);
638
+ }
639
+ catch (e) {
640
+ structured = null;
641
+ }
642
+ if (structured)
643
+ extensions.push({ type: type, name: name, ...structured });
644
+ else
645
+ extensions.push({ type: type, name: name, data: (0, BufferToHex_1.BufferToHex)(dataBuffer) });
646
+ }
647
+ return extensions;
648
+ }
649
+ /**
650
+ * Decode a single extension's inner structure by type. Returns the structured fields, or
651
+ * null when the type has no (implemented) structure so the caller keeps it as hex. Throws
652
+ * on any bound violation so the caller falls back to hex for that one extension.
653
+ */
654
+ decodeExtensionData(type, buffer, handshakeType) {
655
+ switch (type.toLowerCase()) {
656
+ case '0000': { //server_name
657
+ if (buffer.length === 0)
658
+ return { serverNames: [] }; //ServerHello echoes an empty SNI
659
+ const listLength = buffer.readUInt16BE(0);
660
+ if (2 + listLength !== buffer.length)
661
+ throw new Error('server_name list length');
662
+ const serverNames = [];
663
+ let q = 2;
664
+ while (q < buffer.length) {
665
+ if (q + 3 > buffer.length)
666
+ throw new Error('server_name entry overrun');
667
+ const nameType = buffer.readUInt8(q);
668
+ q += 1;
669
+ const nameLength = buffer.readUInt16BE(q);
670
+ q += 2;
671
+ if (q + nameLength > buffer.length)
672
+ throw new Error('server_name overrun');
673
+ serverNames.push({ nameType: nameType === 0 ? 'host_name' : `${nameType}`, hostName: buffer.subarray(q, q + nameLength).toString('ascii') });
674
+ q += nameLength;
675
+ }
676
+ return { serverNames: serverNames };
677
+ }
678
+ case '000a': //supported_groups
679
+ return { groups: this.decodeCodeList16(buffer) };
680
+ case '000d': //signature_algorithms
681
+ return { signatureAlgorithms: this.decodeCodeList16(buffer) };
682
+ case '000b': { //ec_point_formats (1-byte length, 1-byte codes)
683
+ if (buffer.length < 1)
684
+ throw new Error('ec_point_formats');
685
+ const listLength = buffer.readUInt8(0);
686
+ if (1 + listLength !== buffer.length)
687
+ throw new Error('ec_point_formats length');
688
+ const ecPointFormats = [];
689
+ for (let q = 1; q < buffer.length; q++)
690
+ ecPointFormats.push((0, BufferToHex_1.BufferToHex)(buffer.subarray(q, q + 1)));
691
+ return { ecPointFormats: ecPointFormats };
692
+ }
693
+ case '002d': { //psk_key_exchange_modes (1-byte length, 1-byte modes)
694
+ if (buffer.length < 1)
695
+ throw new Error('psk_key_exchange_modes');
696
+ const listLength = buffer.readUInt8(0);
697
+ if (1 + listLength !== buffer.length)
698
+ throw new Error('psk_key_exchange_modes length');
699
+ const modes = [];
700
+ for (let q = 1; q < buffer.length; q++)
701
+ modes.push((0, BufferToHex_1.BufferToHex)(buffer.subarray(q, q + 1)));
702
+ return { modes: modes };
703
+ }
704
+ case '0010': { //application_layer_protocol_negotiation (ALPN)
705
+ if (buffer.length < 2)
706
+ throw new Error('alpn');
707
+ const listLength = buffer.readUInt16BE(0);
708
+ if (2 + listLength !== buffer.length)
709
+ throw new Error('alpn length');
710
+ const protocols = [];
711
+ let q = 2;
712
+ while (q < buffer.length) {
713
+ const protocolLength = buffer.readUInt8(q);
714
+ q += 1;
715
+ if (q + protocolLength > buffer.length)
716
+ throw new Error('alpn protocol overrun');
717
+ protocols.push(buffer.subarray(q, q + protocolLength).toString('ascii'));
718
+ q += protocolLength;
719
+ }
720
+ return { protocols: protocols };
721
+ }
722
+ case '002b': { //supported_versions (ClientHello: list; ServerHello: single)
723
+ if (handshakeType === HandshakeType.Handshake_3) {
724
+ if (buffer.length !== 2)
725
+ throw new Error('supported_versions (server)');
726
+ return { selectedVersion: this.tlsVersionToString(buffer.readUInt16BE(0)) };
727
+ }
728
+ if (buffer.length < 1)
729
+ throw new Error('supported_versions');
730
+ const listLength = buffer.readUInt8(0);
731
+ if (1 + listLength !== buffer.length || listLength % 2 !== 0)
732
+ throw new Error('supported_versions length');
733
+ const versions = [];
734
+ for (let q = 1; q < buffer.length; q += 2)
735
+ versions.push(this.tlsVersionToString(buffer.readUInt16BE(q)));
736
+ return { versions: versions };
737
+ }
738
+ case '0033': { //key_share (ClientHello: list of entries; ServerHello: single entry)
739
+ if (handshakeType === HandshakeType.Handshake_3) {
740
+ if (buffer.length < 4)
741
+ throw new Error('key_share (server)');
742
+ const keyLength = buffer.readUInt16BE(2);
743
+ if (4 + keyLength !== buffer.length)
744
+ throw new Error('key_share length (server)');
745
+ return { keyShare: { group: (0, BufferToHex_1.BufferToHex)(buffer.subarray(0, 2)), keyExchange: (0, BufferToHex_1.BufferToHex)(buffer.subarray(4)) } };
746
+ }
747
+ if (buffer.length < 2)
748
+ throw new Error('key_share');
749
+ const listLength = buffer.readUInt16BE(0);
750
+ if (2 + listLength !== buffer.length)
751
+ throw new Error('key_share length');
752
+ const keyShares = [];
753
+ let q = 2;
754
+ while (q < buffer.length) {
755
+ if (q + 4 > buffer.length)
756
+ throw new Error('key_share entry overrun');
757
+ const group = (0, BufferToHex_1.BufferToHex)(buffer.subarray(q, q + 2));
758
+ q += 2;
759
+ const keyLength = buffer.readUInt16BE(q);
760
+ q += 2;
761
+ if (q + keyLength > buffer.length)
762
+ throw new Error('key_share key overrun');
763
+ keyShares.push({ group: group, keyExchange: (0, BufferToHex_1.BufferToHex)(buffer.subarray(q, q + keyLength)) });
764
+ q += keyLength;
765
+ }
766
+ return { keyShares: keyShares };
767
+ }
768
+ default:
769
+ return null; //no implemented structure: keep as hex
770
+ }
771
+ }
772
+ /**
773
+ * Decode a 2-byte-length-prefixed list of 2-byte codes into hex strings (used by
774
+ * supported_groups and signature_algorithms).
775
+ */
776
+ decodeCodeList16(buffer) {
777
+ if (buffer.length < 2)
778
+ throw new Error('code list');
779
+ const listLength = buffer.readUInt16BE(0);
780
+ if (2 + listLength !== buffer.length || listLength % 2 !== 0)
781
+ throw new Error('code list length');
782
+ const codes = [];
783
+ for (let q = 2; q < buffer.length; q += 2)
784
+ codes.push((0, BufferToHex_1.BufferToHex)(buffer.subarray(q, q + 2)));
785
+ return codes;
786
+ }
787
+ /**
788
+ * Rebuild a single extension's data buffer from its structured fields (inverse of
789
+ * decodeExtensionData). Only called for extensions decoded structurally (no `data` hex).
790
+ */
791
+ encodeExtensionData(extension, handshakeType) {
792
+ switch (extension.type.toLowerCase()) {
793
+ case '0000': { //server_name
794
+ const entries = Buffer.concat(extension.serverNames.map((serverName) => {
795
+ const host = Buffer.from(serverName.hostName, 'ascii');
796
+ const nameType = serverName.nameType === 'host_name' ? 0 : parseInt(serverName.nameType);
797
+ return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(nameType), (0, NumberToBuffer_1.UInt16ToBuffer)(host.length), host]);
798
+ }));
799
+ if (entries.length === 0)
800
+ return Buffer.alloc(0);
801
+ return Buffer.concat([(0, NumberToBuffer_1.UInt16ToBuffer)(entries.length), entries]);
802
+ }
803
+ case '000a':
804
+ return this.encodeCodeList16(extension.groups);
805
+ case '000d':
806
+ return this.encodeCodeList16(extension.signatureAlgorithms);
807
+ case '000b': {
808
+ const list = Buffer.concat(extension.ecPointFormats.map((format) => (0, HexToBuffer_1.HexToBuffer)(format)));
809
+ return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(list.length), list]);
810
+ }
811
+ case '002d': {
812
+ const list = Buffer.concat(extension.modes.map((mode) => (0, HexToBuffer_1.HexToBuffer)(mode)));
813
+ return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(list.length), list]);
814
+ }
815
+ case '0010': {
816
+ const entries = Buffer.concat(extension.protocols.map((protocol) => {
817
+ const bytes = Buffer.from(protocol, 'ascii');
818
+ return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(bytes.length), bytes]);
819
+ }));
820
+ return Buffer.concat([(0, NumberToBuffer_1.UInt16ToBuffer)(entries.length), entries]);
821
+ }
822
+ case '002b': {
823
+ if (handshakeType === HandshakeType.Handshake_3)
824
+ return this.tlsVersionStringToBuffer(extension.selectedVersion);
825
+ const list = Buffer.concat(extension.versions.map((version) => this.tlsVersionStringToBuffer(version)));
826
+ return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(list.length), list]);
827
+ }
828
+ case '0033': {
829
+ if (handshakeType === HandshakeType.Handshake_3) {
830
+ const key = (0, HexToBuffer_1.HexToBuffer)(extension.keyShare.keyExchange);
831
+ return Buffer.concat([(0, HexToBuffer_1.HexToBuffer)(extension.keyShare.group), (0, NumberToBuffer_1.UInt16ToBuffer)(key.length), key]);
832
+ }
833
+ const entries = Buffer.concat(extension.keyShares.map((keyShare) => {
834
+ const key = (0, HexToBuffer_1.HexToBuffer)(keyShare.keyExchange);
835
+ return Buffer.concat([(0, HexToBuffer_1.HexToBuffer)(keyShare.group), (0, NumberToBuffer_1.UInt16ToBuffer)(key.length), key]);
836
+ }));
837
+ return Buffer.concat([(0, NumberToBuffer_1.UInt16ToBuffer)(entries.length), entries]);
838
+ }
839
+ default:
840
+ return Buffer.alloc(0);
841
+ }
842
+ }
843
+ /**
844
+ * Rebuild a 2-byte-length-prefixed list of 2-byte codes (inverse of decodeCodeList16).
845
+ */
846
+ encodeCodeList16(codes) {
847
+ const list = Buffer.concat(codes.map((code) => (0, HexToBuffer_1.HexToBuffer)(code)));
848
+ return Buffer.concat([(0, NumberToBuffer_1.UInt16ToBuffer)(list.length), list]);
849
+ }
850
+ match() {
851
+ if (!this.prevCodecModule)
852
+ return false;
853
+ if ((0, BufferToHex_1.BufferToHex)(this.readBytes(0, 1)) != '16')
854
+ return false;
855
+ const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2));
856
+ const validVersions = [768, 769, 770, 771, 772];
857
+ return validVersions.includes(version);
858
+ }
859
+ }
860
+ exports.TLS_Handshake = TLS_Handshake;