Skip to contentSkip to conversation

binman: Tidy up some missing bintool docs

PATCH In review Simon Glass 2 participants 6 messages May 5 – May 8

lore
Share & tools
lore
#0 lore raw

v2 cover binman: Tidy up some missing bintool docs

Some of the bintools are missing documentation. This series adds the missing pieces to bring things up to scratch.

Changes in v2:
- Add patch to route PKCS#11 test fixtures through the bintools
- New patch in v2 (per Quentin's review): replace tools.run() of softhsm2-util, pkcs11-tool and p11-kit in ftest.py with the Bintool.run_cmd() wrapper that already exists
- Reword the docstring per Quentin's review: binman uses this bintool only as an availability check, not for runtime PKCS#11 operations

Simon Glass (4):
binman: Flesh out the p11-kit bintool docstring
binman: Flesh out the pkcs11-tool bintool docstring
binman: Flesh out the softhsm2-util bintool docstring
binman: Use bintool wrappers for PKCS#11 tools in tests

 tools/binman/btool/p11_kit.py       | 11 ++++++-
 tools/binman/btool/pkcs11_tool.py   | 11 ++++++-
 tools/binman/btool/softhsm2_util.py | 12 +++++++-
 tools/binman/ftest.py               | 46 ++++++++++++++---------------
 4 files changed, 54 insertions(+), 26 deletions(-)

---
base-commit: 57460fde4ba84d67de4066ee1141e89e8139ed23
branch: binj-us2

Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/4 binman: Flesh out the p11-kit bintool docstring

The Sphinx-generated bintools.rst currently produces an empty section for this bintool, since its class docstring is only a single line and so the body under the heading is blank.

Extend the docstring with a short description of what p11-kit does and how binman uses it, so the generated documentation has useful content.

---

Changes in v2:
- Reword the docstring per Quentin's review: binman uses this bintool only as an availability check, not for runtime PKCS#11 operations

 tools/binman/btool/p11_kit.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/binman/btool/p11_kit.py +10 -1
index 9d8d5d848b4..1bbece5bb2b 100644
@@ -7,7 +7,16 @@ from binman import bintool
 
 
 class Bintoolp11_kit(bintool.Bintool):
-    """p11-kit -- support tool for pkcs#11 libraries"""
+    """p11-kit -- support tool for pkcs#11 libraries
+
+    This bintool wraps the `p11-kit` command, a support tool for PKCS#11
+    modules. Binman uses this wrapper only to check that p11-kit is installed
+    (and to fetch it if missing); any actual PKCS#11 module discovery for
+    signing FIT images or capsules is done outside binman, by mkimage and the
+    OpenSSL PKCS#11 engine.
+
+    See https://p11-glue.github.io/p11-glue/p11-kit.html for more details.
+    """
     def __init__(self, name):
         super().__init__('p11-kit',
                          'Pkcs11 library modules tool',
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/4 binman: Flesh out the pkcs11-tool bintool docstring

In reply to Simon Glass

The Sphinx-generated bintools.rst currently produces an empty section for this bintool, since its class docstring is only a single line and so the body under the heading is blank.

Extend the docstring with a short description of what pkcs11-tool does and how binman uses it, so the generated documentation has useful content.

---

Changes in v2:
- Reword the docstring per Quentin's review: binman uses this bintool only as an availability check, not for runtime PKCS#11 operations

 tools/binman/btool/pkcs11_tool.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/binman/btool/pkcs11_tool.py +10 -1
index 673c0ea0ac3..ca80943f98c 100644
@@ -7,7 +7,16 @@ from binman import bintool
 
 
 class Bintoolpkcs11_tool(bintool.Bintool):
-    """pkcs11-tool -- support tool for managing pkcs#11 tokens"""
+    """pkcs11-tool -- support tool for managing pkcs#11 tokens
+
+    This bintool wraps the `pkcs11-tool` command from the OpenSC project for
+    managing objects stored in PKCS#11 tokens. Binman uses this wrapper only
+    to check that pkcs11-tool is installed (and to fetch it if missing); any
+    actual key or token management for signing FIT images or capsules is done
+    outside binman.
+
+    See https://github.com/OpenSC/OpenSC/wiki for more details.
+    """
     def __init__(self, name):
         super().__init__('pkcs11-tool',
                          'PKCS #11 tokens managing tool',
Signature · 1 line
2.43.0
#3 lore raw

PATCH v2 3/4 binman: Flesh out the softhsm2-util bintool docstring

In reply to Simon Glass

The Sphinx-generated bintools.rst currently produces an empty section for this bintool, since its class docstring is only a single line and so the body under the heading is blank.

Extend the docstring with a short description of what softhsm2-util does and how binman uses it, so the generated documentation has useful content.

---

Changes in v2:
- Reword the docstring per Quentin's review: binman uses this bintool only as an availability check, not for runtime PKCS#11 operations

 tools/binman/btool/softhsm2_util.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
tools/binman/btool/softhsm2_util.py +11 -1
index 869221d841d..fd2ff2d6473 100644
@@ -7,7 +7,17 @@ from binman import bintool
 
 
 class Bintoolsofthsm2_util(bintool.Bintool):
-    """SoftHSMv2 -- support tool for libsofthsm2"""
+    """SoftHSMv2 -- support tool for libsofthsm2
+
+    This bintool wraps the `softhsm2-util` command shipped with SoftHSMv2 (a
+    software implementation of a PKCS#11 token). Binman uses this wrapper only
+    to check that softhsm2-util is installed (and to fetch it if missing); any
+    actual token initialisation or key import for signing FIT images or
+    capsules is done outside binman, typically via mkimage and the OpenSSL
+    PKCS#11 engine.
+
+    See https://www.opendnssec.org/softhsm/ for more details.
+    """
     def __init__(self, name):
         super().__init__('softhsm2-util',
                          'SoftHSMv2 support tool for libsofthsm2',
Signature · 1 line
2.43.0
#4 lore raw

PATCH v2 4/4 binman: Use bintool wrappers for PKCS#11 tools in tests

In reply to Simon Glass

The PKCS#11 signing tests in ftest.py call tools.run('softhsm2-util', ...) directly (and the equivalent for pkcs11-tool and p11-kit), even though the test setup has already constructed the corresponding Bintool instances. As Quentin Schulz observed on v1, the bintool wrapper for these tools is currently used only as an "is this installed?" probe.

Route the eight remaining call sites in ftest.py through <bintool>.run_cmd(...), which the Bintool base class already provides. The change is test-side only; no production binman code calls these tools.

---

Changes in v2:
- New patch in v2 (per Quentin's review): replace tools.run() of softhsm2-util, pkcs11-tool and p11-kit in ftest.py with the Bintool.run_cmd() wrapper that already exists

 tools/binman/ftest.py | 46 +++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)
tools/binman/ftest.py +23 -23
index ca5149ee654..273d0ff0379 100644
@@ -7560,7 +7560,7 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         self._CheckBintool(p11_kit)
 
         p11_kit_config = configparser.ConfigParser()
-        out = tools.run('p11-kit', 'print-config')
+        out = p11_kit.run_cmd('print-config')
         p11_kit_config.read_string(out)
         softhsm2_lib = p11_kit_config.get('softhsm2', 'module',
                                            fallback=None)
@@ -7569,16 +7569,16 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         with unittest.mock.patch.dict('os.environ',
                                       {'SOFTHSM2_CONF': softhsm2_conf,
                                        'PKCS11_MODULE_PATH': softhsm2_lib}):
-                tools.run('softhsm2-util', '--init-token', '--free', '--label',
-                          'U-Boot token', '--pin', '1111', '--so-pin',
-                          '222222')
-                tools.run('pkcs11-tool', '--module', softhsm2_lib,
-                          '--write-object', cert_file, '--pin', '1111',
-                          '--type', 'cert', '--id', '999999', '--label',
-                          'test_cert', '--login')
-                tools.run('softhsm2-util', '--import', private_key, '--token',
-                          'U-Boot token', '--label', 'test_key', '--id', '999999',
-                          '--pin', '1111')
+                softhsm2_util.run_cmd('--init-token', '--free', '--label',
+                                      'U-Boot token', '--pin', '1111',
+                                      '--so-pin', '222222')
+                pkcs11_tool.run_cmd('--module', softhsm2_lib,
+                                    '--write-object', cert_file, '--pin', '1111',
+                                    '--type', 'cert', '--id', '999999', '--label',
+                                    'test_cert', '--login')
+                softhsm2_util.run_cmd('--import', private_key, '--token',
+                                      'U-Boot token', '--label', 'test_key',
+                                      '--id', '999999', '--pin', '1111')
                 data = self._DoReadFile('capsule/signed_pkcs11.dts')
 
         self._CheckCapsule(data, signed_capsule=True)
@@ -8230,12 +8230,12 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
 
         with unittest.mock.patch.dict('os.environ',
                                       {'SOFTHSM2_CONF': softhsm2_conf}):
-            tools.run('softhsm2-util', '--init-token', '--free', '--label',
-                      'U-Boot token', '--pin', '1111', '--so-pin',
-                      '222222')
-            tools.run('softhsm2-util', '--import', private_key, '--token',
-                      'U-Boot token', '--label', 'test_key', '--id', '999999',
-                      '--pin', '1111')
+            softhsm2_util.run_cmd('--init-token', '--free', '--label',
+                                  'U-Boot token', '--pin', '1111',
+                                  '--so-pin', '222222')
+            softhsm2_util.run_cmd('--import', private_key, '--token',
+                                  'U-Boot token', '--label', 'test_key',
+                                  '--id', '999999', '--pin', '1111')
 
         # Make sure the private key can only be accessed through the engine
         os.remove(private_key)
@@ -8305,12 +8305,12 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
 
         with unittest.mock.patch.dict('os.environ',
                                       {'SOFTHSM2_CONF': softhsm2_conf}):
-            tools.run('softhsm2-util', '--init-token', '--free', '--label',
-                      'U-Boot prod token', '--pin', '1234', '--so-pin',
-                      '222222')
-            tools.run('softhsm2-util', '--import', private_key, '--token',
-                      'U-Boot prod token', '--label', 'prod', '--id', '999999',
-                      '--pin', '1234')
+            softhsm2_util.run_cmd('--init-token', '--free', '--label',
+                                  'U-Boot prod token', '--pin', '1234',
+                                  '--so-pin', '222222')
+            softhsm2_util.run_cmd('--import', private_key, '--token',
+                                  'U-Boot prod token', '--label', 'prod',
+                                  '--id', '999999', '--pin', '1234')
 
         # Make sure the private key can only be accessed through the engine
         os.remove(private_key)
Signature · 1 line
2.43.0
Reviewed-by on the v2 series
#5 lore raw
In reply to Simon Glass

Hi Simon,

Quoted 17 lines · Simon Glass

Some of the bintools are missing documentation. This series adds the missing pieces to bring things up to scratch.

Changes in v2:
- Add patch to route PKCS#11 test fixtures through the bintools
- New patch in v2 (per Quentin's review): replace tools.run() of softhsm2-util, pkcs11-tool and p11-kit in ftest.py with the Bintool.run_cmd() wrapper that already exists
- Reword the docstring per Quentin's review: binman uses this bintool only as an availability check, not for runtime PKCS#11 operations

Simon Glass (4):
binman: Flesh out the p11-kit bintool docstring
binman: Flesh out the pkcs11-tool bintool docstring
binman: Flesh out the softhsm2-util bintool docstring
binman: Use bintool wrappers for PKCS#11 tools in tests

Quoted 6 lines
  tools/binman/btool/p11_kit.py       | 11 ++++++-
  tools/binman/btool/pkcs11_tool.py   | 11 ++++++-
  tools/binman/btool/softhsm2_util.py | 12 +++++++-
  tools/binman/ftest.py               | 46 ++++++++++++++---------------
  4 files changed, 54 insertions(+), 26 deletions(-)

Technically the docstring in patch 1 to 3 is incorrect now that we have patch 4 and we use the bintool to call commands on the wrapped binaries.

It's a detail and I don't have anything else to suggest for rephrasing.

Thanks!
Quentin