summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-03-03 19:27:33 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-03-03 19:27:34 +0000
commit8db1eb8b2a062d749116e7aba6c018c594f27a23 (patch)
tree7822a3ef8f21c4b5bb9dc9e424a95b721ba3ea79 /service
parent36625b693ef5da6aa14e9ea0e3581262803795b7 (diff)
parent6a8908d2bc0367397eb92444ac78cc8d43160ef6 (diff)
Merge "SupplicantStaNetworkHal: Fix wep key handling"
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaNetworkHal.java9
-rw-r--r--service/java/com/android/server/wifi/util/NativeUtil.java63
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);
}
/**