mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 09:58:54 +00:00
[Fix #1760] wifi_networks now takes into account slight differences b/w OS X 10.9 and later
This commit is contained in:
parent
34d19a2e60
commit
826643adf8
@ -36,7 +36,7 @@ TEST_F(WifiNetworksTest, test_parse_wifi_networks) {
|
||||
|
||||
QueryData results;
|
||||
auto count = CFDictionaryGetCount(networks);
|
||||
ASSERT_EQ((long)CFDictionaryGetCount(networks), 2);
|
||||
ASSERT_EQ((long)count, 2);
|
||||
const void* keys[count];
|
||||
const void* values[count];
|
||||
CFDictionaryGetKeysAndValues(networks, keys, values);
|
||||
@ -81,5 +81,65 @@ TEST_F(WifiNetworksTest, test_parse_wifi_networks) {
|
||||
EXPECT_EQ(results.back()[column.first], column.second);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(WifiNetworksTest, test_parse_legacy_wifi_networks) {
|
||||
std::string path = kTestDataPath + "test_airport_legacy.plist";
|
||||
|
||||
auto plist = (__bridge CFDictionaryRef)
|
||||
[NSDictionary dictionaryWithContentsOfFile:@(path.c_str())];
|
||||
ASSERT_GE((long)CFDictionaryGetCount(plist), 1);
|
||||
std::string key = "RememberedNetworks";
|
||||
auto cfkey = CFStringCreateWithCString(kCFAllocatorDefault, key.c_str(),
|
||||
kCFStringEncodingUTF8);
|
||||
auto networks = (CFArrayRef)CFDictionaryGetValue(plist, cfkey);
|
||||
|
||||
CFRelease(cfkey);
|
||||
|
||||
QueryData results;
|
||||
auto count = CFArrayGetCount(networks);
|
||||
ASSERT_EQ((long)count, 2);
|
||||
|
||||
for (CFIndex i = 0; i < count; i++) {
|
||||
parseNetworks(
|
||||
(CFDictionaryRef)CFArrayGetValueAtIndex((CFArrayRef)networks, i),
|
||||
results);
|
||||
}
|
||||
|
||||
Row expected1 = {
|
||||
{"ssid", "2890d228 3487"},
|
||||
{"network_name", "High-Fi"},
|
||||
{"security_type", "WPA2 Personal"},
|
||||
{"last_connected", "1419843361"},
|
||||
{"passpoint", "0"},
|
||||
{"possibly_hidden", "0"},
|
||||
{"roaming", "0"},
|
||||
{"roaming_profile", "Single"},
|
||||
{"captive_portal", "0"},
|
||||
{"auto_login", "0"},
|
||||
{"temporarily_disabled", "0"},
|
||||
{"disabled", "0"},
|
||||
};
|
||||
Row expected2 = {
|
||||
{"ssid", "85e965a1 63ab"},
|
||||
{"network_name", "WhyFi"},
|
||||
{"security_type", "Open"},
|
||||
{"last_connected", "1437434883"},
|
||||
{"passpoint", "0"},
|
||||
{"possibly_hidden", "0"},
|
||||
{"roaming", "0"},
|
||||
{"roaming_profile", "None"},
|
||||
{"captive_portal", "1"},
|
||||
{"auto_login", "0"},
|
||||
{"temporarily_disabled", "0"},
|
||||
{"disabled", "0"},
|
||||
};
|
||||
|
||||
for (const auto& column : expected2) {
|
||||
EXPECT_EQ(results.front()[column.first], column.second);
|
||||
}
|
||||
for (const auto& column : expected1) {
|
||||
EXPECT_EQ(results.back()[column.first], column.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,8 @@ std::string extractNetworkProperties(const CFTypeRef& property) {
|
||||
}
|
||||
|
||||
void parseNetworks(const CFDictionaryRef& network, QueryData& results) {
|
||||
if (network == nullptr || CFDictionaryGetCount(network) == 0) {
|
||||
if (network == nullptr || CFGetTypeID(network) != CFDictionaryGetTypeID() ||
|
||||
CFDictionaryGetCount(network) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -136,10 +137,9 @@ QueryData genKnownWifiNetworks(QueryContext& context) {
|
||||
if (plist == nullptr || CFDictionaryGetCount(plist) == 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto cfkey = CFStringCreateWithCString(kCFAllocatorDefault, key.c_str(),
|
||||
kCFStringEncodingUTF8);
|
||||
auto networks = (CFDictionaryRef)CFDictionaryGetValue(plist, cfkey);
|
||||
CFTypeRef networks = CFDictionaryGetValue(plist, cfkey);
|
||||
CFRelease(cfkey);
|
||||
if (networks == nullptr) {
|
||||
VLOG(1) << "Key not found : " << key;
|
||||
@ -147,15 +147,23 @@ QueryData genKnownWifiNetworks(QueryContext& context) {
|
||||
}
|
||||
|
||||
QueryData results;
|
||||
auto count = CFDictionaryGetCount(networks);
|
||||
const void* keys[count];
|
||||
const void* values[count];
|
||||
CFDictionaryGetKeysAndValues(networks, keys, values);
|
||||
if (CFGetTypeID(networks) == CFArrayGetTypeID()) {
|
||||
auto count = CFArrayGetCount((CFArrayRef)networks);
|
||||
for (CFIndex i = 0; i < count; i++) {
|
||||
parseNetworks(
|
||||
(CFDictionaryRef)CFArrayGetValueAtIndex((CFArrayRef)networks, i),
|
||||
results);
|
||||
}
|
||||
} else if (CFGetTypeID(networks) == CFDictionaryGetTypeID()) {
|
||||
auto count = CFDictionaryGetCount((CFDictionaryRef)networks);
|
||||
const void* keys[count];
|
||||
const void* values[count];
|
||||
CFDictionaryGetKeysAndValues((CFDictionaryRef)networks, keys, values);
|
||||
|
||||
for (CFIndex i = 0; i < count; i++) {
|
||||
parseNetworks((CFDictionaryRef)values[i], results);
|
||||
for (CFIndex i = 0; i < count; i++) {
|
||||
parseNetworks((CFDictionaryRef)values[i], results);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
100
tools/tests/test_airport_legacy.plist
Normal file
100
tools/tests/test_airport_legacy.plist
Normal file
@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>RememberedNetworks</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>AutoLogin</key>
|
||||
<false/>
|
||||
<key>Captive</key>
|
||||
<true/>
|
||||
<key>ChannelHistory</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Channel</key>
|
||||
<integer>161</integer>
|
||||
<key>Timestamp</key>
|
||||
<date>2015-07-20T23:28:03Z</date>
|
||||
</dict>
|
||||
</array>
|
||||
<key>Closed</key>
|
||||
<false/>
|
||||
<key>CollocatedGroup</key>
|
||||
<array>
|
||||
<string>foo</string>
|
||||
<string>bar</string>
|
||||
</array>
|
||||
<key>Disabled</key>
|
||||
<false/>
|
||||
<key>LastConnected</key>
|
||||
<date>2015-07-20T23:28:03Z</date>
|
||||
<key>Passpoint</key>
|
||||
<false/>
|
||||
<key>PossiblyHiddenNetwork</key>
|
||||
<false/>
|
||||
<key>RoamingProfileType</key>
|
||||
<string>None</string>
|
||||
<key>SPRoaming</key>
|
||||
<false/>
|
||||
<key>SSID</key>
|
||||
<data>
|
||||
helloWOrld=
|
||||
</data>
|
||||
<key>SSIDString</key>
|
||||
<string>WhyFi</string>
|
||||
<key>SecurityType</key>
|
||||
<string>Open</string>
|
||||
<key>SystemMode</key>
|
||||
<true/>
|
||||
<key>TemporarilyDisabled</key>
|
||||
<false/>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>AutoLogin</key>
|
||||
<false/>
|
||||
<key>Captive</key>
|
||||
<false/>
|
||||
<key>ChannelHistory</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Channel</key>
|
||||
<integer>11</integer>
|
||||
<key>Timestamp</key>
|
||||
<date>2014-12-29T08:56:02Z</date>
|
||||
</dict>
|
||||
</array>
|
||||
<key>Closed</key>
|
||||
<false/>
|
||||
<key>CollocatedGroup</key>
|
||||
<array/>
|
||||
<key>Disabled</key>
|
||||
<false/>
|
||||
<key>LastConnected</key>
|
||||
<date>2014-12-29T08:56:01Z</date>
|
||||
<key>Passpoint</key>
|
||||
<false/>
|
||||
<key>PossiblyHiddenNetwork</key>
|
||||
<false/>
|
||||
<key>RoamingProfileType</key>
|
||||
<string>Single</string>
|
||||
<key>SPRoaming</key>
|
||||
<false/>
|
||||
<key>SSID</key>
|
||||
<data>
|
||||
KJDSKDSHAKD
|
||||
</data>
|
||||
<key>SSIDString</key>
|
||||
<string>High-Fi</string>
|
||||
<key>SecurityType</key>
|
||||
<string>WPA2 Personal</string>
|
||||
<key>SystemMode</key>
|
||||
<true/>
|
||||
<key>TemporarilyDisabled</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</array>
|
||||
<key>Version</key>
|
||||
<integer>14</integer>
|
||||
</dict>
|
||||
</plist>
|
Loading…
Reference in New Issue
Block a user