feat(codesign): Authenticode RSA-SHA256 PE signer (VS-18) #48
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/authenticode-pe-signer-vs-18"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
VS-18: Authenticode signing for Windows agent builds (PE-file rewriter)
Implements the Authenticode signer for
crates/meshcentral-codesign. The PE walker (pe.rs), SPC builder (spc.rs), and CMS/SignedData assembler (cms.rs) already existed and were tested; the missing piece was the RSA signing identity plus the public entry points.sign_pepreviously returnedNotYetImplemented.What changed
signer::RsaSigner: loads a PEM cert + key, pulls the issuerName+ serial for the SignerInfo'sIssuerAndSerialNumber(viax509-parser, matching the PKI crate), and signs the SignedDatasignedAttrswith RSA-PKCS1v1.5-SHA256. Accepts PKCS#8 (PRIVATE KEY, what rcgen/WebSigneremit) and PKCS#1 (RSA PRIVATE KEY) keys.sign_penow drives the full strip -> hash -> SPC -> signedAttrs -> RSA-sign -> CMS -> attach flow.maybe_sign_pe(pe_bytes, Option<&SigningIdentity>)is the config gate: signs when a cert is configured, passes the bytes through unsigned otherwise (the current/legacy default).sign_pe_with_signer: strip any prior signature and pad the image to an 8-byte boundary BEFORE computing the Authenticode hash, so the signed digest matches what a verifier recomputes after the certificate table is appended. PEs whose unsigned length was not 8-aligned would otherwise fail verification.Acceptance criteria
maybe_sign_pe_passes_through_without_identity+smoke_sign_known_pe_produces_verifiable_signature.smoke_sign_known_pe_produces_verifiable_signaturegenerates a real self-signed RSA code-signing cert, signs a known PE, and asserts the rewrite preserves the Authenticode hash and the embedded PKCS#7 carries a cryptographically valid RSA-SHA256 signature over the correctsignedAttrs, with the issuer Name embedded.osslsigncode/signtoolare not installed in this environment (thesigntoolon PATH is NSS's, not Windows Authenticode). The emitted DER was validated out-of-band withopenssl asn1parse/openssl pkcs7: a well-formedpkcs7-signedDatacarrying the SPC indirect-data OID (1.3.6.1.4.1.311.2.1.4), a SHA-256 digest algorithm,contentType+messageDigestsigned attributes, an embedded signing cert, and a 256-bytersaEncryptionsignature. The test performs the same cryptographic + structural check osslsigncode/signtool walk. A reviewer with osslsigncode can confirm against a real agent PE.Out of scope (not in the AC)
The codesign crate is not yet consumed by the web layer. Wiring the signer into
/meshagents/:idserving (binary-catalog reload on signer update, server config schema for the cert path) is a separate integration and is left for a follow-up; this PR delivers the signer and its config gate at the library boundary.Test
cargo test -p meshcentral-codesign-> 36 passed.cargo clippy -p meshcentral-codesign --all-targetsclean.cargo fmt --checkclean.Refs VS-18.