summaryrefslogtreecommitdiffstats
path: root/test/patches/scapy-2.4
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-04-11 15:14:07 +0000
committerDamjan Marion <dmarion@me.com>2019-04-16 15:54:31 +0000
commit47feb1146ec3b0e1cf2ebd83cd5211e1df261194 (patch)
tree602218094ef655d3c430ba29762ebf64d59f15d7 /test/patches/scapy-2.4
parent3cf215aab7237d44cf153b43d80a971be9300626 (diff)
IPSEC: support GCM in ESP
Change-Id: Id2ddb77b4ec3dd543d6e638bc882923f2bac011d Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'test/patches/scapy-2.4')
-rw-r--r--test/patches/scapy-2.4/ipsec.patch52
1 files changed, 37 insertions, 15 deletions
diff --git a/test/patches/scapy-2.4/ipsec.patch b/test/patches/scapy-2.4/ipsec.patch
index b19112db2b7..731fe3ccc25 100644
--- a/test/patches/scapy-2.4/ipsec.patch
+++ b/test/patches/scapy-2.4/ipsec.patch
@@ -1,8 +1,30 @@
diff --git a/scapy/layers/ipsec.py b/scapy/layers/ipsec.py
-index 69e7ae3b..b35da2b1 100644
+index 69e7ae3b..0c69ba1a 100644
--- a/scapy/layers/ipsec.py
+++ b/scapy/layers/ipsec.py
-@@ -518,12 +518,16 @@ class AuthAlgo(object):
+@@ -344,7 +344,8 @@ class CryptAlgo(object):
+ encryptor = cipher.encryptor()
+
+ if self.is_aead:
+- aad = struct.pack('!LL', esp.spi, esp.seq)
++ aad = struct.pack('!LQ' if sa.use_esn else '!LL',
++ esp.spi, esp.seq)
+ encryptor.authenticate_additional_data(aad)
+ data = encryptor.update(data) + encryptor.finalize()
+ data += encryptor.tag[:self.icv_size]
+@@ -381,9 +382,9 @@ class CryptAlgo(object):
+ if self.is_aead:
+ # Tag value check is done during the finalize method
+ decryptor.authenticate_additional_data(
+- struct.pack('!LL', esp.spi, esp.seq)
++ struct.pack('!LQ' if sa.use_esn else '!LL',
++ esp.spi, esp.seq)
+ )
+-
+ try:
+ data = decryptor.update(data) + decryptor.finalize()
+ except InvalidTag as err:
+@@ -518,12 +519,16 @@ class AuthAlgo(object):
else:
return self.mac(key, self.digestmod(), default_backend())
@@ -20,7 +42,7 @@ index 69e7ae3b..b35da2b1 100644
@return: the signed packet
"""
-@@ -534,16 +538,20 @@ class AuthAlgo(object):
+@@ -534,16 +539,20 @@ class AuthAlgo(object):
if pkt.haslayer(ESP):
mac.update(raw(pkt[ESP]))
@@ -42,7 +64,7 @@ index 69e7ae3b..b35da2b1 100644
"""
Check that the integrity check value (icv) of a packet is valid.
-@@ -574,6 +582,8 @@ class AuthAlgo(object):
+@@ -574,6 +583,8 @@ class AuthAlgo(object):
clone = zero_mutable_fields(pkt.copy(), sending=False)
mac.update(raw(clone))
@@ -51,7 +73,7 @@ index 69e7ae3b..b35da2b1 100644
computed_icv = mac.finalize()[:self.icv_size]
# XXX: Cannot use mac.verify because the ICV can be truncated
-@@ -757,7 +767,8 @@ class SecurityAssociation(object):
+@@ -757,7 +768,8 @@ class SecurityAssociation(object):
SUPPORTED_PROTOS = (IP, IPv6)
def __init__(self, proto, spi, seq_num=1, crypt_algo=None, crypt_key=None,
@@ -61,7 +83,7 @@ index 69e7ae3b..b35da2b1 100644
"""
@param proto: the IPsec proto to use (ESP or AH)
@param spi: the Security Parameters Index of this SA
-@@ -771,6 +782,7 @@ class SecurityAssociation(object):
+@@ -771,6 +783,7 @@ class SecurityAssociation(object):
to encapsulate the encrypted packets.
@param nat_t_header: an instance of a UDP header that will be used
for NAT-Traversal.
@@ -69,7 +91,7 @@ index 69e7ae3b..b35da2b1 100644
"""
if proto not in (ESP, AH, ESP.name, AH.name):
-@@ -782,6 +794,7 @@ class SecurityAssociation(object):
+@@ -782,6 +795,7 @@ class SecurityAssociation(object):
self.spi = spi
self.seq_num = seq_num
@@ -77,7 +99,7 @@ index 69e7ae3b..b35da2b1 100644
if crypt_algo:
if crypt_algo not in CRYPT_ALGOS:
-@@ -827,6 +840,17 @@ class SecurityAssociation(object):
+@@ -827,6 +841,17 @@ class SecurityAssociation(object):
raise TypeError('packet spi=0x%x does not match the SA spi=0x%x' %
(pkt.spi, self.spi))
@@ -88,14 +110,14 @@ index 69e7ae3b..b35da2b1 100644
+ upper = num >> 32
+
+ if self.use_esn:
-+ return lower, struct.pack(">I", upper)
++ return lower, struct.pack("!I", upper)
+ else:
+ return lower, None
+
def _encrypt_esp(self, pkt, seq_num=None, iv=None):
if iv is None:
-@@ -835,7 +859,8 @@ class SecurityAssociation(object):
+@@ -835,7 +860,8 @@ class SecurityAssociation(object):
if len(iv) != self.crypt_algo.iv_size:
raise TypeError('iv length must be %s' % self.crypt_algo.iv_size)
@@ -105,7 +127,7 @@ index 69e7ae3b..b35da2b1 100644
if self.tunnel_header:
tunnel = self.tunnel_header.copy()
-@@ -857,7 +882,7 @@ class SecurityAssociation(object):
+@@ -857,7 +883,7 @@ class SecurityAssociation(object):
esp = self.crypt_algo.pad(esp)
esp = self.crypt_algo.encrypt(self, esp, self.crypt_key)
@@ -114,7 +136,7 @@ index 69e7ae3b..b35da2b1 100644
if self.nat_t_header:
nat_t_header = self.nat_t_header.copy()
-@@ -884,7 +909,8 @@ class SecurityAssociation(object):
+@@ -884,7 +910,8 @@ class SecurityAssociation(object):
def _encrypt_ah(self, pkt, seq_num=None):
@@ -124,7 +146,7 @@ index 69e7ae3b..b35da2b1 100644
icv = b"\x00" * self.auth_algo.icv_size)
if self.tunnel_header:
-@@ -924,7 +950,8 @@ class SecurityAssociation(object):
+@@ -924,7 +951,8 @@ class SecurityAssociation(object):
else:
ip_header.plen = len(ip_header.payload) + len(ah) + len(payload)
@@ -134,7 +156,7 @@ index 69e7ae3b..b35da2b1 100644
# sequence number must always change, unless specified by the user
if seq_num is None:
-@@ -955,11 +982,12 @@ class SecurityAssociation(object):
+@@ -955,11 +983,12 @@ class SecurityAssociation(object):
def _decrypt_esp(self, pkt, verify=True):
@@ -148,7 +170,7 @@ index 69e7ae3b..b35da2b1 100644
esp = self.crypt_algo.decrypt(self, encrypted, self.crypt_key,
self.crypt_algo.icv_size or
-@@ -998,9 +1026,11 @@ class SecurityAssociation(object):
+@@ -998,9 +1027,11 @@ class SecurityAssociation(object):
def _decrypt_ah(self, pkt, verify=True):