我知道如何使用證書來保護Web服務。這是我的客戶代碼:如何通過Web服務製作簡單的SSL?
SSLContext ssl = SSLContext.getInstance("SSLv3");
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
String password = Configuration.getConfig("keyStorePassword");
store.load(new FileInputStream(new File(Configuration.getConfig("keyStore"))), password.toCharArray());
kmf.init(store, password.toCharArray());
KeyManager[] keyManagers = new KeyManager[1];
keyManagers = kmf.getKeyManagers();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(store);
TrustManager[] trustManagers = tmf.getTrustManagers();
ssl.init(keyManagers, trustManagers, new SecureRandom());
HttpsConfigurator configurator = new HttpsConfigurator(ssl);
Integer port = Integer.parseInt(Configuration.getConfig("port"));
HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(Configuration.getConfig("host"), port), 0);
httpsServer.setHttpsConfigurator(configurator);
Implementor implementor = new Implementor(); // class with @WebService etc.
HttpContext context = (HttpContext) httpsServer.createContext("/EventWebService");
Endpoint endpoint = Endpoint.create(implementor);
endpoint.publish(context);
現在,如何使'簡單的SSL'?如何在客戶端不存儲證書的情況下進行SSL連接。 (如通過瀏覽器中的HTTPS連接)
我認爲TrustAlmostEverythingManager就是我正在尋找的東西。 我用精確的IP連接到服務器(所以不可能有人會欺騙)。我只是想保護連接免受竊聽。 我想對嗎?也許在將來,將需要生成客戶端和服務器證書。 – razor
嗯......是的,但是如果您的Web服務消費者不在您的組織之中,那麼他們相信自簽名證書會更加困難。我建議提前掏出幾塊錢,讓你的客戶感覺更好。我也建議獲得一個合適的域名,而不是共享一個帶有IP地址的WSDL。自簽名證書非常適合Intranet應用程序和測試環境,但對於外部客戶而言,額外的一些額外費用將會很長! – helios
客戶在組織之外,爲什麼信任是困難的?你的意思是很難驗證服務器? 我知道來自CA的證書會更好,而且這個環境的管理員也知道。 現在,它只是不依賴於我。也許,將來會有適當的證書(由CA頒發)等。 – razor