1313- Kerberos Pre-Authentication: RFC6113 (FAST)
1414- Kerberos Principal Name Canonicalization and Cross-Realm Referrals: RFC6806
1515- Microsoft Windows 2000 Kerberos Change Password and Set Password Protocols: RFC3244
16+ - PKINIT and its extensions: RFC4556, RFC8070, RFC8636 and [MS-PKCA]
1617- User to User Kerberos Authentication: draft-ietf-cat-user2user-03
1718- Public Key Cryptography Based User-to-User Authentication (PKU2U): draft-zhu-pku2u-09
1819- Initial and Pass Through Authentication Using Kerberos V5 (IAKERB):
5960import scapy .asn1 .mib # noqa: F401
6061from scapy .asn1 .ber import BER_id_dec , BER_Decoding_Error
6162from scapy .asn1 .asn1 import (
63+ ASN1_OID ,
6264 ASN1_BIT_STRING ,
6365 ASN1_BOOLEAN ,
6466 ASN1_Class ,
8082 ASN1F_SEQUENCE ,
8183 ASN1F_SEQUENCE_OF ,
8284 ASN1F_STRING ,
85+ ASN1F_STRING_ENCAPS ,
8386 ASN1F_STRING_PacketField ,
8487 ASN1F_enum_INTEGER ,
8588 ASN1F_optional ,
142145from scapy .layers .smb import _NV_VERSION
143146from scapy .layers .smb2 import STATUS_ERREF
144147from scapy .layers .tls .cert import Cert , PrivKey
145- from scapy .layers .x509 import X509_AlgorithmIdentifier
148+ from scapy .layers .x509 import (
149+ _CMS_ENCAPSULATED ,
150+ CMS_ContentInfo ,
151+ CMS_IssuerAndSerialNumber ,
152+ CMS_SignedData ,
153+ X509_AlgorithmIdentifier ,
154+ X509_DirectoryName ,
155+ X509_SubjectPublicKeyInfo ,
156+ )
146157
147158# Redirect exports from RFC3961
148159try :
@@ -1193,7 +1204,8 @@ class KrbFastResponse(ASN1_Packet):
11931204
11941205_PADATA_CLASSES [136 ] = (PA_FX_FAST_REQUEST , PA_FX_FAST_REPLY )
11951206
1196- # RFC 4556
1207+
1208+ # RFC 4556 - PKINIT
11971209
11981210
11991211# sect 3.2.1
@@ -1203,21 +1215,36 @@ class ExternalPrincipalIdentifier(ASN1_Packet):
12031215 ASN1_codec = ASN1_Codecs .BER
12041216 ASN1_root = ASN1F_SEQUENCE (
12051217 ASN1F_optional (
1206- ASN1F_STRING ("subjectName" , "" , implicit_tag = 0xA0 ),
1218+ ASN1F_STRING_ENCAPS (
1219+ "subjectName" , None , X509_DirectoryName , implicit_tag = 0x80
1220+ ),
12071221 ),
12081222 ASN1F_optional (
1209- ASN1F_STRING ("issuerAndSerialNumber" , "" , implicit_tag = 0xA1 ),
1223+ ASN1F_STRING_ENCAPS (
1224+ "issuerAndSerialNumber" ,
1225+ None ,
1226+ CMS_IssuerAndSerialNumber ,
1227+ implicit_tag = 0x81 ,
1228+ ),
12101229 ),
12111230 ASN1F_optional (
1212- ASN1F_STRING ("subjectKeyIdentifier" , "" , implicit_tag = 0xA2 ),
1231+ ASN1F_STRING ("subjectKeyIdentifier" , "" , implicit_tag = 0x82 ),
12131232 ),
12141233 )
12151234
12161235
12171236class PA_PK_AS_REQ (ASN1_Packet ):
12181237 ASN1_codec = ASN1_Codecs .BER
12191238 ASN1_root = ASN1F_SEQUENCE (
1220- ASN1F_STRING ("signedAuthpack" , "" , implicit_tag = 0xA0 ),
1239+ ASN1F_STRING_ENCAPS (
1240+ "signedAuthpack" ,
1241+ CMS_ContentInfo (
1242+ contentType = ASN1_OID ("id-signedData" ),
1243+ content = CMS_SignedData (),
1244+ ),
1245+ CMS_ContentInfo ,
1246+ implicit_tag = 0x80 ,
1247+ ),
12211248 ASN1F_optional (
12221249 ASN1F_SEQUENCE_OF (
12231250 "trustedCertifiers" ,
@@ -1234,6 +1261,96 @@ class PA_PK_AS_REQ(ASN1_Packet):
12341261
12351262_PADATA_CLASSES [16 ] = PA_PK_AS_REQ
12361263
1264+
1265+ # [MS-PKCA] sect 2.2.3
1266+
1267+
1268+ class PAChecksum2 (ASN1_Packet ):
1269+ ASN1_codec = ASN1_Codecs .BER
1270+ ASN1_root = ASN1F_SEQUENCE (
1271+ ASN1F_STRING ("checksum" , "" , explicit_tag = 0xA0 ),
1272+ ASN1F_PACKET (
1273+ "algorithmIdentifier" ,
1274+ X509_AlgorithmIdentifier (),
1275+ X509_AlgorithmIdentifier ,
1276+ explicit_tag = 0xA1 ,
1277+ ),
1278+ )
1279+
1280+
1281+ # still RFC 4556 sect 3.2.1
1282+
1283+
1284+ class PKAuthenticator (ASN1_Packet ):
1285+ ASN1_codec = ASN1_Codecs .BER
1286+ ASN1_root = ASN1F_SEQUENCE (
1287+ Microseconds ("cusec" , 0 , explicit_tag = 0xA0 ),
1288+ KerberosTime ("ctime" , GeneralizedTime (), explicit_tag = 0xA1 ),
1289+ UInt32 ("nonce" , 0 , explicit_tag = 0xA2 ),
1290+ ASN1F_optional (
1291+ ASN1F_STRING ("paChecksum" , "" , explicit_tag = 0xA3 ),
1292+ ),
1293+ # RFC8070 extension
1294+ ASN1F_optional (
1295+ ASN1F_STRING ("freshnessToken" , "" , explicit_tag = 0xA4 ),
1296+ ),
1297+ # [MS-PKCA] sect 2.2.3
1298+ ASN1F_optional (
1299+ ASN1F_PACKET ("paChecksum2" , None , PAChecksum2 , explicit_tag = 0xA5 ),
1300+ ),
1301+ )
1302+
1303+
1304+ # RFC8636 sect 6
1305+
1306+
1307+ class KDFAlgorithmId (ASN1_Packet ):
1308+ ASN1_codec = ASN1_Codecs .BER
1309+ ASN1_root = ASN1F_SEQUENCE (
1310+ ASN1F_OID ("kdfId" , "" , explicit_tag = 0xA0 ),
1311+ )
1312+
1313+
1314+ # still RFC 4556 sect 3.2.1
1315+
1316+
1317+ class AuthPack (ASN1_Packet ):
1318+ ASN1_codec = ASN1_Codecs .BER
1319+ ASN1_root = ASN1F_SEQUENCE (
1320+ ASN1F_PACKET (
1321+ "pkAuthenticator" ,
1322+ PKAuthenticator (),
1323+ PKAuthenticator ,
1324+ explicit_tag = 0xA0 ,
1325+ ),
1326+ ASN1F_optional (
1327+ ASN1F_PACKET (
1328+ "clientPublicValue" ,
1329+ X509_SubjectPublicKeyInfo (),
1330+ X509_SubjectPublicKeyInfo ,
1331+ explicit_tag = 0xA1 ,
1332+ ),
1333+ ),
1334+ ASN1F_optional (
1335+ ASN1F_SEQUENCE_OF (
1336+ "supportedCMSTypes" ,
1337+ [],
1338+ X509_AlgorithmIdentifier ,
1339+ explicit_tag = 0xA2 ,
1340+ ),
1341+ ),
1342+ ASN1F_optional (
1343+ ASN1F_STRING ("clientDCNonce" , None , explicit_tag = 0xA3 ),
1344+ ),
1345+ # RFC8636 extension
1346+ ASN1F_optional (
1347+ ASN1F_SEQUENCE_OF ("supportedKDFs" , None , KDFAlgorithmId , explicit_tag = 0xA4 ),
1348+ ),
1349+ )
1350+
1351+
1352+ _CMS_ENCAPSULATED ["1.3.6.1.5.2.3.1" ] = AuthPack
1353+
12371354# sect 3.2.3
12381355
12391356
@@ -1244,6 +1361,10 @@ class DHRepInfo(ASN1_Packet):
12441361 ASN1F_optional (
12451362 ASN1F_STRING ("serverDHNonce" , "" , explicit_tag = 0xA1 ),
12461363 ),
1364+ # RFC8636 extension
1365+ ASN1F_optional (
1366+ ASN1F_PACKET ("kdf" , None , KDFAlgorithmId , explicit_tag = 0xA2 ),
1367+ ),
12471368 )
12481369
12491370
@@ -1993,6 +2114,8 @@ class KRB_ERROR(ASN1_Packet):
19932114 91 : "KDC_ERR_MORE_PREAUTH_DATA_REQUIRED" ,
19942115 92 : "KDC_ERR_PREAUTH_BAD_AUTHENTICATION_SET" ,
19952116 93 : "KDC_ERR_UNKNOWN_CRITICAL_FAST_OPTIONS" ,
2117+ # RFC8636
2118+ 100 : "KDC_ERR_NO_ACCEPTABLE_KDF" ,
19962119 },
19972120 explicit_tag = 0xA6 ,
19982121 ),
@@ -3174,11 +3297,9 @@ def as_req(self):
31743297 if self .x509 :
31753298 # Special PKINIT (RFC4556) factor
31763299 pafactor = PADATA (
3177- padataType = 16 , # PA-PK-AS-REQ
3178- padataValue = PA_PK_AS_REQ (
3179-
3180- )
3300+ padataType = 16 , padataValue = PA_PK_AS_REQ () # PA-PK-AS-REQ
31813301 )
3302+ raise NotImplementedError ("PKINIT isn't implemented yet !" )
31823303 else :
31833304 # Key-based factor
31843305
@@ -3209,7 +3330,7 @@ def as_req(self):
32093330 ts_key ,
32103331 PA_ENC_TS_ENC (patimestamp = ASN1_GENERALIZED_TIME (now_time )),
32113332 )
3212-
3333+
32133334 # Insert Pre-Authentication data
32143335 padata .insert (
32153336 0 ,
0 commit comments