Skip to content

Commit 2beb66c

Browse files
authored
Preliminary work for PKINIT support (#4840)
1 parent 5eb00ba commit 2beb66c

File tree

7 files changed

+666
-69
lines changed

7 files changed

+666
-69
lines changed

scapy/asn1/asn1.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _fix(self, n=0):
9393
return o(GeneralizedTime()._fix())
9494
elif issubclass(o, ASN1_STRING):
9595
z1 = int(random.expovariate(0.05) + 1)
96-
return o("".join(random.choice(self.chars) for _ in range(z1)))
96+
return o("".join(random.choice(self.chars) for _ in range(z1)).encode())
9797
elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
9898
z2 = int(random.expovariate(0.08) + 1)
9999
return o([self.__class__(objlist=self.objlist)._fix(n + 1)
@@ -520,7 +520,7 @@ def __repr__(self):
520520
)
521521

522522

523-
class ASN1_STRING(ASN1_Object[str]):
523+
class ASN1_STRING(ASN1_Object[bytes]):
524524
tag = ASN1_Class_UNIVERSAL.STRING
525525

526526

@@ -555,11 +555,11 @@ class ASN1_UTF8_STRING(ASN1_STRING):
555555
tag = ASN1_Class_UNIVERSAL.UTF8_STRING
556556

557557

558-
class ASN1_NUMERIC_STRING(ASN1_STRING):
558+
class ASN1_NUMERIC_STRING(ASN1_Object[str]):
559559
tag = ASN1_Class_UNIVERSAL.NUMERIC_STRING
560560

561561

562-
class ASN1_PRINTABLE_STRING(ASN1_STRING):
562+
class ASN1_PRINTABLE_STRING(ASN1_Object[str]):
563563
tag = ASN1_Class_UNIVERSAL.PRINTABLE_STRING
564564

565565

@@ -579,7 +579,7 @@ class ASN1_GENERAL_STRING(ASN1_STRING):
579579
tag = ASN1_Class_UNIVERSAL.GENERAL_STRING
580580

581581

582-
class ASN1_GENERALIZED_TIME(ASN1_STRING):
582+
class ASN1_GENERALIZED_TIME(ASN1_Object[str]):
583583
"""
584584
Improved version of ASN1_GENERALIZED_TIME, properly handling time zones and
585585
all string representation formats defined by ASN.1. These are:
@@ -723,7 +723,7 @@ def __repr__(self):
723723
# type: () -> str
724724
return "<%s[%r]>" % (
725725
self.__dict__.get("name", self.__class__.__name__),
726-
self.val.decode("utf-16be"), # type: ignore
726+
self.val.decode("utf-16be"),
727727
)
728728

729729

@@ -742,7 +742,7 @@ class ASN1_SET(ASN1_SEQUENCE):
742742
tag = ASN1_Class_UNIVERSAL.SET
743743

744744

745-
class ASN1_IPADDRESS(ASN1_STRING):
745+
class ASN1_IPADDRESS(ASN1_Object[str]):
746746
tag = ASN1_Class_UNIVERSAL.IPADDRESS
747747

748748

scapy/asn1/mib.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,36 @@ def load_mib(filenames):
260260
"1.3.14.3.2.29": "sha1RSASign",
261261
}
262262

263+
# nist #
264+
265+
nist_oids = {
266+
"2.16.840.1.101.3.4.2.1": "sha256",
267+
"2.16.840.1.101.3.4.2.2": "sha384",
268+
"2.16.840.1.101.3.4.2.3": "sha512",
269+
"2.16.840.1.101.3.4.2.4": "sha224",
270+
"2.16.840.1.101.3.4.2.5": "sha512-224",
271+
"2.16.840.1.101.3.4.2.6": "sba512-256",
272+
"2.16.840.1.101.3.4.2.7": "sha3-224",
273+
"2.16.840.1.101.3.4.2.8": "sha3-256",
274+
"2.16.840.1.101.3.4.2.9": "sha3-384",
275+
"2.16.840.1.101.3.4.2.10": "sha3-512",
276+
"2.16.840.1.101.3.4.2.11": "shake128",
277+
"2.16.840.1.101.3.4.2.12": "shake256",
278+
}
279+
263280
# thawte #
264281

265282
thawte_oids = {
266283
"1.3.101.112": "Ed25519",
267284
"1.3.101.113": "Ed448",
268285
}
269286

287+
# pkcs7 #
288+
289+
pkcs7_oids = {
290+
"1.2.840.113549.1.7.2": "id-signedData",
291+
}
292+
270293
# pkcs9 #
271294

272295
pkcs9_oids = {
@@ -471,6 +494,7 @@ def load_mib(filenames):
471494
"2.5.29.69": "id-ce-holderNameConstraints",
472495
# [MS-WCCE]
473496
"1.3.6.1.4.1.311.2.1.14": "CERT_EXTENSIONS",
497+
"1.3.6.1.4.1.311.10.3.4": "szOID_EFS_CRYPTO",
474498
"1.3.6.1.4.1.311.20.2": "ENROLL_CERTTYPE",
475499
"1.3.6.1.4.1.311.25.1": "NTDS_REPLICATION",
476500
"1.3.6.1.4.1.311.25.2": "NTDS_CA_SECURITY_EXT",
@@ -560,6 +584,12 @@ def load_mib(filenames):
560584
"1.2.840.10045.4.3.4": "ecdsa-with-SHA512"
561585
}
562586

587+
# ansi-x942 #
588+
589+
x942KeyType_oids = {
590+
"1.2.840.10046.2.1": "dhpublicnumber", # RFC3770 sect 4.1.1
591+
}
592+
563593
# elliptic curves #
564594

565595
ansiX962Curve_oids = {
@@ -672,11 +702,29 @@ def load_mib(filenames):
672702
'1.3.6.1.4.1.311.2.2.30': 'NEGOEX - SPNEGO Extended Negotiation Security Mechanism',
673703
}
674704

705+
# kerberos #
706+
707+
kerberos_oids = {
708+
"1.3.6.1.5.2.3.1": "id-pkinit-authData",
709+
"1.3.6.1.5.2.3.2": "id-pkinit-DHKeyData",
710+
"1.3.6.1.5.2.3.3": "id-pkinit-rkeyData",
711+
"1.3.6.1.5.2.3.4": "id-pkinit-KPClientAuth",
712+
"1.3.6.1.5.2.3.5": "id-pkinit-KPKdc",
713+
# RFC8363
714+
"1.3.6.1.5.2.3.6": "id-pkinit-kdf",
715+
"1.3.6.1.5.2.3.6.1": "id-pkinit-kdf-sha1",
716+
"1.3.6.1.5.2.3.6.2": "id-pkinit-kdf-sha256",
717+
"1.3.6.1.5.2.3.6.3": "id-pkinit-kdf-sha512",
718+
"1.3.6.1.5.2.3.6.4": "id-pkinit-kdf-sha384",
719+
}
720+
675721

676722
x509_oids_sets = [
677723
pkcs1_oids,
678724
secsig_oids,
725+
nist_oids,
679726
thawte_oids,
727+
pkcs7_oids,
680728
pkcs9_oids,
681729
attributeType_oids,
682730
certificateExtension_oids,
@@ -690,9 +738,11 @@ def load_mib(filenames):
690738
evPolicy_oids,
691739
x962KeyType_oids,
692740
x962Signature_oids,
741+
x942KeyType_oids,
693742
ansiX962Curve_oids,
694743
certicomCurve_oids,
695744
gssapi_oids,
745+
kerberos_oids,
696746
]
697747

698748
x509_oids = {}

scapy/asn1fields.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ def i2repr(self, pkt, x):
606606
# type: (ASN1_Packet, _I) -> str
607607
if self.holds_packets:
608608
return super(ASN1F_SEQUENCE_OF, self).i2repr(pkt, x) # type: ignore
609+
elif x is None:
610+
return "[]"
609611
else:
610612
return "[%s]" % ", ".join(
611613
self.fld.i2repr(pkt, x) for x in x # type: ignore
@@ -979,11 +981,40 @@ class ASN1F_STRING_PacketField(ASN1F_STRING):
979981
def i2m(self, pkt, val):
980982
# type: (ASN1_Packet, Any) -> bytes
981983
if hasattr(val, "ASN1_root"):
982-
val = ASN1_STRING(bytes(val)) # type: ignore
984+
val = ASN1_STRING(bytes(val))
983985
return super(ASN1F_STRING_PacketField, self).i2m(pkt, val)
984986

985987
def any2i(self, pkt, x):
986988
# type: (ASN1_Packet, Any) -> Any
987989
if hasattr(x, "add_underlayer"):
988990
x.add_underlayer(pkt)
989991
return super(ASN1F_STRING_PacketField, self).any2i(pkt, x)
992+
993+
994+
class ASN1F_STRING_ENCAPS(ASN1F_STRING_PacketField):
995+
"""
996+
ASN1F_STRING that encapsulates a single ASN1 packet.
997+
"""
998+
999+
def __init__(self,
1000+
name, # type: str
1001+
default, # type: Optional[ASN1_Packet]
1002+
cls, # type: Type[ASN1_Packet]
1003+
context=None, # type: Optional[Any]
1004+
implicit_tag=None, # type: Optional[int]
1005+
explicit_tag=None, # type: Optional[int]
1006+
):
1007+
# type: (...) -> None
1008+
self.cls = cls
1009+
super(ASN1F_STRING_ENCAPS, self).__init__(
1010+
name,
1011+
default and bytes(default), # type: ignore
1012+
context=context,
1013+
implicit_tag=implicit_tag,
1014+
explicit_tag=explicit_tag
1015+
)
1016+
1017+
def m2i(self, pkt, s): # type: ignore
1018+
# type: (ASN1_Packet, bytes) -> Tuple[ASN1_Packet, bytes]
1019+
val = super(ASN1F_STRING_ENCAPS, self).m2i(pkt, s)
1020+
return self.cls(val[0].val, _underlayer=pkt), val[1]

0 commit comments

Comments
 (0)