Sponsored Content
Top Forums Programming Extract Common Name (CN) of SSL certificate using perl code Post 302837925 by spacebar on Saturday 27th of July 2013 04:15:39 PM
Old 07-27-2013
This is a simple example of separating them out to separate files:
Code:
#!/usr/bin/perl -w
# Script: get_certs.pl

use strict;
use warnings;

my @a;
my $fh;
my $i;
my $p;
my $fn;

sub write_to_file;

chomp ( @a=<DATA> );

for $i ( 0 .. $#a ) {
  if ( $a[$i] =~ m/BEGIN CERTIFICATE/ ) {
    $p  = $i + 1;
    $fn = $a[$p] . ".cert";
    open ( $fh, ">$fn" );
    write_to_file( "$a[$i]" );
  } elsif ( $a[$i] =~ m/END CERTIFICATE/ ) {
    write_to_file( "$a[$i]" );
    close $fh;
  } else {
    write_to_file( "$a[$i]" );
  }
}
sub write_to_file {
  print $fh "$_[0]\n";
}

__DATA__
--------------------BEGIN CERTIFICATE------------------
MIID2TCCAsGgAwIBAgIDAjbQMA0GCSqGSIb3DQEBBQUAME
4NwdzxoQ2KDLX4z6DOW/cf/lXUQdpj6HR/oaToODEj+IZpWYeZqF
                             :                             
                             :
6wJHzSXj8gYETpnKXKBuervdo5AaRTPvvz7SBMS24CqFZUE+ENQ=
--------------------END CERTIFICATE-----------------------
--------------------BEGIN CERTIFICATE----------------------
MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAME
IxCzAJBgNVBAYTAlVTAq45pmp0sdhsdkslswqpywmcperewe
                           :                             
                           :                              
hw4EbNX/3aBd7YdStysV6drE57xNNB6pXE0zX5IJL4hmXXeXx
x12E6nV5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3=
--------------------END CERTIFICATE-----------------------

Creates these files:
Code:
$ ls *.cert
MIID2TCCAsGgAwIBAgIDAjbQMA0GCSqGSIb3DQEBBQUAME.cert  MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAME.cert

$ cat MIID2TCCAsGgAwIBAgIDAjbQMA0GCSqGSIb3DQEBBQUAME.cert
--------------------BEGIN CERTIFICATE------------------
MIID2TCCAsGgAwIBAgIDAjbQMA0GCSqGSIb3DQEBBQUAME
4NwdzxoQ2KDLX4z6DOW/cf/lXUQdpj6HR/oaToODEj+IZpWYeZqF
                             :
                             :
6wJHzSXj8gYETpnKXKBuervdo5AaRTPvvz7SBMS24CqFZUE+ENQ=
--------------------END CERTIFICATE-----------------------

$ cat MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAME.cert
--------------------BEGIN CERTIFICATE----------------------
MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAME
IxCzAJBgNVBAYTAlVTAq45pmp0sdhsdkslswqpywmcperewe
                           :
                           :
hw4EbNX/3aBd7YdStysV6drE57xNNB6pXE0zX5IJL4hmXXeXx
x12E6nV5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3=
--------------------END CERTIFICATE-----------------------

Moderator's Comments:
Mod Comment Removed FONT tags from within CODE tags again. Please don't use them.
This User Gave Thanks to spacebar For This Post:
 

9 More Discussions You Might Find Interesting

1. Web Development

SSL Certificate Installation problem

Hello everybody Hope somebody can help me I'm trying to install SSL Certificate on Apache/mod_ssl on Linux with Zend for Oracle. I bought and downloaded certificate from certificate from Network Solutions. Than I followed the instructions to the dot. I created a directory for certificate... (2 Replies)
Discussion started by: Trusevich
2 Replies

2. Web Development

SSL certificate

Dear All Anyone know how to issue two different certification on apache virtualhost fyi i have one virtualhost eg 69.192.1.25:443 already signed with verisign how can i configure another virtualhost 69.192.1.25:443 which signing with another certificate which self signing. i search net not... (1 Reply)
Discussion started by: netxus
1 Replies

3. AIX

Installing SSL certificate on AIX

Hello, I am new in UNIX, and some one asks me to install SSL certificates to allow exchange with an external system. Can someone tell how to install certificate (ex : verisignxxx.cer) on a UNIX server? Many thanks. Tibo (4 Replies)
Discussion started by: tibo51
4 Replies

4. Cybersecurity

SSL certificate

Hi guys. I have some questions about ssl certificates. I looked at SSL providers and saw that they are providing 2 types of certificates: per server or per domain. my server host name is: srv1.example.com I have a smtp, imap, web server on this box. but all services accessed by different... (1 Reply)
Discussion started by: majid.merkava
1 Replies

5. Web Development

export SSL certificate

we are doing TCP for our systems. I have a working SSL certificate on prodction webserver. Im planning to export it to our DR server for TCP purposes. However when I export based on the procedure below, it doesn't work. When I restart the DR webserver, it still says the certifcate is expired.Any... (1 Reply)
Discussion started by: lhareigh890
1 Replies

6. Red Hat

SSL Certificate Renewal on Tomcat

Hi, I want to renew the ssl certificate for one of my application on tomcat without down time. I want to know what would the possible impacts for the users who currently have sessions to the app. Regards, Arumon (1 Reply)
Discussion started by: arumon
1 Replies

7. Programming

Perl to extract ssl certs from xml file

HI Guys, I'm a newbie in perl. (4 Replies)
Discussion started by: jhamaks
4 Replies

8. Cybersecurity

SSL Certificate Stores

Hey everyone, I'm trying to get a lay of the land for OS and Application Certificate Stores. Can someone confirm that I have this concept right? If the application you're using say Firefox has it's own trusted CA store, it uses that exclusively. So if you're running firefox in Windows, Firefox... (4 Replies)
Discussion started by: Lost in Cyberia
4 Replies

9. Web Development

CronJobs issues after SSL certificate

Hello! I had a cron job running on my website, activating a php script every friday. The Php script just activated another photo to add in the gallery. It worked fine until I got an SSL certificate for my website, then everything broke. This was the command before: lynx -source... (0 Replies)
Discussion started by: AGDesign
0 Replies
All times are GMT -4. The time now is 11:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy