我使用wsgen开发了一个简单的Web服务,它在http(非ssl)下工作得很好。我现在需要让它在https (SSL)下工作。我跟着这里的代码走。所以SSL进程现在正在运行…我从Eclipse内作为Java应用程序运行。但是,当我尝试访问它时,我得到"安全连接失败"-"您试图查看的页面无法显示,因为无法验证接收到的数据的真实性"。
也就是说,我是SSL的中间人,所以我可能在这里做错了什么。我使用Keystore Explorer工具做了以下操作:—已创建新的JKS密钥库。—生成新的密钥对—导出密钥对格式为"*"。pk12文件。—打开浏览器,导入*.pk12文件。我试了一个*。cer,但是浏览器不接受Unsigned证书。
所以*。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);
}
Try
SSLContext ssl = SSLContext.getInstance("TLSv1.2");
SSLv3现在是很脆弱的,你的浏览器可能不会接受这样配置的服务器。
另一个选项尝试curl
与-k
选项连接到服务器