Skip to content

Commit 5d1a870

Browse files
narayankAndroid (Google) Code Review
authored andcommitted
Merge "Add APIs to enable SNI and session tickets on sockets." into jb-mr1-dev
2 parents 5d4206a + b4db962 commit 5d1a870

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12738,9 +12738,11 @@ package android.net {
1273812738
method public static javax.net.ssl.SSLSocketFactory getInsecure(int, android.net.SSLSessionCache);
1273912739
method public byte[] getNpnSelectedProtocol(java.net.Socket);
1274012740
method public java.lang.String[] getSupportedCipherSuites();
12741+
method public void setHostname(java.net.Socket, java.lang.String);
1274112742
method public void setKeyManagers(javax.net.ssl.KeyManager[]);
1274212743
method public void setNpnProtocols(byte[][]);
1274312744
method public void setTrustManagers(javax.net.ssl.TrustManager[]);
12745+
method public void setUseSessionTickets(java.net.Socket, boolean);
1274412746
}
1274512747

1274612748
public final class SSLSessionCache {

core/java/android/net/SSLCertificateSocketFactory.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ static byte[] toNpnProtocolsList(byte[]... npnProtocols) {
300300
* null if no protocol was negotiated.
301301
*
302302
* @param socket a socket created by this factory.
303+
* @throws IllegalArgumentException if the socket was not created by this factory.
303304
*/
304305
public byte[] getNpnSelectedProtocol(Socket socket) {
305-
return ((OpenSSLSocketImpl) socket).getNpnSelectedProtocol();
306+
return castToOpenSSLSocket(socket).getNpnSelectedProtocol();
306307
}
307308

308309
/**
@@ -316,6 +317,38 @@ public void setKeyManagers(KeyManager[] keyManagers) {
316317
mInsecureFactory = null;
317318
}
318319

320+
/**
321+
* Enables <a href="http://tools.ietf.org/html/rfc5077#section-3.2">session ticket</a>
322+
* support on the given socket.
323+
*
324+
* @param socket a socket created by this factory
325+
* @param useSessionTickets {@code true} to enable session ticket support on this socket.
326+
* @throws IllegalArgumentException if the socket was not created by this factory.
327+
*/
328+
public void setUseSessionTickets(Socket socket, boolean useSessionTickets) {
329+
castToOpenSSLSocket(socket).setUseSessionTickets(useSessionTickets);
330+
}
331+
332+
/**
333+
* Turns on <a href="http://tools.ietf.org/html/rfc6066#section-3">Server
334+
* Name Indication (SNI)</a> on a given socket.
335+
*
336+
* @param socket a socket created by this factory.
337+
* @param hostName the desired SNI hostname, null to disable.
338+
* @throws IllegalArgumentException if the socket was not created by this factory.
339+
*/
340+
public void setHostname(Socket socket, String hostName) {
341+
castToOpenSSLSocket(socket).setHostname(hostName);
342+
}
343+
344+
private static OpenSSLSocketImpl castToOpenSSLSocket(Socket socket) {
345+
if (!(socket instanceof OpenSSLSocketImpl)) {
346+
throw new IllegalArgumentException("Socket not created by this factory: "
347+
+ socket);
348+
}
349+
350+
return (OpenSSLSocketImpl) socket;
351+
}
319352

320353
/**
321354
* {@inheritDoc}

0 commit comments

Comments
 (0)