diff --git a/package-lock.json b/package-lock.json index a21038ee..2ad8f7e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@astronautlabs/amf": "^0.0.6", "@blu3r4y/lzma": "^2.3.3", "@wavesenterprise/crypto-gost-js": "^2.1.0-RC1", - "@xmldom/xmldom": "^0.8.12", + "@xmldom/xmldom": "^0.8.13", "argon2-browser": "^1.18.0", "arrive": "^2.5.3", "assert": "^2.1.0", @@ -38,7 +38,7 @@ "d3": "7.9.0", "d3-hexbin": "^0.2.2", "diff": "^5.2.2", - "dompurify": "^3.4.0", + "dompurify": "^3.4.1", "es6-promisify": "^7.0.0", "escodegen": "^2.1.0", "esprima": "^4.0.1", @@ -62,7 +62,7 @@ "jsonpath-plus": "^10.4.0", "jsonwebtoken": "9.0.3", "jsqr": "^1.4.0", - "jsrsasign": "^11.1.2", + "jsrsasign": "^11.1.3", "kbpgp": "^2.1.17", "libbzip2-wasm": "0.0.4", "libyara-wasm": "^1.2.1", @@ -115,9 +115,9 @@ "@babel/runtime": "^7.29.2", "@codemirror/commands": "^6.10.3", "@codemirror/language": "^6.12.3", - "@codemirror/search": "^6.6.0", + "@codemirror/search": "^6.7.0", "@codemirror/state": "^6.5.4", - "@codemirror/view": "^6.41.0", + "@codemirror/view": "^6.41.1", "autoprefixer": "^10.5.0", "babel-loader": "^10.1.1", "base64-loader": "^1.0.0", @@ -143,7 +143,7 @@ "grunt-exec": "~3.0.0", "grunt-webpack": "^6.0.0", "grunt-zip": "^1.0.0", - "html-webpack-plugin": "^5.6.6", + "html-webpack-plugin": "^5.6.7", "imports-loader": "^5.0.0", "mini-css-extract-plugin": "2.10.2", "modify-source-webpack-plugin": "^4.1.0", @@ -154,7 +154,7 @@ "postcss-loader": "^8.2.1", "prompt": "^1.3.0", "sitemap": "^8.0.3", - "terser": "^5.46.1", + "terser": "^5.46.2", "webpack": "^5.106.2", "webpack-bundle-analyzer": "^4.10.2", "webpack-dev-server": "5.0.4", @@ -1868,9 +1868,9 @@ } }, "node_modules/@codemirror/search": { - "version": "6.6.0", - "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.6.0.tgz", - "integrity": "sha512-koFuNXcDvyyotWcgOnZGmY7LZqEOXZaaxD/j6n18TCLx2/9HieZJ5H6hs1g8FiRxBD0DNfs0nXn17g872RmYdw==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.7.0.tgz", + "integrity": "sha512-ZvGm99wc/s2cITtMT15LFdn8aH/aS+V+DqyGq/N5ZlV5vWtH+nILvC2nw0zX7ByNoHHDZ2IxxdW38O0tc5nVHg==", "dev": true, "license": "MIT", "dependencies": { @@ -1890,9 +1890,9 @@ } }, "node_modules/@codemirror/view": { - "version": "6.41.0", - "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.41.0.tgz", - "integrity": "sha512-6H/qadXsVuDY219Yljhohglve8xf4B8xJkVOEWfA5uiYKiTFppjqsvsfR5iPA0RbvRBoOyTZpbLIxe9+0UR8xA==", + "version": "6.41.1", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.41.1.tgz", + "integrity": "sha512-ToDnWKbBnke+ZLrP6vgTTDScGi5H37YYuZGniQaBzxMVdtCxMrslsmtnOvbPZk4RX9bvkQqnWR/WS/35tJA0qg==", "dev": true, "license": "MIT", "dependencies": { @@ -4524,9 +4524,9 @@ } }, "node_modules/@xmldom/xmldom": { - "version": "0.8.12", - "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.12.tgz", - "integrity": "sha512-9k/gHF6n/pAi/9tqr3m3aqkuiNosYTurLLUtc7xQ9sxB/wm7WPygCv8GYa6mS0fLJEHhqMC1ATYhz++U/lRHqg==", + "version": "0.8.13", + "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.13.tgz", + "integrity": "sha512-KRYzxepc14G/CEpEGc3Yn+JKaAeT63smlDr+vjB8jRfgTBBI9wRj/nkQEO+ucV8p8I9bfKLWp37uHgFrbntPvw==", "license": "MIT", "engines": { "node": ">=10.0.0" @@ -8296,9 +8296,9 @@ } }, "node_modules/dompurify": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.0.tgz", - "integrity": "sha512-nolgK9JcaUXMSmW+j1yaSvaEaoXYHwWyGJlkoCTghc97KgGDDSnpoU/PlEnw63Ah+TGKFOyY+X5LnxaWbCSfXg==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.1.tgz", + "integrity": "sha512-JahakDAIg1gyOm7dlgWSDjV4n7Ip2PKR55NIT6jrMfIgLFgWo81vdr1/QGqWtFNRqXP9UV71oVePtjqS2ebnPw==", "license": "(MPL-2.0 OR Apache-2.0)", "optionalDependencies": { "@types/trusted-types": "^2.0.7" @@ -10927,9 +10927,9 @@ } }, "node_modules/html-webpack-plugin": { - "version": "5.6.6", - "resolved": "https://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-5.6.6.tgz", - "integrity": "sha512-bLjW01UTrvoWTJQL5LsMRo1SypHW80FTm12OJRSnr3v6YHNhfe+1r0MYUZJMACxnCHURVnBWRwAsWs2yPU9Ezw==", + "version": "5.6.7", + "resolved": "https://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-5.6.7.tgz", + "integrity": "sha512-md+vXtdCAe60s1k6AU3dUyMJnDxUyQAwfwPKoLisvgUF1IXjtlLsk2se54+qfL9Mdm26bbwvjJybpNx48NKRLw==", "dev": true, "license": "MIT", "dependencies": { @@ -12412,9 +12412,9 @@ "license": "Apache-2.0" }, "node_modules/jsrsasign": { - "version": "11.1.2", - "resolved": "https://registry.npmjs.org/jsrsasign/-/jsrsasign-11.1.2.tgz", - "integrity": "sha512-GJuqiU/Grs6BaBBXMAZM9kxhsBrksZE0pF3qIfpkopMd7OMJ9zZmE/+CpV//97srfEyyyq1Ec0ELQtSlW/gPTA==", + "version": "11.1.3", + "resolved": "https://registry.npmjs.org/jsrsasign/-/jsrsasign-11.1.3.tgz", + "integrity": "sha512-nPnK5D/4lv0Dwr7TlzrKtAd8JlLZwFTqTUUB3NQCbtdobcRcohGFxjbPySDVh74iWUudcCsapYT6OxoyhJLhhA==", "license": "MIT" }, "node_modules/jszip": { @@ -17062,9 +17062,9 @@ "license": "MIT" }, "node_modules/terser": { - "version": "5.46.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.46.1.tgz", - "integrity": "sha512-vzCjQO/rgUuK9sf8VJZvjqiqiHFaZLnOiimmUuOKODxWL8mm/xua7viT7aqX7dgPY60otQjUotzFMmCB4VdmqQ==", + "version": "5.46.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.46.2.tgz", + "integrity": "sha512-uxfo9fPcSgLDYob/w1FuL0c99MWiJDnv+5qXSQc5+Ki5NjVNsYi66INnMFBjf6uFz6OnX12piJQPF4IpjJTNTw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { diff --git a/package.json b/package.json index 783a0980..2d7b8ae8 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,9 @@ "@babel/runtime": "^7.29.2", "@codemirror/commands": "^6.10.3", "@codemirror/language": "^6.12.3", - "@codemirror/search": "^6.6.0", + "@codemirror/search": "^6.7.0", "@codemirror/state": "^6.5.4", - "@codemirror/view": "^6.41.0", + "@codemirror/view": "^6.41.1", "autoprefixer": "^10.5.0", "babel-loader": "^10.1.1", "base64-loader": "^1.0.0", @@ -74,7 +74,7 @@ "grunt-exec": "~3.0.0", "grunt-webpack": "^6.0.0", "grunt-zip": "^1.0.0", - "html-webpack-plugin": "^5.6.6", + "html-webpack-plugin": "^5.6.7", "imports-loader": "^5.0.0", "mini-css-extract-plugin": "2.10.2", "modify-source-webpack-plugin": "^4.1.0", @@ -85,7 +85,7 @@ "postcss-loader": "^8.2.1", "prompt": "^1.3.0", "sitemap": "^8.0.3", - "terser": "^5.46.1", + "terser": "^5.46.2", "webpack": "^5.106.2", "webpack-bundle-analyzer": "^4.10.2", "webpack-dev-server": "5.0.4", @@ -97,7 +97,7 @@ "@astronautlabs/amf": "^0.0.6", "@blu3r4y/lzma": "^2.3.3", "@wavesenterprise/crypto-gost-js": "^2.1.0-RC1", - "@xmldom/xmldom": "^0.8.12", + "@xmldom/xmldom": "^0.8.13", "argon2-browser": "^1.18.0", "arrive": "^2.5.3", "assert": "^2.1.0", @@ -121,7 +121,7 @@ "d3": "7.9.0", "d3-hexbin": "^0.2.2", "diff": "^5.2.2", - "dompurify": "^3.4.0", + "dompurify": "^3.4.1", "es6-promisify": "^7.0.0", "escodegen": "^2.1.0", "esprima": "^4.0.1", @@ -145,7 +145,7 @@ "jsonpath-plus": "^10.4.0", "jsonwebtoken": "9.0.3", "jsqr": "^1.4.0", - "jsrsasign": "^11.1.2", + "jsrsasign": "^11.1.3", "kbpgp": "^2.1.17", "libbzip2-wasm": "0.0.4", "libyara-wasm": "^1.2.1", diff --git a/src/core/operations/AnalyseUUID.mjs b/src/core/operations/AnalyseUUID.mjs index b3506017..6f960c8a 100644 --- a/src/core/operations/AnalyseUUID.mjs +++ b/src/core/operations/AnalyseUUID.mjs @@ -1,5 +1,6 @@ /** * @author n1474335 [n1474335@gmail.com] + * @author ko80240 [csk.dev@proton.me] * @copyright Crown Copyright 2023 * @license Apache-2.0 */ @@ -8,6 +9,7 @@ import * as uuid from "uuid"; import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; +import { toHex } from "../lib/Hex.mjs"; /** * Analyse UUID operation @@ -22,27 +24,128 @@ class AnalyseUUID extends Operation { this.name = "Analyse UUID"; this.module = "Crypto"; - this.description = "Tries to determine information about a given UUID and suggests which version may have been used to generate it"; + this.description = "Operation for extracting metadata and detecting the version of a given UUID."; this.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier"; this.inputType = "string"; this.outputType = "string"; - this.args = []; + this.args = [ + { + name: "Include Metadata", + type: "boolean", + value: true + } + ]; } /** - * @param {string} input + * @param {string} input - Expects a valid UUID string * @param {Object[]} args * @returns {string} */ run(input, args) { + input = input.trim(); + + let uuidVersion, uuidBytes; try { - const uuidVersion = uuid.version(input); - return "UUID version: " + uuidVersion; + uuidVersion = uuid.version(input); // Re-using the uuid library to extract version + uuidBytes = uuid.parse(input); // Re-using the uuid library to parse bytes } catch (error) { throw new OperationError("Invalid UUID"); } - } + const [includeMetadata] = args; + const dv = new DataView(uuidBytes.buffer, uuidBytes.byteOffset, uuidBytes.byteLength); // Dataview helps handle the multi-byte ints + const uuidInteger = (dv.getBigUint64(0) << 64n) | dv.getBigUint64(8); + + const sections = [`Version:\n${uuidVersion}`]; + + if (includeMetadata) { + const parser = UUID_PARSERS[uuidVersion]; + const decoded = parser?.(uuidBytes, dv); + sections.push(formatDecoded(decoded)); + } + + sections.push(`UUID Integer:\n${uuidInteger}`); + + return sections.filter(Boolean).join("\n\n"); + } } export default AnalyseUUID; + +/** + * Metadata can be extracted for versions 1, 6, and 7. + * Enum-like frozen mapping of UUID version to parser function. + */ +const UUID_PARSERS = Object.freeze({ + 1: parsev1v6, + 6: parsev1v6, + 7: parsev7, +}); + +/** + * Versions 1 and 6. Note 6 is a re-order of 1. + * Version 1 == layout: timeLow(32) | timeMid(16) | timeHi(12) + * Version 6 == layout: timeHi(32) | timeMid(16) | timeLow(12) + */ +function parsev1v6(uuidBytes, dv) { + const isV1 = (uuidBytes[6] >> 4) === 1; + + const timeStamp = + isV1 ? ( + (BigInt(dv.getUint16(6) & 0x0fff) << 48n) | // mask off version bits + (BigInt(dv.getUint16(4)) << 32n) | + BigInt(dv.getUint32(0)) + ) : ( + (BigInt(dv.getUint32(0)) << 28n) | + (BigInt(dv.getUint16(4)) << 12n) | + (BigInt(dv.getUint16(6) & 0x0fff)) + ); + + // Convert to Unix time + const milliseconds = + Number( + (timeStamp - 122192928000000000n) / 10000n + ); + + return { + timestamp: milliseconds, + isoTimestamp: new Date(milliseconds).toISOString(), + clock: ((uuidBytes[8] & 0x3f) << 8) | uuidBytes[9], + node: toHex(uuidBytes.slice(10), ":").toUpperCase() + }; +} + +/** Version 7 */ +function parsev7(uuidBytes, dv) { + const milliseconds = Number((BigInt(dv.getUint32(0)) << 16n) | BigInt(dv.getUint16(4))); + + return { + timestamp: milliseconds, + isoTimestamp: new Date(milliseconds).toISOString(), + randA: ((uuidBytes[6] & 0x0f) << 8) | uuidBytes[7], + randB: toHex(uuidBytes.slice(8), "").toUpperCase() + }; +} + +/** + * Formats metadata + * + * @param {Object|undefined} decoded + * @returns {string} + */ +function formatDecoded(decoded) { + if (!decoded) return "No metadata available. Only versions 1, 6, 7 are supported."; + + return Object.entries({ + "Timestamp": decoded.timestamp, + "Timestamp (ISO)": decoded.isoTimestamp, + "Node": decoded.node, + "Clock": decoded.clock, + "Rand A": decoded.randA, + "Rand B": decoded.randB + }) + .filter(([, value]) => value !== undefined) + .map(([label, value]) => `${label}:\n${value}`) + .join("\n\n"); +} diff --git a/src/web/HTMLOperation.mjs b/src/web/HTMLOperation.mjs index 30cfd1d9..725f0b5f 100755 --- a/src/web/HTMLOperation.mjs +++ b/src/web/HTMLOperation.mjs @@ -43,17 +43,23 @@ class HTMLOperation { /** * Renders the operation in HTML as a stub operation with no ingredients. * + * @param {boolean} removeIcon - show icon for removing operation + * @param {string} elementId - element ID for aria usage * @returns {string} */ - toStubHtml(removeIcon) { + toStubHtml(removeIcon = false, elementId = null) { let html = "