123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- /////////////////////////////////////////////////////////////////////////////////
- /// Copyright (c) 2012 China Merchants Bank, all rights reserved ///
- /// Adapter Interface for PinPad. ///
- /// ///
- ////////////////////////////////////////////////////////////////////////////////
- #ifndef __PIN_PAD_CLASS_H
- #define __PIN_PAD_CLASS_H
- #pragma once
- #include "DeviceBaseClass.h"
- /** define specified device adapter interface file version*/
- /** once the change cannot compact with before one, CMBer must update this version node and reset the minor-version node*/
- #define PINPAD_INTERFACE_FILE_VERSION_MAJOR 1
- /** any change but not effect compatibility with elder one, CMBer should update this verion node*/
- #define PINPAD_INTERFACE_FILE_VERSION_MINOR 0
- #define PINPAD_INTERFACE_FILE_VERSION_STRING \
- DEVICE_ADAPTER_CLASS_STRINGFY(PINPAD_INTERFACE_FILE_VERSION_MAJOR, PINPAD_INTERFACE_FILE_VERSION_MINOR)
- #define PINPAD_ADAPTER_CLASS_ID \
- DEVICE_ADAPTER_CLASS_COMBINE(PINPAD_INTERFACE_FILE_VERSION_MAJOR)
-
- const int MAX_PIN_READ_SIZE = 256;
- const int MAX_PIN_BLOCK_SIZE = 256;
- const int MAX_MASTER_KEY_SIZE = 128;
- const int MAX_WORKING_KEY_SIZE = 128;
- const int MAX_ACCOUNT_LEN = 32;
- const int MAX_EN_DECRYPT_DATA_SIZE = 512;
- struct PinPadInitParam
- {
- DWORD dwPort;
- DWORD dwBaudRate;
- };
- struct PinReadData
- {
- DWORD dwSize;
- BYTE data[MAX_PIN_READ_SIZE];
- };
- struct MasterKeyParam
- {
- int smFlag; //0:3des,1:sm
- DWORD dwSN; //master key serial number:0,1,2,...
- BYTE key[MAX_MASTER_KEY_SIZE]; //key value
- };
- struct MasterKeyParamEx
- {
- int smFlag; //0:3des,1:sm,11: 本结构体的字段key为设备临时公钥加密的主密钥密文(国密)
- DWORD dwSN; //master key serial number:0,1,2,...
- BYTE key[MAX_EN_DECRYPT_DATA_SIZE]; //(plain or encrypted)key value
- };
- struct WorkKeyParam
- {
- int smFlag; //0:3des,1:sm
- DWORD dwMasterSN; //master key serial number:0,1,2,...
- DWORD dwWorkingSN; //working key serial number:0,1,2,...
- BYTE key[MAX_WORKING_KEY_SIZE]; //key value
- };
- struct PinBlock
- {
- DWORD dwSize;
- BYTE data[MAX_PIN_BLOCK_SIZE];
- };
- struct AccountInfo
- {
- DWORD dwAccLen;
- BYTE account[MAX_ACCOUNT_LEN];
- };
- struct EnDecryptInfo
- {
- DWORD dwSize;
- BYTE data[MAX_EN_DECRYPT_DATA_SIZE]; //en/decrypt data
- };
- //parameter type to set device
- enum SetParamTypeEnum
- {
- EPP_PT_SET_ENCRYPT_METHOD, //data encrypt/decrypt method
- EPP_PT_SET_MAC_ALGORITH, //mac algorithm
- EPP_PT_SET_PIN_ALGORITH, //pin encrypt/decrypt algorithm
- EPP_PT_SET_ECB_CBC_MODE, //encrypt/decrypt mode
- };
- //parameter value to set device
- enum SetParamValueEnum
- {
- ////values for EPP_PT_SET_ENCRYPT_METHOD
- EPP_ALGO_METHOD_DES,
- EPP_ALGO_METHOD_3DES,
- EPP_ALGO_METHOD_DES_TMK,
- EPP_ALGO_METHOD_3DES_TMK,
- //values for EPP_PT_SET_MAC_ALGORITH
- EPP_MAC_ALGO_ASNIX99,
- EPP_MAC_ALGO_PBOC,
- EPP_MAC_ALGO_UNIONPAY,
- //values for EPP_PT_SET_PIN_ALGORITH
- EPP_PIN_ALGO_ISO9564_1_ANSI,//ANSIx9.8
- EPP_PIN_ALGO_IBM3624,
-
- //values for EPP_PT_SET_ECB_CBC_MODE
- //设置加密方式,这里仅为了兼容,保留,设置ECB/CBC请使用 EPP_ALGO_MODE_ECB, EPP_ALGO_MODE_CBC,
- EPP_ALGO_MODE_DEC_ECB,
- EPP_ALGO_MODE_DEC_CBC,
- EPP_ALGO_MODE_3DEC_ECB,
- EPP_ALGO_MODE_3DEC_CBC,
- EPP_ALGO_METHOD_SM4,
- EPP_PIN_ALGO_SM4,
- EPP_ALGO_MODE_ECB,
- EPP_ALGO_MODE_CBC,
- };
- class PinPadClass : public DeviceBaseClass
- {
- public:
- //
- // Open device.
- // Arguments:
- // - dwPort[in] com port number
- // - dwBaudRate[in] Baud rate
- //
- virtual ErrorCodeEnum DevOpen(DWORD dwPort,DWORD dwBaudRate) = 0;
- //
- // Get input key value.
- // Monitor pinpad key press,if any key pressed,set [ch] value and return Error_Succeed.
- // If none was pressed ,return Error_DevCommFailed.
- //
- // Two input mode:plain text,pin(encrypted)
- // 1.In any mode,press key "*,#,blank,cancel,clear,confirm",set ch value
- // "0x2a,0x23,0x20,0x1b,0x08,0x0d" respectively
- // 2.In plain text input mode,press key 0~9,.,00,set ch 0x30~0x39,0x2e,0x4f respectively
- // 3.In pin input mode,press any key of 0~9,set ch 0x3f,else('.','00') set ch 0x3d
- // 4."clear" means clear all the input
- //
- virtual ErrorCodeEnum KeyRead(BYTE &ch) = 0;
- //
- // Set pinpad parameter.
- //
- virtual ErrorCodeEnum SetParam(SetParamTypeEnum eType,SetParamValueEnum eValue) = 0;
- //
- // Set account number.
- // Arguments:
- // - accInfo.account:(ASCII)account value
- // ex:card no "62260755",the accInfo.account should be 0x3632323630373535
- //
- virtual ErrorCodeEnum SetAccNo(AccountInfo accInfo) = 0;
- //
- // Load master key. (in plain text)
- // [key]:byte value in string type. ex. 0x123456FF --> "123456FF"
- //
- virtual ErrorCodeEnum LoadMasterKey(MasterKeyParam masterKey) = 0;
- //
- // Load working key. (encrypted data)
- // Use the according master key to decrypt the key,then load result into pinpad
- // [key]:byte value in string type. ex. 0x123456FF --> "123456FF"
- //
- virtual ErrorCodeEnum LoadWorkingKey(WorkKeyParam wkKey) = 0;
- //
- // Active a working key as current working key.
- // Arguments:
- // - dwMkSN:master key serial number
- // - dwWkSN:working key serial number
- // - ActiveWorkingKey(主密钥序号,99)表示激活“主密钥序号”的主密钥作为当前工作密钥
- //
- virtual ErrorCodeEnum ActiveWorkingKey(DWORD dwMkSN,DWORD dwWkSN) = 0;
- //
- // Start key press(pin mode).
- // byLen:输入密码长度,键盘检测到用户输入byLen位有效!!长度时自动结束输入,计算pinblock
- //
- virtual ErrorCodeEnum StartPinInput(BYTE byLen) = 0;
- //
- // Start key press(pin mode).
- // byLen:输入密码长度,键盘检测到用户输入确认键后结束输入,计算pinblock
- //
- virtual ErrorCodeEnum StartPinInputConfirm(BYTE byLen) = 0;
-
- //
- // Start key press(plain text mode).
- //
- virtual ErrorCodeEnum StartPlainInput() = 0;
- //
- // Close pinpad input.
- //
- virtual ErrorCodeEnum StopInput() = 0;
- //
- // Get pin block.
- // At the end of pin input, to get pin text.
- //
- virtual ErrorCodeEnum GetPinBlock(PinBlock &block) = 0;
- //
- // Encrypt data.
- // Arguments:
- // - srcInfo.data:source plain text data
- // (byte value in string type. ex. 0x123456FF --> "123456FF")
- // - destInfo.data:destination encrypted data
- //
- virtual ErrorCodeEnum EncryptData(EnDecryptInfo srcInfo, EnDecryptInfo &destInfo) = 0;
- //
- // Encrypt data(MAC)
- // Arguments:
- // - srcInfo.data:source plain text data
- // (byte value in string type. ex. 0x123456FF --> "123456FF")
- // - destInfo.data:destination encrypted data
- //
- virtual ErrorCodeEnum MacEncrypt(EnDecryptInfo srcInfo, EnDecryptInfo &destInfo) = 0;
- //
- // Get the encrypt method supported.
- // return value:
- // 0x1:3des only; 0x2:sm4 only; 0x3:both 3des and sm4
- //
- virtual int GetEncryptFunc() = 0;
- //
- // Load master key.
- // [key]:byte value in string type. ex. 0x123456FF --> "123456FF"
- //
- virtual ErrorCodeEnum LoadMasterKeyEx(MasterKeyParamEx enMasterKey) {return Error_NotImpl;}
- };
- #endif // __PIN_PAD_CLASS_H
|