From 01cd8be15ec232a669d1d6b70986ba1db5ff60b6 Mon Sep 17 00:00:00 2001 From: Jack Cushman Date: Mon, 2 Dec 2024 09:21:35 -0500 Subject: [PATCH] Update openssl flags - include nonce in timestamp request - explicitly specify signing algorithm - add cades attribute and drop smimecap attribute from signature --- README.md | 4 ++-- src/nabit/lib/sign.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dd09230..ed215bb 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ The signatures directory can contain two kinds of attestation files: * `.p7s` files are PKCS#7 signature files, which assert a domain or email address vouching for the bag contents. * `.p7s` files are created with the command: ``` - openssl cms -sign -binary -in -out -inkey -signer -certfile -outform PEM + openssl cms -sign -binary -md sha256 -in -out -inkey -signer [-certfile ] -outform PEM -nosmimecap -cades ``` * `.p7s` files can be validated with the command: ``` @@ -262,7 +262,7 @@ The signatures directory can contain two kinds of attestation files: * `.tsr` files are timestamp response files, which assert a time before which the bag was created. * `.tsr` files are created with the command: ``` - openssl ts -query -data -no_nonce -sha256 -cert + openssl ts -query -data -sha256 -cert ``` * `.tsr` files can be validated with the commands: ``` diff --git a/src/nabit/lib/sign.py b/src/nabit/lib/sign.py index 02ef7d0..b0a7252 100644 --- a/src/nabit/lib/sign.py +++ b/src/nabit/lib/sign.py @@ -53,8 +53,12 @@ def timestamp(file_path: str, output_path: str, url: str, cert_chain: str) -> No with tempfile.NamedTemporaryFile(suffix='.tsq') as tsq: # Generate timestamp request, capturing output result = run_openssl([ - "ts", "-query", "-data", file_path, - "-no_nonce", "-sha256", "-cert", "-out", tsq.name + "ts", + "-query", + "-data", file_path, + "-sha256", + "-cert", + "-out", tsq.name ]) # read timestamp query file @@ -121,12 +125,20 @@ def sign(file_path: Path, output_path: Path, key: str, cert_chain: Path) -> None args = [ "cms", "-sign", - "-binary", # do not modify linebreaks in the original file + # choose explicit hash algorithm rather than default + "-md", "sha256", + # do not modify linebreaks in the original file + "-binary", "-in", file_path, "-out", output_path, "-inkey", key, "-signer", signer_file.name, "-outform", "PEM", + # "Exclude the list of supported algorithms from signed attributes" -- only relevant to email + "-nosmimecap", + # "add an ESS signingCertificate or ESS signingCertificateV2 signed-attribute to the SignerInfo, + # in order to make the signature comply with the requirements for a CAdES Basic Electronic Signature (CAdES-BES)." + "-cades", ] if include_chain: args.extend(["-certfile", cert_chain_file.name])