From ba6ce9c65757b9df628d655158f37f537a44e3cd Mon Sep 17 00:00:00 2001
From: Jouni Malinen <jouni@codeaurora.org>
Date: Wed, 13 Mar 2019 13:00:33 +0200
Subject: [PATCH] tests: DPP and duplicated Authentication Response

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
---
 tests/hwsim/test_dpp.py | 53 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tests/hwsim/test_dpp.py b/tests/hwsim/test_dpp.py
index 3e344c913..6eb7a292e 100644
--- a/tests/hwsim/test_dpp.py
+++ b/tests/hwsim/test_dpp.py
@@ -4622,6 +4622,7 @@ def rx_process_frame(dev):
     if "OK" not in dev.request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
         msg['freq'], msg['datarate'], msg['ssi_signal'], binascii.hexlify(msg['frame']).decode())):
         raise Exception("MGMT_RX_PROCESS failed")
+    return msg
 
 def wait_auth_success(responder, initiator):
     ev = responder.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
@@ -5317,3 +5318,55 @@ def test_dpp_conf_file_update(dev, apdev, params):
     wpas.interface_add("wlan5", config=config)
     if len(wpas.list_networks()) != 1:
         raise Exception("Unexpected number of networks")
+
+def test_dpp_duplicated_auth_resp(dev, apdev):
+    """DPP and duplicated Authentication Response"""
+    check_dpp_capab(dev[0])
+    check_dpp_capab(dev[1])
+
+    id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
+    uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
+    id1 = dev[1].dpp_qr_code(uri0)
+
+    dev[0].set("ext_mgmt_frame_handling", "1")
+    dev[1].set("ext_mgmt_frame_handling", "1")
+
+    cmd = "DPP_LISTEN 2412"
+    if "OK" not in dev[0].request(cmd):
+        raise Exception("Failed to start listen operation")
+
+    cmd = "DPP_AUTH_INIT peer=%d" % id1
+    if "OK" not in dev[1].request(cmd):
+        raise Exception("Failed to initiate DPP Authentication")
+
+    # DPP Authentication Request
+    rx_process_frame(dev[0])
+
+    # DPP Authentication Response
+    msg = rx_process_frame(dev[1])
+    frame = binascii.hexlify(msg['frame']).decode()
+    # Duplicated frame
+    if "OK" not in dev[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
+        raise Exception("MGMT_RX_PROCESS failed")
+    # Modified frame - nonzero status
+    if frame[2*32:2*37] != "0010010000":
+        raise Exception("Could not find Status attribute")
+    frame2 = frame[0:2*32] + "0010010001" + frame[2*37:]
+    if "OK" not in dev[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame2)):
+        raise Exception("MGMT_RX_PROCESS failed")
+    frame2 = frame[0:2*32] + "00100100ff" + frame[2*37:]
+    if "OK" not in dev[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame2)):
+        raise Exception("MGMT_RX_PROCESS failed")
+
+    # DPP Authentication Confirmation
+    rx_process_frame(dev[0])
+
+    wait_auth_success(dev[0], dev[1])
+
+    # DPP Configuration Request
+    rx_process_frame(dev[1])
+
+    # DPP Configuration Response
+    rx_process_frame(dev[0])
+
+    wait_conf_completion(dev[1], dev[0])