【问题标题】:How to run a fully FIPS compliant Spring Boot application如何运行完全符合 FIPS 的 Spring Boot 应用程序
【发布时间】:2019-12-02 16:02:38
【问题描述】:
【问题讨论】:
标签:
spring-boot
tomcat
fips
【解决方案1】:
第 1 部分:“Tomcat 在 FIPS 模式下运行”,在 Ubuntu 上
前言 #1:可以在here 找到一些通用(但不完整)说明。
前言 #2:以下要求 OpenSSL 和 FIPS 140-2 认证模块。在 Ubuntu 上,这些仅适用于 Ubuntu 16.04 上的“Ubuntu Advantage Advanced 客户”!请参阅here 和here。
-
$ sudo apt install libapr1 libapr1-dev
(来自here,可能是sudo apt install libapr1-dev libssl-dev,请参阅here)
- 从here下载tomcat-native-1.2.23-src,解压,转到
tomcat-native-1.2.23-src/native/
$ ./configure --with-apr=/usr/bin/apr-1-config --with-java-home=/path/to/java-home/ --with-ssl=yes
$ make
- 将
-Djava.library.path=/path/to/tomcat-native-1.2.23-src/native/.libs 添加到jvm args
- 将以下内容添加到您的项目中
import org.apache.catalina.core.AprLifecycleListener;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AprConfig {
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
@Override
public Ssl getSsl() {
// avoid "IllegalStateException: To use SSL, the connector's protocol handler must be an AbstractHttp11JsseProtocol subclass":
return null;
}
};
// enable APR:
factory.setProtocol("org.apache.coyote.http11.Http11AprProtocol");
AprLifecycleListener aprLifecycleListener = new AprLifecycleListener();
// will throw "FIPS was not available to tcnative at build time. You will need to re-build tcnative against an OpenSSL with FIPS." with default OpenSSL:
aprLifecycleListener.setFIPSMode("on");
factory.addContextLifecycleListeners(aprLifecycleListener);
return factory;
}
}
第 2 部分:“JDK 使用 FIPS ssl 提供程序”
Java 使用 JCE "to use stronger versions of standard algorithms"。需要为最高 8u161、7u171 和 6u16 的 JDK 安装相应的策略文件; “在这些版本及更高版本中,策略文件已包含在内,但默认情况下未启用”,而“JDK 9 及更高版本附带并默认使用无限策略文件”。
JCE 是一个由一些“提供者”实现的接口(就像 JDBC 是一个必须实现的接口)。尽管 Oracle 甚至有一个实现,但符合 FIPS 的提供者并不多(请参阅this list)。我发现只有一个声称与 Java 11 兼容,即版本 1.0.2 中的 "Bouncy Castle Crypto API" - 目前“可用于早期访问”,请参阅 Java FIPS Roadmap。所以这里也要考虑 Java 版本 (see)。
结论
运行完全符合 FIPS 的 Spring Boot 应用程序需要
- 一些配置(见上文)
- 具有 FIPS 兼容库的操作系统支持您的 Java 版本