use of javax.net.ssl.SSLSocket in project Anki-Android by Ramblurr.
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;
}
use of javax.net.ssl.SSLSocket in project OpenAttestation by OpenAttestation.
the class TASecureServer method waitForConnections.
public void waitForConnections() {
SSLSocket sock = null;
/*
Take ownership of the TPM
*/
takeOwnerShip();
while (true) {
try {
sock = (SSLSocket) serverSock.accept();
log.info("Have accepted new socket.");
/*
Take ownership of the TPM. This time if already ownership is done
* then this method will return. This is fix the bug where sometimes
* tcsd is not up.
*/
takeOwnerShip();
handleConnection(sock.getInputStream(), sock.getOutputStream());
} catch (Exception e) {
log.error(null, e);
} finally {
try {
log.info("Closing socket.");
sock.close();
} catch (IOException ex) {
log.error(null, ex);
}
}
log.info("Finished with socket, waiting for next connection.");
}
}
use of javax.net.ssl.SSLSocket in project phonegap-facebook-plugin by Wizcorp.
the class Connection method upgradeToTls.
/**
* Create an {@code SSLSocket} and perform the TLS handshake and certificate
* validation.
*/
private void upgradeToTls(TunnelRequest tunnelRequest) throws IOException {
Platform platform = Platform.get();
// Make an SSL Tunnel on the first message pair of each SSL + proxy connection.
if (requiresTunnel()) {
makeTunnel(tunnelRequest);
}
// Create the wrapper over connected socket.
socket = route.address.sslSocketFactory.createSocket(socket, route.address.uriHost, route.address.uriPort, true);
SSLSocket sslSocket = (SSLSocket) socket;
if (route.modernTls) {
platform.enableTlsExtensions(sslSocket, route.address.uriHost);
} else {
platform.supportTlsIntolerantServer(sslSocket);
}
if (route.modernTls) {
platform.setNpnProtocols(sslSocket, NPN_PROTOCOLS);
}
// Force handshake. This can throw!
sslSocket.startHandshake();
// Verify that the socket's certificates are acceptable for the target host.
if (!route.address.hostnameVerifier.verify(route.address.uriHost, sslSocket.getSession())) {
throw new IOException("Hostname '" + route.address.uriHost + "' was not verified");
}
out = sslSocket.getOutputStream();
in = sslSocket.getInputStream();
byte[] selectedProtocol;
if (route.modernTls && (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) {
if (Arrays.equals(selectedProtocol, SPDY3)) {
// SPDY timeouts are set per-stream.
sslSocket.setSoTimeout(0);
spdyConnection = new SpdyConnection.Builder(route.address.getUriHost(), true, in, out).build();
} else if (!Arrays.equals(selectedProtocol, HTTP_11)) {
throw new IOException("Unexpected NPN transport " + new String(selectedProtocol, "ISO-8859-1"));
}
}
}
use of javax.net.ssl.SSLSocket in project phonegap-facebook-plugin by Wizcorp.
the class HttpsURLConnectionImpl method getPeerPrincipal.
@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
if (cacheResponse != null) {
return cacheResponse.getPeerPrincipal();
}
SSLSocket sslSocket = getSslSocket();
if (sslSocket != null) {
return sslSocket.getSession().getPeerPrincipal();
}
return null;
}
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);
}
}
}
}
Aggregations