本文整理匯總了Java中javax.net.ssl.SSLSessionContext類的典型用法代碼示例。如果您正苦於以下問題:Java SSLSessionContext類的具體用法?Java SSLSessionContext怎麽用?Java SSLSessionContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SSLSessionContext類屬於javax.net.ssl包,在下文中一共展示了SSLSessionContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configureSessionContext
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
@Override
public void configureSessionContext(SSLSessionContext sslSessionContext) {
int sessionCacheSize;
if (endpoint.getSessionCacheSize() != null) {
sessionCacheSize = Integer.parseInt(
endpoint.getSessionCacheSize());
} else {
sessionCacheSize = defaultSessionCacheSize;
}
int sessionTimeout;
if (endpoint.getSessionTimeout() != null) {
sessionTimeout = Integer.parseInt(endpoint.getSessionTimeout());
} else {
sessionTimeout = defaultSessionTimeout;
}
sslSessionContext.setSessionCacheSize(sessionCacheSize);
sslSessionContext.setSessionTimeout(sessionTimeout);
}
示例2: getSessionContext
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
* For server sessions, this returns the set of sessions which
* are currently valid in this process. For client sessions,
* this returns null.
*/
@Override
public SSLSessionContext getSessionContext() {
/*
* An interim security policy until we can do something
* more specific in 1.2. Only allow trusted code (code which
* can set system properties) to get an
* SSLSessionContext. This is to limit the ability of code to
* look up specific sessions or enumerate over them. Otherwise,
* code can only get session objects from successful SSL
* connections which implies that they must have had permission
* to make the network connection in the first place.
*/
SecurityManager sm;
if ((sm = System.getSecurityManager()) != null) {
sm.checkPermission(new SSLPermission("getSSLSessionContext"));
}
return context;
}
示例3: clearSessionCache
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
* Invalidates all SSL/TLS sessions in {@code sessionContext} associated with {@code remoteAddress}.
*
* @param sessionContext collection of SSL/TLS sessions to be (potentially) invalidated
* @param remoteAddress associated with sessions to invalidate
*/
private void clearSessionCache(final SSLSessionContext sessionContext, final InetSocketAddress remoteAddress) {
final String hostName = remoteAddress.getHostName();
final int port = remoteAddress.getPort();
final Enumeration<byte[]> ids = sessionContext.getIds();
if (ids == null) {
return;
}
while (ids.hasMoreElements()) {
final byte[] id = ids.nextElement();
final SSLSession session = sessionContext.getSession(id);
if (session != null && session.getPeerHost() != null && session.getPeerHost().equalsIgnoreCase(hostName)
&& session.getPeerPort() == port) {
session.invalidate();
if (LOG.isDebugEnabled()) {
LOG.debug("Invalidated session " + session);
}
}
}
}
示例4: configureSessionContext
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
@Override
public void configureSessionContext(SSLSessionContext sslSessionContext) {
int sessionCacheSize;
if (endpoint.getSessionCacheSize() != null) {
sessionCacheSize = Integer.parseInt(endpoint.getSessionCacheSize());
} else {
sessionCacheSize = defaultSessionCacheSize;
}
int sessionTimeout;
if (endpoint.getSessionTimeout() != null) {
sessionTimeout = Integer.parseInt(endpoint.getSessionTimeout());
} else {
sessionTimeout = defaultSessionTimeout;
}
sslSessionContext.setSessionCacheSize(sessionCacheSize);
sslSessionContext.setSessionTimeout(sessionTimeout);
}
示例5: test_SSLContext_getServerSessionContext
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
@Test
public void test_SSLContext_getServerSessionContext() throws Exception {
for (String protocol : StandardNames.SSL_CONTEXT_PROTOCOLS) {
SSLContext sslContext = SSLContext.getInstance(protocol);
SSLSessionContext sessionContext = sslContext.getServerSessionContext();
assertNotNull(sessionContext);
if (protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
assertSame(
SSLContext.getInstance(protocol).getServerSessionContext(), sessionContext);
} else {
assertNotSame(
SSLContext.getInstance(protocol).getServerSessionContext(), sessionContext);
}
}
}
示例6: test_SSLContext_getClientSessionContext
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
@Test
public void test_SSLContext_getClientSessionContext() throws Exception {
for (String protocol : StandardNames.SSL_CONTEXT_PROTOCOLS) {
SSLContext sslContext = SSLContext.getInstance(protocol);
SSLSessionContext sessionContext = sslContext.getClientSessionContext();
assertNotNull(sessionContext);
if (protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
assertSame(
SSLContext.getInstance(protocol).getClientSessionContext(), sessionContext);
} else {
assertNotSame(
SSLContext.getInstance(protocol).getClientSessionContext(), sessionContext);
}
}
}
示例7: test_getSession
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @tests javax.net.ssl.SSLSessionContex#getSession(byte[] sessionId)
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getSession",
args = {byte[].class}
)
public final void test_getSession() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
SSLSessionContext sc = context
.getClientSessionContext();
try {
sc.getSession(null);
} catch (NullPointerException e) {
// expected
}
assertNull(sc.getSession(new byte[5]));
}
示例8: getSessionContext
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
* For server sessions, this returns the set of sessions which
* are currently valid in this process. For client sessions,
* this returns null.
*/
public SSLSessionContext getSessionContext() {
/*
* An interim security policy until we can do something
* more specific in 1.2. Only allow trusted code (code which
* can set system properties) to get an
* SSLSessionContext. This is to limit the ability of code to
* look up specific sessions or enumerate over them. Otherwise,
* code can only get session objects from successful SSL
* connections which implies that they must have had permission
* to make the network connection in the first place.
*/
SecurityManager sm;
if ((sm = System.getSecurityManager()) != null) {
sm.checkPermission(new SSLPermission("getSSLSessionContext"));
}
return context;
}
示例9: findSessionToResume
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
private SSLSessionImpl findSessionToResume() {
String host;
int port;
if (engineOwner != null) {
host = engineOwner.getPeerHost();
port = engineOwner.getPeerPort();
} else {
host = socketOwner.getInetAddress().getHostName();
port = socketOwner.getPort();
}
if (host == null || port == -1) {
return null; // starts new session
}
byte[] id;
SSLSession ses;
SSLSessionContext context = parameters.getClientSessionContext();
for (Enumeration<?> en = context.getIds(); en.hasMoreElements();) {
id = (byte[])en.nextElement();
ses = context.getSession(id);
if (host.equals(ses.getPeerHost()) && port == ses.getPeerPort()) {
return (SSLSessionImpl)((SSLSessionImpl)ses).clone(); // resume
}
}
return null; // starts new session
}
示例10: main
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
// try {
SSLServerSocketFactory ssf =
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket ss = (SSLServerSocket)ssf.createServerSocket();
String[] protocols = ss.getSupportedProtocols();
for (int i = 0; i < protocols.length; i++) {
// try {
if (protocols[i].equals("SSLv2Hello")) {
continue;
}
SSLContext sslc = SSLContext.getInstance(protocols[i]);
SSLSessionContext sslsc = sslc.getServerSessionContext();
System.out.println("Protocol: " + protocols[i]);
sslsc.setSessionTimeout(Integer.MAX_VALUE);
int newtime = sslsc.getSessionTimeout();
if (newtime != Integer.MAX_VALUE) {
throw new Exception ("Expected timeout: " +
Integer.MAX_VALUE + ", got instead: " +
newtime);
}
// } catch (Exception e) {
// }
}
// } catch (Exception e) {
// System.out.println(e);
// }
System.out.println("Finished");
}
示例11: findSessionToResume
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
private SSLSessionImpl findSessionToResume() {
String host;
int port;
if (engineOwner != null) {
host = engineOwner.getPeerHost();
port = engineOwner.getPeerPort();
} else {
host = socketOwner.getInetAddress().getHostName();
port = socketOwner.getPort();
}
if (host == null || port == -1) {
return null; // starts new session
}
byte[] id;
SSLSession ses;
SSLSessionContext context = parameters.getClientSessionContext();
for (Enumeration en = context.getIds(); en.hasMoreElements();) {
id = (byte[])en.nextElement();
ses = context.getSession(id);
if (host.equals(ses.getPeerHost()) && port == ses.getPeerPort()) {
return (SSLSessionImpl)((SSLSessionImpl)ses).clone(); // resume
}
}
return null; // starts new session
}
示例12: configureSessionContext
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
@Override
public void configureSessionContext(SSLSessionContext sslSessionContext) {
int sessionCacheSize;
if (endpoint.getSessionCacheSize() != null) {
sessionCacheSize = Integer.parseInt(
endpoint.getSessionCacheSize());
} else {
sessionCacheSize = defaultSessionCacheSize;
}
int sessionTimeout;
if (endpoint.getSessionTimeout() != null) {
sessionTimeout = Integer.parseInt(endpoint.getSessionTimeout());
} else {
sessionTimeout = defaultSessionTimeout;
}
sslSessionContext.setSessionCacheSize(sessionCacheSize);
sslSessionContext.setSessionTimeout(sessionTimeout);
}
示例13: init
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
* Reads the keystore and initializes the SSL socket factory.
*/
void init() throws IOException {
try {
String clientAuthStr = endpoint.getClientAuth();
if ("true".equalsIgnoreCase(clientAuthStr) || "yes".equalsIgnoreCase(clientAuthStr)) {
requireClientAuth = true;
} else if ("want".equalsIgnoreCase(clientAuthStr)) {
wantClientAuth = true;
}
SSLContext context = createSSLContext();
context.init(getKeyManagers(), getTrustManagers(), null);
// Configure SSL session cache
SSLSessionContext sessionContext = context.getServerSessionContext();
if (sessionContext != null) {
configureSessionContext(sessionContext);
}
// create proxy
sslProxy = context.getServerSocketFactory();
// Determine which cipher suites to enable
enabledCiphers = getEnableableCiphers(context);
enabledProtocols = getEnableableProtocols(context);
allowUnsafeLegacyRenegotiation = "true".equals(endpoint.getAllowUnsafeLegacyRenegotiation());
// Check the SSL config is OK
checkConfig();
} catch (Exception e) {
if (e instanceof IOException)
throw (IOException) e;
throw new IOException(e.getMessage(), e);
}
}
示例14: setClientSessionCache
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
* Sets the client-side persistent cache to be used by the context.
*/
public static void setClientSessionCache(SSLContext context, SSLClientSessionCache cache) {
SSLSessionContext clientContext = context.getClientSessionContext();
if (!(clientContext instanceof ClientSessionContext)) {
throw new IllegalArgumentException(
"Not a conscrypt client context: " + clientContext.getClass().getName());
}
((ClientSessionContext) clientContext).setPersistentCache(cache);
}
示例15: setServerSessionCache
import javax.net.ssl.SSLSessionContext; //導入依賴的package包/類
/**
* Sets the server-side persistent cache to be used by the context.
*/
public static void setServerSessionCache(SSLContext context, SSLServerSessionCache cache) {
SSLSessionContext serverContext = context.getServerSessionContext();
if (!(serverContext instanceof ServerSessionContext)) {
throw new IllegalArgumentException(
"Not a conscrypt client context: " + serverContext.getClass().getName());
}
((ServerSessionContext) serverContext).setPersistentCache(cache);
}