ssl - 模块化 Java 13/JavaFx WebWiew 在 jlinked 时无法显示

标签 ssl javafx webview java-platform-module-system jlink

我在嵌入窗口中显示网页时遇到问题,但仅在创建独立的 jlinked 包时且仅适用于某些 https 站点时。

我按照 https://openjfx.io/openjfx-docs/#install-javafx 上的说明进行操作用于创建一个简单的模块化应用程序,当从命令行运行时效果很好

java --module-path "%PATH_TO_FX%;mods" -m uk.co.comsci.testproj/uk.co.comsci.testproj.Launcher

但是在使用命令进行 jlink 之后

jlink --module-path "%PATH_TO_FX_MODS%;mods" --add-modules uk.co.comsci.testproj --output launch

并运行

launch\bin\java.exe -m uk.co.comsci.testproj/uk.co.comsci.testproj.Launcher

javaFx 场景打开,但只是一个空白屏幕...我必须使用任务管理器来终止应用程序。

如果我将 URL 更改为其他 https 站点,则显示正常。

我想这取决于某处的安全设置和策略,但我不知道从哪里开始。

我尝试使用 WireShark 进行监控,这表明当从 java 运行并且它可以工作时,它会执行一些 TLSv1.3 操作来建立连接。当作为 jlinked 包运行时,它只执行 TLSv1.2 的操作。也许有线索?

这是我的 SSCE:

模块信息.java

module uk.co.comsci.testproj {
    requires javafx.web;
    requires javafx.controls;
    requires javafx.media;
    requires javafx.graphics;
    requires javafx.base;
    exports uk.co.comsci.testproj;
}

启动器.java

package uk.co.comsci.testproj;

public class Launcher {
    public static void main(String[] args) {
        try {
            MainApp.main(args);
        } catch (Exception ex) {
            System.err.println("Exception!!! " + ex);
        }
    }
}

MainApp.java

package uk.co.comsci.testproj;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class MainApp extends Application {

    private Stage mainStage;

    public static void main(String[] args) throws Exception {
        launch(args);
    }

    @Override
    public void start(final Stage initStage) throws Exception {

        mainStage = new Stage(StageStyle.DECORATED);

        mainStage.setTitle("Test Project");

        WebView browser = new WebView();
        WebEngine webEngine = browser.getEngine();

//        webEngine.load("https://app.comsci.co.uk"); // url);
        String uri = "https://test-api.service.hmrc.gov.uk/oauth/authorize"
                + "?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8084%2Fredirect"
                + "&state=lFuLG42uri_aAQ_bDBa9TZGGYD0BDKtFRv8xEaKbeQo"
                + "&client_id=tASN6IpBPt5OcIHlWzkaLXTAyMEa&scope=read%3Avat+write%3Avat";
        webEngine.load(uri);

        Button closeButt = new Button("Cancel");
        closeButt.setOnMouseClicked(event -> {
            mainStage.close();
        });
        HBox closeButBar = new HBox(closeButt);
        closeButBar.setAlignment(Pos.BASELINE_RIGHT);

        VBox vlo = new VBox(browser, closeButBar);
        vlo.setFillWidth(true);
        vlo.setSpacing(10.0);
        VBox.setVgrow(browser, Priority.ALWAYS);

        Scene scene2 = new Scene(vlo, 800, 800);
        mainStage.setScene(scene2);
        mainStage.initModality(Modality.APPLICATION_MODAL);
        mainStage.setTitle("Test connection");
        mainStage.showAndWait();
    }

}

非常感谢任何帮助。

最佳答案

好的。终于追踪到了。因此,如果有人遇到同样的问题:

与 JavaFx 或 Webview 无关,这是 TLS 握手失败。

用 http 客户端 get 替换 webview

            String uri = "https://test-api.service.hmrc.gov.uk/oauth/authorize"
                    + "?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8084%2Fredirect"
                    + "&state=lFuLG42uri_aAQ_bDBa9TZGGYD0BDKtFRv8xEaKbeQo"
                    + "&client_id=tASN6IpBPt5OcIHlWzkaLXTAyMEa&scope=read%3Avat+write%3Avat";

            var client = HttpClient.newHttpClient();
            var request = HttpRequest.newBuilder()
                    .GET()
                    .uri(URI.create(uri))
                    .timeout(Duration.ofSeconds(15))
                    .build();

            try {
                HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
                System.out.println("REsponse  " + response.body());
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }

并使用“-Djavax.net.debug=ssl:handshake:verbose”运行显示握手失败。 运行嵌入式 keytool -showinfo -tls 并将其与系统 keytool 输出进行比较表明,jlinked 输出不支持 TLS_ECDHE_... 密码

这里有一些谷歌搜索和帮助https://www.gubatron.com/blog/2019/04/25/solving-received-fatal-alert-handshake_failure-error-when-performing-https-connections-on-a-custom-made-jre-with-jlink/表明我需要做的就是添加

requires jdk.crypto.cryptoki;

到我的 module-info.java :-)

关于ssl - 模块化 Java 13/JavaFx WebWiew 在 jlinked 时无法显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60081037/

相关文章:

ssl - 在Ubuntu 16上使用Apache 2.4反向代理Tomcat 7 : webapp not found

cookies - 两个 ChromeApp WebView 是否可以拥有不同的 cookie 集?

java - 在 javafx 应用程序中使用 HTML5 视频标签

JAVAFX:如何在 TableView 中包含数据的单元格上设置 MouseEvent 左键单击操作

android - 在 Android 应用程序中打包(自定义)WebView

ios - 当视频在 WebView 中播放时,在 iOS (Swift) 中向 AVPlayer 添加 UIButton

ssl - 无法在 Websphere 8.5 中创建的别名的下拉列表中看到签署者证书别名

android - 如何在 Android 7 Nougat 上允许任意加载

internet-explorer - Internet Explorer HTTPS 请求中止?

JavaFX OnDragDropped 未注册