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

OpenSSL – Decode/Read CSR

Posted on January 5, 2018 By David Kittell

Sometimes you when a SSL CSR isn’t named properly you need to get the details of it, the code below will help.

Note: Depending on version and OS the placement numbers (-f5 for example) may be slightly off.

#!/bin/sh

#  ReadSSLCSR.sh
#  
#
#  Created by David Kittell on 1/5/18.
#

csrFile="$1"
csrText=$(openssl req -in $csrFile -noout -subject)
csrCountry=$(echo $csrText | cut -d '/' -f2 | cut -d '=' -f2)
csrState=$(echo $csrText | cut -d '/' -f3 | cut -d '=' -f2)
csrCity=$(echo $csrText | cut -d '/' -f4 | cut -d '=' -f2)
csrOrganization=$(echo $csrText | cut -d '/' -f5 | cut -d '=' -f2)
csrDepartment=$(echo $csrText | cut -d '/' -f6 | cut -d '=' -f2)
csrCN=$(echo $csrText | cut -d '/' -f7 | cut -d '=' -f2)
csrEmail=$(echo $csrText | cut -d '/' -f8 | cut -d '=' -f2)

clear
echo "CSR Details Of $csrFile:"
echo "Country:       $csrCountry"
echo "State:         $csrState"
echo "City:          $csrCity"
echo "Organization:  $csrOrganization"
echo "Department:    $csrDepartment"
echo "Common Name:   $csrCN"
echo "Email Address: $csrEmail"

Once you have created the shell script call to it with the code below. Note: the file extension isn’t really necessary as long as the text is truly a CSR.

sh ReadSSLCSR.sh ~/RandomCSR.csr
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

Code OpenSSL SSL UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

List Views In Database

Posted on February 25, 2013October 26, 2015

SELECT name FROM sys.views ORDER BY name SET NOCOUNT ON DECLARE @ViewName AS nVarChar(128) , @Query AS nVarChar(500) /* Declare Cursor */ DECLARE Cur_Views CURSOR FOR SELECT name FROM [sys].[all_views] x WHERE x.schema_id = 1 — Loop through the views. OPEN Cur_Views — Fetch the first view FETCH NEXT FROM…

Read More

MSSQL – Sort By Day Of Week

Posted on March 21, 2014October 26, 2015

This script utilizes this Format Date Function to sort results based on a day of the week. The case statement in this query is easy to update if your region has a different day for the start of the week. This particular script is part of a metric that I…

Read More

PHP – File Download

Posted on March 16, 2016

When WGET isn’t available PHP comes to the rescue. In this example $path file name can be different than the $url file name or the same, if it is different it will be saved with the file name in $path set_time_limit(0); //Unlimited max execution time $path = ‘filetodownload.txt’; $url =…

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
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes