rumpeltux / onlineticket

Parser for online-tickets according to ETF-918.3
GNU General Public License v3.0
69 stars 10 forks source link

UIC 2.0 Tickets #16

Closed danielmarschall closed 6 months ago

danielmarschall commented 6 months ago

Hello @rumpeltux ,

thank you for the updates! The old tickets are now correctly decoded again.

The only problem is that UIC 2.0 tickets are not working. I think this should be a TODO for the future. (I guess it is a lot of work since UIC 2.0 has some fields changes). If you need test data, I'd be happy to give you two tickets I collected.

==== tickets/2023_10_13_ticket

Traceback (most recent call last):
  File "onlineticket/onlineticket.py", line 542, in <module>
    ot = OT(binary_ticket)
         ^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 84, in __init__
    self.header = self.dict_read(self.generic)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 116, in dict_read
    dat = val[3](self, res)
          ^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 463, in signature_decode
    decoded = asn1.decode(self.read(signature_length))[0]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1424, in __call__
    raise error.SubstrateUnderrunError(
pyasn1.error.SubstrateUnderrunError: 116<62 at <TagSet object, tags 0:0:9>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "onlineticket/onlineticket.py", line 545, in <module>
    fixed = fix_zxing(binary_ticket)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 523, in fix_zxing
    data = data.decode('utf-8').encode('latin1')
           ^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 15-16: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "onlineticket/onlineticket.py", line 549, in <module>
    (repr(ot), repr(fixed), ticket, e, f))
                    ^^^^^
NameError: name 'fixed' is not defined
==== tickets/2023_12_24_ticket

Traceback (most recent call last):
  File "onlineticket/onlineticket.py", line 542, in <module>
    ot = OT(binary_ticket)
         ^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 84, in __init__
    self.header = self.dict_read(self.generic)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 116, in dict_read
    dat = val[3](self, res)
          ^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 463, in signature_decode
    decoded = asn1.decode(self.read(signature_length))[0]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1446, in __call__
    raise error.SubstrateUnderrunError('%d-octet short' % (length - len(substrate)))
pyasn1.error.SubstrateUnderrunError: 37-octet short

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "onlineticket/onlineticket.py", line 545, in <module>
    fixed = fix_zxing(binary_ticket)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "onlineticket/onlineticket.py", line 523, in fix_zxing
    data = data.decode('utf-8').encode('latin1')
           ^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 19: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "onlineticket/onlineticket.py", line 549, in <module>
    (repr(ot), repr(fixed), ticket, e, f))
                    ^^^^^
NameError: name 'fixed' is not defined
rumpeltux commented 6 months ago

I’m not sure how the signature is structured in version 2 tickets, but otherwise the parsing seems to succeed, so I consider this fixed.

danielmarschall commented 6 months ago

Thank you very much for the fast reply and fix!

The UIC 2.0 tickets contain the following output:

OT
        header: b'#UT'
        version:        b'02'
        carrier:        b'1080'
        key_id: b'00002'
        signature:      ("SubstrateUnderrunError('116<62 at <TagSet object, tags 0:0:9>')", b'\t\xf4\x80\x05\xfd)u\r\xf8\x91\xbe\x9d\xea%I\xd4\x14+\x1b\xc1\xf7\t\x18Sa\xd0\xce\xf7n\x00\x11\x0b\x87\x82\xd3\xe8V\xb3\xe1\xf7KuF\xae\\\x1e\x8e\xc0\xf49\x9f\xdb\x8d\x15\n\xa0\x8c\xe4z\xec\x15\xcc\xfdd')
        data_length:    208
        signature_validity:     'INVALID (asn1 decode error)'
        ticket:
        0:      GenericBlock
                head:   b'U_FLEX'
                version:        13
                length: 197
                unknown_content:        ...................................

Not sure if anything can be done for U_FLEX version 13, maybe I can research that.