am 9cb376e7: Merge "Change NPN to forbid empty lists of protocols." into jb-dev

* commit '9cb376e792567b5278e0eb418a3aeb848339a283':
  Change NPN to forbid empty lists of protocols.
This commit is contained in:
Jesse Wilson
2012-05-17 11:20:21 -07:00
committed by Android Git Automerger
2 changed files with 13 additions and 7 deletions

View File

@@ -261,8 +261,8 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory {
* server then the first protocol in the client's list will be selected.
* The order of the client's protocols is otherwise insignificant.
*
* @param npnProtocols a possibly-empty list of protocol byte arrays. All
* arrays must be non-empty and of length less than 256.
* @param npnProtocols a non-empty list of protocol byte arrays. All arrays
* must be non-empty and of length less than 256.
*/
public void setNpnProtocols(byte[][] npnProtocols) {
this.mNpnProtocols = toNpnProtocolsList(npnProtocols);
@@ -273,6 +273,9 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory {
* strings.
*/
static byte[] toNpnProtocolsList(byte[]... npnProtocols) {
if (npnProtocols.length == 0) {
throw new IllegalArgumentException("npnProtocols.length == 0");
}
int totalLength = 0;
for (byte[] s : npnProtocols) {
if (s.length == 0 || s.length > 255) {

View File

@@ -59,6 +59,14 @@ public class SSLTest extends TestCase {
new byte[] { 'h', 't', 't', 'p', '/', '1', '.', '1' })));
}
public void testStringsToNpnBytesEmptyArray() {
try {
SSLCertificateSocketFactory.toNpnProtocolsList();
fail();
} catch (IllegalArgumentException expected) {
}
}
public void testStringsToNpnBytesEmptyByteArray() {
try {
SSLCertificateSocketFactory.toNpnProtocolsList(new byte[0]);
@@ -67,11 +75,6 @@ public class SSLTest extends TestCase {
}
}
public void testStringsToNpnBytesEmptyArray() {
byte[] expected = {};
assertTrue(Arrays.equals(expected, SSLCertificateSocketFactory.toNpnProtocolsList()));
}
public void testStringsToNpnBytesOversizedInput() {
try {
SSLCertificateSocketFactory.toNpnProtocolsList(new byte[256]);