Click here to get back home

Convert::ASN1 - Decode error

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Convert::ASN1 - Decode error patg007 06-02-2005
Get Chitika Premium
Posted by patg007 on June 2, 2005, 9:46 am
Please log in for more thread options


Hi all,

I want to decode a .der file. I upgrade my version to 0.19 but I still
have the same trouble, when I use Data Dumper it gives :
'error' => 'decode error at
/usr/lib/perl5/site_perl/5.8.1/Convert/ASN1/_decode.pm line 123
but asn_dump works find, my asn.1 seems ok.

In fact when I do a decode like that $data =
$structure->decode($dataToCheck);
Dumper of $data gives $VAR1 = undef;
So after when I want to do a $data->->; of course
it prints nothing.

I set the option $asn->configure( decode => { encoding => DER } );
before, don't know if the problem occurs because of that.

I would like to know if somebody had the same problem before and from
what it could come from. I can send my little program if somebody wants
more details.

Regards,
Pat.



Posted by Sisyphus on June 3, 2005, 2:53 pm
Please log in for more thread options



> Hi all,
>
> I want to decode a .der file. I upgrade my version to 0.19 but I still
> have the same trouble, when I use Data Dumper it gives :
> 'error' => 'decode error at
> /usr/lib/perl5/site_perl/5.8.1/Convert/ASN1/_decode.pm line 123
> but asn_dump works find, my asn.1 seems ok.
>
> In fact when I do a decode like that $data =
> $structure->decode($dataToCheck);
> Dumper of $data gives $VAR1 = undef;
> So after when I want to do a $data->->; of course
> it prints nothing.
>
> I set the option $asn->configure( decode => { encoding => DER } );
> before, don't know if the problem occurs because of that.
>
> I would like to know if somebody had the same problem before and from
> what it could come from. I can send my little program if somebody wants
> more details.
>

Post the program here. It's quite acceptable to do that - in fact, it's
expected of you. It's also expected that the script you post be as small as
you can make it, but still demonstrate the problem that you're facing.

Cheers,
Rob




Posted by patg007 on June 3, 2005, 2:53 am
Please log in for more thread options


Ok thanks Rob. I'm quite new on forums.
Well I don't see a way to post files by google so I copy that directly
here. I can't copy the .der file too so you'll not be able to test it.
I will try to post that to your email, to attach the 2 files. Or do you
know another way ?

Here is a resume of my perl program. It still have 168 lines but
because of the asn.1 structure. Tested with Convert::ASN1 v0.19 (the
last). If you copy and test it with the good .der it prints debug
infos, I mean it is totally operationnal for tests.
Regards,
Pat.

#!/usr/bin/perl
##############################
# we want to read a asn.1 file
##############################
use Convert::ASN1 qw(:all);
use Getopt::Long;
use Data::Dumper;

my ($file, $data, $dataToCheck);

# -file answer.der
GetOptions ('file=s' => $file);

# read asn.1 file
my $fileSize = (stat($file))[7];
print "\nsize $fileSize";
print "\nfile $file";

open(INPUT, $file) || die "can't open $file: $!\n";
binmode INPUT;
read INPUT, $dataToCheck, $fileSize;
close(INPUT);

my $asn = Convert::ASN1->new;
# we use Der not Ber
$asn->configure( decode => { encoding => DER } );

# the asn.1
$asn->prepare(q<
        SerValResponse ::= SEQUENCE {
        responseStatus         SerValResponseStatus,
        responseBytes [0] EXPLICIT ResponseBytes OPTIONAL
        }

        SerValResponseStatus ::= ENUMERATED {
        successful (0),
        malformedRequest (1),
        internalError (2),
        tryLater (3),
--(4)
        sigRequired (5),
        unauthorized (6)
        }

        ResponseBytes ::= SEQUENCE {
        responseType OBJECT IDENTIFIER,
        response BasicSerValResponse
        }

        responseValue ::= CHOICE {
        basicResponse BasicSerValResponse
        }

        BasicSerValResponse ::= SEQUENCE {
        tbsResponseData ResponseData,
        signatureAlgorithm AlgorithmIdentifier,
        signature BIT STRING,
                certs EXPLICIT SEQUENCE OF Certificate
}

        ResponseData ::= SEQUENCE {
         version [0] INTEGER,
nonce INTEGER,
responderID ResponderID,
         producedAt GeneralizedTime,
         responses SingleResponse,
         responseExtensions [1] EXPLICIT Extensions OPTIONAL
}

        ResponderID ::= CHOICE {
        byName [1] IA5String
        }

        SingleResponse ::= SEQUENCE {
        certificate Certificate,
        certStatus CertStatus,
        thisUpdate GeneralizedTime,
nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
         singleExtensions [1] EXPLICIT Extensions OPTIONAL
}

        CertStatus ::= CHOICE {
                good [0] IMPLICIT IA5String,
        revoked [1] IMPLICIT RevokedInfo,
        invalid [2] IMPLICIT InvalidInfo
        }

        RevokedInfo ::= SEQUENCE {
                revocationTime GeneralizedTime,
                revocationReason [0] EXPLICIT CRLReason OPTIONAL
        }

        InvalidInfo ::= ENUMERATED {
unknown (0),
invalidValPolicy (1),
invalidCertPolicy (2),
invalidKeyUsage (3),
invalidTrustedPath (4),
outdatedCertificate (5),
invalidExtKeyUsage (6)
        }

        Extensions ::= SEQUENCE OF Extension

        Extension ::= SEQUENCE {
         extnID OBJECT IDENTIFIER,
critical BOOLEAN,
extnValue OCTET STRING
        }

        CRLReason ::= ENUMERATED {
                unspecified (0),
                keyCompromise (1),
                cACompromise (2),
                affiliationChanged (3),
                superseded (4),
                cessationOfOperation (5),
                certificateHold (6),
                removeFromCRL (8)
        }

        AlgorithmIdentifier ::= SEQUENCE {
                algorithm                OBJECT IDENTIFIER,
                parameters                ANY
        }

        CertificateValue ::= SEQUENCE {
                oneCertificate        Certificate
        }

        Certificate ::= OCTET STRING
>);

# choose what we want to read
my $structure = $asn->find('SerValResponse');

if ($asn->error ne '') { print "\nError: " . $asn->error; }
if ($structure->error ne '') { print "\nError: " . $structure->error; }

# link data to asn.1 structure
$data_1 = $structure->decode($dataToCheck);

print "\n";
print "Dumper structure";
print" ==================================================\n";
print Dumper ($structure);
print "\nDumper data";
print" ==================================================\n";
print Dumper ($data_1);

# what we want to have : this doesn't work
print "\nresponseStatus ".
$data_1->-> ."\n";

# For tests
print"==================================================\n";
print "structure\n";
asn_dump($structure);
print"==================================================\n";
print "data\n";
asn_dump($data_1);
print"==================================================\n";
print "asn\n";
asn_dump($asn);
print"==================================================\n";
print "dataToCheck\n";
asn_dump($dataToCheck);



Posted by patg007 on June 3, 2005, 2:57 am
Please log in for more thread options


oups on google I can't see your email entirely so...

Pat.

patrick.grenier@gmail.com



Posted by patg007 on June 3, 2005, 3:08 am
Please log in for more thread options


well, thanks google !
they cut email ?? funny...
ok I try this :

patrick.grenier



Similar ThreadsPosted
Convert from base64 to TIFF or BMP or JPG September 24, 2004, 12:15 am
Is there any way to convert swf file to bitmap? March 30, 2006, 4:58 am
Module to convert emails February 25, 2007, 2:20 pm
how to convert decimal to hexadecimal in perl July 12, 2004, 8:30 am
Convert a PDF document into MS Word docuemnt October 6, 2006, 7:26 am
Convert MS-Word to plain text May 9, 2008, 1:29 pm
module to convert wiki-style to html June 16, 2005, 3:09 pm
OLE Module - Need to convert Excel VB Macro to perl August 3, 2005, 9:06 am
How to convert ArrayOfstring in SOAP into an array of PERL? July 24, 2007, 3:25 pm
Error: RCPT TO: error (550 relay not permitted) February 11, 2006, 1:39 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap