From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.denx.de
Cc: Neha Malcom Francis <n-francis@ti.com>,
Anshul Dalal <anshuld@ti.com>, Simon Glass <sjg@chromium.org>,
Tom Rini <trini@konsulko.com>, Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH v2 1/7] binman: openssl: refactor creation of Distinguished Name section from dict
Date: Fri, 17 Jul 2026 15:58:18 +0200 [thread overview]
Message-ID: <20260717135824.2142135-2-ravi@prevas.dk> (raw)
In-Reply-To: <20260717135824.2142135-1-ravi@prevas.dk>
Instead of manually expanding the req_dist_name_dict, create a helper
function for creating a config section from any dict. That will also
automatically allow other fields to be emitted.
We can allow a field with multiple values, e.g. "OU" -> ["First OU", "Second OU"],
and encode that in the config file using
1.OU = First OU
2.OU = Second OU
as documented in 'man 5 config'.
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---
tools/binman/btool/openssl.py | 58 +++++++++++++++++------------------
1 file changed, 28 insertions(+), 30 deletions(-)
diff --git a/tools/binman/btool/openssl.py b/tools/binman/btool/openssl.py
index b26f087c447..84413428e1e 100644
--- a/tools/binman/btool/openssl.py
+++ b/tools/binman/btool/openssl.py
@@ -36,6 +36,28 @@ class Bintoolopenssl(bintool.Bintool):
name, 'openssl cryptography toolkit',
version_regex=r'OpenSSL (.*) \(', version_args='version')
+ @staticmethod
+ def dict_to_config_section(section_name, data):
+ """Generate a section for an openssl config file from key-value pairs
+
+ Args:
+ section_name: The name of the section
+ data: dict containing key-value pairs
+
+ Returns:
+ A multi-line string containing the section definition.
+
+ Each key must be a string, each value can be a string or a list of strings.
+ """
+ sec = f'[ {section_name} ]\n'
+ for field, value in data.items():
+ if isinstance(value, str):
+ sec += f'{field:22s} = {value}\n'
+ elif isinstance(value, list):
+ for i, s in enumerate(value):
+ sec += f'{i+1}.{field:20s} = {s}\n'
+ return sec
+
def x509_cert(self, cert_fname, input_fname, key_fname, cn, revision,
config_fname):
"""Create a certificate
@@ -92,8 +114,7 @@ imageSize = INTEGER:{len(indata)}
sw_rev (int): Software revision
config_fname (str): Filename to write fconfig into
req_dist_name_dict (dict): Dictionary containing key-value pairs of
- req_distinguished_name section extensions, must contain extensions for
- C, ST, L, O, OU, CN and emailAddress
+ req_distinguished_name section extensions
firewall_cert_data (dict):
- auth_in_place (int): The Priv ID for copying as the
specific host in firewall protected region
@@ -114,14 +135,7 @@ x509_extensions = v3_ca
prompt = no
dirstring_type = nobmp
-[ req_distinguished_name ]
-C = {req_dist_name_dict['C']}
-ST = {req_dist_name_dict['ST']}
-L = {req_dist_name_dict['L']}
-O = {req_dist_name_dict['O']}
-OU = {req_dist_name_dict['OU']}
-CN = {req_dist_name_dict['CN']}
-emailAddress = {req_dist_name_dict['emailAddress']}
+{self.dict_to_config_section('req_distinguished_name', req_dist_name_dict)}
[ v3_ca ]
basicConstraints = CA:true
@@ -163,8 +177,7 @@ numFirewallRegions = INTEGER:{firewall_cert_data['num_firewalls']}
sw_rev (int): Software revision
config_fname (str): Filename to write fconfig into
req_dist_name_dict (dict): Dictionary containing key-value pairs of
- req_distinguished_name section extensions, must contain extensions for
- C, ST, L, O, OU, CN and emailAddress
+ req_distinguished_name section extensions
cert_type (int): Certification type
bootcore (int): Booting core
bootcore_opts(int): Booting core option, lockstep (0) or split (2) mode
@@ -184,14 +197,7 @@ numFirewallRegions = INTEGER:{firewall_cert_data['num_firewalls']}
prompt = no
dirstring_type = nobmp
- [ req_distinguished_name ]
-C = {req_dist_name_dict['C']}
-ST = {req_dist_name_dict['ST']}
-L = {req_dist_name_dict['L']}
-O = {req_dist_name_dict['O']}
-OU = {req_dist_name_dict['OU']}
-CN = {req_dist_name_dict['CN']}
-emailAddress = {req_dist_name_dict['emailAddress']}
+{self.dict_to_config_section('req_distinguished_name', req_dist_name_dict)}
[ v3_ca ]
basicConstraints = CA:true
@@ -252,8 +258,7 @@ emailAddress = {req_dist_name_dict['emailAddress']}
sw_rev (int): Software revision
config_fname (str): Filename to write fconfig into
req_dist_name_dict (dict): Dictionary containing key-value pairs of
- req_distinguished_name section extensions, must contain extensions for
- C, ST, L, O, OU, CN and emailAddress
+ req_distinguished_name section extensions
cert_type (int): Certification type
bootcore (int): Booting core
load_addr (int): Load address of image
@@ -274,14 +279,7 @@ x509_extensions = v3_ca
prompt = no
dirstring_type = nobmp
-[ req_distinguished_name ]
-C = {req_dist_name_dict['C']}
-ST = {req_dist_name_dict['ST']}
-L = {req_dist_name_dict['L']}
-O = {req_dist_name_dict['O']}
-OU = {req_dist_name_dict['OU']}
-CN = {req_dist_name_dict['CN']}
-emailAddress = {req_dist_name_dict['emailAddress']}
+{self.dict_to_config_section('req_distinguished_name', req_dist_name_dict)}
[ v3_ca ]
basicConstraints = CA:true
--
2.55.0
next prev parent reply other threads:[~2026-07-17 13:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 13:58 [PATCH v2 0/7] k3-binman ergonomics Rasmus Villemoes
2026-07-17 13:58 ` Rasmus Villemoes [this message]
2026-07-17 13:58 ` [PATCH v2 2/7] binman: x509_cert: allow and parse distinguished-name subnode Rasmus Villemoes
2026-07-17 13:58 ` [PATCH v2 3/7] binman: x509: fix CN emitted for basic x509 certificates Rasmus Villemoes
2026-07-17 13:58 ` [PATCH v2 4/7] k3-binman.dtsi: add keyfile_template node Rasmus Villemoes
2026-07-17 13:58 ` [PATCH v2 5/7] k3-binman.dtsi: add empty distinguished_name_template Rasmus Villemoes
2026-07-17 13:58 ` [PATCH v2 6/7] k3-binman.dtsi: insert keyfile and distinguished name templates in all ti-secure(-rom) nodes Rasmus Villemoes
2026-07-17 13:58 ` [PATCH v2 7/7] doc: k3.rst: describe use of keyname and distinguished_name binman templates Rasmus Villemoes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260717135824.2142135-2-ravi@prevas.dk \
--to=ravi@prevas.dk \
--cc=anshuld@ti.com \
--cc=n-francis@ti.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox