make_handshake() renamed to make_message() and made more general

This commit is contained in:
Simon Rozman 2016-08-13 18:42:52 +02:00
parent 6d54d45512
commit 9f92a73aa1
2 changed files with 17 additions and 15 deletions

View File

@ -279,33 +279,35 @@ namespace eap
eap::sanitizing_blob make_finished() const; eap::sanitizing_blob make_finished() const;
/// ///
/// Makes a TLS handshake /// Makes a TLS message
/// ///
/// \sa [The Transport Layer Security (TLS) Protocol Version 1.2 (Chapter A.1. Record Layer)](https://tools.ietf.org/html/rfc5246#appendix-A.1) /// \sa [The Transport Layer Security (TLS) Protocol Version 1.2 (Chapter A.1. Record Layer)](https://tools.ietf.org/html/rfc5246#appendix-A.1)
/// ///
/// \param[in] msg Handshake data contents /// \param[in] type Message type
/// \param[in] msg Message data contents
/// ///
/// \returns TLS handshake message /// \returns TLS message message
/// ///
static eap::sanitizing_blob make_handshake(_In_ const sanitizing_blob &msg); static eap::sanitizing_blob make_message(_In_ tls_message_type_t type, _In_ const sanitizing_blob &msg);
/// ///
/// Makes a TLS handshake /// Makes a TLS message
/// ///
/// \param[in] msg Handshake data contents /// \param[in] type Message type
/// \param[in] msg Message data contents
/// \param[in] encrypt Should the message be encrypted? /// \param[in] encrypt Should the message be encrypted?
/// ///
/// \returns TLS handshake message /// \returns TLS message message
/// ///
inline eap::sanitizing_blob make_handshake(_In_ const sanitizing_blob &msg, _In_ bool encrypted) inline eap::sanitizing_blob make_message(_In_ tls_message_type_t type, _In_ const sanitizing_blob &msg, _In_ bool encrypted)
{ {
if (encrypted) { if (encrypted) {
// Make unencrypted handshake, encrypt it, then make a new handshake message. // Make unencrypted handshake, encrypt it, then make a new handshake message.
sanitizing_blob msg_enc(std::move(make_handshake(msg))); sanitizing_blob msg_enc(make_message(type, msg));
encrypt_message(msg_enc); encrypt_message(msg_enc);
return make_handshake(msg_enc); return make_message(type, msg_enc);
} else } else
return make_handshake(msg); return make_message(type, msg);
} }
/// ///

View File

@ -373,7 +373,7 @@ void eap::method_tls::process_request_packet(
m_packet_res.m_id = m_packet_req.m_id; m_packet_res.m_id = m_packet_req.m_id;
m_packet_res.m_flags = 0; m_packet_res.m_flags = 0;
sanitizing_blob hello(make_client_hello()); sanitizing_blob hello(make_client_hello());
sanitizing_blob handshake(make_handshake(hello, m_cipher_spec)); sanitizing_blob handshake(make_message(tls_message_type_handshake, hello, m_cipher_spec));
m_packet_res.m_data.assign(handshake.begin(), handshake.end()); m_packet_res.m_data.assign(handshake.begin(), handshake.end());
CryptHashData(m_hash_handshake_msgs_md5 , hello.data(), (DWORD)hello.size(), 0); CryptHashData(m_hash_handshake_msgs_md5 , hello.data(), (DWORD)hello.size(), 0);
CryptHashData(m_hash_handshake_msgs_sha1, hello.data(), (DWORD)hello.size(), 0); CryptHashData(m_hash_handshake_msgs_sha1, hello.data(), (DWORD)hello.size(), 0);
@ -416,7 +416,7 @@ void eap::method_tls::process_request_packet(
if (m_send_client_cert) { if (m_send_client_cert) {
// Client certificate requested. // Client certificate requested.
sanitizing_blob client_cert(make_client_cert()); sanitizing_blob client_cert(make_client_cert());
sanitizing_blob handshake(make_handshake(client_cert, m_cipher_spec)); sanitizing_blob handshake(make_message(tls_message_type_handshake, client_cert, m_cipher_spec));
m_packet_res.m_data.insert(m_packet_res.m_data.end(), handshake.begin(), handshake.end()); m_packet_res.m_data.insert(m_packet_res.m_data.end(), handshake.begin(), handshake.end());
CryptHashData(m_hash_handshake_msgs_md5 , client_cert.data(), (DWORD)client_cert.size(), 0); CryptHashData(m_hash_handshake_msgs_md5 , client_cert.data(), (DWORD)client_cert.size(), 0);
CryptHashData(m_hash_handshake_msgs_sha1, client_cert.data(), (DWORD)client_cert.size(), 0); CryptHashData(m_hash_handshake_msgs_sha1, client_cert.data(), (DWORD)client_cert.size(), 0);
@ -434,7 +434,7 @@ void eap::method_tls::process_request_packet(
// Create client key exchange message, and append to packet. // Create client key exchange message, and append to packet.
sanitizing_blob client_key_exchange(make_client_key_exchange(pms)); sanitizing_blob client_key_exchange(make_client_key_exchange(pms));
sanitizing_blob handshake(make_handshake(client_key_exchange, m_cipher_spec)); sanitizing_blob handshake(make_message(tls_message_type_handshake, client_key_exchange, m_cipher_spec));
m_packet_res.m_data.insert(m_packet_res.m_data.end(), handshake.begin(), handshake.end()); m_packet_res.m_data.insert(m_packet_res.m_data.end(), handshake.begin(), handshake.end());
CryptHashData(m_hash_handshake_msgs_md5 , client_key_exchange.data(), (DWORD)client_key_exchange.size(), 0); CryptHashData(m_hash_handshake_msgs_md5 , client_key_exchange.data(), (DWORD)client_key_exchange.size(), 0);
CryptHashData(m_hash_handshake_msgs_sha1, client_key_exchange.data(), (DWORD)client_key_exchange.size(), 0); CryptHashData(m_hash_handshake_msgs_sha1, client_key_exchange.data(), (DWORD)client_key_exchange.size(), 0);
@ -458,7 +458,7 @@ void eap::method_tls::process_request_packet(
// Create finished message, and append to packet. // Create finished message, and append to packet.
sanitizing_blob finished(make_finished()); sanitizing_blob finished(make_finished());
sanitizing_blob handshake(make_handshake(finished, m_cipher_spec)); sanitizing_blob handshake(make_message(tls_message_type_handshake, finished, m_cipher_spec));
m_packet_res.m_data.insert(m_packet_res.m_data.end(), handshake.begin(), handshake.end()); m_packet_res.m_data.insert(m_packet_res.m_data.end(), handshake.begin(), handshake.end());
CryptHashData(m_hash_handshake_msgs_md5 , finished.data(), (DWORD)finished.size(), 0); CryptHashData(m_hash_handshake_msgs_md5 , finished.data(), (DWORD)finished.size(), 0);
CryptHashData(m_hash_handshake_msgs_sha1, finished.data(), (DWORD)finished.size(), 0); CryptHashData(m_hash_handshake_msgs_sha1, finished.data(), (DWORD)finished.size(), 0);