From 15dfcb69df6b55b4833f457cdd2e7ea7cde59b60 Mon Sep 17 00:00:00 2001 From: Masashi Honma Date: Sat, 2 Feb 2019 17:52:25 +0200 Subject: [PATCH] tests: Use 'b' prefix to mark Bytes literals explicitly for python3 Signed-off-by: Masashi Honma Signed-off-by: Jouni Malinen --- tests/hwsim/test_ap_ft.py | 32 +-- tests/hwsim/test_ap_hs20.py | 84 +++---- tests/hwsim/test_ap_psk.py | 52 ++--- tests/hwsim/test_ap_wps.py | 386 +++++++++++++++---------------- tests/hwsim/test_dbus.py | 140 +++++------ tests/hwsim/test_dpp.py | 2 +- tests/hwsim/test_eap_proto.py | 16 +- tests/hwsim/test_fils.py | 82 +++---- tests/hwsim/test_gas.py | 4 +- tests/hwsim/test_kernel.py | 2 +- tests/hwsim/test_p2p_messages.py | 8 +- tests/hwsim/test_wnm.py | 2 +- tests/hwsim/test_wpas_mesh.py | 18 +- tests/hwsim/test_wpas_wmm_ac.py | 2 +- 14 files changed, 415 insertions(+), 415 deletions(-) diff --git a/tests/hwsim/test_ap_ft.py b/tests/hwsim/test_ap_ft.py index b5c4d8571..d55abf0f6 100644 --- a/tests/hwsim/test_ap_ft.py +++ b/tests/hwsim/test_ap_ft.py @@ -2061,81 +2061,81 @@ def test_ap_ft_rrb(dev, apdev): _dst_ll = binascii.unhexlify(apdev[0]['bssid'].replace(':','')) _src_ll = binascii.unhexlify(dev[0].own_addr().replace(':','')) - proto = '\x89\x0d' + proto = b'\x89\x0d' ehdr = _dst_ll + _src_ll + proto # Too short RRB frame - pkt = ehdr + '\x01' + pkt = ehdr + b'\x01' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # RRB discarded frame wikth unrecognized type - pkt = ehdr + '\x02' + '\x02' + '\x01\x00' + _src_ll + pkt = ehdr + b'\x02' + b'\x02' + b'\x01\x00' + _src_ll if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # RRB frame too short for action frame - pkt = ehdr + '\x01' + '\x02' + '\x01\x00' + _src_ll + pkt = ehdr + b'\x01' + b'\x02' + b'\x01\x00' + _src_ll if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Too short RRB frame (not enough room for Action Frame body) - pkt = ehdr + '\x01' + '\x02' + '\x00\x00' + _src_ll + pkt = ehdr + b'\x01' + b'\x02' + b'\x00\x00' + _src_ll if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Unexpected Action frame category - pkt = ehdr + '\x01' + '\x02' + '\x0e\x00' + _src_ll + '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\x02' + b'\x0e\x00' + _src_ll + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Unexpected Action in RRB Request - pkt = ehdr + '\x01' + '\x00' + '\x0e\x00' + _src_ll + '\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\x00' + b'\x0e\x00' + _src_ll + b'\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Target AP address in RRB Request does not match with own address - pkt = ehdr + '\x01' + '\x00' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\x00' + b'\x0e\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Not enough room for status code in RRB Response - pkt = ehdr + '\x01' + '\x01' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\x01' + b'\x0e\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # RRB discarded frame with unknown packet_type - pkt = ehdr + '\x01' + '\x02' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\x02' + b'\x0e\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # RRB Response with non-zero status code; no STA match - pkt = ehdr + '\x01' + '\x01' + '\x10\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + '\xff\xff' + pkt = ehdr + b'\x01' + b'\x01' + b'\x10\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\xff\xff' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # RRB Response with zero status code and extra data; STA match - pkt = ehdr + '\x01' + '\x01' + '\x11\x00' + _src_ll + '\x06\x01' + _src_ll + '\x00\x00\x00\x00\x00\x00' + '\x00\x00' + '\x00' + pkt = ehdr + b'\x01' + b'\x01' + b'\x11\x00' + _src_ll + b'\x06\x01' + _src_ll + b'\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Too short PMK-R1 pull - pkt = ehdr + '\x01' + '\xc8' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\xc8' + b'\x0e\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Too short PMK-R1 resp - pkt = ehdr + '\x01' + '\xc9' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\xc9' + b'\x0e\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Too short PMK-R1 push - pkt = ehdr + '\x01' + '\xca' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + pkt = ehdr + b'\x01' + b'\xca' + b'\x0e\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # No matching R0KH address found for PMK-R0 pull response - pkt = ehdr + '\x01' + '\xc9' + '\x5a\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + 76*'\00' + pkt = ehdr + b'\x01' + b'\xc9' + b'\x5a\x00' + _src_ll + b'\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + 76 * b'\00' if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py index 75fef33c2..af4bb774e 100644 --- a/tests/hwsim/test_ap_hs20.py +++ b/tests/hwsim/test_ap_hs20.py @@ -3011,7 +3011,7 @@ def test_ap_hs20_fetch_osu(dev, apdev): raise Exception("GET_HS20_ICON with too many output bytes to fit the buffer succeeded") if "FAIL" not in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 0 0"): raise Exception("GET_HS20_ICON 0..0 succeeded") - icon = "" + icon = b'' pos = 0 while True: if pos > 100000: @@ -3253,7 +3253,7 @@ def test_ap_hs20_fetch_osu_single_ssid2(dev, apdev): os.rmdir(dir) def get_icon(dev, bssid, iconname): - icon = "" + icon = b'' pos = 0 while True: if pos > 100000: @@ -3330,13 +3330,13 @@ def test_ap_hs20_req_operator_icon(dev, apdev): params['operator_icon'] = [ "w1fi_logo", "unknown_logo", "test_logo" ] hostapd.add_ap(apdev[0], params) - value = struct.pack('LBBBB", len(icmp), 0, 0, 0, 58) csum = ip_checksum(pseudo + icmp) return start + csum + end @@ -4362,7 +4362,7 @@ def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0, reachable_time=0, retrans_timer=0, opt=None): link_mc = binascii.unhexlify("3333ff000002") _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x86\xdd' + proto = b'\x86\xdd' ehdr = link_mc + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) @@ -4383,14 +4383,14 @@ def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0, def build_ns(src_ll, ip_src, ip_dst, target, opt=None): link_mc = binascii.unhexlify("3333ff000002") _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x86\xdd' + proto = b'\x86\xdd' ehdr = link_mc + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) if ip_dst is None: ip_dst = ipv6_solicited_node_mcaddr(target) _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) - reserved = '\x00\x00\x00\x00' + reserved = b'\x00\x00\x00\x00' _target = socket.inet_pton(socket.AF_INET6, target) if opt: payload = reserved + _target + opt @@ -4415,7 +4415,7 @@ def send_ns(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None, cmd = "DATA_TEST_FRAME " if opt is None: - opt = "\x01\x01" + binascii.unhexlify(src_ll.replace(':','')) + opt = b"\x01\x01" + binascii.unhexlify(src_ll.replace(':','')) pkt = build_ns(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target, opt=opt) @@ -4425,7 +4425,7 @@ def send_ns(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None, def build_na(src_ll, ip_src, ip_dst, target, opt=None, flags=0): link_mc = binascii.unhexlify("3333ff000002") _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x86\xdd' + proto = b'\x86\xdd' ehdr = link_mc + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) @@ -4464,42 +4464,42 @@ def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr, udp_checksum=True): _dst_ll = binascii.unhexlify(dst_ll.replace(':','')) _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x08\x00' + proto = b'\x08\x00' ehdr = _dst_ll + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET, ip_src) _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst) _subnet_mask = socket.inet_pton(socket.AF_INET, subnet_mask) - _ciaddr = '\x00\x00\x00\x00' + _ciaddr = b'\x00\x00\x00\x00' _yiaddr = socket.inet_pton(socket.AF_INET, yiaddr) - _siaddr = '\x00\x00\x00\x00' - _giaddr = '\x00\x00\x00\x00' + _siaddr = b'\x00\x00\x00\x00' + _giaddr = b'\x00\x00\x00\x00' _chaddr = binascii.unhexlify(chaddr.replace(':','') + "00000000000000000000") payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0) - payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00' + payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*b'\x00' # magic if wrong_magic: - payload += '\x63\x82\x53\x00' + payload += b'\x63\x82\x53\x00' else: - payload += '\x63\x82\x53\x63' + payload += b'\x63\x82\x53\x63' if truncated_opt: - payload += '\x22\xff\x00' + payload += b'\x22\xff\x00' # Option: DHCP Message Type = ACK - payload += '\x35\x01\x05' + payload += b'\x35\x01\x05' # Pad Option - payload += '\x00' + payload += b'\x00' # Option: Subnet Mask - payload += '\x01\x04' + _subnet_mask + payload += b'\x01\x04' + _subnet_mask # Option: Time Offset payload += struct.pack('>BBL', 2, 4, 0) # End Option - payload += '\xff' + payload += b'\xff' # Pad Option - payload += '\x00\x00\x00\x00' + payload += b'\x00\x00\x00\x00' if no_dhcp: payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0) - payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00' + payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*b'\x00' if udp_checksum: pseudohdr = _ip_src + _ip_dst + struct.pack('>BBH', 0, 17, @@ -4515,7 +4515,7 @@ def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr, else: tot_len = 20 + len(udp) start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) ipv4 = start + csum + _ip_src + _ip_dst @@ -4525,7 +4525,7 @@ def build_arp(dst_ll, src_ll, opcode, sender_mac, sender_ip, target_mac, target_ip): _dst_ll = binascii.unhexlify(dst_ll.replace(':','')) _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x08\x06' + proto = b'\x08\x06' ehdr = _dst_ll + _src_ll + proto _sender_mac = binascii.unhexlify(sender_mac.replace(':','')) @@ -5038,8 +5038,8 @@ def _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=False): addr1 = dev[1].p2p_interface_addr() addr2 = dev[2].p2p_interface_addr() - src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) - src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':','')) + src_ll_opt0 = b"\x01\x01" + binascii.unhexlify(addr0.replace(':','')) + src_ll_opt1 = b"\x01\x01" + binascii.unhexlify(addr1.replace(':','')) # DAD NS send_ns(dev[0], ip_src="::", target="aaaa:bbbb:cccc::2") @@ -5050,13 +5050,13 @@ def _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=False): opt='') # test frame with bogus option send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", - opt="\x70\x01\x01\x02\x03\x04\x05\x05") + opt=b"\x70\x01\x01\x02\x03\x04\x05\x05") # test frame with truncated source link-layer address option send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", - opt="\x01\x01\x01\x02\x03\x04") + opt=b"\x01\x01\x01\x02\x03\x04") # test frame with foreign source link-layer address option send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", - opt="\x01\x01\x01\x02\x03\x04\x05\x06") + opt=b"\x01\x01\x01\x02\x03\x04\x05\x06") send_ns(dev[1], ip_src="aaaa:bbbb:dddd::2", target="aaaa:bbbb:dddd::2") @@ -5288,7 +5288,7 @@ def run_proxyarp_errors(dev, apdev, params): wait_fail_trigger(dev[0], "GET_FAIL") with alloc_fail(hapd, 1, "sta_ip6addr_add"): - src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) + src_ll_opt0 = b"\x01\x01" + binascii.unhexlify(addr0.replace(':','')) pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2", ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2", opt=src_ll_opt0) diff --git a/tests/hwsim/test_ap_psk.py b/tests/hwsim/test_ap_psk.py index 7c04d6408..b6ed58d56 100644 --- a/tests/hwsim/test_ap_psk.py +++ b/tests/hwsim/test_ap_psk.py @@ -1245,7 +1245,7 @@ def build_eapol(msg): return data def sha1_prf(key, label, data, outlen): - res = '' + res = b'' counter = 0 while outlen > 0: m = hmac.new(key, label.encode(), hashlib.sha1) @@ -1296,7 +1296,7 @@ def rsn_eapol_key_set(msg, key_info, key_len, nonce, data): msg['length'] = 95 + len(data) else: msg['rsn_key_data_len'] = 0 - msg['rsn_key_data'] = '' + msg['rsn_key_data'] = b'' msg['length'] = 95 def recv_eapol(hapd): @@ -1577,7 +1577,7 @@ def test_ap_wpa2_psk_ext_eapol_key_info(dev, apdev): reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck) hapd_connected(hapd) -def build_eapol_key_1_4(anonce, replay_counter=1, key_data='', key_len=16): +def build_eapol_key_1_4(anonce, replay_counter=1, key_data=b'', key_len=16): msg = {} msg['version'] = 2 msg['type'] = 3 @@ -1626,15 +1626,15 @@ def aes_wrap(kek, plain): b = enc(struct.pack('>Q', a) + r[i - 1]) a = struct.unpack('>Q', b[:8])[0] ^ (n * j + i) r[i - 1] =b[8:] - return struct.pack('>Q', a) + ''.join(r) + return struct.pack('>Q', a) + b''.join(r) def pad_key_data(plain): pad_len = len(plain) % 8 if pad_len: pad_len = 8 - pad_len - plain += '\xdd' + plain += b'\xdd' pad_len -= 1 - plain += pad_len * '\0' + plain += pad_len * b'\x00' return plain def test_ap_wpa2_psk_supp_proto(dev, apdev): @@ -1658,7 +1658,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Invalid AES wrap data length 0") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '', replay_counter=counter) + msg = build_eapol_key_3_4(anonce, kck, b'', replay_counter=counter) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) ev = dev[0].wait_event(["WPA: Unsupported AES-WRAP len 0"]) @@ -1667,7 +1667,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Invalid AES wrap data length 1") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '1', replay_counter=counter) + msg = build_eapol_key_3_4(anonce, kck, b'1', replay_counter=counter) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) ev = dev[0].wait_event(["WPA: Unsupported AES-WRAP len 1"]) @@ -1676,7 +1676,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Invalid AES wrap data length 9") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '123456789', replay_counter=counter) + msg = build_eapol_key_3_4(anonce, kck, b'123456789', replay_counter=counter) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) ev = dev[0].wait_event(["WPA: Unsupported AES-WRAP len 9"]) @@ -1685,7 +1685,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Invalid AES wrap data payload") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter) + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter) # do not increment counter to test replay protection send_eapol(dev[0], bssid, build_eapol(msg)) ev = dev[0].wait_event(["WPA: AES unwrap failed"]) @@ -1694,7 +1694,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Replay Count not increasing") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter) + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) ev = dev[0].wait_event(["WPA: EAPOL-Key Replay Counter did not increase"]) @@ -1703,7 +1703,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Missing Ack bit in key info") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter, + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter, key_info=0x134a) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1713,7 +1713,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Unexpected Request bit in key info") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter, + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter, key_info=0x1bca) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1723,7 +1723,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Unsupported key descriptor version 0") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef', + msg = build_eapol_key_3_4(anonce, kck, b'0123456789abcdef', replay_counter=counter, key_info=0x13c8) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1733,7 +1733,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Key descriptor version 1 not allowed with CCMP") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef', + msg = build_eapol_key_3_4(anonce, kck, b'0123456789abcdef', replay_counter=counter, key_info=0x13c9) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1743,7 +1743,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Invalid AES wrap payload with key descriptor version 2") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef', + msg = build_eapol_key_3_4(anonce, kck, b'0123456789abcdef', replay_counter=counter, key_info=0x13ca) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1753,7 +1753,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Key descriptor version 3 workaround") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef', + msg = build_eapol_key_3_4(anonce, kck, b'0123456789abcdef', replay_counter=counter, key_info=0x13cb) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1769,7 +1769,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Unsupported key descriptor version 4") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef', + msg = build_eapol_key_3_4(anonce, kck, b'0123456789abcdef', replay_counter=counter, key_info=0x13cc) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1779,7 +1779,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Unsupported key descriptor version 7") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef', + msg = build_eapol_key_3_4(anonce, kck, b'0123456789abcdef', replay_counter=counter, key_info=0x13cf) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1789,7 +1789,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Too short EAPOL header length") dev[0].dump_monitor() - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter, + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter, extra_len=-1) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1798,26 +1798,26 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): raise Exception("Key data overflow not reported") logger.debug("Too long EAPOL header length") - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter, + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter, extra_len=1) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) logger.debug("Unsupported descriptor type 0") - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter, + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter, descr_type=0) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) logger.debug("WPA descriptor type 0") - msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter, + msg = build_eapol_key_3_4(anonce, kck, b'12345678', replay_counter=counter, descr_type=254) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) logger.debug("Non-zero key index for pairwise key") dev[0].dump_monitor() - wrapped = aes_wrap(kek, 16*'z') + wrapped = aes_wrap(kek, 16*b'z') msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter, key_info=0x13ea) counter += 1 @@ -1828,7 +1828,7 @@ def test_ap_wpa2_psk_supp_proto(dev, apdev): logger.debug("Invalid Key Data plaintext payload --> disconnect") dev[0].dump_monitor() - wrapped = aes_wrap(kek, 16*'z') + wrapped = aes_wrap(kek, 16*b'z') msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) @@ -1855,7 +1855,7 @@ def test_ap_wpa2_psk_supp_proto_no_ie(dev, apdev): logger.debug("No IEs in msg 3/4 --> disconnect") dev[0].dump_monitor() - wrapped = aes_wrap(kek, 16*'\0') + wrapped = aes_wrap(kek, 16*b'\x00') msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter) counter += 1 send_eapol(dev[0], bssid, build_eapol(msg)) diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py index de2039572..e845df9c1 100644 --- a/tests/hwsim/test_ap_wps.py +++ b/tests/hwsim/test_ap_wps.py @@ -612,11 +612,11 @@ def test_ap_wps_reg_override_ap_settings(dev, apdev): except: pass # Override AP Settings with values that point to another AP - data = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') - data += build_wsc_attr(ATTR_SSID, "test") - data += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') - data += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') - data += build_wsc_attr(ATTR_NETWORK_KEY, '') + data = build_wsc_attr(ATTR_NETWORK_INDEX, b'\x01') + data += build_wsc_attr(ATTR_SSID, b"test") + data += build_wsc_attr(ATTR_AUTH_TYPE, b'\x00\x01') + data += build_wsc_attr(ATTR_ENCR_TYPE, b'\x00\x01') + data += build_wsc_attr(ATTR_NETWORK_KEY, b'') data += build_wsc_attr(ATTR_MAC_ADDR, binascii.unhexlify(apdev[1]['bssid'].replace(':', ''))) with open(ap_settings, "w") as f: f.write(data) @@ -4322,164 +4322,164 @@ RGV2aWNlIEEQSQAGADcqAAEg time.sleep(0.5) logger.info("Too short WLANEvent") - data = '\x00' + data = b'\x00' send_wlanevent(url, uuid, data) logger.info("Invalid WLANEventMAC") - data = '\x00qwertyuiopasdfghjklzxcvbnm' + data = b'\x00qwertyuiopasdfghjklzxcvbnm' send_wlanevent(url, uuid, data) logger.info("Unknown WLANEventType") - data = '\xff02:00:00:00:00:00' + data = b'\xff02:00:00:00:00:00' send_wlanevent(url, uuid, data) logger.info("Probe Request notification without any attributes") - data = '\x0102:00:00:00:00:00' + data = b'\x0102:00:00:00:00:00' send_wlanevent(url, uuid, data) logger.info("Probe Request notification with invalid attribute") - data = '\x0102:00:00:00:00:00\xff' + data = b'\x0102:00:00:00:00:00\xff' send_wlanevent(url, uuid, data) logger.info("EAP message without any attributes") - data = '\x0202:00:00:00:00:00' + data = b'\x0202:00:00:00:00:00' send_wlanevent(url, uuid, data) logger.info("EAP message with invalid attribute") - data = '\x0202:00:00:00:00:00\xff' + data = b'\x0202:00:00:00:00:00\xff' send_wlanevent(url, uuid, data) logger.info("EAP message from new STA and not M1") - data = '\x0202:ff:ff:ff:ff:ff' + '\x10\x22\x00\x01\x05' + data = b'\x0202:ff:ff:ff:ff:ff' + b'\x10\x22\x00\x01\x05' send_wlanevent(url, uuid, data) logger.info("EAP message: M1") - data = '\x0202:00:00:00:00:00' - data += '\x10\x22\x00\x01\x04' - data += '\x10\x47\x00\x10' + 16*'\x00' - data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' - data += '\x10\x1a\x00\x10' + 16*'\x00' - data += '\x10\x32\x00\xc0' + 192*'\x00' - data += '\x10\x04\x00\x02\x00\x00' - data += '\x10\x10\x00\x02\x00\x00' - data += '\x10\x0d\x00\x01\x00' - data += '\x10\x08\x00\x02\x00\x00' - data += '\x10\x44\x00\x01\x00' - data += '\x10\x21\x00\x00' - data += '\x10\x23\x00\x00' - data += '\x10\x24\x00\x00' - data += '\x10\x42\x00\x00' - data += '\x10\x54\x00\x08' + 8*'\x00' - data += '\x10\x11\x00\x00' - data += '\x10\x3c\x00\x01\x00' - data += '\x10\x02\x00\x02\x00\x00' - data += '\x10\x12\x00\x02\x00\x00' - data += '\x10\x09\x00\x02\x00\x00' - data += '\x10\x2d\x00\x04\x00\x00\x00\x00' + data = b'\x0202:00:00:00:00:00' + data += b'\x10\x22\x00\x01\x04' + data += b'\x10\x47\x00\x10' + 16 * b'\x00' + data += b'\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' + data += b'\x10\x1a\x00\x10' + 16 * b'\x00' + data += b'\x10\x32\x00\xc0' + 192 * b'\x00' + data += b'\x10\x04\x00\x02\x00\x00' + data += b'\x10\x10\x00\x02\x00\x00' + data += b'\x10\x0d\x00\x01\x00' + data += b'\x10\x08\x00\x02\x00\x00' + data += b'\x10\x44\x00\x01\x00' + data += b'\x10\x21\x00\x00' + data += b'\x10\x23\x00\x00' + data += b'\x10\x24\x00\x00' + data += b'\x10\x42\x00\x00' + data += b'\x10\x54\x00\x08' + 8 * b'\x00' + data += b'\x10\x11\x00\x00' + data += b'\x10\x3c\x00\x01\x00' + data += b'\x10\x02\x00\x02\x00\x00' + data += b'\x10\x12\x00\x02\x00\x00' + data += b'\x10\x09\x00\x02\x00\x00' + data += b'\x10\x2d\x00\x04\x00\x00\x00\x00' m1 = data send_wlanevent(url, uuid, data) logger.info("EAP message: WSC_ACK") - data = '\x0202:00:00:00:00:00' + '\x10\x22\x00\x01\x0d' + data = b'\x0202:00:00:00:00:00' + b'\x10\x22\x00\x01\x0d' send_wlanevent(url, uuid, data) logger.info("EAP message: M1") send_wlanevent(url, uuid, m1) logger.info("EAP message: WSC_NACK") - data = '\x0202:00:00:00:00:00' + '\x10\x22\x00\x01\x0e' + data = b'\x0202:00:00:00:00:00' + b'\x10\x22\x00\x01\x0e' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 - Too long attribute values") - data = '\x0202:00:00:00:00:00' - data += '\x10\x11\x00\x21' + 33*'\x00' - data += '\x10\x45\x00\x21' + 33*'\x00' - data += '\x10\x42\x00\x21' + 33*'\x00' - data += '\x10\x24\x00\x21' + 33*'\x00' - data += '\x10\x23\x00\x21' + 33*'\x00' - data += '\x10\x21\x00\x41' + 65*'\x00' - data += '\x10\x49\x00\x09\x00\x37\x2a\x05\x02\x00\x00\x05\x00' + data = b'\x0202:00:00:00:00:00' + data += b'\x10\x11\x00\x21' + 33 * b'\x00' + data += b'\x10\x45\x00\x21' + 33 * b'\x00' + data += b'\x10\x42\x00\x21' + 33 * b'\x00' + data += b'\x10\x24\x00\x21' + 33 * b'\x00' + data += b'\x10\x23\x00\x21' + 33 * b'\x00' + data += b'\x10\x21\x00\x41' + 65 * b'\x00' + data += b'\x10\x49\x00\x09\x00\x37\x2a\x05\x02\x00\x00\x05\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing UUID-E") - data = '\x0202:00:00:00:00:00' - data += '\x10\x22\x00\x01\x04' + data = b'\x0202:00:00:00:00:00' + data += b'\x10\x22\x00\x01\x04' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing MAC Address") - data += '\x10\x47\x00\x10' + 16*'\x00' + data += b'\x10\x47\x00\x10' + 16 * b'\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Enrollee Nonce") - data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' + data += b'\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Public Key") - data += '\x10\x1a\x00\x10' + 16*'\x00' + data += b'\x10\x1a\x00\x10' + 16 * b'\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Authentication Type flags") - data += '\x10\x32\x00\xc0' + 192*'\x00' + data += b'\x10\x32\x00\xc0' + 192 * b'\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Encryption Type Flags") - data += '\x10\x04\x00\x02\x00\x00' + data += b'\x10\x04\x00\x02\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Connection Type flags") - data += '\x10\x10\x00\x02\x00\x00' + data += b'\x10\x10\x00\x02\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Config Methods") - data += '\x10\x0d\x00\x01\x00' + data += b'\x10\x0d\x00\x01\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Wi-Fi Protected Setup State") - data += '\x10\x08\x00\x02\x00\x00' + data += b'\x10\x08\x00\x02\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Manufacturer") - data += '\x10\x44\x00\x01\x00' + data += b'\x10\x44\x00\x01\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Model Name") - data += '\x10\x21\x00\x00' + data += b'\x10\x21\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Model Number") - data += '\x10\x23\x00\x00' + data += b'\x10\x23\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Serial Number") - data += '\x10\x24\x00\x00' + data += b'\x10\x24\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Primary Device Type") - data += '\x10\x42\x00\x00' + data += b'\x10\x42\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Device Name") - data += '\x10\x54\x00\x08' + 8*'\x00' + data += b'\x10\x54\x00\x08' + 8 * b'\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing RF Bands") - data += '\x10\x11\x00\x00' + data += b'\x10\x11\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Association State") - data += '\x10\x3c\x00\x01\x00' + data += b'\x10\x3c\x00\x01\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Device Password ID") - data += '\x10\x02\x00\x02\x00\x00' + data += b'\x10\x02\x00\x02\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing Configuration Error") - data += '\x10\x12\x00\x02\x00\x00' + data += b'\x10\x12\x00\x02\x00\x00' send_wlanevent(url, uuid, data) logger.info("EAP message: M1 missing OS Version") - data += '\x10\x09\x00\x02\x00\x00' + data += b'\x10\x09\x00\x02\x00\x00' send_wlanevent(url, uuid, data) logger.info("Check max concurrent requests") @@ -4586,10 +4586,10 @@ RGV2aWNlIEEQSQAGADcqAAEg raise Exception("Unexpected HTTP response: %d" % resp.status) with alloc_fail(dev[0], 1, "xml_get_first_item"): - send_wlanevent(url, uuid, '') + send_wlanevent(url, uuid, b'') with alloc_fail(dev[0], 1, "wpabuf_alloc_ext_data;xml_get_base64_item"): - send_wlanevent(url, uuid, 'foo') + send_wlanevent(url, uuid, b'foo') for func in [ "wps_init", "wps_process_manufacturer", @@ -4608,28 +4608,28 @@ RGV2aWNlIEEQSQAGADcqAAEg send_wlanevent(url2, uuid, m1, no_response=True) logger.info("EAP message: M1") - data = '\x0202:11:22:00:00:00' - data += '\x10\x22\x00\x01\x04' - data += '\x10\x47\x00\x10' + 16*'\x00' - data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' - data += '\x10\x1a\x00\x10' + 16*'\x00' - data += '\x10\x32\x00\xc0' + 192*'\x00' - data += '\x10\x04\x00\x02\x00\x00' - data += '\x10\x10\x00\x02\x00\x00' - data += '\x10\x0d\x00\x01\x00' - data += '\x10\x08\x00\x02\x00\x00' - data += '\x10\x44\x00\x01\x00' - data += '\x10\x21\x00\x00' - data += '\x10\x23\x00\x00' - data += '\x10\x24\x00\x00' - data += '\x10\x42\x00\x00' - data += '\x10\x54\x00\x08' + 8*'\x00' - data += '\x10\x11\x00\x00' - data += '\x10\x3c\x00\x01\x00' - data += '\x10\x02\x00\x02\x00\x00' - data += '\x10\x12\x00\x02\x00\x00' - data += '\x10\x09\x00\x02\x00\x00' - data += '\x10\x2d\x00\x04\x00\x00\x00\x00' + data = b'\x0202:11:22:00:00:00' + data += b'\x10\x22\x00\x01\x04' + data += b'\x10\x47\x00\x10' + 16 * b'\x00' + data += b'\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' + data += b'\x10\x1a\x00\x10' + 16 * b'\x00' + data += b'\x10\x32\x00\xc0' + 192 * b'\x00' + data += b'\x10\x04\x00\x02\x00\x00' + data += b'\x10\x10\x00\x02\x00\x00' + data += b'\x10\x0d\x00\x01\x00' + data += b'\x10\x08\x00\x02\x00\x00' + data += b'\x10\x44\x00\x01\x00' + data += b'\x10\x21\x00\x00' + data += b'\x10\x23\x00\x00' + data += b'\x10\x24\x00\x00' + data += b'\x10\x42\x00\x00' + data += b'\x10\x54\x00\x08' + 8 * b'\x00' + data += b'\x10\x11\x00\x00' + data += b'\x10\x3c\x00\x01\x00' + data += b'\x10\x02\x00\x02\x00\x00' + data += b'\x10\x12\x00\x02\x00\x00' + data += b'\x10\x09\x00\x02\x00\x00' + data += b'\x10\x2d\x00\x04\x00\x00\x00\x00' dev[0].dump_monitor() with alloc_fail(dev[0], 1, "wps_er_add_sta_data"): send_wlanevent(url, uuid, data) @@ -4920,7 +4920,7 @@ def test_ap_wps_er_http_client(dev, apdev): class WPSAPHTTPServer_req_as_resp(WPSAPHTTPServer): def handle_upnp_info(self): - self.wfile.write("GET / HTTP/1.1\r\n\r\n") + self.wfile.write(b"GET / HTTP/1.1\r\n\r\n") run_wps_er_proto_test(dev[0], WPSAPHTTPServer_req_as_resp, no_event_url=True) @@ -6185,7 +6185,7 @@ def get_wsc_msg(dev): if msg['eap_type'] == 254: if len(data) < 3 + 4: raise Exception("Truncated EAP expanded header") - msg['eap_vendor_id'], msg['eap_vendor_type'] = struct.unpack('>LL', '\0' + data[0:7]) + msg['eap_vendor_id'], msg['eap_vendor_type'] = struct.unpack('>LL', b'\x00' + data[0:7]) data = data[7:] else: raise Exception("Unexpected EAP type") @@ -6273,7 +6273,7 @@ group_5_prime = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC group_5_generator = 2 def wsc_kdf(key, label, bits): - result = '' + result = b'' i = 1 while len(result) * 8 < bits: data = struct.pack('>L', i) + label.encode() + struct.pack('>L', bits) @@ -6309,7 +6309,7 @@ def build_attr_encr_settings(authkey, keywrapkey, data): m = hmac.new(authkey, data, hashlib.sha256) kwa = m.digest()[0:8] data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) - iv = 16*'\x99' + iv = 16*b'\x99' aes = AES.new(keywrapkey, AES.MODE_CBC, iv) pad_len = 16 - len(data) % 16 ps = pad_len * struct.pack('B', pad_len) @@ -6391,12 +6391,12 @@ def wsc_dev_pw_hash(authkey, dev_pw, e_pk, r_pk): # Note: Secret values are supposed to be random, but hardcoded values are # fine for testing. - s1 = 16*'\x77' + s1 = 16*b'\x77' m = hmac.new(authkey, s1 + psk1 + e_pk + r_pk, hashlib.sha256) hash1 = m.digest() logger.debug("Hash1: " + binascii.hexlify(hash1).decode()) - s2 = 16*'\x88' + s2 = 16*b'\x88' m = hmac.new(authkey, s2 + psk2 + e_pk + r_pk, hashlib.sha256) hash2 = m.digest() logger.debug("Hash2: " + binascii.hexlify(hash2).decode()) @@ -6523,8 +6523,8 @@ def test_wps_ext(dev, apdev): wsc_start_id = msg['eap_identifier'] mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -6599,12 +6599,12 @@ def test_wps_ext(dev, apdev): # Do not send WSC_Done yet to allow exchangw with STA complete before the # AP disconnects. - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' eap_id = wsc_start_id logger.debug("Send WSC/Start to STA") - wsc_start = build_eap_wsc(1, eap_id, "", opcode=WSC_Start) + wsc_start = build_eap_wsc(1, eap_id, b'', opcode=WSC_Start) send_wsc_msg(dev[0], bssid, wsc_start) eap_id = (eap_id + 1) % 256 @@ -6700,8 +6700,8 @@ def wps_start_kwa(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -6753,7 +6753,7 @@ def test_wps_ext_kwa_proto_no_kwa(dev, apdev): r_s1,keywrapkey,authkey,raw_m3_attrs,eap_id,bssid,attrs = wps_start_kwa(dev, apdev) data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) # Encrypted Settings without KWA - iv = 16*'\x99' + iv = 16*b'\x99' aes = AES.new(keywrapkey, AES.MODE_CBC, iv) pad_len = 16 - len(data) % 16 ps = pad_len * struct.pack('B', pad_len) @@ -6771,7 +6771,7 @@ def test_wps_ext_kwa_proto_data_after_kwa(dev, apdev): kwa = m.digest()[0:8] data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) data += build_wsc_attr(ATTR_VENDOR_EXT, "1234567890") - iv = 16*'\x99' + iv = 16*b'\x99' aes = AES.new(keywrapkey, AES.MODE_CBC, iv) pad_len = 16 - len(data) % 16 ps = pad_len * struct.pack('B', pad_len) @@ -6786,7 +6786,7 @@ def test_wps_ext_kwa_proto_kwa_mismatch(dev, apdev): data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) # Encrypted Settings and KWA with incorrect value data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, 8*'\x00') - iv = 16*'\x99' + iv = 16*b'\x99' aes = AES.new(keywrapkey, AES.MODE_CBC, iv) pad_len = 16 - len(data) % 16 ps = pad_len * struct.pack('B', pad_len) @@ -6803,8 +6803,8 @@ def wps_run_cred_proto(dev, apdev, m8_cred, connect=False, no_connect=False): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -6909,7 +6909,7 @@ def wps_run_cred_proto(dev, apdev, m8_cred, connect=False, no_connect=False): def build_cred(nw_idx='\x01', ssid='test-wps-conf', auth_type='\x00\x20', encr_type='\x00\x08', nw_key="12345678", mac_addr='\x00\x00\x00\x00\x00\x00'): - attrs = '' + attrs = b'' if nw_idx is not None: attrs += build_wsc_attr(ATTR_NETWORK_INDEX, nw_idx) if ssid is not None: @@ -6993,7 +6993,7 @@ def test_wps_ext_cred_proto_invalid_encr_type(dev, apdev): def test_wps_ext_cred_proto_missing_cred(dev, apdev): """WPS and Credential: Missing Credential""" mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - m8_cred = '' + m8_cred = b'' wps_run_cred_proto(dev, apdev, m8_cred) def test_wps_ext_proto_m2_no_public_key(dev, apdev): @@ -7005,8 +7005,8 @@ def test_wps_ext_proto_m2_no_public_key(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -7043,8 +7043,8 @@ def test_wps_ext_proto_m2_invalid_public_key(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -7060,7 +7060,7 @@ def test_wps_ext_proto_m2_invalid_public_key(dev, apdev): logger.debug("Send M2 to STA") m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], - r_nonce, uuid_r, 192*'\xff') + r_nonce, uuid_r, 192*b'\xff') send_wsc_msg(dev[0], bssid, m2) eap_id = (eap_id + 1) % 256 @@ -7081,8 +7081,8 @@ def test_wps_ext_proto_m2_public_key_oom(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -7120,8 +7120,8 @@ def test_wps_ext_proto_nack_m3(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -7163,8 +7163,8 @@ def test_wps_ext_proto_nack_m5(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -7222,8 +7222,8 @@ def wps_nack_m3(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -7321,7 +7321,7 @@ def test_wps_ext_proto_nack_m3_invalid_attr(dev, apdev): """WPS and NACK M3 invalid attribute""" eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) logger.debug("Send NACK to STA") - attrs = '\x10\x10\x00' + attrs = b'\x10\x10\x00' msg = build_eap_wsc(1, eap_id, attrs, opcode=WSC_NACK) send_wsc_msg(dev[0], bssid, msg) dev[0].request("WPS_CANCEL") @@ -7392,7 +7392,7 @@ def test_wps_ext_proto_ack_m3_invalid_attr(dev, apdev): """WPS and ACK M3 invalid attribute""" eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) logger.debug("Send ACK to STA") - attrs = '\x10\x10\x00' + attrs = b'\x10\x10\x00' msg = build_eap_wsc(1, eap_id, attrs, opcode=WSC_ACK) send_wsc_msg(dev[0], bssid, msg) dev[0].request("WPS_CANCEL") @@ -7417,8 +7417,8 @@ def wps_to_m3_helper(dev, apdev): wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, e_pk = wsc_dh_init() logger.debug("Receive M1 from STA") @@ -7531,7 +7531,7 @@ def test_wps_ext_proto_m4_missing_r_snonce1(dev, apdev): attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) #data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) - data = '' + data = b'' attrs += build_attr_encr_settings(authkey, keywrapkey, data) attrs += build_attr_authenticator(authkey, m3, attrs) m4 = build_eap_wsc(1, eap_id, attrs) @@ -7562,7 +7562,7 @@ def test_wps_ext_proto_m4_invalid_pad_string(dev, apdev): m = hmac.new(authkey, data, hashlib.sha256) kwa = m.digest()[0:8] data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) - iv = 16*'\x99' + iv = 16*b'\x99' aes = AES.new(keywrapkey, AES.MODE_CBC, iv) pad_len = 16 - len(data) % 16 ps = (pad_len - 1) * struct.pack('B', pad_len) + struct.pack('B', pad_len - 1) @@ -7599,7 +7599,7 @@ def test_wps_ext_proto_m4_invalid_pad_value(dev, apdev): m = hmac.new(authkey, data, hashlib.sha256) kwa = m.digest()[0:8] data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) - iv = 16*'\x99' + iv = 16*b'\x99' aes = AES.new(keywrapkey, AES.MODE_CBC, iv) pad_len = 16 - len(data) % 16 ps = (pad_len - 1) * struct.pack('B', pad_len) + struct.pack('B', 255) @@ -7654,7 +7654,7 @@ def test_wps_ext_proto_m6_missing_r_snonce2(dev, apdev): attrs += build_attr_msg_type(WPS_M6) attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) #data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) - data = '' + data = b'' attrs += build_attr_encr_settings(authkey, keywrapkey, data) attrs += build_attr_authenticator(authkey, m5, attrs) m6 = build_eap_wsc(1, eap_id, attrs) @@ -7763,8 +7763,8 @@ def wps_run_ap_settings_proto(dev, apdev, ap_settings, success): e_pk = m1_attrs[ATTR_PUBLIC_KEY] appin = '12345670' - uuid_r = 16*'\x33' - r_nonce = 16*'\x44' + uuid_r = 16*b'\x33' + r_nonce = 16*b'\x44' own_private, r_pk = wsc_dh_init() authkey,keywrapkey = wsc_dh_kdf(e_pk, own_private, mac_addr, e_nonce, r_nonce) @@ -7947,8 +7947,8 @@ def test_wps_ext_m3_missing_e_hash1(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -7992,8 +7992,8 @@ def test_wps_ext_m3_missing_e_hash2(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8037,8 +8037,8 @@ def test_wps_ext_m5_missing_e_snonce1(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8074,7 +8074,7 @@ def test_wps_ext_m5_missing_e_snonce1(dev, apdev): attrs += build_attr_msg_type(WPS_M5) attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) #data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) - data = '' + data = b'' attrs += build_attr_encr_settings(authkey, keywrapkey, data) attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) raw_m5_attrs = attrs @@ -8097,8 +8097,8 @@ def test_wps_ext_m5_e_snonce1_mismatch(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8155,8 +8155,8 @@ def test_wps_ext_m7_missing_e_snonce2(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8206,7 +8206,7 @@ def test_wps_ext_m7_missing_e_snonce2(dev, apdev): attrs += build_attr_msg_type(WPS_M7) attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) #data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) - data = '' + data = b'' attrs += build_attr_encr_settings(authkey, keywrapkey, data) attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) @@ -8229,8 +8229,8 @@ def test_wps_ext_m7_e_snonce2_mismatch(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8333,8 +8333,8 @@ def test_wps_ext_m3_m1(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8378,8 +8378,8 @@ def test_wps_ext_m5_m3(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8437,8 +8437,8 @@ def test_wps_ext_m3_m2(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8480,8 +8480,8 @@ def test_wps_ext_m3_m5(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8525,8 +8525,8 @@ def test_wps_ext_m3_m7(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8570,8 +8570,8 @@ def test_wps_ext_m3_done(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8612,8 +8612,8 @@ def test_wps_ext_m2_nack_invalid(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8631,7 +8631,7 @@ def test_wps_ext_m2_nack_invalid(dev, apdev): e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) logger.debug("Send WSC_NACK to AP") - attrs = '\x10\x00\x00' + attrs = b'\x10\x00\x00' nack = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_NACK) send_wsc_msg(hapd, addr, nack) @@ -8651,8 +8651,8 @@ def test_wps_ext_m2_nack_no_msg_type(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8690,8 +8690,8 @@ def test_wps_ext_m2_nack_invalid_msg_type(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8729,8 +8729,8 @@ def test_wps_ext_m2_nack_e_nonce_mismatch(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8748,7 +8748,7 @@ def test_wps_ext_m2_nack_e_nonce_mismatch(dev, apdev): e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) logger.debug("Send WSC_NACK to AP") - nack,attrs = build_nack(msg['eap_identifier'], 16*'\x00', r_nonce, + nack,attrs = build_nack(msg['eap_identifier'], 16*b'\x00', r_nonce, eap_code=2) send_wsc_msg(hapd, addr, nack) @@ -8768,8 +8768,8 @@ def test_wps_ext_m2_nack_no_config_error(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8807,8 +8807,8 @@ def test_wps_ext_m2_ack_invalid(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8826,7 +8826,7 @@ def test_wps_ext_m2_ack_invalid(dev, apdev): e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) logger.debug("Send WSC_ACK to AP") - attrs = '\x10\x00\x00' + attrs = b'\x10\x00\x00' ack = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_ACK) send_wsc_msg(hapd, addr, ack) @@ -8846,8 +8846,8 @@ def test_wps_ext_m2_ack(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8884,8 +8884,8 @@ def test_wps_ext_m2_ack_no_msg_type(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8923,8 +8923,8 @@ def test_wps_ext_m2_ack_invalid_msg_type(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8962,8 +8962,8 @@ def test_wps_ext_m2_ack_e_nonce_mismatch(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -8981,7 +8981,7 @@ def test_wps_ext_m2_ack_e_nonce_mismatch(dev, apdev): e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) logger.debug("Send WSC_ACK to AP") - ack,attrs = build_ack(msg['eap_identifier'], 16*'\x00', r_nonce, + ack,attrs = build_ack(msg['eap_identifier'], 16*b'\x00', r_nonce, eap_code=2) send_wsc_msg(hapd, addr, ack) @@ -9001,7 +9001,7 @@ def test_wps_ext_m1_invalid(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") logger.debug("Send M1 to AP") - attrs = '\x10\x00\x00' + attrs = b'\x10\x00\x00' m1 = build_eap_wsc(2, msg['eap_identifier'], attrs) send_wsc_msg(hapd, addr, m1) @@ -9024,7 +9024,7 @@ def test_wps_ext_m1_missing_msg_type(dev, apdev): m1 = build_eap_wsc(2, msg['eap_identifier'], attrs) send_wsc_msg(hapd, addr, m1) - wps_wait_ap_nack(hapd, dev[0], 16*'\x00', 16*'\x00') + wps_wait_ap_nack(hapd, dev[0], 16*b'\x00', 16*b'\x00') def wps_ext_wsc_done(dev, apdev): pin = "12345670" @@ -9038,8 +9038,8 @@ def wps_ext_wsc_done(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -9105,7 +9105,7 @@ def test_wps_ext_wsc_done_invalid(dev, apdev): hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) logger.debug("Send WSC_Done to AP") - attrs = '\x10\x00\x00' + attrs = b'\x10\x00\x00' wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) @@ -9184,8 +9184,8 @@ def test_wps_ext_m7_no_encr_settings(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") @@ -9257,14 +9257,14 @@ def test_wps_ext_m1_workaround(dev, apdev): raise Exception("Unexpected Op-Code for WSC/Start") mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) - uuid_e = 16*'\x11' - e_nonce = 16*'\x22' + uuid_e = 16*b'\x11' + e_nonce = 16*b'\x22' own_private, e_pk = wsc_dh_init() logger.debug("Send M1 to AP") m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, e_nonce, e_pk, manufacturer='Apple TEST', - model_name='AirPort', config_methods='\xff\xff') + model_name='AirPort', config_methods=b'\xff\xff') send_wsc_msg(hapd, addr, m1) logger.debug("Receive M2 from AP") diff --git a/tests/hwsim/test_dbus.py b/tests/hwsim/test_dbus.py index 5e5078b7d..2e6b9336c 100644 --- a/tests/hwsim/test_dbus.py +++ b/tests/hwsim/test_dbus.py @@ -259,14 +259,14 @@ def test_dbus_properties(dev, apdev): if val != res: raise Exception("WFDIEs value changed") try: - dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray('\x00')) + dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(b'\x00')) raise Exception("Invalid WFDIEs value accepted") except dbus.exceptions.DBusException as e: if "InvalidArgs" not in str(e): raise Exception("Unexpected error message: " + str(e)) - dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray('')) + dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(b'')) dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(val)) - dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray('')) + dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(b'')) res = dbus_get(dbus, wpas_obj, "WFDIEs", byte_arrays=True) if len(res) != 0: raise Exception("WFDIEs not cleared properly") @@ -314,7 +314,7 @@ def test_dbus_properties(dev, apdev): try: wpas_obj.Set(WPAS_DBUS_SERVICE, "WFDIEs", - dbus.ByteArray('', variant_level=2), + dbus.ByteArray(b'', variant_level=2), dbus_interface=dbus.PROPERTIES_IFACE) raise Exception("Invalid Set accepted") except dbus.exceptions.DBusException as e: @@ -443,7 +443,7 @@ def _test_dbus_get_set_wps(dev, apdev): if val[0] != 0x00 or val[1] != 0x05 != val[2] != 0x00 or val[3] != 0x50 or val[4] != 0xf2 or val[5] != 0x04 or val[6] != 0x00 or val[7] != 0x01: raise Exception("DeviceType mismatch after Set") - val2 = '\x01\x02\x03\x04\x05\x06\x07\x08' + val2 = b'\x01\x02\x03\x04\x05\x06\x07\x08' if_obj.Set(WPAS_DBUS_IFACE_WPS, "DeviceType", dbus.ByteArray(val2), dbus_interface=dbus.PROPERTIES_IFACE) val = if_obj.Get(WPAS_DBUS_IFACE_WPS, "DeviceType", @@ -527,11 +527,11 @@ def test_dbus_wps_invalid(dev, apdev): 'Bssid': '02:33:44:55:66:77'}, {'Role': 'enrollee', 'Type': 'pin', 'Pin': 123}, {'Role': 'enrollee', 'Type': 'pbc', - 'Bssid': dbus.ByteArray('12345')}, + 'Bssid': dbus.ByteArray(b'12345')}, {'Role': 'enrollee', 'Type': 'pbc', 'P2PDeviceAddress': 12345}, {'Role': 'enrollee', 'Type': 'pbc', - 'P2PDeviceAddress': dbus.ByteArray('12345')}, + 'P2PDeviceAddress': dbus.ByteArray(b'12345')}, {'Role': 'enrollee', 'Type': 'pbc', 'Foo': 'bar'} ] for args in failures: try: @@ -999,18 +999,18 @@ def test_dbus_scan_invalid(dev, apdev): ({'Type': 'active', 'SSIDs': 'foo'}, "InvalidArgs"), ({'Type': 'active', 'SSIDs': ['foo']}, "InvalidArgs"), ({'Type': 'active', - 'SSIDs': [ dbus.ByteArray("1"), dbus.ByteArray("2"), - dbus.ByteArray("3"), dbus.ByteArray("4"), - dbus.ByteArray("5"), dbus.ByteArray("6"), - dbus.ByteArray("7"), dbus.ByteArray("8"), - dbus.ByteArray("9"), dbus.ByteArray("10"), - dbus.ByteArray("11"), dbus.ByteArray("12"), - dbus.ByteArray("13"), dbus.ByteArray("14"), - dbus.ByteArray("15"), dbus.ByteArray("16"), - dbus.ByteArray("17") ]}, + 'SSIDs': [ dbus.ByteArray(b"1"), dbus.ByteArray(b"2"), + dbus.ByteArray(b"3"), dbus.ByteArray(b"4"), + dbus.ByteArray(b"5"), dbus.ByteArray(b"6"), + dbus.ByteArray(b"7"), dbus.ByteArray(b"8"), + dbus.ByteArray(b"9"), dbus.ByteArray(b"10"), + dbus.ByteArray(b"11"), dbus.ByteArray(b"12"), + dbus.ByteArray(b"13"), dbus.ByteArray(b"14"), + dbus.ByteArray(b"15"), dbus.ByteArray(b"16"), + dbus.ByteArray(b"17") ]}, "InvalidArgs"), ({'Type': 'active', - 'SSIDs': [ dbus.ByteArray("1234567890abcdef1234567890abcdef1") ]}, + 'SSIDs': [ dbus.ByteArray(b"1234567890abcdef1234567890abcdef1") ]}, "InvalidArgs"), ({'Type': 'active', 'IEs': 'foo'}, "InvalidArgs"), ({'Type': 'active', 'IEs': ['foo']}, "InvalidArgs"), @@ -1023,9 +1023,9 @@ def test_dbus_scan_invalid(dev, apdev): 'Channels': [ (dbus.UInt32(2412), dbus.Int32(20)) ] }, "InvalidArgs"), ({'Type': 'active', 'AllowRoam': "yes" }, "InvalidArgs"), - ({'Type': 'passive', 'IEs': [ dbus.ByteArray("\xdd\x00") ]}, + ({'Type': 'passive', 'IEs': [ dbus.ByteArray(b"\xdd\x00") ]}, "InvalidArgs"), - ({'Type': 'passive', 'SSIDs': [ dbus.ByteArray("foo") ]}, + ({'Type': 'passive', 'SSIDs': [ dbus.ByteArray(b"foo") ]}, "InvalidArgs")] for (t,err) in tests: try: @@ -1056,14 +1056,14 @@ def test_dbus_scan_oom(dev, apdev): "=wpas_dbus_get_scan_ies;wpas_dbus_handler_scan", "Scan"): iface.Scan({ 'Type': 'active', - 'IEs': [ dbus.ByteArray("\xdd\x00") ], + 'IEs': [ dbus.ByteArray(b"\xdd\x00") ], 'Channels': [ (dbus.UInt32(2412), dbus.UInt32(20)) ] }) with alloc_fail_dbus(dev[0], 1, "=wpas_dbus_get_scan_ssids;wpas_dbus_handler_scan", "Scan"): iface.Scan({ 'Type': 'active', - 'SSIDs': [ dbus.ByteArray("open"), + 'SSIDs': [ dbus.ByteArray(b"open"), dbus.ByteArray() ], 'Channels': [ (dbus.UInt32(2412), dbus.UInt32(20)) ] }) @@ -1120,9 +1120,9 @@ def test_dbus_scan(dev, apdev): def run_scan(self, *args): logger.debug("run_scan") iface.Scan({'Type': 'active', - 'SSIDs': [ dbus.ByteArray("open"), + 'SSIDs': [ dbus.ByteArray(b"open"), dbus.ByteArray() ], - 'IEs': [ dbus.ByteArray("\xdd\x00"), + 'IEs': [ dbus.ByteArray(b"\xdd\x00"), dbus.ByteArray() ], 'AllowRoam': False, 'Channels': [(dbus.UInt32(2412), dbus.UInt32(20))]}) @@ -1793,7 +1793,7 @@ def test_dbus_network_oom(dev, apdev): tests = [ (1, 'wpa_dbus_dict_get_entry;set_network_properties;wpas_dbus_handler_add_network', - dbus.Dictionary({ 'ssid': dbus.ByteArray(' ') }, + dbus.Dictionary({ 'ssid': dbus.ByteArray(b' ') }, signature='sv')), (1, '=set_network_properties;wpas_dbus_handler_add_network', dbus.Dictionary({ 'ssid': 'foo' }, signature='sv')), @@ -1806,7 +1806,7 @@ def test_dbus_network_oom(dev, apdev): dbus.Dictionary({ 'priority': dbus.Int32(1) }, signature='sv')), (1, '=set_network_properties;wpas_dbus_handler_add_network', - dbus.Dictionary({ 'ssid': dbus.ByteArray(' ') }, + dbus.Dictionary({ 'ssid': dbus.ByteArray(b' ') }, signature='sv')) ] for (count,funcs,args) in tests: with alloc_fail_dbus(dev[0], count, funcs, "AddNetwork", "InvalidArgs"): @@ -1934,10 +1934,10 @@ def test_dbus_blob(dev, apdev): (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0]) iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE) - blob = dbus.ByteArray("\x01\x02\x03") + blob = dbus.ByteArray(b"\x01\x02\x03") iface.AddBlob('blob1', blob) try: - iface.AddBlob('blob1', dbus.ByteArray("\x01\x02\x04")) + iface.AddBlob('blob1', dbus.ByteArray(b"\x01\x02\x04")) raise Exception("Invalid AddBlob() accepted") except dbus.exceptions.DBusException as e: if "BlobExists" not in str(e): @@ -1993,7 +1993,7 @@ def test_dbus_blob(dev, apdev): def run_blob(self, *args): logger.debug("run_blob") - iface.AddBlob('blob2', dbus.ByteArray("\x01\x02\x04")) + iface.AddBlob('blob2', dbus.ByteArray(b"\x01\x02\x04")) iface.RemoveBlob('blob2') return False @@ -2012,7 +2012,7 @@ def test_dbus_blob_oom(dev, apdev): for i in range(1, 4): with alloc_fail_dbus(dev[0], i, "wpas_dbus_handler_add_blob", "AddBlob"): - iface.AddBlob('blob_no_mem', dbus.ByteArray("\x01\x02\x03\x04")) + iface.AddBlob('blob_no_mem', dbus.ByteArray(b"\x01\x02\x03\x04")) def test_dbus_autoscan(dev, apdev): """D-Bus Autoscan()""" @@ -2704,8 +2704,8 @@ def test_dbus_p2p_invalid(dev, apdev): {'RequestedDeviceTypes': dbus.Array([], signature="s")}, {'RequestedDeviceTypes': dbus.Array([['foo']], signature="as")}, {'RequestedDeviceTypes': dbus.Array([], signature="i")}, - {'RequestedDeviceTypes': [dbus.ByteArray('12345678'), - dbus.ByteArray('1234567')]}, + {'RequestedDeviceTypes': [dbus.ByteArray(b'12345678'), + dbus.ByteArray(b'1234567')]}, {'Foo': dbus.Int16(1)}, {'Foo': dbus.UInt16(1)}, {'Foo': dbus.Int64(1)}, @@ -2904,29 +2904,29 @@ def test_dbus_p2p_oom(dev, apdev): with alloc_fail_dbus(dev[0], 1, ":=_wpa_dbus_dict_entry_get_binarray", "Find", "InvalidArgs"): - p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123') ] })) + p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray(b'123') ] })) with alloc_fail_dbus(dev[0], 1, "_wpa_dbus_dict_entry_get_byte_array;_wpa_dbus_dict_entry_get_binarray", "Find", "InvalidArgs"): - p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123') ] })) + p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray(b'123') ] })) with alloc_fail_dbus(dev[0], 2, "=_wpa_dbus_dict_entry_get_binarray", "Find", "InvalidArgs"): - p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123'), - dbus.ByteArray('123') ] })) + p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123'), + dbus.ByteArray(b'123') ] })) with alloc_fail_dbus(dev[0], 1, "wpabuf_alloc_ext_data;_wpa_dbus_dict_entry_get_binarray", "Find", "InvalidArgs"): - p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123') ] })) + p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray(b'123') ] })) with alloc_fail_dbus(dev[0], 1, "_wpa_dbus_dict_fill_value_from_variant;wpas_dbus_handler_p2p_find", "Find", "InvalidArgs"): @@ -2935,7 +2935,7 @@ def test_dbus_p2p_oom(dev, apdev): with alloc_fail_dbus(dev[0], 1, "_wpa_dbus_dict_entry_get_byte_array", "AddService", "InvalidArgs"): args = { 'service_type': 'bonjour', - 'response': dbus.ByteArray(500*'b') } + 'response': dbus.ByteArray(500*b'b') } p2p.AddService(args) with alloc_fail_dbus(dev[0], 2, "_wpa_dbus_dict_entry_get_byte_array", @@ -2978,7 +2978,7 @@ def run_dbus_p2p_discovery(dev, apdev): raise Exception("Unexpected peer(s) in the list") args = {'DiscoveryType': 'social', - 'RequestedDeviceTypes': [dbus.ByteArray('12345678')], + 'RequestedDeviceTypes': [dbus.ByteArray(b'12345678')], 'Timeout': dbus.Int32(1) } p2p.Find(dbus.Dictionary(args)) p2p.StopFind() @@ -3029,7 +3029,7 @@ def run_dbus_p2p_discovery(dev, apdev): sec = res['SecondaryDeviceTypes'] if len(sec) < 1: raise Exception("Secondary device type missing") - if "\x00\x01\x00\x50\xF2\x04\x00\x02" not in sec: + if b"\x00\x01\x00\x50\xF2\x04\x00\x02" not in sec: raise Exception("Secondary device type mismatch") if 'VendorExtension' not in res: @@ -3037,7 +3037,7 @@ def run_dbus_p2p_discovery(dev, apdev): vendor = res['VendorExtension'] if len(vendor) < 1: raise Exception("Vendor extension missing") - if "\x11\x22\x33\x44" not in vendor: + if b"\x11\x22\x33\x44" not in vendor: raise Exception("Secondary device type mismatch") if 'VSIE' not in res: @@ -3045,7 +3045,7 @@ def run_dbus_p2p_discovery(dev, apdev): vendor = res['VSIE'] if len(vendor) < 1: raise Exception("VSIE missing") - if vendor != "\xdd\x06\x00\x11\x22\x33\x55\x66": + if vendor != b"\xdd\x06\x00\x11\x22\x33\x55\x66": raise Exception("VSIE mismatch") self.found = True @@ -3250,7 +3250,7 @@ def test_dbus_p2p_service_discovery(dev, apdev): { 'service_type': 'bonjour', 'response': 'foo' }, { 'service_type': 'bonjour', 'query': bonjour_query }, { 'service_type': 'bonjour', 'response': bonjour_response }, - { 'service_type': 'bonjour', 'query': dbus.ByteArray(500*'a') }, + { 'service_type': 'bonjour', 'query': dbus.ByteArray(500*b'a') }, { 'service_type': 'bonjour', 'foo': 'bar' } ] for args in tests: try: @@ -3260,7 +3260,7 @@ def test_dbus_p2p_service_discovery(dev, apdev): if "InvalidArgs" not in str(e): raise Exception("Unexpected error message for invalid AddService(): " + str(e)) - args = { 'tlv': dbus.ByteArray("\x02\x00\x00\x01") } + args = { 'tlv': dbus.ByteArray(b"\x02\x00\x00\x01") } ref = p2p.ServiceDiscoveryRequest(args) p2p.ServiceDiscoveryCancelRequest(ref) try: @@ -3348,7 +3348,7 @@ def test_dbus_p2p_service_discovery_query(dev, apdev): def deviceFound(self, path): logger.debug("deviceFound: path=%s" % path) args = { 'peer_object': path, - 'tlv': dbus.ByteArray("\x02\x00\x00\x01") } + 'tlv': dbus.ByteArray(b"\x02\x00\x00\x01") } p2p.ServiceDiscoveryRequest(args) def serviceDiscoveryResponse(self, sd_request): @@ -3598,7 +3598,7 @@ def test_dbus_p2p_autogo(dev, apdev): self.exceptions = True raise Exception("Unexpected number of group members") - ext = dbus.ByteArray("\x11\x22\x33\x44") + ext = dbus.ByteArray(b"\x11\x22\x33\x44") # Earlier implementation of this interface was a bit strange. The # property is defined to have aay signature and that is what the # getter returned. However, the setter expected there to be a @@ -3621,7 +3621,7 @@ def test_dbus_p2p_autogo(dev, apdev): # And now verify that the more appropriate encoding is accepted as # well. - res.append(dbus.ByteArray('\xaa\xbb\xcc\xdd\xee\xff')) + res.append(dbus.ByteArray(b'\xaa\xbb\xcc\xdd\xee\xff')) g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', res, dbus_interface=dbus.PROPERTIES_IFACE) res2 = g_obj.Get(WPAS_DBUS_GROUP, 'WPSVendorExtensions', @@ -3635,7 +3635,7 @@ def test_dbus_p2p_autogo(dev, apdev): raise Exception("Vendor extension value changed") for i in range(10): - res.append(dbus.ByteArray('\xaa\xbb')) + res.append(dbus.ByteArray(b'\xaa\xbb')) try: g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', res, dbus_interface=dbus.PROPERTIES_IFACE) @@ -3947,7 +3947,7 @@ def test_dbus_p2p_join(dev, apdev): byte_arrays=True) logger.debug("Group properties: " + str(res)) - ext = dbus.ByteArray("\x11\x22\x33\x44") + ext = dbus.ByteArray(b"\x11\x22\x33\x44") try: # Set(WPSVendorExtensions) not allowed for P2P Client g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', res, @@ -4068,8 +4068,8 @@ def _test_dbus_p2p_config(dev, apdev): raise Exception("Parameter %s value changes" % k) changes = { 'SsidPostfix': 'foo', - 'VendorExtension': [ dbus.ByteArray('\x11\x22\x33\x44') ], - 'SecondaryDeviceTypes': [ dbus.ByteArray('\x11\x22\x33\x44\x55\x66\x77\x88') ]} + 'VendorExtension': [ dbus.ByteArray(b'\x11\x22\x33\x44') ], + 'SecondaryDeviceTypes': [ dbus.ByteArray(b'\x11\x22\x33\x44\x55\x66\x77\x88') ]} if_obj.Set(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig", dbus.Dictionary(changes, signature='sv'), dbus_interface=dbus.PROPERTIES_IFACE) @@ -5554,7 +5554,7 @@ def _test_dbus_vendor_elem(dev, apdev): dev[0].request("VENDOR_ELEM_REMOVE 1 *") try: - ie = dbus.ByteArray("\x00\x00") + ie = dbus.ByteArray(b"\x00\x00") iface.VendorElemAdd(-1, ie) raise Exception("Invalid VendorElemAdd() accepted") except dbus.exceptions.DBusException as e: @@ -5562,7 +5562,7 @@ def _test_dbus_vendor_elem(dev, apdev): raise Exception("Unexpected error message for invalid VendorElemAdd[1]: " + str(e)) try: - ie = dbus.ByteArray("") + ie = dbus.ByteArray(b'') iface.VendorElemAdd(1, ie) raise Exception("Invalid VendorElemAdd() accepted") except dbus.exceptions.DBusException as e: @@ -5570,7 +5570,7 @@ def _test_dbus_vendor_elem(dev, apdev): raise Exception("Unexpected error message for invalid VendorElemAdd[2]: " + str(e)) try: - ie = dbus.ByteArray("\x00\x01") + ie = dbus.ByteArray(b"\x00\x01") iface.VendorElemAdd(1, ie) raise Exception("Invalid VendorElemAdd() accepted") except dbus.exceptions.DBusException as e: @@ -5592,7 +5592,7 @@ def _test_dbus_vendor_elem(dev, apdev): raise Exception("Unexpected error message for invalid VendorElemGet[2]: " + str(e)) try: - ie = dbus.ByteArray("\x00\x00") + ie = dbus.ByteArray(b"\x00\x00") iface.VendorElemRem(-1, ie) raise Exception("Invalid VendorElemRemove() accepted") except dbus.exceptions.DBusException as e: @@ -5600,16 +5600,16 @@ def _test_dbus_vendor_elem(dev, apdev): raise Exception("Unexpected error message for invalid VendorElemRemove[1]: " + str(e)) try: - ie = dbus.ByteArray("") + ie = dbus.ByteArray(b'') iface.VendorElemRem(1, ie) raise Exception("Invalid VendorElemRemove() accepted") except dbus.exceptions.DBusException as e: if "InvalidArgs" not in str(e) or "Invalid value" not in str(e): raise Exception("Unexpected error message for invalid VendorElemRemove[1]: " + str(e)) - iface.VendorElemRem(1, "*") + iface.VendorElemRem(1, b"*") - ie = dbus.ByteArray("\x00\x01\x00") + ie = dbus.ByteArray(b"\x00\x01\x00") iface.VendorElemAdd(1, ie) val = iface.VendorElemGet(1) @@ -5619,7 +5619,7 @@ def _test_dbus_vendor_elem(dev, apdev): if val[i] != dbus.Byte(ie[i]): raise Exception("Unexpected VendorElemGet data") - ie2 = dbus.ByteArray("\xe0\x00") + ie2 = dbus.ByteArray(b"\xe0\x00") iface.VendorElemAdd(1, ie2) ies = ie + ie2 @@ -5631,7 +5631,7 @@ def _test_dbus_vendor_elem(dev, apdev): raise Exception("Unexpected VendorElemGet data[2]") try: - test_ie = dbus.ByteArray("\x01\x01") + test_ie = dbus.ByteArray(b"\x01\x01") iface.VendorElemRem(1, test_ie) raise Exception("Invalid VendorElemRemove() accepted") except dbus.exceptions.DBusException as e: @@ -5643,7 +5643,7 @@ def _test_dbus_vendor_elem(dev, apdev): if len(val) != len(ie2): raise Exception("Unexpected VendorElemGet length[3]") - iface.VendorElemRem(1, "*") + iface.VendorElemRem(1, b"*") try: iface.VendorElemGet(1) raise Exception("Invalid VendorElemGet() accepted after removal") @@ -5754,7 +5754,7 @@ def test_dbus_mesh(dev, apdev): dbus_interface=dbus.PROPERTIES_IFACE, byte_arrays=True) logger.debug("MeshGroup: " + str(res)) - if res != "wpas-mesh-open": + if res != b"wpas-mesh-open": raise Exception("Unexpected MeshGroup") dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1') dev1.mesh_group_remove() diff --git a/tests/hwsim/test_dpp.py b/tests/hwsim/test_dpp.py index aa3a13a19..0443c3b42 100644 --- a/tests/hwsim/test_dpp.py +++ b/tests/hwsim/test_dpp.py @@ -57,7 +57,7 @@ def test_dpp_qr_code_parsing(dev, apdev): "DPP:;;", "DPP:C:1/2;M:;K;;", "DPP:I:;M:01020304050;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;", - "DPP:K:" + base64.b64encode("hello") + ";;", + "DPP:K:" + base64.b64encode(b"hello") + ";;", "DPP:K:MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEXiJuIWt1Q/CPCkuULechh37UsXPmbUANOeN5U9sOQROE4o/NEFeFEejROHYwwehF;;", "DPP:K:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANNZaZA4T/kRDjnmpI1ACOJhAuTIIEk2KFOpS6XPpGF+EVr/ao3XemkE0/nzXmGaLzLqTUCJknSdxTnVPeWfCVsCAwEAAQ==;;", "DPP:K:MIIBCjCB0wYHKoZIzj0CATCBxwIBATAkBgcqhkjOPQEBAhkA/////////////////////v//////////MEsEGP////////////////////7//////////AQYZCEFGeWcgOcPp+mrciQwSf643uzBRrmxAxUAMEWub8hCL2TtV5Uo04Eg6uEhltUEMQQYjagOsDCQ9ny/IOtDoYgA9P8K/YL/EBIHGSuV/8jaeGMQEe1rJM3Vc/l3oR55SBECGQD///////////////+Z3vg2FGvJsbTSKDECAQEDMgAEXiJuIWt1Q/CPCkuULechh37UsXPmbUANOeN5U9sOQROE4o/NEFeFEejROHYwwehF;;", diff --git a/tests/hwsim/test_eap_proto.py b/tests/hwsim/test_eap_proto.py index c07694f49..018211dcf 100644 --- a/tests/hwsim/test_eap_proto.py +++ b/tests/hwsim/test_eap_proto.py @@ -8306,8 +8306,8 @@ def test_eap_fast_proto_phase2(dev, apdev): struct.pack(">HHB", EAP_TLV_INTERMEDIATE_RESULT_TLV, 1, 0xff), True), ("EAP-FAST: More than one Crypto-Binding TLV in the message", - struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A' + - struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A', + struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*b'A' + + struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*b'A', True), ("EAP-FAST: Too short Crypto-Binding TLV", struct.pack(">HHB", EAP_TLV_CRYPTO_BINDING_TLV, 1, 0xff), @@ -8364,7 +8364,7 @@ def test_eap_fast_proto_phase2(dev, apdev): struct.pack(">HHHHHHHH", EAP_TLV_PAC_TLV, 4 + 4 + 4 + 32, PAC_TYPE_PAC_OPAQUE, 0, PAC_TYPE_PAC_INFO, 0, - PAC_TYPE_PAC_KEY, 32) + 32*'A', + PAC_TYPE_PAC_KEY, 32) + 32*b'A', True), ("EAP-FAST: Invalid CRED_LIFETIME length, Ignored unknown PAC-Info type 0, and Invalid PAC-Type length 1", struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2, @@ -8373,7 +8373,7 @@ def test_eap_fast_proto_phase2(dev, apdev): PAC_TYPE_PAC_OPAQUE, 0, PAC_TYPE_PAC_INFO, 13, PAC_TYPE_CRED_LIFETIME, 0, 0, 0, PAC_TYPE_PAC_TYPE, 1, 0, - PAC_TYPE_PAC_KEY, 32) + 32*'A', + PAC_TYPE_PAC_KEY, 32) + 32*b'A', True), ("EAP-FAST: Unsupported PAC-Type 0", struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2, @@ -8381,7 +8381,7 @@ def test_eap_fast_proto_phase2(dev, apdev): struct.pack(">HHHHHHHHHHH", EAP_TLV_PAC_TLV, 4 + 4 + 6 + 4 + 32, PAC_TYPE_PAC_OPAQUE, 0, PAC_TYPE_PAC_INFO, 6, PAC_TYPE_PAC_TYPE, 2, 0, - PAC_TYPE_PAC_KEY, 32) + 32*'A', + PAC_TYPE_PAC_KEY, 32) + 32*b'A', True), ("EAP-FAST: PAC-Info overrun (type=0 len=2 left=1)", struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2, @@ -8389,7 +8389,7 @@ def test_eap_fast_proto_phase2(dev, apdev): struct.pack(">HHHHHHHHBHH", EAP_TLV_PAC_TLV, 4 + 4 + 5 + 4 + 32, PAC_TYPE_PAC_OPAQUE, 0, PAC_TYPE_PAC_INFO, 5, 0, 2, 1, - PAC_TYPE_PAC_KEY, 32) + 32*'A', + PAC_TYPE_PAC_KEY, 32) + 32*b'A', True), ("EAP-FAST: Valid PAC", struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2, @@ -8399,10 +8399,10 @@ def test_eap_fast_proto_phase2(dev, apdev): PAC_TYPE_PAC_OPAQUE, 0, PAC_TYPE_PAC_INFO, 10, PAC_TYPE_A_ID, 1, 0x41, PAC_TYPE_A_ID_INFO, 1, 0x42, - PAC_TYPE_PAC_KEY, 32) + 32*'A', + PAC_TYPE_PAC_KEY, 32) + 32*b'A', True), ("EAP-FAST: Invalid version/subtype in Crypto-Binding TLV", - struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A', + struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*b'A', True) ] for title, payload, failure in tests: logger.info("Phase 2 test: " + title) diff --git a/tests/hwsim/test_fils.py b/tests/hwsim/test_fils.py index c3de79be8..5d4d48621 100644 --- a/tests/hwsim/test_fils.py +++ b/tests/hwsim/test_fils.py @@ -665,15 +665,15 @@ def build_dhcp(req, dhcp_msg, chaddr, giaddr="0.0.0.0", ip_src="0.0.0.0", ip_dst="255.255.255.255", rapid_commit=True, override_op=None, magic_override=None, opt_end=True, extra_op=None): - proto = '\x08\x00' # IPv4 + proto = b'\x08\x00' # IPv4 _ip_src = socket.inet_pton(socket.AF_INET, ip_src) _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst) - _ciaddr = '\x00\x00\x00\x00' - _yiaddr = '\x00\x00\x00\x00' - _siaddr = '\x00\x00\x00\x00' + _ciaddr = b'\x00\x00\x00\x00' + _yiaddr = b'\x00\x00\x00\x00' + _siaddr = b'\x00\x00\x00\x00' _giaddr = socket.inet_pton(socket.AF_INET, giaddr) - _chaddr = binascii.unhexlify(chaddr.replace(':','')) + 10*'\x00' + _chaddr = binascii.unhexlify(chaddr.replace(':','')) + 10 * b'\x00' htype = 1 # Hardware address type; 1 = Ethernet hlen = 6 # Hardware address length hops = 0 @@ -691,14 +691,14 @@ def build_dhcp(req, dhcp_msg, chaddr, giaddr="0.0.0.0", if override_op is not None: op = override_op payload = struct.pack('>BBBBLHH', op, htype, hlen, hops, xid, secs, flags) - sname = 64*'\x00' - file = 128*'\x00' + sname = 64*b'\x00' + file = 128*b'\x00' payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + sname + file # magic - DHCP if magic_override is not None: payload += magic_override else: - payload += '\x63\x82\x53\x63' + payload += b'\x63\x82\x53\x63' # Option: DHCP Message Type if dhcp_msg is not None: payload += struct.pack('BBB', OPT_DHCP_MESSAGE_TYPE, 1, dhcp_msg) @@ -716,7 +716,7 @@ def build_dhcp(req, dhcp_msg, chaddr, giaddr="0.0.0.0", tot_len = 20 + len(udp) start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) ipv4 = start + csum + _ip_src + _ip_dst @@ -817,7 +817,7 @@ def run_fils_sk_hlp(dev, apdev, rapid_commit_server, params): raise Exception("Unexpected ethertype in HLP response: %d" % proto) frame = frame[2:] ip = frame[0:20] - if ip_checksum(ip) != '\x00\x00': + if ip_checksum(ip) != b'\x00\x00': raise Exception("IP header checksum mismatch in HLP response") frame = frame[20:] udp = frame[0:8] @@ -835,7 +835,7 @@ def run_fils_sk_hlp(dev, apdev, rapid_commit_server, params): file = frame[0:128] frame = frame[128:] options = frame - if options[0:4] != '\x63\x82\x53\x63': + if options[0:4] != b'\x63\x82\x53\x63': raise Exception("No DHCP magic seen in HLP response") options = options[4:] # TODO: fully parse and validate DHCPACK options @@ -999,21 +999,21 @@ def test_fils_sk_hlp_req_parsing(dev, apdev, params): tot_len = 20 + 1 start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - _ip_src = '\x00\x00\x00\x00' - _ip_dst = '\x00\x00\x00\x00' - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + _ip_src = b'\x00\x00\x00\x00' + _ip_dst = b'\x00\x00\x00\x00' + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) ipv4_overflow = start + csum + _ip_src + _ip_dst tot_len = 20 start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 123) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) ipv4_unknown_proto = start + csum + _ip_src + _ip_dst tot_len = 20 start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) ipv4_missing_udp_hdr = start + csum + _ip_src + _ip_dst @@ -1022,14 +1022,14 @@ def test_fils_sk_hlp_req_parsing(dev, apdev, params): udp = struct.pack('>HHHH', src_port, dst_port, 8 + 1, 0) tot_len = 20 + len(udp) start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) udp_overflow = start + csum + _ip_src + _ip_dst + udp udp = struct.pack('>HHHH', src_port, dst_port, 7, 0) tot_len = 20 + len(udp) start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) udp_underflow = start + csum + _ip_src + _ip_dst + udp @@ -1038,7 +1038,7 @@ def test_fils_sk_hlp_req_parsing(dev, apdev, params): udp = struct.pack('>HHHH', src_port, dst_port, 8, 0) tot_len = 20 + len(udp) start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) udp_unknown_port = start + csum + _ip_src + _ip_dst + udp @@ -1047,24 +1047,24 @@ def test_fils_sk_hlp_req_parsing(dev, apdev, params): udp = struct.pack('>HHHH', src_port, dst_port, 8, 0) tot_len = 20 + len(udp) start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) dhcp_missing_data = start + csum + _ip_src + _ip_dst + udp dhcp_not_req = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER, chaddr=dev[0].own_addr(), override_op=BOOTREPLY) dhcp_no_magic = build_dhcp(req=True, dhcp_msg=None, - chaddr=dev[0].own_addr(), magic_override='', + chaddr=dev[0].own_addr(), magic_override=b'', rapid_commit=False, opt_end=False) dhcp_unknown_magic = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER, chaddr=dev[0].own_addr(), - magic_override='\x00\x00\x00\x00') + magic_override=b'\x00\x00\x00\x00') dhcp_opts = build_dhcp(req=True, dhcp_msg=DHCPNAK, chaddr=dev[0].own_addr(), - extra_op='\x00\x11', opt_end=False) + extra_op=b'\x00\x11', opt_end=False) dhcp_opts2 = build_dhcp(req=True, dhcp_msg=DHCPNAK, chaddr=dev[0].own_addr(), - extra_op='\x11\x01', opt_end=False) + extra_op=b'\x11\x01', opt_end=False) dhcp_valid = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER, chaddr=dev[0].own_addr()) @@ -1197,16 +1197,16 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): dhcpdisc = build_dhcp(req=False, dhcp_msg=DHCPACK, chaddr=dev[0].own_addr(), giaddr="127.0.0.3") #sock.sendto(dhcpdisc[2+20+8:], addr) - chaddr = binascii.unhexlify(dev[0].own_addr().replace(':','')) + 10*'\x00' - tests = [ "\x00", - "\x02" + 500 * "\x00", - "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 500 * "\x00", - "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 16*"\x00" + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63", - "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 16*"\x00" + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x00\x11", - "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 16*"\x00" + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x11\x01", - "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + chaddr + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x35\x00\xff", - "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + chaddr + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x35\x01\x00\xff", - 1501 * "\x00" ] + chaddr = binascii.unhexlify(dev[0].own_addr().replace(':','')) + 10*b'\x00' + tests = [ b"\x00", + b"\x02" + 500 * b"\x00", + b"\x02\x00\x00\x00" + 20*b"\x00" + b"\x7f\x00\x00\x03" + 500*b"\x00", + b"\x02\x00\x00\x00" + 20*b"\x00" + b"\x7f\x00\x00\x03" + 16*b"\x00" + 64*b"\x00" + 128*b"\x00" + b"\x63\x82\x53\x63", + b"\x02\x00\x00\x00" + 20*b"\x00" + b"\x7f\x00\x00\x03" + 16*b"\x00" + 64*b"\x00" + 128*b"\x00" + b"\x63\x82\x53\x63" + b"\x00\x11", + b"\x02\x00\x00\x00" + 20*b"\x00" + b"\x7f\x00\x00\x03" + 16*b"\x00" + 64*b"\x00" + 128*b"\x00" + b"\x63\x82\x53\x63" + b"\x11\x01", + b"\x02\x00\x00\x00" + 20*b"\x00" + b"\x7f\x00\x00\x03" + chaddr + 64*b"\x00" + 128*b"\x00" + b"\x63\x82\x53\x63" + b"\x35\x00\xff", + b"\x02\x00\x00\x00" + 20*b"\x00" + b"\x7f\x00\x00\x03" + chaddr + 64*b"\x00" + 128*b"\x00" + b"\x63\x82\x53\x63" + b"\x35\x01\x00\xff", + 1501 * b"\x00" ] for t in tests: sock.sendto(t, addr) dev[0].wait_connected() @@ -1234,7 +1234,7 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): logger.debug("Received DHCP message from %s" % str(addr)) dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False, chaddr=dev[0].own_addr(), giaddr="127.0.0.3", - extra_op="\x00\x11", opt_end=False) + extra_op=b"\x00\x11", opt_end=False) sock.sendto(dhcpoffer[2+20+8:], addr) (msg,addr) = sock.recvfrom(1000) logger.debug("Received DHCP message from %s" % str(addr)) @@ -1249,7 +1249,7 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): logger.debug("Received DHCP message from %s" % str(addr)) dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False, chaddr=dev[0].own_addr(), giaddr="127.0.0.3", - extra_op="\x11\x01", opt_end=False) + extra_op=b"\x11\x01", opt_end=False) sock.sendto(dhcpoffer[2+20+8:], addr) (msg,addr) = sock.recvfrom(1000) logger.debug("Received DHCP message from %s" % str(addr)) @@ -1264,7 +1264,7 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): logger.debug("Received DHCP message from %s" % str(addr)) dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False, chaddr=dev[0].own_addr(), giaddr="127.0.0.3", - extra_op="\x36\x01\x30") + extra_op=b"\x36\x01\x30") sock.sendto(dhcpoffer[2+20+8:], addr) (msg,addr) = sock.recvfrom(1000) logger.debug("Received DHCP message from %s" % str(addr)) @@ -1276,7 +1276,7 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): dev[0].request("FILS_HLP_REQ_FLUSH") dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER, chaddr=dev[0].own_addr(), - extra_op="\x00\x11", opt_end=False) + extra_op=b"\x00\x11", opt_end=False) if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc).decode()): raise Exception("FILS_HLP_REQ_ADD failed") dev[0].dump_monitor() @@ -1285,7 +1285,7 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): logger.debug("Received DHCP message from %s" % str(addr)) dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False, chaddr=dev[0].own_addr(), giaddr="127.0.0.3", - extra_op="\x36\x01\x30") + extra_op=b"\x36\x01\x30") sock.sendto(dhcpoffer[2+20+8:], addr) dev[0].wait_connected() dev[0].request("DISCONNECT") @@ -1295,7 +1295,7 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): dev[0].request("FILS_HLP_REQ_FLUSH") dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER, chaddr=dev[0].own_addr(), - extra_op="\x11\x01", opt_end=False) + extra_op=b"\x11\x01", opt_end=False) if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc).decode()): raise Exception("FILS_HLP_REQ_ADD failed") dev[0].dump_monitor() @@ -1304,7 +1304,7 @@ def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params): logger.debug("Received DHCP message from %s" % str(addr)) dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False, chaddr=dev[0].own_addr(), giaddr="127.0.0.3", - extra_op="\x36\x01\x30") + extra_op=b"\x36\x01\x30") sock.sendto(dhcpoffer[2+20+8:], addr) dev[0].wait_connected() dev[0].request("DISCONNECT") diff --git a/tests/hwsim/test_gas.py b/tests/hwsim/test_gas.py index 21a02dfe3..ae8aa7552 100644 --- a/tests/hwsim/test_gas.py +++ b/tests/hwsim/test_gas.py @@ -1606,8 +1606,8 @@ def test_gas_anqp_venue_url(dev, apdev): venue2 = struct.pack('B', len(lang2 + name2)) + lang2.encode() + name2.encode() venue_name = binascii.hexlify(venue_info + venue1 + venue2).decode() - url1 = "http://example.com/venue" - url2 = "https://example.org/venue-info/" + url1 = b"http://example.com/venue" + url2 = b"https://example.org/venue-info/" duple1 = struct.pack('BB', 1 + len(url1), 1) + url1 duple2 = struct.pack('BB', 1 + len(url2), 2) + url2 venue_url = binascii.hexlify(duple1 + duple2).decode() diff --git a/tests/hwsim/test_kernel.py b/tests/hwsim/test_kernel.py index de81ac06b..0427b73bc 100644 --- a/tests/hwsim/test_kernel.py +++ b/tests/hwsim/test_kernel.py @@ -34,7 +34,7 @@ def _test_kernel_bss_leak(dev, apdev, deauth): 'sa': pkt['da'], 'da': pkt['sa'], 'bssid': pkt['bssid'], - 'payload': '\x01\x00', + 'payload': b'\x01\x00', }) break else: diff --git a/tests/hwsim/test_p2p_messages.py b/tests/hwsim/test_p2p_messages.py index c8fea1eab..943fdd514 100644 --- a/tests/hwsim/test_p2p_messages.py +++ b/tests/hwsim/test_p2p_messages.py @@ -411,7 +411,7 @@ def test_p2p_msg_invitation_req(dev, apdev): # Invalid Device Name header length in Device Info attribute dialog_token += 1 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token) - devname = 'A' + devname = b'A' attrs = struct.pack("