theInscriber revisó este gist 5 hours ago. Ir a la revisión
1 file changed, 74 insertions
install-ca.ps1(archivo creado)
| @@ -0,0 +1,74 @@ | |||
| 1 | + | param( | |
| 2 | + | [string]$CaUrl = "https://10.10.40.53", | |
| 3 | + | [string]$Fingerprint = "5fc8c379cab1119c1a9ac7038225f6bcf3a2ffb0e71b257af796b2bd6c71d594", | |
| 4 | + | [string]$StepVersion = "0.28.7", | |
| 5 | + | [switch]$Force | |
| 6 | + | ) | |
| 7 | + | ||
| 8 | + | $ErrorActionPreference = "Stop" | |
| 9 | + | ||
| 10 | + | function Write-Log { | |
| 11 | + | param([string]$Message) | |
| 12 | + | Write-Host "" | |
| 13 | + | Write-Host "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] $Message" | |
| 14 | + | } | |
| 15 | + | ||
| 16 | + | function Ensure-Step { | |
| 17 | + | if (Get-Command step -ErrorAction SilentlyContinue) { | |
| 18 | + | Write-Log "step CLI already installed" | |
| 19 | + | return | |
| 20 | + | } | |
| 21 | + | ||
| 22 | + | $msi = "step-cli_${StepVersion}_amd64.msi" | |
| 23 | + | $url = "https://github.com/smallstep/cli/releases/download/v${StepVersion}/${msi}" | |
| 24 | + | $tmp = Join-Path $env:TEMP $msi | |
| 25 | + | ||
| 26 | + | Write-Log "Downloading step CLI" | |
| 27 | + | Invoke-WebRequest -Uri $url -OutFile $tmp | |
| 28 | + | ||
| 29 | + | Write-Log "Installing step CLI" | |
| 30 | + | Start-Process msiexec.exe -Wait -ArgumentList "/i `"$tmp`" /qn" | |
| 31 | + | Remove-Item $tmp -Force | |
| 32 | + | ||
| 33 | + | $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + | |
| 34 | + | [System.Environment]::GetEnvironmentVariable("Path", "User") | |
| 35 | + | ||
| 36 | + | if (-not (Get-Command step -ErrorAction SilentlyContinue)) { | |
| 37 | + | throw "step CLI installation failed" | |
| 38 | + | } | |
| 39 | + | } | |
| 40 | + | ||
| 41 | + | function Bootstrap-Step { | |
| 42 | + | if ($Force) { | |
| 43 | + | $stepDir = Join-Path $HOME ".step" | |
| 44 | + | if (Test-Path $stepDir) { | |
| 45 | + | Remove-Item -Recurse -Force $stepDir | |
| 46 | + | } | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | Write-Log "Bootstrapping against $CaUrl" | |
| 50 | + | & step ca bootstrap --ca-url $CaUrl --fingerprint $Fingerprint --install --force | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | function Install-WindowsTrust { | |
| 54 | + | $rootCert = Join-Path $HOME ".step\certs\root_ca.crt" | |
| 55 | + | if (-not (Test-Path $rootCert)) { | |
| 56 | + | throw "Root certificate not found at $rootCert" | |
| 57 | + | } | |
| 58 | + | ||
| 59 | + | Write-Log "Installing root CA into Local Machine Root store" | |
| 60 | + | Import-Certificate -FilePath $rootCert -CertStoreLocation "Cert:\LocalMachine\Root" | Out-Null | |
| 61 | + | } | |
| 62 | + | ||
| 63 | + | function Verify-Install { | |
| 64 | + | $rootCert = Join-Path $HOME ".step\certs\root_ca.crt" | |
| 65 | + | Write-Log "Installed root CA:" | |
| 66 | + | & step certificate inspect $rootCert --short | |
| 67 | + | Write-Host "" | |
| 68 | + | Write-Host "Done." | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | Ensure-Step | |
| 72 | + | Bootstrap-Step | |
| 73 | + | Install-WindowsTrust | |
| 74 | + | Verify-Install | |
Siguiente
Anterior