def test_radius_with_extra_attributes_packs(self): # pylint: disable=invalid-name packed_message = bytes.fromhex("010a0073" "be5df1f3b3366c69b977e56a7da47cba" "010675736572" "1f1330323a34323a61633a31373a30303a3666" "1e1434342d34342d34342d34342d34342d34343a" "3d060000000f" "4f08027100061500" "1812f51d90b0f76c85835ed4ac882e522748501201531ea8051d136941fece17473f6b4a") # pylint: disable=line-too-long src_mac = MacAddress.from_string("02:42:ac:17:00:6f") username = "******" radius_packet_id = 10 request_authenticator = bytes.fromhex( "be5df1f3b3366c69b977e56a7da47cba") state = State.create(bytes.fromhex("f51d90b0f76c85835ed4ac882e522748")) secret = "SECRET" extra_attributes = [] extra_attributes.append(CalledStationId.create('44-44-44-44-44-44:')) extra_attributes.append(NASPortType.create(15)) eap_message = TtlsMessage(src_mac, 113, Eap.RESPONSE, 0, b'') packed_radius = MessagePacker.radius_pack( eap_message, src_mac, username, radius_packet_id, request_authenticator, state, secret, extra_attributes=extra_attributes) self.assertEqual(packed_message, packed_radius)
def test_radius_access_request_packs(self): expected_packed_message = bytes.fromhex( "010e01dc688d6504db3c757243f995d5f0d32e50010b686f737431757365721e1434342d34342d34342d34342d34342d34343a3d06000000130606000000021f1330302d30302d30302d31312d31312d30314d17434f4e4e45435420304d627073203830322e3131622c12433634383030344139433930353537390c06000005784fff02250133150016030101280100012403032c36dbf8ee16b94b28efdb8c5603e07823f9b716557b5ef2624b026daea115760000aac030c02cc028c024c014c00a00a500a300a1009f006b006a0069006800390038003700360088008700860085c032c02ec02ac026c00fc005009d003d00350084c02fc02bc027c023c013c00900a400a200a0009e00670040003f003e0033003200310030009a0099009800970045004400430042c031c02dc029c025c00ec004009c003c002f00960041c011c007c00cc00200050004c012c008001600130010000dc00dc003000a00ff01000051000b000403000102000a001c001a00170019001c001b0018001a004f3816000e000d000b000c0009000a000d0020001e060106020603050105020503040104020403030103020303020102020203000f0001011812cefe6083cfdb75dd64722c274ec353725012ab67ed568931f12d258f9ffda931159e" ) attr_list = list() attr_list.append(UserName.create("host1user")) attr_list.append(CalledStationId.create("44-44-44-44-44-44:")) attr_list.append(NASPortType.create(0x13)) attr_list.append(ServiceType.create(0x02)) attr_list.append(CallingStationId.create("00-00-00-11-11-01")) attr_list.append(ConnectInfo.create("CONNECT 0Mbps 802.11b")) attr_list.append(AcctSessionId.create("C648004A9C905579")) attr_list.append(FramedMTU.create(0x0578)) attr_list.append( EAPMessage.create( "02250133150016030101280100012403032c36dbf8ee16b94b28efdb8c5603e07823f9b716557b5ef2624b026daea115760000aac030c02cc028c024c014c00a00a500a300a1009f006b006a0069006800390038003700360088008700860085c032c02ec02ac026c00fc005009d003d00350084c02fc02bc027c023c013c00900a400a200a0009e00670040003f003e0033003200310030009a0099009800970045004400430042c031c02dc029c025c00ec004009c003c002f00960041c011c007c00cc00200050004c012c008001600130010000dc00dc003000a00ff01000051000b000403000102000a001c001a00170019001c001b0018001a0016000e000d000b000c0009000a000d0020001e060106020603050105020503040104020403030103020303020102020203000f000101" )) attr_list.append( State.create(bytes.fromhex("cefe6083cfdb75dd64722c274ec35372"))) attr_list.append( MessageAuthenticator.create( bytes.fromhex("00000000000000000000000000000000"))) attributes = RadiusAttributesList(attr_list) access_request = RadiusAccessRequest( 14, bytes.fromhex("688d6504db3c757243f995d5f0d32e50"), attributes) packed_message = access_request.build("SECRET") self.assertEqual(len(expected_packed_message), len(packed_message)) self.assertEqual(expected_packed_message, packed_message)
def prepare_extra_radius_attributes(self): """Create RADIUS Attirbutes to be sent with every RADIUS request""" attr_list = [ CalledStationId.create(self.server_id), NASPortType.create(15), NASIdentifier.create(self.server_id) ] return attr_list