xref: /openbsd/sbin/iked/iked.conf.5 (revision 6168d348)
1.\" $OpenBSD: iked.conf.5,v 1.83 2021/01/24 19:10:19 tobhe Exp $
2.\"
3.\" Copyright (c) 2010 - 2014 Reyk Floeter <reyk@openbsd.org>
4.\" Copyright (c) 2004 Mathieu Sauve-Frankel  All rights reserved.
5.\"
6.\" Permission to use, copy, modify, and distribute this software for any
7.\" purpose with or without fee is hereby granted, provided that the above
8.\" copyright notice and this permission notice appear in all copies.
9.\"
10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\"
18.Dd $Mdocdate: January 24 2021 $
19.Dt IKED.CONF 5
20.Os
21.Sh NAME
22.Nm iked.conf
23.Nd IKEv2 configuration file
24.Sh DESCRIPTION
25.Nm
26is the configuration file for
27.Xr iked 8 ,
28the Internet Key Exchange version 2 (IKEv2) daemon for IPsec.
29IPsec itself is a pair of protocols:
30Encapsulating Security Payload (ESP),
31which provides integrity and confidentiality;
32and Authentication Header (AH),
33which provides integrity.
34The IPsec protocol itself is described in
35.Xr ipsec 4 .
36.Pp
37In its most basic form, a flow is established between hosts and/or
38networks, and then Security Associations (SA) are established,
39which detail how the desired protection will be achieved.
40IPsec uses flows to determine whether to apply security services to an
41IP packet or not.
42.Xr iked 8
43is used to set up flows and establish SAs automatically,
44by specifying
45.Sq ikev2
46policies in
47.Nm
48(see
49.Sx AUTOMATIC KEYING POLICIES ,
50below).
51.Pp
52Alternative methods of setting up flows and SAs are also possible
53using manual keying or automatic keying using the older ISAKMP/Oakley
54a.k.a. IKEv1 protocol.
55Manual keying is not recommended, but can be convenient for quick
56setups and testing.
57See
58.Xr ipsec.conf 5
59and
60.Xr isakmpd 8
61for more information about manual keying and ISAKMP support.
62.Sh IKED.CONF FILE FORMAT
63.Nm
64is divided into three main sections:
65.Bl -tag -width xxxx
66.It Sy Macros
67User-defined macros may be defined and used later, simplifying the
68configuration file.
69.It Sy Global Configuration
70Global settings for
71.Xr iked 8 .
72.It Sy Automatic Keying Policies
73Policies to set up IPsec flows and SAs automatically.
74.El
75.Pp
76Lines beginning with
77.Sq #
78and empty lines are regarded as comments,
79and ignored.
80Lines may be split using the
81.Sq \e
82character.
83.Pp
84Argument names not beginning with a letter, digit, or underscore
85must be quoted.
86.Pp
87Addresses can be specified in CIDR notation (matching netblocks),
88as symbolic host names, interface names, or interface group names.
89.Pp
90Additional configuration files can be included with the
91.Ic include
92keyword, for example:
93.Bd -literal -offset indent
94include "/etc/macros.conf"
95.Ed
96.Sh MACROS
97Macros can be defined that will later be expanded in context.
98Macro names must start with a letter, digit, or underscore,
99and may contain any of those characters.
100Macro names may not be reserved words (for example
101.Ic flow ,
102.Ic from ,
103.Ic esp ) .
104Macros are not expanded inside quotes.
105.Pp
106For example:
107.Bd -literal -offset indent
108remote_gw = "192.168.3.12"
109ikev2 esp from 192.168.7.0/24 to 192.168.8.0/24 peer $remote_gw
110.Ed
111.Sh GLOBAL CONFIGURATION
112Here are the settings that can be set globally:
113.Bl -tag -width xxxx
114.It Ic set active
115Set
116.Xr iked 8
117to global active mode.
118In active mode the per-policy
119.Ar mode
120setting is respected.
121.Xr iked 8
122will initiate policies set to
123.Ar active
124and wait for incoming requests for policies set to
125.Ar passive .
126This is the default.
127.It Ic set passive
128Set
129.Xr iked 8
130to global passive mode.
131In passive mode no packets are sent to peers and no connections are
132initiated by
133.Xr iked 8 ,
134even for
135.Ar active
136policies.
137This option is used for setups using
138.Xr sasyncd 8
139and
140.Xr carp 4
141to provide redundancy.
142.Xr iked 8
143will run in passive mode until sasyncd has determined that the host
144is the master and can switch to active mode.
145.It Ic set couple
146Load the negotiated security associations (SAs) and flows into the kernel.
147This is the default.
148.It Ic set decouple
149Don't load the negotiated SAs and flows from the kernel.
150This mode is only useful for testing and debugging.
151.It Ic set dpd_check_interval Ar time
152Specify the liveness check interval, in seconds.
153Setting
154.Ar time
155to 0 disables DPD.
156The default value is 60 seconds.
157.It Ic set enforcesingleikesa
158Allow only a single active IKE SA for each
159.Ic dstid .
160When a new SA with the same
161.Ic dstid
162is established, it replaces the old SA.
163.It Ic set noenforcesingleikesa
164Don't limit the number of IKE SAs per
165.Ic dstid .
166This is the default.
167.It Ic set fragmentation
168Enable IKEv2 Message Fragmentation (RFC 7383) support.
169This allows IKEv2 to operate in environments that might block IP fragments.
170.It Ic set nofragmentation
171Disables IKEv2 Message Fragmentation support.
172This is the default.
173.It Ic set mobike
174Enable MOBIKE (RFC 4555) support.
175This is the default.
176MOBIKE allows the peer IP address to be changed for IKE and IPsec SAs.
177Currently
178.Xr iked 8
179only supports MOBIKE when acting as a responder.
180.It Ic set nomobike
181Disables MOBIKE support.
182.It Ic set cert_partial_chain
183Allow partial certificate chain if at least one certificate is a trusted CA from
184.Pa /etc/iked/ca/ .
185.It Ic set ocsp Ar URL Op Ic tolerate Ar time Op Ic maxage Ar time
186Enable OCSP and set the fallback URL of the OCSP responder.
187This fallback will be used if the trusted CA from
188.Pa /etc/iked/ca/
189does not have an OCSP-URL extension.
190Please note that the matching responder certificates
191have to be placed in
192.Pa /etc/iked/ocsp/responder.crt .
193.Pp
194The optional
195.Ic tolerate
196parameter specifies how much the OCSP response attribute
197.Sq thisUpdate
198may be in the future and how much
199.Sq nextUpdate
200may be in the past, with respect to the local time.
201The optional
202.Ic maxage
203parameter specifies how much
204.Sq thisUpdate
205may be in the past.
206If
207.Ic tolerate
208is set to 0 then the times are not verified at all.
209This is the default setting.
210.It Ic user Ar name password
211.Xr iked 8
212supports user-based authentication by tunneling the Extensible
213Authentication Protocol (EAP) over IKEv2.
214In its most basic form, the users will be authenticated against a
215local, integrated password database that is configured with the
216.Ic user
217lines in
218.Nm
219and the
220.Ar name
221and
222.Ar password
223arguments.
224Note that the password has to be specified in plain text which is
225required to support different challenge-based EAP methods like
226EAP-MD5 or EAP-MSCHAPv2.
227.El
228.Sh AUTOMATIC KEYING POLICIES
229This section is used to configure policies that will be used by
230.Xr iked 8
231to set up flows and SAs automatically.
232Some examples of setting up automatic keying:
233.Bd -literal -offset 3n
234# Set up a VPN:
235# First between the gateway machines 192.168.3.1 and 192.168.3.2
236# Second between the networks 10.1.1.0/24 and 10.1.2.0/24
237ikev2 esp from 192.168.3.1 to 192.168.3.2
238ikev2 esp from 10.1.1.0/24 to 10.1.2.0/24 peer 192.168.3.2
239.Ed
240.Pp
241For incoming connections from remote peers, the policies are evaluated
242in sequential order, from first to last.
243The last matching policy decides what action is taken; if no policy matches
244the connection, the default action is to ignore the connection attempt or
245to use the
246.Ar default
247policy, if set.
248Please also see the
249.Sx EXAMPLES
250section for a detailed example of the policy evaluation.
251.Pp
252The first time an IKEv2 connection matches a policy, an IKE SA is
253created; for subsequent packets the connection is identified by the
254IKEv2 parameters that are stored in the SA without evaluating any
255policies.
256After the connection is closed or times out, the IKE SA is
257automatically removed.
258.Pp
259The commands are as follows:
260.Bl -tag -width xxxx
261.It Xo
262.Ic ikev2
263.Op Ar name
264.Xc
265The mandatory
266.Ic ikev2
267keyword will identify an IKEv2 automatic keying policy.
268.Ar name
269is an optional arbitrary string identifying the policy.
270The name should only occur once in
271.Nm
272or any included files.
273If omitted,
274a name will be generated automatically for the policy.
275.It Op Ar eval
276The
277.Ar eval
278option modifies the policy evaluation for this policy.
279It can be one of
280.Ar quick ,
281.Ar skip
282or
283.Ar default .
284If a new incoming connection matches a policy with the
285.Ar quick
286option set, that policy is considered the last matching policy,
287and evaluation of subsequent policies is skipped.
288The
289.Ar skip
290option will disable evaluation of this policy for incoming connections.
291The
292.Ar default
293option sets the default policy and should only be specified once.
294.It Op Ar mode
295.Ar mode
296specifies the IKEv2 mode to use:
297one of
298.Ar passive
299or
300.Ar active .
301When
302.Ar passive
303is specified,
304.Xr iked 8
305will not immediately start negotiation of this tunnel, but wait for an incoming
306request from the remote peer.
307When
308.Ar active
309is specified, negotiation will be started at once.
310If omitted,
311.Ar passive
312mode will be used.
313.It Op Ar ipcomp
314The keyword
315.Ar ipcomp
316specifies that
317.Xr ipcomp 4 ,
318the IP Payload Compression protocol, is negotiated in addition to encapsulation.
319The optional compression is applied before packets are encapsulated.
320IPcomp must be enabled in the kernel:
321.Pp
322.Dl # sysctl net.inet.ipcomp.enable=1
323.It Op Ar tmode
324.Ar tmode
325describes the encapsulation mode to be used.
326Possible modes are
327.Ar tunnel
328and
329.Ar transport ;
330the default is
331.Ar tunnel .
332.It Op Ar encap
333.Ar encap
334specifies the encapsulation protocol to be used.
335Possible protocols are
336.Ar esp
337and
338.Ar ah ;
339the default is
340.Ar esp .
341.It Op Ar af
342This policy only applies to endpoints of the specified address family
343which can be either
344.Ar inet
345or
346.Ar inet6 .
347Note that this only matters for IKEv2 endpoints and does not
348restrict the traffic selectors to negotiate flows with different
349address families, e.g. IPv6 flows negotiated by IPv4 endpoints.
350.It Ic proto Ar protocol
351The optional
352.Ic proto
353parameter restricts the flow to a specific IP protocol.
354Common protocols are
355.Xr icmp 4 ,
356.Xr tcp 4 ,
357and
358.Xr udp 4 .
359For a list of all the protocol name to number mappings used by
360.Xr iked 8 ,
361see the file
362.Pa /etc/protocols .
363.It Ic rdomain Ar number
364Specify a different routing domain for unencrypted traffic.
365The resulting IPsec SAs will match outgoing packets in the specified
366.Ic rdomain Ar number
367and move the encrypted packets to the rdomain the
368.Xr iked 8
369instance is running in.
370Vice versa, incoming
371.Xr ipsec 4
372traffic is moved to
373.Ic rdomain Ar number
374after decryption.
375.It Xo
376.Ic from Ar src
377.Op Ic port Ar sport
378.Op Pq Ar srcnat
379.Ic to Ar dst
380.Op Ic port Ar dport
381.Xc
382Specify one or more traffic selectors for this policy which will be
383used to negotiate the IPsec flows between the IKEv2 peers.
384During the negotiation, the peers may decide to narrow a flow to a
385subset of the configured traffic selector networks to match the
386policies on each side.
387.Pp
388Each traffic selector will apply for packets with source address
389.Ar src
390and destination address
391.Ar dst .
392If the
393.Ar src
394argument specifies a fictional source ID,
395the
396.Ar srcnat
397parameter can be used to specify the actual source address.
398This can be used in outgoing NAT/BINAT scenarios as described below.
399The keyword
400.Ar any
401will match any address (i.e. 0.0.0.0/0 and ::/0).
402If the
403.Ic config address
404option is specified, the
405.Ar dynamic
406keyword can be used to create flows from or to the dynamically
407assigned address.
408.Pp
409The optional
410.Ic port
411modifiers restrict the traffic selectors to the specified ports.
412They are only valid in conjunction with the
413.Xr tcp 4
414and
415.Xr udp 4
416protocols.
417Ports can be specified by number or by name.
418For a list of all port name to number mappings used by
419.Xr ipsecctl 8 ,
420see the file
421.Pa /etc/services .
422.It Ic local Ar localip Ic peer Ar remote
423The
424.Ic local
425parameter specifies the address or FQDN of the local endpoint.
426Unless the gateway is multi-homed or uses address aliases,
427this option is generally not needed.
428.Pp
429The
430.Ic peer
431parameter specifies the address or FQDN of the remote endpoint.
432For host-to-host connections where
433.Ar dst
434is identical to
435.Ar remote ,
436this option is generally not needed as it will be set to
437.Ar dst
438automatically.
439If it is not specified or if the keyword
440.Ar any
441is given, the default peer is used.
442.It Xo
443.Ic ikesa
444.Ic auth Ar algorithm
445.Ic enc Ar algorithm
446.Ic prf Ar algorithm
447.Ic group Ar group
448.Xc
449These parameters define the mode and cryptographic transforms to be
450used for the IKE SA negotiation, also known as phase 1.
451The IKE SA will be used to authenticate the machines and to set up an
452encrypted channel for the IKEv2 protocol.
453.Pp
454Possible values for
455.Ic auth ,
456.Ic enc ,
457.Ic prf ,
458.Ic group ,
459and the default proposals are described below in
460.Sx CRYPTO TRANSFORMS .
461If omitted,
462.Xr iked 8
463will use the default proposals for the IKEv2 protocol.
464.Pp
465The keyword
466.Ic ikesa
467can be used multiple times as a delimiter between IKE SA proposals.
468The order of the proposals depend on the order in the configuration.
469The keywords
470.Ic auth ,
471.Ic enc ,
472.Ic prf
473and
474.Ic group
475can be used multiple times within a single proposal to configure
476multiple crypto transforms.
477.It Xo
478.Ic childsa
479.Ic auth Ar algorithm
480.Ic enc Ar algorithm
481.Ic group Ar group
482.Ic esn
483.Xc
484These parameters define the cryptographic transforms to be used for
485the Child SA negotiation, also known as phase 2.
486Each Child SA will be used to negotiate the actual IPsec SAs.
487The initial Child SA is always negotiated with the initial IKEv2 key
488exchange; additional Child SAs may be negotiated with additional
489Child SA key exchanges for an established IKE SA.
490.Pp
491Possible values for
492.Ic auth ,
493.Ic enc ,
494.Ic group ,
495.Ic esn ,
496and the default proposals are described below in
497.Sx CRYPTO TRANSFORMS .
498If omitted,
499.Xr iked 8
500will use the default proposals for the ESP or AH protocol.
501.Pp
502The
503.Ic group
504option will only be used to enable Perfect Forward Secrecy (PFS)
505for additional Child SAs exchanges that are not part of the initial
506key exchange.
507.Pp
508The keyword
509.Ic childsa
510can be used multiple times as a delimiter between Child SA proposals.
511The order of the proposals depend on the order in the configuration.
512The keywords
513.Ic auth ,
514.Ic enc
515and
516.Ic group
517can be used multiple times within a single proposal to configure
518multiple crypto transforms.
519.It Ic srcid Ar string Ic dstid Ar string
520.Ic srcid
521defines an ID of type
522.Dq FQDN ,
523.Dq ASN1_DN ,
524.Dq IPV4 ,
525.Dq IPV6 ,
526or
527.Dq UFQDN
528that will be used by
529.Xr iked 8
530as the identity of the local peer.
531If the argument is an email address (reyk@example.com),
532.Xr iked 8
533will use UFQDN as the ID type.
534The ASN1_DN type will be used if the string starts with a slash
535.Sq /
536(/C=DE/../CN=10.0.0.1/emailAddress=reyk@example.com).
537If the argument is an IPv4 address or a compressed IPv6 address,
538the ID types IPV4 or IPV6 will be used.
539Anything else is considered to be an FQDN.
540.Pp
541If
542.Ic srcid
543is omitted,
544the default is to use the hostname of the local machine,
545see
546.Xr hostname 1
547to set or print the hostname.
548.Pp
549.Ic dstid
550is similar to
551.Ic srcid ,
552but instead specifies the ID to be used
553by the remote peer.
554.It Ic ikelifetime Ar time
555The optional
556.Ic ikelifetime
557parameter defines the IKE SA expiration timeout by the
558.Ar time
559SA was created.
560A zero value disables active IKE SA rekeying.
561This is the default.
562.Pp
563The accepted format of the
564.Ar time
565specification is described below.
566.It Ic lifetime Ar time Op Ic bytes Ar bytes
567The optional
568.Ic lifetime
569parameter defines the Child SA expiration timeout by the
570.Ar time
571SA was in use and by the number of
572.Ar bytes
573that were processed using the SA.
574Default values are 3 hours and 512 megabytes which means that SA will be
575rekeyed before reaching the time limit or 512 megabytes of data
576will pass through.
577Zero values disable rekeying.
578.Pp
579Several unit specifiers are recognized (ignoring case):
580.Ql m
581and
582.Ql h
583for minutes and hours, and
584.Ql K ,
585.Ql M
586and
587.Ql G
588for kilo-, mega- and gigabytes accordingly.
589.Pp
590Please note that rekeying must happen at least several times a day as
591IPsec security heavily depends on frequent key renewals.
592.It Op Ar ikeauth
593Specify a method to be used to authenticate the remote peer.
594.Xr iked 8
595will automatically determine a method based on public keys or certificates
596configured for the peer.
597.Ar ikeauth
598can be used to override this behaviour.
599Non-psk modes will require setting up certificates and RSA or ECDSA public
600keys; see
601.Xr iked 8
602for more information.
603.Pp
604.Bl -tag -width $domain -compact -offset indent
605.It Ic eap Ar type
606Use EAP to authenticate the initiator.
607The only supported EAP
608.Ar type
609is currently
610.Ar MSCHAP-V2 .
611The responder will use RSA public key authentication.
612.It Ic ecdsa256
613Use ECDSA with a 256-bit elliptic curve key and SHA2-256 for authentication.
614.It Ic ecdsa384
615Use ECDSA with a 384-bit elliptic curve key and SHA2-384 for authentication.
616.It Ic ecdsa521
617Use ECDSA with a 521-bit elliptic curve key and SHA2-512 for authentication.
618.It Ic psk Ar string
619Use a pre-shared key
620.Ar string
621or hex value (starting with 0x) for authentication.
622.It Ic rfc7427
623Only use RFC 7427 signatures for authentication.
624RFC 7427 signatures currently only support SHA2-256 as the hash.
625.It Ic rsa
626Use RSA public key authentication with SHA1 as the hash.
627.El
628.Pp
629The default is to allow any signature authentication.
630.It Ic config Ar option address
631Send one or more optional configuration payloads (CP) to the peer.
632The configuration
633.Ar option
634can be one of the following with the expected address format:
635.Pp
636.Bl -tag -width Ds -compact -offset indent
637.It Ic address Ar address
638Assign a static address on the internal network.
639.It Ic address Ar address/prefix
640Assign a dynamic address on the internal network.
641The address will be assigned from an address pool with the size specified by
642.Ar prefix .
643.It Ic netmask Ar netmask
644The IPv4 netmask of the internal network.
645.It Ic name-server Ar address
646The DNS server address within the internal network.
647.It Ic netbios-server Ar address
648The NetBIOS name server (WINS) within the internal network.
649This option is provided for compatibility with legacy clients.
650.It Ic dhcp-server Ar address
651The address of an internal DHCP server for further configuration.
652.It Ic protected-subnet Ar address/prefix
653The address of an additional IPv4 or IPv6 subnet reachable over the
654gateway.
655This option is used to notify the peer of a subnet behind the gateway (that
656might require a second SA).
657Networks specified in this SA's "from" or "to" options do not need to be
658included.
659.It Ic access-server Ar address
660The address of an internal remote access server.
661.El
662.It Ic tag Ar string
663Add a
664.Xr pf 4
665tag to all packets of IPsec SAs created for this connection.
666This will allow matching packets for this connection by defining
667rules in
668.Xr pf.conf 5
669using the
670.Cm tagged
671keyword.
672.Pp
673The following variables can be used in tags to include information
674from the remote peer on runtime:
675.Pp
676.Bl -tag -width $domain -compact -offset indent
677.It Ar $id
678The
679.Ic dstid
680that was proposed by the remote peer to identify itself.
681It will be expanded to
682.Ar id-value ,
683e.g.\&
684.Ar FQDN/foo.example.com .
685To limit the size of the derived tag,
686.Xr iked 8
687will extract the common name
688.Sq CN=
689from ASN1_DN IDs, for example
690.Ar ASN1_ID//C=DE/../CN=10.1.1.1/..
691will be expanded to
692.Ar 10.1.1.1 .
693.It Ar $eapid
694For a connection using EAP, the identity (username) used by the remote peer.
695.It Ar $domain
696Extract the domain from IDs of type FQDN, UFQDN or ASN1_DN.
697.It Ar $name
698The name of the IKEv2 policy that was configured in
699.Nm
700or automatically generated by
701.Xr iked 8 .
702.El
703.Pp
704For example, if the ID is
705.Ar FQDN/foo.example.com
706or
707.Ar UFQDN/user@example.com ,
708.Dq ipsec-$domain
709expands to
710.Dq ipsec-example.com .
711The variable expansion for the
712.Ar tag
713directive occurs only at runtime (not when the file is parsed)
714and must be quoted, or it will be interpreted as a macro.
715.It Ic tap Ar interface
716Send the decapsulated IPsec traffic to the specified
717.Xr enc 4
718.Ar interface
719instead of
720.Ar enc0
721for filtering and monitoring.
722The traffic will be blocked if the specified
723.Ar interface
724does not exist.
725.El
726.Sh PACKET FILTERING
727IPsec traffic appears unencrypted on the
728.Xr enc 4
729interface
730and can be filtered accordingly using the
731.Ox
732packet filter,
733.Xr pf 4 .
734The grammar for the packet filter is described in
735.Xr pf.conf 5 .
736.Pp
737The following components are relevant to filtering IPsec traffic:
738.Bl -ohang -offset indent
739.It external interface
740Interface for IKE traffic and encapsulated IPsec traffic.
741.It proto udp port 500
742IKE traffic on the external interface.
743.It proto udp port 4500
744IKE NAT-Traversal traffic on the external interface.
745.It proto ah | esp
746Encapsulated IPsec traffic
747on the external interface.
748.It enc0
749Default interface for outgoing traffic before it's been encapsulated,
750and incoming traffic after it's been decapsulated.
751State on this interface should be interface bound;
752see
753.Xr enc 4
754for further information.
755.It proto ipencap
756[tunnel mode only]
757IP-in-IP traffic flowing between gateways
758on the enc0 interface.
759.It tagged ipsec-example.org
760Match traffic of IPsec SAs using the
761.Ic tag
762keyword.
763.El
764.Pp
765If the filtering rules specify to block everything by default,
766the following rule
767would ensure that IPsec traffic never hits the packet filtering engine,
768and is therefore passed:
769.Bd -literal -offset indent
770set skip on enc0
771.Ed
772.Pp
773In the following example, all traffic is blocked by default.
774IPsec-related traffic from gateways {192.168.3.1, 192.168.3.2} and
775networks {10.0.1.0/24, 10.0.2.0/24} is permitted.
776.Bd -literal -offset indent
777block on ix0
778block on enc0
779
780pass  in on ix0 proto udp from 192.168.3.2 to 192.168.3.1 \e
781	port {500, 4500}
782pass out on ix0 proto udp from 192.168.3.1 to 192.168.3.2 \e
783	port {500, 4500}
784
785pass  in on ix0 proto esp from 192.168.3.2 to 192.168.3.1
786pass out on ix0 proto esp from 192.168.3.1 to 192.168.3.2
787
788pass  in on enc0 proto ipencap from 192.168.3.2 to 192.168.3.1 \e
789	keep state (if-bound)
790pass out on enc0 proto ipencap from 192.168.3.1 to 192.168.3.2 \e
791	keep state (if-bound)
792pass  in on enc0 from 10.0.2.0/24 to 10.0.1.0/24 \e
793	keep state (if-bound)
794pass out on enc0 from 10.0.1.0/24 to 10.0.2.0/24 \e
795	keep state (if-bound)
796.Ed
797.Pp
798.Xr pf 4
799has the ability to filter IPsec-related packets
800based on an arbitrary
801.Em tag
802specified within a ruleset.
803The tag is used as an internal marker
804which can be used to identify the packets later on.
805This could be helpful,
806for example,
807in scenarios where users are connecting in from differing IP addresses,
808or to support queue-based bandwidth control,
809since the enc0 interface does not support it.
810.Pp
811The following
812.Xr pf.conf 5
813fragment uses queues for all IPsec traffic with special
814handling for developers and employees:
815.Bd -literal -offset indent
816queue std on ix0 bandwidth 100M
817queue   deflt parent std bandwidth 10M default
818queue   developers parent std bandwidth 75M
819queue   employees parent std bandwidth 5M
820queue   ipsec parent std bandwidth 10M
821
822pass out on ix0 proto esp set queue ipsec
823
824pass out on ix0 tagged ipsec-developers.example.com \e
825	set queue developers
826pass out on ix0 tagged ipsec-employees.example.com \e
827	set queue employees
828.Ed
829.Pp
830The following example assigns the tags in the
831.Nm
832configuration and also sets an alternative
833.Xr enc 4
834device:
835.Bd -literal -offset indent
836ikev2 esp from 10.1.1.0/24 to 10.1.2.0/24 peer 192.168.3.2 \e
837	tag "ipsec-$domain" tap "enc1"
838.Ed
839.Sh OUTGOING NETWORK ADDRESS TRANSLATION
840In some network topologies it is desirable to perform NAT on traffic leaving
841through the VPN tunnel.
842In order to achieve that,
843the
844.Ar src
845argument is used to negotiate the desired network ID with the peer
846and the
847.Ar srcnat
848parameter defines the true local subnet,
849so that a correct SA can be installed on the local side.
850.Pp
851For example,
852if the local subnet is 192.168.1.0/24 and all the traffic
853for a specific VPN peer should appear as coming from 10.10.10.1,
854the following configuration is used:
855.Bd -literal -offset indent
856ikev2 esp from 10.10.10.1 (192.168.1.0/24) to 192.168.2.0/24 \e
857	peer 10.10.20.1
858.Ed
859.Pp
860Naturally,
861a relevant NAT rule is required in
862.Xr pf.conf 5 .
863For the example above,
864this would be:
865.Bd -literal -offset indent
866match out on enc0 from 192.168.1.0/24 to 192.168.2.0/24 \e
867	nat-to 10.10.10.1
868.Ed
869.Pp
870From the peer's point of view,
871the local end of the VPN tunnel is declared to be 10.10.10.1
872and all the traffic arrives with that source address.
873.Sh CRYPTO TRANSFORMS
874The following authentication types are permitted with the
875.Ic auth
876keyword:
877.Bl -column "Authentication" "Key Length" "Truncated Length" "Default" -offset indent
878.It Em "Authentication" Ta Em "Key Length" Ta Em "Truncated Length" Ta Em "Default"
879.It Li hmac-md5 Ta "128 bits" Ta "96 bits" Ta ""
880.It Li hmac-sha1 Ta "160 bits" Ta "96 bits" Ta "x"
881.It Li hmac-sha2-256 Ta "256 bits" Ta "128 bits" Ta "x"
882.It Li hmac-sha2-384 Ta "384 bits" Ta "192 bits" Ta "x"
883.It Li hmac-sha2-512 Ta "512 bits" Ta "256 bits" Ta "x"
884.El
885.Pp
886The following pseudo-random function types are permitted with the
887.Ic prf
888keyword:
889.Bl -column "hmac-sha2-512" "Key Length" "Default" "[IKE only]" -offset indent
890.It Em "PRF" Ta Em "Key Length" Ta Em "Default" Ta ""
891.It Li hmac-md5 Ta "128 bits" Ta "" Ta "[IKE only]"
892.It Li hmac-sha1 Ta "160 bits" Ta "x" Ta "[IKE only]"
893.It Li hmac-sha2-256 Ta "256 bits" Ta "x" Ta "[IKE only]"
894.It Li hmac-sha2-384 Ta "384 bits" Ta "x" Ta "[IKE only]"
895.It Li hmac-sha2-512 Ta "512 bits" Ta "x" Ta "[IKE only]"
896.El
897.Pp
898The following cipher types are permitted with the
899.Ic enc
900keyword:
901.Bl -column "chacha20-poly1305" "Key Length" "Default" "[ESP only]" -offset indent
902.It Em "Cipher" Ta Em "Key Length" Ta Em "Default" Ta ""
903.It Li 3des Ta "168 bits" Ta "x" Ta ""
904.It Li aes-128 Ta "128 bits" Ta "x" Ta ""
905.It Li aes-192 Ta "192 bits" Ta "x" Ta ""
906.It Li aes-256 Ta "256 bits" Ta "x" Ta ""
907.It Li aes-128-ctr Ta "160 bits" Ta "" Ta "[ESP only]"
908.It Li aes-192-ctr Ta "224 bits" Ta "" Ta "[ESP only]"
909.It Li aes-256-ctr Ta "288 bits" Ta "" Ta "[ESP only]"
910.It Li aes-128-gcm Ta "160 bits" Ta "x" Ta ""
911.It Li aes-192-gcm Ta "224 bits" Ta "" Ta "[ESP only]"
912.It Li aes-256-gcm Ta "288 bits" Ta "x" Ta ""
913.It Li aes-128-gcm-12 Ta "160 bits" Ta "" Ta "[IKE only]"
914.It Li aes-256-gcm-12 Ta "288 bits" Ta "" Ta "[IKE only]"
915.It Li blowfish Ta "160 bits" Ta "" Ta "[ESP only]"
916.It Li cast Ta "128 bits" Ta "" Ta "[ESP only]"
917.It Li chacha20-poly1305 Ta "288 bits" Ta "" Ta "[ESP only]"
918.El
919.Pp
920The following cipher types provide only authentication,
921not encryption:
922.Bl -column "chacha20-poly1305" "Key Length" "Default" "[ESP only]" -offset indent
923.It Li aes-128-gmac Ta "160 bits" Ta "" Ta "[ESP only]"
924.It Li aes-192-gmac Ta "224 bits" Ta "" Ta "[ESP only]"
925.It Li aes-256-gmac Ta "288 bits" Ta "" Ta "[ESP only]"
926.It Li null Ta "" Ta "" Ta "[ESP only]"
927.El
928.Pp
929The Extended Sequence Numbers option can be enabled or disabled with the
930.Ic esn
931or
932.Ic noesn
933keywords:
934.Bl -column "noesn" "Default" "[ESP only]" -offset indent
935.It Em ESN Ta Em "Default" Ta Em ""
936.It Li esn Ta "x" Ta "[ESP only]"
937.It Li noesn Ta "x" Ta "[ESP only]"
938.El
939.Pp
940Transforms followed by
941.Bq IKE only
942can only be used with the
943.Ic ikesa
944keyword, transforms with
945.Bq ESP only
946can only be used with the
947.Ic childsa
948keyword.
949.Pp
9503DES requires 24 bytes to form its 168-bit key.
951This is because the most significant bit of each byte is used for parity.
952.Pp
953The keysize of AES-CTR is actually 128-bit.
954However as well as the key, a 32-bit nonce has to be supplied.
955Thus 160 bits of key material have to be supplied.
956The same applies to AES-GCM, AES-GMAC and Chacha20-Poly1305,
957however in the latter case the keysize is 256 bit.
958.Pp
959Using AES-GMAC or NULL with ESP will only provide authentication.
960This is useful in setups where AH cannot be used, e.g. when NAT is involved.
961.Pp
962The following group types are permitted with the
963.Ic group
964keyword:
965.Bl -column "brainpool224" "Group" "Size" "Curve25519" "Default" -offset indent
966.It Em Name Ta Em Group Ta Em Size Ta Em Type Ta Em Default
967.It Li modp768 Ta grp1 Ta 768 Ta "MODP" Ta "" Ta "[insecure]"
968.It Li modp1024 Ta grp2 Ta 1024 Ta "MODP" Ta "x" Ta "[weak]"
969.It Li modp1536 Ta grp5 Ta 1536 Ta "MODP" Ta "x" Ta "[weak]"
970.It Li modp2048 Ta grp14 Ta 2048 Ta "MODP" Ta "x"
971.It Li modp3072 Ta grp15 Ta 3072 Ta "MODP" Ta "x"
972.It Li modp4096 Ta grp16 Ta 4096 Ta "MODP" Ta "x"
973.It Li modp6144 Ta grp17 Ta 6144 Ta "MODP" Ta ""
974.It Li modp8192 Ta grp18 Ta 8192 Ta "MODP" Ta ""
975.It Li ecp256 Ta grp19 Ta 256 Ta "ECP" Ta "x"
976.It Li ecp384 Ta grp20 Ta 384 Ta "ECP" Ta "x"
977.It Li ecp521 Ta grp21 Ta 521 Ta "ECP" Ta "x"
978.It Li ecp192 Ta grp25 Ta 192 Ta "ECP" Ta ""
979.It Li ecp224 Ta grp26 Ta 224 Ta "ECP" Ta ""
980.It Li brainpool224 Ta grp27 Ta 224 Ta "ECP" Ta ""
981.It Li brainpool256 Ta grp28 Ta 256 Ta "ECP" Ta ""
982.It Li brainpool384 Ta grp29 Ta 384 Ta "ECP" Ta ""
983.It Li brainpool512 Ta grp30 Ta 512 Ta "ECP" Ta ""
984.It Li curve25519 Ta grp31 Ta 256 Ta "Curve25519" Ta "x"
985.El
986.Pp
987The currently supported group types are either
988MODP (exponentiation groups modulo a prime),
989ECP (elliptic curve groups modulo a prime),
990or Curve25519.
991Please note that MODP groups of less than 2048 bits are considered
992as weak or insecure (see RFC 8247 section 2.4) and only provided for
993backwards compatibility.
994.Sh FILES
995.Bl -tag -width /etc/examples/iked.conf -compact
996.It Pa /etc/iked.conf
997.It Pa /etc/examples/iked.conf
998.El
999.Sh EXAMPLES
1000The first example is intended for a server with clients connecting to
1001.Xr iked 8
1002as an IPsec gateway, or IKEv2 responder, using mutual public key
1003authentication and additional challenge-based EAP-MSCHAPv2 password
1004authentication:
1005.Bd -literal -offset indent
1006user "test" "password123"
1007
1008ikev2 "win7" esp \e
1009	from dynamic to 172.16.2.0/24 \e
1010	peer 10.0.0.0/8 local 192.168.56.0/24 \e
1011	eap "mschap-v2" \e
1012	config address 172.16.2.1 \e
1013	tag "$name-$id"
1014.Ed
1015.Pp
1016The next example allows peers to authenticate using a pre-shared key
1017.Sq foobar :
1018.Bd -literal -offset indent
1019ikev2 "big test" \e
1020	esp proto tcp \e
1021	from 10.0.0.0/8 port 23 to 20.0.0.0/8 port 40 \e
1022	from 192.168.1.1 to 192.168.2.2 \e
1023	peer any local any \e
1024	ikesa \e
1025		enc 3des auth hmac-sha2-256 \e
1026		group ecp256 group modp1024 \e
1027	ikesa \e
1028		enc 3des auth hmac-sha1 \e
1029		group ecp256 group modp1024 \e
1030	childsa enc aes-128 auth hmac-sha2-256 \e
1031	childsa enc aes-128 auth hmac-sha1 \e
1032	srcid host.example.com \e
1033	dstid 192.168.0.254 \e
1034	psk "foobar"
1035.Ed
1036.Pp
1037The following example illustrates the last matching policy
1038evaluation for incoming connections on an IKEv2 gateway.
1039The peer 192.168.1.34 will always match the first policy because of the
1040.Ar quick
1041keyword;
1042connections from the peers 192.168.1.3 and 192.168.1.2 will be matched
1043by one of the last two policies;
1044any other connections from 192.168.1.0/24 will be matched by the
1045.Sq subnet
1046policy;
1047and any other connection will be matched by the
1048.Sq catch all
1049policy.
1050.Bd -literal -offset indent
1051ikev2 quick esp from 10.10.10.0/24 to 10.20.20.0/24 \e
1052	peer 192.168.1.34
1053ikev2 "catch all" esp from 10.0.1.0/24 to 10.0.2.0/24 \e
1054	peer any
1055ikev2 "subnet" esp from 10.0.3.0/24 to 10.0.4.0/24 \e
1056	peer 192.168.1.0/24
1057ikev2 esp from 10.0.5.0/30 to 10.0.5.4/30 peer 192.168.1.2
1058ikev2 esp from 10.0.5.8/30 to 10.0.5.12/30 peer 192.168.1.3
1059.Ed
1060.Pp
1061This example encrypts a
1062.Xr gre 4
1063tunnel from local machine A (2001:db8::aa:1) to peer D (2001:db8::dd:4) based on
1064FQDN-based public key authentication;
1065.Ar transport
1066mode avoids double encapsulation:
1067.Bd -literal -offset indent
1068ikev2 transport \e
1069	proto gre \e
1070	from 2001:db8::aa:1 to 2001:db8::dd:4 \e
1071	peer D.example.com
1072.Ed
1073.Sh SEE ALSO
1074.Xr enc 4 ,
1075.Xr ipsec 4 ,
1076.Xr ipsec.conf 5 ,
1077.Xr pf.conf 5 ,
1078.Xr ikectl 8 ,
1079.Xr iked 8
1080.Sh HISTORY
1081The
1082.Nm
1083file format first appeared in
1084.Ox 4.8 .
1085.Sh AUTHORS
1086The
1087.Xr iked 8
1088program was written by
1089.An Reyk Floeter Aq Mt reyk@openbsd.org .
1090