diff options
author | Roshan Pius <rpius@google.com> | 2017-03-02 16:01:02 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2017-03-02 16:43:18 -0800 |
commit | 6a8908d2bc0367397eb92444ac78cc8d43160ef6 (patch) | |
tree | 7f16fdf78afa23d7d5ac41f44c5b617652c2432e /service | |
parent | a89f52e241cc52873b3856d4e035717cd562c2db (diff) |
SupplicantStaNetworkHal: Fix wep key handling
According to our public documentation, the wep keys can either be a
quoted ASCII string or a hex string. Since this is similar to the SSID
field, rename the helper function in NativeUtil to reuse for both.
Bug: 35907939
Test: Fixed unit test input for wep networks and validated existing
WEP related tests pass.
Change-Id: I180b9261252dc5745fa3e30e4bc980cde054ba2a
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/SupplicantStaNetworkHal.java | 9 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/util/NativeUtil.java | 63 |
2 files changed, 49 insertions, 23 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java index 121bd88cf..41bfd1b0d 100644 --- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java @@ -182,7 +182,7 @@ public class SupplicantStaNetworkHal { for (int i = 0; i < 4; i++) { config.wepKeys[i] = null; if (getWepKey(i) && !ArrayUtils.isEmpty(mWepKey)) { - config.wepKeys[i] = NativeUtil.stringFromByteArrayList(mWepKey); + config.wepKeys[i] = NativeUtil.bytesToHexOrQuotedAsciiString(mWepKey); } } /** PSK pass phrase */ @@ -260,10 +260,9 @@ public class SupplicantStaNetworkHal { boolean hasSetKey = false; if (config.wepKeys != null) { for (int i = 0; i < config.wepKeys.length; i++) { - // Prevent client screw-up by passing in a WifiConfiguration we gave it - // by preventing "*" as a key. - if (config.wepKeys[i] != null && !config.wepKeys[i].equals("*")) { - if (!setWepKey(i, NativeUtil.stringToByteArrayList(config.wepKeys[i]))) { + if (config.wepKeys[i] != null) { + if (!setWepKey( + i, NativeUtil.hexOrQuotedAsciiStringToBytes(config.wepKeys[i]))) { Log.e(TAG, "failed to set wep_key " + i); return false; } diff --git a/service/java/com/android/server/wifi/util/NativeUtil.java b/service/java/com/android/server/wifi/util/NativeUtil.java index 2309277de..093ba3731 100644 --- a/service/java/com/android/server/wifi/util/NativeUtil.java +++ b/service/java/com/android/server/wifi/util/NativeUtil.java @@ -172,52 +172,79 @@ public class NativeUtil { } /** - * Converts an ssid string to an arraylist of UTF_8 byte values. + * Converts an string to an arraylist of UTF_8 byte values. * These forms are acceptable: * a) ASCII String encapsulated in quotes, or * b) Hex string with no delimiters. * - * @param ssidStr String to be converted. + * @param str String to be converted. * @throws IllegalArgumentException for null string. */ - public static ArrayList<Byte> decodeSsid(String ssidStr) { - if (ssidStr == null) { - throw new IllegalArgumentException("null ssid string"); + public static ArrayList<Byte> hexOrQuotedAsciiStringToBytes(String str) { + if (str == null) { + throw new IllegalArgumentException("null string"); } - int length = ssidStr.length(); - if ((length > 1) && (ssidStr.charAt(0) == '"') && (ssidStr.charAt(length - 1) == '"')) { - ssidStr = ssidStr.substring(1, ssidStr.length() - 1); - return stringToByteArrayList(ssidStr); + int length = str.length(); + if ((length > 1) && (str.charAt(0) == '"') && (str.charAt(length - 1) == '"')) { + str = str.substring(1, str.length() - 1); + return stringToByteArrayList(str); } else { - return byteArrayToArrayList(hexStringToByteArray(ssidStr)); + return byteArrayToArrayList(hexStringToByteArray(str)); } } /** - * Converts an ArrayList<Byte> of UTF_8 byte values to ssid string. + * Converts an ArrayList<Byte> of UTF_8 byte values to string. * The string will either be: * a) ASCII String encapsulated in quotes (if all the bytes are ASCII encodeable and non null), * or * b) Hex string with no delimiters. * - * @param ssidBytes List of bytes for ssid. + * @param bytes List of bytes for ssid. * @throws IllegalArgumentException for null bytes. */ - public static String encodeSsid(ArrayList<Byte> ssidBytes) { - if (ssidBytes == null) { + public static String bytesToHexOrQuotedAsciiString(ArrayList<Byte> bytes) { + if (bytes == null) { throw new IllegalArgumentException("null ssid bytes"); } - byte[] ssidArray = byteArrayFromArrayList(ssidBytes); + byte[] byteArray = byteArrayFromArrayList(bytes); // Check for 0's in the byte stream in which case we cannot convert this into a string. - if (!ssidBytes.contains(Byte.valueOf((byte) 0))) { + if (!bytes.contains(Byte.valueOf((byte) 0))) { CharsetDecoder decoder = StandardCharsets.US_ASCII.newDecoder(); try { - CharBuffer decoded = decoder.decode(ByteBuffer.wrap(ssidArray)); + CharBuffer decoded = decoder.decode(ByteBuffer.wrap(byteArray)); return "\"" + decoded.toString() + "\""; } catch (CharacterCodingException cce) { } } - return hexStringFromByteArray(ssidArray); + return hexStringFromByteArray(byteArray); + } + + /** + * Converts an ssid string to an arraylist of UTF_8 byte values. + * These forms are acceptable: + * a) ASCII String encapsulated in quotes, or + * b) Hex string with no delimiters. + * + * @param ssidStr String to be converted. + * @throws IllegalArgumentException for null string. + */ + public static ArrayList<Byte> decodeSsid(String ssidStr) { + return hexOrQuotedAsciiStringToBytes(ssidStr); + } + + /** + * Converts an ArrayList<Byte> of UTF_8 byte values to ssid string. + * The string will either be: + * a) ASCII String encapsulated in quotes (if all the bytes are ASCII encodeable and non null), + * or + * b) Hex string with no delimiters. + * + * @param ssidBytes List of bytes for ssid. + * @throws IllegalArgumentException for null bytes. + */ + public static String encodeSsid(ArrayList<Byte> ssidBytes) { + return bytesToHexOrQuotedAsciiString(ssidBytes); } /** |