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.El 256.\" 257.Pp 258.It Ar spi 259Security Parameter Index 260.Pq SPI 261for the SAD and the SPD. 262.Ar spi 263must be a decimal number, or a hexadecimal number with 264.Dq Li 0x 265prefix. 266SPI values between 0 and 255 are reserved for future use by IANA 267and they cannot be used. 268.\" 269.Pp 270.It Ar extensions 271take some of the following: 272.Bl -tag -width Fl -compact 273.\" 274.It Fl m Ar mode 275Specify a security protocol mode for use. 276.Ar mode 277is one of following: 278.Li transport , tunnel 279or 280.Li any . 281The default value is 282.Li any . 283.\" 284.It Fl r Ar size 285Specify window size of bytes for replay prevention. 286.Ar size 287must be decimal number in 32-bit word. 288If 289.Ar size 290is zero or not specified, replay check don't take place. 291.\" 292.It Fl u Ar id 293Specify the identifier of the policy entry in SPD. 294See 295.Ar policy . 296.\" 297.It Fl f Ar pad_option 298defines the content of the ESP padding. 299.Ar pad_option 300is one of following: 301.Bl -tag -width random-pad -compact 302.It Li zero-pad 303All of the padding are zero. 304.It Li random-pad 305A series of randomized values are set. 306.It Li seq-pad 307A series of sequential increasing numbers started from 1 are set. 308.El 309.\" 310.It Fl f Li nocyclic-seq 311Don't allow cyclic sequence number. 312.\" 313.It Fl lh Ar time 314.It Fl ls Ar time 315Specify hard/soft life time duration of the SA. 316.El 317.\" 318.Pp 319.It Ar algorithm 320.Bl -tag -width Fl -compact 321.It Fl E Ar ealgo Ar key 322Specify an encryption algorithm 323.Ar ealgo 324for ESP. 325.It Xo 326.Fl E Ar ealgo Ar key 327.Fl A Ar aalgo Ar key 328.Xc 329Specify a encryption algorithm 330.Ar ealgo , 331as well as a payload authentication algorithm 332.Ar aalgo , 333for ESP. 334.It Fl A Ar aalgo Ar key 335Specify an authentication algorithm for AH. 336.It Fl C Ar calgo Op Fl R 337Specify a compression algorithm for IPComp. 338If 339.Fl R 340is specified, 341.Ar spi 342field value will be used as the IPComp CPI 343.Pq compression parameter index 344on wire as is. 345If 346.Fl R 347is not specified, 348the kernel will use well-known CPI on wire, and 349.Ar spi 350field will be used only as an index for kernel internal usage. 351.El 352.Pp 353.Ar key 354must be double-quoted character string, or a series of hexadecimal digits 355preceded by 356.Dq Li 0x . 357.Pp 358Possible values for 359.Ar ealgo , 360.Ar aalgo 361and 362.Ar calgo 363are specified in separate section. 364.\" 365.Pp 366.It Ar src_range 367.It Ar dst_range 368These are selections of the secure communication specified as 369IPv4/v6 address or IPv4/v6 address range, and it may accompany 370TCP/UDP port specification. 371This takes the following form: 372.Bd -literal -offset 373.Ar address 374.Ar address/prefixlen 375.Ar address[port] 376.Ar address/prefixlen[port] 377.Ed 378.Pp 379.Ar prefixlen 380and 381.Ar port 382must be decimal number. 383The square bracket around 384.Ar port 385is really necessary. 386They are not manpage metacharacters. 387For FQDN resolution, the rules applicable to 388.Ar src 389and 390.Ar dst 391apply here as well. 392.\" 393.Pp 394.It Ar upperspec 395Upper-layer protocol to be used. 396You can use one of words in 397.Pa /etc/protocols 398as 399.Ar upperspec . 400Or 401.Li icmp6 , 402.Li ip4 , 403and 404.Li any 405can be specified. 406.Li any 407stands for 408.Dq any protocol . 409Also you can use the protocol number. 410You can specify a type and/or a code of ICMPv6 when 411Upper-layer protocol is ICMPv6. 412the specification can be placed after 413.Li icmp6 . 414A type is separated with a code by single comma. 415A code must be specified anytime. 416When a zero is specified, the kernel deals with it as a wildcard. 417Note that the kernel can not distinguish a wildcard from that a type 418of ICMPv6 is zero. 419For example, the following means the policy doesn't require IPsec 420for any inbound Neighbor Solicitation. 421.Dl spdadd ::/0 ::/0 icmp6 135,0 -P in none ; 422.Pp 423NOTE: 424.Ar upperspec 425does not work against forwarding case at this moment, 426as it requires extra reassembly at forwarding node 427.Pq not implemented at this moment . 428We have many protocols in 429.Pa /etc/protocols , 430but protocols except of TCP, UDP and ICMP may not be suitable to use with IPsec. 431You have to consider and be careful to use them. 432.\" 433.Pp 434.It Ar policy 435.Ar policy 436is the one of the following three formats: 437.Bd -literal -offset indent 438.It Fl P Ar direction Li discard 439.It Fl P Ar direction Li none 440.It Xo Fl P Ar direction Li ipsec 441.Ar protocol/mode/src-dst/level Op ... 442.Xc 443.Ed 444.Pp 445You must specify the direction of its policy as 446.Ar direction . 447Either 448.Li out 449or 450.Li in 451are used. 452.Li discard 453means the packet matching indexes will be discarded. 454.Li none 455means that IPsec operation will not take place onto the packet. 456.Li ipsec 457means that IPsec operation will take place onto the packet. 458The part of 459.Ar protocol/mode/src-dst/level 460specifies the rule how to process the packet. 461Either 462.Li ah , 463.Li esp 464or 465.Li ipcomp 466is to be set as 467.Ar protocol . 468.Ar mode 469is either 470.Li transport 471or 472.Li tunnel . 473If 474.Ar mode 475is 476.Li tunnel , 477you must specify the end-points addresses of the SA as 478.Ar src 479and 480.Ar dst 481with 482.Sq - 483between these addresses which is used to specify the SA to use. 484If 485.Ar mode 486is 487.Li transport , 488both 489.Ar src 490and 491.Ar dst 492can be omitted. 493.Ar level 494is to be one of the following: 495.Li default , use , require 496or 497.Li unique . 498If the SA is not available in every level, the kernel will request 499getting SA to the key exchange daemon. 500.Li default 501means the kernel consults to the system wide default against protocol you 502specified, e.g. 503.Li esp_trans_deflev 504sysctl variable, when the kernel processes the packet. 505.Li use 506means that the kernel use a SA if it's available, 507otherwise the kernel keeps normal operation. 508.Li require 509means SA is required whenever the kernel sends a packet matched 510with the policy. 511.Li unique 512is the same to require. 513In addition, it allows the policy to bind with the unique out-bound SA. 514You just specify the policy level 515.Li unique , 516.Xr racoon 8 517will configure the SA for the policy. 518If you configure the SA by manual keying for that policy, 519you can put the decimal number as the policy identifier after 520.Li unique 521separated by colon 522.Sq \&: 523like the following; 524.Li unique:number . 525in order to bind this policy to the SA. 526.Li number 527must be between 1 and 32767. 528It corresponds to 529.Ar extensions Fl u 530of the manual SA configuration. 531When you want to use SA bundle, you can define multiple rules. 532For example, if an IP header was followed by AH header followed by ESP header 533followed by an upper layer protocol header, the rule 534would be: 535.Dl esp/transport//require ah/transport//require ; 536The rule order is very important. 537.Pp 538Note that 539.Dq Li discard 540and 541.Dq Li none 542are not in the syntax described in 543.Xr ipsec_set_policy 3 . 544There are little differences in the syntax. 545See 546.Xr ipsec_set_policy 3 547for detail. 548.Pp 549.El 550.Pp 551.\" 552.Sh ALGORITHMS 553The following list shows the supported algorithms. 554.Sy protocol 555and 556.Sy algorithm 557are almost orthogonal. 558Followings are the list of authentication algorithms that can be used as 559.Ar aalgo 560in 561.Fl A Ar aalgo 562of 563.Ar protocol 564parameter: 565.Pp 566.Bd -literal -offset indent 567algorithm keylen (bits) comment 568hmac-md5 128 ah: rfc2403 569 128 ah-old: rfc2085 570hmac-sha1 160 ah: rfc2404 571 160 ah-old: 128bit ICV (no document) 572keyed-md5 128 ah: 96bit ICV (no document) 573 128 ah-old: rfc1828 574keyed-sha1 160 ah: 96bit ICV (no document) 575 160 ah-old: 128bit ICV (no document) 576null 0 to 2048 for debugging 577hmac-sha2-256 256 ah: 96bit ICV 578 (draft-ietf-ipsec-ciph-sha-256-00) 579 256 ah-old: 128bit ICV (no document) 580hmac-sha2-384 384 ah: 96bit ICV (no document) 581 384 ah-old: 128bit ICV (no document) 582hmac-sha2-512 512 ah: 96bit ICV (no document) 583 512 ah-old: 128bit ICV (no document) 584hmac-ripemd160 160 ah: 96bit ICV (RFC2857) 585 ah-old: 128bit ICV (no document) 586aes-xcbc-mac 128 ah: 96bit ICV (RFC3566) 587 128 ah-old: 128bit ICV (no document) 588.Ed 589.Pp 590Followings are the list of encryption algorithms that can be used as 591.Ar ealgo 592in 593.Fl E Ar ealgo 594of 595.Ar protocol 596parameter: 597.Pp 598.Bd -literal -offset indent 599algorithm keylen (bits) comment 600des-cbc 64 esp-old: rfc1829, esp: rfc2405 6013des-cbc 192 rfc2451 602null 0 to 2048 rfc2410 603blowfish-cbc 40 to 448 rfc2451 604cast128-cbc 40 to 128 rfc2451 605des-deriv 64 ipsec-ciph-des-derived-01 6063des-deriv 192 no document 607rijndael-cbc 128/192/256 rfc3602 608aes-ctr 160/224/288 draft-ietf-ipsec-ciph-aes-ctr-03 609.Ed 610.Pp 611Note that the first 128 bits of a key for 612.Li aes-ctr 613will be used as AES key, and remaining 32 bits will be used as nonce. 614.Pp 615Followings are the list of compression algorithms that can be used as 616.Ar calgo 617in 618.Fl C Ar calgo 619of 620.Ar protocol 621parameter: 622.Pp 623.Bd -literal -offset indent 624algorithm comment 625deflate rfc2394 626.Ed 627.\" 628.Sh RETURN VALUES 629The command exits with 0 on success, and non-zero on errors. 630.\" 631.Sh EXAMPLES 632.Bd -literal -offset 633add 3ffe:501:4819::1 3ffe:501:481d::1 esp 123457 634 -E des-cbc 0x3ffe05014819ffff ; 635 636add -6 myhost.example.com yourhost.example.com ah 123456 637 -A hmac-sha1 "AH SA configuration!" ; 638 639add 10.0.11.41 10.0.11.33 esp 0x10001 640 -E des-cbc 0x3ffe05014819ffff 641 -A hmac-md5 "authentication!!" ; 642 643get 3ffe:501:4819::1 3ffe:501:481d::1 ah 123456 ; 644 645flush ; 646 647dump esp ; 648 649spdadd 10.0.11.41/32[21] 10.0.11.33/32[any] any 650 -P out ipsec esp/tunnel/192.168.0.1-192.168.1.2/require ; 651 652.Ed 653.\" 654.Sh SEE ALSO 655.Xr ipsec_set_policy 3 , 656.Xr racoon 8 , 657.Xr sysctl 8 658.Rs 659.%T "Changed manual key configuration for IPsec" 660.%O "http://www.kame.net/newsletter/19991007/" 661.%D "October 1999" 662.Re 663.\" 664.Sh HISTORY 665The 666.Nm 667command first appeared in WIDE Hydrangea IPv6 protocol stack kit. 668The command was completely re-designed in June 1998. 669.\" 670.Sh BUGS 671.Nm 672should report and handle syntax errors better. 673.Pp 674For IPsec gateway configuration, 675.Ar src_range 676and 677.Ar dst_range 678with TCP/UDP port number do not work, as the gateway does not reassemble 679packets 680.Pq cannot inspect upper-layer headers . 681