Last active
December 25, 2025 05:03
-
-
Save Aries0d0f/5b75aed1eac2750807f6ffb07e50dc48 to your computer and use it in GitHub Desktop.
Quick preview X509 Certificate via Firefox-based browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/zsh | |
| # This script helps you use a Firefox-based browser's | |
| # built-in certificate inspection feature to | |
| # preview certificate files without actually serve it. | |
| # It's particularly useful for debugging self-signed | |
| # certificate chains and examining certificate details. | |
| view-cert() { | |
| # Script to convert certificate files to Firefox certificate viewer URLs | |
| # Usage: view-cert <certificate-file> | |
| if [ $# -eq 0 ]; then | |
| echo "Usage: $0 <certificate-file>" | |
| echo "Example: $0 mycert.crt" | |
| exit 1 | |
| fi | |
| CERT_FILE="$1" | |
| if [ ! -f "$CERT_FILE" ]; then | |
| echo "Error: File '$CERT_FILE' not found" | |
| exit 1 | |
| fi | |
| # Extract all certificates from the file and build the URL | |
| url="about:certificate" | |
| first=true | |
| # Split the file by certificate blocks | |
| while IFS= read -r line; do | |
| if [[ "$line" == "-----BEGIN CERTIFICATE-----" ]]; then | |
| # Start collecting certificate data | |
| cert_data="" | |
| in_cert=true | |
| elif [[ "$line" == "-----END CERTIFICATE-----" ]]; then | |
| # End of certificate, URL encode and add to URL | |
| # URL encode the base64 data (encode +, /, =) | |
| encoded_cert=$(echo -n "$cert_data" | sed 's/+/%2B/g; s/\//%2F/g; s/=/%3D/g') | |
| if [ "$first" = true ]; then | |
| url="${url}?cert=${encoded_cert}" | |
| first=false | |
| else | |
| url="${url}&cert=${encoded_cert}" | |
| fi | |
| in_cert=false | |
| elif [ "$in_cert" = true ]; then | |
| # Collect base64 data (remove all whitespace) | |
| cert_data="${cert_data}${line}" | |
| fi | |
| done < "$CERT_FILE" | |
| # Only Support if the browser is Firefox-based, like Firefox, Zen, Tor. | |
| # If your default browser is not Firefox-based but you did have Firefox-based browser installed on the system, you can change the variable `DEFAULT_BROWSER` to make it work. | |
| DEFAULT_BROWSER="$(mdfind kMDItemCFBundleIdentifier = "$(plutil -convert json -o - "$HOME/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist" | jq -r '.LSHandlers[] | select( .LSHandlerURLScheme=="https" ) | .LSHandlerRoleAll')" | grep -E '^/Applications/')" | |
| open -u "$url" -a "$DEFAULT_BROWSER" | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certificate Viewer Plugin
Overview
This script helps you use a Firefox-based browser's built-in certificate inspection feature to view certificate files. It's particularly useful for debugging self-signed certificate chains and examining certificate details.
The script reads certificate files (
.crt,.pem, or any file containing PEM-encoded certificates), encodes them, and opens them in Firefox's certificate viewer interface.Requirements
opencommand) / Linux (requires some modification)zshorbashshelljqcommand-line JSON processor (Optional, for determining default browser on macOS; install via Homebrew:brew install jq)Note
This script is designed for macOS as it uses the macOS-exclusive
opencommand. To use it on Linux, replaceopenwithxdg-open. Despite the shebang line declaringzsh, the script also works withbashwithout modifications.Installation
1. Download the Script
Download
viewer.plugin.shand save it to a convenient location, such as:~/scripts/viewer.plugin.sh~/.local/bin/viewer.plugin.sh$PATH2. Make it Executable (Optional)
If you plan to run it directly, make the script executable:
3. Source the Plugin
The script is designed as a shell plugin, so you need to source it into your shell to use the
view-certfunction.For permanent availability (add to your shell's RC file):
For Zsh users (
~/.zshrc):For Bash users (
~/.bashrcor~/.bash_profile):For one-time use (current session only):
source /path/to/viewer.plugin.shAfter sourcing, reload your shell configuration:
Usage
Basic Usage
Examples
View a single certificate:
View a certificate chain:
View a Let's Encrypt certificate:
How It Works
about:certificate)Troubleshooting
Error: "command not found: view-cert"
Error: "File not found"
Browser doesn't open
Error: "jq: command not found"
If you encounter an error indicating that
jqis not found, you need to install it. On macOS, you can installjqusing Homebrew with the following command:Or you can just remove the lines that use
jqto determine the default browser, and manually specify your Firefox-based browser path in the script (e.g.,/Applications/Firefox.app).