1.\" $OpenBSD: iked.conf.5,v 1.78 2020/09/23 14:25:55 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: September 23 2020 $ 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 reponse 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 . 392The keyword 393.Ar any 394will match any address (i.e. 0.0.0.0/0). 395If the 396.Ar src 397argument specifies a fictional source ID, 398the 399.Ar srcnat 400parameter can be used to specify the actual source address. 401This can be used in outgoing NAT/BINAT scenarios as described below. 402.Pp 403The optional 404.Ic port 405modifiers restrict the traffic selectors to the specified ports. 406They are only valid in conjunction with the 407.Xr tcp 4 408and 409.Xr udp 4 410protocols. 411Ports can be specified by number or by name. 412For a list of all port name to number mappings used by 413.Xr ipsecctl 8 , 414see the file 415.Pa /etc/services . 416.It Ic local Ar localip Ic peer Ar remote 417The 418.Ic local 419parameter specifies the address or FQDN of the local endpoint. 420Unless the gateway is multi-homed or uses address aliases, 421this option is generally not needed. 422.Pp 423The 424.Ic peer 425parameter specifies the address or FQDN of the remote endpoint. 426For host-to-host connections where 427.Ar dst 428is identical to 429.Ar remote , 430this option is generally not needed as it will be set to 431.Ar dst 432automatically. 433If it is not specified or if the keyword 434.Ar any 435is given, the default peer is used. 436.It Xo 437.Ic ikesa 438.Ic auth Ar algorithm 439.Ic enc Ar algorithm 440.Ic prf Ar algorithm 441.Ic group Ar group 442.Xc 443These parameters define the mode and cryptographic transforms to be 444used for the IKE SA negotiation, also known as phase 1. 445The IKE SA will be used to authenticate the machines and to set up an 446encrypted channel for the IKEv2 protocol. 447.Pp 448Possible values for 449.Ic auth , 450.Ic enc , 451.Ic prf , 452.Ic group , 453and the default proposals are described below in 454.Sx CRYPTO TRANSFORMS . 455If omitted, 456.Xr iked 8 457will use the default proposals for the IKEv2 protocol. 458.Pp 459The keyword 460.Ic ikesa 461can be used multiple times as a delimiter between IKE SA proposals. 462The order of the proposals depend on the order in the configuration. 463The keywords 464.Ic auth , 465.Ic enc , 466.Ic prf 467and 468.Ic group 469can be used multiple times within a single proposal to configure 470multiple crypto transforms. 471.It Xo 472.Ic childsa 473.Ic auth Ar algorithm 474.Ic enc Ar algorithm 475.Ic group Ar group 476.Ic esn 477.Xc 478These parameters define the cryptographic transforms to be used for 479the Child SA negotiation, also known as phase 2. 480Each Child SA will be used to negotiate the actual IPsec SAs. 481The initial Child SA is always negotiated with the initial IKEv2 key 482exchange; additional Child SAs may be negotiated with additional 483Child SA key exchanges for an established IKE SA. 484.Pp 485Possible values for 486.Ic auth , 487.Ic enc , 488.Ic group , 489.Ic esn , 490and the default proposals are described below in 491.Sx CRYPTO TRANSFORMS . 492If omitted, 493.Xr iked 8 494will use the default proposals for the ESP or AH protocol. 495.Pp 496The 497.Ic group 498option will only be used to enable Perfect Forward Secrecy (PFS) 499for additional Child SAs exchanges that are not part of the initial 500key exchange. 501.Pp 502The keyword 503.Ic childsa 504can be used multiple times as a delimiter between Child SA proposals. 505The order of the proposals depend on the order in the configuration. 506The keywords 507.Ic auth , 508.Ic enc 509and 510.Ic group 511can be used multiple times within a single proposal to configure 512multiple crypto transforms. 513.It Ic srcid Ar string Ic dstid Ar string 514.Ic srcid 515defines an ID of type 516.Dq FQDN , 517.Dq ASN1_DN , 518.Dq IPV4 , 519.Dq IPV6 , 520or 521.Dq UFQDN 522that will be used by 523.Xr iked 8 524as the identity of the local peer. 525If the argument is an email address (reyk@example.com), 526.Xr iked 8 527will use UFQDN as the ID type. 528The ASN1_DN type will be used if the string starts with a slash 529.Sq / 530(/C=DE/../CN=10.0.0.1/emailAddress=reyk@example.com). 531If the argument is an IPv4 address or a compressed IPv6 address, 532the ID types IPV4 or IPV6 will be used. 533Anything else is considered to be an FQDN. 534.Pp 535If 536.Ic srcid 537is omitted, 538the default is to use the hostname of the local machine, 539see 540.Xr hostname 1 541to set or print the hostname. 542.Pp 543.Ic dstid 544is similar to 545.Ic srcid , 546but instead specifies the ID to be used 547by the remote peer. 548.It Ic ikelifetime Ar time 549The optional 550.Ic ikelifetime 551parameter defines the IKE SA expiration timeout by the 552.Ar time 553SA was created. 554A zero value disables active IKE SA rekeying. 555This is the default. 556.Pp 557The accepted format of the 558.Ar time 559specification is described below. 560.It Ic lifetime Ar time Op Ic bytes Ar bytes 561The optional 562.Ic lifetime 563parameter defines the Child SA expiration timeout by the 564.Ar time 565SA was in use and by the number of 566.Ar bytes 567that were processed using the SA. 568Default values are 3 hours and 512 megabytes which means that SA will be 569rekeyed before reaching the time limit or 512 megabytes of data 570will pass through. 571Zero values disable rekeying. 572.Pp 573Several unit specifiers are recognized (ignoring case): 574.Ql m 575and 576.Ql h 577for minutes and hours, and 578.Ql K , 579.Ql M 580and 581.Ql G 582for kilo-, mega- and gigabytes accordingly. 583.Pp 584Please note that rekeying must happen at least several times a day as 585IPsec security heavily depends on frequent key renewals. 586.It Op Ar ikeauth 587Specify a method to be used to authenticate the remote peer. 588.Xr iked 8 589will automatically determine a method based on public keys or certificates 590configured for the peer. 591.Ar ikeauth 592can be used to override this behaviour. 593Non-psk modes will require setting up certificates and RSA or ECDSA public 594keys; see 595.Xr iked 8 596for more information. 597.Pp 598.Bl -tag -width $domain -compact -offset indent 599.It Ic eap Ar type 600Use EAP to authenticate the initiator. 601The only supported EAP 602.Ar type 603is currently 604.Ar MSCHAP-V2 . 605The responder will use RSA public key authentication. 606.It Ic ecdsa256 607Use ECDSA with a 256-bit elliptic curve key and SHA2-256 for authentication. 608.It Ic ecdsa384 609Use ECDSA with a 384-bit elliptic curve key and SHA2-384 for authentication. 610.It Ic ecdsa521 611Use ECDSA with a 521-bit elliptic curve key and SHA2-512 for authentication. 612.It Ic psk Ar string 613Use a pre-shared key 614.Ar string 615or hex value (starting with 0x) for authentication. 616.It Ic rfc7427 617Only use RFC 7427 signatures for authentication. 618RFC 7427 signatures currently only support SHA2-256 as the hash. 619.It Ic rsa 620Use RSA public key authentication with SHA1 as the hash. 621.El 622.Pp 623The default is to allow any signature authentication. 624.It Ic config Ar option address 625Send one or more optional configuration payloads (CP) to the peer. 626The configuration 627.Ar option 628can be one of the following with the expected address format: 629.Pp 630.Bl -tag -width Ds -compact -offset indent 631.It Ic address Ar address 632Assign a static address on the internal network. 633.It Ic address Ar address/prefix 634Assign a dynamic address on the internal network. 635The address will be assigned from an address pool with the size specified by 636.Ar prefix . 637.It Ic netmask Ar netmask 638The IPv4 netmask of the internal network. 639.It Ic name-server Ar address 640The DNS server address within the internal network. 641.It Ic netbios-server Ar address 642The NetBIOS name server (WINS) within the internal network. 643This option is provided for compatibility with legacy clients. 644.It Ic dhcp-server Ar address 645The address of an internal DHCP server for further configuration. 646.It Ic protected-subnet Ar address/prefix 647The address of an additional IPv4 or IPv6 subnet reachable over the 648gateway. 649This option is used to notify the peer of a subnet behind the gateway (that 650might require a second SA). 651Networks specified in this SA's "from" or "to" options do not need to be 652included. 653.It Ic access-server Ar address 654The address of an internal remote access server. 655.El 656.It Ic tag Ar string 657Add a 658.Xr pf 4 659tag to all packets of IPsec SAs created for this connection. 660This will allow matching packets for this connection by defining 661rules in 662.Xr pf.conf 5 663using the 664.Cm tagged 665keyword. 666.Pp 667The following variables can be used in tags to include information 668from the remote peer on runtime: 669.Pp 670.Bl -tag -width $domain -compact -offset indent 671.It Ar $id 672The 673.Ic dstid 674that was proposed by the remote peer to identify itself. 675It will be expanded to 676.Ar id-value , 677e.g.\& 678.Ar FQDN/foo.example.com . 679To limit the size of the derived tag, 680.Xr iked 8 681will extract the common name 682.Sq CN= 683from ASN1_DN IDs, for example 684.Ar ASN1_ID//C=DE/../CN=10.1.1.1/.. 685will be expanded to 686.Ar 10.1.1.1 . 687.It Ar $eapid 688For a connection using EAP, the identity (username) used by the remote peer. 689.It Ar $domain 690Extract the domain from IDs of type FQDN, UFQDN or ASN1_DN. 691.It Ar $name 692The name of the IKEv2 policy that was configured in 693.Nm 694or automatically generated by 695.Xr iked 8 . 696.El 697.Pp 698For example, if the ID is 699.Ar FQDN/foo.example.com 700or 701.Ar UFQDN/user@example.com , 702.Dq ipsec-$domain 703expands to 704.Dq ipsec-example.com . 705The variable expansion for the 706.Ar tag 707directive occurs only at runtime (not when the file is parsed) 708and must be quoted, or it will be interpreted as a macro. 709.It Ic tap Ar interface 710Send the decapsulated IPsec traffic to the specified 711.Xr enc 4 712.Ar interface 713instead of 714.Ar enc0 715for filtering and monitoring. 716The traffic will be blocked if the specified 717.Ar interface 718does not exist. 719.El 720.Sh PACKET FILTERING 721IPsec traffic appears unencrypted on the 722.Xr enc 4 723interface 724and can be filtered accordingly using the 725.Ox 726packet filter, 727.Xr pf 4 . 728The grammar for the packet filter is described in 729.Xr pf.conf 5 . 730.Pp 731The following components are relevant to filtering IPsec traffic: 732.Bl -ohang -offset indent 733.It external interface 734Interface for IKE traffic and encapsulated IPsec traffic. 735.It proto udp port 500 736IKE traffic on the external interface. 737.It proto udp port 4500 738IKE NAT-Traversal traffic on the external interface. 739.It proto ah | esp 740Encapsulated IPsec traffic 741on the external interface. 742.It enc0 743Default interface for outgoing traffic before it's been encapsulated, 744and incoming traffic after it's been decapsulated. 745State on this interface should be interface bound; 746see 747.Xr enc 4 748for further information. 749.It proto ipencap 750[tunnel mode only] 751IP-in-IP traffic flowing between gateways 752on the enc0 interface. 753.It tagged ipsec-example.org 754Match traffic of IPsec SAs using the 755.Ic tag 756keyword. 757.El 758.Pp 759If the filtering rules specify to block everything by default, 760the following rule 761would ensure that IPsec traffic never hits the packet filtering engine, 762and is therefore passed: 763.Bd -literal -offset indent 764set skip on enc0 765.Ed 766.Pp 767In the following example, all traffic is blocked by default. 768IPsec-related traffic from gateways {192.168.3.1, 192.168.3.2} and 769networks {10.0.1.0/24, 10.0.2.0/24} is permitted. 770.Bd -literal -offset indent 771block on ix0 772block on enc0 773 774pass in on ix0 proto udp from 192.168.3.2 to 192.168.3.1 \e 775 port {500, 4500} 776pass out on ix0 proto udp from 192.168.3.1 to 192.168.3.2 \e 777 port {500, 4500} 778 779pass in on ix0 proto esp from 192.168.3.2 to 192.168.3.1 780pass out on ix0 proto esp from 192.168.3.1 to 192.168.3.2 781 782pass in on enc0 proto ipencap from 192.168.3.2 to 192.168.3.1 \e 783 keep state (if-bound) 784pass out on enc0 proto ipencap from 192.168.3.1 to 192.168.3.2 \e 785 keep state (if-bound) 786pass in on enc0 from 10.0.2.0/24 to 10.0.1.0/24 \e 787 keep state (if-bound) 788pass out on enc0 from 10.0.1.0/24 to 10.0.2.0/24 \e 789 keep state (if-bound) 790.Ed 791.Pp 792.Xr pf 4 793has the ability to filter IPsec-related packets 794based on an arbitrary 795.Em tag 796specified within a ruleset. 797The tag is used as an internal marker 798which can be used to identify the packets later on. 799This could be helpful, 800for example, 801in scenarios where users are connecting in from differing IP addresses, 802or to support queue-based bandwidth control, 803since the enc0 interface does not support it. 804.Pp 805The following 806.Xr pf.conf 5 807fragment uses queues for all IPsec traffic with special 808handling for developers and employees: 809.Bd -literal -offset indent 810queue std on ix0 bandwidth 100M 811queue deflt parent std bandwidth 10M default 812queue developers parent std bandwidth 75M 813queue employees parent std bandwidth 5M 814queue ipsec parent std bandwidth 10M 815 816pass out on ix0 proto esp set queue ipsec 817 818pass out on ix0 tagged ipsec-developers.example.com \e 819 set queue developers 820pass out on ix0 tagged ipsec-employees.example.com \e 821 set queue employees 822.Ed 823.Pp 824The following example assigns the tags in the 825.Nm 826configuration and also sets an alternative 827.Xr enc 4 828device: 829.Bd -literal -offset indent 830ikev2 esp from 10.1.1.0/24 to 10.1.2.0/24 peer 192.168.3.2 \e 831 tag "ipsec-$domain" tap "enc1" 832.Ed 833.Sh OUTGOING NETWORK ADDRESS TRANSLATION 834In some network topologies it is desirable to perform NAT on traffic leaving 835through the VPN tunnel. 836In order to achieve that, 837the 838.Ar src 839argument is used to negotiate the desired network ID with the peer 840and the 841.Ar srcnat 842parameter defines the true local subnet, 843so that a correct SA can be installed on the local side. 844.Pp 845For example, 846if the local subnet is 192.168.1.0/24 and all the traffic 847for a specific VPN peer should appear as coming from 10.10.10.1, 848the following configuration is used: 849.Bd -literal -offset indent 850ikev2 esp from 10.10.10.1 (192.168.1.0/24) to 192.168.2.0/24 \e 851 peer 10.10.20.1 852.Ed 853.Pp 854Naturally, 855a relevant NAT rule is required in 856.Xr pf.conf 5 . 857For the example above, 858this would be: 859.Bd -literal -offset indent 860match out on enc0 from 192.168.1.0/24 to 192.168.2.0/24 \e 861 nat-to 10.10.10.1 862.Ed 863.Pp 864From the peer's point of view, 865the local end of the VPN tunnel is declared to be 10.10.10.1 866and all the traffic arrives with that source address. 867.Sh CRYPTO TRANSFORMS 868The following authentication types are permitted with the 869.Ic auth 870keyword: 871.Bl -column "Authentication" "Key Length" "Truncated Length" "Default" -offset indent 872.It Em "Authentication" Ta Em "Key Length" Ta Em "Truncated Length" Ta Em "Default" 873.It Li hmac-md5 Ta "128 bits" Ta "96 bits" Ta "" 874.It Li hmac-sha1 Ta "160 bits" Ta "96 bits" Ta "x" 875.It Li hmac-sha2-256 Ta "256 bits" Ta "128 bits" Ta "x" 876.It Li hmac-sha2-384 Ta "384 bits" Ta "192 bits" Ta "" 877.It Li hmac-sha2-512 Ta "512 bits" Ta "256 bits" Ta "" 878.El 879.Pp 880The following pseudo-random function types are permitted with the 881.Ic prf 882keyword: 883.Bl -column "hmac-sha2-512" "Key Length" "Default" "[IKE only]" -offset indent 884.It Em "PRF" Ta Em "Key Length" Ta Em "Default" Ta "" 885.It Li hmac-md5 Ta "128 bits" Ta "" Ta "[IKE only]" 886.It Li hmac-sha1 Ta "160 bits" Ta "x" Ta "[IKE only]" 887.It Li hmac-sha2-256 Ta "256 bits" Ta "x" Ta "[IKE only]" 888.It Li hmac-sha2-384 Ta "384 bits" Ta "" Ta "[IKE only]" 889.It Li hmac-sha2-512 Ta "512 bits" Ta "" Ta "[IKE only]" 890.El 891.Pp 892The following cipher types are permitted with the 893.Ic enc 894keyword: 895.Bl -column "chacha20-poly1305" "Key Length" "Default" "[ESP only]" -offset indent 896.It Em "Cipher" Ta Em "Key Length" Ta Em "Default" Ta "" 897.It Li 3des Ta "168 bits" Ta "x" Ta "" 898.It Li aes-128 Ta "128 bits" Ta "x" Ta "" 899.It Li aes-192 Ta "192 bits" Ta "x" Ta "" 900.It Li aes-256 Ta "256 bits" Ta "x" Ta "" 901.It Li aes-128-ctr Ta "160 bits" Ta "" Ta "[ESP only]" 902.It Li aes-192-ctr Ta "224 bits" Ta "" Ta "[ESP only]" 903.It Li aes-256-ctr Ta "288 bits" Ta "" Ta "[ESP only]" 904.It Li aes-128-gcm Ta "160 bits" Ta "x" Ta "" 905.It Li aes-192-gcm Ta "224 bits" Ta "" Ta "[ESP only]" 906.It Li aes-256-gcm Ta "288 bits" Ta "x" Ta "" 907.It Li aes-128-gcm-12 Ta "160 bits" Ta "" Ta "[IKE only]" 908.It Li aes-256-gcm-12 Ta "288 bits" Ta "" Ta "[IKE only]" 909.It Li blowfish Ta "160 bits" Ta "" Ta "[ESP only]" 910.It Li cast Ta "128 bits" Ta "" Ta "[ESP only]" 911.It Li chacha20-poly1305 Ta "288 bits" Ta "" Ta "[ESP only]" 912.El 913.Pp 914The following cipher types provide only authentication, 915not encryption: 916.Bl -column "chacha20-poly1305" "Key Length" "Default" "[ESP only]" -offset indent 917.It Li aes-128-gmac Ta "160 bits" Ta "" Ta "[ESP only]" 918.It Li aes-192-gmac Ta "224 bits" Ta "" Ta "[ESP only]" 919.It Li aes-256-gmac Ta "288 bits" Ta "" Ta "[ESP only]" 920.It Li null Ta "" Ta "" Ta "[ESP only]" 921.El 922.Pp 923The Extended Sequence Numbers option can be enabled or disabled with the 924.Ic esn 925or 926.Ic noesn 927keywords: 928.Bl -column "noesn" "Default" "[ESP only]" -offset indent 929.It Em ESN Ta Em "Default" Ta Em "" 930.It Li esn Ta "x" Ta "[ESP only]" 931.It Li noesn Ta "x" Ta "[ESP only]" 932.El 933.Pp 934Transforms followed by 935.Bq IKE only 936can only be used with the 937.Ic ikesa 938keyword, transforms with 939.Bq ESP only 940can only be used with the 941.Ic childsa 942keyword. 943.Pp 9443DES requires 24 bytes to form its 168-bit key. 945This is because the most significant bit of each byte is used for parity. 946.Pp 947The keysize of AES-CTR is actually 128-bit. 948However as well as the key, a 32-bit nonce has to be supplied. 949Thus 160 bits of key material have to be supplied. 950The same applies to AES-GCM, AES-GMAC and Chacha20-Poly1305, 951however in the latter case the keysize is 256 bit. 952.Pp 953Using AES-GMAC or NULL with ESP will only provide authentication. 954This is useful in setups where AH cannot be used, e.g. when NAT is involved. 955.Pp 956The following group types are permitted with the 957.Ic group 958keyword: 959.Bl -column "brainpool224" "Group" "Size" "Curve25519" "Default" -offset indent 960.It Em Name Ta Em Group Ta Em Size Ta Em Type Ta Em Default 961.It Li modp768 Ta grp1 Ta 768 Ta "MODP" Ta "" Ta "[insecure]" 962.It Li modp1024 Ta grp2 Ta 1024 Ta "MODP" Ta "x" Ta "[weak]" 963.It Li modp1536 Ta grp5 Ta 1536 Ta "MODP" Ta "x" Ta "[weak]" 964.It Li modp2048 Ta grp14 Ta 2048 Ta "MODP" Ta "x" 965.It Li modp3072 Ta grp15 Ta 3072 Ta "MODP" Ta "x" 966.It Li modp4096 Ta grp16 Ta 4096 Ta "MODP" Ta "x" 967.It Li modp6144 Ta grp17 Ta 6144 Ta "MODP" Ta "" 968.It Li modp8192 Ta grp18 Ta 8192 Ta "MODP" Ta "" 969.It Li ecp256 Ta grp19 Ta 256 Ta "ECP" Ta "x" 970.It Li ecp384 Ta grp20 Ta 384 Ta "ECP" Ta "x" 971.It Li ecp521 Ta grp21 Ta 521 Ta "ECP" Ta "x" 972.It Li ecp192 Ta grp25 Ta 192 Ta "ECP" Ta "" 973.It Li ecp224 Ta grp26 Ta 224 Ta "ECP" Ta "" 974.It Li brainpool224 Ta grp27 Ta 224 Ta "ECP" Ta "" 975.It Li brainpool256 Ta grp28 Ta 256 Ta "ECP" Ta "" 976.It Li brainpool384 Ta grp29 Ta 384 Ta "ECP" Ta "" 977.It Li brainpool512 Ta grp30 Ta 512 Ta "ECP" Ta "" 978.It Li curve25519 Ta grp31 Ta 256 Ta "Curve25519" Ta "x" 979.El 980.Pp 981The currently supported group types are either 982MODP (exponentiation groups modulo a prime), 983ECP (elliptic curve groups modulo a prime), 984or Curve25519. 985Please note that MODP groups of less than 2048 bits are considered 986as weak or insecure (see RFC 8247 section 2.4) and only provided for 987backwards compatibility. 988.Sh FILES 989.Bl -tag -width /etc/examples/iked.conf -compact 990.It Pa /etc/iked.conf 991.It Pa /etc/examples/iked.conf 992.El 993.Sh EXAMPLES 994The first example is intended for a server with clients connecting to 995.Xr iked 8 996as an IPsec gateway, or IKEv2 responder, using mutual public key 997authentication and additional challenge-based EAP-MSCHAPv2 password 998authentication: 999.Bd -literal -offset indent 1000user "test" "password123" 1001 1002ikev2 "win7" esp \e 1003 from 0.0.0.0/0 to 172.16.2.0/24 \e 1004 peer 10.0.0.0/8 local 192.168.56.0/24 \e 1005 eap "mschap-v2" \e 1006 config address 172.16.2.1 \e 1007 tag "$name-$id" 1008.Ed 1009.Pp 1010The next example allows peers to authenticate using a pre-shared key 1011.Sq foobar : 1012.Bd -literal -offset indent 1013ikev2 "big test" \e 1014 esp proto tcp \e 1015 from 10.0.0.0/8 port 23 to 20.0.0.0/8 port 40 \e 1016 from 192.168.1.1 to 192.168.2.2 \e 1017 peer any local any \e 1018 ikesa \e 1019 enc 3des auth hmac-sha2-256 \e 1020 group ecp256 group modp1024 \e 1021 ikesa \e 1022 enc 3des auth hmac-sha1 \e 1023 group ecp256 group modp1024 \e 1024 childsa enc aes-128 auth hmac-sha2-256 \e 1025 childsa enc aes-128 auth hmac-sha1 \e 1026 srcid host.example.com \e 1027 dstid 192.168.0.254 \e 1028 psk "foobar" 1029.Ed 1030.Pp 1031The following example illustrates the last matching policy 1032evaluation for incoming connections on an IKEv2 gateway. 1033The peer 192.168.1.34 will always match the first policy because of the 1034.Ar quick 1035keyword; 1036connections from the peers 192.168.1.3 and 192.168.1.2 will be matched 1037by one of the last two policies; 1038any other connections from 192.168.1.0/24 will be matched by the 1039.Sq subnet 1040policy; 1041and any other connection will be matched by the 1042.Sq catch all 1043policy. 1044.Bd -literal -offset indent 1045ikev2 quick esp from 10.10.10.0/24 to 10.20.20.0/24 \e 1046 peer 192.168.1.34 1047ikev2 "catch all" esp from 10.0.1.0/24 to 10.0.2.0/24 \e 1048 peer any 1049ikev2 "subnet" esp from 10.0.3.0/24 to 10.0.4.0/24 \e 1050 peer 192.168.1.0/24 1051ikev2 esp from 10.0.5.0/30 to 10.0.5.4/30 peer 192.168.1.2 1052ikev2 esp from 10.0.5.8/30 to 10.0.5.12/30 peer 192.168.1.3 1053.Ed 1054.Pp 1055This example encrypts a 1056.Xr gre 4 1057tunnel from local machine A (2001:db8::aa:1) to peer D (2001:db8::dd:4) based on 1058FQDN-based public key authentication; 1059.Ar transport 1060mode avoids double encapsulation: 1061.Bd -literal -offset indent 1062ikev2 transport \e 1063 proto gre \e 1064 from 2001:db8::aa:1 to 2001:db8::dd:4 \e 1065 peer D.example.com 1066.Ed 1067.Sh SEE ALSO 1068.Xr enc 4 , 1069.Xr ipsec 4 , 1070.Xr ipsec.conf 5 , 1071.Xr pf.conf 5 , 1072.Xr ikectl 8 , 1073.Xr iked 8 1074.Sh HISTORY 1075The 1076.Nm 1077file format first appeared in 1078.Ox 4.8 . 1079.Sh AUTHORS 1080The 1081.Xr iked 8 1082program was written by 1083.An Reyk Floeter Aq Mt reyk@openbsd.org . 1084