Pipelines/Steps/Install/OnPrem/Sitecore/SSL/New-ClientCert.ps1

$ErrorActionPreference = "Stop"

$prefix = $SAFConfiguration.prefix
$hostNames = @()

if (![string]::IsNullOrEmpty($SAFConfiguration.ssl.hostNames)) {
    $hostNames = $SAFConfiguration.ssl.hostNames
}
elseif ($SAFConfiguration.system.serverRole -eq "AllInOneQuickly") {
    $hostNames = $SAFConfiguration.sitecore.hostNames
    $hostNames += $SAFConfiguration.search.solr.hostName
    if ($SAFConfiguration.system.sitecoreMode -eq "XP") {
        $hostNames += $SAFConfiguration.xConnect.hostName
    }
}

if($hostNames.Length -eq 0) {
    throw "Please, provide Host names for SSL generation..."
}

$exportPath = Get-Location
$rootCertName = BuildSitecoreRootCertName -Prefix $prefix
$clientCertName = BuildSitecoreClientCertName -Prefix $prefix

$certDestPath = Join-Path -Path $exportPath -ChildPath "SitecoreClientSSLCertificate_SAF.pfx"
if (Test-Path $certDestPath) {
    Write-Warning "It seems that you alredy have SitecoreClientSSLCertificate_SAF.pfx SSL certificate. Skipping creation..."
    Start-Sleep -s 5
}
else {
    GenerateClientCert -RootCertName $rootCertName -ClientCertName $clientCertName -Hostnames $hostNames
    ExportCert -CertName $clientCertName -PfxName "SitecoreClientSSLCertificate_SAF.pfx" -ExportPath $exportPath -Password $SAFDefaultPFXPassword
}