首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级到Java17后未能加载keystore类型[PKCS12]

升级到Java17后未能加载keystore类型[PKCS12]
EN

Stack Overflow用户
提问于 2022-06-19 06:13:23
回答 1查看 219关注 0票数 0

我在本地主机上使用ssl运行Springboot应用程序。我有一些集成测试来验证ssl是否有效:

application.properties

代码语言:javascript
复制
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:ssl/localhost.p12
server.ssl.key-store-password=localhost_ssl
server.ssl.key-alias=localhost_ssl
server.ssl.enabled=true

集成试验

代码语言:javascript
复制
@ParameterizedTest
@MethodSource("getSslTestParameters")
void onlyAllowSecureCallsToEndpoint(boolean includesSecure, ResultMatcher expectedStatus) throws Exception {
    MockHttpServletRequestBuilder postCall = post("/api/tutors/register")
            .content(objectMapper.writeValueAsString(TutorRegistrationDTO.builder().build()))
            .contentType(APPLICATION_JSON)
            .with(csrf());
    if (includesSecure) {
        postCall.secure(true);
    }
    mvc.perform(postCall).andExpect(expectedStatus);
}

private static Stream<Arguments> getSslTestParameters() {
    return Stream.of(
            Arguments.of(true, status().isOk()),
            Arguments.of(false, status().isFound()));
}

当我使用IntelliJ和Maven运行它时,这个测试在Java8中运行得很好。现在,我对Java 17进行了升级,当我使用IntelliJ运行它时,它仍然工作,但是当我运行Maven构建时,它就停止工作了。我得到以下错误:

代码语言:javascript
复制
IOException: Failed to load keystore type [PKCS12] with path [jar:file:/C:/mypath/target/app-1.0.0-SNAPSHOT.jar!/ssl/localhost.p12] due to [Illegal char <:> at index 3: jar:file:\C:\mypath\target\app-1.0.0-SNAPSHOT.jar!\ssl\localhost.p12]

我可以确认localhost.p12在jar中是可用的,但是它在解析.p12文件时似乎有问题。我假设文件本身并没有错,因为测试仍然适用于IntelliJ。

我已经通过设置IntelliJ验证了postCall.secure(false)并没有给出错误的阳性结果,并验证了测试是否如预期的那样失败。

ssl在Java 8和17之间的工作方式是否发生了变化?我在文件里找不到任何相关的东西。

编辑:我应该补充说,应用程序仍然没有问题地运行。问题完全在于考试。

EN

回答 1

Stack Overflow用户

发布于 2022-06-19 06:27:10

它不再正确地从Maven解释到jar的路径。它抱怨路径jar:...,分号。

我通过将/ssl/localhost.p12复制到集成测试Maven模块的测试资源来解决这个问题。

我无法解释为什么它可以在Java 8而不是Java 17中解释jar路径。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72674646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档