SORU
24 NİSAN 2010, CUMARTESİ


Nasıl 4.0 HttpClient Apache SSL sertifika hataları görmezden

Nasıl Apache HttpClient 4.0 ile geçersiz SSL sertifika hataları bypass mı?

CEVAP
24 NİSAN 2010, CUMARTESİ


Kendi TrustManager ile bir SSLContext oluşturmak ve HTTPS düzeni bu bağlamda kullanarak oluşturmanız gerekir. İşte kodu

SSLContext sslContext = SSLContext.getInstance("SSL");

// set up a TrustManager that trusts everything
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                    System.out.println("getAcceptedIssuers =============");
                    return null;
            }

            public void checkClientTrusted(X509Certificate[] certs,
                            String authType) {
                    System.out.println("checkClientTrusted =============");
            }

            public void checkServerTrusted(X509Certificate[] certs,
                            String authType) {
                    System.out.println("checkServerTrusted =============");
            }
} }, new SecureRandom());

SSLSocketFactory sf = new SSLSocketFactory(sslContext);
Scheme httpsScheme = new Scheme("https", 443, sf);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(httpsScheme);

// apache HttpClient version >4.2 should use BasicClientConnectionManager
ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • MugenPowerBatteries

    MugenPowerBa

    8 EKİM 2010
  • nemoking of kinges

    nemoking of

    4 EYLÜL 2009
  • skiesofblack.net

    skiesofblack

    14 HAZİRAN 2009