Implements a RADIUS packet (RFC 2865).
| 1308 | |
| 1309 | |
| 1310 | class Radius(Packet): |
| 1311 | """ |
| 1312 | Implements a RADIUS packet (RFC 2865). |
| 1313 | """ |
| 1314 | |
| 1315 | name = "RADIUS" |
| 1316 | fields_desc = [ |
| 1317 | ByteEnumField("code", 1, _packet_codes), |
| 1318 | ByteField("id", 0), |
| 1319 | FieldLenField( |
| 1320 | "len", |
| 1321 | None, |
| 1322 | "attributes", |
| 1323 | "H", |
| 1324 | adjust=lambda pkt, x: len(pkt.attributes) + 20 |
| 1325 | ), |
| 1326 | XStrFixedLenField("authenticator", "", 16), |
| 1327 | PacketListField( |
| 1328 | "attributes", |
| 1329 | [], |
| 1330 | RadiusAttribute, |
| 1331 | length_from=lambda pkt: pkt.len - 20 |
| 1332 | ) |
| 1333 | ] |
| 1334 | |
| 1335 | def compute_authenticator(self, packed_request_auth, shared_secret): |
| 1336 | """ |
| 1337 | Computes the authenticator field (RFC 2865 - Section 3) |
| 1338 | """ |
| 1339 | |
| 1340 | data = prepare_packed_data(self, packed_request_auth) |
| 1341 | radius_mac = hashlib.md5(data + shared_secret) |
| 1342 | return radius_mac.digest() |
| 1343 | |
| 1344 | def post_build(self, p, pay): |
| 1345 | p += pay |
| 1346 | length = self.len |
| 1347 | if length is None: |
| 1348 | length = len(p) |
| 1349 | p = p[:2] + struct.pack("!H", length) + p[4:] |
| 1350 | return p |
| 1351 | |
| 1352 | def mysummary(self): |
| 1353 | extra = "" |
| 1354 | if self.code == 1: |
| 1355 | # Access-Request |
| 1356 | attrs = { |
| 1357 | ( |
| 1358 | (x.vendor_id, x.vendor_type) |
| 1359 | if RadiusAttr_Vendor_Specific in x else |
| 1360 | x.type |
| 1361 | ): x |
| 1362 | for x in self.attributes |
| 1363 | if isinstance(x, RadiusAttribute) |
| 1364 | } |
| 1365 | # Log additional attributes |
| 1366 | if 1 in attrs: |
| 1367 | extra += "User:'%s' " % attrs[1].value.decode(errors="ignore") |
no test coverage detected
searching dependent graphs…