test_suite_b.py 5.6 KB

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