1.\" $OpenBSD: ipsec.conf.5,v 1.151 2015/12/09 21:41:50 naddy Exp $ 2.\" 3.\" Copyright (c) 2004 Mathieu Sauve-Frankel All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24.\" 25.Dd $Mdocdate: December 9 2015 $ 26.Dt IPSEC.CONF 5 27.Os 28.Sh NAME 29.Nm ipsec.conf 30.Nd IPsec configuration file 31.Sh DESCRIPTION 32The 33.Nm 34file specifies rules and definitions for IPsec, 35which provides security services for IP datagrams. 36IPsec itself is a pair of protocols: 37Encapsulating Security Payload (ESP), 38which provides integrity and confidentiality; 39and Authentication Header (AH), 40which provides integrity. 41The IPsec protocol itself is described in 42.Xr ipsec 4 . 43.Pp 44In its most basic form, a 45.Em flow 46is established between hosts and/or networks, 47and then Security Associations 48.Pq Em SA 49are established, 50which detail how the desired protection will be achieved. 51IPsec uses flows 52to determine whether to apply security services to an IP packet or not. 53.Pp 54Generally speaking 55an automated keying daemon, 56such as 57.Xr isakmpd 8 , 58is used to set up flows and establish SAs, 59by specifying an 60.Sq ike 61line in 62.Nm 63(see 64.Sx AUTOMATIC KEYING , 65below). 66An authentication method, 67such as public key authentication, 68will also have to be set up: 69see the PKI section of 70.Xr isakmpd 8 71for information on the types of authentication available, 72and the procedures for setting them up. 73.Pp 74The keying daemon, 75.Xr isakmpd 8 , 76can be enabled to run at boot time via the 77.Va isakmpd_flags 78variable in 79.Xr rc.conf.local 8 . 80Note that it will probably need to be run with at least the 81.Fl K 82option, to avoid 83.Xr keynote 4 84policy checking. 85The 86.Nm 87configuration itself is loaded at boot time 88if the variable 89.Va ipsec 90is set to 91.Dv YES 92in 93.Xr rc.conf.local 8 . 94A utility called 95.Xr ipsecctl 8 96is also available to load 97.Nm 98configurations, and can additionally be used 99to view and modify IPsec flows. 100.Pp 101An alternative method of setting up SAs is also possible using 102manual keying. 103Manual keying is not recommended, 104but can be convenient for quick setups and testing. 105Those procedures are documented within this page. 106.Sh IPSEC.CONF FILE FORMAT 107The current line can be extended over multiple lines using a backslash 108.Pq Sq \e . 109Comments can be put anywhere in the file using a hash mark 110.Pq Sq # , 111and extend to the end of the current line. 112Care should be taken when commenting out multi-line text: 113the comment is effective until the end of the entire block. 114.Pp 115Argument names not beginning with a letter, digit, or underscore 116must be quoted. 117.Pp 118Addresses can be specified in CIDR notation (matching netblocks), 119as symbolic host names, interface names, or interface group names. 120.Pp 121Certain parameters can be expressed as lists, in which case 122.Xr ipsecctl 8 123generates all the necessary combinations. 124For example: 125.Bd -literal -offset indent 126ike esp from {192.168.1.1, 192.168.1.2} to \e 127 {10.0.0.17, 10.0.0.18} peer 192.168.10.1 128.Ed 129.Pp 130Will expand to: 131.Bd -literal -offset indent 132ike esp from 192.168.1.1 to 10.0.0.17 peer 192.168.10.1 133ike esp from 192.168.1.1 to 10.0.0.18 peer 192.168.10.1 134ike esp from 192.168.1.2 to 10.0.0.17 peer 192.168.10.1 135ike esp from 192.168.1.2 to 10.0.0.18 peer 192.168.10.1 136.Ed 137.Pp 138Macros can be defined that will later be expanded in context. 139Macro names must start with a letter, digit, or underscore, 140and may contain any of those characters. 141Macro names may not be reserved words (for example 142.Ic flow , 143.Ic from , 144.Ic esp ) . 145Macros are not expanded inside quotes. 146.Pp 147For example: 148.Bd -literal -offset indent 149remote_gw = "192.168.3.12" 150flow esp from 192.168.7.0/24 to 192.168.8.0/24 peer $remote_gw 151.Ed 152.Pp 153Additional configuration files can be included with the 154.Ic include 155keyword, for example: 156.Bd -literal -offset indent 157include "/etc/macros.conf" 158.Ed 159.Sh AUTOMATIC KEYING 160In this scenario, 161.Nm 162is used to set up flows and SAs automatically using 163.Xr isakmpd 8 164with the ISAKMP/Oakley a.k.a. IKEv1 protocol. 165To configure automatic keying using the IKEv2 protocol, see 166.Xr iked.conf 5 167instead. 168Some examples of setting up automatic keying: 169.Bd -literal -offset 3n 170# Set up a VPN: 171# First between the gateway machines 192.168.3.1 and 192.168.3.2 172# Second between the networks 10.1.1.0/24 and 10.1.2.0/24 173ike esp from 192.168.3.1 to 192.168.3.2 174ike esp from 10.1.1.0/24 to 10.1.2.0/24 peer 192.168.3.2 175.Ed 176.Pp 177The commands are as follows: 178.Bl -tag -width xxxx 179.It Xo 180.Ic ike 181.Op Ar mode 182.Op Ar encap 183.Op Ar tmode 184.Xc 185.Ar mode 186specifies the IKEv1 mode to use: 187one of 188.Ar passive , 189.Ar active , 190or 191.Ar dynamic . 192When 193.Ar passive 194is specified, 195.Xr isakmpd 8 196will not immediately start negotiation of this tunnel, but wait for an incoming 197request from the remote peer. 198When 199.Ar active 200or 201.Ar dynamic 202is specified, negotiation will be started at once. 203The 204.Ar dynamic 205mode will additionally enable Dead Peer Detection (DPD) and use the 206local hostname as the identity of the local peer, if not specified by 207the 208.Ic srcid 209parameter. 210.Ar dynamic 211mode should be used for hosts with dynamic IP addresses like road 212warriors or dialup hosts. 213If omitted, 214.Ar active 215mode will be used. 216.Pp 217.Ar encap 218specifies the encapsulation protocol to be used. 219Possible protocols are 220.Ar esp 221and 222.Ar ah ; 223the default is 224.Ar esp . 225.Pp 226.Ar tmode 227describes the encapsulation mode to be used. 228Possible modes are 229.Ar tunnel 230and 231.Ar transport ; 232the default is 233.Ar tunnel . 234.It Ic proto Ar protocol 235The optional 236.Ic proto 237parameter restricts the flow to a specific IP protocol. 238Common protocols are 239.Xr icmp 4 , 240.Xr tcp 4 , 241and 242.Xr udp 4 . 243For a list of all the protocol name to number mappings used by 244.Xr ipsecctl 8 , 245see the file 246.Pa /etc/protocols . 247.It Xo 248.Ic from Ar src 249.Op Ic port Ar sport 250.Op Pq Ar srcnat 251.Ic to Ar dst 252.Op Ic port Ar dport 253.Xc 254This rule applies for packets with source address 255.Ar src 256and destination address 257.Ar dst . 258The keyword 259.Ar any 260will match any address (i.e. 0.0.0.0/0). 261If the 262.Ar src 263argument specifies a fictional source ID, 264the 265.Ar srcnat 266parameter can be used to specify the actual source address. 267This can be used in outgoing NAT/BINAT scenarios as described below in 268.Sx OUTGOING NETWORK ADDRESS TRANSLATION . 269Host addresses are parsed as type 270.Dq IPV4_ADDR ; 271adding the suffix /32 will change the type to 272.Dq IPV4_ADDR_SUBNET , 273which can improve interoperability with some IKEv1 implementations. 274.Pp 275The optional 276.Ic port 277modifiers restrict the flows to the specified ports. 278They are only valid in conjunction with the 279.Xr tcp 4 280and 281.Xr udp 4 282protocols. 283Ports can be specified by number or by name. 284For a list of all port name to number mappings used by 285.Xr ipsecctl 8 , 286see the file 287.Pa /etc/services . 288.It Ic local Ar localip Ic peer Ar remote 289The 290.Ic local 291parameter specifies the address or FQDN of the local endpoint. 292Unless we are multi-homed or have aliases, 293this option is generally not needed. 294.Pp 295The 296.Ic peer 297parameter specifies the address or FQDN of the remote endpoint. 298For host-to-host connections where 299.Ar dst 300is identical to 301.Ar remote , 302this option is generally not needed as it will be set to 303.Ar dst 304automatically. 305If it is not specified or if the keyword 306.Ar any 307is given, the default peer is used. 308.It Xo 309.Ar mode 310.Ic auth Ar algorithm 311.Ic enc Ar algorithm 312.Ic group Ar group 313.Ic lifetime Ar time 314.Xc 315These parameters define the mode and cryptographic transforms to be 316used for the phase 1 negotiation. 317During phase 1 318the machines authenticate and set up an encrypted channel. 319.Pp 320The mode can be either 321.Ar main , 322which specifies main mode, or 323.Ar aggressive , 324which specifies aggressive mode. 325Possible values for 326.Ic auth , 327.Ic enc , 328and 329.Ic group 330are described below in 331.Sx CRYPTO TRANSFORMS . 332.Pp 333The 334.Ic lifetime 335parameter specifies the phase 1 lifetime in seconds. 336Two unit specifiers are recognized (ignoring case): 337.Ql m 338and 339.Ql h 340for minutes and hours, respectively. 341.Pp 342If omitted, 343.Xr ipsecctl 8 344will use the default values 345.Ar main , 346.Ar hmac-sha1 , 347.Ar aes , 348.Ar modp3072 , 349and 350.Ar 3600 . 351.It Xo 352.Ic quick auth Ar algorithm 353.Ic enc Ar algorithm 354.Ic group Ar group 355.Ic lifetime Ar time 356.Xc 357These parameters define the cryptographic transforms to be used for 358the phase 2 negotiation. 359During phase 2 360the actual IPsec negotiations happen. 361.Pp 362Possible values for 363.Ic auth , 364.Ic enc , 365and 366.Ic group 367are described below in 368.Sx CRYPTO TRANSFORMS . 369Perfect Forward Secrecy (PFS) is enabled unless 370.Ic group Ar none 371is specified. 372.Pp 373The 374.Ic lifetime 375parameter specifies the phase 2 lifetime in seconds. 376Two unit specifiers are recognized (ignoring case): 377.Ql m 378and 379.Ql h 380for minutes and hours, respectively. 381.Pp 382If omitted, 383.Xr ipsecctl 8 384will use the default values 385.Ar hmac-sha2-256 386and 387.Ar aes ; 388PFS will only be used if the remote side requests it. 389The default phase 2 lifetime value is 390.Ar 1200 . 391.It Ic srcid Ar string Ic dstid Ar string 392.Ic srcid 393defines an ID of type 394.Dq USER_FQDN 395or 396.Dq FQDN 397that will be used by 398.Xr isakmpd 8 399as the identity of the local peer. 400If the argument is an email address (bob@example.com), 401.Xr ipsecctl 8 402will use USER_FQDN as the ID type. 403Anything else is considered to be an FQDN. 404If 405.Ic srcid 406is omitted, 407the default is to use the IP address of the connecting machine. 408.Pp 409.Ic dstid 410is similar to 411.Ic srcid , 412but instead specifies the ID to be used 413by the remote peer. 414.It Ic psk Ar string 415Use a pre-shared key 416.Ar string 417for authentication. 418If this option is not specified, 419public key authentication is used (see 420.Xr isakmpd 8 ) . 421.It Ic tag Ar string 422Add a 423.Xr pf 4 424tag to all packets of phase 2 SAs created for this connection. 425This will allow matching packets for this connection by defining 426rules in 427.Xr pf.conf 5 428using the 429.Cm tagged 430keyword. 431.Pp 432The following variables can be used in tags to include information 433from the remote peer on runtime: 434.Pp 435.Bl -tag -width $domain -compact -offset indent 436.It Ar $id 437The remote phase 1 ID. 438It will be expanded to 439.Ar id-type/id-value , 440e.g.\& 441.Ar fqdn/foo.bar.org . 442.It Ar $domain 443Extract the domain from IDs of type FQDN or UFQDN. 444.El 445.Pp 446For example, if the ID is 447.Ar fqdn/foo.bar.org 448or 449.Ar ufqdn/user@bar.org , 450.Dq ipsec-$domain 451expands to 452.Dq ipsec-bar.org . 453The variable expansion for the 454.Ar tag 455directive occurs only at runtime, not during configuration file parse time. 456.El 457.Sh PACKET FILTERING 458IPsec traffic appears unencrypted on the 459.Xr enc 4 460interface 461and can be filtered accordingly using the 462.Ox 463packet filter, 464.Xr pf 4 . 465The grammar for the packet filter is described in 466.Xr pf.conf 5 . 467.Pp 468The following components are relevant to filtering IPsec traffic: 469.Bl -ohang -offset indent 470.It external interface 471Interface for ISAKMP traffic and encapsulated IPsec traffic. 472.It proto udp port 500 473ISAKMP traffic on the external interface. 474.It proto udp port 4500 475ISAKMP NAT-Traversal traffic on the external interface. 476.It proto ah | esp 477Encapsulated IPsec traffic 478on the external interface. 479.It enc0 480Interface for outgoing traffic before it's been encapsulated, 481and incoming traffic after it's been decapsulated. 482State on this interface should be interface bound; 483see 484.Xr enc 4 485for further information. 486.It proto ipencap 487[tunnel mode only] 488IP-in-IP traffic flowing between gateways 489on the enc0 interface. 490.It tagged ipsec-example.org 491Match traffic of phase 2 SAs using the 492.Ic tag 493keyword. 494.El 495.Pp 496If the filtering rules specify to block everything by default, 497the following rule 498would ensure that IPsec traffic never hits the packet filtering engine, 499and is therefore passed: 500.Bd -literal -offset indent 501set skip on enc0 502.Ed 503.Pp 504In the following example, all traffic is blocked by default. 505IPsec-related traffic from gateways {192.168.3.1, 192.168.3.2} and 506networks {10.0.1.0/24, 10.0.2.0/24} is permitted. 507.Bd -literal -offset indent 508block on sk0 509block on enc0 510 511pass in on sk0 proto udp from 192.168.3.2 to 192.168.3.1 \e 512 port {500, 4500} 513pass out on sk0 proto udp from 192.168.3.1 to 192.168.3.2 \e 514 port {500, 4500} 515 516pass in on sk0 proto esp from 192.168.3.2 to 192.168.3.1 517pass out on sk0 proto esp from 192.168.3.1 to 192.168.3.2 518 519pass in on enc0 proto ipencap from 192.168.3.2 to 192.168.3.1 \e 520 keep state (if-bound) 521pass out on enc0 proto ipencap from 192.168.3.1 to 192.168.3.2 \e 522 keep state (if-bound) 523pass in on enc0 from 10.0.2.0/24 to 10.0.1.0/24 \e 524 keep state (if-bound) 525pass out on enc0 from 10.0.1.0/24 to 10.0.2.0/24 \e 526 keep state (if-bound) 527.Ed 528.Pp 529.Xr pf 4 530has the ability to filter IPsec-related packets 531based on an arbitrary 532.Em tag 533specified within a ruleset. 534The tag is used as an internal marker 535which can be used to identify the packets later on. 536This could be helpful, 537for example, 538in scenarios where users are connecting in from differing IP addresses, 539or to support queue-based bandwidth control, 540since the enc0 interface does not support it. 541.Pp 542The following 543.Xr pf.conf 5 544fragment uses queues for all IPsec traffic with special 545handling for developers and employees: 546.Bd -literal -offset indent 547queue std on sk0 bandwidth 100M 548queue deflt parent std bandwidth 10M default 549queue developers parent std bandwidth 75M 550queue employees parent std bandwidth 5M 551queue ipsec parent std bandwidth 10M 552 553pass out on sk0 proto esp set queue ipsec 554 555pass out on sk0 tagged ipsec-developers.bar.org set queue developers 556pass out on sk0 tagged ipsec-employees.bar.org set queue employees 557.Ed 558.Pp 559The tags will be assigned by the following 560.Nm 561example: 562.Bd -literal -offset indent 563ike esp from 10.1.1.0/24 to 10.1.2.0/24 peer 192.168.3.2 \e 564 tag ipsec-$domain 565.Ed 566.Sh OUTGOING NETWORK ADDRESS TRANSLATION 567In some network topologies it is desirable to perform NAT on traffic leaving 568through the VPN tunnel. 569In order to achieve that, 570the 571.Ar src 572argument is used to negotiate the desired network ID with the peer 573and the 574.Ar srcnat 575parameter defines the true local subnet, 576so that a correct SA can be installed on the local side. 577.Pp 578For example, 579if the local subnet is 192.168.1.0/24 and all the traffic 580for a specific VPN peer should appear as coming from 10.10.10.1, 581the following configuration is used: 582.Bd -literal -offset indent 583ike esp from 10.10.10.1 (192.168.1.0/24) to 192.168.2.0/24 \e 584 peer 10.10.20.1 585.Ed 586.Pp 587Naturally, 588a relevant NAT rule is required in 589.Xr pf.conf 5 . 590For the example above, 591this would be: 592.Bd -literal -offset indent 593match out on enc0 from 192.168.1.0/24 to 192.168.2.0/24 \e 594 nat-to 10.10.10.1 595.Ed 596.Pp 597From the peer's point of view, 598the local end of the VPN tunnel is declared to be 10.10.10.1 599and all the traffic arrives with that source address. 600.Sh CRYPTO TRANSFORMS 601It is very important that keys are not guessable. 602One practical way of generating keys is to use 603.Xr openssl 1 . 604The following generates a 160-bit (20-byte) key: 605.Bd -literal -offset indent 606$ openssl rand -hex 20 607.Ed 608.Pp 609The following authentication types are permitted with the 610.Ic auth 611keyword: 612.Bl -column "Authentication" "Key Length" "Description" -offset indent 613.It Em "Authentication" Ta Em "Key Length" Ta "" 614.It Li hmac-md5 Ta "128 bits" Ta "" 615.It Li hmac-ripemd160 Ta "160 bits" Ta "[phase 2 only]" 616.It Li hmac-sha1 Ta "160 bits" Ta "" 617.It Li hmac-sha2-256 Ta "256 bits" Ta "" 618.It Li hmac-sha2-384 Ta "384 bits" Ta "" 619.It Li hmac-sha2-512 Ta "512 bits" Ta "" 620.El 621.Pp 622The following cipher types are permitted with the 623.Ic enc 624keyword: 625.Bl -column "aes-128-gmac" "Key Length" "Description" -offset indent 626.It Em "Cipher" Ta Em "Key Length" Ta "" 627.It Li 3des Ta "168 bits" Ta "" 628.It Li aes Ta "128 bits" Ta "" 629.It Li aes-128 Ta "128 bits" Ta "" 630.It Li aes-192 Ta "192 bits" Ta "" 631.It Li aes-256 Ta "256 bits" Ta "" 632.It Li aesctr Ta "160 bits" Ta "[phase 2 only, IKE only]" 633.It Li aes-128-ctr Ta "160 bits" Ta "[phase 2 only, IKE only]" 634.It Li aes-192-ctr Ta "224 bits" Ta "[phase 2 only, IKE only]" 635.It Li aes-256-ctr Ta "288 bits" Ta "[phase 2 only, IKE only]" 636.It Li aes-128-gcm Ta "160 bits" Ta "[phase 2 only, IKE only]" 637.It Li aes-192-gcm Ta "224 bits" Ta "[phase 2 only, IKE only]" 638.It Li aes-256-gcm Ta "288 bits" Ta "[phase 2 only, IKE only]" 639.It Li aes-128-gmac Ta "160 bits" Ta "[phase 2 only, IKE only]" 640.It Li aes-192-gmac Ta "224 bits" Ta "[phase 2 only, IKE only]" 641.It Li aes-256-gmac Ta "288 bits" Ta "[phase 2 only, IKE only]" 642.It Li blowfish Ta "160 bits" Ta "" 643.It Li cast Ta "128 bits" Ta "" 644.It Li null Ta "(none)" Ta "[phase 2 only]" 645.El 646.Pp 6473DES requires 24 bytes to form its 168-bit key. 648This is because the most significant bit of each byte is used for parity. 649.Pp 650The keysize of AES-CTR can be 128, 192, or 256 bits. 651However as well as the key, a 32-bit nonce has to be supplied. 652Thus 160, 224, or 288 bits of key material, respectively, have to be supplied. 653The same applies to AES-GCM and AES-GMAC. 654.Pp 655Using AES-GMAC or NULL with ESP will only provide authentication. 656This is useful in setups where AH cannot be used, e.g. when NAT is involved. 657.Pp 658The following group types are permitted with the 659.Ic group 660keyword: 661.Bl -column "modp1024" "Size" "Description" -offset indent 662.It Em Group Ta Em Size Ta "" 663.It Li modp768 Ta 768 Ta "[DH group 1]" 664.It Li modp1024 Ta 1024 Ta "[DH group 2]" 665.It Li modp1536 Ta 1536 Ta "[DH group 5]" 666.It Li modp2048 Ta 2048 Ta "[DH group 14]" 667.It Li modp3072 Ta 3072 Ta "[DH group 15]" 668.It Li modp4096 Ta 4096 Ta "[DH group 16]" 669.It Li modp6144 Ta 6144 Ta "[DH group 17]" 670.It Li modp8192 Ta 8192 Ta "[DH group 18]" 671.It Li none Ta 0 Ta "[phase 2 only]" 672.El 673.Sh MANUAL FLOWS 674In this scenario, 675.Nm 676is used to set up flows manually. 677IPsec uses flows 678to determine whether to apply security services to an IP packet or not. 679Some examples of setting up flows: 680.Bd -literal -offset 3n 681# Set up two flows: 682# First between the machines 192.168.3.14 and 192.168.3.100 683# Second between the networks 192.168.7.0/24 and 192.168.8.0/24 684flow esp from 192.168.3.14 to 192.168.3.100 685flow esp from 192.168.7.0/24 to 192.168.8.0/24 peer 192.168.3.12 686.Ed 687.Pp 688The following types of flow are available: 689.Bl -tag -width xxxx 690.It Ic flow esp 691ESP can provide the following properties: 692authentication, integrity, replay protection, and confidentiality of the data. 693If no flow type is specified, 694this is the default. 695.It Ic flow ah 696AH provides authentication, integrity, and replay protection, but not 697confidentiality. 698.It Ic flow ipip 699IPIP does not provide authentication, integrity, replay protection, or 700confidentiality. 701However, it does allow tunnelling of IP traffic over IP, without setting up 702.Xr gif 4 703interfaces. 704.El 705.Pp 706The commands are as follows: 707.Bl -tag -width xxxx 708.It Ic in No or Ic out 709This rule applies to incoming or outgoing packets. 710If neither 711.Ic in 712nor 713.Ic out 714are specified, 715.Xr ipsecctl 8 716will assume the direction 717.Ic out 718for this rule and will construct a proper 719.Ic in 720rule. 721Thus packets in both directions will be matched. 722.It Ic proto Ar protocol 723The optional 724.Ic proto 725parameter restricts the flow to a specific IP protocol. 726Common protocols are 727.Xr icmp 4 , 728.Xr tcp 4 , 729and 730.Xr udp 4 . 731For a list of all the protocol name to number mappings used by 732.Xr ipsecctl 8 , 733see the file 734.Pa /etc/protocols . 735.It Xo 736.Ic from Ar src 737.Op Ic port Ar sport 738.Ic to Ar dst 739.Op Ic port Ar dport 740.Xc 741This rule applies for packets with source address 742.Ar src 743and destination address 744.Ar dst . 745The keyword 746.Ar any 747will match any address (i.e. 0.0.0.0/0). 748The optional 749.Ic port 750modifiers restrict the flows to the specified ports. 751They are only valid in conjunction with the 752.Xr tcp 4 753and 754.Xr udp 4 755protocols. 756Ports can be specified by number or by name. 757For a list of all port name to number mappings used by 758.Xr ipsecctl 8 , 759see the file 760.Pa /etc/services . 761.It Ic local Ar localip 762The 763.Ic local 764parameter specifies the address or FQDN of the local endpoint of this 765flow and can be usually left out. 766.It Ic peer Ar remote 767The 768.Ic peer 769parameter specifies the address or FQDN of the remote endpoint of this 770flow. 771For host-to-host connections where 772.Ar dst 773is identical to 774.Ar remote , 775the 776.Ic peer 777specification can be left out as it will be set to 778.Ar dst 779automatically. 780Only if the keyword 781.Ar any 782is given is a flow without peer created. 783.It Ic type Ar modifier 784This optional parameter sets up special flows using modifiers. 785By default, 786.Xr ipsecctl 8 787will automatically set up normal flows with the corresponding type. 788.Ar modifier 789may be one of the following: 790.Pp 791.Bl -tag -width "acquireXX" -offset indent -compact 792.It acquire 793Use IPsec and establish SAs dynamically. 794Unencrypted traffic is permitted until it is protected by IPsec. 795.It bypass 796Matching packets are not processed by IPsec. 797.It deny 798Matching packets are dropped. 799.It dontacq 800Use IPsec. 801If no SAs are available, 802does not trigger 803.Xr isakmpd 8 . 804.It require 805Use IPsec and establish SAs dynamically. 806Unencrypted traffic is not permitted until it is protected by IPsec. 807.It use 808Use IPsec. 809Unencrypted traffic is permitted. 810Does not trigger 811.Xr isakmpd 8 . 812.El 813.El 814.Sh MANUAL SECURITY ASSOCIATIONS (SAs) 815In this scenario, 816.Nm 817is used to set up SAs manually. 818The security parameters for a flow 819are stored in the Security Association Database (SADB). 820An example of setting up an SA: 821.Bd -literal -offset 3n 822# Set up an IPsec SA for flows between 192.168.3.14 and 192.168.3.12 823esp from 192.168.3.14 to 192.168.3.12 spi 0xdeadbeef:0xbeefdead \e 824 authkey file "auth14:auth12" enckey file "enc14:enc12" 825.Ed 826.Pp 827Parameters specify the peers, Security Parameter Index (SPI), 828cryptographic transforms, and key material to be used. 829The following rules enter SAs in the SADB: 830.Pp 831.Bl -tag -width "tcpmd5XX" -offset indent -compact 832.It Ic esp 833Enter an ESP SA. 834.It Ic ah 835Enter an AH SA. 836.It Ic ipcomp 837Enter an IPCOMP SA. 838.It Ic ipip 839Enter an IPIP pseudo SA. 840.It Ic tcpmd5 841Enter a TCP MD5 SA. 842.El 843.Pp 844The commands are as follows: 845.Bl -tag -width xxxx 846.It Ar mode 847For ESP and AH 848.\".Ic ipcomp 849the encapsulation mode can be specified. 850Possible modes are 851.Ar tunnel 852and 853.Ar transport . 854When left out, 855.Ar tunnel 856is chosen. 857For details on modes see 858.Xr ipsec 4 . 859.It Ic from Ar src Ic to Ar dst 860This SA is for a 861.Ar flow 862between the peers 863.Ar src 864and 865.Ar dst . 866.It Ic spi Ar number 867The SPI identifies a specific SA. 868.Ar number 869is a 32-bit value and needs to be unique. 870.It Ic auth Ar algorithm 871For ESP and AH 872an authentication algorithm can be specified. 873Possible values 874are described above in 875.Sx CRYPTO TRANSFORMS . 876.Pp 877If no algorithm is specified, 878.Xr ipsecctl 8 879will choose 880.Ar hmac-sha2-256 881by default. 882.\".It Xo 883.\".Ic comp 884.\".Aq Ar algorithm 885.\".Xc 886.\"The compression algorithm to be used. 887.\"Possible algorithms are 888.\".Ar deflate 889.\"and 890.\".Ar lzs . 891.\"Note that 892.\".Ar lzs 893.\"is only available with 894.\".Xr hifn 4 895.\"because of the patent held by Hifn, Inc. 896.It Ic enc Ar algorithm 897For ESP 898an encryption algorithm can be specified. 899Possible values 900are described above in 901.Sx CRYPTO TRANSFORMS . 902.Pp 903If no algorithm is specified, 904.Xr ipsecctl 8 905will choose 906.Ar aes 907by default. 908.It Ic authkey Ar keyspec 909.Ar keyspec 910defines the authentication key to be used. 911It is either a hexadecimal string or a path to a file containing the key. 912The filename may be given as either an absolute path to the file 913or a relative pathname, 914and is specified as follows: 915.Bd -literal -offset indent 916authkey file "filename" 917.Ed 918.It Ic enckey Ar keyspec 919The encryption key is defined similarly to 920.Ic authkey . 921.It Xo 922.Ic tcpmd5 923.Ic from Ar src 924.Ic to Ar dst 925.Ic spi Ar number 926.Ic authkey Ar keyspec 927.Xc 928TCP MD5 signatures are generally used between BGP daemons, such as 929.Xr bgpd 8 . 930Since 931.Xr bgpd 8 932itself already provides this functionality, 933this option is generally not needed. 934More information on TCP MD5 signatures can be found in 935.Xr tcp 4 , 936.Xr bgpd.conf 5 , 937and RFC 2385. 938.Pp 939This rule applies for packets with source address 940.Ar src 941and destination address 942.Ar dst . 943The parameter 944.Ic spi 945is a 32-bit value defining the Security Parameter Index (SPI) for this SA. 946The encryption key is defined similarly to 947.Ic authkey . 948.El 949.Pp 950Since an SA is directional, a second SA is normally configured in the 951reverse direction. 952This is done by adding a second, colon-separated, value to 953.Ic spi , 954.Ic authkey , 955and 956.Ic enckey . 957.Sh SEE ALSO 958.Xr openssl 1 , 959.Xr enc 4 , 960.Xr ipcomp 4 , 961.Xr ipsec 4 , 962.Xr tcp 4 , 963.Xr pf.conf 5 , 964.Xr ipsecctl 8 , 965.Xr isakmpd 8 966.Sh HISTORY 967The 968.Nm 969file format first appeared in 970.Ox 3.8 . 971