SpSecureClient.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef SPSECURECALLBACK_H
  2. #define SPSECURECALLBACK_H
  3. #pragma once
  4. //
  5. // thin wrapper over RVCComm client library, we provide security session for the terminal.
  6. //
  7. // note: use mod_tokenmgr for Token management and RSA encryption and decryption,
  8. // so this header rely on mod_tokenmgr module, more detail please refer to design doc.
  9. #include "RVCComm.h"
  10. #include "SpBase.h"
  11. #include <assert.h>
  12. #pragma comment(lib, "ws2_32.lib")
  13. struct ENTITY_CONNECT_INFO;
  14. enum RvcCommStateEnum : DWORD
  15. {
  16. CS_Stop = 0, // 停止状态
  17. CS_Connectting, // 连接中
  18. CS_Fail, // 连接失败
  19. CS_Connected, // 连接建立
  20. CS_Break, // 异常中断
  21. };
  22. class SPBASE_API SpSecureClient : public CSecureClientBase
  23. {
  24. public:
  25. SpSecureClient(CEntityBase *pEntityBase);
  26. // !!!!!!!! 此函数已降级,请使用ConnectFromCentralSetting
  27. // 手工指定通讯参数,@nOption:1、重新鉴权新建会话密钥;2、通过握手使用缓存会话密钥;3、不使用会话密钥,即非安全通道; 4、不协商,直接使用共享会话密钥
  28. bool Connect(const char *pServerAddr, int nPort, int nOption); // wait until all authentication operation has been finished
  29. // !!!!!!!! 此函数已降级,请使用ConnectFromCentralSetting
  30. // 使用实体配置项连接, 连接参数从实体配置文件中读取 [Main::Server]和[Main::Server_Backup]项
  31. bool ConnectFromConfig(int nOption);
  32. // 使用集中配置项连接
  33. bool ConnectFromCentralSetting();
  34. bool IsConnectionOK();
  35. bool IsSecureConn();
  36. void Close();
  37. string SendPackage(const CSmartPointer<IPackage>& pSendPkg);
  38. CSmartPointer<IPackage> ReceivePackage(int nWaitSecond);
  39. CSmartPointer<IPackage> CreateNewPackage(const char *pServiceCode);
  40. CSmartPointer<IPackage> CreateReplyPackage(const CSmartPointer<IPackage>& pRecvPkg);
  41. protected:
  42. virtual ~SpSecureClient(); // 不应该直接delete,而用DecRef()
  43. //获取当前实体连接到的server, -1, unlink; 0, link to server 1; 1, link to server 2
  44. int getCurrentLink();
  45. // virtual function to be override by user
  46. virtual void OnErrorMsg(DWORD dwSysCode, DWORD dwUserCode, const CSimpleStringA &pErrMsg);
  47. virtual void OnDisconnect();
  48. virtual void OnPkgAnswer(const CSmartPointer<IPackage> &pRecvPkg) =0;
  49. private:
  50. // override CSecureClientBase
  51. virtual void OnReceivePackage(CSmartPointer<IPackage> &pRecvPkg);
  52. virtual void OnClose();
  53. virtual void OnError(DWORD dwSysCode, DWORD dwUserCode, const char *pErrMsg);
  54. virtual void OnAuthPass();
  55. virtual bool OnAuthRequest(CConnAuthReq *pReq);
  56. virtual bool OnSessionKeyRet(CConnAuthRet *pRet, BYTE *pBuf, int *pBufLen);
  57. virtual bool OnGetSharedSK(char *pTerminalNo, int *pTerminalNoLen, BYTE *pBuf, int *pBufLen);
  58. ErrorCodeEnum ParseIPAddress(const char *str, CSimpleStringA &ip, int &port);
  59. DWORD GetEntityUserCode(DWORD code);
  60. bool findConnectInfo(const char *pEntityName, ENTITY_CONNECT_INFO *connectInfo);
  61. bool readConnectInfoFromCentralSetting(const char *pEntityName, ENTITY_CONNECT_INFO *connectInfo);
  62. bool readConnectInfoFromConfig(const char *pEntityName, ENTITY_CONNECT_INFO *connectInfo);
  63. bool setConnectInfo(const ENTITY_CONNECT_INFO *connectInfo);
  64. void connectClose(const char *pEntityName);
  65. //不支持双活
  66. bool Connect_Single(ENTITY_CONNECT_INFO *connectInfo, int option);
  67. //支持双活
  68. bool Connect_Dual(ENTITY_CONNECT_INFO *connectInfo, int option);
  69. void OnReConnect();
  70. protected:
  71. CEntityBase *m_pEntity;
  72. private:
  73. bool m_bClosed;
  74. friend struct OnPackageTask;
  75. friend struct OnDisconnectTask;
  76. friend struct OnErrorTask;
  77. };
  78. #endif // SPSECURECALLBACK_H