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