5 #ifndef _INC_cSSLMsgL_H
28 static const size_t k_nSizePref = 3;
43 : m_nMsgType((BYTE)eMsgType)
45 , m_nVersion((BYTE)eVer)
46 , m_nContLengthH(HIBYTE(wContLen))
47 , m_nContLengthL(LOBYTE(wContLen))
72 m_nMsgType = (BYTE)eMsgType;
101 WORD nContLength = get_ContLength();
102 if (nContLength < 1 || nContLength > k_Content_Size_Max)
109 return MAKEWORD(m_nContLengthL, m_nContLengthH);
113 m_nContLengthH = HIBYTE(nContLen);
114 m_nContLengthL = LOBYTE(nContLen);
115 ASSERT(isValidContLength());
121 return isValidMsgType() && isValidVersion() && isValidContLength();
126 put_MsgType(eMsgType);
128 put_ContLength(wContLength);
156 m_nTypeH = HIBYTE(eType);
157 m_nTypeL = LOBYTE(eType);
161 return MAKEWORD(m_nLengthL, m_nLengthH);
165 m_nLengthH = HIBYTE(wLen);
166 m_nLengthL = LOBYTE(wLen);
171 return (BYTE*)(
this + 1);
175 return (
const BYTE*)(
this + 1);
199 m_nHandType = (BYTE)eHandType;
216 return (
const BYTE*)(
this + 1);
221 return (BYTE*)(
this + 1);
265 #if defined(USE_ZLIB)
266 static const size_t k_SSL_COMPRESSION_ADD = 1024;
268 static const size_t k_SSL_COMPRESSION_ADD = 0;
272 static const size_t k_SSL_PADDING_ADD = 256;
275 static const size_t k_Msg_Size_Max =
sizeof(
cSSLMsgHeader) + 16 + k_MAC_Size_Max + k_SSL_PADDING_ADD + k_Content_Size_Max + k_SSL_COMPRESSION_ADD;
301 static HRESULT GRAYCALL CheckSSLClientHello(
const void* pData,
size_t nSize);
342 m_Data[
sizeof(m_Data) - 1] = 0x00;
346 return ::memcmp(m_Data, n.m_Data,
sizeof(
THIS_t));
383 HRESULT ReadHello(
const BYTE* pData,
size_t nSize);
384 size_t get_WriteHelloSize() const noexcept;
385 HRESULT WriteHello(BYTE* pData) const;
403 const BYTE* get_MsgRaw() const noexcept
406 return SUPER_t::get_DataBytes();
410 ASSERT(SUPER_t::isValidPtr());
416 ASSERT(SUPER_t::isValidPtr());
418 cMem::Zero(get_Data(),
sizeof(cSSLMsgHeader));
423 if (m_nContLength == 0)
425 return get_Msg().m_Hdr.get_MsgType();
429 get_Msg().m_Hdr.put_MsgType(eMsgType);
434 return get_Msg().m_Hdr.get_Version();
438 get_Msg().m_Hdr.put_Version(v);
441 size_t get_ContLength() const noexcept
443 return m_nContLength;
445 void put_ContLength(
size_t nContLen)
447 this->m_nContLength = (WORD)nContLen;
448 get_Msg().m_Hdr.put_ContLength((WORD)nContLen);
451 BYTE* get_Cont0()
const
455 return get_Msg().m_u.m_Iv;
463 bool UpdateReadHdr();
503 m_pContApp = get_Cont0() + nSizeIv;
508 return m_bCompleteMsg;
513 m_bCompleteMsg =
true;
523 m_bCompleteMsg =
false;
527 m_pContApp = get_Cont0();
532 void UpdateHashV3(
cHashWrap& rHasher,
const BYTE* pSecret);
533 void UpdateHmac(
cHashWrap& rHasher,
bool bEncrypt);
534 void UpdateHmacExtra(
cHashWrap& rHasher,
size_t nSizePad, BYTE nCorrect);
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define CATTR_PACKED
Definition: GrayCore.h:87
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cHashWrap.h:18
Definition: cSSLMsg.h:305
cSSLCtr(UINT i)
Definition: cSSLMsg.h:319
const BYTE * get_Ctr() const
Definition: cSSLMsg.h:333
COMPARE_t Compare(const THIS_t &n) const
Definition: cSSLMsg.h:344
void SetZeroCtr()
Definition: cSSLMsg.h:324
void SetFillCtr()
Definition: cSSLMsg.h:338
bool isZero() const
Definition: cSSLMsg.h:329
cSSLCtr()
Definition: cSSLMsg.h:315
Definition: cSSLMsg.h:226
SSL_ALERT_TYPE get_Description() const
Definition: cSSLMsg.h:238
BYTE m_Description
SSL_ALERT_TYPE. This field identifies which type of alert is being sent. 0 = Close notify,...
Definition: cSSLMsg.h:232
SSL_ALERT_LEVEL_TYPE get_Level() const
Definition: cSSLMsg.h:234
BYTE m_Level
1 = warning SSL_ALERT_LEVEL_WARNING, 2 = fatal error. SSL_ALERT_LEVEL_FATAL
Definition: cSSLMsg.h:231
Definition: cSSLMsg.h:471
const BYTE * get_Ctr() const noexcept
Definition: cSSLMsg.h:490
void ResetMsg(bool bHandshake)
Definition: cSSLMsg.h:518
BYTE * get_ContApp() const noexcept
Definition: cSSLMsg.h:495
bool isCompleteMsg() const noexcept
Definition: cSSLMsg.h:506
void put_ContAppIvSize(size_t nSizeIv)
Definition: cSSLMsg.h:500
void SetCompleteMsg() noexcept
Definition: cSSLMsg.h:510
size_t m_nIntIndex
Amount of data read/written so far in m_pHdr. ( if !m_bCompleteMsg includes sizeof(cSSLMsgHeader) els...
Definition: cSSLMsg.h:483
cSSLCtr m_Ctr
Counter added to the hash.
Definition: cSSLMsg.h:484
Definition: cSSLMsg.h:245
BYTE m_ProtocolType
CCS protocol type = 1 = SSL3_MT_CCS. Only value allowed.
Definition: cSSLMsg.h:251
Definition: cSSLMsg.h:133
Definition: cSSLMsg.h:139
BYTE m_nTypeL
TLS_EXT_TYPE.
Definition: cSSLMsg.h:145
BYTE m_nLengthH
Length.
Definition: cSSLMsg.h:146
void put_ExtLen(size_t wLen) noexcept
Definition: cSSLMsg.h:163
TLS_EXT_TYPE get_ExtType() const noexcept
Definition: cSSLMsg.h:150
BYTE m_nTypeH
TLS_EXT_TYPE.
Definition: cSSLMsg.h:144
WORD get_ExtLen() const noexcept
Definition: cSSLMsg.h:159
const BYTE * get_ExtData() const noexcept
Definition: cSSLMsg.h:173
BYTE m_nLengthL
Definition: cSSLMsg.h:147
void put_ExtType(TLS_EXT_TYPE eType) noexcept
Definition: cSSLMsg.h:154
BYTE * get_ExtData() noexcept
Definition: cSSLMsg.h:169
Definition: cSSLMsg.h:357
BYTE m_nClientVersion
Minor version byte from SSL_VERSION_TYPE. ProtocolVersion.
Definition: cSSLMsg.h:372
cArrayVal< SSL_CipherSuite_t > m_aCipherSuite
Cryptographic suite selector. a key exchange algorithm and a CipherSpec combo. (2^16-1)
Definition: cSSLMsg.h:378
cHeapBlock m_SessionId
(var len <= 32)
Definition: cSSLMsg.h:377
cHeapBlock m_Extensions
Other stuff for forward version compatibility. cSSLMsgHandExt.
Definition: cSSLMsg.h:380
BYTE m_nClientVersion3
Major version is always 3. SSL_VERSION_MAJOR_BYTE.
Definition: cSSLMsg.h:371
DWORD m_TimeUnixGmt
32 bit cTimeInt/TIMESEC_t. used as part of random below.
Definition: cSSLMsg.h:374
cArrayVal< SSL_Compress_t > m_aCompressionMethod
(2^8-1)
Definition: cSSLMsg.h:379
Definition: cSSLMsg.h:180
const BYTE * get_DataPtr() const
Definition: cSSLMsg.h:212
void put_Length(DWORD len)
Definition: cSSLMsg.h:207
DWORD get_Length() const
Definition: cSSLMsg.h:202
SSL_HAND_TYPE get_HandType() const
Definition: cSSLMsg.h:193
BYTE m_nHandType
SSL_HAND_TYPE. sub message type. e.g. SSL_HAND_ClientHello.
Definition: cSSLMsg.h:186
void put_HandType(SSL_HAND_TYPE eHandType)
Definition: cSSLMsg.h:197
BYTE * get_DataPtr()
Definition: cSSLMsg.h:218
Definition: cSSLMsg.h:255
cSSLMsgHeader m_Hdr
header. size=5
Definition: cSSLMsg.h:277
static const size_t k_Msg_Size_Max
Max possible size of *this.
Definition: cSSLMsg.h:275
Definition: cStream.h:126
TLS_EXT_TYPE
Definition: SSLTypes.h:192
SSL_MSG_TYPE
Definition: SSLTypes.h:45
@ SSL_MSG_APPLICATION_DATA
0x17 = any application defined data.
Definition: SSLTypes.h:54
@ SSL_MSG_UNK
Definition: SSLTypes.h:50
@ SSL_MSG_ALERT
0x15 = closing or some error.
Definition: SSLTypes.h:52
@ SSL_MSG_CHANGE_CIPHER_SPEC
0x14 = switch to the negotiated encryption.
Definition: SSLTypes.h:51
@ SSL_MSG_HANDSHAKE
0x16 = get this first. SSL3_RT_HANDSHAKE. negotiate the channel. SSL_HAND_TYPE
Definition: SSLTypes.h:53
UNITTEST2_PREDEF(cQuadtree)
SSL_ALERT_TYPE
Definition: SSLTypes.h:235
SSL_VERSION_TYPE
Definition: SSLTypes.h:66
@ SSL_VERSION_SUPPORT_MAX
Definition: SSLTypes.h:74
SSL_HAND_TYPE
Definition: SSLTypes.h:152
@ SSL_VERSION_MAJOR_BYTE
Definition: SSLTypes.h:63
SSL_ALERT_LEVEL_TYPE
Definition: SSLTypes.h:227
int COMPARE_t
result of compare. 0=same, 1=a>b, -1=a<b
Definition: cValT.h:17
class __DECL_IMPORT cStreamInput
Definition: cString.h:26
Definition: cSSLMsg.h:286
Definition: SSLTypes.h:270
static void SetNVal3(BYTE *p, DWORD nVal) noexcept
Definition: cMem.h:597
static void SetHtoN(void *pData, TYPE nVal) noexcept
Definition: cMem.h:584
static DWORD GetNVal3(const BYTE *p) noexcept
Definition: cMem.h:591
static void Zero(void *pData, size_t nSizeBlock) noexcept
Definition: cMem.h:100
static bool IsZeros(const void *pData, size_t nSize) noexcept
Definition: cMem.h:65
static void Fill(void *pDst, size_t nSize, BYTE bVal) noexcept
Definition: cMem.h:174
< m_nMsgType packet content/payload type specific data.
Definition: cSSLMsg.h:280
cSSLMsgChangeCipherSpec m_ChangeCipherSpec
m_nMsgType = SSL_MSG_CHANGE_CIPHER_SPEC = 0x14.
Definition: cSSLMsg.h:281
cSSLMsgHandshake m_Handshake
m_nMsgType = SSL_MSG_HANDSHAKE = 0x16 can repeat inside the message up to m_wLength.
Definition: cSSLMsg.h:283
cSSLMsgAlert m_Alert
m_nMsgType = SSL_MSG_ALERT = 0x15 = Some error occurred.
Definition: cSSLMsg.h:282