juks / iso-8583-socket-queue

ISO 8583 gateway
MIT License
194 stars 111 forks source link

How to config LengthHeader+TPDU+MSG? #33

Closed rayyeh closed 5 years ago

rayyeh commented 5 years ago

Hi, POS format = LengthHeader(2 bytes)+TPDU+02xx..... . (Hypercom /NAC message format) My config: { "useLengthHeader": true, "useStaticHeader": "6001509999" ==> It is TPDU data }

2018-09-26 09:29:43 - : Writing to queue http:::1:54891 [0]
2018-09-26 09:29:43 - : New queue item 0
2018-09-26 09:29:43 - : Processing queue [pending 1 / total 1]
2018-09-26 09:29:43 - : Queue keys dump: 0
2018-09-26 09:29:43 - : Upstreaming data for http:::1:54891
2018-09-26 09:29:43 - : [..P..00600800........000000060718170000000100000123456123567890124567]
2018-09-26 09:29:43 - : [60 01 50 99 99 30 30 36 30 30 38 30 30 22 20 01 00 00 c0 00 00 30 30 30 30

I check log,I find msg is TPDU+LengthHeader . How to config TCPIPLen+TPDU+MSG? Thank you !

juks commented 5 years ago

Hi! Added lengthHeaderFirst parameter. You need to set it to true.

rayyeh commented 5 years ago

Where to set lengthHeaderFirst parameter ? I do not see it in parameters.js file.

juks commented 5 years ago

Please check here https://github.com/juks/SocketQueue/blob/98e64cece38c666950415a03b5ea28fd6955b530/parameters.js#L38

rayyeh commented 5 years ago

Hi Juks, My Host system accept the format of message : LengthofMSG+TPDU+iso8583rawdata LengthOfHeader is length of (TPDU+is8583rawdata). It is hex value . eg. msg len = 100, it is x'0064', 2 bytes. TPDU is 5 bytes, eg. 60015082A5, x'60015082A5'. How to set parameter ? Is it correct ? "useLengthHeader": false, "lengthHeaderFirst": true, "useStaticHeader" : "60015082A5"

juks commented 5 years ago

Hi Rayyeh!

Consider the lengthHeaderType=hex configuration parameter. Also, you can implement the length header logic of any type by yourself.

Please, check an example here https://github.com/juks/SocketQueue/blob/98e64cece38c666950415a03b5ea28fd6955b530/lib/iso8583/lib/packager/smartVista.js#L332.

rayyeh commented 5 years ago

Hi junks, I use openWay to sent transaction. It seems useLengthHeader is wrong. 2018-10-15 17:33:25 - : Client ::ffff:192.168.7.44:34846 sent data (81b) useStaticHeader ="60015082A5" , 5 bytes. 5+81 = 86 bytes, 2018-10-15 17:33:25 - : [00 51 => it show 81 bytes. How to fix the problem ? Thanks !

config.json

"useLengthHeader": true, "lengthHeaderFirst": true, "lengthHeaderType": "hex", "useStaticHeader" : "60015082A5"

2018-10-15 17:32:49 - : Connecting to upstream server 192.168.110.93:5020
2018-10-15 17:32:49 - : Relay raw ISO-8583 server is now running on port 5678
2018-10-15 17:32:49 - : Connected to upstream 192.168.110.93:5020!
2018-10-15 17:32:49 - : Processing queue [pending 0 / total 0]
2018-10-15 17:32:49 - : The queue is empty
2018-10-15 17:33:25 - : Client ::ffff:192.168.7.44:34846 connected
2018-10-15 17:33:25 - : Client ::ffff:192.168.7.44:34846 sent data (81b)
2018-10-15 17:33:25 - : [..p........EyRI.....................P.14100109000100049900012..001482....16100991]
2018-10-15 17:33:25 - :

::ffff:192.168.7.44:34846

 Message Type Indicator [0].......................0100
 Bitmap [1].......................................7024058000C00006
 Primary Account Number [2].......................4579524900000706
 Processing Code [3]..............................000000
 Amount, Transaction [4]..........................000000011100
 System Trace Audit Number [11]...................001493
 Date, Expiration [14]............................905
 POS Entry Mode [22]..............................0810
 Function Code [24]...............................0150
 Pos Condition Code [25]..........................00
 Card Acceptor Terminal Identification [41].......14100109
 Card Acceptor ID [42]............................000100049900012
 Reserved [62]....................................001482
 Additional Data [63]............................. 16100991

===================================================================
2018-10-15 17:33:25 - : Writing to queue ::ffff:192.168.7.44:34846 [0]
2018-10-15 17:33:25 - : New queue item 0
2018-10-15 17:33:25 - : Processing queue [pending 1 / total 1]
2018-10-15 17:33:25 - : Queue keys dump: 0
2018-10-15 17:33:25 - : Upstreaming data for ::ffff:192.168.7.44:34846
2018-10-15 17:33:25 - : [.Q..P....p........EyRI.....................P.14100109000100049900012..001482....16100991]
2018-10-15 17:33:25 - : [00 51 60 01 50 82 a5 01 00 70 24 05 80 00 c0 00 06 16 45 79 52 49 00 00 07 06 00 00 00 00 00 00 01 11 00 00 14 93 09 05 08 10 01 50 00 31 34 31 30 30 31 30 39 30 30 30 31 30 30 30 34 39 39 30 30 30 31 32 00 06 30 30 31 34 38 32 00 10 00 08 31 36 31 30 30 39 39 31]
2018-10-15 17:33:25 - : Got data from ISO-host (64b)
2018-10-15 17:33:25 - : [......P..08...................3....P00001493..........1214100109]
2018-10-15 17:33:25 - : [00 3e 60 82 a5 01 50 01 10 30 38 01 00 0e 80 00 00 00 00 00 00 00 00 01 11 00 00 14 93 17 33 25 10 15 01 50 30 30 30 30 31 34 39 33 20 20 20 20 20 20 20 20 20 20 31 32 31 34 31 30 30 31 30 39]
2018-10-15 17:33:25 - : Releasing terminal 14100109 with the key 0
2018-10-15 17:33:25 - : Parsed data for ::ffff:192.168.7.44:34846
2018-10-15 17:33:25 - :

ISO host to ::ffff:192.168.7.44:34846

 [ <faulty>]
 Message Type Indicator [0].......................0110
 Bitmap [1].......................................303801000E800000
 Processing Code [3]..............................000000
 Amount, Transaction [4]..........................000000011100
 System Trace Audit Number [11]...................001493
 Processing Time [12].............................173325
 Processing Date [13].............................1015
 Function Code [24]...............................0150
 Retrieval Reference Number [37]..................00001493    
 Authorisation Identification Response [38].......      
 Response code [39]...............................12 (Invalid transaction)
 Card Acceptor Terminal Identification [41].......14100109

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

juks commented 5 years ago

Hi!

Client ::ffff:192.168.7.44:34846 sent data (81b). 81 = 0x51. 00 51 is correct length header in hex mode.

Also you have a proper response from ISO host where System Trace Audit Number (11) and terminal id (41) are correct to what was sent. This is 100% proof the ISO host got your message properly.

I think the problem is not the format but the values. Unfortunately, I can't assist with it right now, and suggest you debug the case by yourself and maybe provide some improvement for the source.

rayyeh commented 5 years ago

Hi juks, I modify code and test it. You can close the case.Thanks ! Temp code: SocketQueue\lib\iso8583-packet\lib\iso8583Packet.js // Return source raw message Iso8583Packet.prototype.getRawMessage = function(options) { // No raw -- return syntetic message if (!this.rawData) return this.getMessage(options); if (!options) options = {};

var staticHeader = options.staticHeader ? new Buffer(options.staticHeader) : new Buffer(""); var lengthHeader = options.lengthHeader ? this.getLengthHeader(this.rawData.length) : new Buffer(''); // RAY var rawDataLEN = this.rawData.length + 5; var lengthHeader = options.lengthHeader ? this.getLengthHeader(rawDataLEN) : new Buffer(''); //RAY

if (typeof this.rawData == 'object' && this.rawData instanceof Buffer) { if (global.c['lengthHeaderFirst']) {