@@ -688,6 +688,75 @@ If you aren't using Razor, or don't want to use the TagHelpers library, you can
688688string nonce = HttpContext .GetNonce ();
689689```
690690
691+ # Verifying NuGet provenance attestations
692+
693+ All releases of the NuGet packages in this repository include provenance attestations , a Software Bill of Materials (SBOM ),
694+ and attestations for the SBOMs . These attestations are generated based on the NuGet packages created in the pipeline .
695+ However , [nuget .org modifies any uploaded packages ]((https :// andrewlock.net/creating-provenance-attestations-for-nuget-packages-in-github-actions/#and-now-for-the-bad-news))
696+ to include a signature file , which changes the SHA of the packages .
697+
698+ To verify the provenance for a given downloaded NuGet package from nuget .org , you must first reverse the signature file
699+ modification , to reconstruct the package for which the attestation was made . You can then use the GitHub CLI to verify
700+ the provenance of the package and the associated SBOMs .
701+
702+ To remove the signature file on Linux or macOS , you can use the `zip ` utility :
703+
704+ ```bash
705+ file = " path/to/NetEscapades.AspNetCore.SecurityHeaders.1.0.0.nupkg"
706+ zip - d $file .signature .p7s
707+ ```
708+
709+ alternatively , use PowerShell and .NET to remove the `.signature .p7s ` file :
710+
711+ ```powershell
712+ $file = " path/to/NetEscapades.AspNetCore.SecurityHeaders.1.0.0.nupkg"
713+ [Reflection .Assembly ]:: LoadWithPartialName ('System.IO.Compression' )
714+ $stream = New - Object IO .FileStream ($file , [IO .FileMode ]:: Open )
715+ $zip = New - Object IO .Compression .ZipArchive ($stream , [IO .Compression .ZipArchiveMode ]:: Update )
716+ $zip .Entries | ? { $_ .Name - eq " .signature.p7s" } | % { $_ .Delete () }
717+ $zip .Dispose ();
718+ ```
719+
720+ You can then verify the provenance of the package using [the GitHub CLI ](https :// cli.github.com/):
721+
722+ ```bash
723+ gh attestation verify -- owner andrewlock " NetEscapades.AspNetCore.SecurityHeaders.1.0.0.nupkg"
724+ gh attestation verify -- owner andrewlock " NetEscapades.AspNetCore.SecurityHeaders.TagHelpers.1.0.0.nupkg"
725+ ```
726+
727+ on success , this displays output similar to the following :
728+
729+ ```bash
730+ Loaded digest sha256 :bf809ff0ed6a8a31131df4391b169e35ded44d4dfd97cc797123441683a95c9f for file :// NetEscapades.AspNetCore.SecurityHeaders.1.0.0.nupkg
731+ Loaded 2 attestations from GitHub API
732+
733+ The following policy criteria will be enforced :
734+ - Predicate type must match :................ https :// slsa.dev/provenance/v1
735+ - Source Repository Owner URI must match :.. . https : // github.com/andrewlock
736+ - Subject Alternative Name must match regex : (? i )^ https :// github.com/andrewlock/
737+ - OIDC Issuer must match :.................. . https : // token.actions.githubusercontent.com
738+
739+ ✓ Verification succeeded !
740+
741+ The following 1 attestation matched the policy criteria
742+
743+ - Attestation #1
744+ - Build repo :.... . andrewlock / NetEscapades .AspNetCore .SecurityHeaders
745+ - Build workflow :. .github / workflows / BuildAndPack .yml @refs / tags / v1 .0 . 0
746+ - Signer repo :.... andrewlock / NetEscapades .AspNetCore .SecurityHeaders
747+ - Signer workflow : .github / workflows / BuildAndPack .yml @refs / tags / v1 .0 . 0
748+ ```
749+
750+ SBOMs are provided in the GitHub release for the packages using the [CycloneDX standard ](https :// cyclonedx.org/).
751+ As for build provenance , attestations for the SBOMs must be verified against the _ .nupkg_ files
752+ with the `.signature .p7s ` file removed . Assuming you have modified the _ .nupkg_ files to remove the signature file , as described above ,
753+ you can verify the SBOM attestations by specifying the `-- predicate - type `:
754+
755+ ```bash
756+ gh attestation verify -- owner andrewlock -- predicate - type https :// cyclonedx.org/bom "NetEscapades.AspNetCore.SecurityHeaders.1.0.0nupkg"
757+ gh attestation verify -- owner andrewlock -- predicate - type https :// cyclonedx.org/bom "NetEscapades.AspNetCore.SecurityHeaders.TagHelpers.1.0.0.nupkg"
758+ ```
759+
691760## Additional Resources
692761
693762* [ASP .NET Core Middleware Docs ](https :// docs.asp.net/en/latest/fundamentals/middleware.html)
0 commit comments