I am trying to receive the ASN1 structure of a certificate with Convert::ASN1. I have my certificate in PEM format in a file.

This is what I did:

1. Read the PEM certificate

my $s_filename = 'path/to/file'; my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtim +e, $ctime, $blksize, $blocks) = stat $s_filename; open FILE, "<$s_filename" or die "no such file"; binmode FILE; my $pem_cert; read FILE, $pem_cert, $size; close FILE;

2. Remove 'BEGIN' and 'END'-CERTIFICATE

$pem_cert =~ /-----BEGIN CERTIFICATE-----(?:\r\n?|\n)(.+)(?:\r\n?|\n)- +----END CERTIFICATE-----/s; my $s_pem = $1;

3. Receive the DER format, because Convert::ASN1 works with DER or BER format

my $der   = MIME::Base64::decode($s_pem);

3. Create Convert::ASN1 object

my $asn = Convert::ASN1->new;

4. Configure the encoding of the object – to be DER, because by default Convert::ASN1 works with BER format

$asn->configure(encoding => 'DER');

5. Decode the DER format, which causes the problem

my $out = $asn->decode($der); if(!defined $out) { die $asn->error(); } print Dumper($out);

This is the output:

decode error 0 1918 at /.../Convert/ASN1/_decode.pm line 260.

When I tried to follow the execution using step-by-step debugger, I saw that there is nothing in ASN1's $self->{script}, but I can't understand what that variable stands for.

Can somebody help me?


In reply to 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.