1 .\" $NetBSD: setkey.8,v 1.20 2006/10/06 12:02:27 manu Exp $
3 .\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the project nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Nd manually manipulate the IPsec SA/SP database
62 adds, updates, dumps, or flushes
63 Security Association Database (SAD) entries
64 as well as Security Policy Database (SPD) entries in the kernel.
67 takes a series of operations from standard input
80 Dump the SAD entries or SPD entries contained in the specified
86 usually does not display dead SAD entries with
90 is also specified, the dead SAD entries will be displayed as well.
91 A dead SAD entry is one that has expired but remains in the
92 system because it is referenced by some SPD entries.
97 is also specified, the SPD entries are dumped.
100 is specified, the ports are displayed.
102 Flush the SAD entries.
105 is also specified, the SPD entries are flushed.
107 Add hexadecimal dump in
115 On other systems, synonym for
118 Use semantics used in kernel.
119 Available only in Linux.
123 Loop forever with short output on
127 The program will check validity of the input, but no changes to
128 the SPD will be made.
130 Use semantics described in IPsec RFCs.
131 This mode is default.
132 For details see section
133 .Sx RFC vs Linux kernel semantics .
134 Available only in Linux.
138 Loop forever and dump all the messages transmitted to the
142 prints the unformatted timestamps.
144 Print version string.
147 The program will dump messages exchanged on the
149 socket, including messages sent from other processes to the kernel.
151 .Ss Configuration syntax
158 accepts the following configuration syntax.
159 Lines starting with hash signs
161 are treated as comment lines.
163 .It Li add Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi \
164 Oo Ar extensions Oc Ar algorithm ... Li ;
167 can fail for multiple reasons, including when the key length does
168 not match the specified algorithm.
170 .It Li get Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi Li ;
173 .It Li delete Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi Li ;
176 .It Li deleteall Oo Fl 46n Oc Ar src Ar dst Ar protocol Li ;
177 Remove all SAD entries that match the specification.
179 .It Li flush Oo Ar protocol Oc Li ;
180 Clear all SAD entries matched by the options.
182 on the command line achieves the same functionality.
184 .It Li dump Oo Ar protocol Oc Li ;
185 Dumps all SAD entries matched by the options.
187 on the command line achieves the same functionality.
189 .It Li spdadd Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
190 Ar label Ar policy Li ;
193 .It Li spdadd tagged Ar tag Ar policy Li ;
194 Add an SPD entry based on a PF tag.
196 must be a string surrounded by double quotes.
198 .It Li spddelete Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
199 Fl P Ar direction Li ;
203 Clear all SPD entries.
205 on the command line achieves the same functionality.
208 Dumps all SPD entries.
210 on the command line achieves the same functionality.
214 Meta-arguments are as follows:
216 .Bl -tag -compact -width Ds
219 Source/destination of the secure communication is specified as
220 an IPv4/v6 address, and an optional port number between square
223 can resolve a FQDN into numeric addresses.
224 If the FQDN resolves into multiple addresses,
226 will install multiple SAD/SPD entries into the kernel
227 by trying all possible combinations.
232 restrict the address resolution of FQDN in certain ways.
236 restrict results into IPv4/v6 addresses only, respectively.
238 avoids FQDN resolution and requires addresses to be numeric addresses.
244 .Bl -tag -width Fl -compact
256 TCP-MD5 based on rfc2385
261 Security Parameter Index
263 for the SAD and the SPD.
265 must be a decimal number, or a hexadecimal number with a
268 SPI values between 0 and 255 are reserved for future use by IANA
270 TCP-MD5 associations must use 0x1000 and therefore only have per-host
271 granularity at this time.
275 take some of the following:
276 .Bl -tag -width Fl -compact
279 Specify a security protocol mode for use.
282 .Li transport , tunnel ,
289 Specify window size of bytes for replay prevention.
291 must be decimal number in 32-bit word.
294 is zero or not specified, replay checks don't take place.
297 Specify the identifier of the policy entry in the SPD.
301 .It Fl f Ar pad_option
302 defines the content of the ESP padding.
305 .Bl -tag -width random-pad -compact
307 All the paddings are zero.
309 A series of randomized values are used.
311 A series of sequential increasing numbers started from 1 are used.
314 .It Fl f Li nocyclic-seq
315 Don't allow cyclic sequence numbers.
319 Specify hard/soft life time duration of the SA measured in seconds.
323 Specify hard/soft life time duration of the SA measured in bytes transported.
325 .It Fl ctx Ar doi Ar algorithm Ar context-name
326 Specify an access control label. The access control label is interpreted
327 by the LSM (e.g., SELinux). Ultimately, it enables MAC on network
329 .Bl -tag -width Fl -compact
331 The domain of interpretation, which is used by the
332 IKE daemon to identify the domain in which negotiation takes place.
334 Indicates the LSM for which the label is generated (e.g., SELinux).
336 The string representation of the label that is interpreted by the LSM.
342 .Bl -tag -width Fl -compact
343 .It Fl E Ar ealgo Ar key
344 Specify an encryption algorithm
347 .It Fl E Ar ealgo Ar key Fl A Ar aalgo Ar key
348 Specify an encryption algorithm
350 as well as a payload authentication algorithm
353 .It Fl A Ar aalgo Ar key
354 Specify an authentication algorithm for AH.
355 .It Fl C Ar calgo Op Fl R
356 Specify a compression algorithm for IPComp.
361 field value will be used as the IPComp CPI
362 .Pq compression parameter index
367 the kernel will use well-known CPI on wire, and
369 field will be used only as an index for kernel internal usage.
373 must be a double-quoted character string, or a series of hexadecimal
389 These select the communications that should be secured by IPsec.
390 They can be an IPv4/v6 address or an IPv4/v6 address range, and
391 may be accompanied by a TCP/UDP port specification.
392 This takes the following form:
395 .Ar address/prefixlen
397 .Ar address/prefixlen[port]
403 must be decimal numbers.
404 The square brackets around
406 are really necessary,
407 they are not man page meta-characters.
408 For FQDN resolution, the rules applicable to
416 Upper-layer protocol to be used.
417 You can use one of the words in
429 You can also use the protocol number.
430 You can specify a type and/or a code of ICMPv6 when the
431 upper-layer protocol is ICMPv6.
432 The specification can be placed after
434 A type is separated from a code by single comma.
435 A code must always be specified.
436 When a zero is specified, the kernel deals with it as a wildcard.
437 Note that the kernel can not distinguish a wildcard from an ICPMv6
439 For example, the following means that the policy doesn't require IPsec
440 for any inbound Neighbor Solicitation.
441 .Dl spdadd ::/0 ::/0 icmp6 135,0 -P in none ;
445 does not work against forwarding case at this moment,
446 as it requires extra reassembly at the forwarding node
447 .Pq not implemented at this moment .
448 There are many protocols in
450 but all protocols except of TCP, UDP, and ICMP may not be suitable
452 You have to consider carefully what to use.
457 is the access control label for the policy. This label is interpreted
458 by the LSM (e.g., SELinux). Ultimately, it enables MAC on network
459 communications. When a policy contains an access control label, SAs
460 negotiated with this policy will contain the label. It's format:
461 .Bl -tag -width Fl -compact
463 .It Fl ctx Ar doi Ar algorithm Ar context-name
464 .Bl -tag -width Fl -compact
466 The domain of interpretation, which is used by the
467 IKE daemon to identify the domain in which negotiation takes place.
469 Indicates the LSM for which the label is generated (e.g., SELinux).
471 The string representation of the label that is interpreted by the LSM.
478 is in one of the following three formats:
481 .Fl P Ar direction [priority specification] Li discard
483 .Fl P Ar direction [priority specification] Li none
485 .Fl P Ar direction [priority specification] Li ipsec
486 .Ar protocol/mode/src-dst/level Op ...
489 You must specify the direction of its policy as
498 .Ar priority specification
499 is used to control the placement of the policy within the SPD.
500 Policy position is determined by
501 a signed integer where higher priorities indicate the policy is placed
502 closer to the beginning of the list and lower priorities indicate the
503 policy is placed closer to the end of the list.
504 Policies with equal priorities are added at the end of groups
508 be specified when setkey has been compiled against kernel headers that
509 support policy priorities (Linux \*[Gt]= 2.6.6).
510 If the kernel does not support priorities, a warning message will
511 be printed the first time a priority specification is used.
512 Policy priority takes one of the following formats:
513 .Bl -tag -width "discard"
514 .It Ar {priority,prio} offset
516 is an integer in the range from \-2147483647 to 214783648.
517 .It Ar {priority,prio} base {+,\-} offset
520 .Li low (\-1073741824) ,
523 .Li high (1073741824)
526 is an unsigned integer.
527 It can be up to 1073741824 for
528 positive offsets, and up to 1073741823 for negative offsets.
532 means the packet matching indexes will be discarded.
534 means that IPsec operation will not take place onto the packet.
536 means that IPsec operation will take place onto the packet.
539 .Ar protocol/mode/src-dst/level
540 part specifies the rule how to process the packet.
557 you must specify the end-point addresses of the SA as
563 between these addresses, which is used to specify the SA to use.
574 is to be one of the following:
575 .Li default , use , require ,
578 If the SA is not available in every level, the kernel will
579 ask the key exchange daemon to establish a suitable SA.
581 means the kernel consults the system wide default for the protocol
582 you specified, e.g. the
584 sysctl variable, when the kernel processes the packet.
586 means that the kernel uses an SA if it's available,
587 otherwise the kernel keeps normal operation.
589 means SA is required whenever the kernel sends a packet matched
594 in addition, it allows the policy to match the unique out-bound SA.
595 You just specify the policy level
598 will configure the SA for the policy.
599 If you configure the SA by manual keying for that policy,
600 you can put a decimal number as the policy identifier after
606 in order to bind this policy to the SA.
608 must be between 1 and 32767.
611 of the manual SA configuration.
612 When you want to use SA bundle, you can define multiple rules.
613 For example, if an IP header was followed by an AH header followed
614 by an ESP header followed by an upper layer protocol header, the
616 .Dl esp/transport//require ah/transport//require ;
617 The rule order is very important.
619 When NAT-T is enabled in the kernel, policy matching for ESP over
620 UDP packets may be done on endpoint addresses and port
621 (this depends on the system.
622 System that do not perform the port check cannot support
623 multiple endpoints behind the same NAT).
624 When using ESP over UDP, you can specify port numbers in the endpoint
625 addresses to get the correct matching.
628 spdadd 10.0.11.0/24[any] 10.0.11.33/32[any] any -P out ipsec
629 esp/tunnel/192.168.0.1[4500]-192.168.1.2[30000]/require ;
632 These ports must be left unspecified (which defaults to 0) for
633 anything other than ESP over UDP.
634 They can be displayed in SPD dump using
642 are not in the syntax described in
643 .Xr ipsec_set_policy 3 .
644 There are a few differences in the syntax.
646 .Xr ipsec_set_policy 3
651 The following list shows the supported algorithms.
655 are almost orthogonal.
656 These authentication algorithms can be used as
664 .Bd -literal -offset indent
665 algorithm keylen (bits)
666 hmac-md5 128 ah: rfc2403
668 hmac-sha1 160 ah: rfc2404
669 160 ah-old: 128bit ICV (no document)
670 keyed-md5 128 ah: 96bit ICV (no document)
672 keyed-sha1 160 ah: 96bit ICV (no document)
673 160 ah-old: 128bit ICV (no document)
674 null 0 to 2048 for debugging
675 hmac-sha256 256 ah: 96bit ICV
676 (draft-ietf-ipsec-ciph-sha-256-00)
677 256 ah-old: 128bit ICV (no document)
678 hmac-sha384 384 ah: 96bit ICV (no document)
679 384 ah-old: 128bit ICV (no document)
680 hmac-sha512 512 ah: 96bit ICV (no document)
681 512 ah-old: 128bit ICV (no document)
682 hmac-ripemd160 160 ah: 96bit ICV (RFC2857)
683 ah-old: 128bit ICV (no document)
684 aes-xcbc-mac 128 ah: 96bit ICV (RFC3566)
685 128 ah-old: 128bit ICV (no document)
686 tcp-md5 8 to 640 tcp: rfc2385
689 These encryption algorithms can be used as
697 .Bd -literal -offset indent
698 algorithm keylen (bits)
699 des-cbc 64 esp-old: rfc1829, esp: rfc2405
701 null 0 to 2048 rfc2410
702 blowfish-cbc 40 to 448 rfc2451
703 cast128-cbc 40 to 128 rfc2451
704 des-deriv 64 ipsec-ciph-des-derived-01
705 3des-deriv 192 no document
706 rijndael-cbc 128/192/256 rfc3602
707 twofish-cbc 0 to 256 draft-ietf-ipsec-ciph-aes-cbc-01
708 aes-ctr 160/224/288 draft-ietf-ipsec-ciph-aes-ctr-03
709 camellia-cbc 128/192/256 rfc4312
712 Note that the first 128 bits of a key for
714 will be used as AES key, and the remaining 32 bits will be used as nonce.
716 These compression algorithms can be used as
724 .Bd -literal -offset indent
729 .Ss RFC vs Linux kernel semantics
730 The Linux kernel uses the
732 policy instead of the
734 policy for packets what are forwarded through that particular box.
740 manages and shows policies and SAs exactly as they are stored in the kernel.
754 (not implemented yet) filters out all
759 The command exits with 0 on success, and non-zero on errors.
763 add 3ffe:501:4819::1 3ffe:501:481d::1 esp 123457
764 -E des-cbc 0x3ffe05014819ffff ;
766 add -6 myhost.example.com yourhost.example.com ah 123456
767 -A hmac-sha1 "AH SA configuration!" ;
769 add 10.0.11.41 10.0.11.33 esp 0x10001
770 -E des-cbc 0x3ffe05014819ffff
771 -A hmac-md5 "authentication!!" ;
773 get 3ffe:501:4819::1 3ffe:501:481d::1 ah 123456 ;
779 spdadd 10.0.11.41/32[21] 10.0.11.33/32[any] any
780 -P out ipsec esp/tunnel/192.168.0.1-192.168.1.2/require ;
782 add 10.1.10.34 10.1.10.36 tcp 0x1000 -A tcp-md5 "TCP-MD5 BGP secret" ;
784 add 10.0.11.41 10.0.11.33 esp 0x10001
785 -ctx 1 1 "system_u:system_r:unconfined_t:SystemLow-SystemHigh"
786 -E des-cbc 0x3ffe05014819ffff;
788 spdadd 10.0.11.41 10.0.11.33 any
789 -ctx 1 1 "system_u:system_r:unconfined_t:SystemLow-SystemHigh"
790 -P out ipsec esp/transport//require ;
794 .Xr ipsec_set_policy 3 ,
798 .%T "Changed manual key configuration for IPsec"
799 .%O "http://www.kame.net/newsletter/19991007/"
806 command first appeared in the WIDE Hydrangea IPv6 protocol stack
808 The command was completely re-designed in June 1998.
812 should report and handle syntax errors better.
814 For IPsec gateway configuration,
818 with TCP/UDP port numbers does not work, as the gateway does not
820 .Pq it cannot inspect upper-layer headers .