P1sec / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
GNU Lesser General Public License v2.1
380 stars 130 forks source link

CipherKeyData field is not parsed correctly when decoded #227

Closed Marc-Egli closed 1 year ago

Marc-Egli commented 1 year ago

Hello,

I am not sure I understand the behavior of the following snippet of code

from pycrate_mobile.NAS import *
from pycrate_mobile import *

val = {'CipherKeyData': ({ 'ValidityDuration': 16459},) }
msg = EMMAttachAccept(val=val)
# CipherKeyData fields are correctly presented
show(msg)

decoded_msg, err = parse_NASLTE_MT(msg.to_bytes())
# Decoding of the CipherKeyData field failed
if err != 0:
    print('Decoding error')
    print(err)
# CipherKeyData fields are not shown correctly anymore
show(decoded_msg)
# But this still holds
assert Msg.to_bytes() == msg.to_bytes()

I try to set the values in the CipherKeyData field but encountered this parsing error when I tried to decode the encoding of the message I just created.

The assertion still holds so I think this is not a big problem in terms of the generated data. I tried looking into how the CipherKeyData is handled but couldn't figure what the issue was.

Thanks in advance.

p1-bmu commented 1 year ago

I fixed this in the last commit, the C0 length was not automated as it should have been.

Marc-Egli commented 1 year ago

Thank you very much. I was not on the latest commit. Sorry for bothering.

p1-bmu commented 1 year ago

No problem, I fixed it thanks to your feedback.