LoraIlieva has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Receive certificate ASN1 structure
by haukex (Archbishop) on Sep 14, 2016 at 12:59 UTC | |
|
Re: Receive certificate ASN1 structure
by VinsWorldcom (Prior) on Sep 14, 2016 at 16:04 UTC |