Commit 20dbffcd41f67425d64232f96a45910e935848d8
1 parent
301c3abb
feat(dlcm+etrade_crad_client):新增m1卡接口,修改卡务读卡流程
新增m1卡接口,修改卡务读卡流程,未完成。
Showing
10 changed files
with
234 additions
and
178 deletions
dlcm/dlcm/DLCCard.cc
@@ -866,7 +866,7 @@ int DLCCard::M1AuthenticationKey(const unsigned short section, unsigned char* ke | @@ -866,7 +866,7 @@ int DLCCard::M1AuthenticationKey(const unsigned short section, unsigned char* ke | ||
866 | 866 | ||
867 | do | 867 | do |
868 | { | 868 | { |
869 | - if (kSuccess != DLCDevice::Instance().M1LoadKeyHex(0, (const unsigned char*)"ffffffffffff", section)) | 869 | + if (kSuccess != DLCDevice::Instance().M1LoadKeyHex(0, (const unsigned char*)key, section)) |
870 | { | 870 | { |
871 | result = kM1LoadKeyFailed; | 871 | result = kM1LoadKeyFailed; |
872 | break; | 872 | break; |
dlcm/dlcm/DLCCardManager.cc
@@ -93,4 +93,9 @@ DL_DLL_API int __stdcall DLCM1ReadCard(const unsigned short block_num, const uns | @@ -93,4 +93,9 @@ DL_DLL_API int __stdcall DLCM1ReadCard(const unsigned short block_num, const uns | ||
93 | DL_DLL_API int __stdcall DLCM1WriteCard(const unsigned short block_num, const unsigned char* data) | 93 | DL_DLL_API int __stdcall DLCM1WriteCard(const unsigned short block_num, const unsigned char* data) |
94 | { | 94 | { |
95 | return DLCCard::Instance().M1WriteCard(block_num, data); | 95 | return DLCCard::Instance().M1WriteCard(block_num, data); |
96 | +} | ||
97 | + | ||
98 | +DL_DLL_API int __stdcall DLCM1FindCard() | ||
99 | +{ | ||
100 | + return DLCDevice::Instance().M1FindCard(); | ||
96 | } | 101 | } |
97 | \ No newline at end of file | 102 | \ No newline at end of file |
dlcm/dlcm/DLCDevice.cc
@@ -55,7 +55,7 @@ int DLCDevice::FindAndResetCard() | @@ -55,7 +55,7 @@ int DLCDevice::FindAndResetCard() | ||
55 | if (!dc_card(dev_, 0, &snr)) | 55 | if (!dc_card(dev_, 0, &snr)) |
56 | { | 56 | { |
57 | result = kSuccessFindCard; | 57 | result = kSuccessFindCard; |
58 | - if (!dc_pro_reset(dev_, recv_data_len, recv_data)) | 58 | + if (!dc_pro_reset(dev_, recv_data_len, recv_data)) |
59 | { | 59 | { |
60 | result = kSuccess; | 60 | result = kSuccess; |
61 | } | 61 | } |
@@ -112,7 +112,8 @@ int DLCDevice::FindCard() | @@ -112,7 +112,8 @@ int DLCDevice::FindCard() | ||
112 | 112 | ||
113 | int DLCDevice::M1Authentication(const unsigned char mode, const unsigned short section) | 113 | int DLCDevice::M1Authentication(const unsigned char mode, const unsigned short section) |
114 | { | 114 | { |
115 | - return dc_authentication(dev_, mode, section); | 115 | + int result = dc_authentication(dev_, mode, section); |
116 | + return result; | ||
116 | } | 117 | } |
117 | 118 | ||
118 | int DLCDevice::M1LoadKeyHex(const unsigned char mode, const unsigned char* key, const unsigned char section) | 119 | int DLCDevice::M1LoadKeyHex(const unsigned char mode, const unsigned char* key, const unsigned char section) |
@@ -128,4 +129,10 @@ int DLCDevice::M1Read(const unsigned char adr, const unsigned char* data) | @@ -128,4 +129,10 @@ int DLCDevice::M1Read(const unsigned char adr, const unsigned char* data) | ||
128 | int DLCDevice::M1Write(const unsigned char adr, const unsigned char* data) | 129 | int DLCDevice::M1Write(const unsigned char adr, const unsigned char* data) |
129 | { | 130 | { |
130 | return dc_write(dev_, adr, (unsigned char*)data); | 131 | return dc_write(dev_, adr, (unsigned char*)data); |
132 | +} | ||
133 | + | ||
134 | +int DLCDevice::M1FindCard() | ||
135 | +{ | ||
136 | + unsigned long snr = 0; | ||
137 | + return dc_card(dev_, 0, &snr); | ||
131 | } | 138 | } |
132 | \ No newline at end of file | 139 | \ No newline at end of file |
dlcm/dlcm/DLCDevice.h
@@ -23,6 +23,7 @@ public: | @@ -23,6 +23,7 @@ public: | ||
23 | int M1LoadKeyHex(const unsigned char mode, const unsigned char* key, const unsigned char section); | 23 | int M1LoadKeyHex(const unsigned char mode, const unsigned char* key, const unsigned char section); |
24 | int M1Read(const unsigned char adr, const unsigned char* data); | 24 | int M1Read(const unsigned char adr, const unsigned char* data); |
25 | int M1Write(const unsigned char adr, const unsigned char* data); | 25 | int M1Write(const unsigned char adr, const unsigned char* data); |
26 | + int M1FindCard(); | ||
26 | 27 | ||
27 | private: | 28 | private: |
28 | int Connect(); | 29 | int Connect(); |
dlcm/dlcm/DLCardManager.h
@@ -110,4 +110,8 @@ DL_DLL_API int __stdcall DLCM1ReadCard(const unsigned short block_num, const uns | @@ -110,4 +110,8 @@ DL_DLL_API int __stdcall DLCM1ReadCard(const unsigned short block_num, const uns | ||
110 | **/ | 110 | **/ |
111 | DL_DLL_API int __stdcall DLCM1WriteCard(const unsigned short block_num, const unsigned char* data); | 111 | DL_DLL_API int __stdcall DLCM1WriteCard(const unsigned short block_num, const unsigned char* data); |
112 | 112 | ||
113 | +/*m1¿¨Ñ°¿¨ | ||
114 | + **/ | ||
115 | +DL_DLL_API int __stdcall DLCM1FindCard(); | ||
116 | + | ||
113 | #endif //end DL_CARD_MANAGER_H | 117 | #endif //end DL_CARD_MANAGER_H |
114 | \ No newline at end of file | 118 | \ No newline at end of file |
dlcm/dlcm/main.cpp
@@ -8,42 +8,19 @@ int main() | @@ -8,42 +8,19 @@ int main() | ||
8 | { | 8 | { |
9 | std::cout << "Test start " << std::endl; | 9 | std::cout << "Test start " << std::endl; |
10 | DLCConnectDevice(); | 10 | DLCConnectDevice(); |
11 | - DLCFindCard(); | 11 | + int result = DLCFindCard(); |
12 | 12 | ||
13 | - ////WriteTest(); | 13 | + result = DLCM1FindCard(); |
14 | + | ||
15 | + result = DLCM1AuthenticationKey(0, (unsigned char*)"ffffffffffff"); | ||
14 | 16 | ||
15 | - //ReadTest(); | 17 | + unsigned char read_text[32] = { 0 }; |
18 | + result = DLCM1ReadCard(1, read_text); | ||
19 | + const char *write_text = "222222222222"; | ||
20 | + result = DLCM1WriteCard(1, (const unsigned char*)write_text); | ||
16 | 21 | ||
17 | - ////InstallKeyTest(); | 22 | + DLCDisconnectDevice(); |
18 | 23 | ||
19 | - ////AuthenticationKeyTest(); | ||
20 | - | ||
21 | - CreateFileTest(); | ||
22 | - | ||
23 | - | ||
24 | - //DLCDisconnectDevice(); | ||
25 | - | ||
26 | - /*unsigned char write_data[9] = { 0 }; | ||
27 | - for (int index = 0; index != 9; ++index) | ||
28 | - { | ||
29 | - write_data[index] = index; | ||
30 | - } | ||
31 | - unsigned char cmd[50] = { 0 }; | ||
32 | - | ||
33 | - unsigned char key[16] = { 0 }; | ||
34 | - | ||
35 | - unsigned char random[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };*/ | ||
36 | - | ||
37 | - //DLCSOGetRandom(cmd); | ||
38 | - | ||
39 | - //DLCSOAuthenticationKey(1, key, random, cmd); | ||
40 | - | ||
41 | - //DLCSOReadData(5, 16, cmd); | ||
42 | - | ||
43 | - //DLCSOWriteData(key, random, 5, 9, write_data, cmd); | ||
44 | - | ||
45 | - //unsigned char dir[2] = { 0x00, 0x25 }; | ||
46 | - //DLCSOSelectDir(dir, cmd); | ||
47 | 24 | ||
48 | getchar(); | 25 | getchar(); |
49 | } | 26 | } |
50 | \ No newline at end of file | 27 | \ No newline at end of file |
etrade_card_client/ETradeClient/hardware/DLCardManager.h
1 | +// 作者:刘野 | ||
2 | +// 卡片硬件操作库导出接口。 | ||
3 | +// 包含dll导出接口和so库导出接口 | ||
4 | + | ||
1 | #ifndef DL_CARD_MANAGER_H | 5 | #ifndef DL_CARD_MANAGER_H |
2 | #define DL_CARD_MANAGER_H | 6 | #define DL_CARD_MANAGER_H |
3 | 7 | ||
4 | #define DL_DLL_API extern "C" __declspec(dllexport) | 8 | #define DL_DLL_API extern "C" __declspec(dllexport) |
5 | 9 | ||
6 | -DL_DLL_API int __stdcall ConnectDLDevice(); | ||
7 | -DL_DLL_API int __stdcall FindDLCard(); | ||
8 | -DL_DLL_API int __stdcall AuthenticationDLKey(unsigned char* pKey); | ||
9 | -DL_DLL_API int __stdcall ReadDLCardData(unsigned char* pDirID, unsigned char cFileID, short u16Offset, int u32DateLen, unsigned char* pData, unsigned char* pKey = 0); | ||
10 | -DL_DLL_API int __stdcall WriteDLCardData(unsigned char* pDirID, unsigned char cFileID, unsigned char cOffset, unsigned short cDateLen, unsigned char* pData, unsigned char* pKey); | ||
11 | -DL_DLL_API int __stdcall InstallDLKey(unsigned char* pDirID, unsigned char cKeyID, unsigned char* pNewKey, int iKeyType, unsigned char* pMainKey); | ||
12 | -DL_DLL_API int __stdcall DisconnectDLDevice(); | ||
13 | 10 | ||
14 | -#endif | ||
15 | \ No newline at end of file | 11 | \ No newline at end of file |
12 | +/* 连接读卡器 */ | ||
13 | +DL_DLL_API int __stdcall DLCConnectDevice(); | ||
14 | + | ||
15 | +/* 关闭读卡器 */ | ||
16 | +DL_DLL_API int __stdcall DLCDisconnectDevice(); | ||
17 | + | ||
18 | +/* 寻卡 */ | ||
19 | +DL_DLL_API int __stdcall DLCFindCard(); | ||
20 | + | ||
21 | +/* | ||
22 | + * 验证秘钥 | ||
23 | + * 输入16字节秘钥key_。 | ||
24 | + * 返回值返回结果 | ||
25 | + * */ | ||
26 | +DL_DLL_API int __stdcall DLCAuthenticationKey(const unsigned char* dir, const unsigned char key_id, const unsigned char* key); | ||
27 | + | ||
28 | +/* | ||
29 | + * 读取数据 | ||
30 | + * 输入dir2字节目录标识、file_id1字节文件标识、read_offset2字节、 | ||
31 | + * data_len2字节、read_key16字节读秘钥(没有置空)和read_data(长度依据读取长度而定)。 | ||
32 | + * 输出结果填入read_data。 | ||
33 | + * */ | ||
34 | +DL_DLL_API int __stdcall DLCReadCardData(const unsigned char* dir, const unsigned char file_id, const unsigned int data_offset, const unsigned int data_len, const unsigned char* read_key, unsigned char* read_data); | ||
35 | + | ||
36 | +/* | ||
37 | +* 写入数据 | ||
38 | +* 输入dir2字节目录标识、file_id2字节文件标识、read_offset2字节、 | ||
39 | +* data_len2字节、read_key16字节读秘钥(没有置空)和read_data(长度依据读取长度而定)。 | ||
40 | +* 输出结果填入read_data。 | ||
41 | +* */ | ||
42 | +DL_DLL_API int __stdcall DLCWriteCardData(const unsigned char* dir, const unsigned char file_id, const unsigned int data_offset, const unsigned int data_len, const unsigned char* write_key, const unsigned char* write_data); | ||
43 | + | ||
44 | +/* | ||
45 | + * 安装/更新秘钥 | ||
46 | + * 输入dir2字节目录标识、key_id1字节文件标识、key_type32位秘钥类型、 | ||
47 | + * main_key16字节主控秘钥(没有置空)、new_key16字节新秘钥。 | ||
48 | + **/ | ||
49 | +DL_DLL_API int __stdcall DLCInstallKey(const unsigned char* dir, const unsigned char key_id, const int key_type, const unsigned char* main_key, const unsigned char* new_key); | ||
50 | + | ||
51 | +/* | ||
52 | + * 建立文件 | ||
53 | + * 输入parent_dir2字节父目录、parent_key2字节父目录主控秘钥、file_name2字节文件标识、 | ||
54 | + * file_size2字节文件大小、safe_type4字节安全类型和file_type4字节文件类型 | ||
55 | + **/ | ||
56 | +DL_DLL_API int __stdcall DLCCreateFile(const unsigned char* parent_dir, const unsigned char* parent_key, const unsigned char* file_name, const unsigned char* file_size, const int file_type); | ||
57 | + | ||
58 | + | ||
59 | +DL_DLL_API int __stdcall DLCSelectFile(const unsigned char* dir); | ||
60 | + | ||
61 | +//SO库API | ||
62 | +// | ||
63 | +/* | ||
64 | + * 该函数用以获取8字节随机数 | ||
65 | + * 输入5字节的无符号字符型数组指针,函数将更改数组内容,输出5字节指令。 | ||
66 | + * 返回值返回错误码。 | ||
67 | + */ | ||
68 | +int __stdcall DLCSOGetRandom(unsigned char* get_randam_cmd); | ||
69 | + | ||
70 | +/* | ||
71 | + * 该函数用于验证秘钥。 | ||
72 | + * 输入key_id1字节秘钥标识、key16字节16进制秘钥值和random8字节16进制随机数,返回cmd13字节16进制指令。 | ||
73 | + * 返回值返回结果。 | ||
74 | + */ | ||
75 | +int __stdcall DLCSOAuthenticationKey(const unsigned char key_id, const unsigned char* key, const unsigned char* random, unsigned char* cmd); | ||
76 | + | ||
77 | +/* | ||
78 | + * 该函数用于读取数据。 | ||
79 | + * 输入data_offfset数据初始偏移,data_offfset最大为ffff,data_len数据长度,data_len最大为ff,返回16进制cmd指令,cmd数组长度 = data_len + 5。 | ||
80 | + * 读出的数据将存在data_中。 | ||
81 | + * 返回值返回错误码。 | ||
82 | + */ | ||
83 | +int __stdcall DLCSOReadData(const unsigned int data_offfset, const unsigned int data_len, unsigned char* cmd); | ||
84 | + | ||
85 | +/* | ||
86 | +* 该函数用于写入数据。 | ||
87 | +* 输入write_key字节16进制读秘钥(没有置空)、random8字节16进制随机数(没有置空)、data_offfset2字节数据初始偏移、data_len2字节数据长度和data16进制数据,cmd数组长度 = data_len + 9。 | ||
88 | +* 返回值返回错误码。 | ||
89 | +*/ | ||
90 | +int __stdcall DLCSOWriteData(const unsigned char* write_key, const unsigned char* random, const unsigned int data_offfset, const unsigned int data_len, const unsigned char* data, unsigned char* cmd); | ||
91 | + | ||
92 | + | ||
93 | +/*该函数用于选择目录 | ||
94 | + *输入dir两字节16进制目录标识,返回cmd7字节16进制指令 | ||
95 | + **/ | ||
96 | +int __stdcall DLCSOSelectDir(const unsigned char* dir, unsigned char* cmd); | ||
97 | + | ||
98 | + | ||
99 | +//m1卡api | ||
100 | +/*输入section扇区编号,长度为12的16进制秘钥key | ||
101 | + **/ | ||
102 | +DL_DLL_API int __stdcall DLCM1AuthenticationKey(const unsigned short section, unsigned char* key); | ||
103 | + | ||
104 | +/*读取m1卡 | ||
105 | + *输入block_num数据块编号,返回16字节数据块 | ||
106 | + */ | ||
107 | +DL_DLL_API int __stdcall DLCM1ReadCard(const unsigned short block_num, const unsigned char* data); | ||
108 | + | ||
109 | +/*写入m1卡 | ||
110 | + *输入block_num数据块编号,返回16字节数据块 | ||
111 | + **/ | ||
112 | +DL_DLL_API int __stdcall DLCM1WriteCard(const unsigned short block_num, const unsigned char* data); | ||
113 | + | ||
114 | +/*m1卡寻卡 | ||
115 | + **/ | ||
116 | +DL_DLL_API int __stdcall DLCM1FindCard(); | ||
117 | + | ||
118 | +#endif //end DL_CARD_MANAGER_H | ||
16 | \ No newline at end of file | 119 | \ No newline at end of file |
etrade_card_client/ETradeClient/hardware/dili_card_device.cpp
@@ -103,7 +103,6 @@ namespace DILICard | @@ -103,7 +103,6 @@ namespace DILICard | ||
103 | 103 | ||
104 | RWDevice::RWDevice() | 104 | RWDevice::RWDevice() |
105 | { | 105 | { |
106 | - Init(); | ||
107 | } | 106 | } |
108 | RWDevice::~RWDevice() | 107 | RWDevice::~RWDevice() |
109 | { | 108 | { |
@@ -113,7 +112,7 @@ namespace DILICard | @@ -113,7 +112,7 @@ namespace DILICard | ||
113 | { | 112 | { |
114 | bool bResult = true; | 113 | bool bResult = true; |
115 | 114 | ||
116 | - int iResult = ConnectDLDevice(); | 115 | + int iResult = DLCConnectDevice(); |
117 | if (0 != iResult) | 116 | if (0 != iResult) |
118 | { | 117 | { |
119 | bResult = false; | 118 | bResult = false; |
@@ -124,17 +123,14 @@ namespace DILICard | @@ -124,17 +123,14 @@ namespace DILICard | ||
124 | } | 123 | } |
125 | void RWDevice::Disconnect() const | 124 | void RWDevice::Disconnect() const |
126 | { | 125 | { |
127 | - DisconnectDLDevice(); | ||
128 | - } | ||
129 | - void RWDevice::Beep(uint32_t time) const | ||
130 | - { | ||
131 | - m_fn_beep(time); | 126 | + DLCDisconnectDevice(); |
132 | } | 127 | } |
128 | + | ||
133 | bool RWDevice::FindCard() const | 129 | bool RWDevice::FindCard() const |
134 | { | 130 | { |
135 | bool bResult = true; | 131 | bool bResult = true; |
136 | 132 | ||
137 | - int iResult = FindDLCard(); | 133 | + int iResult = DLCFindCard(); |
138 | if (0 != iResult) | 134 | if (0 != iResult) |
139 | { | 135 | { |
140 | bResult = false; | 136 | bResult = false; |
@@ -415,34 +411,6 @@ namespace DILICard | @@ -415,34 +411,6 @@ namespace DILICard | ||
415 | } | 411 | } |
416 | 412 | ||
417 | //------Private Implementations---------------- | 413 | //------Private Implementations---------------- |
418 | - void RWDevice::Init() | ||
419 | - { | ||
420 | - //const std::wstring kDLLFile = L"./dyn.dll"; | ||
421 | - //HINSTANCE dll_handle = LoadLibrary(kDLLFile.c_str()); | ||
422 | - //if (NULL != dll_handle) | ||
423 | - //{ | ||
424 | - // m_fn_open = (OpenFn)GetProcAddress(dll_handle, "open"); | ||
425 | - // m_fn_beep = (BeepFn)GetProcAddress(dll_handle, "beep"); | ||
426 | - // m_fn_close = (CloseFn)GetProcAddress(dll_handle, "close"); | ||
427 | - // m_fn_find_card = (FindCardFn)GetProcAddress(dll_handle, "findCard"); | ||
428 | - // m_fn_write_bin_data = (WriteBinaryDataFn)GetProcAddress(dll_handle, "write_bin_file"); | ||
429 | - // m_fn_get_value = (GetValueFn)GetProcAddress(dll_handle, "get_value_char"); // Don't use "get_value" version!!! | ||
430 | - // m_fn_ch_dir = (ChangeDirFn)GetProcAddress(dll_handle, "chang_dir"); | ||
431 | - // m_fn_read_bin_data = (ReadBinaryDataFn)GetProcAddress(dll_handle, "read_bin_file"); | ||
432 | - // m_fn_ex_auth = (ExternalAuthFn)GetProcAddress(dll_handle, "External_Authentication"); | ||
433 | - // m_fn_install_key = (InstallKeyFn)GetProcAddress(dll_handle, "InstallKey"); | ||
434 | - //} | ||
435 | - //else | ||
436 | - // throw std::exception(("Fail to load the DILI card device DLL from path : " + wstr_2_str(kDLLFile)).c_str()); | ||
437 | - } | ||
438 | - | ||
439 | - std::string RWDevice::GetValue() const | ||
440 | - { | ||
441 | - char val[DEFAULT_DATA_BLOCK_LEN] = { 0 }; | ||
442 | - m_fn_get_value(&val[0]); | ||
443 | - return val; | ||
444 | - } | ||
445 | - | ||
446 | std::string RWDevice::ReadCardFile(const std::string& dir, | 414 | std::string RWDevice::ReadCardFile(const std::string& dir, |
447 | char file_id, | 415 | char file_id, |
448 | uint32_t offset, | 416 | uint32_t offset, |
@@ -457,11 +425,11 @@ namespace DILICard | @@ -457,11 +425,11 @@ namespace DILICard | ||
457 | if (NULL != key_id) | 425 | if (NULL != key_id) |
458 | { | 426 | { |
459 | memcpy(aucKey, key.c_str(), 32); | 427 | memcpy(aucKey, key.c_str(), 32); |
460 | - iResult = ReadDLCardData(aucDir, file_id, offset, length, aucData, aucKey); | 428 | + iResult = DLCReadCardData(aucDir, file_id, offset, length, aucData, aucKey); |
461 | } | 429 | } |
462 | else | 430 | else |
463 | { | 431 | { |
464 | - iResult = ReadDLCardData(aucDir, file_id, offset, length, aucData); | 432 | + iResult = DLCReadCardData(aucDir, file_id, offset, length, NULL, aucData); |
465 | } | 433 | } |
466 | 434 | ||
467 | 435 | ||
@@ -499,7 +467,7 @@ namespace DILICard | @@ -499,7 +467,7 @@ namespace DILICard | ||
499 | { | 467 | { |
500 | unsigned char aucDataBlock[DATA_MAX_LEN] = { 0 }; | 468 | unsigned char aucDataBlock[DATA_MAX_LEN] = { 0 }; |
501 | memcpy(aucDataBlock, data.substr(iStartIndex, DATA_MAX_LEN).c_str(), DATA_MAX_LEN); | 469 | memcpy(aucDataBlock, data.substr(iStartIndex, DATA_MAX_LEN).c_str(), DATA_MAX_LEN); |
502 | - iResult = WriteDLCardData(aucDir, file_id, iOffset, DATA_MAX_LEN, aucDataBlock, aucKey); | 470 | + iResult = DLCWriteCardData(aucDir, file_id, iOffset, DATA_MAX_LEN, aucDataBlock, aucKey); |
503 | if (0 != iResult) | 471 | if (0 != iResult) |
504 | { | 472 | { |
505 | err_msg << "Write data to file failed, FILE: " << file_id << ", ErrorCode: " << iResult; | 473 | err_msg << "Write data to file failed, FILE: " << file_id << ", ErrorCode: " << iResult; |
@@ -514,7 +482,7 @@ namespace DILICard | @@ -514,7 +482,7 @@ namespace DILICard | ||
514 | { | 482 | { |
515 | unsigned char aucData[DATA_MAX_LEN] = { 0 }; | 483 | unsigned char aucData[DATA_MAX_LEN] = { 0 }; |
516 | memcpy(aucData, data.substr(iStartIndex, iDataLength).c_str(), iDataLength); | 484 | memcpy(aucData, data.substr(iStartIndex, iDataLength).c_str(), iDataLength); |
517 | - iResult = WriteDLCardData(aucDir, file_id, iOffset, iDataLength, aucData, aucKey); | 485 | + iResult = DLCWriteCardData(aucDir, file_id, iOffset, iDataLength, aucData, aucKey); |
518 | if (0 != iResult) | 486 | if (0 != iResult) |
519 | { | 487 | { |
520 | err_msg << "Write data to file failed, FILE: " << file_id << ", ErrorCode: " << iResult; | 488 | err_msg << "Write data to file failed, FILE: " << file_id << ", ErrorCode: " << iResult; |
@@ -536,7 +504,7 @@ namespace DILICard | @@ -536,7 +504,7 @@ namespace DILICard | ||
536 | memcpy(aucDir, dir.c_str(), 4); | 504 | memcpy(aucDir, dir.c_str(), 4); |
537 | memcpy(aucMainKey, main_key.c_str(), 32); | 505 | memcpy(aucMainKey, main_key.c_str(), 32); |
538 | memcpy(aucNewKey, install_key.c_str(), 32); | 506 | memcpy(aucNewKey, install_key.c_str(), 32); |
539 | - int iResult = InstallDLKey(aucDir, key_id, aucNewKey, emKeyType, aucMainKey); | 507 | + int iResult = DLCInstallKey(aucDir, key_id, emKeyType, aucMainKey, aucNewKey); |
540 | if (0 != iResult) | 508 | if (0 != iResult) |
541 | { | 509 | { |
542 | err_msg << "Update key failed, key to be updated: " << install_key << ", ErrorCode: " << iResult; | 510 | err_msg << "Update key failed, key to be updated: " << install_key << ", ErrorCode: " << iResult; |
@@ -549,7 +517,7 @@ namespace DILICard | @@ -549,7 +517,7 @@ namespace DILICard | ||
549 | bool bResult = true; | 517 | bool bResult = true; |
550 | unsigned char aucKey[32] = { 0 }; | 518 | unsigned char aucKey[32] = { 0 }; |
551 | memcpy(aucKey, sKey.c_str(), 32); | 519 | memcpy(aucKey, sKey.c_str(), 32); |
552 | - int iResult = AuthenticationDLKey(aucKey); | 520 | + int iResult = DLCAuthenticationKey((const unsigned char*)"3f00", 0, aucKey); |
553 | if (iResult) | 521 | if (iResult) |
554 | { | 522 | { |
555 | bResult = false; | 523 | bResult = false; |
etrade_card_client/ETradeClient/hardware/dili_card_device.h
@@ -41,23 +41,12 @@ namespace DILICard | @@ -41,23 +41,12 @@ namespace DILICard | ||
41 | 41 | ||
42 | class RWDevice | 42 | class RWDevice |
43 | { | 43 | { |
44 | - typedef bool(__stdcall *OpenFn)(); | ||
45 | - typedef void(__stdcall *CloseFn)(); | ||
46 | - typedef void(__stdcall *BeepFn)(int time); // Unit: 10ms. | ||
47 | - typedef int(__stdcall *FindCardFn)(char* sn); // This function will read the card serial number. | ||
48 | - typedef bool(__stdcall *WriteBinaryDataFn)(char file_id, int offset, int length, const char* key, const char* data); | ||
49 | - typedef bool(__stdcall *ChangeDirFn)(const char* dir); | ||
50 | - typedef void(__stdcall *GetValueFn)(char* value); | ||
51 | - typedef bool(__stdcall *ReadBinaryDataFn)(char file_id, int offset, int length); | ||
52 | - typedef bool(__stdcall *ExternalAuthFn)(char key_id, const char* key); | ||
53 | - typedef bool(__stdcall *InstallKeyFn)(const char* main_key, const char* cmd_head, const char* install_key, bool is_main_key, bool); | ||
54 | public: | 44 | public: |
55 | RWDevice(); | 45 | RWDevice(); |
56 | ~RWDevice(); | 46 | ~RWDevice(); |
57 | 47 | ||
58 | bool Connect() const; | 48 | bool Connect() const; |
59 | void Disconnect() const; | 49 | void Disconnect() const; |
60 | - void Beep(uint32_t time) const; // Unit: 10ms. | ||
61 | bool FindCard() const; // If card found, card's serial number will be returned. | 50 | bool FindCard() const; // If card found, card's serial number will be returned. |
62 | void ActivateCard(const std::string& card_sn, | 51 | void ActivateCard(const std::string& card_sn, |
63 | const std::string& key_DCCK, | 52 | const std::string& key_DCCK, |
@@ -70,6 +59,10 @@ namespace DILICard | @@ -70,6 +59,10 @@ namespace DILICard | ||
70 | void WriteCardServiceInfo(const std::string& key_F0015_DAMK1, const std::string& data) const; | 59 | void WriteCardServiceInfo(const std::string& key_F0015_DAMK1, const std::string& data) const; |
71 | bool AuthenticationKey(const std::string sKey) const; | 60 | bool AuthenticationKey(const std::string sKey) const; |
72 | 61 | ||
62 | + int M1FindCard() const; | ||
63 | + BasicInfo M1ReadBasicInfo() const; | ||
64 | + int M1WriteBasicInfo(std::string card_num, std::string card_type_num, std::string market_id, std::string safe_code, std::string m1_type, std::string card_version); | ||
65 | + | ||
73 | enum KeyType | 66 | enum KeyType |
74 | { | 67 | { |
75 | KT_DCCK = 0, | 68 | KT_DCCK = 0, |
@@ -77,8 +70,6 @@ namespace DILICard | @@ -77,8 +70,6 @@ namespace DILICard | ||
77 | KT_DAMK, | 70 | KT_DAMK, |
78 | }; | 71 | }; |
79 | private: | 72 | private: |
80 | - void Init(); | ||
81 | - std::string GetValue() const; | ||
82 | std::string ReadCardFile(const std::string& dir, | 73 | std::string ReadCardFile(const std::string& dir, |
83 | char file_id, | 74 | char file_id, |
84 | uint32_t offset, | 75 | uint32_t offset, |
@@ -96,18 +87,6 @@ namespace DILICard | @@ -96,18 +87,6 @@ namespace DILICard | ||
96 | const std::string& main_key, | 87 | const std::string& main_key, |
97 | const std::string& install_key, | 88 | const std::string& install_key, |
98 | KeyType emKeyType) const; | 89 | KeyType emKeyType) const; |
99 | - | ||
100 | - private: | ||
101 | - OpenFn m_fn_open; | ||
102 | - BeepFn m_fn_beep; | ||
103 | - CloseFn m_fn_close; | ||
104 | - FindCardFn m_fn_find_card; | ||
105 | - WriteBinaryDataFn m_fn_write_bin_data; | ||
106 | - ChangeDirFn m_fn_ch_dir; | ||
107 | - GetValueFn m_fn_get_value; | ||
108 | - ReadBinaryDataFn m_fn_read_bin_data; | ||
109 | - ExternalAuthFn m_fn_ex_auth; | ||
110 | - InstallKeyFn m_fn_install_key; | ||
111 | }; | 90 | }; |
112 | } // DILICard | 91 | } // DILICard |
113 | #endif // ETRADECLIENT_HARDWARE_DILI_CARD_DEVICE_H_INCLUDED | 92 | #endif // ETRADECLIENT_HARDWARE_DILI_CARD_DEVICE_H_INCLUDED |
etrade_card_client/ETradeClient/hardware/hardware_cmd.cpp
@@ -763,104 +763,116 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | @@ -763,104 +763,116 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | ||
763 | auto& dili_card_device = DILICardRWDevice(); | 763 | auto& dili_card_device = DILICardRWDevice(); |
764 | Reply reply; | 764 | Reply reply; |
765 | DILICard::BasicInfo card_basic_info; | 765 | DILICard::BasicInfo card_basic_info; |
766 | - do | 766 | + |
767 | + do | ||
767 | { | 768 | { |
768 | - try | ||
769 | - { | ||
770 | - dili_card_device.Connect(); | ||
771 | - } | ||
772 | - catch (std::exception& ex) | ||
773 | - { | ||
774 | - LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); | ||
775 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; | ||
776 | - break; | ||
777 | - } | ||
778 | try | 769 | try |
779 | { | 770 | { |
780 | - dili_card_device.FindCard(); | 771 | + dili_card_device.Connect(); |
781 | } | 772 | } |
782 | catch (std::exception& ex) | 773 | catch (std::exception& ex) |
783 | { | 774 | { |
784 | - LOG_FATAL(L"寻卡失败,错误信息: " + str_2_wstr(ex.what())); | ||
785 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | 775 | + LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); |
776 | + reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; | ||
786 | break; | 777 | break; |
787 | } | 778 | } |
788 | 779 | ||
789 | - try { card_basic_info = dili_card_device.ReadCardBasicInfo(); } | ||
790 | - catch (std::exception& ex) | 780 | + //读取CPU卡 |
781 | + do | ||
791 | { | 782 | { |
792 | - LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | ||
793 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | ||
794 | - break; | ||
795 | - } | 783 | + try |
784 | + { | ||
785 | + dili_card_device.FindCard(); | ||
786 | + } | ||
787 | + catch (std::exception& ex) | ||
788 | + { | ||
789 | + LOG_FATAL(L"寻卡失败,错误信息: " + str_2_wstr(ex.what())); | ||
790 | + reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | ||
791 | + break; | ||
792 | + } | ||
796 | 793 | ||
797 | - | ||
798 | - if (SL_2 == ApplicationConfig::Instance().SecurityLevel()) | ||
799 | - { | ||
800 | - LOG_TRACE(L"计算主控秘钥。"); | ||
801 | - std::string sSN = card_basic_info.chip_num + "44494c49" + card_basic_info.chip_num; | ||
802 | - std::string sDCCK; | 794 | + try { card_basic_info = dili_card_device.ReadCardBasicInfo(); } |
795 | + catch (std::exception& ex) | ||
796 | + { | ||
797 | + LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | ||
798 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | ||
799 | + break; | ||
800 | + } | ||
803 | 801 | ||
804 | - if (ET_DES == ApplicationConfig::Instance().EncryptType()) | 802 | + |
803 | + if (SL_2 == ApplicationConfig::Instance().SecurityLevel()) | ||
805 | { | 804 | { |
806 | - LOG_TRACE(L"软加密模式计算主控秘钥。"); | ||
807 | - const char* pDCCKDL = "43434bff43434bff"; | 805 | + LOG_TRACE(L"计算主控秘钥。"); |
806 | + std::string sSN = card_basic_info.chip_num + "44494c49" + card_basic_info.chip_num; | ||
807 | + std::string sDCCK; | ||
808 | 808 | ||
809 | - unsigned char aucCardSNHex[16] = { 0 }; | ||
810 | - unsigned char aucDCCKDL[8] = { 0 }; | ||
811 | - EncryptTools::StringToHex((unsigned char*)pDCCKDL, 16, aucDCCKDL); | ||
812 | - EncryptTools::StringToHex((unsigned char*)sSN.c_str(), 32, aucCardSNHex); | 809 | + if (ET_DES == ApplicationConfig::Instance().EncryptType()) |
810 | + { | ||
811 | + LOG_TRACE(L"软加密模式计算主控秘钥。"); | ||
812 | + const char* pDCCKDL = "43434bff43434bff"; | ||
813 | 813 | ||
814 | - unsigned char aucNewDCCKHex[16] = { 0 }; | ||
815 | - unsigned char aucNewDCCK[32] = { 0 }; | 814 | + unsigned char aucCardSNHex[16] = { 0 }; |
815 | + unsigned char aucDCCKDL[8] = { 0 }; | ||
816 | + EncryptTools::StringToHex((unsigned char*)pDCCKDL, 16, aucDCCKDL); | ||
817 | + EncryptTools::StringToHex((unsigned char*)sSN.c_str(), 32, aucCardSNHex); | ||
816 | 818 | ||
817 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDCCKDL, aucNewDCCKHex); | 819 | + unsigned char aucNewDCCKHex[16] = { 0 }; |
820 | + unsigned char aucNewDCCK[32] = { 0 }; | ||
818 | 821 | ||
819 | - EncryptTools::HexToChar(aucNewDCCKHex, 16, aucNewDCCK); | 822 | + EncryptTools::Encrypt(aucCardSNHex, 16, aucDCCKDL, aucNewDCCKHex); |
820 | 823 | ||
821 | - std::string sDCCKKey((char*)aucNewDCCK, 32); | ||
822 | - | ||
823 | - sDCCK = sDCCKKey; | ||
824 | - } | ||
825 | - else if (ET_PWM == ApplicationConfig::Instance().EncryptType()) | ||
826 | - { | ||
827 | - LOG_TRACE(L"加密机模式计算主控秘钥。"); | ||
828 | - const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | ||
829 | - const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | ||
830 | - const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | 824 | + EncryptTools::HexToChar(aucNewDCCKHex, 16, aucNewDCCK); |
831 | 825 | ||
832 | - auto& pwd_machine = PWDMachine_(); | 826 | + std::string sDCCKKey((char*)aucNewDCCK, 32); |
833 | 827 | ||
834 | - if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | ||
835 | - { | ||
836 | - LOG_ERROR(L"连接加密机失败!"); | ||
837 | - reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | 828 | + sDCCK = sDCCKKey; |
838 | } | 829 | } |
839 | - | ||
840 | - try | 830 | + else if (ET_PWM == ApplicationConfig::Instance().EncryptType()) |
841 | { | 831 | { |
842 | - sDCCK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kDCCK>(), sSN, TIMEOUT); | 832 | + LOG_TRACE(L"加密机模式计算主控秘钥。"); |
833 | + const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | ||
834 | + const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | ||
835 | + const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | ||
836 | + | ||
837 | + auto& pwd_machine = PWDMachine_(); | ||
838 | + | ||
839 | + if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | ||
840 | + { | ||
841 | + LOG_ERROR(L"连接加密机失败!"); | ||
842 | + reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | ||
843 | + } | ||
844 | + | ||
845 | + try | ||
846 | + { | ||
847 | + sDCCK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kDCCK>(), sSN, TIMEOUT); | ||
848 | + } | ||
849 | + catch (std::exception& ex) | ||
850 | + { | ||
851 | + LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | ||
852 | + reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | ||
853 | + break; | ||
854 | + } | ||
855 | + pwd_machine.Disconnect(); | ||
843 | } | 856 | } |
844 | - catch (std::exception& ex) | 857 | + |
858 | + LOG_TRACE(L"验证卡片。"); | ||
859 | + if (!dili_card_device.AuthenticationKey(sDCCK)) | ||
845 | { | 860 | { |
846 | - LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | ||
847 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | 861 | + LOG_FATAL(L"秘钥验证失败,卡片需要升级!"); |
862 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_NEED_UPDATE; | ||
848 | break; | 863 | break; |
849 | } | 864 | } |
850 | - pwd_machine.Disconnect(); | ||
851 | - } | ||
852 | 865 | ||
853 | - LOG_TRACE(L"验证卡片。"); | ||
854 | - if (!dili_card_device.AuthenticationKey(sDCCK)) | ||
855 | - { | ||
856 | - LOG_FATAL(L"秘钥验证失败,卡片需要升级!"); | ||
857 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_NEED_UPDATE; | ||
858 | - break; | ||
859 | } | 866 | } |
867 | + } while (0); | ||
860 | 868 | ||
861 | - } | ||
862 | - | 869 | + //读取m1卡 |
870 | + do | ||
871 | + { | ||
872 | + | ||
873 | + } while (0); | ||
863 | } while (0); | 874 | } while (0); |
875 | + | ||
864 | dili_card_device.Disconnect(); | 876 | dili_card_device.Disconnect(); |
865 | if (boost::iequals(reply.error_code, StatusCode::OK)) | 877 | if (boost::iequals(reply.error_code, StatusCode::OK)) |
866 | LOG_TRACE(L"读取卡片基本信息成功。"); | 878 | LOG_TRACE(L"读取卡片基本信息成功。"); |