Package org.apache.http.conn.ssl

Examples of org.apache.http.conn.ssl.TrustSelfSignedStrategy


public class ApacheHttpClient {
  static DefaultHttpClient httpClient = null;

  private ApacheHttpClient() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException{
    // Allow self-signed SSL certificates:
    TrustStrategy trustStrategy = new TrustSelfSignedStrategy();
    X509HostnameVerifier hostnameVerifier = new AllowAllHostnameVerifier();
    SSLSocketFactory sslSf = new SSLSocketFactory(trustStrategy,
          hostnameVerifier);
    Scheme https = new Scheme("https", 443, sslSf);
View Full Code Here


 
  private ApacheHttpClient() throws KeyManagementException,
      UnrecoverableKeyException, NoSuchAlgorithmException,
      KeyStoreException {
    // Allow self-signed SSL certificates:
    TrustStrategy trustStrategy = new TrustSelfSignedStrategy();
    X509HostnameVerifier hostnameVerifier = new AllowAllHostnameVerifier();
    SSLSocketFactory sslSf = new SSLSocketFactory(trustStrategy,
        hostnameVerifier);
    Scheme https = new Scheme("https", 443, sslSf);
   
View Full Code Here

            instream.close();
        }

        // Trust own CA and all self-signed certs
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
                .build();
        // Allow TLSv1 protocol only
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                sslcontext,
                new String[] { "TLSv1" },
View Full Code Here

    }

    @Test
    public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException {
        final SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
        final CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

        // new
View Full Code Here

        if (isTrusted(method.getURI().getAuthority())) {
            // creating a special configuration that allows connections to non-trusted HTTPS hosts
            try {
                SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
                sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy() {
                    @Override
                    public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                        return true;
                    }
                });
View Full Code Here

   */
  private CloseableHttpClient buildClient(boolean trustSelfSigned) {
    try {
      // if required, define custom SSL context allowing self-signed certs
      SSLContext sslContext = !trustSelfSigned ? SSLContexts.createSystemDefault() : SSLContexts.custom()
        .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();

      // set timeouts for the HTTP client
      int globalTimeout = readFromProperty("bdTimeout", 10000);
      int connectTimeout = readFromProperty("bdConnectTimeout", globalTimeout);
      int connectionRequestTimeout = readFromProperty("bdConnectionRequestTimeout", globalTimeout);
View Full Code Here

   */
  private HttpClient buildClient(boolean trustSelfSigned) {
    try {
      // if required, define custom SSL context allowing self-signed certs
      SSLContext sslContext = !trustSelfSigned ? SSLContexts.createSystemDefault() : SSLContexts.custom()
        .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();

      // set timeouts for the HTTP client
      RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT).setConnectTimeout(10000)
        .setSocketTimeout(10000).setConnectionRequestTimeout(10000).build();

View Full Code Here

   */
  private CloseableHttpClient buildClient(boolean trustSelfSigned) {
    try {
      // if required, define custom SSL context allowing self-signed certs
      SSLContext sslContext = !trustSelfSigned ? SSLContexts.createSystemDefault() : SSLContexts.custom()
        .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();

      // set timeouts for the HTTP client
      int globalTimeout = readFromProperty("bdTimeout", 10000);
      int connectTimeout = readFromProperty("bdConnectTimeout", globalTimeout);
      int connectionRequestTimeout = readFromProperty("bdConnectionRequestTimeout", globalTimeout);
View Full Code Here

  }

  @Provides
  public SSLSocketFactory provideSSLSocketFactory() {
    try {
      return new SSLSocketFactory(new TrustSelfSignedStrategy());
    }
    catch(RuntimeException e) {
      throw e;
    }
    catch(Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.http.conn.ssl.TrustSelfSignedStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.