res = ''
counter = 0
while outlen > 0:
- m = hmac.new(key, label, hashlib.sha1)
+ m = hmac.new(key, label.encode(), hashlib.sha1)
m.update(struct.pack('B', 0))
m.update(data)
m.update(struct.pack('B', counter))
'Connection: close\r\n' + \
'Content-Length: ' + str(len(payload)) + '\r\n' + \
'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n'
- return hdr + payload
+ return (hdr + payload).encode()
def gen_wps_control(payload_override=None):
payload = '''<?xml version="1.0"?>
'Connection: close\r\n' + \
'Content-Length: ' + str(len(payload)) + '\r\n' + \
'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n'
- return hdr + payload
+ return (hdr + payload).encode()
def gen_wps_event(sid='uuid:7eb3342a-8a5f-47fe-a585-0785bfec6d8a'):
payload = ""
hdr += 'SID: ' + sid + '\r\n'
hdr += 'Timeout: Second-1801\r\n' + \
'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n'
- return hdr + payload
+ return (hdr + payload).encode()
class WPSAPHTTPServer(StreamRequestHandler):
def handle(self):
'Content-Length: ' + str(len(payload)) + '\r\n' + \
'Timeout: Second-1801\r\n' + \
'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n'
- self.wfile.write(hdr + payload)
+ self.wfile.write((hdr + payload).encode())
run_wps_er_proto_test(dev[0], WPSAPHTTPServer_fail_subscribe)
def test_ap_wps_er_http_proto_subscribe_invalid_response(dev, apdev):
'Content-Length: ' + str(len(payload)) + '\r\n' + \
'Timeout: Second-1801\r\n' + \
'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n'
- self.wfile.write(hdr + payload)
+ self.wfile.write((hdr + payload).encode())
run_wps_er_proto_test(dev[0], WPSAPHTTPServer_subscribe_invalid_response)
def test_ap_wps_er_http_proto_subscribe_invalid_response(dev, apdev):
'Connection: close\r\n' + \
'Content-Length: ' + str(len(payload)) + '\r\n' + \
'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n'
- self.wfile.write(hdr + payload)
+ self.wfile.write((hdr + payload).encode())
run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_device, no_event_url=True)
def test_ap_wps_er_http_proto_upnp_info_no_device_type(dev, apdev):
'Connection: close\r\n' + \
'Content-Length: ' + str(len(payload)) + '\r\n' + \
'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n'
- self.wfile.write(hdr + payload)
+ self.wfile.write((hdr + payload).encode())
run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_device, no_event_url=True)
def test_ap_wps_er_http_proto_upnp_info_invalid_udn_uuid(dev, apdev):
result = ''
i = 1
while len(result) * 8 < bits:
- data = struct.pack('>L', i) + label + struct.pack('>L', bits)
+ data = struct.pack('>L', i) + label.encode() + struct.pack('>L', bits)
m = hmac.new(key, data, hashlib.sha256)
result += m.digest()
i += 1
return authkey,keywrapkey,emsk
def wsc_dev_pw_half_psk(authkey, dev_pw):
- m = hmac.new(authkey, dev_pw, hashlib.sha256)
+ m = hmac.new(authkey, dev_pw.encode(), hashlib.sha256)
return m.digest()[0:16]
def wsc_dev_pw_psk(authkey, dev_pw):
"wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nI-ID=1\nEND\n",
"wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nA-ID-Info=1\nEND\n" ]
for pac in tests:
- blob = binascii.hexlify(pac).decode()
+ blob = binascii.hexlify(pac.encode()).decode()
dev[0].request("SET blob fast_pac_errors " + blob)
dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
eap="FAST", anonymous_identity="FAST",
tests = [ "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nEND\n",
"wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nEND\nSTART\nEND\nSTART\nEND\n" ]
for pac in tests:
- blob = binascii.hexlify(pac).decode()
+ blob = binascii.hexlify(pac.encode()).decode()
dev[0].request("SET blob fast_pac_errors " + blob)
dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
eap="FAST", anonymous_identity="FAST",
expected = ''
count = 0
for realm in fils_realms:
- hash = hashlib.sha256(realm.lower()).digest()
+ hash = hashlib.sha256(realm.lower().encode()).digest()
expected += binascii.hexlify(hash[0:2]).decode()
count += 1
if count == 7:
info = bss['anqp_fils_realm_info']
expected = ''
for realm in fils_realms:
- hash = hashlib.sha256(realm.lower()).digest()
+ hash = hashlib.sha256(realm.lower().encode()).digest()
expected += binascii.hexlify(hash[0:2]).decode()
if info != expected:
raise Exception("Unexpected FILS Realm Info ANQP-element: " + info)
geo_loc = "001052834d12efd2b08b9b4bf1cc2c00004104050000000000060100"
civic_loc = "0000f9555302f50102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5"
held_uri = "https://held.example.com/location"
- held = struct.pack('BBB', 0, 1 + len(held_uri), 1) + held_uri
+ held = struct.pack('BBB', 0, 1 + len(held_uri), 1) + held_uri.encode()
supl_fqdn = "supl.example.com"
- supl = struct.pack('BBB', 0, 1 + len(supl_fqdn), 1) + supl_fqdn
+ supl = struct.pack('BBB', 0, 1 + len(supl_fqdn), 1) + supl_fqdn.encode()
public_id = binascii.hexlify(held + supl).decode()
params = { "ssid": "gas/anqp",
"interworking": "1",
name1= "Example venue"
lang2 = "fin"
name2 = "Esimerkkipaikka"
- venue1 = struct.pack('B', len(lang1 + name1)) + lang1 + name1
- venue2 = struct.pack('B', len(lang2 + name2)) + lang2 + name2
+ venue1 = struct.pack('B', len(lang1 + name1)) + lang1.encode() + name1.encode()
+ 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"
name1= "Example venue"
lang2 = "fin"
name2 = "Esimerkkipaikka"
- venue1 = struct.pack('B', len(lang1 + name1)) + lang1 + name1
- venue2 = struct.pack('B', len(lang2 + name2)) + lang2 + name2
+ venue1 = struct.pack('B', len(lang1 + name1)) + lang1.encode() + name1.encode()
+ 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/"
- duple1 = struct.pack('BB', 1 + len(url1), 1) + url1
- duple2 = struct.pack('BB', 1 + len(url2), 2) + url2
+ duple1 = struct.pack('BB', 1 + len(url1.encode()), 1) + url1.encode()
+ duple2 = struct.pack('BB', 1 + len(url2.encode()), 2) + url2.encode()
venue_url = binascii.hexlify(duple1 + duple2).decode()
params = { "ssid": "gas/anqp",
name1= "Example venue"
lang2 = "fin"
name2 = "Esimerkkipaikka"
- venue1 = struct.pack('B', len(lang1 + name1)) + lang1 + name1
- venue2 = struct.pack('B', len(lang2 + name2)) + lang2 + name2
+ venue1 = struct.pack('B', len(lang1 + name1)) + lang1.encode() + name1.encode()
+ venue2 = struct.pack('B', len(lang2 + name2)) + lang2.encode() + name2.encode()
venue_name = binascii.hexlify(venue_info + venue1 + venue2)
url1 = "http://example.com/venue"
from test_gas import anqp_adv_proto
def ie_ssid(ssid):
- return struct.pack("<BB", WLAN_EID_SSID, len(ssid)) + ssid
+ return struct.pack("<BB", WLAN_EID_SSID, len(ssid)) + ssid.encode()
def ie_supp_rates():
return struct.pack("<BBBBBBBBBB", WLAN_EID_SUPP_RATES, 8,
val2 = struct.unpack('8B', binascii.unhexlify(dev_type))
t = (P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 4 + len(name)) + val
t2 = val2 + (0,)
- return struct.pack("<BH6B", *t) + struct.pack(">H", config_methods) + struct.pack("8BB", *t2) + struct.pack('>HH', 0x1011, len(name)) +name
+ return struct.pack("<BH6B", *t) + struct.pack(">H", config_methods) + struct.pack("8BB", *t2) + struct.pack('>HH', 0x1011, len(name)) + name.encode()
def p2p_attr_group_id(addr, ssid):
val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
t = (P2P_ATTR_GROUP_ID, 6 + len(ssid)) + val
- return struct.pack('<BH6B', *t) + ssid
+ return struct.pack('<BH6B', *t) + ssid.encode()
def p2p_attr_operating_channel(op_class=81, chan=1):
return struct.pack("<BHBBBBB", P2P_ATTR_OPERATING_CHANNEL, 5,