2014-09-02 60 views
0

您好,我有關於使用https和ssl啓用嵌入式jety的問題。關於這個問題,我完全是虛構的。 我想按照這個代碼:如何使用https和ssl啓用嵌入式碼頭

http://www.smartjava.org/content/embedded-jetty-client-certificates

,但我需要有服務器和客戶端密鑰庫。我跟着這個: http://www.eclipse.org/jetty/documentation/current/configuring-ssl.html#generating-csr-from-openssl

來生成密鑰,但我不知道如何使用它們,另一方面我不知道如果這就是我想要的。

有什麼想法嗎?順便說我的碼頭版本是8.

謝謝!

回答

0

一旦我有一些ssl網站的問題,從它下載的東西。 我不知道它有同樣的問題,但我可以製作這個可信任的對象。有了它,我可以管理HTTPS連接和下載:

// Create a new trust manager that trust all certificates 
    TrustManager[] trustAllCerts = new TrustManager[]{ 
     new X509TrustManager() { 
      public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
       return null; 
      } 
      public void checkClientTrusted(
       java.security.cert.X509Certificate[] certs, String authType) { 
      } 
      public void checkServerTrusted(
       java.security.cert.X509Certificate[] certs, String authType) { 
      } 
     } 
    }; 

    // Activate the new trust manager 
    try { 
     SSLContext sc = SSLContext.getInstance("SSL"); 
     sc.init(null, trustAllCerts, new java.security.SecureRandom()); 
     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 
    } catch (Exception e) { 
    } 


    URL url = new URL(src); 
    URLConnection connection = url.openConnection(); 
    InputStream is = connection.getInputStream(); 
    BufferedImage bufImgOne = ImageIO.read(url); 
    ImageIO.write(bufImgOne, "jpg", new File("test.jpg")); 

如果不解決只或幾乎請寫出比我試圖幫助 或者乾脆刪除不垃圾郵件的線程

+1

這是給客戶端的,對嗎?而OP希望在服務器端擁有SSL – nogard 2014-09-02 13:49:15

+0

是的,這是客戶端 – Csanesz 2014-09-02 14:21:53