0%

wpa_supplicant is a WPA(Wi-Fi Protected Access) Supplicant for Linux,
BSD and Windows with support for WPA and WPA2 (IEEE 802.11i / RSN).
Supplicant is the IEEE 802.1X/WPA component that is used in the client stations.
It implements key negotiation with a WPA Authenticator
and it can optionally control roaming
and IEEE 802.11 authentication/association of the wlan driver.

wpa_supplicant模块结构

wpa_supplicant模块图如下:

Event loop/事件循环模块

wpa_supplicant uses a single process/thread model
and an event loop to provide callbacks on events
(registered timeout, received packet, signal).
eloop.h defines the event loop interface. eloop.c is
an implementation of such an event loop using select() and sockets.
This is suitable for most UNIX/POSIX systems.
When porting to other operating systems,
it may be necessary to replace that implementation with OS specific
mechanisms that provide similar functionality.

wpa_supplicant采用单线程模式,基于事件驱动(event loop)。

wpa_supplicant needs to have access to
sending and receiving layer 2 (link layer) packets with two Ethertypes:
EAP-over-LAN (EAPOL) 0x888e and RSN pre-authentication 0x88c7. l2_packet.h
defines the interfaces used for this in the core wpa_supplicant implementation.

Configuration/配置模块

wpa_supplicant implements a configuration interface
that allows the backend to be easily replaced in order to read
configuration data from a suitable source depending on the target
platform. config.c implements the generic code that can be shared with
all configuration backends. Each backend is implemented in its own config_*.c file.

Driver interface/驱动接口模块

Unless the target OS and driver is already supported,
most porting projects have to implement a driver wrapper.
This may be done by adding a new driver interface module or
modifying an existing module (driver_*.c) if the new target
is similar to one of them. Driver wrapper implementation describes
the details of the driver interface
and discusses the tasks involved in porting this part of wpa_supplicant.

Control interface/控制接口模块

wpa_supplicant uses a control interface
to allow external processed to get status information
and to control the operations. Currently, this is implemented with
socket based communication; both UNIX domain sockets and UDP sockets are supported.
If the target OS does not support sockets,
this interface will likely need to be modified to
use another mechanism like message queues.
The control interface is optional component,
so it is also possible to run wpa_supplicant without porting this part.

Driver events/驱动事件模块

wpa_supplicant needs to receive event callbacks
when certain events occur
(association, disassociation, Michael MIC failure, scan results available, PMKSA caching candidate).
These events and the callback details are defined in
driver.h (wpa_supplicant_event() function and enum wpa_event_type).

XXX state machine/状态机模块

WPA/WPA2 state machine,EAP state machine(RFC4137),EAPOL state machine(802.1X).

wpa_supplicant代码结构

wpa_supplicant implementation is divided into number of independent modules.
Core code includes functionality for controlling the network selection,
association, and configuration. Independent modules include WPA code
(key handshake, PMKSA caching, pre-authentication),
EAPOL state machine, and EAP state machine and methods.
In addition, there are number of separate files for generic helper functions.

Both WPA and EAPOL/EAP state machines can be used separately
in other programs than wpa_supplicant. As an example,
the included test programs eapol_test and preauth_test are using these modules.

Driver interface API is defined in driver.h
and all hardware/driver dependent functionality is implemented in driver_*.c.

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

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

  • wpa_supplicant core functionality/核心功能
  • Generic helper functions/通用辅助
  • Cryptographic functions/加密功能
  • TLS library/TLS库
  • Configuration/配置
  • Control interface/控制接口
  • WPA supplicant/WPA提供
  • EAP peer/EAP点
  • EAPOL supplicant/EAPOL提供
  • Windows port/windosw端口
  • Test programs/测试程序

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

wpa_supplicant core functionality/核心功能

  • wpa_supplicant.c 程序初始化、控制主循环。
  • main.c main()用于类UNIX或Windows操作系统设置参数配置wpa_supplicant。
  • events.c 驱动事件处理;wpa_supplicant_enent()和相关功能。
  • wpa_supplicant_i.h 核心功能和的内部定义;在独立的模块中不应该包含这个头文件。

Generic helper functions/通用辅助

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实现。
    可以用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。

Cryptographic functions/加密功能

  • md5.c and md5.h MD5算法 (如果TLS支持开启,使用加密库取代) HMAC-MD5 (键入校验码以验证信息真伪)
  • rc4.c and rc4.h RC4算法(广播/默认密钥加密)
  • sha1.c and sha1.h SHA-1算法 (如果TLS支持开启,使用加密库取代) HMAC-SHA-1 (键入校验码以验证信息真伪) 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算法 (如果TLS支持开启,使用加密库取代)
  • aes_wrap.c, aes_wrap.h, aes.c AES算法 (如果TLS支持开启,使用加密库取代), 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 crypto库封装定义
  • crypto_openssl.c libcrypto封装函数 (OpenSSL)
  • crypto_internal.c crypto封装函数内部实现
  • crypto_gnutls.c libgcrypt封装函数(used by GnuTLS)
  • ms_funcs.c and ms_funcs.h MSCHAPV2 和 LEAP 帮助函数
  • tls.h TLS库封装定义
  • 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

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

  • asn1.c and asn1.h ASN.1 DER编码分析
  • bignum.c and bignum.h 大数运算(Big number math)
  • rsa.c and rsa.h RSA加密算法
  • x509v3.c and x509v3.h X.509v3数字证书分析和处理
  • tlsv1_client.c, tlsv1_client.h TLSv1客户端 (RFC 2246)
  • tlsv1_client_i.h TLSv1 client内部结构体
  • tlsv1_client_read.c TLSv1 客户端: 读握手信息
  • tlsv1_client_write.c TLSv1 客户端: 写握手信息
  • tlsv1_common.c and tlsv1_common.h TLSv1通用规则和定义(routines and definitions)
  • tlsv1_cred.c and tlsv1_cred.h TLSv1证书
  • tlsv1_record.c and tlsv1_record.h TLSv1记录协议

Configuration/配置

  • config_ssid.h 每个网络的配置项定义
  • config.h wpa_supplicant的配置定义
  • config.c 配置解析器和命令函数
  • config_file.c 文本配置文件后端(e.g., wpa_supplicant.conf)
  • config_winreg.c 配置Windows注册表后端(Configuration backend for Windows registry)

Control interface/控制接口

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 的控制接口后端
  • wpa_ctrl.c and wpa_ctrl.h 提供给外部程序访问wpa_supplicant控制接口的库函数
  • wpa_cli.c 使用wpa_supplicant控制接口的示例程序

WPA supplicant/WPA提供

  • wpa.c and wpa.h WPA 的状态机和4-Way/Group Key握手处理
  • preauth.c and preauth.h PMKSA缓存 和 预认证 (RSN/WPA2)
  • wpa_i.h WPA代码内部定义;其他模块不要包含该头文件

EAP peer/EAP点

EAP点实现作为一个独立模块可以用在其他程序中。

  • eap.c and eap.h EAP状态机和方法接口
  • eap_defs.h EAP通用定义
  • eap_i.h EAP状态机和方法内部定义,不应该被其他模块包含
  • eap_sim_common.c and eap_sim_common.h EAP-SIM 和 EAP-AKA 通用代码
  • eap_tls_common.c and eap_tls_common.h EAP-PEAP, EAP-TTLS, 和 EAP-FAST 通用代码
  • eap_tlv.c and eap_tlv.h EAP-PEAP 和 EAP-FAST 的 EAP-TLV 代码
  • 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: 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 其他EPA实现方法

EAPOL supplicant/EAPOL提供

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

Windows port/windosw端口

  • ndis_events.c 代码以更易于使用的方式从NdisMIndicateStatus()接收事件并分发它们到wpa_supplicant driver_ndis.c
  • win_if_list.c 监听当前网络接口的外部程序

Test programs/测试程序

  • radius_client.c and radius_client.h 用于eapol测试的RADIUS认证客户端
  • radius.c and radius.h 用于eapol测试的RADIUS消息处理
  • eapol_test.c 独立EAP测试工具和集成RADIUS认证客户端
  • preauth_test.c 独立RSN预认证工具
  • wpa_passphrase.c WPA ASCII密码转为PSK

References


layout: post
title: Makedown语法简介
description:
category: 编辑
tags: makedown



段落和换行

一个 Markdown 段落是由一个或多个连续的文本行组成,它的前后要有一个以上的空行(空行的定义是显示上看起来像是空的,便会被视为空行。比方说,若某一行只包含空格和制表符,则该行也会被视为空行)。普通段落不该用空格或制表符来缩进。

简单说:连续两个回车完成对段落的换行。

在Markdown当中设置标题,有两种方式:
第一种:通过在文字下方添加四个以上的“=”和“-”,他们分别表示一级标题和二级标题。例如:

H1
=======
H2
-------

H1

H2

第二种:在文字开头加上 “#”,通过“#”数量表示几级标题。(一共只有1~6级标题,1级标题字体最大)例如:

# H1
## H2
##### H5

H1

H2

H5

引用

通过在文字开头添加“>”表示块注释。区块引用可以嵌套(例如:引用内的引用),只要根据层次加上不同数量的 >

> This is the first level of quoting.
>   
> > This is nested blockquote.
>   
> Back to the first level.

This is the first level of quoting.

This is nested blockquote.

Back to the first level.

引用的区块内也可以使用其他的 Markdown 语法,包括标题、列表、代码区块等:

> ## 这是一个标题。
>   
> 1.   这是第一行列表项。
> 2.   这是第二行列表项。

这是一个标题。

  1. 这是第一行列表项。
  2. 这是第二行列表项。

列表

Markdown 支持有序列表和无序列表。

无序列表使用星号、加号或是减号作为列表标记:

*   Red
*   Green
*   Blue
  • Red
  • Green
  • Blue

等同于:

+   Red
+   Green
+   Blue
  • Red
  • Green
  • Blue

也等同于:

-   Red
-   Green
-   Blue
  • Red
  • Green
  • Blue

有序列表则使用数字接着一个英文句点:

1.  Bird
2.  McHale
3.  Parish
  1. Bird
  2. McHale
  3. Parish

代码

实现方式有两种:

第一种:简单文字出现一个代码框。使用`(不是单引号而是左上角的ESC下面~中的

`<blockquote>`

<blockquote>

第二种:大片文字需要实现代码框。使用Tab和四个空格。

int main()
{
//
}

分隔线

你可以在一行中用三个以上的星号、减号、底线来建立一个分隔线,行内不能有其他东西。你也可以在星号或是减号中间插入空格。

***
---


Markdown中有两种方式实现链接,分别为内联方式和引用方式,不管是哪一种,链接文字都是用 [方括号] 来标记。

内联方式:

This is an [example link](http://example.com/).

This is an example link.

引用方式:

I get 10 times more traffic from [Google][1] than from [Yahoo][2] or [MSN][3].  
...
[1]: http://google.com/        "Google" 
[2]: http://search.yahoo.com/  "Yahoo Search" 
[3]: http://search.msn.com/    "MSN Search"

I get 10 times more traffic from [Google][1] than from [Yahoo][2] or [MSN][3].

[1]: http://google.com/ “Google”
[2]: http://search.yahoo.com/ “Yahoo Search”
[3]: http://search.msn.com/ “MSN Search”

强调

Markdown 使用星号(*)和底线(_)作为标记强调字词的符号,被 *_ 包围的字词会被转成用 <em> 标签包围,用两个 *_ 包起来的话,则会被转成 <strong>,例如:

1个为斜体,两个为粗体。

*single asterisks*
_single underscores_
**double asterisks**
__double underscores__

single asterisks
single underscores
double asterisks
double underscores

你可以随便用你喜欢的样式,唯一的限制是,你用什么符号开启标签,就要用什么符号结束。

强调也可以直接插在文字中间:

un*frigging*believable

unfriggingbelievable

但是如果你的 *_ 两边都有空白的话,它们就只会被当成普通的符号

如果要在文字前后直接插入普通的星号或底线,你可以用反斜线:

\*this text is surrounded by literal asterisks\*

*this text is surrounded by literal asterisks*

图片

图片的处理方式和链接的处理方式,非常的类似。

内联方式:

![alt text](/path/to/img.jpg "Title")

引用方式:

![alt text][id] 
...
[id]: /path/to/img.jpg "Title"

反斜杠

Markdown 可以利用反斜杠来插入一些在语法中有其它意义的符号,例如:如果你想要用星号加在文字旁边的方式来做出强调效果(但不用 <em> 标签),你可以在星号的前面加上反斜杠:

\*literal asterisks\*

*literal asterisks*

Markdown 支持以下这些符号前面加上反斜杠来帮助插入普通的符号:

\   反斜线
`   反引号
*   星号
_   底线
{}  花括号
[]  方括号
()  括弧
#   井字号
+   加号
-   减号
.   英文句点
!   惊叹号

References:

iptables是Linux系统中最重要的网络管控工具。它与Kernel中的netfilter模块配合工作,
其主要功能是为netfilter设置一些过滤(filter)或网络地址转换(NAT)的规则。当Kernel收到网络数据包后,
将会依据iptables设置的规则进行相应的操作。

iptables原理

iptables的语法比较复杂,但工作原理较易理解。清楚iptables的前提是理解它的表(Table)、链(Chain)和规则(Rule)
三者关系如下图所示:

tables

Read more »