JETTY with SSL

1548 ワード

keystore関連資料の作成
jetty 9プログラミングに基づく埋め込みhttpサーバの構築
JAvaにおけるKeytoolの使用概要
じっこうコード
関数をカプセル化し、コネクタを簡単に構築
ServerConnector buildSslConnector(Server server, int securePort, String keyStorePath, String keyStorePassword, String keyManagerPassword) {
        HttpConfiguration https_config = new HttpConfiguration();
        https_config.setSecureScheme("https");
        https_config.setSecurePort(securePort);
        https_config.addCustomizer(new SecureRequestCustomizer());

        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(keyStorePath);
        sslContextFactory.setKeyStorePassword(keyStorePassword);
        sslContextFactory.setKeyManagerPassword(keyManagerPassword);

        ServerConnector httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
        httpsConnector.setPort(securePort);

        return httpsConnector;
    }

サーバ起動コード
Server httpServer = new Server();
        ServerConnector sslConnector = buildSslConnector(httpServer,   ,
                keystore  ,
                keystore  ,
                    );

        httpServer.addConnector(sslConnector);

        //  web app
        try {
            httpServer.start();
            httpServer.join();
        } catch (Exception e) {
            e.printStackTrace();
        }

証明書の発行者はドメイン名と一致し、信頼できる証明書に手動で追加する必要があります.そうしないと、ブラウザは認識しません.