juks / iso-8583-socket-queue

ISO 8583 gateway
MIT License
194 stars 111 forks source link

Packer for field 53 #16

Closed temper5 closed 6 years ago

temper5 commented 6 years ago

What the packer I can use for field 53? In specification this field consist from two sub fields f53a – lenght and f53b – data.

Field 53: Security Related Control Information Subfield 53a: Key Length Format n 2 Description In request and response messages this field contains length of Subfield 53b; Host should send Subfield 53a in the response message to POS terminal if terminal sent valid Subfields 53a and 53b in the request message to host. The key length in response message can be single length (8 byte), double length (16 bytes) or triple length (24 bytes) if key is in BCH representations. Subfield 53b: Key Information Format b 8/16/24 Description In request messages this subfield identifies maximum key length for key change transactions. Valid values are: 01 – single, 02 – double, 03 – triple key length. NOTE: The lengths have been converted to reflect their BCH representations. In response messages this subfield identifies security management information used in the current transaction or specifies security management information to be used in future transactions. This field is currently being used to supply new keys to devices for key change transactions. These keys can be either Single Des (8bytes) or Triple Des (16 or 24 bytes). NOTE: The lengths have been converted to reflect their BCH representations.

This is my "tmp" packager config for field 53:

'53': { length: 24, name: 'Security Related Control Information', type: 'b', alias: ''

In the example problem in response message where field53 not seems like not binary: cat ./800_TAK.txt - | nc localhost 2014

2017-07-21 13:07:35 - info: Important: starting... 2017-07-21 13:07:35 - info: Remote host configuration name: tmp 2017-07-21 13:07:35 - info: Connecting to upstream server localhost:5000 2017-07-21 13:07:35 - info: Relay raw ISO-8583 server is now running on port 2014 2017-07-21 13:07:35 - info: Echo server is now running on port 5000

2017-07-21 13:07:35 - info: Connected to upstream 127.0.0.1:5000! 2017-07-21 13:07:35 - info: Processing queue [pending 0 / total 0] 2017-07-21 13:07:35 - info: The queue is empty 2017-07-21 13:07:38 - info: Client ::1:34696 connected 2017-07-21 13:07:38 - info: Client ::1:34696 sent data (49b) 2017-07-21 13:07:38 - verbose: [0800........9900000619000000123456815170B0100000.] 2017-07-21 13:07:38 - verbose:

::1:34696

 [Echo Request]

 Message Type Indicator [0].......................0800
 Bitmap [1].......................................2220010800800800
 Processing Code [3]..............................990000
 Transmission Date and Time [7]...................0619000000
 System Trace Audit Number [11]...................123456
 Function Code [24]...............................815
 Batch Number [29]................................170
 Card Acceptor Terminal Identification [41].......B0100000
 Security Related Control Information [53]........02

================================================================================================

2017-07-21 13:07:38 - info: Writing to queue ::1:34696 [0] 2017-07-21 13:07:38 - info: New queue item 1 2017-07-21 13:07:38 - info: Processing queue [pending 1 / total 1] 2017-07-21 13:07:38 - verbose: Queue keys dump: 1 2017-07-21 13:07:38 - info: Upstreaming data for ::1:34696 2017-07-21 13:07:38 - verbose: [.....00490800........9900000619000000123456815170B0100000.] 2017-07-21 13:07:38 - verbose: [60 00 00 09 99 30 30 34 39 30 38 30 30 22 20 01 08 00 80 08 00 39 39 30 30 30 30 30 36 31 39 30 30 30 30 30 30 31 32 33 34 35 36 38 31 35 31 37 30 42 30 31 30 30 30 30 30 02] 2017-07-21 13:07:38 - info: Echo server got data 2017-07-21 13:07:38 - info: Replying to client B0100000 2017-07-21 13:07:38 - info: Echo server sent response 2017-07-21 13:07:38 - info: Got data from ISO-host (72b) 2017-07-21 13:07:38 - verbose: [.....00630810........9900000721130738123456170410758002020000B0100000NAN] 2017-07-21 13:07:38 - verbose: [60 00 00 09 99 30 30 36 33 30 38 31 30 22 20 00 08 0a 80 08 00 39 39 30 30 30 30 30 37 32 31 31 33 30 37 33 38 31 32 33 34 35 36 31 37 30 34 31 30 37 35 38 30 30 32 30 32 30 30 30 30 42 30 31 30 30 30 30 30 4e 41 4e] 2017-07-21 13:07:38 - info: Upstream error: ISO host sent data with no client connected! Ignoring...

ISO host says

 [Echo Response]

 Message Type Indicator [0].......................0810
 Bitmap [1].......................................222000080A800800
 Processing Code [3]..............................990000
 Transmission Date and Time [7]...................0721130738
 System Trace Audit Number [11]...................123456
 Batch Number [29]................................170
 Retrieval Reference Number [37]..................410758002020
 Response code [39]...............................0 (Successful Transaction)
 Card Acceptor Terminal Identification [41].......B0100000
 Security Related Control Information [53]........4e414e

================================================================================================

juks commented 6 years ago

Please check packagers with names that start with ll

Like:

https://github.com/juks/SocketQueue/blob/master/lib/iso8583/lib/packer/ll-bin-n.js

juks commented 6 years ago

The default packager for EMV data is

'55': {
    length: 255,
    name:   'EMV Data',
    type:   'll-bin-char',
    alias:  ''
},
temper5 commented 6 years ago

Thanks. I have try fixed-b. Why answer data in field 53 not in binary format (like field 1 - Bitmap)? Example: cat ./800_TAK.txt - | nc localhost 2014 0810" 9900000721154807123456170741083062098000B010000002

2017-07-21 15:48:04 - info: Important: starting... 2017-07-21 15:48:04 - info: Remote host configuration name: tmp 2017-07-21 15:48:04 - info: Connecting to upstream server localhost:5000 2017-07-21 15:48:04 - info: Relay raw ISO-8583 server is now running on port 2014 2017-07-21 15:48:04 - info: Echo server is now running on port 5000

2017-07-21 15:48:04 - info: Connected to upstream 127.0.0.1:5000! 2017-07-21 15:48:04 - info: Processing queue [pending 0 / total 0] 2017-07-21 15:48:04 - info: The queue is empty 2017-07-21 15:48:07 - info: Client ::1:34808 connected 2017-07-21 15:48:07 - info: Client ::1:34808 sent data (49b) 2017-07-21 15:48:07 - verbose: [0800........9900000619000000123456815170B0100000.] 2017-07-21 15:48:07 - verbose:

::1:34808

 [Echo Request]

 Message Type Indicator [0].......................0800
 Bitmap [1].......................................2220010800800800
 Processing Code [3]..............................990000
 Transmission Date and Time [7]...................0619000000
 System Trace Audit Number [11]...................123456
 Function Code [24]...............................815
 Batch Number [29]................................170
 Card Acceptor Terminal Identification [41].......B0100000
 Security Related Control Information [53]........02

================================================================================================

2017-07-21 15:48:07 - info: Writing to queue ::1:34808 [0] 2017-07-21 15:48:07 - info: New queue item 1 2017-07-21 15:48:07 - info: Processing queue [pending 1 / total 1] 2017-07-21 15:48:07 - verbose: Queue keys dump: 1 2017-07-21 15:48:07 - info: Upstreaming data for ::1:34808 2017-07-21 15:48:07 - verbose: [.....00490800........9900000619000000123456815170B0100000.] 2017-07-21 15:48:07 - verbose: [60 09 99 00 00 30 30 34 39 30 38 30 30 22 20 01 08 00 80 08 00 39 39 30 30 30 30 30 36 31 39 30 30 30 30 30 30 31 32 33 34 35 36 38 31 35 31 37 30 42 30 31 30 30 30 30 30 02] 2017-07-21 15:48:07 - info: Echo server got data 2017-07-21 15:48:07 - info: Replying to client B0100000 2017-07-21 15:48:07 - info: Echo server sent response 2017-07-21 15:48:07 - info: Got data from ISO-host (71b) 2017-07-21 15:48:07 - verbose: [.....00620810........9900000721154807123456170741083062098000B010000002] 2017-07-21 15:48:07 - verbose: [60 09 99 00 00 30 30 36 32 30 38 31 30 22 20 00 08 0a 80 08 00 39 39 30 30 30 30 30 37 32 31 31 35 34 38 30 37 31 32 33 34 35 36 31 37 30 37 34 31 30 38 33 30 36 32 30 39 38 30 30 30 42 30 31 30 30 30 30 30 30 32] 2017-07-21 15:48:07 - verbose: Releasing terminal B0100000 with the key 1 2017-07-21 15:48:07 - info: Parsed data for ::1:34808 2017-07-21 15:48:07 - verbose:

ISO host to ::1:34808

 [Echo Response]

 Message Type Indicator [0].......................0810
 Bitmap [1].......................................222000080A800800
 Processing Code [3]..............................990000
 Transmission Date and Time [7]...................0721154807
 System Trace Audit Number [11]...................123456
 Batch Number [29]................................170
 Retrieval Reference Number [37]..................741083062098
 Response code [39]...............................0 (Successful Transaction)
 Card Acceptor Terminal Identification [41].......B0100000
 Security Related Control Information [53]........3032

================================================================================================

2017-07-21 15:48:07 - info: Processing queue [pending 0 / total 0] 2017-07-21 15:48:07 - info: The queue is empty 2017-07-21 15:48:07 - info: Client ::1:34808 event 2017-07-21 15:48:07 - info: Client ::1:34808 event 2017-07-21 15:48:07 - info: Client with queue id 1 terminated activity. No queue item was found 2017-07-21 15:48:07 - info: Processing queue [pending 0 / total 0] 2017-07-21 15:48:07 - info: The queue is empty

juks commented 6 years ago

Unfortunately, some hardcode is still not eliminated. The projects is evaluation from custom to universal solution.

It is set here: https://github.com/juks/SocketQueue/blob/master/lib/iso8583/lib/iso8583.js#L37

What I need to do:

temper5 commented 6 years ago

I think you only need to change packer in exports.pack for convert hex to bin.

I have change "fixed-b" like this:

exports.pack = function(data, packager) { var bytes = []; var str; for(var i=0; i< data.length-1; i+=2){ bytes.push(parseInt(data.substr(i, 2), 16)); } str = String.fromCharCode.apply(String, bytes); data = str; return { msg: data, };

And now ansewer is correct binary format.

cat ./800_TAK.txt - | nc localhost 2014 0810" 9900000721180226123456170062104708978000B0100000

2017-07-21 18:02:21 - info: Important: starting... 2017-07-21 18:02:21 - info: Remote host configuration name: tmp 2017-07-21 18:02:21 - info: Connecting to upstream server localhost:5000 2017-07-21 18:02:21 - info: Relay raw ISO-8583 server is now running on port 2014 2017-07-21 18:02:21 - info: Echo server is now running on port 5000

2017-07-21 18:02:21 - info: Connected to upstream 127.0.0.1:5000! 2017-07-21 18:02:21 - info: Processing queue [pending 0 / total 0] 2017-07-21 18:02:21 - info: The queue is empty 2017-07-21 18:02:26 - info: Client ::1:34912 connected 2017-07-21 18:02:26 - info: Client ::1:34912 sent data (49b) 2017-07-21 18:02:26 - verbose: [0800........9900000619000000123456815170B0100000.] 2017-07-21 18:02:26 - verbose:

::1:34912

 [Echo Request]

 Message Type Indicator [0].......................0800
 Bitmap [1].......................................2220010800800800
 Processing Code [3]..............................990000
 Transmission Date and Time [7]...................0619000000
 System Trace Audit Number [11]...................123456
 Function Code [24]...............................815
 Batch Number [29]................................170
 Card Acceptor Terminal Identification [41].......B0100000
 Security Related Control Information [53]........02

================================================================================================

2017-07-21 18:02:26 - info: Writing to queue ::1:34912 [0] 2017-07-21 18:02:26 - info: New queue item 1 2017-07-21 18:02:26 - info: Processing queue [pending 1 / total 1] 2017-07-21 18:02:26 - verbose: Queue keys dump: 1 2017-07-21 18:02:26 - info: Upstreaming data for ::1:34912 2017-07-21 18:02:26 - verbose: [.....00490800........9900000619000000123456815170B0100000.] 2017-07-21 18:02:26 - verbose: [60 09 99 00 00 30 30 34 39 30 38 30 30 22 20 01 08 00 80 08 00 39 39 30 30 30 30 30 36 31 39 30 30 30 30 30 30 31 32 33 34 35 36 38 31 35 31 37 30 42 30 31 30 30 30 30 30 02] 2017-07-21 18:02:26 - info: Echo server got data 2017-07-21 18:02:26 - info: Replying to client B0100000 Field53: 02 2017-07-21 18:02:26 - info: Echo server sent response 2017-07-21 18:02:26 - info: Got data from ISO-host (70b) 2017-07-21 18:02:26 - verbose: [.....00610810........9900000721180226123456170062104708978000B0100000.] 2017-07-21 18:02:26 - verbose: [60 09 99 00 00 30 30 36 31 30 38 31 30 22 20 00 08 0a 80 08 00 39 39 30 30 30 30 30 37 32 31 31 38 30 32 32 36 31 32 33 34 35 36 31 37 30 30 36 32 31 30 34 37 30 38 39 37 38 30 30 30 42 30 31 30 30 30 30 30 02] 2017-07-21 18:02:26 - verbose: Releasing terminal B0100000 with the key 1 2017-07-21 18:02:26 - info: Parsed data for ::1:34912 2017-07-21 18:02:26 - verbose:

ISO host to ::1:34912

 [Echo Response]

 Message Type Indicator [0].......................0810
 Bitmap [1].......................................222000080A800800
 Processing Code [3]..............................990000
 Transmission Date and Time [7]...................0721180226
 System Trace Audit Number [11]...................123456
 Batch Number [29]................................170
 Retrieval Reference Number [37]..................062104708978
 Response code [39]...............................0 (Successful Transaction)
 Card Acceptor Terminal Identification [41].......B0100000
 Security Related Control Information [53]........02

================================================================================================

2017-07-21 18:02:26 - info: Processing queue [pending 0 / total 0] 2017-07-21 18:02:26 - info: The queue is empty 2017-07-21 18:02:26 - info: Client ::1:34912 event 2017-07-21 18:02:26 - info: Client ::1:34912 event 2017-07-21 18:02:26 - info: Client with queue id 1 terminated activity. No queue item was found 2017-07-21 18:02:26 - info: Processing queue [pending 0 / total 0] 2017-07-21 18:02:26 - info: The queue is empty

juks commented 6 years ago

Thanks. By default it assumes binary mask to come as a Buffer: https://github.com/juks/SocketQueue/blob/master/lib/iso8583/lib/iso8583.js#L164

temper5 commented 6 years ago

Thank you. Close this issue.