【发布时间】:2016-03-22 15:41:35
【问题描述】:
我正在尝试将 .net 应用程序移植到具有集成 Web 浏览器的 JavaFx,该浏览器可打开需要证书的网站。在 Windows 中,证书是从提供的 .pfx 文件和密码短语安装的。 当浏览器调用网站时,会弹出一个显示已安装证书的窗口,如果有多个证书,则用户选择正确的证书并打开网站。 使用以下代码,我可以让网站使用我的证书打开连接。
private void Connect() throws NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, IOException, CertificateException, UnrecoverableKeyException, KeyManagementException {
SSLContext ctx = SSLContext.getInstance("TLS");
KeyManager[] keyManagers;
KeyStore keyStore = KeyStore.getInstance("pkcs12");
FileInputStream keyStoreFile = new FileInputStream(new File("Certificate.pfx"));
String keyStorePassword = "password";
keyStore.load(keyStoreFile, keyStorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, keyStorePassword.toCharArray());
keyManagers = kmf.getKeyManagers();
ctx.init(keyManagers, null, new SecureRandom());
SSLSocketFactory sslSocketFactory = ctx.getSocketFactory();
URL url = new URL("https://example.com");
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setSSLSocketFactory(sslSocketFactory);
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
}
我怎样才能让它在 WebView 控件中工作?
谢谢
【问题讨论】:
标签: ssl javafx webview certificate client