mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 06:55:08 -04:00
Merge a0ade26505
into 7c8be12d52
This commit is contained in:
commit
02fe0d0717
6 changed files with 138 additions and 24 deletions
33
package-lock.json
generated
33
package-lock.json
generated
|
@ -94,6 +94,7 @@
|
||||||
"ua-parser-js": "^1.0.38",
|
"ua-parser-js": "^1.0.38",
|
||||||
"unorm": "^1.6.0",
|
"unorm": "^1.6.0",
|
||||||
"utf8": "^3.0.0",
|
"utf8": "^3.0.0",
|
||||||
|
"uuid": "^11.1.0",
|
||||||
"vkbeautify": "^0.99.3",
|
"vkbeautify": "^0.99.3",
|
||||||
"xpath": "0.0.34",
|
"xpath": "0.0.34",
|
||||||
"xregexp": "^5.1.1",
|
"xregexp": "^5.1.1",
|
||||||
|
@ -13876,6 +13877,15 @@
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/nightwatch/node_modules/uuid": {
|
||||||
|
"version": "8.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"uuid": "dist/bin/uuid"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/nightwatch/node_modules/yallist": {
|
"node_modules/nightwatch/node_modules/yallist": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||||
|
@ -16819,6 +16829,15 @@
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/sockjs/node_modules/uuid": {
|
||||||
|
"version": "8.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"uuid": "dist/bin/uuid"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/socks": {
|
"node_modules/socks": {
|
||||||
"version": "2.8.3",
|
"version": "2.8.3",
|
||||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz",
|
"resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz",
|
||||||
|
@ -18106,13 +18125,15 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/uuid": {
|
"node_modules/uuid": {
|
||||||
"version": "8.3.2",
|
"version": "11.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz",
|
||||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
"integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==",
|
||||||
"dev": true,
|
"funding": [
|
||||||
"license": "MIT",
|
"https://github.com/sponsors/broofa",
|
||||||
|
"https://github.com/sponsors/ctavan"
|
||||||
|
],
|
||||||
"bin": {
|
"bin": {
|
||||||
"uuid": "dist/bin/uuid"
|
"uuid": "dist/esm/bin/uuid"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/v8flags": {
|
"node_modules/v8flags": {
|
||||||
|
|
|
@ -180,6 +180,7 @@
|
||||||
"ua-parser-js": "^1.0.38",
|
"ua-parser-js": "^1.0.38",
|
||||||
"unorm": "^1.6.0",
|
"unorm": "^1.6.0",
|
||||||
"utf8": "^3.0.0",
|
"utf8": "^3.0.0",
|
||||||
|
"uuid": "^11.1.0",
|
||||||
"vkbeautify": "^0.99.3",
|
"vkbeautify": "^0.99.3",
|
||||||
"xpath": "0.0.34",
|
"xpath": "0.0.34",
|
||||||
"xregexp": "^5.1.1",
|
"xregexp": "^5.1.1",
|
||||||
|
|
|
@ -545,6 +545,7 @@
|
||||||
"Pseudo-Random Number Generator",
|
"Pseudo-Random Number Generator",
|
||||||
"Generate De Bruijn Sequence",
|
"Generate De Bruijn Sequence",
|
||||||
"Generate UUID",
|
"Generate UUID",
|
||||||
|
"Analyse UUID",
|
||||||
"Generate TOTP",
|
"Generate TOTP",
|
||||||
"Generate HOTP",
|
"Generate HOTP",
|
||||||
"Generate QR Code",
|
"Generate QR Code",
|
||||||
|
|
48
src/core/operations/AnalyseUUID.mjs
Normal file
48
src/core/operations/AnalyseUUID.mjs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2023
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as uuid from "uuid";
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyse UUID operation
|
||||||
|
*/
|
||||||
|
class AnalyseUUID extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AnalyseUUID constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
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.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
try {
|
||||||
|
const uuidVersion = uuid.version(input);
|
||||||
|
return "UUID version: " + uuidVersion;
|
||||||
|
} catch (error) {
|
||||||
|
throw new OperationError("Invalid UUID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AnalyseUUID;
|
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import crypto from "crypto";
|
import * as uuid from "uuid";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
/**
|
/**
|
||||||
* Generate UUID operation
|
* Generate UUID operation
|
||||||
*/
|
*/
|
||||||
|
@ -20,11 +20,38 @@ class GenerateUUID extends Operation {
|
||||||
|
|
||||||
this.name = "Generate UUID";
|
this.name = "Generate UUID";
|
||||||
this.module = "Crypto";
|
this.module = "Crypto";
|
||||||
this.description = "Generates an RFC 4122 version 4 compliant Universally Unique Identifier (UUID), also known as a Globally Unique Identifier (GUID).<br><br>A version 4 UUID relies on random numbers, in this case generated using <code>window.crypto</code> if available and falling back to <code>Math.random</code> if not.";
|
this.description =
|
||||||
|
"Generates an RFC 9562 (formerly RFC 4122) compliant Universally Unique Identifier (UUID), " +
|
||||||
|
"also known as a Globally Unique Identifier (GUID).<br>" +
|
||||||
|
"<br>" +
|
||||||
|
"We currently support generating the following UUID versions:<br>" +
|
||||||
|
"<ul>" +
|
||||||
|
"<li><strong>v1</strong>: Timestamp-based</li>" +
|
||||||
|
"<li><strong>v3</strong>: Namespace w/ MD5</li>" +
|
||||||
|
"<li><strong>v4</strong>: Random (default)</li>" +
|
||||||
|
"<li><strong>v5</strong>: Namespace w/ SHA-1</li>" +
|
||||||
|
"<li><strong>v6</strong>: Timestamp, reordered</li>" +
|
||||||
|
"<li><strong>v7</strong>: Unix Epoch time-based</li>" +
|
||||||
|
"</ul>" +
|
||||||
|
"UUIDs are generated using the <a href='https://npmjs.org/uuid/'><code>uuid</code><a> package.<br>";
|
||||||
this.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier";
|
this.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [];
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Version",
|
||||||
|
hint: "UUID version",
|
||||||
|
type: "option",
|
||||||
|
value: ["v1", "v3", "v4", "v5", "v6", "v7"],
|
||||||
|
defaultIndex: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Namespace",
|
||||||
|
hint: "UUID namespace (UUID; valid for v3 and v5)",
|
||||||
|
type: "string",
|
||||||
|
value: "1b671a64-40d5-491e-99b0-da01ff1f3341"
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,16 +60,17 @@ class GenerateUUID extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const buf = new Uint32Array(4).map(() => {
|
const [version, namespace] = args;
|
||||||
return crypto.randomBytes(4).readUInt32BE(0, true);
|
const hasDesiredVersion = typeof uuid[version] === "function";
|
||||||
});
|
if (!hasDesiredVersion) throw new OperationError("Invalid UUID version");
|
||||||
let i = 0;
|
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
const requiresNamespace = ["v3", "v5"].includes(version);
|
||||||
const r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
if (!requiresNamespace) return uuid[version]();
|
||||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
|
||||||
i++;
|
const hasValidNamespace = typeof namespace === "string" && uuid.validate(namespace);
|
||||||
return v.toString(16);
|
if (!hasValidNamespace) throw new OperationError("Invalid UUID namespace");
|
||||||
});
|
|
||||||
|
return uuid[version](input, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -580,10 +580,25 @@ Password: 282760`;
|
||||||
assert.strictEqual(result.toString().substr(0, 37), "-----BEGIN PGP PRIVATE KEY BLOCK-----");
|
assert.strictEqual(result.toString().substr(0, 37), "-----BEGIN PGP PRIVATE KEY BLOCK-----");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
it("Generate UUID", () => {
|
...[1, 3, 4, 5, 6, 7].map(version => it(`Generate UUID v${version}`, () => {
|
||||||
const result = chef.generateUUID();
|
const result = chef.generateUUID("", { "version": `v${version}` }).toString();
|
||||||
assert.ok(result.toString());
|
assert.ok(result);
|
||||||
assert.strictEqual(result.toString().length, 36);
|
assert.strictEqual(result.length, 36);
|
||||||
|
})),
|
||||||
|
|
||||||
|
...[1, 3, 4, 5, 6, 7].map(version => it(`Analyze UUID v${version}`, () => {
|
||||||
|
const uuid = chef.generateUUID("", { "version": `v${version}` }).toString();
|
||||||
|
const result = chef.analyseUUID(uuid).toString();
|
||||||
|
const expected = `UUID version: ${version}`;
|
||||||
|
assert.strictEqual(result, expected);
|
||||||
|
})),
|
||||||
|
|
||||||
|
it("Generate UUID using defaults", () => {
|
||||||
|
const uuid = chef.generateUUID();
|
||||||
|
assert.ok(uuid);
|
||||||
|
|
||||||
|
const analysis = chef.analyseUUID(uuid).toString();
|
||||||
|
assert.strictEqual(analysis, "UUID version: 4");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
it("Gzip, Gunzip", () => {
|
it("Gzip, Gunzip", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue