1 # The Versatile IKE Control Interface (VICI) protocol #
3 The vici plugin implements the server side of an IPC protocol to configure,
4 monitor and control the IKE daemon charon. It uses request/response and event
5 messages to communicate over a reliable stream based transport.
7 ## Transport protocol ##
9 To provide the service, the plugin opens a listening socket using a reliable,
10 stream based transport. charon relies on the different stream service
11 abstractions provided by libstrongswan, such as TCP and UNIX sockets.
13 A client connects to this service to access functionality. It may send an
14 arbitrary number of packets over the connection before closing it.
16 To exchange data, the transport protocol is segmented into byte sequences.
17 Each byte sequence is prefixed by a 32-bit length header in network order,
18 followed by the data. The maximum segment length is currently limited to 512KB
19 of data, and the length field contains the length of the data only, not
20 including the length field itself.
22 The order of byte sequences must be strict, byte sequences must arrive in the
27 Within the byte sequences defined by the transport layer, both the client
28 and the server can exchange packets. The type of packet defines its structure
29 and purpose. The packet type is a 8-bit identifier, and is the first byte
30 in a transport layer byte sequence. The length of the packet is given by the
33 While a packet type may define the format of the wrapped data freely, currently
34 all types either contain a name, a message or both. The following packet types
35 are currently defined:
37 * _CMD_REQUEST = 0_: A named request message
38 * _CMD_RESPONSE = 1_: An unnamed response message for a request
39 * _CMD_UNKNOWN = 2_: An unnamed response if requested command is unknown
40 * _EVENT_REGISTER = 3_: A named event registration request
41 * _EVENT_UNREGISTER = 4_: A named event deregistration request
42 * _EVENT_CONFIRM = 5_: An unnamed response for successful event (de-)registration
43 * _EVENT_UNKNOWN = 6_: A unnamed response if event (de-)registration failed
44 * _EVENT = 7_: A named event message
46 For packets having a named type, after the packet type an 8-bit length header
47 of the name follows, indicating the string length in bytes of the name tag, not
48 including the length field itself. The name is an ASCII string that is not
51 The rest of the packet forms the exchanged message, the length is determined
52 by the transport byte sequence length, subtracting the packet type and
53 the optional name tag in some messages.
57 Commands are currently always requested by the client. The server replies with
58 a response, or with a CMD_UNKNOWN failure message to let the client know
59 that it does not have a handler for such a command. There is no sequence number
60 to associate responses to requests, so only one command can be active at
61 a time on a single connection.
65 To receive event messages, the client explicitly registers for events by name,
66 and also unregisters if it does not want to receive events of the named kind
67 anymore. The server confirms event registration using EVENT_CONFIRM, or
68 indicates that there is no such event source with EVENT_UNKNOWN.
70 Events may get raised at any time while registered, even during an active
71 request command. This mechanism is used to feed continuous data during a request,
76 The defined packet types optionally wrap a message with additional data.
77 Messages are currently used in CMD_REQUEST/CMD_RESPONSE, and in EVENT packets.
78 A message uses a hierarchial tree of sections. Each section (or the implicit
79 root section) contains an arbitrary set of key/value pairs, lists and
80 sub-sections. The length of a message is not part of the message itself, but
81 the wrapping layer, usually calculated from the transport byte sequence length.
83 The message encoding consists of a sequence of elements. Each element starts
84 with the element type, optionally followed by an element name and/or an element
85 value. Currently the following message element types are defined:
87 * _SECTION_START = 1_: Begin a new section having a name
88 * _SECTION_END = 2_: End a previously started section
89 * _KEY_VALUE = 3_: Define a value for a named key in the current section
90 * _LIST_START = 4_: Begin a named list for list items
91 * _LIST_ITEM = 5_: Define an unnamed item value in the current list
92 * _LIST_END = 6_: End a previously started list
94 Types are encoded as 8-bit values. Types having a name (SECTION_START,
95 KEY_VALUE and LIST_START) have an ASCII string following the type, which itself
96 uses an 8-bit length header. The string must not be null-terminated, the string
97 length does not include the length field itself.
99 Types having a value (KEY_VALUE and LIST_ITEM) have a raw blob sequence,
100 prefixed with a 16-bit network order length. The blob follows the type or the
101 name tag if available, the length defined by the length field does not include
102 the length field itself.
104 The interpretation of any value is not defined by the message format; it can
105 take arbitrary blobs. The application may specify types for specific keys, such
106 as strings or integer representations. The vici plugin currently uses
107 non-null terminated strings as values only; numbers get encoded as strings.
111 Sections may be opened in the implicit root section, or any previously section.
112 They can be nested to arbitrary levels. A SECTION_END marker always closes
113 the last opened section; SECTION_START and SECTION_END items must be balanced
118 Key/Value pair elements may appear in the implicit root section or any explicit
119 sub-section at any level. Key names must be unique in the current section, use
120 lists to define multiple values for a key. Key/values may not appear in lists,
121 use a sub-section instead.
125 Lists may appear at the same locations as Key/Values, and may not be nested.
126 Only a single list may be opened at the same time, and all lists must be closed
127 in valid messages. After opening a list, only list items may appear before the
128 list closing element. Empty lists are allowed, list items may appear within
131 ### Encoding example ###
133 Consider the following structure using pseudo-markup for this example:
140 list1 = [ item1, item2 ]
143 The example above reprensents a valid tree structure, that gets encoded as
144 the following C array:
148 3, 4,'k','e','y','1', 0,6,'v','a','l','u','e','1',
150 1, 8,'s','e','c','t','i','o','n','1',
152 1, 11,'s','u','b','-','s','e','c','t','i','o','n',
154 3, 4,'k','e','y','2', 0,6,'v','a','l','u','e','2',
155 /* sub-section end */
158 4, 5, 'l','i','s','t','1',
160 5, 0,5,'i','t','e','m','1',
162 5, 0,5,'i','t','e','m','2',
169 ## Client-initiated commands ##
171 Based on the packet layer, VICI implements commands requested by the client
172 and responded to by the server using named _CMD_REQUEST_ and _CMD_RESPONSE_
173 packets wrapping messages. The request message may contain command arguments,
174 the response message the reply.
176 Some commands use response streaming, that is, a request triggers a series of
177 events to consecutively stream data to the client before the response message
178 completes the stream. A client must register for the appropriate event to
179 receive the stream, and unregister after the response has been received.
181 The following client issued commands with the appropriate command input and
182 output messages are currently defined:
186 Returns daemon and system specific version information.
189 daemon = <IKE daemon name>
190 version = <strongSwan version>
191 sysname = <operating system name>
192 release = <operating system release>
193 machine = <hardware identifier>
198 Returns IKE daemon statistics and load information.
202 running = <relative uptime in human-readable form>
203 since = <absolute startup time>
206 total = <total number of worker threads>
207 idle = <worker threads currently idle>
209 critical = <threads processing "critical" priority jobs>
210 high = <threads processing "high" priority jobs>
211 medium = <threads processing "medium" priority jobs>
212 low = <threads processing "low" priority jobs>
216 critical = <jobs queued with "critical" priority>
217 high = <jobs queued with "high" priority>
218 medium = <jobs queued with "medium" priority>
219 low = <jobs queued with "low" priority>
221 scheduled = <number of jobs scheduled for timed execution>
223 total = <total number of IKE_SAs active>
224 half-open = <number of IKE_SAs in half-open state>
227 <names of loaded plugins>
229 mem = { # available if built with leak-detective or on Windows
230 total = <total heap memory usage in bytes>
231 allocs = <total heap allocation blocks>
232 <heap-name>* = { # on Windows only
233 total = <heap memory usage in bytes by this heap>
234 allocs = <allocated blocks for this heap>
237 mallinfo = { # available with mallinfo() support
238 sbrk = <non-mmaped space available>
239 mmap = <mmaped space available>
240 used = <total number of bytes used>
241 free = <available but unused bytes>
245 ### reload-settings() ###
247 Reloads _strongswan.conf_ settings and all plugins supporting configuration
251 success = <yes or no>
252 errmsg = <error string on failure>
257 Initiates an SA while streaming _control-log_ events.
260 child = <CHILD_SA configuration name to initiate>
261 timeout = <timeout in seconds before returning>
262 loglevel = <loglevel to issue "control-log" events for>
264 success = <yes or no>
265 errmsg = <error string on failure or timeout>
270 Terminates an SA while streaming _control-log_ events.
273 child = <terminate a CHILD_SA by configuration name>
274 ike = <terminate an IKE_SA by configuration name>
275 child_id = <terminate a CHILD_SA by its reqid>
276 ike_id = <terminate an IKE_SA by its unique id>
277 timeout = <timeout in seconds before returning>
278 loglevel = <loglevel to issue "control-log" events for>
280 success = <yes or no>
281 errmsg = <error string on failure or timeout>
286 Install a trap, drop or bypass policy defined by a CHILD_SA config.
289 child = <CHILD_SA configuration name to install>
291 success = <yes or no>
292 errmsg = <error string on failure>
297 Uninstall a trap, drop or bypass policy defined by a CHILD_SA config.
300 child = <CHILD_SA configuration name to install>
302 success = <yes or no>
303 errmsg = <error string on failure>
308 Lists currently active IKE_SAs and associated CHILD_SAs by streaming _list-sa_
312 noblock = <use non-blocking mode if key is set>
313 ike = <filter listed IKE_SAs by its name>
314 ike_id = <filter listed IKE_SA by its unique id>
316 # completes after streaming list-sa events
319 ### list-policies() ###
321 List currently installed trap, drop and bypass policies by streaming
322 _list-policy_ events.
325 drop = <set to yes to list drop policies>
326 pass = <set to yes to list bypass policies>
327 trap = <set to yes to list trap policies>
328 child = <filter by CHILD_SA configuration name>
330 # completes after streaming list-sa events
335 List currently loaded connections by streaming _list-conn_ events. This
336 call includes all connections known by the daemon, not only those loaded
340 ike = <list connections matching a given configuration name only>
342 # completes after streaming list-conn events
347 Return a list of connection names loaded exclusively over vici, not including
348 connections found in other backends.
352 <list of connection names>
358 List currently loaded certificates by streaming _list-cert_ events. This
359 call includes all certificates known by the daemon, not only those loaded
363 type = <certificate type to filter for, or ANY>
364 subject = <set to list only certificates having subject>
366 # completes after streaming list-cert events
371 Load a single connection definition into the daemon. An existing connection
372 with the same name gets updated or replaced.
375 <IKE_SA config name> = {
376 # IKE configuration parameters with authentication and CHILD_SA
377 # subsections. Refer to swanctl.conf(5) for details.
379 success = <yes or no>
380 errmsg = <error string on failure>
384 ### unload-conn() ###
386 Unload a previously loaded connection definition by name.
389 name = <IKE_SA config name>
391 success = <yes or no>
392 errmsg = <error string on failure>
397 Load a certificate into the daemon.
400 type = <certificate type, X509|X509CA|X509AA|X509CRL|X509AC>
401 data = <PEM or DER encoded certificate data>
403 success = <yes or no>
404 errmsg = <error string on failure>
409 Load a private key into the daemon.
412 type = <private key type, RSA|ECDSA>
413 data = <PEM or DER encoded key data>
415 success = <yes or no>
416 errmsg = <error string on failure>
419 ### load-shared() ###
421 Load a shared IKE PSK, EAP or XAuth secret into the daemon.
424 type = <private key type, IKE|EAP|XAUTH>
425 data = <raw shared key data>
427 <list of shared key owner identities>
430 success = <yes or no>
431 errmsg = <error string on failure>
434 ### clear-creds() ###
436 Clear all loaded certificate, private key and shared key credentials. This
437 affects only credentials loaded over vici, but additionally flushes the
441 success = <yes or no>
442 errmsg = <error string on failure>
447 Load an in-memory virtual IP and configuration attribute pool. Existing
448 pools with the same name get updated, if possible.
452 addrs = <subnet of virtual IP pool addresses>
453 <attribute type>* = [
454 # attribute type is one of address, dns, nbns, dhcp, netmask,
455 # server, subnet, split_include, split_exclude or a numerical
456 # attribute type identifier.
457 <list of attributes for type>
461 success = <yes or no>
462 errmsg = <error string on failure>
465 ### unload-pool() ###
467 Unload a previously loaded virtual IP and configuration attribute pool.
468 Unloading fails for pools with leases currently online.
471 name = <virtual IP address pool to delete>
473 success = <yes or no>
474 errmsg = <error string on failure>
479 List the currently loaded pools.
483 base = <virtual IP pool base address>
484 size = <total number of addresses in the pool>
485 online = <number of leases online>
486 offline = <number of leases offline>
490 ## Server-issued events ##
492 Based on the packet layer, the vici plugin raises event messages using named
493 EVENT packets wrapping messages. The message contains event details.
497 The _log_ event is issued to registered clients for each debug log message.
498 This event is not associated with a command.
501 group = <subsystem identifier for debug message>
502 level = <log level, 0-4>
503 thread = <numerical thread identifier issuing the log message>
504 ikesa-name = <name of IKE_SA, if log is associated with any>
505 ikesa-uniqued = <unique identifier of IKE_A, if log associated with any>
506 msg = <log message text>
511 The _control-log_ event is issued for log events during active _initiate_ or
512 _terminate_ commands. It is issued only to clients currently having such
516 group = <subsystem identifier for debug message>
517 level = <log level, 0-4>
518 ikesa-name = <name of IKE_SA, if log associated with any>
519 ikesa-uniqued = <unique identifier of IKE_A, if log associated with any>
520 msg = <log message text>
525 The _list-sa_ event is issued to stream IKE_SAs during an active _list-sas_
529 <IKE_SA config name> = {
530 uniqueid = <IKE_SA unique identifier>
531 version = <IKE version, 1 or 2>
532 state = <IKE_SA state name>
533 local-host = <local IKE endpoint address>
534 local-id = <local IKE identity>
535 remote-host = <remote IKE endpoint address>
536 remote-id = <remote IKE identity>
537 remote-xauth-id = <remote XAuth identity, if XAuth-authenticated>
538 remote-eap-id = <remote EAP identity, if EAP-authenticated>
539 initiator = <yes, if initiator of IKE_SA>
540 initiator-spi = <hex encoded initiator SPI / cookie>
541 responder-spi = <hex encoded responder SPI / cookie>
542 encr-alg = <IKE encryption algorithm string>
543 encr-keysize = <key size for encr-alg, if applicable>
544 integ-alg = <IKE integrity algorithm string>
545 integ-keysize = <key size for encr-alg, if applicable>
546 prf-alg = <IKE pseudo random function string>
547 dh-group = <IKE Diffie-Hellman group string>
548 established = <seconds the IKE_SA has been established>
549 rekey-time = <seconds before IKE_SA gets rekeyed>
550 reauth-time = <seconds before IKE_SA gets re-authenticated>
552 <list of currently queued tasks for execution>
555 <list of tasks currently initiating actively>
558 <list of tasks currently handling passively>
562 uniqueid = <unique CHILD_SA identifier>
563 reqid = <reqid of CHILD_SA>
564 state = <state string of CHILD_SA>
565 mode = <IPsec mode, tunnel|transport|beet>
566 protocol = <IPsec protocol AH|ESP>
567 encap = <yes if using UDP encapsulation>
568 spi-in = <hex encoded inbound SPI>
569 spi-out = <hex encoded outbound SPI>
570 cpi-in = <hex encoded inbound CPI, if using compression>
571 cpi-out = <hex encoded outbound CPI, if using compression>
572 encr-alg = <ESP encryption algorithm name, if any>
573 encr-keysize = <ESP encryption key size, if applicable>
574 integ-alg = <ESP or AH integrity algorithm name, if any>
575 integ-keysize = <ESP or AH integrity key size, if applicable>
576 prf-alg = <CHILD_SA pseudo random function name>
577 dh-group = <CHILD_SA PFS rekeying DH group name, if any>
578 esn = <1 if using extended sequence numbers>
579 bytes-in = <number of input bytes processed>
580 packets-in = <number of input packets processed>
581 use-in = <seconds since last inbound packet, if any>
582 bytes-out = <number of output bytes processed>
583 packets-out = <number of output packets processed>
584 use-out = <seconds since last outbound packet, if any>
585 rekey-time = <seconds before CHILD_SA gets rekeyed>
586 life-time = <seconds before CHILD_SA expires>
587 install-time = <seconds the CHILD_SA has been installed>
589 <list of local traffic selectors>
592 <list of remote traffic selectors>
601 The _list-policy_ event is issued to stream installed policies during an active
602 _list-policies_ command.
605 <child-sa-config-name> = {
606 mode = <policy mode, tunnel|transport|pass|drop>
608 <list of local traffic selectors>
611 <list of remote traffic selectors>
618 The _list-conn_ event is issued to stream loaded connection during an active
619 _list-conns_ command.
622 <IKE_SA connection name> = {
624 <list of valid local IKE endpoint addresses>
627 <list of valid remote IKE endpoint addresses>
629 version = <IKE version as string, IKEv1|IKEv2 or 0 for any>
631 local*, remote* = { # multiple local and remote auth sections
632 class = <authentication type>
633 eap-type = <EAP type to authenticate if when using EAP>
634 eap-vendor = <EAP vendor for type, if any>
635 xauth = <xauth backend name>
636 revocation = <revocation policy>
638 aaa_id = <AAA authentication backend identity>
639 eap_id = <EAP identity for authentication>
640 xauth_id = <XAuth username for authentication>
642 <group membership required to use connection>
645 <certificates allowed for authentication>
648 <CA certificates allowed for authentication>
652 <CHILD_SA config name>* = {
655 <list of local traffic selectors>
658 <list of remote traffic selectors>
667 The _list-cert_ event is issued to stream loaded certificates during an active
668 _list-certs_ command.
671 type = <certificate type>
672 has_privkey = <set if a private key for the certificate is available>
673 data = <ASN1 encoded certificate data>
677 # libvici C client library #
679 libvici is the reference implementation of a C client library implementing
680 the vici protocol. It builds upon libstrongswan, but provides a stable API
681 to implement client applications in the C programming language. libvici uses
682 the libstrongswan thread pool to deliver event messages asynchronously.
684 ## Connecting to the daemon ##
686 This example shows how to connect to the daemon using the default URI, and
687 then perform proper cleanup:
695 int main(int argc, char *argv[])
701 conn = vici_connect(NULL);
705 vici_disconnect(conn);
710 fprintf(stderr, "connecting failed: %s\n", strerror(errno));
716 ## A simple client request ##
718 In the following example, a simple _version_ request is issued to the daemon
719 and the result is printed:
721 int get_version(vici_conn_t *conn)
727 req = vici_begin("version");
728 res = vici_submit(req, conn);
731 printf("%s %s (%s, %s, %s)\n",
732 vici_find_str(res, "", "daemon"),
733 vici_find_str(res, "", "version"),
734 vici_find_str(res, "", "sysname"),
735 vici_find_str(res, "", "release"),
736 vici_find_str(res, "", "machine"));
742 fprintf(stderr, "version request failed: %s\n", strerror(errno));
747 ## A request with event streaming and callback parsing ##
749 In this more advanced example, the _list-conns_ command is used to stream
750 loaded connections with the _list-conn_ event. The event message is parsed
751 with a simple callback to print the connection name:
753 int conn_cb(void *null, vici_res_t *res, char *name)
755 printf("%s\n", name);
759 void list_cb(void *null, char *name, vici_res_t *res)
761 if (vici_parse_cb(res, conn_cb, NULL, NULL, NULL) != 0)
763 fprintf(stderr, "parsing failed: %s\n", strerror(errno));
767 int list_conns(vici_conn_t *conn)
773 if (vici_register(conn, "list-conn", list_cb, NULL) == 0)
775 req = vici_begin("list-conns");
776 res = vici_submit(req, conn);
784 fprintf(stderr, "request failed: %s\n", strerror(errno));
786 vici_register(conn, "list-conn", NULL, NULL);
791 fprintf(stderr, "registration failed: %s\n", strerror(errno));
796 ## API documentation ##
798 More information about the libvici API is available in the _libvici.h_ header
799 file or the generated Doxygen documentation.
803 The _vici ruby gem_ is a pure ruby implementation of the VICI protocol to
804 implement client applications. It is provided in the _ruby_ subdirectory, and
805 gets built and installed if strongSwan has been _./configure_'d with
806 _--enable-vici_ and _--enable-ruby-gems_.
808 The _Connection_ class from the _Vici_ module provides the high level interface,
809 the underlying classes are usually not required to build ruby applications
810 using VICI. The _Connection_ class provides methods for the supported VICI
811 commands and an event listening mechanism.
813 To represent the VICI message data tree, the gem converts the binary encoding
814 to ruby data types. The _Connection_ class takes and returns ruby objects for
815 the exchanged message data:
816 * Sections get encoded as Hash, containing other sections as Hash, or
817 * Key/Values, where the values are Strings as Hash values
818 * Lists get encoded as Arrays with String values
819 Non-String values that are not a Hash nor an Array get converted with .to_s
822 ## Connecting to the daemon ##
824 To create a connection to the daemon, a socket can be passed to the
825 _Connection_ constructor. If none is passed, a default Unix socket at
826 _/var/run/charon.vici_ is used:
831 v = Vici::Connection.new(UNIXSocket.new("/var/run/charon.vici"))
833 ## A simple client request ##
835 An example to print the daemon version information is as simple as:
838 puts "%s %s (%s, %s, %s)" % [
839 x["daemon"], x["version"], x["sysname"], x["release"], x["machine"]
842 ## A request with closure invocation ##
844 The _Connection_ class takes care of event streaming by invoking a closure
845 for each event. The following example lists all loaded connections using the
846 _list-conns_ command and implicitly the _list-conn_ event:
848 v.list_conns { |conn|
849 conn.each { |key, value|
854 ## API documentation ##
856 For more details about the ruby gem refer to the comments in the gem source
857 code or the generated documentation.
861 The _vici Python egg_ is a pure Python implementation of the VICI protocol to
862 implement client applications. It is provided in the _python_ subdirectory, and
863 gets built and installed if strongSwan has been _./configure_'d with
864 _--enable-vici_ and _--enable-python-eggs_.
866 The _vici_ module provides a _Session()_ constructor for a high level interface,
867 the underlying classes are usually not required to build Python applications
868 using VICI. The _Session_ class provides methods for the supported VICI
871 To represent the VICI message data tree, the library converts the binary
872 encoding to Python data types. The _Session_ class takes and returns Python
873 objects for the exchanged message data:
874 * Sections get encoded as OrderedDict, containing other sections, or
875 * Key/Values, where the values are strings as dictionary values
876 * Lists get encoded as Python Lists with string values
877 Values that do not conform to Python dict or list get converted to strings using
880 ## Connecting to the daemon ##
882 To create a connection to the daemon, a socket can be passed to the _Session_
883 constructor. If none is passed, a default Unix socket at _/var/run/charon.vici_
889 s = socket.socket(socket.AF_UNIX)
890 s.connect("/var/run/charon.vici")
893 ## A simple client request ##
895 An example to print the daemon version information is as simple as:
899 print "{daemon} {version} ({sysname}, {release}, {machine})".format(**ver)
901 ## A request with response iteration ##
903 The _Session_ class returns an iterable list for streamed events. Currently a
904 list is returned with all streamed event messages, but a future release might
905 provide more scalable object streaming. The following example lists all loaded
906 connections using the _list-conns_ command and implicitly the _list-conn_ event:
908 for conn in v.list_conns():
912 ## Sorting in dictionaries ##
914 In VICI, in some message trees the order of objects in dictionary matters. In
915 contrast to ruby Hashes, Python dictionaries do not preserve order of added
916 objects. It is therefore recommended to use OrderedDicts instead of the default
917 dictionaries. Objects returned by the library use OrderedDicts.
919 ## API documentation ##
921 For more details about the Python egg refer to the comments in the Python source