Skip to content

Commit

Permalink
(#281) Prevents Creation Of Unrequired Self-Signed Certificate
Browse files Browse the repository at this point in the history
The Chocolatey-Management-Service package generates a self-signed certificate to use if no thumbprint is specified as a parameter.

Regardless of if a certificate was specified, we were installing it without a thumbprint and then setting the certificate later.

This resulted in an unused self-signed certificate being generated and stored.

This change ensures the package gets the appropriate parameter in order to not generate unneeded certificate(s).
  • Loading branch information
JPRuskin committed Jan 8, 2025
1 parent 15db143 commit 6b877bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
29 changes: 13 additions & 16 deletions Start-C4bCcmSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ param(
[System.Management.Automation.PSCredential]
$DatabaseCredential = (Get-Credential -Username ChocoUser -Message 'Create a credential for the ChocolateyManagement DB user (document this somewhere)'),

#Certificate to use for CCM service
# Certificate to use for CCM service
[Parameter()]
[Alias('Thumbprint')]
[String]
$CertificateThumbprint
)
Expand Down Expand Up @@ -116,31 +117,27 @@ process {
$hostName = [System.Net.Dns]::GetHostName()
$domainName = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName

if(-Not $hostName.endswith($domainName)) {
if (-not $hostName.EndsWith($domainName)) {
$hostName += "." + $domainName
}

Write-Host "Installing Chocolatey Central Management Service"
if($CertificateThumbprint){
$chocoArgs = @('install', 'chocolatey-management-service', "--source='ChocolateyInternal'", '-y', "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress')
if ($CertificateThumbprint) {
Write-Verbose "Validating certificate is in LocalMachine\TrustedPeople Store"
if($CertificateThumbprint -notin (Get-ChildItem Cert:\LocalMachine\TrustedPeople | Select-Object -Expand Thumbprint)){
if (-not (Get-Item Cert:\LocalMachine\TrustedPeople\$CertificateThumbprint) -and -not (Get-Item Cert:\LocalMachine\My\$CertificateThumbprint)) {
Write-Warning "You specified $CertificateThumbprint for use with CCM service, but the certificate is not in the required LocalMachine\TrustedPeople store!"
Write-Warning "Please place certificate with thumbprint: $CertificateThumbprint in the LocalMachine\TrustedPeople store and re-run this step"
throw "Certificate not in correct location....exiting."
}
else {
throw "Certificate not in correct location... exiting."
} elseif ($MyCertificate = Get-Item Cert:\LocalMachine\My\$CertificateThumbprint) {
Write-Verbose "Copying certificate from 'Personal' store to 'TrustedPeople'"
Copy-CertToStore $MyCertificate
} else {
Write-Verbose "Certificate has been successfully found in correct store"
$chocoArgs = @('install', 'chocolatey-management-service', '-y', "--package-parameters-sensitive='/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User Id=$DatabaseUser;Password=$DatabaseUserPw'")
& Invoke-Choco @chocoArgs

Set-CcmCertificate -CertificateThumbprint $CertificateThumbprint
}
$chocoArgs += @("--package-parameters='/CertificateThumbprint=$CertificateThumbprint'")
}

else {
$chocoArgs = @('install', 'chocolatey-management-service', "--source='ChocolateyInternal'", '-y', "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress')
& Invoke-Choco @chocoArgs
}
& Invoke-Choco @chocoArgs

Write-Host "Installing Chocolatey Central Management Website"
$chocoArgs = @('install', 'chocolatey-management-web', "--source='ChocolateyInternal'", '-y', "--package-parameters-sensitive=""'/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'""", '--no-progress')
Expand Down
12 changes: 5 additions & 7 deletions Start-C4bSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,14 @@ try {

# Kick off unattended running of remaining setup scripts.
if ($Unattend) {
$Certificate = @{}
if ($Thumbprint) {$Certificate.Thumbprint = $Thumbprint}

Set-Location "$env:SystemDrive\choco-setup\files"
.\Start-C4BNexusSetup.ps1
.\Start-C4bCcmSetup.ps1 -DatabaseCredential $DatabaseCredential
.\Start-C4bCcmSetup.ps1 @Certificate -DatabaseCredential $DatabaseCredential
.\Start-C4bJenkinsSetup.ps1
if ($Thumbprint) {
.\Set-SslSecurity.ps1 -Thumbprint $Thumbprint
}
else {
.\Set-SslSecurity.ps1
}
.\Set-SslSecurity.ps1 @Certificate
}
} finally {
$ErrorActionPreference = $DefaultEap
Expand Down

0 comments on commit 6b877bd

Please sign in to comment.