Skip to contentSkip to conversation

openssl: add fips support

PATCH Superseded Yi Zhao 2 participants 7 messages May 9, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yi Zhao

author
#0 lore raw

PATCH 1/1 openssl: add fips support

* Add PACKAGECONFIG[fips] to enable fips build.
* Split a new package openssl-ossl-module-fips for fips.so.
* Add pkg_postinst_ontarget for openssl-ossl-module-fips to ensure the config file fipsmodule.cnf is created on target.

---
 .../openssl/openssl_3.5.0.bb                  | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
meta/recipes-connectivity/openssl/openssl_3.5.0.bb +17 -2
index 865e04deb2..fdb304c73c 100644
@@ -31,6 +31,7 @@ PACKAGECONFIG[cryptodev-linux] = "enable-devcryptoeng,disable-devcryptoeng,crypt
 PACKAGECONFIG[no-tls1] = "no-tls1"
 PACKAGECONFIG[no-tls1_1] = "no-tls1_1"
 PACKAGECONFIG[manpages] = ""
+PACKAGECONFIG[fips] = "enable-fips"
 
 B = "${WORKDIR}/build"
 do_configure[cleandirs] = "${B}"
@@ -154,7 +155,9 @@ do_compile:append () {
 }
 
 do_install () {
-	oe_runmake DESTDIR="${D}" MANDIR="${mandir}" MANSUFFIX=ssl install_sw install_ssldirs ${@bb.utils.contains('PACKAGECONFIG', 'manpages', 'install_docs', '', d)}
+	oe_runmake DESTDIR="${D}" MANDIR="${mandir}" MANSUFFIX=ssl install_sw install_ssldirs \
+	    ${@bb.utils.contains('PACKAGECONFIG', 'manpages', 'install_docs', '', d)} \
+	    ${@bb.utils.contains('PACKAGECONFIG', 'fips', 'install_fips', '', d)}
 
 	oe_multilib_header openssl/opensslconf.h
 	oe_multilib_header openssl/configuration.h
@@ -172,6 +175,11 @@ do_install () {
 	ln -sf ${@oe.path.relative('${libdir}/ssl-3', '${sysconfdir}/ssl/certs')} ${D}${libdir}/ssl-3/certs
 	ln -sf ${@oe.path.relative('${libdir}/ssl-3', '${sysconfdir}/ssl/private')} ${D}${libdir}/ssl-3/private
 	ln -sf ${@oe.path.relative('${libdir}/ssl-3', '${sysconfdir}/ssl/openssl.cnf')} ${D}${libdir}/ssl-3/openssl.cnf
+
+	# Generate fipsmodule.cnf on first boot
+	if ${@bb.utils.contains('PACKAGECONFIG', 'fips', 'true', 'false', d)}; then
+		rm -f ${D}${libdir}/ssl-3/fipsmodule.cnf
+	fi
 }
 
 do_install:append:class-native () {
@@ -229,12 +237,18 @@ do_install_ptest() {
 	ln -s ${libdir}/ossl-modules/ ${D}${PTEST_PATH}/providers
 }
 
+pkg_postinst_ontarget:${PN}-ossl-module-fips () {
+	if test -f ${libdir}/ossl-modules/fips.so; then
+		${bindir}/openssl fipsinstall -out ${libdir}/ssl-3/fipsmodule.cnf -module ${libdir}/ossl-modules/fips.so
+	fi
+}
+
 # Add the openssl.cnf file to the openssl-conf package. Make the libcrypto
 # package RRECOMMENDS on this package. This will enable the configuration
 # file to be installed for both the openssl-bin package and the libcrypto
 # package since the openssl-bin package depends on the libcrypto package.
 
-PACKAGES =+ "libcrypto libssl openssl-conf ${PN}-engines ${PN}-misc ${PN}-ossl-module-legacy"
+PACKAGES =+ "libcrypto libssl openssl-conf ${PN}-engines ${PN}-misc ${PN}-ossl-module-legacy ${PN}-ossl-module-fips"
 
 FILES:libcrypto = "${libdir}/libcrypto${SOLIBS}"
 FILES:libssl = "${libdir}/libssl${SOLIBS}"
@@ -246,6 +260,7 @@ FILES:${PN}-engines = "${libdir}/engines-3"
 FILES:${PN}-engines:append:mingw32:class-nativesdk = " ${prefix}${libdir}/engines-3"
 FILES:${PN}-misc = "${libdir}/ssl-3/misc ${bindir}/c_rehash"
 FILES:${PN}-ossl-module-legacy = "${libdir}/ossl-modules/legacy.so"
+FILES:${PN}-ossl-module-fips = "${libdir}/ossl-modules/fips.so"
 FILES:${PN} =+ "${libdir}/ssl-3/* ${libdir}/ossl-modules/"
 FILES:${PN}:append:class-nativesdk = " ${SDKPATHNATIVE}/environment-setup.d/openssl.sh"
 
Signature · 1 line
2.48.1
#1 lore raw

meta/recipes-connectivity/openssl/openssl_3.5.0.bb do_install_ptest() { · line 245

Quoted 12 lines · Yi Zhao via lists.openembedded.org

* Add pkg_postinst_ontarget for openssl-ossl-module-fips to ensure the config file fipsmodule.cnf is created on target.

meta/recipes-connectivity/openssl/openssl_3.5.0.bb +10 -0
+       # Generate fipsmodule.cnf on first boot
+       if ${@bb.utils.contains('PACKAGECONFIG', 'fips', 'true', 'false', d)}; then
+               rm -f ${D}${libdir}/ssl-3/fipsmodule.cnf
+       fi
+pkg_postinst_ontarget:${PN}-ossl-module-fips () {
+       if test -f ${libdir}/ossl-modules/fips.so; then
+               ${bindir}/openssl fipsinstall -out ${libdir}/ssl-3/fipsmodule.cnf -module ${libdir}/ossl-modules/fips.so
+       fi
+}
+

This needs to be better explained:

- why is the standard fipsmodule.cnf deleted in do_install? If upstream installs it, then why can't we simply use it?

- why re-generation of that file has to happen on target? Can we use native openssl instead? Or run target openssl with qemu usermode?

Alex

author
#2 lore raw
Quoted 16 lines · Alexander Kanavin

meta/recipes-connectivity/openssl/openssl_3.5.0.bb do_install_ptest() { · line 245

Quoted 12 lines · Yi Zhao via lists.openembedded.org

* Add pkg_postinst_ontarget for openssl-ossl-module-fips to ensure the config file fipsmodule.cnf is created on target.

meta/recipes-connectivity/openssl/openssl_3.5.0.bb +10 -0
+       # Generate fipsmodule.cnf on first boot
+       if ${@bb.utils.contains('PACKAGECONFIG', 'fips', 'true', 'false', d)}; then
+               rm -f ${D}${libdir}/ssl-3/fipsmodule.cnf
+       fi
+pkg_postinst_ontarget:${PN}-ossl-module-fips () {
+       if test -f ${libdir}/ossl-modules/fips.so; then
+               ${bindir}/openssl fipsinstall -out ${libdir}/ssl-3/fipsmodule.cnf -module ${libdir}/ossl-modules/fips.so
+       fi
+}
+

This needs to be better explained:

Quoted 5 lines

- why is the standard fipsmodule.cnf deleted in do_install? If upstream installs it, then why can't we simply use it?

- why re-generation of that file has to happen on target? Can we use native openssl instead? Or run target openssl with qemu usermode?

The "openssl fipsinstall" command will do the following things:
1. Runs the FIPS module self tests on target
2. Generates config file fipsmodule.conf containing information about the module such as the calculated MAC of the FIPS module and the MAC of the value of the self tests status

We should not use the same fipsmodule.cnf on different machines. So it will be generated on the target.

//Yi

Quoted 2 lines

Alex

#3 lore raw
Quoted 8 lines

The "openssl fipsinstall" command will do the following things:
1. Runs the FIPS module self tests on target
2. Generates config file fipsmodule.conf containing information about the module such as the calculated MAC of the FIPS module and the MAC of the value of the self tests status

We should not use the same fipsmodule.cnf on different machines. So it will be generated on the target.

Thanks. Is the original file (which is installed and then deleted) pre-packaged with openssl tarball, or generated during build? Can you show the difference between that, and the file that gets generated on target? I'd like to see the actual content.

Alex

author
#4 lore raw
Quoted 6 lines · Alexander Kanavin via lists.openembedded.org
Quoted 6 lines

The "openssl fipsinstall" command will do the following things:
1. Runs the FIPS module self tests on target
2. Generates config file fipsmodule.conf containing information about the module such as the calculated MAC of the FIPS module and the MAC of the value of the self tests status

Quoted 6 lines
Quoted 2 lines

We should not use the same fipsmodule.cnf on different machines. So it will be generated on the target.

Thanks. Is the original file (which is installed and then deleted) pre-packaged with openssl tarball, or generated during build? Can you show the difference between that, and the file that gets generated on target? I'd like to see the actual content.

The original file is generated by util/mk-fipsmodule-cnf.pl during build.

Here is the diff result:

$ diff fipsmodule.cnf.orig  fipsmodule.cnf
6,29c6,30
< module-mac = 8A:6E:E0:65:18:AF:1C:1C:67:FA:CF:8E:89:9B:67:03:4A:1F:0E:87:1A:34:23:D3:5D:90:73:98:32:A3:AC:31
< tls1-prf-ems-check = 1
< no-short-mac = 1
< drbg-no-trunc-md = 1
< signature-digest-check = 1
< dsa-sign-disabled = 1
< hkdf-digest-check = 1
< tls13-kdf-digest-check = 1
< tls1-prf-digest-check = 1
< sshkdf-digest-check = 1
< sskdf-digest-check = 1
< x963kdf-digest-check = 1
< tdes-encrypt-disabled = 1
< rsa-pkcs15-pad-disabled = 1
< rsa-pss-saltlen-check = 1
< rsa-sign-x931-pad-disabled = 1
< hkdf-key-check = 1
< kbkdf-key-check = 1
< tls13-kdf-key-check = 1
< tls1-prf-key-check = 1
< sshkdf-key-check = 1
< sskdf-key-check = 1
< x963kdf-key-check = 1
< x942kdf-key-check = 1
---
Quoted 17 lines

hmac-key-check = 0
kmac-key-check = 0
tls1-prf-ems-check = 0
no-short-mac = 0
drbg-no-trunc-md = 0
signature-digest-check = 0
hkdf-digest-check = 0
tls13-kdf-digest-check = 0
tls1-prf-digest-check = 0
sshkdf-digest-check = 0
sskdf-digest-check = 0
x963kdf-digest-check = 0
dsa-sign-disabled = 0
tdes-encrypt-disabled = 0
rsa-pkcs15-pad-disabled = 0
rsa-pss-saltlen-check = 0
rsa-sign-x931-pad-disabled = 0

Quoted 8 lines

hkdf-key-check = 0
kbkdf-key-check = 0
tls13-kdf-key-check = 0
tls1-prf-key-check = 0
sshkdf-key-check = 0
sskdf-key-check = 0
x963kdf-key-check = 0
x942kdf-key-check = 0

31,33c32,33
< ecdh-cofactor-check = 1
< hmac-key-check = 1
< kmac-key-check = 1
---

Quoted 14 lines

ecdh-cofactor-check = 0
module-mac = 83:F9:46:E4:60:88:FC:B7:CF:7D:CA:30:1F:9D:9A:FB:4C:18:5F:57:68:44:C7:2D:8D:8A:CD:92:21:D4:10:44

Alex

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#216203): https://lists.openembedded.org/g/openembedded-core/message/216203
Mute This Topic: https://lists.openembedded.org/mt/112895798/7283133
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

author
#6 lore raw
Quoted 8 lines · Alexander Kanavin
Quoted 1 line · Yi Zhao

The original file is generated by util/mk-fipsmodule-cnf.pl during build.

Thanks. It's a little odd that this script is not using 'openssl fipsinstall', but rather seems to be writing out a hardcoded config:
https://github.com/openssl/openssl/blob/master/util/mk-fipsmodule-cnf.pl

Otherwise looks fine - you can send a v2 with the information provided in responses to questions added to the commit message.

Thanks, I will send V2.

//Yi

Quoted 2 lines

Alex