test_suite_b.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Suite B tests
  2. # Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import time
  7. import logging
  8. logger = logging.getLogger()
  9. import hostapd
  10. from utils import HwsimSkip
  11. def test_suite_b(dev, apdev):
  12. """WPA2-PSK/GCMP connection at Suite B 128-bit level"""
  13. if "GCMP" not in dev[0].get_capability("pairwise"):
  14. raise HwsimSkip("GCMP not supported")
  15. if "BIP-GMAC-128" not in dev[0].get_capability("group_mgmt"):
  16. raise HwsimSkip("BIP-GMAC-128 not supported")
  17. if "WPA-EAP-SUITE-B" not in dev[0].get_capability("key_mgmt"):
  18. raise HwsimSkip("WPA-EAP-SUITE-B not supported")
  19. tls = dev[0].request("GET tls_library")
  20. if not tls.startswith("OpenSSL"):
  21. raise HwsimSkip("TLS library not supported for Suite B: " + tls);
  22. if "build=OpenSSL 1.0.2" not in tls or "run=OpenSSL 1.0.2" not in tls:
  23. raise HwsimSkip("OpenSSL version not supported for Suite B: " + tls)
  24. params = { "ssid": "test-suite-b",
  25. "wpa": "2",
  26. "wpa_key_mgmt": "WPA-EAP-SUITE-B",
  27. "rsn_pairwise": "GCMP",
  28. "group_mgmt_cipher": "BIP-GMAC-128",
  29. "ieee80211w": "2",
  30. "ieee8021x": "1",
  31. "openssl_ciphers": "SUITEB128",
  32. #"dh_file": "auth_serv/dh.conf",
  33. "eap_server": "1",
  34. "eap_user_file": "auth_serv/eap_user.conf",
  35. "ca_cert": "auth_serv/ec-ca.pem",
  36. "server_cert": "auth_serv/ec-server.pem",
  37. "private_key": "auth_serv/ec-server.key" }
  38. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  39. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B", ieee80211w="2",
  40. openssl_ciphers="SUITEB128",
  41. eap="TLS", identity="tls user",
  42. ca_cert="auth_serv/ec-ca.pem",
  43. client_cert="auth_serv/ec-user.pem",
  44. private_key="auth_serv/ec-user.key",
  45. pairwise="GCMP", group="GCMP", scan_freq="2412")
  46. tls_cipher = dev[0].get_status_field("EAP TLS cipher")
  47. if tls_cipher != "ECDHE-ECDSA-AES128-GCM-SHA256":
  48. raise Exception("Unexpected TLS cipher: " + tls_cipher)
  49. bss = dev[0].get_bss(apdev[0]['bssid'])
  50. if 'flags' not in bss:
  51. raise Exception("Could not get BSS flags from BSS table")
  52. if "[WPA2-EAP-SUITE-B-GCMP]" not in bss['flags']:
  53. raise Exception("Unexpected BSS flags: " + bss['flags'])
  54. dev[0].request("DISCONNECT")
  55. dev[0].wait_disconnected(timeout=20)
  56. dev[0].dump_monitor()
  57. dev[0].request("RECONNECT")
  58. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  59. "CTRL-EVENT-CONNECTED"], timeout=20)
  60. if ev is None:
  61. raise Exception("Roaming with the AP timed out")
  62. if "CTRL-EVENT-EAP-STARTED" in ev:
  63. raise Exception("Unexpected EAP exchange")
  64. def test_suite_b_192(dev, apdev):
  65. """WPA2-PSK/GCMP-256 connection at Suite B 192-bit level"""
  66. if "GCMP-256" not in dev[0].get_capability("pairwise"):
  67. raise HwsimSkip("GCMP-256 not supported")
  68. if "BIP-GMAC-256" not in dev[0].get_capability("group_mgmt"):
  69. raise HwsimSkip("BIP-GMAC-256 not supported")
  70. if "WPA-EAP-SUITE-B-192" not in dev[0].get_capability("key_mgmt"):
  71. raise HwsimSkip("WPA-EAP-SUITE-B-192 not supported")
  72. tls = dev[0].request("GET tls_library")
  73. if not tls.startswith("OpenSSL"):
  74. raise HwsimSkip("TLS library not supported for Suite B: " + tls);
  75. if "build=OpenSSL 1.0.2" not in tls or "run=OpenSSL 1.0.2" not in tls:
  76. raise HwsimSkip("OpenSSL version not supported for Suite B: " + tls)
  77. params = { "ssid": "test-suite-b",
  78. "wpa": "2",
  79. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  80. "rsn_pairwise": "GCMP-256",
  81. "group_mgmt_cipher": "BIP-GMAC-256",
  82. "ieee80211w": "2",
  83. "ieee8021x": "1",
  84. "openssl_ciphers": "SUITEB192",
  85. "eap_server": "1",
  86. "eap_user_file": "auth_serv/eap_user.conf",
  87. "ca_cert": "auth_serv/ec2-ca.pem",
  88. "server_cert": "auth_serv/ec2-server.pem",
  89. "private_key": "auth_serv/ec2-server.key" }
  90. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  91. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  92. ieee80211w="2",
  93. openssl_ciphers="SUITEB192",
  94. eap="TLS", identity="tls user",
  95. ca_cert="auth_serv/ec2-ca.pem",
  96. client_cert="auth_serv/ec2-user.pem",
  97. private_key="auth_serv/ec2-user.key",
  98. pairwise="GCMP-256", group="GCMP-256", scan_freq="2412")
  99. tls_cipher = dev[0].get_status_field("EAP TLS cipher")
  100. if tls_cipher != "ECDHE-ECDSA-AES256-GCM-SHA384":
  101. raise Exception("Unexpected TLS cipher: " + tls_cipher)
  102. bss = dev[0].get_bss(apdev[0]['bssid'])
  103. if 'flags' not in bss:
  104. raise Exception("Could not get BSS flags from BSS table")
  105. if "[WPA2-EAP-SUITE-B-192-GCMP-256]" not in bss['flags']:
  106. raise Exception("Unexpected BSS flags: " + bss['flags'])
  107. dev[0].request("DISCONNECT")
  108. dev[0].wait_disconnected(timeout=20)
  109. dev[0].dump_monitor()
  110. dev[0].request("RECONNECT")
  111. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  112. "CTRL-EVENT-CONNECTED"], timeout=20)
  113. if ev is None:
  114. raise Exception("Roaming with the AP timed out")
  115. if "CTRL-EVENT-EAP-STARTED" in ev:
  116. raise Exception("Unexpected EAP exchange")