]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Include Message-Authenticator attribute in RADIUS tests
authorJouni Malinen <j@w1.fi>
Sun, 17 Mar 2024 09:10:16 +0000 (11:10 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 9 Jul 2024 11:58:39 +0000 (14:58 +0300)
This is in preparation for hostapd requiring this attribute for all
cases.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/test_eap_proto.py
tests/hwsim/test_radius.py

index 0aa292c371ca45cb8f709250d84de152710bc9ee..50d898a1843ee2657a8e287d4b87d55bdc0c37b3 100644 (file)
@@ -82,6 +82,22 @@ def add_message_authenticator_attr(reply, digest):
         digest = b"0x" + binascii.hexlify(digest)
     reply.AddAttribute("Message-Authenticator", digest)
 
+def build_message_auth(pkt, reply):
+    hmac_obj = hmac.new(reply.secret, digestmod=hashlib.md5)
+    hmac_obj.update(struct.pack("B", reply.code))
+    hmac_obj.update(struct.pack("B", reply.id))
+
+    reply.AddAttribute("Message-Authenticator", 16*b'\x00')
+    attrs = reply._PktEncodeAttributes()
+
+    # Length
+    flen = 4 + 16 + len(attrs)
+    hmac_obj.update(struct.pack(">H", flen))
+    hmac_obj.update(pkt.authenticator)
+    hmac_obj.update(attrs)
+    del reply[80]
+    add_message_authenticator_attr(reply, hmac_obj.digest())
+
 def run_pyrad_server(srv, t_stop, eap_handler):
     srv.RunWithStop(t_stop, eap_handler)
 
@@ -113,21 +129,8 @@ def start_radius_server(eap_handler):
                 logger.info("No EAP request available")
             reply.code = pyrad.packet.AccessChallenge
 
-            hmac_obj = hmac.new(reply.secret, digestmod=hashlib.md5)
-            hmac_obj.update(struct.pack("B", reply.code))
-            hmac_obj.update(struct.pack("B", reply.id))
-
             # reply attributes
-            reply.AddAttribute("Message-Authenticator", 16*b'\x00')
-            attrs = reply._PktEncodeAttributes()
-
-            # Length
-            flen = 4 + 16 + len(attrs)
-            hmac_obj.update(struct.pack(">H", flen))
-            hmac_obj.update(pkt.authenticator)
-            hmac_obj.update(attrs)
-            del reply[80]
-            add_message_authenticator_attr(reply, hmac_obj.digest())
+            build_message_auth(pkt, reply)
 
             self.SendReplyPacket(pkt.fd, reply)
 
index a98a75a5e8a12aa5c3a730ef90b5f5fcfa3a15c1..cfa8378c2d6afb1ce6401b9bc0b1d1769c031014 100644 (file)
@@ -22,7 +22,7 @@ import hostapd
 from utils import *
 from test_ap_hs20 import build_dhcp_ack
 from test_ap_ft import ft_params1
-from test_eap_proto import add_message_authenticator_attr
+from test_eap_proto import add_message_authenticator_attr, build_message_auth
 
 def connect(dev, ssid, wait_connect=True):
     dev.connect(ssid, key_mgmt="WPA-EAP", scan_freq="2412",
@@ -1233,6 +1233,8 @@ def start_radius_psk_server(psk, invalid_code=False, acct_interim_interval=0,
             if self.t_events['session_timeout']:
                 reply.AddAttribute("Session-Timeout",
                                    self.t_events['session_timeout'])
+            build_message_auth(pkt, reply)
+
             self.SendReplyPacket(pkt.fd, reply)
 
         def RunWithStop(self, t_events):
@@ -1587,6 +1589,7 @@ def test_ap_vlan_wpa2_psk_radius_required(dev, apdev):
                 reply.AddAttribute("Tunnel-Type", 13)
                 reply.AddAttribute("Tunnel-Medium-Type", 6)
                 reply.AddAttribute("Tunnel-Private-Group-ID", "1")
+            build_message_auth(pkt, reply)
             self.SendReplyPacket(pkt.fd, reply)
 
         def RunWithStop(self, t_events):