【问题标题】:ssl certificate issue for jgit in javafx app image versus javafx app runtimejavafx 应用程序映像中 jgit 的 ssl 证书问题与 javafx 应用程序运行时
【发布时间】:2021-02-23 17:56:46
【问题描述】:

我使用 jgit 开发了一个简单的 JavaFX 应用程序,它允许用户使用 git。

当应用程序从 IntelliJ 想法启动时,我能够使用我的“git clone”命令的 jgit 实现克隆 GitHub 存储库,没有任何问题。但是,一旦我从我的应用程序创建了一个图像并从该图像启动了应用程序,我就会遇到 SSL 证书问题:

异常:org.eclipse.jgit.api.errors.TransportException: 由于 SSL 问题,无法建立到 https://my-github-repo.git 的安全连接。

我试图了解为什么只有在从映像运行应用程序时才会出现 SSL 证书问题。有人可以解释一下吗?我知道我可以禁用 SSL 验证(关于该主题有一些问题已得到解答),但我想知道为什么它在 IDE 中而不是从创建的图像中工作...... p>

这是我对 http 的简化 git clone 实现:

try { 

            CloneCommand command = Git.cloneRepository();

            command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));

            // run the clone command
            command.setURI(repositoryUrl);
            command.setDirectory(dirFramework);
            git = command.call();

} catch (Exception e) {
    LOG.error("Error occurred during task: Git clone: " + e);
}

为了创建图像,我将“org.beryx.runtime”插件与 Gradle 任务“runtime”一起使用。

这是 build.gradle 的内容:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.runtime' version '1.11.4'
}

group 'org.sovap'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {

    // xml stuff
    compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
    compile 'jakarta.activation:jakarta.activation-api:1.2.2'

    // logger
    compile 'org.apache.logging.log4j:log4j-core:2.13.3'
    compile 'org.slf4j:slf4j-api:1.7.30'
    compile 'org.slf4j:slf4j-simple:1.7.30'

    // cucumber
    compile 'io.cucumber:gherkin:15.0.2'

    // jgit
    compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
    compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
    compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'

    // file utils
    compile 'commons-io:commons-io:2.7'

    //controlsfx
    compile 'org.controlsfx:controlsfx:11.0.2'

}

javafx {
    version = "15"
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
}

application {
    mainClassName = 'org.sovap.taman.Launcher'
    applicationName = 'taman'
}

runtime {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    imageDir = file("$buildDir/taman")
}

编辑 1:

图像是如何创建的? - 使用插件“org.beryx.runtime”版本“1.11.4”创建图像,Gradle 任务称为“runtime”。在 build.gradle 内容的最后你可以看到一些运行时任务的具体配置。

此外,还可以在此处包含模块:https://badass-runtime-plugin.beryx.org/releases/latest/

我已经使用您在 build.gradle 中提到的运行时任务模块测试了配置(也是一一):

runtime {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    imageDir = file("$buildDir/taman")
    modules = ['jdk.crypto.cryptoki', 'jdk.crypto.ec', 'jdk.crypto.mscapi']
}

但是,从图像启动应用程序时出现以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
        at org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory.newConfigurationBuilder(ConfigurationBuilderFactory.java:38)
        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.<init>(PropertiesConfigurationBuilder.java:72)
        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:52)
        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:551)
        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:475)
        at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:687)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:602)
        at org.sovap.taman.App.<clinit>(App.java:15)
        at org.sovap.taman.Launcher.main(Launcher.java:6)
Caused by: java.lang.ClassNotFoundException: javax.xml.stream.XMLStreamException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 16 more

您使用的是哪个版本的 Java 11? -java版本“11.0.8”2020-07-14 LTS 关于图像和 IntelliJ IDEA 环境的不同版本的 JDK - 它应该在我的机器上使用相同的安装

我想我需要将模块添加到运行时任务中,但我不知道哪些以及如何识别它们...您可以指出我的方向吗?

编辑 2:

根据接受的答案,我的运行时任务配置中缺少模块。以下是我如何确定要添加哪些:

插件“org.beryx.runtime”包含一个任务,我用于为运行时任务建议模块(任务:suggestModules) 运行它后,我创建了一个具有以下运行时配置的模块列表(包括已接受答案中的那些):

runtime {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    imageDir = file("$buildDir/taman")
    modules = [
            'java.desktop',
            'java.logging',
            'java.xml',
            'java.compiler',
            'java.datatransfer',
            'java.rmi',
            'java.sql',
            'java.naming',
            'java.scripting',
            'java.management',
            'java.security.jgss',
            'jdk.jfr',
            'java.net.http',
            'jdk.jsobject',
            'jdk.xml.dom',
            'jdk.unsupported',
            'jdk.crypto.cryptoki',
            'jdk.crypto.ec',
            'jdk.crypto.mscapi']
}

现在一切正常。

【问题讨论】:

  • 请分享您遇到的任何异常情况。
  • 我已经编辑了这个问题。感谢您的时间和精力。
  • 为异常添加整个堆栈跟踪。例如。有没有提到“起因”?
  • 堆栈跟踪中没有其他内容了:2020-11-12 10:09:47,727 [ERROR] [Thread-5] taman.utils.GitUtils - 任务期间发生错误:Git 克隆: org.eclipse.jgit.api.errors.TransportException: github.com/my-repo.git: 由于 SSL 问题,无法建立到 github.com/my-repo.git 的安全连接

标签: ssl javafx jgit


【解决方案1】:

最可能的情况是您在 JRE 映像中缺少与验证 SSL 连接所需的加密相关的模块。

最终映像中有哪些 jdk.crypto.* 模块? 也许如果缺少其中之一,它会影响处理 SSL 证书的能力?

  • jdk.crypto.cryptoki
  • jdk.crypto.ec
  • jdk.crypto.mscapi

由于安全/加密代码的某些方面是通过服务提供商完成的,也许当您生成 JRE 映像时,您应该传递 “--bind-services”选项到“链接服务提供者模块及其依赖”

您需要分享有关如何创建图像以及报告了哪些具体错误的更多详细信息。尝试包含任何报告的异常的完整堆栈跟踪。

您使用的是哪个版本的 Java 11? 你会不会遇到这个:JDK 11 SSL Error on valid certificate (working in previous versions)

(如果您在 IDE 和打包映像中使用相同的 JDK 版本运行,则不太可能,但我想我会提到它以防万一它给您提示。)

【讨论】:

  • 嗨@swpalmer,谢谢你的回答,我已经添加了 build.gradle 内容。其他一切都已经存在(例外以及图像的准备方式......),现在我把它加粗了,因为它更明显了。关于您的回答,您提到了一个与加密相关的模块。你能详细说明一下吗?感谢您的时间和精力。
  • 我找到了使用您建议的模块的解决方案。非常感谢!
猜你喜欢
  • 2020-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多