Install/OnPrem/New-ServerCert.ps1

Import-Module "$PSScriptRoot\..\..\Common\SSL\SSL-Module.psm1" -Force
$ErrorActionPreference = "Stop"

$prefix = $global:Configuration.prefix
$hostNames = @()

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

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

$password = $global:Configuration.ssl.auto.pfxPassword
$exportPath = Get-Location
$rootCertName = BuildSitecoreRootCertName -Prefix $prefix
$serverCertName = BuildSitecoreServerCertName -Prefix $prefix

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