ipsec

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ipsec holds komando's own IPsec clients: IKEv1 (for L2TP/IPsec and Cisco-style IPsec with XAUTH) and IKEv2, with ESP carried in UDP (RFC 3948), so they run as an ordinary program without admin rights and without changing the computer's network: komando always tells the server it is behind NAT, so ESP never needs a raw socket.

Written from the RFCs (2407-2409, 3706, 3947, 3948, 4303, 7296, 7427, draft-beaulieu-ike-xauth, draft-dukes-ike-mode-cfg); no code from strongSwan, Libreswan or racoon is used.

Index

Constants

This section is empty.

Variables

View Source
var ErrNeedsPerson = errors.New("the VPN login asks for a one-time code; a person runs `komando vpn up NAME`")

ErrNeedsPerson: the login asks for a one-time code and nobody is there.

Functions

This section is empty.

Types

type AuthError

type AuthError struct{ Msg string }

AuthError is a login the server refused.

func (*AuthError) Error

func (e *AuthError) Error() string
type L2TPLink struct {
	// contains filtered or unexported fields
}

L2TPLink carries L2TP over ESP transport mode: UDP port 1701 both ways.

func (*L2TPLink) Done

func (l *L2TPLink) Done() <-chan struct{}

func (*L2TPLink) Recv

func (l *L2TPLink) Recv() <-chan []byte

func (*L2TPLink) Send

func (l *L2TPLink) Send(b []byte) error

Send sends one L2TP datagram. The UDP checksum is 0 (allowed for IPv4; ESP already protects the datagram).

type LegacyCryptoError added in v0.7.0

type LegacyCryptoError struct{ Msg string }

LegacyCryptoError: the server accepted none of the strong IKEv1 proposals and may speak only old, weak ciphers, which komando offers only when legacy crypto is allowed (Options.LegacyCrypto). The caller names the per-VPN setting that allows them.

func (*LegacyCryptoError) Error added in v0.7.0

func (e *LegacyCryptoError) Error() string

type Options

type Options struct {
	Server   string // host or host:port of the IKE server
	PSK      string // pre-shared key (IKEv1; IKEv2 when no EAP)
	User     string // XAUTH / L2TP PPP / EAP user name
	Password string
	ID       string // IKEv1: the group name (aggressive mode); IKEv2: our identity
	RemoteID string // IKEv2: the server's identity (default: Server's host)
	CA       []byte // IKEv2: the CA that signed the server certificate (PEM); empty: the system's
	// Prompt asks a person for a one-time code (XAUTH); nil: nobody there.
	Prompt func(label string, secret bool) (string, error)
	Log    func(format string, args ...any)
	// Lifetime of the SAs komando proposes (0: 8h for IKE, 1h for ESP).
	Lifetime time.Duration
	// Debug logs every IKE message sent and received (sizes, types).
	Debug bool
	// LegacyCrypto lets IKEv1 also offer and accept 3DES and the small DH
	// groups 2 (1024-bit) and 5 (1536-bit), which old servers may still
	// need. They are weak, so a person turns this on for one VPN at a time.
	LegacyCrypto bool
}

Options are what a client needs to connect.

type Session

type Session struct {

	// tunnel mode: the address and DNS servers the server gave
	Address netip.Addr
	DNS     []netip.Addr
	// contains filtered or unexported fields
}

Session is an established IPsec connection: ESP SAs over UDP, kept up (dead peer detection, rekeys) until closed.

func DialCisco

func DialCisco(ctx context.Context, o Options) (*Session, error)

DialCisco connects Cisco-style IPsec (IKEv1 with XAUTH and mode config, as in Cisco ASA/IOS, MikroTik, strongSwan and the "IPSec" type of macOS and iOS): ESP in tunnel mode; Address and DNS are the server's.

func DialIKEv2

func DialIKEv2(ctx context.Context, o Options) (*Session, error)

DialIKEv2 connects an IKEv2 VPN: with a pre-shared key, or with an EAP login (User, Password) after checking the server's certificate.

func DialL2TP

func DialL2TP(ctx context.Context, o Options) (*Session, error)

DialL2TP sets up the IPsec part of L2TP/IPsec: ESP in transport mode for UDP port 1701, with a pre-shared key. The caller runs L2TP over it.

func (*Session) Close

func (s *Session) Close() error

Close ends the session, telling the server.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done is closed when the session ended.

func (*Session) Err

func (s *Session) Err() error

Err says why the session ended.

func (*Session) L2TP

func (s *Session) L2TP() *L2TPLink

L2TP returns the session's L2TP datagram link.

func (*Session) Tunnel

func (s *Session) Tunnel() *Tunnel

Tunnel returns the session as a packet tunnel.

type Tunnel

type Tunnel struct {
	*Session
	// contains filtered or unexported fields
}

Tunnel is a tunnel-mode session: IPv4 packets in and out.

func (*Tunnel) Addresses

func (t *Tunnel) Addresses() []netip.Addr

func (*Tunnel) DNS

func (t *Tunnel) DNS() []netip.Addr

func (*Tunnel) MTU

func (t *Tunnel) MTU() int

func (*Tunnel) Packets

func (t *Tunnel) Packets() <-chan []byte

func (*Tunnel) WritePacket

func (t *Tunnel) WritePacket(p []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL