1.\" $KAME: setkey.8,v 1.89 2003/09/07 22:17:41 itojun Exp $ 2.\" $FreeBSD$ 3.\" 4.\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the project nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.Dd November 20, 2000 32.Dt SETKEY 8 33.Os 34.\" 35.Sh NAME 36.Nm setkey 37.Nd manually manipulate the IPsec SA/SP database 38.\" 39.Sh SYNOPSIS 40.Nm 41.Op Fl v 42.Fl c 43.Nm 44.Op Fl v 45.Fl f Ar filename 46.Nm 47.Op Fl aPlv 48.Fl D 49.Nm 50.Op Fl Pv 51.Fl F 52.Nm 53.Op Fl h 54.Fl x 55.\" 56.Sh DESCRIPTION 57The 58.Nm 59command adds, updates, dumps, or flushes 60Security Association Database (SAD) entries 61as well as Security Policy Database (SPD) entries in the kernel. 62.Pp 63The 64.Nm 65command takes a series of operations from the standard input 66.Po 67if invoked with 68.Fl c 69.Pc 70or the file named 71.Ar filename 72.Po 73if invoked with 74.Fl f Ar filename 75.Pc . 76.Bl -tag -width Ds 77.It Fl D 78Dump the SAD entries. 79If with 80.Fl P , 81the SPD entries are dumped. 82.It Fl F 83Flush the SAD entries. 84If with 85.Fl P , 86the SPD entries are flushed. 87.It Fl a 88.Nm 89usually does not display dead SAD entries with 90.Fl D . 91If with 92.Fl a , 93the dead SAD entries will be displayed as well. 94A dead SAD entry means that 95it has been expired but remains in the system 96because it is referenced by some SPD entries. 97.It Fl h 98Add hexadecimal dump on 99.Fl x 100mode. 101.It Fl l 102Loop forever with short output on 103.Fl D . 104.It Fl v 105Be verbose. 106The program will dump messages exchanged on 107.Dv PF_KEY 108socket, including messages sent from other processes to the kernel. 109.It Fl x 110Loop forever and dump all the messages transmitted to 111.Dv PF_KEY 112socket. 113.Fl xx 114makes each timestamps unformatted. 115.El 116.Ss Configuration syntax 117With 118.Fl c 119or 120.Fl f 121on the command line, 122.Nm 123accepts the following configuration syntax. 124Lines starting with hash signs ('#') are treated as comment lines. 125.Bl -tag -width Ds 126.It Xo 127.Li add 128.Op Fl 46n 129.Ar src Ar dst Ar protocol Ar spi 130.Op Ar extensions 131.Ar algorithm ... 132.Li ; 133.Xc 134Add an SAD entry. 135.Li add 136can fail with multiple reasons, 137including when the key length does not match the specified algorithm. 138.\" 139.It Xo 140.Li get 141.Op Fl 46n 142.Ar src Ar dst Ar protocol Ar spi 143.Li ; 144.Xc 145Show an SAD entry. 146.\" 147.It Xo 148.Li delete 149.Op Fl 46n 150.Ar src Ar dst Ar protocol Ar spi 151.Li ; 152.Xc 153Remove an SAD entry. 154.\" 155.It Xo 156.Li deleteall 157.Op Fl 46n 158.Ar src Ar dst Ar protocol 159.Li ; 160.Xc 161Remove all SAD entries that match the specification. 162.\" 163.It Xo 164.Li flush 165.Op Ar protocol 166.Li ; 167.Xc 168Clear all SAD entries matched by the options. 169.Fl F 170on the command line achieves the same functionality. 171.\" 172.It Xo 173.Li dump 174.Op Ar protocol 175.Li ; 176.Xc 177Dumps all SAD entries matched by the options. 178.Fl D 179on the command line achieves the same functionality. 180.\" 181.It Xo 182.Li spdadd 183.Op Fl 46n 184.Ar src_range Ar dst_range Ar upperspec Ar policy 185.Li ; 186.Xc 187Add an SPD entry. 188.\" 189.It Xo 190.Li spddelete 191.Op Fl 46n 192.Ar src_range Ar dst_range Ar upperspec Fl P Ar direction 193.Li ; 194.Xc 195Delete an SPD entry. 196.\" 197.It Xo 198.Li spdflush 199.Li ; 200.Xc 201Clear all SPD entries. 202.Fl FP 203on the command line achieves the same functionality. 204.\" 205.It Xo 206.Li spddump 207.Li ; 208.Xc 209Dumps all SPD entries. 210.Fl DP 211on the command line achieves the same functionality. 212.El 213.\" 214.Pp 215Meta-arguments are as follows: 216.Pp 217.Bl -tag -compact -width Ds 218.It Ar src 219.It Ar dst 220Source/destination of the secure communication is specified as 221IPv4/v6 address. 222.Nm 223can resolve a FQDN into numeric addresses. 224If the FQDN resolves into multiple addresses, 225.Nm 226will install multiple SAD/SPD entries into the kernel 227by trying all possible combinations. 228.Fl 4 , 229.Fl 6 230and 231.Fl n 232restricts the address resolution of FQDN in certain ways. 233.Fl 4 234and 235.Fl 6 236restrict results into IPv4/v6 addresses only, respectively. 237.Fl n 238avoids FQDN resolution and requires addresses to be numeric addresses. 239.\" 240.Pp 241.It Ar protocol 242.Ar protocol 243is one of following: 244.Bl -tag -width Fl -compact 245.It Li esp 246ESP based on rfc2406 247.It Li esp-old 248ESP based on rfc1827 249.It Li ah 250AH based on rfc2402 251.It Li ah-old 252AH based on rfc1826 253.It Li ipcomp 254IPComp 255.It Li tcp 256TCP-MD5 based on rfc2385 257.El 258.\" 259.Pp 260.It Ar spi 261Security Parameter Index 262.Pq SPI 263for the SAD and the SPD. 264.Ar spi 265must be a decimal number, or a hexadecimal number with 266.Dq Li 0x 267prefix. 268SPI values between 0 and 255 are reserved for future use by IANA 269and they cannot be used. 270TCP-MD5 associations must use 0x1000 and therefore only have per-host 271granularity at this time. 272.\" 273.Pp 274.It Ar extensions 275take some of the following: 276.Bl -tag -width Fl -compact 277.\" 278.It Fl m Ar mode 279Specify a security protocol mode for use. 280.Ar mode 281is one of following: 282.Li transport , tunnel 283or 284.Li any . 285The default value is 286.Li any . 287.\" 288.It Fl r Ar size 289Specify window size of bytes for replay prevention. 290.Ar size 291must be decimal number in 32-bit word. 292If 293.Ar size 294is zero or not specified, replay check don't take place. 295.\" 296.It Fl u Ar id 297Specify the identifier of the policy entry in SPD. 298See 299.Ar policy . 300.\" 301.It Fl f Ar pad_option 302defines the content of the ESP padding. 303.Ar pad_option 304is one of following: 305.Bl -tag -width random-pad -compact 306.It Li zero-pad 307All of the padding are zero. 308.It Li random-pad 309A series of randomized values are set. 310.It Li seq-pad 311A series of sequential increasing numbers started from 1 are set. 312.El 313.\" 314.It Fl f Li nocyclic-seq 315Don't allow cyclic sequence number. 316.\" 317.It Fl lh Ar time 318.It Fl ls Ar time 319Specify hard/soft life time duration of the SA. 320.El 321.\" 322.Pp 323.It Ar algorithm 324.Bl -tag -width Fl -compact 325.It Fl E Ar ealgo Ar key 326Specify an encryption algorithm 327.Ar ealgo 328for ESP. 329.It Xo 330.Fl E Ar ealgo Ar key 331.Fl A Ar aalgo Ar key 332.Xc 333Specify a encryption algorithm 334.Ar ealgo , 335as well as a payload authentication algorithm 336.Ar aalgo , 337for ESP. 338.It Fl A Ar aalgo Ar key 339Specify an authentication algorithm for AH. 340.It Fl C Ar calgo Op Fl R 341Specify a compression algorithm for IPComp. 342If 343.Fl R 344is specified, 345.Ar spi 346field value will be used as the IPComp CPI 347.Pq compression parameter index 348on wire as is. 349If 350.Fl R 351is not specified, 352the kernel will use well-known CPI on wire, and 353.Ar spi 354field will be used only as an index for kernel internal usage. 355.El 356.Pp 357.Ar key 358must be double-quoted character string, or a series of hexadecimal digits 359preceded by 360.Dq Li 0x . 361.Pp 362Possible values for 363.Ar ealgo , 364.Ar aalgo 365and 366.Ar calgo 367are specified in separate section. 368.\" 369.Pp 370.It Ar src_range 371.It Ar dst_range 372These are selections of the secure communication specified as 373IPv4/v6 address or IPv4/v6 address range, and it may accompany 374TCP/UDP port specification. 375This takes the following form: 376.Bd -literal -offset 377.Ar address 378.Ar address/prefixlen 379.Ar address[port] 380.Ar address/prefixlen[port] 381.Ed 382.Pp 383.Ar prefixlen 384and 385.Ar port 386must be decimal number. 387The square bracket around 388.Ar port 389is really necessary. 390They are not manpage metacharacters. 391For FQDN resolution, the rules applicable to 392.Ar src 393and 394.Ar dst 395apply here as well. 396.\" 397.Pp 398.It Ar upperspec 399Upper-layer protocol to be used. 400You can use one of words in 401.Pa /etc/protocols 402as 403.Ar upperspec . 404Or 405.Li icmp6 , 406.Li ip4 , 407and 408.Li any 409can be specified. 410.Li any 411stands for 412.Dq any protocol . 413Also you can use the protocol number. 414You can specify a type and/or a code of ICMPv6 when 415Upper-layer protocol is ICMPv6. 416the specification can be placed after 417.Li icmp6 . 418A type is separated with a code by single comma. 419A code must be specified anytime. 420When a zero is specified, the kernel deals with it as a wildcard. 421Note that the kernel can not distinguish a wildcard from that a type 422of ICMPv6 is zero. 423For example, the following means the policy doesn't require IPsec 424for any inbound Neighbor Solicitation. 425.Dl spdadd ::/0 ::/0 icmp6 135,0 -P in none ; 426.Pp 427NOTE: 428.Ar upperspec 429does not work against forwarding case at this moment, 430as it requires extra reassembly at forwarding node 431.Pq not implemented at this moment . 432We have many protocols in 433.Pa /etc/protocols , 434but protocols except of TCP, UDP and ICMP may not be suitable to use with IPsec. 435You have to consider and be careful to use them. 436.\" 437.Pp 438.It Ar policy 439.Ar policy 440is the one of the following three formats: 441.Bd -literal -offset indent 442.It Fl P Ar direction Li discard 443.It Fl P Ar direction Li none 444.It Xo Fl P Ar direction Li ipsec 445.Ar protocol/mode/src-dst/level Op ... 446.Xc 447.Ed 448.Pp 449You must specify the direction of its policy as 450.Ar direction . 451Either 452.Li out 453or 454.Li in 455are used. 456.Li discard 457means the packet matching indexes will be discarded. 458.Li none 459means that IPsec operation will not take place onto the packet. 460.Li ipsec 461means that IPsec operation will take place onto the packet. 462The part of 463.Ar protocol/mode/src-dst/level 464specifies the rule how to process the packet. 465Either 466.Li ah , 467.Li esp 468or 469.Li ipcomp 470is to be set as 471.Ar protocol . 472.Ar mode 473is either 474.Li transport 475or 476.Li tunnel . 477If 478.Ar mode 479is 480.Li tunnel , 481you must specify the end-points addresses of the SA as 482.Ar src 483and 484.Ar dst 485with 486.Sq - 487between these addresses which is used to specify the SA to use. 488If 489.Ar mode 490is 491.Li transport , 492both 493.Ar src 494and 495.Ar dst 496can be omitted. 497.Ar level 498is to be one of the following: 499.Li default , use , require 500or 501.Li unique . 502If the SA is not available in every level, the kernel will request 503getting SA to the key exchange daemon. 504.Li default 505means the kernel consults to the system wide default against protocol you 506specified, e.g. 507.Li esp_trans_deflev 508sysctl variable, when the kernel processes the packet. 509.Li use 510means that the kernel use a SA if it's available, 511otherwise the kernel keeps normal operation. 512.Li require 513means SA is required whenever the kernel sends a packet matched 514with the policy. 515.Li unique 516is the same to require. 517In addition, it allows the policy to bind with the unique out-bound SA. 518You just specify the policy level 519.Li unique , 520.Xr racoon 8 521will configure the SA for the policy. 522If you configure the SA by manual keying for that policy, 523you can put the decimal number as the policy identifier after 524.Li unique 525separated by colon 526.Sq \&: 527like the following; 528.Li unique:number . 529in order to bind this policy to the SA. 530.Li number 531must be between 1 and 32767. 532It corresponds to 533.Ar extensions Fl u 534of the manual SA configuration. 535When you want to use SA bundle, you can define multiple rules. 536For example, if an IP header was followed by AH header followed by ESP header 537followed by an upper layer protocol header, the rule 538would be: 539.Dl esp/transport//require ah/transport//require ; 540The rule order is very important. 541.Pp 542Note that 543.Dq Li discard 544and 545.Dq Li none 546are not in the syntax described in 547.Xr ipsec_set_policy 3 . 548There are little differences in the syntax. 549See 550.Xr ipsec_set_policy 3 551for detail. 552.Pp 553.El 554.Pp 555.\" 556.Sh ALGORITHMS 557The following list shows the supported algorithms. 558.Sy protocol 559and 560.Sy algorithm 561are almost orthogonal. 562Followings are the list of authentication algorithms that can be used as 563.Ar aalgo 564in 565.Fl A Ar aalgo 566of 567.Ar protocol 568parameter: 569.Pp 570.Bd -literal -offset indent 571algorithm keylen (bits) comment 572hmac-md5 128 ah: rfc2403 573 128 ah-old: rfc2085 574hmac-sha1 160 ah: rfc2404 575 160 ah-old: 128bit ICV (no document) 576keyed-md5 128 ah: 96bit ICV (no document) 577 128 ah-old: rfc1828 578keyed-sha1 160 ah: 96bit ICV (no document) 579 160 ah-old: 128bit ICV (no document) 580null 0 to 2048 for debugging 581hmac-sha2-256 256 ah: 96bit ICV 582 (draft-ietf-ipsec-ciph-sha-256-00) 583 256 ah-old: 128bit ICV (no document) 584hmac-sha2-384 384 ah: 96bit ICV (no document) 585 384 ah-old: 128bit ICV (no document) 586hmac-sha2-512 512 ah: 96bit ICV (no document) 587 512 ah-old: 128bit ICV (no document) 588hmac-ripemd160 160 ah: 96bit ICV (RFC2857) 589 ah-old: 128bit ICV (no document) 590aes-xcbc-mac 128 ah: 96bit ICV (RFC3566) 591 128 ah-old: 128bit ICV (no document) 592tcp-md5 8 to 640 tcp: rfc2385 593.Ed 594.Pp 595Followings are the list of encryption algorithms that can be used as 596.Ar ealgo 597in 598.Fl E Ar ealgo 599of 600.Ar protocol 601parameter: 602.Pp 603.Bd -literal -offset indent 604algorithm keylen (bits) comment 605des-cbc 64 esp-old: rfc1829, esp: rfc2405 6063des-cbc 192 rfc2451 607null 0 to 2048 rfc2410 608blowfish-cbc 40 to 448 rfc2451 609cast128-cbc 40 to 128 rfc2451 610des-deriv 64 ipsec-ciph-des-derived-01 6113des-deriv 192 no document 612rijndael-cbc 128/192/256 rfc3602 613aes-ctr 160/224/288 draft-ietf-ipsec-ciph-aes-ctr-03 614.Ed 615.Pp 616Note that the first 128 bits of a key for 617.Li aes-ctr 618will be used as AES key, and remaining 32 bits will be used as nonce. 619.Pp 620Followings are the list of compression algorithms that can be used as 621.Ar calgo 622in 623.Fl C Ar calgo 624of 625.Ar protocol 626parameter: 627.Pp 628.Bd -literal -offset indent 629algorithm comment 630deflate rfc2394 631.Ed 632.\" 633.Sh RETURN VALUES 634The command exits with 0 on success, and non-zero on errors. 635.\" 636.Sh EXAMPLES 637.Bd -literal -offset 638add 3ffe:501:4819::1 3ffe:501:481d::1 esp 123457 639 -E des-cbc 0x3ffe05014819ffff ; 640 641add -6 myhost.example.com yourhost.example.com ah 123456 642 -A hmac-sha1 "AH SA configuration!" ; 643 644add 10.0.11.41 10.0.11.33 esp 0x10001 645 -E des-cbc 0x3ffe05014819ffff 646 -A hmac-md5 "authentication!!" ; 647 648get 3ffe:501:4819::1 3ffe:501:481d::1 ah 123456 ; 649 650flush ; 651 652dump esp ; 653 654spdadd 10.0.11.41/32[21] 10.0.11.33/32[any] any 655 -P out ipsec esp/tunnel/192.168.0.1-192.168.1.2/require ; 656 657add 10.1.10.34 10.1.10.36 tcp 0x1000 -A tcp-md5 "TCP-MD5 BGP secret" ; 658 659.Ed 660.\" 661.Sh SEE ALSO 662.Xr ipsec_set_policy 3 , 663.Xr racoon 8 , 664.Xr sysctl 8 665.Rs 666.%T "Changed manual key configuration for IPsec" 667.%O "http://www.kame.net/newsletter/19991007/" 668.%D "October 1999" 669.Re 670.\" 671.Sh HISTORY 672The 673.Nm 674command first appeared in WIDE Hydrangea IPv6 protocol stack kit. 675The command was completely re-designed in June 1998. 676.\" 677.Sh BUGS 678.Nm 679should report and handle syntax errors better. 680.Pp 681For IPsec gateway configuration, 682.Ar src_range 683and 684.Ar dst_range 685with TCP/UDP port number do not work, as the gateway does not reassemble 686packets 687.Pq cannot inspect upper-layer headers . 688