📄 gsecuresocket.h
字号:
/* Copyright (C) 2006, Mike Gashler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. see http://www.gnu.org/copyleft/lesser.html*/#ifndef __GEZSOCKET_H__#define __GEZSOCKET_H__#include "GSocket.h"class GSecureSocketServer : public GSocketServer{protected: GKeyPair* m_pKeyPair; GRand* m_pRand; GPointerArray* m_pPassphrases; int m_nPassphraseSize; GPointerArray* m_pClientPassphrases; GIntArray* m_nClientPassphraseSizes; GSecureSocketServer(int nMaxPacketSize, GRand* pRand, int nPort);public: // nRandomDataSize should be cryptographic random data four times the size you want your keys to be static GSecureSocketServer* HostSecureSocket(u_short nPort, int nMaxPacketSize, GRand* pRand); virtual ~GSecureSocketServer(); // Send some data bool Send(const void* pBuf, int nLen, int nConnectionNumber); // Returns the number of messages waiting to be received // Note: you should call this method regularly. If you don't, client's won't be // able to handshake with this socket. int GetMessageCount(); // Receive the next message. (You are responsible to delete the buffer this returns) unsigned char* GetNextMessage(int* pnSize, int* pnOutConnectionNumber);protected: void Handshake(); bool SendPublicKey(int nConnection); bool SendPassphrase(int nConnection, GKeyPair* pKeyPair); bool OnReceivePublicKey(const char* pXML, int nXMLSize, int nConnectionNumber); bool OnReceivePassphrase(const unsigned char* pCypher, int nCypherSize, int nConnectionNumber);};// --------------------------------------------------------------------------class GSecureSocketClient : public GSocketClient{protected: GKeyPair* m_pKeyPair; GRand* m_pRand; unsigned char* m_pPassphrase; int m_nPassphraseSize; unsigned char* m_pServerPassphrase; int m_nServerPassphraseSize; GSecureSocketClient(int nMaxPacketSize, GRand* pRand);public: // nRandomDataSize should be cryptographic random data four times the size you want your keys to be static GSecureSocketClient* ConnectToSecureSocket(const char* szAddress, u_short nPort, int nMaxPacketSize, GRand* pRand); virtual ~GSecureSocketClient(); // Send some data bool Send(const void* pBuf, int nLen); // Returns the number of messages waiting to be received int GetMessageCount(); // Receive the next message. (You are responsible to delete the buffer this returns) unsigned char* GetNextMessage(int* pnSize);protected: bool HandShake(); bool SendPublicKey(); bool SendPassphrase(GKeyPair* pKeyPair); bool OnReceivePublicKey(const char* pXML, int nXMLSize); bool OnReceivePassphrase(const unsigned char* pCypher, int nCypherSize);};#endif // __GEZSOCKET_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -