预备

首先提及一个概念叫重放攻击,对应的机制叫做:anti-replay

https://en.wikipedia.org/wiki/Anti-replay

IPsec协议的anti-replay特性就是用来应对重放攻击的一种机制,方法是:

增加两个机制:序列号(seqence number)和收包窗口(sliding window)

发包方从0开始计数,每发一个包就把序号加1。 收包方拥有一个长度为N的滑动窗口,序号在窗口外的包都认为是无效包。

序号在窗口内的重复包,也被认为是无效包。窗口下边界处的包会导致窗口向前滑动。

以下内容都在ESP内讨论。

基于前文,我们已经了解到了ESP内的两个概念seq num,reply window,和一个属性anti-replay

seq num

是在报文内的,由发包者决定,并加到报文上。见图:

reply window

replay window是收包方本地的,自维护不协商。

anti-replay

anti-replay可以理解为是一个特性。

RFC中规定任何IPsec实现中都必须实现,且默认开启,不可以协商。 但是接收端可以关掉这个特效。(这好像矛盾了??--!)

另外,ipsec还支持多播和单播,这个时候以上讨论的内容都没有区别。

但是同时ipsec还支持多个sender共用一个SA。在这种情况下,anti-replay就是失效的,自然seq num和reply window也就没有用了。

当anti-replay生效的时候,seq number满了之后就只能重协商chlidsa。

当anti-replay不生效的是,sender不再关心seq number,就一直加加加,然后溢出就变成0.

于是,这里有了一个新的问题,

seq number满了就要重协商。看包我们发现这个字段是uint32的,所以,在高速网络中,每2^32个包就要重协商一次。

为了解决这个问题,现在引入一个新的概念,叫做:Extended Sequence Number(ESN)

见包结构:


   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Security Parameters Index (SPI) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---
| IV (optional) | ^ p
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | a
| Rest of Payload Data (variable) | | y
~ ~ | l
| | | o
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | a
| | TFC Padding * (optional, variable) | v d
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---
| | Padding (- bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Pad Length | Next Header |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Integrity Check Value-ICV (variable) |
~ ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ What What What
# of Requ'd Encrypt Integ is
bytes [] Covers Covers Xmtd
------ ------ ------ ------ ------
SPI M Y plain
Seq# (low-order bits) M Y plain p
------ a
IV variable O Y plain | y
IP datagram [] variable M or D Y Y cipher[] |-l
TFC padding [] variable O Y Y cipher[] | o
------ a
Padding - M Y Y cipher[] d
Pad Length M Y Y cipher[]
Next Header M Y Y cipher[]
Seq# (high-order bits) if ESN [] Y not xmtd
ICV Padding variable if need Y not xmtd
ICV variable M [] plain

这样的话,seq number便扩展到了64个bit。

ESN塞在了Next Header的后面。包头里面的seq number和原来一样是明文传输的,用来存这个数的低32位。 ESN是密文传输的(或者不传输),用来存储这个数的高32位。

需要注意的是,这个地方还有点复杂我还没有深入分析。这个ESN在不同的场景下的作用好像还不一样。还会被用于做完整性验证信息?

详见:

https://tools.ietf.org/html/rfc4303#section-2.2

https://tools.ietf.org/html/rfc4303#section-3.3.2.2

https://tools.ietf.org/html/rfc4303#section-3.4.3

二点一

ESN number的高32bit会被双方计数维护,不会被放在报文的payload里参与传输。但是在计算消息认证码的时候,会把它放进去一起参与计算。

https://tools.ietf.org/html/rfc4303#section-3.3.3

   If ESN (see Appendix) is selected, only the low-order  bits of the
sequence number are transmitted in the Sequence Number field,
although both sender and receiver maintain full -bit ESN counters.
The high order bits are included in the integrity check in an
algorithm/mode-specific fashion, e.g., the high-order bits may be
appended after the Next Header field when a separate integrity
algorithm is employed.

见下图,这是一张启用了ESN的esp包结构,与没有ESN的包,并没有什么区别。

丢包与乱序。

https://tools.ietf.org/html/rfc4303#page-38

在这个机制里,有几个值W(anti window的大小),T(合法包的seq的上限),B(合法包的seq的下限)

当累计的连续的不合法包的数量(T-B)大于2^32个的时候,将触发ESP的重认证(re-synchronization)机制。收到了一个合法包之后,计数将被重置为0

为什么是,2^32这么大的一个数呢?

因为ESP认为,上层应该会更早的感知链路出来问题。如TCP会自行发现。有交互的UDP,应用层也会发现。

这里的re-synchronization机制只针对一种情况,就是udp单侧发包,对方无回应的应用场景。

写到这里。。突然发现后边的内容理解的不是很好。。。就先这样了。。。。

到底re-synchronization机制是什么??

TO BE continue

A3..  Triggering Re-synchronization

   For each SA, the receiver records the number of consecutive packets
that fail authentication. This count is used to trigger the re-
synchronization process, which should be performed in the background
or using a separate processor. Receipt of a valid packet on the SA
resets the counter to zero. The value used to trigger the re-
synchronization process is a local parameter. There is no
requirement to support distinct trigger values for different SAs,
although an implementer may choose to do so. A3.. Re-synchronization Process When the above trigger point is reached, a "bad" packet is selected
for which authentication is retried using successively larger values
for the upper half of the sequence number (Seqh). These values are
generated by incrementing by one for each retry. The number of
retries should be limited, in case this is a packet from the "past"
or a bogus packet. The limit value is a local parameter. (Because
the Seqh value is implicitly placed after the ESP (or AH) payload, it
may be possible to optimize this procedure by executing the integrity
algorithm over the packet up to the endpoint of the payload, then
compute different candidate ICVs by varying the value of Seqh.)
Successful authentication of a packet via this procedure resets the
consecutive failure count and sets the value of T to that of the
received packet. This solution requires support only on the part of the receiver,
thereby allowing for backward compatibility. Also, because re-
synchronization efforts would either occur in the background or
utilize an additional processor, this solution does not impact
traffic processing and a denial of service attack cannot divert
resources away from traffic processing.

[crypto][ipsec] 简述ESP协议的sequence number机制的更多相关文章

  1. 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ from:ht ...

  2. [转] 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    点击阅读原译文 原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ ...

  3. mysql oom之后的page 447 log sequence number 292344272 is in the future

    mysql oom之后,重启时发生130517 16:00:10 InnoDB: Error: page 447 log sequence number 292344272InnoDB: is in ...

  4. Sequence Number

    1570: Sequence Number 时间限制: 1 Sec  内存限制: 1280 MB 题目描述 In Linear algebra, we have learned the definit ...

  5. InnoDB: The log sequence number in ibdata files does not match

    InnoDB: The log sequence number in ibdata files does not matchInnoDB的:在ibdata文件的日志序列号不匹配 可能ibdata文件损 ...

  6. hzau 1205 Sequence Number(二分)

    G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...

  7. Thread <number> cannot allocate new log, sequence <number>浅析

    有时候,你会在ORACLE数据库的告警日志中发现"Thread <number> cannot allocate new log, sequence <number> ...

  8. ORA-02287: sequence number not allowed here问题的解决

    当插入值需要从另外一张表中检索得到的时候,如下语法的sql语句已经不能完成该功能:insert into my_table(id, name) values ((select seq_my_table ...

  9. Python之路迭代器协议、for循环机制、三元运算、列表解析式、生成器

    Python之路迭代器协议.for循环机制.三元运算.列表解析式.生成器 一.迭代器协议 a迭代的含义 迭代器即迭代的工具,那什么是迭代呢? #迭代是一个重复的过程,每次重复即一次迭代,并且每次迭代的 ...

随机推荐

  1. mysl 常用函数 union all if ifnull exists case when

    1.union all UNION 操作符用于合并两个或多个 SELECT 语句的结果集.请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 S ...

  2. C++的一些小Tip

    string转数字: 一种是转换为char*后再使用atoi:atoi(s.c_str()).这个方法的神奇之处在于,如果s是负数也能顺利转化,但是,在leetcode显示,自己先判断是不是负数的话计 ...

  3. JQuery EasyUI 初始

    基于jQuery的用户界面插件集合 1. jQuery easyui提供了一个完整的组件的集合,包括强大的DataGrid,树网格,面板.用户可以使用他们一起,或者只是用一些组件,组合和构建他想要的跨 ...

  4. 在 VsCode 中自定义代码补全

    前言 之前公司的 Vscode 折腾成功过,如今给自己家装一个忘记怎么定义了,故回忆一下写个博文记录 代码补全顾名思义就是输入一两个字母自动提示相关的联想操作,由于VsCode非常精简所以很多联想没有 ...

  5. class-dump 安装使用详解

    顾名思义,它的作用就是把Mach-O文件的class信息给dump出来(把类信息给导出来),生成对应的.h头文件 官方地址:http://stevenygard.com/projects/class- ...

  6. 【java】Java相关学习参考链接(持续更新)

    How to do in java,https://howtodoinjava.com/,Java手册,分版本,并且有每个版本的新特性的详细解析. Java World,https://www.jav ...

  7. Razor---服务器端标记语言

    Razor 是一种允许您向网页中嵌入基于服务器的代码(Visual Basic 和 C#)的标记语法<ul> @for (int i = 0; i < 10; i++) { < ...

  8. 数位dp-入门模板题 hdu2089

    #include<bits/stdc++.h> using namespace std; ][],n,m; void init(){//dp[i][j]:i位的数,最高位是j dp[][] ...

  9. java设计模式自我总结---适配器模式

    上一篇博客说完了 java 23 中设计模式中的五种 创建性模式,由于篇幅过长,新开一贴今天开始学习结构型模式, 结构型模式包括以下七种:适配器模式.装饰模式.代理模式.外观模式.桥接模式.组合模式. ...

  10. phonegap走起

    最近phonegap已发布4.0的了..速度提升了不少,很给力.小白们可以看下如何构建phonegap开发平台. 此文将说明如何建立一个可以被vs2015打开的phonegap的项目.我还会加上ion ...