use of org.eclipse.jetty.io.ssl.SslConnection in project jetty.project by eclipse.
the class SecureRequestCustomizer method customize.
@Override
public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
EndPoint endp = request.getHttpChannel().getEndPoint();
if (endp instanceof DecryptedEndPoint) {
SslConnection.DecryptedEndPoint ssl_endp = (DecryptedEndPoint) endp;
SslConnection sslConnection = ssl_endp.getSslConnection();
SSLEngine sslEngine = sslConnection.getSSLEngine();
customize(sslEngine, request);
if (request.getHttpURI().getScheme() == null)
request.setScheme(HttpScheme.HTTPS.asString());
} else if (endp instanceof ProxyConnectionFactory.ProxyEndPoint) {
ProxyConnectionFactory.ProxyEndPoint proxy = (ProxyConnectionFactory.ProxyEndPoint) endp;
if (request.getHttpURI().getScheme() == null && proxy.getAttribute(ProxyConnectionFactory.TLS_VERSION) != null)
request.setScheme(HttpScheme.HTTPS.asString());
}
if (HttpScheme.HTTPS.is(request.getScheme()))
customizeSecure(request);
}
use of org.eclipse.jetty.io.ssl.SslConnection in project jetty.project by eclipse.
the class SslConnectionTest method testSslConnectionClosedBeforeFill.
@Test
public void testSslConnectionClosedBeforeFill() throws Exception {
File keyStore = MavenTestingUtils.getTestResourceFile("keystore.jks");
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keyStore.getAbsolutePath());
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.start();
ByteBufferPool byteBufferPool = new MappedByteBufferPool();
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.start();
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
SSLEngine sslEngine = sslContextFactory.newSSLEngine();
sslEngine.setUseClientMode(false);
SslConnection sslConnection = new SslConnection(byteBufferPool, threadPool, endPoint, sslEngine);
EndPoint sslEndPoint = sslConnection.getDecryptedEndPoint();
sslEndPoint.setConnection(new AbstractConnection(sslEndPoint, threadPool) {
@Override
public void onFillable() {
}
});
// There are no bytes in the endPoint, so we fill zero.
// However, this will trigger state changes in SSLEngine
// that will later cause it to throw ISE("Internal error").
sslEndPoint.fill(BufferUtil.EMPTY_BUFFER);
// Close the connection before filling.
sslEndPoint.shutdownOutput();
// Put some bytes in the endPoint to trigger
// the required state changes in SSLEngine.
byte[] bytes = new byte[] { 0x16, 0x03, 0x03, 0x00, 0x00 };
endPoint.addInput(ByteBuffer.wrap(bytes));
// reads from the EndPoint.
try {
sslEndPoint.fill(BufferUtil.EMPTY_BUFFER);
Assert.fail();
} catch (SSLHandshakeException x) {
// Expected.
}
}
Aggregations