A Node.js/TypeScript tool for generating encrypted SSL certificate pinning configurations. This tool helps secure mobile applications by encrypting SSL pinning data using RSA-OAEP-256 encryption.
This tool reads SSL certificate pinning configurations from a JSON file, encrypts them using a public key, and outputs an encrypted file that can be securely distributed to client applications. It's particularly useful for mobile app developers implementing certificate pinning for enhanced security. You may need to replace the example.com placeholder with your appropriate domain.
- Node.js (v14 or higher)
- npm or yarn
- OpenSSL (for hash extraction script)
- Clone the repository:
git clone https://github.com/thinesjs/ssl-pinning-generator
cd ssl-pinning-generator- Install dependencies:
npm install- Build the project:
npm run buildCreate or modify the ssl-pinning-config.json file with your domain configurations, or run npm run export:ssl-config:
{
"example.com": {
"includeSubdomains": true,
"publicKeyHashes": [
"primary-certificate-hash=",
"backup-certificate-hash="
]
}
}Ensure you have a ssl-public.pem file in the root directory containing the RSA public key for encryption.
Run the generator:
npm run generateOr use individual commands:
# Build TypeScript
npm run build
# Run the generator
npm startThis will create an encrypted ssl-pinning file containing your SSL pinning configuration.
To fetch and decrypt SSL pinning configuration from a remote URL:
npm run read:sslThis will:
- Fetch the encrypted SSL pinning configuration from
https://assets.example.com/certs/ssl-pinning - Decrypt it using the RSA private key from
ssl-private.pem - Display the decrypted JSON configuration in the console
Note: You need the corresponding private key (ssl-private.json) to decrypt the configuration.
To fetch, decrypt, and save the SSL pinning configuration from the remote URL to your local file:
npm run export:sslThis will:
- Fetch the encrypted SSL pinning configuration from
https://assets.example.com/certs/ssl-pinning - Decrypt it using the RSA private key from
ssl-private.json - Save the decrypted JSON configuration to
ssl-pinning-config.json - Display the configuration in the console for verification
This is useful for updating your local configuration file with the latest remote configuration.
The ssl-pinning-config.json file should follow this structure:
{
"domain.com": {
"includeSubdomains": boolean,
"publicKeyHashes": [
"base64-encoded-sha256-hash1",
"base64-encoded-sha256-hash2"
]
}
}- includeSubdomains: Whether to apply pinning to subdomains
- publicKeyHashes: Array of base64-encoded SHA-256 hashes of public keys
The project includes a utility script for extracting SSL certificate hashes from certificate files:
./scripts/generate_ssl_hashes.shPlace your SSL certificates in the /certs directory following this structure:
certs/
βββ accounts_example_com/
β βββ accounts_example_com.crt # Leaf/server certificate
β βββ accounts_example_com.ca-bundle # Intermediate and root certificates
βββ transfer_example_com/
β βββ transfer_example_com.crt # Leaf/server certificate
β βββ transfer_example_com.ca-bundle # Intermediate and root certificates
βββ {domain_with_underscores}/
βββ {domain_with_underscores}.crt
βββ {domain_with_underscores}.ca-bundle
Note: Domain names should use underscores instead of dots in folder and file names (e.g., accounts.example.com becomes accounts_example_com).
The script:
- Scans the
/certsdirectory for domain folders - For each domain folder, looks for
.crt(leaf certificate) and.ca-bundle(certificate chain) files - Extracts the public key from the leaf certificate and generates a SHA-256 hash
- Splits the certificate bundle and generates backup hashes from intermediate certificates
- Outputs the primary hash and backup hashes in base64 format
- Converts domain folder names back to proper domain format (underscores to dots)
For each domain, the script outputs:
accounts.example.com:
1. qhTtMzlmLJregAc7uDRRNrcEsIAe1iYn2gb9brfCcmE=
2. NYbU7PBwV4y9J67c4guWTki8FJ+uudrXL0a4V4aRcrg= [BACKUP]
3. 2qkGb+4ldSHX4Z6slboc9d8oF4g7jaAjClvNJARkiTE= [BACKUP]
The first hash is from the leaf certificate, while subsequent hashes marked as [BACKUP] are from intermediate certificates in the chain.
The tool generates:
- ssl-pinning: Encrypted configuration file (JWE format)
- dist/index.js: Compiled JavaScript from TypeScript source
ssl-pinning-generator/
βββ src/
β βββ index.ts # Main application logic
βββ scripts/
β βββ get_ssl_hashes.sh # SSL hash extraction utility
βββ dist/ # Compiled JavaScript output
βββ ssl-pinning-config.json # SSL pinning configuration
βββ ssl-pinning # Encrypted output file
βββ package.json # Project dependencies and scripts
βββ tsconfig.json # TypeScript configuration
npm run build: Compile TypeScript to JavaScriptnpm start: Run the compiled application (encrypt mode)npm run generate:ssl: Build and run the generator (encrypt SSL config)npm run read:ssl: Build and read encrypted SSL config from URLnpm run export:ssl: Build and export encrypted SSL config from URL to local filenpm test: Run tests (placeholder)
- node-jose: JSON Web Encryption/Signature library
- typescript: TypeScript compiler
- @types/node: Node.js type definitions
- @types/node-jose: Type definitions for node-jose
- Private Key Protection: Keep your private key secure and never commit it to version control
- Certificate Rotation: Regularly update certificate hashes when certificates are renewed
- Backup Certificates: Always include backup certificate hashes to prevent application breakage
- Secure Distribution: Use secure channels to distribute the encrypted configuration
The tool includes comprehensive error handling for:
- Missing input files (
ssl-pinning-config.json,ssl-public.pem) - Invalid JSON configuration
- Encryption failures
- File I/O errors