Skip to main content

patch

Function patch 

Source
pub fn patch(
    igvm_data: &[u8],
    corim_signature: &[u8],
    platform: IgvmPlatformType,
    expected_document: Option<&[u8]>,
) -> Result<Vec<u8>>
Expand description

Verify a CoRIM signature against the document already embedded in an IGVM file, then patch the corresponding CorimSignature header.

The CoRIM document is expected to already be present in the IGVM file for the target platform (auto-generated at build time). This function:

  1. Parses the IGVM file and locates the existing CorimDocument for the target platform.
  2. If expected_document is provided, asserts that it matches the in-file document byte-for-byte. This catches the common UX trap where a user supplies a --corim-bundle whose embedded payload was signed against a different document than the one baked into the IGVM file: without this check the failure would surface as an opaque “cryptographic verification failed” error.
  3. Cryptographically verifies corim_signature against the in-file document via envelope::verify_corim_signature. The issuer certificate is taken from the signature envelope’s x5chain / x5bag header.
  4. Stages the signature replacement via [IgvmSerializer::set_corim_signature], which suppresses any in-file document/signature pair for the platform and re-emits the existing document followed by the new signature in the required order, then serializes.

Verification runs before any serializer mutation, so a failed verification leaves no partially-modified output.

§Arguments

  • igvm_data - The original IGVM file contents
  • corim_signature - Detached COSE_Sign1 signature payload (nil payload)
  • platform - The target platform type
  • expected_document - Optional CoRIM document bytes that the caller asserts should match the document embedded in the IGVM file. Used when the signature was extracted from a bundled envelope; pass None when the caller doesn’t have an independent copy.

§Returns

The modified IGVM file contents with the CoRIM signature header inserted or updated.

§Errors

Returns an error if the IGVM file has no CorimDocument header for the target platform – the signature cannot be attached without a corresponding document – or if expected_document is provided and does not match the in-file document, or if cryptographic verification of corim_signature against the in-file document fails.