eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

test-ssid-security.c (3536B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2015-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <stdio.h>
     28 #include <string.h>
     29 #include <assert.h>
     30 #include <ell/ell.h>
     31 
     32 #include "src/iwd.h"
     33 #include "src/common.h"
     34 #include "src/ie.h"
     35 
     36 struct test_data {
     37 	unsigned char *rsne;
     38 	unsigned int rsne_len;
     39 	enum ie_bss_capability capability;
     40 	enum security expected;
     41 };
     42 
     43 static unsigned char ssid_security_wpa_data_1[] = {
     44 	0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
     45 	0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
     46 	0x00, 0x0f, 0xac, 0x02, 0x0c, 0x00,
     47 };
     48 
     49 static struct test_data ssid_security_wpa_test_1 = {
     50 	.rsne = ssid_security_wpa_data_1,
     51 	.rsne_len = sizeof(ssid_security_wpa_data_1),
     52 	.capability = IE_BSS_CAP_ESS,
     53 	.expected = SECURITY_PSK,
     54 };
     55 
     56 static unsigned char ssid_security_wpa2_data_1[] = {
     57 	0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
     58 	0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
     59 	0x00, 0x0f, 0xac, 0x02, 0x00, 0x00,
     60 };
     61 
     62 static struct test_data ssid_security_wpa_test_2 = {
     63 	.rsne = ssid_security_wpa2_data_1,
     64 	.rsne_len = sizeof(ssid_security_wpa2_data_1),
     65 	.capability = IE_BSS_CAP_ESS,
     66 	.expected = SECURITY_PSK,
     67 };
     68 
     69 static unsigned char ssid_security_8021x_data_1[] = {
     70 	0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
     71 	0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
     72 	0x00, 0x0f, 0xac, 0x01, 0x28, 0x00,
     73 };
     74 
     75 static struct test_data ssid_security_8021x_test_1 = {
     76 	.rsne = ssid_security_8021x_data_1,
     77 	.rsne_len = sizeof(ssid_security_8021x_data_1),
     78 	.capability = IE_BSS_CAP_ESS,
     79 	.expected = SECURITY_8021X,
     80 };
     81 
     82 static struct test_data ssid_security_wep_test_1 = {
     83 	.capability = IE_BSS_CAP_ESS | IE_BSS_CAP_PRIVACY,
     84 	.expected = SECURITY_WEP,
     85 };
     86 
     87 static struct test_data ssid_security_open_test_1 = {
     88 	.capability = IE_BSS_CAP_ESS,
     89 	.expected = SECURITY_NONE,
     90 };
     91 
     92 static void ssid_security_test(const void *data)
     93 {
     94 	const struct test_data *test = data;
     95 	struct ie_rsn_info info;
     96 	const struct ie_rsn_info *infop;
     97 	int ret;
     98 
     99 	if (test->rsne) {
    100 		ret = ie_parse_rsne_from_data(test->rsne,
    101 							test->rsne_len, &info);
    102 		assert(ret == 0);
    103 
    104 		infop = &info;
    105 	} else
    106 		infop = NULL;
    107 
    108 	assert(security_determine(test->capability, infop) == test->expected);
    109 }
    110 
    111 int main(int argc, char *argv[])
    112 {
    113 	l_test_init(&argc, &argv);
    114 
    115 	l_test_add("/SSID Security/Open",
    116 			ssid_security_test, &ssid_security_open_test_1);
    117 	l_test_add("/SSID Security/WPA",
    118 			ssid_security_test, &ssid_security_wpa_test_1);
    119 	l_test_add("/SSID Security/WPA2",
    120 			ssid_security_test, &ssid_security_wpa_test_2);
    121 	l_test_add("/SSID Security/8021x",
    122 			ssid_security_test, &ssid_security_8021x_test_1);
    123 	l_test_add("/SSID Security/WEP",
    124 			ssid_security_test, &ssid_security_wep_test_1);
    125 
    126 	return l_test_run();
    127 }