dpp-nfc: Add test mode for negotiated connection handover

Allow all actual DPP processing steps in wpa_supplicant to be skipped by
specifying hardcoded URI values. Also allow a hardcoded crn to be
specified to force specific handover requestor/selector roles.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
Jouni Malinen 2020-07-24 00:30:38 +03:00 committed by Jouni Malinen
parent 730fc307b1
commit 6eaee933d7

View file

@ -248,6 +248,11 @@ def dpp_handover_client(llc, alt=False):
if alt:
global altchanlist
chan_override = altchanlist
global test_uri, test_alt_uri
if test_uri:
summary("TEST MODE: Using specified URI (alt=%s)" % str(alt))
uri = test_alt_uri if alt else test_uri
else:
uri = wpas_get_nfc_uri(start_listen=False, chan_override=chan_override)
if uri is None:
summary("Cannot start handover client - no bootstrap URI available",
@ -256,6 +261,13 @@ def dpp_handover_client(llc, alt=False):
uri = ndef.UriRecord(uri)
summary("NFC URI record for DPP: " + str(uri))
carrier = ndef.Record('application/vnd.wfa.dpp', 'A', uri.data)
global test_crn
if test_crn:
prev, = struct.unpack('>H', test_crn)
summary("TEST MODE: Use specified crn %d" % prev)
crn = test_crn
test_crn = struct.pack('>H', prev + 0x10)
else:
crn = os.urandom(2)
hr = ndef.HandoverRequestRecord(version="1.4", crn=crn)
hr.add_alternative_carrier('active', carrier.name)
@ -338,6 +350,9 @@ def dpp_handover_client(llc, alt=False):
dpp_found = True
uri = carrier.data[1:].decode("utf-8")
summary("DPP URI: " + uri)
if test_uri:
summary("TEST MODE: Fake processing")
break
res = wpas_report_handover_sel(uri)
if res is None or "FAIL" in res:
summary("DPP handover report rejected", color=C_RED)
@ -467,9 +482,19 @@ class HandoverServer(nfc.handover.HandoverServer):
uri = carrier.data[1:].decode("utf-8")
summary("Received DPP URI: " + uri)
data = wpas_get_nfc_uri(start_listen=False, pick_channel=True)
global test_uri, test_alt_uri
if test_uri:
summary("TEST MODE: Using specified URI")
data = test_sel_uri if test_sel_uri else test_uri
else:
data = wpas_get_nfc_uri(start_listen=False,
pick_channel=True)
summary("Own URI (pre-processing): %s" % data)
if test_uri:
summary("TEST MODE: Fake processing")
res = "OK"
else:
res = wpas_report_handover_req(uri)
if res is None or "FAIL" in res:
summary("DPP handover request processing failed",
@ -481,8 +506,13 @@ class HandoverServer(nfc.handover.HandoverServer):
summary("Own URI (try another channel list): %s" % data)
continue
if test_alt_uri:
summary("TEST MODE: Reject initial proposal")
continue
found = True
if not test_uri:
wpas = wpas_connect()
if wpas is None:
continue
@ -494,6 +524,7 @@ class HandoverServer(nfc.handover.HandoverServer):
uri = ndef.UriRecord(data)
summary("Own bootstrapping NFC URI record: " + str(uri))
if not test_uri:
info = wpas.request("DPP_BOOTSTRAP_INFO %d" % own_id)
freq = None
for line in info.splitlines():
@ -802,6 +833,14 @@ def main():
parser.add_argument('--chan', default=None, help='channel list')
parser.add_argument('--altchan', default=None, help='alternative channel list')
parser.add_argument('--netrole', default=None, help='netrole for Enrollee')
parser.add_argument('--test-uri', default=None,
help='test mode: initial URI')
parser.add_argument('--test-alt-uri', default=None,
help='test mode: alternative URI')
parser.add_argument('--test-sel-uri', default=None,
help='test mode: handover select URI')
parser.add_argument('--test-crn', default=None,
help='test mode: hardcoded crn')
parser.add_argument('command', choices=['write-nfc-uri',
'write-nfc-hs'],
nargs='?')
@ -814,10 +853,18 @@ def main():
global no_wait
no_wait = args.no_wait
global chanlist, altchanlist, netrole
global chanlist, altchanlist, netrole, test_uri, test_alt_uri, test_sel_uri
global test_crn
chanlist = args.chan
altchanlist = args.altchan
netrole = args.netrole
test_uri = args.test_uri
test_alt_uri = args.test_alt_uri
test_sel_uri = args.test_sel_uri
if args.test_crn:
test_crn = struct.pack('>H', int(args.test_crn))
else:
test_crn = None
logging.basicConfig(level=args.loglevel)