【问题标题】:Using wildcard ssl certificate for Spring Boot backend为 Spring Boot 后端使用通配符 ssl 证书
【发布时间】:2019-02-24 13:46:26
【问题描述】:

我已从我的托管商 (Hoster X) 那里为我的域获取了通配符 SSL 证书,例如域.com。

现在我有一个 Spring Boot 后端在服务器 A 上运行(未托管在 Hoster X,IP:1.1.1.1,URL:api.domain.com),我的前端在另一个服务器 B 上运行(托管在 Hoster X,IP :2.2.2.2,网址 app.domain.com)。

api.domain.com 到 IP 1.1.1.1 的重定向是通过 Hoster X 的 DNS 配置中的 A 资源记录设置的,因为 domain.com 是在此处注册的。

在我的 Spring Boot 后端上安装证书以确保前端和后端之间的通信安全的一般方法是什么?我是否必须下载通配符证书才能将其安装到后端密钥库中?据我所知,我只能在 Hoster X 服务器上托管的域上的主机菜单中配置 SSL 证书。

【问题讨论】:

    标签: security spring-boot ssl ssl-certificate server-configuration


    【解决方案1】:

    在后端服务器上,使用 openssl 和以下命令将私钥文件、证书文件和 CA 文件合并到一个 pkcs12 密钥库中:

    openssl pkcs12 -export -in <certfile> -inkey <keyfile> -out <keystorefile> -name tomcat -CAfile <cacertfile> -caname root
    

    系统会提示您输入密钥库密码。现在将生成的密钥库文件(扩展名“p12”)复制到 Spring Boot 应用程序的资源目录。

    现在在 application.yml 中设置 Spring Boot SSL 配置:

    server:
        port: 8443
    
    # Spring SSL configuration
        ssl:
            enabled: true
            key-store: classpath:keystore.p12
            key-store-password: "<KeystorePassword>"
            keyStoreType: PKCS12
            keyAlias: tomcat
    

    或者,将 keystore.p12 复制到后端服务器的某个位置,并使用绝对路径指向该位置:

    server:
        ssl:
            key-store: /path/to/keystore.p12
    

    在前端机器的 DNS 设置中创建一条 A 记录很重要,这样所有前端到后端的请求都通过调用域而不是 IP,因为通配符证书仅对域有效。

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 2018-09-07
      • 1970-01-01
      • 2014-12-30
      • 2020-07-28
      • 2014-11-25
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      相关资源
      最近更新 更多