Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASN1 length long length issue. #9

Open
Adamhingoro opened this issue Sep 18, 2021 · 3 comments
Open

ASN1 length long length issue. #9

Adamhingoro opened this issue Sep 18, 2021 · 3 comments

Comments

@Adamhingoro
Copy link

ASN1 has 2 implementations for the data length.

  • short ( < 127 )
  • long ( > 127 )

then the IE value length is greater than 127 it still encodes/decodes the length in the shorter implementation thus not able to communicate with any other ASN1 service.

@wmnsk
Copy link
Owner

wmnsk commented Sep 25, 2021

Thanks. Could you point out which code exactly causes the problem?

@Adamhingoro
Copy link
Author

In almost all interfaces of the UnmarshalBinary and MarshalTo functions.
You have used 2 by default of length attribute.

but for longer ASN it could be different.

@anilk247
Copy link

func (t *Transaction) UnmarshalBinary(b []byte) error {
t.Type = Tag(b[0])
t.Length = b[1]

var err error
var offset = 2

.....

Above is the one of the places where it needs to be fixed. Got it fixed locally like below

func (t *Transaction) UnmarshalBinary(b []byte) error {

var err error
var offset = 2

t.Type = Tag(b[0])
if b[1] & 0x80 == 0 {
    t.Length = b[1]
} else {
   lenOfLen =  b[1] & 0x0f
   offset += lenOfLen
   t.Length = byteSlice2Int (b[2:2+ lenOfLen]
}

.....

func byteSlice2Int(data []byte) int {

exp := float64(len(data) - 1)
var i, res int

for i = 0; i < len(data); i = i + 1 {
    res = res + int((math.Exp2(8*exp) * float64(data[i])))
    exp = exp - 1
}

return res

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants