Compare commits

..

207 commits

Author SHA1 Message Date
a3957273
7c8be12d52
Merge pull request #1548 from brun0ne/add-php-serialization
Some checks failed
CodeQL Analysis / Analyze (push) Has been cancelled
Master Build, Test & Deploy / main (push) Has been cancelled
Add new operation: PHP Serialize
2025-04-05 19:06:23 +01:00
a3957273
e849569b10
Merge pull request #2013 from plvie/master
Add ECB/NoPadding and CBC/NoPadding support to AES encryption
2025-04-05 19:04:08 +01:00
Paul Vié
fa559fdbed split edit 2025-04-05 14:28:14 +02:00
a3957273
74d631c71e
Merge pull request #1991 from peterc-s/master
Some checks are pending
CodeQL Analysis / Analyze (push) Waiting to run
Master Build, Test & Deploy / main (push) Waiting to run
Add Base32 Hex Extended Alphabet and Base32 Tests.
2025-04-05 05:57:56 +01:00
a3957273
305a02c8a2
Merge pull request #1974 from PathToLife/feature/docker-multiplatform-build
Docker multiplatform build support
2025-04-05 05:42:01 +01:00
a3957273
5a3b7bc4c0
Merge pull request #2014 from 0xh3xa/master
Fix(RecipeWaiter): sanitize user input in addOperation to prevent XSS
2025-04-05 05:14:58 +01:00
heaprc
c83e1ac4fb Fix(RecipeWaiter): eslint format error 2025-04-05 00:42:37 +02:00
heaprc
857576dbe4 fix(RecipeWaiter): sanitize user input in addOperation to prevent XSS 2025-04-05 00:18:54 +02:00
Paul Vié
e00a636fc0 fix semicolon 2025-04-04 18:40:27 +02:00
Garab
6f4cbd8688
Merge branch 'gchq:master' into master 2025-04-04 18:32:40 +02:00
a3957273
848660f8e1
Merge pull request #2006 from 0xh3xa/master
Some checks failed
CodeQL Analysis / Analyze (push) Has been cancelled
Master Build, Test & Deploy / main (push) Has been cancelled
Bug Fix: selected theme not loading when refreshing
2025-04-03 19:15:02 +01:00
heaprc
0e7b1f7c78 resolve conflict in applyPreferredColorScheme method 2025-04-03 09:31:53 +02:00
0xh3xa
bbb211d819
Merge branch 'master' into master 2025-04-03 09:23:39 +02:00
0xh3xa
9ca0152aac
Merge branch 'master' into master 2025-04-03 09:22:38 +02:00
a3957273
4b72484ca4
Merge pull request #1993 from r4mos/master
Some checks are pending
CodeQL Analysis / Analyze (push) Waiting to run
Master Build, Test & Deploy / main (push) Waiting to run
Add CRC Operation
2025-04-03 08:22:11 +01:00
a3957273
e469f00fc7
Merge pull request #1286 from ccarpo/master
Added a JSON to YAML and a YAML to JSON operation
2025-04-03 08:19:20 +01:00
a3957273
75e3f35932
Merge pull request #1863 from JSCU-CNI/x509_fingerprints
Add fingerprints to the 'Parse X.509 certificate' operation
2025-04-03 08:18:04 +01:00
a3957273
9a8804ab94
Merge pull request #1604 from zhzy0077/jq
Support jq as an operation.
2025-04-03 08:15:35 +01:00
a3957273
f5b5227e53
Merge pull request #1909 from flakjacket95/master
Add SM2 Encrypt and Decrypt Operations
2025-04-03 08:14:23 +01:00
a3957273
14472d3b40
Merge pull request #2007 from 0xh3xa/bugfix/invalid-theme-option
Load the user's preferred color scheme if the URL contains an invalid theme
2025-04-03 08:00:39 +01:00
heaprc
9f30dd0e7a fix invalid theme error 2025-03-29 04:40:29 +01:00
0xh3xa
49d69a293b
Fix selected theme not loading when refreshing 2025-03-29 01:27:38 +01:00
Paul Vié
23de98f892 Add ECB/NoPadding and CBC/NoPadding Encryption 2025-03-26 11:46:47 +01:00
Dan Flack
8852712f0d
Merge branch 'master' into master 2025-03-16 00:44:31 -04:00
zhzy0077
b62def3d3e making it a seperate module. 2025-03-12 20:15:23 +08:00
zhzy0077
464c92e7bf Rename to "Jq" 2025-03-12 20:15:09 +08:00
zhzy0077
95044ab767 Making it depending on 0.5.1 version. 2025-03-12 20:15:00 +08:00
CCarpo
a809321b63 renamed function for clarity 2025-03-10 20:55:35 +01:00
Computer Network Investigation
b6f0f9b200
Merge branch 'master' into x509_fingerprints 2025-03-10 16:44:41 +01:00
PathToLife
a42c7de112
test buildah platforms flag environment variables 2025-03-10 18:00:49 +13:00
PathToLife
b85036b78f
Dockerfile manual architecture selection for multiplatform build. Disable NPM Publish for testing 2025-03-10 17:28:20 +13:00
PathToLife
3b75e13287
ci release error fix, apply detect chrome driver version npm install env var 2025-03-10 12:46:34 +13:00
CCarpo
98ef5d0110
Merge branch 'master' into master 2025-03-07 15:03:33 +01:00
ccarpo
2c21d72a6a Merge branch 'master' of https://github.com/ccarpo/CyberChef 2025-03-07 12:39:30 +01:00
r4mos
42efc0187c Fixed Test for non-working buttons 2025-03-04 08:46:41 +01:00
r4mos
d5f007deea Fixed non-working buttons 2025-03-04 08:43:16 +01:00
r4mos
566b423065 Correct forgotten test 2025-03-03 17:33:54 +01:00
r4mos
1b4760c447 Add Custom CRC 2025-03-03 17:15:26 +01:00
r4mos
3025391821 Browser test changed to adapt to new CRC operation 2025-03-03 09:19:01 +01:00
r4mos
4e62aa6e1d The CRC Operation is implemented natively with all currently known CRC's. Old Operations (CRC8, CRC16 and CRC32) and their dependencies are removed 2025-03-02 01:51:09 +01:00
r4mos
fcecd029c7 The CRC Operation is implemented natively with all currently known CRC's. Old Operations (CRC8, CRC16 and CRC32) and their dependencies are removed 2025-03-02 01:41:12 +01:00
peterc-s
3057a20791
Add Base32 Hex Extended option. 2025-02-28 16:52:15 +00:00
PathToLife
b2981d3cc7
Merge branch 'master' into feature/docker-multiplatform-build 2025-02-24 04:47:35 +00:00
a3957273
d3357d2acd
Merge pull request #1981 from bartblaze/master 2025-02-21 22:12:47 +00:00
bartblaze
7babef6f93 Preserve uppercase
This will preserve uppercase.
2025-02-17 17:35:22 +01:00
Brunon Blok
a40aed2b47
Merge branch 'master' into add-php-serialization 2025-02-17 14:09:03 +01:00
CCarpo
5cef2b13a3 fixed typo in categories. 2025-02-17 08:46:28 +01:00
CCarpo
c2936a6f2c removed old data format 2025-02-17 08:44:42 +01:00
CCarpo
06b7f0129f fixed linter issues. 2025-02-17 08:42:14 +01:00
CCarpo
e44e6fed35
Merge branch 'master' into master 2025-02-17 08:36:14 +01:00
Zhiyuan Zheng
a74e2e585e add lock. 2025-02-17 13:49:17 +08:00
Zhiyuan Zheng
d602897221 Merge branch 'master' into jq 2025-02-17 13:47:34 +08:00
a3957273
1b8c229df2
Merge pull request #1976 from evenstensberg/feat/cspell
chore(root): add cspell
2025-02-16 18:48:31 +00:00
a3957273
aa7bbc1a62
Merge pull request #1977 from depperm/CC-1889
CC-1889 add _ option
2025-02-16 18:37:00 +00:00
David Marshall
6ccbc892c7 CC-1889 2025-02-16 09:03:46 -05:00
Even Stensberg
7b3980a5e2
chore(root): add cspell 2025-02-16 13:53:36 +01:00
a3957273
7906f9d560
Merge pull request #630 from MShwed/feature/mime-rfc2047
Feature: MIME RFC2047 Decoding
2025-02-16 12:11:02 +00:00
mshwed
2ae923b73e Updated category and fixed imports 2025-02-15 23:03:05 -05:00
mshwed
15bbed093c fixed formatting 2025-02-15 22:23:49 -05:00
mshwed
23faeadea2 Fixed linting issues 2025-02-15 22:20:42 -05:00
mshwed
50c0d4bcd6 Added test case for ISO and ASCII 2025-02-15 22:20:42 -05:00
mshwed
7f97afd3e0 Added parsing of headers. 2025-02-15 22:20:41 -05:00
mshwed
c3994aa8e3 Added support for converting hex characters 2025-02-15 22:16:58 -05:00
mshwed
8166f981ae in progress 2025-02-15 22:16:58 -05:00
a3957273
1cfbc2babb
Merge pull request #1105 from linuxgemini/linuxgemini-patch-modhex
Introduce Yubico's Modhex for Conversion
2025-02-16 02:18:30 +00:00
a3957273
eb912547ac
Merge branch 'master' into linuxgemini-patch-modhex 2025-02-16 01:55:11 +00:00
a3957273
bcf62ec73d
Merge pull request #1903 from FranciscoPombal/rot13_numbers_negative_shift_amount
fix: ROT13 - shifting numbers by negative amounts
2025-02-16 01:47:09 +00:00
a3957273
004ef7f5dc
Merge pull request #1904 from FranciscoPombal/des_triple_des_error_message
fix: DES/Triple DES - misleading error messages
2025-02-16 01:43:36 +00:00
a3957273
9ab990ff59
Merge pull request #1921 from vs4vijay/theme-auto-detection
automatically theme mode based on user preference
2025-02-16 01:36:28 +00:00
a3957273
fb8e1be9f0
Merge pull request #1933 from k3ach/master
Updated luhn checksum operation to work with different bases
2025-02-16 01:30:37 +00:00
PathToLife
324560aeae
Merge branch 'gchq:master' into feature/docker-multiplatform-build 2025-02-16 00:54:09 +00:00
a3957273
95c6406d05
Merge pull request #1966 from exactlyaron/fix/generate-totp-issue-1964
Fix Generate TOTP & HOPT
2025-02-15 23:06:55 +00:00
a3957273
51b9fe644b
Merge pull request #1971 from bartblaze/master
Add Leet Speak
2025-02-15 22:55:52 +00:00
a3957273
fed10f3ee6
Merge pull request #1915 from Oshawk/take-nth-bytes
Add 'Take nth bytes' operation
2025-02-14 15:45:27 +00:00
a3957273
7cc3e5804b
Merge branch 'master' into take-nth-bytes 2025-02-14 15:44:12 +00:00
a3957273
dcf0bbb02b
Merge pull request #1914 from Oshawk/drop-nth-bytes
Add 'Drop nth bytes' operation
2025-02-14 15:43:41 +00:00
PathToLife
f8b613b4e7
Docker multiplatform build support. Pending CI workflow test 2025-02-13 20:57:45 +13:00
a3957273
e48fc4c8d8
Merge pull request #1902 from FranciscoPombal/blowfish_ecr_iv
fix: Blowfish - ignore IV length in ECB mode
2025-02-12 22:37:31 +00:00
a3957273
1b53b8d23f
Merge pull request #1780 from jb30795/master
IPv6 Transition Operation
2025-02-12 22:35:29 +00:00
a3957273
355566736a
Merge branch 'master' into blowfish_ecr_iv 2025-02-12 20:08:47 +00:00
a3957273
b99a76f9a6
Merge branch 'master' into master 2025-02-12 20:08:43 +00:00
a3957273
912bbe54aa
Merge branch 'master' into drop-nth-bytes 2025-02-12 20:08:30 +00:00
a3957273
26a16b6945
Merge branch 'master' into take-nth-bytes 2025-02-12 20:08:24 +00:00
a3957273
feaf3dd119
Merge branch 'master' into theme-auto-detection 2025-02-12 19:59:44 +00:00
a3957273
3187ff6322
Merge branch 'master' into master 2025-02-12 19:53:55 +00:00
a3957273
13f94a23f8
Merge pull request #1899 from c65722/strip_ipv4_header
Add Strip IPv4 header operation
2025-02-12 19:53:34 +00:00
a3957273
592e660deb
Merge pull request #1973 from gchq/bug/disable-loading-from-url
Disable flakey URL test
2025-02-12 19:53:24 +00:00
a3957273
3cdbdf4223
Merge branch 'master' into master 2025-02-12 19:51:20 +00:00
c65722
8cd875d06a
Merge branch 'master' into strip_ipv4_header 2025-02-11 10:11:18 +00:00
a3957273
bf36fe8143
Merge pull request #1866 from Adamkadaban/master
add offset field to 'Add Line Numbers' operation
2025-02-11 00:50:03 +00:00
a3957273
d3ee16f38b Disable flakey URL test 2025-02-11 00:49:14 +00:00
a3957273
41c5403700
Merge branch 'master' into master 2025-02-11 00:46:18 +00:00
a3957273
e1d3af26da
Merge pull request #1955 from max0x53/compress
Webpack compress with gzip and brotli
2025-02-11 00:43:36 +00:00
a3957273
5a7cb9e047
Merge branch 'master' into fix/generate-totp-issue-1964 2025-02-11 00:42:41 +00:00
a3957273
a41068e633
Merge branch 'master' into master 2025-02-11 00:40:26 +00:00
a3957273
bce04609a5
Merge branch 'master' into theme-auto-detection 2025-02-11 00:40:11 +00:00
a3957273
d4da81fa91
Merge branch 'master' into master 2025-02-11 00:39:40 +00:00
a3957273
d3e31890ae
Merge branch 'master' into strip_ipv4_header 2025-02-11 00:38:21 +00:00
a3957273
9d014aeaa5
Merge pull request #1898 from c65722/strip_tcp_header
Add Strip TCP header operation
2025-02-11 00:38:01 +00:00
a3957273
156de53dc1
Merge branch 'master' into strip_tcp_header 2025-02-11 00:27:38 +00:00
a3957273
9f2527d736
Merge branch 'master' into strip_ipv4_header 2025-02-11 00:27:19 +00:00
a3957273
7ecc235b31
Merge pull request #1900 from c65722/strip_udp_header
Add Strip UDP header operation
2025-02-11 00:26:59 +00:00
a3957273
51ed3b2fc1
Merge branch 'master' into strip_tcp_header 2025-02-11 00:26:52 +00:00
a3957273
306e29da76
Merge pull request #1972 from gchq/feature/detect-chromedriver
Automatically detect chrome driver version
2025-02-11 00:23:11 +00:00
a3957273
9cc84b1c62
Merge branch 'master' into feature/detect-chromedriver 2025-02-11 00:23:00 +00:00
a3957273
f02b3f22ad
Merge pull request #1936 from c65722/parse_tls_record
Add Parse TLS record operation
2025-02-11 00:22:12 +00:00
a3957273
e9b8163626
Merge pull request #1957 from RandomByte/jwt-sign/add-header-option
Add 'header' ingredient to JWT Sign operation
2025-02-11 00:13:56 +00:00
a3957273
20390ae08e
Merge pull request #1959 from simonarnell/patch-1
Corrected path to generateNodeIndex.mjs
2025-02-11 00:08:24 +00:00
a3957273
fcdcce7ee4
Merge pull request #1961 from GuilhermoReadonly/patch-1
Fix typo in description of JWT Sign recipe
2025-02-11 00:06:21 +00:00
a3957273
3d017d5f84 Add it to the correct file. 2025-02-11 00:02:39 +00:00
Alexander
5455061e15 Atomatically detect chrome driver version 2025-02-10 23:53:55 +00:00
a3957273
caa373c1be
Merge branch 'master' into master 2025-02-10 23:38:41 +00:00
a3957273
f4995dbc30
Merge pull request #1887 from robinsandhu/feature/parse-crl
Add operation for parsing X.509 CRLs
2025-02-10 23:35:58 +00:00
bartblaze
f14c423c64 Add Leet Speak
Not too many use cases, but something I thought of (and have seen in a few skiddie malware samples).

Will also resolve #1234
2025-02-05 18:34:59 +01:00
exactlyaron
6f63de81b1 style: fix linting 2025-01-23 11:46:01 +00:00
exactlyaron
75991321de tests: fix tests 2025-01-23 11:41:26 +00:00
exactlyaron
b560d74b8e tests: comment out Generate HOTP test 2025-01-23 11:28:24 +00:00
exactlyaron
90133e3f90 fix: refactor GenerateHOTP to use optauth 2025-01-23 11:28:13 +00:00
exactlyaron
672cb5dea4 fix: refactor GenerateTOTP to use optauth 2025-01-23 11:28:04 +00:00
exactlyaron
7eb9e08ad2 build(deps): use optauth instead of opt 2025-01-23 11:27:45 +00:00
exactlyaron
2007b26d57 build(deps): update otp 0.1.3 → 1.1.2 2025-01-23 00:25:59 +00:00
exactlyaron
e804555278 fix: refactor GenerateTOTP 2025-01-23 00:24:20 +00:00
Adamkadaban
6b75ba8903 fix bug where no input leads to error in console 2025-01-13 15:48:18 -05:00
Adam Hassan
54e559c5a6
Merge branch 'master' into master 2025-01-13 12:24:45 -05:00
Guilhem Radonde
cc7cc7f8fd
misc: typo 2025-01-10 09:32:41 +01:00
Simon Arnell
6a92f922cb
corrected path to generateNodeIndex.mjs 2025-01-09 12:32:57 +02:00
Merlin Beutlberger
71c8c8aac0 Add 'header' ingredient to JWT Sign operation
Expose the 'header' option of the jsonwebtoken module [1] as an ingredient.
This allows for adding and overwriting JWT header fields such as 'type' or 'kid'.

[1]: https://github.com/auth0/node-jsonwebtoken?tab=readme-ov-file#usage
2025-01-04 18:31:24 +01:00
Max S
304266020d Webpack compress with gzip and brotli 2024-12-28 17:20:15 +00:00
Vijay Soni
02f45e545d
Merge branch 'master' into theme-auto-detection 2024-12-27 13:41:39 +05:30
Robin Sandhu
3deb121043
Merge branch 'master' into feature/parse-crl 2024-12-01 16:04:01 +00:00
k3a.ch
bab0a7ffed fixed typo 2024-11-30 20:57:56 +01:00
c65722
1fcc365d9e
Add Parse TLS record operation 2024-11-02 16:58:19 +00:00
Pascal Burri
b92c1e7da0 fixed code format, added tests 2024-10-27 22:36:53 +01:00
k3ach
0c6c45b152
Merge branch 'gchq:master' into master 2024-10-26 15:50:30 +02:00
Pascal Burri
802c576c60 Updated luhn checksum to to work with base 2-36 2024-10-26 15:49:24 +02:00
n1474335
3822c6c520
10.19.4 2024-10-23 16:10:44 +01:00
n1474335
47c85a105d
Added message format arg to RSA Verify operation 2024-10-23 16:02:08 +01:00
n1474335
d3adfc7c3e
Updated chromedriver 2024-10-23 15:53:07 +01:00
n1474335
270a333179
10.19.3 2024-10-23 14:03:18 +01:00
n1474335
895a929925
Fixed RSA Sign and Verify character encodings 2024-10-23 14:03:09 +01:00
Vijay Soni
e484d426fe automatically theme mode based on user preference
Related to #1901

Implemented automatic dark theme change based on user preference using the `prefers-color-scheme` media query.
2024-10-07 01:28:46 +05:30
Oshawk
4c6dcf182d Merge remote-tracking branch 'upstream/master' into take-nth-bytes 2024-09-25 18:57:20 +01:00
Oshawk
4bb1e335ea Merge remote-tracking branch 'upstream/master' into drop-nth-bytes 2024-09-25 18:14:57 +01:00
Dan Flack
ae9054dc37 Remove highlighting and correct one module mismatch 2024-09-22 18:58:36 +02:00
Dan Flack
f61bdf06c6 Additional linter corrections 2024-09-21 12:00:37 +02:00
Dan Flack
0f16fa0ce1 Updates for linter 2024-09-21 11:47:01 +02:00
flackjacket95
84ce8e6f30 Add tests 2024-09-21 11:40:57 +02:00
Dan Flack
9eff9e5018 Set default paramater indices 2024-09-21 11:40:32 +02:00
Dan Flack
857d3b6d17 Fully functional encrypt/decrypt 2024-09-21 11:40:32 +02:00
Dan Flack
54cfb17145 Initial migration to library; add decryption operation 2024-09-21 11:40:32 +02:00
Dan Flack
99ba6b487c Add comments, docs, and some additional restructuring 2024-09-21 11:40:32 +02:00
flakjacket
a1647b02cb Initial SM2 changes 2024-09-21 11:40:12 +02:00
jb30795
b15322467b
Merge branch 'master' into master 2024-09-20 10:59:28 +01:00
jb30795
9229fe9ac7 Remove console.log statement 2024-09-20 10:49:13 +01:00
jb30795
488c458720 updates to operation and addition of more tests 2024-09-20 10:46:09 +01:00
Francisco Pombal
784b2631a8 fix: DES/Triple DES - failing tests 2024-09-16 15:44:28 +01:00
Francisco Pombal
3eb1af0278 fix: DES/Triple DES - misleading error messages
Fixes https://github.com/gchq/CyberChef/issues/1843.
2024-09-16 15:36:57 +01:00
Francisco Pombal
7e5eb01a5e fix: ROT13 - shifting numbers by negative amounts
Fixes https://github.com/gchq/CyberChef/issues/1886.
2024-09-15 23:51:48 +01:00
Francisco Pombal
1fce8e5112 fix: Blowfish - ignore IV length in ECB mode
Fixes https://github.com/gchq/CyberChef/issues/1895.
2024-09-15 22:21:10 +01:00
c65722
748379f0b0
Add Strip TCP header operation 2024-09-15 18:49:17 +01:00
c65722
da74d9b22d
Add Strip UDP header operation 2024-09-15 18:14:21 +01:00
c65722
738e6feda0
Add Strip IPv4 header operation 2024-09-15 17:46:47 +01:00
Robin Sandhu
1fde2fba29
Add basic tests for Parse X.509 CRL operations 2024-08-25 14:28:55 +01:00
Robin Sandhu
a50d4d63eb Format issuerAltName CRL extension 2024-08-25 14:15:00 +01:00
Robin Sandhu
dbc90090cf
Add support for multiple input format
i.e. DER Hex, Base64, Raw
2024-08-25 05:47:29 +01:00
Robin Sandhu
e65869a10b
Add operation for parsing X.509 CRLs
Signed-off-by: Robin Sandhu <er.robinsandhu@gmail.com>
2024-08-25 05:02:59 +01:00
Computer Network Investigation
7877a0d7d0
Merge branch 'master' into x509_fingerprints 2024-08-15 18:03:58 +02:00
n1474335
d635cca210
10.19.2 2024-08-14 15:35:17 +01:00
n1474335
0e82e4b7c6
Updated chromedriver 2024-08-14 15:35:12 +01:00
n1474335
5f88ae44ec
10.19.1 2024-08-14 15:22:06 +01:00
n1474335
7a5225c961
Fixed JA4 version fallback value 2024-08-14 15:21:57 +01:00
jb30795
a80b1568ac Lint errors 2024-08-09 14:32:31 +01:00
jb30795
a616e46b50 Handling of /24 ranges 2024-08-09 14:28:50 +01:00
jb30795
752ce789c2 Updating tests 2024-08-07 21:19:13 +01:00
jb30795
660069865a Updating description 2024-08-07 21:02:00 +01:00
jb30795
9169254fff minor wording update 2024-08-07 19:13:44 +01:00
jb30795
e12b00485e Merge branch 'master' of ssh://github.com/jb30795/CyberChef-IPv6-Transition 2024-08-07 18:50:13 +01:00
jb30795
51a07a27db Formatting updates 2024-08-07 18:49:58 +01:00
jb30795
c8c9e572a6
Merge branch 'master' into master 2024-08-07 18:42:08 +01:00
jb30795
7fb4824cd6 Merge branch 'master' of ssh://github.com/jb30795/CyberChef-IPv6-Transition 2024-08-07 18:39:08 +01:00
jb30795
5e763b86dc Option to remove headers and ignore blank input rows 2024-08-07 18:17:00 +01:00
jb30795
b090ce0428 Update to accept multiple inputs 2024-08-07 17:06:15 +01:00
Adamkadaban
3dddb516c9 add offset field to 'Add Line Numbers' operation 2024-07-27 20:06:18 -07:00
JSCU-CNI
fb3c36af85 Add fingerprints to 'Parse X.509 certificate' operation 2024-07-24 14:23:40 +02:00
n1474335
a477f47aec
Merge branch 'master' of github.com:gchq/CyberChef 2024-06-21 14:14:59 +01:00
n1474335
965570d250
10.18.9 2024-06-21 14:12:36 +01:00
n1474335
ab37c1e562
Fixed Optical Character Recognition and added tests 2024-06-21 14:12:28 +01:00
İlteriş Yağıztegin Eroğlu
edd22372d8 feat(Modhex): Introduce basic Modhex conversion
Signed-off-by: İlteriş Yağıztegin Eroğlu <ilteris@asenkron.com.tr>
2024-06-17 23:58:58 +00:00
jb30795
66d3b6e9ed
Merge branch 'master' into master 2024-04-08 11:06:45 +01:00
jb30795
036f80d734 indentation 2024-04-04 17:00:14 +01:00
jb30795
3ca4c2fd45 Initial commit for new IPv6 Transition operation 2024-04-04 15:54:43 +01:00
ccarpo
cc21fe18ca fixed typo. 2023-11-21 09:24:54 +01:00
ccarpo
4255d8d543 Renamed JSON to Yaml to Beautify JSON 2023-11-21 09:19:58 +01:00
ccarpo
7353315baa Renamed JSON to Yaml to Beautify JSON 2023-11-21 08:56:20 +01:00
zhzy0077
721061d054 fix typo. 2023-07-25 14:48:03 +08:00
zhzy0077
d2da11c79a Support jq. 2023-07-25 14:42:43 +08:00
Brunon Blok
c0e84dcd50 change comments 2023-04-09 19:06:59 +00:00
Brunon Blok
15b426ebb6 clean up code formatting and fix missing entries 2023-04-06 21:03:46 +00:00
Brunon Blok
bf1e708a4c added PHP Serialize operation 2023-04-06 20:32:50 +00:00
Philipp Arnold
23763363ba Added a JSON to YAML and a YALM to JSON operation 2021-12-10 23:22:57 +01:00
Oshawk
518b336431 Add tests to index
Added tests to index.
2019-10-21 21:01:33 +01:00
Oshawk
b125f82784 Add tests
Added tests for 'Drop nth bytes' operation.
2019-10-21 20:59:04 +01:00
Oshawk
30349dbcb9 Add operation
Added 'Drop nth bytes' operation.
2019-10-21 20:44:57 +01:00
Oshawk
02f6537973 Add tests
Added tests for the 'Take nth byte' operation.
2019-10-21 20:16:14 +01:00
Oshawk
502f126986 Fix linting
Fixed linting.
2019-10-21 20:15:45 +01:00
Oshawk
7c7d1823ca Fix formatting issue
Fixed issue where new lines were truncated.
2019-10-21 19:53:57 +01:00
Oshawk
ce6d38860d Add operation
Added 'Take nth bytes' operation.
2019-10-21 19:39:01 +01:00
93 changed files with 17353 additions and 3956 deletions

17
.cspell.json Normal file
View file

@ -0,0 +1,17 @@
{
"version": "0.2",
"language": "en,en-gb",
"words": [],
"dictionaries": [
"npm",
"softwareTerms",
"node",
"html",
"css",
"bash",
"en-gb",
"misc"
],
"ignorePaths": ["package.json", "package-lock.json", "node_modules"]
}

View file

@ -19,6 +19,7 @@ jobs:
- name: Install - name: Install
run: | run: |
export DETECT_CHROMEDRIVER_VERSION=true
npm install npm install
npm run setheapsize npm run setheapsize

View file

@ -18,6 +18,7 @@ jobs:
- name: Install - name: Install
run: | run: |
export DETECT_CHROMEDRIVER_VERSION=true
npm install npm install
npm run setheapsize npm run setheapsize

View file

@ -25,6 +25,7 @@ jobs:
- name: Install - name: Install
run: | run: |
export DETECT_CHROMEDRIVER_VERSION=true
npm ci npm ci
npm run setheapsize npm run setheapsize
@ -61,12 +62,22 @@ jobs:
tags: ${{ steps.image-metadata.outputs.tags }} tags: ${{ steps.image-metadata.outputs.tags }}
labels: ${{ steps.image-metadata.outputs.labels }} labels: ${{ steps.image-metadata.outputs.labels }}
containerfiles: ./Dockerfile containerfiles: ./Dockerfile
platforms: linux/amd64 platforms: linux/amd64,linux/arm64
oci: true oci: true
# enable build layer caching between platforms
layers: true
# Webpack seems to use a lot of open files, increase the max open file limit to accomodate. # Webpack seems to use a lot of open files, increase the max open file limit to accomodate.
extra-args: | extra-args: |
--ulimit nofile=10000 --ulimit nofile=10000
- name: Publish to GHCR
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
- name: Upload Release Assets - name: Upload Release Assets
id: upload-release-assets id: upload-release-assets
@ -81,13 +92,6 @@ jobs:
- name: Publish to NPM - name: Publish to NPM
uses: JS-DevTools/npm-publish@v1 uses: JS-DevTools/npm-publish@v1
if: false
with: with:
token: ${{ secrets.NPM_TOKEN }} token: ${{ secrets.NPM_TOKEN }}
- name: Publish to GHCR
uses: redhat-actions/push-to-registry@v2
with:
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}

View file

@ -1,9 +1,36 @@
FROM node:18-alpine AS build #####################################
# Build the app to a static website #
#####################################
# Modifier --platform=$BUILDPLATFORM limits the platform to "BUILDPLATFORM" during buildx multi-platform builds
# This is because npm "chromedriver" package is not compatiable with all platforms
# For more info see: https://docs.docker.com/build/building/multi-platform/#cross-compilation
FROM --platform=$BUILDPLATFORM node:18-alpine AS builder
WORKDIR /app
COPY package.json .
COPY package-lock.json .
# Install dependencies
# --ignore-scripts prevents postinstall script (which runs grunt) as it depends on files other than package.json
RUN npm ci --ignore-scripts
# Copy files needed for postinstall and build
COPY . . COPY . .
RUN npm ci
# npm postinstall runs grunt, which depends on files other than package.json
RUN npm run postinstall
# Build the app
RUN npm run build RUN npm run build
FROM nginx:1.25-alpine3.18 AS cyberchef #########################################
# Package static build files into nginx #
#########################################
# We are using Github Actions: redhat-actions/buildah-build@v2 which needs manual selection of arch in base image
# Remove TARGETARCH if docker buildx is supported in the CI release as --platform=$TARGETPLATFORM will be automatically set
ARG TARGETARCH
ARG TARGETPLATFORM
FROM ${TARGETARCH}/nginx:stable-alpine AS cyberchef
COPY --from=build ./build/prod /usr/share/nginx/html/ COPY --from=builder /app/build/prod /usr/share/nginx/html/

9603
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "cyberchef", "name": "cyberchef",
"version": "10.19.0", "version": "10.19.4",
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
"author": "n1474335 <n1474335@gmail.com>", "author": "n1474335 <n1474335@gmail.com>",
"homepage": "https://gchq.github.io/CyberChef", "homepage": "https://gchq.github.io/CyberChef",
@ -55,11 +55,13 @@
"babel-plugin-dynamic-import-node": "^2.3.3", "babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-builtin-extend": "1.1.2", "babel-plugin-transform-builtin-extend": "1.1.2",
"base64-loader": "^1.0.0", "base64-loader": "^1.0.0",
"chromedriver": "^125.0.3", "chromedriver": "^130.0.0",
"cli-progress": "^3.12.0", "cli-progress": "^3.12.0",
"colors": "^1.4.0", "colors": "^1.4.0",
"compression-webpack-plugin": "^11.1.0",
"copy-webpack-plugin": "^12.0.2", "copy-webpack-plugin": "^12.0.2",
"core-js": "^3.37.1", "core-js": "^3.37.1",
"cspell": "^8.17.3",
"css-loader": "7.1.2", "css-loader": "7.1.2",
"eslint": "^9.4.0", "eslint": "^9.4.0",
"eslint-plugin-jsdoc": "^48.2.9", "eslint-plugin-jsdoc": "^48.2.9",
@ -121,6 +123,7 @@
"d3": "7.9.0", "d3": "7.9.0",
"d3-hexbin": "^0.2.2", "d3-hexbin": "^0.2.2",
"diff": "^5.2.0", "diff": "^5.2.0",
"dompurify": "^3.2.5",
"es6-promisify": "^7.0.0", "es6-promisify": "^7.0.0",
"escodegen": "^2.1.0", "escodegen": "^2.1.0",
"esprima": "^4.0.1", "esprima": "^4.0.1",
@ -132,8 +135,8 @@
"highlight.js": "^11.9.0", "highlight.js": "^11.9.0",
"ieee754": "^1.2.1", "ieee754": "^1.2.1",
"jimp": "^0.22.12", "jimp": "^0.22.12",
"jq-web": "^0.5.1",
"jquery": "3.7.1", "jquery": "3.7.1",
"js-crc": "^0.2.0",
"js-sha3": "^0.9.3", "js-sha3": "^0.9.3",
"jsesc": "^3.0.2", "jsesc": "^3.0.2",
"json5": "^2.2.3", "json5": "^2.2.3",
@ -159,7 +162,7 @@
"notepack.io": "^3.0.1", "notepack.io": "^3.0.1",
"ntlm": "^0.1.3", "ntlm": "^0.1.3",
"nwmatcher": "^1.4.4", "nwmatcher": "^1.4.4",
"otp": "0.1.3", "otpauth": "9.3.6",
"path": "^0.12.7", "path": "^0.12.7",
"popper.js": "^1.16.1", "popper.js": "^1.16.1",
"process": "^0.11.10", "process": "^0.11.10",
@ -192,6 +195,7 @@
"testui": "npx grunt testui", "testui": "npx grunt testui",
"testuidev": "npx nightwatch --env=dev", "testuidev": "npx nightwatch --env=dev",
"lint": "npx grunt lint", "lint": "npx grunt lint",
"lint:grammar": "cspell ./src",
"postinstall": "npx grunt exec:fixCryptoApiImports && npx grunt exec:fixSnackbarMarkup && npx grunt exec:fixJimpModule", "postinstall": "npx grunt exec:fixCryptoApiImports && npx grunt exec:fixSnackbarMarkup && npx grunt exec:fixJimpModule",
"newop": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newOperation.mjs", "newop": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newOperation.mjs",
"minor": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newMinorVersion.mjs", "minor": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newMinorVersion.mjs",

View file

@ -72,9 +72,14 @@
"Avro to JSON", "Avro to JSON",
"CBOR Encode", "CBOR Encode",
"CBOR Decode", "CBOR Decode",
"YAML to JSON",
"JSON to YAML",
"Caret/M-decode", "Caret/M-decode",
"Rison Encode", "Rison Encode",
"Rison Decode" "Rison Decode",
"To Modhex",
"From Modhex",
"MIME Decoding"
] ]
}, },
{ {
@ -164,6 +169,7 @@
"name": "Public Key", "name": "Public Key",
"ops": [ "ops": [
"Parse X.509 certificate", "Parse X.509 certificate",
"Parse X.509 CRL",
"Parse ASN.1 hex string", "Parse ASN.1 hex string",
"PEM to Hex", "PEM to Hex",
"Hex to PEM", "Hex to PEM",
@ -189,7 +195,9 @@
"Parse SSH Host Key", "Parse SSH Host Key",
"Parse CSR", "Parse CSR",
"Public Key from Certificate", "Public Key from Certificate",
"Public Key from Private Key" "Public Key from Private Key",
"SM2 Encrypt",
"SM2 Decrypt"
] ]
}, },
{ {
@ -233,9 +241,14 @@
"Parse User Agent", "Parse User Agent",
"Parse IP range", "Parse IP range",
"Parse IPv6 address", "Parse IPv6 address",
"IPv6 Transition Addresses",
"Parse IPv4 header", "Parse IPv4 header",
"Strip IPv4 header",
"Parse TCP", "Parse TCP",
"Strip TCP header",
"Parse TLS record",
"Parse UDP", "Parse UDP",
"Strip UDP header",
"Parse SSH Host Key", "Parse SSH Host Key",
"Parse URI", "Parse URI",
"URL Encode", "URL Encode",
@ -268,7 +281,8 @@
"Unicode Text Format", "Unicode Text Format",
"Remove Diacritics", "Remove Diacritics",
"Unescape Unicode Characters", "Unescape Unicode Characters",
"Convert to NATO alphabet" "Convert to NATO alphabet",
"Convert Leet Speak"
] ]
}, },
{ {
@ -320,7 +334,9 @@
"Unescape string", "Unescape string",
"Pseudo-Random Number Generator", "Pseudo-Random Number Generator",
"Sleep", "Sleep",
"File Tree" "File Tree",
"Take nth bytes",
"Drop nth bytes"
] ]
}, },
{ {
@ -429,9 +445,7 @@
"Fletcher-64 Checksum", "Fletcher-64 Checksum",
"Adler-32 Checksum", "Adler-32 Checksum",
"Luhn Checksum", "Luhn Checksum",
"CRC-8 Checksum", "CRC Checksum",
"CRC-16 Checksum",
"CRC-32 Checksum",
"TCP/IP Checksum" "TCP/IP Checksum"
] ]
}, },
@ -453,8 +467,10 @@
"CSS Minify", "CSS Minify",
"XPath expression", "XPath expression",
"JPath expression", "JPath expression",
"Jq",
"CSS selector", "CSS selector",
"PHP Deserialize", "PHP Deserialize",
"PHP Serialize",
"Microsoft Script Decoder", "Microsoft Script Decoder",
"Strip HTML tags", "Strip HTML tags",
"Diff", "Diff",

23
src/core/lib/Base32.mjs Normal file
View file

@ -0,0 +1,23 @@
// import Utils from "../Utils.mjs";
/**
* Base32 resources.
*
* @author Peter C-S [petercs@purelymail.com]
* @license Apache-2.0
*/
/**
* Base32 alphabets.
*/
export const ALPHABET_OPTIONS = [
{
name: "Standard", // https://www.rfc-editor.org/rfc/rfc4648#section-6
value: "A-Z2-7=",
},
{
name: "Hex Extended", // https://www.rfc-editor.org/rfc/rfc4648#section-7
value: "0-9A-V=",
},
];

View file

@ -62,3 +62,9 @@ export const URL_REGEX = new RegExp(protocol + hostname + "(?:" + port + ")?(?:"
* Domain name regular expression * Domain name regular expression
*/ */
export const DOMAIN_REGEX = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/ig; export const DOMAIN_REGEX = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/ig;
/**
* DMARC Domain name regular expression
*/
export const DMARC_DOMAIN_REGEX = /\b((?=[a-z0-9_-]{1,63}\.)(xn--)?[a-z0-9_]+(-[a-z0-9_]+)*\.)+[a-z]{2,63}\b/ig;

View file

@ -44,7 +44,7 @@ export function toJA4(bytes) {
the TLS version is the value of the Protocol Version. Handshake version (located at the top of the packet) the TLS version is the value of the Protocol Version. Handshake version (located at the top of the packet)
should be ignored. should be ignored.
*/ */
let version = tlsr.version.value; let version = tlsr.handshake.value.helloVersion.value;
for (const ext of tlsr.handshake.value.extensions.value) { for (const ext of tlsr.handshake.value.extensions.value) {
if (ext.type.value === "supported_versions") { if (ext.type.value === "supported_versions") {
version = parseHighestSupportedVersion(ext.value.data); version = parseHighestSupportedVersion(ext.value.data);
@ -189,7 +189,7 @@ export function toJA4S(bytes) {
the TLS version is the value of the Protocol Version. Handshake version (located at the top of the packet) the TLS version is the value of the Protocol Version. Handshake version (located at the top of the packet)
should be ignored. should be ignored.
*/ */
let version = tlsr.version.value; let version = tlsr.handshake.value.helloVersion.value;
for (const ext of tlsr.handshake.value.extensions.value) { for (const ext of tlsr.handshake.value.extensions.value) {
if (ext.type.value === "supported_versions") { if (ext.type.value === "supported_versions") {
version = parseHighestSupportedVersion(ext.value.data); version = parseHighestSupportedVersion(ext.value.data);

165
src/core/lib/Modhex.mjs Normal file
View file

@ -0,0 +1,165 @@
/**
* @author linuxgemini [ilteris@asenkron.com.tr]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { fromHex, toHex } from "./Hex.mjs";
/**
* Modhex alphabet.
*/
const MODHEX_ALPHABET = "cbdefghijklnrtuv";
/**
* Modhex alphabet map.
*/
const MODHEX_ALPHABET_MAP = MODHEX_ALPHABET.split("");
/**
* Hex alphabet to substitute Modhex.
*/
const HEX_ALPHABET = "0123456789abcdef";
/**
* Hex alphabet map to substitute Modhex.
*/
const HEX_ALPHABET_MAP = HEX_ALPHABET.split("");
/**
* Convert a byte array into a modhex string.
*
* @param {byteArray|Uint8Array|ArrayBuffer} data
* @param {string} [delim=" "]
* @param {number} [padding=2]
* @returns {string}
*
* @example
* // returns "cl bf bu"
* toModhex([10,20,30]);
*
* // returns "cl:bf:bu"
* toModhex([10,20,30], ":");
*/
export function toModhex(data, delim=" ", padding=2, extraDelim="", lineSize=0) {
if (!data) return "";
if (data instanceof ArrayBuffer) data = new Uint8Array(data);
const regularHexString = toHex(data, "", padding, "", 0);
let modhexString = "";
for (const letter of regularHexString.split("")) {
modhexString += MODHEX_ALPHABET_MAP[HEX_ALPHABET_MAP.indexOf(letter)];
}
let output = "";
const groupingRegexp = new RegExp(`.{1,${padding}}`, "g");
const groupedModhex = modhexString.match(groupingRegexp);
for (let i = 0; i < groupedModhex.length; i++) {
const group = groupedModhex[i];
output += group + delim;
if (extraDelim) {
output += extraDelim;
}
// Add LF after each lineSize amount of bytes but not at the end
if ((i !== groupedModhex.length - 1) && ((i + 1) % lineSize === 0)) {
output += "\n";
}
}
// Remove the extraDelim at the end (if there is one)
// and remove the delim at the end, but if it's prepended there's nothing to remove
const rTruncLen = extraDelim.length + delim.length;
if (rTruncLen) {
// If rTruncLen === 0 then output.slice(0,0) will be returned, which is nothing
return output.slice(0, -rTruncLen);
} else {
return output;
}
}
/**
* Convert a byte array into a modhex string as efficiently as possible with no options.
*
* @param {byteArray|Uint8Array|ArrayBuffer} data
* @returns {string}
*
* @example
* // returns "clbfbu"
* toModhexFast([10,20,30]);
*/
export function toModhexFast(data) {
if (!data) return "";
if (data instanceof ArrayBuffer) data = new Uint8Array(data);
const output = [];
for (let i = 0; i < data.length; i++) {
output.push(MODHEX_ALPHABET_MAP[(data[i] >> 4) & 0xf]);
output.push(MODHEX_ALPHABET_MAP[data[i] & 0xf]);
}
return output.join("");
}
/**
* Convert a modhex string into a byte array.
*
* @param {string} data
* @param {string} [delim]
* @param {number} [byteLen=2]
* @returns {byteArray}
*
* @example
* // returns [10,20,30]
* fromModhex("cl bf bu");
*
* // returns [10,20,30]
* fromModhex("cl:bf:bu", "Colon");
*/
export function fromModhex(data, delim="Auto", byteLen=2) {
if (byteLen < 1 || Math.round(byteLen) !== byteLen)
throw new OperationError("Byte length must be a positive integer");
// The `.replace(/\s/g, "")` an interesting workaround: Hex "multiline" tests aren't actually
// multiline. Tests for Modhex fixes that, thus exposing the issue.
data = data.toLowerCase().replace(/\s/g, "");
if (delim !== "None") {
const delimRegex = delim === "Auto" ? /[^cbdefghijklnrtuv]/gi : Utils.regexRep(delim);
data = data.split(delimRegex);
} else {
data = [data];
}
let regularHexString = "";
for (let i = 0; i < data.length; i++) {
for (const letter of data[i].split("")) {
regularHexString += HEX_ALPHABET_MAP[MODHEX_ALPHABET_MAP.indexOf(letter)];
}
}
const output = fromHex(regularHexString, "None", byteLen);
return output;
}
/**
* To Modhex delimiters.
*/
export const TO_MODHEX_DELIM_OPTIONS = ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "None"];
/**
* From Modhex delimiters.
*/
export const FROM_MODHEX_DELIM_OPTIONS = ["Auto"].concat(TO_MODHEX_DELIM_OPTIONS);

View file

@ -26,6 +26,9 @@ export function objToTable(obj, nested=false) {
</tr>`; </tr>`;
for (const key in obj) { for (const key in obj) {
if (typeof obj[key] === "function")
continue;
html += `<tr><td style='word-wrap: break-word'>${key}</td>`; html += `<tr><td style='word-wrap: break-word'>${key}</td>`;
if (typeof obj[key] === "object") if (typeof obj[key] === "object")
html += `<td style='padding: 0'>${objToTable(obj[key], true)}</td>`; html += `<td style='padding: 0'>${objToTable(obj[key], true)}</td>`;

258
src/core/lib/SM2.mjs Normal file
View file

@ -0,0 +1,258 @@
/**
* Utilities and operations utilized for SM2 encryption and decryption
* @author flakjacket95 [dflack95@gmail.com]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
import { fromHex } from "../lib/Hex.mjs";
import Utils from "../Utils.mjs";
import Sm3 from "crypto-api/src/hasher/sm3.mjs";
import {toHex} from "crypto-api/src/encoder/hex.mjs";
import r from "jsrsasign";
/**
* SM2 Class for encryption and decryption operations
*/
export class SM2 {
/**
* Constructor for SM2 class; sets up with the curve and the output format as specified in user args
*
* @param {*} curve
* @param {*} format
*/
constructor(curve, format) {
this.ecParams = null;
this.rng = new r.SecureRandom();
/*
For any additional curve definitions utilized by SM2, add another block like the below for that curve, then add the curve name to the Curve selection dropdown
*/
r.crypto.ECParameterDB.regist(
"sm2p256v1", // name / p = 2**256 - 2**224 - 2**96 + 2**64 - 1
256,
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", // p
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", // a
"28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", // b
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", // n
"1", // h
"32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", // gx
"BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", // gy
[]
); // alias
this.ecParams = r.crypto.ECParameterDB.getByName(curve);
this.format = format;
}
/**
* Set the public key coordinates for the SM2 class
*
* @param {string} publicKeyX
* @param {string} publicKeyY
*/
setPublicKey(publicKeyX, publicKeyY) {
/*
* TODO: This needs some additional length validation; and checking for errors in the decoding process
* TODO: Can probably support other public key encoding methods here as well in the future
*/
this.publicKey = this.ecParams.curve.decodePointHex("04" + publicKeyX + publicKeyY);
if (this.publicKey.isInfinity()) {
throw new OperationError("Invalid Public Key");
}
}
/**
* Set the private key value for the SM2 class
*
* @param {string} privateKey
*/
setPrivateKey(privateKeyHex) {
this.privateKey = new r.BigInteger(privateKeyHex, 16);
}
/**
* Main encryption function; takes user input, processes encryption and returns the result in hex (with the components arranged as configured by the user args)
*
* @param {*} input
* @returns {string}
*/
encrypt(input) {
const G = this.ecParams.G;
/*
* Compute a new, random public key along the same elliptic curve to form the starting point for our encryption process (record the resulting X and Y as hex to provide as part of the operation output)
* k: Randomly generated BigInteger
* c1: Result of dotting our curve generator point `G` with the value of `k`
*/
const k = this.generatePublicKey();
const c1 = G.multiply(k);
const [hexC1X, hexC1Y] = this.getPointAsHex(c1);
/*
* Compute p2 (secret) using the public key, and the chosen k value above
*/
const p2 = this.publicKey.multiply(k);
/*
* Compute the C3 SM3 hash before we transform the array
*/
const c3 = this.c3(p2, input);
/*
* Genreate a proper length encryption key, XOR iteratively, and convert newly encrypted data to hex
*/
const key = this.kdf(p2, input.byteLength);
for (let i = 0; i < input.byteLength; i++) {
input[i] ^= Utils.ord(key[i]);
}
const c2 = Buffer.from(input).toString("hex");
/*
* Check user input specs; order the output components as selected
*/
if (this.format === "C1C3C2") {
return hexC1X + hexC1Y + c3 + c2;
} else {
return hexC1X + hexC1Y + c2 + c3;
}
}
/**
* Function to decrypt an SM2 encrypted message
*
* @param {*} input
*/
decrypt(input) {
const c1X = input.slice(0, 64);
const c1Y = input.slice(64, 128);
let c3 = "";
let c2 = "";
if (this.format === "C1C3C2") {
c3 = input.slice(128, 192);
c2 = input.slice(192);
} else {
c2 = input.slice(128, -64);
c3 = input.slice(-64);
}
c2 = Uint8Array.from(fromHex(c2));
const c1 = this.ecParams.curve.decodePointHex("04" + c1X + c1Y);
/*
* Compute the p2 (secret) value by taking the C1 point provided in the encrypted package, and multiplying by the private k value
*/
const p2 = c1.multiply(this.privateKey);
/*
* Similar to encryption; compute sufficient length key material and XOR the input data to recover the original message
*/
const key = this.kdf(p2, c2.byteLength);
for (let i = 0; i < c2.byteLength; i++) {
c2[i] ^= Utils.ord(key[i]);
}
const check = this.c3(p2, c2);
if (check === c3) {
return c2.buffer;
} else {
throw new OperationError("Decryption Error -- Computed Hashes Do Not Match");
}
}
/**
* Generates a large random number
*
* @param {*} limit
* @returns
*/
getBigRandom(limit) {
return new r.BigInteger(limit.bitLength(), this.rng)
.mod(limit.subtract(r.BigInteger.ONE))
.add(r.BigInteger.ONE);
}
/**
* Helper function for generating a large random K number; utilized for generating our initial C1 point
* TODO: Do we need to do any sort of validation on the resulting k values?
*
* @returns {BigInteger}
*/
generatePublicKey() {
const n = this.ecParams.n;
const k = this.getBigRandom(n);
return k;
}
/**
* SM2 Key Derivation Function (KDF); Takes P2 point, and generates a key material stream large enough to encrypt all of the input data
*
* @param {*} p2
* @param {*} len
* @returns {string}
*/
kdf(p2, len) {
const [hX, hY] = this.getPointAsHex(p2);
const total = Math.ceil(len / 32) + 1;
let cnt = 1;
let keyMaterial = "";
while (cnt < total) {
const num = Utils.intToByteArray(cnt, 4, "big");
const overall = fromHex(hX).concat(fromHex(hY)).concat(num);
keyMaterial += this.sm3(overall);
cnt++;
}
return keyMaterial;
}
/**
* Calculates the C3 component of our final encrypted payload; which is the SM3 hash of the P2 point and the original, unencrypted input data
*
* @param {*} p2
* @param {*} input
* @returns {string}
*/
c3(p2, input) {
const [hX, hY] = this.getPointAsHex(p2);
const overall = fromHex(hX).concat(Array.from(input)).concat(fromHex(hY));
return toHex(this.sm3(overall));
}
/**
* SM3 setup helper function; takes input data as an array, processes the hash and returns the result
*
* @param {*} data
* @returns {string}
*/
sm3(data) {
const hashData = Utils.arrayBufferToStr(Uint8Array.from(data).buffer, false);
const hasher = new Sm3();
hasher.update(hashData);
return hasher.finalize();
}
/**
* Utility function, returns an elliptic curve points X and Y values as hex;
*
* @param {EcPointFp} point
* @returns {[]}
*/
getPointAsHex(point) {
const biX = point.getX().toBigInteger();
const biY = point.getY().toBigInteger();
const charlen = this.ecParams.keycharlen;
const hX = ("0000000000" + biX.toString(16)).slice(- charlen);
const hY = ("0000000000" + biY.toString(16)).slice(- charlen);
return [hX, hY];
}
}

View file

@ -112,7 +112,7 @@ class AESDecrypt extends Operation {
run(input, args) { run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option), const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option), iv = Utils.convertToByteString(args[1].string, args[1].option),
mode = args[2].substring(0, 3), mode = args[2].split("/")[0],
noPadding = args[2].endsWith("NoPadding"), noPadding = args[2].endsWith("NoPadding"),
inputType = args[3], inputType = args[3],
outputType = args[4], outputType = args[4],

View file

@ -66,6 +66,14 @@ class AESEncrypt extends Operation {
{ {
name: "ECB", name: "ECB",
off: [5] off: [5]
},
{
name: "CBC/NoPadding",
off: [5]
},
{
name: "ECB/NoPadding",
off: [5]
} }
] ]
}, },
@ -98,7 +106,8 @@ class AESEncrypt extends Operation {
run(input, args) { run(input, args) {
const key = Utils.convertToByteString(args[0].string, args[0].option), const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option), iv = Utils.convertToByteString(args[1].string, args[1].option),
mode = args[2], mode = args[2].split("/")[0],
noPadding = args[2].endsWith("NoPadding"),
inputType = args[3], inputType = args[3],
outputType = args[4], outputType = args[4],
aad = Utils.convertToByteString(args[5].string, args[5].option); aad = Utils.convertToByteString(args[5].string, args[5].option);
@ -114,11 +123,20 @@ The following algorithms will be used based on the size of the key:
input = Utils.convertToByteString(input, inputType); input = Utils.convertToByteString(input, inputType);
// Handle NoPadding modes
if (noPadding && input.length % 16 !== 0) {
throw new OperationError("Input length must be a multiple of 16 bytes for NoPadding modes.");
}
const cipher = forge.cipher.createCipher("AES-" + mode, key); const cipher = forge.cipher.createCipher("AES-" + mode, key);
cipher.start({ cipher.start({
iv: iv, iv: iv,
additionalData: mode === "GCM" ? aad : undefined additionalData: mode === "GCM" ? aad : undefined
}); });
if (noPadding) {
cipher.mode.pad = function(output, options) {
return true;
};
}
cipher.update(forge.util.createBuffer(input)); cipher.update(forge.util.createBuffer(input));
cipher.finish(); cipher.finish();

View file

@ -22,7 +22,13 @@ class AddLineNumbers extends Operation {
this.description = "Adds line numbers to the output."; this.description = "Adds line numbers to the output.";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = []; this.args = [
{
"name": "Offset",
"type": "number",
"value": 0
}
];
} }
/** /**
@ -33,10 +39,11 @@ class AddLineNumbers extends Operation {
run(input, args) { run(input, args) {
const lines = input.split("\n"), const lines = input.split("\n"),
width = lines.length.toString().length; width = lines.length.toString().length;
const offset = args[0] ? parseInt(args[0], 10) : 0;
let output = ""; let output = "";
for (let n = 0; n < lines.length; n++) { for (let n = 0; n < lines.length; n++) {
output += (n+1).toString().padStart(width, " ") + " " + lines[n] + "\n"; output += (n+1+offset).toString().padStart(width, " ") + " " + lines[n] + "\n";
} }
return output.slice(0, output.length-1); return output.slice(0, output.length-1);
} }

View file

@ -76,8 +76,8 @@ class BlowfishDecrypt extends Operation {
Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`); Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);
} }
if (iv.length !== 8) { if (mode !== "ECB" && iv.length !== 8) {
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes`); throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes.`);
} }
input = Utils.convertToByteString(input, inputType); input = Utils.convertToByteString(input, inputType);

View file

@ -72,12 +72,12 @@ class BlowfishEncrypt extends Operation {
if (key.length < 4 || key.length > 56) { if (key.length < 4 || key.length > 56) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`); Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);
} }
if (iv.length !== 8) { if (mode !== "ECB" && iv.length !== 8) {
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes`); throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes.`);
} }
input = Utils.convertToByteString(input, inputType); input = Utils.convertToByteString(input, inputType);

View file

@ -1,41 +0,0 @@
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import JSCRC from "js-crc";
/**
* CRC-16 Checksum operation
*/
class CRC16Checksum extends Operation {
/**
* CRC16Checksum constructor
*/
constructor() {
super();
this.name = "CRC-16 Checksum";
this.module = "Crypto";
this.description = "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961.";
this.infoURL = "https://wikipedia.org/wiki/Cyclic_redundancy_check";
this.inputType = "ArrayBuffer";
this.outputType = "string";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
return JSCRC.crc16(input);
}
}
export default CRC16Checksum;

View file

@ -1,41 +0,0 @@
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import JSCRC from "js-crc";
/**
* CRC-32 Checksum operation
*/
class CRC32Checksum extends Operation {
/**
* CRC32Checksum constructor
*/
constructor() {
super();
this.name = "CRC-32 Checksum";
this.module = "Crypto";
this.description = "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961; the 32-bit CRC function of Ethernet and many other standards is the work of several researchers and was published in 1975.";
this.infoURL = "https://wikipedia.org/wiki/Cyclic_redundancy_check";
this.inputType = "ArrayBuffer";
this.outputType = "string";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
return JSCRC.crc32(input);
}
}
export default CRC32Checksum;

View file

@ -1,157 +0,0 @@
/**
* @author mshwed [m@ttshwed.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHexFast } from "../lib/Hex.mjs";
/**
* CRC-8 Checksum operation
*/
class CRC8Checksum extends Operation {
/**
* CRC8Checksum constructor
*/
constructor() {
super();
this.name = "CRC-8 Checksum";
this.module = "Crypto";
this.description = "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961.";
this.infoURL = "https://wikipedia.org/wiki/Cyclic_redundancy_check";
this.inputType = "ArrayBuffer";
this.outputType = "string";
this.args = [
{
"name": "Algorithm",
"type": "option",
"value": [
"CRC-8",
"CRC-8/CDMA2000",
"CRC-8/DARC",
"CRC-8/DVB-S2",
"CRC-8/EBU",
"CRC-8/I-CODE",
"CRC-8/ITU",
"CRC-8/MAXIM",
"CRC-8/ROHC",
"CRC-8/WCDMA"
]
}
];
}
/**
* Generates the pre-computed lookup table for byte division
*
* @param polynomial
*/
calculateCRC8LookupTable(polynomial) {
const crc8Table = new Uint8Array(256);
let currentByte;
for (let i = 0; i < 256; i++) {
currentByte = i;
for (let bit = 0; bit < 8; bit++) {
if ((currentByte & 0x80) !== 0) {
currentByte <<= 1;
currentByte ^= polynomial;
} else {
currentByte <<= 1;
}
}
crc8Table[i] = currentByte;
}
return crc8Table;
}
/**
* Calculates the CRC-8 Checksum from an input
*
* @param {ArrayBuffer} input
* @param {number} polynomial
* @param {number} initializationValue
* @param {boolean} inputReflection
* @param {boolean} outputReflection
* @param {number} xorOut
*/
calculateCRC8(input, polynomial, initializationValue, inputReflection, outputReflection, xorOut) {
const crcSize = 8;
const crcTable = this.calculateCRC8LookupTable(polynomial);
let crc = initializationValue !== 0 ? initializationValue : 0;
let currentByte, position;
input = new Uint8Array(input);
for (const inputByte of input) {
currentByte = inputReflection ? this.reverseBits(inputByte, crcSize) : inputByte;
position = (currentByte ^ crc) & 255;
crc = crcTable[position];
}
crc = outputReflection ? this.reverseBits(crc, crcSize) : crc;
if (xorOut !== 0) crc = crc ^ xorOut;
return toHexFast(new Uint8Array([crc]));
}
/**
* Reverse the bits for a given input byte.
*
* @param {number} input
*/
reverseBits(input, hashSize) {
let reversedByte = 0;
for (let i = hashSize - 1; i >= 0; i--) {
reversedByte |= ((input & 1) << i);
input >>= 1;
}
return reversedByte;
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const algorithm = args[0];
switch (algorithm) {
case "CRC-8":
return this.calculateCRC8(input, 0x7, 0x0, false, false, 0x0);
case "CRC-8/CDMA2000":
return this.calculateCRC8(input, 0x9B, 0xFF, false, false, 0x0);
case "CRC-8/DARC":
return this.calculateCRC8(input, 0x39, 0x0, true, true, 0x0);
case "CRC-8/DVB-S2":
return this.calculateCRC8(input, 0xD5, 0x0, false, false, 0x0);
case "CRC-8/EBU":
return this.calculateCRC8(input, 0x1D, 0xFF, true, true, 0x0);
case "CRC-8/I-CODE":
return this.calculateCRC8(input, 0x1D, 0xFD, false, false, 0x0);
case "CRC-8/ITU":
return this.calculateCRC8(input, 0x7, 0x0, false, false, 0x55);
case "CRC-8/MAXIM":
return this.calculateCRC8(input, 0x31, 0x0, true, true, 0x0);
case "CRC-8/ROHC":
return this.calculateCRC8(input, 0x7, 0xFF, true, true, 0x0);
case "CRC-8/WCDMA":
return this.calculateCRC8(input, 0x9B, 0x0, true, true, 0x0);
default:
throw new OperationError("Unknown checksum algorithm");
}
}
}
export default CRC8Checksum;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,116 @@
/**
* @author bartblaze []
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* Convert Leet Speak operation
*/
class ConvertLeetSpeak extends Operation {
/**
* ConvertLeetSpeak constructor
*/
constructor() {
super();
this.name = "Convert Leet Speak";
this.module = "Default";
this.description = "Converts to and from Leet Speak.";
this.infoURL = "https://wikipedia.org/wiki/Leet";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Direction",
type: "option",
value: ["To Leet Speak", "From Leet Speak"],
defaultIndex: 0
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const direction = args[0];
if (direction === "To Leet Speak") {
return input.replace(/[a-z]/gi, char => {
const leetChar = toLeetMap[char.toLowerCase()] || char;
return char === char.toUpperCase() ? leetChar.toUpperCase() : leetChar;
});
} else if (direction === "From Leet Speak") {
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/gi, char => {
const normalChar = fromLeetMap[char] || char;
return normalChar;
});
}
}
}
const toLeetMap = {
"a": "4",
"b": "b",
"c": "c",
"d": "d",
"e": "3",
"f": "f",
"g": "g",
"h": "h",
"i": "1",
"j": "j",
"k": "k",
"l": "l",
"m": "m",
"n": "n",
"o": "0",
"p": "p",
"q": "q",
"r": "r",
"s": "5",
"t": "7",
"u": "u",
"v": "v",
"w": "w",
"x": "x",
"y": "y",
"z": "z"
};
const fromLeetMap = {
"4": "a",
"b": "b",
"c": "c",
"d": "d",
"3": "e",
"f": "f",
"g": "g",
"h": "h",
"1": "i",
"j": "j",
"k": "k",
"l": "l",
"m": "m",
"n": "n",
"0": "o",
"p": "p",
"q": "q",
"r": "r",
"5": "s",
"7": "t",
"u": "u",
"v": "v",
"w": "w",
"x": "x",
"y": "y",
"z": "z"
};
export default ConvertLeetSpeak;

View file

@ -22,7 +22,7 @@ class DESDecrypt extends Operation {
this.name = "DES Decrypt"; this.name = "DES Decrypt";
this.module = "Ciphers"; this.module = "Ciphers";
this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br>Triple DES uses a key length of 24 bytes (192 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default."; this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.";
this.infoURL = "https://wikipedia.org/wiki/Data_Encryption_Standard"; this.infoURL = "https://wikipedia.org/wiki/Data_Encryption_Standard";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
@ -72,8 +72,7 @@ class DESDecrypt extends Operation {
if (key.length !== 8) { if (key.length !== 8) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
DES uses a key length of 8 bytes (64 bits). DES uses a key length of 8 bytes (64 bits).`);
Triple DES uses a key length of 24 bytes (192 bits).`);
} }
if (iv.length !== 8 && mode !== "ECB") { if (iv.length !== 8 && mode !== "ECB") {
throw new OperationError(`Invalid IV length: ${iv.length} bytes throw new OperationError(`Invalid IV length: ${iv.length} bytes

View file

@ -22,7 +22,7 @@ class DESEncrypt extends Operation {
this.name = "DES Encrypt"; this.name = "DES Encrypt";
this.module = "Ciphers"; this.module = "Ciphers";
this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br>Triple DES uses a key length of 24 bytes (192 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used."; this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used.";
this.infoURL = "https://wikipedia.org/wiki/Data_Encryption_Standard"; this.infoURL = "https://wikipedia.org/wiki/Data_Encryption_Standard";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
@ -70,8 +70,7 @@ class DESEncrypt extends Operation {
if (key.length !== 8) { if (key.length !== 8) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
DES uses a key length of 8 bytes (64 bits). DES uses a key length of 8 bytes (64 bits).`);
Triple DES uses a key length of 24 bytes (192 bits).`);
} }
if (iv.length !== 8 && mode !== "ECB") { if (iv.length !== 8 && mode !== "ECB") {
throw new OperationError(`Invalid IV length: ${iv.length} bytes throw new OperationError(`Invalid IV length: ${iv.length} bytes

View file

@ -0,0 +1,79 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Drop nth bytes operation
*/
class DropNthBytes extends Operation {
/**
* DropNthBytes constructor
*/
constructor() {
super();
this.name = "Drop nth bytes";
this.module = "Default";
this.description = "Drops every nth byte starting with a given byte.";
this.infoURL = "";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.args = [
{
name: "Drop every",
type: "number",
value: 4
},
{
name: "Starting at",
type: "number",
value: 0
},
{
name: "Apply to each line",
type: "boolean",
value: false
}
];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
const n = args[0];
const start = args[1];
const eachLine = args[2];
if (parseInt(n, 10) !== n || n <= 0) {
throw new OperationError("'Drop every' must be a positive integer.");
}
if (parseInt(start, 10) !== start || start < 0) {
throw new OperationError("'Starting at' must be a positive or zero integer.");
}
let offset = 0;
const output = [];
for (let i = 0; i < input.length; i++) {
if (eachLine && input[i] === 0x0a) {
output.push(0x0a);
offset = i + 1;
} else if (i - offset < start || (i - (start + offset)) % n !== 0) {
output.push(input[i]);
}
}
return output;
}
}
export default DropNthBytes;

View file

@ -5,7 +5,7 @@
*/ */
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import { search, DOMAIN_REGEX } from "../lib/Extract.mjs"; import { search, DOMAIN_REGEX, DMARC_DOMAIN_REGEX } from "../lib/Extract.mjs";
import { caseInsensitiveSort } from "../lib/Sort.mjs"; import { caseInsensitiveSort } from "../lib/Sort.mjs";
/** /**
@ -39,6 +39,11 @@ class ExtractDomains extends Operation {
name: "Unique", name: "Unique",
type: "boolean", type: "boolean",
value: false value: false
},
{
name: "Underscore (DMARC, DKIM, etc)",
type: "boolean",
value: false
} }
]; ];
} }
@ -49,11 +54,11 @@ class ExtractDomains extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const [displayTotal, sort, unique] = args; const [displayTotal, sort, unique, dmarc] = args;
const results = search( const results = search(
input, input,
DOMAIN_REGEX, dmarc ? DMARC_DOMAIN_REGEX : DOMAIN_REGEX,
null, null,
sort ? caseInsensitiveSort : null, sort ? caseInsensitiveSort : null,
unique unique

View file

@ -6,6 +6,8 @@
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs"; import Utils from "../Utils.mjs";
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
/** /**
* From Base32 operation * From Base32 operation
@ -27,8 +29,8 @@ class FromBase32 extends Operation {
this.args = [ this.args = [
{ {
name: "Alphabet", name: "Alphabet",
type: "binaryString", type: "editableOption",
value: "A-Z2-7=" value: ALPHABET_OPTIONS
}, },
{ {
name: "Remove non-alphabet chars", name: "Remove non-alphabet chars",
@ -41,6 +43,11 @@ class FromBase32 extends Operation {
pattern: "^(?:[A-Z2-7]{8})+(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}={1})?$", pattern: "^(?:[A-Z2-7]{8})+(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}={1})?$",
flags: "", flags: "",
args: ["A-Z2-7=", false] args: ["A-Z2-7=", false]
},
{
pattern: "^(?:[0-9A-V]{8})+(?:[0-9A-V]{2}={6}|[0-9A-V]{4}={4}|[0-9A-V]{5}={3}|[0-9A-V]{7}={1})?$",
flags: "",
args: ["0-9A-V=", false]
} }
]; ];
} }
@ -96,3 +103,4 @@ class FromBase32 extends Operation {
} }
export default FromBase32; export default FromBase32;

View file

@ -0,0 +1,84 @@
/**
* @author linuxgemini [ilteris@asenkron.com.tr]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import { FROM_MODHEX_DELIM_OPTIONS, fromModhex } from "../lib/Modhex.mjs";
/**
* From Modhex operation
*/
class FromModhex extends Operation {
/**
* FromModhex constructor
*/
constructor() {
super();
this.name = "From Modhex";
this.module = "Default";
this.description = "Converts a modhex byte string back into its raw value.";
this.infoURL = "https://en.wikipedia.org/wiki/YubiKey#ModHex";
this.inputType = "string";
this.outputType = "byteArray";
this.args = [
{
name: "Delimiter",
type: "option",
value: FROM_MODHEX_DELIM_OPTIONS
}
];
this.checks = [
{
pattern: "^(?:[cbdefghijklnrtuv]{2})+$",
flags: "i",
args: ["None"]
},
{
pattern: "^[cbdefghijklnrtuv]{2}(?: [cbdefghijklnrtuv]{2})*$",
flags: "i",
args: ["Space"]
},
{
pattern: "^[cbdefghijklnrtuv]{2}(?:,[cbdefghijklnrtuv]{2})*$",
flags: "i",
args: ["Comma"]
},
{
pattern: "^[cbdefghijklnrtuv]{2}(?:;[cbdefghijklnrtuv]{2})*$",
flags: "i",
args: ["Semi-colon"]
},
{
pattern: "^[cbdefghijklnrtuv]{2}(?::[cbdefghijklnrtuv]{2})*$",
flags: "i",
args: ["Colon"]
},
{
pattern: "^[cbdefghijklnrtuv]{2}(?:\\n[cbdefghijklnrtuv]{2})*$",
flags: "i",
args: ["Line feed"]
},
{
pattern: "^[cbdefghijklnrtuv]{2}(?:\\r\\n[cbdefghijklnrtuv]{2})*$",
flags: "i",
args: ["CRLF"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
const delim = args[0] || "Auto";
return fromModhex(input, delim, 2);
}
}
export default FromModhex;

View file

@ -27,9 +27,7 @@ import Fletcher16Checksum from "./Fletcher16Checksum.mjs";
import Fletcher32Checksum from "./Fletcher32Checksum.mjs"; import Fletcher32Checksum from "./Fletcher32Checksum.mjs";
import Fletcher64Checksum from "./Fletcher64Checksum.mjs"; import Fletcher64Checksum from "./Fletcher64Checksum.mjs";
import Adler32Checksum from "./Adler32Checksum.mjs"; import Adler32Checksum from "./Adler32Checksum.mjs";
import CRC8Checksum from "./CRC8Checksum.mjs"; import CRCChecksum from "./CRCChecksum.mjs";
import CRC16Checksum from "./CRC16Checksum.mjs";
import CRC32Checksum from "./CRC32Checksum.mjs";
import BLAKE2b from "./BLAKE2b.mjs"; import BLAKE2b from "./BLAKE2b.mjs";
import BLAKE2s from "./BLAKE2s.mjs"; import BLAKE2s from "./BLAKE2s.mjs";
import Streebog from "./Streebog.mjs"; import Streebog from "./Streebog.mjs";
@ -120,9 +118,9 @@ class GenerateAllHashes extends Operation {
{name: "Fletcher-32", algo: (new Fletcher32Checksum), inputType: "byteArray", params: []}, {name: "Fletcher-32", algo: (new Fletcher32Checksum), inputType: "byteArray", params: []},
{name: "Fletcher-64", algo: (new Fletcher64Checksum), inputType: "byteArray", params: []}, {name: "Fletcher-64", algo: (new Fletcher64Checksum), inputType: "byteArray", params: []},
{name: "Adler-32", algo: (new Adler32Checksum), inputType: "byteArray", params: []}, {name: "Adler-32", algo: (new Adler32Checksum), inputType: "byteArray", params: []},
{name: "CRC-8", algo: (new CRC8Checksum), inputType: "arrayBuffer", params: ["CRC-8"]}, {name: "CRC-8", algo: (new CRCChecksum), inputType: "arrayBuffer", params: ["CRC-8"]},
{name: "CRC-16", algo: (new CRC16Checksum), inputType: "arrayBuffer", params: []}, {name: "CRC-16", algo: (new CRCChecksum), inputType: "arrayBuffer", params: ["CRC-16"]},
{name: "CRC-32", algo: (new CRC32Checksum), inputType: "arrayBuffer", params: []} {name: "CRC-32", algo: (new CRCChecksum), inputType: "arrayBuffer", params: ["CRC-32"]}
]; ];
} }

View file

@ -5,16 +5,14 @@
*/ */
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import otp from "otp"; import * as OTPAuth from "otpauth";
import ToBase32 from "./ToBase32.mjs";
/** /**
* Generate HOTP operation * Generate HOTP operation
*/ */
class GenerateHOTP extends Operation { class GenerateHOTP extends Operation {
/** /**
* GenerateHOTP constructor *
*/ */
constructor() { constructor() {
super(); super();
@ -31,11 +29,6 @@ class GenerateHOTP extends Operation {
"type": "string", "type": "string",
"value": "" "value": ""
}, },
{
"name": "Key size",
"type": "number",
"value": 32
},
{ {
"name": "Code length", "name": "Code length",
"type": "number", "type": "number",
@ -50,21 +43,26 @@ class GenerateHOTP extends Operation {
} }
/** /**
* @param {ArrayBuffer} input *
* @param {Object[]} args
* @returns {string}
*/ */
run(input, args) { run(input, args) {
const otpObj = otp({ const secretStr = new TextDecoder("utf-8").decode(input).trim();
name: args[0], const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
keySize: args[1],
codeLength: args[2],
secret: (new ToBase32).run(input, []).split("=")[0],
});
const counter = args[3];
return `URI: ${otpObj.hotpURL}\n\nPassword: ${otpObj.hotp(counter)}`;
}
const hotp = new OTPAuth.HOTP({
issuer: "",
label: args[0],
algorithm: "SHA1",
digits: args[1],
counter: args[2],
secret: OTPAuth.Secret.fromBase32(secret)
});
const uri = hotp.toString();
const code = hotp.generate();
return `URI: ${uri}\n\nPassword: ${code}`;
}
} }
export default GenerateHOTP; export default GenerateHOTP;

View file

@ -5,20 +5,17 @@
*/ */
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import otp from "otp"; import * as OTPAuth from "otpauth";
import ToBase32 from "./ToBase32.mjs";
/** /**
* Generate TOTP operation * Generate TOTP operation
*/ */
class GenerateTOTP extends Operation { class GenerateTOTP extends Operation {
/** /**
* GenerateTOTP constructor *
*/ */
constructor() { constructor() {
super(); super();
this.name = "Generate TOTP"; this.name = "Generate TOTP";
this.module = "Default"; this.module = "Default";
this.description = "The Time-based One-Time Password algorithm (TOTP) is an algorithm that computes a one-time password from a shared secret key and the current time. It has been adopted as Internet Engineering Task Force standard RFC 6238, is the cornerstone of Initiative For Open Authentication (OAUTH), and is used in a number of two-factor authentication systems. A TOTP is an HOTP where the counter is the current time.<br><br>Enter the secret as the input or leave it blank for a random secret to be generated. T0 and T1 are in seconds."; this.description = "The Time-based One-Time Password algorithm (TOTP) is an algorithm that computes a one-time password from a shared secret key and the current time. It has been adopted as Internet Engineering Task Force standard RFC 6238, is the cornerstone of Initiative For Open Authentication (OAUTH), and is used in a number of two-factor authentication systems. A TOTP is an HOTP where the counter is the current time.<br><br>Enter the secret as the input or leave it blank for a random secret to be generated. T0 and T1 are in seconds.";
@ -31,11 +28,6 @@ class GenerateTOTP extends Operation {
"type": "string", "type": "string",
"value": "" "value": ""
}, },
{
"name": "Key size",
"type": "number",
"value": 32
},
{ {
"name": "Code length", "name": "Code length",
"type": "number", "type": "number",
@ -55,22 +47,27 @@ class GenerateTOTP extends Operation {
} }
/** /**
* @param {ArrayBuffer} input *
* @param {Object[]} args
* @returns {string}
*/ */
run(input, args) { run(input, args) {
const otpObj = otp({ const secretStr = new TextDecoder("utf-8").decode(input).trim();
name: args[0], const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
keySize: args[1],
codeLength: args[2],
secret: (new ToBase32).run(input, []).split("=")[0],
epoch: args[3],
timeSlice: args[4]
});
return `URI: ${otpObj.totpURL}\n\nPassword: ${otpObj.totp()}`;
}
const totp = new OTPAuth.TOTP({
issuer: "",
label: args[0],
algorithm: "SHA1",
digits: args[1],
period: args[3],
epoch: args[2] * 1000, // Convert seconds to milliseconds
secret: OTPAuth.Secret.fromBase32(secret)
});
const uri = totp.toString();
const code = totp.generate();
return `URI: ${uri}\n\nPassword: ${code}`;
}
} }
export default GenerateTOTP; export default GenerateTOTP;

View file

@ -0,0 +1,209 @@
/**
* @author jb30795 [jb30795@proton.me]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* IPv6 Transition Addresses operation
*/
class IPv6TransitionAddresses extends Operation {
/**
* IPv6TransitionAddresses constructor
*/
constructor() {
super();
this.name = "IPv6 Transition Addresses";
this.module = "Default";
this.description = "Converts IPv4 addresses to their IPv6 Transition addresses. IPv6 Transition addresses can also be converted back into their original IPv4 address. MAC addresses can also be converted into the EUI-64 format, this can them be appended to your IPv6 /64 range to obtain a full /128 address.<br><br>Transition technologies enable translation between IPv4 and IPv6 addresses or tunneling to allow traffic to pass through the incompatible network, allowing the two standards to coexist.<br><br>Only /24 ranges and currently handled. Remove headers to easily copy out results.";
this.infoURL = "https://wikipedia.org/wiki/IPv6_transition_mechanism";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Ignore ranges",
"type": "boolean",
"value": true
},
{
"name": "Remove headers",
"type": "boolean",
"value": false
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const XOR = {"0": "2", "1": "3", "2": "0", "3": "1", "4": "6", "5": "7", "6": "4", "7": "5", "8": "a", "9": "b", "a": "8", "b": "9", "c": "e", "d": "f", "e": "c", "f": "d"};
/**
* Function to convert to hex
*/
function hexify(octet) {
return Number(octet).toString(16).padStart(2, "0");
}
/**
* Function to convert Hex to Int
*/
function intify(hex) {
return parseInt(hex, 16);
}
/**
* Function converts IPv4 to IPv6 Transtion address
*/
function ipTransition(input, range) {
let output = "";
const HEXIP = input.split(".");
/**
* 6to4
*/
if (!args[1]) {
output += "6to4: ";
}
output += "2002:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
if (range) {
output += "00::/40\n";
} else {
output += hexify(HEXIP[3]) + "::/48\n";
}
/**
* Mapped
*/
if (!args[1]) {
output += "IPv4 Mapped: ";
}
output += "::ffff:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
if (range) {
output += "00/120\n";
} else {
output += hexify(HEXIP[3]) + "\n";
}
/**
* Translated
*/
if (!args[1]) {
output += "IPv4 Translated: ";
}
output += "::ffff:0:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
if (range) {
output += "00/120\n";
} else {
output += hexify(HEXIP[3]) + "\n";
}
/**
* Nat64
*/
if (!args[1]) {
output += "Nat 64: ";
}
output += "64:ff9b::" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
if (range) {
output += "00/120\n";
} else {
output += hexify(HEXIP[3]) + "\n";
}
return output;
}
/**
* Convert MAC to EUI-64
*/
function macTransition(input) {
let output = "";
const MACPARTS = input.split(":");
if (!args[1]) {
output += "EUI-64 Interface ID: ";
}
const MAC = MACPARTS[0] + MACPARTS[1] + ":" + MACPARTS[2] + "ff:fe" + MACPARTS[3] + ":" + MACPARTS[4] + MACPARTS[5];
output += MAC.slice(0, 1) + XOR[MAC.slice(1, 2)] + MAC.slice(2);
return output;
}
/**
* Convert IPv6 address to its original IPv4 or MAC address
*/
function unTransition(input) {
let output = "";
let hextets = "";
/**
* 6to4
*/
if (input.startsWith("2002:")) {
if (!args[1]) {
output += "IPv4: ";
}
output += String(intify(input.slice(5, 7))) + "." + String(intify(input.slice(7, 9)))+ "." + String(intify(input.slice(10, 12)))+ "." + String(intify(input.slice(12, 14))) + "\n";
} else if (input.startsWith("::ffff:") || input.startsWith("0000:0000:0000:0000:0000:ffff:") || input.startsWith("::ffff:0000:") || input.startsWith("0000:0000:0000:0000:ffff:0000:") || input.startsWith("64:ff9b::") || input.startsWith("0064:ff9b:0000:0000:0000:0000:")) {
/**
* Mapped/Translated/Nat64
*/
hextets = /:([0-9a-z]{1,4}):[0-9a-z]{1,4}$/.exec(input)[1].padStart(4, "0") + /:([0-9a-z]{1,4})$/.exec(input)[1].padStart(4, "0");
if (!args[1]) {
output += "IPv4: ";
}
output += intify(hextets.slice(-8, -7) + hextets.slice(-7, -6)) + "." +intify(hextets.slice(-6, -5) + hextets.slice(-5, -4)) + "." +intify(hextets.slice(-4, -3) + hextets.slice(-3, -2)) + "." +intify(hextets.slice(-2, -1) + hextets.slice(-1,)) + "\n";
} else if (input.slice(-12, -7).toUpperCase() === "FF:FE") {
/**
* EUI-64
*/
if (!args[1]) {
output += "Mac Address: ";
}
const MAC = (input.slice(-19, -17) + ":" + input.slice(-17, -15) + ":" + input.slice(-14, -12) + ":" + input.slice(-7, -5) + ":" + input.slice(-4, -2) + ":" + input.slice(-2,)).toUpperCase();
output += MAC.slice(0, 1) + XOR[MAC.slice(1, 2)] + MAC.slice(2) + "\n";
}
return output;
}
/**
* Main
*/
let output = "";
let inputs = input.split("\n");
// Remove blank rows
inputs = inputs.filter(Boolean);
for (let i = 0; i < inputs.length; i++) {
// if ignore ranges is checked and input is a range, skip
if ((args[0] && !inputs[i].includes("/")) || (!args[0])) {
if (/^[0-9]{1,3}(?:\.[0-9]{1,3}){3}$/.test(inputs[i])) {
output += ipTransition(inputs[i], false);
} else if (/\/24$/.test(inputs[i])) {
output += ipTransition(inputs[i], true);
} else if (/^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$/.test(inputs[i])) {
output += macTransition(inputs[i]);
} else if (/^((?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test(inputs[i])) {
output += unTransition(inputs[i]);
} else {
output = "Enter compressed or expanded IPv6 address, IPv4 address or MAC Address.";
}
}
}
return output;
}
}
export default IPv6TransitionAddresses;

View file

@ -0,0 +1,46 @@
/**
* @author ccarpo [ccarpo@gmx.net]
* @copyright Crown Copyright 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import YAML from "yaml";
/**
* JSON to YAML operation
*/
class JSONtoYAML extends Operation {
/**
* JSONtoYAML constructor
*/
constructor() {
super();
this.name = "JSON to YAML";
this.module = "Default";
this.description = "Format a JSON object into YAML";
this.infoURL = "https://en.wikipedia.org/wiki/YAML";
this.inputType = "JSON";
this.outputType = "string";
this.args = [];
}
/**
* @param {JSON} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
try {
return YAML.stringify(input);
} catch (err) {
throw new OperationError("Test");
}
}
}
export default JSONtoYAML;

View file

@ -36,6 +36,11 @@ class JWTSign extends Operation {
name: "Signing algorithm", name: "Signing algorithm",
type: "option", type: "option",
value: JWT_ALGORITHMS value: JWT_ALGORITHMS
},
{
name: "Header",
type: "text",
value: "{}"
} }
]; ];
} }
@ -46,11 +51,12 @@ class JWTSign extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const [key, algorithm] = args; const [key, algorithm, header] = args;
try { try {
return jwt.sign(input, key, { return jwt.sign(input, key, {
algorithm: algorithm === "None" ? "none" : algorithm algorithm: algorithm === "None" ? "none" : algorithm,
header: JSON.parse(header || "{}")
}); });
} catch (err) { } catch (err) {
throw new OperationError(`Error: Have you entered the key correctly? The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA. throw new OperationError(`Error: Have you entered the key correctly? The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA.

View file

@ -22,7 +22,7 @@ class JWTVerify extends Operation {
this.name = "JWT Verify"; this.name = "JWT Verify";
this.module = "Crypto"; this.module = "Crypto";
this.description = "Verifies that a JSON Web Token is valid and has been signed with the provided secret / private key.<br><br>The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA."; this.description = "Verifies that a JSON Web Token is valid and has been signed with the provided secret / private key.<br><br>The key should be either the secret for HMAC algorithms or the PEM-encoded public key for RSA and ECDSA.";
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token"; this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
this.inputType = "string"; this.inputType = "string";
this.outputType = "JSON"; this.outputType = "JSON";

View file

@ -0,0 +1,57 @@
/**
* @author zhzy0077 [zhzy0077@hotmail.com]
* @copyright Crown Copyright 2023
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import jq from "jq-web";
/**
* jq operation
*/
class Jq extends Operation {
/**
* Jq constructor
*/
constructor() {
super();
this.name = "Jq";
this.module = "Jq";
this.description = "jq is a lightweight and flexible command-line JSON processor.";
this.infoURL = "https://github.com/jqlang/jq";
this.inputType = "JSON";
this.outputType = "string";
this.args = [
{
name: "Query",
type: "string",
value: ""
}
];
}
/**
* @param {JSON} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [query] = args;
let result;
try {
result = jq.json(input, query);
} catch (err) {
throw new OperationError(`Invalid jq expression: ${err.message}`);
}
return JSON.stringify(result);
}
}
export default Jq;

View file

@ -1,5 +1,6 @@
/** /**
* @author n1073645 [n1073645@gmail.com] * @author n1073645 [n1073645@gmail.com]
* @author k3ach [k3ach@proton.me]
* @copyright Crown Copyright 2020 * @copyright Crown Copyright 2020
* @license Apache-2.0 * @license Apache-2.0
*/ */
@ -20,39 +21,46 @@ class LuhnChecksum extends Operation {
this.name = "Luhn Checksum"; this.name = "Luhn Checksum";
this.module = "Default"; this.module = "Default";
this.description = "The Luhn algorithm, also known as the modulus 10 or mod 10 algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers and Canadian Social Insurance Numbers."; this.description = "The Luhn mod N algorithm using the english alphabet. The Luhn mod N algorithm is an extension to the Luhn algorithm (also known as mod 10 algorithm) that allows it to work with sequences of values in any even-numbered base. This can be useful when a check digit is required to validate an identification string composed of letters, a combination of letters and digits or any arbitrary set of N characters where N is divisible by 2.";
this.infoURL = "https://wikipedia.org/wiki/Luhn_algorithm"; this.infoURL = "https://en.wikipedia.org/wiki/Luhn_mod_N_algorithm";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = []; this.args = [
{
"name": "Radix",
"type": "number",
"value": 10
}
];
} }
/** /**
* Generates the Luhn Checksum from the input. * Generates the Luhn checksum from the input.
* *
* @param {string} inputStr * @param {string} inputStr
* @returns {number} * @returns {number}
*/ */
checksum(inputStr) { checksum(inputStr, radix = 10) {
let even = false; let even = false;
return inputStr.split("").reverse().reduce((acc, elem) => { return inputStr.split("").reverse().reduce((acc, elem) => {
// Convert element to integer. // Convert element to an integer based on the provided radix.
let temp = parseInt(elem, 10); let temp = parseInt(elem, radix);
// If element is not an integer. // If element is not a valid number in the given radix.
if (isNaN(temp)) if (isNaN(temp)) {
throw new OperationError("Character: " + elem + " is not a digit."); throw new Error("Character: " + elem + " is not valid in radix " + radix + ".");
}
// If element is in an even position // If element is in an even position
if (even) { if (even) {
// Double the element and add the quotient and remainder together. // Double the element and sum the quotient and remainder.
temp = 2 * elem; temp = 2 * temp;
temp = Math.floor(temp/10) + (temp % 10); temp = Math.floor(temp / radix) + (temp % radix);
} }
even = !even; even = !even;
return acc + temp; return acc + temp;
}, 0) % 10; }, 0) % radix; // Use radix as the modulus base
} }
/** /**
@ -63,9 +71,20 @@ class LuhnChecksum extends Operation {
run(input, args) { run(input, args) {
if (!input) return ""; if (!input) return "";
const checkSum = this.checksum(input); const radix = args[0];
let checkDigit = this.checksum(input + "0");
checkDigit = checkDigit === 0 ? 0 : (10-checkDigit); if (radix < 2 || radix > 36) {
throw new OperationError("Error: Radix argument must be between 2 and 36");
}
if (radix % 2 !== 0) {
throw new OperationError("Error: Radix argument must be divisible by 2");
}
const checkSum = this.checksum(input, radix).toString(radix);
let checkDigit = this.checksum(input + "0", radix);
checkDigit = checkDigit === 0 ? 0 : (radix - checkDigit);
checkDigit = checkDigit.toString(radix);
return `Checksum: ${checkSum} return `Checksum: ${checkSum}
Checkdigit: ${checkDigit} Checkdigit: ${checkDigit}

View file

@ -0,0 +1,171 @@
/**
* @author mshwed [m@ttshwed.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import Utils from "../Utils.mjs";
import { fromHex } from "../lib/Hex.mjs";
import { fromBase64 } from "../lib/Base64.mjs";
import cptable from "codepage";
/**
* MIME Decoding operation
*/
class MIMEDecoding extends Operation {
/**
* MIMEDecoding constructor
*/
constructor() {
super();
this.name = "MIME Decoding";
this.module = "Default";
this.description = "Enables the decoding of MIME message header extensions for non-ASCII text";
this.infoURL = "https://tools.ietf.org/html/rfc2047";
this.inputType = "byteArray";
this.outputType = "string";
this.args = [];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const mimeEncodedText = Utils.byteArrayToUtf8(input);
const encodedHeaders = mimeEncodedText.replace(/\r\n/g, "\n");
const decodedHeader = this.decodeHeaders(encodedHeaders);
return decodedHeader;
}
/**
* Decode MIME header strings
*
* @param headerString
*/
decodeHeaders(headerString) {
// No encoded words detected
let i = headerString.indexOf("=?");
if (i === -1) return headerString;
let decodedHeaders = headerString.slice(0, i);
let header = headerString.slice(i);
let isBetweenWords = false;
let start, cur, charset, encoding, j, end, text;
while (header.length > -1) {
start = header.indexOf("=?");
if (start === -1) break;
cur = start + "=?".length;
i = header.slice(cur).indexOf("?");
if (i === -1) break;
charset = header.slice(cur, cur + i);
cur += i + "?".length;
if (header.length < cur + "Q??=".length) break;
encoding = header[cur];
cur += 1;
if (header[cur] !== "?") break;
cur += 1;
j = header.slice(cur).indexOf("?=");
if (j === -1) break;
text = header.slice(cur, cur + j);
end = cur + j + "?=".length;
if (encoding.toLowerCase() === "b") {
text = fromBase64(text);
} else if (encoding.toLowerCase() === "q") {
text = this.parseQEncodedWord(text);
} else {
isBetweenWords = false;
decodedHeaders += header.slice(0, start + 2);
header = header.slice(start + 2);
}
if (start > 0 && (!isBetweenWords || header.slice(0, start).search(/\S/g) > -1)) {
decodedHeaders += header.slice(0, start);
}
decodedHeaders += this.convertFromCharset(charset, text);
header = header.slice(end);
isBetweenWords = true;
}
if (header.length > 0) {
decodedHeaders += header;
}
return decodedHeaders;
}
/**
* Converts decoded text for supported charsets.
* Supports UTF-8, US-ASCII, ISO-8859-*
*
* @param encodedWord
*/
convertFromCharset(charset, encodedText) {
charset = charset.toLowerCase();
const parsedCharset = charset.split("-");
if (parsedCharset.length === 2 && parsedCharset[0] === "utf" && charset === "utf-8") {
return cptable.utils.decode(65001, encodedText);
} else if (parsedCharset.length === 2 && charset === "us-ascii") {
return cptable.utils.decode(20127, encodedText);
} else if (parsedCharset.length === 3 && parsedCharset[0] === "iso" && parsedCharset[1] === "8859") {
const isoCharset = parseInt(parsedCharset[2], 10);
if (isoCharset >= 1 && isoCharset <= 16) {
return cptable.utils.decode(28590 + isoCharset, encodedText);
}
}
throw new OperationError("Unhandled Charset");
}
/**
* Parses a Q encoded word
*
* @param encodedWord
*/
parseQEncodedWord(encodedWord) {
let decodedWord = "";
for (let i = 0; i < encodedWord.length; i++) {
if (encodedWord[i] === "_") {
decodedWord += " ";
// Parse hex encoding
} else if (encodedWord[i] === "=") {
if ((i + 2) >= encodedWord.length) throw new OperationError("Incorrectly Encoded Word");
const decodedHex = Utils.byteArrayToChars(fromHex(encodedWord.substring(i + 1, i + 3)));
decodedWord += decodedHex;
i += 2;
} else if (
(encodedWord[i].charCodeAt(0) >= " ".charCodeAt(0) && encodedWord[i].charCodeAt(0) <= "~".charCodeAt(0)) ||
encodedWord[i] === "\n" ||
encodedWord[i] === "\r" ||
encodedWord[i] === "\t") {
decodedWord += encodedWord[i];
} else {
throw new OperationError("Incorrectly Encoded Word");
}
}
return decodedWord;
}
}
export default MIMEDecoding;

View file

@ -12,9 +12,10 @@ import { isImage } from "../lib/FileType.mjs";
import { toBase64 } from "../lib/Base64.mjs"; import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils.mjs"; import { isWorkerEnvironment } from "../Utils.mjs";
import process from "process";
import { createWorker } from "tesseract.js"; import { createWorker } from "tesseract.js";
const OEM_MODES = ["Tesseract only", "LSTM only", "Tesseract/LSTM Combined"];
/** /**
* Optical Character Recognition operation * Optical Character Recognition operation
*/ */
@ -37,6 +38,12 @@ class OpticalCharacterRecognition extends Operation {
name: "Show confidence", name: "Show confidence",
type: "boolean", type: "boolean",
value: true value: true
},
{
name: "OCR Engine Mode",
type: "option",
value: OEM_MODES,
defaultIndex: 1
} }
]; ];
} }
@ -47,7 +54,7 @@ class OpticalCharacterRecognition extends Operation {
* @returns {string} * @returns {string}
*/ */
async run(input, args) { async run(input, args) {
const [showConfidence] = args; const [showConfidence, oemChoice] = args;
if (!isWorkerEnvironment()) throw new OperationError("This operation only works in a browser"); if (!isWorkerEnvironment()) throw new OperationError("This operation only works in a browser");
@ -56,12 +63,13 @@ class OpticalCharacterRecognition extends Operation {
throw new OperationError("Unsupported file type (supported: jpg,png,pbm,bmp) or no file provided"); throw new OperationError("Unsupported file type (supported: jpg,png,pbm,bmp) or no file provided");
} }
const assetDir = isWorkerEnvironment() ? `${self.docURL}/assets/` : `${process.cwd()}/src/core/vendor/`; const assetDir = `${self.docURL}/assets/`;
const oem = OEM_MODES.indexOf(oemChoice);
try { try {
self.sendStatusMessage("Spinning up Tesseract worker..."); self.sendStatusMessage("Spinning up Tesseract worker...");
const image = `data:${type};base64,${toBase64(input)}`; const image = `data:${type};base64,${toBase64(input)}`;
const worker = createWorker({ const worker = await createWorker("eng", oem, {
workerPath: `${assetDir}tesseract/worker.min.js`, workerPath: `${assetDir}tesseract/worker.min.js`,
langPath: `${assetDir}tesseract/lang-data`, langPath: `${assetDir}tesseract/lang-data`,
corePath: `${assetDir}tesseract/tesseract-core.wasm.js`, corePath: `${assetDir}tesseract/tesseract-core.wasm.js`,
@ -71,11 +79,6 @@ class OpticalCharacterRecognition extends Operation {
} }
} }
}); });
await worker.load();
self.sendStatusMessage(`Loading English language pack...`);
await worker.loadLanguage("eng");
self.sendStatusMessage("Intialising Tesseract API...");
await worker.initialize("eng");
self.sendStatusMessage("Finding text..."); self.sendStatusMessage("Finding text...");
const result = await worker.recognize(image); const result = await worker.recognize(image);

View file

@ -0,0 +1,126 @@
/**
* @author brun0ne [brunonblok@gmail.com]
* @copyright Crown Copyright 2023
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* PHP Serialize operation
*/
class PHPSerialize extends Operation {
/**
* PHPSerialize constructor
*/
constructor() {
super();
this.name = "PHP Serialize";
this.module = "Default";
this.description = "Performs PHP serialization on JSON data.<br><br>This function does not support <code>object</code> tags.<br><br>Since PHP doesn't distinguish dicts and arrays, this operation is not always symmetric to <code>PHP Deserialize</code>.<br><br>Example:<br><code>[5,&quot;abc&quot;,true]</code><br>becomes<br><code>a:3:{i:0;i:5;i:1;s:3:&quot;abc&quot;;i:2;b:1;}<code>";
this.infoURL = "https://www.phpinternalsbook.com/php5/classes_objects/serialization.html";
this.inputType = "JSON";
this.outputType = "string";
this.args = [];
}
/**
* @param {JSON} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
/**
* Determines if a number is an integer
* @param {number} value
* @returns {boolean}
*/
function isInteger(value) {
return typeof value === "number" && parseInt(value.toString(), 10) === value;
}
/**
* Serialize basic types
* @param {string | number | boolean} content
* @returns {string}
*/
function serializeBasicTypes(content) {
const basicTypes = {
"string": "s",
"integer": "i",
"float": "d",
"boolean": "b"
};
/**
* Booleans
* cast to 0 or 1
*/
if (typeof content === "boolean") {
return `${basicTypes.boolean}:${content ? 1 : 0}`;
}
/* Numbers */
if (typeof content === "number") {
if (isInteger(content)) {
return `${basicTypes.integer}:${content.toString()}`;
} else {
return `${basicTypes.float}:${content.toString()}`;
}
}
/* Strings */
if (typeof content === "string")
return `${basicTypes.string}:${content.length}:"${content}"`;
/** This should be unreachable */
throw new OperationError(`Encountered a non-implemented type: ${typeof content}`);
}
/**
* Recursively serialize
* @param {*} object
* @returns {string}
*/
function serialize(object) {
/* Null */
if (object == null) {
return `N;`;
}
if (typeof object !== "object") {
/* Basic types */
return `${serializeBasicTypes(object)};`;
} else if (object instanceof Array) {
/* Arrays */
const serializedElements = [];
for (let i = 0; i < object.length; i++) {
serializedElements.push(`${serialize(i)}${serialize(object[i])}`);
}
return `a:${object.length}:{${serializedElements.join("")}}`;
} else if (object instanceof Object) {
/**
* Objects
* Note: the output cannot be guaranteed to be in the same order as the input
*/
const serializedElements = [];
const keys = Object.keys(object);
for (const key of keys) {
serializedElements.push(`${serialize(key)}${serialize(object[key])}`);
}
return `a:${keys.length}:{${serializedElements.join("")}}`;
}
/** This should be unreachable */
throw new OperationError(`Encountered a non-implemented type: ${typeof object}`);
}
return serialize(input);
}
}
export default PHPSerialize;

View file

@ -0,0 +1,884 @@
/**
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import {toHexFast} from "../lib/Hex.mjs";
import {objToTable} from "../lib/Protocol.mjs";
import Stream from "../lib/Stream.mjs";
/**
* Parse TLS record operation.
*/
class ParseTLSRecord extends Operation {
/**
* ParseTLSRecord constructor.
*/
constructor() {
super();
this.name = "Parse TLS record";
this.module = "Default";
this.description = "Parses one or more TLS records";
this.infoURL = "https://wikipedia.org/wiki/Transport_Layer_Security";
this.inputType = "ArrayBuffer";
this.outputType = "json";
this.presentType = "html";
this.args = [];
this._handshakeParser = new HandshakeParser();
this._contentTypes = new Map();
for (const key in ContentType) {
this._contentTypes[ContentType[key]] = key.toString().toLocaleLowerCase();
}
}
/**
* @param {ArrayBuffer} input - Stream, containing one or more raw TLS Records.
* @param {Object[]} args
* @returns {Object[]} Array of Object representations of TLS Records contained within input.
*/
run(input, args) {
const s = new Stream(new Uint8Array(input));
const output = [];
while (s.hasMore()) {
const record = this._readRecord(s);
if (record) {
output.push(record);
}
}
return output;
}
/**
* Reads a TLS Record from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw TLS Record.
* @returns {Object} Object representation of TLS Record.
*/
_readRecord(input) {
const RECORD_HEADER_LEN = 5;
if (input.position + RECORD_HEADER_LEN > input.length) {
input.moveTo(input.length);
return null;
}
const type = input.readInt(1);
const typeString = this._contentTypes[type] ?? type.toString();
const version = "0x" + toHexFast(input.getBytes(2));
const length = input.readInt(2);
const content = input.getBytes(length);
const truncated = content.length < length;
const recordHeader = new RecordHeader(typeString, version, length, truncated);
if (!content.length) {
return {...recordHeader};
}
if (type === ContentType.HANDSHAKE) {
return this._handshakeParser.parse(new Stream(content), recordHeader);
}
const record = {...recordHeader};
record.value = "0x" + toHexFast(content);
return record;
}
/**
* Displays the parsed TLS Records in a tabular style.
*
* @param {Object[]} data - Array of Object representations of the TLS Records.
* @returns {html} HTML representation of TLS Records contained within data.
*/
present(data) {
return data.map(r => objToTable(r)).join("\n\n");
}
}
export default ParseTLSRecord;
/**
* Repesents the known values of type field of a TLS Record header.
*/
const ContentType = Object.freeze({
CHANGE_CIPHER_SPEC: 20,
ALERT: 21,
HANDSHAKE: 22,
APPLICATION_DATA: 23,
});
/**
* Represents a TLS Record header
*/
class RecordHeader {
/**
* RecordHeader cosntructor.
*
* @param {string} type - String representation of TLS Record type field.
* @param {string} version - Hex representation of TLS Record version field.
* @param {int} length - Length of TLS Record.
* @param {bool} truncated - Is TLS Record truncated.
*/
constructor(type, version, length, truncated) {
this.type = type;
this.version = version;
this.length = length;
if (truncated) {
this.truncated = true;
}
}
}
/**
* Parses TLS Handshake messages.
*/
class HandshakeParser {
/**
* HandshakeParser constructor.
*/
constructor() {
this._clientHelloParser = new ClientHelloParser();
this._serverHelloParser = new ServerHelloParser();
this._newSessionTicketParser = new NewSessionTicketParser();
this._certificateParser = new CertificateParser();
this._certificateRequestParser = new CertificateRequestParser();
this._certificateVerifyParser = new CertificateVerifyParser();
this._handshakeTypes = new Map();
for (const key in HandshakeType) {
this._handshakeTypes[HandshakeType[key]] = key.toString().toLowerCase();
}
}
/**
* Parses a single TLS handshake message.
*
* @param {Stream} input - Stream, containing a raw Handshake message.
* @param {RecordHeader} recordHeader - TLS Record header.
* @returns {Object} Object representation of Handshake.
*/
parse(input, recordHeader) {
const output = {...recordHeader};
if (!input.hasMore()) {
return output;
}
const handshakeType = input.readInt(1);
output.handshakeType = this._handshakeTypes[handshakeType] ?? handshakeType.toString();
if (input.position + 3 > input.length) {
input.moveTo(input.length);
return output;
}
const handshakeLength = input.readInt(3);
if (handshakeLength + 4 !== recordHeader.length) {
input.moveTo(0);
output.handshakeType = this._handshakeTypes[HandshakeType.FINISHED];
output.handshakeValue = "0x" + toHexFast(input.bytes);
return output;
}
const content = input.getBytes(handshakeLength);
if (!content.length) {
return output;
}
switch (handshakeType) {
case HandshakeType.CLIENT_HELLO:
return {...output, ...this._clientHelloParser.parse(new Stream(content))};
case HandshakeType.SERVER_HELLO:
return {...output, ...this._serverHelloParser.parse(new Stream(content))};
case HandshakeType.NEW_SESSION_TICKET:
return {...output, ...this._newSessionTicketParser.parse(new Stream(content))};
case HandshakeType.CERTIFICATE:
return {...output, ...this._certificateParser.parse(new Stream(content))};
case HandshakeType.CERTIFICATE_REQUEST:
return {...output, ...this._certificateRequestParser.parse(new Stream(content))};
case HandshakeType.CERTIFICATE_VERIFY:
return {...output, ...this._certificateVerifyParser.parse(new Stream(content))};
default:
output.handshakeValue = "0x" + toHexFast(content);
}
return output;
}
}
/**
* Represents the known values of the msg_type field of a TLS Handshake message.
*/
const HandshakeType = Object.freeze({
HELLO_REQUEST: 0,
CLIENT_HELLO: 1,
SERVER_HELLO: 2,
NEW_SESSION_TICKET: 4,
CERTIFICATE: 11,
SERVER_KEY_EXCHANGE: 12,
CERTIFICATE_REQUEST: 13,
SERVER_HELLO_DONE: 14,
CERTIFICATE_VERIFY: 15,
CLIENT_KEY_EXCHANGE: 16,
FINISHED: 20,
});
/**
* Parses TLS Handshake ClientHello messages.
*/
class ClientHelloParser {
/**
* ClientHelloParser constructor.
*/
constructor() {
this._extensionsParser = new ExtensionsParser();
}
/**
* Parses a single TLS Handshake ClientHello message.
*
* @param {Stream} input - Stream, containing a raw ClientHello message.
* @returns {Object} Object representation of ClientHello.
*/
parse(input) {
const output = {};
output.clientVersion = this._readClientVersion(input);
output.random = this._readRandom(input);
const sessionID = this._readSessionID(input);
if (sessionID) {
output.sessionID = sessionID;
}
output.cipherSuites = this._readCipherSuites(input);
output.compressionMethods = this._readCompressionMethods(input);
output.extensions = this._readExtensions(input);
return output;
}
/**
* Reads the client_version field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ClientHello message, with position before client_version field.
* @returns {string} Hex representation of client_version.
*/
_readClientVersion(input) {
return readBytesAsHex(input, 2);
}
/**
* Reads the random field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ClientHello message, with position before random field.
* @returns {string} Hex representation of random.
*/
_readRandom(input) {
return readBytesAsHex(input, 32);
}
/**
* Reads the session_id field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ClientHello message, with position before session_id length field.
* @returns {string} Hex representation of session_id, or empty string if session_id not present.
*/
_readSessionID(input) {
return readSizePrefixedBytesAsHex(input, 1);
}
/**
* Reads the cipher_suites field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ClientHello message, with position before cipher_suites length field.
* @returns {Object} Object represention of cipher_suites field.
*/
_readCipherSuites(input) {
const output = {};
output.length = input.readInt(2);
if (!output.length) {
return {};
}
const cipherSuites = new Stream(input.getBytes(output.length));
if (cipherSuites.length < output.length) {
output.truncated = true;
}
output.values = [];
while (cipherSuites.hasMore()) {
const cipherSuite = readBytesAsHex(cipherSuites, 2);
if (cipherSuite) {
output.values.push(cipherSuite);
}
}
return output;
}
/**
* Reads the compression_methods field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ClientHello message, with position before compression_methods length field.
* @returns {Object} Object representation of compression_methods field.
*/
_readCompressionMethods(input) {
const output = {};
output.length = input.readInt(1);
if (!output.length) {
return {};
}
const compressionMethods = new Stream(input.getBytes(output.length));
if (compressionMethods.length < output.length) {
output.truncated = true;
}
output.values = [];
while (compressionMethods.hasMore()) {
const compressionMethod = readBytesAsHex(compressionMethods, 1);
if (compressionMethod) {
output.values.push(compressionMethod);
}
}
return output;
}
/**
* Reads the extensions field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ClientHello message, with position before extensions length field.
* @returns {Object} Object representations of extensions field.
*/
_readExtensions(input) {
const output = {};
output.length = input.readInt(2);
if (!output.length) {
return {};
}
const extensions = new Stream(input.getBytes(output.length));
if (extensions.length < output.length) {
output.truncated = true;
}
output.values = this._extensionsParser.parse(extensions);
return output;
}
}
/**
* Parses TLS Handshake ServeHello messages.
*/
class ServerHelloParser {
/**
* ServerHelloParser constructor.
*/
constructor() {
this._extensionsParser = new ExtensionsParser();
}
/**
* Parses a single TLS Handshake ServerHello message.
*
* @param {Stream} input - Stream, containing a raw ServerHello message.
* @return {Object} Object representation of ServerHello.
*/
parse(input) {
const output = {};
output.serverVersion = this._readServerVersion(input);
output.random = this._readRandom(input);
const sessionID = this._readSessionID(input);
if (sessionID) {
output.sessionID = sessionID;
}
output.cipherSuite = this._readCipherSuite(input);
output.compressionMethod = this._readCompressionMethod(input);
output.extensions = this._readExtensions(input);
return output;
}
/**
* Reads the server_version field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ServerHello message, with position before server_version field.
* @returns {string} Hex representation of server_version.
*/
_readServerVersion(input) {
return readBytesAsHex(input, 2);
}
/**
* Reads the random field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ServerHello message, with position before random field.
* @returns {string} Hex representation of random.
*/
_readRandom(input) {
return readBytesAsHex(input, 32);
}
/**
* Reads the session_id field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ServertHello message, with position before session_id length field.
* @returns {string} Hex representation of session_id, or empty string if session_id not present.
*/
_readSessionID(input) {
return readSizePrefixedBytesAsHex(input, 1);
}
/**
* Reads the cipher_suite field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ServerHello message, with position before cipher_suite field.
* @returns {string} Hex represention of cipher_suite.
*/
_readCipherSuite(input) {
return readBytesAsHex(input, 2);
}
/**
* Reads the compression_method field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ServerHello message, with position before compression_method field.
* @returns {string} Hex represention of compression_method.
*/
_readCompressionMethod(input) {
return readBytesAsHex(input, 1);
}
/**
* Reads the extensions field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw ServerHello message, with position before extensions length field.
* @returns {Object} Object representation of extensions field.
*/
_readExtensions(input) {
const output = {};
output.length = input.readInt(2);
if (!output.length) {
return {};
}
const extensions = new Stream(input.getBytes(output.length));
if (extensions.length < output.length) {
output.truncated = true;
}
output.values = this._extensionsParser.parse(extensions);
return output;
}
}
/**
* Parses TLS Handshake Hello Extensions.
*/
class ExtensionsParser {
/**
* Parses a stream of TLS Handshake Hello Extensions.
*
* @param {Stream} input - Stream, containing multiple raw Extensions, with position before first extension length field.
* @returns {Object[]} Array of Object representations of Extensions contained within input.
*/
parse(input) {
const output = [];
while (input.hasMore()) {
const extension = this._readExtension(input);
if (extension) {
output.push(extension);
}
}
return output;
}
/**
* Reads a single Extension from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a list of Extensions, with position before the length field of the next Extension.
* @returns {Object} Object representation of Extension.
*/
_readExtension(input) {
const output = {};
if (input.position + 4 > input.length) {
input.moveTo(input.length);
return null;
}
output.type = "0x" + toHexFast(input.getBytes(2));
output.length = input.readInt(2);
if (!output.length) {
return output;
}
const value = input.getBytes(output.length);
if (!value || value.length !== output.length) {
output.truncated = true;
}
if (value && value.length) {
output.value = "0x" + toHexFast(value);
}
return output;
}
}
/**
* Parses TLS Handshake NewSessionTicket messages.
*/
class NewSessionTicketParser {
/**
* Parses a single TLS Handshake NewSessionTicket message.
*
* @param {Stream} input - Stream, containing a raw NewSessionTicket message.
* @returns {Object} Object representation of NewSessionTicket.
*/
parse(input) {
return {
ticketLifetimeHint: this._readTicketLifetimeHint(input),
ticket: this._readTicket(input),
};
}
/**
* Reads the ticket_lifetime_hint field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw NewSessionTicket message, with position before ticket_lifetime_hint field.
* @returns {string} Lifetime hint, in seconds.
*/
_readTicketLifetimeHint(input) {
if (input.position + 4 > input.length) {
input.moveTo(input.length);
return "";
}
return input.readInt(4) + "s";
}
/**
* Reads the ticket field fromt the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw NewSessionTicket message, with position before ticket length field.
* @returns {string} Hex representation of ticket.
*/
_readTicket(input) {
return readSizePrefixedBytesAsHex(input, 2);
}
}
/**
* Parses TLS Handshake Certificate messages.
*/
class CertificateParser {
/**
* Parses a single TLS Handshake Certificate message.
*
* @param {Stream} input - Stream, containing a raw Certificate message.
* @returns {Object} Object representation of Certificate.
*/
parse(input) {
const output = {};
output.certificateList = this._readCertificateList(input);
return output;
}
/**
* Reads the certificate_list field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw Certificate message, with position before certificate_list length field.
* @returns {string[]} Array of strings, each containing a hex representation of a value within the certificate_list field.
*/
_readCertificateList(input) {
const output = {};
if (input.position + 3 > input.length) {
input.moveTo(input.length);
return output;
}
output.length = input.readInt(3);
if (!output.length) {
return output;
}
const certificates = new Stream(input.getBytes(output.length));
if (certificates.length < output.length) {
output.truncated = true;
}
output.values = [];
while (certificates.hasMore()) {
const certificate = this._readCertificate(certificates);
if (certificate) {
output.values.push(certificate);
}
}
return output;
}
/**
* Reads a single certificate from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a list of certificicates, with position before the length field of the next certificate.
* @returns {string} Hex representation of certificate.
*/
_readCertificate(input) {
return readSizePrefixedBytesAsHex(input, 3);
}
}
/**
* Parses TLS Handshake CertificateRequest messages.
*/
class CertificateRequestParser {
/**
* Parses a single TLS Handshake CertificateRequest message.
*
* @param {Stream} input - Stream, containing a raw CertificateRequest message.
* @return {Object} Object representation of CertificateRequest.
*/
parse(input) {
const output = {};
output.certificateTypes = this._readCertificateTypes(input);
output.supportedSignatureAlgorithms = this._readSupportedSignatureAlgorithms(input);
const certificateAuthorities = this._readCertificateAuthorities(input);
if (certificateAuthorities.length) {
output.certificateAuthorities = certificateAuthorities;
}
return output;
}
/**
* Reads the certificate_types field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw CertificateRequest message, with position before certificate_types length field.
* @return {string[]} Array of strings, each containing a hex representation of a value within the certificate_types field.
*/
_readCertificateTypes(input) {
const output = {};
output.length = input.readInt(1);
if (!output.length) {
return {};
}
const certificateTypes = new Stream(input.getBytes(output.length));
if (certificateTypes.length < output.length) {
output.truncated = true;
}
output.values = [];
while (certificateTypes.hasMore()) {
const certificateType = readBytesAsHex(certificateTypes, 1);
if (certificateType) {
output.values.push(certificateType);
}
}
return output;
}
/**
* Reads the supported_signature_algorithms field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw CertificateRequest message, with position before supported_signature_algorithms length field.
* @returns {string[]} Array of strings, each containing a hex representation of a value within the supported_signature_algorithms field.
*/
_readSupportedSignatureAlgorithms(input) {
const output = {};
output.length = input.readInt(2);
if (!output.length) {
return {};
}
const signatureAlgorithms = new Stream(input.getBytes(output.length));
if (signatureAlgorithms.length < output.length) {
output.truncated = true;
}
output.values = [];
while (signatureAlgorithms.hasMore()) {
const signatureAlgorithm = readBytesAsHex(signatureAlgorithms, 2);
if (signatureAlgorithm) {
output.values.push(signatureAlgorithm);
}
}
return output;
}
/**
* Reads the certificate_authorities field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw CertificateRequest message, with position before certificate_authorities length field.
* @returns {string[]} Array of strings, each containing a hex representation of a value within the certificate_authorities field.
*/
_readCertificateAuthorities(input) {
const output = {};
output.length = input.readInt(2);
if (!output.length) {
return {};
}
const certificateAuthorities = new Stream(input.getBytes(output.length));
if (certificateAuthorities.length < output.length) {
output.truncated = true;
}
output.values = [];
while (certificateAuthorities.hasMore()) {
const certificateAuthority = this._readCertificateAuthority(certificateAuthorities);
if (certificateAuthority) {
output.values.push(certificateAuthority);
}
}
return output;
}
/**
* Reads a single certificate authority from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a list of raw certificate authorities, with position before the length field of the next certificate authority.
* @returns {string} Hex representation of certificate authority.
*/
_readCertificateAuthority(input) {
return readSizePrefixedBytesAsHex(input, 2);
}
}
/**
* Parses TLS Handshake CertificateVerify messages.
*/
class CertificateVerifyParser {
/**
* Parses a single CertificateVerify Message.
*
* @param {Stream} input - Stream, containing a raw CertificateVerify message.
* @returns {Object} Object representation of CertificateVerify.
*/
parse(input) {
return {
algorithmHash: this._readAlgorithmHash(input),
algorithmSignature: this._readAlgorithmSignature(input),
signature: this._readSignature(input),
};
}
/**
* Reads the algorithm.hash field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw CertificateVerify message, with position before algorithm.hash field.
* @return {string} Hex representation of hash algorithm.
*/
_readAlgorithmHash(input) {
return readBytesAsHex(input, 1);
}
/**
* Reads the algorithm.signature field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw CertificateVerify message, with position before algorithm.signature field.
* @return {string} Hex representation of signature algorithm.
*/
_readAlgorithmSignature(input) {
return readBytesAsHex(input, 1);
}
/**
* Reads the signature field from the following bytes in the provided Stream.
*
* @param {Stream} input - Stream, containing a raw CertificateVerify message, with position before signature field.
* @return {string} Hex representation of signature.
*/
_readSignature(input) {
return readSizePrefixedBytesAsHex(input, 2);
}
}
/**
* Read the following size prefixed bytes from the provided Stream, and reuturn as a hex string.
*
* @param {Stream} input - Stream to read from.
* @param {int} sizePrefixLength - Length of the size prefix field.
* @returns {string} Hex representation of bytes read from Stream, empty string is returned if
* field cannot be read in full.
*/
function readSizePrefixedBytesAsHex(input, sizePrefixLength) {
const length = input.readInt(sizePrefixLength);
if (!length) {
return "";
}
return readBytesAsHex(input, length);
}
/**
* Read n bytes from the provided Stream, and return as a hex string.
*
* @param {Stream} input - Stream to read from.
* @param {int} n - Number of bytes to read.
* @returns {string} Hex representation of bytes read from Stream, or empty string if field cannot
* be read in full.
*/
function readBytesAsHex(input, n) {
const bytes = input.getBytes(n);
if (!bytes || bytes.length !== n) {
return "";
}
return "0x" + toHexFast(bytes);
}

View file

@ -0,0 +1,391 @@
/**
* @author robinsandhu
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import r from "jsrsasign";
import Operation from "../Operation.mjs";
import { fromBase64 } from "../lib/Base64.mjs";
import { toHex } from "../lib/Hex.mjs";
import { formatDnObj } from "../lib/PublicKey.mjs";
import OperationError from "../errors/OperationError.mjs";
import Utils from "../Utils.mjs";
/**
* Parse X.509 CRL operation
*/
class ParseX509CRL extends Operation {
/**
* ParseX509CRL constructor
*/
constructor() {
super();
this.name = "Parse X.509 CRL";
this.module = "PublicKey";
this.description = "Parse Certificate Revocation List (CRL)";
this.infoURL = "https://wikipedia.org/wiki/Certificate_revocation_list";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Input format",
"type": "option",
"value": ["PEM", "DER Hex", "Base64", "Raw"]
}
];
this.checks = [
{
"pattern": "^-+BEGIN X509 CRL-+\\r?\\n[\\da-z+/\\n\\r]+-+END X509 CRL-+\\r?\\n?$",
"flags": "i",
"args": ["PEM"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string} Human-readable description of a Certificate Revocation List (CRL).
*/
run(input, args) {
if (!input.length) {
return "No input";
}
const inputFormat = args[0];
let undefinedInputFormat = false;
try {
switch (inputFormat) {
case "DER Hex":
input = input.replace(/\s/g, "").toLowerCase();
break;
case "PEM":
break;
case "Base64":
input = toHex(fromBase64(input, null, "byteArray"), "");
break;
case "Raw":
input = toHex(Utils.strToArrayBuffer(input), "");
break;
default:
undefinedInputFormat = true;
}
} catch (e) {
throw "Certificate load error (non-certificate input?)";
}
if (undefinedInputFormat) throw "Undefined input format";
const crl = new r.X509CRL(input);
let out = `Certificate Revocation List (CRL):
Version: ${crl.getVersion() === null ? "1 (0x0)" : "2 (0x1)"}
Signature Algorithm: ${crl.getSignatureAlgorithmField()}
Issuer:\n${formatDnObj(crl.getIssuer(), 8)}
Last Update: ${generalizedDateTimeToUTC(crl.getThisUpdate())}
Next Update: ${generalizedDateTimeToUTC(crl.getNextUpdate())}\n`;
if (crl.getParam().ext !== undefined) {
out += `\tCRL extensions:\n${formatCRLExtensions(crl.getParam().ext, 8)}\n`;
}
out += `Revoked Certificates:\n${formatRevokedCertificates(crl.getRevCertArray(), 4)}
Signature Value:\n${formatCRLSignature(crl.getSignatureValueHex(), 8)}`;
return out;
}
}
/**
* Generalized date time string to UTC.
* @param {string} datetime
* @returns UTC datetime string.
*/
function generalizedDateTimeToUTC(datetime) {
// Ensure the string is in the correct format
if (!/^\d{12,14}Z$/.test(datetime)) {
throw new OperationError(`failed to format datetime string ${datetime}`);
}
// Extract components
let centuary = "20";
if (datetime.length === 15) {
centuary = datetime.substring(0, 2);
datetime = datetime.slice(2);
}
const year = centuary + datetime.substring(0, 2);
const month = datetime.substring(2, 4);
const day = datetime.substring(4, 6);
const hour = datetime.substring(6, 8);
const minute = datetime.substring(8, 10);
const second = datetime.substring(10, 12);
// Construct ISO 8601 format string
const isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}Z`;
// Parse using standard Date object
const isoDateTime = new Date(isoString);
return isoDateTime.toUTCString();
}
/**
* Format CRL extensions.
* @param {r.ExtParam[] | undefined} extensions
* @param {Number} indent
* @returns Formatted string detailing CRL extensions.
*/
function formatCRLExtensions(extensions, indent) {
if (Array.isArray(extensions) === false || extensions.length === 0) {
return indentString(`No CRL extensions.`, indent);
}
let out = ``;
extensions.sort((a, b) => {
if (!Object.hasOwn(a, "extname") || !Object.hasOwn(b, "extname")) {
return 0;
}
if (a.extname < b.extname) {
return -1;
} else if (a.extname === b.extname) {
return 0;
} else {
return 1;
}
});
extensions.forEach((ext) => {
if (!Object.hasOwn(ext, "extname")) {
throw new OperationError(`CRL entry extension object missing 'extname' key: ${ext}`);
}
switch (ext.extname) {
case "authorityKeyIdentifier":
out += `X509v3 Authority Key Identifier:\n`;
if (Object.hasOwn(ext, "kid")) {
out += `\tkeyid:${colonDelimitedHexFormatString(ext.kid.hex.toUpperCase())}\n`;
}
if (Object.hasOwn(ext, "issuer")) {
out += `\tDirName:${ext.issuer.str}\n`;
}
if (Object.hasOwn(ext, "sn")) {
out += `\tserial:${colonDelimitedHexFormatString(ext.sn.hex.toUpperCase())}\n`;
}
break;
case "cRLDistributionPoints":
out += `X509v3 CRL Distribution Points:\n`;
ext.array.forEach((distPoint) => {
const fullName = `Full Name:\n${formatGeneralNames(distPoint.dpname.full, 4)}`;
out += indentString(fullName, 4) + "\n";
});
break;
case "cRLNumber":
if (!Object.hasOwn(ext, "num")) {
throw new OperationError(`'cRLNumber' CRL entry extension missing 'num' key: ${ext}`);
}
out += `X509v3 CRL Number:\n\t${ext.num.hex.toUpperCase()}\n`;
break;
case "issuerAltName":
out += `X509v3 Issuer Alternative Name:\n${formatGeneralNames(ext.array, 4)}\n`;
break;
default:
out += `${ext.extname}:\n`;
out += `\tUnsupported CRL extension. Try openssl CLI.\n`;
break;
}
});
return indentString(chop(out), indent);
}
/**
* Format general names array.
* @param {Object[]} names
* @returns Multi-line formatted string describing all supported general name types.
*/
function formatGeneralNames(names, indent) {
let out = ``;
names.forEach((name) => {
const key = Object.keys(name)[0];
switch (key) {
case "ip":
out += `IP:${name.ip}\n`;
break;
case "dns":
out += `DNS:${name.dns}\n`;
break;
case "uri":
out += `URI:${name.uri}\n`;
break;
case "rfc822":
out += `EMAIL:${name.rfc822}\n`;
break;
case "dn":
out += `DIR:${name.dn.str}\n`;
break;
case "other":
out += `OtherName:${name.other.oid}::${Object.values(name.other.value)[0].str}\n`;
break;
default:
out += `${key}: unsupported general name type`;
break;
}
});
return indentString(chop(out), indent);
}
/**
* Colon-delimited hex formatted output.
* @param {string} hexString Hex String
* @returns String representing input hex string with colon delimiter.
*/
function colonDelimitedHexFormatString(hexString) {
if (hexString.length % 2 !== 0) {
hexString = "0" + hexString;
}
return chop(hexString.replace(/(..)/g, "$&:"));
}
/**
* Format revoked certificates array
* @param {r.RevokedCertificate[] | null} revokedCertificates
* @param {Number} indent
* @returns Multi-line formatted string output of revoked certificates array
*/
function formatRevokedCertificates(revokedCertificates, indent) {
if (Array.isArray(revokedCertificates) === false || revokedCertificates.length === 0) {
return indentString("No Revoked Certificates.", indent);
}
let out=``;
revokedCertificates.forEach((revCert) => {
if (!Object.hasOwn(revCert, "sn") || !Object.hasOwn(revCert, "date")) {
throw new OperationError("invalid revoked certificate object, missing either serial number or date");
}
out += `Serial Number: ${revCert.sn.hex.toUpperCase()}
Revocation Date: ${generalizedDateTimeToUTC(revCert.date)}\n`;
if (Object.hasOwn(revCert, "ext") && Array.isArray(revCert.ext) && revCert.ext.length !== 0) {
out += `\tCRL entry extensions:\n${indentString(formatCRLEntryExtensions(revCert.ext), 2*indent)}\n`;
}
});
return indentString(chop(out), indent);
}
/**
* Format CRL entry extensions.
* @param {Object[]} exts
* @returns Formatted multi-line string describing CRL entry extensions.
*/
function formatCRLEntryExtensions(exts) {
let out = ``;
const crlReasonCodeToReasonMessage = {
0: "Unspecified",
1: "Key Compromise",
2: "CA Compromise",
3: "Affiliation Changed",
4: "Superseded",
5: "Cessation Of Operation",
6: "Certificate Hold",
8: "Remove From CRL",
9: "Privilege Withdrawn",
10: "AA Compromise",
};
const holdInstructionOIDToName = {
"1.2.840.10040.2.1": "Hold Instruction None",
"1.2.840.10040.2.2": "Hold Instruction Call Issuer",
"1.2.840.10040.2.3": "Hold Instruction Reject",
};
exts.forEach((ext) => {
if (!Object.hasOwn(ext, "extname")) {
throw new OperationError(`CRL entry extension object missing 'extname' key: ${ext}`);
}
switch (ext.extname) {
case "cRLReason":
if (!Object.hasOwn(ext, "code")) {
throw new OperationError(`'cRLReason' CRL entry extension missing 'code' key: ${ext}`);
}
out += `X509v3 CRL Reason Code:
${Object.hasOwn(crlReasonCodeToReasonMessage, ext.code) ? crlReasonCodeToReasonMessage[ext.code] : `invalid reason code: ${ext.code}`}\n`;
break;
case "2.5.29.23": // Hold instruction
out += `Hold Instruction Code:\n\t${Object.hasOwn(holdInstructionOIDToName, ext.extn.oid) ? holdInstructionOIDToName[ext.extn.oid] : `${ext.extn.oid}: unknown hold instruction OID`}\n`;
break;
case "2.5.29.24": // Invalidity Date
out += `Invalidity Date:\n\t${generalizedDateTimeToUTC(ext.extn.gentime.str)}\n`;
break;
default:
out += `${ext.extname}:\n`;
out += `\tUnsupported CRL entry extension. Try openssl CLI.\n`;
break;
}
});
return chop(out);
}
/**
* Format CRL signature.
* @param {String} sigHex
* @param {Number} indent
* @returns String representing hex signature value formatted on multiple lines.
*/
function formatCRLSignature(sigHex, indent) {
if (sigHex.length % 2 !== 0) {
sigHex = "0" + sigHex;
}
return indentString(formatMultiLine(chop(sigHex.replace(/(..)/g, "$&:"))), indent);
}
/**
* Format string onto multiple lines.
* @param {string} longStr
* @returns String as a multi-line string.
*/
function formatMultiLine(longStr) {
const lines = [];
for (let remain = longStr ; remain !== "" ; remain = remain.substring(54)) {
lines.push(remain.substring(0, 54));
}
return lines.join("\n");
}
/**
* Indent a multi-line string by n spaces.
* @param {string} input String
* @param {number} spaces How many leading spaces
* @returns Indented string.
*/
function indentString(input, spaces) {
const indent = " ".repeat(spaces);
return input.replace(/^/gm, indent);
}
/**
* Remove last character from a string.
* @param {string} s String
* @returns Chopped string.
*/
function chop(s) {
if (s.length < 1) {
return s;
}
return s.substring(0, s.length - 1);
}
export default ParseX509CRL;

View file

@ -6,7 +6,8 @@
import r from "jsrsasign"; import r from "jsrsasign";
import { fromBase64 } from "../lib/Base64.mjs"; import { fromBase64 } from "../lib/Base64.mjs";
import { toHex } from "../lib/Hex.mjs"; import { runHash } from "../lib/Hash.mjs";
import { fromHex, toHex } from "../lib/Hex.mjs";
import { formatByteStr, formatDnObj } from "../lib/PublicKey.mjs"; import { formatByteStr, formatDnObj } from "../lib/PublicKey.mjs";
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs"; import Utils from "../Utils.mjs";
@ -81,7 +82,8 @@ class ParseX509Certificate extends Operation {
} }
if (undefinedInputFormat) throw "Undefined input format"; if (undefinedInputFormat) throw "Undefined input format";
const sn = cert.getSerialNumberHex(), const hex = Utils.strToArrayBuffer(Utils.byteArrayToChars(fromHex(cert.hex))),
sn = cert.getSerialNumberHex(),
issuer = cert.getIssuer(), issuer = cert.getIssuer(),
subject = cert.getSubject(), subject = cert.getSubject(),
pk = cert.getPublicKey(), pk = cert.getPublicKey(),
@ -191,6 +193,10 @@ Issuer
${issuerStr} ${issuerStr}
Subject Subject
${subjectStr} ${subjectStr}
Fingerprints
MD5: ${runHash("md5", hex)}
SHA1: ${runHash("sha1", hex)}
SHA256: ${runHash("sha256", hex)}
Public Key Public Key
${pkStr.slice(0, -1)} ${pkStr.slice(0, -1)}
Certificate Signature Certificate Signature

View file

@ -59,15 +59,16 @@ class ROT13 extends Operation {
rot13Upperacse = args[1], rot13Upperacse = args[1],
rotNumbers = args[2]; rotNumbers = args[2];
let amount = args[3], let amount = args[3],
chr; amountNumbers = args[3];
if (amount) { if (amount) {
if (amount < 0) { if (amount < 0) {
amount = 26 - (Math.abs(amount) % 26); amount = 26 - (Math.abs(amount) % 26);
amountNumbers = 10 - (Math.abs(amountNumbers) % 10);
} }
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
chr = input[i]; let chr = input[i];
if (rot13Upperacse && chr >= 65 && chr <= 90) { // Upper case if (rot13Upperacse && chr >= 65 && chr <= 90) { // Upper case
chr = (chr - 65 + amount) % 26; chr = (chr - 65 + amount) % 26;
output[i] = chr + 65; output[i] = chr + 65;
@ -75,7 +76,7 @@ class ROT13 extends Operation {
chr = (chr - 97 + amount) % 26; chr = (chr - 97 + amount) % 26;
output[i] = chr + 97; output[i] = chr + 97;
} else if (rotNumbers && chr >= 48 && chr <= 57) { // Numbers } else if (rotNumbers && chr >= 48 && chr <= 57) { // Numbers
chr = (chr - 48 + amount) % 10; chr = (chr - 48 + amountNumbers) % 10;
output[i] = chr + 48; output[i] = chr + 48;
} }
} }

View file

@ -60,7 +60,7 @@ class RSASign extends Operation {
const privateKey = forge.pki.decryptRsaPrivateKey(key, password); const privateKey = forge.pki.decryptRsaPrivateKey(key, password);
// Generate message hash // Generate message hash
const md = MD_ALGORITHMS[mdAlgo].create(); const md = MD_ALGORITHMS[mdAlgo].create();
md.update(input, "utf8"); md.update(input, "raw");
// Sign message hash // Sign message hash
const sig = privateKey.sign(md); const sig = privateKey.sign(md);
return sig; return sig;

View file

@ -8,6 +8,7 @@ import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs"; import OperationError from "../errors/OperationError.mjs";
import forge from "node-forge"; import forge from "node-forge";
import { MD_ALGORITHMS } from "../lib/RSA.mjs"; import { MD_ALGORITHMS } from "../lib/RSA.mjs";
import Utils from "../Utils.mjs";
/** /**
* RSA Verify operation * RSA Verify operation
@ -37,6 +38,11 @@ class RSAVerify extends Operation {
type: "text", type: "text",
value: "" value: ""
}, },
{
name: "Message format",
type: "option",
value: ["Raw", "Hex", "Base64"]
},
{ {
name: "Message Digest Algorithm", name: "Message Digest Algorithm",
type: "option", type: "option",
@ -51,7 +57,7 @@ class RSAVerify extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const [pemKey, message, mdAlgo] = args; const [pemKey, message, format, mdAlgo] = args;
if (pemKey.replace("-----BEGIN RSA PUBLIC KEY-----", "").length === 0) { if (pemKey.replace("-----BEGIN RSA PUBLIC KEY-----", "").length === 0) {
throw new OperationError("Please enter a public key."); throw new OperationError("Please enter a public key.");
} }
@ -60,7 +66,8 @@ class RSAVerify extends Operation {
const pubKey = forge.pki.publicKeyFromPem(pemKey); const pubKey = forge.pki.publicKeyFromPem(pemKey);
// Generate message digest // Generate message digest
const md = MD_ALGORITHMS[mdAlgo].create(); const md = MD_ALGORITHMS[mdAlgo].create();
md.update(message, "utf8"); const messageStr = Utils.convertToByteString(message, format);
md.update(messageStr, "raw");
// Compare signed message digest and generated message digest // Compare signed message digest and generated message digest
const result = pubKey.verify(md.digest().bytes(), input); const result = pubKey.verify(md.digest().bytes(), input);
return result ? "Verified OK" : "Verification Failure"; return result ? "Verified OK" : "Verification Failure";

View file

@ -0,0 +1,71 @@
/**
* @author flakjacket95 [dflack95@gmail.com]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
import Operation from "../Operation.mjs";
import { SM2 } from "../lib/SM2.mjs";
/**
* SM2Decrypt operation
*/
class SM2Decrypt extends Operation {
/**
* SM2Decrypt constructor
*/
constructor() {
super();
this.name = "SM2 Decrypt";
this.module = "Crypto";
this.description = "Decrypts a message utilizing the SM2 standard";
this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc)
this.inputType = "string";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Private Key",
type: "string",
value: "DEADBEEF"
},
{
"name": "Input Format",
"type": "option",
"value": ["C1C3C2", "C1C2C3"],
"defaultIndex": 0
},
{
name: "Curve",
type: "option",
"value": ["sm2p256v1"],
"defaultIndex": 0
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const [privateKey, inputFormat, curveName] = args;
if (privateKey.length !== 64) {
throw new OperationError("Input private key must be in hex; and should be 32 bytes");
}
const sm2 = new SM2(curveName, inputFormat);
sm2.setPrivateKey(privateKey);
const result = sm2.decrypt(input);
return result;
}
}
export default SM2Decrypt;

View file

@ -0,0 +1,77 @@
/**
* @author flakjacket95 [dflack95@gmail.com]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
import Operation from "../Operation.mjs";
import { SM2 } from "../lib/SM2.mjs";
/**
* SM2 Encrypt operation
*/
class SM2Encrypt extends Operation {
/**
* SM2Encrypt constructor
*/
constructor() {
super();
this.name = "SM2 Encrypt";
this.module = "Crypto";
this.description = "Encrypts a message utilizing the SM2 standard";
this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc)
this.inputType = "ArrayBuffer";
this.outputType = "string";
this.args = [
{
name: "Public Key X",
type: "string",
value: "DEADBEEF"
},
{
name: "Public Key Y",
type: "string",
value: "DEADBEEF"
},
{
"name": "Output Format",
"type": "option",
"value": ["C1C3C2", "C1C2C3"],
"defaultIndex": 0
},
{
name: "Curve",
type: "option",
"value": ["sm2p256v1"],
"defaultIndex": 0
}
];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
const [publicKeyX, publicKeyY, outputFormat, curveName] = args;
this.outputFormat = outputFormat;
if (publicKeyX.length !== 64 || publicKeyY.length !== 64) {
throw new OperationError("Invalid Public Key - Ensure each component is 32 bytes in size and in hex");
}
const sm2 = new SM2(curveName, outputFormat);
sm2.setPublicKey(publicKeyX, publicKeyY);
const result = sm2.encrypt(new Uint8Array(input));
return result;
}
}
export default SM2Encrypt;

View file

@ -0,0 +1,57 @@
/**
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import Stream from "../lib/Stream.mjs";
/**
* Strip IPv4 header operation
*/
class StripIPv4Header extends Operation {
/**
* StripIPv4Header constructor
*/
constructor() {
super();
this.name = "Strip IPv4 header";
this.module = "Default";
this.description = "Strips the IPv4 header from an IPv4 packet, outputting the payload.";
this.infoURL = "https://wikipedia.org/wiki/IPv4";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const MIN_HEADER_LEN = 20;
const s = new Stream(new Uint8Array(input));
if (s.length < MIN_HEADER_LEN) {
throw new OperationError("Input length is less than minimum IPv4 header length");
}
const ihl = s.readInt(1) & 0x0f;
const dataOffsetBytes = ihl * 4;
if (s.length < dataOffsetBytes) {
throw new OperationError("Input length is less than IHL");
}
s.moveTo(dataOffsetBytes);
return s.getBytes().buffer;
}
}
export default StripIPv4Header;

View file

@ -0,0 +1,60 @@
/**
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import Stream from "../lib/Stream.mjs";
/**
* Strip TCP header operation
*/
class StripTCPHeader extends Operation {
/**
* StripTCPHeader constructor
*/
constructor() {
super();
this.name = "Strip TCP header";
this.module = "Default";
this.description = "Strips the TCP header from a TCP segment, outputting the payload.";
this.infoURL = "https://wikipedia.org/wiki/Transmission_Control_Protocol";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const MIN_HEADER_LEN = 20;
const DATA_OFFSET_OFFSET = 12;
const DATA_OFFSET_LEN_BITS = 4;
const s = new Stream(new Uint8Array(input));
if (s.length < MIN_HEADER_LEN) {
throw new OperationError("Need at least 20 bytes for a TCP Header");
}
s.moveTo(DATA_OFFSET_OFFSET);
const dataOffsetWords = s.readBits(DATA_OFFSET_LEN_BITS);
const dataOffsetBytes = dataOffsetWords * 4;
if (s.length < dataOffsetBytes) {
throw new OperationError("Input length is less than data offset");
}
s.moveTo(dataOffsetBytes);
return s.getBytes().buffer;
}
}
export default StripTCPHeader;

View file

@ -0,0 +1,51 @@
/**
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Stream from "../lib/Stream.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Strip UDP header operation
*/
class StripUDPHeader extends Operation {
/**
* StripUDPHeader constructor
*/
constructor() {
super();
this.name = "Strip UDP header";
this.module = "Default";
this.description = "Strips the UDP header from a UDP datagram, outputting the payload.";
this.infoURL = "https://wikipedia.org/wiki/User_Datagram_Protocol";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const HEADER_LEN = 8;
const s = new Stream(new Uint8Array(input));
if (s.length < HEADER_LEN) {
throw new OperationError("Need 8 bytes for a UDP Header");
}
s.moveTo(HEADER_LEN);
return s.getBytes().buffer;
}
}
export default StripUDPHeader;

View file

@ -0,0 +1,79 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Take nth bytes operation
*/
class TakeNthBytes extends Operation {
/**
* TakeNthBytes constructor
*/
constructor() {
super();
this.name = "Take nth bytes";
this.module = "Default";
this.description = "Takes every nth byte starting with a given byte.";
this.infoURL = "";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.args = [
{
name: "Take every",
type: "number",
value: 4
},
{
name: "Starting at",
type: "number",
value: 0
},
{
name: "Apply to each line",
type: "boolean",
value: false
}
];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
const n = args[0];
const start = args[1];
const eachLine = args[2];
if (parseInt(n, 10) !== n || n <= 0) {
throw new OperationError("'Take every' must be a positive integer.");
}
if (parseInt(start, 10) !== start || start < 0) {
throw new OperationError("'Starting at' must be a positive or zero integer.");
}
let offset = 0;
const output = [];
for (let i = 0; i < input.length; i++) {
if (eachLine && input[i] === 0x0a) {
output.push(0x0a);
offset = i + 1;
} else if (i - offset >= start && (i - (start + offset)) % n === 0) {
output.push(input[i]);
}
}
return output;
}
}
export default TakeNthBytes;

View file

@ -6,6 +6,7 @@
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs"; import Utils from "../Utils.mjs";
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
/** /**
* To Base32 operation * To Base32 operation
@ -27,8 +28,8 @@ class ToBase32 extends Operation {
this.args = [ this.args = [
{ {
name: "Alphabet", name: "Alphabet",
type: "binaryString", type: "editableOption",
value: "A-Z2-7=" value: ALPHABET_OPTIONS
} }
]; ];
} }
@ -83,3 +84,4 @@ class ToBase32 extends Operation {
} }
export default ToBase32; export default ToBase32;

View file

@ -0,0 +1,55 @@
/**
* @author linuxgemini [ilteris@asenkron.com.tr]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import { TO_MODHEX_DELIM_OPTIONS, toModhex } from "../lib/Modhex.mjs";
import Utils from "../Utils.mjs";
/**
* To Modhex operation
*/
class ToModhex extends Operation {
/**
* ToModhex constructor
*/
constructor() {
super();
this.name = "To Modhex";
this.module = "Default";
this.description = "Converts the input string to modhex bytes separated by the specified delimiter.";
this.infoURL = "https://en.wikipedia.org/wiki/YubiKey#ModHex";
this.inputType = "ArrayBuffer";
this.outputType = "string";
this.args = [
{
name: "Delimiter",
type: "option",
value: TO_MODHEX_DELIM_OPTIONS
},
{
name: "Bytes per line",
type: "number",
value: 0
}
];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const delim = Utils.charRep(args[0]);
const lineSize = args[1];
return toModhex(new Uint8Array(input), delim, 2, "", lineSize);
}
}
export default ToModhex;

View file

@ -22,7 +22,7 @@ class TripleDESDecrypt extends Operation {
this.name = "Triple DES Decrypt"; this.name = "Triple DES Decrypt";
this.module = "Ciphers"; this.module = "Ciphers";
this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default."; this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.";
this.infoURL = "https://wikipedia.org/wiki/Triple_DES"; this.infoURL = "https://wikipedia.org/wiki/Triple_DES";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
@ -73,8 +73,7 @@ class TripleDESDecrypt extends Operation {
if (key.length !== 24 && key.length !== 16) { if (key.length !== 24 && key.length !== 16) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
Triple DES uses a key length of 24 bytes (192 bits). Triple DES uses a key length of 24 bytes (192 bits).`);
DES uses a key length of 8 bytes (64 bits).`);
} }
if (iv.length !== 8 && mode !== "ECB") { if (iv.length !== 8 && mode !== "ECB") {
throw new OperationError(`Invalid IV length: ${iv.length} bytes throw new OperationError(`Invalid IV length: ${iv.length} bytes

View file

@ -22,7 +22,7 @@ class TripleDESEncrypt extends Operation {
this.name = "Triple DES Encrypt"; this.name = "Triple DES Encrypt";
this.module = "Ciphers"; this.module = "Ciphers";
this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used."; this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used.";
this.infoURL = "https://wikipedia.org/wiki/Triple_DES"; this.infoURL = "https://wikipedia.org/wiki/Triple_DES";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
@ -72,8 +72,7 @@ class TripleDESEncrypt extends Operation {
if (key.length !== 24 && key.length !== 16) { if (key.length !== 24 && key.length !== 16) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
Triple DES uses a key length of 24 bytes (192 bits). Triple DES uses a key length of 24 bytes (192 bits).`);
DES uses a key length of 8 bytes (64 bits).`);
} }
if (iv.length !== 8 && mode !== "ECB") { if (iv.length !== 8 && mode !== "ECB") {
throw new OperationError(`Invalid IV length: ${iv.length} bytes throw new OperationError(`Invalid IV length: ${iv.length} bytes

View file

@ -0,0 +1,45 @@
/**
* @author ccarpo [ccarpo@gmx.net]
* @copyright Crown Copyright 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import jsYaml from "js-yaml";
/**
* YAML to JSON operation
*/
class YAMLToJSON extends Operation {
/**
* YAMLToJSON constructor
*/
constructor() {
super();
this.name = "YAML to JSON";
this.module = "Default";
this.description = "Convert YAML to JSON";
this.infoURL = "https://en.wikipedia.org/wiki/YAML";
this.inputType = "string";
this.outputType = "JSON";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {JSON}
*/
run(input, args) {
try {
return jsYaml.load(input);
} catch (err) {
throw new OperationError("Unable to parse YAML: " + err);
}
}
}
export default YAMLToJSON;

View file

@ -23,7 +23,7 @@ const dir = path.join(`${process.cwd()}/src/node`);
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
console.log("\nCWD: " + process.cwd()); console.log("\nCWD: " + process.cwd());
console.log("Error: generateNodeIndex.mjs should be run from the project root"); console.log("Error: generateNodeIndex.mjs should be run from the project root");
console.log("Example> node --experimental-modules src/core/config/scripts/generateNodeIndex.mjs"); console.log("Example> node --experimental-modules src/node/config/scripts/generateNodeIndex.mjs");
process.exit(1); process.exit(1);
} }

3
src/web/App.mjs Executable file → Normal file
View file

@ -60,6 +60,7 @@ class App {
this.initialiseSplitter(); this.initialiseSplitter();
this.loadLocalStorage(); this.loadLocalStorage();
this.manager.options.applyPreferredColorScheme();
this.populateOperationsList(); this.populateOperationsList();
this.manager.setup(); this.manager.setup();
this.manager.output.saveBombe(); this.manager.output.saveBombe();
@ -536,6 +537,8 @@ class App {
// Read in theme from URI params // Read in theme from URI params
if (this.uriParams.theme) { if (this.uriParams.theme) {
this.manager.options.changeTheme(Utils.escapeHtml(this.uriParams.theme)); this.manager.options.changeTheme(Utils.escapeHtml(this.uriParams.theme));
} else {
this.manager.options.applyPreferredColorScheme();
} }
window.dispatchEvent(this.manager.statechange); window.dispatchEvent(this.manager.statechange);

29
src/web/waiters/OptionsWaiter.mjs Executable file → Normal file
View file

@ -160,9 +160,36 @@ class OptionsWaiter {
// Update theme selection // Update theme selection
const themeSelect = document.getElementById("theme"); const themeSelect = document.getElementById("theme");
themeSelect.selectedIndex = themeSelect.querySelector(`option[value="${theme}"`).index; let themeOption = themeSelect.querySelector(`option[value="${theme}"]`);
if (!themeOption) {
const preferredColorScheme = this.getPreferredColorScheme();
document.querySelector(":root").className = preferredColorScheme;
themeOption = themeSelect.querySelector(`option[value="${preferredColorScheme}"]`);
}
themeSelect.selectedIndex = themeOption.index;
} }
/**
* Applies the user's preferred color scheme using the `prefers-color-scheme` media query.
*/
applyPreferredColorScheme() {
const themeFromStorage = this.app?.options?.theme;
let theme = themeFromStorage;
if (!theme) {
theme = this.getPreferredColorScheme();
}
this.changeTheme(theme);
}
/**
* Get the user's preferred color scheme using the `prefers-color-scheme` media query.
*/
getPreferredColorScheme() {
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)").matches;
return prefersDarkScheme ? "dark" : "classic";
}
/** /**
* Changes the console logging level. * Changes the console logging level.

View file

@ -8,6 +8,7 @@ import HTMLOperation from "../HTMLOperation.mjs";
import Sortable from "sortablejs"; import Sortable from "sortablejs";
import Utils from "../../core/Utils.mjs"; import Utils from "../../core/Utils.mjs";
import {escapeControlChars} from "../utils/editorUtils.mjs"; import {escapeControlChars} from "../utils/editorUtils.mjs";
import DOMPurify from "dompurify";
/** /**
@ -435,7 +436,9 @@ class RecipeWaiter {
const item = document.createElement("li"); const item = document.createElement("li");
item.classList.add("operation"); item.classList.add("operation");
item.innerHTML = name; const clean = DOMPurify.sanitize(name);
item.innerHTML = clean;
this.buildRecipeOperation(item); this.buildRecipeOperation(item);
document.getElementById("rec-list").appendChild(item); document.getElementById("rec-list").appendChild(item);

View file

@ -675,42 +675,42 @@ module.exports = {
} }
}, },
"Loading from URL": browser => { // "Loading from URL": browser => {
utils.clear(browser); // utils.clear(browser);
/* Side panel displays correct info */ // /* Side panel displays correct info */
utils.uploadFile(browser, "files/TowelDay.jpeg"); // utils.uploadFile(browser, "files/TowelDay.jpeg");
browser // browser
.waitForElementVisible("#input-text .cm-file-details") // .waitForElementVisible("#input-text .cm-file-details")
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown") // .waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
.waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail") // .waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail")
.waitForElementVisible("#input-text .cm-file-details .file-details-name") // .waitForElementVisible("#input-text .cm-file-details .file-details-name")
.waitForElementVisible("#input-text .cm-file-details .file-details-size") // .waitForElementVisible("#input-text .cm-file-details .file-details-size")
.waitForElementVisible("#input-text .cm-file-details .file-details-type") // .waitForElementVisible("#input-text .cm-file-details .file-details-type")
.waitForElementVisible("#input-text .cm-file-details .file-details-loaded"); // .waitForElementVisible("#input-text .cm-file-details .file-details-loaded");
/* Complex deep link populates the input correctly (encoding, eol, input) */ // /* Complex deep link populates the input correctly (encoding, eol, input) */
browser // browser
.urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=FF&oeol=PS") // .urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=FF&oeol=PS")
.waitForElementVisible("#rec-list li.operation"); // .waitForElementVisible("#rec-list li.operation");
browser.expect.element(`#input-text .cm-content`).to.have.property("textContent").match(/^.{65}$/); // browser.expect.element(`#input-text .cm-content`).to.have.property("textContent").match(/^.{65}$/);
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("66"); // browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("66");
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2"); // browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
browser.expect.element("#input-text .chr-enc-value").text.that.equals("KOI8-U Ukrainian Cyrillic"); // browser.expect.element("#input-text .chr-enc-value").text.that.equals("KOI8-U Ukrainian Cyrillic");
browser.expect.element("#output-text .chr-enc-value").text.that.equals("UTF-16BE"); // browser.expect.element("#output-text .chr-enc-value").text.that.equals("UTF-16BE");
browser.expect.element("#input-text .eol-value").text.that.equals("FF"); // browser.expect.element("#input-text .eol-value").text.that.equals("FF");
browser.expect.element("#output-text .eol-value").text.that.equals("PS"); // browser.expect.element("#output-text .eol-value").text.that.equals("PS");
utils.bake(browser); // utils.bake(browser);
browser.expect.element(`#output-text .cm-content`).to.have.property("textContent").match(/^.{44}$/); // browser.expect.element(`#output-text .cm-content`).to.have.property("textContent").match(/^.{44}$/);
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("44"); // browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("44");
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1"); // browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1");
}, // },
"Replace input with output": browser => { "Replace input with output": browser => {
/* Input is correctly populated */ /* Input is correctly populated */

View file

@ -64,9 +64,9 @@ module.exports = {
testOp(browser, ["From Hex", "Bzip2 Decompress"], "425a68393141592653597b0884b7000003038000008200ce00200021a647a4218013709517c5dc914e14241ec2212dc0", "test_output", [[], [true]]); testOp(browser, ["From Hex", "Bzip2 Decompress"], "425a68393141592653597b0884b7000003038000008200ce00200021a647a4218013709517c5dc914e14241ec2212dc0", "test_output", [[], [true]]);
// testOp(browser, "CBOR Decode", "test input", "test output"); // testOp(browser, "CBOR Decode", "test input", "test output");
// testOp(browser, "CBOR Encode", "test input", "test output"); // testOp(browser, "CBOR Encode", "test input", "test output");
testOp(browser, "CRC-16 Checksum", "test input", "77c7"); testOp(browser, "CRC Checksum", "test input", "77c7", ["CRC-16"]);
testOp(browser, "CRC-32 Checksum", "test input", "29822bc8"); testOp(browser, "CRC Checksum", "test input", "29822bc8", ["CRC-32"]);
testOp(browser, "CRC-8 Checksum", "test input", "9d"); testOp(browser, "CRC Checksum", "test input", "9d", ["CRC-8"]);
// testOp(browser, "CSS Beautify", "test input", "test_output"); // testOp(browser, "CSS Beautify", "test input", "test_output");
// testOp(browser, "CSS Minify", "test input", "test_output"); // testOp(browser, "CSS Minify", "test input", "test_output");
// testOp(browser, "CSS selector", "test input", "test_output"); // testOp(browser, "CSS selector", "test input", "test_output");
@ -236,7 +236,7 @@ module.exports = {
// testOp(browser, "OR", "test input", "test_output"); // testOp(browser, "OR", "test input", "test_output");
// testOp(browser, "Object Identifier to Hex", "test input", "test_output"); // testOp(browser, "Object Identifier to Hex", "test input", "test_output");
testOpHtml(browser, "Offset checker", "test input\n\nbest input", ".hl5", "est input"); testOpHtml(browser, "Offset checker", "test input\n\nbest input", ".hl5", "est input");
// testOp(browser, "Optical Character Recognition", "test input", "test_output"); testOpFile(browser, "Optical Character Recognition", "files/testocr.png", false, /This is a lot of 12 point text to test the/, [], 10000);
// testOp(browser, "PEM to Hex", "test input", "test_output"); // testOp(browser, "PEM to Hex", "test input", "test_output");
// testOp(browser, "PGP Decrypt", "test input", "test_output"); // testOp(browser, "PGP Decrypt", "test input", "test_output");
// testOp(browser, "PGP Decrypt and Verify", "test input", "test_output"); // testOp(browser, "PGP Decrypt and Verify", "test input", "test_output");
@ -408,7 +408,7 @@ module.exports = {
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops * @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
* @param {string} input - input text for test * @param {string} input - input text for test
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops * @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/ */
function bakeOp(browser, opName, input, args=[]) { function bakeOp(browser, opName, input, args=[]) {
browser.perform(function() { browser.perform(function() {
@ -425,8 +425,8 @@ function bakeOp(browser, opName, input, args=[]) {
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops * @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
* @param {string} input - input text * @param {string} input - input text
* @param {string} output - expected output * @param {string|RegExp} output - expected output
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops * @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/ */
function testOp(browser, opName, input, output, args=[]) { function testOp(browser, opName, input, output, args=[]) {
bakeOp(browser, opName, input, args); bakeOp(browser, opName, input, args);
@ -440,8 +440,8 @@ function testOp(browser, opName, input, output, args=[]) {
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops * @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
* @param {string} input - input text * @param {string} input - input text
* @param {string} cssSelector - CSS selector for HTML output * @param {string} cssSelector - CSS selector for HTML output
* @param {string} output - expected output * @param {string|RegExp} output - expected output
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops * @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/ */
function testOpHtml(browser, opName, input, cssSelector, output, args=[]) { function testOpHtml(browser, opName, input, cssSelector, output, args=[]) {
bakeOp(browser, opName, input, args); bakeOp(browser, opName, input, args);
@ -459,9 +459,9 @@ function testOpHtml(browser, opName, input, cssSelector, output, args=[]) {
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops * @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
* @param {string} filename - filename of image file from samples directory * @param {string} filename - filename of image file from samples directory
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops * @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
*/ */
function testOpImage(browser, opName, filename, args) { function testOpImage(browser, opName, filename, args=[]) {
browser.perform(function() { browser.perform(function() {
console.log(`Current test: ${opName}`); console.log(`Current test: ${opName}`);
}); });
@ -481,11 +481,12 @@ function testOpImage(browser, opName, filename, args) {
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops * @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
* @param {string} filename - filename of file from samples directory * @param {string} filename - filename of file from samples directory
* @param {string} cssSelector - CSS selector for HTML output * @param {string|boolean} cssSelector - CSS selector for HTML output or false for normal text output
* @param {string} output - expected output * @param {string|RegExp} output - expected output
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops * @param {Array<string>|Array<Array<string>>} [args=[]] - arguments, nested if multiple ops
* @param {number} [waitWindow=1000] - The number of milliseconds to wait for the output to be correct
*/ */
function testOpFile(browser, opName, filename, cssSelector, output, args) { function testOpFile(browser, opName, filename, cssSelector, output, args=[], waitWindow=1000) {
browser.perform(function() { browser.perform(function() {
console.log(`Current test: ${opName}`); console.log(`Current test: ${opName}`);
}); });
@ -494,9 +495,14 @@ function testOpFile(browser, opName, filename, cssSelector, output, args) {
browser.pause(100).waitForElementVisible("#stale-indicator", 5000); browser.pause(100).waitForElementVisible("#stale-indicator", 5000);
utils.bake(browser); utils.bake(browser);
if (typeof output === "string") { if (!cssSelector) {
// Text output
utils.expectOutput(browser, output, true, waitWindow);
} else if (typeof output === "string") {
// HTML output - string match
browser.expect.element("#output-html " + cssSelector).text.that.equals(output); browser.expect.element("#output-html " + cssSelector).text.that.equals(output);
} else if (output instanceof RegExp) { } else if (output instanceof RegExp) {
// HTML output - RegEx match
browser.expect.element("#output-html " + cssSelector).text.that.matches(output); browser.expect.element("#output-html " + cssSelector).text.that.matches(output);
} }
} }

View file

@ -180,15 +180,16 @@ function loadRecipe(browser, opName, input, args) {
* @param {Browser} browser - Nightwatch client * @param {Browser} browser - Nightwatch client
* @param {string|RegExp} expected - The expected output value * @param {string|RegExp} expected - The expected output value
* @param {boolean} [waitNotNull=false] - Wait for the output to not be empty before testing the value * @param {boolean} [waitNotNull=false] - Wait for the output to not be empty before testing the value
* @param {number} [waitWindow=1000] - The number of milliseconds to wait for the output to be correct
*/ */
function expectOutput(browser, expected, waitNotNull=false) { function expectOutput(browser, expected, waitNotNull=false, waitWindow=1000) {
if (waitNotNull && expected !== "") { if (waitNotNull && expected !== "") {
browser.waitUntil(async function() { browser.waitUntil(async function() {
const output = await this.execute(function() { const output = await this.execute(function() {
return window.app.manager.output.outputEditorView.state.doc.toString(); return window.app.manager.output.outputEditorView.state.doc.toString();
}); });
return output.length; return output.length;
}, 1000); }, waitWindow);
} }
browser.execute(expected => { browser.execute(expected => {

View file

@ -119,7 +119,7 @@ TestRegister.addApiTests([
assert.strictEqual(result[0].module, "Ciphers"); assert.strictEqual(result[0].module, "Ciphers");
assert.strictEqual(result[0].inputType, "string"); assert.strictEqual(result[0].inputType, "string");
assert.strictEqual(result[0].outputType, "string"); assert.strictEqual(result[0].outputType, "string");
assert.strictEqual(result[0].description, "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default."); assert.strictEqual(result[0].description, "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.");
assert.strictEqual(result[0].args.length, 5); assert.strictEqual(result[0].args.length, 5);
}), }),

View file

@ -305,16 +305,6 @@ Full hash: $2a$10$ODeP1.6fMsb.ENk2ngPUCO7qTGVPyHA9TqDVcyupyed8FjsiF65L6`;
assert.strictEqual(result.toString(), "2"); assert.strictEqual(result.toString(), "2");
}), }),
it("CRC16 Checksum", () => {
const result = chef.CRC16Checksum("Rain on Your Parade");
assert.strictEqual(result.toString(), "db1c");
}),
it("CRC32 Checksum", () => {
const result = chef.CRC32Checksum("Rain on Your Parade");
assert.strictEqual(result.toString(), "e902f76c");
}),
it("CSS Beautify", () => { it("CSS Beautify", () => {
const result = chef.CSSBeautify("header {color:black;padding:3rem;}"); const result = chef.CSSBeautify("header {color:black;padding:3rem;}");
const expected = `header { const expected = `header {
@ -575,12 +565,11 @@ Top Drawer`, {
}), }),
it("Generate HOTP", () => { it("Generate HOTP", () => {
const result = chef.generateHOTP("Cut The Mustard", { const result = chef.generateHOTP("JBSWY3DPEHPK3PXP", {
name: "colonel",
}); });
const expected = `URI: otpauth://hotp/colonel?secret=IN2XIICUNBSSATLVON2GC4TE const expected = `URI: otpauth://hotp/?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&counter=0
Password: 034148`; Password: 282760`;
assert.strictEqual(result.toString(), expected); assert.strictEqual(result.toString(), expected);
}), }),

View file

@ -20,6 +20,7 @@ import TestRegister from "../lib/TestRegister.mjs";
import "./tests/AESKeyWrap.mjs"; import "./tests/AESKeyWrap.mjs";
import "./tests/AvroToJSON.mjs"; import "./tests/AvroToJSON.mjs";
import "./tests/BaconCipher.mjs"; import "./tests/BaconCipher.mjs";
import "./tests/Base32.mjs";
import "./tests/Base45.mjs"; import "./tests/Base45.mjs";
import "./tests/Base58.mjs"; import "./tests/Base58.mjs";
import "./tests/Base62.mjs"; import "./tests/Base62.mjs";
@ -44,7 +45,6 @@ import "./tests/ChaCha.mjs";
import "./tests/ChangeIPFormat.mjs"; import "./tests/ChangeIPFormat.mjs";
import "./tests/CharEnc.mjs"; import "./tests/CharEnc.mjs";
import "./tests/Charts.mjs"; import "./tests/Charts.mjs";
import "./tests/Checksum.mjs";
import "./tests/Ciphers.mjs"; import "./tests/Ciphers.mjs";
import "./tests/CipherSaber2.mjs"; import "./tests/CipherSaber2.mjs";
import "./tests/CMAC.mjs"; import "./tests/CMAC.mjs";
@ -54,11 +54,14 @@ import "./tests/Comment.mjs";
import "./tests/Compress.mjs"; import "./tests/Compress.mjs";
import "./tests/ConditionalJump.mjs"; import "./tests/ConditionalJump.mjs";
import "./tests/ConvertCoordinateFormat.mjs"; import "./tests/ConvertCoordinateFormat.mjs";
import "./tests/ConvertLeetSpeak.mjs";
import "./tests/ConvertToNATOAlphabet.mjs"; import "./tests/ConvertToNATOAlphabet.mjs";
import "./tests/CRCChecksum.mjs";
import "./tests/Crypt.mjs"; import "./tests/Crypt.mjs";
import "./tests/CSV.mjs"; import "./tests/CSV.mjs";
import "./tests/DateTime.mjs"; import "./tests/DateTime.mjs";
import "./tests/DefangIP.mjs"; import "./tests/DefangIP.mjs";
import "./tests/DropNthBytes.mjs";
import "./tests/ECDSA.mjs"; import "./tests/ECDSA.mjs";
import "./tests/ELFInfo.mjs"; import "./tests/ELFInfo.mjs";
import "./tests/Enigma.mjs"; import "./tests/Enigma.mjs";
@ -102,6 +105,8 @@ import "./tests/LZNT1Decompress.mjs";
import "./tests/LZString.mjs"; import "./tests/LZString.mjs";
import "./tests/Magic.mjs"; import "./tests/Magic.mjs";
import "./tests/Media.mjs"; import "./tests/Media.mjs";
import "./tests/MIMEDecoding.mjs";
import "./tests/Modhex.mjs";
import "./tests/MorseCode.mjs"; import "./tests/MorseCode.mjs";
import "./tests/MS.mjs"; import "./tests/MS.mjs";
import "./tests/MultipleBombe.mjs"; import "./tests/MultipleBombe.mjs";
@ -115,11 +120,13 @@ import "./tests/ParseObjectIDTimestamp.mjs";
import "./tests/ParseQRCode.mjs"; import "./tests/ParseQRCode.mjs";
import "./tests/ParseSSHHostKey.mjs"; import "./tests/ParseSSHHostKey.mjs";
import "./tests/ParseTCP.mjs"; import "./tests/ParseTCP.mjs";
import "./tests/ParseTLSRecord.mjs";
import "./tests/ParseTLV.mjs"; import "./tests/ParseTLV.mjs";
import "./tests/ParseUDP.mjs"; import "./tests/ParseUDP.mjs";
import "./tests/PEMtoHex.mjs"; import "./tests/PEMtoHex.mjs";
import "./tests/PGP.mjs"; import "./tests/PGP.mjs";
import "./tests/PHP.mjs"; import "./tests/PHP.mjs";
import "./tests/PHPSerialize.mjs";
import "./tests/PowerSet.mjs"; import "./tests/PowerSet.mjs";
import "./tests/Protobuf.mjs"; import "./tests/Protobuf.mjs";
import "./tests/PubKeyFromCert.mjs"; import "./tests/PubKeyFromCert.mjs";
@ -139,18 +146,33 @@ import "./tests/SetIntersection.mjs";
import "./tests/SetUnion.mjs"; import "./tests/SetUnion.mjs";
import "./tests/Shuffle.mjs"; import "./tests/Shuffle.mjs";
import "./tests/SIGABA.mjs"; import "./tests/SIGABA.mjs";
import "./tests/SM2.mjs";
import "./tests/SM4.mjs"; import "./tests/SM4.mjs";
// import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet // import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet
import "./tests/StrUtils.mjs"; import "./tests/StrUtils.mjs";
import "./tests/StripIPv4Header.mjs";
import "./tests/StripTCPHeader.mjs";
import "./tests/StripUDPHeader.mjs";
import "./tests/Subsection.mjs"; import "./tests/Subsection.mjs";
import "./tests/SwapCase.mjs"; import "./tests/SwapCase.mjs";
import "./tests/SymmetricDifference.mjs"; import "./tests/SymmetricDifference.mjs";
import "./tests/TakeNthBytes.mjs";
import "./tests/TextEncodingBruteForce.mjs"; import "./tests/TextEncodingBruteForce.mjs";
import "./tests/ToFromInsensitiveRegex.mjs"; import "./tests/ToFromInsensitiveRegex.mjs";
import "./tests/TranslateDateTimeFormat.mjs"; import "./tests/TranslateDateTimeFormat.mjs";
import "./tests/Typex.mjs"; import "./tests/Typex.mjs";
import "./tests/UnescapeString.mjs"; import "./tests/UnescapeString.mjs";
import "./tests/Unicode.mjs"; import "./tests/Unicode.mjs";
import "./tests/RSA.mjs";
import "./tests/CBOREncode.mjs";
import "./tests/CBORDecode.mjs";
import "./tests/JA3Fingerprint.mjs";
import "./tests/JA3SFingerprint.mjs";
import "./tests/HASSH.mjs";
import "./tests/JSONtoYAML.mjs";
// Cannot test operations that use the File type yet
// import "./tests/SplitColourChannels.mjs";
import "./tests/YARA.mjs"; import "./tests/YARA.mjs";
import "./tests/ParseCSR.mjs"; import "./tests/ParseCSR.mjs";
import "./tests/XXTEA.mjs"; import "./tests/XXTEA.mjs";

View file

@ -0,0 +1,176 @@
/**
* Base32 Tests
*
* @author Peter C-S [petercs@purelymail.com]
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
import {ALPHABET_OPTIONS} from "../../../src/core/lib/Base32.mjs";
// Example Standard Base32 Tests
const STANDARD_INP = "HELLO BASE32";
const STANDARD_OUT = "JBCUYTCPEBBECU2FGMZA====";
// Example Hex Extended Base32 Tests
const EXTENDED_INP = "HELLO BASE32 EXTENDED";
const EXTENDED_OUT = "912KOJ2F41142KQ56CP20HAOAH2KSH258G======";
// All Bytes
const ALL_BYTES = [
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f",
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f",
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f",
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f",
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf",
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf",
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef",
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
].join("");
const ALL_BYTES_EXTENDED_OUT = "000G40O40K30E209185GO38E1S8124GJ2GAHC5OO34D1M70T3OFI08924CI2A9H750KIKAPC5KN2UC1H68PJ8D9M6SS3IEHR7GUJSFQ085146H258P3KGIAA9D64QJIFA18L4KQKALB5EM2PB9DLONAUBTG62OJ3CHIMCPR8D5L6MR3DDPNN0SBIEDQ7ATJNF1SNKURSFLV7V041GA1O91C6GU48J2KBHI6OT3SGI699754LIQBPH6CQJEE9R7KVK2GQ58T4KMJAFA59LALQPBDELUOB3CLJMIQRDDTON6TBNF5TNQVS1GE2OF2CBHM7P34SLIUCPN7CVK6HQB9T9LEMQVCDJMMRRJETTNV0S7HE7P75SRJUHQFATFMERRNFU3OV5SVKUNRFFU7PVBTVPVFUVS======";
const ALL_BYTES_STANDARD_OUT = "AAAQEAYEAUDAOCAJBIFQYDIOB4IBCEQTCQKRMFYYDENBWHA5DYPSAIJCEMSCKJRHFAUSUKZMFUXC6MBRGIZTINJWG44DSOR3HQ6T4P2AIFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLJNVYXK6L5QGCYTDMRSWMZ3INFVGW3DNNZXXA4LSON2HK5TXPB4XU634PV7H7AEBQKBYJBMGQ6EITCULRSGY5D4QSGJJHFEVS2LZRGM2TOOJ3HU7UCQ2FI5EUWTKPKFJVKV2ZLNOV6YLDMVTWS23NN5YXG5LXPF5X274BQOCYPCMLRWHZDE4VS6MZXHM7UGR2LJ5JVOW27MNTWW33TO55X7A4HROHZHF43T6R2PK5PWO33XP6DY7F47U6X3PP6HZ7L57Z7P674======";
TestRegister.addTests([
{
name: "To Base32 Standard: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "To Base32",
args: [ALPHABET_OPTIONS[0].value],
},
],
},
{
name: "To Base32 Hex Extended: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "To Base32",
args: [ALPHABET_OPTIONS[1].value],
},
],
},
{
name: "From Base32 Standard: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "From Base32",
args: [ALPHABET_OPTIONS[0].value, false],
},
],
},
{
name: "From Base32 Hex Extended: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "From Base32",
args: [ALPHABET_OPTIONS[1].value, false],
},
],
},
{
name: "To Base32 Standard: " + STANDARD_INP,
input: STANDARD_INP,
expectedOutput: STANDARD_OUT,
recipeConfig: [
{
op: "To Base32",
args: [ALPHABET_OPTIONS[0].value],
},
],
},
{
name: "To Base32 Hex Extended: " + EXTENDED_INP,
input: EXTENDED_INP,
expectedOutput: EXTENDED_OUT,
recipeConfig: [
{
op: "To Base32",
args: [ALPHABET_OPTIONS[1].value],
},
],
},
{
name: "From Base32 Standard: " + STANDARD_OUT,
input: STANDARD_OUT,
expectedOutput: STANDARD_INP,
recipeConfig: [
{
op: "From Base32",
args: [ALPHABET_OPTIONS[0].value, false],
},
],
},
{
name: "From Base32 Hex Extended: " + EXTENDED_OUT,
input: EXTENDED_OUT,
expectedOutput: EXTENDED_INP,
recipeConfig: [
{
op: "From Base32",
args: [ALPHABET_OPTIONS[1].value, false],
},
],
},
{
name: "To Base32 Hex Standard: All Bytes",
input: ALL_BYTES,
expectedOutput: ALL_BYTES_STANDARD_OUT,
recipeConfig: [
{
op: "To Base32",
args: [ALPHABET_OPTIONS[0].value],
},
],
},
{
name: "To Base32 Hex Extended: All Bytes",
input: ALL_BYTES,
expectedOutput: ALL_BYTES_EXTENDED_OUT,
recipeConfig: [
{
op: "To Base32",
args: [ALPHABET_OPTIONS[1].value],
},
],
},
{
name: "From Base32 Hex Standard: All Bytes",
input: ALL_BYTES_STANDARD_OUT,
expectedOutput: ALL_BYTES,
recipeConfig: [
{
op: "From Base32",
args: [ALPHABET_OPTIONS[0].value, false],
},
],
},
{
name: "From Base32 Hex Extended: All Bytes",
input: ALL_BYTES_EXTENDED_OUT,
expectedOutput: ALL_BYTES,
recipeConfig: [
{
op: "From Base32",
args: [ALPHABET_OPTIONS[1].value, false],
},
],
},
]);

File diff suppressed because it is too large Load diff

View file

@ -1,241 +0,0 @@
/**
* Checksum tests.
*
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
const BASIC_STRING = "The ships hung in the sky in much the same way that bricks don't.";
const UTF8_STR = "ნუ პანიკას";
const ALL_BYTES = [
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f",
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f",
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f",
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f",
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf",
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf",
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef",
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
].join("");
TestRegister.addTests([
{
name: "CRC-8: nothing",
input: "",
expectedOutput: "00",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8"]
}
]
},
{
name: "CRC-8: default check",
input: "123456789",
expectedOutput: "f4",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8"]
}
]
},
{
name: "CRC-8: CDMA2000",
input: "123456789",
expectedOutput: "da",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/CDMA2000"]
}
]
},
{
name: "CRC-8: DARC",
input: "123456789",
expectedOutput: "15",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/DARC"]
}
]
},
{
name: "CRC-8: DVB-S2",
input: "123456789",
expectedOutput: "bc",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/DVB-S2"]
}
]
},
{
name: "CRC-8: EBU",
input: "123456789",
expectedOutput: "97",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/EBU"]
}
]
},
{
name: "CRC-8: I-CODE",
input: "123456789",
expectedOutput: "7e",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/I-CODE"]
}
]
},
{
name: "CRC-8: ITU",
input: "123456789",
expectedOutput: "a1",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/ITU"]
}
]
},
{
name: "CRC-8: MAXIM",
input: "123456789",
expectedOutput: "a1",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/MAXIM"]
}
]
},
{
name: "CRC-8: ROHC",
input: "123456789",
expectedOutput: "d0",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/ROHC"]
}
]
},
{
name: "CRC-8: WCDMA",
input: "123456789",
expectedOutput: "25",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/WCDMA"]
}
]
},
{
name: "CRC-16: nothing",
input: "",
expectedOutput: "0000",
recipeConfig: [
{
"op": "CRC-16 Checksum",
"args": []
}
]
},
{
name: "CRC-16: basic string",
input: BASIC_STRING,
expectedOutput: "0c70",
recipeConfig: [
{
"op": "CRC-16 Checksum",
"args": []
}
]
},
{
name: "CRC-16: UTF-8",
input: UTF8_STR,
expectedOutput: "dcf6",
recipeConfig: [
{
"op": "CRC-16 Checksum",
"args": []
}
]
},
{
name: "CRC-16: all bytes",
input: ALL_BYTES,
expectedOutput: "bad3",
recipeConfig: [
{
"op": "CRC-16 Checksum",
"args": []
}
]
},
{
name: "CRC-32: nothing",
input: "",
expectedOutput: "00000000",
recipeConfig: [
{
"op": "CRC-32 Checksum",
"args": []
}
]
},
{
name: "CRC-32: basic string",
input: BASIC_STRING,
expectedOutput: "bf4b739c",
recipeConfig: [
{
"op": "CRC-32 Checksum",
"args": []
}
]
},
{
name: "CRC-32: UTF-8",
input: UTF8_STR,
expectedOutput: "87553290",
recipeConfig: [
{
"op": "CRC-32 Checksum",
"args": []
}
]
},
{
name: "CRC-32: all bytes",
input: ALL_BYTES,
expectedOutput: "29058c73",
recipeConfig: [
{
"op": "CRC-32 Checksum",
"args": []
}
]
}
]);

View file

@ -0,0 +1,55 @@
/**
* @author bartblaze []
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Convert to Leet Speak: basic text",
input: "leet",
expectedOutput: "l337",
recipeConfig: [
{
op: "Convert Leet Speak",
args: ["To Leet Speak"]
}
]
},
{
name: "Convert from Leet Speak: basic leet",
input: "l337",
expectedOutput: "leet",
recipeConfig: [
{
op: "Convert Leet Speak",
args: ["From Leet Speak"]
}
]
},
{
name: "Convert to Leet Speak: basic text, keep case",
input: "HELLO",
expectedOutput: "H3LL0",
recipeConfig: [
{
op: "Convert Leet Speak",
args: ["To Leet Speak"]
}
]
},
{
name: "Convert from Leet Speak: basic leet, keep case",
input: "H3LL0",
expectedOutput: "HeLLo",
recipeConfig: [
{
op: "Convert Leet Speak",
args: ["From Leet Speak"]
}
]
}
]);

View file

@ -580,8 +580,7 @@ Tag: a8f04c4d93bbef82bef61a103371aef9`,
input: "", input: "",
expectedOutput: `Invalid key length: 0 bytes expectedOutput: `Invalid key length: 0 bytes
DES uses a key length of 8 bytes (64 bits). DES uses a key length of 8 bytes (64 bits).`,
Triple DES uses a key length of 24 bytes (192 bits).`,
recipeConfig: [ recipeConfig: [
{ {
"op": "DES Encrypt", "op": "DES Encrypt",
@ -674,8 +673,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
input: "", input: "",
expectedOutput: `Invalid key length: 0 bytes expectedOutput: `Invalid key length: 0 bytes
Triple DES uses a key length of 24 bytes (192 bits). Triple DES uses a key length of 24 bytes (192 bits).`,
DES uses a key length of 8 bytes (64 bits).`,
recipeConfig: [ recipeConfig: [
{ {
"op": "Triple DES Encrypt", "op": "Triple DES Encrypt",
@ -1300,8 +1298,7 @@ The following algorithms will be used based on the size of the key:
input: "", input: "",
expectedOutput: `Invalid key length: 0 bytes expectedOutput: `Invalid key length: 0 bytes
DES uses a key length of 8 bytes (64 bits). DES uses a key length of 8 bytes (64 bits).`,
Triple DES uses a key length of 24 bytes (192 bits).`,
recipeConfig: [ recipeConfig: [
{ {
"op": "DES Decrypt", "op": "DES Decrypt",
@ -1394,8 +1391,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
input: "", input: "",
expectedOutput: `Invalid key length: 0 bytes expectedOutput: `Invalid key length: 0 bytes
Triple DES uses a key length of 24 bytes (192 bits). Triple DES uses a key length of 24 bytes (192 bits).`,
DES uses a key length of 8 bytes (64 bits).`,
recipeConfig: [ recipeConfig: [
{ {
"op": "Triple DES Decrypt", "op": "Triple DES Decrypt",
@ -1579,19 +1575,31 @@ DES uses a key length of 8 bytes (64 bits).`,
from Crypto.Cipher import Blowfish from Crypto.Cipher import Blowfish
import binascii import binascii
input_data = b"The quick brown fox jumps over the lazy dog." # Blowfish cipher parameters - key, mode, iv, segment_size, nonce
key = binascii.unhexlify("0011223344556677") key = binascii.unhexlify("0011223344556677")
iv = binascii.unhexlify("0000000000000000")
mode = Blowfish.MODE_CBC mode = Blowfish.MODE_CBC
kwargs = {}
iv = binascii.unhexlify("ffeeddccbbaa9988")
if mode in [Blowfish.MODE_CBC, Blowfish.MODE_CFB, Blowfish.MODE_OFB]:
kwargs = {"iv": iv}
if mode == Blowfish.MODE_CFB:
kwargs["segment_size"] = 64
if mode == Blowfish.MODE_CTR:
nonce = binascii.unhexlify("0000000000000000")
nonce = nonce[:7]
kwargs["nonce"] = nonce
cipher = Blowfish.new(key, mode, **kwargs)
# Input data and padding
input_data = b"The quick brown fox jumps over the lazy dog."
if mode == Blowfish.MODE_ECB or mode == Blowfish.MODE_CBC: if mode == Blowfish.MODE_ECB or mode == Blowfish.MODE_CBC:
padding_len = 8-(len(input_data) & 7) padding_len = 8-(len(input_data) & 7)
for i in range(padding_len): for i in range(padding_len):
input_data += bytes([padding_len]) input_data += bytes([padding_len])
cipher = Blowfish.new(key, mode) # set iv, nonce, segment_size etc. here # Encrypted text
cipher_text = cipher.encrypt(input_data) cipher_text = cipher.encrypt(input_data)
cipher_text = binascii.hexlify(cipher_text).decode("UTF-8") cipher_text = binascii.hexlify(cipher_text).decode("UTF-8")
print("Encrypted: {}".format(cipher_text)) print("Encrypted: {}".format(cipher_text))

View file

@ -0,0 +1,123 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
/**
* Drop nth bytes tests
*/
TestRegister.addTests([
{
name: "Drop nth bytes: Nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Drop nth bytes: Nothing (apply to each line)",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Drop nth bytes: Basic single line",
input: "0123456789",
expectedOutput: "1235679",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Drop nth bytes: Basic single line (apply to each line)",
input: "0123456789",
expectedOutput: "1235679",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Drop nth bytes: Complex single line",
input: "0123456789",
expectedOutput: "01234678",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Drop nth bytes: Complex single line (apply to each line)",
input: "0123456789",
expectedOutput: "01234678",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, true],
},
],
},
{
name: "Drop nth bytes: Basic multi line",
input: "01234\n56789",
expectedOutput: "123\n5689",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Drop nth bytes: Basic multi line (apply to each line)",
input: "01234\n56789",
expectedOutput: "123\n678",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Drop nth bytes: Complex multi line",
input: "01234\n56789",
expectedOutput: "012345679",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Drop nth bytes: Complex multi line (apply to each line)",
input: "012345\n6789ab",
expectedOutput: "01234\n6789a",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, true],
},
],
}
]);

View file

@ -0,0 +1,63 @@
/**
* IPv6Transition tests.
*
* @author jb30795
*
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "IPv6 Transition: IPv4 to IPv6",
input: "198.51.100.7",
expectedOutput: "6to4: 2002:c633:6407::/48\nIPv4 Mapped: ::ffff:c633:6407\nIPv4 Translated: ::ffff:0:c633:6407\nNat 64: 64:ff9b::c633:6407",
recipeConfig: [
{
op: "IPv6 Transition Addresses",
args: [true, false],
},
],
}, {
name: "IPv6 Transition: IPv4 /24 Range to IPv6",
input: "198.51.100.0/24",
expectedOutput: "6to4: 2002:c633:6400::/40\nIPv4 Mapped: ::ffff:c633:6400/120\nIPv4 Translated: ::ffff:0:c633:6400/120\nNat 64: 64:ff9b::c633:6400/120",
recipeConfig: [
{
op: "IPv6 Transition Addresses",
args: [false, false],
},
],
}, {
name: "IPv6 Transition: IPv4 to IPv6 Remove headers",
input: "198.51.100.7",
expectedOutput: "2002:c633:6407::/48\n::ffff:c633:6407\n::ffff:0:c633:6407\n64:ff9b::c633:6407",
recipeConfig: [
{
op: "IPv6 Transition Addresses",
args: [true, true],
},
],
}, {
name: "IPv6 Transition: IPv6 to IPv4",
input: "64:ff9b::c633:6407",
expectedOutput: "IPv4: 198.51.100.7",
recipeConfig: [
{
op: "IPv6 Transition Addresses",
args: [true, false],
},
],
}, {
name: "IPv6 Transition: MAC to EUI-64",
input: "a1:b2:c3:d4:e5:f6",
expectedOutput: "EUI-64 Interface ID: a3b2:c3ff:fed4:e5f6",
recipeConfig: [
{
op: "IPv6 Transition Addresses",
args: [true, false],
},
],
},
]);

View file

@ -0,0 +1,41 @@
/**
* YAML tests.
*
* @author ccarpo [ccarpo@gmx.net]
*
* @copyright Crown Copyright 2021
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
const EXAMPLE_YAML = `number: 3\nplain: string\nblock: |\n two\n lines`;
const EXAMPLE_JSON = `{ "number": 3, "plain": "string" }`;
TestRegister.addTests([
{
name: "YAML to JSON",
input: EXAMPLE_YAML,
expectedOutput: JSON.stringify({
"number": 3,
"plain": "string",
"block": "two\nlines\n"
}, null, 4),
recipeConfig: [
{
op: "YAML to JSON",
args: [],
}
],
},
{
name: "JSON to YAML",
input: EXAMPLE_JSON,
expectedOutput: `number: 3\nplain: string\n`,
recipeConfig: [
{
op: "JSON to YAML",
args: [],
}
],
},
]);

View file

@ -44,7 +44,18 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [hsKey, "HS256"], args: [hsKey, "HS256", "{}"],
}
],
},
{
name: "JWT Sign: HS256 with custom header",
input: inputObject,
expectedOutput: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImN1c3RvbS5rZXkifQ.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.kXln8btJburfRlND8IDZAQ8NZGFFZhvHyooHa6N9za8",
recipeConfig: [
{
op: "JWT Sign",
args: [hsKey, "HS256", `{"kid":"custom.key"}`],
} }
], ],
}, },
@ -55,7 +66,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [hsKey, "HS384"], args: [hsKey, "HS384", "{}"],
} }
], ],
}, },
@ -66,7 +77,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [hsKey, "HS512"], args: [hsKey, "HS512", "{}"],
} }
], ],
}, },
@ -77,7 +88,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [esKey, "ES256"], args: [esKey, "ES256", "{}"],
}, },
{ {
op: "JWT Decode", op: "JWT Decode",
@ -92,7 +103,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [esKey, "ES384"], args: [esKey, "ES384", "{}"],
}, },
{ {
op: "JWT Decode", op: "JWT Decode",
@ -107,7 +118,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [esKey, "ES512"], args: [esKey, "ES512", "{}"],
}, },
{ {
op: "JWT Decode", op: "JWT Decode",
@ -122,7 +133,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [rsKey, "RS256"], args: [rsKey, "RS256", "{}"],
}, },
{ {
op: "JWT Decode", op: "JWT Decode",
@ -137,7 +148,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [rsKey, "RS384"], args: [rsKey, "RS384", "{}"],
}, },
{ {
op: "JWT Decode", op: "JWT Decode",
@ -152,7 +163,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "JWT Sign", op: "JWT Sign",
args: [esKey, "RS512"], args: [esKey, "RS512", "{}"],
}, },
{ {
op: "JWT Decode", op: "JWT Decode",

View file

@ -2,11 +2,392 @@
* From Decimal tests * From Decimal tests
* *
* @author n1073645 [n1073645@gmail.com] * @author n1073645 [n1073645@gmail.com]
* @author k3ach [k3ach@proton.me]
* @copyright Crown Copyright 2020 * @copyright Crown Copyright 2020
* @licence Apache-2.0 * @licence Apache-2.0
*/ */
import TestRegister from "../../lib/TestRegister.mjs"; import TestRegister from "../../lib/TestRegister.mjs";
const testCases = [
{
radix: 2,
input: "01",
checksum: "1",
checkdigit: "1",
}, {
radix: 2,
input: "001111",
checksum: "0",
checkdigit: "0",
}, {
radix: 2,
input: "00011101",
checksum: "0",
checkdigit: "0",
}, {
radix: 2,
input: "0100101101",
checksum: "1",
checkdigit: "1",
}, {
radix: 4,
input: "0123",
checksum: "1",
checkdigit: "1",
}, {
radix: 4,
input: "130100",
checksum: "2",
checkdigit: "2",
}, {
radix: 4,
input: "32020313",
checksum: "3",
checkdigit: "0",
}, {
radix: 4,
input: "302233210112",
checksum: "3",
checkdigit: "0",
}, {
radix: 6,
input: "012345",
checksum: "4",
checkdigit: "4",
}, {
radix: 6,
input: "134255",
checksum: "2",
checkdigit: "4",
}, {
radix: 6,
input: "15021453",
checksum: "5",
checkdigit: "4",
}, {
radix: 6,
input: "211450230513",
checksum: "3",
checkdigit: "1",
}, {
radix: 8,
input: "01234567",
checksum: "2",
checkdigit: "2",
}, {
radix: 8,
input: "340624",
checksum: "0",
checkdigit: "4",
}, {
radix: 8,
input: "07260247",
checksum: "3",
checkdigit: "3",
}, {
radix: 8,
input: "026742114675",
checksum: "7",
checkdigit: "1",
}, {
radix: 10,
input: "0123456789",
checksum: "7",
checkdigit: "7",
}, {
radix: 10,
input: "468543",
checksum: "7",
checkdigit: "4",
}, {
radix: 10,
input: "59377601",
checksum: "5",
checkdigit: "6",
}, {
radix: 10,
input: "013909981254",
checksum: "1",
checkdigit: "3",
}, {
radix: 12,
input: "0123456789ab",
checksum: "3",
checkdigit: "3",
}, {
radix: 12,
input: "284685",
checksum: "0",
checkdigit: "6",
}, {
radix: 12,
input: "951a2661",
checksum: "0",
checkdigit: "8",
}, {
radix: 12,
input: "898202676387",
checksum: "b",
checkdigit: "9",
}, {
radix: 14,
input: "0123456789abcd",
checksum: "a",
checkdigit: "a",
}, {
radix: 14,
input: "33db25",
checksum: "0",
checkdigit: "d",
}, {
radix: 14,
input: "0b4ac128",
checksum: "b",
checkdigit: "3",
}, {
radix: 14,
input: "3d1c6d16160d",
checksum: "3",
checkdigit: "c",
}, {
radix: 16,
input: "0123456789abcdef",
checksum: "4",
checkdigit: "4",
}, {
radix: 16,
input: "e1fe64",
checksum: "b",
checkdigit: "6",
}, {
radix: 16,
input: "241a5dcd",
checksum: "1",
checkdigit: "9",
}, {
radix: 16,
input: "1fea740e0e1f",
checksum: "7",
checkdigit: "4",
}, {
radix: 18,
input: "0123456789abcdefgh",
checksum: "d",
checkdigit: "d",
}, {
radix: 18,
input: "995dgf",
checksum: "9",
checkdigit: "1",
}, {
radix: 18,
input: "9f80h32h",
checksum: "1",
checkdigit: "0",
}, {
radix: 18,
input: "5f9428e493g4",
checksum: "8",
checkdigit: "c",
}, {
radix: 20,
input: "0123456789abcdefghij",
checksum: "5",
checkdigit: "5",
}, {
radix: 20,
input: "918jci",
checksum: "h",
checkdigit: "d",
}, {
radix: 20,
input: "jab7j50d",
checksum: "g",
checkdigit: "j",
}, {
radix: 20,
input: "c56fe85eb6gg",
checksum: "g",
checkdigit: "5",
}, {
radix: 22,
input: "0123456789abcdefghijkl",
checksum: "g",
checkdigit: "g",
}, {
radix: 22,
input: "de57le",
checksum: "5",
checkdigit: "l",
}, {
radix: 22,
input: "e3fg6dfc",
checksum: "f",
checkdigit: "d",
}, {
radix: 22,
input: "1f8l80ai4kbg",
checksum: "l",
checkdigit: "f",
}, {
radix: 24,
input: "0123456789abcdefghijklmn",
checksum: "6",
checkdigit: "6",
}, {
radix: 24,
input: "agne7d",
checksum: "4",
checkdigit: "f",
}, {
radix: 24,
input: "1l4d9cf4",
checksum: "d",
checkdigit: "c",
}, {
radix: 24,
input: "blc1j09i3296",
checksum: "8",
checkdigit: "7",
}, {
radix: 26,
input: "0123456789abcdefghijklmnop",
checksum: "j",
checkdigit: "j",
}, {
radix: 26,
input: "82n9op",
checksum: "i",
checkdigit: "2",
}, {
radix: 26,
input: "e9cddn70",
checksum: "9",
checkdigit: "i",
}, {
radix: 26,
input: "ck0ep419knom",
checksum: "p",
checkdigit: "g",
}, {
radix: 28,
input: "0123456789abcdefghijklmnopqr",
checksum: "7",
checkdigit: "7",
}, {
radix: 28,
input: "a6hnoo",
checksum: "h",
checkdigit: "9",
}, {
radix: 28,
input: "lblc7kh0",
checksum: "a",
checkdigit: "f",
}, {
radix: 28,
input: "64k5piod3lmf",
checksum: "0",
checkdigit: "p",
}, {
radix: 30,
input: "0123456789abcdefghijklmnopqrst",
checksum: "m",
checkdigit: "m",
}, {
radix: 30,
input: "t69j7d",
checksum: "9",
checkdigit: "s",
}, {
radix: 30,
input: "p54o9ig3",
checksum: "a",
checkdigit: "o",
}, {
radix: 30,
input: "gc1njrt55030",
checksum: "6",
checkdigit: "1",
}, {
radix: 32,
input: "0123456789abcdefghijklmnopqrstuv",
checksum: "8",
checkdigit: "8",
}, {
radix: 32,
input: "rdou19",
checksum: "u",
checkdigit: "3",
}, {
radix: 32,
input: "ighj0pc7",
checksum: "3",
checkdigit: "8",
}, {
radix: 32,
input: "op4nn5fvjsrs",
checksum: "g",
checkdigit: "j",
}, {
radix: 34,
input: "0123456789abcdefghijklmnopqrstuvwx",
checksum: "p",
checkdigit: "p",
}, {
radix: 34,
input: "nvftj5",
checksum: "b",
checkdigit: "f",
}, {
radix: 34,
input: "u9v9g162",
checksum: "j",
checkdigit: "b",
}, {
radix: 34,
input: "o5gqg5d7gjh9",
checksum: "5",
checkdigit: "q",
}, {
radix: 36,
input: "0123456789abcdefghijklmnopqrstuvwxyz",
checksum: "9",
checkdigit: "9",
}, {
radix: 36,
input: "29zehu",
checksum: "i",
checkdigit: "j",
}, {
radix: 36,
input: "1snmikbu",
checksum: "s",
checkdigit: "v",
}, {
radix: 36,
input: "jpkar545q7gb",
checksum: "3",
checkdigit: "d",
},
];
testCases.forEach(element => {
TestRegister.addTests([
{
name: "Luhn Checksum Mod " + element.radix + " on " + element.input,
input: element.input,
expectedOutput: "Checksum: " + element.checksum + "\nCheckdigit: " + element.checkdigit + "\nLuhn Validated String: " + element.input + element.checkdigit,
recipeConfig: [
{
op: "Luhn Checksum",
args: [element.radix]
},
],
},
]);
});
TestRegister.addTests([ TestRegister.addTests([
{ {
name: "Luhn Checksum on standard data", name: "Luhn Checksum on standard data",
@ -15,7 +396,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "Luhn Checksum", op: "Luhn Checksum",
args: [] args: [10]
}, },
], ],
}, },
@ -26,7 +407,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "Luhn Checksum", op: "Luhn Checksum",
args: [] args: [10]
}, },
], ],
}, },
@ -37,18 +418,7 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "Luhn Checksum", op: "Luhn Checksum",
args: [] args: [10]
},
],
},
{
name: "Luhn Checksum on invalid data",
input: "35641709b012469",
expectedOutput: "Character: b is not a digit.",
recipeConfig: [
{
op: "Luhn Checksum",
args: []
}, },
], ],
}, },
@ -59,8 +429,8 @@ TestRegister.addTests([
recipeConfig: [ recipeConfig: [
{ {
op: "Luhn Checksum", op: "Luhn Checksum",
args: [] args: [10]
}, },
], ],
} },
]); ]);

View file

@ -0,0 +1,89 @@
/**
* MIME Header Decoding tests
*
* @author mshwed [m@ttshwed.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Encoded comments",
input: "(=?ISO-8859-1?Q?a?=)",
expectedOutput: "(a)",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "Encoded adjacent comments whitespace",
input: "(=?ISO-8859-1?Q?a?= b)",
expectedOutput: "(a b)",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "Encoded adjacent single whitespace ignored",
input: "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)",
expectedOutput: "(ab)",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "Encoded adjacent double whitespace ignored",
input: "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)",
expectedOutput: "(ab)",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "Encoded adjacent CRLF whitespace ignored",
input: "(=?ISO-8859-1?Q?a?=\r\n =?ISO-8859-1?Q?b?=)",
expectedOutput: "(ab)",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "UTF-8 Encodings Multiple Headers",
input: "=?utf-8?q?=C3=89ric?= <eric@example.org>, =?utf-8?q?Ana=C3=AFs?= <anais@example.org>",
expectedOutput: "Éric <eric@example.org>, Anaïs <anais@example.org>",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "ISO Decoding",
input: "From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>\nTo: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>\nCC: =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>\nSubject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\n=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=",
expectedOutput: "From: Keith Moore <moore@cs.utk.edu>\nTo: Keld Jørn Simonsen <keld@dkuug.dk>\nCC: André Pirard <PIRARD@vm1.ulg.ac.be>\nSubject: If you can read this you understand the example.",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
}
]);

View file

@ -0,0 +1,150 @@
/**
* Modhex operation tests.
* @author linuxgemini [ilteris@asenkron.com.tr]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "ASCII to Modhex stream",
input: "aberystwyth",
expectedOutput: "hbhdhgidikieifiiikifhj",
recipeConfig: [
{
"op": "To Modhex",
"args": [
"None",
0
]
},
]
},
{
name: "ASCII to Modhex with colon deliminator",
input: "aberystwyth",
expectedOutput: "hb:hd:hg:id:ik:ie:if:ii:ik:if:hj",
recipeConfig: [
{
"op": "To Modhex",
"args": [
"Colon",
0
]
}
]
},
{
name: "Modhex stream to UTF-8",
input: "uhkgkbuhkgkbugltlkugltkc",
expectedOutput: "救救孩子",
recipeConfig: [
{
"op": "From Modhex",
"args": [
"Auto"
]
}
]
},
{
name: "Mixed case Modhex stream to UTF-8",
input: "uhKGkbUHkgkBUGltlkugltkc",
expectedOutput: "救救孩子",
recipeConfig: [
{
"op": "From Modhex",
"args": [
"Auto"
]
}
]
},
{
name: "Mutiline Modhex with comma to ASCII (Auto Mode)",
input: "fk,dc,ie,hb,ii,dc,ht,ik,ie,hg,hr,hh,dc,ie,hk,\n\
if,if,hk,hu,hi,dc,hk,hu,dc,if,hj,hg,dc,he,id,\n\
hv,if,he,hj,dc,hv,hh,dc,if,hj,hg,dc,if,hj,hk,\n\
ie,dc,hh,hk,hi,dc,if,id,hg,hg,dr,dc,ie,if,hb,\n\
id,ih,hk,hu,hi,dc,if,hv,dc,hf,hg,hb,if,hj,dr,\n\
dc,hl,ig,ie,if,dc,hd,hg,he,hb,ig,ie,hg,dc,fk,\n\
dc,he,hv,ig,hr,hf,hu,di,if,dc,ht,hb,hn,hg,dc,\n\
ig,ic,dc,ht,ik,dc,ht,hk,hu,hf,dc,ii,hj,hk,he,\n\
hj,dc,hv,hh,dc,if,hj,hg,dc,hh,hk,hi,ie,dc,fk,\n\
dc,ii,hv,ig,hr,hf,dc,he,hj,hv,hv,ie,hg,du",
expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.",
recipeConfig: [
{
"op": "From Modhex",
"args": [
"Auto"
]
}
]
},
{
name: "Mutiline Modhex with percent to ASCII (Percent Mode)",
input: "fk%dc%ie%hb%ii%dc%ht%ik%ie%hg%hr%hh%dc%ie%hk%\n\
if%if%hk%hu%hi%dc%hk%hu%dc%if%hj%hg%dc%he%id%\n\
hv%if%he%hj%dc%hv%hh%dc%if%hj%hg%dc%if%hj%hk%\n\
ie%dc%hh%hk%hi%dc%if%id%hg%hg%dr%dc%ie%if%hb%\n\
id%ih%hk%hu%hi%dc%if%hv%dc%hf%hg%hb%if%hj%dr%\n\
dc%hl%ig%ie%if%dc%hd%hg%he%hb%ig%ie%hg%dc%fk%\n\
dc%he%hv%ig%hr%hf%hu%di%if%dc%ht%hb%hn%hg%dc%\n\
ig%ic%dc%ht%ik%dc%ht%hk%hu%hf%dc%ii%hj%hk%he%\n\
hj%dc%hv%hh%dc%if%hj%hg%dc%hh%hk%hi%ie%dc%fk%\n\
dc%ii%hv%ig%hr%hf%dc%he%hj%hv%hv%ie%hg%du",
expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.",
recipeConfig: [
{
"op": "From Modhex",
"args": [
"Percent"
]
}
]
},
{
name: "Mutiline Modhex with semicolon to ASCII (Semi-colon Mode)",
input: "fk;dc;ie;hb;ii;dc;ht;ik;ie;hg;hr;hh;dc;ie;hk;\n\
if;if;hk;hu;hi;dc;hk;hu;dc;if;hj;hg;dc;he;id;\n\
hv;if;he;hj;dc;hv;hh;dc;if;hj;hg;dc;if;hj;hk;\n\
ie;dc;hh;hk;hi;dc;if;id;hg;hg;dr;dc;ie;if;hb;\n\
id;ih;hk;hu;hi;dc;if;hv;dc;hf;hg;hb;if;hj;dr;\n\
dc;hl;ig;ie;if;dc;hd;hg;he;hb;ig;ie;hg;dc;fk;\n\
dc;he;hv;ig;hr;hf;hu;di;if;dc;ht;hb;hn;hg;dc;\n\
ig;ic;dc;ht;ik;dc;ht;hk;hu;hf;dc;ii;hj;hk;he;\n\
hj;dc;hv;hh;dc;if;hj;hg;dc;hh;hk;hi;ie;dc;fk;\n\
dc;ii;hv;ig;hr;hf;dc;he;hj;hv;hv;ie;hg;du",
expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.",
recipeConfig: [
{
"op": "From Modhex",
"args": [
"Semi-colon"
]
}
]
},
{
name: "ASCII to Modhex with comma and line breaks",
input: "aberystwyth",
expectedOutput: "hb,hd,hg,id,\nik,ie,if,ii,\nik,if,hj",
recipeConfig: [
{
"op": "To Modhex",
"args": [
"Comma",
4
]
}
]
},
]);

View file

@ -11,12 +11,12 @@ import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([ TestRegister.addTests([
{ {
name: "Generate HOTP", name: "Generate HOTP",
input: "12345678901234567890", input: "JBSWY3DPEHPK3PXP",
expectedOutput: "URI: otpauth://hotp/OTPAuthentication?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ\n\nPassword: 755224", expectedOutput: `URI: otpauth://hotp/?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&counter=0\n\nPassword: 282760`,
recipeConfig: [ recipeConfig: [
{ {
op: "Generate HOTP", op: "Generate HOTP",
args: ["", 32, 6, 0], args: ["", 6, 0], // [Name, Code length, Counter]
}, },
], ],
}, },

View file

@ -0,0 +1,112 @@
/**
* PHP Serialization tests.
*
* @author brun0ne [brunonblok@gmail.com]
*
* @copyright Crown Copyright 2023
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "PHP Serialize empty array",
input: "[]",
expectedOutput: "a:0:{}",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize empty object",
input: "{}",
expectedOutput: "a:0:{}",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize null",
input: "null",
expectedOutput: "N;",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize integer",
input: "10",
expectedOutput: "i:10;",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize float",
input: "14.523",
expectedOutput: "d:14.523;",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize boolean",
input: "[true, false]",
expectedOutput: "a:2:{i:0;b:1;i:1;b:0;}",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize string",
input: "\"Test string to serialize\"",
expectedOutput: "s:24:\"Test string to serialize\";",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize object",
input: "{\"a\": 10,\"0\": {\"ab\": true}}",
expectedOutput: "a:2:{s:1:\"0\";a:1:{s:2:\"ab\";b:1;}s:1:\"a\";i:10;}",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
},
{
name: "PHP Serialize array",
input: "[1,\"abc\",true,{\"x\":1,\"y\":2}]",
expectedOutput: "a:4:{i:0;i:1;i:1;s:3:\"abc\";i:2;b:1;i:3;a:2:{s:1:\"x\";i:1;s:1:\"y\";i:2;}}",
recipeConfig: [
{
op: "PHP Serialize",
args: []
}
]
}
]);

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,331 @@
/**
* Parse X.509 CRL tests.
*
* @author robinsandhu
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
const IN_CRL_PEM_RSA = `-----BEGIN X509 CRL-----
MIID7jCCAdYCAQEwDQYJKoZIhvcNAQELBQAwQjELMAkGA1UEBhMCVUsxDzANBgNV
BAgMBkxvbmRvbjELMAkGA1UECgwCQkIxFTATBgNVBAMMDFRlc3QgUm9vdCBDQRcN
MjQwODI1MTE0OTEwWhcNMjQwOTI0MTE0OTEwWjA1MDMCAhAAFw0yNDA4MjUwMzIz
MDhaMB4wCgYDVR0VBAMKAQYwEAYDVR0XBAkGByqGSM44AgOgggEnMIIBIzAJBgNV
HRIEAjAAMH0GA1UdIwR2MHSAFLjJrf2oUFTVhW40i0xgL7BJtodGoUakRDBCMQsw
CQYDVQQGEwJVSzEPMA0GA1UECAwGTG9uZG9uMQswCQYDVQQKDAJCQjEVMBMGA1UE
AwwMVGVzdCBSb290IENBghQ3XUv2vXwRfMxGGv/XLywm+B5LPTAtBgNVHS4EJjAk
MCKgIKAehhxodHRwOi8vZXhhbXBsZS5jb20vZGVsdGEtY3JsMFsGA1UdHwRUMFIw
IaAfoB2GG2h0dHA6Ly9leGFtcGxlLmNvbS9mdWxsLWNybDAhoB+gHYYbbGRhcDov
L2V4YW1wbGUuY29tL2Z1bGwtY3JsMAqgCKAGhwR/AAABMAsGA1UdFAQEAgIePDAN
BgkqhkiG9w0BAQsFAAOCAgEAAxsr+9nELUVWhFekwy6GsqH8xOf6EqGjRaEdX49W
mB40m2VajOkK8UHGoVyZzoDI2r/c8OPXUtbpK0fpvEl3SZU5j/C8JbZaZFFrEGeH
fSEqdVHFjohpawNcG41Qs+YT21TBqH1hD5yVI7gjVvfKICRfxDpl5oGClxBCVOSV
gVtLbe9q44uCBJ1kUkoc9Vz47Hv7JyckgqVXkORWHt2SFNALxlMEzOEQTpuC5Kcb
4i7hTCUF+kpkIvr02LJImq0Aaqzs6cC/DcdJiRPPyfaN8fQryFv76gg9i8zZcb6c
W42rvumiyw+7nnZfmq53webr5fCHaXhZk47ASOJD6GC5cX9rje1qGRgULXRhqcvK
n319s2iXj3FStDDorKGgsCV2zYmotX17ExB98CcCgBE52zMtRZilwhOGeh8mx3qT
l0W2B8uKKAq5BMmiziSBzQt700JPiruURZXbQ1fH1n7pKP6wGEh2e9TfQMlN20hE
I+CMt+1bG0Bpt5AfiwE8UykQ/WvpVxdJrgj0JM0yA37KfC8XD+cmavJ5/grorbj3
t0zBdK7bl+Y45VU/5/mX5ZR3O3ea1RclPM3hKMREfPneOlpan6r3dVwFqEN/TeTu
46vuDeKaEr3yJkOFfy0lSYPhPhzhU5vDR5ibxqvwxZNznI2AdTnZLEf8LRqnTVo1
qx0=
-----END X509 CRL-----`;
const OUT_CRL_PEM_RSA = `Certificate Revocation List (CRL):
Version: 2 (0x1)
Signature Algorithm: SHA256withRSA
Issuer:
C = UK
ST = London
O = BB
CN = Test Root CA
Last Update: Sun, 25 Aug 2024 11:49:10 GMT
Next Update: Tue, 24 Sep 2024 11:49:10 GMT
CRL extensions:
2.5.29.46:
Unsupported CRL extension. Try openssl CLI.
X509v3 Authority Key Identifier:
keyid:B8:C9:AD:FD:A8:50:54:D5:85:6E:34:8B:4C:60:2F:B0:49:B6:87:46
DirName:/C=UK/ST=London/O=BB/CN=Test Root CA
serial:37:5D:4B:F6:BD:7C:11:7C:CC:46:1A:FF:D7:2F:2C:26:F8:1E:4B:3D
X509v3 CRL Distribution Points:
Full Name:
URI:http://example.com/full-crl
Full Name:
URI:ldap://example.com/full-crl
Full Name:
IP:127.0.0.1
X509v3 CRL Number:
1E3C
issuerAltName:
Unsupported CRL extension. Try openssl CLI.
Revoked Certificates:
Serial Number: 1000
Revocation Date: Sun, 25 Aug 2024 03:23:08 GMT
CRL entry extensions:
X509v3 CRL Reason Code:
Certificate Hold
Hold Instruction Code:
Hold Instruction Reject
Signature Value:
03:1b:2b:fb:d9:c4:2d:45:56:84:57:a4:c3:2e:86:b2:a1:fc:
c4:e7:fa:12:a1:a3:45:a1:1d:5f:8f:56:98:1e:34:9b:65:5a:
8c:e9:0a:f1:41:c6:a1:5c:99:ce:80:c8:da:bf:dc:f0:e3:d7:
52:d6:e9:2b:47:e9:bc:49:77:49:95:39:8f:f0:bc:25:b6:5a:
64:51:6b:10:67:87:7d:21:2a:75:51:c5:8e:88:69:6b:03:5c:
1b:8d:50:b3:e6:13:db:54:c1:a8:7d:61:0f:9c:95:23:b8:23:
56:f7:ca:20:24:5f:c4:3a:65:e6:81:82:97:10:42:54:e4:95:
81:5b:4b:6d:ef:6a:e3:8b:82:04:9d:64:52:4a:1c:f5:5c:f8:
ec:7b:fb:27:27:24:82:a5:57:90:e4:56:1e:dd:92:14:d0:0b:
c6:53:04:cc:e1:10:4e:9b:82:e4:a7:1b:e2:2e:e1:4c:25:05:
fa:4a:64:22:fa:f4:d8:b2:48:9a:ad:00:6a:ac:ec:e9:c0:bf:
0d:c7:49:89:13:cf:c9:f6:8d:f1:f4:2b:c8:5b:fb:ea:08:3d:
8b:cc:d9:71:be:9c:5b:8d:ab:be:e9:a2:cb:0f:bb:9e:76:5f:
9a:ae:77:c1:e6:eb:e5:f0:87:69:78:59:93:8e:c0:48:e2:43:
e8:60:b9:71:7f:6b:8d:ed:6a:19:18:14:2d:74:61:a9:cb:ca:
9f:7d:7d:b3:68:97:8f:71:52:b4:30:e8:ac:a1:a0:b0:25:76:
cd:89:a8:b5:7d:7b:13:10:7d:f0:27:02:80:11:39:db:33:2d:
45:98:a5:c2:13:86:7a:1f:26:c7:7a:93:97:45:b6:07:cb:8a:
28:0a:b9:04:c9:a2:ce:24:81:cd:0b:7b:d3:42:4f:8a:bb:94:
45:95:db:43:57:c7:d6:7e:e9:28:fe:b0:18:48:76:7b:d4:df:
40:c9:4d:db:48:44:23:e0:8c:b7:ed:5b:1b:40:69:b7:90:1f:
8b:01:3c:53:29:10:fd:6b:e9:57:17:49:ae:08:f4:24:cd:32:
03:7e:ca:7c:2f:17:0f:e7:26:6a:f2:79:fe:0a:e8:ad:b8:f7:
b7:4c:c1:74:ae:db:97:e6:38:e5:55:3f:e7:f9:97:e5:94:77:
3b:77:9a:d5:17:25:3c:cd:e1:28:c4:44:7c:f9:de:3a:5a:5a:
9f:aa:f7:75:5c:05:a8:43:7f:4d:e4:ee:e3:ab:ee:0d:e2:9a:
12:bd:f2:26:43:85:7f:2d:25:49:83:e1:3e:1c:e1:53:9b:c3:
47:98:9b:c6:ab:f0:c5:93:73:9c:8d:80:75:39:d9:2c:47:fc:
2d:1a:a7:4d:5a:35:ab:1d`;
const IN_CRL_PEM_RSA_CRL_REASON_AND_INVALIDITY_DATE = `-----BEGIN X509 CRL-----
MIID9jCCAd4CAQEwDQYJKoZIhvcNAQELBQAwQjELMAkGA1UEBhMCVUsxDzANBgNV
BAgMBkxvbmRvbjELMAkGA1UECgwCQkIxFTATBgNVBAMMDFRlc3QgUm9vdCBDQRcN
MjQwODI1MTIwODU2WhcNMjQwOTI0MTIwODU2WjA9MDsCAhAAFw0yNDA4MjUxMjA4
NDhaMCYwCgYDVR0VBAMKAQEwGAYDVR0YBBEYDzIwMjQwODI1MDAwMDAwWqCCAScw
ggEjMAkGA1UdEgQCMAAwfQYDVR0jBHYwdIAUuMmt/ahQVNWFbjSLTGAvsEm2h0ah
RqREMEIxCzAJBgNVBAYTAlVLMQ8wDQYDVQQIDAZMb25kb24xCzAJBgNVBAoMAkJC
MRUwEwYDVQQDDAxUZXN0IFJvb3QgQ0GCFDddS/a9fBF8zEYa/9cvLCb4Hks9MC0G
A1UdLgQmMCQwIqAgoB6GHGh0dHA6Ly9leGFtcGxlLmNvbS9kZWx0YS1jcmwwWwYD
VR0fBFQwUjAhoB+gHYYbaHR0cDovL2V4YW1wbGUuY29tL2Z1bGwtY3JsMCGgH6Ad
hhtsZGFwOi8vZXhhbXBsZS5jb20vZnVsbC1jcmwwCqAIoAaHBH8AAAEwCwYDVR0U
BAQCAh49MA0GCSqGSIb3DQEBCwUAA4ICAQByLp7JWQmB1NhlLACH6zFOe31yCTVy
xJQtgujtSri1LNu6IwzBGsKBQIl3ucwMxPvoZzlujNLmshUT3nSogV0/5n1q0Gyj
5Yiz2iw8mmKJLmGZ9Oz3QoGxgFww0/0x/VwRHuS2hw+A7JB8tO/2nW3oTclvS55l
R+VtkDjUN58+Yl2SQksvb3qD6bHHJTCaP7Dskls0fdBIoYIDvZejrTYSSzTX/Kw4
735P0GBMhj7zVF8azGz2PFpSISg4huJMyp7EDKZf2c2dnkuwmEUlPQEBLX25j/Il
81OxfVVFja+wUagaGtjEPGy5gsU8zFwkWhjaD5PGBbZvnT+EDsOtJPU7Ot/sBHfz
XqUtMrfmz/S/GsQ+QCpnBvarBy9QYuk9M0ePBGy33CUQpjPULxuJJVAHxNoetHCv
7udng2Pi4D8vDNfzbMwHt7HurMo0CsSju+cL4rnIfsz02RrD9WC84KxBLWkqC7Hi
IKGIpF740Yc4BliVE1HDaOKyI6FEft5asj3OgXwmBw7pVlxSNWACaA2vOFkdN/V5
XZZjVJdRJxkgEfCvsJVenFp8ND6gmJmWum7tqM5ytmiXjPtejsPpVq4IclG+Yhnr
tFQ9TDEuCrNsRIGGGDodyXq1+kGXY0w8RqGEb7J4Og/M6r4LMAKPkO7e0nEibTqX
d2igvR2e5p+yKw==
-----END X509 CRL-----`;
const OUT_CRL_PEM_RSA_CRL_REASON_AND_INVALIDITY_DATE = `Certificate Revocation List (CRL):
Version: 2 (0x1)
Signature Algorithm: SHA256withRSA
Issuer:
C = UK
ST = London
O = BB
CN = Test Root CA
Last Update: Sun, 25 Aug 2024 12:08:56 GMT
Next Update: Tue, 24 Sep 2024 12:08:56 GMT
CRL extensions:
2.5.29.46:
Unsupported CRL extension. Try openssl CLI.
X509v3 Authority Key Identifier:
keyid:B8:C9:AD:FD:A8:50:54:D5:85:6E:34:8B:4C:60:2F:B0:49:B6:87:46
DirName:/C=UK/ST=London/O=BB/CN=Test Root CA
serial:37:5D:4B:F6:BD:7C:11:7C:CC:46:1A:FF:D7:2F:2C:26:F8:1E:4B:3D
X509v3 CRL Distribution Points:
Full Name:
URI:http://example.com/full-crl
Full Name:
URI:ldap://example.com/full-crl
Full Name:
IP:127.0.0.1
X509v3 CRL Number:
1E3D
issuerAltName:
Unsupported CRL extension. Try openssl CLI.
Revoked Certificates:
Serial Number: 1000
Revocation Date: Sun, 25 Aug 2024 12:08:48 GMT
CRL entry extensions:
X509v3 CRL Reason Code:
Key Compromise
Invalidity Date:
Sun, 25 Aug 2024 00:00:00 GMT
Signature Value:
72:2e:9e:c9:59:09:81:d4:d8:65:2c:00:87:eb:31:4e:7b:7d:
72:09:35:72:c4:94:2d:82:e8:ed:4a:b8:b5:2c:db:ba:23:0c:
c1:1a:c2:81:40:89:77:b9:cc:0c:c4:fb:e8:67:39:6e:8c:d2:
e6:b2:15:13:de:74:a8:81:5d:3f:e6:7d:6a:d0:6c:a3:e5:88:
b3:da:2c:3c:9a:62:89:2e:61:99:f4:ec:f7:42:81:b1:80:5c:
30:d3:fd:31:fd:5c:11:1e:e4:b6:87:0f:80:ec:90:7c:b4:ef:
f6:9d:6d:e8:4d:c9:6f:4b:9e:65:47:e5:6d:90:38:d4:37:9f:
3e:62:5d:92:42:4b:2f:6f:7a:83:e9:b1:c7:25:30:9a:3f:b0:
ec:92:5b:34:7d:d0:48:a1:82:03:bd:97:a3:ad:36:12:4b:34:
d7:fc:ac:38:ef:7e:4f:d0:60:4c:86:3e:f3:54:5f:1a:cc:6c:
f6:3c:5a:52:21:28:38:86:e2:4c:ca:9e:c4:0c:a6:5f:d9:cd:
9d:9e:4b:b0:98:45:25:3d:01:01:2d:7d:b9:8f:f2:25:f3:53:
b1:7d:55:45:8d:af:b0:51:a8:1a:1a:d8:c4:3c:6c:b9:82:c5:
3c:cc:5c:24:5a:18:da:0f:93:c6:05:b6:6f:9d:3f:84:0e:c3:
ad:24:f5:3b:3a:df:ec:04:77:f3:5e:a5:2d:32:b7:e6:cf:f4:
bf:1a:c4:3e:40:2a:67:06:f6:ab:07:2f:50:62:e9:3d:33:47:
8f:04:6c:b7:dc:25:10:a6:33:d4:2f:1b:89:25:50:07:c4:da:
1e:b4:70:af:ee:e7:67:83:63:e2:e0:3f:2f:0c:d7:f3:6c:cc:
07:b7:b1:ee:ac:ca:34:0a:c4:a3:bb:e7:0b:e2:b9:c8:7e:cc:
f4:d9:1a:c3:f5:60:bc:e0:ac:41:2d:69:2a:0b:b1:e2:20:a1:
88:a4:5e:f8:d1:87:38:06:58:95:13:51:c3:68:e2:b2:23:a1:
44:7e:de:5a:b2:3d:ce:81:7c:26:07:0e:e9:56:5c:52:35:60:
02:68:0d:af:38:59:1d:37:f5:79:5d:96:63:54:97:51:27:19:
20:11:f0:af:b0:95:5e:9c:5a:7c:34:3e:a0:98:99:96:ba:6e:
ed:a8:ce:72:b6:68:97:8c:fb:5e:8e:c3:e9:56:ae:08:72:51:
be:62:19:eb:b4:54:3d:4c:31:2e:0a:b3:6c:44:81:86:18:3a:
1d:c9:7a:b5:fa:41:97:63:4c:3c:46:a1:84:6f:b2:78:3a:0f:
cc:ea:be:0b:30:02:8f:90:ee:de:d2:71:22:6d:3a:97:77:68:
a0:bd:1d:9e:e6:9f:b2:2b`;
const IN_CRL_PEM_RSA_CRL_EXTENSIONS = `-----BEGIN X509 CRL-----
MIIE0DCCArgCAQEwDQYJKoZIhvcNAQELBQAwQjELMAkGA1UEBhMCVUsxDzANBgNV
BAgMBkxvbmRvbjELMAkGA1UECgwCQkIxFTATBgNVBAMMDFRlc3QgUm9vdCBDQRcN
MjQwODI1MTIzNzEwWhcNMjQwOTI0MTIzNzEwWjA9MDsCAhAAFw0yNDA4MjUxMjA4
NDhaMCYwCgYDVR0VBAMKAQEwGAYDVR0YBBEYDzIwMjQwODI1MDAwMDAwWqCCAgEw
ggH9MIHiBgNVHRIEgdowgdegFAYEKgMEBaAMFgpDdXN0b21OYW1lgQ5jYUBleGFt
cGxlLmNvbYYSaHR0cDovL2V4YW1wbGUuY29tgg5jYS5leGFtcGxlLmNvbYcEwKgB
AaSBhDCBgTELMAkGA1UEBhMCVVMxFTATBgNVBAgMDEV4YW1wbGVTdGF0ZTEUMBIG
A1UEBwwLRXhhbXBsZUNpdHkxEzARBgNVBAoMCkV4YW1wbGVPcmcxFDASBgNVBAsM
C0V4YW1wbGVVbml0MRowGAYDVQQDDBFFeGFtcGxlQ29tbW9uTmFtZTB9BgNVHSME
djB0gBS4ya39qFBU1YVuNItMYC+wSbaHRqFGpEQwQjELMAkGA1UEBhMCVUsxDzAN
BgNVBAgMBkxvbmRvbjELMAkGA1UECgwCQkIxFTATBgNVBAMMDFRlc3QgUm9vdCBD
QYIUN11L9r18EXzMRhr/1y8sJvgeSz0wLQYDVR0uBCYwJDAioCCgHoYcaHR0cDov
L2V4YW1wbGUuY29tL2RlbHRhLWNybDBbBgNVHR8EVDBSMCGgH6AdhhtodHRwOi8v
ZXhhbXBsZS5jb20vZnVsbC1jcmwwIaAfoB2GG2xkYXA6Ly9leGFtcGxlLmNvbS9m
dWxsLWNybDAKoAigBocEfwAAATALBgNVHRQEBAICHkIwDQYJKoZIhvcNAQELBQAD
ggIBAF/9L4aGmId2igw7+MfDxokevIJkJX/MkmHpXBl1b4hL85FGD7OPCmn47VzC
Wejlc/AQB7mWyUugvrVEq/FiCO8a8Fieyjw5uCYz0eiNnuvHVRGM2mOEkiA0I/rn
F5AFB1YfCFGXPyRkXNRbOBE91mhOzh1H9PX2qVnj5l3KsPE/7YuteacR0TkfkRJa
BXLic+5F/CCV/J/iYR7LncuLUlhBfsosG/ucHL70EytlfX6CBWY3kBbmj7nd497T
QG392+m9xp7MIsJAS+3qEzwJAfni6zUV0fWh/ucOl8BIjHEh97VqI3+8yzhdXfkF
2gkfpkqJQY0+5OO1VSRYTlQNld3QjN/VVJjatfHyaXfPCx4VEKW1kWYo+0zxO4SL
SB/+S/o99bCeNy1MXqEvy5HoDwFHePXGsAEPHWPdj7EWm7g9T/Fl1iSR6hpohvDD
K4LaGdVhzvCraLIh8H7XW3KztvZvDQejYQAgADW0UO0rFHJ1XXhKYSqXNGnfDt+3
cRpt2XxSxt5HJtHlatiI25PuBMNWV2Zod4RHB/8UEvs1KC7dcwkAiCEY+E3o/zkC
rdZ/8XtNf5a4WSN/D7pPsfsO6SE+7lxkJ+UQcZLXAz8b5ArPTlWt2HdJIBEVs25K
FAkizyldhnAcNHFk7XN94eTLNeD6hUbFL9pNHiSmKu5A9YW0
-----END X509 CRL-----`;
const OUT_CRL_PEM_RSA_CRL_EXTENSIONS = `Certificate Revocation List (CRL):
Version: 2 (0x1)
Signature Algorithm: SHA256withRSA
Issuer:
C = UK
ST = London
O = BB
CN = Test Root CA
Last Update: Sun, 25 Aug 2024 12:37:10 GMT
Next Update: Tue, 24 Sep 2024 12:37:10 GMT
CRL extensions:
2.5.29.46:
Unsupported CRL extension. Try openssl CLI.
X509v3 Authority Key Identifier:
keyid:B8:C9:AD:FD:A8:50:54:D5:85:6E:34:8B:4C:60:2F:B0:49:B6:87:46
DirName:/C=UK/ST=London/O=BB/CN=Test Root CA
serial:37:5D:4B:F6:BD:7C:11:7C:CC:46:1A:FF:D7:2F:2C:26:F8:1E:4B:3D
X509v3 CRL Distribution Points:
Full Name:
URI:http://example.com/full-crl
Full Name:
URI:ldap://example.com/full-crl
Full Name:
IP:127.0.0.1
X509v3 CRL Number:
1E42
X509v3 Issuer Alternative Name:
OtherName:1.2.3.4.5::CustomName
EMAIL:ca@example.com
URI:http://example.com
DNS:ca.example.com
IP:192.168.1.1
DIR:/C=US/ST=ExampleState/L=ExampleCity/O=ExampleOrg/OU=ExampleUnit/CN=ExampleCommonName
Revoked Certificates:
Serial Number: 1000
Revocation Date: Sun, 25 Aug 2024 12:08:48 GMT
CRL entry extensions:
X509v3 CRL Reason Code:
Key Compromise
Invalidity Date:
Sun, 25 Aug 2024 00:00:00 GMT
Signature Value:
5f:fd:2f:86:86:98:87:76:8a:0c:3b:f8:c7:c3:c6:89:1e:bc:
82:64:25:7f:cc:92:61:e9:5c:19:75:6f:88:4b:f3:91:46:0f:
b3:8f:0a:69:f8:ed:5c:c2:59:e8:e5:73:f0:10:07:b9:96:c9:
4b:a0:be:b5:44:ab:f1:62:08:ef:1a:f0:58:9e:ca:3c:39:b8:
26:33:d1:e8:8d:9e:eb:c7:55:11:8c:da:63:84:92:20:34:23:
fa:e7:17:90:05:07:56:1f:08:51:97:3f:24:64:5c:d4:5b:38:
11:3d:d6:68:4e:ce:1d:47:f4:f5:f6:a9:59:e3:e6:5d:ca:b0:
f1:3f:ed:8b:ad:79:a7:11:d1:39:1f:91:12:5a:05:72:e2:73:
ee:45:fc:20:95:fc:9f:e2:61:1e:cb:9d:cb:8b:52:58:41:7e:
ca:2c:1b:fb:9c:1c:be:f4:13:2b:65:7d:7e:82:05:66:37:90:
16:e6:8f:b9:dd:e3:de:d3:40:6d:fd:db:e9:bd:c6:9e:cc:22:
c2:40:4b:ed:ea:13:3c:09:01:f9:e2:eb:35:15:d1:f5:a1:fe:
e7:0e:97:c0:48:8c:71:21:f7:b5:6a:23:7f:bc:cb:38:5d:5d:
f9:05:da:09:1f:a6:4a:89:41:8d:3e:e4:e3:b5:55:24:58:4e:
54:0d:95:dd:d0:8c:df:d5:54:98:da:b5:f1:f2:69:77:cf:0b:
1e:15:10:a5:b5:91:66:28:fb:4c:f1:3b:84:8b:48:1f:fe:4b:
fa:3d:f5:b0:9e:37:2d:4c:5e:a1:2f:cb:91:e8:0f:01:47:78:
f5:c6:b0:01:0f:1d:63:dd:8f:b1:16:9b:b8:3d:4f:f1:65:d6:
24:91:ea:1a:68:86:f0:c3:2b:82:da:19:d5:61:ce:f0:ab:68:
b2:21:f0:7e:d7:5b:72:b3:b6:f6:6f:0d:07:a3:61:00:20:00:
35:b4:50:ed:2b:14:72:75:5d:78:4a:61:2a:97:34:69:df:0e:
df:b7:71:1a:6d:d9:7c:52:c6:de:47:26:d1:e5:6a:d8:88:db:
93:ee:04:c3:56:57:66:68:77:84:47:07:ff:14:12:fb:35:28:
2e:dd:73:09:00:88:21:18:f8:4d:e8:ff:39:02:ad:d6:7f:f1:
7b:4d:7f:96:b8:59:23:7f:0f:ba:4f:b1:fb:0e:e9:21:3e:ee:
5c:64:27:e5:10:71:92:d7:03:3f:1b:e4:0a:cf:4e:55:ad:d8:
77:49:20:11:15:b3:6e:4a:14:09:22:cf:29:5d:86:70:1c:34:
71:64:ed:73:7d:e1:e4:cb:35:e0:fa:85:46:c5:2f:da:4d:1e:
24:a6:2a:ee:40:f5:85:b4`;
TestRegister.addTests([
{
name: "Parse X.509 CRL: Example PEM encoded CRL with RSA signature",
input: IN_CRL_PEM_RSA,
expectedOutput: OUT_CRL_PEM_RSA,
recipeConfig: [
{
"op": "Parse X.509 CRL",
"args": ["PEM"]
}
]
},
{
name: "Parse X.509 CRL: Example PEM encoded CRL with RSA signature, CRL Reason and Invalidity Date",
input: IN_CRL_PEM_RSA_CRL_REASON_AND_INVALIDITY_DATE,
expectedOutput: OUT_CRL_PEM_RSA_CRL_REASON_AND_INVALIDITY_DATE,
recipeConfig: [
{
"op": "Parse X.509 CRL",
"args": ["PEM"]
}
]
},
{
name: "Parse X.509 CRL: Example PEM encoded CRL with RSA signature and CRL Extensions",
input: IN_CRL_PEM_RSA_CRL_EXTENSIONS,
expectedOutput: OUT_CRL_PEM_RSA_CRL_EXTENSIONS,
recipeConfig: [
{
"op": "Parse X.509 CRL",
"args": ["PEM"]
}
]
},
]);

View file

@ -135,10 +135,21 @@ TestRegister.addTests([
}, },
], ],
}, },
{
name: "ROT13: no shift amount",
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
recipeConfig: [
{
op: "ROT13",
args: [true, true, true, 0]
},
],
},
{ {
name: "ROT13: normal", name: "ROT13: normal",
input: "The Quick Brown Fox Jumped Over The Lazy Dog.", input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt.", expectedOutput: "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt. 3456789012",
recipeConfig: [ recipeConfig: [
{ {
op: "ROT13", op: "ROT13",
@ -146,10 +157,21 @@ TestRegister.addTests([
}, },
], ],
}, },
{
name: "ROT13: negative shift amount",
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt. 7890123456",
recipeConfig: [
{
op: "ROT13",
args: [true, true, true, -13]
},
],
},
{ {
name: "ROT13: full loop", name: "ROT13: full loop",
input: "The Quick Brown Fox Jumped Over The Lazy Dog.", input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog.", expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 6789012345",
recipeConfig: [ recipeConfig: [
{ {
op: "ROT13", op: "ROT13",
@ -157,10 +179,21 @@ TestRegister.addTests([
}, },
], ],
}, },
{
name: "ROT13: full loop (negative shift amount)",
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 4567890123",
recipeConfig: [
{
op: "ROT13",
args: [true, true, true, -26]
},
],
},
{ {
name: "ROT13: lowercase only", name: "ROT13: lowercase only",
input: "The Quick Brown Fox Jumped Over The Lazy Dog.", input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "Tur Qhvpx Bebja Fbk Jhzcrq Oire Tur Lnml Dbt.", expectedOutput: "Tur Qhvpx Bebja Fbk Jhzcrq Oire Tur Lnml Dbt. 0123456789",
recipeConfig: [ recipeConfig: [
{ {
op: "ROT13", op: "ROT13",
@ -170,8 +203,8 @@ TestRegister.addTests([
}, },
{ {
name: "ROT13: uppercase only", name: "ROT13: uppercase only",
input: "The Quick Brown Fox Jumped Over The Lazy Dog.", input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "Ghe Duick Orown Sox Wumped Bver Ghe Yazy Qog.", expectedOutput: "Ghe Duick Orown Sox Wumped Bver Ghe Yazy Qog. 0123456789",
recipeConfig: [ recipeConfig: [
{ {
op: "ROT13", op: "ROT13",
@ -179,6 +212,50 @@ TestRegister.addTests([
}, },
], ],
}, },
{
name: "ROT13: numbers only",
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 5678901234",
recipeConfig: [
{
op: "ROT13",
args: [false, false, true, 5]
},
],
},
{
name: "ROT13: numbers only (negative shift amount)",
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 5678901234",
recipeConfig: [
{
op: "ROT13",
args: [false, false, true, 5]
},
],
},
{
name: "ROT13: numbers only loop",
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
recipeConfig: [
{
op: "ROT13",
args: [false, false, true, 10]
},
],
},
{
name: "ROT13: numbers only loop (negative shift amount)",
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
recipeConfig: [
{
op: "ROT13",
args: [false, false, true, -10]
},
],
},
{ {
name: "ROT47: nothing", name: "ROT47: nothing",
input: "", input: "",

View file

@ -0,0 +1,135 @@
/**
* SM2 Tests
*
* @author flakjacket95 [dflack95@gmail.com]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
/* Plaintexts */
const SMALL_PLAIN = "I am a small plaintext";
const LARGE_PLAIN = "I am a larger plaintext, that will require the encryption KDF to generate a much larger key to properly encrypt me";
/* Test Key Parameters */
const PUBLIC_X = "f7d903cab7925066c31150a92b31e548e63f954f92d01eaa0271fb2a336baef8";
const PUBLIC_Y = "fb0c45e410ef7a6cdae724e6a78dbff52562e97ede009e762b667d9b14adea6c";
const PRIVATE_K = "e74a72505084c3269aa9b696d603e3e08c74c6740212c11a31e26cdfe08bdf6a";
const CURVE = "sm2p256v1";
/* Decryption Test Ciphertext*/
const CIPHERTEXT_1 = "9a31bc0adb4677cdc4141479e3949572a55c3e6fb52094721f741c2bd2e179aaa87be6263bc1be602e473be3d5de5dce97f8248948b3a7e15f9f67f64aef21575e0c05e6171870a10ff9ab778dbef24267ad90e1a9d47d68f757d57c4816612e9829f804025dea05a511cda39371c22a2828f976f72e";
const CIPHERTEXT_2 = "d3647d68568a2e7a4f8e843286be7bf2b4d80256697d19a73df306ae1a7e6d0364d942e23d2340606e7a2502a838b132f9242587b2ea7e4c207e87242eea8cae68f5ff4da2a95a7f6d350608ae5b6777e1d925bf9c560087af84aba7befba713130106ddb4082d803811bca3864594722f3198d58257fe4ba37f4aa540adf4cb0568bddd2d8140ad3030deea0a87e3198655cc4d22bfc3d73b1c4afec2ff15d68c8d1298d97132cace922ee8a4e41ca288a7e748b77ca94aa81dc283439923ae7939e00898e16fe5111fbe1d928d152b216a";
const CIPHERTEXT_3 = "5f340eeb4398fa8950ee3408d0e3fe34bf7728c9fdb060c94b916891b5c693610274160b52a7132a2bf16ad5cdb57d1e00da2f3ddbd55350729aa9c268b53e40c05ccce9912daa14406e8c132e389484e69757350be25351755dcc6c25c94b3c1a448b2cf8c2017582125eb6cf782055b199a875e966";
const CIPHERTEXT_4 = "0649bac46c3f9fd7fb3b2be4bff27414d634651efd02ca67d8c802bbc5468e77d035c39b581d6b56227f5d87c0b4efbea5032c0761139295ae194b9f1fce698f2f4b51d89fa5554171a1aad2e61fe9de89831aec472ecc5ab178ebf4d2230c1fb94fca03e536b87b9eba6db71ba9939260a08ffd230ca86cb45cf754854222364231bdb8b873791d63ad57a4b3fa5b6375388dc879373f5f1be9051bc5072a8afbec5b7b034e4907aa5bb4b6b1f50e725d09cb6a02e07ce20263005f6c9157ce05d3ea739d231d4f09396fb72aa680884d78";
TestRegister.addTests([
{
name: "SM2 Decrypt: Small Input; Format One",
input: CIPHERTEXT_1,
expectedOutput: SMALL_PLAIN,
recipeConfig: [
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C3C2", CURVE]
}
]
},
{
name: "SM2 Decrypt: Large Input; Format One",
input: CIPHERTEXT_2,
expectedOutput: LARGE_PLAIN,
recipeConfig: [
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C3C2", CURVE]
}
]
},
{
name: "SM2 Decrypt: Small Input; Format Two",
input: CIPHERTEXT_3,
expectedOutput: SMALL_PLAIN,
recipeConfig: [
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C2C3", CURVE]
}
]
},
{
name: "SM2 Decrypt: Large Input; Format Two",
input: CIPHERTEXT_4,
expectedOutput: LARGE_PLAIN,
recipeConfig: [
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C2C3", CURVE]
}
]
},
{
name: "SM2 Encrypt And Decrypt: Small Input; Format One",
input: SMALL_PLAIN,
expectedOutput: SMALL_PLAIN,
recipeConfig: [
{
"op": "SM2 Encrypt",
"args": [PUBLIC_X, PUBLIC_Y, "C1C3C2", CURVE],
},
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C3C2", CURVE]
}
]
},
{
name: "SM2 Encrypt And Decrypt: Large Input; Format One",
input: LARGE_PLAIN,
expectedOutput: LARGE_PLAIN,
recipeConfig: [
{
"op": "SM2 Encrypt",
"args": [PUBLIC_X, PUBLIC_Y, "C1C3C2", CURVE],
},
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C3C2", CURVE]
}
]
},
{
name: "SM2 Encrypt And Decrypt: Small Input; Format Two",
input: SMALL_PLAIN,
expectedOutput: SMALL_PLAIN,
recipeConfig: [
{
"op": "SM2 Encrypt",
"args": [PUBLIC_X, PUBLIC_Y, "C1C2C3", CURVE],
},
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C2C2", CURVE]
}
]
},
{
name: "SM2 Encrypt And Decrypt: Large Input; Format Two",
input: LARGE_PLAIN,
expectedOutput: LARGE_PLAIN,
recipeConfig: [
{
"op": "SM2 Encrypt",
"args": [PUBLIC_X, PUBLIC_Y, "C1C2C3", CURVE],
},
{
"op": "SM2 Decrypt",
"args": [PRIVATE_K, "C1C2C3", CURVE]
}
]
},
]);

View file

@ -0,0 +1,126 @@
/**
* Strip IPv4 header tests.
*
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Strip IPv4 header: No options, No payload",
input: "450000140005400080060000c0a80001c0a80002",
expectedOutput: "",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: No options, Payload",
input: "450000140005400080060000c0a80001c0a80002ffffffffffffffff",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Options, No payload",
input: "460000140005400080060000c0a80001c0a8000207000000",
expectedOutput: "",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Options, Payload",
input: "460000140005400080060000c0a80001c0a8000207000000ffffffffffffffff",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Input length lesss than minimum header length",
input: "450000140005400080060000c0a80001c0a800",
expectedOutput: "Input length is less than minimum IPv4 header length",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Input length less than IHL",
input: "460000140005400080060000c0a80001c0a80000",
expectedOutput: "Input length is less than IHL",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
}
]);

View file

@ -0,0 +1,126 @@
/**
* Strip TCP header tests.
*
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Strip TCP header: No options, No payload",
input: "7f900050000fa4b2000cb2a45010bff100000000",
expectedOutput: "",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip TCP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip TCP header: No options, Payload",
input: "7f900050000fa4b2000cb2a45010bff100000000ffffffffffffffff",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip TCP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip TCP header: Options, No payload",
input: "7f900050000fa4b2000cb2a47010bff100000000020405b404020000",
expectedOutput: "",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip TCP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip TCP header: Options, Payload",
input: "7f900050000fa4b2000cb2a47010bff100000000020405b404020000ffffffffffffffff",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip TCP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip TCP header: Input length less than minimum header length",
input: "7f900050000fa4b2000cb2a45010bff1000000",
expectedOutput: "Need at least 20 bytes for a TCP Header",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip TCP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip TCP header: Input length less than data offset",
input: "7f900050000fa4b2000cb2a47010bff100000000",
expectedOutput: "Input length is less than data offset",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip TCP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
}
]);

View file

@ -0,0 +1,69 @@
/**
* Strip UDP header tests.
*
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Strip UDP header: No payload",
input: "8111003500000000",
expectedOutput: "",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip UDP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip UDP header: Payload",
input: "8111003500080000ffffffffffffffff",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip UDP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip UDP header: Input length less than header length",
input: "81110035000000",
expectedOutput: "Need 8 bytes for a UDP Header",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip UDP header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
}
]);

View file

@ -0,0 +1,123 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
/**
* Take nth bytes tests
*/
TestRegister.addTests([
{
name: "Take nth bytes: Nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Take nth bytes: Nothing (apply to each line)",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Take nth bytes: Basic single line",
input: "0123456789",
expectedOutput: "048",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Take nth bytes: Basic single line (apply to each line)",
input: "0123456789",
expectedOutput: "048",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Take nth bytes: Complex single line",
input: "0123456789",
expectedOutput: "59",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Take nth bytes: Complex single line (apply to each line)",
input: "0123456789",
expectedOutput: "59",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, true],
},
],
},
{
name: "Take nth bytes: Basic multi line",
input: "01234\n56789",
expectedOutput: "047",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Take nth bytes: Basic multi line (apply to each line)",
input: "01234\n56789",
expectedOutput: "04\n59",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Take nth bytes: Complex multi line",
input: "01234\n56789",
expectedOutput: "\n8",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Take nth bytes: Complex multi line (apply to each line)",
input: "012345\n6789ab",
expectedOutput: "5\nb",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, true],
},
],
}
]);

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View file

@ -1,8 +1,10 @@
const webpack = require("webpack"); const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin");
const { ModifySourcePlugin, ReplaceOperation } = require("modify-source-webpack-plugin"); const { ModifySourcePlugin, ReplaceOperation } = require("modify-source-webpack-plugin");
const path = require("path"); const path = require("path");
const zlib = require("zlib");
/** /**
* Webpack configuration details for use with Grunt. * Webpack configuration details for use with Grunt.
@ -64,6 +66,21 @@ module.exports = {
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: "assets/[name].css" filename: "assets/[name].css"
}), }),
new CompressionPlugin({
filename: "[path][base].gz",
algorithm: "gzip",
test: /\.(js|css|html)$/,
}),
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|html)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
}),
new CopyWebpackPlugin({ new CopyWebpackPlugin({
patterns: [ patterns: [
{ {