本文整理了Java中javax.net.ssl.SSLException
类的一些代码示例,展示了SSLException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLException
类的具体详情如下:
包路径:javax.net.ssl.SSLException
类名称:SSLException
[英]The base class for all SSL related exceptions.
[中]所有SSL相关异常的基类。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public SSLContext createSslContext() throws SSLException {
checkParameters();
try {
KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance(keyAlgorithm);
KeyStore keyStore = loadKeyStore(keyStoreType, keyStoreFilePath, keyStorePwd);
keyMgrFactory.init(keyStore, keyStorePwd);
TrustManager[] mgrs = trustMgrs;
if (mgrs == null) {
TrustManagerFactory trustMgrFactory = TrustManagerFactory.getInstance(keyAlgorithm);
KeyStore trustStore = loadKeyStore(trustStoreType, trustStoreFilePath, trustStorePwd);
trustMgrFactory.init(trustStore);
mgrs = trustMgrFactory.getTrustManagers();
}
SSLContext ctx = SSLContext.getInstance(proto);
if (cipherSuites != null || protocols != null) {
SSLParameters sslParameters = new SSLParameters();
if (cipherSuites != null)
sslParameters.setCipherSuites(cipherSuites);
if (protocols != null)
sslParameters.setProtocols(protocols);
ctx = new SSLContextWrapper(ctx, sslParameters);
}
ctx.init(keyMgrFactory.getKeyManagers(), mgrs, null);
return ctx;
}
catch (GeneralSecurityException e) {
throw new SSLException("Failed to initialize SSL context " + parameters(), e);
}
}
代码示例来源:origin: apache/usergrid
in.close();
SSLContext context = SSLContext.getInstance( "TLS" );
TrustManagerFactory tmf = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
tmf.init( ks );
X509TrustManager defaultTrustManager = ( X509TrustManager ) tmf.getTrustManagers()[0];
SavingTrustManager tm = new SavingTrustManager( defaultTrustManager );
context.init( null, new TrustManager[] { tm }, null );
SSLSocketFactory factory = context.getSocketFactory();
LOG.debug( "Cert is NOT trusted: {}", e.getMessage() );
代码示例来源:origin: k9mail/k-9
private void handleSslException(SSLException e) throws CertificateValidationException, SSLException {
if (e.getCause() instanceof CertificateException) {
throw new CertificateValidationException(e.getMessage(), e);
} else {
throw e;
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public final SSLException noSNIContextForSslConnection() {
final SSLException result = new SSLException(String.format(getLoggingLocale(), noSNIContextForSslConnection$str()));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
private static final String mechMessageAfterComplete = "ELY05001: Authentication mechanism exchange received a message after authentication was already complete";
代码示例来源:origin: igniterealtime/Openfire
tlsEngineResult = tlsEngine.unwrap( net, out );
} catch ( SSLException e ) {
if ( e.getMessage().startsWith( "Unsupported record version Unknown-" ) ) {
throw new SSLException( "We appear to have received plain text data where we expected encrypted data. A common cause for this is a peer sending us a plain-text error message when it shouldn't send a message, but close the socket instead).", e );
if (tlsEngineResult.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
代码示例来源:origin: redisson/redisson
keyManagerFactory = buildKeyManagerFactory(keyCertChain, key, keyPassword, keyManagerFactory);
SSLContext ctx = sslContextProvider == null ? SSLContext.getInstance(PROTOCOL)
: SSLContext.getInstance(PROTOCOL, sslContextProvider);
ctx.init(keyManagerFactory == null ? null : keyManagerFactory.getKeyManagers(),
trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
null);
SSLSessionContext sessCtx = ctx.getClientSessionContext();
if (sessionCacheSize > 0) {
sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
throw (SSLException) e;
throw new SSLException("failed to initialize the client-side SSL context", e);
代码示例来源:origin: redisson/redisson
} else {
keyManagerFactory = new OpenSslCachingX509KeyManagerFactory(
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()));
keyManagerFactory.init(ks, keyPasswordChars);
keyMaterialProvider = providerFor(keyManagerFactory, keyPassword);
} else if (keyManagerFactory != null) {
throw new SSLException("failed to set certificate and key", e);
trustManagerFactory = buildTrustManagerFactory(trustCertCollection, trustManagerFactory);
} else if (trustManagerFactory == null) {
trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
final X509TrustManager manager = chooseTrustManager(trustManagerFactory.getTrustManagers());
keyMaterialProvider.destroy();
throw new SSLException("unable to setup trustmanager", e);
代码示例来源:origin: redisson/redisson
SSLContext ctx = sslContextProvider == null ? SSLContext.getInstance(PROTOCOL)
: SSLContext.getInstance(PROTOCOL, sslContextProvider);
ctx.init(keyManagerFactory.getKeyManagers(),
trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
null);
SSLSessionContext sessCtx = ctx.getServerSessionContext();
if (sessionCacheSize > 0) {
sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
throw (SSLException) e;
throw new SSLException("failed to initialize the server-side SSL context", e);
代码示例来源:origin: io.netty/netty
throw new SSLException("NPN/ALPN unsupported: " + nextProtocols);
ctx = SSLContext.getInstance(PROTOCOL);
if (trustManagerFactory == null) {
ctx.init(null, null, null);
} else {
trustManagerFactory.init((KeyStore) null);
ctx.init(null, trustManagerFactory.getTrustManagers(), null);
trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(ks);
SSLSessionContext sessCtx = ctx.getClientSessionContext();
if (sessionCacheSize > 0) {
sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
throw new SSLException("failed to initialize the server-side SSL context", e);
代码示例来源:origin: io.netty/netty
throw new SSLException("NPN/ALPN unsupported: " + nextProtocols);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
kmf.init(ks, keyPasswordChars);
ctx = SSLContext.getInstance(PROTOCOL);
ctx.init(kmf.getKeyManagers(), null, null);
SSLSessionContext sessCtx = ctx.getServerSessionContext();
if (sessionCacheSize > 0) {
sessCtx.setSessionCacheSize((int) Math.min(sessionCacheSize, Integer.MAX_VALUE));
sessCtx.setSessionTimeout((int) Math.min(sessionTimeout, Integer.MAX_VALUE));
throw new SSLException("failed to initialize the server-side SSL context", e);
代码示例来源:origin: redisson/redisson
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
sslContextBuilder.trustManager(trustManagerFactory);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, password);
sslContextBuilder.keyManager(keyManagerFactory);
method.invoke(sslParams, "HTTPS");
} catch (Exception e) {
throw new SSLException(e);
sslEngine.setSSLParameters(sslParams);
代码示例来源:origin: braintree/braintree_android
public TLSSocketFactory() throws SSLException {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null); // use system security providers
mInternalSSLSocketFactory = sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new SSLException(e.getMessage());
}
}
代码示例来源:origin: apache/tinkerpop
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keystore.load(in, password);
kmf.init(keystore, password);
} else {
throw new IllegalStateException("keyStore must be configured when SSL is enabled.");
truststore.load(in, password);
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(truststore);
builder.trustManager(tmf);
return builder.build();
} catch (SSLException ssle) {
logger.error(ssle.getMessage());
throw new RuntimeException("There was an error enabling SSL.", ssle);
代码示例来源:origin: TooTallNate/Java-WebSocket
int appBufferSize = engine.getSession().getApplicationBufferSize();
myAppData = ByteBuffer.allocate( appBufferSize );
peerAppData = ByteBuffer.allocate( appBufferSize );
peerNetData.clear();
handshakeStatus = engine.getHandshakeStatus();
boolean handshakeComplete = false;
while( !handshakeComplete) {
case NEED_UNWRAP:
if( socketChannel.read( peerNetData ) < 0 ) {
if( engine.isInboundDone() && engine.isOutboundDone() ) {
return false;
break;
switch(result.getStatus()) {
case OK:
break;
throw new IllegalStateException( "Invalid SSL status: " + result.getStatus() );
break;
case BUFFER_UNDERFLOW:
throw new SSLException( "Buffer underflow occured after a wrap. I don't think we should ever get here." );
case CLOSED:
try {
代码示例来源:origin: apache/kafka
case CLOSED:
default:
throw new SSLException("Unexpected handshake status: " + handshakeResult.getStatus());
handshakeResult = sslEngine.unwrap(peerEngine.netBuffer, appBuffer);
peerEngine.netBuffer.compact();
handshakeStatus = handshakeResult.getHandshakeStatus();
switch (handshakeResult.getStatus()) {
case OK: break;
case CLOSED:
default:
throw new SSLException("Unexpected handshake status: " + handshakeResult.getStatus());
case NOT_HANDSHAKING:
if (handshakeResult.getHandshakeStatus() != SSLEngineResult.HandshakeStatus.FINISHED)
throw new SSLException("Did not finish handshake");
return;
default:
代码示例来源:origin: wildfly/wildfly
if (wrap) {
if (TRACE_SSL) msg.tracef("TLS wrap from %s to %s", Buffers.debugString(srcs, srcOff, srcLen), Buffers.debugString(sendBuffer));
result = engine.wrap(srcs, srcOff, srcLen, sendBuffer);
WRAP_RESULT: switch (result.getStatus()) {
case BUFFER_UNDERFLOW: {
assert result.bytesConsumed() == 0;
assert result.bytesProduced() == 0;
result = engine.unwrap(receiveBuffer, realDsts, 0, dstLen + 1);
final long userProduced = preRem - Buffers.remaining(dsts, dstOff, dstLen);
switch (result.getStatus()) {
if (res == -1) {
state &= ~READ_FLAG_READY;
engine.closeInbound();
} else if (res == 0) {
readBlocked = true;
task.run();
} catch (Throwable cause) {
throw new SSLException("Delegated task threw an exception", cause);
代码示例来源:origin: apache/geode
@Override
public synchronized ByteBuffer wrap(ByteBuffer appData) throws IOException {
checkClosed();
myNetData.clear();
while (appData.hasRemaining()) {
// ensure we have lots of capacity since encrypted data might
// be larger than the app data
int remaining = myNetData.capacity() - myNetData.position();
if (remaining < (appData.remaining() * 2)) {
int newCapacity = expandedCapacity(appData, myNetData);
myNetData = expandWriteBuffer(TRACKED_SENDER, myNetData, newCapacity, stats);
}
SSLEngineResult wrapResult = engine.wrap(appData, myNetData);
if (wrapResult.getHandshakeStatus() == NEED_TASK) {
handleBlockingTasks();
}
if (wrapResult.getStatus() != OK) {
throw new SSLException("Error encrypting data: " + wrapResult);
}
}
myNetData.flip();
return myNetData;
}
代码示例来源:origin: apache/ignite
/**
* Writes close_notify message to the network output buffer.
*
* @throws SSLException If wrap failed or SSL engine does not get closed
* after wrap.
* @return {@code True} if <tt>close_notify</tt> message was encoded, {@code false} if outbound
* stream was already closed.
*/
boolean closeOutbound() throws SSLException {
assert isHeldByCurrentThread();
if (!sslEngine.isOutboundDone()) {
sslEngine.closeOutbound();
outNetBuf.clear();
SSLEngineResult res = sslEngine.wrap(handshakeBuf, outNetBuf);
if (res.getStatus() != CLOSED)
throw new SSLException("Incorrect SSL engine status after closeOutbound call [status=" +
res.getStatus() + ", handshakeStatus=" + res.getHandshakeStatus() + ", ses=" + ses + ']');
outNetBuf.flip();
return true;
}
return false;
}
代码示例来源:origin: igniterealtime/Openfire
if (rbc.read(incomingNetBB) == -1) {
try {
tlsEngine.closeInbound();
} catch (javax.net.ssl.SSLException ex) {
if ("Inbound closed before receiving peer's close_notify: possible truncation attack?".equals( ex.getMessage() ) ) {
throw new SSLHandshakeException( "The peer closed the connection while performing a TLS handshake." );
result = tlsEngine.unwrap(incomingNetBB, appBB);
incomingNetBB.compact();
initialHSStatus = result.getHandshakeStatus();
switch (result.getStatus()) {
throw new IOException("Received" + result.getStatus()
+ "during initial handshaking");
result = tlsEngine.wrap(hsBB, outgoingNetBB);
outgoingNetBB.flip();
代码示例来源:origin: apache/nifi
throw new SSLException("Unable to encrypt message because no SSLEngine has been configured");
final SSLEngineResult result = sslEngine.wrap(plaintext, destinationBuffer);
switch (result.getStatus()) {
case OK:
destinationBuffer.flip();
case BUFFER_OVERFLOW:
final ByteBuffer tempBuffer = ByteBuffer.allocate(destinationBuffer.capacity() + sslEngine.getSession().getApplicationBufferSize());
destinationBuffer.flip();
tempBuffer.put(destinationBuffer);
内容来源于网络,如有侵权,请联系作者删除!