1*7dc08ffcSJunyu Lai############################## 2*7dc08ffcSJunyu Lai% IPsec layer regression tests 3*7dc08ffcSJunyu Lai############################## 4*7dc08ffcSJunyu Lai 5*7dc08ffcSJunyu Lai~ crypto 6*7dc08ffcSJunyu Lai 7*7dc08ffcSJunyu Lai############################################################################### 8*7dc08ffcSJunyu Lai+ IPv4 / ESP - Transport - Encryption Algorithms 9*7dc08ffcSJunyu Lai 10*7dc08ffcSJunyu Lai####################################### 11*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - NULL 12*7dc08ffcSJunyu Lai~ -crypto 13*7dc08ffcSJunyu Lai 14*7dc08ffcSJunyu Laiimport socket 15*7dc08ffcSJunyu Lai 16*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 17*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 18*7dc08ffcSJunyu Laip /= Raw('testdata') 19*7dc08ffcSJunyu Laip = IP(raw(p)) 20*7dc08ffcSJunyu Laip 21*7dc08ffcSJunyu Lai 22*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 23*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 24*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 25*7dc08ffcSJunyu Lai 26*7dc08ffcSJunyu Laie = sa.encrypt(p) 27*7dc08ffcSJunyu Laie 28*7dc08ffcSJunyu Lai 29*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 30*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 31*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 32*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 33*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 34*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 35*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 36*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 37*7dc08ffcSJunyu Lai 38*7dc08ffcSJunyu Laid = sa.decrypt(e) 39*7dc08ffcSJunyu Laid 40*7dc08ffcSJunyu Lai 41*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 42*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 43*7dc08ffcSJunyu Lai 44*7dc08ffcSJunyu Lai####################################### 45*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - DES - NULL 46*7dc08ffcSJunyu Lai 47*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 48*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 49*7dc08ffcSJunyu Laip /= Raw('testdata') 50*7dc08ffcSJunyu Laip = IP(raw(p)) 51*7dc08ffcSJunyu Laip 52*7dc08ffcSJunyu Lai 53*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 54*7dc08ffcSJunyu Lai crypt_algo='DES', crypt_key=b'8bytekey', 55*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 56*7dc08ffcSJunyu Lai 57*7dc08ffcSJunyu Laie = sa.encrypt(p) 58*7dc08ffcSJunyu Laie 59*7dc08ffcSJunyu Lai 60*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 61*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 62*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 63*7dc08ffcSJunyu Lai* the encrypted packet should have an ESP layer 64*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 65*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 66*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 67*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 68*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 69*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 70*7dc08ffcSJunyu Lai 71*7dc08ffcSJunyu Laid = sa.decrypt(e) 72*7dc08ffcSJunyu Laid 73*7dc08ffcSJunyu Lai 74*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 75*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 76*7dc08ffcSJunyu Lai 77*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 78*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 79*7dc08ffcSJunyu Lai# mode tunnel enc 'cbc(des)' '0x38627974656b6579' auth digest_null '' flag align4 80*7dc08ffcSJunyu Lairef = IP() \ 81*7dc08ffcSJunyu Lai / ESP(spi=0x222, 82*7dc08ffcSJunyu Lai data=b'\x0f\x6d\x2f\x3d\x1e\xc1\x0b\xc2\xb6\x8f\xfd\x67\x39\xc0\x96\x2c' 83*7dc08ffcSJunyu Lai b'\x17\x79\x88\xf6\xbc\x4d\xf7\x45\xd8\x36\x63\x86\xcd\x08\x7c\x08' 84*7dc08ffcSJunyu Lai b'\x2b\xf8\xa2\x91\x18\x21\x88\xd9\x26\x00\xc5\x21\x24\xbf\x8f\xf5' 85*7dc08ffcSJunyu Lai b'\x6c\x47\xb0\x3a\x8e\xdb\x75\x21\xd9\x33\x85\x5a\x15\xc6\x31\x00' 86*7dc08ffcSJunyu Lai b'\x1c\xef\x3e\x12\xce\x70\xec\x8f\x48\xc7\x81\x9b\x66\xcb\xf5\x39' 87*7dc08ffcSJunyu Lai b'\x91\xb3\x8e\x72\xfb\x7f\x64\x65\x6c\xf4\xa9\xf2\x5e\x63\x2f\x60', 88*7dc08ffcSJunyu Lai seq=1) 89*7dc08ffcSJunyu Lai 90*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 91*7dc08ffcSJunyu Laid_ref 92*7dc08ffcSJunyu Lai 93*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 94*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 95*7dc08ffcSJunyu Lai 96*7dc08ffcSJunyu Lai####################################### 97*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - 3DES - NULL 98*7dc08ffcSJunyu Lai 99*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 100*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 101*7dc08ffcSJunyu Laip /= Raw('testdata') 102*7dc08ffcSJunyu Laip = IP(raw(p)) 103*7dc08ffcSJunyu Laip 104*7dc08ffcSJunyu Lai 105*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 106*7dc08ffcSJunyu Lai crypt_algo='3DES', crypt_key=b'threedifferent8byteskeys', 107*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 108*7dc08ffcSJunyu Lai 109*7dc08ffcSJunyu Laie = sa.encrypt(p) 110*7dc08ffcSJunyu Laie 111*7dc08ffcSJunyu Lai 112*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 113*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 114*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 115*7dc08ffcSJunyu Lai* the encrypted packet should have an ESP layer 116*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 117*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 118*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 119*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 120*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 121*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 122*7dc08ffcSJunyu Lai 123*7dc08ffcSJunyu Laid = sa.decrypt(e) 124*7dc08ffcSJunyu Laid 125*7dc08ffcSJunyu Lai 126*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 127*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 128*7dc08ffcSJunyu Lai 129*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 130*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 131*7dc08ffcSJunyu Lai# mode tunnel enc 'cbc(des3_ede)' '0x7468726565646966666572656e743862797465736b657973' auth digest_null '' flag align4 132*7dc08ffcSJunyu Lairef = IP() \ 133*7dc08ffcSJunyu Lai / ESP(spi=0x222, 134*7dc08ffcSJunyu Lai data=b'\x36\x5c\x9b\x41\x37\xc8\x59\x1e\x39\x63\xe8\x6b\xf7\x0d\x97\x54' 135*7dc08ffcSJunyu Lai b'\x13\x84\xf6\x81\x66\x19\xe7\xcb\x75\x94\xf1\x0b\x8e\xa3\xf1\xa0' 136*7dc08ffcSJunyu Lai b'\x3e\x88\x51\xc4\x50\xd0\xa9\x1f\x16\x25\xc6\xbd\xe9\x0b\xdc\xae' 137*7dc08ffcSJunyu Lai b'\xf8\x13\x00\xa3\x8c\x53\xee\x1c\x96\xc0\xfe\x99\x70\xab\x94\x77' 138*7dc08ffcSJunyu Lai b'\xd7\xc4\xe8\xfd\x9f\x96\x28\xb8\x95\x20\x86\x7b\x19\xbc\x8f\xf5' 139*7dc08ffcSJunyu Lai b'\x96\xb0\x7e\xcc\x04\x83\xae\x4d\xa3\xba\x1d\x44\xf0\xba\x2e\xcd', 140*7dc08ffcSJunyu Lai seq=1) 141*7dc08ffcSJunyu Lai 142*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 143*7dc08ffcSJunyu Laid_ref 144*7dc08ffcSJunyu Lai 145*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 146*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 147*7dc08ffcSJunyu Lai 148*7dc08ffcSJunyu Lai####################################### 149*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-CBC - NULL 150*7dc08ffcSJunyu Lai 151*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 152*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 153*7dc08ffcSJunyu Laip /= Raw('testdata') 154*7dc08ffcSJunyu Laip = IP(raw(p)) 155*7dc08ffcSJunyu Laip 156*7dc08ffcSJunyu Lai 157*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 158*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 159*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 160*7dc08ffcSJunyu Lai 161*7dc08ffcSJunyu Laie = sa.encrypt(p) 162*7dc08ffcSJunyu Laie 163*7dc08ffcSJunyu Lai 164*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 165*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 166*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 167*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 168*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 169*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 170*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 171*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 172*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 173*7dc08ffcSJunyu Lai 174*7dc08ffcSJunyu Laid = sa.decrypt(e) 175*7dc08ffcSJunyu Laid 176*7dc08ffcSJunyu Lai 177*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 178*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 179*7dc08ffcSJunyu Lai 180*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 181*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 182*7dc08ffcSJunyu Lai# mode tunnel enc 'cbc(aes)' '0x7369787465656e6279746573206b6579' auth digest_null '' flag align4 183*7dc08ffcSJunyu Lairef = IP() \ 184*7dc08ffcSJunyu Lai / ESP(spi=0x222, 185*7dc08ffcSJunyu Lai data=b'\x08\x2f\x94\xe6\x53\xd8\x8e\x13\x70\xe8\xff\x61\x52\x90\x27\x3c' 186*7dc08ffcSJunyu Lai b'\xf2\xb4\x1f\x75\xd2\xa0\xac\xae\x1c\xa8\x5e\x1c\x78\x21\x4c\x7f' 187*7dc08ffcSJunyu Lai b'\xc3\x30\x17\x6a\x8d\xf3\xb1\xa7\xd1\xa8\x42\x01\xd6\x8d\x2d\x7e' 188*7dc08ffcSJunyu Lai b'\x5d\x06\xdf\xaa\x05\x27\x42\xb1\x00\x12\xcf\xff\x64\x02\x5a\x40' 189*7dc08ffcSJunyu Lai b'\xcd\xca\x1b\x91\xba\xf8\xc8\x59\xe7\xbd\x4d\x19\xb4\x8d\x39\x25' 190*7dc08ffcSJunyu Lai b'\x6c\x73\xf1\x2d\xaa\xee\xe1\x0b\x71\xcd\xfc\x11\x1d\x56\xce\x60' 191*7dc08ffcSJunyu Lai b'\xed\xd2\x32\x87\xd4\x90\xc3\xf5\x31\x47\x97\x69\x83\x82\x6d\x38', 192*7dc08ffcSJunyu Lai seq=1) 193*7dc08ffcSJunyu Lai 194*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 195*7dc08ffcSJunyu Laid_ref 196*7dc08ffcSJunyu Lai 197*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 198*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 199*7dc08ffcSJunyu Lai 200*7dc08ffcSJunyu Lai####################################### 201*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-CTR - NULL 202*7dc08ffcSJunyu Lai 203*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 204*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 205*7dc08ffcSJunyu Laip /= Raw('testdata') 206*7dc08ffcSJunyu Laip = IP(raw(p)) 207*7dc08ffcSJunyu Laip 208*7dc08ffcSJunyu Lai 209*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 210*7dc08ffcSJunyu Lai crypt_algo='AES-CTR', crypt_key=b'16bytekey+4bytenonce', 211*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 212*7dc08ffcSJunyu Lai 213*7dc08ffcSJunyu Laie = sa.encrypt(p) 214*7dc08ffcSJunyu Laie 215*7dc08ffcSJunyu Lai 216*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 217*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 218*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 219*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 220*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 221*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 222*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 223*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 224*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 225*7dc08ffcSJunyu Lai 226*7dc08ffcSJunyu Laid = sa.decrypt(e) 227*7dc08ffcSJunyu Laid 228*7dc08ffcSJunyu Lai 229*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 230*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 231*7dc08ffcSJunyu Lai 232*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 233*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 234*7dc08ffcSJunyu Lai# mode tunnel enc 'rfc3686(ctr(aes))' '0x3136627974656b65792b34627974656e6f6e6365' auth digest_null '' flag align4 235*7dc08ffcSJunyu Lairef = IP() \ 236*7dc08ffcSJunyu Lai / ESP(spi=0x222, 237*7dc08ffcSJunyu Lai data=b'\xc4\xca\x09\x0f\x8b\xd3\x05\x3d\xac\x5a\x2f\x87\xca\x71\x10\x01' 238*7dc08ffcSJunyu Lai b'\xa7\x95\xc9\x07\xcc\xd4\x05\x58\x65\x23\x22\x4b\x63\x9b\x1f\xef' 239*7dc08ffcSJunyu Lai b'\x55\xb9\x1a\x91\x52\x76\x00\xf7\x94\x7b\x1d\xe1\x8e\x03\x2e\x85' 240*7dc08ffcSJunyu Lai b'\xad\xdd\x83\x22\x8a\xc3\x88\x6e\x85\xf5\x9b\xed\xa9\x6e\xb1\xc3' 241*7dc08ffcSJunyu Lai b'\x78\x00\x2f\xcd\x77\xe8\x3e\xec\x0e\x77\x94\xb2\x9b\x0f\x64\x5e' 242*7dc08ffcSJunyu Lai b'\x09\x83\x03\x7d\x83\x22\x39\xbb\x94\x66\xae\x9f\xbf\x01\xda\xfb', 243*7dc08ffcSJunyu Lai seq=1) 244*7dc08ffcSJunyu Lai 245*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 246*7dc08ffcSJunyu Laid_ref 247*7dc08ffcSJunyu Lai 248*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 249*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 250*7dc08ffcSJunyu Lai 251*7dc08ffcSJunyu Lai####################################### 252*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - Blowfish - NULL 253*7dc08ffcSJunyu Lai 254*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 255*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 256*7dc08ffcSJunyu Laip /= Raw('testdata') 257*7dc08ffcSJunyu Laip = IP(raw(p)) 258*7dc08ffcSJunyu Laip 259*7dc08ffcSJunyu Lai 260*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 261*7dc08ffcSJunyu Lai crypt_algo='Blowfish', crypt_key=b'sixteenbytes key', 262*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 263*7dc08ffcSJunyu Lai 264*7dc08ffcSJunyu Laie = sa.encrypt(p) 265*7dc08ffcSJunyu Laie 266*7dc08ffcSJunyu Lai 267*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 268*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 269*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 270*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 271*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 272*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 273*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 274*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 275*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 276*7dc08ffcSJunyu Lai 277*7dc08ffcSJunyu Laid = sa.decrypt(e) 278*7dc08ffcSJunyu Laid 279*7dc08ffcSJunyu Lai 280*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 281*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 282*7dc08ffcSJunyu Lai 283*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 284*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 285*7dc08ffcSJunyu Lai# mode tunnel enc 'cbc(blowfish)' '0x7369787465656e6279746573206b6579' auth digest_null '' flag align4 286*7dc08ffcSJunyu Lairef = IP() \ 287*7dc08ffcSJunyu Lai / ESP(spi=0x222, 288*7dc08ffcSJunyu Lai data=b'\x93\x9f\x5a\x10\x55\x57\x30\xa0\xb4\x00\x72\x1e\x46\x42\x46\x20' 289*7dc08ffcSJunyu Lai b'\xbc\x01\xef\xc3\x79\xcc\x3e\x55\x64\xba\x09\xc2\x6a\x5a\x5c\xb3' 290*7dc08ffcSJunyu Lai b'\xcc\xb5\xd5\x87\x82\xb0\x0a\x94\x58\xfc\x50\x37\x40\xe1\x03\xd3' 291*7dc08ffcSJunyu Lai b'\x4a\x09\xb2\x23\x53\x56\xa4\x45\x4c\xbb\x81\x1c\xdb\x31\xa7\x67' 292*7dc08ffcSJunyu Lai b'\xbd\x38\x8e\xba\x55\xd9\x1f\xf1\x3c\xeb\x07\x4c\x02\xb0\x3e\xc5' 293*7dc08ffcSJunyu Lai b'\xf6\x60\xdd\x68\xe1\xd4\xec\xee\x27\xc0\x6d\x1a\x80\xe2\xcc\x7d', 294*7dc08ffcSJunyu Lai seq=1) 295*7dc08ffcSJunyu Lai 296*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 297*7dc08ffcSJunyu Laid_ref 298*7dc08ffcSJunyu Lai 299*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 300*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 301*7dc08ffcSJunyu Lai 302*7dc08ffcSJunyu Lai####################################### 303*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - CAST - NULL 304*7dc08ffcSJunyu Lai 305*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 306*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 307*7dc08ffcSJunyu Laip /= Raw('testdata') 308*7dc08ffcSJunyu Laip = IP(raw(p)) 309*7dc08ffcSJunyu Laip 310*7dc08ffcSJunyu Lai 311*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 312*7dc08ffcSJunyu Lai crypt_algo='CAST', crypt_key=b'sixteenbytes key', 313*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 314*7dc08ffcSJunyu Lai 315*7dc08ffcSJunyu Laie = sa.encrypt(p) 316*7dc08ffcSJunyu Laie 317*7dc08ffcSJunyu Lai 318*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 319*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 320*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 321*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 322*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 323*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 324*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 325*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 326*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 327*7dc08ffcSJunyu Lai 328*7dc08ffcSJunyu Laid = sa.decrypt(e) 329*7dc08ffcSJunyu Laid 330*7dc08ffcSJunyu Lai 331*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 332*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 333*7dc08ffcSJunyu Lai 334*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 335*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 336*7dc08ffcSJunyu Lai# mode tunnel enc 'cbc(cast5)' '0x7369787465656e6279746573206b6579' auth digest_null '' flag align4 337*7dc08ffcSJunyu Lairef = IP() \ 338*7dc08ffcSJunyu Lai / ESP(spi=0x222, 339*7dc08ffcSJunyu Lai data=b'\xcd\x4a\x46\x05\x51\x54\x73\x35\x1d\xad\x4b\x10\xc1\x15\xe2\x70' 340*7dc08ffcSJunyu Lai b'\xbc\x9c\x53\x8f\x4d\x1c\x87\x1a\xc1\xb0\xdf\x80\xd1\x0c\xa4\x59' 341*7dc08ffcSJunyu Lai b'\xe6\x50\xde\x46\xdb\x3f\x28\xc2\xda\x6c\x2b\x81\x5e\x7c\x7b\x4f' 342*7dc08ffcSJunyu Lai b'\xbc\x8d\xc1\x6d\x4a\x2b\x04\x91\x9e\xc4\x0b\xba\x05\xba\x3b\x71' 343*7dc08ffcSJunyu Lai b'\xac\xe3\x16\xcf\x7f\x00\xc5\x87\x7d\x72\x48\xe6\x5b\x43\x19\x24' 344*7dc08ffcSJunyu Lai b'\xae\xa6\x2c\xcc\xad\xbf\x37\x6c\x6e\xea\x71\x67\x73\xd6\x11\x9f', 345*7dc08ffcSJunyu Lai seq=1) 346*7dc08ffcSJunyu Lai 347*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 348*7dc08ffcSJunyu Laid_ref 349*7dc08ffcSJunyu Lai 350*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 351*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 352*7dc08ffcSJunyu Lai 353*7dc08ffcSJunyu Lai############################################################################### 354*7dc08ffcSJunyu Lai+ IPv4 / ESP - Tunnel - Encryption Algorithms 355*7dc08ffcSJunyu Lai 356*7dc08ffcSJunyu Lai####################################### 357*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - NULL 358*7dc08ffcSJunyu Lai~ -crypto 359*7dc08ffcSJunyu Lai 360*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 361*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 362*7dc08ffcSJunyu Laip /= Raw('testdata') 363*7dc08ffcSJunyu Laip = IP(raw(p)) 364*7dc08ffcSJunyu Laip 365*7dc08ffcSJunyu Lai 366*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 367*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 368*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 369*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 370*7dc08ffcSJunyu Lai 371*7dc08ffcSJunyu Laie = sa.encrypt(p) 372*7dc08ffcSJunyu Laie 373*7dc08ffcSJunyu Lai 374*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 375*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 376*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 377*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 378*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 379*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 380*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 381*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 382*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 383*7dc08ffcSJunyu Lai 384*7dc08ffcSJunyu Laid = sa.decrypt(e) 385*7dc08ffcSJunyu Laid 386*7dc08ffcSJunyu Lai 387*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 388*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 389*7dc08ffcSJunyu Lai 390*7dc08ffcSJunyu Lai####################################### 391*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - DES - NULL 392*7dc08ffcSJunyu Lai 393*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 394*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 395*7dc08ffcSJunyu Laip /= Raw('testdata') 396*7dc08ffcSJunyu Laip = IP(raw(p)) 397*7dc08ffcSJunyu Laip 398*7dc08ffcSJunyu Lai 399*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 400*7dc08ffcSJunyu Lai crypt_algo='DES', crypt_key=b'8bytekey', 401*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 402*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 403*7dc08ffcSJunyu Lai 404*7dc08ffcSJunyu Laie = sa.encrypt(p) 405*7dc08ffcSJunyu Laie 406*7dc08ffcSJunyu Lai 407*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 408*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 409*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 410*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 411*7dc08ffcSJunyu Lai* the encrypted packet should have an ESP layer 412*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 413*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 414*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 415*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 416*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 417*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 418*7dc08ffcSJunyu Lai 419*7dc08ffcSJunyu Laid = sa.decrypt(e) 420*7dc08ffcSJunyu Laid 421*7dc08ffcSJunyu Lai 422*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 423*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 424*7dc08ffcSJunyu Lai 425*7dc08ffcSJunyu Lai####################################### 426*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - 3DES - NULL 427*7dc08ffcSJunyu Lai 428*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 429*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 430*7dc08ffcSJunyu Laip /= Raw('testdata') 431*7dc08ffcSJunyu Laip = IP(raw(p)) 432*7dc08ffcSJunyu Laip 433*7dc08ffcSJunyu Lai 434*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 435*7dc08ffcSJunyu Lai crypt_algo='3DES', crypt_key=b'threedifferent8byteskeys', 436*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 437*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 438*7dc08ffcSJunyu Lai 439*7dc08ffcSJunyu Laie = sa.encrypt(p) 440*7dc08ffcSJunyu Laie 441*7dc08ffcSJunyu Lai 442*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 443*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 444*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 445*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 446*7dc08ffcSJunyu Lai* the encrypted packet should have an ESP layer 447*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 448*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 449*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 450*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 451*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 452*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 453*7dc08ffcSJunyu Lai 454*7dc08ffcSJunyu Laid = sa.decrypt(e) 455*7dc08ffcSJunyu Laid 456*7dc08ffcSJunyu Lai 457*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 458*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 459*7dc08ffcSJunyu Lai 460*7dc08ffcSJunyu Lai####################################### 461*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-CBC - NULL 462*7dc08ffcSJunyu Lai 463*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 464*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 465*7dc08ffcSJunyu Laip /= Raw('testdata') 466*7dc08ffcSJunyu Laip = IP(raw(p)) 467*7dc08ffcSJunyu Laip 468*7dc08ffcSJunyu Lai 469*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 470*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 471*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 472*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 473*7dc08ffcSJunyu Lai 474*7dc08ffcSJunyu Laie = sa.encrypt(p) 475*7dc08ffcSJunyu Laie 476*7dc08ffcSJunyu Lai 477*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 478*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 479*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 480*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 481*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 482*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 483*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 484*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 485*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 486*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 487*7dc08ffcSJunyu Lai 488*7dc08ffcSJunyu Laid = sa.decrypt(e) 489*7dc08ffcSJunyu Laid 490*7dc08ffcSJunyu Lai 491*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 492*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 493*7dc08ffcSJunyu Lai 494*7dc08ffcSJunyu Lai####################################### 495*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-CTR - NULL 496*7dc08ffcSJunyu Lai 497*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 498*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 499*7dc08ffcSJunyu Laip /= Raw('testdata') 500*7dc08ffcSJunyu Laip = IP(raw(p)) 501*7dc08ffcSJunyu Laip 502*7dc08ffcSJunyu Lai 503*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 504*7dc08ffcSJunyu Lai crypt_algo='AES-CTR', crypt_key=b'16bytekey+4bytenonce', 505*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 506*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 507*7dc08ffcSJunyu Lai 508*7dc08ffcSJunyu Laie = sa.encrypt(p) 509*7dc08ffcSJunyu Laie 510*7dc08ffcSJunyu Lai 511*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 512*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 513*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 514*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 515*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 516*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 517*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 518*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 519*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 520*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 521*7dc08ffcSJunyu Lai 522*7dc08ffcSJunyu Laid = sa.decrypt(e) 523*7dc08ffcSJunyu Laid 524*7dc08ffcSJunyu Lai 525*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 526*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 527*7dc08ffcSJunyu Lai 528*7dc08ffcSJunyu Lai####################################### 529*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - Blowfish - NULL 530*7dc08ffcSJunyu Lai 531*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 532*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 533*7dc08ffcSJunyu Laip /= Raw('testdata') 534*7dc08ffcSJunyu Laip = IP(raw(p)) 535*7dc08ffcSJunyu Laip 536*7dc08ffcSJunyu Lai 537*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 538*7dc08ffcSJunyu Lai crypt_algo='Blowfish', crypt_key=b'sixteenbytes key', 539*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 540*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 541*7dc08ffcSJunyu Lai 542*7dc08ffcSJunyu Laie = sa.encrypt(p) 543*7dc08ffcSJunyu Laie 544*7dc08ffcSJunyu Lai 545*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 546*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 547*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 548*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 549*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 550*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 551*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 552*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 553*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 554*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 555*7dc08ffcSJunyu Lai 556*7dc08ffcSJunyu Laid = sa.decrypt(e) 557*7dc08ffcSJunyu Laid 558*7dc08ffcSJunyu Lai 559*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 560*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 561*7dc08ffcSJunyu Lai 562*7dc08ffcSJunyu Lai####################################### 563*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - CAST - NULL 564*7dc08ffcSJunyu Lai 565*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 566*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 567*7dc08ffcSJunyu Laip /= Raw('testdata') 568*7dc08ffcSJunyu Laip = IP(raw(p)) 569*7dc08ffcSJunyu Laip 570*7dc08ffcSJunyu Lai 571*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 572*7dc08ffcSJunyu Lai crypt_algo='CAST', crypt_key=b'sixteenbytes key', 573*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 574*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 575*7dc08ffcSJunyu Lai 576*7dc08ffcSJunyu Laie = sa.encrypt(p) 577*7dc08ffcSJunyu Laie 578*7dc08ffcSJunyu Lai 579*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 580*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 581*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 582*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 583*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 584*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 585*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 586*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 587*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 588*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 589*7dc08ffcSJunyu Lai 590*7dc08ffcSJunyu Laid = sa.decrypt(e) 591*7dc08ffcSJunyu Laid 592*7dc08ffcSJunyu Lai 593*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 594*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 595*7dc08ffcSJunyu Lai 596*7dc08ffcSJunyu Lai############################################################################### 597*7dc08ffcSJunyu Lai+ IPv4 / ESP - Transport - Authentication Algorithms 598*7dc08ffcSJunyu Lai 599*7dc08ffcSJunyu Lai####################################### 600*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - HMAC-SHA1-96 601*7dc08ffcSJunyu Lai 602*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 603*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 604*7dc08ffcSJunyu Laip /= Raw('testdata') 605*7dc08ffcSJunyu Laip = IP(raw(p)) 606*7dc08ffcSJunyu Laip 607*7dc08ffcSJunyu Lai 608*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 609*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 610*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 611*7dc08ffcSJunyu Lai 612*7dc08ffcSJunyu Laie = sa.encrypt(p) 613*7dc08ffcSJunyu Laie 614*7dc08ffcSJunyu Lai 615*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 616*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 617*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 618*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 619*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 620*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 621*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 622*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 623*7dc08ffcSJunyu Lai 624*7dc08ffcSJunyu Lai* integrity verification should pass 625*7dc08ffcSJunyu Laid = sa.decrypt(e) 626*7dc08ffcSJunyu Lai 627*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 628*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 629*7dc08ffcSJunyu Lai 630*7dc08ffcSJunyu Lai####################################### 631*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - HMAC-SHA1-96 - altered packet 632*7dc08ffcSJunyu Lai 633*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 634*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 635*7dc08ffcSJunyu Laip /= Raw('testdata') 636*7dc08ffcSJunyu Laip = IP(raw(p)) 637*7dc08ffcSJunyu Laip 638*7dc08ffcSJunyu Lai 639*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 640*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 641*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 642*7dc08ffcSJunyu Lai 643*7dc08ffcSJunyu Laie = sa.encrypt(p) 644*7dc08ffcSJunyu Laie 645*7dc08ffcSJunyu Lai 646*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 647*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 648*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 649*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 650*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 651*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 652*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 653*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 654*7dc08ffcSJunyu Lai 655*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 656*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 657*7dc08ffcSJunyu Lai 658*7dc08ffcSJunyu Lai* integrity verification should fail 659*7dc08ffcSJunyu Laitry: 660*7dc08ffcSJunyu Lai d = sa.decrypt(e) 661*7dc08ffcSJunyu Lai assert(False) 662*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 663*7dc08ffcSJunyu Lai err 664*7dc08ffcSJunyu Lai 665*7dc08ffcSJunyu Lai####################################### 666*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - SHA2-256-128 667*7dc08ffcSJunyu Lai 668*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 669*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 670*7dc08ffcSJunyu Laip /= Raw('testdata') 671*7dc08ffcSJunyu Laip = IP(raw(p)) 672*7dc08ffcSJunyu Laip 673*7dc08ffcSJunyu Lai 674*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 675*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 676*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key') 677*7dc08ffcSJunyu Lai 678*7dc08ffcSJunyu Laie = sa.encrypt(p) 679*7dc08ffcSJunyu Laie 680*7dc08ffcSJunyu Lai 681*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 682*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 683*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 684*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 685*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 686*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 687*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 688*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 689*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 690*7dc08ffcSJunyu Lai 691*7dc08ffcSJunyu Lai* integrity verification should pass 692*7dc08ffcSJunyu Laid = sa.decrypt(e) 693*7dc08ffcSJunyu Lai 694*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 695*7dc08ffcSJunyu Laiassert(d == p) 696*7dc08ffcSJunyu Lai 697*7dc08ffcSJunyu Lai####################################### 698*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - SHA2-256-128 - altered packet 699*7dc08ffcSJunyu Lai 700*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 701*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 702*7dc08ffcSJunyu Laip /= Raw('testdata') 703*7dc08ffcSJunyu Laip = IP(raw(p)) 704*7dc08ffcSJunyu Laip 705*7dc08ffcSJunyu Lai 706*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 707*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 708*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key') 709*7dc08ffcSJunyu Lai 710*7dc08ffcSJunyu Laie = sa.encrypt(p) 711*7dc08ffcSJunyu Laie 712*7dc08ffcSJunyu Lai 713*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 714*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 715*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 716*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 717*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 718*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 719*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 720*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 721*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 722*7dc08ffcSJunyu Lai 723*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 724*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 725*7dc08ffcSJunyu Lai 726*7dc08ffcSJunyu Lai* integrity verification should fail 727*7dc08ffcSJunyu Laitry: 728*7dc08ffcSJunyu Lai d = sa.decrypt(e) 729*7dc08ffcSJunyu Lai assert(False) 730*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 731*7dc08ffcSJunyu Lai err 732*7dc08ffcSJunyu Lai 733*7dc08ffcSJunyu Lai####################################### 734*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - SHA2-384-192 735*7dc08ffcSJunyu Lai 736*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 737*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 738*7dc08ffcSJunyu Laip /= Raw('testdata') 739*7dc08ffcSJunyu Laip = IP(raw(p)) 740*7dc08ffcSJunyu Laip 741*7dc08ffcSJunyu Lai 742*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 743*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 744*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key') 745*7dc08ffcSJunyu Lai 746*7dc08ffcSJunyu Laie = sa.encrypt(p) 747*7dc08ffcSJunyu Laie 748*7dc08ffcSJunyu Lai 749*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 750*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 751*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 752*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 753*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 754*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 755*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 756*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 757*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 758*7dc08ffcSJunyu Lai 759*7dc08ffcSJunyu Lai* integrity verification should pass 760*7dc08ffcSJunyu Laid = sa.decrypt(e) 761*7dc08ffcSJunyu Lai 762*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 763*7dc08ffcSJunyu Laiassert(d == p) 764*7dc08ffcSJunyu Lai 765*7dc08ffcSJunyu Lai####################################### 766*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - SHA2-384-192 - altered packet 767*7dc08ffcSJunyu Lai 768*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 769*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 770*7dc08ffcSJunyu Laip /= Raw('testdata') 771*7dc08ffcSJunyu Laip = IP(raw(p)) 772*7dc08ffcSJunyu Laip 773*7dc08ffcSJunyu Lai 774*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 775*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 776*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key') 777*7dc08ffcSJunyu Lai 778*7dc08ffcSJunyu Laie = sa.encrypt(p) 779*7dc08ffcSJunyu Laie 780*7dc08ffcSJunyu Lai 781*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 782*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 783*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 784*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 785*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 786*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 787*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 788*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 789*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 790*7dc08ffcSJunyu Lai 791*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 792*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 793*7dc08ffcSJunyu Lai 794*7dc08ffcSJunyu Lai* integrity verification should fail 795*7dc08ffcSJunyu Laitry: 796*7dc08ffcSJunyu Lai d = sa.decrypt(e) 797*7dc08ffcSJunyu Lai assert(False) 798*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 799*7dc08ffcSJunyu Lai err 800*7dc08ffcSJunyu Lai 801*7dc08ffcSJunyu Lai####################################### 802*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - SHA2-512-256 803*7dc08ffcSJunyu Lai 804*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 805*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 806*7dc08ffcSJunyu Laip /= Raw('testdata') 807*7dc08ffcSJunyu Laip = IP(raw(p)) 808*7dc08ffcSJunyu Laip 809*7dc08ffcSJunyu Lai 810*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 811*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 812*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key') 813*7dc08ffcSJunyu Lai 814*7dc08ffcSJunyu Laie = sa.encrypt(p) 815*7dc08ffcSJunyu Laie 816*7dc08ffcSJunyu Lai 817*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 818*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 819*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 820*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 821*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 822*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 823*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 824*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 825*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 826*7dc08ffcSJunyu Lai 827*7dc08ffcSJunyu Lai* integrity verification should pass 828*7dc08ffcSJunyu Laid = sa.decrypt(e) 829*7dc08ffcSJunyu Lai 830*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 831*7dc08ffcSJunyu Laiassert(d == p) 832*7dc08ffcSJunyu Lai 833*7dc08ffcSJunyu Lai####################################### 834*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - SHA2-512-256 - altered packet 835*7dc08ffcSJunyu Lai 836*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 837*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 838*7dc08ffcSJunyu Laip /= Raw('testdata') 839*7dc08ffcSJunyu Laip = IP(raw(p)) 840*7dc08ffcSJunyu Laip 841*7dc08ffcSJunyu Lai 842*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 843*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 844*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key') 845*7dc08ffcSJunyu Lai 846*7dc08ffcSJunyu Laie = sa.encrypt(p) 847*7dc08ffcSJunyu Laie 848*7dc08ffcSJunyu Lai 849*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 850*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 851*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 852*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 853*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 854*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 855*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 856*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 857*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 858*7dc08ffcSJunyu Lai 859*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 860*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 861*7dc08ffcSJunyu Lai 862*7dc08ffcSJunyu Lai* integrity verification should fail 863*7dc08ffcSJunyu Laitry: 864*7dc08ffcSJunyu Lai d = sa.decrypt(e) 865*7dc08ffcSJunyu Lai assert(False) 866*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 867*7dc08ffcSJunyu Lai err 868*7dc08ffcSJunyu Lai 869*7dc08ffcSJunyu Lai####################################### 870*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - HMAC-MD5-96 871*7dc08ffcSJunyu Lai 872*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 873*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 874*7dc08ffcSJunyu Laip /= Raw('testdata') 875*7dc08ffcSJunyu Laip = IP(raw(p)) 876*7dc08ffcSJunyu Laip 877*7dc08ffcSJunyu Lai 878*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 879*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 880*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key') 881*7dc08ffcSJunyu Lai 882*7dc08ffcSJunyu Laie = sa.encrypt(p) 883*7dc08ffcSJunyu Laie 884*7dc08ffcSJunyu Lai 885*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 886*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 887*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 888*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 889*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 890*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 891*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 892*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 893*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 894*7dc08ffcSJunyu Lai 895*7dc08ffcSJunyu Lai* integrity verification should pass 896*7dc08ffcSJunyu Laid = sa.decrypt(e) 897*7dc08ffcSJunyu Lai 898*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 899*7dc08ffcSJunyu Laiassert(d == p) 900*7dc08ffcSJunyu Lai 901*7dc08ffcSJunyu Lai####################################### 902*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - HMAC-MD5-96 - altered packet 903*7dc08ffcSJunyu Lai 904*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 905*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 906*7dc08ffcSJunyu Laip /= Raw('testdata') 907*7dc08ffcSJunyu Laip = IP(raw(p)) 908*7dc08ffcSJunyu Laip 909*7dc08ffcSJunyu Lai 910*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 911*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 912*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key') 913*7dc08ffcSJunyu Lai 914*7dc08ffcSJunyu Laie = sa.encrypt(p) 915*7dc08ffcSJunyu Laie 916*7dc08ffcSJunyu Lai 917*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 918*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 919*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 920*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 921*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 922*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 923*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 924*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 925*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 926*7dc08ffcSJunyu Lai 927*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 928*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 929*7dc08ffcSJunyu Lai 930*7dc08ffcSJunyu Lai* integrity verification should fail 931*7dc08ffcSJunyu Laitry: 932*7dc08ffcSJunyu Lai d = sa.decrypt(e) 933*7dc08ffcSJunyu Lai assert(False) 934*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 935*7dc08ffcSJunyu Lai err 936*7dc08ffcSJunyu Lai 937*7dc08ffcSJunyu Lai####################################### 938*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - AES-CMAC-96 939*7dc08ffcSJunyu Lai 940*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 941*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 942*7dc08ffcSJunyu Laip /= Raw('testdata') 943*7dc08ffcSJunyu Laip = IP(raw(p)) 944*7dc08ffcSJunyu Laip 945*7dc08ffcSJunyu Lai 946*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 947*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 948*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key') 949*7dc08ffcSJunyu Lai 950*7dc08ffcSJunyu Laie = sa.encrypt(p) 951*7dc08ffcSJunyu Laie 952*7dc08ffcSJunyu Lai 953*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 954*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 955*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 956*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 957*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 958*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 959*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 960*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 961*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 962*7dc08ffcSJunyu Lai 963*7dc08ffcSJunyu Lai* integrity verification should pass 964*7dc08ffcSJunyu Laid = sa.decrypt(e) 965*7dc08ffcSJunyu Lai 966*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 967*7dc08ffcSJunyu Laiassert(d == p) 968*7dc08ffcSJunyu Lai 969*7dc08ffcSJunyu Lai####################################### 970*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - NULL - AES-CMAC-96 - altered packet 971*7dc08ffcSJunyu Lai 972*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 973*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 974*7dc08ffcSJunyu Laip /= Raw('testdata') 975*7dc08ffcSJunyu Laip = IP(raw(p)) 976*7dc08ffcSJunyu Laip 977*7dc08ffcSJunyu Lai 978*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 979*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 980*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key') 981*7dc08ffcSJunyu Lai 982*7dc08ffcSJunyu Laie = sa.encrypt(p) 983*7dc08ffcSJunyu Laie 984*7dc08ffcSJunyu Lai 985*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 986*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 987*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 988*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 989*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 990*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 991*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 992*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 993*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 994*7dc08ffcSJunyu Lai 995*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 996*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 997*7dc08ffcSJunyu Lai 998*7dc08ffcSJunyu Lai* integrity verification should fail 999*7dc08ffcSJunyu Laitry: 1000*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1001*7dc08ffcSJunyu Lai assert(False) 1002*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1003*7dc08ffcSJunyu Lai err 1004*7dc08ffcSJunyu Lai 1005*7dc08ffcSJunyu Lai############################################################################### 1006*7dc08ffcSJunyu Lai+ IPv4 / ESP - Tunnel - Authentication Algorithms 1007*7dc08ffcSJunyu Lai 1008*7dc08ffcSJunyu Lai####################################### 1009*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - HMAC-SHA1-96 1010*7dc08ffcSJunyu Lai 1011*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1012*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1013*7dc08ffcSJunyu Laip /= Raw('testdata') 1014*7dc08ffcSJunyu Laip = IP(raw(p)) 1015*7dc08ffcSJunyu Laip 1016*7dc08ffcSJunyu Lai 1017*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1018*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1019*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 1020*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1021*7dc08ffcSJunyu Lai 1022*7dc08ffcSJunyu Laie = sa.encrypt(p) 1023*7dc08ffcSJunyu Laie 1024*7dc08ffcSJunyu Lai 1025*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1026*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1027*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1028*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1029*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1030*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1031*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1032*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1033*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1034*7dc08ffcSJunyu Lai 1035*7dc08ffcSJunyu Lai* integrity verification should pass 1036*7dc08ffcSJunyu Laid = sa.decrypt(e) 1037*7dc08ffcSJunyu Lai 1038*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 1039*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 1040*7dc08ffcSJunyu Lai 1041*7dc08ffcSJunyu Lai####################################### 1042*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - HMAC-SHA1-96 - altered packet 1043*7dc08ffcSJunyu Lai 1044*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1045*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1046*7dc08ffcSJunyu Laip /= Raw('testdata') 1047*7dc08ffcSJunyu Laip = IP(raw(p)) 1048*7dc08ffcSJunyu Laip 1049*7dc08ffcSJunyu Lai 1050*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1051*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1052*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 1053*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1054*7dc08ffcSJunyu Lai 1055*7dc08ffcSJunyu Laie = sa.encrypt(p) 1056*7dc08ffcSJunyu Laie 1057*7dc08ffcSJunyu Lai 1058*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1059*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1060*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1061*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1062*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1063*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1064*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1065*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1066*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1067*7dc08ffcSJunyu Lai 1068*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1069*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 1070*7dc08ffcSJunyu Lai 1071*7dc08ffcSJunyu Lai* integrity verification should fail 1072*7dc08ffcSJunyu Laitry: 1073*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1074*7dc08ffcSJunyu Lai assert(False) 1075*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1076*7dc08ffcSJunyu Lai err 1077*7dc08ffcSJunyu Lai 1078*7dc08ffcSJunyu Lai####################################### 1079*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - SHA2-256-128 1080*7dc08ffcSJunyu Lai 1081*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1082*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1083*7dc08ffcSJunyu Laip /= Raw('testdata') 1084*7dc08ffcSJunyu Laip = IP(raw(p)) 1085*7dc08ffcSJunyu Laip 1086*7dc08ffcSJunyu Lai 1087*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1088*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1089*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key', 1090*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1091*7dc08ffcSJunyu Lai 1092*7dc08ffcSJunyu Laie = sa.encrypt(p) 1093*7dc08ffcSJunyu Laie 1094*7dc08ffcSJunyu Lai 1095*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1096*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1097*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1098*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1099*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1100*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1101*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1102*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1103*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1104*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1105*7dc08ffcSJunyu Lai 1106*7dc08ffcSJunyu Lai* integrity verification should pass 1107*7dc08ffcSJunyu Laid = sa.decrypt(e) 1108*7dc08ffcSJunyu Lai 1109*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 1110*7dc08ffcSJunyu Laiassert(d == p) 1111*7dc08ffcSJunyu Lai 1112*7dc08ffcSJunyu Lai####################################### 1113*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - SHA2-256-128 - altered packet 1114*7dc08ffcSJunyu Lai 1115*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1116*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1117*7dc08ffcSJunyu Laip /= Raw('testdata') 1118*7dc08ffcSJunyu Laip = IP(raw(p)) 1119*7dc08ffcSJunyu Laip 1120*7dc08ffcSJunyu Lai 1121*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1122*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1123*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key', 1124*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1125*7dc08ffcSJunyu Lai 1126*7dc08ffcSJunyu Laie = sa.encrypt(p) 1127*7dc08ffcSJunyu Laie 1128*7dc08ffcSJunyu Lai 1129*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1130*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1131*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1132*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1133*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1134*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1135*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1136*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1137*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1138*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1139*7dc08ffcSJunyu Lai 1140*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1141*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 1142*7dc08ffcSJunyu Lai 1143*7dc08ffcSJunyu Lai* integrity verification should fail 1144*7dc08ffcSJunyu Laitry: 1145*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1146*7dc08ffcSJunyu Lai assert(False) 1147*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1148*7dc08ffcSJunyu Lai err 1149*7dc08ffcSJunyu Lai 1150*7dc08ffcSJunyu Lai####################################### 1151*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - SHA2-384-192 1152*7dc08ffcSJunyu Lai 1153*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1154*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1155*7dc08ffcSJunyu Laip /= Raw('testdata') 1156*7dc08ffcSJunyu Laip = IP(raw(p)) 1157*7dc08ffcSJunyu Laip 1158*7dc08ffcSJunyu Lai 1159*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1160*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1161*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key', 1162*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1163*7dc08ffcSJunyu Lai 1164*7dc08ffcSJunyu Laie = sa.encrypt(p) 1165*7dc08ffcSJunyu Laie 1166*7dc08ffcSJunyu Lai 1167*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1168*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1169*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1170*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1171*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1172*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1173*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1174*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1175*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1176*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1177*7dc08ffcSJunyu Lai 1178*7dc08ffcSJunyu Lai* integrity verification should pass 1179*7dc08ffcSJunyu Laid = sa.decrypt(e) 1180*7dc08ffcSJunyu Lai 1181*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 1182*7dc08ffcSJunyu Laiassert(d == p) 1183*7dc08ffcSJunyu Lai 1184*7dc08ffcSJunyu Lai####################################### 1185*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - SHA2-384-192 - altered packet 1186*7dc08ffcSJunyu Lai 1187*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1188*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1189*7dc08ffcSJunyu Laip /= Raw('testdata') 1190*7dc08ffcSJunyu Laip = IP(raw(p)) 1191*7dc08ffcSJunyu Laip 1192*7dc08ffcSJunyu Lai 1193*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1194*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1195*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key', 1196*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1197*7dc08ffcSJunyu Lai 1198*7dc08ffcSJunyu Laie = sa.encrypt(p) 1199*7dc08ffcSJunyu Laie 1200*7dc08ffcSJunyu Lai 1201*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1202*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1203*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1204*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1205*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1206*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1207*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1208*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1209*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1210*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1211*7dc08ffcSJunyu Lai 1212*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1213*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 1214*7dc08ffcSJunyu Lai 1215*7dc08ffcSJunyu Lai* integrity verification should fail 1216*7dc08ffcSJunyu Laitry: 1217*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1218*7dc08ffcSJunyu Lai assert(False) 1219*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1220*7dc08ffcSJunyu Lai err 1221*7dc08ffcSJunyu Lai 1222*7dc08ffcSJunyu Lai####################################### 1223*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - SHA2-512-256 1224*7dc08ffcSJunyu Lai 1225*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1226*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1227*7dc08ffcSJunyu Laip /= Raw('testdata') 1228*7dc08ffcSJunyu Laip = IP(raw(p)) 1229*7dc08ffcSJunyu Laip 1230*7dc08ffcSJunyu Lai 1231*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1232*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1233*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key', 1234*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1235*7dc08ffcSJunyu Lai 1236*7dc08ffcSJunyu Laie = sa.encrypt(p) 1237*7dc08ffcSJunyu Laie 1238*7dc08ffcSJunyu Lai 1239*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1240*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1241*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1242*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1243*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1244*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1245*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1246*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1247*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1248*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1249*7dc08ffcSJunyu Lai 1250*7dc08ffcSJunyu Lai* integrity verification should pass 1251*7dc08ffcSJunyu Laid = sa.decrypt(e) 1252*7dc08ffcSJunyu Lai 1253*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 1254*7dc08ffcSJunyu Laiassert(d == p) 1255*7dc08ffcSJunyu Lai 1256*7dc08ffcSJunyu Lai####################################### 1257*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - SHA2-512-256 - altered packet 1258*7dc08ffcSJunyu Lai 1259*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1260*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1261*7dc08ffcSJunyu Laip /= Raw('testdata') 1262*7dc08ffcSJunyu Laip = IP(raw(p)) 1263*7dc08ffcSJunyu Laip 1264*7dc08ffcSJunyu Lai 1265*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1266*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1267*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key', 1268*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1269*7dc08ffcSJunyu Lai 1270*7dc08ffcSJunyu Laie = sa.encrypt(p) 1271*7dc08ffcSJunyu Laie 1272*7dc08ffcSJunyu Lai 1273*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1274*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1275*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1276*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1277*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1278*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1279*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1280*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1281*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1282*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1283*7dc08ffcSJunyu Lai 1284*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1285*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 1286*7dc08ffcSJunyu Lai 1287*7dc08ffcSJunyu Lai* integrity verification should fail 1288*7dc08ffcSJunyu Laitry: 1289*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1290*7dc08ffcSJunyu Lai assert(False) 1291*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1292*7dc08ffcSJunyu Lai err 1293*7dc08ffcSJunyu Lai 1294*7dc08ffcSJunyu Lai####################################### 1295*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - HMAC-MD5-96 1296*7dc08ffcSJunyu Lai 1297*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1298*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1299*7dc08ffcSJunyu Laip /= Raw('testdata') 1300*7dc08ffcSJunyu Laip = IP(raw(p)) 1301*7dc08ffcSJunyu Laip 1302*7dc08ffcSJunyu Lai 1303*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1304*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1305*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key', 1306*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1307*7dc08ffcSJunyu Lai 1308*7dc08ffcSJunyu Laie = sa.encrypt(p) 1309*7dc08ffcSJunyu Laie 1310*7dc08ffcSJunyu Lai 1311*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1312*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1313*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1314*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1315*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1316*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1317*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1318*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1319*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1320*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1321*7dc08ffcSJunyu Lai 1322*7dc08ffcSJunyu Lai* integrity verification should pass 1323*7dc08ffcSJunyu Laid = sa.decrypt(e) 1324*7dc08ffcSJunyu Lai 1325*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 1326*7dc08ffcSJunyu Laiassert(d == p) 1327*7dc08ffcSJunyu Lai 1328*7dc08ffcSJunyu Lai####################################### 1329*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - HMAC-MD5-96 - altered packet 1330*7dc08ffcSJunyu Lai 1331*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1332*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1333*7dc08ffcSJunyu Laip /= Raw('testdata') 1334*7dc08ffcSJunyu Laip = IP(raw(p)) 1335*7dc08ffcSJunyu Laip 1336*7dc08ffcSJunyu Lai 1337*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1338*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1339*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key', 1340*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1341*7dc08ffcSJunyu Lai 1342*7dc08ffcSJunyu Laie = sa.encrypt(p) 1343*7dc08ffcSJunyu Laie 1344*7dc08ffcSJunyu Lai 1345*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1346*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1347*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1348*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1349*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1350*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1351*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1352*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1353*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1354*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1355*7dc08ffcSJunyu Lai 1356*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1357*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 1358*7dc08ffcSJunyu Lai 1359*7dc08ffcSJunyu Lai* integrity verification should fail 1360*7dc08ffcSJunyu Laitry: 1361*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1362*7dc08ffcSJunyu Lai assert(False) 1363*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1364*7dc08ffcSJunyu Lai err 1365*7dc08ffcSJunyu Lai 1366*7dc08ffcSJunyu Lai####################################### 1367*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - AES-CMAC-96 1368*7dc08ffcSJunyu Lai 1369*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1370*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1371*7dc08ffcSJunyu Laip /= Raw('testdata') 1372*7dc08ffcSJunyu Laip = IP(raw(p)) 1373*7dc08ffcSJunyu Laip 1374*7dc08ffcSJunyu Lai 1375*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1376*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1377*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key', 1378*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1379*7dc08ffcSJunyu Lai 1380*7dc08ffcSJunyu Laie = sa.encrypt(p) 1381*7dc08ffcSJunyu Laie 1382*7dc08ffcSJunyu Lai 1383*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1384*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1385*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1386*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1387*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1388*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1389*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1390*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1391*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1392*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1393*7dc08ffcSJunyu Lai 1394*7dc08ffcSJunyu Lai* integrity verification should pass 1395*7dc08ffcSJunyu Laid = sa.decrypt(e) 1396*7dc08ffcSJunyu Lai 1397*7dc08ffcSJunyu Lai* after decryption the original packet should be preserved 1398*7dc08ffcSJunyu Laiassert(d == p) 1399*7dc08ffcSJunyu Lai 1400*7dc08ffcSJunyu Lai####################################### 1401*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - NULL - AES-CMAC-96 - altered packet 1402*7dc08ffcSJunyu Lai 1403*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1404*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1405*7dc08ffcSJunyu Laip /= Raw('testdata') 1406*7dc08ffcSJunyu Laip = IP(raw(p)) 1407*7dc08ffcSJunyu Laip 1408*7dc08ffcSJunyu Lai 1409*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1410*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 1411*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key', 1412*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1413*7dc08ffcSJunyu Lai 1414*7dc08ffcSJunyu Laie = sa.encrypt(p) 1415*7dc08ffcSJunyu Laie 1416*7dc08ffcSJunyu Lai 1417*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1418*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1419*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1420*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1421*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1422*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1423*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1424*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1425*7dc08ffcSJunyu Lai* after encryption the original packet payload should be readable 1426*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 1427*7dc08ffcSJunyu Lai 1428*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1429*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 1430*7dc08ffcSJunyu Lai 1431*7dc08ffcSJunyu Lai* integrity verification should fail 1432*7dc08ffcSJunyu Laitry: 1433*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1434*7dc08ffcSJunyu Lai assert(False) 1435*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1436*7dc08ffcSJunyu Lai err 1437*7dc08ffcSJunyu Lai 1438*7dc08ffcSJunyu Lai############################################################################### 1439*7dc08ffcSJunyu Lai+ IPv4 / ESP - Encryption + Authentication 1440*7dc08ffcSJunyu Lai 1441*7dc08ffcSJunyu Lai####################################### 1442*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-CBC - HMAC-SHA1-96 1443*7dc08ffcSJunyu Lai 1444*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1445*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1446*7dc08ffcSJunyu Laip /= Raw('testdata') 1447*7dc08ffcSJunyu Laip = IP(raw(p)) 1448*7dc08ffcSJunyu Laip 1449*7dc08ffcSJunyu Lai 1450*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1451*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 1452*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 1453*7dc08ffcSJunyu Lai 1454*7dc08ffcSJunyu Laie = sa.encrypt(p) 1455*7dc08ffcSJunyu Laie 1456*7dc08ffcSJunyu Lai 1457*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1458*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 1459*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1460*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1461*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1462*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1463*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1464*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1465*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1466*7dc08ffcSJunyu Lai 1467*7dc08ffcSJunyu Laid = sa.decrypt(e) 1468*7dc08ffcSJunyu Laid 1469*7dc08ffcSJunyu Lai 1470*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 1471*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 1472*7dc08ffcSJunyu Lai 1473*7dc08ffcSJunyu Lai####################################### 1474*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-CBC - HMAC-SHA1-96 - altered packet 1475*7dc08ffcSJunyu Lai 1476*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1477*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1478*7dc08ffcSJunyu Laip /= Raw('testdata') 1479*7dc08ffcSJunyu Laip = IP(raw(p)) 1480*7dc08ffcSJunyu Laip 1481*7dc08ffcSJunyu Lai 1482*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1483*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 1484*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 1485*7dc08ffcSJunyu Lai 1486*7dc08ffcSJunyu Laie = sa.encrypt(p) 1487*7dc08ffcSJunyu Laie 1488*7dc08ffcSJunyu Lai 1489*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1490*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 1491*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1492*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1493*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1494*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1495*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1496*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1497*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1498*7dc08ffcSJunyu Lai 1499*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1500*7dc08ffcSJunyu Laie[ESP].seq += 1 1501*7dc08ffcSJunyu Lai 1502*7dc08ffcSJunyu Lai* integrity verification should fail 1503*7dc08ffcSJunyu Laitry: 1504*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1505*7dc08ffcSJunyu Lai assert(False) 1506*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1507*7dc08ffcSJunyu Lai err 1508*7dc08ffcSJunyu Lai 1509*7dc08ffcSJunyu Lai####################################### 1510*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-GCM - NULL 1511*7dc08ffcSJunyu Lai 1512*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1513*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1514*7dc08ffcSJunyu Laip /= Raw('testdata') 1515*7dc08ffcSJunyu Laip = IP(raw(p)) 1516*7dc08ffcSJunyu Laip 1517*7dc08ffcSJunyu Lai 1518*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1519*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 1520*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 1521*7dc08ffcSJunyu Lai 1522*7dc08ffcSJunyu Laie = sa.encrypt(p) 1523*7dc08ffcSJunyu Laie 1524*7dc08ffcSJunyu Lai 1525*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1526*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 1527*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1528*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1529*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1530*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1531*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1532*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1533*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1534*7dc08ffcSJunyu Lai 1535*7dc08ffcSJunyu Laid = sa.decrypt(e) 1536*7dc08ffcSJunyu Laid 1537*7dc08ffcSJunyu Lai 1538*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 1539*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 1540*7dc08ffcSJunyu Lai 1541*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 1542*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 1543*7dc08ffcSJunyu Lai# mode tunnel aead 'rfc4106(gcm(aes))' '0x3136627974656b65792b34627974656e6f6e6365' 128 flag align4 1544*7dc08ffcSJunyu Lairef = IP() \ 1545*7dc08ffcSJunyu Lai / ESP(spi=0x222, 1546*7dc08ffcSJunyu Lai data=b'\x66\x00\x28\x86\xe9\xdf\xc5\x24\xb0\xbd\xfd\x62\x61\x7e\xd3\x76' 1547*7dc08ffcSJunyu Lai b'\x7b\x48\x28\x8e\x76\xaa\xea\x48\xb8\x40\x30\x8a\xce\x50\x71\xbb' 1548*7dc08ffcSJunyu Lai b'\xc0\xb2\x47\x71\xd7\xa4\xa0\xcb\x03\x68\xd3\x16\x5a\x7c\x37\x84' 1549*7dc08ffcSJunyu Lai b'\x87\xc7\x19\x59\xb4\x7c\x76\xe3\x48\xc0\x90\x4b\xd2\x36\x95\xc1' 1550*7dc08ffcSJunyu Lai b'\xb7\xa4\xb6\x7b\x89\xe6\x4f\x10\xae\xdb\x84\x47\x46\x00\xb4\x44' 1551*7dc08ffcSJunyu Lai b'\xe6\x6d\x16\x55\x5f\x82\x36\xa5\x49\xf7\x52\x81\x65\x90\x4d\x28' 1552*7dc08ffcSJunyu Lai b'\x92\xb2\xe3\xf1\xa4\x02\xd2\x37\xac\x0b\x7a\x10\xcf\x64\x46\xb9', 1553*7dc08ffcSJunyu Lai seq=1) 1554*7dc08ffcSJunyu Lai 1555*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 1556*7dc08ffcSJunyu Laid_ref 1557*7dc08ffcSJunyu Lai 1558*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 1559*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 1560*7dc08ffcSJunyu Lai 1561*7dc08ffcSJunyu Lai####################################### 1562*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-GCM - NULL - altered packet 1563*7dc08ffcSJunyu Lai 1564*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1565*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1566*7dc08ffcSJunyu Laip /= Raw('testdata') 1567*7dc08ffcSJunyu Laip = IP(raw(p)) 1568*7dc08ffcSJunyu Laip 1569*7dc08ffcSJunyu Lai 1570*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1571*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 1572*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 1573*7dc08ffcSJunyu Lai 1574*7dc08ffcSJunyu Laie = sa.encrypt(p) 1575*7dc08ffcSJunyu Laie 1576*7dc08ffcSJunyu Lai 1577*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1578*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 1579*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1580*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1581*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1582*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1583*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1584*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1585*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1586*7dc08ffcSJunyu Lai 1587*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1588*7dc08ffcSJunyu Laie[ESP].seq += 1 1589*7dc08ffcSJunyu Lai 1590*7dc08ffcSJunyu Lai* integrity verification should fail 1591*7dc08ffcSJunyu Laitry: 1592*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1593*7dc08ffcSJunyu Lai assert(False) 1594*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1595*7dc08ffcSJunyu Lai err 1596*7dc08ffcSJunyu Lai 1597*7dc08ffcSJunyu Lai####################################### 1598*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-CCM - NULL 1599*7dc08ffcSJunyu Lai~ crypto_advanced 1600*7dc08ffcSJunyu Lai 1601*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1602*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1603*7dc08ffcSJunyu Laip /= Raw('testdata') 1604*7dc08ffcSJunyu Laip = IP(raw(p)) 1605*7dc08ffcSJunyu Laip 1606*7dc08ffcSJunyu Lai 1607*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1608*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 1609*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 1610*7dc08ffcSJunyu Lai 1611*7dc08ffcSJunyu Laie = sa.encrypt(p) 1612*7dc08ffcSJunyu Laie 1613*7dc08ffcSJunyu Lai 1614*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1615*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1616*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1617*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1618*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1619*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1620*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1621*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1622*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1623*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1624*7dc08ffcSJunyu Lai 1625*7dc08ffcSJunyu Laid = sa.decrypt(e) 1626*7dc08ffcSJunyu Laid 1627*7dc08ffcSJunyu Lai 1628*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 1629*7dc08ffcSJunyu Laiassert(d == p) 1630*7dc08ffcSJunyu Lai 1631*7dc08ffcSJunyu Lai# Generated with Linux 4.4.0-62-generic #83-Ubuntu 1632*7dc08ffcSJunyu Lai# ip xfrm state add src 10.125.0.2 dst 10.125.0.1 proto esp spi 546 reqid 1 \ 1633*7dc08ffcSJunyu Lai# mode tunnel aead 'rfc4309(ccm(aes))' '0x3136627974656b657933627974656e6f6e6365' 64 1634*7dc08ffcSJunyu Lairef = IP() \ 1635*7dc08ffcSJunyu Lai / ESP(spi=0x222, 1636*7dc08ffcSJunyu Lai data=b'\x2e\x02\x9f\x1f\xad\x76\x80\x58\x8f\xeb\x45\xf1\x66\xe3\xad\xa6' 1637*7dc08ffcSJunyu Lai b'\x90\x1b\x2b\x7d\xd3\x3d\xa4\x53\x35\xc8\xfa\x92\xfd\xd7\x42\x2f' 1638*7dc08ffcSJunyu Lai b'\x87\x60\x9b\x46\xb0\x21\x5e\x82\xfb\x2f\x59\xba\xf0\x6c\xe5\x51' 1639*7dc08ffcSJunyu Lai b'\xb8\x36\x20\x88\xfe\x49\x86\x60\xe8\x0a\x3d\x36\xb5\x8a\x08\xa9' 1640*7dc08ffcSJunyu Lai b'\x5e\xe3\x87\xfa\x93\x3f\xe8\xc2\xc5\xbf\xb1\x2e\x6f\x7d\xc5\xa5' 1641*7dc08ffcSJunyu Lai b'\xd8\xe5\xf3\x25\x21\x81\x43\x16\x48\x10\x7c\x04\x31\x20\x07\x7c' 1642*7dc08ffcSJunyu Lai b'\x7b\xda\x5d\x1a\x72\x45\xc4\x79', 1643*7dc08ffcSJunyu Lai seq=1) 1644*7dc08ffcSJunyu Lai 1645*7dc08ffcSJunyu Laid_ref = sa.decrypt(ref) 1646*7dc08ffcSJunyu Laid_ref 1647*7dc08ffcSJunyu Lai 1648*7dc08ffcSJunyu Lai* Check for ICMP layer in decrypted reference 1649*7dc08ffcSJunyu Laiassert(d_ref.haslayer(ICMP)) 1650*7dc08ffcSJunyu Lai 1651*7dc08ffcSJunyu Lai####################################### 1652*7dc08ffcSJunyu Lai= IPv4 / ESP - Transport - AES-CCM - NULL - altered packet 1653*7dc08ffcSJunyu Lai~ crypto_advanced 1654*7dc08ffcSJunyu Lai 1655*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1656*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1657*7dc08ffcSJunyu Laip /= Raw('testdata') 1658*7dc08ffcSJunyu Laip = IP(raw(p)) 1659*7dc08ffcSJunyu Laip 1660*7dc08ffcSJunyu Lai 1661*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1662*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 1663*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 1664*7dc08ffcSJunyu Lai 1665*7dc08ffcSJunyu Laie = sa.encrypt(p) 1666*7dc08ffcSJunyu Laie 1667*7dc08ffcSJunyu Lai 1668*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1669*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1670*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1671*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1672*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1673*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1674*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1675*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1676*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1677*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1678*7dc08ffcSJunyu Lai 1679*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1680*7dc08ffcSJunyu Laie[ESP].seq += 1 1681*7dc08ffcSJunyu Lai 1682*7dc08ffcSJunyu Lai* integrity verification should fail 1683*7dc08ffcSJunyu Laitry: 1684*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1685*7dc08ffcSJunyu Lai assert(False) 1686*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1687*7dc08ffcSJunyu Lai err 1688*7dc08ffcSJunyu Lai 1689*7dc08ffcSJunyu Lai####################################### 1690*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-CBC - HMAC-SHA1-96 1691*7dc08ffcSJunyu Lai 1692*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1693*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1694*7dc08ffcSJunyu Laip /= Raw('testdata') 1695*7dc08ffcSJunyu Laip = IP(raw(p)) 1696*7dc08ffcSJunyu Laip 1697*7dc08ffcSJunyu Lai 1698*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1699*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 1700*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 1701*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1702*7dc08ffcSJunyu Lai 1703*7dc08ffcSJunyu Laie = sa.encrypt(p) 1704*7dc08ffcSJunyu Laie 1705*7dc08ffcSJunyu Lai 1706*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1707*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1708*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1709*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1710*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1711*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1712*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1713*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1714*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1715*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1716*7dc08ffcSJunyu Lai 1717*7dc08ffcSJunyu Laid = sa.decrypt(e) 1718*7dc08ffcSJunyu Laid 1719*7dc08ffcSJunyu Lai 1720*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 1721*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 1722*7dc08ffcSJunyu Lai 1723*7dc08ffcSJunyu Lai####################################### 1724*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-CBC - HMAC-SHA1-96 - altered packet 1725*7dc08ffcSJunyu Lai 1726*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1727*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1728*7dc08ffcSJunyu Laip /= Raw('testdata') 1729*7dc08ffcSJunyu Laip = IP(raw(p)) 1730*7dc08ffcSJunyu Laip 1731*7dc08ffcSJunyu Lai 1732*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1733*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 1734*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 1735*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1736*7dc08ffcSJunyu Lai 1737*7dc08ffcSJunyu Laie = sa.encrypt(p) 1738*7dc08ffcSJunyu Laie 1739*7dc08ffcSJunyu Lai 1740*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1741*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1742*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1743*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1744*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1745*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1746*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1747*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1748*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1749*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1750*7dc08ffcSJunyu Lai 1751*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1752*7dc08ffcSJunyu Laie[ESP].seq += 1 1753*7dc08ffcSJunyu Lai 1754*7dc08ffcSJunyu Lai* integrity verification should fail 1755*7dc08ffcSJunyu Laitry: 1756*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1757*7dc08ffcSJunyu Lai assert(False) 1758*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1759*7dc08ffcSJunyu Lai err 1760*7dc08ffcSJunyu Lai 1761*7dc08ffcSJunyu Lai####################################### 1762*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-GCM - NULL 1763*7dc08ffcSJunyu Lai 1764*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1765*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1766*7dc08ffcSJunyu Laip /= Raw('testdata') 1767*7dc08ffcSJunyu Laip = IP(raw(p)) 1768*7dc08ffcSJunyu Laip 1769*7dc08ffcSJunyu Lai 1770*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1771*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 1772*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 1773*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1774*7dc08ffcSJunyu Lai 1775*7dc08ffcSJunyu Laie = sa.encrypt(p) 1776*7dc08ffcSJunyu Laie 1777*7dc08ffcSJunyu Lai 1778*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1779*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1780*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1781*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1782*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1783*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1784*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1785*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1786*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1787*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1788*7dc08ffcSJunyu Lai 1789*7dc08ffcSJunyu Laid = sa.decrypt(e) 1790*7dc08ffcSJunyu Laid 1791*7dc08ffcSJunyu Lai 1792*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 1793*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 1794*7dc08ffcSJunyu Lai 1795*7dc08ffcSJunyu Lai####################################### 1796*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-GCM - NULL - altered packet 1797*7dc08ffcSJunyu Lai 1798*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1799*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1800*7dc08ffcSJunyu Laip /= Raw('testdata') 1801*7dc08ffcSJunyu Laip = IP(raw(p)) 1802*7dc08ffcSJunyu Laip 1803*7dc08ffcSJunyu Lai 1804*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1805*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 1806*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 1807*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1808*7dc08ffcSJunyu Lai 1809*7dc08ffcSJunyu Laie = sa.encrypt(p) 1810*7dc08ffcSJunyu Laie 1811*7dc08ffcSJunyu Lai 1812*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1813*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1814*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1815*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1816*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1817*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1818*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1819*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1820*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1821*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1822*7dc08ffcSJunyu Lai 1823*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1824*7dc08ffcSJunyu Laie[ESP].seq += 1 1825*7dc08ffcSJunyu Lai 1826*7dc08ffcSJunyu Lai* integrity verification should fail 1827*7dc08ffcSJunyu Laitry: 1828*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1829*7dc08ffcSJunyu Lai assert(False) 1830*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1831*7dc08ffcSJunyu Lai err 1832*7dc08ffcSJunyu Lai 1833*7dc08ffcSJunyu Lai####################################### 1834*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-CCM - NULL 1835*7dc08ffcSJunyu Lai~ crypto_advanced 1836*7dc08ffcSJunyu Lai 1837*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1838*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1839*7dc08ffcSJunyu Laip /= Raw('testdata') 1840*7dc08ffcSJunyu Laip = IP(raw(p)) 1841*7dc08ffcSJunyu Laip 1842*7dc08ffcSJunyu Lai 1843*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1844*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 1845*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 1846*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1847*7dc08ffcSJunyu Lai 1848*7dc08ffcSJunyu Laie = sa.encrypt(p) 1849*7dc08ffcSJunyu Laie 1850*7dc08ffcSJunyu Lai 1851*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1852*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1853*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1854*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1855*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1856*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1857*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1858*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1859*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1860*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1861*7dc08ffcSJunyu Lai 1862*7dc08ffcSJunyu Laid = sa.decrypt(e) 1863*7dc08ffcSJunyu Laid 1864*7dc08ffcSJunyu Lai 1865*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 1866*7dc08ffcSJunyu Laiassert(d == p) 1867*7dc08ffcSJunyu Lai 1868*7dc08ffcSJunyu Lai####################################### 1869*7dc08ffcSJunyu Lai= IPv4 / ESP - Tunnel - AES-CCM - NULL 1870*7dc08ffcSJunyu Lai~ crypto_advanced 1871*7dc08ffcSJunyu Lai 1872*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1873*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1874*7dc08ffcSJunyu Laip /= Raw('testdata') 1875*7dc08ffcSJunyu Laip = IP(raw(p)) 1876*7dc08ffcSJunyu Laip 1877*7dc08ffcSJunyu Lai 1878*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 1879*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 1880*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 1881*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 1882*7dc08ffcSJunyu Lai 1883*7dc08ffcSJunyu Laie = sa.encrypt(p) 1884*7dc08ffcSJunyu Laie 1885*7dc08ffcSJunyu Lai 1886*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1887*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 1888*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 1889*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1890*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_ESP) 1891*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 1892*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 1893*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 1894*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 1895*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 1896*7dc08ffcSJunyu Lai 1897*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1898*7dc08ffcSJunyu Laie[ESP].seq += 1 1899*7dc08ffcSJunyu Lai 1900*7dc08ffcSJunyu Lai* integrity verification should fail 1901*7dc08ffcSJunyu Laitry: 1902*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1903*7dc08ffcSJunyu Lai assert(False) 1904*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1905*7dc08ffcSJunyu Lai err 1906*7dc08ffcSJunyu Lai 1907*7dc08ffcSJunyu Lai############################################################################### 1908*7dc08ffcSJunyu Lai+ IPv4 / AH - Transport 1909*7dc08ffcSJunyu Lai 1910*7dc08ffcSJunyu Lai####################################### 1911*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - HMAC-SHA1-96 1912*7dc08ffcSJunyu Lai 1913*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1914*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1915*7dc08ffcSJunyu Laip /= Raw('testdata') 1916*7dc08ffcSJunyu Laip = IP(raw(p)) 1917*7dc08ffcSJunyu Laip 1918*7dc08ffcSJunyu Lai 1919*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 1920*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'sixteenbytes key') 1921*7dc08ffcSJunyu Lai 1922*7dc08ffcSJunyu Laie = sa.encrypt(p) 1923*7dc08ffcSJunyu Laie 1924*7dc08ffcSJunyu Lai 1925*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1926*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 1927*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1928*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 1929*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 1930*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 1931*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 1932*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 1933*7dc08ffcSJunyu Lai 1934*7dc08ffcSJunyu Lai* alter mutable fields in the packet 1935*7dc08ffcSJunyu Laie.ttl = 2 1936*7dc08ffcSJunyu Lai 1937*7dc08ffcSJunyu Lai* integrity verification should pass 1938*7dc08ffcSJunyu Laid = sa.decrypt(e) 1939*7dc08ffcSJunyu Laid 1940*7dc08ffcSJunyu Lai 1941*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 1942*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 1943*7dc08ffcSJunyu Lai 1944*7dc08ffcSJunyu Lai####################################### 1945*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - HMAC-SHA1-96 - altered packet 1946*7dc08ffcSJunyu Lai 1947*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1948*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1949*7dc08ffcSJunyu Laip /= Raw('testdata') 1950*7dc08ffcSJunyu Laip = IP(raw(p)) 1951*7dc08ffcSJunyu Laip 1952*7dc08ffcSJunyu Lai 1953*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 1954*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'sixteenbytes key') 1955*7dc08ffcSJunyu Lai 1956*7dc08ffcSJunyu Laie = sa.encrypt(p) 1957*7dc08ffcSJunyu Laie 1958*7dc08ffcSJunyu Lai 1959*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1960*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 1961*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1962*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 1963*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 1964*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 1965*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 1966*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 1967*7dc08ffcSJunyu Lai 1968*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 1969*7dc08ffcSJunyu Laie[TCP].sport = 5 1970*7dc08ffcSJunyu Lai 1971*7dc08ffcSJunyu Lai* integrity verification should fail 1972*7dc08ffcSJunyu Laitry: 1973*7dc08ffcSJunyu Lai d = sa.decrypt(e) 1974*7dc08ffcSJunyu Lai assert(False) 1975*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 1976*7dc08ffcSJunyu Lai err 1977*7dc08ffcSJunyu Lai 1978*7dc08ffcSJunyu Lai####################################### 1979*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - SHA2-256-128 1980*7dc08ffcSJunyu Lai 1981*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 1982*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 1983*7dc08ffcSJunyu Laip /= Raw('testdata') 1984*7dc08ffcSJunyu Laip = IP(raw(p)) 1985*7dc08ffcSJunyu Laip 1986*7dc08ffcSJunyu Lai 1987*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 1988*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key') 1989*7dc08ffcSJunyu Lai 1990*7dc08ffcSJunyu Laie = sa.encrypt(p) 1991*7dc08ffcSJunyu Laie 1992*7dc08ffcSJunyu Lai 1993*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 1994*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 1995*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 1996*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 1997*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 1998*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 1999*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2000*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2001*7dc08ffcSJunyu Lai 2002*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2003*7dc08ffcSJunyu Laie.ttl = 2 2004*7dc08ffcSJunyu Lai 2005*7dc08ffcSJunyu Lai* integrity verification should pass 2006*7dc08ffcSJunyu Laid = sa.decrypt(e) 2007*7dc08ffcSJunyu Laid 2008*7dc08ffcSJunyu Lai 2009*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2010*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2011*7dc08ffcSJunyu Lai 2012*7dc08ffcSJunyu Lai####################################### 2013*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - SHA2-256-128 - altered packet 2014*7dc08ffcSJunyu Lai 2015*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2016*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2017*7dc08ffcSJunyu Laip /= Raw('testdata') 2018*7dc08ffcSJunyu Laip = IP(raw(p)) 2019*7dc08ffcSJunyu Laip 2020*7dc08ffcSJunyu Lai 2021*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2022*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key') 2023*7dc08ffcSJunyu Lai 2024*7dc08ffcSJunyu Laie = sa.encrypt(p) 2025*7dc08ffcSJunyu Laie 2026*7dc08ffcSJunyu Lai 2027*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2028*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2029*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2030*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2031*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2032*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2033*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2034*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2035*7dc08ffcSJunyu Lai 2036*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2037*7dc08ffcSJunyu Laie[TCP].dport = 46 2038*7dc08ffcSJunyu Lai 2039*7dc08ffcSJunyu Lai* integrity verification should fail 2040*7dc08ffcSJunyu Laitry: 2041*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2042*7dc08ffcSJunyu Lai assert(False) 2043*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2044*7dc08ffcSJunyu Lai err 2045*7dc08ffcSJunyu Lai 2046*7dc08ffcSJunyu Lai####################################### 2047*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - SHA2-384-192 2048*7dc08ffcSJunyu Lai 2049*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2050*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2051*7dc08ffcSJunyu Laip /= Raw('testdata') 2052*7dc08ffcSJunyu Laip = IP(raw(p)) 2053*7dc08ffcSJunyu Laip 2054*7dc08ffcSJunyu Lai 2055*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2056*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key') 2057*7dc08ffcSJunyu Lai 2058*7dc08ffcSJunyu Laie = sa.encrypt(p) 2059*7dc08ffcSJunyu Laie 2060*7dc08ffcSJunyu Lai 2061*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2062*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2063*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2064*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2065*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2066*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2067*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2068*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2069*7dc08ffcSJunyu Lai 2070*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2071*7dc08ffcSJunyu Laie.ttl = 2 2072*7dc08ffcSJunyu Lai 2073*7dc08ffcSJunyu Lai* integrity verification should pass 2074*7dc08ffcSJunyu Laid = sa.decrypt(e) 2075*7dc08ffcSJunyu Laid 2076*7dc08ffcSJunyu Lai 2077*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2078*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2079*7dc08ffcSJunyu Lai 2080*7dc08ffcSJunyu Lai####################################### 2081*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - SHA2-384-192 - altered packet 2082*7dc08ffcSJunyu Lai 2083*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2084*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2085*7dc08ffcSJunyu Laip /= Raw('testdata') 2086*7dc08ffcSJunyu Laip = IP(raw(p)) 2087*7dc08ffcSJunyu Laip 2088*7dc08ffcSJunyu Lai 2089*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2090*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key') 2091*7dc08ffcSJunyu Lai 2092*7dc08ffcSJunyu Laie = sa.encrypt(p) 2093*7dc08ffcSJunyu Laie 2094*7dc08ffcSJunyu Lai 2095*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2096*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2097*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2098*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2099*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2100*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2101*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2102*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2103*7dc08ffcSJunyu Lai 2104*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2105*7dc08ffcSJunyu Laie[TCP].dport = 46 2106*7dc08ffcSJunyu Lai 2107*7dc08ffcSJunyu Lai* integrity verification should fail 2108*7dc08ffcSJunyu Laitry: 2109*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2110*7dc08ffcSJunyu Lai assert(False) 2111*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2112*7dc08ffcSJunyu Lai err 2113*7dc08ffcSJunyu Lai 2114*7dc08ffcSJunyu Lai####################################### 2115*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - SHA2-512-256 2116*7dc08ffcSJunyu Lai 2117*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2118*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2119*7dc08ffcSJunyu Laip /= Raw('testdata') 2120*7dc08ffcSJunyu Laip = IP(raw(p)) 2121*7dc08ffcSJunyu Laip 2122*7dc08ffcSJunyu Lai 2123*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2124*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key') 2125*7dc08ffcSJunyu Lai 2126*7dc08ffcSJunyu Laie = sa.encrypt(p) 2127*7dc08ffcSJunyu Laie 2128*7dc08ffcSJunyu Lai 2129*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2130*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2131*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2132*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2133*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2134*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2135*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2136*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2137*7dc08ffcSJunyu Lai 2138*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2139*7dc08ffcSJunyu Laie.ttl = 2 2140*7dc08ffcSJunyu Lai 2141*7dc08ffcSJunyu Lai* integrity verification should pass 2142*7dc08ffcSJunyu Laid = sa.decrypt(e) 2143*7dc08ffcSJunyu Laid 2144*7dc08ffcSJunyu Lai 2145*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2146*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2147*7dc08ffcSJunyu Lai 2148*7dc08ffcSJunyu Lai####################################### 2149*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - SHA2-512-256 - altered packet 2150*7dc08ffcSJunyu Lai 2151*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2152*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2153*7dc08ffcSJunyu Laip /= Raw('testdata') 2154*7dc08ffcSJunyu Laip = IP(raw(p)) 2155*7dc08ffcSJunyu Laip 2156*7dc08ffcSJunyu Lai 2157*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2158*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key') 2159*7dc08ffcSJunyu Lai 2160*7dc08ffcSJunyu Laie = sa.encrypt(p) 2161*7dc08ffcSJunyu Laie 2162*7dc08ffcSJunyu Lai 2163*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2164*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2165*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2166*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2167*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2168*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2169*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2170*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2171*7dc08ffcSJunyu Lai 2172*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2173*7dc08ffcSJunyu Laie[TCP].dport = 46 2174*7dc08ffcSJunyu Lai 2175*7dc08ffcSJunyu Lai* integrity verification should fail 2176*7dc08ffcSJunyu Laitry: 2177*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2178*7dc08ffcSJunyu Lai assert(False) 2179*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2180*7dc08ffcSJunyu Lai err 2181*7dc08ffcSJunyu Lai 2182*7dc08ffcSJunyu Lai####################################### 2183*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - HMAC-MD5-96 2184*7dc08ffcSJunyu Lai 2185*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2186*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2187*7dc08ffcSJunyu Laip /= Raw('testdata') 2188*7dc08ffcSJunyu Laip = IP(raw(p)) 2189*7dc08ffcSJunyu Laip 2190*7dc08ffcSJunyu Lai 2191*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2192*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key') 2193*7dc08ffcSJunyu Lai 2194*7dc08ffcSJunyu Laie = sa.encrypt(p) 2195*7dc08ffcSJunyu Laie 2196*7dc08ffcSJunyu Lai 2197*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2198*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2199*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2200*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2201*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2202*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2203*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2204*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2205*7dc08ffcSJunyu Lai 2206*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2207*7dc08ffcSJunyu Laie.ttl = 2 2208*7dc08ffcSJunyu Lai 2209*7dc08ffcSJunyu Lai* integrity verification should pass 2210*7dc08ffcSJunyu Laid = sa.decrypt(e) 2211*7dc08ffcSJunyu Laid 2212*7dc08ffcSJunyu Lai 2213*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2214*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2215*7dc08ffcSJunyu Lai 2216*7dc08ffcSJunyu Lai####################################### 2217*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - HMAC-MD5-96 - altered packet 2218*7dc08ffcSJunyu Lai 2219*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2220*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2221*7dc08ffcSJunyu Laip /= Raw('testdata') 2222*7dc08ffcSJunyu Laip = IP(raw(p)) 2223*7dc08ffcSJunyu Laip 2224*7dc08ffcSJunyu Lai 2225*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2226*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key') 2227*7dc08ffcSJunyu Lai 2228*7dc08ffcSJunyu Laie = sa.encrypt(p) 2229*7dc08ffcSJunyu Laie 2230*7dc08ffcSJunyu Lai 2231*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2232*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2233*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2234*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2235*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2236*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2237*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2238*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2239*7dc08ffcSJunyu Lai 2240*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2241*7dc08ffcSJunyu Laie[TCP].dport = 46 2242*7dc08ffcSJunyu Lai 2243*7dc08ffcSJunyu Lai* integrity verification should fail 2244*7dc08ffcSJunyu Laitry: 2245*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2246*7dc08ffcSJunyu Lai assert(False) 2247*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2248*7dc08ffcSJunyu Lai err 2249*7dc08ffcSJunyu Lai 2250*7dc08ffcSJunyu Lai####################################### 2251*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - AES-CMAC-96 2252*7dc08ffcSJunyu Lai 2253*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2254*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2255*7dc08ffcSJunyu Laip /= Raw('testdata') 2256*7dc08ffcSJunyu Laip = IP(raw(p)) 2257*7dc08ffcSJunyu Laip 2258*7dc08ffcSJunyu Lai 2259*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2260*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key') 2261*7dc08ffcSJunyu Lai 2262*7dc08ffcSJunyu Laie = sa.encrypt(p) 2263*7dc08ffcSJunyu Laie 2264*7dc08ffcSJunyu Lai 2265*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2266*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2267*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2268*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2269*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2270*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2271*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2272*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2273*7dc08ffcSJunyu Lai 2274*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2275*7dc08ffcSJunyu Laie.ttl = 2 2276*7dc08ffcSJunyu Lai 2277*7dc08ffcSJunyu Lai* integrity verification should pass 2278*7dc08ffcSJunyu Laid = sa.decrypt(e) 2279*7dc08ffcSJunyu Laid 2280*7dc08ffcSJunyu Lai 2281*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2282*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2283*7dc08ffcSJunyu Lai 2284*7dc08ffcSJunyu Lai####################################### 2285*7dc08ffcSJunyu Lai= IPv4 / AH - Transport - AES-CMAC-96 - altered packet 2286*7dc08ffcSJunyu Lai 2287*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2288*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2289*7dc08ffcSJunyu Laip /= Raw('testdata') 2290*7dc08ffcSJunyu Laip = IP(raw(p)) 2291*7dc08ffcSJunyu Laip 2292*7dc08ffcSJunyu Lai 2293*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2294*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key') 2295*7dc08ffcSJunyu Lai 2296*7dc08ffcSJunyu Laie = sa.encrypt(p) 2297*7dc08ffcSJunyu Laie 2298*7dc08ffcSJunyu Lai 2299*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2300*7dc08ffcSJunyu Laiassert(e.src == '1.1.1.1' and e.dst == '2.2.2.2') 2301*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2302*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 2303*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2304*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2305*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2306*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2307*7dc08ffcSJunyu Lai 2308*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2309*7dc08ffcSJunyu Laie[TCP].dport = 46 2310*7dc08ffcSJunyu Lai 2311*7dc08ffcSJunyu Lai* integrity verification should fail 2312*7dc08ffcSJunyu Laitry: 2313*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2314*7dc08ffcSJunyu Lai assert(False) 2315*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2316*7dc08ffcSJunyu Lai err 2317*7dc08ffcSJunyu Lai 2318*7dc08ffcSJunyu Lai############################################################################### 2319*7dc08ffcSJunyu Lai+ IPv4 / AH - Tunnel 2320*7dc08ffcSJunyu Lai 2321*7dc08ffcSJunyu Lai####################################### 2322*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - HMAC-SHA1-96 2323*7dc08ffcSJunyu Lai 2324*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2325*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2326*7dc08ffcSJunyu Laip /= Raw('testdata') 2327*7dc08ffcSJunyu Laip = IP(raw(p)) 2328*7dc08ffcSJunyu Laip 2329*7dc08ffcSJunyu Lai 2330*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2331*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 2332*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2333*7dc08ffcSJunyu Lai 2334*7dc08ffcSJunyu Laie = sa.encrypt(p) 2335*7dc08ffcSJunyu Laie 2336*7dc08ffcSJunyu Lai 2337*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2338*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2339*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2340*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2341*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2342*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2343*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2344*7dc08ffcSJunyu Lai 2345*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2346*7dc08ffcSJunyu Laie.ttl = 2 2347*7dc08ffcSJunyu Lai 2348*7dc08ffcSJunyu Lai* integrity verification should pass 2349*7dc08ffcSJunyu Laid = sa.decrypt(e) 2350*7dc08ffcSJunyu Laid 2351*7dc08ffcSJunyu Lai 2352*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 2353*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2354*7dc08ffcSJunyu Lai 2355*7dc08ffcSJunyu Lai####################################### 2356*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - HMAC-SHA1-96 - altered packet 2357*7dc08ffcSJunyu Lai 2358*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2359*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2360*7dc08ffcSJunyu Laip /= Raw('testdata') 2361*7dc08ffcSJunyu Laip = IP(raw(p)) 2362*7dc08ffcSJunyu Laip 2363*7dc08ffcSJunyu Lai 2364*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2365*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 2366*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2367*7dc08ffcSJunyu Lai 2368*7dc08ffcSJunyu Laie = sa.encrypt(p) 2369*7dc08ffcSJunyu Laie 2370*7dc08ffcSJunyu Lai 2371*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2372*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2373*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2374*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2375*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2376*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2377*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2378*7dc08ffcSJunyu Lai 2379*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2380*7dc08ffcSJunyu Laie.dst = '4.4.4.4' 2381*7dc08ffcSJunyu Lai 2382*7dc08ffcSJunyu Lai* integrity verification should fail 2383*7dc08ffcSJunyu Laitry: 2384*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2385*7dc08ffcSJunyu Lai assert(False) 2386*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2387*7dc08ffcSJunyu Lai err 2388*7dc08ffcSJunyu Lai 2389*7dc08ffcSJunyu Lai####################################### 2390*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - SHA2-256-128 2391*7dc08ffcSJunyu Lai 2392*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2393*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2394*7dc08ffcSJunyu Laip /= Raw('testdata') 2395*7dc08ffcSJunyu Laip = IP(raw(p)) 2396*7dc08ffcSJunyu Laip 2397*7dc08ffcSJunyu Lai 2398*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2399*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key', 2400*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2401*7dc08ffcSJunyu Lai 2402*7dc08ffcSJunyu Laie = sa.encrypt(p) 2403*7dc08ffcSJunyu Laie 2404*7dc08ffcSJunyu Lai 2405*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2406*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2407*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2408*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2409*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2410*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2411*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2412*7dc08ffcSJunyu Lai 2413*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2414*7dc08ffcSJunyu Laie.ttl = 2 2415*7dc08ffcSJunyu Lai 2416*7dc08ffcSJunyu Lai* integrity verification should pass 2417*7dc08ffcSJunyu Laid = sa.decrypt(e) 2418*7dc08ffcSJunyu Laid 2419*7dc08ffcSJunyu Lai 2420*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2421*7dc08ffcSJunyu Laiassert(d == p) 2422*7dc08ffcSJunyu Lai 2423*7dc08ffcSJunyu Lai####################################### 2424*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - SHA2-256-128 - altered packet 2425*7dc08ffcSJunyu Lai 2426*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2427*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2428*7dc08ffcSJunyu Laip /= Raw('testdata') 2429*7dc08ffcSJunyu Laip = IP(raw(p)) 2430*7dc08ffcSJunyu Laip 2431*7dc08ffcSJunyu Lai 2432*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2433*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key', 2434*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2435*7dc08ffcSJunyu Lai 2436*7dc08ffcSJunyu Laie = sa.encrypt(p) 2437*7dc08ffcSJunyu Laie 2438*7dc08ffcSJunyu Lai 2439*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2440*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2441*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2442*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2443*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2444*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2445*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2446*7dc08ffcSJunyu Lai 2447*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2448*7dc08ffcSJunyu Laie.dst = '4.4.4.4' 2449*7dc08ffcSJunyu Lai 2450*7dc08ffcSJunyu Lai* integrity verification should fail 2451*7dc08ffcSJunyu Laitry: 2452*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2453*7dc08ffcSJunyu Lai assert(False) 2454*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2455*7dc08ffcSJunyu Lai err 2456*7dc08ffcSJunyu Lai 2457*7dc08ffcSJunyu Lai####################################### 2458*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - SHA2-384-192 2459*7dc08ffcSJunyu Lai 2460*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2461*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2462*7dc08ffcSJunyu Laip /= Raw('testdata') 2463*7dc08ffcSJunyu Laip = IP(raw(p)) 2464*7dc08ffcSJunyu Laip 2465*7dc08ffcSJunyu Lai 2466*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2467*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key', 2468*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2469*7dc08ffcSJunyu Lai 2470*7dc08ffcSJunyu Laie = sa.encrypt(p) 2471*7dc08ffcSJunyu Laie 2472*7dc08ffcSJunyu Lai 2473*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2474*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2475*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2476*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2477*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2478*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2479*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2480*7dc08ffcSJunyu Lai 2481*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2482*7dc08ffcSJunyu Laie.ttl = 2 2483*7dc08ffcSJunyu Lai 2484*7dc08ffcSJunyu Lai* integrity verification should pass 2485*7dc08ffcSJunyu Laid = sa.decrypt(e) 2486*7dc08ffcSJunyu Laid 2487*7dc08ffcSJunyu Lai 2488*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2489*7dc08ffcSJunyu Laiassert(d == p) 2490*7dc08ffcSJunyu Lai 2491*7dc08ffcSJunyu Lai####################################### 2492*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - SHA2-384-192 - altered packet 2493*7dc08ffcSJunyu Lai 2494*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2495*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2496*7dc08ffcSJunyu Laip /= Raw('testdata') 2497*7dc08ffcSJunyu Laip = IP(raw(p)) 2498*7dc08ffcSJunyu Laip 2499*7dc08ffcSJunyu Lai 2500*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2501*7dc08ffcSJunyu Lai auth_algo='SHA2-384-192', auth_key=b'secret key', 2502*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2503*7dc08ffcSJunyu Lai 2504*7dc08ffcSJunyu Laie = sa.encrypt(p) 2505*7dc08ffcSJunyu Laie 2506*7dc08ffcSJunyu Lai 2507*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2508*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2509*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2510*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2511*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2512*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2513*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2514*7dc08ffcSJunyu Lai 2515*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2516*7dc08ffcSJunyu Laie.dst = '4.4.4.4' 2517*7dc08ffcSJunyu Lai 2518*7dc08ffcSJunyu Lai* integrity verification should fail 2519*7dc08ffcSJunyu Laitry: 2520*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2521*7dc08ffcSJunyu Lai assert(False) 2522*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2523*7dc08ffcSJunyu Lai err 2524*7dc08ffcSJunyu Lai 2525*7dc08ffcSJunyu Lai####################################### 2526*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - SHA2-512-256 2527*7dc08ffcSJunyu Lai 2528*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2529*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2530*7dc08ffcSJunyu Laip /= Raw('testdata') 2531*7dc08ffcSJunyu Laip = IP(raw(p)) 2532*7dc08ffcSJunyu Laip 2533*7dc08ffcSJunyu Lai 2534*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2535*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key', 2536*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2537*7dc08ffcSJunyu Lai 2538*7dc08ffcSJunyu Laie = sa.encrypt(p) 2539*7dc08ffcSJunyu Laie 2540*7dc08ffcSJunyu Lai 2541*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2542*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2543*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2544*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2545*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2546*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2547*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2548*7dc08ffcSJunyu Lai 2549*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2550*7dc08ffcSJunyu Laie.ttl = 2 2551*7dc08ffcSJunyu Lai 2552*7dc08ffcSJunyu Lai* integrity verification should pass 2553*7dc08ffcSJunyu Laid = sa.decrypt(e) 2554*7dc08ffcSJunyu Laid 2555*7dc08ffcSJunyu Lai 2556*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2557*7dc08ffcSJunyu Laiassert(d == p) 2558*7dc08ffcSJunyu Lai 2559*7dc08ffcSJunyu Lai####################################### 2560*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - SHA2-512-256 - altered packet 2561*7dc08ffcSJunyu Lai 2562*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2563*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2564*7dc08ffcSJunyu Laip /= Raw('testdata') 2565*7dc08ffcSJunyu Laip = IP(raw(p)) 2566*7dc08ffcSJunyu Laip 2567*7dc08ffcSJunyu Lai 2568*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2569*7dc08ffcSJunyu Lai auth_algo='SHA2-512-256', auth_key=b'secret key', 2570*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2571*7dc08ffcSJunyu Lai 2572*7dc08ffcSJunyu Laie = sa.encrypt(p) 2573*7dc08ffcSJunyu Laie 2574*7dc08ffcSJunyu Lai 2575*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2576*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2577*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2578*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2579*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2580*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2581*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2582*7dc08ffcSJunyu Lai 2583*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2584*7dc08ffcSJunyu Laie.dst = '4.4.4.4' 2585*7dc08ffcSJunyu Lai 2586*7dc08ffcSJunyu Lai* integrity verification should fail 2587*7dc08ffcSJunyu Laitry: 2588*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2589*7dc08ffcSJunyu Lai assert(False) 2590*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2591*7dc08ffcSJunyu Lai err 2592*7dc08ffcSJunyu Lai 2593*7dc08ffcSJunyu Lai####################################### 2594*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - HMAC-MD5-96 2595*7dc08ffcSJunyu Lai 2596*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2597*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2598*7dc08ffcSJunyu Laip /= Raw('testdata') 2599*7dc08ffcSJunyu Laip = IP(raw(p)) 2600*7dc08ffcSJunyu Laip 2601*7dc08ffcSJunyu Lai 2602*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2603*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key', 2604*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2605*7dc08ffcSJunyu Lai 2606*7dc08ffcSJunyu Laie = sa.encrypt(p) 2607*7dc08ffcSJunyu Laie 2608*7dc08ffcSJunyu Lai 2609*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2610*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2611*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2612*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2613*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2614*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2615*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2616*7dc08ffcSJunyu Lai 2617*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2618*7dc08ffcSJunyu Laie.ttl = 2 2619*7dc08ffcSJunyu Lai 2620*7dc08ffcSJunyu Lai* integrity verification should pass 2621*7dc08ffcSJunyu Laid = sa.decrypt(e) 2622*7dc08ffcSJunyu Laid 2623*7dc08ffcSJunyu Lai 2624*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2625*7dc08ffcSJunyu Laiassert(d == p) 2626*7dc08ffcSJunyu Lai 2627*7dc08ffcSJunyu Lai####################################### 2628*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - HMAC-MD5-96 - altered packet 2629*7dc08ffcSJunyu Lai 2630*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2631*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2632*7dc08ffcSJunyu Laip /= Raw('testdata') 2633*7dc08ffcSJunyu Laip = IP(raw(p)) 2634*7dc08ffcSJunyu Laip 2635*7dc08ffcSJunyu Lai 2636*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2637*7dc08ffcSJunyu Lai auth_algo='HMAC-MD5-96', auth_key=b'secret key', 2638*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2639*7dc08ffcSJunyu Lai 2640*7dc08ffcSJunyu Laie = sa.encrypt(p) 2641*7dc08ffcSJunyu Laie 2642*7dc08ffcSJunyu Lai 2643*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2644*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2645*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2646*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2647*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2648*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2649*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2650*7dc08ffcSJunyu Lai 2651*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2652*7dc08ffcSJunyu Laie.dst = '4.4.4.4' 2653*7dc08ffcSJunyu Lai 2654*7dc08ffcSJunyu Lai* integrity verification should fail 2655*7dc08ffcSJunyu Laitry: 2656*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2657*7dc08ffcSJunyu Lai assert(False) 2658*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2659*7dc08ffcSJunyu Lai err 2660*7dc08ffcSJunyu Lai 2661*7dc08ffcSJunyu Lai####################################### 2662*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - AES-CMAC-96 2663*7dc08ffcSJunyu Lai 2664*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2665*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2666*7dc08ffcSJunyu Laip /= Raw('testdata') 2667*7dc08ffcSJunyu Laip = IP(raw(p)) 2668*7dc08ffcSJunyu Laip 2669*7dc08ffcSJunyu Lai 2670*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2671*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key', 2672*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2673*7dc08ffcSJunyu Lai 2674*7dc08ffcSJunyu Laie = sa.encrypt(p) 2675*7dc08ffcSJunyu Laie 2676*7dc08ffcSJunyu Lai 2677*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2678*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2679*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2680*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2681*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2682*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2683*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2684*7dc08ffcSJunyu Lai 2685*7dc08ffcSJunyu Lai* alter mutable fields in the packet 2686*7dc08ffcSJunyu Laie.ttl = 2 2687*7dc08ffcSJunyu Lai 2688*7dc08ffcSJunyu Lai* integrity verification should pass 2689*7dc08ffcSJunyu Laid = sa.decrypt(e) 2690*7dc08ffcSJunyu Laid 2691*7dc08ffcSJunyu Lai 2692*7dc08ffcSJunyu Lai* after decryption the original packet should be unaltered 2693*7dc08ffcSJunyu Laiassert(d == p) 2694*7dc08ffcSJunyu Lai 2695*7dc08ffcSJunyu Lai####################################### 2696*7dc08ffcSJunyu Lai= IPv4 / AH - Tunnel - AES-CMAC-96 - altered packet 2697*7dc08ffcSJunyu Lai 2698*7dc08ffcSJunyu Laip = IP(src='1.1.1.1', dst='2.2.2.2') 2699*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2700*7dc08ffcSJunyu Laip /= Raw('testdata') 2701*7dc08ffcSJunyu Laip = IP(raw(p)) 2702*7dc08ffcSJunyu Laip 2703*7dc08ffcSJunyu Lai 2704*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 2705*7dc08ffcSJunyu Lai auth_algo='AES-CMAC-96', auth_key=b'sixteenbytes key', 2706*7dc08ffcSJunyu Lai tunnel_header=IP(src='11.11.11.11', dst='22.22.22.22')) 2707*7dc08ffcSJunyu Lai 2708*7dc08ffcSJunyu Laie = sa.encrypt(p) 2709*7dc08ffcSJunyu Laie 2710*7dc08ffcSJunyu Lai 2711*7dc08ffcSJunyu Laiassert(isinstance(e, IP)) 2712*7dc08ffcSJunyu Laiassert(e.src == '11.11.11.11' and e.dst == '22.22.22.22') 2713*7dc08ffcSJunyu Laiassert(e.chksum != p.chksum) 2714*7dc08ffcSJunyu Laiassert(e.proto == socket.IPPROTO_AH) 2715*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 2716*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 2717*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 2718*7dc08ffcSJunyu Lai 2719*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 2720*7dc08ffcSJunyu Laie.dst = '4.4.4.4' 2721*7dc08ffcSJunyu Lai 2722*7dc08ffcSJunyu Lai* integrity verification should fail 2723*7dc08ffcSJunyu Laitry: 2724*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2725*7dc08ffcSJunyu Lai assert(False) 2726*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2727*7dc08ffcSJunyu Lai err 2728*7dc08ffcSJunyu Lai 2729*7dc08ffcSJunyu Lai############################################################################### 2730*7dc08ffcSJunyu Lai+ IPv6 / ESP 2731*7dc08ffcSJunyu Lai 2732*7dc08ffcSJunyu Lai####################################### 2733*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - NULL - NULL 2734*7dc08ffcSJunyu Lai~ -crypto 2735*7dc08ffcSJunyu Lai 2736*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2737*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2738*7dc08ffcSJunyu Laip /= Raw('testdata') 2739*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2740*7dc08ffcSJunyu Laip 2741*7dc08ffcSJunyu Lai 2742*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2743*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 2744*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 2745*7dc08ffcSJunyu Lai 2746*7dc08ffcSJunyu Laie = sa.encrypt(p) 2747*7dc08ffcSJunyu Laie 2748*7dc08ffcSJunyu Lai 2749*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2750*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2751*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2752*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2753*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2754*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2755*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 2756*7dc08ffcSJunyu Lai 2757*7dc08ffcSJunyu Laid = sa.decrypt(e) 2758*7dc08ffcSJunyu Laid 2759*7dc08ffcSJunyu Lai 2760*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 2761*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2762*7dc08ffcSJunyu Lai 2763*7dc08ffcSJunyu Lai####################################### 2764*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - AES-CBC - NULL 2765*7dc08ffcSJunyu Lai 2766*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2767*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2768*7dc08ffcSJunyu Laip /= Raw('testdata') 2769*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2770*7dc08ffcSJunyu Laip 2771*7dc08ffcSJunyu Lai 2772*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2773*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 2774*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 2775*7dc08ffcSJunyu Lai 2776*7dc08ffcSJunyu Laie = sa.encrypt(p) 2777*7dc08ffcSJunyu Laie 2778*7dc08ffcSJunyu Lai 2779*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2780*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2781*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2782*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2783*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2784*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2785*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 2786*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 2787*7dc08ffcSJunyu Lai 2788*7dc08ffcSJunyu Laid = sa.decrypt(e) 2789*7dc08ffcSJunyu Laid 2790*7dc08ffcSJunyu Lai 2791*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 2792*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2793*7dc08ffcSJunyu Lai 2794*7dc08ffcSJunyu Lai####################################### 2795*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - NULL - HMAC-SHA1-96 2796*7dc08ffcSJunyu Lai 2797*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2798*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2799*7dc08ffcSJunyu Laip /= Raw('testdata') 2800*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2801*7dc08ffcSJunyu Laip 2802*7dc08ffcSJunyu Lai 2803*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2804*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 2805*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 2806*7dc08ffcSJunyu Lai 2807*7dc08ffcSJunyu Laie = sa.encrypt(p) 2808*7dc08ffcSJunyu Laie 2809*7dc08ffcSJunyu Lai 2810*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2811*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2812*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2813*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2814*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2815*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2816*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 2817*7dc08ffcSJunyu Lai 2818*7dc08ffcSJunyu Lai* integrity verification should pass 2819*7dc08ffcSJunyu Laid = sa.decrypt(e) 2820*7dc08ffcSJunyu Lai 2821*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 2822*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2823*7dc08ffcSJunyu Lai 2824*7dc08ffcSJunyu Lai####################################### 2825*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - NULL - HMAC-SHA1-96 - altered packet 2826*7dc08ffcSJunyu Lai 2827*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2828*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2829*7dc08ffcSJunyu Laip /= Raw('testdata') 2830*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2831*7dc08ffcSJunyu Laip 2832*7dc08ffcSJunyu Lai 2833*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2834*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 2835*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 2836*7dc08ffcSJunyu Lai 2837*7dc08ffcSJunyu Laie = sa.encrypt(p) 2838*7dc08ffcSJunyu Laie 2839*7dc08ffcSJunyu Lai 2840*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2841*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2842*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2843*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2844*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2845*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2846*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 2847*7dc08ffcSJunyu Lai 2848*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 2849*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 2850*7dc08ffcSJunyu Lai 2851*7dc08ffcSJunyu Lai* integrity verification should fail 2852*7dc08ffcSJunyu Laitry: 2853*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2854*7dc08ffcSJunyu Lai assert(False) 2855*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2856*7dc08ffcSJunyu Lai err 2857*7dc08ffcSJunyu Lai 2858*7dc08ffcSJunyu Lai####################################### 2859*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - AES-CBC - HMAC-SHA1-96 2860*7dc08ffcSJunyu Lai 2861*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2862*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2863*7dc08ffcSJunyu Laip /= Raw('testdata') 2864*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2865*7dc08ffcSJunyu Laip 2866*7dc08ffcSJunyu Lai 2867*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2868*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 2869*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 2870*7dc08ffcSJunyu Lai 2871*7dc08ffcSJunyu Laie = sa.encrypt(p) 2872*7dc08ffcSJunyu Laie 2873*7dc08ffcSJunyu Lai 2874*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2875*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2876*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2877*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2878*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2879*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2880*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 2881*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 2882*7dc08ffcSJunyu Lai 2883*7dc08ffcSJunyu Laid = sa.decrypt(e) 2884*7dc08ffcSJunyu Laid 2885*7dc08ffcSJunyu Lai 2886*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 2887*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2888*7dc08ffcSJunyu Lai 2889*7dc08ffcSJunyu Lai####################################### 2890*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - AES-CBC - HMAC-SHA1-96 - altered packet 2891*7dc08ffcSJunyu Lai 2892*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2893*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2894*7dc08ffcSJunyu Laip /= Raw('testdata') 2895*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2896*7dc08ffcSJunyu Laip 2897*7dc08ffcSJunyu Lai 2898*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2899*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 2900*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 2901*7dc08ffcSJunyu Lai 2902*7dc08ffcSJunyu Laie = sa.encrypt(p) 2903*7dc08ffcSJunyu Laie 2904*7dc08ffcSJunyu Lai 2905*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2906*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2907*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2908*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2909*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2910*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2911*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 2912*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 2913*7dc08ffcSJunyu Lai 2914*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 2915*7dc08ffcSJunyu Laie[ESP].seq += 1 2916*7dc08ffcSJunyu Lai 2917*7dc08ffcSJunyu Lai* integrity verification should fail 2918*7dc08ffcSJunyu Laitry: 2919*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2920*7dc08ffcSJunyu Lai assert(False) 2921*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2922*7dc08ffcSJunyu Lai err 2923*7dc08ffcSJunyu Lai 2924*7dc08ffcSJunyu Lai####################################### 2925*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - AES-GCM - NULL 2926*7dc08ffcSJunyu Lai 2927*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2928*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2929*7dc08ffcSJunyu Laip /= Raw('testdata') 2930*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2931*7dc08ffcSJunyu Laip 2932*7dc08ffcSJunyu Lai 2933*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2934*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 2935*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 2936*7dc08ffcSJunyu Lai 2937*7dc08ffcSJunyu Laie = sa.encrypt(p) 2938*7dc08ffcSJunyu Laie 2939*7dc08ffcSJunyu Lai 2940*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2941*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2942*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2943*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2944*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2945*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2946*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 2947*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 2948*7dc08ffcSJunyu Lai 2949*7dc08ffcSJunyu Laid = sa.decrypt(e) 2950*7dc08ffcSJunyu Laid 2951*7dc08ffcSJunyu Lai 2952*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 2953*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 2954*7dc08ffcSJunyu Lai 2955*7dc08ffcSJunyu Lai####################################### 2956*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - AES-GCM - NULL - altered packet 2957*7dc08ffcSJunyu Lai 2958*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2959*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2960*7dc08ffcSJunyu Laip /= Raw('testdata') 2961*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2962*7dc08ffcSJunyu Laip 2963*7dc08ffcSJunyu Lai 2964*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 2965*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 2966*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 2967*7dc08ffcSJunyu Lai 2968*7dc08ffcSJunyu Laie = sa.encrypt(p) 2969*7dc08ffcSJunyu Laie 2970*7dc08ffcSJunyu Lai 2971*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 2972*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 2973*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 2974*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 2975*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 2976*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 2977*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 2978*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 2979*7dc08ffcSJunyu Lai 2980*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 2981*7dc08ffcSJunyu Laie[ESP].seq += 1 2982*7dc08ffcSJunyu Lai 2983*7dc08ffcSJunyu Lai* integrity verification should fail 2984*7dc08ffcSJunyu Laitry: 2985*7dc08ffcSJunyu Lai d = sa.decrypt(e) 2986*7dc08ffcSJunyu Lai assert(False) 2987*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 2988*7dc08ffcSJunyu Lai err 2989*7dc08ffcSJunyu Lai 2990*7dc08ffcSJunyu Lai####################################### 2991*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - AES-CCM - NULL 2992*7dc08ffcSJunyu Lai~ crypto_advanced 2993*7dc08ffcSJunyu Lai 2994*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 2995*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 2996*7dc08ffcSJunyu Laip /= Raw('testdata') 2997*7dc08ffcSJunyu Laip = IPv6(raw(p)) 2998*7dc08ffcSJunyu Laip 2999*7dc08ffcSJunyu Lai 3000*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3001*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 3002*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 3003*7dc08ffcSJunyu Lai 3004*7dc08ffcSJunyu Laie = sa.encrypt(p) 3005*7dc08ffcSJunyu Laie 3006*7dc08ffcSJunyu Lai 3007*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3008*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3009*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3010*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3011*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3012*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3013*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3014*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3015*7dc08ffcSJunyu Lai 3016*7dc08ffcSJunyu Laid = sa.decrypt(e) 3017*7dc08ffcSJunyu Laid 3018*7dc08ffcSJunyu Lai 3019*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 3020*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3021*7dc08ffcSJunyu Lai 3022*7dc08ffcSJunyu Lai####################################### 3023*7dc08ffcSJunyu Lai= IPv6 / ESP - Transport - AES-CCM - NULL - altered packet 3024*7dc08ffcSJunyu Lai~ crypto_advanced 3025*7dc08ffcSJunyu Lai 3026*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3027*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3028*7dc08ffcSJunyu Laip /= Raw('testdata') 3029*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3030*7dc08ffcSJunyu Laip 3031*7dc08ffcSJunyu Lai 3032*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3033*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 3034*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None) 3035*7dc08ffcSJunyu Lai 3036*7dc08ffcSJunyu Laie = sa.encrypt(p) 3037*7dc08ffcSJunyu Laie 3038*7dc08ffcSJunyu Lai 3039*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3040*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3041*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3042*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3043*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3044*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3045*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3046*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3047*7dc08ffcSJunyu Lai 3048*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 3049*7dc08ffcSJunyu Laie[ESP].seq += 1 3050*7dc08ffcSJunyu Lai 3051*7dc08ffcSJunyu Lai* integrity verification should fail 3052*7dc08ffcSJunyu Laitry: 3053*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3054*7dc08ffcSJunyu Lai assert(False) 3055*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3056*7dc08ffcSJunyu Lai err 3057*7dc08ffcSJunyu Lai 3058*7dc08ffcSJunyu Lai####################################### 3059*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - NULL - NULL 3060*7dc08ffcSJunyu Lai~ -crypto 3061*7dc08ffcSJunyu Lai 3062*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3063*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3064*7dc08ffcSJunyu Laip /= Raw('testdata') 3065*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3066*7dc08ffcSJunyu Laip 3067*7dc08ffcSJunyu Lai 3068*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3069*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 3070*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 3071*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3072*7dc08ffcSJunyu Lai 3073*7dc08ffcSJunyu Laie = sa.encrypt(p) 3074*7dc08ffcSJunyu Laie 3075*7dc08ffcSJunyu Lai 3076*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3077*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3078*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3079*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3080*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3081*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3082*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3083*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 3084*7dc08ffcSJunyu Lai 3085*7dc08ffcSJunyu Laid = sa.decrypt(e) 3086*7dc08ffcSJunyu Laid 3087*7dc08ffcSJunyu Lai 3088*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3089*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3090*7dc08ffcSJunyu Lai 3091*7dc08ffcSJunyu Lai####################################### 3092*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - AES-CBC - NULL 3093*7dc08ffcSJunyu Lai 3094*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3095*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3096*7dc08ffcSJunyu Laip /= Raw('testdata') 3097*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3098*7dc08ffcSJunyu Laip 3099*7dc08ffcSJunyu Lai 3100*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3101*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 3102*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 3103*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3104*7dc08ffcSJunyu Lai 3105*7dc08ffcSJunyu Laie = sa.encrypt(p) 3106*7dc08ffcSJunyu Laie 3107*7dc08ffcSJunyu Lai 3108*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3109*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3110*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3111*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3112*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3113*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3114*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3115*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3116*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3117*7dc08ffcSJunyu Lai 3118*7dc08ffcSJunyu Laid = sa.decrypt(e) 3119*7dc08ffcSJunyu Laid 3120*7dc08ffcSJunyu Lai 3121*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3122*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3123*7dc08ffcSJunyu Lai 3124*7dc08ffcSJunyu Lai####################################### 3125*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - NULL - HMAC-SHA1-96 3126*7dc08ffcSJunyu Lai 3127*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3128*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3129*7dc08ffcSJunyu Laip /= Raw('testdata') 3130*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3131*7dc08ffcSJunyu Laip 3132*7dc08ffcSJunyu Lai 3133*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3134*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 3135*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 3136*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3137*7dc08ffcSJunyu Lai 3138*7dc08ffcSJunyu Laie = sa.encrypt(p) 3139*7dc08ffcSJunyu Laie 3140*7dc08ffcSJunyu Lai 3141*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3142*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3143*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3144*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3145*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3146*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3147*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3148*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 3149*7dc08ffcSJunyu Lai 3150*7dc08ffcSJunyu Lai* integrity verification should pass 3151*7dc08ffcSJunyu Laid = sa.decrypt(e) 3152*7dc08ffcSJunyu Lai 3153*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3154*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3155*7dc08ffcSJunyu Lai 3156*7dc08ffcSJunyu Lai####################################### 3157*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - NULL - HMAC-SHA1-96 - altered packet 3158*7dc08ffcSJunyu Lai 3159*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3160*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3161*7dc08ffcSJunyu Laip /= Raw('testdata') 3162*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3163*7dc08ffcSJunyu Laip 3164*7dc08ffcSJunyu Lai 3165*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3166*7dc08ffcSJunyu Lai crypt_algo='NULL', crypt_key=None, 3167*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 3168*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3169*7dc08ffcSJunyu Lai 3170*7dc08ffcSJunyu Laie = sa.encrypt(p) 3171*7dc08ffcSJunyu Laie 3172*7dc08ffcSJunyu Lai 3173*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3174*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3175*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3176*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3177*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3178*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3179*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3180*7dc08ffcSJunyu Laiassert(b'testdata' in e[ESP].data) 3181*7dc08ffcSJunyu Lai 3182*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 3183*7dc08ffcSJunyu Laie[ESP].data = e[ESP].data.replace(b'\x01', b'\x21') 3184*7dc08ffcSJunyu Lai 3185*7dc08ffcSJunyu Lai* integrity verification should fail 3186*7dc08ffcSJunyu Laitry: 3187*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3188*7dc08ffcSJunyu Lai assert(False) 3189*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3190*7dc08ffcSJunyu Lai err 3191*7dc08ffcSJunyu Lai 3192*7dc08ffcSJunyu Lai####################################### 3193*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - AES-CBC - HMAC-SHA1-96 3194*7dc08ffcSJunyu Lai 3195*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3196*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3197*7dc08ffcSJunyu Laip /= Raw('testdata') 3198*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3199*7dc08ffcSJunyu Laip 3200*7dc08ffcSJunyu Lai 3201*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3202*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 3203*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 3204*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3205*7dc08ffcSJunyu Lai 3206*7dc08ffcSJunyu Laie = sa.encrypt(p) 3207*7dc08ffcSJunyu Laie 3208*7dc08ffcSJunyu Lai 3209*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3210*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3211*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3212*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3213*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3214*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3215*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3216*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3217*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3218*7dc08ffcSJunyu Lai 3219*7dc08ffcSJunyu Laid = sa.decrypt(e) 3220*7dc08ffcSJunyu Laid 3221*7dc08ffcSJunyu Lai 3222*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3223*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3224*7dc08ffcSJunyu Lai 3225*7dc08ffcSJunyu Lai####################################### 3226*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - AES-CBC - HMAC-SHA1-96 - altered packet 3227*7dc08ffcSJunyu Lai 3228*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3229*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3230*7dc08ffcSJunyu Laip /= Raw('testdata') 3231*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3232*7dc08ffcSJunyu Laip 3233*7dc08ffcSJunyu Lai 3234*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3235*7dc08ffcSJunyu Lai crypt_algo='AES-CBC', crypt_key=b'sixteenbytes key', 3236*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 3237*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3238*7dc08ffcSJunyu Lai 3239*7dc08ffcSJunyu Laie = sa.encrypt(p) 3240*7dc08ffcSJunyu Laie 3241*7dc08ffcSJunyu Lai 3242*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3243*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3244*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3245*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3246*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3247*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3248*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3249*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3250*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3251*7dc08ffcSJunyu Lai 3252*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 3253*7dc08ffcSJunyu Laie[ESP].seq += 1 3254*7dc08ffcSJunyu Lai 3255*7dc08ffcSJunyu Lai* integrity verification should fail 3256*7dc08ffcSJunyu Laitry: 3257*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3258*7dc08ffcSJunyu Lai assert(False) 3259*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3260*7dc08ffcSJunyu Lai err 3261*7dc08ffcSJunyu Lai 3262*7dc08ffcSJunyu Lai####################################### 3263*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - AES-GCM - NULL 3264*7dc08ffcSJunyu Lai 3265*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3266*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3267*7dc08ffcSJunyu Laip /= Raw('testdata') 3268*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3269*7dc08ffcSJunyu Laip 3270*7dc08ffcSJunyu Lai 3271*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3272*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 3273*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 3274*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3275*7dc08ffcSJunyu Lai 3276*7dc08ffcSJunyu Laie = sa.encrypt(p) 3277*7dc08ffcSJunyu Laie 3278*7dc08ffcSJunyu Lai 3279*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3280*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3281*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3282*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3283*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3284*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3285*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3286*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3287*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3288*7dc08ffcSJunyu Lai 3289*7dc08ffcSJunyu Laid = sa.decrypt(e) 3290*7dc08ffcSJunyu Laid 3291*7dc08ffcSJunyu Lai 3292*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 3293*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3294*7dc08ffcSJunyu Lai 3295*7dc08ffcSJunyu Lai####################################### 3296*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - AES-GCM - NULL - altered packet 3297*7dc08ffcSJunyu Lai 3298*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3299*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3300*7dc08ffcSJunyu Laip /= Raw('testdata') 3301*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3302*7dc08ffcSJunyu Laip 3303*7dc08ffcSJunyu Lai 3304*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3305*7dc08ffcSJunyu Lai crypt_algo='AES-GCM', crypt_key=b'16bytekey+4bytenonce', 3306*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 3307*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3308*7dc08ffcSJunyu Lai 3309*7dc08ffcSJunyu Laie = sa.encrypt(p) 3310*7dc08ffcSJunyu Laie 3311*7dc08ffcSJunyu Lai 3312*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3313*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3314*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3315*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3316*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3317*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3318*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3319*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3320*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3321*7dc08ffcSJunyu Lai 3322*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 3323*7dc08ffcSJunyu Laie[ESP].seq += 1 3324*7dc08ffcSJunyu Lai 3325*7dc08ffcSJunyu Lai* integrity verification should fail 3326*7dc08ffcSJunyu Laitry: 3327*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3328*7dc08ffcSJunyu Lai assert(False) 3329*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3330*7dc08ffcSJunyu Lai err 3331*7dc08ffcSJunyu Lai 3332*7dc08ffcSJunyu Lai####################################### 3333*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - AES-CCM - NULL 3334*7dc08ffcSJunyu Lai~ crypto_advanced 3335*7dc08ffcSJunyu Lai 3336*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3337*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3338*7dc08ffcSJunyu Laip /= Raw('testdata') 3339*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3340*7dc08ffcSJunyu Laip 3341*7dc08ffcSJunyu Lai 3342*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3343*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 3344*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 3345*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3346*7dc08ffcSJunyu Lai 3347*7dc08ffcSJunyu Laie = sa.encrypt(p) 3348*7dc08ffcSJunyu Laie 3349*7dc08ffcSJunyu Lai 3350*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3351*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3352*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3353*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3354*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3355*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3356*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3357*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3358*7dc08ffcSJunyu Lai 3359*7dc08ffcSJunyu Laid = sa.decrypt(e) 3360*7dc08ffcSJunyu Laid 3361*7dc08ffcSJunyu Lai 3362*7dc08ffcSJunyu Lai* after decryption original packet should be preserved 3363*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3364*7dc08ffcSJunyu Lai 3365*7dc08ffcSJunyu Lai####################################### 3366*7dc08ffcSJunyu Lai= IPv6 / ESP - Tunnel - AES-CCM - NULL - altered packet 3367*7dc08ffcSJunyu Lai~ crypto_advanced 3368*7dc08ffcSJunyu Lai 3369*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3370*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3371*7dc08ffcSJunyu Laip /= Raw('testdata') 3372*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3373*7dc08ffcSJunyu Laip 3374*7dc08ffcSJunyu Lai 3375*7dc08ffcSJunyu Laisa = SecurityAssociation(ESP, spi=0x222, 3376*7dc08ffcSJunyu Lai crypt_algo='AES-CCM', crypt_key=b'16bytekey3bytenonce', 3377*7dc08ffcSJunyu Lai auth_algo='NULL', auth_key=None, 3378*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3379*7dc08ffcSJunyu Lai 3380*7dc08ffcSJunyu Laie = sa.encrypt(p) 3381*7dc08ffcSJunyu Laie 3382*7dc08ffcSJunyu Lai 3383*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3384*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3385*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_ESP) 3386*7dc08ffcSJunyu Laiassert(e.haslayer(ESP)) 3387*7dc08ffcSJunyu Laiassert(not e.haslayer(TCP)) 3388*7dc08ffcSJunyu Laiassert(e[ESP].spi == sa.spi) 3389*7dc08ffcSJunyu Lai* after encryption the original packet payload should NOT be readable 3390*7dc08ffcSJunyu Laiassert(b'testdata' not in e[ESP].data) 3391*7dc08ffcSJunyu Lai 3392*7dc08ffcSJunyu Lai* simulate the alteration of the packet before decryption 3393*7dc08ffcSJunyu Laie[ESP].seq += 1 3394*7dc08ffcSJunyu Lai 3395*7dc08ffcSJunyu Lai* integrity verification should fail 3396*7dc08ffcSJunyu Laitry: 3397*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3398*7dc08ffcSJunyu Lai assert(False) 3399*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3400*7dc08ffcSJunyu Lai err 3401*7dc08ffcSJunyu Lai 3402*7dc08ffcSJunyu Lai####################################### 3403*7dc08ffcSJunyu Lai############################################################################### 3404*7dc08ffcSJunyu Lai+ IPv6 / AH 3405*7dc08ffcSJunyu Lai 3406*7dc08ffcSJunyu Lai####################################### 3407*7dc08ffcSJunyu Lai= IPv6 / AH - Transport - HMAC-SHA1-96 3408*7dc08ffcSJunyu Lai 3409*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3410*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3411*7dc08ffcSJunyu Laip /= Raw('testdata') 3412*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3413*7dc08ffcSJunyu Laip 3414*7dc08ffcSJunyu Lai 3415*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3416*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 3417*7dc08ffcSJunyu Lai 3418*7dc08ffcSJunyu Laie = sa.encrypt(p) 3419*7dc08ffcSJunyu Laie 3420*7dc08ffcSJunyu Lai 3421*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3422*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3423*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 3424*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3425*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3426*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3427*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3428*7dc08ffcSJunyu Lai 3429*7dc08ffcSJunyu Lai* alter mutable fields in the packet 3430*7dc08ffcSJunyu Laie.hlim = 2 3431*7dc08ffcSJunyu Lai 3432*7dc08ffcSJunyu Lai* integrity verification should pass 3433*7dc08ffcSJunyu Laid = sa.decrypt(e) 3434*7dc08ffcSJunyu Laid 3435*7dc08ffcSJunyu Lai 3436*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3437*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3438*7dc08ffcSJunyu Lai 3439*7dc08ffcSJunyu Lai####################################### 3440*7dc08ffcSJunyu Lai= IPv6 / AH - Transport - HMAC-SHA1-96 - altered packet 3441*7dc08ffcSJunyu Lai 3442*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3443*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3444*7dc08ffcSJunyu Laip /= Raw('testdata') 3445*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3446*7dc08ffcSJunyu Laip 3447*7dc08ffcSJunyu Lai 3448*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3449*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 3450*7dc08ffcSJunyu Lai 3451*7dc08ffcSJunyu Laie = sa.encrypt(p) 3452*7dc08ffcSJunyu Laie 3453*7dc08ffcSJunyu Lai 3454*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3455*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3456*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 3457*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3458*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3459*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3460*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3461*7dc08ffcSJunyu Lai 3462*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 3463*7dc08ffcSJunyu Laie[TCP].dport = 46 3464*7dc08ffcSJunyu Lai 3465*7dc08ffcSJunyu Lai* integrity verification should fail 3466*7dc08ffcSJunyu Laitry: 3467*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3468*7dc08ffcSJunyu Lai assert(False) 3469*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3470*7dc08ffcSJunyu Lai err 3471*7dc08ffcSJunyu Lai 3472*7dc08ffcSJunyu Lai####################################### 3473*7dc08ffcSJunyu Lai= IPv6 / AH - Transport - SHA2-256-128 3474*7dc08ffcSJunyu Lai 3475*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3476*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3477*7dc08ffcSJunyu Laip /= Raw('testdata') 3478*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3479*7dc08ffcSJunyu Laip 3480*7dc08ffcSJunyu Lai 3481*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3482*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key') 3483*7dc08ffcSJunyu Lai 3484*7dc08ffcSJunyu Laie = sa.encrypt(p) 3485*7dc08ffcSJunyu Laie 3486*7dc08ffcSJunyu Lai 3487*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3488*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3489*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 3490*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3491*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3492*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3493*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3494*7dc08ffcSJunyu Lai 3495*7dc08ffcSJunyu Lai* alter mutable fields in the packet 3496*7dc08ffcSJunyu Laie.hlim = 2 3497*7dc08ffcSJunyu Lai 3498*7dc08ffcSJunyu Lai* integrity verification should pass 3499*7dc08ffcSJunyu Laid = sa.decrypt(e) 3500*7dc08ffcSJunyu Laid 3501*7dc08ffcSJunyu Lai 3502*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3503*7dc08ffcSJunyu Laiassert(d[TCP] == p[TCP]) 3504*7dc08ffcSJunyu Lai 3505*7dc08ffcSJunyu Lai####################################### 3506*7dc08ffcSJunyu Lai= IPv6 / AH - Transport - SHA2-256-128 - altered packet 3507*7dc08ffcSJunyu Lai 3508*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3509*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3510*7dc08ffcSJunyu Laip /= Raw('testdata') 3511*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3512*7dc08ffcSJunyu Laip 3513*7dc08ffcSJunyu Lai 3514*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3515*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key') 3516*7dc08ffcSJunyu Lai 3517*7dc08ffcSJunyu Laie = sa.encrypt(p) 3518*7dc08ffcSJunyu Laie 3519*7dc08ffcSJunyu Lai 3520*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3521*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3522*7dc08ffcSJunyu Lai* the encrypted packet should have an AH layer 3523*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3524*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3525*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3526*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3527*7dc08ffcSJunyu Lai 3528*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 3529*7dc08ffcSJunyu Laie[TCP].dport = 46 3530*7dc08ffcSJunyu Lai 3531*7dc08ffcSJunyu Lai* integrity verification should fail 3532*7dc08ffcSJunyu Laitry: 3533*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3534*7dc08ffcSJunyu Lai assert(False) 3535*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3536*7dc08ffcSJunyu Lai err 3537*7dc08ffcSJunyu Lai 3538*7dc08ffcSJunyu Lai####################################### 3539*7dc08ffcSJunyu Lai= IPv6 / AH - Tunnel - HMAC-SHA1-96 3540*7dc08ffcSJunyu Lai 3541*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3542*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3543*7dc08ffcSJunyu Laip /= Raw('testdata') 3544*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3545*7dc08ffcSJunyu Laip 3546*7dc08ffcSJunyu Lai 3547*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3548*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 3549*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3550*7dc08ffcSJunyu Lai 3551*7dc08ffcSJunyu Laie = sa.encrypt(p) 3552*7dc08ffcSJunyu Laie 3553*7dc08ffcSJunyu Lai 3554*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3555*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3556*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3557*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3558*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3559*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3560*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3561*7dc08ffcSJunyu Lai 3562*7dc08ffcSJunyu Lai* alter mutable fields in the packet 3563*7dc08ffcSJunyu Laie.hlim = 2 3564*7dc08ffcSJunyu Lai 3565*7dc08ffcSJunyu Lai* integrity verification should pass 3566*7dc08ffcSJunyu Laid = sa.decrypt(e) 3567*7dc08ffcSJunyu Laid 3568*7dc08ffcSJunyu Lai 3569*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3570*7dc08ffcSJunyu Laiassert(d == p) 3571*7dc08ffcSJunyu Lai 3572*7dc08ffcSJunyu Lai####################################### 3573*7dc08ffcSJunyu Lai= IPv6 / AH - Tunnel - HMAC-SHA1-96 - altered packet 3574*7dc08ffcSJunyu Lai 3575*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3576*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3577*7dc08ffcSJunyu Laip /= Raw('testdata') 3578*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3579*7dc08ffcSJunyu Laip 3580*7dc08ffcSJunyu Lai 3581*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3582*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key', 3583*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3584*7dc08ffcSJunyu Lai 3585*7dc08ffcSJunyu Laie = sa.encrypt(p) 3586*7dc08ffcSJunyu Laie 3587*7dc08ffcSJunyu Lai 3588*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3589*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3590*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3591*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3592*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3593*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3594*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3595*7dc08ffcSJunyu Lai 3596*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 3597*7dc08ffcSJunyu Laie.src = 'cc::ee' 3598*7dc08ffcSJunyu Lai 3599*7dc08ffcSJunyu Lai* integrity verification should fail 3600*7dc08ffcSJunyu Laitry: 3601*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3602*7dc08ffcSJunyu Lai assert(False) 3603*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3604*7dc08ffcSJunyu Lai err 3605*7dc08ffcSJunyu Lai 3606*7dc08ffcSJunyu Lai####################################### 3607*7dc08ffcSJunyu Lai= IPv6 / AH - Tunnel - SHA2-256-128 3608*7dc08ffcSJunyu Lai 3609*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3610*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3611*7dc08ffcSJunyu Laip /= Raw('testdata') 3612*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3613*7dc08ffcSJunyu Laip 3614*7dc08ffcSJunyu Lai 3615*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3616*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key', 3617*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3618*7dc08ffcSJunyu Lai 3619*7dc08ffcSJunyu Laie = sa.encrypt(p) 3620*7dc08ffcSJunyu Laie 3621*7dc08ffcSJunyu Lai 3622*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3623*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3624*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3625*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3626*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3627*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3628*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3629*7dc08ffcSJunyu Lai 3630*7dc08ffcSJunyu Lai* alter mutable fields in the packet 3631*7dc08ffcSJunyu Laie.hlim = 2 3632*7dc08ffcSJunyu Lai 3633*7dc08ffcSJunyu Lai* integrity verification should pass 3634*7dc08ffcSJunyu Laid = sa.decrypt(e) 3635*7dc08ffcSJunyu Laid 3636*7dc08ffcSJunyu Lai 3637*7dc08ffcSJunyu Lai* after decryption the original packet payload should be unaltered 3638*7dc08ffcSJunyu Laiassert(d == p) 3639*7dc08ffcSJunyu Lai 3640*7dc08ffcSJunyu Lai####################################### 3641*7dc08ffcSJunyu Lai= IPv6 / AH - Tunnel - SHA2-256-128 - altered packet 3642*7dc08ffcSJunyu Lai 3643*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3644*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3645*7dc08ffcSJunyu Laip /= Raw('testdata') 3646*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3647*7dc08ffcSJunyu Laip 3648*7dc08ffcSJunyu Lai 3649*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3650*7dc08ffcSJunyu Lai auth_algo='SHA2-256-128', auth_key=b'secret key', 3651*7dc08ffcSJunyu Lai tunnel_header=IPv6(src='aa::bb', dst='bb::aa')) 3652*7dc08ffcSJunyu Lai 3653*7dc08ffcSJunyu Laie = sa.encrypt(p) 3654*7dc08ffcSJunyu Laie 3655*7dc08ffcSJunyu Lai 3656*7dc08ffcSJunyu Laiassert(isinstance(e, IPv6)) 3657*7dc08ffcSJunyu Lai* after encryption packet should be encapsulated with the given ip tunnel header 3658*7dc08ffcSJunyu Laiassert(e.src == 'aa::bb' and e.dst == 'bb::aa') 3659*7dc08ffcSJunyu Laiassert(e.nh == socket.IPPROTO_AH) 3660*7dc08ffcSJunyu Laiassert(e.haslayer(AH)) 3661*7dc08ffcSJunyu Laiassert(e.haslayer(TCP)) 3662*7dc08ffcSJunyu Laiassert(e[AH].spi == sa.spi) 3663*7dc08ffcSJunyu Lai 3664*7dc08ffcSJunyu Lai* simulate the alteration of the packet before verification 3665*7dc08ffcSJunyu Laie.src = 'cc::ee' 3666*7dc08ffcSJunyu Lai 3667*7dc08ffcSJunyu Lai* integrity verification should fail 3668*7dc08ffcSJunyu Laitry: 3669*7dc08ffcSJunyu Lai d = sa.decrypt(e) 3670*7dc08ffcSJunyu Lai assert(False) 3671*7dc08ffcSJunyu Laiexcept IPSecIntegrityError as err: 3672*7dc08ffcSJunyu Lai err 3673*7dc08ffcSJunyu Lai 3674*7dc08ffcSJunyu Lai############################################################################### 3675*7dc08ffcSJunyu Lai+ IPv6 + Extensions / AH 3676*7dc08ffcSJunyu Lai 3677*7dc08ffcSJunyu Lai####################################### 3678*7dc08ffcSJunyu Lai= IPv6 + Extensions / AH - Transport 3679*7dc08ffcSJunyu Lai 3680*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3681*7dc08ffcSJunyu Laip /= IPv6ExtHdrHopByHop() 3682*7dc08ffcSJunyu Laip /= IPv6ExtHdrDestOpt() 3683*7dc08ffcSJunyu Laip /= IPv6ExtHdrRouting() 3684*7dc08ffcSJunyu Laip /= IPv6ExtHdrDestOpt() 3685*7dc08ffcSJunyu Laip /= IPv6ExtHdrFragment() 3686*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3687*7dc08ffcSJunyu Laip /= Raw('testdata') 3688*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3689*7dc08ffcSJunyu Laip 3690*7dc08ffcSJunyu Lai 3691*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3692*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 3693*7dc08ffcSJunyu Lai 3694*7dc08ffcSJunyu Laie = sa.encrypt(p) 3695*7dc08ffcSJunyu Laie 3696*7dc08ffcSJunyu Lai 3697*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3698*7dc08ffcSJunyu Lai* AH header should be inserted between the routing header and the dest options header 3699*7dc08ffcSJunyu Laiassert(isinstance(e[AH].underlayer, IPv6ExtHdrRouting)) 3700*7dc08ffcSJunyu Laiassert(isinstance(e[AH].payload, IPv6ExtHdrDestOpt)) 3701*7dc08ffcSJunyu Lai 3702*7dc08ffcSJunyu Lai####################################### 3703*7dc08ffcSJunyu Lai= IPv6 + Routing Header / AH - Transport 3704*7dc08ffcSJunyu Lai 3705*7dc08ffcSJunyu Laip = IPv6(src='11::22', dst='22::11') 3706*7dc08ffcSJunyu Laip /= IPv6ExtHdrHopByHop() 3707*7dc08ffcSJunyu Laip /= IPv6ExtHdrRouting(addresses=['aa::bb', 'cc::dd', 'ee::ff']) 3708*7dc08ffcSJunyu Laip /= TCP(sport=45012, dport=80) 3709*7dc08ffcSJunyu Laip /= Raw('testdata') 3710*7dc08ffcSJunyu Laip = IPv6(raw(p)) 3711*7dc08ffcSJunyu Laip 3712*7dc08ffcSJunyu Lai 3713*7dc08ffcSJunyu Laisa = SecurityAssociation(AH, spi=0x222, 3714*7dc08ffcSJunyu Lai auth_algo='HMAC-SHA1-96', auth_key=b'secret key') 3715*7dc08ffcSJunyu Lai 3716*7dc08ffcSJunyu Laie = sa.encrypt(p) 3717*7dc08ffcSJunyu Laie 3718*7dc08ffcSJunyu Lai 3719*7dc08ffcSJunyu Laiassert(e.src == '11::22' and e.dst == '22::11') 3720*7dc08ffcSJunyu Lai* AH header should be inserted between the routing header and TCP 3721*7dc08ffcSJunyu Laiassert(isinstance(e[AH].underlayer, IPv6ExtHdrRouting)) 3722*7dc08ffcSJunyu Laiassert(isinstance(e[AH].payload, TCP)) 3723*7dc08ffcSJunyu Lai 3724*7dc08ffcSJunyu Lai* reorder the routing header as the receiver will get it 3725*7dc08ffcSJunyu Laifinal = e[IPv6ExtHdrRouting].addresses.pop() 3726*7dc08ffcSJunyu Laie[IPv6ExtHdrRouting].addresses.insert(0, e.dst) 3727*7dc08ffcSJunyu Laie.dst = final 3728*7dc08ffcSJunyu Laie[IPv6ExtHdrRouting].segleft = 0 3729*7dc08ffcSJunyu Lai 3730*7dc08ffcSJunyu Lai* integrity verification should pass 3731*7dc08ffcSJunyu Laid = sa.decrypt(e) 3732*7dc08ffcSJunyu Laid 3733*7dc08ffcSJunyu Lai 3734