-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0_setup-https-cert.ps1
More file actions
56 lines (48 loc) · 1.93 KB
/
Copy path0_setup-https-cert.ps1
File metadata and controls
56 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$ErrorActionPreference = 'Stop'
Write-Host '============================================'
Write-Host ' HTTPS Development Certificate Setup'
Write-Host '============================================'
Write-Host ''
# ---- Paths ----
$certDir = Join-Path $env:USERPROFILE '.aspnet\https'
$certPath = Join-Path $certDir 'aspnetapp.pfx'
$envFile = Join-Path $PSScriptRoot '.env'
if (-not (Test-Path $certDir)) {
New-Item -ItemType Directory -Path $certDir -Force | Out-Null
}
# ---- Password input (Console.ReadLine style: visible echo) ----
$password = Read-Host 'Enter certificate password'
if ([string]::IsNullOrWhiteSpace($password)) {
Write-Host ''
Write-Host '[ERROR] No password entered. Aborting.' -ForegroundColor Red
exit 1
}
# ---- 1. Export certificate to PFX ----
Write-Host ''
Write-Host '[1/3] Exporting certificate to PFX...'
dotnet dev-certs https -ep $certPath -p $password
if ($LASTEXITCODE -ne 0) {
Write-Host '[ERROR] Failed to export the certificate.' -ForegroundColor Red
exit 1
}
# ---- 2. Trust the certificate ----
Write-Host ''
Write-Host '[2/3] Trusting the certificate...'
dotnet dev-certs https --trust
if ($LASTEXITCODE -ne 0) {
Write-Host '[WARN] Failed to trust the certificate (manual trust may be required).' -ForegroundColor Yellow
}
# ---- 3. Create .env (UTF-8 without BOM so docker compose can read it) ----
Write-Host ''
Write-Host '[3/3] Creating .env file...'
$envContent = "# HTTPS development certificate settings (auto-generated, keep out of Git)`r`nCERT_PASSWORD=$password`r`n"
[System.IO.File]::WriteAllText($envFile, $envContent, (New-Object System.Text.UTF8Encoding($false)))
# ---- Summary ----
Write-Host ''
Write-Host '============================================'
Write-Host ' Done'
Write-Host '============================================'
Write-Host " Certificate : $certPath"
Write-Host " .env : $envFile"
Write-Host '============================================'
Write-Host ''