Creating a Message Authentication Code (MAC) for Stø Token Service ISO API¶
Introduction¶
All messages and responses to the ISO API must be protected by a Message Authentication Code (MAC). This mechanism ensures message integrity and authenticity, confirming that the message has not been altered and originates from a trusted source.
The MAC is generated by the entity connecting to the ISO API (e.g., POS aggregator or processor) after receiving a payment message from the payment network and performing detokenization to retrieve the funding PAN. Once the funding PAN is obtained, the payment process can proceed securely.
This document provides a step-by-step guide for creating a MAC for ISO messages, using examples from Thales Payshield 10k. Other Hardware Security Modules (HSMs) may be used if they support the required cryptographic operations.
1. Exporting the Protected MAC Key from the HSM¶
Using the shared MAC Key Encryption Key (KEK), generate a random MAC session key and securely export it from the HSM.
Example wrapped key:
D0144M6AC00E00000DB97F430EF5FE7839125445749AD6477439749EA17F35F4E1132C076114CC3D87099D9B5612849B68F462E05B1931848C7AE73D4DAB89ABBC31215F2E7623E5
Include this wrapped key in Field 48 along with the MAC key index.
Example Field 48 with MAC key index 1 in tag 001 and the wrapped key in tag 002. Spaces added for readability. Note that the length of each tag is represented in decimal format:
001 001 1 002 144 D0144M6AC00E00000DB97F430EF5FE7839125445749AD6477439749EA17F35F4E1132C076114CC3D87099D9B5612849B68F462E05B1931848C7AE73D4DAB89ABBC31215F2E7623E5
2. Constructing Input for the MAC Operation¶
Using data from the payment network and the constructed Field 48, the ISO message fields may appear as follows:
Field-2 : [5032001760096254]
Field-3 : [000000]
Field-4 : [000000002100]
Field-7 : [1224170000]
Field-14 : [2908]
Field-18 : [1520]
Field-19 : [250]
Field-22 : [070]
Field-23 : [000]
Field-37 : [172544206765]
Field-42 : [4992]
Field-43 : [STØ Token Service /0026 /Oslo /NO]
Field-48 : [0010011002144D0144M6AC00E00000DB97F430EF5FE7839125445749AD6477439749EA17F35F4E1132C076114CC3D87099D9B5612849B68F462E05B1931848C7AE73D4DAB89ABBC31215F2E7623E5]
Field-49 : [978]
Field-55 : [9F02060000000021009F03060000000000009F1A020250950500000000005F2A0209789A031801099C01009F37040F010E0382021A809F360200019F10200FA501A081010000EEAF28C68381C2ED0F0000000000000000000000000000009F2608A1A717065FF030A3]
3. Producing Binary Encoding of the ISO Message¶
Convert the fields into an ISO message. Ensure the bitmap includes Field 64.
Example binary representation:
110072046600086182011050320017600962540000000000000021001224170000290815200250007000003137323534343230363736353439393220202020202020202020205354D820546F6B656E205365727669636520202020202F30303236202F4F736C6F2020202020202020202020202020202020202F4E4F209D3030313030313130303231343444303134344D3641433030453030303030444239374634333045463546453738333931323534343537343941443634373734333937343945413137463335463445313133324330373631313443433344383730393944394235363132383439423638463436324530354231393331383438433741453733443444414238394142424333313231354632453736323345350978699F02060000000021009F03060000000000009F1A020250950500000000005F2A0209789A031801099C01009F37040F010E0382021A809F360200019F10200FA501A081010000EEAF28C68381C2ED0F0000000000000000000000000000009F2608A1A717065FF030A3
3.1 Details on bitmap¶
The header of the ISO message consists of the MTI and the bitmap. In this example, the MTI is 1100, indicating a financial transaction request. The bitmap indicates which fields are present in the message. Here, the bitmap includes Field 64 for the MAC.
11007204660008618201
The bitmap can be broken down further:
| Byte | Bit Pattern | Fields Present |
|---|---|---|
| 72 | 01110010 | 2, 3, 4, 7 |
| 04 | 00000100 | 14 |
| 66 | 01100110 | 18, 19, 22, 23 |
| 00 | 00000000 | |
| 08 | 00001000 | 37 |
| 61 | 01100001 | 42, 43, 48 |
| 82 | 10000010 | 49, 43, 55 |
| 01 | 00000001 | 64 |
4. Transforming Input¶
Apply the transformation for MAC calculation. Default method: SHA-256 (64 rounds).
Example transformed input:
277AB4951A20BCB9982ED4CD9A0DD1CB30AFBD581B9246A5F0423151BCB60C54
5. Generating the MAC¶
Use the HSM to compute the MAC. In this example, AES-CMAC is applied according to RFC-4493.
Result:
7A046E168CA023C11AFDEF0ED721DECA
Add this MAC to Field 64 of the ISO message.
Field Summary¶
MTI : 1100
Bitmap : {2, 3, 4, 7, 14, 18, 19, 22, 23, 37, 42, 43, 48, 49, 55, 64}
Field-2 : [5032001760096254]
Field-3 : [000000]
Field-4 : [000000002100]
Field-7 : [1224170000]
Field-14 : [2908]
Field-18 : [1520]
Field-19 : [250]
Field-22 : [070]
Field-23 : [000]
Field-37 : [172544206765]
Field-42 : [4992 ]
Field-43 : [STØ Token Service /0026 /Oslo /NO ]
Field-48 : [0010011002144D0144M6AC00E00000DB97F430EF5FE7839125445749AD6477439749EA17F35F4E1132C076114CC3D87099D9B5612849B68F462E05B1931848C7AE73D4DAB89ABBC31215F2E7623E5]
Field-49 : [978]
Field-55 : [9F02060000000021009F03060000000000009F1A020250950500000000005F2A0209789A031801099C01009F37040F010E0382021A809F360200019F10200FA501A081010000EEAF28C68381C2ED0F0000000000000000000000000000009F2608A1A717065FF030A3]
Field-64 : [7A046E168CA023C11AFDEF0ED721DECA]
6. Encoding for Transmission¶
Encode the binary data as Base64 for transmission.
Example:
EQByBGYACGGCARBQMgAXYAliVAAAAAAAAAAhABIkFwAAKQgVIAJQAHAAADE3MjU0NDIwNjc2NTQ5OTIgICAgICAgICAgIFNU2CBUb2tlbiBTZXJ2aWNlICAgICAvMDAyNiAvT3NsbyAgICAgICAgICAgICAgICAgIC9OTyCdMDAxMDAxMTAwMjE0NEQwMTQ0TTZBQzAwRTAwMDAwREI5N0Y0MzBFRjVGRTc4MzkxMjU0NDU3NDlBRDY0Nzc0Mzk3NDlFQTE3RjM1RjRFMTEzMkMwNzYxMTRDQzNEODcwOTlEOUI1NjEyODQ5QjY4RjQ2MkUwNUIxOTMxODQ4QzdBRTczRDREQUI4OUFCQkMzMTIxNUYyRTc2MjNFNQl4aZ8CBgAAAAAhAJ8DBgAAAAAAAJ8aAgJQlQUAAAAAAF8qAgl4mgMYAQmcAQCfNwQPAQ4DggIagJ82AgABnxAgD6UBoIEBAADuryjGg4HC7Q8AAAAAAAAAAAAAAAAAAACfJgihpxcGX/Awo3oEbhaMoCPBGv3vDtch3so=