Methods Summary |
---|
public final java.util.Enumeration | getIds()
final Iterator<SSLSession> iterator = sessionIterator();
return new Enumeration<byte[]>() {
public boolean hasMoreElements() {
return iterator.hasNext();
}
public byte[] nextElement() {
return iterator.next().getId();
}
};
|
public final int | getSessionCacheSize()
return maximumSize;
|
public final int | getSessionTimeout()
return timeout;
|
static void | log(java.lang.Throwable t)
java.util.logging.Logger.global.log(Level.WARNING,
"Error converting session.", t);
|
abstract java.util.Iterator | sessionIterator()Returns the collection of sessions ordered by least-recently-used first.
|
public final void | setSessionCacheSize(int size)
if (size < 0) {
throw new IllegalArgumentException("size < 0");
}
int oldMaximum = maximumSize;
maximumSize = size;
// Trim cache to size if necessary.
if (size < oldMaximum) {
trimToSize();
}
|
byte[] | toBytes(javax.net.ssl.SSLSession session)Converts the given session to bytes.
// TODO: Support SSLSessionImpl, too.
if (!(session instanceof OpenSSLSessionImpl)) {
return null;
}
OpenSSLSessionImpl sslSession = (OpenSSLSessionImpl) session;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream daos = new DataOutputStream(baos);
daos.writeInt(OPEN_SSL); // session type ID
// Session data.
byte[] data = sslSession.getEncoded();
daos.writeInt(data.length);
daos.write(data);
// Certificates.
X509Certificate[] certs = session.getPeerCertificateChain();
daos.writeInt(certs.length);
// TODO: Call nativegetpeercertificates()
for (X509Certificate cert : certs) {
data = cert.getEncoded();
daos.writeInt(data.length);
daos.write(data);
}
return baos.toByteArray();
} catch (IOException e) {
log(e);
return null;
} catch (CertificateEncodingException e) {
log(e);
return null;
}
|
javax.net.ssl.SSLSession | toSession(byte[] data, java.lang.String host, int port)Creates a session from the given bytes.
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dais = new DataInputStream(bais);
try {
int type = dais.readInt();
if (type != OPEN_SSL) {
log(new AssertionError("Unexpected type ID: " + type));
return null;
}
int length = dais.readInt();
byte[] sessionData = new byte[length];
dais.readFully(sessionData);
int count = dais.readInt();
X509Certificate[] certs = new X509Certificate[count];
for (int i = 0; i < count; i++) {
length = dais.readInt();
byte[] certData = new byte[length];
dais.readFully(certData);
certs[i] = X509Certificate.getInstance(certData);
}
return new OpenSSLSessionImpl(sessionData, parameters, host, port,
certs, this);
} catch (IOException e) {
log(e);
return null;
} catch (CertificateException e) {
log(e);
return null;
}
|
abstract void | trimToSize()Makes sure cache size is < maximumSize.
|