Skip to content

Commit

Permalink
Update openssl flags
Browse files Browse the repository at this point in the history
- include nonce in timestamp request
- explicitly specify signing algorithm
- add cades attribute and drop smimecap attribute from signature
  • Loading branch information
jcushman committed Dec 2, 2024
1 parent e1182c7 commit 01cd8be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <original_file> -out <signature_file> -inkey <key_file> -signer <cert_chain> -certfile <cert_chain> -outform PEM
openssl cms -sign -binary -md sha256 -in <original_file> -out <signature_file> -inkey <key_file> -signer <first_cert> [-certfile <remaining_chain>] -outform PEM -nosmimecap -cades
```
* `.p7s` files can be validated with the command:
```
Expand All @@ -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 <original_file> -no_nonce -sha256 -cert
openssl ts -query -data <original_file> -sha256 -cert
```
* `.tsr` files can be validated with the commands:
```
Expand Down
18 changes: 15 additions & 3 deletions src/nabit/lib/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 01cd8be

Please sign in to comment.