Commit ea6947f0000ae0627a1e1fab85faf1a997fdeddd
1 parent
e454f69f
feat(etrade_card_client):提交卡务客户端只读卡号版本、
提交卡务客户端只读卡号版本。
Showing
27 changed files
with
603 additions
and
1529 deletions
etrade_card_client/Config/application_config.json
... | ... | @@ -8,8 +8,5 @@ |
8 | 8 | "client_cert_store": "MY", |
9 | 9 | "client_cert_subject": "*.diligrp.com", |
10 | 10 | "client_cert_filename": "", |
11 | - "client_cert_password": "", | |
12 | - "security_level": 0, | |
13 | - "encrypt_type": 1, | |
14 | - "id_reader": 1 | |
11 | + "client_cert_password": "" | |
15 | 12 | } |
16 | 13 | \ No newline at end of file | ... | ... |
etrade_card_client/Config/url_cfg.json
... | ... | @@ -8,6 +8,5 @@ |
8 | 8 | "menu_auth_path":"/counter/loadPermission.do", |
9 | 9 | "user_msg_count_path":"/message/countUserMessage.do", |
10 | 10 | "user_msg_path":"/message/userMessageInit.page", |
11 | - "modify_pwd_path":"/employee/client/initModifyPassword.page", | |
12 | - "server_time_path":"/system/getSystemTime.do" | |
11 | + "modify_pwd_path":"/employee/client/initModifyPassword.page" | |
13 | 12 | } |
14 | 13 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient.rc
... | ... | @@ -77,7 +77,7 @@ IDR_MAINFRAME ICON "res\\ETradeClient.ico" |
77 | 77 | |
78 | 78 | IDR_MAINFRAME MENU |
79 | 79 | BEGIN |
80 | - POPUP "文件(&t)" | |
80 | + POPUP "文件(&F)" | |
81 | 81 | BEGIN |
82 | 82 | MENUITEM "退出(&X)", ID_EXIT |
83 | 83 | END |
... | ... | @@ -196,7 +196,7 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x1 |
196 | 196 | BEGIN |
197 | 197 | END |
198 | 198 | |
199 | -IDD_MODIFY_CONFIG DIALOGEX 0, 0, 324, 257 | |
199 | +IDD_MODIFY_CONFIG DIALOGEX 0, 0, 324, 207 | |
200 | 200 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU |
201 | 201 | CAPTION "客户端配置" |
202 | 202 | FONT 9, "MS Shell Dlg", 0, 0, 0x0 |
... | ... | @@ -224,11 +224,8 @@ BEGIN |
224 | 224 | LTEXT "操作超时",IDC_STATIC,185,140,28,8 |
225 | 225 | EDITTEXT IDC_EDIT_PIN_PAD_TIMEOUT,224,139,40,12,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER |
226 | 226 | LTEXT "秒",IDC_STATIC,266,140,14,8 |
227 | - DEFPUSHBUTTON "确定",IDOK,102,228,50,14 | |
228 | - PUSHBUTTON "取消",IDCANCEL,165,228,50,14 | |
229 | - GROUPBOX "身份证读卡器",IDC_STATIC_IDREADER,18,168,288,42 | |
230 | - CONTROL "华视电子读卡器",IDC_RADIO_HUASHIDIANZI,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,60,186,64,10 | |
231 | - CONTROL "新中新电子读卡器",IDC_RADIO_XINZHONGXIN,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,174,186,71,10 | |
227 | + DEFPUSHBUTTON "确定",IDOK,103,174,50,14 | |
228 | + PUSHBUTTON "取消",IDCANCEL,165,174,50,14 | |
232 | 229 | END |
233 | 230 | |
234 | 231 | |
... | ... | @@ -296,7 +293,7 @@ BEGIN |
296 | 293 | LEFTMARGIN, 7 |
297 | 294 | RIGHTMARGIN, 317 |
298 | 295 | TOPMARGIN, 7 |
299 | - BOTTOMMARGIN, 248 | |
296 | + BOTTOMMARGIN, 198 | |
300 | 297 | END |
301 | 298 | END |
302 | 299 | #endif // APSTUDIO_INVOKED |
... | ... | @@ -346,7 +343,6 @@ BEGIN |
346 | 343 | ID_INDICATOR_SCRL "SCRL" |
347 | 344 | ID_INDICATOR_OVR "OVR" |
348 | 345 | ID_INDICATOR_REC "REC" |
349 | - ID_INDICATOR_TIME "00:00:00" | |
350 | 346 | END |
351 | 347 | |
352 | 348 | STRINGTABLE | ... | ... |
etrade_card_client/ETradeClient.vcxproj
... | ... | @@ -60,7 +60,6 @@ |
60 | 60 | <Link> |
61 | 61 | <SubSystem>Windows</SubSystem> |
62 | 62 | <GenerateDebugInformation>true</GenerateDebugInformation> |
63 | - <AdditionalDependencies>dlcm.lib;SynIDCardAPI.lib;DesDLL.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
64 | 63 | </Link> |
65 | 64 | <Midl> |
66 | 65 | <MkTypLibCompatible>false</MkTypLibCompatible> |
... | ... | @@ -87,7 +86,6 @@ |
87 | 86 | <GenerateDebugInformation>true</GenerateDebugInformation> |
88 | 87 | <EnableCOMDATFolding>true</EnableCOMDATFolding> |
89 | 88 | <OptimizeReferences>true</OptimizeReferences> |
90 | - <AdditionalDependencies>dlcm.lib;SynIDCardAPI.lib;DesDLL.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
91 | 89 | </Link> |
92 | 90 | <Midl> |
93 | 91 | <MkTypLibCompatible>false</MkTypLibCompatible> |
... | ... | @@ -121,12 +119,11 @@ |
121 | 119 | <ClInclude Include="ETradeClient\browser\popup_browser_handler.h" /> |
122 | 120 | <ClInclude Include="ETradeClient\hardware\bank_card_reader.h" /> |
123 | 121 | <ClInclude Include="ETradeClient\hardware\dili_card_device.h" /> |
124 | - <ClInclude Include="ETradeClient\hardware\DLCardManager.h" /> | |
122 | + <ClInclude Include="ETradeClient\hardware\DLCamCardManager.h" /> | |
125 | 123 | <ClInclude Include="ETradeClient\hardware\hardware_cmd.h" /> |
126 | 124 | <ClInclude Include="ETradeClient\hardware\id_card_reader.h" /> |
127 | 125 | <ClInclude Include="ETradeClient\hardware\password_machine.h" /> |
128 | 126 | <ClInclude Include="ETradeClient\hardware\pin_pad.h" /> |
129 | - <ClInclude Include="ETradeClient\hardware\SynPublic.h" /> | |
130 | 127 | <ClInclude Include="ETradeClient\mfc_ui\ETradeClient.h" /> |
131 | 128 | <ClInclude Include="ETradeClient\mfc_ui\ETradeClientView.h" /> |
132 | 129 | <ClInclude Include="ETradeClient\mfc_ui\LoginDialog.h" /> |
... | ... | @@ -135,9 +132,6 @@ |
135 | 132 | <ClInclude Include="ETradeClient\mfc_ui\PopupBrowserDlgView.h" /> |
136 | 133 | <ClInclude Include="ETradeClient\mfc_ui\ConfigDialog.h" /> |
137 | 134 | <ClInclude Include="ETradeClient\utility\application_config.h" /> |
138 | - <ClInclude Include="ETradeClient\utility\DLBmpManager.h" /> | |
139 | - <ClInclude Include="ETradeClient\utility\DLDes.h" /> | |
140 | - <ClInclude Include="ETradeClient\utility\ETTimeManage.h" /> | |
141 | 135 | <ClInclude Include="ETradeClient\utility\logging.h" /> |
142 | 136 | <ClInclude Include="ETradeClient\utility\menu_res_auth_mgr.h" /> |
143 | 137 | <ClInclude Include="ETradeClient\utility\openssl_aes_cbc.h" /> |
... | ... | @@ -165,6 +159,7 @@ |
165 | 159 | <ClCompile Include="ETradeClient\browser\popup_browser_handler.cpp" /> |
166 | 160 | <ClCompile Include="ETradeClient\hardware\bank_card_reader.cpp" /> |
167 | 161 | <ClCompile Include="ETradeClient\hardware\dili_card_device.cpp" /> |
162 | + <ClCompile Include="ETradeClient\hardware\DLCamCardManager.cpp" /> | |
168 | 163 | <ClCompile Include="ETradeClient\hardware\hardware_cmd.cpp" /> |
169 | 164 | <ClCompile Include="ETradeClient\hardware\id_card_reader.cpp" /> |
170 | 165 | <ClCompile Include="ETradeClient\hardware\password_machine.cpp" /> |
... | ... | @@ -177,8 +172,6 @@ |
177 | 172 | <ClCompile Include="ETradeClient\mfc_ui\PopupBrowserDlgView.cpp" /> |
178 | 173 | <ClCompile Include="ETradeClient\mfc_ui\ConfigDialog.cpp" /> |
179 | 174 | <ClCompile Include="ETradeClient\utility\application_config.cpp" /> |
180 | - <ClCompile Include="ETradeClient\utility\DLBmpManager.cpp" /> | |
181 | - <ClCompile Include="ETradeClient\utility\ETTimeManage.cpp" /> | |
182 | 175 | <ClCompile Include="ETradeClient\utility\logging.cpp" /> |
183 | 176 | <ClCompile Include="ETradeClient\utility\menu_res_auth_mgr.cpp" /> |
184 | 177 | <ClCompile Include="ETradeClient\utility\openssl_aes_cbc.cpp" /> | ... | ... |
etrade_card_client/ETradeClient.vcxproj.filters
... | ... | @@ -168,21 +168,9 @@ |
168 | 168 | <ClInclude Include="ETradeClient\browser\error_page.h"> |
169 | 169 | <Filter>Header Files\browser</Filter> |
170 | 170 | </ClInclude> |
171 | - <ClInclude Include="ETradeClient\hardware\SynPublic.h"> | |
171 | + <ClInclude Include="ETradeClient\hardware\DLCamCardManager.h"> | |
172 | 172 | <Filter>Header Files\hardware</Filter> |
173 | 173 | </ClInclude> |
174 | - <ClInclude Include="ETradeClient\hardware\DLCardManager.h"> | |
175 | - <Filter>Header Files\hardware</Filter> | |
176 | - </ClInclude> | |
177 | - <ClInclude Include="ETradeClient\utility\DLBmpManager.h"> | |
178 | - <Filter>Header Files\utility</Filter> | |
179 | - </ClInclude> | |
180 | - <ClInclude Include="ETradeClient\utility\DLDes.h"> | |
181 | - <Filter>Header Files\utility</Filter> | |
182 | - </ClInclude> | |
183 | - <ClInclude Include="ETradeClient\utility\ETTimeManage.h"> | |
184 | - <Filter>Header Files\utility</Filter> | |
185 | - </ClInclude> | |
186 | 174 | </ItemGroup> |
187 | 175 | <ItemGroup> |
188 | 176 | <ClCompile Include="stdafx.cpp"> |
... | ... | @@ -248,6 +236,9 @@ |
248 | 236 | <ClCompile Include="ETradeClient\browser\popup_browser_handler.cpp"> |
249 | 237 | <Filter>Source Files\browser</Filter> |
250 | 238 | </ClCompile> |
239 | + <ClCompile Include="ETradeClient\mfc_ui\PopupBrowserDlgView.cpp"> | |
240 | + <Filter>Source Files\mfc_ui</Filter> | |
241 | + </ClCompile> | |
251 | 242 | <ClCompile Include="ETradeClient\mfc_ui\LoginEdit.cpp"> |
252 | 243 | <Filter>Source Files\mfc_ui</Filter> |
253 | 244 | </ClCompile> |
... | ... | @@ -281,14 +272,8 @@ |
281 | 272 | <ClCompile Include="ETradeClient\browser\error_page.cpp"> |
282 | 273 | <Filter>Source Files\browser</Filter> |
283 | 274 | </ClCompile> |
284 | - <ClCompile Include="ETradeClient\mfc_ui\PopupBrowserDlgView.cpp"> | |
285 | - <Filter>Source Files\mfc_ui</Filter> | |
286 | - </ClCompile> | |
287 | - <ClCompile Include="ETradeClient\utility\DLBmpManager.cpp"> | |
288 | - <Filter>Source Files\utility</Filter> | |
289 | - </ClCompile> | |
290 | - <ClCompile Include="ETradeClient\utility\ETTimeManage.cpp"> | |
291 | - <Filter>Source Files\utility</Filter> | |
275 | + <ClCompile Include="ETradeClient\hardware\DLCamCardManager.cpp"> | |
276 | + <Filter>Source Files\hardware</Filter> | |
292 | 277 | </ClCompile> |
293 | 278 | </ItemGroup> |
294 | 279 | <ItemGroup> | ... | ... |
etrade_card_client/ETradeClient/browser/async_js_callback_handler.cpp
... | ... | @@ -109,10 +109,10 @@ namespace HW |
109 | 109 | |
110 | 110 | |
111 | 111 | LOG_TRACE(L"Ö´ÐÐÓ²¼þµ÷ÓÃÇëÇó:" + str_2_wstr("[" + hw_req.cmd + "," +hw_req.file_id + "," + hw_req.seq + "]")); |
112 | - | |
112 | + | |
113 | 113 | HardwareCmd::Reply reply = m_hw_cmd_map.at(hw_req.cmd + hw_req.file_id).Execute(hw_req.data); |
114 | 114 | std::string answer = ""; |
115 | - if (boost::iequals(OK, reply.error_code) || boost::iequals("309", reply.error_code)) // Succeed. | |
115 | + if (boost::iequals(OK, reply.error_code)) // Succeed. | |
116 | 116 | answer = hw_req.cmd + "_ack"; |
117 | 117 | else |
118 | 118 | answer = hw_req.cmd + "_failed"; | ... | ... |
etrade_card_client/ETradeClient/hardware/DLCamCardManager.cpp
0 → 100644
1 | +#include "stdafx.h" | |
2 | +#include <exception> | |
3 | +#include <cstdint> | |
4 | +#include <sstream> | |
5 | +#include <iomanip> // hex conversion. | |
6 | +#include <intrin.h> | |
7 | +#include "etradeclient/hardware/DLCamCardManager.h" | |
8 | +#include "etradeclient/hardware/ex_reference/bank_card_reader/dcrf32.h" | |
9 | +#include "ETradeClient/hardware/dili_card_device.h" | |
10 | + // Endian conversion. | |
11 | + | |
12 | +static const uint8_t CARD_CHIP_NUM_LEN = 12; // 卡面号 | |
13 | +static const uint8_t CARD_TYPE_CODE_LEN = 16; // 卡片类型码(卡类型编码) | |
14 | +static const uint8_t CARD_ISSUER_CODE_LEN = 20; // 发卡机构编码 | |
15 | +static const uint8_t CARD_VERIFY_CODE_LEN = 8; // 校验码(安全码编码(3位数)) | |
16 | +static const uint8_t CARD_SN_LEN = 32; // 卡片内码, 卡序列号SN | |
17 | + | |
18 | +static const uint8_t CARD_TYPE_CODE_LEN_USE = 6; | |
19 | +static const uint8_t CARD_ISSUER_CODE_LEN_USE = 4; | |
20 | +static const uint8_t CARD_VERIFY_CODE_LEN_USE = 3; | |
21 | + | |
22 | +static const char PADDING_CHAR = 'f'; | |
23 | + | |
24 | +template <typename T> | |
25 | +std::string DecToHex(T d, bool show_base = false) | |
26 | +{ | |
27 | + std::stringstream ss; | |
28 | + if (show_base) | |
29 | + ss << "0x"; | |
30 | + ss << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex << static_cast<int>(d); | |
31 | + return ss.str(); | |
32 | +} | |
33 | + | |
34 | +DLCamCardManager::DLCamCardManager() : | |
35 | +m_icdev(NULL) | |
36 | +{} | |
37 | + | |
38 | +DLCamCardManager::~DLCamCardManager() | |
39 | +{ | |
40 | + DisConnect(); | |
41 | +} | |
42 | + | |
43 | +std::string DLCamCardManager::HexToChar(unsigned char* pHex, int iLen) | |
44 | +{ | |
45 | + std::string sResult; | |
46 | + if (pHex && iLen) | |
47 | + { | |
48 | + for (int index = 0; index < iLen; ++index) | |
49 | + { | |
50 | + char cNum[3] = { 0 }; | |
51 | + sprintf_s(cNum, "%2X", pHex[index]); | |
52 | + sResult.append(cNum, 2); | |
53 | + } | |
54 | + } | |
55 | + return sResult; | |
56 | +} | |
57 | + | |
58 | +bool DLCamCardManager::CheckOrderResult(unsigned char* pResult, unsigned char cLen) | |
59 | +{ | |
60 | + bool bResult = false; | |
61 | + if (pResult[(int)cLen - 2] == 0x90 && | |
62 | + pResult[(int)cLen - 1] == 0x00) | |
63 | + { | |
64 | + bResult = true; | |
65 | + } | |
66 | + return bResult; | |
67 | +} | |
68 | + | |
69 | +bool DLCamCardManager::Connect() | |
70 | +{ | |
71 | + static const uint8_t RETRY_COUNT = 10; | |
72 | + | |
73 | + const int kUSBPort = 100, kBaudRate = 0; // port 为 100时,表示使用USB接口通讯,则波特率无效,因此设置为0. | |
74 | + const int kBeepMs = 10; | |
75 | + uint8_t conn_count = 0; | |
76 | + do | |
77 | + { | |
78 | + m_icdev = dc_init(kUSBPort, kBaudRate); | |
79 | + if (0 < (int)m_icdev) | |
80 | + { | |
81 | + dc_beep(m_icdev, kBeepMs); | |
82 | + return true; | |
83 | + } | |
84 | + ++conn_count; | |
85 | + } while (conn_count < RETRY_COUNT); | |
86 | + return false; | |
87 | +} | |
88 | + | |
89 | +bool DLCamCardManager::DisConnect() | |
90 | +{ | |
91 | + bool bResult = false; | |
92 | + if (m_icdev) | |
93 | + { | |
94 | + int iResult = dc_exit(m_icdev); | |
95 | + if (iResult) | |
96 | + { | |
97 | + bResult = false; | |
98 | + } | |
99 | + else | |
100 | + { | |
101 | + bResult = true; | |
102 | + } | |
103 | + } | |
104 | + return bResult; | |
105 | +} | |
106 | + | |
107 | +bool DLCamCardManager::SelectMF() | |
108 | +{ | |
109 | + bool bResult = true; | |
110 | + | |
111 | + const int kOK = 0; | |
112 | + const unsigned int kTimeout = 7; // 延迟时间,单位为:10ms, 7 来自与官方示例,该值如果设过大会导致操作失败. | |
113 | + const unsigned int kMaxDataSize = 512; | |
114 | + const unsigned char kSendDataLen = 7; // 发送的信息长度 | |
115 | + unsigned char recv_data_len = 0; // 读取信息的长度 | |
116 | + unsigned char send_data[kMaxDataSize] = { 0 }, recv_data[kMaxDataSize] = { 0 }; | |
117 | + | |
118 | + send_data[0] = 0x00; // CLA | |
119 | + send_data[1] = 0xA4; // INS | |
120 | + send_data[2] = 0x00; // P1,按文件名选择DF | |
121 | + send_data[3] = 0x00; // P2 | |
122 | + send_data[4] = 0x02; // Lc 数据长度 | |
123 | + // Data:DF文件名 | |
124 | + send_data[5] = 0x3F; | |
125 | + send_data[6] = 0x00; | |
126 | + | |
127 | + __int16 iResult = 0; | |
128 | + if (m_icdev) | |
129 | + { | |
130 | + iResult = dc_pro_command(m_icdev, kSendDataLen, send_data, &recv_data_len, recv_data, kTimeout); | |
131 | + } | |
132 | + else | |
133 | + { | |
134 | + bResult = false; | |
135 | + throw std::exception("Card reader handle is empty!"); | |
136 | + } | |
137 | + | |
138 | + | |
139 | + if (iResult != kOK || !CheckOrderResult(recv_data, recv_data_len)) | |
140 | + { | |
141 | + bResult = false; | |
142 | + throw std::exception("Select MF failed!"); | |
143 | + } | |
144 | + | |
145 | + return bResult; | |
146 | +} | |
147 | + | |
148 | +bool DLCamCardManager::SelectFile() | |
149 | +{ | |
150 | + bool bResult = false; | |
151 | + | |
152 | + const int kOK = 0; | |
153 | + const unsigned int kTimeout = 7; // 延迟时间,单位为:10ms, 7 来自与官方示例,该值如果设过大会导致操作失败. | |
154 | + const unsigned int kMaxDataSize = 512; | |
155 | + const unsigned char kSendDataLen = 7; // 发送的信息长度 | |
156 | + unsigned char recv_data_len = 0; // 读取信息的长度 | |
157 | + unsigned char send_data[kMaxDataSize] = { 0 }, recv_data[kMaxDataSize] = { 0 }; | |
158 | + | |
159 | + send_data[0] = 0x00; // CLA | |
160 | + send_data[1] = 0xA4; // INS | |
161 | + send_data[2] = 0x00; // P1,按文件名选择DF | |
162 | + send_data[3] = 0x00; // P2 | |
163 | + send_data[4] = 0x02; // Lc 数据长度 | |
164 | + // Data:DF文件名 | |
165 | + send_data[5] = 0x00; | |
166 | + send_data[6] = 0x05; | |
167 | + | |
168 | + __int16 iResult = 0; | |
169 | + if (m_icdev) | |
170 | + { | |
171 | + iResult = dc_pro_command(m_icdev, kSendDataLen, send_data, &recv_data_len, recv_data, kTimeout); | |
172 | + } | |
173 | + else | |
174 | + { | |
175 | + bResult = false; | |
176 | + throw std::exception("Card reader handle is empty!"); | |
177 | + } | |
178 | + if (iResult != kOK || !CheckOrderResult(recv_data, recv_data_len)) | |
179 | + { | |
180 | + bResult = false; | |
181 | + throw std::exception("Select 0x05 file failed!"); | |
182 | + } | |
183 | + | |
184 | + return bResult; | |
185 | +} | |
186 | + | |
187 | + | |
188 | +std::string DLCamCardManager::ReadCardBasicFile() | |
189 | +{ | |
190 | + std::string sResult; | |
191 | + const int kOK = 0; | |
192 | + const unsigned int kTimeout = 7; // 延迟时间,单位为:10ms, 7 来自与官方示例,该值如果设过大会导致操作失败. | |
193 | + const unsigned int kMaxDataSize = 512; | |
194 | + const unsigned char kSendDataLen = 5; // 发送的信息长度 | |
195 | + unsigned char recv_data_len = 0; // 读取信息的长度 | |
196 | + unsigned char send_data[kMaxDataSize] = { 0 }, recv_data[kMaxDataSize] = { 0 }; | |
197 | + | |
198 | + | |
199 | + send_data[0] = 0x00; // CLA | |
200 | + send_data[1] = 0xB0; // INS | |
201 | + send_data[2] = 0x85; // P1 | |
202 | + send_data[3] = 0x00; // P2,按文件记录号访问 | |
203 | + send_data[4] = 0x2C; // Le | |
204 | + | |
205 | + bool bResult = true; | |
206 | + __int16 iResult = 0; | |
207 | + if (m_icdev) | |
208 | + { | |
209 | + iResult = dc_pro_command(m_icdev, kSendDataLen, send_data, &recv_data_len, recv_data, kTimeout); | |
210 | + } | |
211 | + else | |
212 | + { | |
213 | + bResult = false; | |
214 | + throw std::exception("Card reader handle is empty!"); | |
215 | + } | |
216 | + if (iResult != kOK || !CheckOrderResult(recv_data, recv_data_len)) | |
217 | + { | |
218 | + bResult = false; | |
219 | + throw std::exception("Read data at 0x05 file failed!"); | |
220 | + } | |
221 | + | |
222 | + if (bResult) | |
223 | + { | |
224 | + RecordDataT sTemp = RecordDataT(recv_data, recv_data_len); | |
225 | + for (int index = 0; index < (int)recv_data_len - 2; ++index) | |
226 | + sResult.append(DecToHex(sTemp.at(index))); | |
227 | + } | |
228 | + return sResult; | |
229 | +} | |
230 | + | |
231 | +DILICard::BasicInfo DLCamCardManager::ReadCardBasicInfo() | |
232 | +{ | |
233 | + std::string basic_info_str = ReadCardBasicFile(); | |
234 | + int iTotalLength = basic_info_str.size(); | |
235 | + if (basic_info_str.size() < iTotalLength) | |
236 | + { | |
237 | + throw std::exception("Card basic info error!"); | |
238 | + } | |
239 | + DILICard::BasicInfo basic_info; | |
240 | + | |
241 | + uint32_t offset = 0; | |
242 | + basic_info.chip_num = basic_info_str.substr(offset, CARD_CHIP_NUM_LEN); | |
243 | + offset += CARD_CHIP_NUM_LEN; | |
244 | + | |
245 | + std::string field; | |
246 | + field = basic_info_str.substr(offset, CARD_TYPE_CODE_LEN); | |
247 | + basic_info.type_code = field.substr(0, CARD_TYPE_CODE_LEN_USE); | |
248 | + offset += CARD_TYPE_CODE_LEN; | |
249 | + | |
250 | + field = basic_info_str.substr(offset, CARD_ISSUER_CODE_LEN); | |
251 | + basic_info.issuer_code = field.substr(0, CARD_ISSUER_CODE_LEN_USE); | |
252 | + offset += CARD_ISSUER_CODE_LEN; | |
253 | + | |
254 | + field = basic_info_str.substr(offset, CARD_VERIFY_CODE_LEN); | |
255 | + basic_info.verify_code = field.substr(0, CARD_VERIFY_CODE_LEN_USE); | |
256 | + offset += CARD_VERIFY_CODE_LEN; | |
257 | + | |
258 | + //sn号全为f或者全为0时,入库会有问题,暂时用卡面号替代sn号 add by liuye 2017.7.27 | |
259 | + //basic_info.device_id = basic_info_str.substr(offset, CARD_SN_LEN); | |
260 | + basic_info.device_id = basic_info.chip_num; | |
261 | + // | |
262 | + | |
263 | + return basic_info; | |
264 | +} | |
265 | + | |
266 | +void DLCamCardManager::FindAndResetCard() // 寻卡并复位卡片 | |
267 | +{ | |
268 | + unsigned long snr = 0; | |
269 | + unsigned char lenth[128] = { 0 }; | |
270 | + unsigned char data[128] = { 0 }; | |
271 | + int st = 0; | |
272 | + | |
273 | + if (m_icdev) | |
274 | + { | |
275 | + st = dc_card(m_icdev, 0, &snr); // 一定要先寻卡 | |
276 | + if (0 != st) | |
277 | + throw std::exception("Find dili card failed!"); | |
278 | + st = dc_pro_reset(m_icdev, lenth, data); | |
279 | + if (0 != st) | |
280 | + throw std::exception("Reset dili card failed!"); | |
281 | + } | |
282 | + else | |
283 | + { | |
284 | + throw std::exception("Card reader handle is empty!"); | |
285 | + } | |
286 | + | |
287 | +} | |
0 | 288 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient/hardware/DLCamCardManager.h
0 → 100644
1 | +#ifndef ETRADECLIENT_DL_CAM_CARD_MANAGER_H_INCLUDED | |
2 | +#define ETRADECLIENT_DL_CAM_CARD_MANAGER_H_INCLUDED | |
3 | + | |
4 | +#include <string> | |
5 | +#include "ETradeClient/hardware/dili_card_device.h" | |
6 | + | |
7 | +class DLCamCardManager | |
8 | +{ | |
9 | + typedef std::basic_string<unsigned char> RecordDataT; | |
10 | +public: | |
11 | + DLCamCardManager(); | |
12 | + ~DLCamCardManager(); | |
13 | + | |
14 | + bool Connect(); | |
15 | + bool DisConnect(); | |
16 | + void FindAndResetCard(); | |
17 | + bool SelectMF(); | |
18 | + bool SelectFile(); | |
19 | + DILICard::BasicInfo ReadCardBasicInfo(); | |
20 | + | |
21 | +private: | |
22 | + std::string HexToChar(unsigned char* pHex, int iLen); | |
23 | + bool CheckOrderResult(unsigned char* pResult, unsigned char cLen); | |
24 | + std::string ReadCardBasicFile(); | |
25 | + | |
26 | + HANDLE m_icdev; | |
27 | +}; | |
28 | + | |
29 | +#endif | |
0 | 30 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient/hardware/dili_card_device.cpp
... | ... | @@ -10,7 +10,6 @@ |
10 | 10 | #include <intrin.h> // Endian conversion. |
11 | 11 | |
12 | 12 | #include "etradeclient/utility/string_converter.h" |
13 | -#include "ETradeClient/hardware/DLCardManager.h" | |
14 | 13 | |
15 | 14 | template <typename T> |
16 | 15 | std::string DecToHex(T d, bool show_base = false) |
... | ... | @@ -111,37 +110,35 @@ namespace DILICard |
111 | 110 | } |
112 | 111 | bool RWDevice::Connect() const |
113 | 112 | { |
114 | - bool bResult = true; | |
115 | - | |
116 | - int iResult = DLCConnectDevice(); | |
117 | - if (0 != iResult) | |
113 | + static const uint8_t RETRY_COUNT = 10; | |
114 | + uint8_t conn_count = 0; | |
115 | + do | |
118 | 116 | { |
119 | - bResult = false; | |
120 | - throw std::exception(std::to_string(iResult).c_str()); | |
121 | - } | |
122 | - | |
123 | - return bResult; | |
117 | + if (m_fn_open()) | |
118 | + return true; | |
119 | + ++conn_count; | |
120 | + } while (conn_count < RETRY_COUNT); | |
121 | + return false; | |
124 | 122 | } |
125 | 123 | void RWDevice::Disconnect() const |
126 | 124 | { |
127 | - DLCDisconnectDevice(); | |
125 | + m_fn_close(); | |
128 | 126 | } |
129 | 127 | void RWDevice::Beep(uint32_t time) const |
130 | 128 | { |
131 | 129 | m_fn_beep(time); |
132 | 130 | } |
133 | - bool RWDevice::FindCard() const | |
131 | + std::string RWDevice::FindCard() const | |
134 | 132 | { |
135 | - bool bResult = true; | |
136 | - | |
137 | - int iResult = DLCFindCard(); | |
138 | - if (0 != iResult) | |
139 | - { | |
140 | - bResult = false; | |
141 | - throw std::exception(std::to_string(iResult).c_str()); | |
142 | - } | |
143 | - | |
144 | - return bResult; | |
133 | + static const uint8_t OK = 0; | |
134 | + char sn[CARD_SN_LEN + 1] = { 0x0 }; | |
135 | + // 仅仅检查‘m_fn_find_card’的返回值不够,因为该函数有BUG:即使未能正确读到卡序列号, | |
136 | + // 该函数依然可能返回0. 例如在每次正确读到卡片后,如果把卡拿走并马上再次读卡,此时该函数 | |
137 | + // 会返回0,但并没有读到卡序列号。 | |
138 | + if (OK == m_fn_find_card(sn) && sn[0] != 0x0) | |
139 | + return sn; | |
140 | + else | |
141 | + throw std::exception("Card not found!"); | |
145 | 142 | } |
146 | 143 | |
147 | 144 | // 卡基本信息文件包括:卡面号,卡片硬件标识(卡片内码, 卡序列号SN),卡片类型码,发卡机构编码,校验码。 |
... | ... | @@ -209,26 +206,14 @@ namespace DILICard |
209 | 206 | */ |
210 | 207 | |
211 | 208 | // 设置密码 |
212 | - //九方元通的卡,damk的秘钥标示为0 | |
213 | - std::string sCardType = chip_num_str.substr(4, 1); | |
214 | - if (sCardType == "1") | |
215 | - { | |
216 | - SetPassword(DF01_DIR, 0, K_F0015_DACK_DV, key_F0015_DAMK1.c_str(), KT_DAMK); | |
217 | - SetPassword(MF_FILE_DIR, 0, K_DCCK_DV, key_F0015_DAMK1.c_str(), KT_DAMK); | |
218 | - } | |
219 | - else | |
220 | - { | |
221 | - SetPassword(DF01_DIR, 1, K_F0015_DACK_DV, key_F0015_DAMK1.c_str(), KT_DAMK); | |
222 | - SetPassword(MF_FILE_DIR, 1, K_DCCK_DV, key_F0015_DAMK1.c_str(), KT_DAMK); | |
223 | - } | |
224 | - // | |
225 | - SetPassword(DF01_DIR, 1, K_F0015_DACK_DV, key_F0015_DEAK.c_str(), KT_DEAK); | |
226 | - SetPassword(DF01_DIR, 0, K_F0015_DACK_DV, key_F0015_DACK.c_str(), KT_DCCK); | |
227 | - SetPassword(MF_FILE_DIR, 0, K_DCCK_DV, key_DCCK.c_str(), KT_DCCK); | |
209 | + SetPassword(DF01_DIR, ACTIVATE_KEY_ID, K_F0015_DACK_DV, K_F0015_DAMK1_CMD_HEAD, key_F0015_DAMK1.c_str(), false); | |
210 | + SetPassword(DF01_DIR, ACTIVATE_KEY_ID, K_F0015_DACK_DV, K_F0015_DEAK_CMD_HEAD, key_F0015_DEAK.c_str(), false); | |
211 | + SetPassword(DF01_DIR, ACTIVATE_KEY_ID, K_F0015_DACK_DV, K_F0015_DACK_CMD_HEAD, key_F0015_DACK.c_str(), true); | |
212 | + SetPassword(MF_FILE_DIR, ACTIVATE_KEY_ID, K_DCCK_DV, K_DCCK_CMD_HEAD, key_DCCK.c_str(), true); | |
228 | 213 | |
229 | 214 | // 写卡片硬件标识(卡片内码, 卡序列号SN) |
230 | 215 | // 注意这里offset计算不需要进行“/2”转换,因为这个API层面操作的都是HEX字符串格式,在“WriteCardFile”内部会自动进行“/2”转换。 |
231 | - WriteCardFile(MF_FILE_DIR, BASIC_INFO_FILE_ID, CARD_SN_DATA_OFFSET, ACTIVATE_KEY_ID, key_F0015_DAMK1.c_str(), card_sn); | |
216 | + WriteCardFile(MF_FILE_DIR, BASIC_INFO_FILE_ID, CARD_SN_DATA_OFFSET, ACTIVATE_KEY_ID, K_F0005_DCMK1, card_sn); | |
232 | 217 | |
233 | 218 | // 读发卡机构 |
234 | 219 | uint8_t issuer_code_len = CARD_ISSUER_CODE_HAERBIN_HADA.size(); |
... | ... | @@ -289,24 +274,16 @@ namespace DILICard |
289 | 274 | //need_write_code_type = true; |
290 | 275 | // |
291 | 276 | } |
292 | - | |
293 | - //卡类型码纠错仅针对于智信融创的老卡 add by daxiong 2017.10.19 | |
294 | - if (sCardType != "0") | |
295 | - { | |
296 | - need_write_code_type = false; | |
297 | - } | |
298 | - // | |
299 | - | |
300 | 277 | // 注意这里offset计算不需要进行“/2”转换,因为这个API层面操作的都是HEX字符串格式,在“WriteCardFile”内部会自动进行“/2”转换。 |
301 | 278 | if (need_write_code_type) // 根据需要重新写入卡片类型编码. |
302 | 279 | { |
303 | 280 | static const uint32_t TYPE_CODE_DATA_OFFSET = CARD_CHIP_NUM_LEN; |
304 | - WriteCardFile(MF_FILE_DIR, BASIC_INFO_FILE_ID, TYPE_CODE_DATA_OFFSET, ACTIVATE_KEY_ID, key_F0015_DAMK1, card_type_str); | |
281 | + WriteCardFile(MF_FILE_DIR, BASIC_INFO_FILE_ID, TYPE_CODE_DATA_OFFSET, ACTIVATE_KEY_ID, K_F0005_DCMK1, card_type_str); | |
305 | 282 | } |
306 | 283 | |
307 | 284 | //将业务信息文件中的数据长度设置为0. |
308 | 285 | WriteCardFile(DF01_DIR, SERVICE_INFO_FILE_ID, 0/*offset*/, ACTIVATE_KEY_ID, key_F0015_DAMK1, DecToHex(0)); // Default length is 0. |
309 | -} | |
286 | + } | |
310 | 287 | |
311 | 288 | void RWDevice::ResetCard(const std::string& key_DCCK, const std::string& key_F0015_DACK) const |
312 | 289 | { |
... | ... | @@ -327,26 +304,10 @@ namespace DILICard |
327 | 304 | |
328 | 305 | |
329 | 306 | // 设置密码 |
330 | - static const uint32_t CHIP_NUM_DATA_OFFSET = 0; | |
331 | - const char kKeyID = NULL; // No need to do authentication. | |
332 | - const std::string kKey = ""; | |
333 | - std::string chip_num_str = ReadCardFile(MF_FILE_DIR, BASIC_INFO_FILE_ID, CHIP_NUM_DATA_OFFSET, CARD_CHIP_NUM_LEN, kKeyID, kKey); | |
334 | - //九方元通的卡,damk的秘钥标示为0 | |
335 | - std::string sCardType = chip_num_str.substr(4, 1); | |
336 | - if (sCardType == "1") | |
337 | - { | |
338 | - SetPassword(DF01_DIR, 0, key_F0015_DACK.c_str(), K_F0015_DAMK1_DV, KT_DAMK); | |
339 | - SetPassword(MF_FILE_DIR, 0, key_DCCK.c_str(), K_F0005_DCMK1, KT_DAMK); | |
340 | - } | |
341 | - else | |
342 | - { | |
343 | - SetPassword(DF01_DIR, 1, key_F0015_DACK.c_str(), K_F0015_DAMK1_DV, KT_DAMK); | |
344 | - SetPassword(MF_FILE_DIR, 1, key_DCCK.c_str(), K_F0005_DCMK1, KT_DAMK); | |
345 | - } | |
346 | - // | |
347 | - SetPassword(DF01_DIR, 1, key_F0015_DACK, K_F0015_DEAK_DV, KT_DEAK); | |
348 | - SetPassword(DF01_DIR, 0, key_F0015_DACK, K_F0015_DACK_DV, KT_DCCK); | |
349 | - SetPassword(MF_FILE_DIR, 0, key_DCCK.c_str(), K_DCCK_DV, KT_DCCK); | |
307 | + SetPassword(DF01_DIR, ACTIVATE_KEY_ID, key_F0015_DACK.c_str(), K_F0015_DAMK1_CMD_HEAD, K_F0015_DAMK1_DV, false); | |
308 | + SetPassword(DF01_DIR, ACTIVATE_KEY_ID, key_F0015_DACK, K_F0015_DEAK_CMD_HEAD, K_F0015_DEAK_DV, false); | |
309 | + SetPassword(DF01_DIR, ACTIVATE_KEY_ID, key_F0015_DACK, K_F0015_DACK_CMD_HEAD, K_F0015_DACK_DV, true); | |
310 | + SetPassword(MF_FILE_DIR, ACTIVATE_KEY_ID, key_DCCK.c_str(), K_DCCK_CMD_HEAD, K_DCCK_DV, true); | |
350 | 311 | |
351 | 312 | // 充值卡片内码 |
352 | 313 | // 注意这里offset计算不需要进行“/2”转换,因为这个API层面操作的都是HEX字符串格式,在“WriteCardFile”内部会自动进行“/2”转换。 |
... | ... | @@ -417,23 +378,23 @@ namespace DILICard |
417 | 378 | //------Private Implementations---------------- |
418 | 379 | void RWDevice::Init() |
419 | 380 | { |
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()); | |
381 | + const std::wstring kDLLFile = L"./dyn.dll"; | |
382 | + HINSTANCE dll_handle = LoadLibrary(kDLLFile.c_str()); | |
383 | + if (NULL != dll_handle) | |
384 | + { | |
385 | + m_fn_open = (OpenFn)GetProcAddress(dll_handle, "open"); | |
386 | + m_fn_beep = (BeepFn)GetProcAddress(dll_handle, "beep"); | |
387 | + m_fn_close = (CloseFn)GetProcAddress(dll_handle, "close"); | |
388 | + m_fn_find_card = (FindCardFn)GetProcAddress(dll_handle, "findCard"); | |
389 | + m_fn_write_bin_data = (WriteBinaryDataFn)GetProcAddress(dll_handle, "write_bin_file"); | |
390 | + m_fn_get_value = (GetValueFn)GetProcAddress(dll_handle, "get_value_char"); // Don't use "get_value" version!!! | |
391 | + m_fn_ch_dir = (ChangeDirFn)GetProcAddress(dll_handle, "chang_dir"); | |
392 | + m_fn_read_bin_data = (ReadBinaryDataFn)GetProcAddress(dll_handle, "read_bin_file"); | |
393 | + m_fn_ex_auth = (ExternalAuthFn)GetProcAddress(dll_handle, "External_Authentication"); | |
394 | + m_fn_install_key = (InstallKeyFn)GetProcAddress(dll_handle, "InstallKey"); | |
395 | + } | |
396 | + else | |
397 | + throw std::exception(("Fail to load the DILI card device DLL from path : " + wstr_2_str(kDLLFile)).c_str()); | |
437 | 398 | } |
438 | 399 | |
439 | 400 | std::string RWDevice::GetValue() const |
... | ... | @@ -451,29 +412,27 @@ namespace DILICard |
451 | 412 | const std::string& key) const |
452 | 413 | { |
453 | 414 | std::stringstream err_msg; |
454 | - unsigned char aucDir[4] = { 0 }, aucKey[32] = { 0 }, aucData[500] = { 0 }; | |
455 | - memcpy(aucDir, dir.c_str(), 4); | |
456 | - int iResult = 0; | |
457 | - if (NULL != key_id) | |
415 | + if (!m_fn_ch_dir(dir.c_str())) // First change to specified directory. | |
458 | 416 | { |
459 | - memcpy(aucKey, key.c_str(), 32); | |
460 | - iResult = DLCReadCardData(aucDir, file_id, offset, length, aucKey, aucData); | |
417 | + err_msg << "Change directory failed, DIR: " << dir << ", ErrorCode: " << GetValue(); | |
418 | + throw std::exception(err_msg.str().c_str()); | |
461 | 419 | } |
462 | - else | |
420 | + if (NULL != key_id) // If authentication is needed. | |
463 | 421 | { |
464 | - iResult = DLCReadCardData(aucDir, file_id, offset, length, NULL, aucData); | |
422 | + if (!m_fn_ex_auth(key_id, key.c_str())) | |
423 | + { | |
424 | + err_msg << "Authenticate file failed, FILE: " << file_id << ", ErrorCode: " << GetValue(); | |
425 | + throw std::exception(err_msg.str().c_str()); | |
426 | + } | |
465 | 427 | } |
466 | - | |
467 | - | |
468 | - if (0 != iResult) | |
428 | + // Read binary data from card. | |
429 | + if (!m_fn_read_bin_data(file_id, offset / 2, length / 2)) // Why "/ 2"? refer to the comment at the front of this file. | |
469 | 430 | { |
470 | - err_msg << "Read DL card data failed, dir:" << dir << ", file:" << file_id << ", ErrorCode:" << iResult; | |
431 | + err_msg << "Read file failed, FILE: " << file_id << ", ErrorCode: " << GetValue(); | |
471 | 432 | throw std::exception(err_msg.str().c_str()); |
472 | 433 | } |
473 | 434 | |
474 | - std::string sData = (char*)aucData; | |
475 | - return sData; | |
476 | - | |
435 | + return GetValue(); | |
477 | 436 | } |
478 | 437 | |
479 | 438 | void RWDevice::WriteCardFile(const std::string& dir, |
... | ... | @@ -484,102 +443,60 @@ namespace DILICard |
484 | 443 | const std::string& data) const |
485 | 444 | { |
486 | 445 | std::stringstream err_msg; |
487 | - int iResult = 0; | |
488 | - const int DATA_MAX_LEN = 500; | |
489 | - | |
490 | - unsigned char aucDir[4] = { 0 }, aucKey[32] = { 0 }; | |
491 | - memcpy(aucDir, dir.c_str(), 4); | |
492 | - memcpy(aucKey, key.c_str(), 32); | |
446 | + if (!m_fn_ch_dir(dir.c_str())) // First change to specified directory. | |
447 | + { | |
448 | + err_msg << "Change directory failed, DIR: " << dir << ", ErrorCode: " << GetValue(); | |
449 | + throw std::exception(err_msg.str().c_str()); | |
450 | + } | |
493 | 451 | |
494 | - int iDataLength = data.size(); | |
495 | - int iStartIndex = 0, iOffset = offset; | |
496 | - do | |
452 | + uint32_t length = data.size(); | |
453 | + uint32_t written_data_size = 0; | |
454 | + while (written_data_size < length) | |
497 | 455 | { |
498 | - while (iDataLength - DATA_MAX_LEN > 0) | |
456 | + if (NULL != key_id) // If authentication is needed. | |
499 | 457 | { |
500 | - unsigned char aucDataBlock[DATA_MAX_LEN] = { 0 }; | |
501 | - memcpy(aucDataBlock, data.substr(iStartIndex, DATA_MAX_LEN).c_str(), DATA_MAX_LEN); | |
502 | - iResult = DLCWriteCardData(aucDir, file_id, iOffset, DATA_MAX_LEN, aucDataBlock, aucKey); | |
503 | - if (0 != iResult) | |
458 | + if (!m_fn_ex_auth(key_id, key.c_str())) | |
504 | 459 | { |
505 | - err_msg << "Write data to file failed, FILE: " << file_id << ", ErrorCode: " << iResult; | |
460 | + err_msg << "Authenticate file failed, FILE: " << file_id << ", ErrorCode: " << GetValue(); | |
506 | 461 | throw std::exception(err_msg.str().c_str()); |
507 | - break; | |
508 | 462 | } |
509 | - iStartIndex += DATA_MAX_LEN; | |
510 | - iDataLength -= DATA_MAX_LEN; | |
511 | - iOffset += DATA_MAX_LEN; | |
512 | 463 | } |
513 | - if (0 == iResult) | |
464 | + std::string data_block = data.substr(written_data_size, WRITE_DATA_BLOCK_LEN * 2); // Why "* 2"? refer to the comment at the front of this file. | |
465 | + uint32_t block_size = data_block.size(); | |
466 | + | |
467 | + | |
468 | + if (!m_fn_write_bin_data(file_id, (offset + written_data_size) / 2, block_size / 2, key.c_str(), data_block.c_str())) // Why "/ 2"? refer to the comment at the front of this file. | |
514 | 469 | { |
515 | - unsigned char aucData[DATA_MAX_LEN] = { 0 }; | |
516 | - memcpy(aucData, data.substr(iStartIndex, iDataLength).c_str(), iDataLength); | |
517 | - iResult = DLCWriteCardData(aucDir, file_id, iOffset, iDataLength, aucData, aucKey); | |
518 | - if (0 != iResult) | |
519 | - { | |
520 | - err_msg << "Write data to file failed, FILE: " << file_id << ", ErrorCode: " << iResult; | |
521 | - throw std::exception(err_msg.str().c_str()); | |
522 | - break; | |
523 | - } | |
470 | + err_msg << "Write data to file failed, FILE: " << file_id << ", ErrorCode: " << GetValue(); | |
471 | + throw std::exception(err_msg.str().c_str()); | |
524 | 472 | } |
525 | - } while (0); | |
473 | + | |
474 | + written_data_size += block_size; | |
475 | + } | |
526 | 476 | } |
527 | 477 | |
528 | 478 | void RWDevice::SetPassword(const std::string& dir, |
529 | 479 | char key_id, |
530 | 480 | const std::string& main_key, |
481 | + const std::string& cmd_head, | |
531 | 482 | const std::string& install_key, |
532 | - KeyType emKeyType) const | |
483 | + bool is_main_key) const | |
533 | 484 | { |
534 | 485 | std::stringstream err_msg; |
535 | - unsigned char aucDir[4] = { 0 }, aucMainKey[32] = { 0 }, aucNewKey[32] = { 0 }; | |
536 | - memcpy(aucDir, dir.c_str(), 4); | |
537 | - memcpy(aucMainKey, main_key.c_str(), 32); | |
538 | - memcpy(aucNewKey, install_key.c_str(), 32); | |
539 | - int iResult = DLCInstallKey(aucDir, key_id, emKeyType, aucNewKey, aucMainKey); | |
540 | - if (0 != iResult) | |
486 | + if (!m_fn_ch_dir(dir.c_str())) // First change to specified directory. | |
541 | 487 | { |
542 | - err_msg << "Update key failed, key to be updated: " << install_key << ", ErrorCode: " << iResult; | |
488 | + err_msg << "Change directory failed, DIR: " << dir << ", ErrorCode: " << GetValue(); | |
543 | 489 | throw std::exception(err_msg.str().c_str()); |
544 | 490 | } |
545 | - } | |
546 | - | |
547 | - void RWDevice::CreateCardFile(const std::string dir, const std::string dir_key, const std::string file_name, const std::string file_size, const int file_type) const | |
548 | - { | |
549 | - std::stringstream err_msg; | |
550 | - unsigned char aucDir[4] = { 0 }, aucKey[32] = { 0 }, aucFileName[4] = { 0 }, aucFileSize[4] = { 0 }; | |
551 | - memcpy(aucDir, dir.c_str(), 4); | |
552 | - memcpy(aucKey, dir_key.c_str(), 32); | |
553 | - memcpy(aucFileName, file_name.c_str(), 4); | |
554 | - memcpy(aucFileSize, file_size.c_str(), 4); | |
555 | - int iResult = DLCCreateFile(aucDir, aucKey, aucFileName, aucFileSize, file_type); | |
556 | - if (0 != iResult) | |
491 | + if (!m_fn_ex_auth(key_id, main_key.c_str())) | |
557 | 492 | { |
558 | - err_msg << "Create file failed, ErrorCode: " << iResult; | |
493 | + err_msg << "Authenticate key failed, original key: " << main_key << ", ErrorCode: " << GetValue(); | |
559 | 494 | throw std::exception(err_msg.str().c_str()); |
560 | 495 | } |
561 | - } | |
562 | - | |
563 | - bool RWDevice::NeedCreateFile() const | |
564 | - { | |
565 | - return DLCSelectFile((const unsigned char*)"df20") == 0 ? false : true; | |
566 | - } | |
567 | - | |
568 | - bool RWDevice::AuthenticationKey(const std::string sKey) const | |
569 | - { | |
570 | - bool bResult = true; | |
571 | - unsigned char aucKey[32] = { 0 }; | |
572 | - memcpy(aucKey, sKey.c_str(), 32); | |
573 | - int iResult = DLCAuthenticationKey((const unsigned char*)"3f00", 0, aucKey); | |
574 | - if (iResult) | |
496 | + if (!m_fn_install_key(main_key.c_str(), cmd_head.c_str(), install_key.c_str(), is_main_key, true)) | |
575 | 497 | { |
576 | - bResult = false; | |
577 | - } | |
578 | - else | |
579 | - { | |
580 | - bResult = true; | |
498 | + err_msg << "Update key failed, key to be updated: " << install_key << ", ErrorCode: " << GetValue(); | |
499 | + throw std::exception(err_msg.str().c_str()); | |
581 | 500 | } |
582 | - | |
583 | - return bResult; | |
584 | 501 | } |
585 | 502 | } // DILICard |
586 | 503 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient/hardware/dili_card_device.h
... | ... | @@ -58,7 +58,7 @@ namespace DILICard |
58 | 58 | bool Connect() const; |
59 | 59 | void Disconnect() const; |
60 | 60 | void Beep(uint32_t time) const; // Unit: 10ms. |
61 | - bool FindCard() const; // If card found, card's serial number will be returned. | |
61 | + std::string FindCard() const; // If card found, card's serial number will be returned. | |
62 | 62 | void ActivateCard(const std::string& card_sn, |
63 | 63 | const std::string& key_DCCK, |
64 | 64 | const std::string& key_F0015_DACK, |
... | ... | @@ -68,23 +68,6 @@ namespace DILICard |
68 | 68 | BasicInfo ReadCardBasicInfo() const; |
69 | 69 | std::string ReadCardServiceInfo(const std::string& key_F0015_DEAK) const; |
70 | 70 | void WriteCardServiceInfo(const std::string& key_F0015_DAMK1, const std::string& data) const; |
71 | - bool AuthenticationKey(const std::string sKey) const; | |
72 | - | |
73 | - //´´½¨ÍÑ»ú½»Ò×ËùÐèÎļþ add by liuye | |
74 | - void CreateCardFile(const std::string dir, | |
75 | - const std::string dir_key, | |
76 | - const std::string file_name, | |
77 | - const std::string file_size, | |
78 | - const int file_type) const; | |
79 | - | |
80 | - bool NeedCreateFile() const; | |
81 | - | |
82 | - enum KeyType | |
83 | - { | |
84 | - KT_DCCK = 0, | |
85 | - KT_DEAK, | |
86 | - KT_DAMK, | |
87 | - }; | |
88 | 71 | private: |
89 | 72 | void Init(); |
90 | 73 | std::string GetValue() const; |
... | ... | @@ -103,8 +86,9 @@ namespace DILICard |
103 | 86 | void SetPassword(const std::string& dir, |
104 | 87 | char key_id, |
105 | 88 | const std::string& main_key, |
89 | + const std::string& cmd_head, | |
106 | 90 | const std::string& install_key, |
107 | - KeyType emKeyType) const; | |
91 | + bool is_main_key) const; | |
108 | 92 | |
109 | 93 | private: |
110 | 94 | OpenFn m_fn_open; | ... | ... |
etrade_card_client/ETradeClient/hardware/hardware_cmd.cpp
... | ... | @@ -16,10 +16,7 @@ |
16 | 16 | #include "etradeclient/hardware/dili_card_device.h" |
17 | 17 | #include "etradeclient/hardware/bank_card_reader.h" |
18 | 18 | #include "etradeclient/hardware/password_machine.h" |
19 | -#include "ETradeClient/utility/openssl_aes_cbc.h" | |
20 | -#include "ETradeClient/utility/DLBmpManager.h" | |
21 | -#include "ETradeClient/utility/string_converter.h" | |
22 | -#include "ETradeClient/utility/DLDes.h" | |
19 | +#include "etradeclient/hardware/DLCamCardManager.h" | |
23 | 20 | |
24 | 21 | namespace StatusCode |
25 | 22 | { |
... | ... | @@ -43,8 +40,6 @@ namespace StatusCode |
43 | 40 | static const std::string DILI_CARD_DEVICE_READ_SERVICE_INFO_FAILED = "305"; // 读取卡片业务信息失败. |
44 | 41 | static const std::string DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED = "306"; // 写入卡片业务信息失败. |
45 | 42 | static const std::string DILI_CARD_DEVICE_WRITE_UNMATCHED_CARD = "307"; // 写卡卡片的序列号不匹配. |
46 | - static const std::string DILI_CARD_DEVICE_NEED_UPDATE_CAN_NOT_USE = "308"; //卡片需要升级,请升级后继续使用。 | |
47 | - static const std::string DILI_CARD_DEVICE_NEED_UPDATE_CAN_USE = "309"; //卡片需要升级。 | |
48 | 43 | |
49 | 44 | static const std::string PWD_MACHINE_CONNECT_FAILED = "401"; // 连接加密机失败. |
50 | 45 | static const std::string PWD_MACHINE_GET_KEY_FAILED = "402"; // 从加密机读取密钥失败. |
... | ... | @@ -52,182 +47,6 @@ namespace StatusCode |
52 | 47 | static const std::string BANK_CARD_READ_CARD_NUM_FAILED = "501"; // 读取银行卡卡号失败. |
53 | 48 | } |
54 | 49 | |
55 | -namespace EncryptTools | |
56 | -{ | |
57 | - int Encrypt(unsigned char* pSrc, unsigned char u8Len, unsigned char* pKey, unsigned char* pCiphertText) | |
58 | - { | |
59 | - int iResult = 0; | |
60 | - | |
61 | - uint8_t au8DataBlock[50][8] = { 0 }; | |
62 | - | |
63 | - int iBlockCount = 0, iCoverPos = 0, iBlockNum = 0; | |
64 | - iBlockCount = u8Len / 8; | |
65 | - iCoverPos = u8Len % 8; | |
66 | - | |
67 | - while (iBlockCount > 0) | |
68 | - { | |
69 | - memcpy(au8DataBlock[iBlockNum], pSrc, 8); | |
70 | - pSrc += 8; | |
71 | - --iBlockCount; | |
72 | - ++iBlockNum; | |
73 | - } | |
74 | - | |
75 | - if (iCoverPos) | |
76 | - { | |
77 | - memcpy(au8DataBlock[iBlockNum], pSrc, iCoverPos); | |
78 | - au8DataBlock[iBlockNum][iCoverPos] = 0x80; | |
79 | - ++iCoverPos; | |
80 | - for (int index = iCoverPos; iCoverPos < 8; ++iCoverPos) | |
81 | - { | |
82 | - au8DataBlock[iBlockNum][iCoverPos] = 0x00; | |
83 | - } | |
84 | - } | |
85 | - else | |
86 | - { | |
87 | - --iBlockNum; | |
88 | - } | |
89 | - | |
90 | - uint8_t au8KeyL[8] = { 0 }, au8KeyR[8] = { 0 }; | |
91 | - memcpy(au8KeyL, pKey, 8); | |
92 | - memcpy(au8KeyR, pKey, 8); | |
93 | - for (int index = 0; index <= iBlockNum; ++index) | |
94 | - { | |
95 | - uint8_t au8Cipher1[8] = { 0 }, au8Cipher2[8] = { 0 }; | |
96 | - DES(au8KeyL, au8DataBlock[index], au8Cipher1); | |
97 | - _DES(au8KeyR, au8Cipher1, au8Cipher2); | |
98 | - DES(au8KeyL, au8Cipher2, &pCiphertText[index * 8]); | |
99 | - } | |
100 | - | |
101 | - return iResult; | |
102 | - } | |
103 | - | |
104 | - bool HexToChar(unsigned char* pHex, int iHexLen, unsigned char* pChar) | |
105 | - { | |
106 | - bool bResult = true; | |
107 | - if (pHex && iHexLen && pChar) | |
108 | - { | |
109 | - int iCharCount = 0; | |
110 | - for (int index = 0; index < iHexLen; ++index) | |
111 | - { | |
112 | - char cNum[3] = { 0 }; | |
113 | - if (pHex[index] <= 0x0f) | |
114 | - { | |
115 | - pChar[iCharCount] = '0'; | |
116 | - ++iCharCount; | |
117 | - sprintf_s(cNum, "%X", pHex[index]); | |
118 | - pChar[iCharCount] = cNum[0]; | |
119 | - ++iCharCount; | |
120 | - } | |
121 | - else | |
122 | - { | |
123 | - sprintf_s(cNum, "%2X", pHex[index]); | |
124 | - pChar[iCharCount] = cNum[0]; | |
125 | - ++iCharCount; | |
126 | - pChar[iCharCount] = cNum[1]; | |
127 | - ++iCharCount; | |
128 | - } | |
129 | - } | |
130 | - } | |
131 | - return bResult; | |
132 | - } | |
133 | - | |
134 | - bool CharToHex(unsigned char* pStr, unsigned char& cHex) | |
135 | - { | |
136 | - bool bResult = true; | |
137 | - | |
138 | - unsigned char aHex[2] = { 0 }, cTemp = 0; | |
139 | - if (pStr) | |
140 | - { | |
141 | - int iCount = 2; | |
142 | - do | |
143 | - { | |
144 | - char cStr = tolower(pStr[iCount - 1]); | |
145 | - switch (cStr) | |
146 | - { | |
147 | - case '0': | |
148 | - case '1': | |
149 | - case '2': | |
150 | - case '3': | |
151 | - case '4': | |
152 | - case '5': | |
153 | - case '6': | |
154 | - case '7': | |
155 | - case '8': | |
156 | - case '9': | |
157 | - { | |
158 | - cTemp = atoi(&cStr); | |
159 | - break; | |
160 | - } | |
161 | - case 'a': | |
162 | - { | |
163 | - cTemp = 10; | |
164 | - break; | |
165 | - } | |
166 | - case 'b': | |
167 | - { | |
168 | - cTemp = 11; | |
169 | - break; | |
170 | - } | |
171 | - case 'c': | |
172 | - { | |
173 | - cTemp = 12; | |
174 | - break; | |
175 | - } | |
176 | - case 'd': | |
177 | - { | |
178 | - cTemp = 13; | |
179 | - break; | |
180 | - } | |
181 | - case 'e': | |
182 | - { | |
183 | - cTemp = 14; | |
184 | - break; | |
185 | - } | |
186 | - case 'f': | |
187 | - { | |
188 | - cTemp = 15; | |
189 | - break; | |
190 | - } | |
191 | - } | |
192 | - aHex[iCount - 1] = cTemp; | |
193 | - --iCount; | |
194 | - } while (iCount); | |
195 | - | |
196 | - cHex = (aHex[0] << 4) + aHex[1]; | |
197 | - } | |
198 | - else | |
199 | - { | |
200 | - bResult = false; | |
201 | - } | |
202 | - return bResult; | |
203 | - } | |
204 | - | |
205 | - bool StringToHex(unsigned char* pStr, int iLen, unsigned char* pHex) | |
206 | - { | |
207 | - bool bResult = true; | |
208 | - | |
209 | - int iStrIndex = 0; | |
210 | - int index = 0; | |
211 | - while (bResult && iStrIndex < iLen) | |
212 | - { | |
213 | - bResult = CharToHex(&pStr[iStrIndex], pHex[index]); | |
214 | - ++index; | |
215 | - iStrIndex += 2; | |
216 | - } | |
217 | - | |
218 | - if (!bResult) | |
219 | - { | |
220 | - throw std::exception("9999"); | |
221 | - } | |
222 | - /*for (int index = 0, iStrIndex = 0; iStrIndex < iLen; ++index, iStrIndex += 2) | |
223 | - { | |
224 | - CharToHex(&pStr[iStrIndex], pHex[index]); | |
225 | - }*/ | |
226 | - | |
227 | - return bResult; | |
228 | - } | |
229 | -} | |
230 | - | |
231 | 50 | namespace |
232 | 51 | { |
233 | 52 | const PINPad& PINPad_() |
... | ... | @@ -236,7 +55,7 @@ namespace |
236 | 55 | return pin_pad; |
237 | 56 | } |
238 | 57 | |
239 | - IDCardReader& IDCardReader_() | |
58 | + const IDCardReader& IDCardReader_() | |
240 | 59 | { |
241 | 60 | static IDCardReader id_card_reader; |
242 | 61 | return id_card_reader; |
... | ... | @@ -260,7 +79,11 @@ namespace |
260 | 79 | return bank_card_reader; |
261 | 80 | } |
262 | 81 | |
263 | - std::string g_sCardNum;//用于办卡时,保证操作的卡片是同一张 | |
82 | + const DLCamCardManager& DLCamCardManager_() | |
83 | + { | |
84 | + static DLCamCardManager CamCardManager; | |
85 | + return CamCardManager; | |
86 | + } | |
264 | 87 | } |
265 | 88 | |
266 | 89 | ReadPINPadCmd::Reply ReadPINPadCmd::Execute(const std::string& input) |
... | ... | @@ -322,95 +145,34 @@ ReadPINPadCmd::Reply ReadIDCardCmd::Execute(const std::string& input) |
322 | 145 | auto& id_card_reader = IDCardReader_(); |
323 | 146 | Reply reply; |
324 | 147 | IDCardInfo id_card_info; |
325 | - | |
326 | - uint8_t u8IDReaderType = ApplicationConfig::Instance().IDReaderType(); | |
327 | - | |
328 | - switch (u8IDReaderType) | |
329 | - { | |
330 | - case 0: | |
148 | + do | |
331 | 149 | { |
332 | - do | |
150 | + try | |
333 | 151 | { |
334 | - try | |
152 | + if (!id_card_reader.Connect()) | |
335 | 153 | { |
336 | - if (!id_card_reader.Connect()) | |
337 | - { | |
338 | - LOG_ERROR(L"建立身份证读卡器连接失败!"); | |
339 | - reply.error_code = StatusCode::ID_CARD_READER_CONNECT_FAILED; | |
340 | - break; | |
341 | - } | |
342 | - if (!id_card_reader.VerifyCard()) | |
343 | - { | |
344 | - LOG_ERROR(L"未找到身份证或身份证验证失败!"); | |
345 | - reply.error_code = StatusCode::ID_CARD_READER_VERIFY_FAILED; | |
346 | - break; | |
347 | - } | |
348 | - id_card_info = id_card_reader.ReadCard(); | |
349 | - } | |
350 | - catch (std::exception& ex) | |
351 | - { | |
352 | - LOG_FATAL(L"读取身份证信息失败,错误信息: " + str_2_wstr(ex.what())); | |
353 | - reply.error_code = StatusCode::ID_CARD_READER_READ_FAILED; | |
154 | + LOG_ERROR(L"建立身份证读卡器连接失败!"); | |
155 | + reply.error_code = StatusCode::ID_CARD_READER_CONNECT_FAILED; | |
354 | 156 | break; |
355 | 157 | } |
356 | - } while (0); | |
357 | - id_card_reader.Disconnect(); | |
358 | - } | |
359 | - break; | |
360 | - case 1: | |
361 | - { | |
362 | - do | |
363 | - { | |
364 | - try | |
365 | - { | |
366 | - if (!id_card_reader.SynConnect()) | |
367 | - { | |
368 | - LOG_ERROR(L"建立身份证读卡器连接失败!"); | |
369 | - reply.error_code = StatusCode::ID_CARD_READER_CONNECT_FAILED; | |
370 | - break; | |
371 | - } | |
372 | - if (!id_card_reader.SynFindCard()) | |
373 | - { | |
374 | - LOG_ERROR(L"未找到身份证或身份证验证失败!"); | |
375 | - reply.error_code = StatusCode::ID_CARD_READER_VERIFY_FAILED; | |
376 | - break; | |
377 | - } | |
378 | - id_card_info = id_card_reader.SynReadCard(); | |
379 | - } | |
380 | - catch (std::exception& ex) | |
158 | + if (!id_card_reader.VerifyCard()) | |
381 | 159 | { |
382 | - LOG_FATAL(L"读取身份证信息失败,错误信息: " + str_2_wstr(ex.what())); | |
383 | - reply.error_code = StatusCode::ID_CARD_READER_READ_FAILED; | |
160 | + LOG_ERROR(L"未找到身份证或身份证验证失败!"); | |
161 | + reply.error_code = StatusCode::ID_CARD_READER_VERIFY_FAILED; | |
384 | 162 | break; |
385 | 163 | } |
386 | - } while (0); | |
387 | - id_card_reader.SynDisConnect(); | |
388 | - } | |
389 | - break; | |
390 | - } | |
391 | - | |
392 | - if (boost::iequals(reply.error_code, StatusCode::OK)) | |
393 | - LOG_TRACE(L"读取身份证信息成功。"); | |
394 | - | |
395 | - CDLBmpManager cBmp; | |
396 | - string sBmpData = cBmp.ReadBmp(wstr_2_str(id_card_info.portrait_img_path).c_str()); | |
397 | - switch (u8IDReaderType) | |
398 | - { | |
399 | - case 0: | |
400 | - { | |
401 | - DeleteFile(id_card_info.portrait_img_path.c_str()); | |
402 | - wstring sPath = id_card_info.portrait_img_path.substr(0, id_card_info.portrait_img_path.size() - 6); | |
403 | - DeleteFile((sPath + L"wz.txt").c_str()); | |
404 | - DeleteFile((sPath + L"xp.wlt").c_str()); | |
164 | + id_card_info = id_card_reader.ReadCard(); | |
405 | 165 | } |
406 | - break; | |
407 | - case 1: | |
166 | + catch (std::exception& ex) | |
408 | 167 | { |
409 | - DeleteFile(id_card_info.portrait_img_path.c_str()); | |
168 | + LOG_FATAL(L"读取身份证信息失败,错误信息: " + str_2_wstr(ex.what())); | |
169 | + reply.error_code = StatusCode::ID_CARD_READER_READ_FAILED; | |
170 | + break; | |
410 | 171 | } |
411 | - break; | |
412 | - } | |
413 | - | |
172 | + } while (0); | |
173 | + id_card_reader.Disconnect(); | |
174 | + if (boost::iequals(reply.error_code, StatusCode::OK)) | |
175 | + LOG_TRACE(L"读取身份证信息成功。"); | |
414 | 176 | |
415 | 177 | reply.data.put("id", wstr_2_str(id_card_info.id_code)); |
416 | 178 | reply.data.put("name", wstr_2_str(id_card_info.name)); // Use 'wstr_2_str' to convert to UTF-8 string. |
... | ... | @@ -422,178 +184,44 @@ ReadPINPadCmd::Reply ReadIDCardCmd::Execute(const std::string& input) |
422 | 184 | reply.data.put("depart", wstr_2_str(id_card_info.depart)); |
423 | 185 | reply.data.put("start_date", wstr_2_str(id_card_info.start_date)); |
424 | 186 | reply.data.put("end_date", wstr_2_str(id_card_info.end_date)); |
425 | - reply.data.put("img_data", sBmpData); | |
426 | 187 | return reply; |
427 | 188 | } |
428 | 189 | |
429 | 190 | ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) |
430 | 191 | { |
192 | + //临时只读基本信息 add by liuye | |
193 | + LOG_TRACE(L"园区卡开卡操作。"); | |
194 | + auto cCamCard = DLCamCardManager_(); | |
431 | 195 | Reply reply; |
432 | - LOG_TRACE(L"卡片激活。"); | |
433 | - | |
434 | - std::string card_sn; | |
435 | - std::string key_DCCK, key_F0015_DACK, key_F0015_DEAK, key_F0015_DAMK1, key_F0005_DAMK1; | |
436 | 196 | DILICard::BasicInfo card_basic_info; |
437 | - SecurityLevel slLevel = (SecurityLevel)ApplicationConfig::Instance().SecurityLevel(); | |
438 | - EncryptType etEncrypType = (EncryptType)ApplicationConfig::Instance().EncryptType(); | |
439 | - auto& dili_card_device = DILICardRWDevice(); | |
440 | - do | |
197 | + try | |
441 | 198 | { |
442 | - try | |
443 | - { | |
444 | - dili_card_device.Connect(); | |
445 | - } | |
446 | - catch (std::exception& ex) | |
447 | - { | |
448 | - LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); | |
449 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; | |
450 | - break; | |
451 | - } | |
452 | - try | |
453 | - { | |
454 | - dili_card_device.FindCard(); | |
455 | - } | |
456 | - catch (std::exception& ex) | |
457 | - { | |
458 | - LOG_FATAL(L"寻卡失败,错误信息: " + str_2_wstr(ex.what())); | |
459 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | |
460 | - break; | |
461 | - } | |
462 | - | |
463 | - DILICard::BasicInfo stuCardBasicInfo; | |
464 | - try { stuCardBasicInfo = dili_card_device.ReadCardBasicInfo(); } | |
465 | - catch (std::exception& ex) | |
466 | - { | |
467 | - LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | |
468 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | |
469 | - break; | |
470 | - } | |
471 | - | |
472 | - if (dili_card_device.NeedCreateFile()) | |
473 | - { | |
474 | - try | |
475 | - { | |
476 | - std::string key = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0"; | |
477 | - dili_card_device.CreateCardFile("3f00", key, "df20", std::string(), 1); | |
478 | - dili_card_device.CreateCardFile("df20", key, "0025", "0324", 3); | |
479 | - dili_card_device.CreateCardFile("df20", key, "0026", "0709", 3); | |
480 | - } | |
481 | - catch (std::exception& ex) | |
482 | - { | |
483 | - LOG_FATAL(L"创建文件失败失败,错误信息: " + str_2_wstr(ex.what())); | |
484 | - } | |
485 | - } | |
486 | - | |
487 | - LOG_TRACE(L"计算SN。"); | |
488 | - card_sn = stuCardBasicInfo.chip_num + std::string("44494c49") + stuCardBasicInfo.chip_num; | |
489 | - | |
490 | - if (slLevel == HardwareCmd::SL_0) | |
491 | - { | |
492 | - stuCardBasicInfo.device_id = card_sn; | |
493 | - card_basic_info = stuCardBasicInfo; | |
494 | - reply.error_code = StatusCode::OK; | |
495 | - break; | |
496 | - } | |
497 | - | |
498 | - if (etEncrypType == ET_PWM) | |
499 | - { | |
500 | - LOG_TRACE(L"加密机模式计算主控秘钥。"); | |
501 | - const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | |
502 | - const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | |
503 | - const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | |
504 | - | |
505 | - auto& pwd_machine = PWDMachine_(); | |
506 | - | |
507 | - if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | |
508 | - { | |
509 | - LOG_ERROR(L"连接加密机失败!"); | |
510 | - reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | |
511 | - } | |
512 | - | |
513 | - try | |
514 | - { | |
515 | - key_DCCK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kDCCK>(), card_sn, TIMEOUT); | |
516 | - key_F0015_DACK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DACK>(), card_sn, TIMEOUT); | |
517 | - key_F0015_DEAK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DEAK>(), card_sn, TIMEOUT); | |
518 | - key_F0015_DAMK1 = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DAMK1>(), card_sn, TIMEOUT); | |
519 | - key_F0005_DAMK1 = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DAMK1>(), card_sn, TIMEOUT); | |
520 | - } | |
521 | - catch (std::exception& ex) | |
522 | - { | |
523 | - LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | |
524 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
525 | - break; | |
526 | - } | |
527 | - | |
528 | - pwd_machine.Disconnect(); | |
529 | - } | |
530 | - else if (etEncrypType == ET_DES) | |
531 | - { | |
532 | - LOG_TRACE(L"软加密模式计算主控秘钥。"); | |
533 | - try | |
534 | - { | |
535 | - const char* pDCCKDL = "43434bff43434bff"; | |
536 | - const char* pDACKDL = "41434bff41434bff"; | |
537 | - const char* pDEAKDL = "45414bff45414bff"; | |
538 | - const char* pDAMKDL = "414d4b31414d4b31"; | |
539 | - | |
540 | - unsigned char aucCardSNHex[16] = { 0 }; | |
541 | - unsigned char aucDCCKDL[8] = { 0 }, aucDACKDL[8] = { 0 }, aucDEAKDL[8] = { 0 }, aucDAMKDL[8] = { 0 }; | |
542 | - EncryptTools::StringToHex((unsigned char*)pDCCKDL, 16, aucDCCKDL); | |
543 | - EncryptTools::StringToHex((unsigned char*)pDACKDL, 16, aucDACKDL); | |
544 | - EncryptTools::StringToHex((unsigned char*)pDEAKDL, 16, aucDEAKDL); | |
545 | - EncryptTools::StringToHex((unsigned char*)pDAMKDL, 16, aucDAMKDL); | |
546 | - EncryptTools::StringToHex((unsigned char*)card_sn.c_str(), 32, aucCardSNHex); | |
547 | - | |
548 | - unsigned char aucNewDAMKHex[16] = { 0 }, aucNewDCCKHex[16] = { 0 }, aucNewDACKHex[16] = { 0 }, aucNewDEAKHex[16] = { 0 }; | |
549 | - unsigned char aucNewDAMK[32] = { 0 }, aucNewDCCK[32] = { 0 }, aucNewDACK[32] = { 0 }, aucNewDEAK[32] = { 0 }; | |
550 | - | |
551 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDAMKDL, aucNewDAMKHex); | |
552 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDCCKDL, aucNewDCCKHex); | |
553 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDACKDL, aucNewDACKHex); | |
554 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDEAKDL, aucNewDEAKHex); | |
555 | - | |
556 | - EncryptTools::HexToChar(aucNewDAMKHex, 16, aucNewDAMK); | |
557 | - EncryptTools::HexToChar(aucNewDCCKHex, 16, aucNewDCCK); | |
558 | - EncryptTools::HexToChar(aucNewDACKHex, 16, aucNewDACK); | |
559 | - EncryptTools::HexToChar(aucNewDEAKHex, 16, aucNewDEAK); | |
560 | - | |
561 | - std::string sDAMKKey((char*)aucNewDAMK, 32); | |
562 | - std::string sDCCKKey((char*)aucNewDCCK, 32); | |
563 | - std::string sDACKKey((char*)aucNewDACK, 32); | |
564 | - std::string sDEAKKey((char*)aucNewDEAK, 32); | |
565 | - | |
566 | - key_F0005_DAMK1 = key_F0015_DAMK1 = sDAMKKey; | |
567 | - key_DCCK = sDCCKKey; | |
568 | - key_F0015_DACK = sDACKKey; | |
569 | - key_F0015_DEAK = sDEAKKey; | |
570 | - | |
571 | - } | |
572 | - catch (std::exception& ex) | |
573 | - { | |
574 | - LOG_FATAL(L"软加密密钥失败"); | |
575 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
576 | - break; | |
577 | - } | |
578 | - } | |
199 | + LOG_TRACE(L"连接读卡器。"); | |
200 | + cCamCard.Connect(); | |
201 | + LOG_TRACE(L"寻卡操作。"); | |
202 | + cCamCard.FindAndResetCard(); | |
203 | + LOG_TRACE(L"切换主目录。"); | |
204 | + cCamCard.SelectMF(); | |
205 | + LOG_TRACE(L"切换文件。"); | |
206 | + cCamCard.SelectFile(); | |
207 | + LOG_TRACE(L"读取卡片基本信息。"); | |
208 | + card_basic_info = cCamCard.ReadCardBasicInfo(); | |
209 | + } | |
210 | + catch (std::exception& ex) | |
211 | + { | |
212 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_ACTIVATE_CARD_FAILED; | |
213 | + LOG_FATAL(L"读取园区卡信息失败,错误信息: " + str_2_wstr(ex.what())); | |
214 | + } | |
215 | + cCamCard.DisConnect(); | |
579 | 216 | |
580 | - try | |
581 | - { | |
582 | - dili_card_device.ActivateCard(card_sn, key_DCCK, key_F0015_DACK, key_F0015_DEAK, key_F0015_DAMK1); | |
583 | - card_basic_info = dili_card_device.ReadCardBasicInfo(); | |
584 | - } | |
585 | - catch (std::exception& ex) | |
586 | - { | |
587 | - LOG_FATAL(L"卡片激活失败,错误信息: " + str_2_wstr(ex.what())); | |
588 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_ACTIVATE_CARD_FAILED; | |
589 | - break; | |
590 | - } | |
591 | - | |
592 | - } while (0); | |
593 | - | |
594 | - dili_card_device.Disconnect(); | |
595 | 217 | if (boost::iequals(reply.error_code, StatusCode::OK)) |
596 | - LOG_TRACE(L"卡片激活成功。"); | |
218 | + { | |
219 | + LOG_TRACE(L"园区卡卡片激活成功。"); | |
220 | + } | |
221 | + else | |
222 | + { | |
223 | + LOG_TRACE(L"园区卡卡片激活失败。"); | |
224 | + } | |
597 | 225 | |
598 | 226 | reply.data.put("chipNo", card_basic_info.chip_num); |
599 | 227 | reply.data.put("deviceId", card_basic_info.device_id); |
... | ... | @@ -601,169 +229,44 @@ ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) |
601 | 229 | reply.data.put("issuerCode", card_basic_info.issuer_code); |
602 | 230 | reply.data.put("verifyCode", card_basic_info.verify_code); |
603 | 231 | return reply; |
232 | + // | |
604 | 233 | } |
605 | 234 | |
606 | 235 | ReadPINPadCmd::Reply ResetDILICardCmd::Execute(const std::string& input) |
607 | 236 | { |
608 | - //const uint8_t BEEP_TIME = 20; // 20 * 10ms | |
609 | - | |
610 | - | |
611 | - LOG_TRACE(L"卡片撤销激活。"); | |
612 | - auto& dili_card_device = DILICardRWDevice(); | |
613 | - | |
237 | + //临时只读基本信息 add by liuye | |
238 | + LOG_TRACE(L"撤销园区卡激活操作。"); | |
239 | + auto cCamCard = DLCamCardManager_(); | |
614 | 240 | Reply reply; |
615 | - std::string card_sn; | |
616 | - std::string key_DCCK, key_F0015_DACK; | |
617 | 241 | DILICard::BasicInfo card_basic_info; |
618 | - | |
619 | - SecurityLevel slLevel = (SecurityLevel)ApplicationConfig::Instance().SecurityLevel(); | |
620 | - EncryptType etEncrypType = (EncryptType)ApplicationConfig::Instance().EncryptType(); | |
621 | - | |
622 | - do | |
242 | + try | |
623 | 243 | { |
624 | - try | |
625 | - { | |
626 | - dili_card_device.Connect(); | |
627 | - } | |
628 | - catch (std::exception& ex) | |
629 | - { | |
630 | - LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); | |
631 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; | |
632 | - break; | |
633 | - } | |
634 | - try | |
635 | - { | |
636 | - dili_card_device.FindCard(); | |
637 | - } | |
638 | - catch (std::exception& ex) | |
639 | - { | |
640 | - LOG_FATAL(L"寻卡失败,错误信息: " + str_2_wstr(ex.what())); | |
641 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | |
642 | - break; | |
643 | - } | |
644 | - | |
645 | - DILICard::BasicInfo stuCardBasicInfo; | |
646 | - try { stuCardBasicInfo = dili_card_device.ReadCardBasicInfo(); } | |
647 | - catch (std::exception& ex) | |
648 | - { | |
649 | - LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | |
650 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | |
651 | - break; | |
652 | - } | |
653 | - | |
654 | - if (slLevel == HardwareCmd::SL_0) | |
655 | - { | |
656 | - card_basic_info = stuCardBasicInfo; | |
657 | - reply.error_code = StatusCode::OK; | |
658 | - break; | |
659 | - } | |
660 | - | |
661 | - //card_sn = stuCardBasicInfo.device_id; | |
662 | - | |
663 | - LOG_TRACE(L"计算SN。"); | |
664 | - if (slLevel == HardwareCmd::SL_1) | |
665 | - { | |
666 | - card_sn = stuCardBasicInfo.device_id; | |
667 | - } | |
668 | - else if (slLevel == HardwareCmd::SL_2) | |
669 | - { | |
670 | - card_sn = stuCardBasicInfo.chip_num + "44494c49" + stuCardBasicInfo.chip_num; | |
671 | - } | |
672 | - | |
673 | - if (etEncrypType == ET_PWM) | |
674 | - { | |
675 | - LOG_TRACE(L"加密机模式计算主控秘钥。"); | |
676 | - const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | |
677 | - const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | |
678 | - const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | |
679 | - | |
680 | - auto& pwd_machine = PWDMachine_(); | |
681 | - | |
682 | - if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | |
683 | - { | |
684 | - LOG_ERROR(L"连接加密机失败!"); | |
685 | - reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | |
686 | - } | |
687 | - | |
688 | - try | |
689 | - { | |
690 | - key_DCCK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kDCCK>(), card_sn, TIMEOUT); | |
691 | - key_F0015_DACK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DACK>(), card_sn, TIMEOUT); | |
692 | - } | |
693 | - catch (std::exception& ex) | |
694 | - { | |
695 | - LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | |
696 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
697 | - break; | |
698 | - } | |
699 | - | |
700 | - pwd_machine.Disconnect(); | |
701 | - } | |
702 | - else if (etEncrypType == ET_DES) | |
703 | - { | |
704 | - LOG_TRACE(L"软加密模式计算主控秘钥。"); | |
705 | - try | |
706 | - { | |
707 | - const char* pDCCKDL = "43434bff43434bff"; | |
708 | - const char* pDACKDL = "41434bff41434bff"; | |
709 | - | |
710 | - unsigned char aucCardSNHex[16] = { 0 }; | |
711 | - unsigned char aucDCCKDL[8] = { 0 }, aucDACKDL[8] = { 0 }; | |
712 | - EncryptTools::StringToHex((unsigned char*)pDCCKDL, 16, aucDCCKDL); | |
713 | - EncryptTools::StringToHex((unsigned char*)pDACKDL, 16, aucDACKDL); | |
714 | - EncryptTools::StringToHex((unsigned char*)card_sn.c_str(), 32, aucCardSNHex); | |
715 | - | |
716 | - unsigned char aucNewDCCKHex[16] = { 0 }, aucNewDACKHex[16] = { 0 }; | |
717 | - unsigned char aucNewDCCK[32] = { 0 }, aucNewDACK[32] = { 0 }; | |
718 | - | |
719 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDCCKDL, aucNewDCCKHex); | |
720 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDACKDL, aucNewDACKHex); | |
721 | - | |
722 | - EncryptTools::HexToChar(aucNewDCCKHex, 16, aucNewDCCK); | |
723 | - EncryptTools::HexToChar(aucNewDACKHex, 16, aucNewDACK); | |
724 | - | |
725 | - std::string sDCCKKey((char*)aucNewDCCK, 32); | |
726 | - std::string sDACKKey((char*)aucNewDACK, 32); | |
727 | - | |
728 | - key_DCCK = sDCCKKey; | |
729 | - key_F0015_DACK = sDACKKey; | |
730 | - | |
731 | - } | |
732 | - catch (std::exception& ex) | |
733 | - { | |
734 | - LOG_FATAL(L"软加密密钥失败"); | |
735 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
736 | - break; | |
737 | - } | |
738 | - } | |
739 | - | |
740 | - if (slLevel == HardwareCmd::SL_2) | |
741 | - { | |
742 | - LOG_TRACE(L"验证卡片。"); | |
743 | - if (!dili_card_device.AuthenticationKey(key_DCCK)) | |
744 | - { | |
745 | - LOG_FATAL(L"秘钥验证失败,卡片需要升级!"); | |
746 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_NEED_UPDATE_CAN_NOT_USE; | |
747 | - break; | |
748 | - } | |
749 | - } | |
750 | - | |
244 | + LOG_TRACE(L"连接读卡器。"); | |
245 | + cCamCard.Connect(); | |
246 | + LOG_TRACE(L"寻卡操作。"); | |
247 | + cCamCard.FindAndResetCard(); | |
248 | + LOG_TRACE(L"切换主目录。"); | |
249 | + cCamCard.SelectMF(); | |
250 | + LOG_TRACE(L"切换文件。"); | |
251 | + cCamCard.SelectFile(); | |
252 | + LOG_TRACE(L"读取卡片基本信息。"); | |
253 | + card_basic_info = cCamCard.ReadCardBasicInfo(); | |
254 | + } | |
255 | + catch (std::exception& ex) | |
256 | + { | |
257 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_RESET_CARD_FAILED; | |
258 | + LOG_FATAL(L"读取园区卡信息失败,错误信息: " + str_2_wstr(ex.what())); | |
259 | + } | |
260 | + cCamCard.DisConnect(); | |
751 | 261 | |
752 | - try | |
753 | - { | |
754 | - dili_card_device.ResetCard(key_DCCK, key_F0015_DACK); | |
755 | - card_basic_info = dili_card_device.ReadCardBasicInfo(); | |
756 | - } | |
757 | - catch (std::exception& ex) | |
758 | - { | |
759 | - LOG_FATAL(L"卡片撤销激活失败,错误信息: " + str_2_wstr(ex.what())); | |
760 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_RESET_CARD_FAILED; | |
761 | - break; | |
762 | - } | |
763 | - } while (0); | |
764 | - dili_card_device.Disconnect(); | |
765 | 262 | if (boost::iequals(reply.error_code, StatusCode::OK)) |
766 | - LOG_TRACE(L"卡片撤销激活成功。"); | |
263 | + { | |
264 | + LOG_TRACE(L"撤销园区卡激活操作成功。"); | |
265 | + } | |
266 | + else | |
267 | + { | |
268 | + LOG_TRACE(L"撤销园区卡激活操作失败。"); | |
269 | + } | |
767 | 270 | |
768 | 271 | reply.data.put("chipNo", card_basic_info.chip_num); |
769 | 272 | reply.data.put("deviceId", card_basic_info.device_id); |
... | ... | @@ -771,243 +274,97 @@ ReadPINPadCmd::Reply ResetDILICardCmd::Execute(const std::string& input) |
771 | 274 | reply.data.put("issuerCode", card_basic_info.issuer_code); |
772 | 275 | reply.data.put("verifyCode", card_basic_info.verify_code); |
773 | 276 | return reply; |
277 | + // | |
774 | 278 | } |
775 | 279 | |
776 | 280 | ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) |
777 | 281 | { |
778 | - LOG_TRACE(L"读取卡片基本信息。"); | |
779 | - auto& dili_card_device = DILICardRWDevice(); | |
282 | + //临时只读基本信息 add by liuye | |
283 | + LOG_TRACE(L"读取园区卡基本信息操作。"); | |
284 | + auto cCamCard = DLCamCardManager_(); | |
780 | 285 | Reply reply; |
781 | 286 | DILICard::BasicInfo card_basic_info; |
782 | - do | |
287 | + try | |
783 | 288 | { |
784 | - try | |
785 | - { | |
786 | - dili_card_device.Connect(); | |
787 | - } | |
788 | - catch (std::exception& ex) | |
789 | - { | |
790 | - LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); | |
791 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; | |
792 | - break; | |
793 | - } | |
794 | - try | |
795 | - { | |
796 | - dili_card_device.FindCard(); | |
797 | - } | |
798 | - catch (std::exception& ex) | |
799 | - { | |
800 | - LOG_FATAL(L"寻卡失败,错误信息: " + str_2_wstr(ex.what())); | |
801 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | |
802 | - break; | |
803 | - } | |
804 | - | |
805 | - try { card_basic_info = dili_card_device.ReadCardBasicInfo(); } | |
806 | - catch (std::exception& ex) | |
807 | - { | |
808 | - LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | |
809 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | |
810 | - break; | |
811 | - } | |
812 | - | |
813 | - | |
814 | - if (SL_2 == ApplicationConfig::Instance().SecurityLevel()) | |
815 | - { | |
816 | - LOG_TRACE(L"计算主控秘钥。"); | |
817 | - std::string sSN = card_basic_info.chip_num + "44494c49" + card_basic_info.chip_num; | |
818 | - std::string sDCCK; | |
819 | - | |
820 | - if (ET_DES == ApplicationConfig::Instance().EncryptType()) | |
821 | - { | |
822 | - LOG_TRACE(L"软加密模式计算主控秘钥。"); | |
823 | - const char* pDCCKDL = "43434bff43434bff"; | |
824 | - | |
825 | - unsigned char aucCardSNHex[16] = { 0 }; | |
826 | - unsigned char aucDCCKDL[8] = { 0 }; | |
827 | - EncryptTools::StringToHex((unsigned char*)pDCCKDL, 16, aucDCCKDL); | |
828 | - EncryptTools::StringToHex((unsigned char*)sSN.c_str(), 32, aucCardSNHex); | |
829 | - | |
830 | - unsigned char aucNewDCCKHex[16] = { 0 }; | |
831 | - unsigned char aucNewDCCK[32] = { 0 }; | |
832 | - | |
833 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDCCKDL, aucNewDCCKHex); | |
834 | - | |
835 | - EncryptTools::HexToChar(aucNewDCCKHex, 16, aucNewDCCK); | |
836 | - | |
837 | - std::string sDCCKKey((char*)aucNewDCCK, 32); | |
838 | - | |
839 | - sDCCK = sDCCKKey; | |
840 | - } | |
841 | - else if (ET_PWM == ApplicationConfig::Instance().EncryptType()) | |
842 | - { | |
843 | - LOG_TRACE(L"加密机模式计算主控秘钥。"); | |
844 | - const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | |
845 | - const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | |
846 | - const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | |
847 | - | |
848 | - auto& pwd_machine = PWDMachine_(); | |
849 | - | |
850 | - if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | |
851 | - { | |
852 | - LOG_ERROR(L"连接加密机失败!"); | |
853 | - reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | |
854 | - } | |
855 | - | |
856 | - try | |
857 | - { | |
858 | - sDCCK = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kDCCK>(), sSN, TIMEOUT); | |
859 | - } | |
860 | - catch (std::exception& ex) | |
861 | - { | |
862 | - LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | |
863 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
864 | - break; | |
865 | - } | |
866 | - pwd_machine.Disconnect(); | |
867 | - } | |
868 | - | |
869 | - LOG_TRACE(L"验证卡片。"); | |
870 | - if (!dili_card_device.AuthenticationKey(sDCCK)) | |
871 | - { | |
872 | - LOG_FATAL(L"秘钥验证失败,卡片需要升级!"); | |
873 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_NEED_UPDATE_CAN_NOT_USE; | |
874 | - break; | |
875 | - } | |
876 | - | |
877 | - } | |
878 | - | |
879 | - if (dili_card_device.NeedCreateFile()) | |
880 | - { | |
881 | - LOG_FATAL(L"卡片需要升级!"); | |
882 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_NEED_UPDATE_CAN_USE; | |
883 | - //启动卡片升级程序 add by liuye | |
884 | - ShellExecute(NULL, L"open", L".\\DLCardTool.exe", NULL, NULL, SW_SHOW); | |
885 | - // | |
886 | - } | |
289 | + LOG_TRACE(L"连接读卡器。"); | |
290 | + cCamCard.Connect(); | |
291 | + LOG_TRACE(L"寻卡操作。"); | |
292 | + cCamCard.FindAndResetCard(); | |
293 | + LOG_TRACE(L"切换主目录。"); | |
294 | + cCamCard.SelectMF(); | |
295 | + LOG_TRACE(L"切换文件。"); | |
296 | + cCamCard.SelectFile(); | |
297 | + LOG_TRACE(L"读取卡片基本信息。"); | |
298 | + card_basic_info = cCamCard.ReadCardBasicInfo(); | |
299 | + } | |
300 | + catch (std::exception& ex) | |
301 | + { | |
302 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | |
303 | + LOG_FATAL(L"读取园区卡信息失败,错误信息: " + str_2_wstr(ex.what())); | |
304 | + } | |
305 | + cCamCard.DisConnect(); | |
887 | 306 | |
888 | - } while (0); | |
889 | - dili_card_device.Disconnect(); | |
890 | - if (boost::iequals(reply.error_code, StatusCode::OK) || boost::iequals(reply.error_code, StatusCode::DILI_CARD_DEVICE_NEED_UPDATE_CAN_USE)) | |
891 | - LOG_TRACE(L"读取卡片基本信息成功。"); | |
307 | + if (boost::iequals(reply.error_code, StatusCode::OK)) | |
308 | + { | |
309 | + LOG_TRACE(L"读取园区卡信息成功。"); | |
310 | + } | |
311 | + else | |
312 | + { | |
313 | + LOG_TRACE(L"读取园区卡信息失败。"); | |
314 | + } | |
892 | 315 | |
893 | 316 | reply.data.put("chipNo", card_basic_info.chip_num); |
894 | 317 | reply.data.put("deviceId", card_basic_info.device_id); |
895 | 318 | reply.data.put("type", card_basic_info.type_code); |
896 | 319 | reply.data.put("issuerCode", card_basic_info.issuer_code); |
897 | 320 | reply.data.put("verifyCode", card_basic_info.verify_code); |
898 | - g_sCardNum = card_basic_info.device_id; | |
899 | 321 | return reply; |
322 | + // | |
900 | 323 | } |
901 | 324 | |
902 | 325 | ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& input) |
903 | 326 | { |
904 | - SecurityLevel slLevel = (SecurityLevel)ApplicationConfig::Instance().SecurityLevel(); | |
905 | - EncryptType etEncrypType = (EncryptType)ApplicationConfig::Instance().EncryptType(); | |
327 | + const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | |
328 | + const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | |
329 | + const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | |
330 | + const uint8_t BEEP_TIME = 20; // 20 * 10ms | |
906 | 331 | LOG_TRACE(L"读取卡片业务信息。"); |
907 | 332 | auto& dili_card_device = DILICardRWDevice(); |
908 | - | |
333 | + auto& pwd_machine = PWDMachine_(); | |
909 | 334 | Reply reply; |
910 | - | |
911 | - //安全等级都为0了,还读个毛的业务信息,直接返回! | |
912 | - if (slLevel == HardwareCmd::SL_0) | |
913 | - { | |
914 | - reply.error_code == StatusCode::OK; | |
915 | - LOG_TRACE(L"读取卡片业务信息成功。"); | |
916 | - return reply; | |
917 | - } | |
918 | - | |
335 | + std::string card_sn; | |
919 | 336 | std::string key_r; |
920 | 337 | std::string service_data; |
921 | 338 | do |
922 | 339 | { |
923 | - try | |
924 | - { | |
925 | - dili_card_device.Connect(); | |
926 | - } | |
927 | - catch (std::exception& ex) | |
340 | + if (!dili_card_device.Connect()) | |
928 | 341 | { |
929 | - LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); | |
342 | + LOG_ERROR(L"打开CPU卡读卡器失败!"); | |
930 | 343 | reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; |
931 | 344 | break; |
932 | 345 | } |
933 | - try | |
346 | + if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | |
934 | 347 | { |
935 | - dili_card_device.FindCard(); | |
348 | + LOG_ERROR(L"连接加密机失败!"); | |
349 | + reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | |
350 | + break; | |
936 | 351 | } |
352 | + dili_card_device.Beep(BEEP_TIME); | |
353 | + try { card_sn = dili_card_device.FindCard(); } | |
937 | 354 | catch (std::exception& ex) |
938 | 355 | { |
939 | - LOG_FATAL(L"寻卡失败,错误信息: " + str_2_wstr(ex.what())); | |
356 | + LOG_FATAL(L"查找卡片失败,错误信息: " + str_2_wstr(ex.what())); | |
940 | 357 | reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; |
941 | 358 | break; |
942 | 359 | } |
943 | - | |
944 | - DILICard::BasicInfo stuCardBasicInfo; | |
945 | - try { stuCardBasicInfo = dili_card_device.ReadCardBasicInfo(); } | |
360 | + try { key_r = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DEAK>(), card_sn, TIMEOUT); } | |
946 | 361 | catch (std::exception& ex) |
947 | 362 | { |
948 | - LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | |
949 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | |
363 | + LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | |
364 | + reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
950 | 365 | break; |
951 | 366 | } |
952 | 367 | |
953 | - LOG_TRACE(L"计算SN。"); | |
954 | - std::string sSN; | |
955 | - if (slLevel == HardwareCmd::SL_1) | |
956 | - { | |
957 | - sSN = stuCardBasicInfo.device_id; | |
958 | - } | |
959 | - else if (slLevel == HardwareCmd::SL_2) | |
960 | - { | |
961 | - sSN = stuCardBasicInfo.chip_num + "44494c49" + stuCardBasicInfo.chip_num; | |
962 | - } | |
963 | - | |
964 | - if (etEncrypType == ET_PWM) | |
965 | - { | |
966 | - LOG_TRACE(L"加密机模式计算主控秘钥。"); | |
967 | - auto& pwd_machine = PWDMachine_(); | |
968 | - const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | |
969 | - const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | |
970 | - const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | |
971 | - | |
972 | - if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | |
973 | - { | |
974 | - LOG_ERROR(L"连接加密机失败!"); | |
975 | - reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | |
976 | - break; | |
977 | - } | |
978 | - | |
979 | - try { key_r = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DEAK>(), sSN, TIMEOUT); } | |
980 | - catch (std::exception& ex) | |
981 | - { | |
982 | - LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | |
983 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
984 | - break; | |
985 | - } | |
986 | - | |
987 | - pwd_machine.Disconnect(); | |
988 | - } | |
989 | - else if (etEncrypType == ET_DES) | |
990 | - { | |
991 | - LOG_TRACE(L"软加密模式计算主控秘钥。"); | |
992 | - const char* pDEAKDL = "45414bff45414bff"; | |
993 | - | |
994 | - unsigned char aucCardSNHex[16] = { 0 }; | |
995 | - unsigned char aucDEAKDL[8] = { 0 }; | |
996 | - EncryptTools::StringToHex((unsigned char*)pDEAKDL, 16, aucDEAKDL); | |
997 | - EncryptTools::StringToHex((unsigned char*)sSN.c_str(), 32, aucCardSNHex); | |
998 | - | |
999 | - unsigned char aucNewDEAKHex[16] = { 0 }; | |
1000 | - unsigned char aucNewDEAK[32] = { 0 }; | |
1001 | - | |
1002 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDEAKDL, aucNewDEAKHex); | |
1003 | - | |
1004 | - EncryptTools::HexToChar(aucNewDEAKHex, 16, aucNewDEAK); | |
1005 | - | |
1006 | - std::string sDEAKKey((char*)aucNewDEAK, 32); | |
1007 | - | |
1008 | - key_r = sDEAKKey; | |
1009 | - } | |
1010 | - | |
1011 | 368 | try { service_data = dili_card_device.ReadCardServiceInfo(key_r); } |
1012 | 369 | catch (std::exception& ex) |
1013 | 370 | { |
... | ... | @@ -1016,8 +373,8 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu |
1016 | 373 | break; |
1017 | 374 | } |
1018 | 375 | } while (0); |
1019 | - | |
1020 | 376 | dili_card_device.Disconnect(); |
377 | + pwd_machine.Disconnect(); | |
1021 | 378 | if (boost::iequals(reply.error_code, StatusCode::OK)) |
1022 | 379 | LOG_TRACE(L"读取卡片业务信息成功。"); |
1023 | 380 | |
... | ... | @@ -1027,152 +384,24 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu |
1027 | 384 | |
1028 | 385 | ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& input) |
1029 | 386 | { |
1030 | - const char DATA_SPLITER = ':'; | |
1031 | - SecurityLevel slLevel = (SecurityLevel)ApplicationConfig::Instance().SecurityLevel(); | |
1032 | - EncryptType etEncrypType = (EncryptType)ApplicationConfig::Instance().EncryptType(); | |
1033 | - | |
1034 | - LOG_TRACE(L"写入卡片业务信息。"); | |
1035 | - auto& dili_card_device = DILICardRWDevice(); | |
1036 | - | |
387 | + //临时方法,不写入业务数据 add by liuye | |
1037 | 388 | Reply reply; |
1038 | - //std::string card_sn; | |
1039 | - std::string key_w; | |
1040 | - do | |
389 | + auto cCamCard = DLCamCardManager_(); | |
390 | + DILICard::BasicInfo card_basic_info; | |
391 | + try | |
1041 | 392 | { |
1042 | - try | |
1043 | - { | |
1044 | - dili_card_device.Connect(); | |
1045 | - } | |
1046 | - catch (std::exception& ex) | |
1047 | - { | |
1048 | - LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); | |
1049 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; | |
1050 | - break; | |
1051 | - } | |
1052 | - | |
1053 | - //安全等级都为0了,还写个毛的业务信息,直接返回! | |
1054 | - if (slLevel == HardwareCmd::SL_0) | |
1055 | - { | |
1056 | - reply.error_code == StatusCode::OK; | |
1057 | - LOG_TRACE(L"读取卡片业务信息成功。"); | |
1058 | - return reply; | |
1059 | - } | |
1060 | - | |
1061 | - try | |
1062 | - { | |
1063 | - dili_card_device.FindCard(); | |
1064 | - } | |
1065 | - catch (std::exception& ex) | |
1066 | - { | |
1067 | - LOG_FATAL(L"寻卡失败,错误信息: " + str_2_wstr(ex.what())); | |
1068 | - reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | |
1069 | - break; | |
1070 | - } | |
1071 | - | |
1072 | - DILICard::BasicInfo stuCardBasicInfo; | |
1073 | - try { stuCardBasicInfo = dili_card_device.ReadCardBasicInfo(); } | |
1074 | - catch (std::exception& ex) | |
1075 | - { | |
1076 | - LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | |
1077 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | |
1078 | - break; | |
1079 | - } | |
1080 | - //card_sn = stuCardBasicInfo.device_id; | |
1081 | - | |
1082 | - LOG_TRACE(L"计算SN。"); | |
1083 | - std::string sSN; | |
1084 | - if (slLevel == HardwareCmd::SL_1) | |
1085 | - { | |
1086 | - sSN = stuCardBasicInfo.device_id; | |
1087 | - } | |
1088 | - else if (slLevel == HardwareCmd::SL_2) | |
1089 | - { | |
1090 | - sSN = stuCardBasicInfo.chip_num + "44494c49" + stuCardBasicInfo.chip_num; | |
1091 | - } | |
1092 | - | |
1093 | - | |
1094 | - std::size_t index = input.find(DATA_SPLITER); | |
1095 | - if (std::string::npos == index) // NOT found. | |
1096 | - { | |
1097 | - LOG_ERROR(L"写入卡片业务信息失败,错误信息:请求数据错误。"); | |
1098 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED; | |
1099 | - break; | |
1100 | - } | |
1101 | - std::string device_id = g_sCardNum;//用于办卡时,保证操作的卡片是同一张; | |
1102 | - std::string service_data = input.substr(index + 1, input.size() - index - 1); | |
1103 | - | |
1104 | - // 验证操作的是否是同一张卡,即device_id是否匹配 | |
1105 | - if (!boost::iequals(sSN, device_id)) | |
1106 | - { | |
1107 | - LOG_ERROR(L"写卡卡片的序列号不匹配!"); | |
1108 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_UNMATCHED_CARD; | |
1109 | - break; | |
1110 | - } | |
1111 | - | |
1112 | - if (etEncrypType == ET_PWM) | |
1113 | - { | |
1114 | - LOG_TRACE(L"加密机模式计算主控秘钥。"); | |
1115 | - auto& pwd_machine = PWDMachine_(); | |
1116 | - | |
1117 | - const std::string PWD_MACHINE_IP = ApplicationConfig::Instance().PWDMachineIP(); | |
1118 | - const uint32_t PWD_MACHINE_PORT = ApplicationConfig::Instance().PWDMachinePort(); | |
1119 | - const uint8_t TIMEOUT = ApplicationConfig::Instance().PWDMachineTimeout(); | |
1120 | - | |
1121 | - if (!pwd_machine.Connect(PWD_MACHINE_IP, PWD_MACHINE_PORT)) | |
1122 | - { | |
1123 | - LOG_ERROR(L"连接加密机失败!"); | |
1124 | - reply.error_code = StatusCode::PWD_MACHINE_CONNECT_FAILED; | |
1125 | - break; | |
1126 | - } | |
1127 | - | |
1128 | - try { key_w = pwd_machine.GetCardPassword(DILICard::CardKeyCode<DILICard::KeyCode::kF0015_DAMK1>(), sSN, TIMEOUT); } | |
1129 | - catch (std::exception& ex) | |
1130 | - { | |
1131 | - LOG_FATAL(L"从加密机读取密钥失败,错误信息: " + str_2_wstr(ex.what())); | |
1132 | - reply.error_code = StatusCode::PWD_MACHINE_GET_KEY_FAILED; | |
1133 | - break; | |
1134 | - } | |
1135 | - | |
1136 | - pwd_machine.Disconnect(); | |
1137 | - } | |
1138 | - else if (etEncrypType == ET_DES) | |
1139 | - { | |
1140 | - LOG_TRACE(L"软加密模式计算15写秘钥。"); | |
1141 | - const char* pDAMKDL = "414d4b31414d4b31"; | |
1142 | - | |
1143 | - unsigned char aucCardSNHex[16] = { 0 }; | |
1144 | - unsigned char aucDAMKDL[8] = { 0 }; | |
1145 | - EncryptTools::StringToHex((unsigned char*)pDAMKDL, 16, aucDAMKDL); | |
1146 | - EncryptTools::StringToHex((unsigned char*)sSN.c_str(), 32, aucCardSNHex); | |
1147 | - | |
1148 | - unsigned char aucNewDAMKHex[16] = { 0 }; | |
1149 | - unsigned char aucNewDAMK[32] = { 0 }; | |
1150 | - | |
1151 | - EncryptTools::Encrypt(aucCardSNHex, 16, aucDAMKDL, aucNewDAMKHex); | |
1152 | - | |
1153 | - EncryptTools::HexToChar(aucNewDAMKHex, 16, aucNewDAMK); | |
1154 | - | |
1155 | - std::string sDAMKKey((char*)aucNewDAMK, 32); | |
1156 | - | |
1157 | - key_w = sDAMKKey; | |
1158 | - } | |
1159 | - | |
1160 | - try { dili_card_device.WriteCardServiceInfo(key_w, service_data); } | |
1161 | - catch (std::exception& ex) | |
1162 | - { | |
1163 | - LOG_FATAL(L"写入卡片业务信息失败,错误信息: " + str_2_wstr(ex.what())); | |
1164 | - reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED; | |
1165 | - break; | |
1166 | - } | |
1167 | - | |
1168 | - | |
1169 | - } while (0); | |
1170 | - | |
1171 | - dili_card_device.Disconnect(); | |
1172 | - if (boost::iequals(reply.error_code, StatusCode::OK)) | |
1173 | - LOG_TRACE(L"写入卡片业务信息成功。"); | |
1174 | - reply.data.put("", ""); | |
393 | + LOG_TRACE(L"连接读卡器。"); | |
394 | + cCamCard.Connect(); | |
395 | + } | |
396 | + catch (std::exception& ex) | |
397 | + { | |
398 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED; | |
399 | + LOG_FATAL(L"读取园区卡信息失败,错误信息: " + str_2_wstr(ex.what())); | |
400 | + } | |
401 | + cCamCard.DisConnect(); | |
402 | + LOG_TRACE(L"写入业务数据操作成功!"); | |
1175 | 403 | return reply; |
404 | + // | |
1176 | 405 | } |
1177 | 406 | |
1178 | 407 | ReadPINPadCmd::Reply ReadBankCardNumCmd::Execute(const std::string& input) |
... | ... | @@ -1207,3 +436,4 @@ ReadPINPadCmd::Reply ReadBankCardNumCmd::Execute(const std::string& input) |
1207 | 436 | reply.data.put("chipNo", bank_card_no); |
1208 | 437 | return reply; |
1209 | 438 | } |
439 | + | ... | ... |
etrade_card_client/ETradeClient/hardware/hardware_cmd.h
... | ... | @@ -18,21 +18,6 @@ public: |
18 | 18 | std::string error_code; |
19 | 19 | }; |
20 | 20 | |
21 | - //卡片安全等级 | |
22 | - enum SecurityLevel | |
23 | - { | |
24 | - SL_0 = 0, // 0表示最低级,不替换秘钥,不写入业务信息,不做安全认证 | |
25 | - SL_1, // 等级1需要替换秘钥,写入业务信息,不做安全认证 | |
26 | - SL_2 // 等级2需要替换秘钥,写入业务信息,需要安全认证 | |
27 | - }; | |
28 | - | |
29 | - //秘钥加密方式 | |
30 | - enum EncryptType | |
31 | - { | |
32 | - ET_PWM = 0, //加密机方式加密 | |
33 | - ET_DES = 1 //des算法加密 | |
34 | - }; | |
35 | - | |
36 | 21 | virtual ~HardwareCmd() {} |
37 | 22 | |
38 | 23 | /*Exception will be thrown if any error happens.*/ | ... | ... |
etrade_card_client/ETradeClient/hardware/id_card_reader.cpp
... | ... | @@ -7,7 +7,6 @@ |
7 | 7 | #include "etradeclient/hardware/id_card_reader.h" |
8 | 8 | #include "etradeclient/utility/application_config.h" |
9 | 9 | #include "etradeclient/utility/string_converter.h" |
10 | -#include "ETradeClient/hardware/SynPublic.h" | |
11 | 10 | |
12 | 11 | namespace |
13 | 12 | { |
... | ... | @@ -20,7 +19,6 @@ namespace |
20 | 19 | const std::string IDCardReader::ID_CARD_READER_HARDWARE_INFO = "China-Vision_CVR-100U"; |
21 | 20 | |
22 | 21 | IDCardReader::IDCardReader() |
23 | - :m_iPort(0) | |
24 | 22 | { |
25 | 23 | Init(); |
26 | 24 | } |
... | ... | @@ -147,108 +145,4 @@ void IDCardReader::GetPortraitPath(std::wstring& portrait_path) const |
147 | 145 | throw std::exception("ID card portrait image does not exist."); |
148 | 146 | |
149 | 147 | portrait_path = portrait_path_; |
150 | -} | |
151 | - | |
152 | -bool IDCardReader::SynConnect() | |
153 | -{ | |
154 | - bool bResult = true; | |
155 | - int iRet = 0; | |
156 | - | |
157 | - iRet = Syn_FindUSBReader(); | |
158 | - | |
159 | - if (iRet == 0) | |
160 | - { | |
161 | - bResult = false; | |
162 | - } | |
163 | - else | |
164 | - { | |
165 | - m_iPort = iRet; | |
166 | - if (Syn_OpenPort(m_iPort)) | |
167 | - { | |
168 | - bResult = false; | |
169 | - } | |
170 | - } | |
171 | - | |
172 | - return bResult; | |
173 | -} | |
174 | - | |
175 | -bool IDCardReader::SynDisConnect() | |
176 | -{ | |
177 | - bool bResult = true; | |
178 | - | |
179 | - if (m_iPort) | |
180 | - { | |
181 | - if (Syn_ClosePort(m_iPort)) | |
182 | - { | |
183 | - bResult = false; | |
184 | - } | |
185 | - } | |
186 | - return bResult; | |
187 | -} | |
188 | - | |
189 | -bool IDCardReader::SynFindCard() | |
190 | -{ | |
191 | - bool bResult = true; | |
192 | - | |
193 | - do | |
194 | - { | |
195 | - unsigned char aucIIN[4] = { 0 }, aucSN[8] = { 0 }; | |
196 | - if (Syn_StartFindIDCard(m_iPort, aucIIN, 0)) | |
197 | - { | |
198 | - bResult = false; | |
199 | - break; | |
200 | - } | |
201 | - | |
202 | - if (Syn_SelectIDCard(m_iPort, aucSN, 0)) | |
203 | - { | |
204 | - bResult = false; | |
205 | - break; | |
206 | - } | |
207 | - } while (0); | |
208 | - | |
209 | - return bResult; | |
210 | -} | |
211 | - | |
212 | -BOOL StringToWString(const std::string &str, std::wstring &wstr) | |
213 | -{ | |
214 | - int nLen = (int)str.length(); | |
215 | - wstr.resize(nLen, L' '); | |
216 | - | |
217 | - int nResult = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)str.c_str(), nLen, (LPWSTR)wstr.c_str(), nLen); | |
218 | - | |
219 | - if (nResult == 0) | |
220 | - { | |
221 | - return FALSE; | |
222 | - } | |
223 | - return TRUE; | |
224 | -} | |
225 | - | |
226 | -IDCardInfo IDCardReader::SynReadCard() | |
227 | -{ | |
228 | - IDCardInfo stuCardInfo; | |
229 | - IDCardData stuCardData; | |
230 | - | |
231 | - char ctmp[256] = { 0 }; | |
232 | - Syn_SetPhotoPath(1, ctmp); | |
233 | - Syn_SetPhotoName(2); | |
234 | - Syn_SetPhotoType(0); | |
235 | - Syn_SetSexType(1); | |
236 | - Syn_SetNationType(2); | |
237 | - Syn_SetBornType(3); | |
238 | - | |
239 | - if (!Syn_ReadMsg(m_iPort, 0, &stuCardData)) | |
240 | - { | |
241 | - StringToWString(stuCardData.Name, stuCardInfo.name); | |
242 | - StringToWString(stuCardData.Sex, stuCardInfo.gender); | |
243 | - StringToWString(stuCardData.Nation, stuCardInfo.nation); | |
244 | - StringToWString(stuCardData.Born, stuCardInfo.birth_date); | |
245 | - StringToWString(stuCardData.Address, stuCardInfo.address); | |
246 | - StringToWString(stuCardData.IDCardNo, stuCardInfo.id_code); | |
247 | - StringToWString(stuCardData.GrantDept, stuCardInfo.depart); | |
248 | - StringToWString(stuCardData.UserLifeBegin, stuCardInfo.start_date); | |
249 | - StringToWString(stuCardData.UserLifeEnd, stuCardInfo.end_date); | |
250 | - StringToWString(stuCardData.PhotoFileName, stuCardInfo.portrait_img_path); | |
251 | - } | |
252 | - | |
253 | - return stuCardInfo; | |
254 | 148 | } |
255 | 149 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient/hardware/id_card_reader.h
... | ... | @@ -41,21 +41,12 @@ public: |
41 | 41 | bool VerifyCard() const; |
42 | 42 | IDCardInfo ReadCard() const; |
43 | 43 | |
44 | - //新中新电子身份证读卡器接口 add by liuye 2017.10.24 | |
45 | - bool SynConnect(); | |
46 | - bool SynFindCard(); | |
47 | - IDCardInfo SynReadCard(); | |
48 | - bool SynDisConnect(); | |
49 | - // | |
50 | - | |
51 | 44 | private: |
52 | 45 | void Init(); // Load library to initialize all the function object. |
53 | 46 | bool DoConnect(int port_min, int port_max) const; |
54 | 47 | void GetCardField(ReadContentFieldFunc fn, std::wstring& field) const; |
55 | 48 | void GetPortraitPath(std::wstring& portrait_path) const; |
56 | 49 | |
57 | - | |
58 | - | |
59 | 50 | InitCommFunc m_init_comm_fn; // Function object to init the communitation with ID card reader. |
60 | 51 | CloseCommFunc m_close_comm_fn; // Function object to close the communitation with ID card reader. |
61 | 52 | AuthenticateFunc m_auth_fn; // Function object to authentication of the ID card reader. |
... | ... | @@ -71,8 +62,6 @@ private: |
71 | 62 | ReadContentFieldFunc m_get_start_date_fn; |
72 | 63 | ReadContentFieldFunc m_get_end_data_fn; |
73 | 64 | |
74 | - int m_iPort; | |
75 | - | |
76 | 65 | static const std::string ID_CARD_READER_HARDWARE_INFO; // Currently this field is not used. |
77 | 66 | }; |
78 | 67 | #endif // ETRADECLIENT_HARDWARE_ID_CARD_READER_H_INCLUDED | ... | ... |
etrade_card_client/ETradeClient/mfc_ui/ConfigDialog.cpp
... | ... | @@ -18,7 +18,6 @@ END_MESSAGE_MAP() |
18 | 18 | |
19 | 19 | CConfigDialog::CConfigDialog(CWnd* pParent /*=NULL*/) |
20 | 20 | : CDialog(CConfigDialog::IDD, pParent) |
21 | - , m_id_reader_type(0) | |
22 | 21 | {} |
23 | 22 | |
24 | 23 | static const int HTTP = 0, HTTPS = 1; |
... | ... | @@ -30,7 +29,7 @@ void CConfigDialog::DoDataExchange(CDataExchange* pDX) |
30 | 29 | const int kMinPortValue = 0, kMaxPortValue = 65535; |
31 | 30 | const int kMinMsgCountQueryInterval = 60, kMaxMsgCountQueryInterval = 3600; |
32 | 31 | const int kMinTimeoutMs = 100, kMaxTimeoutMs = 10000; |
33 | - const int kMinTimeoutSeconds = 1, kMaxTimeoutSeconds = 15; | |
32 | + const int kMinTimeoutSeconds = 1, kMaxTimeoutSeconds = 10; | |
34 | 33 | const int kMinPwdLen = 6, kMaxPwdLen = 32; |
35 | 34 | |
36 | 35 | DDX_Text(pDX, IDC_EDIT_MSG_COUNT_QUERY_INTERVAL, m_msg_count_query_interval); |
... | ... | @@ -54,8 +53,6 @@ void CConfigDialog::DoDataExchange(CDataExchange* pDX) |
54 | 53 | |
55 | 54 | DDX_Text(pDX, IDC_EDIT_PIN_PAD_TIMEOUT, m_pin_pad_timeout); |
56 | 55 | DDV_MinMaxInt(pDX, m_pin_pad_timeout, kMinTimeoutSeconds, kMaxTimeoutSeconds); |
57 | - | |
58 | - DDX_Radio(pDX, IDC_RADIO_HUASHIDIANZI, m_id_reader_type); | |
59 | 56 | } |
60 | 57 | |
61 | 58 | void CConfigDialog::OnCbnSelchangeComboProtocol() |
... | ... | @@ -79,7 +76,6 @@ BOOL CConfigDialog::OnInitDialog() |
79 | 76 | m_pwd_machine_timeout = app_config.PWDMachineTimeout(); |
80 | 77 | m_pin_pad_pwd_len = app_config.PINPadPWDLen(); |
81 | 78 | m_pin_pad_timeout = app_config.PINPadTimeout(); |
82 | - m_id_reader_type = app_config.IDReaderType(); | |
83 | 79 | |
84 | 80 | const URLConfig& url_config = URLConfig::Instance(); |
85 | 81 | m_protocol_index = url_config.IsHttps() ? HTTPS : HTTP; |
... | ... | @@ -103,8 +99,7 @@ void CConfigDialog::OnOK() |
103 | 99 | m_pwd_machine_port, |
104 | 100 | m_pwd_machine_timeout, |
105 | 101 | m_pin_pad_pwd_len, |
106 | - m_pin_pad_timeout, | |
107 | - m_id_reader_type); | |
102 | + m_pin_pad_timeout); | |
108 | 103 | URLConfig::Instance().ModifyCfg((HTTPS == m_protocol_index), m_server_port); |
109 | 104 | |
110 | 105 | return CDialog::OnOK(); | ... | ... |
etrade_card_client/ETradeClient/mfc_ui/ConfigDialog.h
etrade_card_client/ETradeClient/mfc_ui/MainFrm.cpp
... | ... | @@ -29,9 +29,6 @@ |
29 | 29 | #include "etradeclient/utility/url_config.h" |
30 | 30 | #include "etradeclient/utility/string_converter.h" |
31 | 31 | |
32 | -#include "windows.h" | |
33 | -#include "TimeAPI.h" | |
34 | - | |
35 | 32 | #ifdef _DEBUG |
36 | 33 | #define new DEBUG_NEW |
37 | 34 | #endif |
... | ... | @@ -89,15 +86,9 @@ BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) |
89 | 86 | |
90 | 87 | ON_COMMAND_RANGE(ID_ISSUE_MEIGUI_CARD, ID_OPER_LOG_QUERY, OnMenuBtnClicked) |
91 | 88 | ON_COMMAND_RANGE(RELOAD, USER_ACCOUNT, OnToolBarBtnClicked) |
92 | - | |
89 | + | |
93 | 90 | ON_MESSAGE(WM_CEF_SESSION_EXPIRED, OnSessionExpired) |
94 | - ON_MESSAGE(WM_UPDATE_USER_MSG_COUNT, OnGotMsgCount) | |
95 | - | |
96 | - ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateStateBar) | |
97 | - | |
98 | - ON_WM_TIMER() | |
99 | - | |
100 | - ON_MESSAGE(WM_TIME_TICK, UpdateTime) | |
91 | + ON_MESSAGE(WM_UPDATE_USER_MSG_COUNT,OnGotMsgCount) | |
101 | 92 | END_MESSAGE_MAP() |
102 | 93 | |
103 | 94 | static UINT indicators[] = |
... | ... | @@ -106,7 +97,6 @@ static UINT indicators[] = |
106 | 97 | ID_INDICATOR_CAPS, |
107 | 98 | ID_INDICATOR_NUM, |
108 | 99 | ID_INDICATOR_SCRL, |
109 | - ID_INDICATOR_TIME | |
110 | 100 | }; |
111 | 101 | |
112 | 102 | // CMainFrame construction/destruction |
... | ... | @@ -137,7 +127,7 @@ bool CMainFrame::Launch() |
137 | 127 | |
138 | 128 | void CMainFrame::UpdateStatus(LPCTSTR status) |
139 | 129 | { |
140 | - //m_status_bar.SetPaneText(0, status); | |
130 | + m_status_bar.SetPaneText(0, status); | |
141 | 131 | } |
142 | 132 | |
143 | 133 | BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) |
... | ... | @@ -180,24 +170,6 @@ void CMainFrame::Dump(CDumpContext& dc) const |
180 | 170 | |
181 | 171 | // CMainFrame message handlers |
182 | 172 | |
183 | -UINT TimeTick(LPVOID lParam) | |
184 | -{ | |
185 | - CMainFrame* pDlg = (CMainFrame*)lParam; | |
186 | - DWORD dwStart, dwStop; | |
187 | - dwStop = timeGetTime();// 起始值和终止值 | |
188 | - while (TRUE) | |
189 | - { | |
190 | - dwStart = dwStop;// 上一次的终止值变成新的起始值 | |
191 | - ::SendMessage(pDlg->m_hWnd, WM_TIME_TICK, 0, 0);//发送消息通知对话框该更新时间了 | |
192 | - do | |
193 | - { | |
194 | - dwStop = timeGetTime(); | |
195 | - } while (dwStop - 1000 < dwStart); | |
196 | - } | |
197 | - return 0; | |
198 | -} | |
199 | - | |
200 | - | |
201 | 173 | int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) |
202 | 174 | { |
203 | 175 | do |
... | ... | @@ -212,14 +184,6 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) |
212 | 184 | break; |
213 | 185 | if (!CreateMainFrmUI()) |
214 | 186 | break; |
215 | - | |
216 | - AfxBeginThread(TimeTick, this);//这个级别高一点,用来更新时间 | |
217 | - SetTimer(1, 60000, NULL);//这个级别低一点,用来从服务器获取时间 | |
218 | - | |
219 | - UINT nIndex = m_status_bar.CommandToIndex(ID_INDICATOR_TIME);//获取时间指示器索引 | |
220 | - m_status_bar.SetPaneText(nIndex, m_cTimeManager.GetServerTime()); | |
221 | - | |
222 | - | |
223 | 187 | return 0; // Return 0 if all succeed. |
224 | 188 | } while (0); |
225 | 189 | return -1; // Return -1 to indicate error happens. |
... | ... | @@ -304,10 +268,10 @@ void CMainFrame::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu) |
304 | 268 | minfo.fMask = MIIM_FTYPE | MIIM_ID; |
305 | 269 | pMenu->GetMenuItemInfo(pos, &minfo, TRUE); |
306 | 270 | |
307 | - if ((minfo.fState & MFS_DISABLED) || (minfo.fState & MFS_UNCHECKED)) | |
271 | + /*if ((minfo.fState & MFS_DISABLED) || (minfo.fState & MFS_UNCHECKED)) | |
308 | 272 | { |
309 | - int i = 0; | |
310 | - } | |
273 | + int i = 0; | |
274 | + }*/ | |
311 | 275 | |
312 | 276 | if (minfo.fType == MFT_SEPARATOR) // Don't handle the separator. |
313 | 277 | continue; |
... | ... | @@ -513,8 +477,6 @@ bool CMainFrame::CreateMainFrmUI() |
513 | 477 | } |
514 | 478 | m_status_bar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT)); |
515 | 479 | |
516 | - //m_status_bar.SetPaneStyle(0, SBPS_NORMAL); | |
517 | - | |
518 | 480 | //@{ |
519 | 481 | if (!CreateWebNaviToolBar()) |
520 | 482 | { |
... | ... | @@ -814,33 +776,4 @@ LRESULT CMainFrame::OnCrashClose(WPARAM wParam, LPARAM lParam) |
814 | 776 | LOG_TRACE(L"崩溃程序关闭。"); |
815 | 777 | CFrameWnd::OnClose(); |
816 | 778 | return 0; |
817 | -} | |
818 | - | |
819 | - | |
820 | - | |
821 | -void CMainFrame::OnTimer(UINT_PTR nIDEvent) | |
822 | -{ | |
823 | - CString sTime; | |
824 | - if (nIDEvent == 1) | |
825 | - { | |
826 | - sTime = m_cTimeManager.GetServerTime(); | |
827 | - UINT nIndex = m_status_bar.CommandToIndex(ID_INDICATOR_TIME);//获取时间指示器索引 | |
828 | - m_status_bar.SetPaneText(nIndex, sTime); | |
829 | - } | |
830 | - | |
831 | - CFrameWnd::OnTimer(nIDEvent); | |
832 | -} | |
833 | - | |
834 | -void CMainFrame::OnUpdateStateBar(CCmdUI *pCmdUI) | |
835 | -{ | |
836 | - pCmdUI->Enable(); | |
837 | -} | |
838 | - | |
839 | -LRESULT CMainFrame::UpdateTime(WPARAM wParam, LPARAM lParam) | |
840 | -{ | |
841 | - CString sTime = m_cTimeManager.UpdateTime(); | |
842 | - UINT nIndex = m_status_bar.CommandToIndex(ID_INDICATOR_TIME);//获取时间指示器索引 | |
843 | - m_status_bar.SetPaneText(nIndex, sTime); | |
844 | - | |
845 | - return NULL; | |
846 | 779 | } |
847 | 780 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient/mfc_ui/MainFrm.h
... | ... | @@ -12,8 +12,6 @@ |
12 | 12 | #include "etradeclient/browser/user_msg_monitor.h" |
13 | 13 | #include "etradeclient/utility/menu_res_auth_mgr.h" |
14 | 14 | |
15 | -#include "etradeclient/utility/ETTimeManage.h" | |
16 | - | |
17 | 15 | class CMainFrame : public CFrameWnd |
18 | 16 | { |
19 | 17 | typedef std::map<uint32_t, HICON> MenuIconsType; |
... | ... | @@ -59,8 +57,6 @@ protected: |
59 | 57 | |
60 | 58 | afx_msg LRESULT OnCrashClose(WPARAM wParam, LPARAM lParam); |
61 | 59 | |
62 | - afx_msg void OnUpdateStateBar(CCmdUI *pCmdUI); | |
63 | - | |
64 | 60 | DECLARE_MESSAGE_MAP() |
65 | 61 | |
66 | 62 | private: |
... | ... | @@ -98,15 +94,6 @@ private: |
98 | 94 | int m_msg_count; |
99 | 95 | |
100 | 96 | bool m_is_view_closing; |
101 | - | |
102 | - CETTimeManage m_cTimeManager; | |
103 | - | |
104 | -public: | |
105 | - afx_msg void OnSize(UINT nType, int cx, int cy); | |
106 | - afx_msg void OnTimer(UINT_PTR nIDEvent); | |
107 | - afx_msg LRESULT UpdateTime(WPARAM wParam, LPARAM lParam); | |
108 | - | |
109 | - | |
110 | 97 | }; |
111 | 98 | |
112 | 99 | ... | ... |
etrade_card_client/ETradeClient/utility/application_config.cpp
... | ... | @@ -48,18 +48,6 @@ ApplicationConfig::ApplicationConfig() |
48 | 48 | m_client_cert_subject = ptree.get<std::string>("client_cert_subject"); |
49 | 49 | m_client_cert_filename = ptree.get<std::string>("client_cert_filename"); |
50 | 50 | m_client_cert_password = ptree.get<std::string>("client_cert_password"); |
51 | - m_security_level = ptree.get<uint8_t>("security_level"); //安全等级,数值越大等级越高,0为最低级 | |
52 | - m_encrypt_type = ptree.get<uint8_t>("encrypt_type"); //0为加密机加密,1为软加密 | |
53 | - m_id_reader = ptree.get<uint8_t>("id_reader");//读卡器种类,0为华视电子,1为新中新电子 | |
54 | - | |
55 | - | |
56 | - | |
57 | - //为了安全起见,目前只支持加密机加密一种模式 add by daxiong 2017.10.19 | |
58 | - /*if (m_is_encrypt == 1) | |
59 | - { | |
60 | - m_encrypt_type = 0; | |
61 | - }*/ | |
62 | - // | |
63 | 51 | } |
64 | 52 | catch (...) // Catch the exception in order for logging. |
65 | 53 | { |
... | ... | @@ -73,8 +61,7 @@ void ApplicationConfig::ModifyCfg(uint32_t msg_query_interval, |
73 | 61 | uint32_t pwd_machine_port, |
74 | 62 | uint32_t pwd_machine_time_out, |
75 | 63 | uint8_t pin_pad_pwd_len, |
76 | - uint8_t pin_pad_timeout, | |
77 | - int id_reader_type) | |
64 | + uint8_t pin_pad_timeout) | |
78 | 65 | { |
79 | 66 | std::stringstream ss; |
80 | 67 | namespace PT = boost::property_tree; |
... | ... | @@ -85,7 +72,6 @@ void ApplicationConfig::ModifyCfg(uint32_t msg_query_interval, |
85 | 72 | m_pwd_machine_timeout = pwd_machine_time_out; |
86 | 73 | m_pin_pad_pwd_len = pin_pad_pwd_len; |
87 | 74 | m_pin_pad_timeout = pin_pad_timeout; |
88 | - m_id_reader = id_reader_type; | |
89 | 75 | try |
90 | 76 | { |
91 | 77 | PT::ptree root; |
... | ... | @@ -99,10 +85,6 @@ void ApplicationConfig::ModifyCfg(uint32_t msg_query_interval, |
99 | 85 | root.put("client_cert_subject", m_client_cert_subject); |
100 | 86 | root.put("client_cert_filename", m_client_cert_filename); |
101 | 87 | root.put("client_cert_password", m_client_cert_password); |
102 | - root.put("security_level", m_security_level); | |
103 | - root.put("encrypt_type", m_encrypt_type); | |
104 | - root.put("id_reader", m_id_reader); | |
105 | - | |
106 | 88 | |
107 | 89 | PT::write_json(ss, root, true); |
108 | 90 | } |
... | ... | @@ -177,20 +159,4 @@ std::string ApplicationConfig::ClientCertFileName() const |
177 | 159 | std::string ApplicationConfig::ClientCertPassword() const |
178 | 160 | { |
179 | 161 | return m_client_cert_password; |
180 | -} | |
181 | - | |
182 | -uint8_t ApplicationConfig::SecurityLevel() const | |
183 | -{ | |
184 | - return m_security_level; | |
185 | -} | |
186 | - | |
187 | -uint8_t ApplicationConfig::EncryptType() const | |
188 | -{ | |
189 | - return m_encrypt_type; | |
190 | -} | |
191 | - | |
192 | -uint8_t ApplicationConfig::IDReaderType() const | |
193 | -{ | |
194 | - return m_id_reader; | |
195 | -} | |
196 | - | |
162 | +} | |
197 | 163 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient/utility/application_config.h
... | ... | @@ -16,8 +16,7 @@ public: |
16 | 16 | uint32_t pwd_machine_port, |
17 | 17 | uint32_t pwd_machine_time_out, |
18 | 18 | uint8_t pin_pad_pwd_len, |
19 | - uint8_t pin_pad_timeout, | |
20 | - int id_reader_type); | |
19 | + uint8_t pin_pad_timeout); | |
21 | 20 | |
22 | 21 | uint32_t MsgCountQueryInterval() const; // Return value in second. |
23 | 22 | std::string PWDMachineIP() const; // Don't worry about the cost of returning string object because we have RVO & move semantics. |
... | ... | @@ -29,10 +28,6 @@ public: |
29 | 28 | std::string ClientCertSubject() const; |
30 | 29 | std::string ClientCertFileName() const; |
31 | 30 | std::string ClientCertPassword() const; |
32 | - uint8_t SecurityLevel() const; | |
33 | - uint8_t EncryptType() const; | |
34 | - uint8_t IDReaderType() const; | |
35 | - | |
36 | 31 | private: |
37 | 32 | ApplicationConfig(); |
38 | 33 | ApplicationConfig(const ApplicationConfig&); |
... | ... | @@ -51,10 +46,5 @@ private: |
51 | 46 | std::string m_client_cert_subject; |
52 | 47 | std::string m_client_cert_filename; |
53 | 48 | std::string m_client_cert_password; |
54 | - | |
55 | - uint8_t m_security_level; | |
56 | - uint8_t m_encrypt_type; | |
57 | - uint8_t m_id_reader; | |
58 | - | |
59 | 49 | }; |
60 | 50 | #endif // ETRADECLIENT_UTILITY_APPLICATION_CONFIG_H_INCLUDED | ... | ... |
etrade_card_client/ETradeClient/utility/openssl_aes_cbc.cpp
... | ... | @@ -18,11 +18,7 @@ namespace |
18 | 18 | const int kBlockSize = 16; |
19 | 19 | const int kKeyLength = 16;// 128Bit |
20 | 20 | const std::array<unsigned char, kKeyLength> kUserKey{ { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'i' } }; |
21 | - const std::array<unsigned char, kKeyLength> kDCCK{ { '4', '3', '4', '3', '4', 'b', 'f', 'f', '4', '3', '4', '3', '4', 'b', 'f', 'f' } }; | |
22 | - const std::array<unsigned char, kKeyLength> kDACK{ { '4', '1', '4', '3', '4', 'b', 'f', 'f', '4', '1', '4', '3', '4', 'b', 'f', 'f' } }; | |
23 | - const std::array<unsigned char, kKeyLength> kDEAK{ { '4', '5', '4', '1', '4', 'b', 'f', 'f', '4', '5', '4', '1', '4', 'b', 'f', 'f' } }; | |
24 | - const std::array<unsigned char, kKeyLength> kDAMK{ { '4', '1', '4', 'd', '4', 'b', '3', '1', '4', '1', '4', 'd', '4', 'b', '3', '1' } }; | |
25 | - | |
21 | + | |
26 | 22 | class AesCbcInterface |
27 | 23 | { |
28 | 24 | typedef struct AesKeySt |
... | ... | @@ -43,15 +39,12 @@ namespace |
43 | 39 | size_t length, const AES_KEY *key, unsigned char *ivec, const int enc); |
44 | 40 | |
45 | 41 | public: |
46 | - AesCbcInterface(const std::array<unsigned char, kKeyLength>& user_key, const std::array<unsigned char, kKeyLength>& dcck, | |
47 | - const std::array<unsigned char, kKeyLength>& dack, const std::array<unsigned char, kKeyLength>& deak, | |
48 | - const std::array<unsigned char, kKeyLength>& damk) | |
49 | - : m_user_key(user_key), m_dcck_key(dcck), m_dack_key(dack), m_deak_key(deak), m_damk_key(damk) | |
42 | + AesCbcInterface(const std::array<unsigned char, kKeyLength>& user_key) : m_user_key(user_key) | |
50 | 43 | { |
51 | 44 | Init(); |
52 | 45 | } |
53 | 46 | |
54 | - const std::string Encrypt(const std::string& plaintext, int iKeyIndex = 0) const | |
47 | + const std::string Encrypt(const std::string& plaintext) const | |
55 | 48 | { |
56 | 49 | unsigned char c_plaintext[kBlockSize]; |
57 | 50 | unsigned char c_ciphertext[kBlockSize]; |
... | ... | @@ -64,35 +57,8 @@ namespace |
64 | 57 | |
65 | 58 | unsigned int kKeyBits = m_user_key.size() * 8; |
66 | 59 | AES_KEY aes_key; |
67 | - switch (iKeyIndex) | |
68 | - { | |
69 | - case 0: | |
70 | - { | |
71 | - m_fn_aes_set_encrypt_key(m_user_key.data(), kKeyBits, &aes_key); | |
72 | - break; | |
73 | - } | |
74 | - case 1: | |
75 | - { | |
76 | - m_fn_aes_set_encrypt_key(m_dcck_key.data(), kKeyBits, &aes_key); | |
77 | - break; | |
78 | - } | |
79 | - case 2: | |
80 | - { | |
81 | - m_fn_aes_set_encrypt_key(m_dack_key.data(), kKeyBits, &aes_key); | |
82 | - break; | |
83 | - } | |
84 | - case 3: | |
85 | - { | |
86 | - m_fn_aes_set_encrypt_key(m_deak_key.data(), kKeyBits, &aes_key); | |
87 | - break; | |
88 | - } | |
89 | - case 4: | |
90 | - { | |
91 | - m_fn_aes_set_encrypt_key(m_damk_key.data(), kKeyBits, &aes_key); | |
92 | - break; | |
93 | - } | |
94 | - } | |
95 | - | |
60 | + m_fn_aes_set_encrypt_key(m_user_key.data(), kKeyBits, &aes_key); | |
61 | + | |
96 | 62 | std::string ciphertext; |
97 | 63 | ciphertext.append((char*)iv, kBlockSize);// 保存iv数据 |
98 | 64 | |
... | ... | @@ -129,7 +95,7 @@ namespace |
129 | 95 | return ciphertext; |
130 | 96 | } |
131 | 97 | |
132 | - const std::string Decrypt(const std::string& ciphertext, int iKeyIndex = 0) const | |
98 | + const std::string Decrypt(const std::string& ciphertext) const | |
133 | 99 | { |
134 | 100 | unsigned char c_plaintext[kBlockSize]; |
135 | 101 | unsigned char c_ciphertext[kBlockSize]; |
... | ... | @@ -137,34 +103,7 @@ namespace |
137 | 103 | |
138 | 104 | const int kKeyBits = m_user_key.size() * 8; |
139 | 105 | AES_KEY aes_key; |
140 | - switch (iKeyIndex) | |
141 | - { | |
142 | - case 0: | |
143 | - { | |
144 | - m_fn_aes_set_decrypt_key(m_user_key.data(), kKeyBits, &aes_key); | |
145 | - break; | |
146 | - } | |
147 | - case 1: | |
148 | - { | |
149 | - m_fn_aes_set_decrypt_key(m_dcck_key.data(), kKeyBits, &aes_key); | |
150 | - break; | |
151 | - } | |
152 | - case 2: | |
153 | - { | |
154 | - m_fn_aes_set_decrypt_key(m_dack_key.data(), kKeyBits, &aes_key); | |
155 | - break; | |
156 | - } | |
157 | - case 3: | |
158 | - { | |
159 | - m_fn_aes_set_decrypt_key(m_deak_key.data(), kKeyBits, &aes_key); | |
160 | - break; | |
161 | - } | |
162 | - case 4: | |
163 | - { | |
164 | - m_fn_aes_set_decrypt_key(m_damk_key.data(), kKeyBits, &aes_key); | |
165 | - break; | |
166 | - } | |
167 | - } | |
106 | + m_fn_aes_set_decrypt_key(m_user_key.data(), kKeyBits, &aes_key); | |
168 | 107 | |
169 | 108 | std::string plaintext; |
170 | 109 | |
... | ... | @@ -217,10 +156,6 @@ namespace |
217 | 156 | |
218 | 157 | private: |
219 | 158 | const std::array<unsigned char, kKeyLength> m_user_key; |
220 | - const std::array<unsigned char, kKeyLength> m_dcck_key; | |
221 | - const std::array<unsigned char, kKeyLength> m_dack_key; | |
222 | - const std::array<unsigned char, kKeyLength> m_deak_key; | |
223 | - const std::array<unsigned char, kKeyLength> m_damk_key; | |
224 | 159 | |
225 | 160 | HINSTANCE m_dll_handle; |
226 | 161 | AesSetEncryptKey m_fn_aes_set_encrypt_key; |
... | ... | @@ -230,21 +165,21 @@ namespace |
230 | 165 | |
231 | 166 | const AesCbcInterface& GetAesCbcInterface() |
232 | 167 | { |
233 | - static AesCbcInterface aes_cbc_interface(kUserKey, kDCCK, kDACK, kDEAK, kDAMK); // 出错会抛出异常 | |
168 | + static AesCbcInterface aes_cbc_interface(kUserKey); // 出错会抛出异常 | |
234 | 169 | return aes_cbc_interface; |
235 | 170 | } |
236 | 171 | } |
237 | 172 | |
238 | 173 | namespace AES_CBC |
239 | 174 | { |
240 | - std::string Encrypt(const std::string& plaintext, int iKeyIndex) | |
175 | + std::string Encrypt(const std::string& plaintext) | |
241 | 176 | { |
242 | - return GetAesCbcInterface().Encrypt(plaintext, iKeyIndex); | |
177 | + return GetAesCbcInterface().Encrypt(plaintext); | |
243 | 178 | } |
244 | 179 | |
245 | - std::string Decrypt(const std::string& ciphertext, int iKeyIndex) | |
180 | + std::string Decrypt(const std::string& ciphertext) | |
246 | 181 | { |
247 | - return GetAesCbcInterface().Decrypt(ciphertext, iKeyIndex); | |
182 | + return GetAesCbcInterface().Decrypt(ciphertext); | |
248 | 183 | } |
249 | 184 | |
250 | 185 | void EncryptToFile(const std::string& plaintext, const std::string& ciphertext_file_name) | ... | ... |
etrade_card_client/ETradeClient/utility/openssl_aes_cbc.h
... | ... | @@ -8,10 +8,9 @@ |
8 | 8 | exception message to std::wstring in Unicode encoding.*/ |
9 | 9 | namespace AES_CBC |
10 | 10 | { |
11 | - //iKeyIndex:0为默认加密配置文件秘钥,1为dcck秘钥,2为dack秘钥,3为deak秘钥,4为damk秘钥 | |
12 | - std::string Encrypt(const std::string& plaintext, int iKeyIndex = 0); | |
11 | + std::string Encrypt(const std::string& plaintext); | |
13 | 12 | |
14 | - std::string Decrypt(const std::string& ciphertext, int iKeyIndex = 0); | |
13 | + std::string Decrypt(const std::string& ciphertext); | |
15 | 14 | |
16 | 15 | void EncryptToFile(const std::string& plaintext, const std::string& ciphertext_file_name); |
17 | 16 | ... | ... |
etrade_card_client/ETradeClient/utility/url_config.cpp
... | ... | @@ -61,7 +61,6 @@ URLConfig::URLConfig() |
61 | 61 | m_user_msg_count_path = ptree.get<std::string>("user_msg_count_path"); |
62 | 62 | m_user_msg_path = ptree.get<std::string>("user_msg_path"); |
63 | 63 | m_modify_pwd_path = ptree.get<std::string>("modify_pwd_path"); |
64 | - m_server_time_path = ptree.get<std::string>("server_time_path"); | |
65 | 64 | } |
66 | 65 | catch (...) // Catch the exception in order for logging. |
67 | 66 | { |
... | ... | @@ -92,7 +91,6 @@ void URLConfig::ModifyCfg(bool is_https, uint16_t port) |
92 | 91 | root.put("user_msg_count_path", m_user_msg_count_path); |
93 | 92 | root.put("user_msg_path", m_user_msg_path); |
94 | 93 | root.put("modify_pwd_path", m_modify_pwd_path); |
95 | - root.put("server_time_path", m_server_time_path); | |
96 | 94 | PT::write_json(ss, root, true); |
97 | 95 | } |
98 | 96 | catch (...) // Catch the exception in order for logging. |
... | ... | @@ -168,8 +166,4 @@ std::string URLConfig::UserMsgPath() const |
168 | 166 | std::string URLConfig::PwdModificationPath() const |
169 | 167 | { |
170 | 168 | return m_modify_pwd_path; |
171 | -} | |
172 | -std::string URLConfig::ServerTimePath() const | |
173 | -{ | |
174 | - return m_server_time_path; | |
175 | 169 | } |
176 | 170 | \ No newline at end of file | ... | ... |
etrade_card_client/ETradeClient/utility/url_config.h
... | ... | @@ -29,7 +29,6 @@ public: |
29 | 29 | std::string UserMsgCountPath() const; |
30 | 30 | std::string UserMsgPath() const; |
31 | 31 | std::string PwdModificationPath() const; |
32 | - std::string ServerTimePath() const; | |
33 | 32 | private: |
34 | 33 | URLConfig(); |
35 | 34 | URLConfig(const URLConfig&); |
... | ... | @@ -46,6 +45,5 @@ private: |
46 | 45 | std::string m_user_msg_count_path; |
47 | 46 | std::string m_user_msg_path; |
48 | 47 | std::string m_modify_pwd_path; |
49 | - std::string m_server_time_path; | |
50 | 48 | }; |
51 | 49 | #endif // ETRADECLIENT_UTILITY_URL_CONFIG_H_INCLUDED | ... | ... |
etrade_card_client/ETradeClient/utility/win_http.cpp
... | ... | @@ -91,7 +91,7 @@ WinHttp::Request WinHttp::OpenRequest(const Method& method, const std::string& r |
91 | 91 | break; |
92 | 92 | } |
93 | 93 | // Create an HTTP request handle. |
94 | - HINTERNET handle = WinHttpOpenRequest(m_connect, method_name.c_str(), str_2_wstr(res_path/*res_path_test*/).c_str(), | |
94 | + HINTERNET handle = WinHttpOpenRequest(m_connect, method_name.c_str(), str_2_wstr(res_path).c_str(), | |
95 | 95 | NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, m_is_https ? WINHTTP_FLAG_SECURE : 0); |
96 | 96 | if (!handle) |
97 | 97 | { | ... | ... |
etrade_card_client/ETradeClient/utility/win_msg_define.h
... | ... | @@ -23,9 +23,7 @@ |
23 | 23 | #define WM_CEF_MSG_VIEW_CLOSE_BROWSER (WM_USER + 117) |
24 | 24 | #define WM_CRASH_CLOSE (WM_USER + 118) |
25 | 25 | |
26 | -#define WM_TIME_TICK (WM_USER + 119) | |
27 | - | |
28 | -#define WM_UPDATE_USER_MSG_COUNT (WM_USER + 300) | |
26 | +#define WM_UPDATE_USER_MSG_COUNT (WM_USER + 200) | |
29 | 27 | |
30 | 28 | |
31 | 29 | ... | ... |
etrade_card_client/resource.h
... | ... | @@ -25,10 +25,6 @@ |
25 | 25 | #define IDC_EDIT_MSG_COUNT_QUERY_INTERVAL 1013 |
26 | 26 | #define IDC_EDIT_PIN_PAD_LEN 1014 |
27 | 27 | #define IDC_EDIT_PIN_PAD_TIMEOUT 1015 |
28 | -#define IDC_STATIC_IDREADER 1016 | |
29 | -#define IDC_RADIO_HUASHIDIANZI 1017 | |
30 | -#define IDC_RADIO2 1018 | |
31 | -#define IDC_RADIO_XINZHONGXIN 1018 | |
32 | 28 | #define ID_EXIT 32782 |
33 | 29 | #define ID_MODIFY_PASSWORD 32801 |
34 | 30 | #define ID_MODIFY_CONFIG 32807 |
... | ... | @@ -59,17 +55,16 @@ |
59 | 55 | #define ID_FEE_PAYMENT 50160 |
60 | 56 | #define ID_SETTLE_ACCOUNTS_APPLY 50170 |
61 | 57 | #define ID_CUSTOMER_QUERY 50180 |
62 | -#define ID_CUS_MANAGE 50181 | |
63 | 58 | #define ID_OPER_LOG_QUERY 50190 |
64 | -#define ID_INDICATOR_TIME 59142 | |
59 | +#define ID_CUS_MANAGE 50181 | |
65 | 60 | |
66 | 61 | // Next default values for new objects |
67 | 62 | // |
68 | 63 | #ifdef APSTUDIO_INVOKED |
69 | 64 | #ifndef APSTUDIO_READONLY_SYMBOLS |
70 | -#define _APS_NEXT_RESOURCE_VALUE 326 | |
65 | +#define _APS_NEXT_RESOURCE_VALUE 325 | |
71 | 66 | #define _APS_NEXT_COMMAND_VALUE 32829 |
72 | -#define _APS_NEXT_CONTROL_VALUE 1018 | |
67 | +#define _APS_NEXT_CONTROL_VALUE 1014 | |
73 | 68 | #define _APS_NEXT_SYMED_VALUE 311 |
74 | 69 | #endif |
75 | 70 | #endif | ... | ... |