Giter VIP home page Giter VIP logo

jwt-webtool's Introduction

JWT Web tool

This is the source code for a web tool that can decode JWT, verify signed JWT, decrypt encrypted JWT, and create signed or encrypted JWT. It works nicely for lots of cases. It also has a few limitations; details below.

screengrab

License

This code is Copyright (c) 2019-2024 Google LLC, and is released under the Apache Source License v2.0. For information see the LICENSE file.

Purpose

I built this as a tool that might be helpful to developers learning JWT, or experimenting with ways to use JWT. The output of this repo is currently running here.

Disclaimer

This tool is not an official Google product, nor is it part of an official Google product.

Limitations

This tool has some limitations:

  • For signed JWT, the tool handles JWT that use ECDSA (ES256, ES384, ES512), RSA (RS256, RS384, RS512, PS256, PS384, PS512) or HMAC algorithms (HS256, HS384, HS512).

  • For encrypted JWT, specifically for key encryption, it handles JWT that use RSA keys and RSA algorithms (RSA-OAEP, RSA-OAEP-256), JWT that use EC keys and various ECDH algorithms (ECDH-ES, ECDH-ES+A128KW, ECDH-ES+A256KW) as well as JWT that use the PBES2 algorithms. It does not currently support the "dir" alg type. It supports all types of enc algorithms.

  • In either case (signed or encrypted), this tool does not handle crit headers, nor will it extract the certificate from an x5c header. Nor will it check thumbprints of an x5t header.

  • This tool uses EcmaScript v9, and webcrypto, which means it will run only on modern, current browsers.

Design

This is a single-page web app. It has no "backend" supporting it. All JWT signing and verifying, or encrypting or decrypting, happens within the browser. Anything a user pastes into the UI never leaves the browser. It just needs a few static files.

There's a shortcut: if you open the url with ?JWT_HERE, it will decode that JWT. It saves you a step, pasting in your own JWT. If you're paranoid you can also use the # as a separator.

You may want to fork this and bundle it into an intranet, to allow developers within a company to experiment with JWT. You can also run it from a file:// URL.

From my perspective, there's no security issue with using the publicly hosted tool, but your company's security auditors may not agree..

Dependencies

The web app depends on

Build Dependencies

This tool uses webpack v5 for bundling the assets.

Please send pull requests

Constructive feedback is always appreciated. PR's will be appreciated.

Developing

If you fork this repo to mess with the code, here's what I advise.

Before you do anything you need to install the dependencies.

npm install

To build a "development" distribution:

npm run devbuild

This build will allow you to run the page and debug with the browser dev tools, and see the original source lines in your in-browser debugger. You can load the page via a file:/// url, and it will work just fine. For that, open a Chrome browser tab (or whatever browser you use) to file:///path/to/dist/index.html .

During development, I prefer to use the webpack "watch" capability, which rebuilds as I modify the source code. To do that, execute this in a terminal:

npm run watch

The above command will run "forever", and will rebundle when any source file changes. When you save a file, wait a few seconds for the build, maybe 5 seconds, and then just click the reload button in the browser tab, to see the updates.

To build a production distribution:

npm run build

Bugs / Feature Gaps

  • For verification of signed JWT, or creation of encrypted JWT, it is not possible to use an x509v3 certificate for the source of the public key. You need to extract the public key yourself.

jwt-webtool's People

Contributors

antifob avatar dependabot[bot] avatar dinochiesa avatar mormegil-cz avatar seanburford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jwt-webtool's Issues

build errors

Just a heads up, I had to run npm install codemirror@5 to get the build working. I don't do a lot of javascript, so I couldn't tell you why that worked.

Add an easier way to use a public key to reencode with HS256

As it stands, there is no simple way to reencode a decoded JWT using a public key with HS256 (Due to the header, footer, and newlines that a public key contains)

If you have a public key file you are currently required to convert it to hex, remove the new lines, and use the "Hex" option with the new result (Simply using the UTF-8 option on a new-line-stripped public key doesn't work)

I suggest an additional "Public Key" option with HS256 to streamline this process.

Fails to decode valid JWE generated by python-jose - During decryption: Error: invalid iv

I am not sure where exactly is the problem (maybe python-jose does something weird), but unless it's a token encrypted by the tool itself, it errors out when trying to decode (dir, A256GCM).

python-jose==3.3.0

from hashlib import sha256

from jose import jwe
from jose.constants import ALGORITHMS

hasher = sha256()
hasher.update("secretsecret".encode())
secret_key = hasher.digest()

print("SECRET KEY HEX: ", secret_key.hex())

encrypted_token = jwe.encrypt(
    '{"test":1}',
    key=secret_key,
    encryption=ALGORITHMS.A256GCM,
    algorithm=ALGORITHMS.DIR,
)

print(encrypted_token.decode())

If you input this information into the app and click the tick button, it throws an error.

During decryption: Error: invalid iv main.js:2:854160
t@https://dinochiesa.github.io/jwt/js/main.js:2:641222
2736/l/<@https://dinochiesa.github.io/jwt/js/main.js:2:641941
3748/t.setupFallback/i<@https://dinochiesa.github.io/jwt/js/main.js:2:659660
5382/t.decrypt@https://dinochiesa.github.io/jwt/js/main.js:2:663729
value@https://dinochiesa.github.io/jwt/js/main.js:2:712705
4581/u/value/c</<@https://dinochiesa.github.io/jwt/js/main.js:2:699838
promise callback*4581/u/value/c<@https://dinochiesa.github.io/jwt/js/main.js:2:699811
promise callback*value@https://dinochiesa.github.io/jwt/js/main.js:2:699605
Z/<@https://dinochiesa.github.io/jwt/js/main.js:2:853408
async*Z@https://dinochiesa.github.io/jwt/js/main.js:2:853345
dispatch@https://dinochiesa.github.io/jwt/js/main.js:2:333003
9755/</add/y.handle@https://dinochiesa.github.io/jwt/js/main.js:2:330998
EventListener.handleEvent*add@https://dinochiesa.github.io/jwt/js/main.js:2:331460
9755/</ke/<@https://dinochiesa.github.io/jwt/js/main.js:2:330065
each@https://dinochiesa.github.io/jwt/js/main.js:2:292606
each@https://dinochiesa.github.io/jwt/js/main.js:2:291086
ke@https://dinochiesa.github.io/jwt/js/main.js:2:330040
on@https://dinochiesa.github.io/jwt/js/main.js:2:336520
@https://dinochiesa.github.io/jwt/js/main.js:2:865754
u@https://dinochiesa.github.io/jwt/js/main.js:2:319965
9755/</Deferred/then/a/</c<@https://dinochiesa.github.io/jwt/js/main.js:2:320267
setTimeout handler*9755/</Deferred/then/a/<@https://dinochiesa.github.io/jwt/js/main.js:2:320476
l@https://dinochiesa.github.io/jwt/js/main.js:2:318247
fireWith@https://dinochiesa.github.io/jwt/js/main.js:2:318995
fire@https://dinochiesa.github.io/jwt/js/main.js:2:319031
l@https://dinochiesa.github.io/jwt/js/main.js:2:318247
fireWith@https://dinochiesa.github.io/jwt/js/main.js:2:318995
ready@https://dinochiesa.github.io/jwt/js/main.js:2:321981
z@https://dinochiesa.github.io/jwt/js/main.js:2:321759
EventListener.handleEvent*9755/<@https://dinochiesa.github.io/jwt/js/main.js:2:322130
9755/<@https://dinochiesa.github.io/jwt/js/main.js:2:289716
9755@https://dinochiesa.github.io/jwt/js/main.js:2:289829
r@https://dinochiesa.github.io/jwt/js/main.js:2:841639
3734@https://dinochiesa.github.io/jwt/js/main.js:2:64031
r@https://dinochiesa.github.io/jwt/js/main.js:2:841639
@https://dinochiesa.github.io/jwt/js/main.js:2:842322
@https://dinochiesa.github.io/jwt/js/main.js:2:869268
@https://dinochiesa.github.io/jwt/js/main.js:2:869588
main.js:2:854197

encrypted token idempotence

Heya,

When using 'Encrypted' mode, the token changes every time when using the same inputs.

I assumed that this is due to the "iat" or "exp" timestamps changing, but they appear to be static and removing them doesn't make the tokens consistent.

Question: is this a 'feature' of web tokens or maybe just an implementation detail of the webtool? 🤔

Screenshot 2023-03-17 at 11 48 46

Screenshot 2023-03-17 at 11 48 57

npm install fails

Hi, first great project. It looks very useful. Unfortunately, when I run npm install I receive an error. Is this a node version issue?

jwt-webtool git:(main)  npm install
npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.3.3: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated popper.js@1.16.0: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
npm WARN deprecated core-js@2.6.10: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path /Users/mike/git/jwt-webtool/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node scripts/install.js
npm ERR! /Users/mike/git/jwt-webtool/node_modules/string-width/index.js:2
npm ERR! var stripAnsi = require('strip-ansi');
npm ERR!                 ^
npm ERR!
npm ERR! Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/mike/git/jwt-webtool/node_modules/strip-ansi/index.js from /Users/mike/git/jwt-webtool/node_modules/string-width/index.js not supported.
npm ERR! Instead change the require of /Users/mike/git/jwt-webtool/node_modules/strip-ansi/index.js in /Users/mike/git/jwt-webtool/node_modules/string-width/index.js to a dynamic import() which is available in all CommonJS modules.
npm ERR!     at Object.<anonymous> (/Users/mike/git/jwt-webtool/node_modules/string-width/index.js:2:17)
npm ERR!     at Object.<anonymous> (/Users/mike/git/jwt-webtool/node_modules/wide-align/align.js:2:19)
npm ERR!     at Object.<anonymous> (/Users/mike/git/jwt-webtool/node_modules/gauge/render-template.js:2:13)
npm ERR!     at Object.<anonymous> (/Users/mike/git/jwt-webtool/node_modules/gauge/plumbing.js:3:22)
npm ERR!     at Object.<anonymous> (/Users/mike/git/jwt-webtool/node_modules/gauge/index.js:2:16)
npm ERR!     at Object.<anonymous> (/Users/mike/git/jwt-webtool/node_modules/npmlog/log.js:3:13)
npm ERR!     at Object.<anonymous> (/Users/mike/git/jwt-webtool/node_modules/node-sass/scripts/install.js:9:9) {
npm ERR!   code: 'ERR_REQUIRE_ESM'
npm ERR! }
npm ERR!
npm ERR! Node.js v17.0.1

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mike/.npm/_logs/2022-01-20T16_55_40_520Z-debug.log

credit my contribution to the switchable dark mode feature

Hi Dino Chiesa,

I hope you're doing well.

I'm reaching out regarding pull request #32 I submitted on Feb 3 for the switchable dark mode feature. I noticed that the pull request was closed on Apr 26, and the feature was subsequently added to the tool without any mention of my contribution.

I understand that changes might have been made which led to conflicts, making it challenging to merge the pull request directly. However, I believe that acknowledging contributions is important in fostering a collaborative and respectful open-source community.

Would it be possible to credit my contribution to the switchable dark mode feature in the project? It could be as simple as mentioning my GitHub handle @rdavydov in the commit message or the project’s acknowledgments.

Thank you for considering this request. I appreciate your understanding and look forward to your response.

Best regards,
Roman Davydov
@rdavydov

Does the tool decrypt JWE?

Does the tool decrypt JWE?

Symmetric Key
Below is an access_token which is a JWE.

I pasted the same in the left side of https://dinochiesa.github.io/jwt/ and gave the correct Symmetric Key B374A26A71490437AA024E4FADD5B497 and click on right arrow to decrypt it but it shows a popup an encrypted JWT but does not decrypt the payload.

eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0.u0By6Um5AQ657kC0h18C80Hddr780XBKuoVZfTVI0KbYy1VJSqprs6sKHcxyiefuTUHIN4m8cPwma6Wh3vFKFMZfV1asiqWR.g3h9R-Rw-9Ek1UbChbuLww.Z8Gb2Bmghz7wNojWbMawFpJOnkaLsEu7rJPLvP49y637aKTYvx52BZZXdwvdjU9W6uv8igm2EvUCTJMepuBNGT1Er_IG7VhPysyvofTlZJsua8fWaUzoSHeMcDZLMjfd-hunKyE469sWb5mpjoaZkXStmkloGMPzqN6w1kFIHenLMD8MPLlMseSXb-fIu79a5tP2sSzNvcXd71NkIL8Lvb1kbpJlk78NBQa7S7r1z2P70FuD2_zfQw9ozPg2r6zT.-POciCP4tbU6FDbkn0fnMFurrAsCnMqtcCOV2ak8hSA
image

Asymmetric Key
I pasted the same in the left side of https://dinochiesa.github.io/jwt/ and gave the correct Asymmetric Key public and private key and click on right arrow to decrypt it but it shows a popup an encrypted JWT but does not decrypt the payload.

eyJraWQiOiJ0ZXN0b2F1dGgwMS5hcHAiLCJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZDQkMtSFM1MTIifQ.ohghcHCb-iaiDmqlxboyMdCcs0IsEacCywQ-3TqJPKD8bzeS_HUm_9TWElzgj5IhZw1fBmuKg5uW1hhvqcx-HMOGA3ApEhbLkdihpWGA3lJxeGdVFR5aG91cE9-tHregxIgskoCtV4UQVAjJutMMXIpl5cyPUMqwLOf3ei0lUKpLx6dHgPDxFn1Up3c9l0MrEXqoe49hzC3USyD2jvFsZELJxWV9Y_VwWdmnjQBS9AZl-1VObF35UnGXrY0UJ-Uch0nrOjj8az_6oahGPKmf9c3Afab7FVbbPIoA4UOD1Dkv-gaiC9sWc-vhHy4FwrIV4xytcXoo6GYUPjKddXSshA.aIeMLD0pEy0Esv687yh_BQ.u5RhLjkDtnmVpP4BFqIpbTdmO-p53VfWwZ99rqInN9FtoVn2piOVx1apW7SRY1DIh-Rc9edf4hRJqOxdaKkN_IofOjh440xyqMvU69txRYxcK7EaeSWNNL0k85Rg-UnbCCP7HI2ypfc8dHKDZoK-Yu4yCqbp7ClUQ9Hl2F_eIESoTuHYfSuaXddb99D0xa8m39dCsLM8Xfg0ilJQXRQno-ZDQYfuvqcELnNFPTpvxvnyrJi5xNbd2ZzIP1ybj81w.m4SmApfLN9swfQPenaj3vwP__f9y_6qDHdWxK5-CGHY
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.