Skip to content

Instantly share code, notes, and snippets.

@StevePlace68
StevePlace68 / cert-splitter.sh
Last active May 24, 2024 16:10
Split certificates from a certificate chain
#!/bin/bash
# Define file locations/password, change to match your machine
CA_BUNDLE="/etc/ssl/certs/ca-bundle.crt"
TRUSTSTORE="/path/to/my-truststore.jks"
TRUSTSTORE_PASS="changeit"
# Split the ca-bundle.crt into individual certificates
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/' "$CA_BUNDLE" | \
awk 'BEGIN {c=0} /-----BEGIN CERTIFICATE-----/ {c++} { print > ("cert" c ".pem") }'