]> git.ipfire.org Git - people/ms/strongswan.git/blame_incremental - README.md
aesni: Implement 256-bit key schedule
[people/ms/strongswan.git] / README.md
... / ...
CommitLineData
1# strongSwan Configuration #
2
3## Overview ##
4
5strongSwan is an OpenSource IPsec-based VPN solution.
6
7This document is just a short introduction, for more detailed information
8consult the man pages and [**our wiki**](http://wiki.strongswan.org).
9
10
11## Quickstart ##
12
13In the following examples we assume, for reasons of clarity, that **left**
14designates the **local** host and that **right** is the **remote** host.
15
16Certificates for users, hosts and gateways are issued by a fictitious
17strongSwan CA. How to generate private keys and certificates using OpenSSL or
18the strongSwan PKI tool will be explained in one of the sections below.
19The CA certificate `strongswanCert.pem` must be present on all VPN endpoints
20in order to be able to authenticate the peers.
21
22
23### Site-to-site case ###
24
25In this scenario two security gateways _moon_ and _sun_ will connect the
26two subnets _moon-net_ and _sun-net_ with each other through a VPN tunnel
27set up between the two gateways:
28
29 10.1.0.0/16 -- | 192.168.0.1 | === | 192.168.0.2 | -- 10.2.0.0/16
30 moon-net moon sun sun-net
31
32Configuration on gateway _moon_:
33
34 /etc/ipsec.d/cacerts/strongswanCert.pem
35
36 /etc/ipsec.d/certs/moonCert.pem
37
38 /etc/ipsec.secrets:
39
40 : RSA moonKey.pem "<optional passphrase>"
41
42 /etc/ipsec.conf:
43
44 conn net-net
45 leftsubnet=10.1.0.0/16
46 leftcert=moonCert.pem
47 right=192.168.0.2
48 rightsubnet=10.2.0.0/16
49 rightid="C=CH, O=strongSwan, CN=sun.strongswan.org"
50 auto=start
51
52Configuration on gateway _sun_:
53
54 /etc/ipsec.d/cacerts/strongswanCert.pem
55
56 /etc/ipsec.d/certs/sunCert.pem
57
58 /etc/ipsec.secrets:
59
60 : RSA sunKey.pem "<optional passphrase>"
61
62 /etc/ipsec.conf:
63
64 conn net-net
65 leftsubnet=10.2.0.0/16
66 leftcert=sunCert.pem
67 right=192.168.0.1
68 rightsubnet=10.1.0.0/16
69 rightid="C=CH, O=strongSwan, CN=moon.strongswan.org"
70 auto=start
71
72
73### Host-to-host case ###
74
75This is a setup between two single hosts which don't have a subnet behind
76them. Although IPsec transport mode would be sufficient for host-to-host
77connections we will use the default IPsec tunnel mode.
78
79 | 192.168.0.1 | === | 192.168.0.2 |
80 moon sun
81
82Configuration on host _moon_:
83
84 /etc/ipsec.d/cacerts/strongswanCert.pem
85
86 /etc/ipsec.d/certs/moonCert.pem
87
88 /etc/ipsec.secrets:
89
90 : RSA moonKey.pem "<optional passphrase>"
91
92 /etc/ipsec.conf:
93
94 conn host-host
95 leftcert=moonCert.pem
96 right=192.168.0.2
97 rightid="C=CH, O=strongSwan, CN=sun.strongswan.org"
98 auto=start
99
100Configuration on host _sun_:
101
102 /etc/ipsec.d/cacerts/strongswanCert.pem
103
104 /etc/ipsec.d/certs/sunCert.pem
105
106 /etc/ipsec.secrets:
107
108 : RSA sunKey.pem "<optional passphrase>"
109
110 /etc/ipsec.conf:
111
112 conn host-host
113 leftcert=sunCert.pem
114 right=192.168.0.1
115 rightid="C=CH, O=strongSwan, CN=moon.strongswan.org"
116 auto=start
117
118
119### Roadwarrior case ###
120
121This is a very common case where a strongSwan gateway serves an arbitrary
122number of remote VPN clients usually having dynamic IP addresses.
123
124 10.1.0.0/16 -- | 192.168.0.1 | === | x.x.x.x |
125 moon-net moon carol
126
127Configuration on gateway _moon_:
128
129 /etc/ipsec.d/cacerts/strongswanCert.pem
130
131 /etc/ipsec.d/certs/moonCert.pem
132
133 /etc/ipsec.secrets:
134
135 : RSA moonKey.pem "<optional passphrase>"
136
137 /etc/ipsec.conf:
138
139 conn rw
140 leftsubnet=10.1.0.0/16
141 leftcert=moonCert.pem
142 right=%any
143 auto=add
144
145Configuration on roadwarrior _carol_:
146
147 /etc/ipsec.d/cacerts/strongswanCert.pem
148
149 /etc/ipsec.d/certs/carolCert.pem
150
151 /etc/ipsec.secrets:
152
153 : RSA carolKey.pem "<optional passphrase>"
154
155 /etc/ipsec.conf:
156
157 conn home
158 leftcert=carolCert.pem
159 right=192.168.0.1
160 rightsubnet=10.1.0.0/16
161 rightid="C=CH, O=strongSwan, CN=moon.strongswan.org"
162 auto=start
163
164
165### Roadwarrior case with virtual IP ###
166
167Roadwarriors usually have dynamic IP addresses assigned by the ISP they are
168currently attached to. In order to simplify the routing from _moon-net_ back
169to the remote access client _carol_ it would be desirable if the roadwarrior had
170an inner IP address chosen from a pre-defined pool.
171
172 10.1.0.0/16 -- | 192.168.0.1 | === | x.x.x.x | -- 10.3.0.1
173 moon-net moon carol virtual IP
174
175In our example the virtual IP address is chosen from the address pool
176`10.3.0.0/16` which can be configured by adding the parameter
177
178 rightsourceip=10.3.0.0/16
179
180to the gateway's `ipsec.conf`. To request an IP address from this pool a
181roadwarrior can use IKEv1 mode config or IKEv2 configuration payloads.
182The configuration for both is the same
183
184 leftsourceip=%config
185
186Configuration on gateway _moon_:
187
188 /etc/ipsec.d/cacerts/strongswanCert.pem
189
190 /etc/ipsec.d/certs/moonCert.pem
191
192 /etc/ipsec.secrets:
193
194 : RSA moonKey.pem "<optional passphrase>"
195
196 /etc/ipsec.conf:
197
198 conn rw
199 leftsubnet=10.1.0.0/16
200 leftcert=moonCert.pem
201 right=%any
202 rightsourceip=10.3.0.0/16
203 auto=add
204
205Configuration on roadwarrior _carol_:
206
207 /etc/ipsec.d/cacerts/strongswanCert.pem
208
209 /etc/ipsec.d/certs/carolCert.pem
210
211 /etc/ipsec.secrets:
212
213 : RSA carolKey.pem "<optional passphrase>"
214
215 /etc/ipsec.conf:
216
217 conn home
218 leftsourceip=%config
219 leftcert=carolCert.pem
220 right=192.168.0.1
221 rightsubnet=10.1.0.0/16
222 rightid="C=CH, O=strongSwan, CN=moon.strongswan.org"
223 auto=start
224
225
226## Generating certificates and CRLs ##
227
228This section is not a full-blown tutorial on how to use OpenSSL or the
229strongSwan PKI tool. It just lists a few points that are relevant if you want
230to generate your own certificates and CRLs for use with strongSwan.
231
232
233### Generating a CA certificate ###
234
235The OpenSSL statement
236
237 openssl req -x509 -days 1460 -newkey rsa:4096 \
238 -keyout strongswanKey.pem -out strongswanCert.pem
239
240creates a 4096 bit RSA private key `strongswanKey.pem` and a self-signed CA
241certificate `strongswanCert.pem` with a validity of 4 years (1460 days).
242
243 openssl x509 -in cert.pem -noout -text
244
245lists the properties of a X.509 certificate `cert.pem`. It allows you to verify
246whether the configuration defaults in `openssl.cnf` have been inserted
247correctly.
248
249If you prefer the CA certificate to be in binary DER format then the following
250command achieves this transformation:
251
252 openssl x509 -in strongswanCert.pem -outform DER -out strongswanCert.der
253
254The statements
255
256 ipsec pki --gen -s 4096 > strongswanKey.der
257 ipsec pki --self --ca --lifetime 1460 --in strongswanKey.der \
258 --dn "C=CH, O=strongSwan, CN=strongSwan Root CA" \
259 > strongswanCert.der
260 ipsec pki --print --in strongswanCert.der
261
262achieve about the same with the strongSwan PKI tool. Unlike OpenSSL the tool
263stores keys and certificates in the binary DER format by default.
264The `--outform` option may be used to write PEM encoded files.
265
266The directory `/etc/ipsec.d/cacerts` contains all required CA certificates
267either in binary DER or in Base64 PEM format, irrespective of the file suffix
268the correct format will be determined.
269
270
271### Generating a host or user certificate ###
272
273The OpenSSL statement
274
275 openssl req -newkey rsa:2048 -keyout hostKey.pem \
276 -out hostReq.pem
277
278generates a 2048 bit RSA private key `hostKey.pem` and a certificate request
279`hostReq.pem` which has to be signed by the CA.
280
281If you want to add a _subjectAltName_ field to the host certificate you must
282edit the OpenSSL configuration file `openssl.cnf` and add the following line in
283the `[ usr_cert ]` section:
284
285 subjectAltName=DNS:moon.strongswan.org
286
287if you want to identify the host by its Fully Qualified Domain Name (FQDN), or
288
289 subjectAltName=IP:192.168.0.1
290
291if you want the ID to be of type _IPV4_ADDR_. Of course you could include both
292ID types with
293
294 subjectAltName=DNS:moon.strongswan.org,IP:192.168.0.1
295
296but the use of an IP address for the identification of a host should be
297discouraged anyway.
298
299For user certificates the appropriate ID type is _RFC822_ADDR_ which can be
300specified as
301
302 subjectAltName=email:carol@strongswan.org
303
304or if the user's e-mail address is part of the subject's distinguished name
305
306 subjectAltName=email:copy
307
308Now the certificate request can be signed by the CA with the command
309
310 openssl ca -in hostReq.pem -days 730 -out hostCert.pem -notext
311
312If you omit the `-days` option then the `default_days` value (365 days)
313specified in `openssl.cnf` is used. The `-notext` option avoids that a human
314readable listing of the certificate is prepended to the Base64 encoded
315certificate body.
316
317If you want to use the dynamic CRL fetching feature described in one of the
318following sections then you may include one or several _crlDistributionPoints_
319in your end certificates. This can be done in the `[ usr_cert ]` section of the
320`openssl.cnf` configuration file:
321
322 crlDistributionPoints=@crl_dp
323
324 [ crl_dp ]
325
326 URI.1="http://crl.strongswan.org/strongswan.crl"
327 URI.2="ldap://ldap.strongswan.org/cn=strongSwan Root CA, o=strongSwan,
328 c=CH?certificateRevocationList"
329
330If you have only a single HTTP distribution point then the short form
331
332 crlDistributionPoints="URI:http://crl.strongswan.org/strongswan.crl"
333
334also works.
335
336Again the statements
337
338 ipsec pki --gen > moonKey.der
339 ipsec pki --pub --in moonKey.der | ipsec pki --issue --lifetime 730 \
340 --cacert strongswanCert.der --cakey strongswanKey.der \
341 --dn "C=CH, O=strongSwan, CN=moon.strongswan.org" \
342 --san moon.strongswan.org --san 192.168.0.1 \
343 --crl http://crl.strongswan.org/strongswan.crl > moonCert.der
344
345do something similar using the strongSwan PKI tool.
346
347Usually, a Windows or Mac OS X (or iOS) based VPN client needs its private key,
348its host or user certificate, and the CA certificate. The most convenient way
349to load this information is to put everything into a PKCS#12 container:
350
351 openssl pkcs12 -export -inkey carolKey.pem \
352 -in carolCert.pem -name "carol" \
353 -certfile strongswanCert.pem -caname "strongSwan Root CA" \
354 -out carolCert.p12
355
356
357### Generating a CRL ###
358
359An empty CRL that is signed by the CA can be generated with the command
360
361 openssl ca -gencrl -crldays 15 -out crl.pem
362
363If you omit the `-crldays` option then the `default_crl_days` value (30 days)
364specified in `openssl.cnf` is used.
365
366If you prefer the CRL to be in binary DER format then this conversion
367can be achieved with
368
369 openssl crl -in crl.pem -outform DER -out cert.crl
370
371The strongSwan PKI tool provides the `--signcrl` command to sign CRLs.
372
373The directory `/etc/ipsec.d/crls` contains all CRLs either in binary DER
374or in Base64 PEM format, irrespective of the file suffix the correct format
375will be determined.
376
377
378### Revoking a certificate ###
379
380A specific host certificate stored in the file `host.pem` is revoked with the
381command
382
383 openssl ca -revoke host.pem
384
385Next the CRL file must be updated
386
387 openssl ca -gencrl -crldays 60 -out crl.pem
388
389The content of the CRL file can be listed with the command
390
391 openssl crl -in crl.pem -noout -text
392
393in the case of a Base64 CRL, or alternatively for a CRL in DER format
394
395 openssl crl -inform DER -in cert.crl -noout -text
396
397Again the `--signcrl` command of the strongSwan PKI tool may also be used to
398create new CRLs containing additional certificates.
399
400
401## Configuring the connections - ipsec.conf ##
402
403### Configuring my side ###
404
405Usually the **local** side is the same for all connections. Therefore it makes
406sense to put the definitions characterizing the strongSwan security gateway into
407the `conn %default` section of the configuration file `/etc/ipsec.conf`. If we
408assume throughout this document that the strongSwan security gateway is **left**
409and the peer is **right** then we can write
410
411 conn %default
412 leftcert=moonCert.pem
413 # load connection definitions automatically
414 auto=add
415
416The X.509 certificate by which the strongSwan security gateway will authenticate
417itself by sending it in binary form to its peers as part of the Internet Key
418Exchange (IKE) is specified in the line
419
420 leftcert=moonCert.pem
421
422The certificate can either be stored in Base64 PEM-format or in the binary
423DER-format. Irrespective of the file suffix the correct format will be
424determined. Therefore `leftcert=moonCert.der` or `leftcert=moonCert.cer`
425would also be valid alternatives.
426
427When using relative pathnames as in the examples above, the certificate files
428must be stored in in the directory `/etc/ipsec.d/certs`. In order to
429distinguish strongSwan's own certificates from locally stored trusted peer
430certificates (see below for details), they could also be stored in a
431subdirectory below `/etc/ipsec.d/certs` as e.g. in
432
433 leftcert=mycerts/moonCert.pem
434
435Absolute pathnames are also possible as in
436
437 leftcert=/usr/ssl/certs/moonCert.pem
438
439As an ID for the VPN gateway we recommend the use of a Fully Qualified Domain
440Name (FQDN) of the form
441
442 conn rw
443 right=%any
444 leftid=moon.strongswan.org
445
446**Important**: When a FQDN identifier is used it must be explicitly included as
447a so called _subjectAltName_ of type _dnsName_ (`DNS:`) in the certificate
448indicated by `leftcert`. For details on how to generate certificates with
449_subjectAltNames_, please refer to the sections above.
450
451If you don't want to mess with _subjectAltNames_, you can use the certificate's
452Distinguished Name (DN) instead, which is an identifier of type _DER_ASN1_DN_
453and which can be written e.g. in the LDAP-type format
454
455 conn rw
456 right=%any
457 leftid="C=CH, O=strongSwan, CN=moon.strongswan.org"
458
459Since the subject's DN is part of the certificate, the `leftid` does not have to
460be declared explicitly. Thus the entry
461
462 conn rw
463 right=%any
464
465automatically assumes the subject DN of `leftcert` to be the host ID.
466
467
468### Multiple certificates ###
469
470strongSwan supports multiple local host certificates and corresponding
471RSA private keys:
472
473 conn rw1
474 right=%any
475 rightid=peer1.domain1
476 leftcert=myCert1.pem
477 # leftid is DN of myCert1
478
479 conn rw2
480 right=%any
481 rightid=peer2.domain2
482 leftcert=myCert2.pem
483 # leftid is DN of myCert2
484
485When _peer1_ initiates a connection then strongSwan will send _myCert1_ and will
486sign with _myKey1_ defined in `/etc/ipsec.secrets` (see below) whereas
487_myCert2_ and _myKey2_ will be used in a connection setup started from _peer2_.
488
489
490### Configuring the peer side using CA certificates ###
491
492Now we can proceed to define our connections. In many applications we might
493have dozens of road warriors connecting to a central strongSwan security
494gateway. The following most simple statement:
495
496 conn rw
497 right=%any
498
499defines the general roadwarrior case. The line `right=%any` literally means
500that any IPsec peer is accepted, regardless of its current IP source address and
501its ID, as long as the peer presents a valid X.509 certificate signed by a CA
502the strongSwan security gateway puts explicit trust in. Additionally, the
503signature during IKE gives proof that the peer is in possession of the private
504key matching the public key contained in the transmitted certificate.
505
506The ID by which a peer is identifying itself during IKE can by any of the ID
507types _IPV[46]_ADDR_, _FQDN_, _RFC822_ADDR_ or _DER_ASN1_DN_. If one of the
508first three ID types is used, then the accompanying X.509 certificate of the
509peer must contain a matching _subjectAltName_ field of the type _ipAddress_
510(`IP:`), _dnsName_ (`DNS:`) or _rfc822Name_ (`email:`), respectively. With the
511fourth type, _DER_ASN1_DN_, the identifier must completely match the subject
512field of the peer's certificate. One of the two possible representations of a
513Distinguished Name (DN) is the LDAP-type format
514
515 rightid="C=CH, O=strongSwan IPsec, CN=sun.strongswan.org"
516
517Additional whitespace can be added everywhere as desired since it will be
518automatically eliminated by the parser. An exception is the single whitespace
519between individual words, like e.g. in `strongSwan IPsec`, which is preserved.
520
521The Relative Distinguished Names (RDNs) can alternatively be separated by a
522slash `/` instead of a comma `,`
523
524 rightid="/C=CH/O=strongSwan IPsec/CN=sun.strongswan.org"
525
526This is the representation extracted from the certificate by the OpenSSL
527`-subject` command line option
528
529 openssl x509 -in sunCert.pem -noout -subject
530
531The following RDNs are supported by strongSwan
532
533| Name | Description |
534|--------------------|----------------------------------|
535| DC | Domain Component |
536| C | Country |
537| ST | State or province |
538| L | Locality or town |
539| O | Organization |
540| OU | Organizational Unit |
541| CN | Common Name |
542| ND | NameDistinguisher, used with CN |
543| N | Name |
544| G | Given name |
545| S | Surname |
546| I | Initials |
547| T | Personal title |
548| E | E-mail |
549| Email | E-mail |
550| emailAddress | E-mail |
551| SN | Serial number |
552| serialNumber | Serial number |
553| D | Description |
554| ID | X.500 Unique Identifier |
555| UID | User ID |
556| TCGID | [Siemens] Trust Center Global ID |
557| UN | Unstructured Name |
558| unstructuredName | Unstructured Name |
559| UA | Unstructured Address |
560| unstructuredAddress| Unstructured Address |
561| EN | Employee Number |
562| employeeNumber | Employee Number |
563| dnQualifier | DN Qualifier |
564
565With the roadwarrior connection definition listed above, an IPsec SA for
566the strongSwan security gateway `moon.strongswan.org` itself can be established.
567If the roadwarriors should be able to reach e.g. the two subnets `10.1.0.0/24`
568and `10.1.3.0/24` behind the security gateway then the following connection
569definitions will make this possible
570
571 conn rw1
572 right=%any
573 leftsubnet=10.1.0.0/24
574
575 conn rw3
576 right=%any
577 leftsubnet=10.1.3.0/24
578
579For IKEv2 connections this can even be simplified by using
580
581 leftsubnet=10.1.0.0/24,10.1.3.0/24
582
583If not all peers in possession of a X.509 certificate signed by a specific
584certificate authority shall be given access to the Linux security gateway,
585then either a subset of them can be barred by listing the serial numbers of
586their certificates in a certificate revocation list (CRL) or as an alternative,
587access can be controlled by explicitly putting a roadwarrior entry for each
588eligible peer into `ipsec.conf`:
589
590 conn sun
591 right=%any
592 rightid=sun.strongswan.org
593
594 conn carol
595 right=%any
596 rightid=carol@strongswan.org
597
598 conn dave
599 right=%any
600 rightid="C=CH, O=strongSwan, CN=dave@strongswan.org"
601
602When the IP address of a peer is known to be stable, it can be specified as
603well. This entry is mandatory when the strongSwan host wants to act as the
604initiator of an IPsec connection.
605
606 conn sun
607 right=192.168.0.2
608 rightid=sun.strongswan.org
609
610 conn carol
611 right=192.168.0.100
612 rightid=carol@strongswan.org
613
614 conn dave
615 right=192.168.0.200
616 rightid="C=CH, O=strongSwan, CN=dave@strongswan.org"
617
618 conn venus
619 right=192.168.0.50
620
621In the last example the ID types _FQDN_, _RFC822_ADDR_, _DER_ASN1_DN_ and
622_IPV4_ADDR_, respectively, were used. Of course all connection definitions
623presented so far have included the lines in the `conn %defaults` section,
624comprising among other a `leftcert` entry.
625
626
627### Handling Virtual IPs and narrowing ###
628
629Often roadwarriors are behind NAT-boxes, which causes the inner IP source
630address of an IPsec tunnel to be different from the outer IP source address
631usually assigned dynamically by the ISP. Whereas the varying outer IP address
632can be handled by the `right=%any` construct, the inner IP address or subnet
633must always be declared in a connection definition. Therefore for the three
634roadwarriors _rw1_ to _rw3_ connecting to a strongSwan security gateway the
635following entries are required in `/etc/ipsec.conf`:
636
637 conn rw1
638 right=%any
639 righsubnet=10.4.0.5/32
640
641 conn rw2
642 right=%any
643 rightsubnet=10.4.0.47/32
644
645 conn rw3
646 right=%any
647 rightsubnet=10.4.0.128/28
648
649Because the charon daemon uses narrowing (even for IKEv1) these three entries
650can be reduced to the single connection definition
651
652 conn rw
653 right=%any
654 rightsubnet=10.4.0.0/24
655
656Any host will be accepted (of course after successful authentication based on
657the peer's X.509 certificate only) if it declares a client subnet lying totally
658within the boundaries defined by the subnet definition (in our example
659`10.4.0.0/24`).
660
661This strongSwan feature can also be helpful with VPN clients getting a
662dynamically assigned inner IP from a DHCP server located on the NAT router box.
663
664Since the private IP address of roadwarriors will often not be known they are
665usually assigned virtual IPs from a predefined pool. This also makes routing
666traffic back to the roadwarriors easier. For example, to assign each client an
667IP address from the `10.5.0.0/24` subnet `conn rw` can be defined as
668
669 conn rw
670 right=%any
671 rightsourceip=10.5.0.0/24
672
673
674### Protocol and Port Selectors ###
675
676strongSwan offers the possibility to restrict the protocol and optionally the
677ports in an IPsec SA using the `rightprotoport` and `leftprotoport` parameters.
678For IKEv2 multiple such restrictions can also be configured in
679`leftsubnet` and `rightsubnet`.
680
681Some examples:
682
683 conn icmp
684 right=%any
685 rightprotoport=icmp
686 leftid=moon.strongswan.org
687 leftprotoport=icmp
688
689 conn http
690 right=%any
691 rightprotoport=6
692 leftid=moon.strongswan.org
693 leftprotoport=6/80
694
695 conn l2tp
696 right=%any
697 # with port wildcard for interoperability with certain L2TP clients
698 rightprotoport=17/%any
699 leftid=moon.strongswan.org
700 leftprotoport=17/1701
701
702 conn dhcp
703 right=%any
704 rightprotoport=udp/bootpc
705 leftid=moon.strongswan.org
706 leftsubnet=0.0.0.0/0 #allows DHCP discovery broadcast
707 leftprotoport=udp/bootps
708
709Protocols and ports can be designated either by their numerical values
710or by their acronyms defined in `/etc/services`.
711
712Based on the protocol and port selectors appropriate policies will be set
713up, so that only the specified payload types will pass through the IPsec
714tunnel.
715
716
717### IPsec policies based on wildcards ###
718
719In large VPN-based remote access networks there is often a requirement that
720access to the various parts of an internal network must be granted selectively,
721e.g. depending on the group membership of the remote access user. strongSwan
722makes this possible by applying wildcard filtering on the VPN user's
723distinguished name (_ID_DER_ASN1_DN_).
724
725Let's make a practical example:
726
727An organization has a sales department (_OU=Sales_) and a research group
728(_OU=Research_). In the company intranet there are separate subnets for Sales
729(`10.0.0.0/24`) and Research (`10.0.1.0/24`) but both groups share a common web
730server (`10.0.2.100`). The VPN clients use Virtual IP addresses that are either
731assigned statically or from a dynamic pool. The sales and research departments
732use IP addresses from separate address pools (`10.1.0.0/24`) and
733(`10.1.1.0/24`), respectively. An X.509 certificate is issued to each employee,
734containing in its subject distinguished name the country (_C=CH_), the company
735(_O=ACME_), the group membership (_OU=Sales_ or _OU=Research_) and the common
736name (e.g. _CN=Bart Simpson_).
737
738The IPsec policy defined above can now be enforced with the following three
739IPsec security associations:
740
741 conn sales
742 right=%any
743 rightid="C=CH, O=ACME, OU=Sales, CN=*"
744 rightsourceip=10.1.0.0/24 # Sales IP range
745 leftsubnet=10.0.0.0/24 # Sales subnet
746
747 conn research
748 right=%any
749 rightid="C=CH, O=ACME, OU=Research, CN=*"
750 rightsourceip=10.1.1.0/24 # Research IP range
751 leftsubnet=10.0.1.0/24 # Research subnet
752
753 conn web
754 right=%any
755 rightid="C=CH, O=ACME, OU=*, CN=*"
756 rightsubnet=10.1.0.0/23 # Remote access IP range
757 leftsubnet=10.0.2.100/32 # Web server
758 rightprotoport=tcp # TCP protocol only
759 leftprotoport=tcp/http # TCP port 80 only
760
761The `*` character is used as a wildcard in relative distinguished names (RDNs).
762In order to match a wildcard template, the _ID_DER_ASN1_DN_ of a peer must
763contain the same number of RDNs (selected from the list given earlier) appearing
764in the exact order defined by the template.
765
766 "C=CH, O=ACME, OU=Research, OU=Special Effects, CN=Bart Simpson"
767
768matches the templates
769
770 "C=CH, O=ACME, OU=Research, OU=*, CN=*"
771 "C=CH, O=ACME, OU=*, OU=Special Effects, CN=*"
772 "C=CH, O=ACME, OU=*, OU=*, CN=*"
773
774but not the template
775
776 "C=CH, O=ACME, OU=*, CN=*"
777
778which doesn't have the same number of RDNs.
779
780
781### IPsec policies based on CA certificates ###
782
783As an alternative to the wildcard based IPsec policies described above, access
784to specific client host and subnets can be controlled on the basis of the CA
785that issued the peer certificate
786
787 conn sales
788 right=%any
789 rightca="C=CH, O=ACME, OU=Sales, CN=Sales CA"
790 rightsourceip=10.1.0.0/24 # Sales IP range
791 leftsubnet=10.0.0.0/24 # Sales subnet
792
793 conn research
794 right=%any
795 rightca="C=CH, O=ACME, OU=Research, CN=Research CA"
796 rightsourceip=10.1.1.0/24 # Research IP range
797 leftsubnet=10.0.1.0/24 # Research subnet
798
799 conn web
800 right=%any
801 rightca="C=CH, O=ACME, CN=ACME Root CA"
802 rightsubnet=10.1.0.0/23 # Remote access IP range
803 leftsubnet=10.0.2.100/32 # Web server
804 rightprotoport=tcp # TCP protocol only
805 leftprotoport=tcp/http # TCP port 80 only
806
807In the example above, the connection _sales_ can be used by peers
808presenting certificates issued by the Sales CA, only. In the same way,
809the use of the connection _research_ is restricted to owners of certificates
810issued by the Research CA. The connection _web_ is open to both "Sales" and
811"Research" peers because the required _ACME Root CA_ is the issuer of the
812Research and Sales intermediate CAs. If no `rightca` parameter is present
813then any valid certificate issued by one of the trusted CAs in
814`/etc/ipsec.d/cacerts` can be used by the peer.
815
816The `leftca` parameter usually doesn't have to be set explicitly because
817by default it is set to the issuer field of the certificate loaded via
818`leftcert`. The statement
819
820 rightca=%same
821
822sets the CA requested from the peer to the CA used by the left side itself
823as e.g. in
824
825 conn sales
826 right=%any
827 rightca=%same
828 leftcert=mySalesCert.pem
829
830
831## Configuring certificates and CRLs ##
832
833
834### Installing the CA certificates ###
835
836X.509 certificates received by strongSwan during the IKE protocol are
837automatically authenticated by going up the trust chain until a self-signed
838root CA certificate is reached. Usually host certificates are directly signed
839by a root CA, but strongSwan also supports multi-level hierarchies with
840intermediate CAs in between. All CA certificates belonging to a trust chain
841must be copied in either binary DER or Base64 PEM format into the directory
842
843 /etc/ipsec.d/cacerts/
844
845
846### Installing optional certificate revocation lists (CRLs) ###
847
848By copying a CA certificate into `/etc/ipsec.d/cacerts/`, automatically all user
849or host certificates issued by this CA are declared valid. Unfortunately,
850private keys might get compromised inadvertently or intentionally, personal
851certificates of users leaving a company have to be blocked immediately, etc.
852To this purpose certificate revocation lists (CRLs) have been created. CRLs
853contain the serial numbers of all user or host certificates that have been
854revoked due to various reasons.
855
856After successful verification of the X.509 trust chain, strongSwan searches its
857list of CRLs, either obtained by loading them from the `/etc/ipsec.d/crls/`
858directory, or fetching them dynamically from a HTTP or LDAP server, for the
859presence of a CRL issued by the CA that has signed the certificate.
860
861If the serial number of the certificate is found in the CRL then the public key
862contained in the certificate is declared invalid and the IKE SA will not be
863established. If no CRL is found or if the deadline defined in the _nextUpdate_
864field of the CRL has been reached, a warning is issued but the public key will
865nevertheless be accepted (this behavior can be changed, see below). CRLs must
866be stored either in binary DER or Base64 PEM format in the `crls` directory.
867
868
869### Dynamic update of certificates and CRLs ###
870
871strongSwan reads certificates and CRLs from their respective files during system
872startup and keeps them in memory. X.509 certificates have a finite life span
873defined by their validity field. Therefore it must be possible to replace CA or
874OCSP certificates kept in system memory without disturbing established IKE SAs.
875Certificate revocation lists should also be updated in the regular intervals
876indicated by the _nextUpdate_ field in the CRL body. The following interactive
877commands allow the manual replacement of the various files:
878
879
880| Command | Action |
881|-------------------------|-------------------------------------------------|
882| ipsec rereadaacerts | reload all files in `/etc/ipsec.d/aacerts/` |
883| ipsec rereadacerts | reload all files in `/etc/ipsec.d/acerts/` |
884| ipsec rereadcacerts | reload all files in `/etc/ipsec.d/cacerts/` |
885| ipsec rereadcrls | reload all files in `/etc/ipsec.d/crls/` |
886| ipsec rereadocspcerts | reload all files in `/etc/ipsec.d/ocspcerts/` |
887| ipsec rereadsecrets | reload `/etc/ipsec.secrets` and configured keys |
888| ipsec rereadall | all the commands above combined |
889| ipsec purgecerts | purge all cached certificates |
890| ipsec purgecrl | purge all cached CRLs |
891| ipsec purgeocsp | purge the OCSP cache |
892
893
894CRLs can also be automatically fetched from an HTTP or LDAP server by using
895the CRL distribution points contained in X.509 certificates.
896
897
898### Local caching of CRLs ###
899
900The `ipsec.conf` option
901
902 config setup
903 cachecrls=yes
904
905activates the local caching of CRLs that were dynamically fetched from an
906HTTP or LDAP server. Cached copies are stored in `/etc/ipsec.d/crls` using a
907unique filename formed from the issuer's _subjectKeyIdentifier_ and the
908suffix `.crl`.
909
910With the cached copy the CRL is immediately available after startup. When the
911local copy is about to expire it is automatically replaced with an updated CRL
912fetched from one of the defined CRL distribution points.
913
914
915### Online Certificate Status Protocol (OCSP) ###
916
917The _Online Certificate Status Protocol_ is defined by RFC 2560. It can be
918used to query an OCSP server about the current status of an X.509 certificate
919and is often used as a more dynamic alternative to a static Certificate
920Revocation List (CRL). Both the OCSP request sent by the client and the OCSP
921response messages returned by the server are transported via a standard
922TCP/HTTP connection.
923
924In the simplest OCSP setup, a default URI under which the OCSP server for a
925given CA can be accessed is defined in `ipsec.conf`:
926
927 ca strongswan
928 cacert=strongswanCert.pem
929 ocspuri=http://ocsp.strongswan.org:8880
930 auto=add
931
932The HTTP port can be freely chosen.
933
934OpenSSL implements an OCSP server that can be used in conjunction with an
935OpenSSL-based Public Key Infrastructure. The OCSP server is started with the
936following command:
937
938 openssl ocsp -index index.txt -CA strongswanCert.pem -port 8880 \
939 -rkey ocspKey.pem -rsigner ocspCert.pem \
940 -resp_no_certs -nmin 60 -text
941
942The command consists of the parameters
943
944 -index index.txt is a copy of the OpenSSL index file containing the list
945 of all issued certificates. The certificate status in index.txt
946 is designated either by V for valid or R for revoked. If a new
947 certificate is added or if a certificate is revoked using the
948 openssl ca command, the OCSP server must be restarted in order for
949 the changes in index.txt to take effect.
950
951 -CA the CA certificate
952
953 -port the HTTP port the OCSP server is listening on.
954
955 -rkey the private key used to sign the OCSP response. The use of the
956 sensitive CA private key is not recommended since this could
957 jeopardize the security of your production PKI if the OCSP
958 server is hacked. It is much better to generate a special
959 RSA private key just for OCSP signing use instead.
960
961 -rsigner the certificate of the OCSP server containing a public key which
962 matches the private key defined by -rkey and which can be used by
963 the client to check the trustworthiness of the signed OCSP
964 response.
965
966 -resp_no_certs With this option the OCSP signer certificate defined by
967 -rsigner is not included in the OCSP response.
968
969 -nmin the validity interval of an OCSP response given in minutes.
970
971 -text this option activates a verbose logging output, showing the
972 contents of both the received OCSP request and sent OCSP response.
973
974
975The OCSP signer certificate can either be put into the default directory
976
977 /etc/ipsec.d/ocspcerts
978
979or alternatively strongSwan can receive it as part of the OCSP response from the
980remote OCSP server. In order to verify that the server is indeed authorized by
981a CA to deal out certificate status information an extended key usage attribute
982must be included in the OCSP server certificate. Just insert the parameter
983
984 extendedKeyUsage=OCSPSigner
985
986in the `[ usr_cert ]` section of your `openssl.cnf` configuration file before
987the CA signs the OCSP server certificate.
988
989For a given CA the corresponding _ca_ section in `ipsec.conf` (see below) allows
990to define the URI of a single OCSP server. As an alternative an OCSP URI can be
991embedded into each host and user certificate by putting the line
992
993 authorityInfoAccess = OCSP;URI:http://ocsp.strongswan.org:8880
994
995into the `[ usr_cert ]` section of your `openssl.cnf` configuration file.
996If an OCSP _authorityInfoAccess_ extension is present in a certificate then this
997record overrides the default URI defined by the ca section.
998
999
1000### CRL Policy ###
1001
1002By default strongSwan is quite tolerant concerning the handling of CRLs. It is
1003not mandatory for a CRL to be present in `/etc/ipsec.d/crls` and if the
1004expiration date defined by the _nextUpdate_ field of a CRL has been reached just
1005a warning is issued but a peer certificate will always be accepted if it has not
1006been revoked.
1007
1008If you want to enforce a stricter CRL policy then you can do this by setting
1009the `strictcrlpolicy` option. This is done in the `config setup` section
1010of the `ipsec.conf` file:
1011
1012 config setup
1013 strictcrlpolicy=yes
1014 ...
1015
1016A certificate received from a peer will not be accepted if no corresponding
1017CRL or OCSP response is available. And if an IKE SA re-negotiation takes
1018place after the _nextUpdate_ deadline has been reached, the peer certificate
1019will be declared invalid and the cached public key will be deleted, causing
1020the connection in question to fail. Therefore if you are going to use the
1021`strictcrlpolicy=yes` option, make sure that the CRLs will always be updated
1022in time. Otherwise a total standstill might ensue.
1023
1024As mentioned earlier the default setting is `strictcrlpolicy=no`.
1025
1026
1027### Configuring the peer side using locally stored certificates ###
1028
1029If you don't want to use trust chains based on CA certificates as proposed above
1030you can alternatively import trusted peer certificates directly.
1031
1032With the `conn %default` section defined above and the use of the `rightcert`
1033keyword for the peer side, the connection definitions presented earlier can
1034alternatively be written as
1035
1036 conn sun
1037 right=%any
1038 rightid=sun.strongswan.org
1039 rightcert=sunCert.cer
1040
1041 conn carol
1042 right=192.168.0.100
1043 rightcert=carolCert.der
1044
1045If the peer certificates are loaded locally then there is no need to send any
1046certificates to the other end via the IKE protocol. Especially if self-signed
1047certificates are used which wouldn't be accepted anyway by the other side.
1048In these cases it is recommended to add
1049
1050 leftsendcert=never
1051
1052to the connection definition(s) in order to avoid the sending of the host's
1053own certificate. The default value is
1054
1055 leftsendcert=ifasked
1056
1057which causes certificates to only be sent if a certificate request is received.
1058If a peer does not send a certificate request then the setting
1059
1060 leftsendcert=always
1061
1062may be used to force sending of the certificate to the other peer.
1063
1064If a peer certificate contains a _subjectAltName_ extension, then an alternative
1065`rightid` type can be used, as the example `conn sun` shows. If no `rightid`
1066entry is present then the subject distinguished name contained in the
1067certificate is taken as the ID.
1068
1069Using the same rules concerning pathnames that apply to the gateway's own
1070certificates, the following two definitions are also valid for trusted peer
1071certificates:
1072
1073 rightcert=peercerts/carolCert.der
1074
1075or
1076
1077 rightcert=/usr/ssl/certs/carolCert.der
1078
1079
1080## Configuring the private keys - ipsec.secrets ##
1081
1082
1083### Loading private key files ###
1084
1085strongSwan is able to load RSA (or ECDSA) private keys in the PKCS#1 or PKCS#8
1086file formats, or from PKCS#12 containers. The key files can optionally be
1087secured with a passphrase.
1088
1089RSA private key files are declared in `/etc/ipsec.secrets` using the syntax
1090
1091 : RSA <my keyfile> "<optional passphrase>"
1092
1093The key file can be either in Base64 PEM-format or binary DER-format. The
1094actual coding is detected automatically. The example
1095
1096 : RSA moonKey.pem
1097
1098uses a pathname relative to the default directory
1099
1100 /etc/ipsec.d/private
1101
1102As an alternative an absolute pathname can be given as in
1103
1104 : RSA /usr/ssl/private/moonKey.pem
1105
1106In both cases make sure that the key files are root readable only.
1107
1108Often a private key must be transported from the Certification Authority
1109where it was generated to the target security gateway where it is going
1110to be used. In order to protect the key it can be encrypted with a symmetric
1111cipher using a transport key derived from a cryptographically strong
1112passphrase.
1113
1114Once on the security gateway the private key can either be permanently
1115unlocked so that it can be used by the IKE daemon without having to know a
1116passphrase
1117
1118 openssl rsa -in moonKey.pem -out moonKey.pem
1119
1120or as an option the key file can remain secured. In this case the passphrase
1121unlocking the private key must be added after the pathname in
1122`/etc/ipsec.secrets`
1123
1124 : RSA moonKey.pem "This is my passphrase"
1125
1126Some CAs distribute private keys embedded in a PKCS#12 file. strongSwan can read
1127private keys directly from such a file (end-entity and CA certificates are
1128also extracted):
1129
1130 : P12 moonCert.p12 "This is my passphrase"
1131
1132
1133### Entering passphrases interactively ###
1134
1135On a VPN gateway you would want to put the passphrase protecting the private
1136key file right into `/etc/ipsec.secrets` as described in the previous section,
1137so that the gateway can be booted in unattended mode. The risk of keeping
1138unencrypted secrets on a server can be minimized by putting the box into a
1139locked room. As long as no one can get root access on the machine the private
1140keys are safe.
1141
1142On a mobile laptop computer the situation is quite different. The computer can
1143be stolen or the user may leave it unattended so that unauthorized persons
1144can get access to it. In theses cases it would be preferable not to keep any
1145passphrases openly in `/etc/ipsec.secrets` but to prompt for them interactively
1146instead. This is easily done by defining
1147
1148 : RSA moonKey.pem %prompt
1149
1150Since strongSwan is usually started during the boot process, usually no
1151interactive console windows is available which can be used to prompt for
1152the passphrase. This must be initiated by the user by typing
1153
1154 ipsec secrets
1155
1156which actually is an alias for the existing command
1157
1158 ipsec rereadsecrets
1159
1160and which causes a passphrase prompt to appear. To abort entering a passphrase
1161enter just a carriage return.
1162
1163
1164## Configuring CA properties - ipsec.conf ##
1165
1166Besides the definition of IPsec connections the `ipsec.conf` file can also
1167be used to configure a few properties of the certification authorities
1168needed to establish the X.509 trust chains. The following example shows
1169some of the parameters that are currently available:
1170
1171 ca strongswan
1172 cacert=strongswanCert.pem
1173 ocspuri=http://ocsp.strongswan.org:8880
1174 crluri=http://crl.strongswan.org/strongswan.crl'
1175 crluri2="ldap://ldap.strongswan.org/O=strongSwan, C=CH?certificateRevocationList"
1176 auto=add
1177
1178In a similar way as `conn` sections are used for connection definitions, an
1179arbitrary number of optional `ca` sections define the basic properties of CAs.
1180
1181Each ca section is named with a unique label
1182
1183 ca strongswan
1184
1185The only mandatory parameter is
1186
1187 cacert=strongswanCert.pem
1188
1189which points to the CA certificate which usually resides in the default
1190directory `/etc/ipsec.d/cacerts/` but could also be retrieved via an absolute
1191path name.
1192
1193The OCSP URI
1194
1195 ocspuri=http://ocsp.strongswan.org:8880
1196
1197allows to define an individual OCSP server per CA. Also up to two additional
1198CRL distribution points (CDPs) can be defined
1199
1200 crluri=http://crl.strongswan.org/strongswan.crl'
1201 crluri2="ldap://ldap.strongswan.org/O=strongSwan, C=CH?certificateRevocationList"
1202
1203which are added to any CDPs already present in the received certificates
1204themselves.
1205
1206With the `auto=add` statement the `ca` definition is automatically loaded during
1207startup. Setting `auto=ignore` will ignore the `ca` section.
1208
1209Any parameters which appear in several ca definitions can be put in
1210a common `ca %default` section
1211
1212 ca %default
1213 crluri=http://crl.strongswan.org/strongswan.crl'
1214
1215
1216## Monitoring functions ##
1217
1218strongSwan offers the following monitoring functions:
1219
1220| Command | Action |
1221|---------------------|---------------------------------------------------|
1222| ipsec listaacerts | list all Authorization Authority certificates loaded from `/etc/ipsec.d/aacerts/` |
1223| ipsec listacerts | list all X.509 attribute certificates loaded from `/etc/ipsec.d/acerts/` |
1224| ipsec listalgs | list cryptographic algorithms for IKE |
1225| ipsec listcacerts | list all CA certificates loaded from `/etc/ipsec.d/cacerts/` or received via IKE |
1226| ipsec listcainfos | list all properties defined in `ca` sections in `ipsec.conf` |
1227| ipsec listcerts | list all certificates loaded via `leftcert` and `rightcert` |
1228| ipsec listcounters | list global or connection specific counter values |
1229| ipsec listcrls | list all CLRs loaded from `/etc/ipsec.d/crls/` |
1230| ipsec listocsp | list contents of the OCSP response cache |
1231| ipsec listocspcerts | list all OCSP signer certificates loaded from `/etc/ipsec.d/ocspcerts/` or received in OCSP responses |
1232| ipsec listplugins | list all loaded plugin features |
1233| ipsec listpubkeys | list all raw public keys e.g. loaded via `leftsigkey` and `rightsigkey` |
1234| ipsec listall | all the above commands combined |
1235| ipsec status | list concise status information on established connections |
1236| ipsec statusall | list detailed status information on connections |
1237
1238
1239## Firewall support functions ##
1240
1241
1242### Environment variables in the updown script ###
1243
1244strongSwan makes the following environment variables available
1245in the _updown_ script indicated by the `leftupdown` option:
1246
1247| Variable | Example | Comment |
1248|-----------------------|---------------------------|-----------------|
1249| $PLUTO_PEER_ID | carol@strongswan.org | RFC822_ADDR (1) |
1250| $PLUTO_PEER_PROTOCOL | 17 | udp (2) |
1251| $PLUTO_PEER_PORT | 68 | bootpc (3) |
1252| $PLUTO_MY_ID | moon.strongswan.org | FQDN (1) |
1253| $PLUTO_MY_PROTOCOL | 17 | udp (2) |
1254| $PLUTO_MY_PORT | 67 | bootps (3) |
1255
1256(1) $PLUTO_PEER_ID/$PLUTO_MY_ID contain the IDs of the two ends
1257 of an established connection. In our examples these
1258 correspond to the strings defined by `rightid` and `leftid`,
1259 respectively.
1260
1261(2) $PLUTO_PEER_PROTOCOL/$PLUTO_MY_PROTOCOL contain the protocol
1262 defined by the `rightprotoport` and `leftprotoport` options,
1263 respectively. Both variables contain the same protocol value.
1264 The variables take on the value '0' if no protocol has been defined.
1265
1266(3) $PLUTO_PEER_PORT/$PLUTO_MY_PORT contain the ports defined by
1267 the `rightprotoport` and `leftprotoport` options, respectively.
1268 The variables take on the value '0' if no port has been defined.
1269
1270There are several more, refer to the provided default script for a documentation
1271of them.
1272
1273
1274### Automatic insertion and deletion of iptables firewall rules ###
1275
1276The default `_updown` script automatically inserts and deletes dynamic
1277`iptables` firewall rules upon the establishment or teardown, respectively, of
1278an IPsec security association. This feature is activated with the line
1279
1280 leftfirewall=yes
1281
1282If you define a `leftsubnet` with a netmask larger than `/32` then the
1283automatically inserted _FORWARD_ `iptables` rules will not allow clients to
1284access the internal IP address of the gateway even if it is part of that subnet
1285definition. If you want additional _INPUT_ and _OUTPUT_ `iptables` rules to be
1286inserted, so that the host itself can be accessed then add the following line:
1287
1288 lefthostaccess=yes
1289
1290The `_updown` script also features a logging facility which will register the
1291creation (+) and the expiration (-) of each successfully established VPN
1292connection in a special syslog file in the following concise and easily
1293readable format:
1294
1295 Jul 19 18:58:38 moon vpn:
1296 + carol.strongswan.org 192.168.0.100 -- 192.168.0.1 == 10.1.0.0/16
1297 Jul 19 22:15:17 moon vpn:
1298 - carol.strongswan.org 192.168.0.100 -- 192.168.0.1 == 10.1.0.0/16