Perl to extract ssl certs from xml file


 
Thread Tools Search this Thread
Top Forums Programming Perl to extract ssl certs from xml file
# 1  
Old 03-01-2013
Perl to extract ssl certs from xml file

HI Guys,

I'm a newbie in perl.

Last edited by jhamaks; 07-17-2013 at 02:56 PM.. Reason: change in requirement
# 2  
Old 03-01-2013
Please wrap your exsample in CODE tags!
Is the following what you want?
Code:
perl -ne 'print if s|^<certificate FullCert="(.*)"/>|$1|' file.xml

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 03-05-2013
Need the perl code in a script, Not in one liner.

[QUOTE=MadeInGermany;302774275]Please wrap your exsample in CODE tags!
Is the following what you want?

Last edited by jhamaks; 07-17-2013 at 02:58 PM.. Reason: confidential data
# 4  
Old 03-05-2013
Code:
#!/usr/bin/perl
use strict;
use warnings;

open my ($in_fh), '<', 'infile.xml'
or die "Could not open input file: $!\n";

my %certs;

while(<$in_fh>) {
 push ( @{$certs{$2}}, $1) if (my ($cert, $name) = /^<certificate FullCert="([^"]+)".* name="([^"]+)"/);
}

close $in_fh;

for my $cert_name (keys %certs) {
 open my $out_fh, '>', $cert_name
 or warn "Could not open output file ($cert_name): $!\n";
 printf $out_fh "%s\n", $_ for (@{$certs{$cert_name}});
}

This User Gave Thanks to elixir_sinari For This Post:
# 5  
Old 03-05-2013
This is working!! :)

Quote:
Originally Posted by elixir_sinari
Code:
#!/usr/bin/perl
use strict;
use warnings;
 
open my ($in_fh), '<', 'infile.xml'
or die "Could not open input file: $!\n";
 
my %certs;
 
while(<$in_fh>) {
 push ( @{$certs{$2}}, $1) if (my ($cert, $name) = /^<certificate FullCert="([^"]+)".* name="([^"]+)"/);
}
 
close $in_fh;
 
for my $cert_name (keys %certs) {
 open my $out_fh, '>', $cert_name
 or warn "Could not open output file ($cert_name): $!\n";
 printf $out_fh "%s\n", $_ for (@{$certs{$cert_name}});
}


Perfect!!!! This is what i wanted...thanks a ton!! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract certs from apache ca-bundle.crt file?

Apache web server reads Certificate Authority(CA) certs from ../cert/ca-bundle.crt file for SSL authentication. It has all certs in PEM format and no way to know exactly what they are. I want to get each cert seperated by boundary strings into a file and feed it to "keytool" command to see what... (7 Replies)
Discussion started by: kchinnam
7 Replies

2. Programming

Extract Common Name (CN) of SSL certificate using perl code

Hello folks, I need a piece of code in perl which can read the file having multiple ssl certificates in text format one after the other as shown below. I need to parse this file and find out the common names of each of ssl certs it contains. E.g. -----BEGIN CERTIFICATE-----... (4 Replies)
Discussion started by: jhamaks
4 Replies

3. Shell Programming and Scripting

Extract a particular xml only from an xml jar file

Hi..need help on how to extract a particular xml file only from an xml jar file... thanks! (2 Replies)
Discussion started by: qwerty000
2 Replies

4. Red Hat

How to Find all the SSL certs on a give host Cent OS

Hi I am trying to find all the ssl certs installed/located on cent os Host , Please help . (1 Reply)
Discussion started by: smartguyz2012
1 Replies

5. Programming

Extract xml data and create word document using perl.

Hi, I have large xml data file.I need to extract node and some tags in the node and after I need to create word document. my XMl data is look like as below -<student> <number>24</number> <education>bachelor</bachelor> <specialization>computers</specialization> ... (3 Replies)
Discussion started by: veerubiji
3 Replies

6. Programming

extract xml data and create word document using perl.

hi, i have large xml file which contains students information, i need to extract student number and some address tags and create a word document for the extracted data. my data looking llike this <student> <number>24</number> <education>bachelors</education> ... (1 Reply)
Discussion started by: veerubiji
1 Replies

7. Shell Programming and Scripting

Perl script to extract 'ID' From XML File

File1.xml <?xml version.........> - <abcd:abcd_list version="1" www.john_uncle's_server.com" xmlns: - <device id="100"> <firmware>12.4(3d)</firmware> <location id="500">Sitting Room</location> </device> - <device id="101"> <firmware>12.4(3d)</firmware> <location id="501">Class... (1 Reply)
Discussion started by: sureshcisco
1 Replies

8. Shell Programming and Scripting

Perl script for extract data from xml files

Hi All, Prepare a perl script for extracting data from xml file. The xml data look like as AC StartTime="1227858839" ID="88" ETime="1227858837" DSTFlag="false" Type="2" Duration="303" /> <AS StartTime="1227858849" SigPairs="119 40 98 15 100 32 128 18 131 23 70 39 123 20 120 27 100 17 136 12... (3 Replies)
Discussion started by: allways4u21
3 Replies

9. UNIX for Advanced & Expert Users

ssl certs

Hi all can anyone tell me how i can discover the strength of encryption in an ssl cert. I have used various methods ie apps and verisign web page but they just give me general info. I need to know the encryption level. The cert in question is used in Weblogic application for Solaris 8 any... (1 Reply)
Discussion started by: silvaman
1 Replies
Login or Register to Ask a Question