-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateVPNCerts.ps1
26 lines (20 loc) · 1023 Bytes
/
CreateVPNCerts.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
# Run this script before the terraform script
# It will generate a new cert suitable for a P2S VPN
# It also imports the cert to the current user store.
$cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature `
-Subject "CN=P2SVPNRootCert" -KeyExportPolicy Exportable `
-HashAlgorithm sha256 -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign
New-SelfSignedCertificate -Type Custom -DnsName P2SVPNClientCert -KeySpec Signature `
-Subject "CN=P2SVPNClientCert" -KeyExportPolicy Exportable `
-HashAlgorithm sha256 -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" `
-Signer $cert -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2")
Export-Certificate -Cert $cert -FilePath "P2SVPNRootCert.cer" -Type CERT
$certFile = 'P2SVPNRootCert.cer'
$content = @(
'-----BEGIN CERTIFICATE-----'
[System.Convert]::ToBase64String($cert.RawData, 'InsertLineBreaks')
'-----END CERTIFICATE-----'
)
$content | Out-File -FilePath $certFile -Encoding UTF8