8000 feat: add JWT decoding script for MDS3 format by tjsilver · Pull Request #575 · guardian/janus-app · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add JWT decoding script for MDS3 format #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions script/decode_jwt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

# Define paths
JWT_FILE="/Users/thalia_silver/code/janus-app/blob.jwt"
OUTPUT_FILE="/Users/thalia_silver/code/janus-app/decoded_jwt.json"

# Check if the JWT file exists
if [ ! -f "$JWT_FILE" ]; then
echo "Error: JWT file not found at $JWT_FILE"
exit 1
fi

# Read the JWT token from file
JWT=$(cat "$JWT_FILE")

if [ -z "$JWT" ]; then
echo "Error: JWT file is empty"
exit 1
fi

echo "Processing MDS3 format JWT token..."

# Split the JWT into parts
IFS='.' read -ra JWT_PARTS <<< "$JWT"

if [ ${#JWT_PARTS[@]} -ne 3 ]; then
echo "Error: Invalid JWT format. Expected 3 parts (header.payload.signature)"
exit 1
fi

# Function to decode base64url to base64 and then decode
decode_base64() {
local input=$1
# Add padding if needed
local mod4=$((${#input} % 4))
if [ $mod4 -eq 2 ]; then input="${input}==";
elif [ $mod4 -eq 3 ]; then input="${input}="; fi

# Replace URL-safe characters
input=$(echo "$input" | tr -d '\n' | tr '_-' '/+')

# Decode
echo "$input" | base64 --decode
}

# Decode payload (MDS3 format is in the payload)
PAYLOAD=$(decode_base64 "${JWT_PARTS[1]}")

# Format and save as JSON
echo "$PAYLOAD" | jq '.' > "$OUTPUT_FILE" 2>/dev/null

# If jq is not available or fails, try a basic approach
if [ $? -ne 0 ]; then
echo "Warning: jq not available or failed to format. Saving raw decoded payload."
echo "$PAYLOAD" > "$OUTPUT_FILE"
fi

echo "Decoded JWT saved to $OUTPUT_FILE"

# Display a preview of the decoded content
echo "------------------------"
echo "Preview of decoded content:"
head -n 10 "$OUTPUT_FILE"
echo "------------------------"
echo "Decoding complete."
0