Skip to content

Commit

Permalink
fix ambiguous cert selection in WinRM enable script (ansible#21263)
Browse files Browse the repository at this point in the history
Rather than trying to guess which cert we just generated,   parse the generated cert data and extract the thumbprint directly.
  • Loading branch information
nitzmahone authored and trondhindenes committed Feb 13, 2017
1 parent a6cb377 commit ba353b0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/scripts/ConfigureRemotingForAnsible.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ Function New-LegacySelfSignedCert
$certdata = $enrollment.CreateRequest(0)
$enrollment.InstallResponse(2, $certdata, 0, "")

# Return the thumbprint of the last installed certificate;
# This is needed for the new HTTPS WinRM listerner we're
# going to create further down.
Get-ChildItem "Cert:\LocalMachine\my"| Sort-Object NotBefore -Descending | Select -First 1 | Select -Expand Thumbprint
# extract/return the thumbprint from the generated cert
$parsed_cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$parsed_cert.Import([System.Text.Encoding]::UTF8.GetBytes($certdata))

return $parsed_cert.Thumbprint
}

# Setup error handling.
Expand Down

0 comments on commit ba353b0

Please sign in to comment.