-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
519 lines (447 loc) · 16.5 KB
/
setup
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/bin/bash -e
echo
echo "=== Mikhail Nuzhin setting IKEv2-setup in Docker ==="
echo
function exit_badly {
echo "$1"
exit 1
}
IP=$(dig -4 +short myip.opendns.com @resolver1.opendns.com)
echo
echo "External IP: ${IP}"
echo
echo "*** This hostname must already resolve to this machine ***"
read -r -p "Hostname for VPN: " VPNHOST
VPNHOSTIP=$(dig -4 +short "${VPNHOST}")
[[ -n "$VPNHOSTIP" ]] || exit_badly "Cannot resolve VPN hostname: aborting"
if [[ "${IP}" != "${VPNHOSTIP}" ]]; then
echo "Warning: ${VPNHOST} resolves to ${VPNHOSTIP}, not ${IP}"
echo "Either you're behind NAT, or something is wrong (e.g. hostname points to wrong IP, CloudFlare proxying shenanigans, ...)"
read -r -p "Press [Return] to continue anyway, or Ctrl-C to abort"
fi
read -r -p "VPN username: " VPNUSERNAME
while true; do
read -r -s -p "VPN password (no quotes, please): " VPNPASSWORD
echo
read -r -s -p "Confirm VPN password: " VPNPASSWORD2
echo
[[ "${VPNPASSWORD}" = "${VPNPASSWORD2}" ]] && break
echo "Passwords didn't match -- please try again"
done
echo '
Public DNS servers include:
176.103.130.130,176.103.130.131 AdGuard https://adguard.com/en/adguard-dns/overview.html
176.103.130.132,176.103.130.134 AdGuard Family https://adguard.com/en/adguard-dns/overview.html
1.1.1.1,1.0.0.1 Cloudflare/APNIC https://1.1.1.1
84.200.69.80,84.200.70.40 DNS.WATCH https://dns.watch
8.8.8.8,8.8.4.4 Google https://developers.google.com/speed/public-dns/
208.67.222.222,208.67.220.220 OpenDNS https://www.opendns.com
208.67.222.123,208.67.220.123 OpenDNS FamilyShield https://www.opendns.com
9.9.9.9,149.112.112.112 Quad9 https://quad9.net
77.88.8.8,77.88.8.1 Yandex https://dns.yandex.com
77.88.8.88,77.88.8.2 Yandex Safe https://dns.yandex.com
77.88.8.7,77.88.8.3 Yandex Family https://dns.yandex.com
'
read -r -p "DNS servers for VPN users (default: 176.103.130.130,176.103.130.131): " VPNDNS
VPNDNS=${VPNDNS:-'176.103.130.130,176.103.130.131'}
grep -Fq 'MikhailNuzhin' ikev2/conf/ipsec.conf || echo "# strongSwan IPsec configuration file
config setup
strictcrlpolicy=yes
uniqueids=never
conn roadwarrior
auto=add
compress=no
type=tunnel
keyexchange=ikev2
fragmentation=yes
forceencaps=yes
ike=aes256gcm16-prfsha384-ecp384,aes256-aes128-sha256-sha1-modp2048-modp4096-modp1024!
esp=aes256gcm16-ecp384,aes128-aes256-sha1-sha256-modp2048-modp4096-modp1024!
dpdaction=clear
dpddelay=300s
rekey=no
left=%any
leftid=@${VPNHOST}
leftcert=cert.pem
leftsendcert=always
leftsubnet=0.0.0.0/0
right=%any
rightid=%any
rightauth=eap-mschapv2
eap_identity=%any
rightdns=${VPNDNS}
rightsourceip=10.101.0.0/16
rightsendcert=never
" > ikev2/conf/ipsec.conf
grep -Fq 'MikhailNuzhin' ikev2/conf/ipsec.secrets || echo "# strongSwan IPsec secrets file
${VPNHOST} : RSA \"privkey.pem\"
${VPNUSERNAME} : EAP \"${VPNPASSWORD}\"
" > ikev2/conf/ipsec.secrets
grep -Fq 'MikhailNuzhin' ikev2/bin/run || echo "# Startup file strongSwan
#!/bin/bash
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -I INPUT -i eth0 -m state --state NEW -m recent --set
iptables -I INPUT -i eth0 -m state --state NEW -m recent --update --seconds 300 --hitcount 60 -j DROP
iptables -A INPUT -p udp --dport 500 -j ACCEPT
iptables -A INPUT -p udp --dport 4500 -j ACCEPT
iptables -A FORWARD --match policy --pol ipsec --dir in --proto esp -s 10.101.0.0/16 -j ACCEPT
iptables -A FORWARD --match policy --pol ipsec --dir out --proto esp -d 10.101.0.0/16 -j ACCEPT
iptables -t mangle -A FORWARD --match policy --pol ipsec --dir in -s 10.101.0.0/16 -o eth0 -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1361:1536 -j TCPMSS --set-mss 1360
iptables -t nat -A POSTROUTING -s 10.101.0.0/16 -o eth0 -m policy --pol ipsec --dir out -j ACCEPT # exempt IPsec traffic from masquerading
iptables -t nat -A POSTROUTING -s 10.101.0.0/16 -o eth0 -j MASQUERADE
iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP
ln -f -s "/etc/letsencrypt/live/${VPNHOST}/cert.pem" /etc/ipsec.d/certs/cert.pem
ln -f -s "/etc/letsencrypt/live/${VPNHOST}/privkey.pem" /etc/ipsec.d/private/privkey.pem
ln -f -s "/etc/letsencrypt/live/${VPNHOST}/chain.pem" /etc/ipsec.d/cacerts/chain.pem
/usr/sbin/ipsec start --nofork
" > ikev2/bin/run
mkdir -p ~/ikev2/connect
cd ~/ikev2/connect
cat << EOF > vpn-ios.mobileconfig
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
<plist version='1.0'>
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>IKEv2</key>
<dict>
<key>AuthenticationMethod</key>
<string>None</string>
<key>ChildSecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256-GCM</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-384</string>
<key>DiffieHellmanGroup</key>
<integer>20</integer>
<key>LifeTimeInMinutes</key>
<integer>1440</integer>
</dict>
<key>DeadPeerDetectionRate</key>
<string>Medium</string>
<key>DisableMOBIKE</key>
<integer>0</integer>
<key>DisableRedirect</key>
<integer>0</integer>
<key>EnableCertificateRevocationCheck</key>
<integer>0</integer>
<key>EnablePFS</key>
<true/>
<key>ExtendedAuthEnabled</key>
<true/>
<key>IKESecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256-GCM</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-384</string>
<key>DiffieHellmanGroup</key>
<integer>20</integer>
<key>LifeTimeInMinutes</key>
<integer>1440</integer>
</dict>
<key>OnDemandEnabled</key>
<integer>1</integer>
<key>OnDemandRules</key>
<array>
<dict>
<key>Action</key>
<string>Connect</string>
</dict>
</array>
<key>RemoteAddress</key>
<string>${VPNHOST}</string>
<key>RemoteIdentifier</key>
<string>${VPNHOST}</string>
<key>UseConfigurationAttributeInternalIPSubnet</key>
<integer>0</integer>
</dict>
<key>IPv4</key>
<dict>
<key>OverridePrimary</key>
<integer>1</integer>
</dict>
<key>PayloadDescription</key>
<string>Configures VPN settings</string>
<key>PayloadDisplayName</key>
<string>VPN</string>
<key>PayloadIdentifier</key>
<string>com.apple.vpn.managed.$(uuidgen)</string>
<key>PayloadType</key>
<string>com.apple.vpn.managed</string>
<key>PayloadUUID</key>
<string>$(uuidgen)</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>Proxies</key>
<dict>
<key>HTTPEnable</key>
<integer>0</integer>
<key>HTTPSEnable</key>
<integer>0</integer>
</dict>
<key>UserDefinedName</key>
<string>${VPNHOST}</string>
<key>VPNType</key>
<string>IKEv2</string>
</dict>
</array>
<key>PayloadDisplayName</key>
<string>IKEv2 VPN configuration (${VPNHOST})</string>
<key>PayloadIdentifier</key>
<string>com.mackerron.vpn.$(uuidgen)</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>$(uuidgen)</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>
EOF
cat << EOF > vpn-mac.applescript
set vpnuser to text returned of (display dialog "Please enter your VPN username" default answer "")
set vpnpass to text returned of (display dialog "Please enter your VPN password" default answer "" with hidden answer)
set plist to "<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
<plist version='1.0'>
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>IKEv2</key>
<dict>
<key>AuthenticationMethod</key>
<string>None</string>
<key>ChildSecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256-GCM</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-384</string>
<key>DiffieHellmanGroup</key>
<integer>20</integer>
<key>LifeTimeInMinutes</key>
<integer>1440</integer>
</dict>
<key>DeadPeerDetectionRate</key>
<string>Medium</string>
<key>DisableMOBIKE</key>
<integer>0</integer>
<key>DisableRedirect</key>
<integer>0</integer>
<key>EnableCertificateRevocationCheck</key>
<integer>0</integer>
<key>EnablePFS</key>
<true/>
<key>ExtendedAuthEnabled</key>
<true/>
<key>AuthName</key>
<string>" & vpnuser & "</string>
<key>AuthPassword</key>
<string>" & vpnpass & "</string>
<key>IKESecurityAssociationParameters</key>
<dict>
<key>EncryptionAlgorithm</key>
<string>AES-256-GCM</string>
<key>IntegrityAlgorithm</key>
<string>SHA2-384</string>
<key>DiffieHellmanGroup</key>
<integer>20</integer>
<key>LifeTimeInMinutes</key>
<integer>1440</integer>
</dict>
<key>OnDemandEnabled</key>
<integer>1</integer>
<key>OnDemandRules</key>
<array>
<dict>
<key>Action</key>
<string>Connect</string>
</dict>
</array>
<key>RemoteAddress</key>
<string>${VPNHOST}</string>
<key>RemoteIdentifier</key>
<string>${VPNHOST}</string>
<key>UseConfigurationAttributeInternalIPSubnet</key>
<integer>0</integer>
</dict>
<key>IPv4</key>
<dict>
<key>OverridePrimary</key>
<integer>1</integer>
</dict>
<key>PayloadDescription</key>
<string>Configures VPN settings</string>
<key>PayloadDisplayName</key>
<string>VPN</string>
<key>PayloadIdentifier</key>
<string>com.apple.vpn.managed.$(uuidgen)</string>
<key>PayloadType</key>
<string>com.apple.vpn.managed</string>
<key>PayloadUUID</key>
<string>$(uuidgen)</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>Proxies</key>
<dict>
<key>HTTPEnable</key>
<integer>0</integer>
<key>HTTPSEnable</key>
<integer>0</integer>
</dict>
<key>UserDefinedName</key>
<string>${VPNHOST}</string>
<key>VPNType</key>
<string>IKEv2</string>
</dict>
</array>
<key>PayloadDisplayName</key>
<string>IKEv2 VPN configuration (${VPNHOST})</string>
<key>PayloadIdentifier</key>
<string>com.mackerron.vpn.$(uuidgen)</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>$(uuidgen)</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>"
set tmpdir to do shell script "mktemp -d"
set tmpfile to tmpdir & "/vpn.mobileconfig"
do shell script "touch " & tmpfile
write plist to tmpfile
do shell script "open /System/Library/PreferencePanes/Profiles.prefPane " & tmpfile
delay 5
do shell script "rm " & tmpfile
EOF
cat << EOF > vpn-android.sswan
{
"uuid": "$(uuidgen)",
"name": "${VPNHOST}",
"type": "ikev2-eap",
"remote": {
"addr": "${VPNHOST}"
}
}
EOF
cat << EOF > vpn-ubuntu-client.sh
if [[ \$(id -u) -ne 0 ]]; then echo "Please run as root (e.g. sudo ./path/to/this/script)"; exit 1; fi
read -p "VPN username (same as entered on server): " VPNUSERNAME
while true; do
read -s -p "VPN password (same as entered on server): " VPNPASSWORD
echo
read -s -p "Confirm VPN password: " VPNPASSWORD2
echo
[ "\$VPNPASSWORD" = "\$VPNPASSWORD2" ] && break
echo "Passwords didn't match -- please try again"
done
apt-get install -y strongswan libstrongswan-standard-plugins libcharon-extra-plugins
apt-get install -y libcharon-standard-plugins || true # 17.04+ only
ln -f -s /etc/ssl/certs/ISRG_Root_X1.pem /etc/ipsec.d/cacerts/
grep -Fq 'MikhailNuzhin' /etc/ipsec.conf || echo "
conn ikev2vpn
ikelifetime=60m
keylife=20m
rekeymargin=3m
keyingtries=1
keyexchange=ikev2
ike=aes256gcm16-prfsha384-ecp384!
esp=aes256gcm16-ecp384!
leftsourceip=%config
leftauth=eap-mschapv2
eap_identity=\${VPNUSERNAME}
right=${VPNHOST}
rightauth=pubkey
rightid=@${VPNHOST}
rightsubnet=0.0.0.0/0
auto=add # or auto=start to bring up automatically
" >> /etc/ipsec.conf
grep -Fq 'MikhailNuzhin' /etc/ipsec.secrets || echo "
\${VPNUSERNAME} : EAP \"\${VPNPASSWORD}\"
" >> /etc/ipsec.secrets
ipsec restart
sleep 5 # is there a better way?
echo "Bringing up VPN ..."
ipsec up ikev2vpn
ipsec statusall
echo
echo -n "Testing IP address ... "
VPNIP=\$(dig -4 +short ${VPNHOST})
ACTUALIP=\$(dig -4 +short myip.opendns.com @resolver1.opendns.com)
if [[ "\$VPNIP" == "\$ACTUALIP" ]]; then echo "PASSED (IP: \${VPNIP})"; else echo "FAILED (IP: \${ACTUALIP}, VPN IP: \${VPNIP})"; fi
echo
echo "To disconnect: ipsec down ikev2vpn"
echo "To reconnect: ipsec up ikev2vpn"
echo "To connect automatically: change auto=add to auto=start in /etc/ipsec.conf"
EOF
cat << EOF > vpn-instructions.txt
== iOS ==
A configuration profile is attached as vpn-ios.mobileconfig.
Open this attachment. Then go to Settings > General > VPN & Device Management, and find the profile under 'DOWNLOADED PROFILE'.
You will be asked for your device PIN or password, and then your VPN username and password.
These instructions apply to iOS 15. Earlier (and probably later) versions of iOS will also work, but the exact setup steps may differ.
== macOS ==
In macOS Monterey, your VPN username and password must be embedded in the profile file. However, your password cannot be included in a profile sent by email for security reasons.
So: open vpn-mac.applescript and run it from Script Editor. You'll be prompted for your VPN username and password.
System Preferences will then open. Select the profile listed as 'Downloaded' on the left, and click 'Install...' in the main panel.
== Windows ==
You will need Windows 10 Pro or above. Please run the following commands in PowerShell:
\$Response = Invoke-WebRequest -UseBasicParsing -Uri https://valid-isrgrootx1.letsencrypt.org
Add-VpnConnection -Name "${VPNHOST}" \`
-ServerAddress "${VPNHOST}" \`
-TunnelType IKEv2 \`
-EncryptionLevel Maximum \`
-AuthenticationMethod EAP \`
-RememberCredential
Set-VpnConnectionIPsecConfiguration -ConnectionName "${VPNHOST}" \`
-AuthenticationTransformConstants GCMAES256 \`
-CipherTransformConstants GCMAES256 \`
-EncryptionMethod GCMAES256 \`
-IntegrityCheckMethod SHA384 \`
-DHGroup ECP384 \`
-PfsGroup ECP384 \`
-Force
# Run the following command to retain access to the local network (e.g. printers, file servers) while the VPN is connected.
# On a home network, you probably want this. On a public network, you probably don't.
Set-VpnConnection -Name "${VPNHOST}" -SplitTunneling \$True
You will need to enter your chosen VPN username and password in order to connect.
== Android ==
Download the strongSwan app from the Play Store: https://play.google.com/store/apps/details?id=org.strongswan.android
Then open the attached .sswan file, or select it after choosing 'Import VPN profile' from the strongSwan app menu. You will need to enter your chosen VPN username and password in order to >
For a persistent connection, go to your device's Settings app and choose Network & Internet > Advanced > VPN > strongSwan VPN Client, tap the gear icon and toggle on 'Always-on VPN' (these>
== Ubuntu ==
A bash script to set up strongSwan as a VPN client is attached as vpn-ubuntu-client.sh. You will need to chmod +x and then run the script as root.
EOF
cd
echo
echo "--- How to connect ---"
echo
echo "Connection instructions can be found in your home directory, '~/ikev2/connect'"
echo
echo "--- Build dokcaer image ---"
echo
docker build -t mn/ikev2 -f ~/ikev2/dockerfile .
echo
echo "--- Run docker container ---"
echo
docker-compose -f ~/ikev2/docker-compose.yml up -d
docker ps