cyberchef 9.38.8 → 9.38.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cyberchef",
3
- "version": "9.38.8",
3
+ "version": "9.38.9",
4
4
  "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
5
5
  "author": "n1474335 <n1474335@gmail.com>",
6
6
  "homepage": "https://gchq.github.io/CyberChef",
@@ -9,35 +9,25 @@
9
9
  import { toHex, fromHex } from "./Hex.mjs";
10
10
 
11
11
  /**
12
- * Formats Distinguished Name (DN) strings.
12
+ * Formats Distinguished Name (DN) objects to strings.
13
13
  *
14
- * @param {string} dnStr
14
+ * @param {Object} dnObj
15
15
  * @param {number} indent
16
16
  * @returns {string}
17
17
  */
18
- export function formatDnStr(dnStr, indent) {
19
- const fields = dnStr.substr(1).replace(/([^\\])\//g, "$1$1/").split(/[^\\]\//);
20
- let output = "",
21
- maxKeyLen = 0,
22
- key,
23
- value,
24
- i,
25
- str;
26
-
27
- for (i = 0; i < fields.length; i++) {
28
- if (!fields[i].length) continue;
29
-
30
- key = fields[i].split("=")[0];
18
+ export function formatDnObj(dnObj, indent) {
19
+ let output = "";
31
20
 
32
- maxKeyLen = key.length > maxKeyLen ? key.length : maxKeyLen;
33
- }
21
+ const maxKeyLen = dnObj.array.reduce((max, item) => {
22
+ return item[0].type.length > max ? item[0].type.length : max;
23
+ }, 0);
34
24
 
35
- for (i = 0; i < fields.length; i++) {
36
- if (!fields[i].length) continue;
25
+ for (let i = 0; i < dnObj.array.length; i++) {
26
+ if (!dnObj.array[i].length) continue;
37
27
 
38
- key = fields[i].split("=")[0];
39
- value = fields[i].split("=")[1];
40
- str = key.padEnd(maxKeyLen, " ") + " = " + value + "\n";
28
+ const key = dnObj.array[i][0].type;
29
+ const value = dnObj.array[i][0].value;
30
+ const str = `${key.padEnd(maxKeyLen, " ")} = ${value}\n`;
41
31
 
42
32
  output += str.padStart(indent + str.length, " ");
43
33
  }
@@ -7,7 +7,7 @@
7
7
  import r from "jsrsasign";
8
8
  import { fromBase64 } from "../lib/Base64.mjs";
9
9
  import { toHex } from "../lib/Hex.mjs";
10
- import { formatByteStr, formatDnStr } from "../lib/PublicKey.mjs";
10
+ import { formatByteStr, formatDnObj } from "../lib/PublicKey.mjs";
11
11
  import Operation from "../Operation.mjs";
12
12
  import Utils from "../Utils.mjs";
13
13
 
@@ -76,8 +76,8 @@ class ParseX509Certificate extends Operation {
76
76
  }
77
77
 
78
78
  const sn = cert.getSerialNumberHex(),
79
- issuer = cert.getIssuerString(),
80
- subject = cert.getSubjectString(),
79
+ issuer = cert.getIssuer(),
80
+ subject = cert.getSubject(),
81
81
  pk = cert.getPublicKey(),
82
82
  pkFields = [],
83
83
  sig = cert.getSignatureValueHex();
@@ -170,10 +170,10 @@ class ParseX509Certificate extends Operation {
170
170
  extensions = cert.getInfo().split("X509v3 Extensions:\n")[1].split("signature")[0];
171
171
  } catch (err) {}
172
172
 
173
- const issuerStr = formatDnStr(issuer, 2),
173
+ const issuerStr = formatDnObj(issuer, 2),
174
174
  nbDate = formatDate(cert.getNotBefore()),
175
175
  naDate = formatDate(cert.getNotAfter()),
176
- subjectStr = formatDnStr(subject, 2);
176
+ subjectStr = formatDnObj(subject, 2);
177
177
 
178
178
  return `Version: ${cert.version} (0x${Utils.hex(cert.version - 1)})
179
179
  Serial number: ${new r.BigInteger(sn, 16).toString()} (0x${sn})