📄 xtunnelsprotocol.h
字号:
/* File: XTunnelsProtocol.h Contains: X-Tunnels protocol definitions shared with client Copyright: (c) 2003 by Xten Networks, Inc., all rights reserved.*/#ifndef XTUNNELSPROTOCOL_H__9730C05E_67C3_441A_9D8B_AE1B24E80407_#define XTUNNELSPROTOCOL_H__9730C05E_67C3_441A_9D8B_AE1B24E80407_ 1#include <sys/types.h>#include "uici.h"#include "uuid.h"// endian has been switched from little to big// let's be flexible about it#include "XTunnelsByteOrder.h"#define XTUNNELS_PROTOCOL_BIG_ENDIAN 1#if XTUNNELS_PROTOCOL_BIG_ENDIAN#define HOST2XT32 XTunnelsSwapInt32HostToBig#define XT2HOST32 XTunnelsSwapInt32BigToHost#define HOST2XT16 XTunnelsSwapInt16HostToBig#define XT2HOST16 XTunnelsSwapInt16BigToHost#define BIG2XT32(x) x#define XT2BIG32(x) x#define BIG2XT16(x) x#define XT2BIG16(x) x#else#define HOST2XT32 XTunnelsSwapInt32HostToLittle#define XT2HOST32 XTunnelsSwapInt32LittleToHost#define HOST2XT16 XTunnelsSwapInt16HostToLittle#define XT2HOST16 XTunnelsSwapInt16LittleToHost#define BIG2XT32 XTunnelsSwapInt32#define XT2BIG32 XTunnelsSwapInt32#define BIG2XT16 XTunnelsSwapInt16#define XT2BIG16 XTunnelsSwapInt16#endif // XTUNNELS_PROTOCOL_BIG_ENDIANnamespace XTunnels {extern "C" {// client to server messaging - uses a dual direction challenge mechanism//// client is EWaitingVersion//// client --> CXscMarshal_XTunnels_Version --> server// client -->CXscMarshal_XTunnels_ClientToServer_Hello --> server// client <-- CXscMarshal_XTunnels_Version <-- server//// client is EWaitingChallenge//// client <-- CXscMarshal_XTunnels_ServerToClient_Challenge <-- server//// client is EWaitingChallengeReply//// client --> CXscMarshal_XTunnels_ChallengeReply --> server// client <-- CXscMarshal_XTunnels_ChallengeReply <-- server//// client is EWaitingReady//// client --> CXscMarshal_XTunnels_ClientToServer_Ready --> server// client <-- CXscMarshal_XTunnels_ServerToClient_Ready <-- server//// client is EReadyenum { // this needs changing for every release build ECurrentServerVersion = 1090, // these change when client needs to differentiate between them ECurrentProtocolMajorVersion = 1, ECurrentProtocolMinorVersion = 0, // the port which client expects server to be listening on kDefaultListenPort = 13838, // the port which admin stuff expects server to be listening on kDefaultControlPort = 13839, // the maximum number of clients we allow // allocate ports from 5000-45000 / (1 + 10 * 2) possible per connection = 1904.762 EMaximumClients = 1000, // the time client and server have to say something before child gets a SIGALRM#if DEBUG EChildDisconnectTimeOut = 600, // this is hardcoded and may not be changed; expect ping every 45 sec from client#else EChildDisconnectTimeOut = 60, // this is hardcoded and may not be changed; expect ping every 45 sec from client#endif DEBUG EChildDeathwatchTimeOut = 300, // session invalid after this and child quits -- client can negotiate this lower EUseDefaultDeathwatchTimeOut = 0, // client sends to not renegotiate deathwatch timeout EChildPingClientTimeOut = 30, // send a ping packet after this long without sending client anything EChildSaveTimeOut = 600, // 3600 * 24, // how often to update database with traffic // for updating alarm() timeout in SetAlarm() EReceivedPacket = 1, ESentPacket = 2, EOnDeathwatch = 3, // for piping back restore session validation from parent kStartNewSession = 1, // session ID follows kFillOutPortList = 2, // long count followed by count { long port, long socket } pairs follows // the maximum data size and total size we'll allow any packets to contain EMaxDBPasswordLength = 32, EMaxDBUsernameLength = 32, EMaxDBHostLength = 128, EMaxSmallBufferSize = 1024, // for names, passwords, encryption keys, etc. EMaxMediumBufferSize = 4096, // for status strings, DB queries, etc. EMaxLargeBufferSize = 32 * 1024, // for status strings, DB queries, etc. EMaxPacketDataSize = 96 * 1024, EMaxForwardedDataSize = 65 * 1024, EMaxPacketSize = EMaxPacketDataSize + 20, // sizeof(TXTunnelsPacketHeaderBasic) + sizeof(TXTunnelsPacketHeaderEncrypt) + sizeof(unsigned long), // for child and pipe tracking of active ports when on deathwatch EMaxActivePortCount = 101, // 50 active lines + TCP ought to be enough for anybody // high bit of packet command indicates encryption kIsEncryptedPacket = 0x80000000, // database definitions // table of server authentication rules ERuleAcceptConnection = 1, ERuleAcceptAnonymousConnection = 2, ERuleDenyConnection = 3, ERuleOnlyTransmitTo = 4, // protocol messages // this precedes all parameter data blocks and is part of encrypted data EPacketMagicNumber = 0xDA1F7AD1, // basic protocol messages EMessagePing = 1, EMessageVersion = 2, // common messages for client/server EMessageChallengeReply = 100, EMessageDisconnect = 101, kDisconnectReasonAuthenticationFailed = 100, kDisconnectReasonTooBusy = 101, kDisconnectReasonWrongVersion = 102, kDisconnectReasonNormal = 200, kDisconnectReasonTimeout = 201, kDisconnectReasonMustClose = 202, // high bit of disconnect reason indicates delay before retry EDisconnectDelayFlag = 0x80000000, // client to server specific messages EMessageClientHello = 200, ELoginAnonymous = 0, // -- m_cUserName is ignored ELoginNamePassword = 1, // -- m_cUserName is the user name for the login ELoginSessionID = 2, // -- m_cUserName is the public part of the session ID EAlgorithm_None = 0, // anonymous only -- must reply with a challenge reply of NULL blob pointer and 0 bytes length blob size EAlgorithm_MD5 = 1, // --- m_pChallengeBlob is a unqiue ID which opposite side must pass into an MD5 algorithm as // "uniqueID:password" and reply with the result // must reply with blob of string of MD5 result, without final NUL byte, blob size is the string length // packet size is 16 bytes EAlgorithm_Triple_DES = 2, // --- m_pChallengeBlob is an encoded buffer which uses an MD5 string generated from the password as the encyrption key // must reply with decoded buffer as passed into triple DES // packet size is 24 EAlgorithm_AES_128_Bits = 3, // = AES 128 bits - same as tripleDES // packet size seems to be 16 for all AES EAlgorithm_AES_192_Bits = 4, // = AES 192 bits - same as tripleDES EAlgorithm_AES_256_Bits = 5, // = AES 256 bits - same as tripleDES EAlgorithm_SHA1 = 6, // -- m_pChallengeBlob is a unqiue ID which opposite side must pass into an SHA1 algorithm // as "uniqueID:password" and reply with the result // must reply with blob of string of SHA1 result, without final NUL byte, // blob size is the string length // HMAC is always 20 bytes long EMessageClientReady = 201, EMessageClientRequestSinglePort = 202, EMessageClientRequestEvenBasedPortPair = 203, // NOTE: will only close the port base port, all other ports are part of the port base must close EMessageClientRequestClosePort = 204, // CXscMarshal_XTunnels_ClientToServer_RequestSendPacket is allowed to be sent to the server redirect UDP port // but only after CXscMarshal_XTunnels_ClientToServer_RequestBindRedirectPortUDPToIP has been received EMessageClientRequestSendPacket = 205, // CXscMarshal_XTunnels_ClientToServer_RequestTestUDPRedirectPortCheck is allowed to be sent to the server redirect UDP port // but only before CXscMarshal_XTunnels_ClientToServer_RequestBindRedirectPortUDPToIP has been received // // This server must reply to this command CXscMarshal_XTunnels_ServerToClient_ReplyTestUDPRedirectPortCheck EMessageClientRequestTestUDPRedirectPortCheck = 206, // This message is received over the TCP channel. Once received, the server will reject any packets // coming into the UDP redirect port that do not match m_dwOnlyAllowFromIPAddress and m_wOnlyAllowFromPort EMessageClientRequestBindRedirectPortUDPToIP = 207, // This message is received over the TCP channel. The server sends // CXscMarshal_XTunnels_ServerToClient_ReplyBindTestUDPRedirectPortReply over the UDP redirect port in responce // to this message. EMessageClientRequestBindTestUDPRedirectPortReply = 208, // The server must now forward all CXscMarshal_XTunnels_ServerToClient_NotifyPacketArrived over the UDP redirect port EMessageClientRequestBindUDPRedirectPortPacketForward = 209, // This message is used to generate a secure conversation session key. Encryption must be enabled to // send this command. Receiving party does not have to check for encryption first, as only a badly written // client would ever send this unencrypted. // // Conversation key can be requested at any time, only if server protocol version is 1.0 or greater. // protocol major: 1 // protocol minor: 0 EMessageClientRequestXCipherSecureConversationKey = 210, // server to client specific messages EMessageServerChallenge = 300, EMessageServerReady = 301, EMessageServerPortsAvailable = 302, EMessageServerPacketArrived = 303, // This message is sent over the TCP channel, and is in response to the CXscMarshal_XTunnels_ClientToServer_RequestTestUDPRedirectPortCheck // packet. The server must fill in the m_dwSourceIPAddress and m_wSourcePort with the source IP // address and source port to which the CXscMarshal_XTunnels_ClientToServer_RequestTestUDPRedirectPortCheck // packet was received from. EMessageServerReplyTestUDPRedirectPortCheck = 304, // This message is sent over the UDP channel in response to the CXscMarshal_XTunnels_ClientToServer_RequestBindTestUDPRedirectPortReply // message. EMessageServerReplyBindTestUDPRedirectPortReply = 305, // This message is announced *before* the CXscMarshal_XTunnels_ServerToClient_Ready *if* the client protocol version is 1.0 or greater // protocol major: 1 // protocol minor: 0 // dwSupportFlags // X-Cipher supported - 0x00000001 - if set, x-cipher is supported EMessage_ServerToClient_NotifyServerSupport = 306, ESupportXCipher = 1, // This message is used to reply to the request to generate a secure conversation session key. Encryption must be enabled to // send this command. Server does not have to check for encryption first, as only a badly written // client would have ever requested a secure conversation key when encryption was not enabled. // // Only available if client protocol version is 1.0 or greater. // protocol major: 1 // protocol minor: 0 // // m_dwErrorCode - must be zero if successful, non-zero results mean m_pSecurityKeyBlob is NULL and m_dwSecurityKeyBlobSize is zero // m_cErrorReason - a human readable reason for the failure EMessage_ServerToClient_ReplyXCipherSecureConversationKey = 307, // message to clear out cache EMessage_GlobalXCipherSaysToClearCache = 500}; // end enums#if VS_TARGET_OS_MAC#pragma options align=packed#elif VS_TARGET_OS_LINUX#pragma pack (1)#elif VS_TARGET_OS_OPENBSD#pragma pack (1)#else#error undefined target OS!#endif // VS_TARGET_OS_MAC// note that all fields going between client and server are BIG endian (controlled by define above)struct PingParam { // no additional data -- note that size of empty struct is 1 };struct TVersionParam { unsigned char m_byProtocolMajor; unsigned char m_byProtocolMinor; unsigned short m_wVersionID; };struct ChallengeReplyParam { enum { kMaxChallengeReplyBlobSize = 8 * 1024 }; // 8K should be big enough for anybody // m_dwReplyChallengeBlobSize is the blob reply to the challenge, which when valid will authenticate the user // m_cSessionEncryptionKey - is a unique ID which is becomes an encryption key by creating an MD5 string with "uniqueID:password" // if this field is blank, the remote side does not want encryption unsigned long challengereplyblobsize; char challengereplyblob[kMaxChallengeReplyBlobSize]; // note: sent packed, not structure's size! unsigned short sessionkeysize; char sessionkey[EMaxSmallBufferSize]; // note no trailing NUL };struct DisconnectParam { unsigned long reason; unsigned short messagesize; char message[EMaxSmallBufferSize]; // note no trailing NUL };struct TClientToServerHelloParam { // first part is we can send header and these up to the actual end of usernamechars unsigned long how; unsigned short useridsize; char m_szUserID[EMaxDBUsernameLength]; // note: sent packed, not our above maximum acceptable size! unsigned short userhostsize; char m_szHost[EMaxDBHostLength]; // note: sent packed, not our above maximum acceptable size! uuid_t sessionuuid; unsigned long algorithm; unsigned long desiredtimeout; // 0 for default unsigned long challengeblobsize; char challengeblob[EMaxSmallBufferSize]; /* interpretation of fields, from enum below; kLoginAnonymous = 0, // -- m_cUserName is ignored kLoginNamePassword = 1, // -- m_cUserName is the user name for the login kLoginSessionID = 2, // -- m_cUserName is the public part of the session ID kAlgorithmNone = 0, // anonymous only -- must reply with a challenge reply of NULL blob pointer and 0 bytes length blob size EAlgorithmMD5 = 1, // --- m_pChallengeBlob is a unqiue ID which opposite side must pass into an MD5 algorithm as "uniqueID:password" and reply with the result // must reply with blob of string of MD5 result, without final NUL byte, blob size is the string length kAlgorithmTripleDES = 2, // --- m_pChallengeBlob is an encoded buffer which uses an MD5 string generated from the password as the encyrption key // must reply with decoded buffer as passed into triple DES kAlgorithmAES128 = 3, // = AES 128 bits - same as tripleDES kAlgorithmAES192 = 4, // = AES 192 bits - same as tripleDES kAlgorithmAES256 = 5, // = AES 256 bits - same as tripleDES
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -