@@ -19,6 +19,9 @@ on the provided configuration.
1919. PARAMETER Kernel
2020 Indicates build is for kernel mode.
2121
22+ . PARAMETER TestCertificates
23+ Generate test certificates. Only supported for Windows test configuration.
24+
2225. EXAMPLE
2326 prepare-machine.ps1 -Configuration Build
2427
@@ -45,7 +48,10 @@ param (
4548 [switch ]$Kernel ,
4649
4750 [Parameter (Mandatory = $false )]
48- [switch ]$FailOnError
51+ [switch ]$FailOnError ,
52+
53+ [Parameter (Mandatory = $false )]
54+ [switch ]$TestCertificates
4955)
5056
5157# Requires -RunAsAdministrator
@@ -174,6 +180,68 @@ if ($IsWindows) {
174180 }
175181
176182 if ($Configuration -eq " Test" ) {
183+ if ($TestCertificates ) {
184+ # Install test certificates on windows
185+ $PfxPassword = ConvertTo-SecureString - String " TestCert" - Force - AsPlainText
186+ $NewRoot = $false
187+ Write-Host " Searching for MsQuicTestRoot certificate..."
188+ $RootCert = Get-ChildItem - path Cert:\LocalMachine\Root\* - Recurse | Where-Object {$_.Subject -eq " CN=MsQuicTestRoot" }
189+ if (! $RootCert ) {
190+ Write-Host " MsQuicTestRoot not found! Creating new MsQuicTestRoot certificate..."
191+ $RootCert = New-SelfSignedCertificate - Subject " CN=MsQuicTestRoot" - FriendlyName MsQuicTestRoot - KeyUsageProperty Sign - KeyUsage CertSign, DigitalSignature - CertStoreLocation cert:\CurrentUser\My - HashAlgorithm SHA256 - Provider " Microsoft Software Key Storage Provider" - KeyExportPolicy Exportable - KeyAlgorithm ECDSA_nistP521 - CurveExport CurveName - NotAfter(Get-Date ).AddYears(5 ) - TextExtension @ (" 2.5.29.19 = {text}ca=1&pathlength=0" ) - Type Custom
192+ $TempRootPath = Join-Path $Env: TEMP " MsQuicTestRoot.cer"
193+ Export-Certificate - Type CERT - Cert $RootCert - FilePath $TempRootPath
194+ CertUtil.exe - addstore Root $TempRootPath
195+ Remove-Item $TempRootPath
196+ $NewRoot = $true
197+ Write-Host " New MsQuicTestRoot certificate installed!"
198+ } else {
199+ Write-Host " Found existing MsQuicTestRoot certificate!"
200+ }
201+ Write-Host " Searching for MsQuicTestServer certificate..."
202+ $ServerCert = Get-ChildItem - path Cert:\LocalMachine\My\* - Recurse | Where-Object {$_.Subject -eq " CN=MsQuicTestServer" }
203+ if (! $ServerCert ) {
204+ Write-Host " MsQuicTestServer not found! Creating new MsQuicTestServer certificate..."
205+ $ServerCert = New-SelfSignedCertificate - Subject " CN=MsQuicTestServer" - DnsName $env: computername , localhost, " 127.0.0.1" , " ::1" - FriendlyName MsQuicTestServer - KeyUsageProperty Sign - KeyUsage DigitalSignature - CertStoreLocation cert:\CurrentUser\My - HashAlgorithm SHA256 - Provider " Microsoft Software Key Storage Provider" - KeyExportPolicy Exportable - KeyAlgorithm ECDSA_nistP256 - CurveExport CurveName - NotAfter(Get-Date ).AddYears(5 ) - TextExtension @ (" 2.5.29.19 = {text}" , " 2.5.29.37 = {text}1.3.6.1.5.5.7.3.1" ) - Signer $RootCert
206+ $TempServerPath = Join-Path $Env: TEMP " MsQuicTestServerCert.pfx"
207+ Export-PfxCertificate - Cert $ServerCert - Password $PfxPassword - FilePath $TempServerPath
208+ Import-PfxCertificate - FilePath $TempServerPath - Password $PfxPassword - Exportable - CertStoreLocation Cert:\LocalMachine\My
209+ Remove-Item $TempServerPath
210+ Write-Host " New MsQuicTestServer certificate installed!"
211+ } else {
212+ Write-Host " Found existing MsQuicTestServer certificate!"
213+ }
214+ Write-Host " Searching for MsQuicTestExpiredServer certificate..."
215+ $ExpiredServerCert = Get-ChildItem - path Cert:\LocalMachine\My\* - Recurse | Where-Object {$_.Subject -eq " CN=MsQuicTestExpiredServer" }
216+ if (! $ExpiredServerCert ) {
217+ Write-Host " MsQuicTestExpiredServer not found! Creating new MsQuicTestExpiredServer certificate..."
218+ $ExpiredServerCert = New-SelfSignedCertificate - Subject " CN=MsQuicTestExpiredServer" - DnsName $env: computername , localhost, " 127.0.0.1" , " ::1" - FriendlyName MsQuicTestExpiredServer - KeyUsageProperty Sign - KeyUsage DigitalSignature - CertStoreLocation cert:\CurrentUser\My - HashAlgorithm SHA256 - Provider " Microsoft Software Key Storage Provider" - KeyExportPolicy Exportable - KeyAlgorithm ECDSA_nistP256 - CurveExport CurveName - NotBefore (Get-Date ).AddYears(-2 ) - NotAfter(Get-Date ).AddYears(-1 ) - TextExtension @ (" 2.5.29.19 = {text}" , " 2.5.29.37 = {text}1.3.6.1.5.5.7.3.1" ) - Signer $RootCert
219+ $TempExpiredServerPath = Join-Path $Env: TEMP " MsQuicTestExpiredServerCert.pfx"
220+ Export-PfxCertificate - Cert $ExpiredServerCert - Password $PfxPassword - FilePath $TempExpiredServerPath
221+ Import-PfxCertificate - FilePath $TempExpiredServerPath - Password $PfxPassword - Exportable - CertStoreLocation Cert:\LocalMachine\My
222+ Remove-Item $TempExpiredServerPath
223+ Write-Host " New MsQuicTestExpiredServer certificate installed!"
224+ } else {
225+ Write-Host " Found existing MsQuicTestExpiredServer certificate!"
226+ }
227+ Write-Host " Searching for MsQuicTestClient certificate..."
228+ $ClientCert = Get-ChildItem - path Cert:\LocalMachine\My\* - Recurse | Where-Object {$_.Subject -eq " CN=MsQuicTestClient" }
229+ if (! $ClientCert ) {
230+ Write-Host " MsQuicTestClient not found! Creating new MsQuicTestClient certificate..."
231+ $ClientCert = New-SelfSignedCertificate - Subject " CN=MsQuicTestClient" - FriendlyName MsQuicTestClient - KeyUsageProperty Sign - KeyUsage DigitalSignature - CertStoreLocation cert:\CurrentUser\My - HashAlgorithm SHA256 - Provider " Microsoft Software Key Storage Provider" - KeyExportPolicy Exportable - KeyAlgorithm ECDSA_nistP256 - CurveExport CurveName - NotAfter(Get-Date ).AddYears(5 ) - TextExtension @ (" 2.5.29.19 = {text}" , " 2.5.29.37 = {text}1.3.6.1.5.5.7.3.2" ) - Signer $RootCert
232+ $TempClientPath = Join-Path $Env: TEMP " MsQuicTestClientCert.pfx"
233+ Export-PfxCertificate - Cert $ClientCert - Password $PfxPassword - FilePath $TempClientPath
234+ Import-PfxCertificate - FilePath $TempClientPath - Password $PfxPassword - Exportable - CertStoreLocation Cert:\LocalMachine\My
235+ Remove-Item $TempClientPath
236+ Write-Host " New MsQuicTestClient certificate installed!"
237+ }else {
238+ Write-Host " Found existing MsQuicTestClient certificate!"
239+ }
240+ if ($NewRoot ) {
241+ Write-Host " Deleting MsQuicTestRoot from MY store..."
242+ Remove-Item $rootCert.PSPath
243+ }
244+ }
177245 # Install OpenCppCoverage on test machines
178246 if (! (Test-Path " C:\Program Files\OpenCppCoverage\OpenCppCoverage.exe" )) {
179247 # Download the installer.
0 commit comments