预备

首先提及一个概念叫重放攻击,对应的机制叫做: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)

见包结构:

   0                   1                   2                   30 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|               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 (0-255 bytes)        |+-+-+-+-+-+-+-+-+-+-+-+-+-+     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|                               |  Pad Length   | Next Header   |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|         Integrity Check Value-ICV   (variable)                |~                                                               ~|                                                               |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+What    What    What# of     Requ'd  Encrypt Integ    isbytes      [1]   Covers  Covers  Xmtd------   ------  ------  ------  ------SPI                       4        M              Y     plainSeq# (low-order bits)     4        M              Y     plain       p------ aIV                     variable    O              Y     plain     | yIP datagram [2]        variable  M or D    Y      Y     cipher[3] |-lTFC padding [4]        variable    O       Y      Y     cipher[3] | o------ aPadding                 0-255      M       Y      Y     cipher[3]   dPad Length                1        M       Y      Y     cipher[3]Next Header               1        M       Y      Y     cipher[3]Seq# (high-order bits)    4     if ESN [5]        Y     not xmtdICV Padding            variable if need           Y     not xmtdICV                    variable   M [6]                 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 32 bits of thesequence number are transmitted in the Sequence Number field,although both sender and receiver maintain full 64-bit ESN counters.The high order 32 bits are included in the integrity check in analgorithm/mode-specific fashion, e.g., the high-order 32 bits may beappended after the Next Header field when a separate integrityalgorithm 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.1.  Triggering Re-synchronizationFor each SA, the receiver records the number of consecutive packetsthat fail authentication.  This count is used to trigger the re-synchronization process, which should be performed in the backgroundor using a separate processor.  Receipt of a valid packet on the SAresets the counter to zero.  The value used to trigger the re-synchronization process is a local parameter.  There is norequirement to support distinct trigger values for different SAs,although an implementer may choose to do so.A3.2.  Re-synchronization ProcessWhen the above trigger point is reached, a "bad" packet is selectedfor which authentication is retried using successively larger valuesfor the upper half of the sequence number (Seqh).  These values aregenerated by incrementing by one for each retry.  The number ofretries should be limited, in case this is a packet from the "past"or a bogus packet.  The limit value is a local parameter.  (Becausethe Seqh value is implicitly placed after the ESP (or AH) payload, itmay be possible to optimize this procedure by executing the integrityalgorithm over the packet up to the endpoint of the payload, thencompute different candidate ICVs by varying the value of Seqh.)Successful authentication of a packet via this procedure resets theconsecutive failure count and sets the value of T to that of thereceived 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 orutilize an additional processor, this solution does not impacttraffic processing and a denial of service attack cannot divertresources away from traffic processing.

转载于:https://www.cnblogs.com/hugetong/p/10524537.html

[crypto][ipsec] 简述ESP协议的sequence number机制相关推荐

  1. 协议簇:TCP 解析: Sequence Number

    简介 序列号(Sequence Number) 是 TCP 协议中非常重要的一个概念,以至于不得不专门来学习一下.这篇文章我们就来解开他的面纱. 在 TCP 的设计中,通过TCP协议发送的每个字节都对 ...

  2. 计算机网络sequence number,TCP协议中SequenceNumber和Ack Numbe

    Sequence Number lzyws7393074532892018-04-25 Number Sequence qq_391789932452017-09-21 理解TCP序列号(Sequen ...

  3. 网络协议 — IPSec 安全隧道协议族

    目录 文章目录 目录 IPSec 安全隧道协议族 封装协议 Authentication Header 协议 Encapsulating Security Payload 协议 封装模式 Transp ...

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

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

  5. 转:理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    http://blog.csdn.net/a19881029/article/details/38091243 原文见:http://packetlife.net/blog/2010/jun/7/un ...

  6. 对tcp三次握手的详解之 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    重要 !!!!!!!!!       转载自[怀揣梦想,努力前行] 对tcp三次握手的详解之 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number) ...

  7. TCP 中的Sequence Number

    我们关注的就是序号和确认号 这二者也是 TCP 实现可靠传输的方式.下图是一次随便抓包的截图(相对序列号) 意义 在TCP传输中,每一个字节都是有序号的,从0开始.通过序号的方式保存数据的顺序,接收端 ...

  8. 网络安全-IPSec(互联网安全协议)

    互联网安全协议(Internet Protocol Security,IPSec)是一个应用在OSI网络层保护基于TCP或UDP的协议簇(主要有AH.ESP.SA.IKE),通过对IP协议的分组进行加 ...

  9. sqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 40 expe

    sqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 40 expe ...

最新文章

  1. Java Websocket实例【服务端与客户端实现全双工通讯】
  2. The ultimate end-to-end tutorial to create and deploy a fully decentralized Dapp in ethereum
  3. JAVA元注解@interface详解(@Target,@Documented,@Retention,@Inherited)
  4. js中的数组基本知识
  5. 面向对象程序设计中“超类”和“子类”概念的来历
  6. pythonfor循环输入_python的for循环
  7. 学生阅读作业三——对习而学教学方式的思考
  8. merge r语言daframe_R语言:数据框
  9. Python爬取虎扑NBA球员信息
  10. 135端口入侵教程(仅学习用)
  11. 计算机音乐研究生专业,约翰霍普金斯大学计算机音乐音乐硕士研究生申请要求及申请材料要求清单...
  12. iphone11没有锁屏声音_iphone11屏幕解锁按键音怎么关闭-互盾苹果恢复精灵
  13. 固定资产管理系统能给行政和IT人员带来什么?
  14. 【Proteus仿真】【51单片机】音乐盒电子琴设计
  15. winform中添加Windows Media Player
  16. Code Combat学习心得(Kithgard地牢45关Mightier Than the Sword)
  17. 金岩石:陈晓失误已铸成大错
  18. 密码算法(SM1、SM2、SM3、SM4、同态加密、密态计算、隐私计算和安全多方计算)
  19. Android运行时Crash自动恢复框架:Recovery
  20. 触摸屏基本原理介绍【转】

热门文章

  1. jquery插件合集之图片裁剪
  2. javascript框架比较(三)
  3. 吴恩达深度学习 —— 2.4 梯度下降
  4. 牛客网刷题 --- 输入输出数据处理
  5. 前n个自然数的平方和的求解方法--经典与独创
  6. OpenCV-数字图像处理之直方图均衡化
  7. 棋盘覆盖-分治法(代码实现)
  8. 包管理器Bower使用手册之一
  9. 打造超炫的专属Eclipse
  10. STM32 - 定时器的设定 - 基础- 02 - Capture/compare channels 和相关设置寄存器 - 和STM32缩写词条解释