public void testSuccessfulVerifyTargetOverHttps() throws Exception { //Stub HttpClient so that executeMethod returns a 200 response when(mockedHttpClient.executeMethod(any(HostConfiguration.class), any(HttpMethod.class), any(HttpState.class))).thenReturn(200); target.setEndpointProtocol(HTTPS_PROTOCOL); target.setEndpointPort(HTTPS_PORT); //Call verifyTarget transmitter.verifyTarget(target); ArgumentCaptor<HostConfiguration> hostConfig = ArgumentCaptor.forClass(HostConfiguration.class); ArgumentCaptor<HttpMethod> httpMethod = ArgumentCaptor.forClass(HttpMethod.class); ArgumentCaptor<HttpState> httpState = ArgumentCaptor.forClass(HttpState.class); verify(mockedHttpClient).executeMethod(hostConfig.capture(), httpMethod.capture(), httpState.capture()); assertEquals("port", HTTPS_PORT, hostConfig.getValue().getPort()); assertTrue("socket factory", hostConfig.getValue().getProtocol().getSocketFactory() instanceof SecureProtocolSocketFactory); assertEquals("protocol", HTTPS_PROTOCOL.toLowerCase(), hostConfig.getValue().getProtocol().getScheme().toLowerCase()); }
private HostConfiguration setupSSLIfNeeded(Settings settings, HostConfiguration hostConfig) { if (!sslEnabled) { return hostConfig; } // we actually have a socks proxy, let's start the setup if (log.isDebugEnabled()) { log.debug("SSL Connection enabled"); } // // switch protocol // due to how HttpCommons work internally this dance is best to be kept as is // String schema = "https"; int port = 443; SecureProtocolSocketFactory sslFactory = new SSLSocketFactory(settings); replaceProtocol(hostConfig, sslFactory, schema, port); return hostConfig; }
private HostConfiguration setupSSLIfNeeded(Settings settings, HostConfiguration hostConfig) { if (!sslEnabled) { return hostConfig; } // we actually have a socks proxy, let's start the setup if (log.isDebugEnabled()) { log.debug("SSL Connection enabled"); } // // switch protocol // due to how HttpCommons work internally this dance is best to be kept as is // String schema = "https"; int port = 443; SecureProtocolSocketFactory sslFactory = new SSLSocketFactory(settings); replaceProtocol(sslFactory, schema, port); return hostConfig; }
/** * Instructs the proxy to establish a secure tunnel to the host. The socket will * be switched to the secure socket. Subsequent communication is done via the secure * socket. The method can only be called once on a proxied secure connection. * * @throws IllegalStateException if connection is not secure and proxied or * if the socket is already secure. * @throws IOException if an attempt to establish the secure tunnel results in an * I/O error. */ public void tunnelCreated() throws IllegalStateException, IOException { LOG.trace("enter HttpConnection.tunnelCreated()"); if (!isSecure() || !isProxied()) { throw new IllegalStateException( "Connection must be secure " + "and proxied to use this feature"); } if (usingSecureSocket) { throw new IllegalStateException("Already using a secure socket"); } if (LOG.isDebugEnabled()) { LOG.debug("Secure tunnel to " + this.hostName + ":" + this.portNumber); } SecureProtocolSocketFactory socketFactory = (SecureProtocolSocketFactory) protocolInUse.getSocketFactory(); socket = socketFactory.createSocket(socket, hostName, portNumber, true); int sndBufSize = this.params.getSendBufferSize(); if (sndBufSize >= 0) { socket.setSendBufferSize(sndBufSize); } int rcvBufSize = this.params.getReceiveBufferSize(); if (rcvBufSize >= 0) { socket.setReceiveBufferSize(rcvBufSize); } int outbuffersize = socket.getSendBufferSize(); if (outbuffersize > 2048) { outbuffersize = 2048; } int inbuffersize = socket.getReceiveBufferSize(); if (inbuffersize > 2048) { inbuffersize = 2048; } inputStream = new BufferedInputStream(socket.getInputStream(), inbuffersize); outputStream = new BufferedOutputStream(socket.getOutputStream(), outbuffersize); usingSecureSocket = true; tunnelEstablished = true; }
/** * Gets the protocol socket factory used for the https scheme. * * @return protocol socket factory used for the https scheme */ public SecureProtocolSocketFactory getHttpsProtocolSocketFactory() { return httpsProtocolSocketFactory; }
/** * Sets the protocol socket factory used for the https scheme. * * @param factory the httpsProtocolSocketFactory to set */ public void setHttpsProtocolSocketFactory(SecureProtocolSocketFactory factory) { httpsProtocolSocketFactory = factory; }