From a73c94c8de89aa2c404e97ae7108dfa666c76d6f Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 11 Jul 2022 18:46:29 -0400 Subject: [PATCH] Support OWE mode --- .../net/wifi/SoftApConfigurationCompat.kt | 21 +++++++++---- .../net/wifi/WifiApDialogFragment.kt | 30 +++++++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt index 74b17702..d38f1c4b 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt @@ -87,7 +87,14 @@ data class SoftApConfigurationCompat( */ private const val LEGACY_WPA2_PSK = 4 - val securityTypes = arrayOf("OPEN", "WPA2-PSK", "WPA3-SAE Transition mode", "WPA3-SAE") + val securityTypes = arrayOf( + "OPEN", + "WPA2-PSK", + "WPA3-SAE Transition mode", + "WPA3-SAE", + "WPA3-OWE Transition", + "WPA3-OWE", + ) private val qrSanitizer = Regex("([\\\\\":;,])") @@ -304,6 +311,7 @@ data class SoftApConfigurationCompat( SoftApConfiguration.SECURITY_TYPE_WPA2_PSK } android.net.wifi.WifiConfiguration.KeyMgmt.SAE -> SoftApConfiguration.SECURITY_TYPE_WPA3_SAE + android.net.wifi.WifiConfiguration.KeyMgmt.OWE -> SoftApConfiguration.SECURITY_TYPE_WPA3_OWE else -> android.net.wifi.WifiConfiguration.KeyMgmt.strings .getOrElse(selected) { "?" }.let { throw IllegalArgumentException("Unrecognized key management $it ($selected)") @@ -417,6 +425,8 @@ data class SoftApConfigurationCompat( // CHANGED: not actually converted in framework-wifi SoftApConfiguration.SECURITY_TYPE_WPA3_SAE, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION -> android.net.wifi.WifiConfiguration.KeyMgmt.SAE + SoftApConfiguration.SECURITY_TYPE_WPA3_OWE, + SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION -> android.net.wifi.WifiConfiguration.KeyMgmt.OWE else -> throw IllegalArgumentException("Convert fail, unsupported security type :$securityType") }) result.allowedAuthAlgorithms.clear() @@ -463,11 +473,12 @@ data class SoftApConfigurationCompat( fun toQrCode() = StringBuilder("WIFI:").apply { fun String.sanitize() = qrSanitizer.replace(this) { "\\${it.groupValues[1]}" } when (securityType) { - SoftApConfiguration.SECURITY_TYPE_OPEN -> { } - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK -> append("T:WPA;") - SoftApConfiguration.SECURITY_TYPE_WPA3_SAE, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION -> { - append("T:SAE;") + SoftApConfiguration.SECURITY_TYPE_OPEN, SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION, + SoftApConfiguration.SECURITY_TYPE_WPA3_OWE -> { } + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION -> { + append("T:WPA;") } + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE -> append("T:SAE;") else -> throw IllegalArgumentException("Unsupported authentication type") } append("S:") diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt index 41a40059..8931739e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt @@ -170,18 +170,23 @@ class WifiApDialogFragment : AlertDialogFragment?) = error("Must select something") override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - if (position != SoftApConfiguration.SECURITY_TYPE_OPEN) { - dialogView.passwordWrapper.isGone = false - if (position == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE) { - dialogView.passwordWrapper.isCounterEnabled = false - dialogView.passwordWrapper.counterMaxLength = 0 - dialogView.password.filters = emptyArray() - } else { - dialogView.passwordWrapper.isCounterEnabled = true - dialogView.passwordWrapper.counterMaxLength = 63 - dialogView.password.filters = arrayOf(InputFilter.LengthFilter(63)) + when (position) { + SoftApConfiguration.SECURITY_TYPE_OPEN, + SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION, + SoftApConfiguration.SECURITY_TYPE_WPA3_OWE -> dialogView.passwordWrapper.isGone = true + else -> { + dialogView.passwordWrapper.isGone = false + if (position == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE) { + dialogView.passwordWrapper.isCounterEnabled = false + dialogView.passwordWrapper.counterMaxLength = 0 + dialogView.password.filters = emptyArray() + } else { + dialogView.passwordWrapper.isCounterEnabled = true + dialogView.passwordWrapper.counterMaxLength = 63 + dialogView.password.filters = arrayOf(InputFilter.LengthFilter(63)) + } } - } else dialogView.passwordWrapper.isGone = true + } validate() } } @@ -278,7 +283,8 @@ class WifiApDialogFragment : AlertDialogFragment true + SoftApConfiguration.SECURITY_TYPE_OPEN, SoftApConfiguration.SECURITY_TYPE_WPA3_OWE_TRANSITION, + SoftApConfiguration.SECURITY_TYPE_WPA3_OWE -> true SoftApConfiguration.SECURITY_TYPE_WPA2_PSK, SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION -> { dialogView.password.length() in 8..63 }