mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Added RSNInformation class. Added helper function in IEEE802_11_Beacon to add a RSN information option.
This commit is contained in:
@@ -578,7 +578,7 @@ namespace Tins {
|
||||
|
||||
protected:
|
||||
|
||||
ManagementFrame();
|
||||
ManagementFrame(const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0);
|
||||
ManagementFrame(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr) throw (std::runtime_error);
|
||||
|
||||
struct CapabilityInformation {
|
||||
@@ -638,6 +638,76 @@ namespace Tins {
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Class that models the RSN information structure.
|
||||
*/
|
||||
class RSNInformation {
|
||||
public:
|
||||
/**
|
||||
* \brief Enum that represents the different cypher suites.
|
||||
*/
|
||||
enum CypherSuites {
|
||||
WEP_40 = 0x01ac0f00,
|
||||
TKIP = 0x02ac0f00,
|
||||
CCMP = 0x04ac0f00,
|
||||
WEP_104 = 0x05ac0f00
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Enum that represents the different akm suites.
|
||||
*/
|
||||
enum AKMSuites {
|
||||
PMKSA = 0x01ac0f00,
|
||||
PSK = 0x02ac0f00
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Creates an instance of RSNInformation.
|
||||
*
|
||||
* By default, the version is set to 1.
|
||||
*/
|
||||
RSNInformation();
|
||||
|
||||
/**
|
||||
* \brief Helper function to create a WPA2-PSK RSNInformation
|
||||
* \return An instance RSNInformation which contains information
|
||||
* for a WPA2-PSK AP.
|
||||
*/
|
||||
static RSNInformation wpa2_psk();
|
||||
|
||||
/**
|
||||
* \brief Adds a pairwise cypher suite.
|
||||
* \param cypher The pairwise cypher suite to be added.
|
||||
*/
|
||||
void add_pairwise_cypher(CypherSuites cypher);
|
||||
|
||||
/**
|
||||
* \brief Adds a akm suite.
|
||||
* \param akm The akm suite to be added.
|
||||
*/
|
||||
void add_akm_cypher(AKMSuites akm);
|
||||
|
||||
/**
|
||||
* \brief Sets the group suite cypher.
|
||||
* \param group The group suite cypher to be set.
|
||||
*/
|
||||
void group_suite(CypherSuites group);
|
||||
|
||||
/**
|
||||
* \brief Serializes this object.
|
||||
* \param size Output parameter which will contain the size of
|
||||
* the allocated buffer.
|
||||
* \return The result of the serialization. This pointer should
|
||||
* be free'd using operator delete[].
|
||||
*/
|
||||
uint8_t *serialize(uint32_t &size) const;
|
||||
private:
|
||||
uint16_t _version, _capabilities;
|
||||
CypherSuites _group_suite;
|
||||
std::list<AKMSuites> _akm_cyphers;
|
||||
std::list<CypherSuites> _pairwise_cyphers;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -650,9 +720,10 @@ namespace Tins {
|
||||
|
||||
/**
|
||||
* \brief Default constructor for the beacon frame.
|
||||
*
|
||||
* \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional).
|
||||
* \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional).
|
||||
*/
|
||||
IEEE802_11_Beacon();
|
||||
IEEE802_11_Beacon(const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0);
|
||||
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 Beacon.
|
||||
@@ -935,6 +1006,12 @@ namespace Tins {
|
||||
* \param new_channel The new channel to be set.
|
||||
*/
|
||||
void channel(uint8_t new_channel);
|
||||
|
||||
/**
|
||||
* \brief Helper method to set the RSN information option.
|
||||
*
|
||||
*/
|
||||
void rsn_information(const RSNInformation& info);
|
||||
|
||||
/**
|
||||
* \brief Returns the frame's header length.
|
||||
@@ -956,9 +1033,6 @@ namespace Tins {
|
||||
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -62,6 +62,10 @@ Tins::IEEE802_11::IEEE802_11(uint32_t iface_index, const uint8_t* dst_hw_addr, c
|
||||
this->iface(iface_index);
|
||||
}
|
||||
|
||||
Tins::IEEE802_11::IEEE802_11(const ieee80211_header *header_ptr) : PDU(ETHERTYPE_IP) {
|
||||
|
||||
}
|
||||
|
||||
Tins::IEEE802_11::IEEE802_11(const uint8_t *buffer, uint32_t total_sz) : PDU(ETHERTYPE_IP), _options_size(0) {
|
||||
|
||||
}
|
||||
@@ -205,11 +209,12 @@ void Tins::IEEE802_11::write_serialization(uint8_t *buffer, uint32_t total_sz, c
|
||||
}
|
||||
}
|
||||
|
||||
Tins::IEEE802_11::IEEE802_11(const ieee80211_header *header_ptr) : PDU(ETHERTYPE_IP) {
|
||||
|
||||
}
|
||||
/*
|
||||
* ManagementFrame
|
||||
*/
|
||||
|
||||
Tins::ManagementFrame::ManagementFrame() : IEEE802_11() {
|
||||
Tins::ManagementFrame::ManagementFrame(const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr) : IEEE802_11(dst_hw_addr, src_hw_addr) {
|
||||
this->type(IEEE802_11::MANAGEMENT);
|
||||
}
|
||||
|
||||
@@ -219,7 +224,12 @@ Tins::ManagementFrame::ManagementFrame(const std::string& iface,
|
||||
this->type(IEEE802_11::MANAGEMENT);
|
||||
}
|
||||
|
||||
Tins::IEEE802_11_Beacon::IEEE802_11_Beacon() : ManagementFrame() {
|
||||
|
||||
/*
|
||||
* Beacon
|
||||
*/
|
||||
|
||||
Tins::IEEE802_11_Beacon::IEEE802_11_Beacon(const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr) : ManagementFrame() {
|
||||
this->subtype(IEEE802_11::BEACON);
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
@@ -247,7 +257,7 @@ void Tins::IEEE802_11_Beacon::rates(const std::list<float> &new_rates) {
|
||||
uint8_t *buffer = new uint8_t[new_rates.size()], *ptr = buffer;
|
||||
for(std::list<float>::const_iterator it = new_rates.begin(); it != new_rates.end(); ++it) {
|
||||
uint8_t result = 0x80, left = *it / 0.5;
|
||||
if(*it - left > 0) //arbitrary value
|
||||
if(*it - left > 0)
|
||||
left++;
|
||||
*(ptr++) = (result | left);
|
||||
}
|
||||
@@ -259,6 +269,13 @@ void Tins::IEEE802_11_Beacon::channel(uint8_t new_channel) {
|
||||
add_tagged_option(DS_SET, 1, &new_channel);
|
||||
}
|
||||
|
||||
void Tins::IEEE802_11_Beacon::rsn_information(const RSNInformation& info) {
|
||||
uint32_t size;
|
||||
uint8_t *buffer = info.serialize(size);
|
||||
add_tagged_option(RSN, size, buffer);
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
uint32_t Tins::IEEE802_11_Beacon::header_size() const {
|
||||
return IEEE802_11::header_size() + sizeof(BeaconBody);
|
||||
}
|
||||
@@ -270,3 +287,57 @@ uint32_t Tins::IEEE802_11_Beacon::write_fixed_parameters(uint8_t *buffer, uint32
|
||||
return sz;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* RSNInformation class
|
||||
*/
|
||||
Tins::RSNInformation::RSNInformation() : _version(1), _capabilities(0) {
|
||||
|
||||
}
|
||||
|
||||
void Tins::RSNInformation::add_pairwise_cypher(CypherSuites cypher) {
|
||||
_pairwise_cyphers.push_back(cypher);
|
||||
}
|
||||
|
||||
void Tins::RSNInformation::add_akm_cypher(AKMSuites akm) {
|
||||
_akm_cyphers.push_back(akm);
|
||||
}
|
||||
|
||||
void Tins::RSNInformation::group_suite(CypherSuites group) {
|
||||
_group_suite = group;
|
||||
}
|
||||
|
||||
uint8_t *Tins::RSNInformation::serialize(uint32_t &size) const {
|
||||
size = sizeof(_version) + sizeof(_capabilities) + sizeof(uint32_t);
|
||||
size += (sizeof(uint16_t) << 1); // 2 lists count.
|
||||
size += sizeof(uint32_t) * (_akm_cyphers.size() + _pairwise_cyphers.size());
|
||||
|
||||
uint8_t *buffer = new uint8_t[size], *ptr = buffer;
|
||||
*(uint16_t*)ptr = _version;
|
||||
ptr += sizeof(_version);
|
||||
*(uint32_t*)ptr = _group_suite;
|
||||
ptr += sizeof(uint32_t);
|
||||
*(uint16_t*)ptr = _pairwise_cyphers.size();
|
||||
ptr += sizeof(uint16_t);
|
||||
for(std::list<CypherSuites>::const_iterator it = _pairwise_cyphers.begin(); it != _pairwise_cyphers.end(); ++it) {
|
||||
*(uint32_t*)ptr = *it;
|
||||
ptr += sizeof(uint32_t);
|
||||
}
|
||||
*(uint16_t*)ptr = _akm_cyphers.size();
|
||||
ptr += sizeof(uint16_t);
|
||||
for(std::list<AKMSuites>::const_iterator it = _akm_cyphers.begin(); it != _akm_cyphers.end(); ++it) {
|
||||
*(uint32_t*)ptr = *it;
|
||||
ptr += sizeof(uint32_t);
|
||||
}
|
||||
*(uint16_t*)ptr = _capabilities;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Tins::RSNInformation Tins::RSNInformation::wpa2_psk() {
|
||||
RSNInformation info;
|
||||
info.group_suite(RSNInformation::CCMP);
|
||||
info.add_pairwise_cypher(RSNInformation::CCMP);
|
||||
info.add_akm_cypher(RSNInformation::PSK);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user