kimgr / asn1ate

A Python library for translating ASN.1 into other forms.
Other
69 stars 41 forks source link

Hexa Value Constraint #35

Open Mourhamo opened 8 years ago

Mourhamo commented 8 years ago

Hi guys,

found a new issue, regarding to the size constraint: In case of a HexaString, the length have to be div by 2 file : constraint.py function : ValueSizeConstraint line 106 : l = len(value)/2 to count the number of OCTET

bye

Mourad

kimgr commented 8 years ago

Hello Mourad,

I'm having trouble seeing the bigger picture. What do you suggest asn1ate is doing wrong?

Thanks!

Mourhamo commented 8 years ago

Sorry I did the issue too quickly.

If ASN1 file define a variable with the terms : "fileID OCTET STRING (SIZE(2))" That means,it has to be an octet string of length 2 Octets

eg: fileID = '0102'

or in the function ValueSizeConstraint (in constraint.py) in line 106 we count the number of string characters and not octets

to day : line 106 : l = len(value) I corrected by : line 106 : l = len(value)/2 to count the number of OCTETs and not the string characters

in my case it correct the problem

kimgr commented 8 years ago

constraint.py is part of pyasn1, not asn1ate.

But it could very well be that asn1ate is producing the wrong data for pyasn1, so I don't think you should modify pyasn1.

Can you create a reproducible example and run it by the pyasn1 mailing list (cc me), and maybe we can work out together where the problem is, and how it should be solved?

Mourhamo commented 8 years ago

oh yes I'm quite lost in files :D Yes for sure i will

Mourhamo commented 8 years ago

Hi Kim,

In fact the probleme is not in pyasn1,

i was thinking that pyasn1 was expecting an hexa like 'FF0D'

but it wait for a b'\xFF\x0D', so the length in string is the double.

in asn1ate, a default Value 'FF0D'H is converted to 'FF0D'H (not a pretty python syntax) when it have to be converted by b'\xFF\x0D' to be pretty regarding to pyasn1

Sorry for the confusing issue :)

Mourad

kimgr commented 8 years ago

I think I understand what the problem is now, but a small, contained example ASN.1 fragment would definitely help.

Mourhamo commented 8 years ago

Here it is:

exctracted from the SimAlliance ASN1

ApplicationInstance ::= SEQUENCE { applicationLoadPackageAID [APPLICATION 15] ApplicationIdentifier, classAID [APPLICATION 15] ApplicationIdentifier, instanceAID [APPLICATION 15] ApplicationIdentifier, extraditeSecurityDomainAID [APPLICATION 15] ApplicationIdentifier OPTIONAL, applicationPrivileges [2] OCTET STRING, lifeCycleState [3] OCTET STRING (SIZE(1)) DEFAULT '07'H, /* Coding according to GP Life Cycle State. */

applicationSpecificParametersC9 [PRIVATE 9] OCTET STRING, systemSpecificParameters [PRIVATE 15] ApplicationSystemParameters OPTIONAL, applicationParameters [PRIVATE 10] UICCApplicationParameters OPTIONAL, processData SEQUENCE OF OCTET STRING OPTIONAL }

The line lifeCycleState [3] OCTET STRING (SIZE(1)) DEFAULT '07'H, define a Default value to '07'H or asn1ate will convert in python as '07'H (not python friendly) it has to be b'\x07' or binascii.unhexlify('07') but definitively not '07'H :)

Regards

kimgr commented 8 years ago

Thanks, just what I needed. I'll try and look into this.