0

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

也就是说,我是 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);

}
4

1 回答 1

0

尝试

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

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

另一种选择尝试连接到服务器的选项curl-k

于 2015-06-07T08:54:41.653 回答