Last active
November 17, 2025 19:31
-
-
Save AfroThundr3007730/ba99753dda66fc4abaf30fb5c0e5d012 to your computer and use it in GitHub Desktop.
Import DoD root certificates into linux CA store
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/bash | |
| # Imports DoD root certificates into Linux CA store | |
| # Version 0.4.3 updated 20251113 by AfroThundr | |
| # SPDX-License-Identifier: GPL-3.0-or-later | |
| # For issues or updated versions of this script, browse to the following URL: | |
| # https://gist.github.com/AfroThundr3007730/ba99753dda66fc4abaf30fb5c0e5d012 | |
| # Dependencies: curl gawk openssl unzip wget | |
| set -euo pipefail | |
| shopt -s extdebug nullglob | |
| add_dod_certs() { | |
| local bundle cert certdir file form tmpdir url update | |
| trap '[[ -d ${tmpdir:-} ]] && rm -fr $tmpdir' EXIT INT TERM | |
| # Location of bundle from DISA site | |
| #url='https://public.cyber.mil/pki-pke/pkipke-document-library/' | |
| #bundle=$(curl -s $url | awk -F '"' 'tolower($2) ~ /dod.zip/ {print $2}') | |
| bundle='https://dl.dod.cyber.mil/wp-content/uploads/pki-pke/zip/unclass-certificates_pkcs7_DoD.zip' | |
| # Set cert directory and update command based on OS | |
| [[ -f /etc/os-release ]] && source /etc/os-release | |
| if [[ ${ID:-} =~ (fedora|rhel|centos) || | |
| ${ID_LIKE:-} =~ (fedora|rhel|centos) ]]; then | |
| certdir=/etc/pki/ca-trust/source/anchors | |
| update='update-ca-trust' | |
| elif [[ ${ID:-} =~ (debian|ubuntu|mint) || | |
| ${ID_LIKE:-} =~ (debian|ubuntu|mint) ]]; then | |
| certdir=/usr/local/share/ca-certificates | |
| update='update-ca-certificates' | |
| else | |
| certdir=${1:-} && update=${2:-} | |
| fi | |
| [[ ${certdir:-} && ${update:-} ]] || { | |
| printf 'Unable to autodetect OS using /etc/os-release.\n' | |
| printf 'Please provide CA certificate directory and update command.\n' | |
| printf 'Example: %s /cert/store/location update-cmd\n' "${0##*/}" | |
| exit 1 | |
| } | |
| # Extract the bundle | |
| wget -qP "${tmpdir:=$(mktemp -d)}" "$bundle" | |
| unzip -qj "$tmpdir"/"${bundle##*/}" -d "$tmpdir" | |
| # Check for existence of PEM or DER format p7b. | |
| for file in "$tmpdir"/*_{DoD,dod}{.,_}{pem,der}.p7b; do | |
| # Iterate over glob instead of testing directly (SC2144) | |
| [[ -f ${file:-} ]] && | |
| form=${file%.*} && form=${form##*_} && form=${form##*.} && break | |
| done | |
| [[ ${form:-} && ${file:-} ]] || { printf 'No bundles found!\n' && exit 1; } | |
| # Convert the PKCS#7 bundle into individual PEM files | |
| openssl pkcs7 -print_certs -inform "$form" -in "$file" | | |
| awk -v d="$tmpdir" \ | |
| 'BEGIN {c=0} /subject=/ {c++} {print > d "/cert." c ".pem"}' | |
| # Rename the files based on the CA name | |
| for cert in "$tmpdir"/cert.*.pem; do | |
| mv "$cert" "$certdir"/"$( | |
| openssl x509 -noout -subject -in "$cert" | | |
| awk -F '(=|= )' '{print gensub(/ /, "_", "g", $NF)}' | |
| )".crt | |
| done | |
| # Remove temp files and update certificate stores | |
| rm -fr "$tmpdir" && $update | |
| } | |
| # Only execute if not being sourced | |
| [[ ${BASH_SOURCE[0]} == "$0" ]] || return 0 && add_dod_certs "$@" |
aaronlippold
commented
Nov 17, 2025
via email
I also need to investigate why remote downloading Of the Stig zips is no
longer working
…--------
Aaron Lippold
***@***.***
260-255-4779
twitter/aim/yahoo,etc.
'aaronlippold'
On Thu, Nov 13, 2025 at 13:31 Josiah Ritchie ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks @AfroThundr3007730 <https://github.com/AfroThundr3007730> for
keeping this working! While this is a simple gist, I appreciate you
maintain it like an open source project. Hopefully, DISA's latest changes
reduce the load for maintenance.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/AfroThundr3007730/ba99753dda66fc4abaf30fb5c0e5d012#gistcomment-5861795>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALK42FGLHRP4E77N7M7PND34TE6NBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJRRGE4TSNJXURXGC3LFVBQWG5DPOJPWSZECUV3GC3DVMWSHI4TVMWSG4YLNMW5XI2DSMVQWIX3QMFZHI2LDNFYGC3TUL5QWG5DJOZUXI6MCUV3GC3DVMWSGO2LTOSSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWVUO2LTORBW63LNMVXHJJTUN5YGSY3TSGBKI5DZOBS2IZ3JON2KK5TBNR2WLKJRGAZDCOBWGA4DBJ3UOJUWOZ3FOKTGG4TFMF2GK>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment