This repository has been archived by the owner on May 28, 2020. It is now read-only.
forked from richardhicks/aovpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet-IKEv2VPNRootCertificate.ps1
209 lines (158 loc) · 8.87 KB
/
Set-IKEv2VPNRootCertificate.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<#
.SYNOPSIS
Configures the trusted root certification authority to be used for IKEv2 VPN connection on Windows Server Routing and Remote Access Service (RRAS) servers.
.PARAMETER Thumbprint
Certificate hash of the trusted root certification authority used for IKEv2 VPN connections.
.PARAMETER EnableCertificateAuthnetication
Enables machine certificate authentication for IKEv2 VPN connections.
.PARAMETER Clear
Clears the currently configured root certification authority.
.PARAMETER Restart
Restarts the RemoteAccess service.
.EXAMPLE
.\Set-IKEv2VPNRootCertificate.ps1 -Clear
Running this command will clear the existing root certification authority configuration.
.EXAMPLE
.\Set-IKEv2VPNRootCertificate.ps1 -Thumbprint '71899A67BF33AF31BEFDC071F8F733B183856332' -Restart
Running this command will configure RRAS to use this certification authority as the exclusive trusted CA for all IKEv2 VPN connections. Including the -Restart swtich restarts the RemoteAccess service for changes to take effect.
.EXAMPLE
.\Set-IKEv2VPNRootCertificate.ps1 -Thumbprint '71899A67BF33AF31BEFDC071F8F733B183856332' -EnableCertificateAuthentication
Running this command will configure RRAS to use this certification authority as the exclusive trusted CA for all IKEv2 VPN connections. Including the -EnableCertificateAuthentication switch will automatically add Certificate authentication to the list of accepted user authentication protocols (prerequisite for setting root CA cert).
.DESCRIPTION
Use this script to configure the trusted root certification authority for IKEv2 VPN connections.
.LINK
https://directaccess.richardhicks.com/
.NOTES
Version: 1.11
Creation Date: August 2, 2019
Last Updated: October 29, 2019
Author: Richard Hicks
Organization: Richard M. Hicks Consulting, Inc.
Contact: [email protected]
Web Site: www.richardhicks.com
#>
[CmdletBinding()]
Param (
[string]$Thumbprint,
[switch]$EnableCertificateAuthnetication,
[switch]$Clear,
[switch]$Restart
)
# Clear current root certificate configuration
If ($Clear) {
Write-Verbose 'Clearing existing root certificate configuration...'
Set-VpnAuthProtocol -RootCertificateNameToAccept $Null
If ($Restart) {
Write-Verbose 'Restarting the RemoteAccess Service...'
Restart-Service RemoteAccess -PassThru
}
ElseIf (-Not $Restart) {
Write-Warning 'The RemoteAccess service must be restarted for these changes to take effect.'
}
Exit
}
# Get current user authentication protocol configuration
$VpnAuthProtocol = (Get-VpnAuthProtocol | Select-Object -ExpandProperty UserAuthProtocolAccepted)
# Ensure that certificate authentication is enabled
If ($VpnAuthProtocol -like '*certificate*') {
Write-Verbose 'Certificate authentication enabled.'
}
ElseIf (-Not $EnableCertificateAuthnetication) {
Write-Warning 'Certificate authentication not enabled. Use the -EnableCertificateAuthnetication parameter to configure it.'
Exit
}
# Assign root certificate
$RootCACert = (Get-ChildItem -Path Cert:\LocalMachine\Root | Where-Object { $_.Thumbprint -eq $Thumbprint } | Select-Object -First 1)
# Create user authentication protocol array
$Protocols = @()
$Protocols = { $Protocols }.Invoke()
ForEach ($Protocol in $VpnAuthProtocol) {
$Protocols.Add($Protocol)
}
# Add the Certificate authentication protocol is required
If ($EnableCertificateAuthnetication) {
$Protocols.Add('Certificate')
}
Write-Verbose 'Updating trusted root certificate information...'
Set-VpnAuthProtocol -UserAuthProtocolAccepted $Protocols -RootCertificateNameToAccept $RootCACert -PassThru
If ($Restart) {
Write-Verbose 'Restarting the RemoteAccess service...'
Restart-Service RemoteAccess -PassThru
}
Else {
Write-Warning 'The RemoteAccess service must be restarted for these changes to take effect.'
}
# SIG # Begin signature block
# MIINbAYJKoZIhvcNAQcCoIINXTCCDVkCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUmXpcadZZfu49p08fDd2x9DOM
# 9rSgggquMIIFMDCCBBigAwIBAgIQBAkYG1/Vu2Z1U0O1b5VQCDANBgkqhkiG9w0B
# AQsFADBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVk
# IElEIFJvb3QgQ0EwHhcNMTMxMDIyMTIwMDAwWhcNMjgxMDIyMTIwMDAwWjByMQsw
# CQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cu
# ZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3VyZWQgSUQg
# Q29kZSBTaWduaW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
# +NOzHH8OEa9ndwfTCzFJGc/Q+0WZsTrbRPV/5aid2zLXcep2nQUut4/6kkPApfmJ
# 1DcZ17aq8JyGpdglrA55KDp+6dFn08b7KSfH03sjlOSRI5aQd4L5oYQjZhJUM1B0
# sSgmuyRpwsJS8hRniolF1C2ho+mILCCVrhxKhwjfDPXiTWAYvqrEsq5wMWYzcT6s
# cKKrzn/pfMuSoeU7MRzP6vIK5Fe7SrXpdOYr/mzLfnQ5Ng2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