scapy.asn1fields

Classes that implement ASN.1 data structures.

class scapy.asn1fields.ASN1F_BIT_STRING(name, default, default_readable=True, context=None, implicit_tag=None, explicit_tag=None)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_BIT_STRING]

ASN1_tag = <ASN1Tag BIT_STRING[3]>
randval()[source]
class scapy.asn1fields.ASN1F_BIT_STRING_ENCAPS(name, default, cls, context=None, implicit_tag=None, explicit_tag=None)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_BIT_STRING]

We may emulate simple string encapsulation with explicit_tag=0x04, but we need a specific class for bit strings because of unused bits, etc.

ASN1_tag = <ASN1Tag BIT_STRING[3]>
i2m(pkt, x)[source]
m2i(pkt, s)[source]
class scapy.asn1fields.ASN1F_BMP_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag BMP_STRING[30]>
class scapy.asn1fields.ASN1F_BOOLEAN(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[bool, scapy.asn1.asn1.ASN1_BOOLEAN]

ASN1_tag = <ASN1Tag BOOLEAN[1]>
randval()[source]
class scapy.asn1fields.ASN1F_CHOICE(name, default, *args, **kwargs)[source]

Bases: scapy.asn1fields.ASN1F_field[Union[ASN1_Packet, Type[scapy.asn1fields.ASN1F_field], ASN1F_PACKET], scapy.asn1.asn1.ASN1_Object[Any]]

Multiple types are allowed: ASN1_Packet, ASN1F_field and ASN1F_PACKET(), See layers/x509.py for examples. Other ASN1F_field instances than ASN1F_PACKET instances must not be used.

ASN1_tag = <ASN1Tag ANY[0]>
holds_packets = 1
i2m(pkt, x)[source]
m2i(pkt, s)[source]

First we have to retrieve the appropriate choice. Then we extract the field/packet, according to this choice.

randval()[source]
class scapy.asn1fields.ASN1F_ENUMERATED(name, default, enum, context=None, implicit_tag=None, explicit_tag=None)[source]

Bases: scapy.asn1fields.ASN1F_field[int, scapy.asn1.asn1.ASN1_INTEGER]

ASN1_tag = <ASN1Tag ENUMERATED[10]>
class scapy.asn1fields.ASN1F_FLAGS(name, default, mapping, context=None, implicit_tag=None, explicit_tag=None)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_BIT_STRING]

get_flags(pkt)[source]
i2repr(pkt, x)[source]
class scapy.asn1fields.ASN1F_GENERALIZED_TIME(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag GENERALIZED_TIME[24]>
randval()[source]
class scapy.asn1fields.ASN1F_IA5_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag IA5_STRING[22]>
class scapy.asn1fields.ASN1F_INTEGER(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[int, scapy.asn1.asn1.ASN1_INTEGER]

ASN1_tag = <ASN1Tag INTEGER[2]>
randval()[source]
class scapy.asn1fields.ASN1F_IPADDRESS(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag IPADDRESS[64]>
class scapy.asn1fields.ASN1F_ISO646_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag ISO646_STRING[26]>
class scapy.asn1fields.ASN1F_NULL(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[int, scapy.asn1.asn1.ASN1_INTEGER]

ASN1_tag = <ASN1Tag NULL[5]>
class scapy.asn1fields.ASN1F_NUMERIC_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag NUMERIC_STRING[18]>
class scapy.asn1fields.ASN1F_OID(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_OID]

ASN1_tag = <ASN1Tag OID[6]>
randval()[source]
class scapy.asn1fields.ASN1F_PACKET(name, default, cls, context=None, implicit_tag=None, explicit_tag=None, next_cls_cb=None)[source]

Bases: scapy.asn1fields.ASN1F_field[ASN1_Packet, Optional[ASN1_Packet]]

holds_packets = 1
i2m(pkt, x)[source]
m2i(pkt, s)[source]
randval()[source]
class scapy.asn1fields.ASN1F_PRINTABLE_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag PRINTABLE_STRING[19]>
class scapy.asn1fields.ASN1F_SEQUENCE(*seq, **kwargs)[source]

Bases: scapy.asn1fields.ASN1F_field[List[Any], List[Any]]

ASN1_tag = <ASN1Tag SEQUENCE[48]>
build(pkt)[source]
dissect(pkt, s)[source]
get_fields_list()[source]
holds_packets = 1
is_empty(pkt)[source]
m2i(pkt, s)[source]

ASN1F_SEQUENCE behaves transparently, with nested ASN1_objects being dissected one by one. Because we use obj.dissect (see loop below) instead of obj.m2i (as we trust dissect to do the appropriate set_vals) we do not directly retrieve the list of nested objects. Thus m2i returns an empty list (along with the proper remainder). It is discarded by dissect() and should not be missed elsewhere.

class scapy.asn1fields.ASN1F_SEQUENCE_OF(name, default, cls, context=None, implicit_tag=None, explicit_tag=None)[source]

Bases: scapy.asn1fields.ASN1F_field[List[ASN1_Packet], List[ASN1_Packet]]

ASN1_tag = <ASN1Tag SEQUENCE[48]>
build(pkt)[source]
holds_packets = 1
is_empty(pkt)[source]
islist = 1
m2i(pkt, s)[source]
randval()[source]
class scapy.asn1fields.ASN1F_SET(*seq, **kwargs)[source]

Bases: scapy.asn1fields.ASN1F_field[List[Any], List[Any]]

ASN1_tag = <ASN1Tag SET[49]>
class scapy.asn1fields.ASN1F_SET_OF(name, default, cls, context=None, implicit_tag=None, explicit_tag=None)[source]

Bases: scapy.asn1fields.ASN1F_field[List[ASN1_Packet], List[ASN1_Packet]]

ASN1_tag = <ASN1Tag SET[49]>
class scapy.asn1fields.ASN1F_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag STRING[4]>
randval()[source]
class scapy.asn1fields.ASN1F_T61_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag T61_STRING[20]>
class scapy.asn1fields.ASN1F_TIME_TICKS(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[int, scapy.asn1.asn1.ASN1_INTEGER]

ASN1_tag = <ASN1Tag TIME_TICKS[67]>
class scapy.asn1fields.ASN1F_UNIVERSAL_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag UNIVERSAL_STRING[28]>
class scapy.asn1fields.ASN1F_UTC_TIME(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag UTC_TIME[23]>
randval()[source]
class scapy.asn1fields.ASN1F_UTF8_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag UTF8_STRING[12]>
class scapy.asn1fields.ASN1F_VIDEOTEX_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_field[str, scapy.asn1.asn1.ASN1_STRING]

ASN1_tag = <ASN1Tag VIDEOTEX_STRING[21]>
exception scapy.asn1fields.ASN1F_badsequence[source]

Bases: Exception

class scapy.asn1fields.ASN1F_element[source]

Bases: object

class scapy.asn1fields.ASN1F_enum_INTEGER(name, default, enum, context=None, implicit_tag=None, explicit_tag=None)[source]

Bases: scapy.asn1fields.ASN1F_field[int, scapy.asn1.asn1.ASN1_INTEGER]

i2m(pkt, s)[source]
i2repr(pkt, x)[source]
class scapy.asn1fields.ASN1F_field(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)[source]

Bases: scapy.asn1fields.ASN1F_element, Generic[scapy.asn1fields._I, scapy.asn1fields._A]

ASN1_tag = <ASN1Tag ANY[0]>
any2i(pkt, x)[source]
build(pkt)[source]
context[source]

alias of scapy.asn1.asn1.ASN1_Class_UNIVERSAL

dissect(pkt, s)[source]
do_copy(x)[source]
extract_packet(cls, s, _underlayer=None)[source]
get_fields_list()[source]
holds_packets = 0
i2h(pkt, x)[source]
i2m(pkt, x)[source]
i2repr(pkt, x)[source]
is_empty(pkt)[source]
islist = 0
m2i(pkt, s)[source]

The good thing about safedec is that it may still decode ASN1 even if there is a mismatch between the expected tag (self.ASN1_tag) and the actual tag; the decoded ASN1 object will simply be put into an ASN1_BADTAG object. However, safedec prevents the raising of exceptions needed for ASN1F_optional processing. Thus we use ‘flexible_tag’, which should be False with ASN1F_optional.

Regarding other fields, we might need to know whether encoding went as expected or not. Noticeably, input methods from cert.py expect certain exceptions to be raised. Hence default flexible_tag is False.

randval()[source]
set_val(pkt, val)[source]
class scapy.asn1fields.ASN1F_optional(field)[source]

Bases: scapy.asn1fields.ASN1F_element

any2i(pkt, x)[source]
build(pkt)[source]
dissect(pkt, s)[source]
i2repr(pkt, x)[source]
m2i(pkt, s)[source]