Hi LoraIlieva,
I haven't used this module before, but if you look at the Convert::ASN1 distribution, in the examples you'll find the script x509decode (in fact, part of your code looks like you got it from there). It contains a lot of supporting ASN.1 definitions that I'm assuming you can't do without; my guess is that's what your script is currently missing. However, it looks like the "x509decode" script will only process files in binary format. I took your MIME::Base64 decoding idea, inserted it into that script, tested it, and it looks like it is able to decode an example .pem file. My modified while loop looks like this:
use MIME::Base64 qw/decode_base64/; while ( my $filename = shift ) { my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat $filename; open FILE, "<$filename" or die "no such file"; binmode FILE; my $pem_cert; read FILE, $pem_cert, $size; close FILE; $pem_cert =~ /-----BEGIN CERT\w*-----(.+?)-----END CERT\w*-----/s; my $der = decode_base64($1); decodeCert( $der ); }
Hope this helps,
-- Hauke D
Updated wording slightly. Update 2: Replaced the regex to be a little more selective.
In reply to Re: Receive certificate ASN1 structure
by haukex
in thread Receive certificate ASN1 structure
by LoraIlieva
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |