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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.