123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #ifndef SPSECURECALLBACK_H
- #define SPSECURECALLBACK_H
- #pragma once
- //
- // thin wrapper over RVCComm client library, we provide security session for the terminal.
- //
- // note: use mod_tokenmgr for Token management and RSA encryption and decryption,
- // so this header rely on mod_tokenmgr module, more detail please refer to design doc.
- #include "RVCComm.h"
- #include "SpBase.h"
- #include <assert.h>
- #pragma comment(lib, "ws2_32.lib")
- struct ENTITY_CONNECT_INFO;
- enum RvcCommStateEnum : DWORD
- {
- CS_Stop = 0, // 停止状态
- CS_Connectting, // 连接中
- CS_Fail, // 连接失败
- CS_Connected, // 连接建立
- CS_Break, // 异常中断
- };
- class SPBASE_API SpSecureClient : public CSecureClientBase
- {
- public:
- SpSecureClient(CEntityBase *pEntityBase);
- // !!!!!!!! 此函数已降级,请使用ConnectFromCentralSetting
- // 手工指定通讯参数,@nOption:1、重新鉴权新建会话密钥;2、通过握手使用缓存会话密钥;3、不使用会话密钥,即非安全通道; 4、不协商,直接使用共享会话密钥
- bool Connect(const char *pServerAddr, int nPort, int nOption); // wait until all authentication operation has been finished
- // 使用集中配置项连接
- bool ConnectFromCentralSetting();
- bool ConnectFromAddress(CSimpleStringA mainServ, CAutoArray<CSimpleStringA> backupServArr, CSimpleStringA& connectedServ);
-
- bool IsConnectionOK();
- bool IsSecureConn();
- void Close();
- string SendPackage(const CSmartPointer<IPackage>& pSendPkg);
- CSmartPointer<IPackage> ReceivePackage(int nWaitSecond);
- CSmartPointer<IPackage> CreateNewPackage(const char *pServiceCode);
- CSmartPointer<IPackage> CreateReplyPackage(const CSmartPointer<IPackage>& pRecvPkg);
- protected:
- virtual ~SpSecureClient(); // 不应该直接delete,而用DecRef()
- //获取当前实体连接到的server, -1, unlink; 0, link to server 1; 1, link to server 2
- int getCurrentLink();
- // virtual function to be override by user
- virtual void OnErrorMsg(DWORD dwSysCode, DWORD dwUserCode, const CSimpleStringA &pErrMsg);
- virtual void OnDisconnect();
- virtual void OnPkgAnswer(const CSmartPointer<IPackage> &pRecvPkg) =0;
-
-
- private:
- // override CSecureClientBase
- virtual void OnReceivePackage(CSmartPointer<IPackage> &pRecvPkg);
- virtual void OnClose();
- virtual void OnError(DWORD dwSysCode, DWORD dwUserCode, const char *pErrMsg);
- virtual void OnAuthPass();
- virtual bool OnAuthRequestSM(CConnAuthSMReq* pReq);
- virtual bool OnSessionKeyRet(CConnAuthRet *pRet, BYTE *pBuf, int *pBufLen);
- virtual bool OnSessionKeySMRet(CConnAuthSMRet* pRet, BYTE* pBuf, int* pBufLen);
- virtual bool OnGetSharedSK(char *pTerminalNo, int *pTerminalNoLen, BYTE *pBuf, int *pBufLen);
- ErrorCodeEnum ParseIPAddress(const char *str, CSimpleStringA &ip, int &port);
- DWORD GetEntityUserCode(DWORD code);
- bool findConnectInfo(const char *pEntityName, ENTITY_CONNECT_INFO *connectInfo);
- bool readConnectInfoFromCentralSetting(const char *pEntityName, ENTITY_CONNECT_INFO *connectInfo);
- bool setConnectInfo(const ENTITY_CONNECT_INFO *connectInfo);
- void connectClose(const char *pEntityName);
-
- //不支持双活
- bool Connect_Single(ENTITY_CONNECT_INFO *connectInfo, int option);
- //支持双活
- bool Connect_Dual(ENTITY_CONNECT_INFO *connectInfo, int option);
-
- bool Connect_Standby(CSimpleStringA mainServ, CAutoArray<CSimpleStringA> backupServArr, int option, CSimpleStringA &connectedServ);
- void OnReConnect();
- void DbgWithLink_DualActive(const char* formatStr, ...);
- protected:
- static void* logProducer;
- public:
- static CEntityBase* m_pEntity;
- static void SetSecureEntity(CEntityBase* t_entity) { m_pEntity = t_entity; };
- private:
- bool m_bClosed;
-
- friend struct OnPackageTask;
- friend struct OnDisconnectTask;
- friend struct OnErrorTask;
- };
- void getHttpToken(std::string& channelId, std::string& token, std::string& terminalNo, std::string& reserve1);
- #endif // SPSECURECALLBACK_H
|