This repository is an attempt to explore the security aspect of JWT verification, especially while performing token validation on an offline device.
I have attempted to implement the certificate generation and JWT token verification via C/C++ APIs and bash scripts.
The implementations for managing certificates and validating JWT in this repository are for demonstration purpose only. These implementations are not intended for production systems.
OpenSSL C APIs
are used for creating RSA Key Pair, X509 Certificates & CSR and validating certificate chain.jwt-cpp
is used for tampering and handling JWT tokens.
openssl command line utility
is used for creating Key Pair, Certificates and validating certificate chain.jq
is used for tampering and handling JWT tokens.
For running scripts/verify_jwt.sh
, install these dependencies
sudo apt install jq basez
To figure out a way to implement JWT verification for an offline system which receives the token and verification keys over an insecure channel. Thus there's always a possibility of tampering with token in an attempt to bypass authentication.
This repository tries to implement and validate the poc for below scenarios for JWT validation using OpenSSL and jwt-cpp.
- System doesn't know which public key to trust
- Attacker can sign the token his own key pair and provide the tampered token along with the public key and system will identify the token as valid.
- System doesn't know which public certificate to trust
- Attacker an sign the token using his own certificate pair and send it along the tampered token for validation and system will identify the token as valid.
- Put public certificate in the trust store ahead of time
- If attacker send his own public certificate with tampered token, system will identify the token invalid since the public certificate is not trusted.
- System will render unusable once key pair is rotated by issuing server
- Put public part of root certificate into the trust store ahead of time
- Server will issue new certificate pair signed by root certificate. And use this end certificate to sign the token.
- System will only trust the public certificate signed by the root certificate available in the trust store.
- Even if the certificate/ key pair is rotated, system will still trust it as long as it's signed by the same root certificate.
- There can be any number of intermediate certificates between root and signing certificate.
- On the validation side, system will validate the certificate issuer chain (received over insecure channel) and if it's valid and trusted, only then the token will be validated against the received public key.
Given the constrains, Trust root certificate ahead of time seems like the best option to appropriately implement JWT verification for an offline system so far.
make clean
make run
cd scripts/
chmod +x verify_token.sh
./verify_jwt.sh <number-of-intermediate-certificates-in-CA-chain>