UpdateMessage::UpdateMessage(char *buffer, uint32_t length) { m_suspect = NULL; if(length < UPDATE_MSG_MIN_SIZE) { m_serializeError = true; return; } m_serializeError = false; //Deserialize the UI_Message header if(!DeserializeHeader(&buffer)) { m_serializeError = true; return; } uint32_t contentsSize; memcpy(&contentsSize, buffer, sizeof(contentsSize)); buffer += sizeof(contentsSize); if(!m_contents.ParseFromArray(buffer, contentsSize)) { m_serializeError = true; return; } buffer += contentsSize; //If more bytes to go... uint32_t bytesToGo = length - (MESSAGE_HDR_SIZE + sizeof(contentsSize) + contentsSize); if(bytesToGo > 0) { try { m_suspect = new Suspect(); if(m_suspect->Deserialize((u_char*)buffer, bytesToGo, NO_FEATURE_DATA) != bytesToGo) { delete m_suspect; m_suspect = NULL; m_serializeError = true; return; } } catch(Nova::serializationException &e) { delete m_suspect; m_suspect = NULL; m_serializeError = true; return; } } }
RequestMessage::RequestMessage(char *buffer, uint32_t length) { m_suspect = NULL; if( length < REQUEST_MSG_MIN_SIZE ) { m_serializeError = true; return; } m_serializeError = false; //Deserialize the UI_Message header if(!DeserializeHeader(&buffer)) { m_serializeError = true; return; } // Deserialize the request message type memcpy(&m_requestType, buffer, sizeof(m_requestType)); buffer += sizeof(m_requestType); switch(m_requestType) { case REQUEST_SUSPECTLIST_REPLY: { // Deserialize the request list type memcpy(&m_listType, buffer, sizeof(m_listType)); buffer += sizeof(m_listType); // Deserialize the length of the suspect list memcpy(&m_suspectListLength, buffer, sizeof(m_suspectListLength)); buffer += sizeof(m_suspectListLength); // Deserialize the list m_suspectList.clear(); for(uint i = 0; i < m_suspectListLength; i++) { SuspectIdentifier address; buffer += address.Deserialize(reinterpret_cast<u_char*>(buffer), length); m_suspectList.push_back(address); } break; } case REQUEST_SUSPECTLIST: { uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_requestType) + sizeof(m_listType); if(length != expectedSize) { m_serializeError = true; return; } // Deserialize the request list type memcpy(&m_listType, buffer, sizeof(m_listType)); buffer += sizeof(m_listType); break; } case REQUEST_SUSPECT: { // Deserialize the address of the suspect being requested buffer += m_suspectAddress.Deserialize(reinterpret_cast<u_char*>(buffer), length); break; } case REQUEST_SUSPECT_REPLY: { uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_requestType) + sizeof(m_suspectLength); if(length < expectedSize) { m_serializeError = true; return; } // DeSerialize the size of the suspect memcpy(&m_suspectLength, buffer, sizeof(m_suspectLength)); buffer += sizeof(m_suspectLength ); expectedSize += m_suspectLength; if(expectedSize != length) { m_serializeError = true; return; } m_suspect = new Suspect(); try { if(m_suspect->Deserialize((u_char*)buffer, length, NO_FEATURE_DATA) != m_suspectLength) { m_serializeError = true; return; } } catch(Nova::serializationException &e) { m_serializeError = true; return; } break; } case REQUEST_SUSPECT_WITHDATA: { // Deserialize the address of the suspect being requested buffer += m_suspectAddress.Deserialize(reinterpret_cast<u_char*>(buffer), length); break; } case REQUEST_SUSPECT_WITHDATA_REPLY: { uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_requestType) + sizeof(m_suspectLength); if(length < expectedSize) { m_serializeError = true; return; } // DeSerialize the size of the suspect memcpy(&m_suspectLength, buffer, sizeof(m_suspectLength)); buffer += sizeof(m_suspectLength ); expectedSize += m_suspectLength; if(expectedSize != length) { m_serializeError = true; return; } m_suspect = new Suspect(); try { if(m_suspect->Deserialize((u_char*)buffer, length, MAIN_FEATURE_DATA) != m_suspectLength) { m_serializeError = true; return; } } catch(Nova::serializationException &e) { m_serializeError = true; return; } break; } case REQUEST_UPTIME_REPLY: { uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_requestType) + sizeof(m_startTime); if(length != expectedSize) { m_serializeError = true; return; } // Deserialize the uptime memcpy(&m_startTime, buffer, sizeof(m_startTime)); buffer += sizeof(m_startTime); break; } case REQUEST_UPTIME: case REQUEST_PING: case REQUEST_PONG: { //Uses: 1) UI_Message Header // 2) ControlMessage Type uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_requestType); if(length != expectedSize) { m_serializeError = true; return; } break; } default: { m_serializeError = true; return; } } }
ControlMessage::ControlMessage(char *buffer, uint32_t length) { if( length < CONTROL_MSG_MIN_SIZE ) { m_serializeError = true; return; } m_serializeError = false; //Deserialize the UI_Message header if(!DeserializeHeader(&buffer)) { m_serializeError = true; return; } //Copy the control message type memcpy(&m_controlType, buffer, sizeof(m_controlType)); buffer += sizeof(m_controlType); switch(m_controlType) { case CONTROL_EXIT_REQUEST: case CONTROL_CLEAR_ALL_REQUEST: case CONTROL_DISCONNECT_NOTICE: case CONTROL_DISCONNECT_ACK: case CONTROL_RECLASSIFY_ALL_REQUEST: case CONTROL_CONNECT_REQUEST: case CONTROL_START_CAPTURE: case CONTROL_START_CAPTURE_ACK: case CONTROL_STOP_CAPTURE: case CONTROL_STOP_CAPTURE_ACK: { //Uses: 1) UI_Message Header // 2) ControlMessage Type uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_controlType); if(length != expectedSize) { m_serializeError = true; return; } break; } case CONTROL_EXIT_REPLY: case CONTROL_CLEAR_SUSPECT_REPLY: case CONTROL_SAVE_SUSPECTS_REPLY: case CONTROL_CLEAR_ALL_REPLY: case CONTROL_RECLASSIFY_ALL_REPLY: case CONTROL_CONNECT_REPLY: { //Uses: 1) UI_Message Header // 2) ControlMessage Type // 3) Boolean success uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_controlType) + sizeof(m_success); if(length != expectedSize) { m_serializeError = true; return; } memcpy(&m_success, buffer, sizeof(m_success)); buffer += sizeof(m_success); break; } case CONTROL_CLEAR_SUSPECT_REQUEST: { //Uses: 1) UI_Message Header // 2) ControlMessage Type // 3) Suspect IP to clear m_suspectAddress.Deserialize(reinterpret_cast<u_char*>(buffer), length); break; } case CONTROL_SAVE_SUSPECTS_REQUEST: { //Uses: 1) UI_Message Header // 2) ControlMessage Type uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_controlType) + sizeof(m_filePath); if(length != expectedSize) { m_serializeError = true; return; } memcpy(m_filePath, buffer, sizeof(m_filePath)); buffer += sizeof(m_filePath); break; } case CONTROL_INVALID: { break; } default: { m_serializeError = true; return; } } }
UpdateMessage::UpdateMessage(char *buffer, uint32_t length) { m_suspect = NULL; if( length < UPDATE_MSG_MIN_SIZE ) { m_serializeError = true; return; } m_serializeError = false; //Deserialize the Message header if(!DeserializeHeader(&buffer)) { m_serializeError = true; return; } //Copy the control message type memcpy(&m_updateType, buffer, sizeof(m_updateType)); buffer += sizeof(m_updateType); switch(m_updateType) { case UPDATE_SUSPECT: { //Uses: 1) Message Header // 2) ControlMessage Type // 3) Length of incoming serialized suspect // 3) Serialized suspect uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_updateType) + sizeof(m_suspectLength); if(length <= expectedSize) { m_serializeError = true; return; } memcpy(&m_suspectLength, buffer, sizeof(m_suspectLength)); buffer += sizeof(m_suspectLength); expectedSize += m_suspectLength; if((expectedSize != length) > SANITY_CHECK) { m_serializeError = true; return; } m_suspect = new Suspect(); try { if(m_suspect->Deserialize((u_char*)buffer, length, NO_FEATURE_DATA) != m_suspectLength) { m_serializeError = true; return; } } catch(Nova::serializationException &e) { m_serializeError = true; return; } break; } case UPDATE_SUSPECT_CLEARED: { //Uses: 1) Message Header // 2) Update Type // 3) Suspect IP m_IPAddress.Deserialize(reinterpret_cast<u_char*>(buffer), length); break; } case UPDATE_SUSPECT_ACK: case UPDATE_ALL_SUSPECTS_CLEARED: case UPDATE_ALL_SUSPECTS_CLEARED_ACK: case UPDATE_SUSPECT_CLEARED_ACK: { //Uses: 1) Message Header // 2) Update Type uint32_t expectedSize = MESSAGE_HDR_SIZE + sizeof(m_updateType); if(length != expectedSize) { m_serializeError = true; return; } break; } default: { m_serializeError = true; return; } } }