session

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package session keeps state for the application, including internal state transitions for the OpenVPN protocol, data channel keys, and all the state pertaining to the different packet counters.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExpiredKey is the error we raise when we have an expired key.
	ErrExpiredKey = errors.New("expired key")

	// ErrNoRemoteSessionID indicates we are missing the remote session ID.
	ErrNoRemoteSessionID = errors.New("missing remote session ID")
)
View Source
var (
	// ErrDataChannelKey is a [DataChannelKey] error.
	ErrDataChannelKey = errors.New("bad data-channel key")
)

Functions

This section is empty.

Types

type DataChannelKey

type DataChannelKey struct {
	// contains filtered or unexported fields
}

DataChannelKey represents a pair of key sources that have been negotiated over the control channel, and from which we will derive local and remote keys for encryption and decrption over the data channel. The index refers to the short key_id that is passed in the lower 3 bits if a packet header. The setup of the keys for a given data channel (that is, for every key_id) is made by expanding the keysources using the prf function.

Do note that we are not yet implementing key renegotiation - but the index is provided for convenience when/if we support that in the future.

func (*DataChannelKey) AddLocalKey

func (dck *DataChannelKey) AddLocalKey(k *KeySource) error

AddLocalKey adds the local keySource to our dataChannelKey.

func (*DataChannelKey) AddRemoteKey

func (dck *DataChannelKey) AddRemoteKey(k *KeySource) error

AddRemoteKey adds the server keySource to our dataChannelKey. This makes the dataChannelKey ready to be used.

func (*DataChannelKey) Local

func (dck *DataChannelKey) Local() *KeySource

Local returns the local KeySource

func (*DataChannelKey) Ready

func (dck *DataChannelKey) Ready() bool

Ready returns whether the DataChannelKey is ready.

func (*DataChannelKey) Remote

func (dck *DataChannelKey) Remote() *KeySource

Remote returns the local KeySource

type KeySource

type KeySource struct {
	R1        [32]byte
	R2        [32]byte
	PreMaster [48]byte
}

KeySource contains random data to generate keys.

func NewKeySource

func NewKeySource() (*KeySource, error)

NewKeySource constructs a new KeySource.

func (*KeySource) Bytes

func (k *KeySource) Bytes() []byte

Bytes returns the byte representation of a KeySource.

type Manager

type Manager struct {

	// Ready is a channel where we signal that we can start accepting data, because we've
	// successfully generated key material for the data channel.
	Ready chan any

	// Failure is a channel where we receive any unrecoverable error.
	Failure chan error
	// contains filtered or unexported fields
}

Manager manages the session. The zero value is invalid. Please, construct using NewManager. This struct is concurrency safe.

func NewManager

func NewManager(config *config.Config) (*Manager, error)

NewManager returns a Manager ready to be used.

func (*Manager) ActiveKey

func (m *Manager) ActiveKey() (*DataChannelKey, error)

ActiveKey returns the dataChannelKey that is actively being used.

func (*Manager) CurrentKeyID

func (m *Manager) CurrentKeyID() uint8

CurrentKeyID returns the key ID currently in use.

func (*Manager) InitTunnelInfo

func (m *Manager) InitTunnelInfo(remoteOption string) error

InitTunnelInfo initializes TunnelInfo from data obtained from the auth response.

func (*Manager) IsRemoteSessionIDSet

func (m *Manager) IsRemoteSessionIDSet() bool

IsRemoteSessionIDSet returns whether we've set the remote session ID.

func (*Manager) LocalDataPacketID

func (m *Manager) LocalDataPacketID() (model.PacketID, error)

LocalDataPacketID returns an unique Packet ID for the Data Channel. It increments the counter for the local data packet ID.

func (*Manager) LocalSessionID

func (m *Manager) LocalSessionID() []byte

LocalSessionID gets the local session ID as bytes.

func (*Manager) NegotiationState

func (m *Manager) NegotiationState() model.NegotiationState

NegotiationState returns the state of the negotiation.

func (*Manager) NewACKForPacketIDs

func (m *Manager) NewACKForPacketIDs(ids []model.PacketID) (*model.Packet, error)

NewACKForPacketIDs creates a new ACK for the given packet IDs.

func (*Manager) NewHardResetPacket

func (m *Manager) NewHardResetPacket() *model.Packet

NewHardResetPacket creates a new hard reset packet for this session. This packet is a special case because, if we resend, we must not bump its packet ID. Normally retransmission is handled at the reliabletransport layer, but we send hard resets at the muxer.

func (*Manager) NewPacket

func (m *Manager) NewPacket(opcode model.Opcode, payload []byte) (*model.Packet, error)

NewPacket creates a new packet for this session.

func (*Manager) RemoteSessionID

func (m *Manager) RemoteSessionID() []byte

RemoteSessionID gets the remote session ID as bytes.

func (*Manager) SetNegotiationState

func (m *Manager) SetNegotiationState(sns model.NegotiationState)

SetNegotiationState sets the state of the negotiation.

func (*Manager) SetRemoteSessionID

func (m *Manager) SetRemoteSessionID(remoteSessionID model.SessionID)

SetRemoteSessionID sets the remote session ID.

func (*Manager) TunnelInfo

func (m *Manager) TunnelInfo() model.TunnelInfo

TunnelInfo returns a copy the current TunnelInfo

func (*Manager) UpdateTunnelInfo

func (m *Manager) UpdateTunnelInfo(ti *model.TunnelInfo)

UpdateTunnelInfo updates the internal tunnel info from the push response message

Jump to

Keyboard shortcuts

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