summaryrefslogtreecommitdiff
path: root/share/man/man8/vpn.8
blob: 1351d5d61c564040ad21b5b3777b5b4b9507642a (plain)
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
.\" $OpenBSD: vpn.8,v 1.14 1999/03/15 15:35:36 deraadt Exp $
.\" Copyright 1998 Niels Provos <provos@physnet.uni-hamburg.de>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"      This product includes software developed by Niels Provos.
.\" 4. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" Manual page, using -mandoc macros
.\"
.Dd Feb 9, 1999
.Dt VPN 8
.Os
.Sh NAME
.Nm vpn
.Nd configuring the system for virtual private networks
.Sh DESCRIPTION
A virtual private network is used to securely connect two or more subnets
over the internet. For each subnet there is a security gateway which is
linked via a cryptographically secured tunnel to the security gateway of
the other subnet.
.Xr ipsec 4
is used to provide the necessary network-layer cryptographic services.
This document describes the configuration process for setting up a 
.Nm VPN .
.Pp
Briefly, creating a VPN consists of the following steps
.Bl -enum -compact
.It
Choose a key exchange method: manual keyed or 
.Xr photurisd 8
.It
Create a Security Association (SA) for each endpoint
.It
Create the appropriate IPSec flows
.It 
Configure your firewall rules appropriately
.El
.Ss Choosing a key exchange method
There are currently two key exchange methods available:
.Pp
.Bl -bullet -inset -compact
.It
manual (symmetric shared secret)
.It
.Xr photurisd 8
.El
.Pp
At present VPNs between private networks must use manual keying.
.Xr photurisd 8
may only be used in situations where both
security gateways are within their protected network ranges.
.Ss Generating Manual Keys
The shared secret symmetric keys used to create a VPN can
be any hexadecimal value, so long as both sides of the connection use 
the same values. Since the security of the VPN is based on these keys 
being unguessable, it is very important that the keys be chosen using a
strong random source. One practical method of generating them
is by using the 
.Xr random 4
device. To produce 160 bits of randomness, for example, do a:
.Bd -literal
   dd if=/dev/urandom bs=1024 count=1 | sha1
.Ed
.Pp
Different cipher types may require different sized keys.
.Pp
.Bl -column "Cipher" "Key Length" -compact
.It Em Cipher	Key Length
.It Li DES Ta "56 bits"
.It Li 3DES Ta "168 bits"
.It Li BLF Ta "Variable (160 bits recommended)"
.It Li CAST Ta "Variable (160 bits recommended)"
.It Li SKIPJACK Ta "80 bits"
.El
.Pp
Use of DES or SKIPJACK as an encryption algorithm is not recommended
(except for backwards compatibility) due to their short key length.
Furthermore, recent attacks on SKIPJACK have shown severe weaknesses
in its structure.
.Pp
Note that when using DES (or 3DES), the most significant bit of each
byte is ignored. This means that 8 bytes are required to form a 56-bit
DES key, and 24 bytes are required to form a 168 bit 3DES key.
.Ss Creating Security Associations
Before the IPSec flows can be defined, two Security Associations (SAs)
must be defined on each end of the VPN, e.g.:
.Bd -literal
ipsecadm new esp -spi SPI_OUT -src A_EXTERNAL_IP
         -dst B_EXTERNAL_IP -forcetunnel
         -enc 3des -auth sha1
         -key ENCRYPTION_KEY -authkey AUTHENTICATION_KEY
   
ipsecadm new esp -spi SPI_IN -src B_EXTERNAL_IP
         -dst A_EXTERNAL_IP -forcetunnel
         -enc 3des -auth sha1
         -key ENCRYPTION_KEY -authkey AUTHENTICATION_KEY
.Ed
.Pp
.Ss Creating IPSec Flows
Both IPsec gateways need to configure
.Xr ipsec 4
routes with the 
.Xr ipsecadm 8
tool:
.Pp
On the security gateway of subnet A:
.Bd -literal
ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
         -addr A_EXTERNAL_IP 255.255.255.255
               B_EXTERNAL_IP 255.255.255.255 -local
ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
         -addr A_INTERNAL_NETWORK A_INTERNAL_NETMASK
               B_INTERNAL_NETWORK B_INTERNAL_NETMASK
ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
         -addr A_EXTERNAL_IP 255.255.255.255
               B_INTERNAL_NETWORK B_INTERNAL_NETMASK -local
ipsecadm flow -dst B_EXTERNAL_IP -spi SPI_OUT -proto esp
         -addr A_INTERNAL_NETWORK A_INTERNAL_NETMASK
               B_EXTERNAL_IP 255.255.255.255
.Ed
.Pp
and on the security gateway of subnet B:
.Bd -literal
ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_IN -proto esp
         -addr B_EXTERNAL_IP 255.255.255.255
               A_EXTERNAL_IP 255.255.255.255 -local
ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_IN -proto esp
         -addr B_INTERNAL_NETWORK B_INTERNAL_NETMASK
               A_INTERNAL_NETWORK A_INTERNAL_NETMASK
ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_OUT -proto esp
         -addr B_EXTERNAL_IP 255.255.255.255
               A_INTERNAL_NETWORK A_INTERNAL_NETMASK -local
ipsecadm flow -dst A_EXTERNAL_IP -spi SPI_OUT -proto esp
         -addr B_INTERNAL_NETWORK B_INTERNAL_NETMASK
               A_EXTERNAL_IP 255.255.255.255
.Ed
.Pp
Furthermore, unless manual keying is used, 
both security gateways need to start the
.Xr photurisd 8
key management daemon with the
.Fl v
flag and make sure it is configured properly on both sides to 
provide the required security services (typically, encryption and
authentication).
.Ss Configuring Firewall Rules
.Xr ipf 8
needs to be configured such that all packets from the outside are blocked
by default. Only successfully IPSec-processed packets (from the 
.Nm enc0 
interface), or 
key management packets (for 
.Xr photurisd 8 , 
.Tn UDP
packets with source and destination ports of 468) should be allowed to pass.
.Pp 
The
.Xr ipf 5
rules for a tunnel which uses encryption (the ESP IPsec protocol) and 
.Xr photurisd 8
on security gateway A might look like this:
.Bd -literal
# ed0 is the only interface going to the outside.
block in log on ed0 from any to any
block out log on ed0 from any to any
block in log on enc0 from any to any

# Passing in encrypted traffic from security gateways
pass in proto sipp-esp from gatewB/32 to gatewA/32
pass out proto sipp-esp from gatewA/32 to gatewB/32

# Passing in traffic from the designated subnets.
pass in on enc0 from netB/netBmask to netA/netAmask

# Passing in Photuris traffic from the security gateways
pass in on ed0 proto udp from gatewB/32 port = 468 to gatewA/32 port = 468
pass out on ed0 proto udp from gatewA/32 port = 468 to gatewB/32 port = 468
.Ed
.Pp
If there are no other
.Xr ipf 5
rules, the "quick" clause can be added to the last three rules.
.Sh EXAMPLES
To create a manual keyed VPN between two class C networks using 
3DES encryption and the following IP addresses:
.Pp
.Bd -literal
 A_INTERNAL_IP = 10.0.50.1
 A_EXTERNAL_IP = 192.168.1.254 
 B_EXTERNAL_IP = 192.168.2.1
 B_INTERNAL_IP = 10.0.99.1
.Ed
.Pp
.Bl -enum
.It
Choose the shared secrets using a suitably random method:
.Pp
.Bd -literal
# dd if=/dev/urandom bs=1024 count=1 | sha1
cd28c327c7fd0943596a96cc7bf9108cd896f33c

# dd if=/dev/urandom bs=1024 count=1 | sha1
44aedc8aa8acf0b8c74acd626cd1b1057fb12c76

# dd if=/dev/urandom bs=1024 count=1 | sha1
c9fff55b501206a6607fb45c392c5e1568db2aaf
.Ed
.Pp
.It
Create the Security Associations (on both endpoints):
.Pp
.Bd -literal
# /sbin/ipsecadm new esp -src 198.168.2.1 -dst 198.168.1.254 \e\ 
   -forcetunnel -spi 1000 -enc 3des -auth sha1 \e\ 
   -key 596a96cc7bf9108cd896f33c44aedc8aa8acf0b8c74acd62 \e\ 
   -authkey c9fff55b501206a6607fb45c392c5e1568db2aaf

# /sbin/ipsecadm new esp -src 198.168.1.254 -dst 198.168.2.1  \e\ 
   -forcetunnel -spi 1001 -enc 3des -auth sha1 \e\ 
   -key 596a96cc7bf9108cd896f33c44aedc8aa8acf0b8c74acd62 \e\ 
   -authkey c9fff55b501206a6607fb45c392c5e1568db2aaf
.Ed
.Pp
.It
Create the ipsec route on machine A:
.Pp
.Bd -literal
# /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \e\ 
    -addr 192.168.1.254 255.255.255.255 \e\ 
          192.168.2.1 255.255.255.255 -local

# /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \e\ 
    -addr 10.0.50.0 255.255.255.0 10.0.99.0 255.255.255.0

# /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \e\ 
    -addr 192.168.1.254 255.255.255.255 \e\ 
          10.0.99.0 255.255.255.0 -local

# /sbin/ipsecadm flow -dst 192.168.2.1 -spi 1001 -proto esp \e\ 
    -addr 10.0.50.0 255.255.255.0 192.168.2.1 255.255.255.255
.Ed
.It
Create the ipsec flow on machine B:
.Bd -literal
# /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \e\ 
    -addr 192.168.2.1 255.255.255.255 \e\ 
          192.168.1.254 255.255.255.255 -local

# /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \e\ 
    -addr 10.0.99.0 255.255.255.0 10.0.50.0 255.255.255.0

# /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \e\ 
     -addr 192.168.2.1 255.255.255.255 \e\ 
           10.0.50.0 255.255.255.0 -local

# /sbin/ipsecadm flow -dst 192.168.1.254 -spi 1000 -proto esp \e\ 
     -addr 10.0.99.0 255.255.255.0 192.168.1.254 255.255.255.255
.Ed
.It
Configure the firewall rules on machine A:
.Bd -literal
# ed0 is the only interface going to the outside.
block in log on ed0 from any to any
block out log on ed0 from any to any
block in log on enc0 from any to any

# Passing in encrypted traffic from security gateways
pass in proto sipp-esp from 192.168.2.1/32 to 192.168.1.254/32
pass out proto sipp-esp from 192.168.1.254/32 to 192.168.2.1/32

# Passing in traffic from the designated subnets.
pass in quick on enc0 from 10.0.99.0/24 to 10.0.50.0/24
.Ed
.It
Configure the firewall rules on machine B:
.Bd -literal
# ed0 is the only interface going to the outside.
block in log on ed0 from any to any
block out log on ed0 from any to any
block in log on enc0 from any to any

# Passing in encrypted traffic from security gateways
pass in proto sipp-esp from 192.168.1.254/32 to 192.168.2.1/32
pass out proto sipp-esp from 192.168.2.1/32 to 192.168.1.254/32

# Passing in traffic from the designated subnets.
pass in quick on enc0 from 10.0.50.0/24 to 10.0.99.0/24
.Ed
.El
.Sh FILES
.Bl -tag -width /etc/photuris/photuris.conf -compact
.It Pa /usr/share/ipsec/rc.vpn
Sample VPN configuration file
.It Pa /etc/photuris/photuris.conf
Photuris configuration file
.It Pa /etc/ipf.rules
Firewall configuration file
.El
.Sh BUGS
When using 
.Xr photurisd 8
in VPN mode, both of the security gateways IP addresses must fall within
their protected netranges.
In situations where the gateway IP is outside the desired netrange, such 
as with private networks (RFC 1597), manual keying must be used.
This should be fixed in the next release.
.Sh SEE ALSO
.Xr ipf 8 ,
.Xr ipsecadm 8 ,
.Xr ipsec 4 ,
.Xr isakmpd 8 ,
.Xr options 4 ,
.Xr ipf 5 ,
.Xr photurisd 8