software:openssl:installca
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
software:openssl:installca [2025/10/19 16:50] – rodolico | software:openssl:installca [2025/10/19 18:38] (current) – rodolico | ||
---|---|---|---|
Line 16: | Line 16: | ||
==== Automated Install ==== | ==== Automated Install ==== | ||
- | The simplest thing I can come up with is to create a share (SMB, whatever) that you can access from all machines, then place the CA Certificate (PEM file) in that share. A possible PowerShell script (untested so far) can be placed in that directory. Now, you can go to that directory on each machine and run the script. The script requires administrator privileges. | + | The simplest thing I can come up with is to create a share (SMB, whatever) that you can access from all machines, then place the CA Certificate (PEM file) in that share. A possible PowerShell script (untested so far) can be placed in that directory. Now, you can go to that directory on each machine and run the script. |
+ | |||
+ | The script requires administrator privileges. | ||
<code powershell installCA.ps1> | <code powershell installCA.ps1> | ||
+ | # Ensure this script runs as an administrator | ||
+ | if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]:: | ||
+ | throw "Run this script as Administrator!" | ||
+ | } | ||
+ | |||
+ | # change this to the actual name of your Certificate | ||
+ | $PemFileName = " | ||
+ | |||
+ | # Define the path to the PEM file | ||
+ | $CurrentDir = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
+ | $PemFilePath = Join-Path -Path $CurrentDir -ChildPath $PemFileName | ||
+ | |||
+ | # Check if PEM file exists | ||
+ | if (-Not (Test-Path $PemFilePath)) { | ||
+ | throw "CA PEM file not found at path: $PemFilePath" | ||
+ | } | ||
+ | |||
+ | # Import CA from PEM file using certutil | ||
+ | Write-Host " | ||
+ | |||
+ | certutil -addstore -f " | ||
+ | |||
+ | # Verify that the CA was imported successfully | ||
+ | $importedCA = Get-ChildItem Cert: | ||
+ | if ($importedCA) { | ||
+ | Write-Host " | ||
+ | $importedCA | Format-Table -Property Subject, Thumbprint | ||
+ | } else { | ||
+ | Write-Host " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Using GPO in a Windows Domain ==== | ||
+ | |||
+ | It is possible (untested) to run the above script from a GPO script to install the CA Certificate on many machines if they are connected to a Windows Domain. The following script is modified to work within a Windows Domain. | ||
+ | |||
+ | <code powershell installCADomain.ps1> | ||
# Ensure this script runs as an administrator | # Ensure this script runs as an administrator | ||
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]:: | if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]:: | ||
Line 71: | Line 110: | ||
</ | </ | ||
- | ==== Using GPO in a Windows Domain ==== | ||
- | It is possible (untested) to run the above script from a GPO script to install the CA Certificate on many machines if they are connected to a Windows Domain. | + | ===== Linux ===== |
+ | Each type of Linux distribution can have a different way of importing a CA, but the procedure is basically the same. | ||
+ | - Copy PEM to a specified directory | ||
+ | - run a command to update the list of CA's | ||
+ | ==== Debian derivatives ==== | ||
+ | |||
+ | <code bash> | ||
+ | sudo cp ca.pem / | ||
+ | sudo update-ca-certificates | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== RedHat Based ==== | ||
+ | <code bash> | ||
+ | cp pemfile / | ||
+ | update-ca-trust | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Automated for Unix ===== | ||
+ | |||
+ | The following script is suitable for use from a centralized server which has root access via ssh to multiple Unix machines. This is written for something like an Ansible server. | ||
+ | |||
+ | It will detect Debian and RedHat based Linux, and FreeBSD Unix. | ||
+ | |||
+ | It will | ||
+ | - copy pem file to the /tmp directory on the target machine | ||
+ | - Attempt to detect the operating system type | ||
+ | - If successful, copy pem to appropriate directory and run udpate command | ||
+ | - Otherwise, give an error message | ||
+ | |||
+ | Called as | ||
+ | <code bash> | ||
+ | ./ | ||
+ | </ | ||
+ | |||
+ | <code bash updateCALinux> | ||
+ | #!/bin/bash | ||
+ | |||
+ | # Check if the required parameters are provided | ||
+ | if [ $# -ne 2 ]; then | ||
+ | echo " | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | TARGET_MACHINE=$1 | ||
+ | CA_CERT_PATH=$2 | ||
+ | |||
+ | # Check if the CA certificate file exists locally | ||
+ | if [ ! -f " | ||
+ | echo "CA certificate not found at $CA_CERT_PATH" | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # Copy the CA certificate to the target machine | ||
+ | echo " | ||
+ | scp " | ||
+ | |||
+ | # Connect to the target machine and determine the OS | ||
+ | ssh root@" | ||
+ | # Detect the OS | ||
+ | if [ -f / | ||
+ | echo " | ||
+ | # Install the CA certificate | ||
+ | cp /tmp/ca.pem / | ||
+ | update-ca-certificates | ||
+ | | ||
+ | elif [ -f / | ||
+ | echo " | ||
+ | # Install the CA certificate | ||
+ | cp /tmp/ca.pem / | ||
+ | update-ca-trust | ||
+ | | ||
+ | elif [ " | ||
+ | echo " | ||
+ | # Install the CA certificate | ||
+ | cp /tmp/ca.pem / | ||
+ | c_rehash / | ||
+ | | ||
+ | else | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | echo "CA certificates updated successfully." | ||
+ | EOF | ||
+ | |||
+ | echo "CA certificate installation completed on $TARGET_MACHINE." | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== MacOS ===== | ||
+ | |||
+ | MacOS is based on FreeBSD and could likely be detected by the generic script under the previous section, but I'll show manual here. | ||
+ | |||
+ | ==== GUI ==== | ||
+ | |||
+ | - Open Finder, then navigate to Applications | Utilities | Keychain Access. | ||
+ | - Open File | Import Items | ||
+ | - Find your certificate and select Open | ||
+ | - Choose which keychain to import it to | ||
+ | - System - Available to all users | ||
+ | - login - Available only to the current user | ||
+ | - Locate the new Cert in the keychain and double click to open it | ||
+ | - Expand the **Trust** section | ||
+ | - Change //When using this certificate// | ||
+ | - Close and save, answering yes to all questions | ||
+ | |||
+ | |||
+ | ==== Command Line ==== | ||
+ | |||
+ | To install rapidly, simply open Terminal (Finder | Applications | Utilities | Terminal ) and issue the following command. You'll need to make sure you know where the PEM file is. | ||
+ | |||
+ | <code sh> | ||
+ | sudo security add-trust-anchor -d -r trustAsRoot -k / | ||
+ | </ |
software/openssl/installca.1760910620.txt.gz · Last modified: 2025/10/19 16:50 by rodolico