-
Notifications
You must be signed in to change notification settings - Fork 9
/
cert_make_localhost_ssl.ps1
37 lines (32 loc) · 1.2 KB
/
cert_make_localhost_ssl.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
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$password = ""
)
$cwd = Convert-Path .
$cerFile = "$cwd\localhost.cer"
$pfxFile = "$cwd\localhost.pfx"
# abort if files exist
if((Test-Path($pfxFile)) -or (Test-Path($cerFile)))
{
Write-Warning "Failed, localhost files already exist in current directory."
Exit
}
# include DnsName property for modern browsers
# https://groups.google.com/a/chromium.org/forum/#!topic/security-dev/IGT2fLJrAeo
$cert = New-SelfSignedCertificate `
-Subject localhost `
-DnsName localhost `
-FriendlyName "Localhost Dev Certificate" `
-NotBefore (Get-Date) `
-NotAfter (Get-Date).AddYears(10) `
-CertStoreLocation "cert:CurrentUser\My" `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-HashAlgorithm SHA256 `
-KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment `
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
$certStore = 'Cert:\CurrentUser\My\' + ($cert.ThumbPrint)
$securePass = ConvertTo-SecureString -String $password -Force -AsPlainText
Export-PfxCertificate -Cert $certStore -FilePath $pfxFile -Password $securePass
Export-Certificate -Cert $certStore -FilePath $cerFile