本文整理了Java中javax.net.ssl.SSLSocketFactory
类的一些代码示例,展示了SSLSocketFactory
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLSocketFactory
类的具体详情如下:
包路径:javax.net.ssl.SSLSocketFactory
类名称:SSLSocketFactory
[英]The abstract factory implementation to create SSLSockets.
[中]创建SSLSockets的抽象工厂实现。
代码示例来源:origin: square/okhttp
private void processHandshakeFailure(Socket raw) throws Exception {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[] {UNTRUSTED_TRUST_MANAGER}, new SecureRandom());
SSLSocketFactory sslSocketFactory = context.getSocketFactory();
SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(
raw, raw.getInetAddress().getHostAddress(), raw.getPort(), true);
try {
socket.startHandshake(); // we're testing a handshake failure
throw new AssertionError();
} catch (IOException expected) {
}
socket.close();
}
代码示例来源:origin: cSploit/android
public ProxyThread(Socket socket, OnRequestListener listener, ArrayList<Proxy.ProxyFilter> filters, String hostRedirection, int portRedirection) throws IOException{
super("ProxyThread");
mSocket = socket;
mWriter = null;
mReader = mSocket.getInputStream();
mRequestListener = listener;
mFilters = filters;
mHostRedirect = hostRedirection;
mPortRedirect = portRedirection;
mSocketFactory = SSLSocketFactory.getDefault();
}
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Returns the supported cipher suites.
*
* @return the supported cipher suites
*/
@Override
public String[] getSupportedCipherSuites() {
return sslCtxt.getSocketFactory().getSupportedCipherSuites();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
*/
public Socket createSocket(
Socket socket,
String host,
int port,
boolean autoClose)
throws IOException, UnknownHostException {
return ((SSLSocketFactory) SSLSocketFactory.getDefault()).createSocket(
socket,
host,
port,
autoClose
);
}
代码示例来源:origin: stackoverflow.com
return delegate.getDefaultCipherSuites();
return delegate.getSupportedCipherSuites();
return makeSocketSafe(delegate.createSocket(s, host, port, autoClose));
return makeSocketSafe(delegate.createSocket(host, port));
return makeSocketSafe(delegate.createSocket(host, port, localHost, localPort));
return makeSocketSafe(delegate.createSocket(host, port));
if (protocols != null && protocols.length == 1 && "SSLv3".equals(protocols[0])) {
List<String> enabledProtocols = new ArrayList<String>(Arrays.asList(delegate.getEnabledProtocols()));
if (enabledProtocols.size() > 1) {
enabledProtocols.remove("SSLv3");
return delegate.getSupportedCipherSuites();
return delegate.getEnabledCipherSuites();
delegate.bind(localAddr);
delegate.close();
delegate.connect(remoteAddr);
代码示例来源:origin: TooTallNate/Java-WebSocket
boolean isNewSocket = false;
if (socketFactory != null) {
socket = socketFactory.createSocket();
} else if( socket == null ) {
socket = new Socket( proxy );
isNewSocket = true;
} else if( socket.isClosed() ) {
throw new IOException();
socket.setTcpNoDelay( isTcpNoDelay() );
socket.setReuseAddress( isReuseAddr() );
if( !socket.isBound() ) {
socket.connect( new InetSocketAddress( uri.getHost(), getPort() ), connectTimeout );
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, null, null);
SSLSocketFactory factory = sslContext.getSocketFactory();
socket = factory.createSocket(socket, uri.getHost(), getPort(), true);
代码示例来源:origin: apache/zookeeper
LOG.info("connecting to {} {}", host, port);
Socket sock;
InetSocketAddress hostaddress= host != null ? new InetSocketAddress(host, port) :
new InetSocketAddress(InetAddress.getByName(null), port);
if (secure) {
LOG.info("using secure socket");
try (X509Util x509Util = new ClientX509Util()) {
SSLContext sslContext = x509Util.getDefaultSSLContext();
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
SSLSocket sslSock = (SSLSocket) socketFactory.createSocket();
sslSock.connect(hostaddress, timeout);
sslSock.startHandshake();
sock = sslSock;
sock = new Socket();
sock.connect(hostaddress, timeout);
sock.setSoTimeout(timeout);
BufferedReader reader = null;
try {
代码示例来源:origin: stackoverflow.com
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { tm }, null);
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
return sslContext.getSocketFactory().createSocket();
代码示例来源:origin: prestodb/presto
private static TTransport createRaw(HostAndPort address, Optional<SSLContext> sslContext, Optional<HostAndPort> socksProxy, int timeoutMillis)
throws TTransportException
{
Proxy proxy = socksProxy
.map(socksAddress -> new Proxy(SOCKS, InetSocketAddress.createUnresolved(socksAddress.getHost(), socksAddress.getPort())))
.orElse(Proxy.NO_PROXY);
Socket socket = new Socket(proxy);
try {
socket.connect(new InetSocketAddress(address.getHost(), address.getPort()), timeoutMillis);
socket.setSoTimeout(timeoutMillis);
if (sslContext.isPresent()) {
// SSL will connect to the SOCKS address when present
HostAndPort sslConnectAddress = socksProxy.orElse(address);
socket = sslContext.get().getSocketFactory().createSocket(socket, sslConnectAddress.getHost(), sslConnectAddress.getPort(), true);
}
return new TSocket(socket);
}
catch (Throwable t) {
// something went wrong, close the socket and rethrow
try {
socket.close();
}
catch (IOException e) {
t.addSuppressed(e);
}
throw new TTransportException(t);
}
}
代码示例来源:origin: stackoverflow.com
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
return context;
InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
sslsock.bind(isa);
sslsock.connect(remoteAddress, connTimeout);
sslsock.setSoTimeout(soTimeout);
return sslsock;
return getSSLContext().getSocketFactory().createSocket();
UnknownHostException
return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose);
代码示例来源:origin: k9mail/k-9
private void upgradeToTls(Socket socket) throws KeyStoreException, IOException, NoSuchAlgorithmException,
CertificateException, UnrecoverableKeyException, KeyManagementException {
KeyStore keyStore = keyStoreProvider.getKeyStore();
String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(defaultAlgorithm);
keyManagerFactory.init(keyStore, keyStoreProvider.getPassword());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
sslSocket.setUseClientMode(false);
sslSocket.startHandshake();
input = Okio.buffer(Okio.source(sslSocket.getInputStream()));
output = Okio.buffer(Okio.sink(sslSocket.getOutputStream()));
}
代码示例来源:origin: glyptodon/guacamole-client
SocketFactory socket_factory = SSLSocketFactory.getDefault();
SocketAddress address = new InetSocketAddress(
InetAddress.getByName(hostname),
port
sock = socket_factory.createSocket();
sock.connect(address, SOCKET_TIMEOUT);
sock.setSoTimeout(SOCKET_TIMEOUT);
reader = new ReaderGuacamoleReader(new InputStreamReader(sock.getInputStream(), "UTF-8"));
writer = new WriterGuacamoleWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
代码示例来源:origin: apache/nifi
socket = new Socket(address.getHostName(), address.getPort());
} else {
socket = sslContext.getSocketFactory().createSocket(address.getHostName(), address.getPort());
socket.setSoTimeout(config.getSocketTimeout());
socket.setReuseAddress(config.getReuseAddress());
代码示例来源:origin: apache/kafka
@Override
public void run() {
try {
SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, new TrustManager[]{new NaiveTrustManager()}, new java.security.SecureRandom());
try (SSLSocket connection = (SSLSocket) sc.getSocketFactory().createSocket(serverAddress.getAddress(), serverAddress.getPort())) {
OutputStream os = connection.getOutputStream();
connection.startHandshake();
handshaked.countDown();
os.write(payload);
os.flush();
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
代码示例来源:origin: k9mail/k-9
@Override
public Socket createSocket(Socket socket, String host, int port, String clientCertificateAlias)
throws NoSuchAlgorithmException, KeyManagementException, MessagingException, IOException {
TrustManager[] trustManagers = new TrustManager[] { new VeryTrustingTrustManager(serverCertificate) };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return sslSocketFactory.createSocket(
socket,
socket.getInetAddress().getHostAddress(),
socket.getPort(),
true);
}
}
代码示例来源:origin: stackoverflow.com
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { tm }, null);
public Socket createSocket(Socket socket, String host, int port,
boolean autoClose) throws IOException, UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host, port,
autoClose);
return sslContext.getSocketFactory().createSocket();
ClientConnectionManager ccm = client.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
DefaultHttpClient sslClient = new DefaultHttpClient(ccm,
client.getParams());
代码示例来源:origin: stackoverflow.com
SSLSocketFactory factory = m_ctx.getSocketFactory();
SSLSocket ss = (SSLSocket)factory.createSocket(s, host, port, autoClose);
ss.setEnabledProtocols(m_protocols);
ss.setEnabledCipherSuites(m_ciphers);
SSLSocketFactory factory = m_ctx.getSocketFactory();
SSLSocket ss = (SSLSocket)factory.createSocket(address, port, localAddress, localPort);
ss.setEnabledProtocols(m_protocols);
ss.setEnabledCipherSuites(m_ciphers);
SSLSocketFactory factory = m_ctx.getSocketFactory();
SSLSocket ss = (SSLSocket)factory.createSocket(host, port, localHost, localPort);
ss.setEnabledProtocols(m_protocols);
SSLSocketFactory factory = m_ctx.getSocketFactory();
SSLSocket ss = (SSLSocket)factory.createSocket(host, port);
ss.setEnabledProtocols(m_protocols);
socket.close();
SSLSocketFactory factory = m_ctx.getSocketFactory();
availableCiphers = factory.getSupportedCipherSuites();
Arrays.sort(availableCiphers);
代码示例来源:origin: oblac/jodd
socket = socketFactory.createSocket(host, port);
socket = new Socket();
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
sslSocket = (SSLSocket) ((SSLSocketFactory)socketFactory).createSocket(socket, host, port, true);
sslSocket = (SSLSocket) (getDefaultSSLSocketFactory(trustAll)).createSocket(socket, host, port, true);
sslSocket.setEnabledProtocols(values);
sslSocket.setSSLParameters(sslParams);
代码示例来源:origin: apache/ignite
/**
* Creates socket binding it to a local host address. This operation is not blocking.
*
* @return Created socket.
* @throws IOException If failed.
*/
Socket createSocket() throws IOException {
Socket sock = null;
try {
if (isSslEnabled())
sock = sslSockFactory.createSocket();
else
sock = new Socket();
sock.bind(new InetSocketAddress(locHost, 0));
sock.setTcpNoDelay(true);
return sock;
} catch (IOException e) {
if (sock != null)
U.closeQuiet(sock);
throw e;
}
}
代码示例来源:origin: runelite/runelite
SocketFactory socketFactory = SSLSocketFactory.getDefault();
socket = socketFactory.createSocket(HOST, PORT);
socket.setSoTimeout(READ_TIMEOUT);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream());
内容来源于网络,如有侵权,请联系作者删除!