Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cb376e7 authored by Jesse Wilson's avatar Jesse Wilson Committed by Android (Google) Code Review
Browse files

Merge "Change NPN to forbid empty lists of protocols." into jb-dev

parents 0a95ce9f 2108ead7
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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) {
+8 −5
Original line number Diff line number Diff line
@@ -59,17 +59,20 @@ public class SSLTest extends TestCase {
                new byte[] { 'h', 't', 't', 'p', '/', '1', '.', '1' })));
    }

    public void testStringsToNpnBytesEmptyByteArray() {
    public void testStringsToNpnBytesEmptyArray() {
        try {
            SSLCertificateSocketFactory.toNpnProtocolsList(new byte[0]);
            SSLCertificateSocketFactory.toNpnProtocolsList();
            fail();
        } catch (IllegalArgumentException expected) {
        }
    }

    public void testStringsToNpnBytesEmptyArray() {
        byte[] expected = {};
        assertTrue(Arrays.equals(expected, SSLCertificateSocketFactory.toNpnProtocolsList()));
    public void testStringsToNpnBytesEmptyByteArray() {
        try {
            SSLCertificateSocketFactory.toNpnProtocolsList(new byte[0]);
            fail();
        } catch (IllegalArgumentException expected) {
        }
    }

    public void testStringsToNpnBytesOversizedInput() {