Fix MSI DigitalSignature handling with MsiDigitalSignatureEx - #508
Conversation
Signing and verification now disagree on MSI digest ordering
Reproducer using the existing fixture, renaming its embedded-cabinet stream so it sorts before DSE: python3 - <<'PY'
from pathlib import Path
b = bytearray(Path("tests/files/unsigned.msi").read_bytes())
b[7168] = 0
Path("early-stream.msi").write_bytes(b)
PY
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout key.pem -out cert.pem -subj /CN=Review \
-days 1 -addext extendedKeyUsage=codeSigning
build/osslsigncode sign -certs cert.pem -key key.pem \
-add-msi-dse -in early-stream.msi -out signed.msi
build/osslsigncode verify -CAfile cert.pem -in signed.msiResult: base passes; this branch fails with The unmodified fixture with DSE, and the modified fixture without DSE, pass on both versions. Suggestion: make signing and verification use the same digest ordering, including the detached-signature digest path. Explicitly address compatibility with previously generated signatures and add an early-sorting-stream regression test. |
8e45767 to
f9fafbe
Compare
|
Also update README.md. Consider adding something like:
|
Verify MsiDigitalSignatureEx separately and include the stream in the MSI content digest at its sorted position instead of prepending the calculated pre-hash. Use the same digest ordering for signing and verification. Signed-off-by: olszomal <Malgorzata.Olszowka@stunnel.org>
f9fafbe to
8b8c657
Compare
Pull Request Type
Related Issue
Fixes #507
Current Behavior
MsiDigitalSignatureExis prepended to the MSI content digest, while the corresponding stream is skipped during stream hashing.This produces an incorrect
DigitalSignaturedigest when another MSI stream sorts beforeMsiDigitalSignatureEx.New Behavior
MsiDigitalSignatureExis included in the MSI content digest at its sorted stream position.The same digest ordering is used for signing and verification. During verification, the recalculated
MsiDigitalSignatureExvalue is also checked against the stored value.Scope of Changes
MsiDigitalSignatureExseparately from the MSI content digest.MsiDigitalSignatureExat its sorted stream position.MsiDigitalSignatureExvalue against the stored value.Testing
Verified an affected MSI file successfully with both
osslsigncodeand Windowssigntool.Additional Notes
License Declaration