salt logic improved

This commit is contained in:
Klaus K Wilting 2018-04-01 18:33:22 +02:00
parent c1065193c6
commit 91ac7eb32f
3 changed files with 7 additions and 8 deletions

View File

@ -35,7 +35,7 @@ extern osjob_t sendjob;
extern uint16_t macnum, blenum, salt; extern uint16_t macnum, blenum, salt;
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim; extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
extern bool joinstate; extern bool joinstate;
extern std::set<uint16_t> macs; extern std::set<uint32_t> macs;
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
extern HAS_DISPLAY u8x8; extern HAS_DISPLAY u8x8;

View File

@ -46,7 +46,7 @@ uint16_t macnum = 0, blenum = 0, salt;
uint64_t uptimecounter = 0; uint64_t uptimecounter = 0;
bool joinstate = false; bool joinstate = false;
std::set<uint16_t> macs; // associative container holds filtered MAC adresses std::set<uint32_t> macs; // associative container holds filtered MAC adresses
// this variable will be changed in the ISR, and read in main loop // this variable will be changed in the ISR, and read in main loop
static volatile bool ButtonTriggered = false; static volatile bool ButtonTriggered = false;

View File

@ -62,9 +62,8 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
char counter [6]; // uint16_t -> 2 byte -> 5 decimals + '0' terminator -> 6 chars char counter [6]; // uint16_t -> 2 byte -> 5 decimals + '0' terminator -> 6 chars
char macbuf [21]; // uint64_t -> 8 byte -> 20 decimals + '0' terminator -> 21 chars char macbuf [21]; // uint64_t -> 8 byte -> 20 decimals + '0' terminator -> 21 chars
uint64_t addr2int; uint64_t addr2int;
uint32_t vendor2int; uint32_t vendor2int, hashedmac;
uint16_t hashedmac; std::pair<std::set<uint32_t>::iterator, bool> newmac;
std::pair<std::set<uint16_t>::iterator, bool> newmac;
if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value
addr2int = ( (uint64_t)hdr->addr2[0] ) | ( (uint64_t)hdr->addr2[1] << 8 ) | ( (uint64_t)hdr->addr2[2] << 16 ) | \ addr2int = ( (uint64_t)hdr->addr2[0] ) | ( (uint64_t)hdr->addr2[1] << 8 ) | ( (uint64_t)hdr->addr2[2] << 16 ) | \
@ -77,15 +76,15 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
// salt and hash MAC, and if new unique one, store identifier in container and increment counter on display // salt and hash MAC, and if new unique one, store identifier in container and increment counter on display
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization // https://en.wikipedia.org/wiki/MAC_Address_Anonymization
addr2int |= (uint64_t) salt << 48; addr2int |= (uint64_t) salt << 48; // prepend 12 bit salt to 48 bit MAC
itoa(addr2int, macbuf, 10); // convert 64 bit MAC to base 10 decimal string itoa(addr2int, macbuf, 10); // convert 64 bit MAC to base 10 decimal string
hashedmac = rokkit(macbuf, 5); // hash MAC for privacy, use 5 chars to fit in uint16_t container hashedmac = rokkit(macbuf, 10); // hash MAC, use 10 chars to fit hash in uint32_t container
newmac = macs.insert(hashedmac); // store hashed MAC if new unique newmac = macs.insert(hashedmac); // store hashed MAC if new unique
if (newmac.second) { // first time seen MAC if (newmac.second) { // first time seen MAC
macnum++; // increment MAC counter macnum++; // increment MAC counter
itoa(macnum, counter, 10); // base 10 decimal counter value itoa(macnum, counter, 10); // base 10 decimal counter value
u8x8.draw2x2String(0, 0, counter); u8x8.draw2x2String(0, 0, counter);
ESP_LOGI(TAG, "#%05i: RSSI %04d -> Hash %04x", macnum, ppkt->rx_ctrl.rssi, hashedmac); ESP_LOGI(TAG, "#%05i: RSSI %04d -> Hash %08x", macnum, ppkt->rx_ctrl.rssi, hashedmac);
} }
#ifdef VENDORFILTER #ifdef VENDORFILTER