安全关联
安全关联两个IPsec之间协商建立的一种协定,内容包括采用哪种IPsec加密协议(AH/ESP),运行模式(传输或者隧道),各种算法,密钥生存期等等。从而决定保护什么,如何保护,以及谁来保护。可以说安全关联是IPsec的基础。安全关联协商主要是在IKE阶段完成。
定义和范围
一个SA能供AH或ESP使用,但是不能同时使用。如果想同时使用AH和ESP,则需要两个关联。
在双向通信中,需要一对SA束(进出各一个)。
IKE在协商时可以准确的创建SA对。
SPD
the Security Policy Database,安全策略数据库。指定IP数据包使用什么服务(IPsec or not),使用什么方式(AH/ESP)等。
SPD是个有序的数据库,由访问控制列表(Access Control Lists (ACLs))或者防火墙中的包过滤器,路由等。
处理选项:
丢弃,特定方向的数据流无法通过IPsec边界。
旁通,数据流可以通过ipsec边界,并且不需要ipsec保护。
保护,数据可以通过ipsec边界,并且被ipsec保护。
SPD在逻辑上被分为3个部分,SPD-S, SPD-I, SPD-O
SPD-S (secure traffic) contains entries for all traffic subject to IPsec protection
SPD-O (outbound) contains entries for all outbound traffic that is to be bypassed or discarded.
SPD-I (inbound) is applied to inbound traffic that will be bypassed or discarded.
"inbound" and "outbound" have nothing to do with IP addresses. Since your
machine forwards packets, each packet is processed twice by IPsec and is
both
inbound and outbound :
first your packet is received on an interface, hence it is processed by
IPsec as
"inbound". Then it is forwarded and sent on another interface : it is
processed
by IPsec again, but as an "outbound" packet.
SDP实体指定报得方向,SDP被键入一个或多个选择器。
SDP包含这些实体有序的列表
| C |
|---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 | struct xfrm_policy
{
struct xfrm_policy *next; // 下一个策略
struct hlist_node bydst; // 按目的地址HASH的链表
struct hlist_node byidx; // 按索引号HASH的链表
/* This lock only affects elements except for entry. */
rwlock_t lock;
atomic_t refcnt;
struct timer_list timer;
u8 type;
u32 priority;
u32 index;
struct xfrm_selector selector;
struct xfrm_lifetime_cfg lft;
struct xfrm_lifetime_cur curlft;
struct dst_entry *bundles;
__u16 family;
__u8 action;
__u8 flags;
__u8 dead;
__u8 xfrm_nr;
struct xfrm_sec_ctx *security;
struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
};
|
经过实际测试,IP包经过ipsec时,是使用三元组(IP-dst,protocol,SPI)进行匹配。
SAD
the Security Association Database
包含安全服务的参数。
| C |
|---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 | struct xfrm_state
{
/* Note: bydst is re-used during gc */
// 每个状态结构挂接到三个HASH链表中
struct hlist_node bydst; // 按目的地址HASH
struct hlist_node bysrc; // 按源地址HASH
struct hlist_node byspi; // 按SPI值HASH
atomic_t refcnt; // 所有使用计数
spinlock_t lock; // 状态锁
struct xfrm_id id; // ID
struct xfrm_selector sel; // 状态选择子
u32 genid;
/* Key manger bits */
struct {
u8 state;
u8 dying;
u32 seq;
} km;
/* Parameters of this state. */
struct {
u32 reqid;
u8 mode;
u8 replay_window;
u8 aalgo, ealgo, calgo;
u8 flags;
u16 family;
xfrm_address_t saddr;
int header_len;
int trailer_len;
} props;
struct xfrm_lifetime_cfg lft; // 生存时间
/* Data for transformer */
struct xfrm_algo *aalg; // hash算法
struct xfrm_algo *ealg; // 加密算法
struct xfrm_algo *calg; // 压缩算法
/* Data for encapsulator */
struct xfrm_encap_tmpl *encap; // NAT-T封装信息
/* Data for care-of address */
xfrm_address_t *coaddr;
/* IPComp needs an IPIP tunnel for handling uncompressed packets */
struct xfrm_state *tunnel;
/* If a tunnel, number of users + 1 */
atomic_t tunnel_users;
/* State for replay detection */
struct xfrm_replay_state replay;
/* Replay detection state at the time we sent the last notification */
struct xfrm_replay_state preplay;
/* internal flag that only holds state for delayed aevent at the
* moment
*/
u32 xflags;
/* Replay detection notification settings */
u32 replay_maxage;
u32 replay_maxdiff;
/* Replay detection notification timer */
struct timer_list rtimer;
/* Statistics */
struct xfrm_stats stats;
struct xfrm_lifetime_cur curlft;
struct timer_list timer;
/* Last used time */
u64 lastused;
/* Reference to data common to all the instances of this
* transformer. */
struct xfrm_type *type;
struct xfrm_mode *mode;
/* Security context */
struct xfrm_sec_ctx *security;
/* Private data of this transformer, format is opaque,
* interpreted by xfrm_type methods. */
void *data;
};
|
SAD 安全关联数据库。
安全关联查找:
1. 根据SPI,目的IP和源IP,查找SAD,如果失败,执行步骤2。
2. 根据SPI和目的IP,查找SAD,如果失败,执行步骤3.
3. 只根据SPI查找SPI。
4. 否则,丢弃该报文,记录相关日志。
PAD
the Peer Authorization Database
提供SA管理协议和SPD之间的关联。