cipher-and-key-mgmt-testing.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. Cipher suite (CCMP, TKIP, GCMP, ..) and key management testing
  2. ==============================================================
  3. wpa_supplicant and hostapd include number of extensions that allow
  4. special test builds to be used for testing functionality related to
  5. correct implementation of IEEE 802.11. These extensions allow behavior
  6. to be modified and invalid operations to be performed to verify behavior
  7. of other devices in unexpected situations. While most of the testing
  8. extensions are focused on the fully automated testing framework with
  9. mac80211_hwsim (see tests/hwsim subdirectory), many of these can be used
  10. for over-the-air testing of the protocol as well.
  11. Since some of the testing extensions can result in exposing key
  12. information or allowing non-compliant behavior, these changes are
  13. disabled in default wpa_supplicant and hostapd builds for production
  14. purposes. Testing functionality can be enabled by adding
  15. CONFIG_TESTING_OPTIONS=y into build configuration (hostapd/.config and
  16. wpa_supplicant/.config).
  17. Testing setup
  18. -------------
  19. These tests can be run as black-box testing without having to modify the
  20. tested device at all or without knowing details of its
  21. functionality. The test commands in wpa_supplicant/hostapd control
  22. interfaces are used to perform unexpected operations and normal data
  23. traffic is used to verify reaction of the tested device to such
  24. operations.
  25. In theory, the test functionality is available with most drivers
  26. supported by wpa_supplicant/hostapd, but the most reliable results are
  27. likely available through ath9k-based devices. If you are using something
  28. else, it is strongly recommended that you'll run the first tests with
  29. sniffer captures and verify that the test tools are behaving correctly.
  30. wpa_supplicant is used to control a test device in station mode to test
  31. an AP and hostapd is similarly used to control a test device in AP mode
  32. to test a station.
  33. Various data traffic generators could be used to test the behavior, but
  34. this document focuses on using ping to test unicast traffic and arping
  35. to test broadcast traffic. To keep things simple and to reduce
  36. interference from unrelated traffic, the steps here assume static IPv4
  37. addresses are used and IPv6 is disabled.
  38. The tests here use WPA2-Personal for simplicity. WPA2-Enterprise and
  39. other cipher suites can also be tested for more complete coverage.
  40. Example hostapd.conf for the test tool in AP mode:
  41. driver=nl80211
  42. hw_mode=g
  43. channel=1
  44. ieee80211n=1
  45. interface=wlan0
  46. ctrl_interface=/var/run/hostapd
  47. ctrl_interface_group=adm
  48. ssid=test-psk
  49. wpa=2
  50. wpa_key_mgmt=WPA-PSK
  51. wpa_pairwise=CCMP
  52. wpa_passphrase=12345678
  53. Example wpa_supplicant.conf for the test tool in station mode:
  54. ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=adm
  55. network={
  56. ssid="test-psk"
  57. key_mgmt=WPA-PSK
  58. psk="12345678"
  59. }
  60. The examples in this document assume following IPv4 address
  61. configuration:
  62. Test tool (either AP or station mode): 192.168.1.1/24
  63. Device under test: 192.168.1.2/24
  64. Data traffic tests
  65. ------------------
  66. ping is used to test whether unicast frames go through on the data
  67. link. It should be noted that ping may need to use broadcast ARP at the
  68. beginning if the other device is not yet in the ARP table, so working
  69. broadcast and unicast connectivity may be needed to get this started.
  70. Example:
  71. $ ping -n -c 5 192.168.1.2
  72. PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
  73. 64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=43.7 ms
  74. 64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=67.9 ms
  75. 64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=900 ms
  76. 64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=5.81 ms
  77. 64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=135 ms
  78. --- 192.168.1.2 ping statistics ---
  79. 5 packets transmitted, 5 received, 0% packet loss, time 4004ms
  80. rtt min/avg/max/mdev = 5.811/230.605/900.223/337.451 ms
  81. This shows working unicast data connectivity.
  82. $ ping -n -c 5 192.168.1.2
  83. PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
  84. --- 192.168.1.2 ping statistics ---
  85. 5 packets transmitted, 0 received, 100% packet loss, time 4033ms
  86. This shows not working unicast data connectivity.
  87. arping is used to test broadcast connectivity.
  88. Example:
  89. $ arping -b -I wlan0 192.168.1.2 -c 5
  90. ARPING 192.168.1.2 from 192.168.1.1 wlan0
  91. Unicast reply from 192.168.1.2 [<DUT MAC address>] 119.695ms
  92. Unicast reply from 192.168.1.2 [<DUT MAC address>] 144.496ms
  93. Unicast reply from 192.168.1.2 [<DUT MAC address>] 166.788ms
  94. Unicast reply from 192.168.1.2 [<DUT MAC address>] 2.283ms
  95. Unicast reply from 192.168.1.2 [<DUT MAC address>] 2.234ms
  96. Sent 5 probes (5 broadcast(s))
  97. Received 5 response(s)
  98. This shows working broadcast data connectivity.
  99. $ arping -b -I wlan0 192.168.1.2 -c 5
  100. ARPING 192.168.1.2 from 192.168.1.1 wlan0
  101. Sent 5 probes (5 broadcast(s))
  102. Received 0 response(s)
  103. This shows not working broadcast data connectivity.
  104. If testing results do not look consistent, the testing state can be
  105. cleared by disconnection and reconnecting the station (the test tool or
  106. the DUT) to the network.
  107. Sniffer and wlantest
  108. --------------------
  109. It is useful to get a wireless sniffer capture from the operating
  110. channel of the AP to be able to confirm DUT behavior if any of the data
  111. tests indicate reason to believe something is not working as expected.
  112. wlantest (from the wlantest directory of hostap.git) can be used to
  113. decrypt and analyze a sniffer capture. For example:
  114. wlantest -r wlan0.pcap -n decrypted.pcap -p 12345678
  115. The debug prints and comments in the generated file indicate where
  116. unexpected behavior has been detected, e.g., when the test tool ends up
  117. clearing its packet number to test replay protection. That can help in
  118. checking whether the DUT actually replies to a frame that it was
  119. supposed to drop due replay.
  120. Testing replay protection on a station device
  121. ---------------------------------------------
  122. Start hostapd and use hostapd_cli on the test device to control testing
  123. operations. Connect the DUT to the network.
  124. <3>AP-STA-CONNECTED <DUT MAC address>
  125. This indicates that the connection was completed successfully.
  126. Verify that broadcast and unicast traffic works correctly (if not,
  127. something is wrong in the test setup and that needs to be resolved
  128. before being able to run any tests).
  129. Verify that unicast traffic works and issue the following command in
  130. hostapd_cli:
  131. > raw RESET_PN <DUT MAC address>
  132. OK
  133. Verify that unicast traffic does not work anymore. If it does, the DUT
  134. does not implement replay protection correctly for unicast frames. Note
  135. that unicast traffic can recover once the packet number from the test
  136. device increases beyond the value used prior to that RESET_PN command.
  137. Verify that broadcast traffic works and issue the following command in
  138. hostapd_cli:
  139. > raw RESET_PN ff:ff:ff:ff:ff:ff
  140. OK
  141. Verify that broadcast traffic does not work anymore. If it does, the DUT
  142. does not implement replay protection correctly for broadcast
  143. frames. Note that broadcast traffic can recover once the packet number
  144. from the test device increases beyond the value used prior to that
  145. RESET_PN command.
  146. Testing replay protection on an AP device
  147. -----------------------------------------
  148. Start the AP (DUT) and start wpa_supplicant on the test device to
  149. connect to the network. Use wpa_cli to control the test device.
  150. <3>SME: Trying to authenticate with <DUT MAC address> (SSID='test-psk' freq=5240 MHz)
  151. <3>CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
  152. <3>Trying to associate with <DUT MAC address> (SSID='test-psk' freq=5240 MHz)
  153. <3>Associated with <DUT MAC address>
  154. <3>WPA: Key negotiation completed with <DUT MAC address> [PTK=CCMP GTK=CCMP]
  155. <3>CTRL-EVENT-CONNECTED - Connection to <DUT MAC address> completed [id=0 id_str=]
  156. Verify that unicast traffic works and issue the following command in
  157. wpa_cli:
  158. > raw RESET_PN
  159. OK
  160. Verify that unicast traffic does not work anymore. If it does, the DUT
  161. does not implement replay protection correctly. Note that unicast
  162. traffic can recover once the packet number from the test device
  163. increases beyond the value used prior to that RESET_PN command.
  164. IEEE 802.11 protocol uses unicast frames in station-to-AP direction, so
  165. there is no need to test AP replay protection behavior separately with
  166. the broadcast IPv4 traffic (which would be converted to unicast frames
  167. on the link layer).
  168. Testing GTK reinstallation protection on a station device (group handshake)
  169. ---------------------------------------------------------------------------
  170. Use the procedure describe above for testing replay protection, but with
  171. the following hostapd_cli commands:
  172. Test broadcast connectivity; should work
  173. > raw RESEND_GROUP_M1 <DUT MAC address>
  174. OK
  175. > raw RESET_PN ff:ff:ff:ff:ff:ff
  176. OK
  177. Test broadcast connectivity; should not work; if it does, the device
  178. does not implement protection for delayed retransmission of Group Key
  179. Message 1/2.
  180. Testing GTK reinstallation protection on a station device (4-way handshake)
  181. ---------------------------------------------------------------------------
  182. Use the procedure described above for testing replay protection for
  183. broadcast traffic, but with the following hostapd_cli commands:
  184. Test broadcast connectivity; should work
  185. > raw RESEND_M3 <DUT MAC address>
  186. OK
  187. > raw RESET_PN ff:ff:ff:ff:ff:ff
  188. OK
  189. Test broadcast connectivity; should not work; if it does, the device
  190. does not implement protection for delayed retransmission of 4-way
  191. handshake EAPOL-Key Message 3/4.
  192. Variant 1: Include extra Message 1/4
  193. Otherwise same as above, but replace RESEND_M3 command with:
  194. > raw RESEND_M1 <DUT MAC address>
  195. OK
  196. > raw RESEND_M3 <DUT MAC address>
  197. OK
  198. Variant 2: Include two extra Message 1/4
  199. Otherwise same as above, but replace RESEND_M3 command with:
  200. > raw RESEND_M1 <DUT MAC address> change-anonce
  201. OK
  202. > raw RESEND_M1 <DUT MAC address>
  203. OK
  204. > raw RESEND_M3 <DUT MAC address>
  205. OK
  206. Testing TK reinstallation protection on a station device (4-way handshake)
  207. --------------------------------------------------------------------------
  208. Use the procedure described above for testing replay protection for
  209. unicast traffic, but with the following hostapd_cli commands:
  210. Test unicast connectivity; should work
  211. > raw RESEND_M3 <DUT MAC address>
  212. OK
  213. > raw RESET_PN <DUT MAC address>
  214. OK
  215. Test unicast connectivity; should not work; if it does, the device
  216. does not implement protection for delayed retransmission of 4-way
  217. handshake EAPOL-Key Message 3/4.
  218. Variant 1: Include extra Message 1/4
  219. Otherwise same as above, but replace RESEND_M3 command with:
  220. > raw RESEND_M1 <DUT MAC address>
  221. OK
  222. > raw RESEND_M3 <DUT MAC address>
  223. OK
  224. Variant 2: Include two extra Message 1/4
  225. Otherwise same as above, but replace RESEND_M3 command with:
  226. > raw RESEND_M1 <DUT MAC address> change-anonce
  227. OK
  228. > raw RESEND_M1 <DUT MAC address>
  229. OK
  230. > raw RESEND_M3 <DUT MAC address>
  231. OK
  232. Testing ANonce generation on an AP device
  233. -----------------------------------------
  234. Start the AP (DUT) and start wpa_supplicant on the test device to
  235. connect to the network. Use wpa_cli to control the test device.
  236. <3>SME: Trying to authenticate with <DUT MAC address> (SSID='test-psk' freq=5240 MHz)
  237. <3>CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
  238. <3>Trying to associate with <DUT MAC address> (SSID='test-psk' freq=5240 MHz)
  239. <3>Associated with <DUT MAC address>
  240. <3>WPA: Key negotiation completed with <DUT MAC address> [PTK=CCMP GTK=CCMP]
  241. <3>CTRL-EVENT-CONNECTED - Connection to <DUT MAC address> completed [id=0 id_str=]
  242. Show the ANonce from the first 4-way handshake, request PTK rekeying,
  243. and show the ANonce from the second 4-way handshake:
  244. > GET anonce
  245. df8c61d1f1f7aca9f1739dd888199547f4af2b8b07f8bf15b45ea271da0072b2
  246. > raw KEY_REQUEST 0 1
  247. OK
  248. > GET anonce
  249. d8ddcb716f28abfdf1352a05d51e7a70f58802122e99d13c730c3c0f09594aac
  250. If the ANonce values are same, the AP did not update the ANonce for
  251. rekeying (it should have as shown in the example above).
  252. Testing FT Reassociation Request frame retransmission on an AP device
  253. ---------------------------------------------------------------------
  254. This test case requires a sniffer to be used and manually analyzed.
  255. Enable FT on the DUT AP (likely two AP devices needed), connect test
  256. tool to the AP using FT protocol (e.g., connect to another AP first and
  257. then use the "ROAM <BSSID>" command), and do the following steps:
  258. - verify unicast traffic from the AP to test station (either ping from
  259. the AP or from a device behind the AP); this needs to work
  260. - wpa_cli "raw RESEND_ASSOC"
  261. - verify unicast traffic from the AP to test station (either ping from
  262. the AP or from a device behind the AP); this is likely to fail, but
  263. the real analysis is done based on the sniffer capture
  264. In the sniffer capture, find the last Reassociation Request frame from
  265. the test station (this is more or less identical to the previous one and
  266. the only one that should not have Authentication frame exchange before
  267. it). Look at the last used PN in a unicast Data frame from the AP to the
  268. test station before the last Reassociation Request frame and the PN in
  269. the following unicast Data frame after the last Reassociation Request
  270. frame. If the PN goes down (e.g., is reset to 1), this would be a sign
  271. of a likely security vulnerability. The AP's TK configuration should be
  272. verified (i.e., whether it is configuring the same TK again and then
  273. allowing it to be used with reused PN values).