Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

DigiCert – OpenSSL Certificate Conversion

Posted on March 9, 2017 By David Kittell

I work with digicert® to get certificates.

The way we get certificates sometimes requires me to convert the certificates, below is the process I use to get the formats for what I may need.

This script assumes you have a directory with only the .csr file and the .zip file from digicert® and then run the shell script.

#!/bin/sh

#  DigiCert.sh
#  
#
#  Created by David Kittell on 3/9/17.
#

sCurrentPath=$(pwd)

printf "Is $sCurrentPath the correct path for the certificates?, if yes type y or if no type n followed by [ENTER]:\n"
read sCertPath

case $sCertPath in
    [yY])
        sServerCertPath=$sCurrentPath
    ;;

    *)
        printf "Type the path of the certificates, followed by [ENTER]:\n"
        read sServerCertPath
        cd $sServerCertPath
    ;;
esac

# Check CSR File
#openssl req -text -noout -verify -in *.csr
CSRInfo=$(openssl req -text -noout -verify -in *.csr)
CSRCommonName=$(echo "$CSRInfo" | grep 'Subject:'  | cut -d '=' -f7 | sed "s|Subject:||" | sed 's/^ *//;s/ *$//')
CSRSANs=$(echo "$CSRInfo" | grep -A1 'Alternative Name' | grep -v 'Alternative Name' | sed "s|DNS:||g"| sed 's/^ *//;s/ *$//')

echo "Certificate Information:\n      Common Name: $CSRCommonName\n      Additional Names: $CSRSANs\n" > ReadMe.txt

# Unzip all files within zip in the current directory
unzip -j *.zip

sServerCert=$(find . -type f  ! -name '*.txt' ! -name '*.csr' ! -name '*.zip' | grep -v -e 'DigiCertCA.crt' -e 'TrustedRoot.crt' | sed "s|./||")
#echo $sServerCert

clear

printf "Is $sServerCert the correct certificate?, if yes type y or if no type n followed by [ENTER]:\n"
read sServer

case $sServer in
    [yY])
    ;;

    *)
        printf "Type the name of the server certificate, followed by [ENTER]:\n"
        read sServerCert
    ;;
esac

#echo $sServerCert

sServerCertNoExt=${sServerCert%.crt}
#echo $sServerCertNoExt

# Check CRT File
#openssl x509 -in $sServerCert  -text -noout

# Convert CRT to PEM
openssl x509 -in $sServerCert -outform PEM -out $sServerCertNoExt.pem

# Use PEM with CA CRT to create p7b
openssl crl2pkcs7 -nocrl -certfile $sServerCertNoExt.pem -out $sServerCertNoExt.p7b -certfile DigiCertCA.crt

# Create PFX
echo "Creating the PFX file, type an export password and confirm it."
openssl pkcs12 -export -nokeys -in $sServerCertNoExt.p7b -out $sServerCertNoExt.pfx -certfile TrustedRoot.crt

echo "\nPFX Location:\n      $sServerCertPath\nPFX Export Password:\n      Look in Password Safe" >> ReadMe.txt

mkdir -p Original_Files/CSR Original_Files/DigiCert CRT Combined_Files

mv $sServerCertNoExt.p7b $sServerCertNoExt.pem Combined_Files

mv *.csr Original_Files/CSR
echo "\nOriginal CSR Location:\n      $sServerCertPath/Original_Files/CSR" >> ReadMe.txt

mv INSTALL_INSTRUCTIONS* Original_Files/DigiCert
mv *.crt CRT
echo "\nDigiCert CRT Location:\n      $sServerCertPath/CRT" >> ReadMe.txt
mv *.zip Original_Files/DigiCert
echo "\nDigiCert Zip Location:\n      $sServerCertPath/Original_Files/DigiCert" >> ReadMe.txt

# Extract the key file from the PFX
#openssl pkcs12 -in $sServerCertNoExt.pfx -nocerts -out $sServerCertNoExt.key -nodes

# Extract the cert file from the PFX
#openssl pkcs12 -in $sServerCertNoExt.pfx -nokeys -out $sServerCertNoExt.cer

echo "\n\nInstallation Instructions:\n      General: https://www.digicert.com/ssl-certificate-installation.htm\n      Apache: https://www.digicert.com/ssl-certificate-installation-apache.htm\n      Tomcat: https://www.digicert.com/ssl-certificate-installation-tomcat.htm" >> ReadMe.txt

echo "Conversion Process Complete"
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

CentOS Code Fedora Mac OS X Shell Mac OSX OpenSSL Red Hat Ubuntu UNIX UNIX Shell Scripts .crt.p7b.pfxcerdigicertOpenSSLpemSSL

Post navigation

Previous post
Next post

Related Posts

Mac OSX Terminal – Add User to Remote Management (VNC)

Posted on November 16, 2016November 16, 2016

Replace “-users admin” with the username you need to grant access to. sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -users admin -privs -all -restart -agent -menu All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system…

Read More

UNIX – Extract RedHat/CentOS/Fedora RPM File

Posted on April 21, 2016April 21, 2016

I love to find RPM files that someone has compiled so that I don’t have to do the manual work but when I find one at a questionable location or one I’m simply not familiar with it’s nice to know what is in it. Recently I did a search on…

Read More

PowerShell – PowerShell Installed/Compatible Version

Posted on December 14, 2015

Possibly one of my important commands is to find out what version I have available on the computer. There are various ways to get this and some are rather long and arduous in comparison clear Write-Output "Get-Host (Really Only For 1.0, use once of the two below instead)" get-host |…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes