mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
frame now generates a random masking key
This commit is contained in:
@@ -341,8 +341,10 @@ void frame::process_extended_header() {
|
||||
|
||||
void frame::process_payload() {
|
||||
if (get_masked()) {
|
||||
char *masking_key = &m_header[get_header_len()-4];
|
||||
|
||||
for (uint64_t i = 0; i < m_payload.size(); i++) {
|
||||
m_payload[i] = (m_payload[i] ^ m_masking_key[i%4]);
|
||||
m_payload[i] = (m_payload[i] ^ masking_key[i%4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,7 +419,21 @@ bool frame::validate_basic_header() const {
|
||||
}
|
||||
|
||||
void frame::generate_masking_key() {
|
||||
throw "masking key generation not implimented";
|
||||
//throw "masking key generation not implimented";
|
||||
|
||||
int32_t key = m_gen();
|
||||
|
||||
std::cout << "genkey: " << key << std::endl;
|
||||
|
||||
//m_masking_key[0] = reinterpret_cast<char*>(&key)[0];
|
||||
//m_masking_key[1] = reinterpret_cast<char*>(&key)[1];
|
||||
//m_masking_key[2] = reinterpret_cast<char*>(&key)[2];
|
||||
//m_masking_key[3] = reinterpret_cast<char*>(&key)[3];
|
||||
|
||||
*(reinterpret_cast<int32_t *>(&m_header[get_header_len()-4])) = key;
|
||||
|
||||
//std::cout << "maskkey: " << m_masking_key << std::endl;
|
||||
|
||||
/* TODO: test and tune
|
||||
|
||||
boost::random::random_device rng;
|
||||
@@ -429,8 +445,7 @@ void frame::generate_masking_key() {
|
||||
}
|
||||
|
||||
void frame::clear_masking_key() {
|
||||
m_masking_key[0] = 0;
|
||||
m_masking_key[1] = 0;
|
||||
m_masking_key[2] = 0;
|
||||
m_masking_key[3] = 0;
|
||||
// this is a no-op as clearing the mask bit also changes the get_header_len
|
||||
// method to not include these byte ranges. Whenever the masking bit is re-
|
||||
// set a new key is generated anyways.
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
#include <boost/random.hpp>
|
||||
#include <boost/random/random_device.hpp>
|
||||
|
||||
namespace websocketpp {
|
||||
|
||||
class frame {
|
||||
@@ -72,7 +75,8 @@ public:
|
||||
static const uint64_t max_payload_size = 100000000; // 100MB
|
||||
|
||||
// create an empty frame for writing into
|
||||
frame() {
|
||||
frame() : m_gen(m_rng,
|
||||
boost::random::uniform_int_distribution<>(INT32_MIN,INT32_MAX)) {
|
||||
// not sure if these are necessary with c++ but putting in just in case
|
||||
memset(m_header,0,MAX_HEADER_LENGTH);
|
||||
}
|
||||
@@ -139,6 +143,11 @@ private:
|
||||
|
||||
char m_masking_key[4];
|
||||
unsigned int m_extended_header_bytes_needed;
|
||||
|
||||
boost::random::random_device m_rng;
|
||||
boost::random::variate_generator<boost::random::random_device&,
|
||||
boost::random::uniform_int_distribution<> >
|
||||
m_gen;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user