Convert::ASN1 - Decode error
am 02.06.2005 17:46:39 von patg007
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->{'field1'}->{'field2'}; 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.
Re: Convert::ASN1 - Decode error
am 03.06.2005 05:53:42 von Sisyphus
"patg007" wrote in message
news:1117727199.408585.273500@f14g2000cwb.googlegroups.com.. .
> 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->{'field1'}->{'field2'}; 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
Re: Convert::ASN1 - Decode error
am 03.06.2005 10:53:07 von patg007
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->{'responseStatus'}->{'SerValResponseStatus'} ."\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);