vici - strongSwan VICI Protocol Interface

6.0.3 · active · verified Thu Apr 16

The 'vici' Python library provides a native interface for strongSwan's Versatile IKE Control Interface (VICI) protocol. It enables external Python applications to configure, monitor, and control the strongSwan 'charon' IKE daemon. The library is currently at version 6.0.3 and is actively maintained, with regular updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to the strongSwan `charon` daemon via its VICI Unix socket, retrieve its version, and list configured connections. It includes error handling for common connection issues like missing sockets or permission errors. Remember to ensure the strongSwan daemon is running and accessible.

import vici
import socket
import os

# Default VICI socket path for Unix-like systems
VICI_SOCKET_PATH = os.environ.get('VICI_SOCKET', '/var/run/charon.vici')

try:
    # Connect to the VICI socket
    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    s.connect(VICI_SOCKET_PATH)
    session = vici.Session(s)

    # Get and print the daemon version information
    version_info = session.version()
    print(f"Connected to strongSwan daemon: {version_info['daemon']} {version_info['version']} "
          f"({version_info['sysname']}, {version_info['release']}, {version_info['machine']})")

    # Example: List loaded connections
    print("\nLoaded Connections:")
    conns_found = False
    for conn in session.list_conns():
        conns_found = True
        print(f"  - {list(conn.keys())[0]}") # Connection name is the first key
    if not conns_found:
        print("  (No connections found)")

    # Important: Close the session/socket when done
    session.close()
    s.close()

except FileNotFoundError:
    print(f"Error: VICI socket not found at {VICI_SOCKET_PATH}. Is strongSwan charon running?")
except PermissionError:
    print(f"Error: Permission denied when accessing VICI socket at {VICI_SOCKET_PATH}. "
          "Adjust socket permissions or run with appropriate privileges.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →