Skip to contentSkip to conversation

openssl: add support for config snippet includes

PATCH In review Jan Luebbe 2 participants 3 messages Feb 16 – Feb 24

lore
Share & tools
lore

Jan Luebbe

author
#0 lore raw

PATCH v2 1/1 openssl: add support for config snippet includes

This allows configuration (such as enabling providers) to be done by adding snippet files to /etc/ssl/openssl.cnf.d instead of modifying a copy of the full configuration file. As new snippets can be added from separate recipes, targeted changes can be done in multiple layers.

For example, the pkcs11-provider can be enabled by adding a pkcs11.cnf containing something like:
[default_sect]
activate = 1

[provider_sect]
pkcs11 = pkcs11_sect

[pkcs11_sect]
pkcs11-module-path = /usr/lib/libckteec.so.0 pkcs11-module-quirks = no-operation-state no-deinit pkcs11-module-encode-provider-uri-to-pem = true activate = 1

---
 meta/recipes-connectivity/openssl/openssl_3.5.5.bb | 7 +++++++
 1 file changed, 7 insertions(+)
meta/recipes-connectivity/openssl/openssl_3.5.5.bb +7 -0
index c0d02b617ba5..94fda03ea206 100644
@@ -186,6 +186,13 @@ do_install () {
 	fi
 }
 
+do_install:append:class-target () {
+        # Add support for config snippet includes
+        echo "" >> ${D}${sysconfdir}/ssl/openssl.cnf
+        echo ".include ${sysconfdir}/ssl/openssl.cnf.d" >> ${D}${sysconfdir}/ssl/openssl.cnf
+        install -d ${D}${sysconfdir}/ssl/openssl.cnf.d
+}
+
 do_install:append:class-native () {
 	create_wrapper ${D}${bindir}/openssl \
 	    OPENSSL_CONF=\${OPENSSL_CONF:-${libdir}/ssl-3/openssl.cnf} \
Signature · 1 line
2.47.3
#1 lore raw
Quoted 29 lines · Jan Luebbe

This allows configuration (such as enabling providers) to be done by adding snippet files to /etc/ssl/openssl.cnf.d instead of modifying a copy of the full configuration file. As new snippets can be added from separate recipes, targeted changes can be done in multiple layers.

For example, the pkcs11-provider can be enabled by adding a pkcs11.cnf containing something like:
[default_sect]
activate = 1

[provider_sect]
pkcs11 = pkcs11_sect

[pkcs11_sect]
pkcs11-module-path = /usr/lib/libckteec.so.0 pkcs11-module-quirks = no-operation-state no-deinit pkcs11-module-encode-provider-uri-to-pem = true activate = 1

---
 meta/recipes-connectivity/openssl/openssl_3.5.5.bb | 7 +++++++
 1 file changed, 7 insertions(+)
meta/recipes-connectivity/openssl/openssl_3.5.5.bb +0 -0
index c0d02b617ba5..94fda03ea206 100644

meta/recipes-connectivity/openssl/openssl_3.5.5.bb do_install () { · line 195

Quoted 10 lines
meta/recipes-connectivity/openssl/openssl_3.5.5.bb +7 -0
@@ -186,6 +186,13 @@ do_install () {
 	fi
 }
 
+do_install:append:class-target () {
+        # Add support for config snippet includes
+        echo "" >> ${D}${sysconfdir}/ssl/openssl.cnf
+        echo ".include ${sysconfdir}/ssl/openssl.cnf.d" >> ${D}${sysconfdir}/ssl/openssl.cnf
+        install -d ${D}${sysconfdir}/ssl/openssl.cnf.d
+}
+

Has there been any discussion with upstream about adding this to openssl.cnf by default?

I see that CentOS Stream 10 has a similar include directive in openssl.cnf, but Debian does not. I wonder if upstream considers this to be "safe".

Best regards,

Signature · 1 line
Paul Barker
author
#2 lore raw
Quoted 37 lines · Paul Barker
Quoted 36 lines · Jan Luebbe

This allows configuration (such as enabling providers) to be done by adding snippet files to /etc/ssl/openssl.cnf.d instead of modifying a copy of the full configuration file. As new snippets can be added from separate recipes, targeted changes can be done in multiple layers.

For example, the pkcs11-provider can be enabled by adding a pkcs11.cnf containing something like:
  [default_sect]
  activate = 1

  [provider_sect]
  pkcs11 = pkcs11_sect

  [pkcs11_sect]
  pkcs11-module-path = /usr/lib/libckteec.so.0 pkcs11-module-quirks = no-operation-state no-deinit pkcs11-module-encode-provider-uri-to-pem = true activate = 1

---
 meta/recipes-connectivity/openssl/openssl_3.5.5.bb | 7 +++++++

 1 file changed, 7 insertions(+)
meta/recipes-connectivity/openssl/openssl_3.5.5.bb +0 -0
index c0d02b617ba5..94fda03ea206 100644
@@ -186,6 +186,13 @@ do_install () {

  fi
 }

+do_install:append:class-target () {
+        # Add support for config snippet includes +        echo "" >> ${D}${sysconfdir}/ssl/openssl.cnf

Quoted 8 lines

meta/recipes-connectivity/openssl/openssl_3.5.5.bb do_install () { · line 195

Quoted 5 lines

+        echo ".include ${sysconfdir}/ssl/openssl.cnf.d" >> ${D}${sysconfdir}/ssl/openssl.cnf
+        install -d ${D}${sysconfdir}/ssl/openssl.cnf.d

meta/recipes-connectivity/openssl/openssl_3.5.5.bb +2 -0
+}
+

Has there been any discussion with upstream about adding this to openssl.cnf by default?

It's a built-in feature in OpenSSL since 1.1.1
https://github.com/openssl/openssl/pull/5351
and was introduced specifically for simplifying configurations when shipping OpenSSL as part of an OS
https://github.com/openssl/openssl/issues/4962

Adding configuration necessary for engines (now also providers) was also mentioned in the issue.

https://docs.openssl.org/3.6/man5/config/ says "As a general rule, the pathname should be an absolute path", which is the case here.

Quoted 3 lines

I see that CentOS Stream 10 has a similar include directive in openssl.cnf, but Debian does not. I wonder if upstream considers this to be "safe".

The approach of snippets in .d directories is used by may other packages as well (systemd, openssh, iproute2, sudo, udev, chrony). In some cases the search paths are hard-coded, in others they are explicitly configured in the "top level" configuration.

Configuration in /etc needs to be protected against unauthorized modification, but that applies to /ssl/openssl.cnf.d/foo.cnf in the same way as for /ssl/openssl.cnf.

Best regards
Jan