List of usage examples for javax.net.ssl SSLSocket setUseClientMode
public abstract void setUseClientMode(boolean mode);
From source file:cache.reverseproxy.CacheableServicesReverseProxy.java
public static Socket createSecureSocket(String host, int port) throws IOException { SSLSocketFactory sslFactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket newSocket = (SSLSocket) sslFactory.createSocket(host, port); newSocket.setUseClientMode(true); newSocket.startHandshake();//from w w w .jav a 2 s. co m return newSocket; }
From source file:Messenger.TorLib.java
public static void postToURL(String hostname, int port, String postKey, String data) throws IOException { Socket socket = TorSocket(hostname, port); SSLSocketFactory sslSf = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslSocket = (SSLSocket) sslSf.createSocket(socket, null, socket.getPort(), false); sslSocket.setUseClientMode(true); sslSocket.startHandshake();//ww w . j ava 2s .co m String path = "/" + postKey; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sslSocket.getOutputStream(), "UTF8")); wr.write("POST " + path + " HTTP/1.0\r\n"); wr.write("Content-Length: " + data.length() + "\r\n"); wr.write("Content-Type: application/x-www-form-urlencoded\r\n"); wr.write("\r\n"); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(sslSocket.getInputStream())); String line; while ((line = rd.readLine()) != null) { System.out.println(line); } wr.close(); rd.close(); sslSocket.close(); }
From source file:Messenger.TorLib.java
/** * This method makes a http GET request for the specified resource to the specified hostname. * It uses the SOCKS proxy to a connection over Tor. * The DNS lookup is also done over Tor. * This method only uses port 443 for SSL. * * @param hostname hostname for target server. * @param port port to connect to.// w w w. j a v a2s . c om * @param resource resource to lookup with GET request. * @return returns a JSON object. * @throws IOException * @throws JSONException */ public static JSONObject getJSON(String hostname, int port, String resource) throws IOException, JSONException, HttpException { //Create a SSL socket using Tor Socket socket = TorSocket(hostname, port); SSLSocketFactory sslSf = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslSocket = (SSLSocket) sslSf.createSocket(socket, null, socket.getPort(), false); sslSocket.setUseClientMode(true); sslSocket.startHandshake(); openSockets.add(sslSocket); //Create the HTTP GET request and push it over the outputstream BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sslSocket.getOutputStream(), "UTF8")); wr.write("GET /" + resource + " HTTP/1.0\r\n"); wr.write("Host: " + hostname + "\r\n"); wr.write("\r\n"); wr.flush(); //Listen for a response on the inputstream BufferedReader br = new BufferedReader(new InputStreamReader(sslSocket.getInputStream())); String t; boolean start = false; String output = ""; while ((t = br.readLine()) != null) { if (t.equals("")) { start = true; } if (start) { output = output + t; } } br.close(); wr.close(); sslSocket.close(); System.out.println(output); openSockets.remove(sslSocket); return new JSONObject(output); }
From source file:de.fun2code.google.cloudprint.push.PushReceiver.java
/** * Sets up the SSL socket for use with XMPP. * /*from ww w . j av a2 s .c om*/ * @param socket * the socket to do TLS over. * @return The SSL Socket. * @throws IOException */ public static SSLSocket setupSSLSocket(Socket socket) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException, IOException { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); TrustManagerFactory tfactory = TrustManagerFactory.getInstance("SunPKIX"); tfactory.init(keyStore); SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslsocket = (SSLSocket) factory.createSocket(socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true); sslsocket.setUseClientMode(true); return sslsocket; }
From source file:com.myJava.file.driver.remote.ftp.FTPSClient.java
protected Socket _openDataConnection_(int command, String arg) throws IOException { SSLSocket socket = (SSLSocket) super._openDataConnection_(command, arg); if (socket != null) { socket.setEnableSessionCreation(true); socket.setUseClientMode(true); socket.startHandshake();//from w ww.ja v a 2 s . co m } return socket; }
From source file:com.subgraph.vega.internal.http.proxy.VegaHttpService.java
private SSLSocket createSSLSocketForHost(HttpHost host, Socket socket) throws IOException { final SSLContext ctx = sslContextRepository.getContextForName(host.getHostName()); if (ctx == null) { throw new IOException("Failed to create SSLContext for host " + host.getHostName()); }//from w ww .j a v a 2 s .co m SSLSocketFactory sslSocketFactory = ctx.getSocketFactory(); SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket, host.getHostName(), host.getPort(), true); sslSocket.setUseClientMode(false); return sslSocket; }
From source file:org.apache.ftpserver.ssl.Ssl.java
/** * Create a secure socket./*from www . j ava 2 s . co m*/ */ public Socket createSocket(String protocol, InetAddress addr, int port, boolean clientMode) throws Exception { // get socket factory SSLContext ctx = getSSLContext(protocol); SSLSocketFactory socFactory = ctx.getSocketFactory(); // create socket SSLSocket ssoc = (SSLSocket) socFactory.createSocket(addr, port); ssoc.setUseClientMode(clientMode); // initialize socket String cipherSuites[] = ssoc.getSupportedCipherSuites(); ssoc.setEnabledCipherSuites(cipherSuites); return ssoc; }
From source file:org.apache.ftpserver.ssl.Ssl.java
/** * Returns a socket layered over an existing socket. *///w w w.jav a 2 s . c o m public Socket createSocket(String protocol, Socket soc, boolean clientMode) throws Exception { // already wrapped - no need to do anything if (soc instanceof SSLSocket) { return soc; } // get socket factory SSLContext ctx = getSSLContext(protocol); SSLSocketFactory socFactory = ctx.getSocketFactory(); // create socket String host = soc.getInetAddress().getHostAddress(); int port = soc.getLocalPort(); SSLSocket ssoc = (SSLSocket) socFactory.createSocket(soc, host, port, true); ssoc.setUseClientMode(clientMode); // initialize socket String cipherSuites[] = ssoc.getSupportedCipherSuites(); ssoc.setEnabledCipherSuites(cipherSuites); ssoc.setNeedClientAuth(m_clientAuthReqd); return ssoc; }
From source file:com.myJava.file.driver.remote.ftp.SecuredSocketFactory.java
private void init(SSLSocket socket) throws IOException { socket.setEnableSessionCreation(true); socket.setUseClientMode(true); socket.startHandshake();//from w w w. ja va 2 s .co m client.setNegociated(); }
From source file:com.apporiented.hermesftp.cmd.impl.FtpCmdAuth.java
private SSLSocket createSslSocket() throws IOException { String clientHost = getCtx().getClientSocket().getInetAddress().getHostAddress(); SSLContext sslContext = getCtx().getOptions().getSslContext(); SSLSocketFactory factory = sslContext.getSocketFactory(); SSLSocket sslSocket = (SSLSocket) factory.createSocket(getCtx().getClientSocket(), clientHost, getCtx().getOptions().getFtpPort(), true); sslSocket.setUseClientMode(false); sslSocket.addHandshakeCompletedListener(this); enableCipherSuites(sslSocket);//from w ww . ja v a2 s . co m log.info("Enabled cipher suites (explicit SSL): " + StringUtils.arrayToCommaDelimitedString(sslSocket.getEnabledCipherSuites())); return sslSocket; }