/** * Return true if the specified object equals this object. * @param obj The object to compare against. * @return true if the objects are equal. */ public boolean equals(Object obj) { if (obj instanceof Protocol) { Protocol p = (Protocol) obj; return ( defaultPort == p.getDefaultPort() && scheme.equalsIgnoreCase(p.getScheme()) && secure == p.isSecure() && socketFactory.equals(p.getSocketFactory())); } else { return false; } }
(SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
if (isSecure() && isProxied()) { Protocol defaultprotocol = Protocol.getProtocol("http"); socketFactory = defaultprotocol.getSocketFactory(); } else { socketFactory = this.protocolInUse.getSocketFactory();
public static SSLConnector getSSLConnector() { return (SSLConnector) protocol.getSocketFactory(); }
String scheme = "https"; Protocol baseHttps = Protocol.getProtocol(scheme); int defaultPort = baseHttps.getDefaultPort(); ProtocolSocketFactory baseFactory = baseHttps.getSocketFactory(); ProtocolSocketFactory customFactory = new CustomHttpsSocketFactory(baseFactory); Protocol customHttps = new Protocol(scheme, customFactory, defaultPort); Protocol.registerProtocol(scheme, customHttps);
private static boolean isRegistered() { Protocol https = Protocol.getProtocol("https"); boolean isRegistered = https.getSocketFactory() instanceof UntrustedSSLProtocolSocketFactory; if (!isRegistered) { defaultSSL = https; } return isRegistered; }
public void setActiveCertificate(){ ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory(); if (sslFactory instanceof SSLConnector) { SSLConnector ssl = (SSLConnector) sslFactory; ssl.setActiveCertificate(); } }
public SSLContextManager getSSLContextManager(){ ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory(); if (sslFactory instanceof SSLConnector) { SSLConnector ssl = (SSLConnector) sslFactory; return ssl.getSSLContextManager(); } return null; }
/** * Return true if the specified object equals this object. * @param obj The object to compare against. * @return true if the objects are equal. */ public boolean equals(Object obj) { if (obj instanceof Protocol) { Protocol p = (Protocol) obj; return ( defaultPort == p.getDefaultPort() && scheme.equalsIgnoreCase(p.getScheme()) && secure == p.isSecure() && socketFactory.equals(p.getSocketFactory())); } else { return false; } }
/** * Return true if the specified object equals this object. * @param obj The object to compare against. * @return true if the objects are equal. */ public boolean equals(Object obj) { if (obj instanceof Protocol) { Protocol p = (Protocol) obj; return ( defaultPort == p.getDefaultPort() && scheme.equalsIgnoreCase(p.getScheme()) && secure == p.isSecure() && socketFactory.equals(p.getSocketFactory())); } else { return false; } }
/** * Return true if the specified object equals this object. * @param obj The object to compare against. * @return true if the objects are equal. */ public boolean equals(Object obj) { if (obj instanceof Protocol) { Protocol p = (Protocol) obj; return ( defaultPort == p.getDefaultPort() && scheme.equalsIgnoreCase(p.getScheme()) && secure == p.isSecure() && socketFactory.equals(p.getSocketFactory())); } else { return false; } }
/** * Return true if the specified object equals this object. * @param obj The object to compare against. * @return true if the objects are equal. */ public boolean equals(Object obj) { if (obj instanceof Protocol) { Protocol p = (Protocol) obj; return ( defaultPort == p.getDefaultPort() && scheme.equalsIgnoreCase(p.getScheme()) && secure == p.isSecure() && socketFactory.equals(p.getSocketFactory())); } else { return false; } }
public void setEnableCertificate(boolean enabled) { ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory(); if (sslFactory instanceof SSLConnector) { SSLConnector ssl = (SSLConnector) sslFactory; ssl.setEnableClientCert(enabled); setUseClientCert(enabled); } }
(SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
(SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
private Protocol cloneProtocolKeepingSocketFactory(Protocol protocol) { Protocol original = getProtocol(); if (protocol.getScheme().equals(original.getScheme())) { // the protocol is the same, create a copy of it but keep the original socket factory return new Protocol(protocol.getScheme(), original.getSocketFactory(), protocol.getDefaultPort()); } return protocol; }
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()); }
public void testHttpsVerifyTargetWithCustomSocketFactory() throws Exception { //Override the default SSL socket factory with our own custom one... CustomSocketFactory socketFactory = new CustomSocketFactory(); transmitter.setHttpsSocketFactory(socketFactory); target.setEndpointProtocol(HTTPS_PROTOCOL); target.setEndpointPort(HTTPS_PORT); //Stub HttpClient so that executeMethod returns a 200 response when(mockedHttpClient.executeMethod(any(HostConfiguration.class), any(HttpMethod.class), any(HttpState.class))).thenReturn(200); //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()); //test that the socket factory passed to HttpClient is our custom one (intentional use of '==') assertTrue("socket factory", hostConfig.getValue().getProtocol().getSocketFactory() == socketFactory); assertEquals("protocol", HTTPS_PROTOCOL.toLowerCase(), hostConfig.getValue().getProtocol().getScheme().toLowerCase()); }
/** * Registers or unregisters the proper components for advanced SSL handling. * @throws IOException */ @SuppressWarnings("deprecation") public static void registerAdvancedSslContext(boolean register, Context context) throws GeneralSecurityException, IOException { Protocol pr = null; try { pr = Protocol.getProtocol("https"); if (pr != null && mDefaultHttpsProtocol == null) { mDefaultHttpsProtocol = pr; } } catch (IllegalStateException e) { // nothing to do here; really } boolean isRegistered = (pr != null && pr.getSocketFactory() instanceof AdvancedSslSocketFactory); if (register && !isRegistered) { Protocol.registerProtocol("https", new Protocol("https", getAdvancedSslSocketFactory(context), 443)); } else if (!register && isRegistered) { if (mDefaultHttpsProtocol != null) { Protocol.registerProtocol("https", mDefaultHttpsProtocol); } } }
@Override public synchronized void setHost(URI uri) { try { Protocol original = getProtocol(); if (uri.getScheme().equals(original.getScheme())) { Protocol newProtocol = new Protocol(uri.getScheme(), original.getSocketFactory(), original.getDefaultPort()); super.setHost(uri.getHost(), uri.getPort(), newProtocol); } else { Protocol protoByName = Protocol.getProtocol(uri.getScheme()); super.setHost(uri.getHost(), uri.getPort(), protoByName); } } catch (URIException uriException) { throw new IllegalArgumentException(uriException); } }