Skip to content

Commit efd15b2

Browse files
committed
(#281) Bring Thumbprint Parameters Into Line
Having CertificateThumbprint and Thumbprint treated differently across the scripts is annoying, and can introduce confusion. This change brings all the scripts into the same $Thumbprint (with an alias for folk who instinctively use CertificateThumbprint), and an argument completer.
1 parent 00de8b0 commit efd15b2

6 files changed

+70
-16
lines changed

Set-SslSecurity.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ param(
2222
# Ignored if supplied alongside -Subject.
2323
[Parameter(ValueFromPipeline, ParameterSetName='Thumbprint')]
2424
[ArgumentCompleter({
25-
Get-ChildItem Cert:\LocalMachine\My | ForEach-Object {
25+
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
2626
[System.Management.Automation.CompletionResult]::new(
2727
$_.Thumbprint,
2828
$_.Thumbprint,
29-
'ParameterValue',
30-
$_.FriendlyName
29+
"ParameterValue",
30+
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$",'${FQDN}')
3131
)
3232
}
3333
})]

Start-C4bCcmSetup.ps1

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ param(
1919

2020
# Certificate to use for CCM service
2121
[Parameter()]
22-
[Alias('Thumbprint')]
22+
[Alias('CertificateThumbprint')]
23+
[ArgumentCompleter({
24+
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
25+
[System.Management.Automation.CompletionResult]::new(
26+
$_.Thumbprint,
27+
$_.Thumbprint,
28+
"ParameterValue",
29+
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$",'${FQDN}')
30+
)
31+
}
32+
})]
2333
[String]
24-
$CertificateThumbprint
34+
$Thumbprint
2535
)
2636
process {
2737
$DefaultEap = $ErrorActionPreference
@@ -123,19 +133,19 @@ process {
123133

124134
Write-Host "Installing Chocolatey Central Management Service"
125135
$chocoArgs = @('install', 'chocolatey-management-service', "--source='ChocolateyInternal'", '-y', "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress')
126-
if ($CertificateThumbprint) {
136+
if ($Thumbprint) {
127137
Write-Verbose "Validating certificate is in LocalMachine\TrustedPeople Store"
128-
if (-not (Get-Item Cert:\LocalMachine\TrustedPeople\$CertificateThumbprint -EA 0) -and -not (Get-Item Cert:\LocalMachine\My\$CertificateThumbprint -EA 0)) {
129-
Write-Warning "You specified $CertificateThumbprint for use with CCM service, but the certificate is not in the required LocalMachine\TrustedPeople store!"
130-
Write-Warning "Please place certificate with thumbprint: $CertificateThumbprint in the LocalMachine\TrustedPeople store and re-run this step"
138+
if (-not (Get-Item Cert:\LocalMachine\TrustedPeople\$Thumbprint -EA 0) -and -not (Get-Item Cert:\LocalMachine\My\$Thumbprint -EA 0)) {
139+
Write-Warning "You specified $Thumbprint for use with CCM service, but the certificate is not in the required LocalMachine\TrustedPeople store!"
140+
Write-Warning "Please place certificate with thumbprint: $Thumbprint in the LocalMachine\TrustedPeople store and re-run this step"
131141
throw "Certificate not in correct location... exiting."
132-
} elseif ($MyCertificate = Get-Item Cert:\LocalMachine\My\$CertificateThumbprint -EA 0) {
142+
} elseif ($MyCertificate = Get-Item Cert:\LocalMachine\My\$Thumbprint -EA 0) {
133143
Write-Verbose "Copying certificate from 'Personal' store to 'TrustedPeople'"
134144
Copy-CertToStore $MyCertificate
135145
} else {
136146
Write-Verbose "Certificate has been successfully found in correct store"
137147
}
138-
$chocoArgs += @("--package-parameters='/CertificateThumbprint=$CertificateThumbprint'")
148+
$chocoArgs += @("--package-parameters='/CertificateThumbprint=$Thumbprint'")
139149
}
140150
& Invoke-Choco @chocoArgs
141151

Start-C4bSetup.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ param(
6363
# the local machine certificate stores.
6464
# Only used in Unattend mode for the SSL setup script.
6565
[Parameter(ParameterSetName='Unattended')]
66+
[ArgumentCompleter({
67+
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
68+
[System.Management.Automation.CompletionResult]::new(
69+
$_.Thumbprint,
70+
$_.Thumbprint,
71+
"ParameterValue",
72+
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$",'${FQDN}')
73+
)
74+
}
75+
})]
6676
[string]
6777
$Thumbprint,
6878

scripts/Set-CCMCert.ps1

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ PS> .\Set-CCMCert.ps1 -CertificateThumbprint 'Your_Certificate_Thumbprint_Value'
1616
[CmdletBinding()]
1717
param(
1818
[Parameter(Mandatory)]
19+
[Alias("CertificateThumbprint")]
20+
[ArgumentCompleter({
21+
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
22+
[System.Management.Automation.CompletionResult]::new(
23+
$_.Thumbprint,
24+
$_.Thumbprint,
25+
"ParameterValue",
26+
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$",'${FQDN}')
27+
)
28+
}
29+
})]
1930
[String]
20-
$CertificateThumbprint
31+
$Thumbprint
2132
)
2233

2334
begin {
@@ -41,14 +52,14 @@ process {
4152
#Add new CCM Web IIS Binding
4253
Write-Verbose "Adding new IIS binding to Chocolatey Central Management"
4354
$guid = [Guid]::NewGuid().ToString("B")
44-
netsh http add sslcert ipport=0.0.0.0:443 certhash=$CertificateThumbprint certstorename=MY appid="$guid"
55+
netsh http add sslcert ipport=0.0.0.0:443 certhash=$Thumbprint certstorename=MY appid="$guid"
4556
Get-WebBinding -Name ChocolateyCentralManagement | Remove-WebBinding
4657
New-WebBinding -Name ChocolateyCentralManagement -Protocol https -Port 443 -SslFlags 0 -IpAddress '*'
4758

4859
#Write Thumbprint to CCM Service appsettings.json
4960
$appSettingsJson = 'C:\ProgramData\chocolatey\lib\chocolatey-management-service\tools\service\appsettings.json'
5061
$json = Get-Content $appSettingsJson | ConvertFrom-Json
51-
$json.CertificateThumbprint = $CertificateThumbprint
62+
$json.CertificateThumbprint = $Thumbprint
5263
$json | ConvertTo-Json | Set-Content $appSettingsJson -Force
5364

5465
#Try Restarting CCM Service

scripts/Set-JenkinsCert.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@
1111
param(
1212
# Thumbprint of the certificate stored in the Trusted People cert-store.
1313
[Parameter(Mandatory)]
14-
[string]$Thumbprint,
14+
[Alias("CertificateThumbprint")]
15+
[ArgumentCompleter({
16+
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
17+
[System.Management.Automation.CompletionResult]::new(
18+
$_.Thumbprint,
19+
$_.Thumbprint,
20+
"ParameterValue",
21+
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$",'${FQDN}')
22+
)
23+
}
24+
})]
25+
[String]
26+
$Thumbprint,
1527

1628
# Port number to use for Jenkins HTTPS.
1729
[uint16]$Port = 7443

scripts/Set-NexusCert.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ PS> .\Set-NexusCert.ps1 -Thumbprint 'Your_Certificate_Thumbprint_Value' -NexusPo
1818
[CmdletBinding()]
1919
param(
2020
[Parameter(Mandatory)]
21-
[string]
21+
[Alias("CertificateThumbprint")]
22+
[ArgumentCompleter({
23+
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
24+
[System.Management.Automation.CompletionResult]::new(
25+
$_.Thumbprint,
26+
$_.Thumbprint,
27+
"ParameterValue",
28+
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$",'${FQDN}')
29+
)
30+
}
31+
})]
32+
[String]
2233
$Thumbprint,
2334

2435
[Parameter()]

0 commit comments

Comments
 (0)