forked from enuchi/React-Google-Apps-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-cert.ps1
40 lines (31 loc) · 1.16 KB
/
generate-cert.ps1
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
# reference code: https://stackoverflow.com/questions/70226493/webpack-dev-server-and-https-this-site-can-t-be-reached
# reference issue: https://github.com/FiloSottile/mkcert/issues/286
$dnsName = "localhost"
$expiry = [DateTime]::Now.AddYears(1);
$repoRoot = Split-Path $PSScriptRoot
$certsDir = "$repoRoot\certs";
$fileName = "cert.pfx";
$passwordText = "abc123";
$name = "ReactApp";
Write-Host "Creating cert directly into CurrentUser\My store"
$certificate = New-SelfSignedCertificate `
-KeyExportPolicy 'Exportable' `
-CertStoreLocation Cert:\CurrentUser\My `
-Subject $name `
-FriendlyName $name `
-DnsName $dnsName `
-NotAfter $expiry
$certFile = Join-Path $certsDir $fileName
Write-Host "Exporting certificate to $certFile"
$password = ConvertTo-SecureString `
-String $passwordText `
-Force -AsPlainText
Export-PfxCertificate `
-Cert $certificate `
-FilePath $certFile `
-Password $password | Out-Null
Write-Host "Importing $certFile to CurrentUser\Root store for immediate system wide trust"
Import-PfxCertificate `
-FilePath $certFile `
-CertStoreLocation Cert:\LocalMachine\Root `
-Password $password | Out-Null