Java Code Examples for org.apache.http.conn.ssl.SSLConnectionSocketFactory#getSystemSocketFactory()

The following examples show how to use org.apache.http.conn.ssl.SSLConnectionSocketFactory#getSystemSocketFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PGPKeysServerClientHttps.java    From pgpverify-maven-plugin with Apache License 2.0 5 votes vote down vote up
protected PGPKeysServerClientHttps(URI uri, int connectTimeout, int readTimeout, int maxAttempts, Proxy proxy)
        throws IOException {

    super(prepareKeyServerURI(uri), connectTimeout, readTimeout, maxAttempts, proxy);

    try {
        if (uri.getHost().toLowerCase(Locale.ROOT).endsWith("sks-keyservers.net")) {
            final CertificateFactory cf = CertificateFactory.getInstance("X.509");
            final Certificate ca = cf.generateCertificate(
                    getClass().getClassLoader().getResourceAsStream("sks-keyservers.netCA.pem"));

            final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());

            keyStore.load(null, null);
            keyStore.setCertificateEntry("ca", ca);

            final TrustManagerFactory tmf
                    = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            tmf.init(keyStore);

            final SSLContext context = SSLContext.getInstance("TLS");
            context.init(null, tmf.getTrustManagers(), null);

            this.sslSocketFactory
                    = new SSLConnectionSocketFactory(
                    context, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
        } else {
            this.sslSocketFactory = SSLConnectionSocketFactory.getSystemSocketFactory();
        }
    } catch (CertificateException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) {
        throw new IOException(e);
    }
}
 
Example 2
Source File: NexusSSLConnectionSocketFactory.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public NexusSSLConnectionSocketFactory(@Nullable final List<SSLContextSelector> sslContextSelectors) {
  this.defaultSocketFactory = SSLConnectionSocketFactory.getSystemSocketFactory();
  this.sslContextSelectors = sslContextSelectors; // might be null
  this.supportedProtocols = split(System.getProperty("https.protocols"));
  this.supportedCipherSuites = split(System.getProperty("https.cipherSuites"));
}