您的位置:首页 > 其它

wpa_supplicant 笔记

2013-12-19 20:54 429 查看
wpa_supplicant
笔记2009年09月25日 星期五 14:11 wpa_supplicant 笔记

来自于wpa_supplicant-devel文档

2、代码结构

核心功能、通用辅助功能、加密功能、TLS库、配置、控制接口、WPA提供者、EAP点、EAPOL提供、窗口端口和测试程序。

wpa_supplicant的实现被分成几个独立的模块。核心代码功能包括控制网络选择、连接和配置。独立模块包括WPA代码(key
handshake,PMKSA
缓存,pre-授权),EAPOL状态机和EAP状态机和方法。另外,还有一些具有通用帮助功能的单独文件。

WPA和EAPOL/EAP状态机可以单独的用于其它的程序中。代码中有eapol_test和preauth_test实例代码使用这另个模块。

Driver interface
API实在driver.h中定义的,所有硬件/驱动相关的功能都是在driver_*.c中实现的。

2.1wpa_supplicant核心功能

wpa_supplicant.c 程序初始化、控制主循环。

main.c 驱动事件处理;wpa_supplicant_enent()和相关功能。

wpa_supplicant_i.h 核心功能和的内部定义;在独立的模块中不应该包含这个头文件。

2.2 通用辅助功能

wpa_supplicant使用同样的辅助功能,其中的一些事和hostapd共用的。目前它使用以下代码:

eloop.c和eloop.h 事件循环(select()循环,具有可选超时、socket读数据回调和信号回调)。

common.c和common.h Common辅助函数。

defs.h 多个文件共用的定义。

l2_packet.h, l2_packet_linux.c,和 l2_packet_pcap.c
Layer2(连接层)访问包装(包括linux本地的实现和对libdnet/libpcap的包装)函数。在移植到libdnet/libpcap不
支持的新系统的时候需要添加新的l2_packet
implementation。可以用Makefile来选择包含那个l2_packet实现。l2_packet_linux.c使用linux的包套
接字(packet sockets),l2_packet_pcap.c移植性更好,使用libpcap和libdnet。

pcsc_funcs.c and pcsc_funcs.h Wrapper for PC/SC lite SIM and smart
card readers

priv_netlink.h 来自linux内核文件的私有版本的网络连接定义,它可以被C库头文件替代once suitable
version becomes commonly available。

version.h 版本号定义.

wireless.h 私有版本的 来自内核的linux wireless extension定义;可以被C库头文件代替once
suitable version becomes commonly available。

2.3 加密功能。

md5.c md5.h
MD5 HMAC-MD5

rc4.c rc4.h RC4(broadcase/default key encryption)

sha1.c sha1.h SHA-1 (replaced with a crypto library if TLS support
is included) HMAC-SHA-1 (keyed

checksum for message authenticity validation) PRF-SHA-1
(pseudorandom (key/nonce generation) function)

PBKDF2-SHA-1 (ASCII passphrase to shared secret) T-PRF (for
EAP-FAST) TLS-PRF (RFC 2246)

sha256.c and sha256.h SHA-256 (replaced with a crypto library if
TLS support is included)

aes_wrap.c, aes_wrap.h, aes.c AES (replaced with a crypto library
if TLS support is included), AES

Key Wrap Algorithm with 128-bit KEK, RFC3394 (broadcast/default key
encryption), One-Key CBC

MAC (OMAC1) hash with AES-128, AES-128 CTR mode encryption, AES-128
EAX mode encryption/

decryption, AES-128 CBC

crypto.h Definition of crypto library wrapper

crypto_openssl.c Wrapper functions for libcrypto (OpenSSL)

crypto_internal.c Wrapper functions for internal crypto
implementation

crypto_gnutls.c Wrapper functions for libgcrypt (used by
GnuTLS)

ms_funcs.c and ms_funcs.h Helper functions for MSCHAPV2 and
LEAP

tls.h Definition of TLS library wrapper

tls_none.c Dummy implementation of TLS library wrapper for cases
where TLS functionality is not included.

tls_openssl.c TLS library wrapper for openssl

tls_internal.c TLS library for internal TLS implementation

tls_gnutls.c TLS library wrapper for GnuTLS

2.4 TLS(Transport Layer Security,传输层安全协议) 库

asn1.c and asn1.h ASN.1 DER parsing

bignum.c and bignum.h Big number math

rsa.c and rsa.h RSA

x509v3.c and x509v3.h X.509v3 certificate parsing and
processing

tlsv1_client.c, tlsv1_client.h TLSv1 client (RFC 2246)

tlsv1_client_i.h Internal structures for TLSv1 client

tlsv1_client_read.c TLSv1 client: read handshake messages

tlsv1_client_write.c TLSv1 client: write handshake messages

tlsv1_common.c and tlsv1_common.h Common TLSv1 routines and
definitions

tlsv1_cred.c and tlsv1_cred.h TLSv1 credentials

tlsv1_record.c and tlsv1_record.h TLSv1 record protocol

2.5 配置

config_ssid.h 每个网络的配置项目。

config.h wpa_supplicant的配置定义。

config.c 配置解析器和common functions。

config_file.c 文本配置文件的后端(e.g., wpa_supplicant.conf)。

config_winreg.c Configuration backend for Windows registry。

2.6 控制接口

wpa_supplicant有一个可以被外部程序用来得到状态信息和进行管理操作的控制接口。在wpa_supplicant的发行版中包括了使用这个控制接口的命令行接口(wpa_cli)和图形接口(wpa_gui)。

ctrl_iface.c 和 ctrl_iface.h wpa_supplicant-side的控制接口。

ctrl_iface_unix.c 基于 UNIX domain sockets 的控制接口后端。

ctrl_iface_udp.c 基于 UDP sockets 的控制接口后端。

ctrl_iface_named_pipe.c Windows named pipes -based control
interface backend。

wpa_ctrl.c and wpa_ctrl.h 提供给外部程序访问wpa_supplicant的控制接口的库函数。

wpa_cli.c Example program for using wpa_supplicant control
interface。

2.7 WPA supplicant

wpa.c and wpa.h WPA 的状态机和 4-Way/Group Key Handshake
processing。

preauth.c and preauth.h PMKSA caching 和 pre-authentication
(RSN/WPA2)。

wpa_i.h Internal definitions for WPA code; not to be included to
other modules。

2.8 EAP peer

EAP peer implementation is a separate module that can be used by
other programs than just wpa_-

supplicant.

eap.c and eap.h EAP state machine and method interface

eap_defs.h Common EAP definitions

eap_i.h Internal definitions for EAP state machine and EAP methods;
not to be included in other modules

eap_sim_common.c and eap_sim_common.h Common code for EAP-SIM and
EAP-AKA

eap_tls_common.c and eap_tls_common.h Common code for EAP-PEAP,
EAP-TTLS, and EAP-FAST

eap_tlv.c and eap_tlv.h EAP-TLV code for EAP-PEAP and
EAP-FAST

eap_ttls.c and eap_ttls.h EAP-TTLS

eap_pax.c, eap_pax_common.h, eap_pax_common.c EAP-PAX

eap_psk.c, eap_psk_common.h, eap_psk_common.c EAP-PSK (note: this
is not needed for WPA-PSK)

eap_sake.c, eap_sake_common.h, eap_sake_common.c EAP-SAKE

eap_gpsk.c, eap_gpsk_common.h, eap_gpsk_common.c EAP-GPSK

eap_aka.c, eap_fast.c, eap_gtc.c, eap_leap.c, eap_md5.c,
eap_mschapv2.c, eap_otp.c, eap_peap.c, eap_-

sim.c, eap_tls.c Other EAP method implementations

2.9 EAPOL supplicant

eapol_supp_sm.c and eapol_supp_sm.h EAPOL supplicant state machine
and IEEE 802.1X processing

2.10 Windows port

ndis_events.c Code for receiving NdisMIndicateStatus() events and
delivering them to wpa_supplicant

driver_ndis.c in more easier to use form

win_if_list.c External program for listing current network
interface

2.11 Test programs

radius_client.c and radius_client.h RADIUS authentication client
implementation for eapol_test

radius.c and radius.h RADIUS message processing for
eapol_test

eapol_test.c Standalone EAP testing tool with integrated RADIUS
authentication client

preauth_test.c Standalone RSN pre-authentication tool

wpa_passphrase.c WPA ASCII passphrase to PSK conversion

Generated on

3、控制接口

wpa_supplicant实现了一个由外部程序使用来控制wpa_supplicant守护程序操作和得到状态信息和事件通知的控制接口。有一个单独
文件的小C库wpa_ctrl.c提供辅助函数来方便使用这个控制接口。外部程序可以把这个文件链接到他们并使用wpa_ctrl.h中提供的函数来与
wpa_supplicant交互。这个库也可以被C++使用。wpa_cli.c和wpa_gui 是使用这个库的实例。

3.1 使用控制接口。

要与wpa_supplicant通信的程序应该链接wpa_ctrl.c文件。这使他们可以用辅助函数,使用wpa_ctrl_open()来打开与
wpa_supplicant控制接口的链接,通过wpa_ctrl_request()来发送命令。

wpa_supplicant使用控制接口进行两种通信:命令和主动发送事件信息。。命令式一对消息,包括来自外部程序的请求和来自
wpa_supplicant的响应,这可以通过wpa_ctrl_request()来执行。主动的事件消息是由wpa_supplicant发送到控
制接口链接的,无需从外部程序指定接收每个消息的请求。然而,外部程序需要通过wpa_strl_attach()来attach到控制接口来接收这些主
动消息。

如果控制接口的链接被用来同时发送名利和处理事件消息,那么在命令的请求和回应之间可能出现一个事件消息。wpa_ctrl_request()的调用者
需要提供一个回调函数(比如msg_cb)来处理这些消息。通常可以调用wpa_ctrl_open()两次打开两个与wpa_supplicant控制
接口的链接,一个连接用来处理命令,一个用来处理事件消息。这样一对请求/回应就不会被事件消息打断了。wpa_cli提供了使用一个连接wpa_gui
提供了使用两个连接的实例。

一旦不再需要与控制接口的链接,应该调用wpa_ctrl_close()来关闭这个链接。如果是用来处理事件消息的链接,应该先调用wpa_ctrl_detach()来断开。

3.2 控制接口命令

以下命令可以用于wpa_ctrl_request():

3.2.1 PING

用来测试wpa_supplicant是否回应控制接口命令。如果链接打开并且wpa_supplicant正在处理命令放回PONG。

3.2.2 MIB

请求MIB变量(dot1x,dot11)list,输出是每行一个variable=value的文本块。比如:

dot11RSNAOptionImplemented=TRUE

dot11RSNAPreauthenticationImplemented=TRUE

dot11RSNAEnabled=FALSE

dot11RSNAPreauthenticationEnabled=FALSE

dot11RSNAConfigVersion=1

dot11RSNAConfigPairwiseKeysSupported=5

………………

………………

3.3.3 STATUS

请求当前WPA/EAPOL/EAP的状态信息。输出是每行一个variable=value的文本块。比如:

bssid=02:00:01:02:03:04

ssid=test network

pairwise_cipher=CCMP

group_cipher=CCMP

key_mgmt=WPA-PSK

wpa_state=COMPLETED

ip_address=192.168.1.21

Supplicant PAE state=AUTHENTICATED

suppPortStatus=Authorized

EAP state=SUCCESS

3.3.4 STATUS-VERBOSE

和STATUS相同,但是提供更多的信息。

bssid=02:00:01:02:03:04

ssid=test network

id=0

pairwise_cipher=CCMP

group_cipher=CCMP

key_mgmt=WPA-PSK

wpa_state=COMPLETED

ip_address=192.168.1.21

Supplicant PAE state=AUTHENTICATED

suppPortStatus=Authorized

heldPeriod=60

authPeriod=30

startPeriod=30

maxStart=3

portControl=Auto

Supplicant Backend state=IDLE

EAP state=SUCCESS

reqMethod=0

methodState=NONE

decision=COND_SUCC

ClientTimeout=60

3.2.5 PMKSA

显示PMKSA缓存。

Index / AA / PMKID / expiration (in seconds) / opportunistic

1 / 02:00:01:02:03:04 / 000102030405060708090a0b0c0d0e0f / 41362 /
0

2 / 02:00:01:33:55:77 / 928389281928383b34afb34ba4212345 / 362 /
1

3.2.6 SET

设置变量。

EAPOL::heldPeriod

EAPOL::authPeriod

EAPOL::startPeriod

EAPOL::maxStart

dot11RSNAConfigPMKLifetime

dot11RSNAConfigPMKReauthThreshold

dot11RSNAConfigSATimeout

Example command:

SET EAPOL::heldPeriod 45

3.2.7 LOGON

IEEE 802.1X EAPOL state machine logon.

3.2.8 LOGOFF

IEEE 802.1X EAPOL state machine logoff.

3.2.9 REASSOCIATE

Force reassociation.

3.2.10 RECONNECT

Connect if disconnected (i.e., like REASSOCIATE, but only connect
if in disconnected state).

3.2.11 PREAUTH

Start pre-authentication with the given BSSID.

3.2.12 ATTACH

Attach the connection as a monitor for unsolicited events. This can
be done with wpa_ctrl_attach().

3.2.13 DETACH

Detach the connection as a monitor for unsolicited events. This can
be done with wpa_ctrl_detach().

3.2.14 LEVEL

Change debug level.

3.2.15 RECONFIGURE

Force wpa_supplicant to re-read its configuration data.

3.2.16 TERMINATE

Terminate wpa_supplicant process.

3.2.17 BSSID

Set preferred BSSID for a network. Network id can be received from
the LIST_NETWORKS command

output.

3.2.18 LIST_NETWORKS

List configured networks.

network id / ssid / bssid / flags

0 example network any [CURRENT]

(note: fields are separated with tabs)

3.2.19 DISCONNECT

Disconnect and wait for REASSOCIATE or RECONNECT command before
connecting.

3.2.20 SCAN

Request a new BSS scan.

3.2.21 SCAN_RESULTS

Get the latest scan results.

bssid / frequency / signal level / flags / ssid

00:09:5b:95:e0:4e 2412 208 [WPA-PSK-CCMP] jkm private

02:55:24:33:77:a3 2462 187 [WPA-PSK-TKIP] testing

00:09:5b:95:e0:4f 2412 209 jkm guest

(note: fields are separated with tabs)

3.2.22 BSS

获得详细的单个BSS搜索结果。BSS命令可以每次一个BSS的遍历搜索结果和取得找到的BSS的全部信息。它提供对SCAN_RESULTS可用的相同
的数据的访问,但是避免了关于大量搜索结果与ctrl_iface消息not fitting的问题。

它提供了两种选择BSS的方法:BSS ,取得搜索结果table中通过index(0--size-1)标识的BSS的信息;BSS
取得给定的BSSID的BSS的信息,BSSID使用00:01:02:03:04:05格式。

BSS信息使用下面的格式表示。但是新的filed可能被添加到这个数据中,所以控制接口的用户应该呢可以忽略它不理解的值。

bssid=00:09:5b:95:e0:4e

freq=2412

beacon_int=0

capabilities=0x0011

qual=51

noise=161

level=212

tsf=0000000000000000

ie=000b6a6b6d2070726976617465010180dd180050f20101000050f20401000050f20401000050f2020000

ssid=jkm private

3.2.23 SELECT_NETWORK

选择一个网络(禁用其他的网络)。network id可以通过 LIST_NETWORKS 命令的输出得到。

3.2.24 ENABLE_NETWORK

使一个网络可用。network id可以通过 LIST_NETWORKS 命令的输出得到。使用 all作为network
id可以使所有网络可用。

3.2.25 DISABLE_NETWORK

禁用一个网络。network id可以通过 LIST_NETWORKS 命令的输出得到。使用 all作为network
id可以使所有网络禁用。

3.2.26 ADD_NETWORK

添加一个网络。这个命令创建一个没有配置的新网络。新创建的网络默认是禁用的,配置过新网络后可以通过ENABLE_NETWORK来使它可用。ADD_NETWORK命令成功返回添加的网络id,失败返回FAIL。

3.2.27 REMOVE_NETWORK

删除一个网络。network id可以通过 LIST_NETWORKS 命令的输出得到。使用 all作为network
id可以删除所有网络。

3.2.28 SET_NETWORK

设置网络变量。network id可以通过 LIST_NETWORKS
命令的输出得到。这个命令使用与配置文件相同的变量和变量值。参阅wpa_supplicant.conf。

ssid (network name, SSID)

psk (WPA passphrase or pre-shared key)

key_mgmt (key management protocol)

identity (EAP identity)

password (EAP password)

...

3.2.29 GET_NETWORK

获取网络变量值。network id可以通过 LIST_NETWORKS 命令的输出得到。

3.2.30 SAVE_CONFIG

向配置文件保存当前配置。

3.3 交互请求

如果wpa_supplicant在授权过程中需要额外的信息(比如,密码),他会在主动的事件消息中使用指定的前缀(CTRL-REQ-
(WPA_CTRL_REQ macro)。外部程序可以通过在具有相应field name的命令中使用CTRL-RSP-
(WPA_CTRL_RSP macro)前缀来提供需要的信息。

下列信息可能需要用户提供:

IDENTITY (EAP identity/user name)

PASSWORD (EAP password)

NEW_PASSWORD (New password if the server is requesting password
change)

PIN (PIN code for accessing a SIM or smartcard)

OTP (one-time password; like password, but the value is used only
once)

PASSPHRASE (passphrase for a private key file)

CTRL-REQ---

CTRL-RSP---

例如:来自wpa_supplicant的请求:

CTRL-REQ-PASSWORD-1-Password needed for SSID test-network

相应来自外部程序的回应:

CTRL-RSP-PASSWORD-1-secret

3.3.1 GET_CAPABILITY
[strict]

获取网络支持的功能列表(eap,pairwise,group,proto)。支持的功能以被空格隔开的值的形式(与在wpa_supplicant配
置文件中相同的格式)被显示。如果参数strict被使用,只有在驱动中显示声明支持的值会被包括。没有strict参数的时候,如果驱动没有提供查询它
所具有的功能的机制,所有可用的功能都被包括进来。

例如:

GET_CAPABILITY eap

AKA FAST GTC LEAP MD5 MSCHAPV2 OTP PAX PEAP PSK SIM TLS TTLS

GET_CAPABILITY pairwise

CCMP TKIP NONE

GET_CAPABILITY pairwise strict

GET_CAPABILITY group

CCMP TKIP WEP104 WEP40

GET_CAPABILITY key_mgmt

WPA-PSK WPA-EAP IEEE8021X NONE

GET_CAPABILITY proto

RSN WPA

GET_CAPABILITY auth_alg

OPEN SHARED LEAP

3.3.2 AP_SCAN

改变ap_scan的值:
0,不搜索;1,wpa_supplicant请求搜索并且使用搜索结果来选择AP;2,wpa_supplicant不使用自己的搜索并且只请求驱动来联系和进行AP的选择。

3.3.3 INTERFACES

列出配置的网络设备

比如:

wlan0

eth0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: