2015-01-28 13:14:56 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2019-10-25 00:43:08 +02:00
|
|
|
* Copyright (C) 2015-2019 Intel Corporation. All rights reserved.
|
2015-01-28 13:14:56 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2016-05-11 22:53:35 +02:00
|
|
|
#include "src/iwd.h"
|
2018-05-24 23:02:04 +02:00
|
|
|
#include "src/common.h"
|
2015-01-28 13:14:56 +01:00
|
|
|
#include "src/ie.h"
|
|
|
|
|
|
|
|
struct test_data {
|
2015-01-28 21:25:39 +01:00
|
|
|
unsigned char *rsne;
|
|
|
|
unsigned int rsne_len;
|
2015-01-28 13:14:56 +01:00
|
|
|
enum ie_bss_capability capability;
|
2016-05-11 22:53:35 +02:00
|
|
|
enum security expected;
|
2015-01-28 13:14:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char ssid_security_wpa_data_1[] = {
|
|
|
|
0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
|
|
|
|
0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
|
|
|
|
0x00, 0x0f, 0xac, 0x02, 0x0c, 0x00,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_data ssid_security_wpa_test_1 = {
|
2015-01-28 21:25:39 +01:00
|
|
|
.rsne = ssid_security_wpa_data_1,
|
|
|
|
.rsne_len = sizeof(ssid_security_wpa_data_1),
|
2015-01-28 13:14:56 +01:00
|
|
|
.capability = IE_BSS_CAP_ESS,
|
2016-05-11 22:53:35 +02:00
|
|
|
.expected = SECURITY_PSK,
|
2015-01-28 13:14:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char ssid_security_wpa2_data_1[] = {
|
|
|
|
0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
|
|
|
|
0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
|
|
|
|
0x00, 0x0f, 0xac, 0x02, 0x00, 0x00,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_data ssid_security_wpa_test_2 = {
|
2015-01-28 21:25:39 +01:00
|
|
|
.rsne = ssid_security_wpa2_data_1,
|
|
|
|
.rsne_len = sizeof(ssid_security_wpa2_data_1),
|
2015-01-28 13:14:56 +01:00
|
|
|
.capability = IE_BSS_CAP_ESS,
|
2016-05-11 22:53:35 +02:00
|
|
|
.expected = SECURITY_PSK,
|
2015-01-28 13:14:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char ssid_security_8021x_data_1[] = {
|
|
|
|
0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
|
|
|
|
0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
|
|
|
|
0x00, 0x0f, 0xac, 0x01, 0x28, 0x00,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_data ssid_security_8021x_test_1 = {
|
2015-01-28 21:25:39 +01:00
|
|
|
.rsne = ssid_security_8021x_data_1,
|
|
|
|
.rsne_len = sizeof(ssid_security_8021x_data_1),
|
2015-01-28 13:14:56 +01:00
|
|
|
.capability = IE_BSS_CAP_ESS,
|
2016-05-11 22:53:35 +02:00
|
|
|
.expected = SECURITY_8021X,
|
2015-01-28 13:14:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_data ssid_security_wep_test_1 = {
|
|
|
|
.capability = IE_BSS_CAP_ESS | IE_BSS_CAP_PRIVACY,
|
2016-05-11 22:53:35 +02:00
|
|
|
.expected = SECURITY_WEP,
|
2015-01-28 13:14:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_data ssid_security_open_test_1 = {
|
|
|
|
.capability = IE_BSS_CAP_ESS,
|
2016-05-11 22:53:35 +02:00
|
|
|
.expected = SECURITY_NONE,
|
2015-01-28 13:14:56 +01:00
|
|
|
};
|
|
|
|
|
2015-01-28 21:25:39 +01:00
|
|
|
static void ssid_security_test(const void *data)
|
2015-01-28 13:14:56 +01:00
|
|
|
{
|
2015-01-28 21:25:39 +01:00
|
|
|
const struct test_data *test = data;
|
2015-01-28 13:14:56 +01:00
|
|
|
struct ie_rsn_info info;
|
2015-01-28 21:25:39 +01:00
|
|
|
const struct ie_rsn_info *infop;
|
2015-01-28 13:14:56 +01:00
|
|
|
int ret;
|
|
|
|
|
2015-01-28 21:25:39 +01:00
|
|
|
if (test->rsne) {
|
|
|
|
ret = ie_parse_rsne_from_data(test->rsne,
|
|
|
|
test->rsne_len, &info);
|
|
|
|
assert(ret == 0);
|
2015-01-28 13:14:56 +01:00
|
|
|
|
2015-01-28 21:25:39 +01:00
|
|
|
infop = &info;
|
|
|
|
} else
|
|
|
|
infop = NULL;
|
2015-01-28 13:14:56 +01:00
|
|
|
|
2018-05-24 23:02:04 +02:00
|
|
|
assert(security_determine(test->capability, infop) == test->expected);
|
2015-01-28 13:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
l_test_init(&argc, &argv);
|
|
|
|
|
|
|
|
l_test_add("/SSID Security/Open",
|
2015-01-28 21:25:39 +01:00
|
|
|
ssid_security_test, &ssid_security_open_test_1);
|
2015-01-28 13:14:56 +01:00
|
|
|
l_test_add("/SSID Security/WPA",
|
2015-01-28 21:25:39 +01:00
|
|
|
ssid_security_test, &ssid_security_wpa_test_1);
|
2015-01-28 13:14:56 +01:00
|
|
|
l_test_add("/SSID Security/WPA2",
|
2015-01-28 21:25:39 +01:00
|
|
|
ssid_security_test, &ssid_security_wpa_test_2);
|
2015-01-28 13:14:56 +01:00
|
|
|
l_test_add("/SSID Security/8021x",
|
2015-01-28 21:25:39 +01:00
|
|
|
ssid_security_test, &ssid_security_8021x_test_1);
|
2015-01-28 13:14:56 +01:00
|
|
|
l_test_add("/SSID Security/WEP",
|
2015-01-28 21:25:39 +01:00
|
|
|
ssid_security_test, &ssid_security_wep_test_1);
|
2015-01-28 13:14:56 +01:00
|
|
|
|
|
|
|
return l_test_run();
|
|
|
|
}
|