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)

Bases: scapy.asn1fields.ASN1F_field

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

Bases: scapy.asn1fields.ASN1F_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.

holds_packets = 1
i2m(pkt, x)
m2i(pkt, s)
class scapy.asn1fields.ASN1F_BMP_STRING(name, default, context=None, implicit_tag=None, explicit_tag=None, flexible_tag=False)

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_field

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

Bases: scapy.asn1fields.ASN1F_field

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)
m2i(pkt, s)

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

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

Bases: scapy.asn1fields.ASN1F_enum_INTEGER

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

Bases: scapy.asn1fields.ASN1F_BIT_STRING

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

Bases: scapy.asn1fields.ASN1F_STRING

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

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_field

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

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_field

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

Bases: scapy.asn1fields.ASN1F_field

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

Bases: scapy.asn1fields.ASN1F_STRING

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

Bases: scapy.asn1fields.ASN1F_field

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

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)

Bases: scapy.asn1fields.ASN1F_field

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

Bases: scapy.asn1fields.ASN1F_SEQUENCE

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

Bases: scapy.asn1fields.ASN1F_SEQUENCE_OF

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

Bases: scapy.asn1fields.ASN1F_field

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

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_STRING

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

Bases: scapy.asn1fields.ASN1F_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)

Bases: scapy.asn1fields.ASN1F_STRING

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

Bases: Exception

class scapy.asn1fields.ASN1F_element

Bases: object

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

Bases: scapy.asn1fields.ASN1F_INTEGER

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

Bases: scapy.asn1fields.ASN1F_element

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

alias of scapy.asn1.asn1.ASN1_Class_UNIVERSAL

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

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()
set_val(pkt, val)
class scapy.asn1fields.ASN1F_optional(field)

Bases: scapy.asn1fields.ASN1F_element

any2i(pkt, x)
build(pkt)
dissect(pkt, s)
i2repr(pkt, x)
m2i(pkt, s)