use of javax.net.ssl.SSLSocket in project apjp by jvansteirteghem.
the class HTTPSServer method stopHTTPSServer.
protected synchronized void stopHTTPSServer() throws HTTPSServerException {
logger.log(2, "HTTPS_SERVER/STOP_HTTPS_SERVER");
try {
thread = null;
try {
SSLSocket outputSSLSocket = HTTPS.createSSLSocket();
outputSSLSocket.connect(new InetSocketAddress(APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS, sslServerSocket.getLocalPort()));
outputSSLSocket.close();
} catch (Exception e) {
}
try {
sslServerSocket.close();
} catch (Exception e) {
}
} catch (Exception e) {
logger.log(2, "HTTPS_SERVER/STOP_HTTPS_SERVER: EXCEPTION", e);
throw new HTTPSServerException("HTTPS_SERVER/STOP_HTTPS_SERVER", e);
}
}
use of javax.net.ssl.SSLSocket in project apjp by jvansteirteghem.
the class HTTPSServer method run.
public void run() {
while (thread != null) {
try {
SSLSocket inputSSLSocket = (SSLSocket) sslServerSocket.accept();
if (thread != null) {
HTTPSServerWorker httpsServerWorker = new HTTPSServerWorker(this, inputSSLSocket);
startHTTPSServerWorker(httpsServerWorker);
} else {
inputSSLSocket.close();
}
} catch (Exception e) {
if (thread != null) {
logger.log(2, "HTTPS_SERVER: EXCEPTION", e);
}
}
}
}
use of javax.net.ssl.SSLSocket in project k-9 by k9mail.
the class DefaultTrustedSocketFactory method createSocket.
public Socket createSocket(Socket socket, String host, int port, String clientCertificateAlias) throws NoSuchAlgorithmException, KeyManagementException, MessagingException, IOException {
TrustManager[] trustManagers = new TrustManager[] { TrustManagerFactory.get(host, port) };
KeyManager[] keyManagers = null;
if (!TextUtils.isEmpty(clientCertificateAlias)) {
keyManagers = new KeyManager[] { new KeyChainKeyManager(context, clientCertificateAlias) };
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, null);
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
Socket trustedSocket;
if (socket == null) {
trustedSocket = socketFactory.createSocket();
} else {
trustedSocket = socketFactory.createSocket(socket, host, port, true);
}
SSLSocket sslSocket = (SSLSocket) trustedSocket;
hardenSocket(sslSocket);
setSniHost(socketFactory, sslSocket, host);
return trustedSocket;
}
use of javax.net.ssl.SSLSocket in project mongo-java-driver by mongodb.
the class SocketStreamHelper method initialize.
static void initialize(final Socket socket, final ServerAddress address, final SocketSettings settings, final SslSettings sslSettings) throws IOException {
socket.setTcpNoDelay(true);
socket.setSoTimeout(settings.getReadTimeout(MILLISECONDS));
socket.setKeepAlive(settings.isKeepAlive());
if (settings.getReceiveBufferSize() > 0) {
socket.setReceiveBufferSize(settings.getReceiveBufferSize());
}
if (settings.getSendBufferSize() > 0) {
socket.setSendBufferSize(settings.getSendBufferSize());
}
if (sslSettings.isEnabled() || socket instanceof SSLSocket) {
if (!(socket instanceof SSLSocket)) {
throw new MongoInternalException("SSL is enabled but the socket is not an instance of javax.net.ssl.SSLSocket");
}
SSLSocket sslSocket = (SSLSocket) socket;
SSLParameters sslParameters = sslSocket.getSSLParameters();
enableSni(address, sslParameters);
if (!sslSettings.isInvalidHostNameAllowed()) {
enableHostNameVerification(sslParameters);
}
sslSocket.setSSLParameters(sslParameters);
}
socket.connect(address.getSocketAddress(), settings.getConnectTimeout(MILLISECONDS));
}
use of javax.net.ssl.SSLSocket in project ignition by mttkay.
the class EasySSLSocketFactory method connectSocket.
/**
* @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
* java.lang.String, int, java.net.InetAddress, int, org.apache.http.params.HttpParams)
*/
@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
if ((localAddress != null) || (localPort > 0)) {
// we need to bind explicitly
if (localPort < 0) {
// indicates "any"
localPort = 0;
}
InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
sslsock.bind(isa);
}
sslsock.connect(remoteAddress, connTimeout);
sslsock.setSoTimeout(soTimeout);
return sslsock;
}
Aggregations