use of javax.net.ssl.SSLSocket in project hbase by apache.
the class SslRMIClientSocketFactorySecure method createSocket.
@Override
public Socket createSocket(String host, int port) throws IOException {
SSLSocket socket = (SSLSocket) super.createSocket(host, port);
ArrayList<String> secureProtocols = new ArrayList<>();
for (String p : socket.getEnabledProtocols()) {
if (!p.contains("SSLv3")) {
secureProtocols.add(p);
}
}
socket.setEnabledProtocols(secureProtocols.toArray(new String[secureProtocols.size()]));
return socket;
}
use of javax.net.ssl.SSLSocket in project kafka by apache.
the class EchoServer method run.
@Override
public void run() {
try {
while (true) {
final Socket socket = serverSocket.accept();
sockets.add(socket);
Thread thread = new Thread() {
@Override
public void run() {
try {
DataInputStream input = new DataInputStream(socket.getInputStream());
DataOutputStream output = new DataOutputStream(socket.getOutputStream());
while (socket.isConnected() && !socket.isClosed()) {
int size = input.readInt();
if (renegotiate.get()) {
renegotiate.set(false);
((SSLSocket) socket).startHandshake();
}
byte[] bytes = new byte[size];
input.readFully(bytes);
output.writeInt(size);
output.write(bytes);
output.flush();
}
} catch (IOException e) {
// ignore
} finally {
try {
socket.close();
} catch (IOException e) {
// ignore
}
}
}
};
thread.start();
threads.add(thread);
}
} catch (IOException e) {
// ignore
}
}
use of javax.net.ssl.SSLSocket in project tomcat by apache.
the class TestSsl method testRenegotiateWorks.
@Test
public void testRenegotiateWorks() throws Exception {
Tomcat tomcat = getTomcatInstance();
Assume.assumeTrue("SSL renegotiation has to be supported for this test", TesterSupport.isClientRenegotiationSupported(getTomcatInstance()));
Context root = tomcat.addContext("", TEMP_DIR);
Wrapper w = Tomcat.addServlet(root, "tester", new TesterServlet());
w.setAsyncSupported(true);
root.addServletMappingDecoded("/", "tester");
TesterSupport.initSsl(tomcat);
tomcat.start();
SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(null, TesterSupport.getTrustManagers(), null);
SSLSocketFactory socketFactory = sslCtx.getSocketFactory();
SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", getPort());
OutputStream os = socket.getOutputStream();
InputStream is = socket.getInputStream();
Reader r = new InputStreamReader(is);
doRequest(os, r);
TesterHandshakeListener listener = new TesterHandshakeListener();
socket.addHandshakeCompletedListener(listener);
socket.startHandshake();
// One request should be sufficient
int requestCount = 0;
int listenerComplete = 0;
try {
while (requestCount < 10) {
requestCount++;
doRequest(os, r);
if (listener.isComplete() && listenerComplete == 0) {
listenerComplete = requestCount;
}
}
} catch (AssertionError | IOException e) {
String message = "Failed on request number " + requestCount + " after startHandshake(). " + e.getMessage();
log.error(message, e);
Assert.fail(message);
}
Assert.assertTrue(listener.isComplete());
System.out.println("Renegotiation completed after " + listenerComplete + " requests");
}
use of javax.net.ssl.SSLSocket in project jetty.project by eclipse.
the class JDK9ALPNTest method testClientNotSupportingALPNServerSpeaksDefaultProtocol.
@Test
public void testClientNotSupportingALPNServerSpeaksDefaultProtocol() throws Exception {
startServer(new AbstractHandler.ErrorDispatchHandler() {
@Override
protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
}
});
SslContextFactory sslContextFactory = new SslContextFactory(true);
sslContextFactory.start();
SSLContext sslContext = sslContextFactory.getSslContext();
try (SSLSocket client = (SSLSocket) sslContext.getSocketFactory().createSocket("localhost", connector.getLocalPort())) {
client.setUseClientMode(true);
client.setSoTimeout(5000);
client.startHandshake();
OutputStream output = client.getOutputStream();
output.write(("" + "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: close\r\n" + "\r\n" + "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 200 "));
while (true) {
if (reader.readLine() == null)
break;
}
}
}
use of javax.net.ssl.SSLSocket in project jetty.project by eclipse.
the class SslContextFactory method newSslSocket.
public SSLSocket newSslSocket() throws IOException {
checkIsStarted();
SSLContext context = getSslContext();
SSLSocketFactory factory = context.getSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket();
socket.setSSLParameters(customize(socket.getSSLParameters()));
return socket;
}
Aggregations