-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpklr.cpp
More file actions
120 lines (108 loc) · 3.43 KB
/
pklr.cpp
File metadata and controls
120 lines (108 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
extern "C" {
#include "nexoid-ed/include/pklr.h"
#include "nexoid-ed/include/gtd.h"
#include "nexoid-ed/src/NexoFast.h"
}
#include "ttd_keeper.hpp"
#include "scapi_internal.hpp"
#include "utils.hpp"
#include <cstring>
// FIXME: Remove it!
extern struct CandidateList* g_CandidateList;
using namespace std;
enum PklrResult
pklr_Process_Read_Record(const uint8_t p1, const uint8_t p2) {
ttd.pan = acp((struct Prefix){
16,
"4761739001010119"
});
e1kd->cd.cvmList = acp([](){
struct CvmList ret{};
ret.amountX = 0;
ret.amountY = 0;
ret.cvRule.l = 3;
ret.cvRule.a[0].cvmCode.cvm = CVM_SIGNATURE;
ret.cvRule.a[0].cvmCode.applyRuleOnFail = 1;
ret.cvRule.a[0].cvmConditionCode = CVM_RESERVED_01;
ret.cvRule.a[1].cvmCode.cvm = CVM_PLAINTEXT_PIN_VERIFICATION_PERFORMED_BY_ICC;
ret.cvRule.a[1].cvmCode.applyRuleOnFail = 1;
ret.cvRule.a[1].cvmConditionCode = CVM_IF_ALWAYS;
ret.cvRule.a[2].cvmCode.cvm = CVM_SIGNATURE;
ret.cvRule.a[2].cvmCode.applyRuleOnFail = 0;
ret.cvRule.a[2].cvmConditionCode = CVM_IF_ALWAYS;
return ret;
}());
return PKLR_OK;
}
enum PklrResult
pklr_Offline_Data_Authentication(void) {
return PKLR_SUCCESSFUL;
}
enum PklrResult
pklr_Build_Candidate_List(void) {
static struct CandidateList cl = {
.l_entry = 1,
.entry = {}
};
cl.entry[0] = {};
cl.entry[0].ApplicationPriorityIndicator = {};
cl.entry[0].ApplicationLabel = (struct string16){ "TestApp", {} };
cl.entry[0].ApplicationPreferredName = (struct string16){ "TestApp #1", {} };
cl.entry[0].IssuerCodeTableIndex = ISO_CODE_TABLE_1;
cl.entry[0].TerminalPriorityIndicator = 0;
cl.entry[0].ApplicationPriorityIndicator.priority = 0;
cl.entry[0].ApplicationPriorityIndicator.cardholderConfirmationRequired = 0;
cl.entry[0].DfName = {};
cl.entry[0].DfName.l_raw = 6;
static const uint8_t tmp[] = { 0xA0, 0x00, 0x00, 0x00, 0x00, 0x01 };
memcpy(cl.entry[0].DfName.raw, tmp, sizeof tmp);
g_CandidateList = &cl;
ttd.processingStatus.buildingCandidateListUsingListOfAid = 1;
ep.cd.applicationEffectiveDate = acp((union yymmdd){ 0x15, 0x01, 0x01 });
ep.cd.applicationExpirationDate = acp((union yymmdd){ 0x25, 0x12, 0x31 });
return PKLR_OK;
}
enum PklrResult
pklr_Build_Candidate_List_Ctless(void) try {
static CandidateList cl;
if (g_CandidateList != nullptr)
throw logic_error("Candidate List must be fresh");
const auto vec = s_scapi->build_candidate_list({});
cl.l_entry = vec.size();
if (cl.l_entry > elementsof(cl.entry))
throw overflow_error("Too many candidates");
copy(vec.begin(), vec.end(), cl.entry);
g_CandidateList = &cl;
return PKLR_OK;
} catch (...) {
TtdKeeper::instance().handle_exception(__func__);
return PKLR_NOK;
}
enum PklrResult
pklr_Kernel_E_Processing(void) {
# if 1
return Kernel_E_Processing();
# else
ttd.outcome = O_ONLINE_REQUEST;
return PKLR_DONE;
# endif
}
enum PklrResult
pklr_First_Generate_Ac_Processing(const uint8_t p1) {
ttd.onlineRequired = true;
return PKLR_OK;
}
enum PklrResult
pklr_Second_Generate_Ac_Processing(const uint8_t p1) {
ttd.tcReceived = true;
ttd.onlineRequired = false;
return PKLR_OK;
}
enum PklrResult
pklr_First_Issuer_Script_Processing(void) {
return PKLR_OK;
}
enum PklrResult
pklr_Second_Issuer_Script_Processing(void) {
return PKLR_OK;
}