Java - 独立 SSL Web 服务 - JAX-WS、JRE、无 Web 服务器

标签 java ssl web jks wsgen

我使用 wsgen 开发了一个简单的 Web 服务,它在 http(非 SSL)下运行良好。我现在需要让它在 https (SSL) 下工作。我遵循了位于 here 的代码.所以 SSL 进程现在运行......我在 Eclipse 中作为 Java 应用程序运行。但是,当我尝试访问它时,出现“安全连接失败”-“无法显示您尝试查看的页面,因为无法验证接收到的数据的真实性”。

也就是说,我是 SSL 的中间人,所以我可能在这里做错了什么。我使用 Keystore Explorer 工具执行了以下操作: - 创建了一个新的 JKS keystore 。 - 生成了一个新的 key 对 - 将 key 对导出为 *.pk12 文件。 - 打开我的浏览器并导入 *.pk12。我尝试了 *.cer,但浏览器不会接受未签名的证书。

所以 *.jks 直接在 Java 代码中打开并且有效,我在 Eclipse 中使用调试进行了验证。 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);

}

最佳答案

尝试

SSLContext ssl =  SSLContext.getInstance("TLSv1.2");

现在已知 SSLv3 容易受到攻击,您的浏览器可能不会接受这样配置的服务器。

另一个选项尝试使用-k选项连接到服务器的curl

关于Java - 独立 SSL Web 服务 - JAX-WS、JRE、无 Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30684640/

相关文章:

api - 如何向我的网站添加 snapchat 共享按钮。是否可以为 Snapchat 添加共享按钮?

web - 如何在 IntelliJ Idea 13 中创建静态 Web 项目?

java - @Context 未在 RESTEasy JAX-RS 应用程序中注入(inject) ServletContext

java - 异步请求不适用于 Tomcat 7/Terracotta 3.6

java - 可能的根本原因包括 -Xss 设置过低和非法循环继承依赖项

java - 从 LinearLayout 按下图像时打开默认应用程序

ssl - 定义自定义负载均衡算法

android - Android kitkat 版本上的 SSL 证书未验证错误

asp.net - IIS 6网站下具体应用使用https

html - 让一个类(class)出现在另一个类(class)悬停上