pbock / ticket-parser

Parse the Aztec code in Deutsche Bahn's train tickets
MIT License
95 stars 4 forks source link

zlib header form aztec is different #2

Closed jurkov closed 6 years ago

jurkov commented 6 years ago

Hello, the zlib header of my tickets are 0x78, 0x3f and not 0x78, 0x9c. Do you have any idea how to decode the content?

justusjonas74 commented 6 years ago

I'm not a maintainer of the project, but interested in the ticket data. Could you upload a sample ticket?

justusjonas74 commented 6 years ago

Another idea: Which lib/tool do you use for reading the barcode. I had some troubles with 'zxing' (and all other libs using zxing) due to the encoding.

I fixed it like this (sure not the best way):

var iconv = require('iconv-lite')
function fixingZXing (buffer) {
  const latin1str = iconv.decode(buffer.toString('utf-8'), 'ISO-8859-1')
  return Buffer.from(latin1str, 'latin1')
}
justusjonas74 commented 6 years ago

The barcode isn't a UIC-918.3 barcode. UIC-918.3 is the main data format for rail traffic tickets. The barcode on the PDF is a VDV Barcode or Statische Berechtigung. This is a special format which is only used in Germany for local transport. It's not supported by this lib.

The specs of this format are published here (German only).

const extractAztec = require('ot-aztec-extract');
const zxing = require('zebra-crossing');
const TicketParser = require('ticket-parser');
const iconv = require('iconv-lite');
const fs = require('fs');

function read(pdfPath) {
  return extractAztec(fs.readFileSync(pdfPath))
  .then(png => zxing.read(png, { pureBarcode: true }))
  .then(data => iconv.encode(data.raw, 'latin1'))
  .then(x => console.log(x.toString()))
}

read('./flt-3ww74b4100-0.pdf')

Output (look for VDV):

���\�
��     ����s��D�vaI�0c��),���q��eaF�\F��c�qo�� ��+ �~�ޗl���<��t�d�
WRr���vݚ�.�P�eT���
                  ���(Q�        �����
                                     �:�4�.�.�}�VDV!��_7��z~����f�����*�ؽ�s��a��k7Rg
                                                                                    Q�����ۇyJ􊹬�[�|��l�����s
?��@Wu������>�'�`zÚ�o!�b�b⯏++�yi��p���#��_8�DEVDV�/�[������2���I S
pbock commented 6 years ago

TIL, because of course there’s a separate format. Thanks for diagnosing this, @justusjonas74!

justusjonas74 commented 6 years ago

Anyone interested in a lib for parsing this format? I guess it's a bit more complex than the UIC barcode...

vkrause commented 4 years ago

We have a decoder for the VDV format here now: https://github.com/KDE/kitinerary/tree/master/src/vdv, that at least gets you past the crypto to the actual payload. There's a number of operator-specific numbers and codes in there that this can't translate yet, but it for example finds some privacy-relevant details in the above sample, such as name, gender and birthdate.

pbock commented 4 years ago

That’s great news! Do you think it would make sense to include VDV compatibility in this library? In that case I’d be grateful for any help because I have no experience with linking to non-JS libraries and no longer live in Germany (which makes testing difficult and dependent on donated data).

I suppose there might also be an incompatibility between the MIT and GNU licences.


As a precaution, I’ve removed this comment by @jurkov due to potential personal data in the linked PDF:

I'm sorry i can't give you my pdf. But you can try this [redacted]

I used zebra-crossing and ot-aztec-extract as descript in #1 . To get the content of the aztec use

function read1(pdfPath) { var ret = extractAztec(fs.readFileSync(pdfPath)) .then(png => zxing.read(png, { pureBarcode: true })) .then(data => iconv.encode(data.raw, 'latin1')) .then(data => fs.writeFileSync('blob.blob', data)) }

Originally posted by @jurkov in https://github.com/pbock/ticket-parser/issues/2#issuecomment-396940827

vkrause commented 4 years ago

I have no idea about the integration, neither technically nor from a use-case POV, sorry. I mainly posted this here as this is one of the very few public discussions on this subject I found while digging into this. In case someone wants to integrate the VDV code elsewhere I'm of course happy to discuss how to support and simplify that, both technically and regarding licenses, if that should turn out to be a problem :)

pbock commented 4 years ago

Thanks! As I have neither the know-how nor much of a use-case, I’ll add a few words to the readme in the hopes of pointing people in the direction of this discussion. Pull requests are gladly accepted!

mBednarz92 commented 1 year ago

I have no idea about the integration, neither technically nor from a use-case POV, sorry. I mainly posted this here as this is one of the very few public discussions on this subject I found while digging into this. In case someone wants to integrate the VDV code elsewhere I'm of course happy to discuss how to support and simplify that, both technically and regarding licenses, if that should turn out to be a problem :)

As I am fighting with some project related to reading and parsing data of VDV ticket. Can I kindly ask you to share your solution again? I can see that is no longer avalible for some reason :(

mBednarz92 commented 1 year ago

Anyone interested in a lib for parsing this format? I guess it's a bit more complex than the UIC barcode...

I am working on that as my job project, but I think it would be extremely useful if we could share this lib as open source. Let me know if interested :)