-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Sign the DAC and DBI during the build process instead of in separate steps #111416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b38b2cd
Sign the DAC and DBI during the build process instead of in separate …
jkoritzinsky 2fb5f81
Remove ESRP version from Versions.props
jkoritzinsky 57a328d
Generate per-config to fix VS
jkoritzinsky 2dd3d71
Fix schema and PR feedback
jkoritzinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[CmdletBinding()] | ||
param( | ||
[string] | ||
[Parameter(Mandatory)] | ||
$esrpClient, | ||
[Parameter(ValueFromRemainingArguments=$true)][string[]]$filesToSign | ||
) | ||
|
||
$inputFile = Get-Content -Raw $PSScriptRoot/signing/input.template.json | ConvertFrom-Json | ||
$inputFile.SignBatches.SignRequestFiles = $filesToSign | ForEach-Object { | ||
@{ | ||
SourceLocation = $_ | ||
} | ||
} | ||
|
||
$inputJson = [System.IO.Path]::GetTempFileName() | ||
# Our JSON goes up to 6 levels deep, so we need to set the depth to 6 | ||
# to successfully round-trip our JSON through ConvertTo-Json | ||
$inputFile | ConvertTo-Json -Depth 6 | Out-File -FilePath $inputJson -Encoding utf8 | ||
|
||
$outputJson = Resolve-Path "$PSScriptRoot/../../artifacts/log/Release/signing-$(New-Guid).json.log" | ||
|
||
Write-Host "Signing files with DAC certificate" | ||
Write-Host "Logging output to $outputJson" | ||
|
||
& $esrpClient sign -a $PSScriptRoot/signing/auth.json -c $PSScriptRoot/signing/config.json -i $inputJson -o $outputJson -p $PSScriptRoot/signing/policy.json | ||
jkoritzinsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Validate that the files are signed correctly | ||
foreach ($file in $filesToSign) { | ||
$signingCert = $(Get-AuthenticodeSignature $file).SignerCertificate | ||
if ($null -eq $signingCert) | ||
{ | ||
throw "File $file does not contain a signature." | ||
} | ||
|
||
if ($signingCert.Subject -ne "CN=.NET DAC, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" ` | ||
-or $signingCert.Issuer -ne "CN=Microsoft Code Signing PCA 2010, O=Microsoft Corporation, L=Redmond, S=Washington, C=US") | ||
{ | ||
throw "File $file not in expected trust chain." | ||
} | ||
|
||
$certEKU = $signingCert.Extensions.Where({ $_.Oid.FriendlyName -eq "Enhanced Key Usage" }) | Select-Object -First 1 | ||
|
||
if ($certEKU.EnhancedKeyUsages.Where({ $_.Value -eq "1.3.6.1.4.1.311.84.4.1" }).Count -ne 1) | ||
{ | ||
throw "Signature for $file does not contain expected EKU." | ||
} | ||
|
||
Write-Host "$file is correctly signed." | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"Version" : "1.0.0", | ||
"AuthenticationType" : "AAD_CERT", | ||
"TenantId" : "72f988bf-86f1-41af-91ab-2d7cd011db47", | ||
"ClientId" : "2234cdec-a13f-4bb2-aa63-04c57fd7a1f9", | ||
"AuthCert" : | ||
{ | ||
"SubjectName" : "CN=2234cdec-a13f-4bb2-aa63-04c57fd7a1f9.microsoft.com", | ||
"StoreLocation" : "CurrentUser", | ||
"StoreName": "My", | ||
"SendX5c" : "true" | ||
}, | ||
"RequestSigningCert" : { | ||
"SubjectName" : "CN=2234cdec-a13f-4bb2-aa63-04c57fd7a1f9", | ||
"StoreLocation" : "CurrentUser", | ||
"StoreName" : "My" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Version" : "1.0.0", | ||
"MaxDegreeOfParallelism" : "50", | ||
"ExponentialRetryCount" : "5", | ||
"EsrpSessionTimeoutInSec" : "1800" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"Version": "1.0.0", | ||
"UseMinimatch" : false, | ||
"SignBatches": [ | ||
{ | ||
"SigningInfo" : { | ||
"Operations" : [ | ||
{ | ||
"keyCode": "CP-471322", | ||
"operationCode": "SigntoolSign", | ||
"parameters": { | ||
"OpusName": "Microsoft", | ||
"OpusInfo": "http://www.microsoft.com", | ||
"PageHash": "/NPH", | ||
"FileDigest": "/fd sha256", | ||
"TimeStamp": "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256" | ||
}, | ||
"toolName": "sign", | ||
"toolVersion": "1.0" | ||
}, | ||
{ | ||
"KeyCode": "CP-471322", | ||
"OperationCode": "SigntoolVerify", | ||
"Parameters": {}, | ||
"ToolName": "sign", | ||
"ToolVersion": "1.0" | ||
} | ||
] | ||
}, | ||
"SourceLocationType" : "UNC", | ||
"DestinationLocationType": "UNC", | ||
"SignRequestFiles" : [ | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"Version": "1.0.0" | ||
} |
34 changes: 34 additions & 0 deletions
34
eng/pipelines/coreclr/templates/install-diagnostic-certs.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
parameters: | ||
isOfficialBuild: | ||
type: boolean | ||
displayName: 'Is Official Build' | ||
certNames: | ||
type: array | ||
displayName: 'Certificate Name' | ||
vaultName: | ||
type: string | ||
displayName: 'Key Vault Name' | ||
azureSubscription: | ||
type: string | ||
displayName: 'Azure Subscription' | ||
|
||
steps: | ||
- ${{ if and(eq(parameters.isOfficialBuild, true), ne(variables['Build.Reason'], 'PullRequest'), or(startswith(variables['Build.SourceBranch'], 'refs/heads/release/'), startswith(variables['Build.SourceBranch'], 'refs/heads/internal/release/'), startswith(variables['Build.SourceBranch'], 'refs/heads/reltest/')), not(endsWith(variables['Build.SourceBranch'], '-staging'))) }}: | ||
- task: AzureKeyVault@2 | ||
inputs: | ||
azureSubscription: ${{ parameters.azureSubscription }} | ||
KeyVaultName: ${{ parameters.vaultName }} | ||
SecretsFilter: ${{ join(',', parameters.certNames) }} | ||
displayName: 'Download secrets: Diagnostic Certificates' | ||
|
||
- task: EsrpClientTool@2 | ||
displayName: Download ESRPClient | ||
|
||
- powershell: | | ||
eng/pipelines/install-diagnostic-certs.ps1 "${{ join(',', parameters.certNames) }}" | ||
$signArgs = '/p:DotNetEsrpToolPath=$(esrpclient.toolpath)\$(esrpclient.toolname)' | ||
echo "##vso[task.setvariable variable=_SignDiagnosticFilesArgs;]$signArgs" | ||
displayName: 'Install diagnostic certificates' | ||
env: | ||
${{ each cert in parameters.certNames }}: | ||
${{ cert }}: $(${{ cert }}) |
11 changes: 11 additions & 0 deletions
11
eng/pipelines/coreclr/templates/remove-diagnostic-certs.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
parameters: | ||
isOfficialBuild: | ||
type: boolean | ||
displayName: 'Is Official Build' | ||
|
||
steps: | ||
- ${{ if and(eq(parameters.isOfficialBuild, true), ne(variables['Build.Reason'], 'PullRequest'), or(startswith(variables['Build.SourceBranch'], 'refs/heads/release/'), startswith(variables['Build.SourceBranch'], 'refs/heads/internal/release/'), startswith(variables['Build.SourceBranch'], 'refs/heads/reltest/')), not(endsWith(variables['Build.SourceBranch'], '-staging'))) }}: | ||
- powershell: | | ||
eng/pipelines/remove-diagnostic-certs.ps1 "$(DacCertificateThumbprints)" | ||
displayName: 'Remove Diagnostic Certificates' | ||
condition: always() |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[CmdletBinding()] | ||
param( | ||
[string] | ||
[Parameter(Mandatory)] | ||
$certList | ||
) | ||
# Required for the pipeline logging functions | ||
$ci = $true | ||
. $PSScriptRoot/../common/pipeline-logging-functions.ps1 | ||
|
||
$certs = $certList -split ',' | ||
$thumbprints = @() | ||
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection | ||
foreach ($cert in $certs) | ||
{ | ||
$certBytes = [System.Convert]::FromBase64String($(Get-Item "Env:$cert").Value) | ||
$certCollection.Import($certBytes,$null, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet) | ||
} | ||
|
||
foreach ($cert in $certCollection) | ||
{ | ||
Write-Host "Installed certificate '$($cert.Thumbprint)' with subject: '$($cert.Subject)'" | ||
$thumbprints += $cert.Thumbprint | ||
} | ||
|
||
$store = Get-Item -Path Cert:\CurrentUser\My | ||
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) | ||
$store.AddRange($certCollection) | ||
$store.Close() | ||
|
||
Write-PipelineSetVariable -name "DacCertificateThumbprints" -Value "$($thumbprints -join ',')" -IsMultiJobVariable $false | ||
Write-Host "Successfully installed diagnostic certificates" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[CmdletBinding()] | ||
param( | ||
[string] | ||
[Parameter(Mandatory)] | ||
$thumbprintList | ||
) | ||
|
||
$thumbprints = $thumbprintList -split ',' | ||
$store = Get-Item -Path Cert:\CurrentUser\My | ||
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) | ||
foreach ($thumbprint in $thumbprints) | ||
{ | ||
$cert = $store.Certificates.Find([System.Security.Cryptography.X509Certificates.X509FindType]::FindByThumbprint, $thumbprint, $false) | ||
if ($null -eq $cert) | ||
{ | ||
Write-Host "Certificate with thumbprint '$thumbprint' not found in the user store." | ||
} | ||
$store.RemoveRange($cert) | ||
Write-Host "Removed certificate '$thumbprint'" | ||
} | ||
$store.Close() | ||
Write-Host "Successfully removed diagnostic certificates" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.