Skip to content

Commit

Permalink
Stringify various EMV fields
Browse files Browse the repository at this point in the history
* Issuer Script Template 1; field 71
* Issuer Script Template 2; field 72
* Issuer Script Command; field 86
* Authorisation Code; field 89
* Issuer Script Identifier; field 9F18
  • Loading branch information
leonlynch committed Mar 24, 2024
1 parent 480980c commit 87b9cd2
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/emv_strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ int emv_tlv_get_info(
info->format = EMV_FORMAT_VAR;
return 0;

case EMV_TAG_71_ISSUER_SCRIPT_TEMPLATE_1:
info->tag_name = "Issuer Script Template 1";
info->tag_desc =
"Contains proprietary issuer data for "
"transmission to the ICC before the second "
"GENERATE AC command";
info->format = EMV_FORMAT_VAR;
return 0;

case EMV_TAG_72_ISSUER_SCRIPT_TEMPLATE_2:
info->tag_name = "Issuer Script Template 2";
info->tag_desc =
"Contains proprietary issuer data for "
"transmission to the ICC after the second "
"GENERATE AC command";
info->format = EMV_FORMAT_VAR;
return 0;

case EMV_TAG_73_DIRECTORY_DISCRETIONARY_TEMPLATE:
info->tag_name = "Directory Discretionary Template";
info->tag_desc =
Expand Down Expand Up @@ -234,6 +252,12 @@ int emv_tlv_get_info(
}
return emv_aid_get_string(tlv->value, tlv->length, value_str, value_str_len);

case EMV_TAG_86_ISSUER_SCRIPT_COMMAND:
info->tag_name = "Issuer Script Command";
info->tag_desc = "Contains a command for transmission to the ICC";
info->format = EMV_FORMAT_VAR;
return 0;

case EMV_TAG_87_APPLICATION_PRIORITY_INDICATOR:
info->tag_name = "Application Priority Indicator";
info->tag_desc =
Expand All @@ -253,6 +277,17 @@ int emv_tlv_get_info(
info->format = EMV_FORMAT_B;
return 0;

case EMV_TAG_89_AUTHORISATION_CODE:
info->tag_name = "Authorisation Code";
info->tag_desc =
"Value generated by the authorisation authority "
"(issuer) for an approved transaction";
// EMV 4.4 Book 3 Annex A indicates that the format is defined
// by the Payment System. M/Chip and VCPS both define this field
// as format 'ans' with length 6.
info->format = EMV_FORMAT_ANS;
return emv_tlv_value_get_string(tlv, info->format, 6, value_str, value_str_len);

case EMV_TAG_8A_AUTHORISATION_RESPONSE_CODE:
info->tag_name = "Authorisation Response Code";
info->tag_desc = "Code that defines the disposition of a message";
Expand Down Expand Up @@ -682,6 +717,12 @@ int emv_tlv_get_info(
info->format = EMV_FORMAT_ANS;
return emv_tlv_value_get_string(tlv, info->format, 15, value_str, value_str_len);

case EMV_TAG_9F18_ISSUER_SCRIPT_IDENTIFIER:
info->tag_name = "Issuer Script Identifier";
info->tag_desc = "Identification of the Issuer Script";
info->format = EMV_FORMAT_B;
return 0;

case EMV_TAG_9F1A_TERMINAL_COUNTRY_CODE:
info->tag_name = "Terminal Country Code";
info->tag_desc =
Expand Down
18 changes: 18 additions & 0 deletions src/emv_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ __BEGIN_DECLS
/// @remark Used as generic EMV data template
#define EMV_TAG_70_DATA_TEMPLATE (0x70)

/// EMV tag 71 Issuer Script Template 1
#define EMV_TAG_71_ISSUER_SCRIPT_TEMPLATE_1 (0x71)

/// EMV tag 72 Issuer Script Template 2
#define EMV_TAG_72_ISSUER_SCRIPT_TEMPLATE_2 (0x72)

/// EMV tag 73 Directory Discretionary Template. Template 61.
#define EMV_TAG_73_DIRECTORY_DISCRETIONARY_TEMPLATE (0x73)

Expand Down Expand Up @@ -88,12 +94,21 @@ __BEGIN_DECLS
/// EMV tag 84 Dedicated File (DF) Name. Template 6F.
#define EMV_TAG_84_DF_NAME (0x84)

/// EMV tag 86 Issuer Script Command. Template 71 or 72.
#define EMV_TAG_86_ISSUER_SCRIPT_COMMAND (0x86)

/// EMV tag 87 Application Priority Indicator. Template 61 or A5.
#define EMV_TAG_87_APPLICATION_PRIORITY_INDICATOR (0x87)

/// EMV tag 88 Short File Indicator (SFI). Template A5.
#define EMV_TAG_88_SFI (0x88)

/// EMV tag 89 Authorisation Code
/// @remark See EMV Contactless Book C-3 v2.11, Annex A.2
/// @remark See Visa Contactless Payment Specification (VCPS) Supplemental Requirements, version 2.2, January 2016, Annex D
/// @remark See M/Chip Requirements for Contact and Contactless, 28 November 2023, Appendix A
#define EMV_TAG_89_AUTHORISATION_CODE (0x89)

/// EMV tag 8A Authorisation Response Code
/// @remark See ISO 8583:2021, J.2.2.2
#define EMV_TAG_8A_AUTHORISATION_RESPONSE_CODE (0x8A)
Expand Down Expand Up @@ -246,6 +261,9 @@ __BEGIN_DECLS
/// @remark Also used as the Card Acceptor Identification by ISO 8583. See EMV 4.4 Book 4, Annex C, Table 40
#define EMV_TAG_9F16_MERCHANT_IDENTIFIER (0x9F16)

/// EMV tag 9F18 Issuer Script Identifier. Template 71 or 72.
#define EMV_TAG_9F18_ISSUER_SCRIPT_IDENTIFIER (0x9F18)

/// EMV tag 9F1A Terminal Country Code
#define EMV_TAG_9F1A_TERMINAL_COUNTRY_CODE (0x9F1A)

Expand Down
80 changes: 79 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##############################################################################
# Copyright (c) 2022-2023 Leon Lynch
# Copyright (c) 2022-2024 Leon Lynch
#
# This file is licensed under the terms of the LGPL v2.1 license.
# See LICENSE file.
Expand Down Expand Up @@ -582,6 +582,84 @@ if(TARGET emv-decode AND BUILD_TESTING)
PASS_REGULAR_EXPRESSION ${emv_decode_9F1D_test2_regex}
)

# From actual Visa transaction
add_test(NAME emv_decode_issuer_response_test1
COMMAND emv-decode --tlv 89063130363630398A023030910A50FC6205038200003030
--mcc-json ${MCC_JSON_BUILD_PATH}
)
string(CONCAT emv_decode_issuer_response_test1_regex
"^89 \\| Authorisation Code : \\[6\\] 31 30 36 36 30 39 \"106609\"[\r\n]"
"8A \\| Authorisation Response Code : \\[2\\] 30 30 \"00 - Approved or completed successfully\"[\r\n]"
"91 : \\[10\\] 50 FC 62 05 03 82 00 00 30 30[\r\n]"
)
set_tests_properties(emv_decode_issuer_response_test1
PROPERTIES
PASS_REGULAR_EXPRESSION ${emv_decode_issuer_response_test1_regex}
)

# From actual Visa transaction
add_test(NAME emv_decode_issuer_response_test2
COMMAND emv-decode --tlv 89063632373132337211860F04DA9F6B0A000000050000919863528A0230309108A584F94900820000
--mcc-json ${MCC_JSON_BUILD_PATH}
)
string(CONCAT emv_decode_issuer_response_test2_regex
"^89 \\| Authorisation Code : \\[6\\] 36 32 37 31 32 33 \"627123\"[\r\n]"
"72 \\| Issuer Script Template 2 : \\[17\\][\r\n]"
" 86 \\| Issuer Script Command : \\[15\\] 04 DA 9F 6B 0A 00 00 00 05 00 00 91 98 63 52[\r\n]"
"8A \\| Authorisation Response Code : \\[2\\] 30 30 \"00 - Approved or completed successfully\"[\r\n]"
"91 : \\[8\\] A5 84 F9 49 00 82 00 00[\r\n]"
)
set_tests_properties(emv_decode_issuer_response_test2
PROPERTIES
PASS_REGULAR_EXPRESSION ${emv_decode_issuer_response_test2_regex}
)

# From actual Mastercard transaction
add_test(NAME emv_decode_issuer_response_test3
COMMAND emv-decode --tlv 910AFC436535D614F37300108A0230308906383139353334
--mcc-json ${MCC_JSON_BUILD_PATH}
)
string(CONCAT emv_decode_issuer_response_test3_regex
"^91 : \\[10\\] FC 43 65 35 D6 14 F3 73 00 10[\r\n]"
"8A \\| Authorisation Response Code : \\[2\\] 30 30 \"00 - Approved or completed successfully\"[\r\n]"
"89 \\| Authorisation Code : \\[6\\] 38 31 39 35 33 34 \"819534\"[\r\n]"
)
set_tests_properties(emv_decode_issuer_response_test3
PROPERTIES
PASS_REGULAR_EXPRESSION ${emv_decode_issuer_response_test3_regex}
)

# From Implementing American Express EMV Acceptance on a Terminal (Oct 2007), page 16, table 5
add_test(NAME emv_decode_issuer_response_test4
COMMAND emv-decode --tlv 72459F18048000000086158424000210FEBF34F00B7CE770DC61DA847BFB1E59862504DA8E00200000000000000000420141035E031F020000000000000000AC7F4DF1D624A0ED
--mcc-json ${MCC_JSON_BUILD_PATH}
)
string(CONCAT emv_decode_issuer_response_test4_regex
"^72 \\| Issuer Script Template 2 : \\[69\\][\r\n]"
" 9F18 \\| Issuer Script Identifier : \\[4\\] 80 00 00 00[\r\n]"
" 86 \\| Issuer Script Command : \\[21\\] 84 24 00 02 10 FE BF 34 F0 0B 7C E7 70 DC 61 DA 84 7B FB 1E 59[\r\n]"
" 86 \\| Issuer Script Command : \\[37\\] 04 DA 8E 00 20 00 00 00 00 00 00 00 00 42 01 41 03 5E 03 1F 02 00 00 00 00 00 00 00 00 AC 7F 4D F1 D6 24 A0 ED[\r\n]"
)
set_tests_properties(emv_decode_issuer_response_test4
PROPERTIES
PASS_REGULAR_EXPRESSION ${emv_decode_issuer_response_test4_regex}
)

# From Implementing American Express EMV Acceptance on a Terminal (Oct 2007), page 17, table 6
add_test(NAME emv_decode_issuer_response_test5
COMMAND emv-decode --tlv 72179F180400004000860E04DA9F580900C7356286E3779889
--mcc-json ${MCC_JSON_BUILD_PATH}
)
string(CONCAT emv_decode_issuer_response_test5_regex
"^72 \\| Issuer Script Template 2 : \\[23\\][\r\n]"
" 9F18 \\| Issuer Script Identifier : \\[4\\] 00 00 40 00[\r\n]"
" 86 \\| Issuer Script Command : \\[14\\] 04 DA 9F 58 09 00 C7 35 62 86 E3 77 98 89[\r\n]"
)
set_tests_properties(emv_decode_issuer_response_test5
PROPERTIES
PASS_REGULAR_EXPRESSION ${emv_decode_issuer_response_test5_regex}
)

if(WIN32)
# Ensure that tests can find required DLLs (if any)
# Assume that the PATH already contains the compiler runtime DLLs
Expand Down

0 comments on commit 87b9cd2

Please sign in to comment.