diff mbox series

Pass path for input and output for CUSTOM sign

Message ID 20241125094959.20420-1-stefano.babic@swupdate.org
State Accepted
Headers show
Series Pass path for input and output for CUSTOM sign | expand

Commit Message

Stefano Babic Nov. 25, 2024, 9:49 a.m. UTC
Signing with custom tool is currently tricky because the path to the
file to be signed and to the siignature are not passed to the external
tool. Add automatically the path for sw-description and sw-description
as last two parameters before calling the script. The syntax will
become:

	--sign CUSTOM, <own tool>,<parms1>,..<parms-n>

And the generator will execute:

<own tool> <parms1> ..<parms-n> <path to sw-desc> <path to sig>

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
Reported-by: Daniel Braunwarth <oss@braunwarth.dev>
---
 swugenerator/main.py     | 4 ++--
 swugenerator/swu_sign.py | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

--
2.43.0
diff mbox series

Patch

diff --git a/swugenerator/main.py b/swugenerator/main.py
index 8785714..f6d8404 100644
--- a/swugenerator/main.py
+++ b/swugenerator/main.py
@@ -136,9 +136,9 @@  def parse_signing_option(
         return SWUSignPKCS11(sign_parms[1])
     if cmd == "CUSTOM":
         # Format : CUSTOM,<custom command>
-        if len(sign_parms) != 2 or not all(sign_parms):
+        if len(sign_parms) < 2 or not all(sign_parms):
             raise InvalidSigningOption("CUSTOM requires custom command")
-        return SWUSignCustom(sign_parms[1])
+        return SWUSignCustom(sign_parms[1:])
     raise InvalidSigningOption("Unknown signing command")


diff --git a/swugenerator/swu_sign.py b/swugenerator/swu_sign.py
index f73802e..5bd0db3 100644
--- a/swugenerator/swu_sign.py
+++ b/swugenerator/swu_sign.py
@@ -97,10 +97,12 @@  class SWUSignCustom(SWUSign):
     def __init__(self, cmd):
         super().__init__()
         self.type = "CUSTOM"
-        self.custom = cmd.split()
+        self.custom = cmd

-    def prepare_cmd(self, *_):
-        self.signcmd = copy.deepcopy(self.custom)
+    def prepare_cmd(self, sw_desc_in, sw_desc_sign):
+        self.signcmd = self.custom
+        self.signcmd.append(sw_desc_in)
+        self.signcmd.append(sw_desc_sign)


 # Note: tested with Nitrokey HSM