我使用wsgen开发了一个简单的Web服务,它在http(非SSL)下工作正常。我现在需要在https(SSL)下运行它。我按照位于here的代码进行操作。所以SSL进程现在正在运行......我在Eclipse中作为Java应用程序运行。但是,当我尝试访问它时,我得到了#34;安全连接失败" - "您尝试查看的页面无法显示,因为无法验证收到的数据的真实性"。
那就是说,我是SSL的中间人,所以我在这里可能做错了。我使用Keystore Explorer工具执行以下操作: - 创建了一个新的JKS密钥库。 - 生成一个新的密钥对 - 将密钥对导出为* .pk12文件。 - 打开我的浏览器并导入* .pk12。我尝试过* .cer,但浏览器不会使用无符号证书。
所以* .jks直接在Java代码中打开并且可以工作,我使用Eclipse中的Debug进行了验证。 SSL服务启动正常,但我仍然在浏览器中得到相同的错误...另一个困难是我似乎找不到任何类型的异常/错误的日志文件甚至开始跟踪问题。我不认为这是一个Java问题......我认为这是一个SSL问题,但我不知道还有什么可以开始。
非常感谢任何帮助!
public static void main(String[] args) throws Exception {
Endpoint endpoint = Endpoint.create(new RapidCommandService());
SSLContext ssl = SSLContext.getInstance("SSLv3");
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
getLog().debug ( SHORT_NAME + ".main() - Java User Directory..........................[" + System.getProperty ( "user.dir" ) + "]" );
getLog().debug ( SHORT_NAME + ".main() - Java Home Directory..........................[" + System.getProperty ( "java.home" ) + "]" );
getLog().debug ( SHORT_NAME + ".main() - Java Version.................................[" + System.getProperty ( "java.version" ) + "]" );
//Load the JKS file (located, in this case, at D:\keystore.jks, with password 'test'
store.load(new FileInputStream("C:\\usr\\apps\\java\\jre-170-65\\lib\\security\\rapid-command-service.jks"), "changeit".toCharArray());
//init the key store, along with the password 'test'
kmf.init(store, "changeit".toCharArray());
KeyManager[] keyManagers = new KeyManager[1];
keyManagers = kmf.getKeyManagers();
//Init the trust manager factory
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
//It will reference the same key store as the key managers
tmf.init(store);
TrustManager[] trustManagers = tmf.getTrustManagers();
ssl.init(keyManagers, trustManagers, new SecureRandom());
getLog().debug ( SHORT_NAME + ".main() - Java SSL Truststore..........................[" + System.getProperty ( "javax.net.ssl.trustStore" ) + "]" );
getLog().debug ( SHORT_NAME + ".main() - Java SSL Keystore............................[" + System.getProperty ( "javax.net.ssl.keyStore" ) + "]" );
//Init a configuration with our SSL context
HttpsConfigurator configurator = new HttpsConfigurator(ssl);
System.setProperty("javax.net.debug", "ssl");
//Create a server on localhost, port 443 (https port)
HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress("localhost", 443), 443);
httpsServer.setHttpsConfigurator(configurator);
//Create a context so our service will be available under this context
HttpContext context = httpsServer.createContext("/rapidCommandService");
httpsServer.start();
//Finally, use the created context to publish the service
endpoint.publish(context);
}
答案 0 :(得分:0)
尝试
SSLContext ssl = SSLContext.getInstance("TLSv1.2");
众所周知,SSLv3易受攻击,您的浏览器可能无法接受这样配置的服务器。
另一个选项是curl
和-k
选项连接到服务器。