@Override public OutputStream getOutputStream() throws IOException { return sock.getOutputStream(); }
public OutputStream getOutputStream() throws IOException { return delegate.getOutputStream(); }
@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); } }
public void fetchSecretKeyFrom(Address target) throws Exception { try(SSLSocket sock=createSocketTo(target)) { DataInput in=new DataInputStream(sock.getInputStream()); OutputStream out=sock.getOutputStream(); // send the secret key request out.write(Type.SECRET_KEY_REQ.ordinal()); out.flush(); byte ordinal=in.readByte(); Type rsp=Type.values()[ordinal]; if(rsp != Type.SECRET_KEY_RSP) throw new IllegalStateException(String.format("expected response of %s but got type=%d", Type.SECRET_KEY_RSP, ordinal)); int version_len=in.readInt(); byte[] version=new byte[version_len]; in.readFully(version); int secret_key_len=in.readInt(); byte[] secret_key=new byte[secret_key_len]; in.readFully(secret_key); SecretKey sk=new SecretKeySpec(secret_key, secret_key_algorithm); Tuple<SecretKey,byte[]> tuple=new Tuple<>(sk, version); log.debug("%s: sending up secret key (version: %s)", local_addr, Util.byteArrayToHexString(version)); up_prot.up(new Event(Event.SET_SECRET_KEY, tuple)); } }
public void upgradeToSSL(SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier) throws IOException { SSLSocket sslSocket = sslSocketFactory.createSocket(this.socket); sslSocket.startHandshake(); socket = sslSocket; inputStream = new ByteArrayInputStream(sslSocket.getInputStream()); outputStream = new ByteArrayOutputStream(sslSocket.getOutputStream()); if (hostnameVerifier != null && !hostnameVerifier.verify(sslSocket.getInetAddress().getHostName(), sslSocket.getSession())) { throw new IdentityVerificationException("\"" + sslSocket.getInetAddress().getHostName() + "\" identity was not confirmed"); } }
BufferedOutputStream writer = new BufferedOutputStream(client.getOutputStream());
DataOutput out=new DataOutputStream(client_sock.getOutputStream());
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())); }
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())); }
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())); }
output = sslSocket.getOutputStream(); output.write(("" + "GET /not_found HTTP/1.1\r\n" +
clientSocket = x509Util.createSSLSocket(); clientSocket.connect(localServerAddress); clientSocket.getOutputStream().write(1); clientSocket.getOutputStream().write(1);
sslSocket = sslSocketFactory().wrapSocket(socket); output = sslSocket.getOutputStream();
@Test public void connectionFailsWithoutValidServerCertificate() throws IOException, StoreConfigurationException { final TrustStoreConfiguration tsc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null); final SslConfiguration sc = SslConfiguration.createSSLConfiguration(null, null, tsc); final SSLSocketFactory factory = sc.getSslSocketFactory(); try { try (final SSLSocket clientSocket = (SSLSocket) factory.createSocket(TLS_TEST_HOST, TLS_TEST_PORT)) { try (final OutputStream os = clientSocket.getOutputStream()) { os.write("GET config/login_verify2?".getBytes()); Assert.fail("Expected IOException"); } catch (final IOException e) { // Expected, do nothing. } } } catch (final UnknownHostException offline) { // this exception is thrown on Windows when offline } }
@Override public OutputStream getOutputStream() throws IOException { return sock.getOutputStream(); }
/** new in Java 7 */ public SocketChannel shutdownOutput() throws IOException { _socket.getOutputStream().close(); return this; }
public int write(ByteBuffer src) throws IOException { if (!src.hasArray()) throw new UnsupportedOperationException(); int pos = src.position(); int len = src.remaining(); _socket.getOutputStream().write(src.array(), src.arrayOffset() + pos, len); src.position(pos + len); return len; }
@Override public void upgradeToSsl() { if (sslSocket != null) // Already upgraded return; if (verbose) System.out.println("[" + this + "] INFO: Upgrading socket to SSL."); try { // Use most secure implementation of SSL available now. // JVM will try to negotiate TLS1.2, then will fallback to TLS1.0, if // TLS1.2 is not supported. SSLContext sslContext = SSLUtils.getSSLContext(); // Trust all certificates (FIXME: insecure) sslContext.init(null, new TrustManager[] {new TrustAllX509TrustManager(sslState)}, null); SSLSocketFactory sslSocketFactory = new SecureSSLSocketFactory(sslContext); sslSocket = (SSLSocket)sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true); sslSocket.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslSocket.getEnabledProtocols())); sslSocket.startHandshake(); InputStream sis = sslSocket.getInputStream(); source.setInputStream(sis); OutputStream sos = sslSocket.getOutputStream(); sink.setOutputStream(sos); } catch (Exception e) { throw new RuntimeException("Cannot upgrade socket to SSL: " + e.getMessage(), e); } }
_output_ = socket.getOutputStream(); _reader = new CRLFLineReader(new InputStreamReader(_input_, _DEFAULT_ENCODING)); _writer = new BufferedWriter(new OutputStreamWriter(_output_, _DEFAULT_ENCODING));
_output_ = socket.getOutputStream(); _reader = new CRLFLineReader( new InputStreamReader(_input_, encoding));