diff --git a/.editorconfig b/.editorconfig index b50059bb..cef4cab0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,7 @@ indent_size = 4 [{package.json,.travis.yml,nightwatch.json}] indent_style = space indent_size = 2 + +[.github/**.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 1350e976..00000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: "CodeQL Analysis" - -on: - workflow_dispatch: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - types: [synchronize, opened, reopened] - schedule: - - cron: '22 17 * * 5' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'javascript' ] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 8a3aff54..74710dff 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -1,58 +1,64 @@ name: "Master Build, Test & Deploy" +permissions: + contents: read + on: workflow_dispatch: push: branches: - - master + - master jobs: main: + permissions: + contents: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - - name: Set node version - uses: actions/setup-node@v3 - with: - node-version: '18.x' + - name: Set node version + uses: actions/setup-node@v6 + with: + node-version: 18 + registry-url: "https://registry.npmjs.org" - - name: Install - run: | - export DETECT_CHROMEDRIVER_VERSION=true - npm install - npm run setheapsize + - name: Install + run: | + export DETECT_CHROMEDRIVER_VERSION=true + npm install + npm run setheapsize - - name: Lint - run: npx grunt lint + - name: Lint + run: npx grunt lint - - name: Unit Tests - run: | - npm test - npm run testnodeconsumer + - name: Unit Tests + run: | + npm test + npm run testnodeconsumer - - name: Production Build - if: success() - run: npx grunt prod --msg="Version 10 is here! Read about the new features here" + - name: Production Build + if: success() + run: npx grunt prod --msg="" - - name: Generate sitemap - run: npx grunt exec:sitemap + - name: Generate sitemap + run: npx grunt exec:sitemap - - name: UI Tests - if: success() - run: | - sudo apt-get install xvfb - xvfb-run --server-args="-screen 0 1200x800x24" npx grunt testui + - name: UI Tests + if: success() + run: | + sudo apt-get install xvfb + xvfb-run --server-args="-screen 0 1200x800x24" npx grunt testui - - name: Prepare for GitHub Pages - if: success() - run: npx grunt copy:ghPages + - name: Prepare for GitHub Pages + if: success() + run: npx grunt copy:ghPages - - name: Deploy to GitHub Pages - if: success() && github.ref == 'refs/heads/master' - uses: crazy-max/ghaction-github-pages@v3 - with: - target_branch: gh-pages - build_dir: ./build/prod - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Deploy to GitHub Pages + if: success() && github.ref == 'refs/heads/master' + uses: crazy-max/ghaction-github-pages@v3 + with: + target_branch: gh-pages + build_dir: ./build/prod + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml index 296e60b9..8f04df72 100644 --- a/.github/workflows/pull_requests.yml +++ b/.github/workflows/pull_requests.yml @@ -1,5 +1,8 @@ name: "Pull Requests" +permissions: + contents: read + on: workflow_dispatch: pull_request: @@ -9,47 +12,46 @@ jobs: main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - - name: Set node version - uses: actions/setup-node@v3 - with: - node-version: '18.x' + - name: Set node version + uses: actions/setup-node@v6 + with: + node-version: 18 + registry-url: "https://registry.npmjs.org" - - name: Install - run: | - export DETECT_CHROMEDRIVER_VERSION=true - npm install - npm run setheapsize + - name: Install + run: | + export DETECT_CHROMEDRIVER_VERSION=true + npm install + npm run setheapsize - - name: Lint - run: npx grunt lint + - name: Lint + run: npx grunt lint - - name: Unit Tests - run: | - npm test - npm run testnodeconsumer + - name: Unit Tests + run: | + npm test + npm run testnodeconsumer - - name: Production Build - if: success() - run: npx grunt prod + - name: Production Build + if: success() + run: npx grunt prod - - name: Production Image Build - if: success() - id: build-image - uses: redhat-actions/buildah-build@v2 - with: - # Not being uploaded to any registry, use a simple name to allow Buildah to build correctly. - image: cyberchef - containerfiles: ./Dockerfile - platforms: linux/amd64 - oci: true - # Webpack seems to use a lot of open files, increase the max open file limit to accomodate. - extra-args: | - --ulimit nofile=10000 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: UI Tests - if: success() - run: | - sudo apt-get install xvfb - xvfb-run --server-args="-screen 0 1200x800x24" npx grunt testui + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Production Image Build + if: success() + id: build-image + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64 + - name: UI Tests + if: success() + run: | + sudo apt-get install xvfb + xvfb-run --server-args="-screen 0 1200x800x24" npx grunt testui diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index a068ffbb..b40af876 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -4,7 +4,11 @@ on: workflow_dispatch: push: tags: - - 'v*' + - "v*" + +permissions: + id-token: write + contents: read env: REGISTRY: ghcr.io @@ -16,78 +20,78 @@ jobs: main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - - name: Set node version - uses: actions/setup-node@v3 - with: - node-version: '18.x' + - name: Set node version + uses: actions/setup-node@v6 + with: + node-version: 18 + registry-url: "https://registry.npmjs.org" - - name: Install - run: | - npm ci - npm run setheapsize + - name: Install + run: | + export DETECT_CHROMEDRIVER_VERSION=true + npm ci + npm run setheapsize - - name: Lint - run: npx grunt lint + - name: Lint + run: npx grunt lint - - name: Unit Tests - run: | - npm test - npm run testnodeconsumer + - name: Unit Tests + run: | + npm test + npm run testnodeconsumer - - name: Production Build - run: npx grunt prod + - name: Production Build + run: npx grunt prod - - name: UI Tests - run: | - sudo apt-get install xvfb - xvfb-run --server-args="-screen 0 1200x800x24" npx grunt testui + - name: UI Tests + run: | + sudo apt-get install xvfb + xvfb-run --server-args="-screen 0 1200x800x24" npx grunt testui - - name: Image Metadata - id: image-metadata - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=semver,pattern={{major}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{version}} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Production Image Build - id: build-image - uses: redhat-actions/buildah-build@v2 - with: - tags: ${{ steps.image-metadata.outputs.tags }} - labels: ${{ steps.image-metadata.outputs.labels }} - containerfiles: ./Dockerfile - platforms: linux/amd64 - oci: true - # Webpack seems to use a lot of open files, increase the max open file limit to accomodate. - extra-args: | - --ulimit nofile=10000 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Image Metadata + id: image-metadata + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{version}} - - name: Upload Release Assets - id: upload-release-assets - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: build/prod/*.zip - tag: ${{ github.ref }} - overwrite: true - file_glob: true - body: "See the [CHANGELOG](https://github.com/gchq/CyberChef/blob/master/CHANGELOG.md) and [commit messages](https://github.com/gchq/CyberChef/commits/master) for details." + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USER }} + password: ${{ env.REGISTRY_PASSWORD }} - - name: Publish to NPM - uses: JS-DevTools/npm-publish@v1 - with: - token: ${{ secrets.NPM_TOKEN }} + - name: Publish to GHCR + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.image-metadata.outputs.tags }} + labels: ${{ steps.image-metadata.outputs.labels }} + platforms: linux/amd64,linux/arm64 - - 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 }} + - name: Upload Release Assets + id: upload-release-assets + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build/prod/*.zip + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "See the [CHANGELOG](https://github.com/gchq/CyberChef/blob/master/CHANGELOG.md) and [commit messages](https://github.com/gchq/CyberChef/commits/master) for details." + + - name: Publish to NPM + run: npm publish diff --git a/CHANGELOG.md b/CHANGELOG.md index d3a8feb7..535a11a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,75 @@ All major and minor version changes will be documented in this file. Details of ## Details +### [10.20.0] - 2026-01-28 +- Fixed Optical Character Recognition and added tests [@n1474335] | [ab37c1e] +- Fixed JA4 version fallback value [@n1474335] | [7a5225c] +- Updated chromedriver [@n1474335] | [0e82e4b] +- Fixed RSA Sign and Verify character encodings [@n1474335] | [895a929] +- Updated chromedriver [@n1474335] | [d3adfc7] +- Added message format arg to RSA Verify operation [@n1474335] | [47c85a1] +- Add operation for parsing X.509 CRLs [@robinsandhu] | [#1887] +- Fix typo in description of JWT Sign recipe [@GuilhermoReadonly] | [#1961] +- Corrected path to generateNodeIndex.mjs [@simonarnell] | [#1959] +- Add 'header' ingredient to JWT Sign operation [@RandomByte] | [#1957] +- Add Parse TLS record operation [@c65722] | [#1936] +- Automatically detect chrome driver version [@gchq] | [#1972] +- Add Strip UDP header operation [@c65722] | [#1900] +- Add Strip TCP header operation [@c65722] | [#1898] +- Webpack compress with gzip and brotli [@max0x53] | [#1955] +- add offset field to 'Add Line Numbers' operation [@Adamkadaban] | [#1866] +- Disable flakey URL test [@a3957273] | [#1973] +- Add Strip IPv4 header operation [@c65722] | [#1899] +- IPv6 Transition Operation [@jb30795] | [#1780] +- fix: Blowfish - ignore IV length in ECB mode [@FranciscoPombal] | [#1902] +- Add 'Drop nth bytes' operation [@Oshawk] | [#1914] +- Add 'Take nth bytes' operation [@Oshawk] | [#1915] +- Add Leet Speak [@bartblaze] | [#1971] +- Fix Generate TOTP & HOPT [@exactlyaron] | [#1966] +- Updated luhn checksum operation to work with different bases [@k3ach] | [#1933] +- automatically theme mode based on user preference [@vs4vijay] | [#1921] +- fix: DES/Triple DES - misleading error messages [@FranciscoPombal] | [#1904] +- fix: ROT13 - shifting numbers by negative amounts [@FranciscoPombal] | [#1903] +- Introduce Yubico's Modhex for Conversion [@linuxgemini] | [#1105] +- Feature: MIME RFC2047 Decoding [@MShwed] | [#630] +- CC-1889 add _ option [@depperm] | [#1977] +- chore(root): add cspell [@evenstensberg] | [#1976] +- Preserve uppercase for Leet Speak [@bartblaze] | [#1981] +- Load the user's preferred color scheme if the URL contains an invalid theme [@0xh3xa] | [#2007] +- Add SM2 Encrypt and Decrypt Operations [@flakjacket95] | [#1909] +- Support jq as an operation. [@zhzy0077] | [#1604] +- Add fingerprints to the 'Parse X.509 certificate' operation [@JSCU-CNI] | [#1863] +- Added a JSON to YAML and a YAML to JSON operation [@ccarpo] | [#1286] +- Add CRC Operation [@r4mos] | [#1993] +- Bug Fix: selected theme not loading when refreshing [@0xh3xa] | [#2006] +- Fix(RecipeWaiter): sanitize user input in addOperation to prevent XSS [@0xh3xa] | [#2014] +- Docker multiplatform build support [@PathToLife] | [#1974] +- Add Base32 Hex Extended Alphabet and Base32 Tests. [@peterc-s] | [#1991] +- Add ECB/NoPadding and CBC/NoPadding support to AES encryption [@plvie] | [#2013] +- Add new operation: PHP Serialize [@brun0ne] | [#1548] +- Push input through postmessage [@kenduguay1] | [#1992] +- Add jsonata query operation [@jonking-ajar] | [#1587] +- Re-enable Npm Release in github workflows [@PathToLife] | [#2031] +- Add to ECDSA Verify the message format [@r4mos] | [#2027] +- Added alternating caps functionality [@sw5678] | [#1897] +- XOR Checksum operation added [@jg42526] | [#2035] +- Add GenerateAllChecksums operation * Remove checksums from GenerateAllHashes operation [@es45411] | [66d445c] +- Update GenerateAllChecksums infoURL [@es45411] | [#2037] +- Add toggle "+" character to URLDecode operation [@es45411] | [#2040] +- Workaround for Safari load bug [@GCHQDeveloper94872] | [#2038] +- Updated Dockerfile to correctly build on ARM64 platforms [@Sma-Das] | [#2042] +- Addresses bug report #2008 Added explicit support for octal IP addresses. Changed approach to IPv4 regex to be string manipulation generated. Added some unit tests for IP address parsing - probably not full coverage. Added lookahead and lookbehind tricks to resolve warned issue that 1.2.3.256 would still be extracted as 1.2.3.25. Now only accepts valid IP addresses. Warning replaced with clause about infinite length dotted decimal forms. [@gchqdev364] | [#2041] +- Remove trim from rail fence [@Odyhibit] | [#1986] +- Fix email regex [@ericli-splunk] | [#2025] +- Add Blake3 hashing [@xumptex] | [#2023] +- Use defaultIndex instead of 0 in transformArgs [@bartvanandel] | [#2015] +- Add "Generate UUID" and "Analyse UUID" operations [@bartvanandel] | [#2011] +- Add new operation: Template [@kendallgoto] | [#2021] +- Add more clear build instructions [@remingtr] | [#1873] +- Show On Map updated to use leaflet over WikiMedia [@0xff1ce] | [#1884] +- Fixed ToDecimal signed logic [@starplanet] | [#1545] +- Use BigInt for encoding/decoding VarInt [@mikecat] | [#1978] + ### [10.19.0] - 2024-06-21 - Add support for ECDSA and DSA in 'Parse CSR' [@robinsandhu] | [#1828] - Fix typos in SIGABA.mjs [@eltociear] | [#1834] @@ -440,6 +509,7 @@ All major and minor version changes will be documented in this file. Details of ## [4.0.0] - 2016-11-28 - Initial open source commit [@n1474335] | [b1d73a72](https://github.com/gchq/CyberChef/commit/b1d73a725dc7ab9fb7eb789296efd2b7e4b08306) +[10.20.0]: https://github.com/gchq/CyberChef/releases/tag/v10.20.0 [10.19.0]: https://github.com/gchq/CyberChef/releases/tag/v10.19.0 [10.18.0]: https://github.com/gchq/CyberChef/releases/tag/v10.18.0 [10.17.0]: https://github.com/gchq/CyberChef/releases/tag/v10.17.0 @@ -630,6 +700,60 @@ All major and minor version changes will be documented in this file. Details of [@cplussharp]: https://github.com/cplussharp [@robinsandhu]: https://github.com/robinsandhu [@eltociear]: https://github.com/eltociear +[@GuilhermoReadonly]: https://github.com/GuilhermoReadonly +[@simonarnell]: https://github.com/simonarnell +[@RandomByte]: https://github.com/RandomByte +[@c65722]: https://github.com/c65722 +[@c65722]: https://github.com/c65722 +[@c65722]: https://github.com/c65722 +[@max0x53]: https://github.com/max0x53 +[@Adamkadaban]: https://github.com/Adamkadaban +[@c65722]: https://github.com/c65722 +[@jb30795]: https://github.com/jb30795 +[@FranciscoPombal]: https://github.com/FranciscoPombal +[@Oshawk]: https://github.com/Oshawk +[@Oshawk]: https://github.com/Oshawk +[@bartblaze]: https://github.com/bartblaze +[@exactlyaron]: https://github.com/exactlyaron +[@k3ach]: https://github.com/k3ach +[@vs4vijay]: https://github.com/vs4vijay +[@FranciscoPombal]: https://github.com/FranciscoPombal +[@FranciscoPombal]: https://github.com/FranciscoPombal +[@linuxgemini]: https://github.com/linuxgemini +[@depperm]: https://github.com/depperm +[@evenstensberg]: https://github.com/evenstensberg +[@bartblaze]: https://github.com/bartblaze +[@0xh3xa]: https://github.com/0xh3xa +[@flakjacket95]: https://github.com/flakjacket95 +[@zhzy0077]: https://github.com/zhzy0077 +[@JSCU-CNI]: https://github.com/JSCU-CNI +[@ccarpo]: https://github.com/ccarpo +[@r4mos]: https://github.com/r4mos +[@0xh3xa]: https://github.com/0xh3xa +[@0xh3xa]: https://github.com/0xh3xa +[@PathToLife]: https://github.com/PathToLife +[@peterc-s]: https://github.com/peterc-s +[@plvie]: https://github.com/plvie +[@kenduguay1]: https://github.com/kenduguay1 +[@jonking-ajar]: https://github.com/jonking-ajar +[@PathToLife]: https://github.com/PathToLife +[@r4mos]: https://github.com/r4mos +[@jg42526]: https://github.com/jg42526 +[@es45411]: https://github.com/es45411 +[@gchq]: https://github.com/gchq +[@gchqdev364]: https://github.com/gchqdev364 +[@GCHQDeveloper94872]: https://github.com/GCHQDeveloper94872 +[@Sma-Das]: https://github.com/Sma-Das +[@gchq]: https://github.com/gchq +[@Odyhibit]: https://github.com/Odyhibit +[@ericli-splunk]: https://github.com/ericli-splunk +[@xumptex]: https://github.com/xumptex +[@bartvanandel]: https://github.com/bartvanandel +[@bartvanandel]: https://github.com/bartvanandel +[@kendallgoto]: https://github.com/kendallgoto +[@remingtr]: https://github.com/remingtr +[@0xff1ce]: https://github.com/0xff1ce +[@starplanet]: https://github.com/starplanet [8ad18b]: https://github.com/gchq/CyberChef/commit/8ad18bc7db6d9ff184ba3518686293a7685bf7b7 @@ -642,6 +766,46 @@ All major and minor version changes will be documented in this file. Details of [760eff4]: https://github.com/gchq/CyberChef/commit/760eff49b5307aaa3104c5e5b437ffe62299acd1 [65ffd8d]: https://github.com/gchq/CyberChef/commit/65ffd8d65d88eb369f6f61a5d1d0f807179bffb7 [0a353ee]: https://github.com/gchq/CyberChef/commit/0a353eeb378b9ca5d49e23c7dfc175ae07107b08 +[66d445c]: https://github.com/gchq/CyberChef/commit/66d445c5ef4e8bd896fd15396e3ce2d660d8ace1 +[ab37c1e]: https://github.com/gchq/CyberChef/commit/ab37c1e562dbee0495ed32876ecbb8225282af25 +[965570d]: https://github.com/gchq/CyberChef/commit/965570d2504c17ee1f96211a1dc10ed40cd2b332 +[a477f47]: https://github.com/gchq/CyberChef/commit/a477f47aecd01d78b11fe186ed4b20d9c487cfac +[7a5225c]: https://github.com/gchq/CyberChef/commit/7a5225c961a5e0d192b03152117cd10a761f73d6 +[5f88ae4]: https://github.com/gchq/CyberChef/commit/5f88ae44ec77228d9bed8f11e8cc8e7dcfb36914 +[0e82e4b]: https://github.com/gchq/CyberChef/commit/0e82e4b7c6c77cadb8be61cb145e081d6ecfdc88 +[d635cca]: https://github.com/gchq/CyberChef/commit/d635cca2106aae2a59caf0e5d7e3633ee1ea3155 +[895a929]: https://github.com/gchq/CyberChef/commit/895a9299255525cb57886deb9d9fd4ba17ae9548 +[270a333]: https://github.com/gchq/CyberChef/commit/270a33317944612d27ea1cc15275ad6b0ed097e5 +[d3adfc7]: https://github.com/gchq/CyberChef/commit/d3adfc7c3e5719279524356bce5261bd8350c0f8 +[47c85a1]: https://github.com/gchq/CyberChef/commit/47c85a105ddbdd4cabfa44ddddbc56e3907a8c33 +[3822c6c]: https://github.com/gchq/CyberChef/commit/3822c6c520a0b4200abc675c33f46082f5b9efc6 +[66d445c]: https://github.com/gchq/CyberChef/commit/66d445c5ef4e8bd896fd15396e3ce2d660d8ace1 +[ab37c1e]: https://github.com/gchq/CyberChef/commit/ab37c1e562dbee0495ed32876ecbb8225282af25 +[965570d]: https://github.com/gchq/CyberChef/commit/965570d2504c17ee1f96211a1dc10ed40cd2b332 +[a477f47]: https://github.com/gchq/CyberChef/commit/a477f47aecd01d78b11fe186ed4b20d9c487cfac +[7a5225c]: https://github.com/gchq/CyberChef/commit/7a5225c961a5e0d192b03152117cd10a761f73d6 +[5f88ae4]: https://github.com/gchq/CyberChef/commit/5f88ae44ec77228d9bed8f11e8cc8e7dcfb36914 +[0e82e4b]: https://github.com/gchq/CyberChef/commit/0e82e4b7c6c77cadb8be61cb145e081d6ecfdc88 +[d635cca]: https://github.com/gchq/CyberChef/commit/d635cca2106aae2a59caf0e5d7e3633ee1ea3155 +[895a929]: https://github.com/gchq/CyberChef/commit/895a9299255525cb57886deb9d9fd4ba17ae9548 +[270a333]: https://github.com/gchq/CyberChef/commit/270a33317944612d27ea1cc15275ad6b0ed097e5 +[d3adfc7]: https://github.com/gchq/CyberChef/commit/d3adfc7c3e5719279524356bce5261bd8350c0f8 +[47c85a1]: https://github.com/gchq/CyberChef/commit/47c85a105ddbdd4cabfa44ddddbc56e3907a8c33 +[3822c6c]: https://github.com/gchq/CyberChef/commit/3822c6c520a0b4200abc675c33f46082f5b9efc6 +[66d445c]: https://github.com/gchq/CyberChef/commit/66d445c5ef4e8bd896fd15396e3ce2d660d8ace1 +[ab37c1e]: https://github.com/gchq/CyberChef/commit/ab37c1e562dbee0495ed32876ecbb8225282af25 +[965570d]: https://github.com/gchq/CyberChef/commit/965570d2504c17ee1f96211a1dc10ed40cd2b332 +[a477f47]: https://github.com/gchq/CyberChef/commit/a477f47aecd01d78b11fe186ed4b20d9c487cfac +[7a5225c]: https://github.com/gchq/CyberChef/commit/7a5225c961a5e0d192b03152117cd10a761f73d6 +[5f88ae4]: https://github.com/gchq/CyberChef/commit/5f88ae44ec77228d9bed8f11e8cc8e7dcfb36914 +[0e82e4b]: https://github.com/gchq/CyberChef/commit/0e82e4b7c6c77cadb8be61cb145e081d6ecfdc88 +[d635cca]: https://github.com/gchq/CyberChef/commit/d635cca2106aae2a59caf0e5d7e3633ee1ea3155 +[895a929]: https://github.com/gchq/CyberChef/commit/895a9299255525cb57886deb9d9fd4ba17ae9548 +[270a333]: https://github.com/gchq/CyberChef/commit/270a33317944612d27ea1cc15275ad6b0ed097e5 +[d3adfc7]: https://github.com/gchq/CyberChef/commit/d3adfc7c3e5719279524356bce5261bd8350c0f8 +[47c85a1]: https://github.com/gchq/CyberChef/commit/47c85a105ddbdd4cabfa44ddddbc56e3907a8c33 +[3822c6c]: https://github.com/gchq/CyberChef/commit/3822c6c520a0b4200abc675c33f46082f5b9efc6 +[66d445c]: https://github.com/gchq/CyberChef/commit/66d445c5ef4e8bd896fd15396e3ce2d660d8ace1 [#95]: https://github.com/gchq/CyberChef/pull/299 [#173]: https://github.com/gchq/CyberChef/pull/173 @@ -778,4 +942,3 @@ All major and minor version changes will be documented in this file. Details of [#512]: https://github.com/gchq/CyberChef/issues/512 [#1732]: https://github.com/gchq/CyberChef/issues/1732 [#1789]: https://github.com/gchq/CyberChef/issues/1789 - diff --git a/Dockerfile b/Dockerfile index be4c8bad..2184a294 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,32 @@ -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 . . -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 -FROM nginx:1.25-alpine3.18 AS cyberchef +######################################### +# Package static build files into nginx # +######################################### +FROM nginx:stable-alpine AS cyberchef -COPY --from=build ./build/prod /usr/share/nginx/html/ +COPY --from=builder /app/build/prod /usr/share/nginx/html/ diff --git a/README.md b/README.md index 5549bda2..89f0371d 100755 --- a/README.md +++ b/README.md @@ -20,21 +20,36 @@ Cryptographic operations in CyberChef should not be relied upon to provide secur [A live demo can be found here][1] - have fun! -## Containers +## Running Locally with Docker -If you would like to try out CyberChef locally you can either build it yourself: +**Prerequisites** +- [Docker](hhttps://www.docker.com/products/docker-desktop/) + - Docker Desktop must be open and running on your machine + + +#### Option 1: Build the Docker Image Yourself + +1. Build the docker image ```bash docker build --tag cyberchef --ulimit nofile=10000 . +``` +2. Run the docker container +```bash docker run -it -p 8080:80 cyberchef ``` +3. Navigate to `http://localhost:8080` in your browser -Or you can use our image directly: +#### Option 2: Use the pre-built Docker Image + +If you prefer to skip the build process, you can use the pre-built image ```bash docker run -it -p 8080:80 ghcr.io/gchq/cyberchef:latest ``` +Just like before, navigate to `http://localhost:8080` in your browser. + This image is built and published through our [GitHub Workflows](.github/workflows/releases.yml) ## How it works diff --git a/package-lock.json b/package-lock.json index 50639ea8..0b7bce14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cyberchef", - "version": "10.19.4", + "version": "10.20.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cyberchef", - "version": "10.19.4", + "version": "10.20.0", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { @@ -31,12 +31,13 @@ "chi-squared": "^1.1.0", "codepage": "^1.15.0", "crypto-api": "^0.8.5", - "crypto-browserify": "^3.12.0", + "crypto-browserify": "^3.12.1", "crypto-js": "^4.2.0", "ctph.js": "0.0.5", "d3": "7.9.0", "d3-hexbin": "^0.2.2", "diff": "^5.2.0", + "dompurify": "^3.2.5", "es6-promisify": "^7.0.0", "escodegen": "^2.1.0", "esprima": "^4.0.1", @@ -45,19 +46,22 @@ "file-saver": "^2.0.5", "flat": "^6.0.1", "geodesy": "1.1.3", + "handlebars": "^4.7.8", + "hash-wasm": "^4.12.0", "highlight.js": "^11.9.0", "ieee754": "^1.2.1", "jimp": "^0.22.12", + "jq-web": "^0.5.1", "jquery": "3.7.1", - "js-crc": "^0.2.0", "js-sha3": "^0.9.3", "jsesc": "^3.0.2", "json5": "^2.2.3", - "jsonpath-plus": "^9.0.0", + "jsonata": "^2.0.3", + "jsonpath-plus": "^10.3.0", "jsonwebtoken": "8.5.1", "jsqr": "^1.4.0", "jsrsasign": "^11.1.0", - "kbpgp": "2.1.15", + "kbpgp": "^2.1.17", "libbzip2-wasm": "0.0.4", "libyara-wasm": "^1.2.1", "lodash": "^4.17.21", @@ -93,6 +97,7 @@ "ua-parser-js": "^1.0.38", "unorm": "^1.6.0", "utf8": "^3.0.0", + "uuid": "^11.1.0", "vkbeautify": "^0.99.3", "xpath": "0.0.34", "xregexp": "^5.1.1", @@ -4364,6 +4369,13 @@ "@types/node": "*" } }, + "node_modules/@types/trusted-types": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", + "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", + "license": "MIT", + "optional": true + }, "node_modules/@types/ws": { "version": "8.5.13", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.13.tgz", @@ -5125,7 +5137,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", - "dev": true, "license": "MIT", "dependencies": { "possible-typed-array-names": "^1.0.0" @@ -8410,6 +8421,15 @@ "url": "https://github.com/fb55/domhandler?sponsor=1" } }, + "node_modules/dompurify": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.2.5.tgz", + "integrity": "sha512-mLPd29uoRe9HpvwP2TxClGQBzGXeEC/we/q+bFlmPPmj2p2Ugl3r6ATu/UU1v77DXNcehiBg9zsr1dREyA/dJQ==", + "license": "(MPL-2.0 OR Apache-2.0)", + "optionalDependencies": { + "@types/trusted-types": "^2.0.7" + } + }, "node_modules/domutils": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.8.0.tgz", @@ -8720,6 +8740,22 @@ "node": ">= 0.4" } }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es6-object-assign": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", @@ -9823,7 +9859,6 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", - "dev": true, "license": "MIT", "dependencies": { "is-callable": "^1.1.3" @@ -9883,14 +9918,16 @@ } }, "node_modules/form-data": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", - "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz", + "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", "dev": true, "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", "mime-types": "^2.1.12" }, "engines": { @@ -10825,6 +10862,27 @@ "dev": true, "license": "MIT" }, + "node_modules/handlebars": { + "version": "4.7.8", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", + "integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.5", + "neo-async": "^2.6.2", + "source-map": "^0.6.1", + "wordwrap": "^1.0.0" + }, + "bin": { + "handlebars": "bin/handlebars" + }, + "engines": { + "node": ">=0.4.7" + }, + "optionalDependencies": { + "uglify-js": "^3.1.4" + } + }, "node_modules/has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", @@ -10923,6 +10981,11 @@ "node": ">= 0.10" } }, + "node_modules/hash-wasm": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/hash-wasm/-/hash-wasm-4.12.0.tgz", + "integrity": "sha512-+/2B2rYLb48I/evdOIhP+K/DD2ca2fgBjp6O+GBEnCDk2e4rpeXIK8GvIyRPjTezgmWn9gmKwkQjjx6BtqDHVQ==" + }, "node_modules/hash.js": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", @@ -11659,7 +11722,6 @@ "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -12010,6 +12072,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-typed-array": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.15.tgz", + "integrity": "sha512-p3EcsicXjit7SaskXHs1hA91QxgTw46Fv6EFKKGS5DRFLD8yKnohjF3hxoju94b/OcMZoQukzpPpBE9uLVKzgQ==", + "license": "MIT", + "dependencies": { + "which-typed-array": "^1.1.16" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-unc-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-unc-path/-/is-unc-path-1.0.0.tgz", @@ -12290,18 +12367,18 @@ "integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==", "license": "BSD-3-Clause" }, + "node_modules/jq-web": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/jq-web/-/jq-web-0.5.1.tgz", + "integrity": "sha512-3Fa3E6g3U1O1j46ljy0EM10yRr4txzILga8J7bqOG8F89gZ6Lilz82WG9z6TItWpYEO0YGa4W8yFGj+NMM1xqQ==", + "license": "ISC" + }, "node_modules/jquery": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz", "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==", "license": "MIT" }, - "node_modules/js-crc": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/js-crc/-/js-crc-0.2.0.tgz", - "integrity": "sha512-8DdCSAOACpF8WDAjyDFBC2rj8OS4HUP9mNZBDfl8jCiPCnJG+2bkuycalxwZh6heFy6PrMvoWTp47lp6gzT65A==", - "license": "MIT" - }, "node_modules/js-sha3": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.9.3.tgz", @@ -12447,22 +12524,30 @@ "node": ">=6" } }, + "node_modules/jsonata": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/jsonata/-/jsonata-2.0.6.tgz", + "integrity": "sha512-WhQB5tXQ32qjkx2GYHFw2XbL90u+LLzjofAYwi+86g6SyZeXHz9F1Q0amy3dWRYczshOC3Haok9J4pOCgHtwyQ==", + "engines": { + "node": ">= 8" + } + }, "node_modules/jsonpath-plus": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-9.0.0.tgz", - "integrity": "sha512-bqE77VIDStrOTV/czspZhTn+o27Xx9ZJRGVkdVShEtPoqsIx5yALv3lWVU6y+PqYvWPJNWE7ORCQheQkEe0DDA==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-10.3.0.tgz", + "integrity": "sha512-8TNmfeTCk2Le33A3vRRwtuworG/L5RrgMvdjhKZxvyShO+mBu2fP50OWUjRLNtvw344DdDarFh9buFAZs5ujeA==", "license": "MIT", "dependencies": { - "@jsep-plugin/assignment": "^1.2.1", - "@jsep-plugin/regex": "^1.0.3", - "jsep": "^1.3.8" + "@jsep-plugin/assignment": "^1.3.0", + "@jsep-plugin/regex": "^1.0.4", + "jsep": "^1.4.0" }, "bin": { "jsonpath": "bin/jsonpath-cli.js", "jsonpath-plus": "bin/jsonpath-cli.js" }, "engines": { - "node": ">=14.0.0" + "node": ">=18.0.0" } }, "node_modules/jsonwebtoken": { @@ -12546,9 +12631,9 @@ } }, "node_modules/kbpgp": { - "version": "2.1.15", - "resolved": "https://registry.npmjs.org/kbpgp/-/kbpgp-2.1.15.tgz", - "integrity": "sha512-iFdQT+m2Mi2DB14kEFydF2joNe9x3E2VZCGZUt7UXsiZnQx5TtSl4KofP7EPtjHvf7weCxNKlEPSYiiCNMZ2jA==", + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/kbpgp/-/kbpgp-2.1.17.tgz", + "integrity": "sha512-pnjH7amyg6dZLXyF42BKbCTST0l0r1ErunqtFRrJCkHkGJb83cZZmx1pnqNFr+d/ls+5gvcHrZLPfUG5q7oRYw==", "license": "BSD-3-Clause", "dependencies": { "bn": "^1.0.5", @@ -13637,7 +13722,6 @@ "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", - "dev": true, "license": "MIT" }, "node_modules/netmask": { @@ -13859,6 +13943,15 @@ "node": ">=8" } }, + "node_modules/nightwatch/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/nightwatch/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -13920,9 +14013,9 @@ } }, "node_modules/node-forge": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", - "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.3.tgz", + "integrity": "sha512-rLvcdSyRCyouf6jcOIPe/BgwG/d7hKjzMKOas33/pHEr6gbq18IK9zV7DiPvzsz0oBJPme6qr6H6kGZuI9/DZg==", "license": "(BSD-3-Clause OR GPL-2.0)", "engines": { "node": ">= 6.13.0" @@ -14837,19 +14930,20 @@ } }, "node_modules/pbkdf2": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz", - "integrity": "sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.5.tgz", + "integrity": "sha512-Q3CG/cYvCO1ye4QKkuH7EXxs3VC/rI1/trd+qX2+PolbaKG0H+bgcZzrTt96mMyRtejk+JMCiLUn3y29W8qmFQ==", "license": "MIT", "dependencies": { - "create-hash": "^1.1.2", - "create-hmac": "^1.1.4", - "ripemd160": "^2.0.1", - "safe-buffer": "^5.0.1", - "sha.js": "^2.4.8" + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "ripemd160": "^2.0.3", + "safe-buffer": "^5.2.1", + "sha.js": "^2.4.12", + "to-buffer": "^1.2.1" }, "engines": { - "node": ">=0.12" + "node": ">= 0.10" } }, "node_modules/peek-readable": { @@ -15107,7 +15201,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -16086,13 +16179,31 @@ } }, "node_modules/ripemd160": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", - "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.3.tgz", + "integrity": "sha512-5Di9UC0+8h1L6ZD2d7awM7E/T4uA1fJRlx6zk/NvdCCVEoAnFqvHmCuNeIKoCeIixBX/q8uM+6ycDvF8woqosA==", "license": "MIT", "dependencies": { - "hash-base": "^3.0.0", - "inherits": "^2.0.1" + "hash-base": "^3.1.2", + "inherits": "^2.0.4" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/ripemd160/node_modules/hash-base": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.2.tgz", + "integrity": "sha512-Bb33KbowVTIj5s7Ked1OsqHUeCpz//tPwR+E2zJgJKo9Z5XolZ9b6bdUgjmYlwnWhoOQKoTd1TYToZGn5mAYOg==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.4", + "readable-stream": "^2.3.8", + "safe-buffer": "^5.2.1", + "to-buffer": "^1.2.1" + }, + "engines": { + "node": ">= 0.8" } }, "node_modules/rison": { @@ -16554,16 +16665,23 @@ "license": "ISC" }, "node_modules/sha.js": { - "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", - "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", + "version": "2.4.12", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.12.tgz", + "integrity": "sha512-8LzC5+bvI45BjpfXU8V5fdU2mfeKiQe1D1gIMn7XUlF3OTUrpdJpPPH4EMAnF0DsHHdSZqCdSss5qCmJKuiO3w==", "license": "(MIT AND BSD-3-Clause)", "dependencies": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" + "inherits": "^2.0.4", + "safe-buffer": "^5.2.1", + "to-buffer": "^1.2.0" }, "bin": { "sha.js": "bin.js" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/shebang-command": { @@ -16802,6 +16920,15 @@ "node": ">=0.8.0" } }, + "node_modules/sockjs/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/socks": { "version": "2.8.3", "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz", @@ -16842,7 +16969,6 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "devOptional": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" @@ -17592,6 +17718,26 @@ "node": ">=14.14" } }, + "node_modules/to-buffer": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.2.2.tgz", + "integrity": "sha512-db0E3UJjcFhpDhAF4tLo03oli3pwl3dbnzXOUIlRKrp+ldk/VUxzpWYZENsw2SZiuBjHAk7DfB0VU7NKdpb6sw==", + "license": "MIT", + "dependencies": { + "isarray": "^2.0.5", + "safe-buffer": "^5.2.1", + "typed-array-buffer": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/to-buffer/node_modules/isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "license": "MIT" + }, "node_modules/to-fast-properties": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", @@ -17774,6 +17920,20 @@ "node": ">= 0.6" } }, + "node_modules/typed-array-buffer": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz", + "integrity": "sha512-nAYYwfY3qnzX30IkA6AQZjVbtK6duGontcQm1WSG1MD94YLqK0515GNApXkoxKOWMusVssAHWLh9SeaoefYFGw==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.3", + "es-errors": "^1.3.0", + "is-typed-array": "^1.1.14" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/ua-parser-js": { "version": "1.0.40", "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.40.tgz", @@ -18089,13 +18249,15 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "license": "MIT", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz", + "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { - "uuid": "dist/bin/uuid" + "uuid": "dist/esm/bin/uuid" } }, "node_modules/v8flags": { @@ -18782,7 +18944,6 @@ "version": "1.1.18", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.18.tgz", "integrity": "sha512-qEcY+KJYlWyLH9vNbsr6/5j59AXk5ni5aakf8ldzBvGde6Iz4sxZGkJyWSAueTG7QhOvNRYb1lDdFmL5Td0QKA==", - "dev": true, "license": "MIT", "dependencies": { "available-typed-arrays": "^1.0.7", @@ -18860,6 +19021,12 @@ "node": ">=0.10.0" } }, + "node_modules/wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==", + "license": "MIT" + }, "node_modules/worker-loader": { "version": "3.0.8", "resolved": "https://registry.npmjs.org/worker-loader/-/worker-loader-3.0.8.tgz", diff --git a/package.json b/package.json index 20180e05..fe50083c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "10.19.4", + "version": "10.20.0", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", @@ -117,12 +117,13 @@ "chi-squared": "^1.1.0", "codepage": "^1.15.0", "crypto-api": "^0.8.5", - "crypto-browserify": "^3.12.0", + "crypto-browserify": "^3.12.1", "crypto-js": "^4.2.0", "ctph.js": "0.0.5", "d3": "7.9.0", "d3-hexbin": "^0.2.2", "diff": "^5.2.0", + "dompurify": "^3.2.5", "es6-promisify": "^7.0.0", "escodegen": "^2.1.0", "esprima": "^4.0.1", @@ -131,19 +132,22 @@ "file-saver": "^2.0.5", "flat": "^6.0.1", "geodesy": "1.1.3", + "handlebars": "^4.7.8", + "hash-wasm": "^4.12.0", "highlight.js": "^11.9.0", "ieee754": "^1.2.1", "jimp": "^0.22.12", + "jq-web": "^0.5.1", "jquery": "3.7.1", - "js-crc": "^0.2.0", "js-sha3": "^0.9.3", "jsesc": "^3.0.2", "json5": "^2.2.3", - "jsonpath-plus": "^9.0.0", + "jsonata": "^2.0.3", + "jsonpath-plus": "^10.3.0", "jsonwebtoken": "8.5.1", "jsqr": "^1.4.0", "jsrsasign": "^11.1.0", - "kbpgp": "2.1.15", + "kbpgp": "^2.1.17", "libbzip2-wasm": "0.0.4", "libyara-wasm": "^1.2.1", "lodash": "^4.17.21", @@ -179,6 +183,7 @@ "ua-parser-js": "^1.0.38", "unorm": "^1.6.0", "utf8": "^3.0.0", + "uuid": "^11.1.0", "vkbeautify": "^0.99.3", "xpath": "0.0.34", "xregexp": "^5.1.1", diff --git a/src/core/Utils.mjs b/src/core/Utils.mjs index a9c381d7..eae86374 100755 --- a/src/core/Utils.mjs +++ b/src/core/Utils.mjs @@ -177,7 +177,7 @@ class Utils { */ static printable(str, preserveWs=false, onlyAscii=false) { if (onlyAscii) { - return str.replace(/[^\x20-\x7f]/g, "."); + return str.replace(/[^\x20-\x7e]/g, "."); } // eslint-disable-next-line no-misleading-character-class diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index de3ea882..aac00ca1 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -26,6 +26,8 @@ "From Base45", "To Base58", "From Base58", + "To Bech32", + "From Bech32", "To Base62", "From Base62", "To Base64", @@ -72,6 +74,8 @@ "Avro to JSON", "CBOR Encode", "CBOR Decode", + "YAML to JSON", + "JSON to YAML", "Caret/M-decode", "Rison Encode", "Rison Decode", @@ -193,7 +197,9 @@ "Parse SSH Host Key", "Parse CSR", "Public Key from Certificate", - "Public Key from Private Key" + "Public Key from Private Key", + "SM2 Encrypt", + "SM2 Decrypt" ] }, { @@ -290,6 +296,7 @@ "To Upper case", "To Lower case", "Swap case", + "Alternating Caps", "To Case Insensitive Regex", "From Case Insensitive Regex", "Add line numbers", @@ -365,11 +372,13 @@ "Regular expression", "XPath expression", "JPath expression", + "Jsonata Query", "CSS selector", "Extract EXIF", "Extract ID3", "Extract Files", - "RAKE" + "RAKE", + "Template" ] }, { @@ -400,6 +409,7 @@ "name": "Hashing", "ops": [ "Analyse hash", + "Generate all checksums", "Generate all hashes", "MD2", "MD4", @@ -418,6 +428,7 @@ "Snefru", "BLAKE2b", "BLAKE2s", + "BLAKE3", "GOST Hash", "Streebog", "SSDEEP", @@ -441,10 +452,9 @@ "Fletcher-64 Checksum", "Adler-32 Checksum", "Luhn Checksum", - "CRC-8 Checksum", - "CRC-16 Checksum", - "CRC-32 Checksum", - "TCP/IP Checksum" + "CRC Checksum", + "TCP/IP Checksum", + "XOR Checksum" ] }, { @@ -465,8 +475,10 @@ "CSS Minify", "XPath expression", "JPath expression", + "Jq", "CSS selector", "PHP Deserialize", + "PHP Serialize", "Microsoft Script Decoder", "Strip HTML tags", "Diff", @@ -541,6 +553,7 @@ "Pseudo-Random Number Generator", "Generate De Bruijn Sequence", "Generate UUID", + "Analyse UUID", "Generate TOTP", "Generate HOTP", "Generate QR Code", diff --git a/src/core/lib/Base32.mjs b/src/core/lib/Base32.mjs new file mode 100644 index 00000000..92b76eca --- /dev/null +++ b/src/core/lib/Base32.mjs @@ -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=", + }, +]; + diff --git a/src/core/lib/Bech32.mjs b/src/core/lib/Bech32.mjs new file mode 100644 index 00000000..6b87a142 --- /dev/null +++ b/src/core/lib/Bech32.mjs @@ -0,0 +1,371 @@ +/** + * Pure JavaScript implementation of Bech32 and Bech32m encoding. + * + * Bech32 is defined in BIP-0173: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki + * Bech32m is defined in BIP-0350: https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki + * + * @author Medjedtxm + * @copyright Crown Copyright 2025 + * @license Apache-2.0 + */ + +import OperationError from "../errors/OperationError.mjs"; + +/** Bech32 character set (32 characters, excludes 1, b, i, o) */ +const CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; + +/** Reverse lookup table for decoding */ +const CHARSET_REV = {}; +for (let i = 0; i < CHARSET.length; i++) { + CHARSET_REV[CHARSET[i]] = i; +} + +/** Checksum constant for Bech32 (BIP-0173) */ +const BECH32_CONST = 1; + +/** Checksum constant for Bech32m (BIP-0350) */ +const BECH32M_CONST = 0x2bc830a3; + +/** Generator polynomial coefficients for checksum */ +const GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]; + +/** + * Compute the polymod checksum + * @param {number[]} values - Array of 5-bit values + * @returns {number} - Checksum value + */ +function polymod(values) { + let chk = 1; + for (const v of values) { + const top = chk >> 25; + chk = ((chk & 0x1ffffff) << 5) ^ v; + for (let i = 0; i < 5; i++) { + if ((top >> i) & 1) { + chk ^= GENERATOR[i]; + } + } + } + return chk; +} + +/** + * Expand HRP for checksum computation + * @param {string} hrp - Human-readable part (lowercase) + * @returns {number[]} - Expanded values + */ +function hrpExpand(hrp) { + const result = []; + for (let i = 0; i < hrp.length; i++) { + result.push(hrp.charCodeAt(i) >> 5); + } + result.push(0); + for (let i = 0; i < hrp.length; i++) { + result.push(hrp.charCodeAt(i) & 31); + } + return result; +} + +/** + * Verify checksum of a Bech32/Bech32m string + * @param {string} hrp - Human-readable part (lowercase) + * @param {number[]} data - Data including checksum (5-bit values) + * @param {string} encoding - "Bech32" or "Bech32m" + * @returns {boolean} - True if checksum is valid + */ +function verifyChecksum(hrp, data, encoding) { + const constant = encoding === "Bech32m" ? BECH32M_CONST : BECH32_CONST; + return polymod(hrpExpand(hrp).concat(data)) === constant; +} + +/** + * Create checksum for Bech32/Bech32m encoding + * @param {string} hrp - Human-readable part (lowercase) + * @param {number[]} data - Data values (5-bit) + * @param {string} encoding - "Bech32" or "Bech32m" + * @returns {number[]} - 6 checksum values + */ +function createChecksum(hrp, data, encoding) { + const constant = encoding === "Bech32m" ? BECH32M_CONST : BECH32_CONST; + const values = hrpExpand(hrp).concat(data).concat([0, 0, 0, 0, 0, 0]); + const mod = polymod(values) ^ constant; + const result = []; + for (let i = 0; i < 6; i++) { + result.push((mod >> (5 * (5 - i))) & 31); + } + return result; +} + +/** + * Convert 8-bit bytes to 5-bit words + * @param {number[]|Uint8Array} data - Input bytes + * @returns {number[]} - 5-bit words + */ +export function toWords(data) { + let value = 0; + let bits = 0; + const result = []; + + for (let i = 0; i < data.length; i++) { + value = (value << 8) | data[i]; + bits += 8; + + while (bits >= 5) { + bits -= 5; + result.push((value >> bits) & 31); + } + } + + // Pad remaining bits + if (bits > 0) { + result.push((value << (5 - bits)) & 31); + } + + return result; +} + +/** + * Convert 5-bit words to 8-bit bytes + * @param {number[]} words - 5-bit words + * @returns {number[]} - Output bytes + */ +export function fromWords(words) { + let value = 0; + let bits = 0; + const result = []; + + for (let i = 0; i < words.length; i++) { + value = (value << 5) | words[i]; + bits += 5; + + while (bits >= 8) { + bits -= 8; + result.push((value >> bits) & 255); + } + } + + // Check for invalid padding per BIP-0173 + // Condition 1: Cannot have 5+ bits remaining (would indicate incomplete byte) + if (bits >= 5) { + throw new OperationError("Invalid padding: too many bits remaining"); + } + // Condition 2: Remaining padding bits must all be zero + if (bits > 0) { + const paddingValue = (value << (8 - bits)) & 255; + if (paddingValue !== 0) { + throw new OperationError("Invalid padding: non-zero bits in padding"); + } + } + + return result; +} + +/** + * Encode data to Bech32/Bech32m string + * + * @param {string} hrp - Human-readable part + * @param {number[]|Uint8Array} data - Data bytes to encode + * @param {string} encoding - "Bech32" or "Bech32m" + * @param {boolean} segwit - If true, treat first byte as witness version (for Bitcoin SegWit) + * @returns {string} - Encoded Bech32/Bech32m string + */ +export function encode(hrp, data, encoding = "Bech32", segwit = false) { + // Validate HRP + if (!hrp || hrp.length === 0) { + throw new OperationError("Human-Readable Part (HRP) cannot be empty."); + } + + // Check HRP characters (ASCII 33-126) + for (let i = 0; i < hrp.length; i++) { + const c = hrp.charCodeAt(i); + if (c < 33 || c > 126) { + throw new OperationError(`HRP contains invalid character at position ${i}. Only printable ASCII characters (33-126) are allowed.`); + } + } + + // Convert HRP to lowercase + const hrpLower = hrp.toLowerCase(); + + let words; + if (segwit && data.length >= 2) { + // SegWit encoding: first byte is witness version (0-16), rest is witness program + const witnessVersion = data[0]; + if (witnessVersion > 16) { + throw new OperationError(`Invalid witness version: ${witnessVersion}. Must be 0-16.`); + } + const witnessProgram = Array.prototype.slice.call(data, 1); + + // Validate witness program length per BIP-0141 + if (witnessProgram.length < 2 || witnessProgram.length > 40) { + throw new OperationError(`Invalid witness program length: ${witnessProgram.length}. Must be 2-40 bytes.`); + } + if (witnessVersion === 0 && witnessProgram.length !== 20 && witnessProgram.length !== 32) { + throw new OperationError(`Invalid witness program length for v0: ${witnessProgram.length}. Must be 20 or 32 bytes.`); + } + + // Witness version is kept as single 5-bit value, program is converted + words = [witnessVersion].concat(toWords(witnessProgram)); + } else { + // Generic encoding: convert all bytes to 5-bit words + words = toWords(data); + } + + // Create checksum + const checksum = createChecksum(hrpLower, words, encoding); + + // Build result string + let result = hrpLower + "1"; + for (const w of words.concat(checksum)) { + result += CHARSET[w]; + } + + // Check maximum length (90 characters) + if (result.length > 90) { + throw new OperationError(`Encoded string exceeds maximum length of 90 characters (got ${result.length}). Consider using smaller input data.`); + } + + return result; +} + +/** + * Decode a Bech32/Bech32m string + * + * @param {string} str - Bech32/Bech32m encoded string + * @param {string} encoding - "Bech32", "Bech32m", or "Auto-detect" + * @returns {{hrp: string, data: number[]}} - Decoded HRP and data bytes + */ +export function decode(str, encoding = "Auto-detect") { + // Check for empty input + if (!str || str.length === 0) { + throw new OperationError("Input cannot be empty."); + } + + // Check maximum length + if (str.length > 90) { + throw new OperationError(`Invalid Bech32 string: exceeds maximum length of 90 characters (got ${str.length}).`); + } + + // Check for mixed case + const hasUpper = /[A-Z]/.test(str); + const hasLower = /[a-z]/.test(str); + if (hasUpper && hasLower) { + throw new OperationError("Invalid Bech32 string: mixed case is not allowed. Use all uppercase or all lowercase."); + } + + // Convert to lowercase for processing + str = str.toLowerCase(); + + // Find separator (last occurrence of '1') + const sepIndex = str.lastIndexOf("1"); + if (sepIndex === -1) { + throw new OperationError("Invalid Bech32 string: no separator '1' found."); + } + + if (sepIndex === 0) { + throw new OperationError("Invalid Bech32 string: Human-Readable Part (HRP) cannot be empty."); + } + + if (sepIndex + 7 > str.length) { + throw new OperationError("Invalid Bech32 string: data part is too short (minimum 6 characters for checksum)."); + } + + // Extract HRP and data part + const hrp = str.substring(0, sepIndex); + const dataPart = str.substring(sepIndex + 1); + + // Validate HRP characters + for (let i = 0; i < hrp.length; i++) { + const c = hrp.charCodeAt(i); + if (c < 33 || c > 126) { + throw new OperationError(`HRP contains invalid character at position ${i}.`); + } + } + + // Decode data characters to 5-bit values + const data = []; + for (let i = 0; i < dataPart.length; i++) { + const c = dataPart[i]; + if (CHARSET_REV[c] === undefined) { + throw new OperationError(`Invalid character '${c}' at position ${sepIndex + 1 + i}.`); + } + data.push(CHARSET_REV[c]); + } + + // Verify checksum + let usedEncoding; + if (encoding === "Bech32") { + if (!verifyChecksum(hrp, data, "Bech32")) { + throw new OperationError("Invalid Bech32 checksum."); + } + usedEncoding = "Bech32"; + } else if (encoding === "Bech32m") { + if (!verifyChecksum(hrp, data, "Bech32m")) { + throw new OperationError("Invalid Bech32m checksum."); + } + usedEncoding = "Bech32m"; + } else { + // Auto-detect: try Bech32 first, then Bech32m + if (verifyChecksum(hrp, data, "Bech32")) { + usedEncoding = "Bech32"; + } else if (verifyChecksum(hrp, data, "Bech32m")) { + usedEncoding = "Bech32m"; + } else { + throw new OperationError("Invalid Bech32/Bech32m string: checksum verification failed."); + } + } + + // Remove checksum (last 6 values) + const words = data.slice(0, data.length - 6); + + // Check if this is likely a SegWit address (Bitcoin, Litecoin, etc.) + // For SegWit, the first 5-bit word is the witness version (0-16) + // and should be extracted separately, not bit-converted with the rest + const segwitHrps = ["bc", "tb", "ltc", "tltc", "bcrt"]; + const couldBeSegWit = segwitHrps.includes(hrp) && words.length > 0 && words[0] <= 16; + + let bytes; + let witnessVersion = null; + + if (couldBeSegWit) { + // Try SegWit decode first + try { + witnessVersion = words[0]; + const programWords = words.slice(1); + const programBytes = fromWords(programWords); + + // Validate SegWit witness program length (20 or 32 bytes for v0, 2-40 for others) + const validV0 = witnessVersion === 0 && (programBytes.length === 20 || programBytes.length === 32); + const validOther = witnessVersion !== 0 && programBytes.length >= 2 && programBytes.length <= 40; + + if (validV0 || validOther) { + // Valid SegWit address + bytes = [witnessVersion, ...programBytes]; + } else { + // Not valid SegWit, fall back to generic decode + witnessVersion = null; + bytes = fromWords(words); + } + } catch (e) { + // SegWit decode failed, try generic decode + witnessVersion = null; + try { + bytes = fromWords(words); + } catch (e2) { + throw new OperationError(`Failed to decode data: ${e2.message}`); + } + } + } else { + // Generic Bech32: convert all words + try { + bytes = fromWords(words); + } catch (e) { + throw new OperationError(`Failed to decode data: ${e.message}`); + } + } + + return { + hrp: hrp, + data: bytes, + encoding: usedEncoding, + witnessVersion: witnessVersion + }; +} diff --git a/src/core/lib/JA4.mjs b/src/core/lib/JA4.mjs index f600f4d8..58422bca 100644 --- a/src/core/lib/JA4.mjs +++ b/src/core/lib/JA4.mjs @@ -91,9 +91,7 @@ export function toJA4(bytes) { let alpn = "00"; for (const ext of tlsr.handshake.value.extensions.value) { if (ext.type.value === "application_layer_protocol_negotiation") { - alpn = parseFirstALPNValue(ext.value.data); - alpn = alpn.charAt(0) + alpn.charAt(alpn.length - 1); - if (alpn.charCodeAt(0) > 127) alpn = "99"; + alpn = alpnFingerprint(parseFirstALPNValue(ext.value.data)); break; } } @@ -212,9 +210,7 @@ export function toJA4S(bytes) { let alpn = "00"; for (const ext of tlsr.handshake.value.extensions.value) { if (ext.type.value === "application_layer_protocol_negotiation") { - alpn = parseFirstALPNValue(ext.value.data); - alpn = alpn.charAt(0) + alpn.charAt(alpn.length - 1); - if (alpn.charCodeAt(0) > 127) alpn = "99"; + alpn = alpnFingerprint(parseFirstALPNValue(ext.value.data)); break; } } @@ -262,3 +258,33 @@ function tlsVersionMapper(version) { default: return "00"; // Unknown } } + +/** + * Checks if a byte is ASCII alphanumeric (0-9, A-Z, a-z). + * @param {number} byte + * @returns {boolean} + */ +function isAlphanumeric(byte) { + return (byte >= 0x30 && byte <= 0x39) || + (byte >= 0x41 && byte <= 0x5A) || + (byte >= 0x61 && byte <= 0x7A); +} + +/** + * Computes the 2-character ALPN fingerprint from raw ALPN bytes. + * If both first and last bytes are ASCII alphanumeric, returns their characters. + * Otherwise, returns first hex digit of first byte + last hex digit of last byte. + * @param {Uint8Array|null} rawBytes + * @returns {string} + */ +function alpnFingerprint(rawBytes) { + if (!rawBytes || rawBytes.length === 0) return "00"; + const firstByte = rawBytes[0]; + const lastByte = rawBytes[rawBytes.length - 1]; + if (isAlphanumeric(firstByte) && isAlphanumeric(lastByte)) { + return String.fromCharCode(firstByte) + String.fromCharCode(lastByte); + } + const firstHex = firstByte.toString(16).padStart(2, "0"); + const lastHex = lastByte.toString(16).padStart(2, "0"); + return firstHex[0] + lastHex[1]; +} diff --git a/src/core/lib/SM2.mjs b/src/core/lib/SM2.mjs new file mode 100644 index 00000000..e8156410 --- /dev/null +++ b/src/core/lib/SM2.mjs @@ -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]; + } +} diff --git a/src/core/lib/TLS.mjs b/src/core/lib/TLS.mjs index 6373bfa2..eaf661a8 100644 --- a/src/core/lib/TLS.mjs +++ b/src/core/lib/TLS.mjs @@ -863,15 +863,15 @@ export function parseHighestSupportedVersion(bytes) { } /** - * Parses the application_layer_protocol_negotiation extension and returns the first value. + * Parses the application_layer_protocol_negotiation extension and returns the first value as raw bytes. * @param {Uint8Array} bytes - * @returns {number} + * @returns {Uint8Array|null} */ export function parseFirstALPNValue(bytes) { const s = new Stream(bytes); const alpnExtLen = s.readInt(2); - if (alpnExtLen < 3) return "00"; + if (alpnExtLen < 2) return null; const strLen = s.readInt(1); - if (strLen < 2) return "00"; - return s.readString(strLen); + if (strLen < 1) return null; + return s.getBytes(strLen); } diff --git a/src/core/operations/AESDecrypt.mjs b/src/core/operations/AESDecrypt.mjs index e24a5119..5e6cec26 100644 --- a/src/core/operations/AESDecrypt.mjs +++ b/src/core/operations/AESDecrypt.mjs @@ -112,7 +112,7 @@ class AESDecrypt extends Operation { run(input, args) { const key = Utils.convertToByteString(args[0].string, args[0].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"), inputType = args[3], outputType = args[4], diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 7b52ff03..84e1c540 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -66,6 +66,14 @@ class AESEncrypt extends Operation { { name: "ECB", off: [5] + }, + { + name: "CBC/NoPadding", + off: [5] + }, + { + name: "ECB/NoPadding", + off: [5] } ] }, @@ -98,7 +106,8 @@ class AESEncrypt extends Operation { run(input, args) { const key = Utils.convertToByteString(args[0].string, args[0].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], outputType = args[4], 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); + // 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); cipher.start({ iv: iv, additionalData: mode === "GCM" ? aad : undefined }); + if (noPadding) { + cipher.mode.pad = function(output, options) { + return true; + }; + } cipher.update(forge.util.createBuffer(input)); cipher.finish(); diff --git a/src/core/operations/AlternatingCaps.mjs b/src/core/operations/AlternatingCaps.mjs new file mode 100644 index 00000000..2d54867c --- /dev/null +++ b/src/core/operations/AlternatingCaps.mjs @@ -0,0 +1,53 @@ +/** + * @author sw5678 + * @copyright Crown Copyright 2023 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; + +/** + * Alternating caps operation + */ +class AlternatingCaps extends Operation { + + /** + * AlternatingCaps constructor + */ + constructor() { + super(); + + this.name = "Alternating Caps"; + this.module = "Default"; + this.description = "Alternating caps, also known as studly caps, sticky caps, or spongecase is a form of text notation in which the capitalization of letters varies by some pattern, or arbitrarily. An example of this would be spelling 'alternative caps' as 'aLtErNaTiNg CaPs'."; + this.infoURL = "https://en.wikipedia.org/wiki/Alternating_caps"; + this.inputType = "string"; + this.outputType = "string"; + this.args= []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + let output = ""; + let previousCaps = true; + for (let i = 0; i < input.length; i++) { + // Check if the element is a letter + if (!RegExp(/^\p{L}/, "u").test(input[i])) { + output += input[i]; + } else if (previousCaps) { + output += input[i].toLowerCase(); + previousCaps = false; + } else { + output += input[i].toUpperCase(); + previousCaps = true; + } + } + return output; + } +} + +export default AlternatingCaps; diff --git a/src/core/operations/AnalyseUUID.mjs b/src/core/operations/AnalyseUUID.mjs new file mode 100644 index 00000000..b3506017 --- /dev/null +++ b/src/core/operations/AnalyseUUID.mjs @@ -0,0 +1,48 @@ +/** + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2023 + * @license Apache-2.0 + */ + +import * as uuid from "uuid"; + +import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; + +/** + * Analyse UUID operation + */ +class AnalyseUUID extends Operation { + + /** + * AnalyseUUID constructor + */ + constructor() { + super(); + + this.name = "Analyse UUID"; + this.module = "Crypto"; + this.description = "Tries to determine information about a given UUID and suggests which version may have been used to generate it"; + this.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + try { + const uuidVersion = uuid.version(input); + return "UUID version: " + uuidVersion; + } catch (error) { + throw new OperationError("Invalid UUID"); + } + } + +} + +export default AnalyseUUID; diff --git a/src/core/operations/BLAKE3.mjs b/src/core/operations/BLAKE3.mjs new file mode 100644 index 00000000..0f686120 --- /dev/null +++ b/src/core/operations/BLAKE3.mjs @@ -0,0 +1,58 @@ +/** + * @author xumptex [xumptex@outlook.fr] + * @copyright Crown Copyright 2025 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; +import { blake3 } from "hash-wasm"; +/** + * BLAKE3 operation + */ +class BLAKE3 extends Operation { + + /** + * BLAKE3 constructor + */ + constructor() { + super(); + + this.name = "BLAKE3"; + this.module = "Hashing"; + this.description = "Hashes the input using BLAKE3 (UTF-8 encoded), with an optional key (also UTF-8), and outputs the result in hexadecimal format."; + this.infoURL = "https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "Size (bytes)", + "type": "number" + }, { + "name": "Key", + "type": "string", + "value": "" + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const key = args[1]; + const size = args[0]; + // Check if the user want a key hash or not + if (key === "") { + return blake3(input, size*8); + } if (key.length !== 32) { + throw new OperationError("The key must be exactly 32 bytes long"); + } + return blake3(input, size*8, key); + } + +} + +export default BLAKE3; diff --git a/src/core/operations/CRC16Checksum.mjs b/src/core/operations/CRC16Checksum.mjs deleted file mode 100644 index 035ee04b..00000000 --- a/src/core/operations/CRC16Checksum.mjs +++ /dev/null @@ -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.

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; diff --git a/src/core/operations/CRC32Checksum.mjs b/src/core/operations/CRC32Checksum.mjs deleted file mode 100644 index cfe84643..00000000 --- a/src/core/operations/CRC32Checksum.mjs +++ /dev/null @@ -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.

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; diff --git a/src/core/operations/CRC8Checksum.mjs b/src/core/operations/CRC8Checksum.mjs deleted file mode 100644 index 193cadf9..00000000 --- a/src/core/operations/CRC8Checksum.mjs +++ /dev/null @@ -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.

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; diff --git a/src/core/operations/CRCChecksum.mjs b/src/core/operations/CRCChecksum.mjs new file mode 100644 index 00000000..88da2fa5 --- /dev/null +++ b/src/core/operations/CRCChecksum.mjs @@ -0,0 +1,1110 @@ +/** + * @author r4mos [2k95ljkhg@mozmail.com] + * @copyright Crown Copyright 2025 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; + +/** + * CRC Checksum operation + */ +class CRCChecksum extends Operation { + + /** + * CRCChecksum constructor + */ + constructor() { + super(); + + this.name = "CRC Checksum"; + this.module = "Default"; + 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."; + this.infoURL = "https://wikipedia.org/wiki/Cyclic_redundancy_check"; + this.inputType = "ArrayBuffer"; + this.outputType = "string"; + this.args = [ + { + name: "Algorithm", + type: "argSelector", + value: [ + { + name: "Custom", + on: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-3/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-3/ROHC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-4/G-704", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-4/INTERLAKEN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-4/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/EPC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/EPC-C1G2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/G-704", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-5/USB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/CDMA2000-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/CDMA2000-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/G-704", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-6/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-7/MMC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-7/ROHC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-7/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/8H2F", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/AES", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/AUTOSAR", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/BLUETOOTH", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/DVB-S2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/EBU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/GSM-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/GSM-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/HITAG", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/I-432-1", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/I-CODE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/ITU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/LTE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/MAXIM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/MAXIM-DOW", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/MIFARE-MAD", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/NRSC-5", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/OPENSAFETY", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/ROHC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/SAE-J1850", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/SAE-J1850-ZERO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/SMBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/TECH-3250", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-8/WCDMA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/ATM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-10/I-610", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-11/FLEXRAY", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-11/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/3GPP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/DECT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-12/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-13/BBC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-14/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-14/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-15/CAN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-15/MPT1327", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ACORN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/AUG-CCITT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/AUTOSAR", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/BLUETOOTH", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/BUYPASS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT-FALSE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT-TRUE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CCITT-ZERO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CDMA2000", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/CMS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DARC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DDS-110", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DECT-R", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DECT-X", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/DNP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/EN-13757", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/EPC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/EPC-C1G2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/GENIBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/I-CODE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IBM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IBM-3740", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IBM-SDLC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/IEC-61158-2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ISO-HDLC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ISO-IEC-14443-3-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ISO-IEC-14443-3-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/KERMIT", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/LHA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/LJ1200", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/LTE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/M17", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MAXIM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MAXIM-DOW", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MCRF4XX", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/MODBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/NRSC-5", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/OPENSAFETY-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/OPENSAFETY-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/PROFIBUS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/RIELLO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/SPI-FUJITSU", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/T10-DIF", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/TELEDISK", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/TMS37157", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/UMTS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/USB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/V-41-LSB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/V-41-MSB", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/VERIFONE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/X-25", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/XMODEM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-16/ZMODEM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-17/CAN-FD", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-21/CAN-FD", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/BLE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/FLEXRAY-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/FLEXRAY-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/INTERLAKEN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/LTE-A", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/LTE-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/OPENPGP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-24/OS-9", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-30/CDMA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-31/PHILIPS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/AAL5", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/ADCCP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/AIXM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/AUTOSAR", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/BASE91-C", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/BASE91-D", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/BZIP2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/C", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/CASTAGNOLI", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/CD-ROM-EDC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/CKSUM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/D", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/DECT-B", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/INTERLAKEN", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/ISCSI", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/ISO-HDLC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/JAMCRC", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/MEF", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/MPEG-2", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/NVME", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/PKZIP", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/POSIX", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/Q", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/SATA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/V-42", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/XFER", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-32/XZ", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-40/GSM", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/ECMA-182", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/GO-ECMA", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/GO-ISO", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/MS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/NVME", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/REDIS", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/WE", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-64/XZ", + off: [1, 2, 3, 4, 5, 6] + }, + { + name: "CRC-82/DARC", + off: [1, 2, 3, 4, 5, 6] + } + ] + }, + { + name: "Width (bits)", + type: "toggleString", + value: "0", + toggleValues: ["Decimal"] + }, + { + name: "Polynomial", + type: "toggleString", + value: "0", + toggleValues: ["Hex"] + }, + { + name: "Initialization", + type: "toggleString", + value: "0", + toggleValues: ["Hex"] + }, + { + name: "Reflect input", + type: "option", + value: ["True", "False"] + }, + { + name: "Reflect output", + type: "option", + value: ["True", "False"] + }, + { + name: "Xor Output", + type: "toggleString", + value: "0", + toggleValues: ["Hex"] + } + ]; + } + + /** + * Reverse the order of bits in a number + * + * @param {BigInt} data + * @param {BigInt} reflect + */ + reflectData(data, reflect) { + let value = 0n; + for (let bit = 0n; bit < reflect; bit++) { + if ((data & 1n) === 1n) { + value |= (1n << ((reflect - 1n) - bit)); + } + data >>= 1n; + } + return value; + } + + /** + * Performs the CRC Checksum calculation bit per bit without acceleration + * + * @param {BigInt} width + * @param {ArrayBuffer} input + * @param {BigInt} poly + * @param {BigInt} remainder + * @param {boolean} reflectIn + * @param {boolean} reflectOut + * @param {BigInt} xorOut + */ + calculateCrcBitPerBit(width, input, poly, remainder, reflectIn, reflectOut, xorOut) { + const TOP_BIT = 1n << (width - 1n); + const MASK = (1n << width) - 1n; + + for (let byte of input) { + byte = BigInt(byte); + if (reflectIn) { + byte = this.reflectData(byte, 8n); + } + + for (let i = 0x80n; i !== 0n; i >>= 1n) { + let bit = remainder & TOP_BIT; + + remainder = (remainder << 1n) & MASK; + + if ((byte & i) !== 0n) { + bit ^= TOP_BIT; + } + + if (bit !== 0n) { + remainder ^= poly; + } + } + } + + if (reflectOut) { + remainder = this.reflectData(remainder, width); + } + + return remainder ^ xorOut; + } + + /** + * Generates the necessary table to speed up the calculation + * + * @param {BigInt} width + * @param {BigInt} poly + * @param {BigInt} MASK + * @param {BigInt} TOP_BIT + */ + generateTable(width, poly, MASK, TOP_BIT) { + const table = new Array(256n); + for (let byte = 0n; byte < 256n; byte++) { + let value = ((byte << width - 8n) & MASK); + for (let bit = 0n; bit < 8n; bit++) { + value = (value & TOP_BIT) === 0n ? + ((value << 1n) & MASK) : + ((value << 1n) & MASK) ^ poly; + } + table[byte] = value; + } + return table; + } + + /** + * Performs the CRC Checksum calculation byte per byte using a computed table to accelerate it + * + * @param {BigInt} width + * @param {ArrayBuffer} input + * @param {BigInt} poly + * @param {BigInt} remainder + * @param {boolean} reflectIn + * @param {boolean} reflectOut + * @param {BigInt} xorOut + */ + calculateCrcBytePerByte(width, input, poly, remainder, reflectIn, reflectOut, xorOut) { + const TOP_BIT = 1n << (width - 1n); + const MASK = (1n << width) - 1n; + const TABLE = this.generateTable(width, poly, MASK, TOP_BIT); + + for (let byte of input) { + byte = BigInt(byte); + if (reflectIn) { + byte = this.reflectData(byte, 8n); + } + remainder ^= (byte << width - 8n) & MASK; + + const INDEX = remainder >> width - 8n; + remainder = (remainder << 8n) & MASK; + remainder ^= TABLE[INDEX]; + } + + if (reflectOut) { + remainder = this.reflectData(remainder, width); + } + return remainder ^ xorOut; + } + + /** + * Calculates the CRC Checksum using Bigint (https://developer.mozilla.org/en-US/docs/Glossary/BigInt) + * + * @param {BigInt} width + * @param {ArrayBuffer} input + * @param {BigInt} poly + * @param {BigInt} init + * @param {boolean} reflectIn + * @param {boolean} reflectOut + * @param {BigInt} xorOut + */ + crc(width, input, poly, init, reflectIn, reflectOut, xorOut) { + const VALUE = width < 8n ? + this.calculateCrcBitPerBit(width, input, poly, init, reflectIn, reflectOut, xorOut) : + this.calculateCrcBytePerByte(width, input, poly, init, reflectIn, reflectOut, xorOut); + + return VALUE.toString(16).padStart(Math.ceil(Number(width) / 4), "0"); + } + + /** + * Validates user input to perform a custom CRC + * + * @param {Object} widthObject + * @param {ArrayBuffer} input + * @param {Object} polyObject + * @param {Object} initObject + * @param {Object} reflectInObject + * @param {Object} reflectOutObject + * @param {Object} xorOutObject + */ + custom(widthObject, input, polyObject, initObject, reflectInObject, reflectOutObject, xorOutObject) { + try { + const width = BigInt(widthObject.string); + const poly = BigInt("0x" + polyObject.string); + const init = BigInt("0x" + initObject.string); + const reflectIn = reflectInObject === "True"; + const reflectOut = reflectOutObject === "True"; + const xorOut = BigInt("0x" + xorOutObject.string); + + return this.crc(width, input, poly, init, reflectIn, reflectOut, xorOut); + } catch (error) { + throw new OperationError("Invalid custom CRC arguments"); + } + } + + /** + * Calculation of all known CRCs. Names and constants extracted from https://reveng.sourceforge.io/crc-catalogue/all.htm + * + * @param {ArrayBuffer} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const algorithm = args[0]; + input = new Uint8Array(input); + + switch (algorithm) { + case "Custom": return this.custom(args[1], input, args[2], args[3], args[4], args[5], args[6]); + case "CRC-3/GSM": return this.crc(3n, input, 0x3n, 0x0n, false, false, 0x7n); + case "CRC-3/ROHC": return this.crc(3n, input, 0x3n, 0x7n, true, true, 0x0n); + case "CRC-4/G-704": return this.crc(4n, input, 0x3n, 0x0n, true, true, 0x0n); + case "CRC-4/INTERLAKEN": return this.crc(4n, input, 0x3n, 0xFn, false, false, 0xFn); + case "CRC-4/ITU": return this.crc(4n, input, 0x3n, 0x0n, true, true, 0x0n); + case "CRC-5/EPC": return this.crc(5n, input, 0x09n, 0x09n, false, false, 0x00n); + case "CRC-5/EPC-C1G2": return this.crc(5n, input, 0x09n, 0x09n, false, false, 0x00n); + case "CRC-5/G-704": return this.crc(5n, input, 0x15n, 0x00n, true, true, 0x00n); + case "CRC-5/ITU": return this.crc(5n, input, 0x15n, 0x00n, true, true, 0x00n); + case "CRC-5/USB": return this.crc(5n, input, 0x05n, 0x1Fn, true, true, 0x1Fn); + case "CRC-6/CDMA2000-A": return this.crc(6n, input, 0x27n, 0x3Fn, false, false, 0x00n); + case "CRC-6/CDMA2000-B": return this.crc(6n, input, 0x07n, 0x3Fn, false, false, 0x00n); + case "CRC-6/DARC": return this.crc(6n, input, 0x19n, 0x00n, true, true, 0x00n); + case "CRC-6/G-704": return this.crc(6n, input, 0x03n, 0x00n, true, true, 0x00n); + case "CRC-6/GSM": return this.crc(6n, input, 0x2Fn, 0x00n, false, false, 0x3Fn); + case "CRC-6/ITU": return this.crc(6n, input, 0x03n, 0x00n, true, true, 0x00n); + case "CRC-7/MMC": return this.crc(7n, input, 0x09n, 0x00n, false, false, 0x00n); + case "CRC-7/ROHC": return this.crc(7n, input, 0x4Fn, 0x7Fn, true, true, 0x00n); + case "CRC-7/UMTS": return this.crc(7n, input, 0x45n, 0x00n, false, false, 0x00n); + case "CRC-8": return this.crc(8n, input, 0x07n, 0x00n, false, false, 0x00n); + case "CRC-8/8H2F": return this.crc(8n, input, 0x2Fn, 0xFFn, false, false, 0xFFn); + case "CRC-8/AES": return this.crc(8n, input, 0x1Dn, 0xFFn, true, true, 0x00n); + case "CRC-8/AUTOSAR": return this.crc(8n, input, 0x2Fn, 0xFFn, false, false, 0xFFn); + case "CRC-8/BLUETOOTH": return this.crc(8n, input, 0xA7n, 0x00n, true, true, 0x00n); + case "CRC-8/CDMA2000": return this.crc(8n, input, 0x9Bn, 0xFFn, false, false, 0x00n); + case "CRC-8/DARC": return this.crc(8n, input, 0x39n, 0x00n, true, true, 0x00n); + case "CRC-8/DVB-S2": return this.crc(8n, input, 0xD5n, 0x00n, false, false, 0x00n); + case "CRC-8/EBU": return this.crc(8n, input, 0x1Dn, 0xFFn, true, true, 0x00n); + case "CRC-8/GSM-A": return this.crc(8n, input, 0x1Dn, 0x00n, false, false, 0x00n); + case "CRC-8/GSM-B": return this.crc(8n, input, 0x49n, 0x00n, false, false, 0xFFn); + case "CRC-8/HITAG": return this.crc(8n, input, 0x1Dn, 0xFFn, false, false, 0x00n); + case "CRC-8/I-432-1": return this.crc(8n, input, 0x07n, 0x00n, false, false, 0x55n); + case "CRC-8/I-CODE": return this.crc(8n, input, 0x1Dn, 0xFDn, false, false, 0x00n); + case "CRC-8/ITU": return this.crc(8n, input, 0x07n, 0x00n, false, false, 0x55n); + case "CRC-8/LTE": return this.crc(8n, input, 0x9Bn, 0x00n, false, false, 0x00n); + case "CRC-8/MAXIM": return this.crc(8n, input, 0x31n, 0x00n, true, true, 0x00n); + case "CRC-8/MAXIM-DOW": return this.crc(8n, input, 0x31n, 0x00n, true, true, 0x00n); + case "CRC-8/MIFARE-MAD": return this.crc(8n, input, 0x1Dn, 0xC7n, false, false, 0x00n); + case "CRC-8/NRSC-5": return this.crc(8n, input, 0x31n, 0xFFn, false, false, 0x00n); + case "CRC-8/OPENSAFETY": return this.crc(8n, input, 0x2Fn, 0x00n, false, false, 0x00n); + case "CRC-8/ROHC": return this.crc(8n, input, 0x07n, 0xFFn, true, true, 0x00n); + case "CRC-8/SAE-J1850": return this.crc(8n, input, 0x1Dn, 0xFFn, false, false, 0xFFn); + case "CRC-8/SAE-J1850-ZERO": return this.crc(8n, input, 0x1Dn, 0x00n, false, false, 0x00n); + case "CRC-8/SMBUS": return this.crc(8n, input, 0x07n, 0x00n, false, false, 0x00n); + case "CRC-8/TECH-3250": return this.crc(8n, input, 0x1Dn, 0xFFn, true, true, 0x00n); + case "CRC-8/WCDMA": return this.crc(8n, input, 0x9Bn, 0x00n, true, true, 0x00n); + case "CRC-10/ATM": return this.crc(10n, input, 0x233n, 0x000n, false, false, 0x000n); + case "CRC-10/CDMA2000": return this.crc(10n, input, 0x3D9n, 0x3FFn, false, false, 0x000n); + case "CRC-10/GSM": return this.crc(10n, input, 0x175n, 0x000n, false, false, 0x3FFn); + case "CRC-10/I-610": return this.crc(10n, input, 0x233n, 0x000n, false, false, 0x000n); + case "CRC-11/FLEXRAY": return this.crc(11n, input, 0x385n, 0x01An, false, false, 0x000n); + case "CRC-11/UMTS": return this.crc(11n, input, 0x307n, 0x000n, false, false, 0x000n); + case "CRC-12/3GPP": return this.crc(12n, input, 0x80Fn, 0x000n, false, true, 0x000n); + case "CRC-12/CDMA2000": return this.crc(12n, input, 0xF13n, 0xFFFn, false, false, 0x000n); + case "CRC-12/DECT": return this.crc(12n, input, 0x80Fn, 0x000n, false, false, 0x000n); + case "CRC-12/GSM": return this.crc(12n, input, 0xD31n, 0x000n, false, false, 0xFFFn); + case "CRC-12/UMTS": return this.crc(12n, input, 0x80Fn, 0x000n, false, true, 0x000n); + case "CRC-13/BBC": return this.crc(13n, input, 0x1CF5n, 0x0000n, false, false, 0x0000n); + case "CRC-14/DARC": return this.crc(14n, input, 0x0805n, 0x0000n, true, true, 0x0000n); + case "CRC-14/GSM": return this.crc(14n, input, 0x202Dn, 0x0000n, false, false, 0x3FFFn); + case "CRC-15/CAN": return this.crc(15n, input, 0x4599n, 0x0000n, false, false, 0x0000n); + case "CRC-15/MPT1327": return this.crc(15n, input, 0x6815n, 0x0000n, false, false, 0x0001n); + case "CRC-16": return this.crc(16n, input, 0x8005n, 0x0000n, true, true, 0x0000n); + case "CRC-16/A": return this.crc(16n, input, 0x1021n, 0xC6C6n, true, true, 0x0000n); + case "CRC-16/ACORN": return this.crc(16n, input, 0x1021n, 0x0000n, false, false, 0x0000n); + case "CRC-16/ARC": return this.crc(16n, input, 0x8005n, 0x0000n, true, true, 0x0000n); + case "CRC-16/AUG-CCITT": return this.crc(16n, input, 0x1021n, 0x1D0Fn, false, false, 0x0000n); + case "CRC-16/AUTOSAR": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0x0000n); + case "CRC-16/B": return this.crc(16n, input, 0x1021n, 0xFFFFn, true, true, 0xFFFFn); + case "CRC-16/BLUETOOTH": return this.crc(16n, input, 0x1021n, 0x0000n, true, true, 0x0000n); + case "CRC-16/BUYPASS": return this.crc(16n, input, 0x8005n, 0x0000n, false, false, 0x0000n); + case "CRC-16/CCITT": return this.crc(16n, input, 0x1021n, 0x0000n, true, true, 0x0000n); + case "CRC-16/CCITT-FALSE": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0x0000n); + case "CRC-16/CCITT-TRUE": return this.crc(16n, input, 0x1021n, 0x0000n, true, true, 0x0000n); + case "CRC-16/CCITT-ZERO": return this.crc(16n, input, 0x1021n, 0x0000n, false, false, 0x0000n); + case "CRC-16/CDMA2000": return this.crc(16n, input, 0xC867n, 0xFFFFn, false, false, 0x0000n); + case "CRC-16/CMS": return this.crc(16n, input, 0x8005n, 0xFFFFn, false, false, 0x0000n); + case "CRC-16/DARC": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0xFFFFn); + case "CRC-16/DDS-110": return this.crc(16n, input, 0x8005n, 0x800Dn, false, false, 0x0000n); + case "CRC-16/DECT-R": return this.crc(16n, input, 0x0589n, 0x0000n, false, false, 0x0001n); + case "CRC-16/DECT-X": return this.crc(16n, input, 0x0589n, 0x0000n, false, false, 0x0000n); + case "CRC-16/DNP": return this.crc(16n, input, 0x3D65n, 0x0000n, true, true, 0xFFFFn); + case "CRC-16/EN-13757": return this.crc(16n, input, 0x3D65n, 0x0000n, false, false, 0xFFFFn); + case "CRC-16/EPC": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0xFFFFn); + case "CRC-16/EPC-C1G2": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0xFFFFn); + case "CRC-16/GENIBUS": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0xFFFFn); + case "CRC-16/GSM": return this.crc(16n, input, 0x1021n, 0x0000n, false, false, 0xFFFFn); + case "CRC-16/I-CODE": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0xFFFFn); + case "CRC-16/IBM": return this.crc(16n, input, 0x8005n, 0x0000n, true, true, 0x0000n); + case "CRC-16/IBM-3740": return this.crc(16n, input, 0x1021n, 0xFFFFn, false, false, 0x0000n); + case "CRC-16/IBM-SDLC": return this.crc(16n, input, 0x1021n, 0xFFFFn, true, true, 0xFFFFn); + case "CRC-16/IEC-61158-2": return this.crc(16n, input, 0x1DCFn, 0xFFFFn, false, false, 0xFFFFn); + case "CRC-16/ISO-HDLC": return this.crc(16n, input, 0x1021n, 0xFFFFn, true, true, 0xFFFFn); + case "CRC-16/ISO-IEC-14443-3-A": return this.crc(16n, input, 0x1021n, 0xC6C6n, true, true, 0x0000n); + case "CRC-16/ISO-IEC-14443-3-B": return this.crc(16n, input, 0x1021n, 0xFFFFn, true, true, 0xFFFFn); + case "CRC-16/KERMIT": return this.crc(16n, input, 0x1021n, 0x0000n, true, true, 0x0000n); + case "CRC-16/LHA": return this.crc(16n, input, 0x8005n, 0x0000n, true, true, 0x0000n); + case "CRC-16/LJ1200": return this.crc(16n, input, 0x6F63n, 0x0000n, false, false, 0x0000n); + case "CRC-16/LTE": return this.crc(16n, input, 0x1021n, 0x0000n, false, false, 0x0000n); + case "CRC-16/M17": return this.crc(16n, input, 0x5935n, 0xFFFFn, false, false, 0x0000n); + case "CRC-16/MAXIM": return this.crc(16n, input, 0x8005n, 0x0000n, true, true, 0xFFFFn); + case "CRC-16/MAXIM-DOW": return this.crc(16n, input, 0x8005n, 0x0000n, true, true, 0xFFFFn); + case "CRC-16/MCRF4XX": return this.crc(16n, input, 0x1021n, 0xFFFFn, true, true, 0x0000n); + case "CRC-16/MODBUS": return this.crc(16n, input, 0x8005n, 0xFFFFn, true, true, 0x0000n); + case "CRC-16/NRSC-5": return this.crc(16n, input, 0x080Bn, 0xFFFFn, true, true, 0x0000n); + case "CRC-16/OPENSAFETY-A": return this.crc(16n, input, 0x5935n, 0x0000n, false, false, 0x0000n); + case "CRC-16/OPENSAFETY-B": return this.crc(16n, input, 0x755Bn, 0x0000n, false, false, 0x0000n); + case "CRC-16/PROFIBUS": return this.crc(16n, input, 0x1DCFn, 0xFFFFn, false, false, 0xFFFFn); + case "CRC-16/RIELLO": return this.crc(16n, input, 0x1021n, 0xB2AAn, true, true, 0x0000n); + case "CRC-16/SPI-FUJITSU": return this.crc(16n, input, 0x1021n, 0x1D0Fn, false, false, 0x0000n); + case "CRC-16/T10-DIF": return this.crc(16n, input, 0x8BB7n, 0x0000n, false, false, 0x0000n); + case "CRC-16/TELEDISK": return this.crc(16n, input, 0xA097n, 0x0000n, false, false, 0x0000n); + case "CRC-16/TMS37157": return this.crc(16n, input, 0x1021n, 0x89ECn, true, true, 0x0000n); + case "CRC-16/UMTS": return this.crc(16n, input, 0x8005n, 0x0000n, false, false, 0x0000n); + case "CRC-16/USB": return this.crc(16n, input, 0x8005n, 0xFFFFn, true, true, 0xFFFFn); + case "CRC-16/V-41-LSB": return this.crc(16n, input, 0x1021n, 0x0000n, true, true, 0x0000n); + case "CRC-16/V-41-MSB": return this.crc(16n, input, 0x1021n, 0x0000n, false, false, 0x0000n); + case "CRC-16/VERIFONE": return this.crc(16n, input, 0x8005n, 0x0000n, false, false, 0x0000n); + case "CRC-16/X-25": return this.crc(16n, input, 0x1021n, 0xFFFFn, true, true, 0xFFFFn); + case "CRC-16/XMODEM": return this.crc(16n, input, 0x1021n, 0x0000n, false, false, 0x0000n); + case "CRC-16/ZMODEM": return this.crc(16n, input, 0x1021n, 0x0000n, false, false, 0x0000n); + case "CRC-17/CAN-FD": return this.crc(17n, input, 0x1685Bn, 0x00000n, false, false, 0x00000n); + case "CRC-21/CAN-FD": return this.crc(21n, input, 0x102899n, 0x000000n, false, false, 0x000000n); + case "CRC-24/BLE": return this.crc(24n, input, 0x00065Bn, 0x555555n, true, true, 0x000000n); + case "CRC-24/FLEXRAY-A": return this.crc(24n, input, 0x5D6DCBn, 0xFEDCBAn, false, false, 0x000000n); + case "CRC-24/FLEXRAY-B": return this.crc(24n, input, 0x5D6DCBn, 0xABCDEFn, false, false, 0x000000n); + case "CRC-24/INTERLAKEN": return this.crc(24n, input, 0x328B63n, 0xFFFFFFn, false, false, 0xFFFFFFn); + case "CRC-24/LTE-A": return this.crc(24n, input, 0x864CFBn, 0x000000n, false, false, 0x000000n); + case "CRC-24/LTE-B": return this.crc(24n, input, 0x800063n, 0x000000n, false, false, 0x000000n); + case "CRC-24/OPENPGP": return this.crc(24n, input, 0x864CFBn, 0xB704CEn, false, false, 0x000000n); + case "CRC-24/OS-9": return this.crc(24n, input, 0x800063n, 0xFFFFFFn, false, false, 0xFFFFFFn); + case "CRC-30/CDMA": return this.crc(30n, input, 0x2030B9C7n, 0x3FFFFFFFn, false, false, 0x3FFFFFFFn); + case "CRC-31/PHILIPS": return this.crc(31n, input, 0x04C11DB7n, 0x7FFFFFFFn, false, false, 0x7FFFFFFFn); + case "CRC-32": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/AAL5": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, false, false, 0xFFFFFFFFn); + case "CRC-32/ADCCP": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/AIXM": return this.crc(32n, input, 0x814141ABn, 0x00000000n, false, false, 0x00000000n); + case "CRC-32/AUTOSAR": return this.crc(32n, input, 0xF4ACFB13n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/BASE91-C": return this.crc(32n, input, 0x1EDC6F41n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/BASE91-D": return this.crc(32n, input, 0xA833982Bn, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/BZIP2": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, false, false, 0xFFFFFFFFn); + case "CRC-32/C": return this.crc(32n, input, 0x1EDC6F41n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/CASTAGNOLI": return this.crc(32n, input, 0x1EDC6F41n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/CD-ROM-EDC": return this.crc(32n, input, 0x8001801Bn, 0x00000000n, true, true, 0x00000000n); + case "CRC-32/CKSUM": return this.crc(32n, input, 0x04C11DB7n, 0x00000000n, false, false, 0xFFFFFFFFn); + case "CRC-32/D": return this.crc(32n, input, 0xA833982Bn, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/DECT-B": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, false, false, 0xFFFFFFFFn); + case "CRC-32/INTERLAKEN": return this.crc(32n, input, 0x1EDC6F41n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/ISCSI": return this.crc(32n, input, 0x1EDC6F41n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/ISO-HDLC": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/JAMCRC": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, true, true, 0x00000000n); + case "CRC-32/MEF": return this.crc(32n, input, 0x741B8CD7n, 0xFFFFFFFFn, true, true, 0x00000000n); + case "CRC-32/MPEG-2": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, false, false, 0x00000000n); + case "CRC-32/NVME": return this.crc(32n, input, 0x1EDC6F41n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/PKZIP": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/POSIX": return this.crc(32n, input, 0x04C11DB7n, 0x00000000n, false, false, 0xFFFFFFFFn); + case "CRC-32/Q": return this.crc(32n, input, 0x814141ABn, 0x00000000n, false, false, 0x00000000n); + case "CRC-32/SATA": return this.crc(32n, input, 0x04C11DB7n, 0x52325032n, false, false, 0x00000000n); + case "CRC-32/V-42": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-32/XFER": return this.crc(32n, input, 0x000000AFn, 0x00000000n, false, false, 0x00000000n); + case "CRC-32/XZ": return this.crc(32n, input, 0x04C11DB7n, 0xFFFFFFFFn, true, true, 0xFFFFFFFFn); + case "CRC-40/GSM": return this.crc(40n, input, 0x0004820009n, 0x0000000000n, false, false, 0xFFFFFFFFFFn); + case "CRC-64/ECMA-182": return this.crc(64n, input, 0x42F0E1EBA9EA3693n, 0x0000000000000000n, false, false, 0x0000000000000000n); + case "CRC-64/GO-ECMA": return this.crc(64n, input, 0x42F0E1EBA9EA3693n, 0xFFFFFFFFFFFFFFFFn, true, true, 0xFFFFFFFFFFFFFFFFn); + case "CRC-64/GO-ISO": return this.crc(64n, input, 0x000000000000001Bn, 0xFFFFFFFFFFFFFFFFn, true, true, 0xFFFFFFFFFFFFFFFFn); + case "CRC-64/MS": return this.crc(64n, input, 0x259C84CBA6426349n, 0xFFFFFFFFFFFFFFFFn, true, true, 0x0000000000000000n); + case "CRC-64/NVME": return this.crc(64n, input, 0xAD93D23594C93659n, 0xFFFFFFFFFFFFFFFFn, true, true, 0xFFFFFFFFFFFFFFFFn); + case "CRC-64/REDIS": return this.crc(64n, input, 0xAD93D23594C935A9n, 0x0000000000000000n, true, true, 0x0000000000000000n); + case "CRC-64/WE": return this.crc(64n, input, 0x42F0E1EBA9EA3693n, 0xFFFFFFFFFFFFFFFFn, false, false, 0xFFFFFFFFFFFFFFFFn); + case "CRC-64/XZ": return this.crc(64n, input, 0x42F0E1EBA9EA3693n, 0xFFFFFFFFFFFFFFFFn, true, true, 0xFFFFFFFFFFFFFFFFn); + case "CRC-82/DARC": return this.crc(82n, input, 0x0308C0111011401440411n, 0x000000000000000000000n, true, true, 0x000000000000000000000n); + default: throw new OperationError("Unknown checksum algorithm"); + } + } + +} + +export default CRCChecksum; diff --git a/src/core/operations/ConvertLeetSpeak.mjs b/src/core/operations/ConvertLeetSpeak.mjs index 54fa62f6..1a7cb2fc 100644 --- a/src/core/operations/ConvertLeetSpeak.mjs +++ b/src/core/operations/ConvertLeetSpeak.mjs @@ -18,7 +18,7 @@ class ConvertLeetSpeak extends Operation { this.name = "Convert Leet Speak"; this.module = "Default"; - this.description = "Converts to and from Leet Speak"; + this.description = "Converts to and from Leet Speak."; this.infoURL = "https://wikipedia.org/wiki/Leet"; this.inputType = "string"; this.outputType = "string"; @@ -39,13 +39,16 @@ class ConvertLeetSpeak extends Operation { */ run(input, args) { const direction = args[0]; + if (direction === "To Leet Speak") { - return input.replace(/[abcdefghijklmnopqrstuvwxyz]/gi, char => { - return toLeetMap[char.toLowerCase()] || char; + 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]/g, char => { - return fromLeetMap[char] || char; + return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/gi, char => { + const normalChar = fromLeetMap[char] || char; + return normalChar; }); } } diff --git a/src/core/operations/ECDSAVerify.mjs b/src/core/operations/ECDSAVerify.mjs index 7e46e867..1f8a53ea 100644 --- a/src/core/operations/ECDSAVerify.mjs +++ b/src/core/operations/ECDSAVerify.mjs @@ -9,6 +9,7 @@ import OperationError from "../errors/OperationError.mjs"; import { fromBase64 } from "../lib/Base64.mjs"; import { toHexFast } from "../lib/Hex.mjs"; import r from "jsrsasign"; +import Utils from "../Utils.mjs"; /** * ECDSA Verify operation @@ -59,6 +60,11 @@ class ECDSAVerify extends Operation { name: "Message", type: "text", value: "" + }, + { + name: "Message format", + type: "option", + value: ["Raw", "Hex", "Base64"] } ]; } @@ -70,7 +76,7 @@ class ECDSAVerify extends Operation { */ run(input, args) { let inputFormat = args[0]; - const [, mdAlgo, keyPem, msg] = args; + const [, mdAlgo, keyPem, msg, msgFormat] = args; if (keyPem.replace("-----BEGIN PUBLIC KEY-----", "").length === 0) { throw new OperationError("Please enter a public key."); @@ -145,7 +151,8 @@ class ECDSAVerify extends Operation { throw new OperationError("Provided key is not a public key."); } sig.init(key); - sig.updateString(msg); + const messageStr = Utils.convertToByteString(msg, msgFormat); + sig.updateString(messageStr); const result = sig.verify(signatureASN1Hex); return result ? "Verified OK" : "Verification Failure"; } diff --git a/src/core/operations/ExtractEmailAddresses.mjs b/src/core/operations/ExtractEmailAddresses.mjs index f50e1aaf..34b838ab 100644 --- a/src/core/operations/ExtractEmailAddresses.mjs +++ b/src/core/operations/ExtractEmailAddresses.mjs @@ -51,7 +51,7 @@ class ExtractEmailAddresses extends Operation { run(input, args) { const [displayTotal, sort, unique] = args, // email regex from: https://www.regextester.com/98066 - regex = /(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?\.)+[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}\])/ig; + regex = /(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?\.)+[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\])/ig; const results = search( input, diff --git a/src/core/operations/ExtractIPAddresses.mjs b/src/core/operations/ExtractIPAddresses.mjs index 97b52478..b74ec8fe 100644 --- a/src/core/operations/ExtractIPAddresses.mjs +++ b/src/core/operations/ExtractIPAddresses.mjs @@ -21,7 +21,7 @@ class ExtractIPAddresses extends Operation { this.name = "Extract IP addresses"; this.module = "Regex"; - this.description = "Extracts all IPv4 and IPv6 addresses.

Warning: Given a string 710.65.0.456, this will match 10.65.0.45 so always check the original input!"; + this.description = "Extracts all IPv4 and IPv6 addresses.

Warning: Given a string 1.2.3.4.5.6.7.8, this will match 1.2.3.4 and 5.6.7.8 so always check the original input!"; this.inputType = "string"; this.outputType = "string"; this.args = [ @@ -65,7 +65,21 @@ class ExtractIPAddresses extends Operation { */ run(input, args) { const [includeIpv4, includeIpv6, removeLocal, displayTotal, sort, unique] = args, - ipv4 = "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?", + + // IPv4 decimal groups can have values 0 to 255. To construct a regex the following sub-regex is reused: + ipv4DecimalByte = "(?:25[0-5]|2[0-4]\\d|1?[0-9]\\d|\\d)", + ipv4OctalByte = "(?:0[1-3]?[0-7]{1,2})", + + // Look behind and ahead will be used to exclude matches with additional decimal digits left and right of IP address + lookBehind = "(?
Bech32m (BIP-0350) is an updated version used for Bitcoin Taproot addresses.

Auto-detect will attempt Bech32 first, then Bech32m if the checksum fails.

Output format options allow you to see the Human-Readable Part (HRP) along with the decoded data."; + this.infoURL = "https://wikipedia.org/wiki/Bech32"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "Encoding", + "type": "option", + "value": ["Auto-detect", "Bech32", "Bech32m"] + }, + { + "name": "Output Format", + "type": "option", + "value": ["Raw", "Hex", "Bitcoin scriptPubKey", "HRP: Hex", "JSON"] + } + ]; + this.checks = [ + { + // Bitcoin mainnet SegWit/Taproot addresses + pattern: "^bc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,87}$", + flags: "i", + args: ["Auto-detect", "Hex"] + }, + { + // Bitcoin testnet addresses + pattern: "^tb1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,87}$", + flags: "i", + args: ["Auto-detect", "Hex"] + }, + { + // AGE public keys + pattern: "^age1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,87}$", + flags: "i", + args: ["Auto-detect", "HRP: Hex"] + }, + { + // AGE secret keys + pattern: "^AGE-SECRET-KEY-1[QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L]{6,87}$", + flags: "", + args: ["Auto-detect", "HRP: Hex"] + }, + { + // Litecoin mainnet addresses + pattern: "^ltc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,87}$", + flags: "i", + args: ["Auto-detect", "Hex"] + }, + { + // Generic bech32 pattern + pattern: "^[a-z]{1,83}1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,}$", + flags: "i", + args: ["Auto-detect", "Hex"] + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const encoding = args[0]; + const outputFormat = args[1]; + + input = input.trim(); + + if (input.length === 0) { + return ""; + } + + const decoded = decode(input, encoding); + + // Format output based on selected option + switch (outputFormat) { + case "Raw": + return decoded.data.map(b => String.fromCharCode(b)).join(""); + + case "Hex": + return toHex(decoded.data, ""); + + case "Bitcoin scriptPubKey": { + // Convert to Bitcoin scriptPubKey format as shown in BIP-0173/BIP-0350 + // Format: [OP_version][length][witness_program] + // OP_0 = 0x00, OP_1-OP_16 = 0x51-0x60 + if (decoded.witnessVersion === null || decoded.data.length < 2) { + // Not a SegWit address, fall back to hex + return toHex(decoded.data, ""); + } + const witnessVersion = decoded.data[0]; + const witnessProgram = decoded.data.slice(1); + + // Convert witness version to OP code + let opCode; + if (witnessVersion === 0) { + opCode = 0x00; // OP_0 + } else if (witnessVersion >= 1 && witnessVersion <= 16) { + opCode = 0x50 + witnessVersion; // OP_1 = 0x51, ..., OP_16 = 0x60 + } else { + // Invalid witness version, fall back to hex + return toHex(decoded.data, ""); + } + + // Build scriptPubKey: [OP_version][length][program] + const scriptPubKey = [opCode, witnessProgram.length, ...witnessProgram]; + return toHex(scriptPubKey, ""); + } + + case "HRP: Hex": + return `${decoded.hrp}: ${toHex(decoded.data, "")}`; + + case "JSON": + return JSON.stringify({ + hrp: decoded.hrp, + encoding: decoded.encoding, + data: toHex(decoded.data, "") + }, null, 2); + + default: + return toHex(decoded.data, ""); + } + } + +} + +export default FromBech32; diff --git a/src/core/operations/FromHexdump.mjs b/src/core/operations/FromHexdump.mjs index e8c25441..6fd3c1dc 100644 --- a/src/core/operations/FromHexdump.mjs +++ b/src/core/operations/FromHexdump.mjs @@ -43,7 +43,7 @@ class FromHexdump extends Operation { */ run(input, args) { const output = [], - regex = /^\s*(?:[\dA-F]{4,16}h?:?)?[ \t]+((?:[\dA-F]{2} ){1,8}(?:[ \t]|[\dA-F]{2}-)(?:[\dA-F]{2} ){1,8}|(?:[\dA-F]{4} )*[\dA-F]{4}|(?:[\dA-F]{2} )*[\dA-F]{2})/igm; + regex = /^\s*(?:[\dA-F]{4,16}h?:?)?[ \t]+((?:[\dA-F]{2} ){1,8}(?:[ \t]|[\dA-F]{2}-)(?:[\dA-F]{2} ){1,8}|(?:[\dA-F]{4} )+(?:[\dA-F]{2})?|(?:[\dA-F]{2} )*[\dA-F]{2})/igm; let block, line; while ((block = regex.exec(input))) { diff --git a/src/core/operations/GenerateAllChecksums.mjs b/src/core/operations/GenerateAllChecksums.mjs new file mode 100644 index 00000000..b5a3d152 --- /dev/null +++ b/src/core/operations/GenerateAllChecksums.mjs @@ -0,0 +1,254 @@ +/** + * @author r4mos [2k95ljkhg@mozmail.com] + * @copyright Crown Copyright 2025 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; +import Adler32Checksum from "./Adler32Checksum.mjs"; +import CRCChecksum from "./CRCChecksum.mjs"; +import Fletcher8Checksum from "./Fletcher8Checksum.mjs"; +import Fletcher16Checksum from "./Fletcher16Checksum.mjs"; +import Fletcher32Checksum from "./Fletcher32Checksum.mjs"; +import Fletcher64Checksum from "./Fletcher64Checksum.mjs"; + +/** + * Generate all checksums operation + */ +class GenerateAllChecksums extends Operation { + + /** + * GenerateAllChecksums constructor + */ + constructor() { + super(); + + this.name = "Generate all checksums"; + this.module = "Crypto"; + this.description = "Generates all available checksums for the input."; + this.infoURL = "https://wikipedia.org/wiki/Checksum"; + this.inputType = "ArrayBuffer"; + this.outputType = "string"; + this.args = [ + { + name: "Length (bits)", + type: "option", + value: [ + "All", "3", "4", "5", "6", "7", "8", "10", "11", "12", "13", "14", "15", "16", "17", "21", "24", "30", "31", "32", "40", "64", "82" + ] + }, + { + name: "Include names", + type: "boolean", + value: true + }, + ]; + + const adler32 = new Adler32Checksum; + const crc = new CRCChecksum; + const fletcher8 = new Fletcher8Checksum; + const fletcher16 = new Fletcher16Checksum; + const fletcher32 = new Fletcher32Checksum; + const fletcher64 = new Fletcher64Checksum; + this.checksums = [ + {name: "CRC-3/GSM", algo: crc, params: ["CRC-3/GSM"]}, + {name: "CRC-3/ROHC", algo: crc, params: ["CRC-3/ROHC"]}, + {name: "CRC-4/G-704", algo: crc, params: ["CRC-4/G-704"]}, + {name: "CRC-4/INTERLAKEN", algo: crc, params: ["CRC-4/INTERLAKEN"]}, + {name: "CRC-4/ITU", algo: crc, params: ["CRC-4/ITU"]}, + {name: "CRC-5/EPC", algo: crc, params: ["CRC-5/EPC"]}, + {name: "CRC-5/EPC-C1G2", algo: crc, params: ["CRC-5/EPC-C1G2"]}, + {name: "CRC-5/G-704", algo: crc, params: ["CRC-5/G-704"]}, + {name: "CRC-5/ITU", algo: crc, params: ["CRC-5/ITU"]}, + {name: "CRC-5/USB", algo: crc, params: ["CRC-5/USB"]}, + {name: "CRC-6/CDMA2000-A", algo: crc, params: ["CRC-6/CDMA2000-A"]}, + {name: "CRC-6/CDMA2000-B", algo: crc, params: ["CRC-6/CDMA2000-B"]}, + {name: "CRC-6/DARC", algo: crc, params: ["CRC-6/DARC"]}, + {name: "CRC-6/G-704", algo: crc, params: ["CRC-6/G-704"]}, + {name: "CRC-6/GSM", algo: crc, params: ["CRC-6/GSM"]}, + {name: "CRC-6/ITU", algo: crc, params: ["CRC-6/ITU"]}, + {name: "CRC-7/MMC", algo: crc, params: ["CRC-7/MMC"]}, + {name: "CRC-7/ROHC", algo: crc, params: ["CRC-7/ROHC"]}, + {name: "CRC-7/UMTS", algo: crc, params: ["CRC-7/UMTS"]}, + {name: "CRC-8", algo: crc, params: ["CRC-8"]}, + {name: "CRC-8/8H2F", algo: crc, params: ["CRC-8/8H2F"]}, + {name: "CRC-8/AES", algo: crc, params: ["CRC-8/AES"]}, + {name: "CRC-8/AUTOSAR", algo: crc, params: ["CRC-8/AUTOSAR"]}, + {name: "CRC-8/BLUETOOTH", algo: crc, params: ["CRC-8/BLUETOOTH"]}, + {name: "CRC-8/CDMA2000", algo: crc, params: ["CRC-8/CDMA2000"]}, + {name: "CRC-8/DARC", algo: crc, params: ["CRC-8/DARC"]}, + {name: "CRC-8/DVB-S2", algo: crc, params: ["CRC-8/DVB-S2"]}, + {name: "CRC-8/EBU", algo: crc, params: ["CRC-8/EBU"]}, + {name: "CRC-8/GSM-A", algo: crc, params: ["CRC-8/GSM-A"]}, + {name: "CRC-8/GSM-B", algo: crc, params: ["CRC-8/GSM-B"]}, + {name: "CRC-8/HITAG", algo: crc, params: ["CRC-8/HITAG"]}, + {name: "CRC-8/I-432-1", algo: crc, params: ["CRC-8/I-432-1"]}, + {name: "CRC-8/I-CODE", algo: crc, params: ["CRC-8/I-CODE"]}, + {name: "CRC-8/ITU", algo: crc, params: ["CRC-8/ITU"]}, + {name: "CRC-8/LTE", algo: crc, params: ["CRC-8/LTE"]}, + {name: "CRC-8/MAXIM", algo: crc, params: ["CRC-8/MAXIM"]}, + {name: "CRC-8/MAXIM-DOW", algo: crc, params: ["CRC-8/MAXIM-DOW"]}, + {name: "CRC-8/MIFARE-MAD", algo: crc, params: ["CRC-8/MIFARE-MAD"]}, + {name: "CRC-8/NRSC-5", algo: crc, params: ["CRC-8/NRSC-5"]}, + {name: "CRC-8/OPENSAFETY", algo: crc, params: ["CRC-8/OPENSAFETY"]}, + {name: "CRC-8/ROHC", algo: crc, params: ["CRC-8/ROHC"]}, + {name: "CRC-8/SAE-J1850", algo: crc, params: ["CRC-8/SAE-J1850"]}, + {name: "CRC-8/SAE-J1850-ZERO", algo: crc, params: ["CRC-8/SAE-J1850-ZERO"]}, + {name: "CRC-8/SMBUS", algo: crc, params: ["CRC-8/SMBUS"]}, + {name: "CRC-8/TECH-3250", algo: crc, params: ["CRC-8/TECH-3250"]}, + {name: "CRC-8/WCDMA", algo: crc, params: ["CRC-8/WCDMA"]}, + {name: "Fletcher-8", algo: fletcher8, params: []}, + {name: "CRC-10/ATM", algo: crc, params: ["CRC-10/ATM"]}, + {name: "CRC-10/CDMA2000", algo: crc, params: ["CRC-10/CDMA2000"]}, + {name: "CRC-10/GSM", algo: crc, params: ["CRC-10/GSM"]}, + {name: "CRC-10/I-610", algo: crc, params: ["CRC-10/I-610"]}, + {name: "CRC-11/FLEXRAY", algo: crc, params: ["CRC-11/FLEXRAY"]}, + {name: "CRC-11/UMTS", algo: crc, params: ["CRC-11/UMTS"]}, + {name: "CRC-12/3GPP", algo: crc, params: ["CRC-12/3GPP"]}, + {name: "CRC-12/CDMA2000", algo: crc, params: ["CRC-12/CDMA2000"]}, + {name: "CRC-12/DECT", algo: crc, params: ["CRC-12/DECT"]}, + {name: "CRC-12/GSM", algo: crc, params: ["CRC-12/GSM"]}, + {name: "CRC-12/UMTS", algo: crc, params: ["CRC-12/UMTS"]}, + {name: "CRC-13/BBC", algo: crc, params: ["CRC-13/BBC"]}, + {name: "CRC-14/DARC", algo: crc, params: ["CRC-14/DARC"]}, + {name: "CRC-14/GSM", algo: crc, params: ["CRC-14/GSM"]}, + {name: "CRC-15/CAN", algo: crc, params: ["CRC-15/CAN"]}, + {name: "CRC-15/MPT1327", algo: crc, params: ["CRC-15/MPT1327"]}, + {name: "CRC-16", algo: crc, params: ["CRC-16"]}, + {name: "CRC-16/A", algo: crc, params: ["CRC-16/A"]}, + {name: "CRC-16/ACORN", algo: crc, params: ["CRC-16/ACORN"]}, + {name: "CRC-16/ARC", algo: crc, params: ["CRC-16/ARC"]}, + {name: "CRC-16/AUG-CCITT", algo: crc, params: ["CRC-16/AUG-CCITT"]}, + {name: "CRC-16/AUTOSAR", algo: crc, params: ["CRC-16/AUTOSAR"]}, + {name: "CRC-16/B", algo: crc, params: ["CRC-16/B"]}, + {name: "CRC-16/BLUETOOTH", algo: crc, params: ["CRC-16/BLUETOOTH"]}, + {name: "CRC-16/BUYPASS", algo: crc, params: ["CRC-16/BUYPASS"]}, + {name: "CRC-16/CCITT", algo: crc, params: ["CRC-16/CCITT"]}, + {name: "CRC-16/CCITT-FALSE", algo: crc, params: ["CRC-16/CCITT-FALSE"]}, + {name: "CRC-16/CCITT-TRUE", algo: crc, params: ["CRC-16/CCITT-TRUE"]}, + {name: "CRC-16/CCITT-ZERO", algo: crc, params: ["CRC-16/CCITT-ZERO"]}, + {name: "CRC-16/CDMA2000", algo: crc, params: ["CRC-16/CDMA2000"]}, + {name: "CRC-16/CMS", algo: crc, params: ["CRC-16/CMS"]}, + {name: "CRC-16/DARC", algo: crc, params: ["CRC-16/DARC"]}, + {name: "CRC-16/DDS-110", algo: crc, params: ["CRC-16/DDS-110"]}, + {name: "CRC-16/DECT-R", algo: crc, params: ["CRC-16/DECT-R"]}, + {name: "CRC-16/DECT-X", algo: crc, params: ["CRC-16/DECT-X"]}, + {name: "CRC-16/DNP", algo: crc, params: ["CRC-16/DNP"]}, + {name: "CRC-16/EN-13757", algo: crc, params: ["CRC-16/EN-13757"]}, + {name: "CRC-16/EPC", algo: crc, params: ["CRC-16/EPC"]}, + {name: "CRC-16/EPC-C1G2", algo: crc, params: ["CRC-16/EPC-C1G2"]}, + {name: "CRC-16/GENIBUS", algo: crc, params: ["CRC-16/GENIBUS"]}, + {name: "CRC-16/GSM", algo: crc, params: ["CRC-16/GSM"]}, + {name: "CRC-16/I-CODE", algo: crc, params: ["CRC-16/I-CODE"]}, + {name: "CRC-16/IBM", algo: crc, params: ["CRC-16/IBM"]}, + {name: "CRC-16/IBM-3740", algo: crc, params: ["CRC-16/IBM-3740"]}, + {name: "CRC-16/IBM-SDLC", algo: crc, params: ["CRC-16/IBM-SDLC"]}, + {name: "CRC-16/IEC-61158-2", algo: crc, params: ["CRC-16/IEC-61158-2"]}, + {name: "CRC-16/ISO-HDLC", algo: crc, params: ["CRC-16/ISO-HDLC"]}, + {name: "CRC-16/ISO-IEC-14443-3-A", algo: crc, params: ["CRC-16/ISO-IEC-14443-3-A"]}, + {name: "CRC-16/ISO-IEC-14443-3-B", algo: crc, params: ["CRC-16/ISO-IEC-14443-3-B"]}, + {name: "CRC-16/KERMIT", algo: crc, params: ["CRC-16/KERMIT"]}, + {name: "CRC-16/LHA", algo: crc, params: ["CRC-16/LHA"]}, + {name: "CRC-16/LJ1200", algo: crc, params: ["CRC-16/LJ1200"]}, + {name: "CRC-16/LTE", algo: crc, params: ["CRC-16/LTE"]}, + {name: "CRC-16/M17", algo: crc, params: ["CRC-16/M17"]}, + {name: "CRC-16/MAXIM", algo: crc, params: ["CRC-16/MAXIM"]}, + {name: "CRC-16/MAXIM-DOW", algo: crc, params: ["CRC-16/MAXIM-DOW"]}, + {name: "CRC-16/MCRF4XX", algo: crc, params: ["CRC-16/MCRF4XX"]}, + {name: "CRC-16/MODBUS", algo: crc, params: ["CRC-16/MODBUS"]}, + {name: "CRC-16/NRSC-5", algo: crc, params: ["CRC-16/NRSC-5"]}, + {name: "CRC-16/OPENSAFETY-A", algo: crc, params: ["CRC-16/OPENSAFETY-A"]}, + {name: "CRC-16/OPENSAFETY-B", algo: crc, params: ["CRC-16/OPENSAFETY-B"]}, + {name: "CRC-16/PROFIBUS", algo: crc, params: ["CRC-16/PROFIBUS"]}, + {name: "CRC-16/RIELLO", algo: crc, params: ["CRC-16/RIELLO"]}, + {name: "CRC-16/SPI-FUJITSU", algo: crc, params: ["CRC-16/SPI-FUJITSU"]}, + {name: "CRC-16/T10-DIF", algo: crc, params: ["CRC-16/T10-DIF"]}, + {name: "CRC-16/TELEDISK", algo: crc, params: ["CRC-16/TELEDISK"]}, + {name: "CRC-16/TMS37157", algo: crc, params: ["CRC-16/TMS37157"]}, + {name: "CRC-16/UMTS", algo: crc, params: ["CRC-16/UMTS"]}, + {name: "CRC-16/USB", algo: crc, params: ["CRC-16/USB"]}, + {name: "CRC-16/V-41-LSB", algo: crc, params: ["CRC-16/V-41-LSB"]}, + {name: "CRC-16/V-41-MSB", algo: crc, params: ["CRC-16/V-41-MSB"]}, + {name: "CRC-16/VERIFONE", algo: crc, params: ["CRC-16/VERIFONE"]}, + {name: "CRC-16/X-25", algo: crc, params: ["CRC-16/X-25"]}, + {name: "CRC-16/XMODEM", algo: crc, params: ["CRC-16/XMODEM"]}, + {name: "CRC-16/ZMODEM", algo: crc, params: ["CRC-16/ZMODEM"]}, + {name: "Fletcher-16", algo: fletcher16, params: []}, + {name: "CRC-17/CAN-FD", algo: crc, params: ["CRC-17/CAN-FD"]}, + {name: "CRC-21/CAN-FD", algo: crc, params: ["CRC-21/CAN-FD"]}, + {name: "CRC-24/BLE", algo: crc, params: ["CRC-24/BLE"]}, + {name: "CRC-24/FLEXRAY-A", algo: crc, params: ["CRC-24/FLEXRAY-A"]}, + {name: "CRC-24/FLEXRAY-B", algo: crc, params: ["CRC-24/FLEXRAY-B"]}, + {name: "CRC-24/INTERLAKEN", algo: crc, params: ["CRC-24/INTERLAKEN"]}, + {name: "CRC-24/LTE-A", algo: crc, params: ["CRC-24/LTE-A"]}, + {name: "CRC-24/LTE-B", algo: crc, params: ["CRC-24/LTE-B"]}, + {name: "CRC-24/OPENPGP", algo: crc, params: ["CRC-24/OPENPGP"]}, + {name: "CRC-24/OS-9", algo: crc, params: ["CRC-24/OS-9"]}, + {name: "CRC-30/CDMA", algo: crc, params: ["CRC-30/CDMA"]}, + {name: "CRC-31/PHILIPS", algo: crc, params: ["CRC-31/PHILIPS"]}, + {name: "Adler-32", algo: adler32, params: []}, + {name: "CRC-32", algo: crc, params: ["CRC-32"]}, + {name: "CRC-32/AAL5", algo: crc, params: ["CRC-32/AAL5"]}, + {name: "CRC-32/ADCCP", algo: crc, params: ["CRC-32/ADCCP"]}, + {name: "CRC-32/AIXM", algo: crc, params: ["CRC-32/AIXM"]}, + {name: "CRC-32/AUTOSAR", algo: crc, params: ["CRC-32/AUTOSAR"]}, + {name: "CRC-32/BASE91-C", algo: crc, params: ["CRC-32/BASE91-C"]}, + {name: "CRC-32/BASE91-D", algo: crc, params: ["CRC-32/BASE91-D"]}, + {name: "CRC-32/BZIP2", algo: crc, params: ["CRC-32/BZIP2"]}, + {name: "CRC-32/C", algo: crc, params: ["CRC-32/C"]}, + {name: "CRC-32/CASTAGNOLI", algo: crc, params: ["CRC-32/CASTAGNOLI"]}, + {name: "CRC-32/CD-ROM-EDC", algo: crc, params: ["CRC-32/CD-ROM-EDC"]}, + {name: "CRC-32/CKSUM", algo: crc, params: ["CRC-32/CKSUM"]}, + {name: "CRC-32/D", algo: crc, params: ["CRC-32/D"]}, + {name: "CRC-32/DECT-B", algo: crc, params: ["CRC-32/DECT-B"]}, + {name: "CRC-32/INTERLAKEN", algo: crc, params: ["CRC-32/INTERLAKEN"]}, + {name: "CRC-32/ISCSI", algo: crc, params: ["CRC-32/ISCSI"]}, + {name: "CRC-32/ISO-HDLC", algo: crc, params: ["CRC-32/ISO-HDLC"]}, + {name: "CRC-32/JAMCRC", algo: crc, params: ["CRC-32/JAMCRC"]}, + {name: "CRC-32/MEF", algo: crc, params: ["CRC-32/MEF"]}, + {name: "CRC-32/MPEG-2", algo: crc, params: ["CRC-32/MPEG-2"]}, + {name: "CRC-32/NVME", algo: crc, params: ["CRC-32/NVME"]}, + {name: "CRC-32/PKZIP", algo: crc, params: ["CRC-32/PKZIP"]}, + {name: "CRC-32/POSIX", algo: crc, params: ["CRC-32/POSIX"]}, + {name: "CRC-32/Q", algo: crc, params: ["CRC-32/Q"]}, + {name: "CRC-32/SATA", algo: crc, params: ["CRC-32/SATA"]}, + {name: "CRC-32/V-42", algo: crc, params: ["CRC-32/V-42"]}, + {name: "CRC-32/XFER", algo: crc, params: ["CRC-32/XFER"]}, + {name: "CRC-32/XZ", algo: crc, params: ["CRC-32/XZ"]}, + {name: "Fletcher-32", algo: fletcher32, params: []}, + {name: "CRC-40/GSM", algo: crc, params: ["CRC-40/GSM"]}, + {name: "CRC-64/ECMA-182", algo: crc, params: ["CRC-64/ECMA-182"]}, + {name: "CRC-64/GO-ECMA", algo: crc, params: ["CRC-64/GO-ECMA"]}, + {name: "CRC-64/GO-ISO", algo: crc, params: ["CRC-64/GO-ISO"]}, + {name: "CRC-64/MS", algo: crc, params: ["CRC-64/MS"]}, + {name: "CRC-64/NVME", algo: crc, params: ["CRC-64/NVME"]}, + {name: "CRC-64/REDIS", algo: crc, params: ["CRC-64/REDIS"]}, + {name: "CRC-64/WE", algo: crc, params: ["CRC-64/WE"]}, + {name: "CRC-64/XZ", algo: crc, params: ["CRC-64/XZ"]}, + {name: "Fletcher-64", algo: fletcher64, params: []}, + {name: "CRC-82/DARC", algo: crc, params: ["CRC-82/DARC"]} + ]; + } + + /** + * @param {ArrayBuffer} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const [length, includeNames] = args; + let output = ""; + this.checksums.forEach(checksum => { + const checksumLength = checksum.name.match(new RegExp("-(\\d{1,2})(\\/|$)"))[1]; + if (length === "All" || length === checksumLength) { + const value = checksum.algo.run(new Uint8Array(input), checksum.params || []); + output += includeNames ? + `${checksum.name}:${" ".repeat(25-checksum.name.length)}${value}\n`: + `${value}\n`; + } + }); + return output; + } +} + +export default GenerateAllChecksums; diff --git a/src/core/operations/GenerateAllHashes.mjs b/src/core/operations/GenerateAllHashes.mjs index d9af8065..df09aa85 100644 --- a/src/core/operations/GenerateAllHashes.mjs +++ b/src/core/operations/GenerateAllHashes.mjs @@ -22,14 +22,6 @@ import HAS160 from "./HAS160.mjs"; import Whirlpool from "./Whirlpool.mjs"; import SSDEEP from "./SSDEEP.mjs"; import CTPH from "./CTPH.mjs"; -import Fletcher8Checksum from "./Fletcher8Checksum.mjs"; -import Fletcher16Checksum from "./Fletcher16Checksum.mjs"; -import Fletcher32Checksum from "./Fletcher32Checksum.mjs"; -import Fletcher64Checksum from "./Fletcher64Checksum.mjs"; -import Adler32Checksum from "./Adler32Checksum.mjs"; -import CRC8Checksum from "./CRC8Checksum.mjs"; -import CRC16Checksum from "./CRC16Checksum.mjs"; -import CRC32Checksum from "./CRC32Checksum.mjs"; import BLAKE2b from "./BLAKE2b.mjs"; import BLAKE2s from "./BLAKE2s.mjs"; import Streebog from "./Streebog.mjs"; @@ -114,16 +106,6 @@ class GenerateAllHashes extends Operation { {name: "SSDEEP", algo: (new SSDEEP()), inputType: "str"}, {name: "CTPH", algo: (new CTPH()), inputType: "str"} ]; - this.checksums = [ - {name: "Fletcher-8", algo: (new Fletcher8Checksum), inputType: "byteArray", params: []}, - {name: "Fletcher-16", algo: (new Fletcher16Checksum), inputType: "byteArray", params: []}, - {name: "Fletcher-32", algo: (new Fletcher32Checksum), inputType: "byteArray", params: []}, - {name: "Fletcher-64", algo: (new Fletcher64Checksum), 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-16", algo: (new CRC16Checksum), inputType: "arrayBuffer", params: []}, - {name: "CRC-32", algo: (new CRC32Checksum), inputType: "arrayBuffer", params: []} - ]; } /** @@ -144,14 +126,6 @@ class GenerateAllHashes extends Operation { output += this.formatDigest(digest, length, includeNames, hash.name); }); - if (length === "All") { - output += "\nChecksums:\n"; - this.checksums.forEach(checksum => { - digest = this.executeAlgo(checksum.algo, checksum.inputType, checksum.params || []); - output += this.formatDigest(digest, length, includeNames, checksum.name); - }); - } - return output; } diff --git a/src/core/operations/GenerateUUID.mjs b/src/core/operations/GenerateUUID.mjs index 1ee0faba..21d063e3 100644 --- a/src/core/operations/GenerateUUID.mjs +++ b/src/core/operations/GenerateUUID.mjs @@ -5,8 +5,8 @@ */ import Operation from "../Operation.mjs"; -import crypto from "crypto"; - +import * as uuid from "uuid"; +import OperationError from "../errors/OperationError.mjs"; /** * Generate UUID operation */ @@ -20,11 +20,38 @@ class GenerateUUID extends Operation { this.name = "Generate UUID"; this.module = "Crypto"; - this.description = "Generates an RFC 4122 version 4 compliant Universally Unique Identifier (UUID), also known as a Globally Unique Identifier (GUID).

A version 4 UUID relies on random numbers, in this case generated using window.crypto if available and falling back to Math.random if not."; + this.description = + "Generates an RFC 9562 (formerly RFC 4122) compliant Universally Unique Identifier (UUID), " + + "also known as a Globally Unique Identifier (GUID).
" + + "
" + + "We currently support generating the following UUID versions:
" + + "" + + "UUIDs are generated using the uuid package.
"; this.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier"; this.inputType = "string"; this.outputType = "string"; - this.args = []; + this.args = [ + { + name: "Version", + hint: "UUID version", + type: "option", + value: ["v1", "v3", "v4", "v5", "v6", "v7"], + defaultIndex: 2, + }, + { + name: "Namespace", + hint: "UUID namespace (UUID; valid for v3 and v5)", + type: "string", + value: "1b671a64-40d5-491e-99b0-da01ff1f3341" + } + ]; } /** @@ -33,16 +60,17 @@ class GenerateUUID extends Operation { * @returns {string} */ run(input, args) { - const buf = new Uint32Array(4).map(() => { - return crypto.randomBytes(4).readUInt32BE(0, true); - }); - let i = 0; - return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { - const r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf, - v = c === "x" ? r : (r & 0x3 | 0x8); - i++; - return v.toString(16); - }); + const [version, namespace] = args; + const hasDesiredVersion = typeof uuid[version] === "function"; + if (!hasDesiredVersion) throw new OperationError("Invalid UUID version"); + + const requiresNamespace = ["v3", "v5"].includes(version); + if (!requiresNamespace) return uuid[version](); + + const hasValidNamespace = typeof namespace === "string" && uuid.validate(namespace); + if (!hasValidNamespace) throw new OperationError("Invalid UUID namespace"); + + return uuid[version](input, namespace); } } diff --git a/src/core/operations/JSONtoYAML.mjs b/src/core/operations/JSONtoYAML.mjs new file mode 100644 index 00000000..0d4cc626 --- /dev/null +++ b/src/core/operations/JSONtoYAML.mjs @@ -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; diff --git a/src/core/operations/Jq.mjs b/src/core/operations/Jq.mjs new file mode 100644 index 00000000..c1e02b34 --- /dev/null +++ b/src/core/operations/Jq.mjs @@ -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; diff --git a/src/core/operations/Jsonata.mjs b/src/core/operations/Jsonata.mjs new file mode 100644 index 00000000..82cc4d39 --- /dev/null +++ b/src/core/operations/Jsonata.mjs @@ -0,0 +1,65 @@ +/** + * @author Jon K (jon@ajarsoftware.com) + * @copyright Crown Copyright 2016 + * @license Apache-2.0 + */ + +import jsonata from "jsonata"; +import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; + +/** + * Jsonata Query operation + */ +class JsonataQuery extends Operation { + /** + * JsonataQuery constructor + */ + constructor() { + super(); + + this.name = "Jsonata Query"; + this.module = "Code"; + this.description = + "Query and transform JSON data with a jsonata query."; + this.infoURL = "https://docs.jsonata.org/overview.html"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + name: "Query", + type: "text", + value: "string", + }, + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + async run(input, args) { + const [query] = args; + let result, jsonObj; + + try { + jsonObj = JSON.parse(input); + } catch (err) { + throw new OperationError(`Invalid input JSON: ${err.message}`); + } + + try { + const expression = jsonata(query); + result = await expression.evaluate(jsonObj); + } catch (err) { + throw new OperationError( + `Invalid Jsonata Expression: ${err.message}` + ); + } + + return JSON.stringify(result === undefined ? "" : result); + } +} + +export default JsonataQuery; diff --git a/src/core/operations/PHPSerialize.mjs b/src/core/operations/PHPSerialize.mjs new file mode 100644 index 00000000..00fb1380 --- /dev/null +++ b/src/core/operations/PHPSerialize.mjs @@ -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.

This function does not support object tags.

Since PHP doesn't distinguish dicts and arrays, this operation is not always symmetric to PHP Deserialize.

Example:
[5,"abc",true]
becomes
a:3:{i:0;i:5;i:1;s:3:"abc";i:2;b:1;}"; + 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; diff --git a/src/core/operations/ParseX509Certificate.mjs b/src/core/operations/ParseX509Certificate.mjs index 11e63424..cdd1e9c7 100644 --- a/src/core/operations/ParseX509Certificate.mjs +++ b/src/core/operations/ParseX509Certificate.mjs @@ -6,7 +6,8 @@ import r from "jsrsasign"; 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 Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; @@ -81,7 +82,8 @@ class ParseX509Certificate extends Operation { } 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(), subject = cert.getSubject(), pk = cert.getPublicKey(), @@ -191,6 +193,10 @@ Issuer ${issuerStr} Subject ${subjectStr} +Fingerprints + MD5: ${runHash("md5", hex)} + SHA1: ${runHash("sha1", hex)} + SHA256: ${runHash("sha256", hex)} Public Key ${pkStr.slice(0, -1)} Certificate Signature diff --git a/src/core/operations/RailFenceCipherDecode.mjs b/src/core/operations/RailFenceCipherDecode.mjs index be54ee12..39795f21 100644 --- a/src/core/operations/RailFenceCipherDecode.mjs +++ b/src/core/operations/RailFenceCipherDecode.mjs @@ -72,7 +72,7 @@ class RailFenceCipherDecode extends Operation { } } - return plaintext.join("").trim(); + return plaintext.join(""); } } diff --git a/src/core/operations/RailFenceCipherEncode.mjs b/src/core/operations/RailFenceCipherEncode.mjs index 03651f85..89eddde7 100644 --- a/src/core/operations/RailFenceCipherEncode.mjs +++ b/src/core/operations/RailFenceCipherEncode.mjs @@ -66,7 +66,7 @@ class RailFenceCipherEncode extends Operation { rows[rowIdx] += plaintext[pos]; } - return rows.join("").trim(); + return rows.join(""); } } diff --git a/src/core/operations/SM2Decrypt.mjs b/src/core/operations/SM2Decrypt.mjs new file mode 100644 index 00000000..39657110 --- /dev/null +++ b/src/core/operations/SM2Decrypt.mjs @@ -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; diff --git a/src/core/operations/SM2Encrypt.mjs b/src/core/operations/SM2Encrypt.mjs new file mode 100644 index 00000000..b1e5f901 --- /dev/null +++ b/src/core/operations/SM2Encrypt.mjs @@ -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; diff --git a/src/core/operations/ShowOnMap.mjs b/src/core/operations/ShowOnMap.mjs index c2ac1c6e..d75c2aa6 100644 --- a/src/core/operations/ShowOnMap.mjs +++ b/src/core/operations/ShowOnMap.mjs @@ -1,6 +1,7 @@ /** * @author j433866 [j433866@gmail.com] - * @copyright Crown Copyright 2019 + * @author 0xff1ce [github.com/0xff1ce] + * @copyright Crown Copyright 2024 * @license Apache-2.0 */ @@ -22,7 +23,7 @@ class ShowOnMap extends Operation { this.name = "Show on map"; this.module = "Hashing"; this.description = "Displays co-ordinates on a slippy map.

Co-ordinates will be converted to decimal degrees before being shown on the map.

Supported formats:
  • Degrees Minutes Seconds (DMS)
  • Degrees Decimal Minutes (DDM)
  • Decimal Degrees (DD)
  • Geohash
  • Military Grid Reference System (MGRS)
  • Ordnance Survey National Grid (OSNG)
  • Universal Transverse Mercator (UTM)

This operation will not work offline."; - this.infoURL = "https://foundation.wikimedia.org/wiki/Maps_Terms_of_Use"; + this.infoURL = "https://osmfoundation.org/wiki/Terms_of_Use"; this.inputType = "string"; this.outputType = "string"; this.presentType = "html"; @@ -85,10 +86,10 @@ class ShowOnMap extends Operation { data = "0, 0"; } const zoomLevel = args[0]; - const tileUrl = "https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png", - tileAttribution = "
Wikimedia maps | © OpenStreetMap contributors", - leafletUrl = "https://unpkg.com/leaflet@1.5.0/dist/leaflet.js", - leafletCssUrl = "https://unpkg.com/leaflet@1.5.0/dist/leaflet.css"; + const tileUrl = "https://tile.openstreetmap.org/{z}/{x}/{y}.png", + tileAttribution = "© OpenStreetMap contributors", + leafletUrl = "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js", + leafletCssUrl = "https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"; return `