【问题标题】:Setup SSL using Spring-Boot and Jetty使用 Spring-Boot 和 Jetty 设置 SSL
【发布时间】:2018-07-05 03:51:48
【问题描述】:

我有一个使用 jetty 运行的 spring-boot 项目,我的 gradle 中特别有

compile("org.springframework.boot:spring-boot-starter-web:1.5.8.RELEASE") {
    exclude module: "spring-boot-starter-tomcat"
}

我想设置 SSL 并已注册,现在拥有 .ca-bundle .crt .p7b .csr.key 文件。此外,我想通过使用@Configuration 类而不是application.properties 来实现这一点,但是我不知道设置 SSL 的第一件事。谁能指出我正确的方向,或者提供一个允许我的 Spring Boot 项目使用 SSL 的代码 sn-p?

【问题讨论】:

    标签: java spring ssl spring-boot jetty


    【解决方案1】:

    1) 您需要将您的证书添加到 JKS 格式的密钥库中。这是基于 Java 的 Web 服务器中用于存储证书的格式。您可以使用this guide 或任何其他适合您的证书格式。

    2) 将生成的文件放入项目的src/main/resources文件夹中。

    3) 让您的网络服务器使用新的密钥库。

    在 Spring Boot 中,Spring 通过 .properties/.yml 配置自动执行此过程会很容易。

    这是.yml 的示例:

    server:
      port: 443
      ssl:
        key-store: classpath:your-keystore.jks
        key-store-password: your-strong-pass
        keyStoreType: PKCS12
        keyAlias: your-alias
    

    每个属性对应于您在第一步中输入的条目。端口应设置为443,因为它是 SSL 连接的默认端口。

    注意:@Configuration 类中这样做没有意义,因为推荐的方式只是属性文件。了解更多详情in the documentation

    【讨论】:

    • 我一直走到最后一步,但是当我启动服务器时,我被告知org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Jetty servlet container Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big. 知道那是什么吗?我使用命令 Program\ Files/Java/jdk1.8.0_66/bin/keytool.exe -import -alias jetty -file my_certificate.crt -keystore keystore.jks -storepass some_password 制作了我的 jks
    • 我不确定是什么问题。但是尝试删除这一行keyStoreType: PKCS12(默认为JKS)。您也可以查看此链接confluence.atlassian.com/jirakb/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 2023-03-26
    • 2018-09-07
    • 2020-12-15
    相关资源
    最近更新 更多