9090 Removing ALL the test certificates from your ADC.
9191. NOTES
9292 File Name : GenLeCertForNS.ps1
93- Version : v2.0 .0
93+ Version : v2.1 .0
9494 Author : John Billekens
9595 Requires : PowerShell v5.1 and up
9696 ADC 11.x and up
9797 Run As Administrator
98- Posh-ACME 3.1 .1 (Will be installed via this script) Thank you @rmbolger for providing the HTTP validation method!
98+ Posh-ACME 3.2 .1 (Will be installed via this script) Thank you @rmbolger for providing the HTTP validation method!
9999 Microsoft .NET Framework 4.7.1 (when using Posh-ACME/WildCard certificates)
100100. LINK
101101 https://blog.j81.nl
@@ -257,7 +257,7 @@ param(
257257
258258# requires -version 5.1
259259# requires -runasadministrator
260- $ScriptVersion = " v2.0 .0"
260+ $ScriptVersion = " v2.1 .0"
261261
262262# region Functions
263263
@@ -477,7 +477,6 @@ function Connect-ADC {
477477 return $session
478478 }
479479}
480-
481480function ConvertTo-TxtValue ([string ]$KeyAuthorization ) {
482481 $keyAuthBytes = [Text.Encoding ]::UTF8.GetBytes($KeyAuthorization )
483482 $sha256 = [Security.Cryptography.SHA256 ]::Create()
@@ -585,6 +584,7 @@ $DNSObjects += [PSCustomObject]@{
585584 Match = $null
586585 SAN = $false
587586 Challenge = $null
587+ Done = $false
588588}
589589if (-not ([string ]::IsNullOrWhiteSpace($SAN ))) {
590590 [string []]$SAN = @ ($SAN.Split (" ," ))
@@ -596,6 +596,7 @@ if (-not ([string]::IsNullOrWhiteSpace($SAN))) {
596596 Match = $null
597597 SAN = $true
598598 Challenge = $null
599+ Done = $false
599600 }
600601 }
601602}
@@ -621,8 +622,7 @@ if ($CleanPoshACMEStorage) {
621622# region Load Module
622623
623624if ((-not ($CleanNS )) -and (-not ($RemoveTestCertificates ))) {
624- # $PoshACMEVersion = "2.6.0"
625- $PoshACMEVersion = " 3.1.1"
625+ $PoshACMEVersion = " 3.2.1"
626626 Write-Verbose " Try loading the Posh-ACME v$PoshACMEVersion Modules"
627627 if (-not (Get-Module Posh- ACME)) {
628628 try {
@@ -1460,33 +1460,42 @@ if ((-not $CleanNS) -and (-not $RemoveTestCertificates) -and ($ValidationMethod
14601460if ((-not $CleanNS ) -and (-not $RemoveTestCertificates ) -and ($ValidationMethod -in " dns" )) {
14611461 Write-Verbose " Check if DNS Records need to be validated"
14621462 Write-Host - ForeGroundColor White " Verification:"
1463+ Foreach ($DNSObject in $DNSObjects ) {
1464+ $PAOrderItem = Posh-ACME\Get-PAOrder - MainDomain $CN | Posh-ACME\Get-PAAuthorizations | Where-Object {$_.fqdn -eq $DNSObject.DNSName }
1465+ Write-Verbose - Message " OrderItem: $ ( $PAOrderItem | Select-Object fqdn, status, DNS01Status, expires | Format-List | Out-String ) "
1466+ if (($PAOrderItem.DNS01Status -notlike " valid" ) -and ($PAOrderItem.DNS01Status -notlike " invalid" )) {
1467+ try {
1468+ Write-Verbose " Start submitting Challenge"
1469+ Posh-ACME\Send-ChallengeAck - ChallengeUrl $ ($PAOrderItem.DNS01Url ) - Account $PAAccount
1470+ Write-Verbose " Done"
1471+ } catch {
1472+ Write-Verbose " Error Details: $ ( $_.Exception.Message ) " - Verbose
1473+ throw " Error while submitting the Challenge"
1474+ }
1475+ Write-Verbose - Message " Finished submitting Challenge"
1476+ } elseif ($PAOrderItem.DNS01Status -like " valid" ) {
1477+ Write-Verbose - Message " This order is done"
1478+ $DNSObject.Done = $true
1479+ }
1480+ $PAOrderItem = $null
1481+ }
14631482 $i = 0
14641483 while ($i -le 10 ) {
14651484 Foreach ($DNSObject in $DNSObjects ) {
1466- $PAOrderItem = Posh-ACME\Get-PAOrder - Refresh - MainDomain $CN | Posh-ACME\Get-PAAuthorizations | Where-Object {$_.fqdn -eq $DNSObject.DNSName }
1467- # $DNSObject.Challenge = Posh-ACME\Get-PAOrder -Refresh -MainDomain $CN | Posh-ACME\Get-PAAuthorizations | Select-Object fqdn, DnsId, HTTP01Status, HTTP01Token, HTTP01Url, DNS01Status, DNS01Token, DNS01Url | Where-Object {$_.fqdn -eq $DNSObject.DNSName }
1468- if (($PAOrderItem.DNS01Status -notlike " valid" ) -and ($PAOrderItem.DNS01Status -notlike " invalid" )) {
1469- Write-Verbose - Message " Start submitting Challenge"
1485+ if ($DNSObject.Done -eq $false ) {
14701486 try {
1471- Write-Verbose " Start submitting Challenge"
1472- Posh-ACME\Send-ChallengeAck - ChallengeUrl $ ($PAOrderItem.DNS01Url ) - Account $PAAccount
1473- } catch {
1474- Write-Verbose " Error Details: $ ( $_.Exception.Message ) " - Verbose
1475- throw " Error while submitting the Challenge"
1476- }
1477- Start-Sleep - Milliseconds 100
1478- try {
1479- $PAValidation = Posh-ACME\Get-PAOrder - Refresh - MainDomain $CN | Posh-ACME\Get-PAAuthorizations | Where-Object {$_.fqdn -eq $DNSObject.DNSName }
1480- Write-Verbose " $ ( $PAValidation | Select-Object fqdn, status, expires | Format-List | Out-String ) "
1487+ $PAOrderItem = Posh-ACME\Get-PAOrder - MainDomain $CN | Posh-ACME\Get-PAAuthorizations | Where-Object {$_.fqdn -eq $DNSObject.DNSName }
1488+ Write-Verbose - Message " OrderItem: $ ( $PAOrderItem | Select-Object fqdn, status, DNS01Status, expires | Format-List | Out-String ) "
1489+ if ($PAOrderItem.DNS01Status -in " valid" , " invalid" ) {
1490+ Write-Verbose - Message " This order is done. Status: $ ( $PAOrderItem.DNS01Status ) "
1491+ $DNSObject.Done = $true
1492+ }
14811493 } catch {
14821494 Write-Verbose " Error Details: $ ( $_.Exception.Message ) "
14831495 throw " Error while retreiving validation status"
14841496 }
1485- # $DNSObject.Challenge = Posh-ACME\Get-PAOrder -Refresh -MainDomain $CN | Posh-ACME\Get-PAAuthorizations | Select-Object fqdn, DnsId, HTTP01Status, HTTP01Token, HTTP01Url, DNS01Status, DNS01Token, DNS01Url | Where-Object {$_.fqdn -eq $DNSObject.DNSName }
1486- Write-Verbose " $ ( $PAValidation | Select-Object fqdn, status, expires | Format-List | Out-String ) "
1487- }
1488-
1489- $PAOrderItem = $null
1497+ $PAOrderItem = $null
1498+ }
14901499 }
14911500 $Items = Posh-ACME\Get-PAOrder - Refresh - MainDomain $CN | Posh-ACME\Get-PAAuthorizations | Select-Object status - ExpandProperty status
14921501 if (($Items | Where-Object {($_ -notlike " valid" ) -and ($_ -notlike " invalid" )}).Count -eq 0 ) {
@@ -1498,14 +1507,17 @@ if ((-not $CleanNS) -and (-not $RemoveTestCertificates) -and ($ValidationMethod
14981507 Start-Sleep - Seconds 2
14991508 }
15001509}
1510+
15011511if ((-not $CleanNS ) -and (-not $RemoveTestCertificates ) -and ($ValidationMethod -in " http" , " dns" )) {
15021512 $Order = $PAOrder | Posh-ACME\Get-PAOrder - Refresh
1513+ Write-Verbose - Message " Order state: $ ( $Order.status ) "
15031514 if ($Order.status -eq " ready" ) {
15041515 Write-Verbose " Order is ready"
15051516 } else {
15061517 Write-Verbose " Order is still not ready, validation failed?" - Verbose
15071518 }
1508- $NewCertificates = New-PACertificate - Domain $ ($DNSObjects.DNSName ) - DnsPlugin Manual - ValidationTimeout 60 - Force - DirectoryUrl $BaseService - FriendlyName $FriendlyName - PfxPass $PfxPassword
1519+ Write-Verbose - Message " Requesting Certificate"
1520+ $NewCertificates = New-PACertificate - Domain $ ($DNSObjects.DNSName ) - DirectoryUrl $BaseService - FriendlyName $FriendlyName - PfxPass $PfxPassword
15091521 Write-Verbose " $ ( $NewCertificates | Format-List | Out-String ) "
15101522 Start-Sleep - Seconds 1
15111523}
0 commit comments