scapy.contrib.psp

PSP layer

Example of use:

>>> payload = IP() / UDP(sport=1234, dport=5678) / Raw("A" * 9)
>>> iv = b'\x01\x02\x03\x04\x05\x06\x07\x08'
>>> spi = 0x11223344
>>> key = b'\xFF\xEE\xDD\xCC\xBB\xAA\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00'
>>> psp_packet = PSP(nexthdr=4, cryptoffset=5, spi=spi, iv=iv, data=payload)
>>> hexdump(psp_packet)
0000  04 01 05 01 11 22 33 44 01 02 03 04 05 06 07 08  ....."3D........
0010  45 00 00 25 00 01 00 00 40 11 7C C5 7F 00 00 01  E..%....@.|.....
0020  7F 00 00 01 04 D2 16 2E 00 11 A0 C4 41 41 41 41  ............AAAA
0030  41 41 41 41 41                                   AAAAA
>>>
>>> psp_packet.encrypt(key)
>>> hexdump(psp_packet)
0000  04 01 05 01 11 22 33 44 01 02 03 04 05 06 07 08  ....."3D........
0010  45 00 00 25 00 01 00 00 40 11 7C C5 7F 00 00 01  E..%....@.|.....
0020  7F 00 00 01 8E 3E 2B 13 45 C7 6B F9 5C DA C3 9B  .....>+.E.k.\...
0030  86 17 62 A0 CF DF FB BE BB C6 31 3A 2B 9D E0 64  ..b.......1:+..d
0040  75 9C DD 71 C9                                   u..q.
>>>
>>> psp_packet.decrypt(key)
>>> hexdump(psp_packet)
0000  04 01 05 01 11 22 33 44 01 02 03 04 05 06 07 08  ....."3D........
0010  45 00 00 25 00 01 00 00 40 11 7C C5 7F 00 00 01  E..%....@.|.....
0020  7F 00 00 01 04 D2 16 2E 00 11 A0 C4 41 41 41 41  ............AAAA
0030  41 41 41 41 41                                   AAAAA
>>>
class scapy.contrib.psp.PSP(_pkt, /, *, nexthdr=0, hdrextlen=1, reserved=0, cryptoffset=0, sample=0, drop=0, version=0, is_virt=0, one_bit=1, spi=0, iv=b'\x00\x00\x00\x00\x00\x00\x00\x00', virtkey=0, sectoken=0, data=None)[source]

Bases: Packet

PSP Security Protocol

See https://github.com/google/psp/blob/main/doc/PSP_Arch_Spec.pdf

aliastypes = [<class 'scapy.contrib.psp.PSP'>, <class 'scapy.packet.Packet'>]
decrypt(key)[source]

Decrypt a PSP packet

Parameters:

key – the secret key used for encryption

Raises:
  • scapy.layers.psp.PSPIntegrityError – if the integrity check fails with an AEAD algorithm

  • scapy.layers.psp.PSPCipherError – if the requested cipher is unsupported

encrypt(key)[source]

Encrypt a PSP packet

Parameters:

key – the secret key used for encryption

Raises:

scapy.layers.psp.PSPCipherError – if the requested cipher is unsupported

fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteField (PSP).nexthdr>, <ByteField (PSP).hdrextlen>, <BitField (PSP).reserved>, <BitField (PSP).cryptoffset>, <BitField (PSP).sample>, <BitField (PSP).drop>, <BitField (PSP).version>, <BitField (PSP).is_virt>, <BitField (PSP).one_bit>, <XIntField (PSP).spi>, <StrFixedLenField (PSP).iv>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <XStrField (PSP).data>]
sanitize_cipher()[source]

Ensure we support the cipher to encrypt/decrypt this packet

Returns:

the supported cipher suite

Raises:

scapy.layers.psp.PSPCipherError – if the requested cipher is unsupported

exception scapy.contrib.psp.PSPCipherError[source]

Bases: Exception

Error risen when the cipher is unsupported.

exception scapy.contrib.psp.PSPIntegrityError[source]

Bases: Exception

Error risen when the integrity check fails.