Jetty SSL无法正常工作。访问网站会产生难以置信的输出

时间:2016-08-17 00:36:53

标签: ssl https jetty embedded-jetty

编辑:浏览器上安装的自签名证书使其正常工作。

我已经在端口8080上为http配置了jetty 9,在端口8443上配置了https。当我访问localhost:8080时,我得到了我的网站,一切正常,但是当我尝试访问localhost:8443时,我得到了这个混乱:{ {3}}

我几乎模仿了jetty文档中的image of unreadable stuff,以便设置http连接器和https连接器。这是我的代码:

File keystoreFile = new File("config/myownkeystore.p12");
    if (!keystoreFile.exists()){
        throw new FileNotFoundException(keystoreFile.getAbsolutePath());
    }

    Server server = new Server();

    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);

    ServerConnector http = new ServerConnector(server,
            new HttpConnectionFactory(http_config));
    http.setPort(8080);
    http.setIdleTimeout(30000);

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreType("PKCS12");
    sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
    sslContextFactory.setKeyStorePassword("myownstorepass");
    sslContextFactory.setKeyManagerPassword("myownkeypass");


    HttpConfiguration https_config = new HttpConfiguration(http_config);
    SecureRequestCustomizer src = new SecureRequestCustomizer();
    src.setStsMaxAge(2000);
    src.setStsIncludeSubDomains(true);
    https_config.addCustomizer(src);

    ServerConnector https = new ServerConnector(server,
        new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
            new HttpConnectionFactory(https_config));
    https.setPort(8443);
    https.setIdleTimeout(500000);

    // Set the connectors
    server.setConnectors(new Connector[] { http, https });

    // servlet handler
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletContextHandler.setResourceBase(".");
    servletContextHandler.setContextPath("/");
    servletContextHandler.addServlet(new ServletHolder(new MainServlet()), "/*");

    // set the handlers
    HandlerCollection handlerList = new HandlerCollection();
    handlerList.setHandlers(new Handler[]{servletContextHandler});
    server.setHandler(handlerList);

起初我认为可能是密钥库类型有问题,因为jetty默认使用jks。因此我将sslcontext切换为使用pkcs12,因为密钥库是.p12文件。那没有用。

我接下来检查了密码,但是私钥和密钥库的密码是相同的,所以这不是问题。

此时,我想在某个地方相信我的代码有问题,但我不知道到底出了什么问题。

0 个答案:

没有答案