MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / buildMessage

Function buildMessage

extra/yassl/src/handshake.cpp:335–383  ·  view source on GitHub ↗

build an encrypted data or alert message for output

Source from the content-addressed store, hash-verified

333
334// build an encrypted data or alert message for output
335void buildMessage(SSL& ssl, output_buffer& output, const Message& msg)
336{
337 uint digestSz = ssl.getCrypto().get_digest().get_digestSize();
338 uint sz = RECORD_HEADER + msg.get_length() + digestSz;
339 uint pad = 0;
340 uint blockSz = ssl.getCrypto().get_cipher().get_blockSize();
341
342 if (ssl.getSecurity().get_parms().cipher_type_ == block) {
343 if (ssl.isTLSv1_1()) // IV
344 sz += blockSz;
345 sz += 1; // pad byte
346 pad = (sz - RECORD_HEADER) % blockSz;
347 pad = blockSz - pad;
348 sz += pad;
349 }
350
351 RecordLayerHeader rlHeader;
352 buildHeader(ssl, rlHeader, msg);
353 rlHeader.length_ = sz - RECORD_HEADER; // record header includes mac
354 // and pad, hanshake doesn't
355 input_buffer iv;
356 if (ssl.isTLSv1_1() && ssl.getSecurity().get_parms().cipher_type_== block){
357 iv.allocate(blockSz);
358 ssl.getCrypto().get_random().Fill(iv.get_buffer(), blockSz);
359 iv.add_size(blockSz);
360 }
361
362 uint ivSz = iv.get_size();
363 output.allocate(sz);
364 output << rlHeader << iv << msg;
365
366 opaque digest[SHA_LEN]; // max size
367 if (ssl.isTLS())
368 TLS_hmac(ssl, digest, output.get_buffer() + RECORD_HEADER + ivSz,
369 output.get_size() - RECORD_HEADER - ivSz, msg.get_type());
370 else
371 hmac(ssl, digest, output.get_buffer() + RECORD_HEADER,
372 output.get_size() - RECORD_HEADER, msg.get_type());
373 output.write(digest, digestSz);
374
375 if (ssl.getSecurity().get_parms().cipher_type_ == block)
376 for (uint i = 0; i <= pad; i++) output[AUTO] = pad; // pad byte gets
377 // pad value too
378 input_buffer cipher(rlHeader.length_);
379 ssl.useCrypto().use_cipher().encrypt(cipher.get_buffer(),
380 output.get_buffer() + RECORD_HEADER, output.get_size() - RECORD_HEADER);
381 output.set_current(RECORD_HEADER);
382 output.write(cipher.get_buffer(), cipher.get_capacity());
383}
384
385
386// build alert message

Callers 2

buildAlertFunction · 0.85
sendDataFunction · 0.85

Calls 15

buildHeaderFunction · 0.85
TLS_hmacFunction · 0.85
hmacFunction · 0.85
get_digestSizeMethod · 0.80
get_digestMethod · 0.80
get_parmsMethod · 0.80
isTLSv1_1Method · 0.80
FillMethod · 0.80
get_randomMethod · 0.80
add_sizeMethod · 0.80
get_sizeMethod · 0.80
isTLSMethod · 0.80

Tested by

no test coverage detected