ikev2

package
v0.0.0-...-4c693b6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNonceLength          = 32
	DefaultIKEKeyMaterialLength = 192
)
View Source
const (
	ProtocolIKE uint8 = 1
	ProtocolAH  uint8 = 2
	ProtocolESP uint8 = 3
)
View Source
const (
	NotifyUnsupportedCriticalPayload uint16 = 1
	NotifyInvalidIKESPI              uint16 = 4
	NotifyInvalidMajorVersion        uint16 = 5
	NotifyInvalidSyntax              uint16 = 7
	NotifyInvalidMessageID           uint16 = 9
	NotifyInvalidSPI                 uint16 = 11
	NotifyNoProposalChosen           uint16 = 14
	NotifyInvalidKEPayload           uint16 = 17
	NotifyAuthenticationFailed       uint16 = 24
	NotifySinglePairRequired         uint16 = 34
	NotifyNoAdditionalSAs            uint16 = 35
	NotifyInternalAddressFailure     uint16 = 36
	NotifyFailedCPRequired           uint16 = 37
	NotifyTSUnacceptable             uint16 = 38
	NotifyInvalidSelectors           uint16 = 39
	NotifyUnacceptableAddresses      uint16 = 40
	NotifyUnexpectedNATDetected      uint16 = 41
	NotifyNATDetectionSourceIP       uint16 = 16388
	NotifyNATDetectionDestinationIP  uint16 = 16389
	NotifyCookie                     uint16 = 16390
	NotifyRekeySA                    uint16 = 16393
	NotifyMOBIKESupported            uint16 = 16396
	NotifyAdditionalIPv4Address      uint16 = 16397
	NotifyAdditionalIPv6Address      uint16 = 16398
	NotifyNoAdditionalAddresses      uint16 = 16399
	NotifyUpdateSAAddresses          uint16 = 16400
	NotifyCookie2                    uint16 = 16401
	NotifyNoNATsAllowed              uint16 = 16402
)
View Source
const (
	MaxIKECookieLength        = 64
	DHGroup2048BitMODP uint16 = 14
	DHGroup256BitECP   uint16 = 19
	DHGroup384BitECP   uint16 = 20
	DHGroup521BitECP   uint16 = 21
	DHGroupCurve25519  uint16 = 31
)
View Source
const (
	TransformENCR     uint8 = 1
	TransformPRF      uint8 = 2
	TransformINTEG    uint8 = 3
	TransformDHRGroup uint8 = 4
	TransformESN      uint8 = 5
)
View Source
const (
	ENCR_AES_CBC    uint16 = 12
	ENCR_AES_GCM_16 uint16 = 20

	PRF_HMAC_SHA1     uint16 = 2
	PRF_HMAC_SHA2_256 uint16 = 5
	PRF_HMAC_SHA2_384 uint16 = 6
	PRF_HMAC_SHA2_512 uint16 = 7

	INTEG_HMAC_SHA1_96      uint16 = 2
	INTEG_AES_XCBC_96       uint16 = 5
	INTEG_HMAC_SHA2_256_128 uint16 = 12
	INTEG_HMAC_SHA2_384_192 uint16 = 13
	INTEG_HMAC_SHA2_512_256 uint16 = 14

	ESNNo  uint16 = 0
	ESNYes uint16 = 1
)
View Source
const (
	IDIPv4Addr   uint8 = 1
	IDFQDN       uint8 = 2
	IDRFC822Addr uint8 = 3
	IDIPv6Addr   uint8 = 5
	IDKeyID      uint8 = 11
)
View Source
const (
	CFGRequest uint8 = 1
	CFGReply   uint8 = 2
	CFGSet     uint8 = 3
	CFGAck     uint8 = 4
)
View Source
const (
	ConfigInternalIPv4Address   uint16 = 1
	ConfigInternalIPv4DNS       uint16 = 3
	ConfigInternalAddressExpiry uint16 = 5
	ConfigInternalIPv6Address   uint16 = 8
	ConfigInternalIPv6DNS       uint16 = 10
	ConfigInternalIPv4Subnet    uint16 = 13
	ConfigSupportedAttributes   uint16 = 14
	ConfigInternalIPv6Subnet    uint16 = 15
)
View Source
const (
	TSIPv4AddressRange uint8 = 7
	TSIPv6AddressRange uint8 = 8
)
View Source
const (
	PayloadNoNext   uint8 = 0
	PayloadSA       uint8 = 33
	PayloadKE       uint8 = 34
	PayloadIDi      uint8 = 35
	PayloadIDr      uint8 = 36
	PayloadCERT     uint8 = 37
	PayloadCERTREQ  uint8 = 38
	PayloadAUTH     uint8 = 39
	PayloadNonce    uint8 = 40
	PayloadNotify   uint8 = 41
	PayloadDelete   uint8 = 42
	PayloadVendorID uint8 = 43
	PayloadTSi      uint8 = 44
	PayloadTSr      uint8 = 45
	PayloadSK       uint8 = 46
	PayloadCP       uint8 = 47
	PayloadEAP      uint8 = 48
	PayloadSKF      uint8 = 53
)
View Source
const (
	ExchangeIKE_SA_INIT     uint8 = 34
	ExchangeIKE_AUTH        uint8 = 35
	ExchangeCREATE_CHILD_SA uint8 = 36
	ExchangeINFORMATIONAL   uint8 = 37
)
View Source
const (
	FlagInitiator uint8 = 0x08
	FlagVersion   uint8 = 0x10
	FlagResponse  uint8 = 0x20
)
View Source
const (
	AttributeKeyLength uint16 = 14
)
View Source
const HeaderLength = 28

Variables

View Source
var (
	ErrInvalidAuthConfig   = errors.New("invalid ikev2 auth config")
	ErrInvalidAuthResponse = errors.New("invalid ikev2 auth response")
)
View Source
var (
	ErrInvalidInitConfig   = errors.New("invalid ikev2 init config")
	ErrInvalidInitResponse = errors.New("invalid ikev2 init response")
)
View Source
var (
	ErrInvalidNotify                    = errors.New("invalid ikev2 notify payload")
	ErrIKEv2NotifyError                 = errors.New("ikev2 notify error")
	ErrNotifyUnsupportedCriticalPayload = errors.New("ikev2 unsupported critical payload notify")
	ErrNotifyInvalidIKESPI              = errors.New("ikev2 invalid ike spi notify")
	ErrNotifyInvalidMajorVersion        = errors.New("ikev2 invalid major version notify")
	ErrNotifyInvalidSyntax              = errors.New("ikev2 invalid syntax notify")
	ErrNotifyInvalidMessageID           = errors.New("ikev2 invalid message id notify")
	ErrNotifyInvalidSPI                 = errors.New("ikev2 invalid spi notify")
	ErrNotifyNoProposalChosen           = errors.New("ikev2 no proposal chosen notify")
	ErrNotifyInvalidKEPayload           = errors.New("ikev2 invalid ke payload notify")
	ErrNotifyAuthenticationFailed       = errors.New("ikev2 authentication failed notify")
	ErrNotifySinglePairRequired         = errors.New("ikev2 single pair required notify")
	ErrNotifyNoAdditionalSAs            = errors.New("ikev2 no additional sas notify")
	ErrNotifyInternalAddressFailure     = errors.New("ikev2 internal address failure notify")
	ErrNotifyFailedCPRequired           = errors.New("ikev2 failed cp required notify")
	ErrNotifyTSUnacceptable             = errors.New("ikev2 ts unacceptable notify")
	ErrNotifyInvalidSelectors           = errors.New("ikev2 invalid selectors notify")
	ErrNotifyUnacceptableAddresses      = errors.New("ikev2 unacceptable addresses notify")
	ErrNotifyUnexpectedNATDetected      = errors.New("ikev2 unexpected nat detected notify")
	ErrInvalidDelete                    = errors.New("invalid ikev2 delete payload")
	ErrInvalidAddress                   = errors.New("invalid ikev2 address")
)
View Source
var (
	ErrInvalidSA              = errors.New("invalid ikev2 sa payload")
	ErrUnsupportedSASelection = errors.New("unsupported ikev2 selected sa")
)
View Source
var (
	ErrInvalidIdentity        = errors.New("invalid ikev2 identity payload")
	ErrInvalidConfiguration   = errors.New("invalid ikev2 configuration payload")
	ErrInvalidTrafficSelector = errors.New("invalid ikev2 traffic selector payload")
)
View Source
var (
	ErrShortHeader   = errors.New("ikev2 header too short")
	ErrShortPayload  = errors.New("ikev2 payload too short")
	ErrInvalidLength = errors.New("ikev2 invalid length")
)
View Source
var ErrInvalidChildSA = errors.New("invalid ikev2 child sa")
View Source
var ErrInvalidCreateChild = errors.New("invalid ikev2 create child sa exchange")
View Source
var ErrInvalidEncryptedFragment = errors.New("invalid ikev2 encrypted fragment payload")
View Source
var ErrInvalidInformational = errors.New("invalid ikev2 informational exchange")
View Source
var ErrInvalidSKPayload = errors.New("invalid ikev2 sk payload")
View Source
var ErrUnsupportedPRF = errors.New("unsupported ikev2 prf")
View Source
var ErrUnsupportedTransform = errors.New("unsupported ikev2 transform")

Functions

func DeriveIKESAKeyMaterial

func DeriveIKESAKeyMaterial(hash crypto.Hash, skeyseed, nonceI, nonceR []byte, spiI, spiR uint64, length int) ([]byte, error)

func FirstNotifyError

func FirstNotifyError(payloads []Payload) error

func IntegrityChecksum

func IntegrityChecksum(profile KeyMaterialProfile, key, data []byte) ([]byte, error)

func InvalidKEPayloadAlternativeGroupFromError

func InvalidKEPayloadAlternativeGroupFromError(err error) (uint16, bool, error)

InvalidKEPayloadAlternativeGroupFromError extracts an INVALID_KE_PAYLOAD suggested DH group from a wrapped NotifyError.

func MarshalPayloads

func MarshalPayloads(payloads []Payload) (first uint8, data []byte, err error)

func NATDetectionHash

func NATDetectionHash(spiI, spiR uint64, ip net.IP, port uint16) ([]byte, error)

func NotifyErrorFor

func NotifyErrorFor(n Notify) error

func NotifyTypeName

func NotifyTypeName(notifyType uint16) string

func PRF

func PRF(hash crypto.Hash, key, data []byte) ([]byte, error)

func PRFHashForTransform

func PRFHashForTransform(id uint16) (crypto.Hash, error)

func PRFPlus

func PRFPlus(hash crypto.Hash, key, seed []byte, length int) ([]byte, error)

func ParseInformationalRequest

func ParseInformationalRequest(raw []byte, init InitResult, keys IKEKeys, messageID uint32) (Message, []Payload, error)

func ParseInformationalRequestContent

func ParseInformationalRequestContent(raw []byte, init InitResult, keys IKEKeys, messageID uint32) (Message, InformationalContent, error)

func ParseInformationalRequestContentFrom

func ParseInformationalRequestContentFrom(raw []byte, init InitResult, keys IKEKeys, messageID uint32, fromInitiator bool) (Message, InformationalContent, error)

func ParseInformationalRequestFrom

func ParseInformationalRequestFrom(raw []byte, init InitResult, keys IKEKeys, messageID uint32, fromInitiator bool) (Message, []Payload, error)

func ParseInformationalResponse

func ParseInformationalResponse(raw []byte, init InitResult, keys IKEKeys, messageID uint32) (Message, []Payload, error)

func ParseInformationalResponseContent

func ParseInformationalResponseContent(raw []byte, init InitResult, keys IKEKeys, messageID uint32) (Message, InformationalContent, error)

func ParseInformationalResponseContentFrom

func ParseInformationalResponseContentFrom(raw []byte, init InitResult, keys IKEKeys, messageID uint32, fromInitiator bool) (Message, InformationalContent, error)

func ParseInformationalResponseFrom

func ParseInformationalResponseFrom(raw []byte, init InitResult, keys IKEKeys, messageID uint32, fromInitiator bool) (Message, []Payload, error)

func RandomIV

func RandomIV(random io.Reader, profile KeyMaterialProfile) ([]byte, error)

func SKEYSEED

func SKEYSEED(hash crypto.Hash, nonceI, nonceR, sharedSecret []byte) ([]byte, error)

func UnprotectMessage

func UnprotectMessage(raw []byte, keys IKEKeys, fromInitiator bool) (Message, []Payload, error)

func ValidateSelectedSA

func ValidateSelectedSA(offered, selected SecurityAssociation) error

func ValidateTrafficSelectorNarrowing

func ValidateTrafficSelectorNarrowing(offered, selected TrafficSelectors) error

Types

type AKAChallengeConfig

type AKAChallengeConfig struct {
	Transport          InitTransport
	Init               InitResult
	Keys               IKEKeys
	SIM                sim.AKAProvider
	EAPKeys            eapaka.Keys
	Identity           string
	Request            eapaka.Packet
	IdentityTranscript [][]byte
	ChildSPI           []byte
	TSi                TrafficSelectors
	TSr                TrafficSelectors
	MessageID          uint32
	Random             io.Reader
	IV                 []byte
	EAPReauthIV        []byte
	EAPReauthCounter   uint16
	EAPReauthCounterOK bool
}

type AKAChallengeResult

type AKAChallengeResult struct {
	RequestBytes             []byte
	ResponseBytes            []byte
	ResponseInner            []Payload
	EAPResponse              eapaka.Packet
	EAPNext                  *eapaka.Packet
	EAPKeys                  eapaka.Keys
	EAPEncryptedAttributes   []eapaka.Attribute
	EAPNextPseudonym         string
	EAPNextReauthID          string
	EAPReauthenticated       bool
	EAPReauthCounter         uint16
	EAPReauthCounterTooSmall bool
	EAPNotifications         []eapaka.Packet
	EAPClientError           bool
	ChildSA                  *ChildSAResult
	SyncFailure              bool
	AuthFailure              bool
	KDFNegotiated            bool
	NextMessageID            uint32
	FollowupRequestBytes     [][]byte
	FollowupResponseBytes    [][]byte
	FinalResponseBytes       []byte
	FinalResponseInner       []Payload
}

func RunIKE_AUTH_AKAChallenge

func RunIKE_AUTH_AKAChallenge(ctx context.Context, cfg AKAChallengeConfig) (AKAChallengeResult, error)

type AuthConfig

type AuthConfig struct {
	Transport         InitTransport
	Init              InitResult
	Keys              IKEKeys
	InitiatorID       Identity
	EAPIdentity       string
	EAPPseudonym      string
	EAPReauthIdentity string
	ChildSA           SecurityAssociation
	ChildSPI          []byte
	TSi               TrafficSelectors
	TSr               TrafficSelectors
	Configuration     Configuration
	Random            io.Reader
	InitialIV         []byte
	EAPIdentityIV     []byte
	InitialMessageID  uint32
}

type AuthResult

type AuthResult struct {
	InitialRequestBytes   []byte
	InitialResponseBytes  []byte
	IdentityRequestBytes  []byte
	IdentityResponseBytes []byte
	InitialResponseInner  []Payload
	IdentityResponseInner []Payload
	EAPRequest            *eapaka.Packet
	EAPAfterIdentity      *eapaka.Packet
	EAPIdentityUsed       string
	IdentityTranscript    [][]byte
	NextMessageID         uint32
}

func RunIKE_AUTH_EAPIdentity

func RunIKE_AUTH_EAPIdentity(ctx context.Context, cfg AuthConfig) (AuthResult, error)

type ChildSADeleteMatch

type ChildSADeleteMatch struct {
	ProtocolID    uint8
	SPI           []byte
	MatchesLocal  bool
	MatchesRemote bool
}

type ChildSADeleteOutcome

type ChildSADeleteOutcome uint8
const (
	ChildSADeleteNone ChildSADeleteOutcome = iota
	// ChildSADeleteCurrent means every AH/ESP delete SPI matches the tracked ESP child.
	ChildSADeleteCurrent
	// ChildSADeleteOther means AH/ESP delete payloads exist, but none match the tracked ESP child.
	ChildSADeleteOther
	// ChildSADeleteMixed means an INFORMATIONAL deletes both the tracked child and other AH/ESP SPIs.
	ChildSADeleteMixed
)

type ChildSADeleteSummary

type ChildSADeleteSummary struct {
	Outcome       ChildSADeleteOutcome
	Deletes       []ChildSADeleteMatch
	CurrentSPIs   [][]byte
	OtherSPIs     [][]byte
	MatchesLocal  bool
	MatchesRemote bool
	DeleteIKE     bool
}

func ClassifyChildSADeletePayloads

func ClassifyChildSADeletePayloads(payloads []Payload, child ChildSAResult) (ChildSADeleteSummary, error)

func ClassifyChildSADeletes

func ClassifyChildSADeletes(content InformationalContent, child ChildSAResult) ChildSADeleteSummary

ClassifyChildSADeletes summarizes AH/ESP Delete payloads against a tracked ESP child SA.

type ChildSAKeys

type ChildSAKeys struct {
	Profile  ESPKeyProfile
	Outbound ESPKeys
	Inbound  ESPKeys
}

func DeriveChildSAKeys

func DeriveChildSAKeys(init InitResult, selectedSA SecurityAssociation) (ChildSAKeys, error)

func DeriveChildSAKeysWithNonces

func DeriveChildSAKeysWithNonces(prf crypto.Hash, skD, nonceI, nonceR []byte, selectedSA SecurityAssociation) (ChildSAKeys, error)

type ChildSARekeyConfig

type ChildSARekeyConfig struct {
	Transport  InitTransport
	Init       InitResult
	Keys       IKEKeys
	MessageID  uint32
	OldChildSA ChildSAResult
	ChildSA    SecurityAssociation
	ChildSPI   []byte
	RekeySPI   []byte
	TSi        TrafficSelectors
	TSr        TrafficSelectors
	Nonce      []byte
	Random     io.Reader
	IV         []byte
}

type ChildSARekeyPlan

type ChildSARekeyPlan struct {
	Config       CreateChildSAConfig
	OldLocalSPI  []byte
	OldRemoteSPI []byte
	RekeySPI     []byte
	NewLocalSPI  []byte
}

func NewChildSARekeyPlan

func NewChildSARekeyPlan(cfg ChildSARekeyConfig) (ChildSARekeyPlan, error)

type ChildSAResult

type ChildSAResult struct {
	SelectedSA    SecurityAssociation
	TSi           TrafficSelectors
	TSr           TrafficSelectors
	Configuration *Configuration
	LocalSPI      []byte
	RemoteSPI     []byte
	Keys          ChildSAKeys
	EAPSuccess    bool
	NextMessageID uint32
}

func ParseChildSAResult

func ParseChildSAResult(init InitResult, inner []Payload, localSPI []byte) (ChildSAResult, error)

func ParseChildSAResultWithNonces

func ParseChildSAResultWithNonces(init InitResult, inner []Payload, localSPI, nonceI, nonceR []byte) (ChildSAResult, error)

type Configuration

type Configuration struct {
	Type       uint8
	Attributes []ConfigurationAttribute
}

func ParseConfiguration

func ParseConfiguration(data []byte) (Configuration, error)

func SWuConfigurationRequest

func SWuConfigurationRequest() Configuration

func (Configuration) MarshalBinary

func (c Configuration) MarshalBinary() ([]byte, error)

type ConfigurationAttribute

type ConfigurationAttribute struct {
	Type  uint16
	Value []byte
}

type CreateChildSAConfig

type CreateChildSAConfig struct {
	Transport InitTransport
	Init      InitResult
	Keys      IKEKeys
	MessageID uint32
	ChildSA   SecurityAssociation
	ChildSPI  []byte
	TSi       TrafficSelectors
	TSr       TrafficSelectors
	Nonce     []byte
	RekeySPI  []byte
	Random    io.Reader
	IV        []byte
}

type CreateChildSAResult

type CreateChildSAResult struct {
	RequestBytes  []byte
	ResponseBytes []byte
	RequestNonce  []byte
	ResponseNonce []byte
	ResponseInner []Payload
	ChildSA       ChildSAResult
	NextMessageID uint32
	Rekeyed       bool
}

func RunCREATE_CHILD_SARekey

func RunCREATE_CHILD_SARekey(ctx context.Context, cfg ChildSARekeyConfig) (CreateChildSAResult, error)

type Delete

type Delete struct {
	ProtocolID uint8
	SPIs       [][]byte
}

func ParseDelete

func ParseDelete(data []byte) (Delete, error)

func (Delete) MarshalBinary

func (d Delete) MarshalBinary() ([]byte, error)

type EAPIdentityExchange

type EAPIdentityExchange struct {
	Request       eapaka.Packet
	Response      eapaka.Packet
	Identity      string
	RequestBytes  []byte
	ResponseBytes []byte
	ResponseInner []Payload
	EAPNext       *eapaka.Packet
	Transcript    [][]byte
	NextMessageID uint32
}

type ESPKeyProfile

type ESPKeyProfile struct {
	EncryptionID        uint16
	EncryptionKeyLength int
	IntegrityID         uint16
	IntegrityKeyLength  int
	ESN                 bool
}

func ESPKeyProfileFromSA

func ESPKeyProfileFromSA(sa SecurityAssociation) (ESPKeyProfile, error)

func (ESPKeyProfile) DirectionKeyLength

func (p ESPKeyProfile) DirectionKeyLength() int

type ESPKeys

type ESPKeys struct {
	EncryptionKey []byte
	IntegrityKey  []byte
}

type EncryptedFragment

type EncryptedFragment struct {
	FragmentNumber uint16
	TotalFragments uint16
	EncryptedData  []byte
}

func ParseEncryptedFragment

func ParseEncryptedFragment(data []byte) (EncryptedFragment, error)

func (EncryptedFragment) MarshalBinary

func (f EncryptedFragment) MarshalBinary() ([]byte, error)

type FullAuthConfig

type FullAuthConfig struct {
	Transport          InitTransport
	Init               InitResult
	Keys               IKEKeys
	SIM                sim.AKAProvider
	EAPKeys            eapaka.Keys
	InitiatorID        Identity
	EAPIdentity        string
	EAPPseudonym       string
	EAPReauthIdentity  string
	EAPReauthCounter   uint16
	EAPReauthCounterOK bool
	ChildSA            SecurityAssociation
	ChildSPI           []byte
	TSi                TrafficSelectors
	TSr                TrafficSelectors
	Configuration      Configuration
	Random             io.Reader
	InitialIV          []byte
	EAPIdentityIV      []byte
	EAPReauthIV        []byte
	InitialMessageID   uint32
}

type FullAuthResult

type FullAuthResult struct {
	Auth                     AuthResult
	IdentityExchanges        []EAPIdentityExchange
	AKAChallenges            []AKAChallengeResult
	ChildSA                  *ChildSAResult
	EAPKeys                  eapaka.Keys
	EAPLast                  *eapaka.Packet
	EAPNotifications         []eapaka.Packet
	EAPClientError           bool
	EAPNextPseudonym         string
	EAPNextReauthID          string
	EAPReauthenticated       bool
	EAPReauthCounter         uint16
	EAPReauthCounterTooSmall bool
	SyncFailure              bool
	AuthFailure              bool
	KDFNegotiations          int
	NextMessageID            uint32
	FinalResponseBytes       []byte
	FinalResponseInner       []Payload
}

func RunIKE_AUTH_Full

func RunIKE_AUTH_Full(ctx context.Context, cfg FullAuthConfig) (FullAuthResult, error)
type Header struct {
	InitiatorSPI uint64
	ResponderSPI uint64
	NextPayload  uint8
	Version      uint8
	ExchangeType uint8
	Flags        uint8
	MessageID    uint32
	Length       uint32
}

func ParseHeader

func ParseHeader(data []byte) (Header, error)

func (Header) MarshalBinary

func (h Header) MarshalBinary() ([]byte, error)

type IKEKeys

type IKEKeys struct {
	Profile KeyMaterialProfile
	SKD     []byte
	SKAi    []byte
	SKAr    []byte
	SKEi    []byte
	SKEr    []byte
	SKPi    []byte
	SKPr    []byte
}

func SplitIKEKeys

func SplitIKEKeys(profile KeyMaterialProfile, keyMaterial []byte) (IKEKeys, error)

type Identity

type Identity struct {
	Type uint8
	Data []byte
}

func ParseIdentity

func ParseIdentity(data []byte) (Identity, error)

func (Identity) MarshalBinary

func (id Identity) MarshalBinary() ([]byte, error)

type InformationalConfig

type InformationalConfig struct {
	Transport     InitTransport
	Init          InitResult
	Keys          IKEKeys
	MessageID     uint32
	FromResponder bool
	Payloads      []Payload
	Random        io.Reader
	IV            []byte
}

type InformationalContent

type InformationalContent struct {
	Payloads      []Payload
	Notifies      []Notify
	NotifyActions []NotifyAction
	Deletes       []Delete
	NotifyError   error
}

func ParseInformationalContent

func ParseInformationalContent(payloads []Payload) (InformationalContent, error)

type InformationalHandling

type InformationalHandling struct {
	Empty                 bool
	LivenessCheck         bool
	DeleteIKE             bool
	DeleteESP             [][]byte
	DeleteAH              [][]byte
	UpdateSAAddresses     bool
	NoAdditionalAddresses bool
	AdditionalAddresses   []net.IP
	Cookie2               []byte
	InvalidSelectors      []InvalidSelectorReport
	NotifyError           error
	Notifies              []Notify
	NotifyActions         []NotifyAction
	Deletes               []Delete
}

func HandleInformationalContent

func HandleInformationalContent(content InformationalContent) (InformationalHandling, error)

func HandleInformationalPayloads

func HandleInformationalPayloads(payloads []Payload) (InformationalHandling, error)

type InformationalRecoveryAction

type InformationalRecoveryAction uint8
const (
	InformationalRecoveryNoAction InformationalRecoveryAction = iota
	InformationalRecoveryUpdateMOBIKEAddresses
	InformationalRecoveryMOBIKEAddressRecovery
	InformationalRecoveryRekeyChildSA
	InformationalRecoveryRetryExchange
	InformationalRecoveryWaitAndRetry
	InformationalRecoveryRecreateChildSA
	InformationalRecoveryRecreateIKESA
	InformationalRecoveryReauthenticate
	InformationalRecoveryAbort
)

func (InformationalRecoveryAction) String

type InformationalRecoveryPlan

type InformationalRecoveryPlan struct {
	Action                InformationalRecoveryAction
	Reason                string
	Retry                 bool
	RetryLater            bool
	RecreateIKE           bool
	RecreateChild         bool
	RekeyChild            bool
	Reauthenticate        bool
	MOBIKEAddressRecovery bool
	SuggestedDHGroup      uint16
	EchoCookie2           bool
	DeleteIKE             bool
	DeleteCurrentChild    bool
	DeleteOtherChild      bool
	UpdateSAAddresses     bool
	Response              InformationalResponsePlan
	ChildDeletes          ChildSADeleteSummary
	NotifyActions         []NotifyAction
}

func PlanInformationalRecovery

func PlanInformationalRecovery(content InformationalContent, child ChildSAResult) (InformationalRecoveryPlan, error)

func PlanInformationalRecoveryPayloads

func PlanInformationalRecoveryPayloads(payloads []Payload, child ChildSAResult) (InformationalRecoveryPlan, error)

type InformationalResponsePlan

type InformationalResponsePlan struct {
	Payloads    []Payload
	EchoCookie2 bool
}

func PlanInformationalResponse

func PlanInformationalResponse(handling InformationalHandling) (InformationalResponsePlan, error)

type InformationalResult

type InformationalResult struct {
	RequestBytes  []byte
	ResponseBytes []byte
	ResponseInner []Payload
	Response      InformationalContent
	NextMessageID uint32
}

func RunInformationalExchange

func RunInformationalExchange(ctx context.Context, cfg InformationalConfig) (InformationalResult, error)

type InitConfig

type InitConfig struct {
	Transport         InitTransport
	Random            io.Reader
	SA                SecurityAssociation
	InitiatorSPI      uint64
	NonceI            []byte
	X25519PrivateKey  []byte
	LocalIP           net.IP
	LocalPort         uint16
	RemoteIP          net.IP
	RemotePort        uint16
	KeyMaterialLength int
}

type InitResult

type InitResult struct {
	RequestBytes    []byte
	ResponseBytes   []byte
	Request         Message
	Response        Message
	SelectedSA      SecurityAssociation
	InitiatorSPI    uint64
	ResponderSPI    uint64
	NonceI          []byte
	NonceR          []byte
	PublicKeyI      []byte
	PublicKeyR      []byte
	SharedSecret    []byte
	PRF             crypto.Hash
	SKEYSEED        []byte
	KeyMaterial     []byte
	Keys            IKEKeys
	MOBIKESupported bool
	NATDetected     bool
}

func RunIKE_SA_INIT

func RunIKE_SA_INIT(ctx context.Context, cfg InitConfig) (InitResult, error)

type InitTransport

type InitTransport interface {
	ExchangeIKE(context.Context, []byte) ([]byte, error)
}

type InvalidSelectorReport

type InvalidSelectorReport struct {
	ProtocolID   uint8
	SPI          []byte
	PacketPrefix []byte
}

func InvalidSelectorReportFromError

func InvalidSelectorReportFromError(err error) (InvalidSelectorReport, bool, error)

type KeyExchange

type KeyExchange struct {
	DHGroup uint16
	KeyData []byte
}

func ParseKeyExchange

func ParseKeyExchange(data []byte) (KeyExchange, error)

func (KeyExchange) MarshalBinary

func (k KeyExchange) MarshalBinary() []byte

type KeyMaterialProfile

type KeyMaterialProfile struct {
	PRF                     crypto.Hash
	EncryptionID            uint16
	EncryptionKeyLength     int
	EncryptionBlockSize     int
	IntegrityID             uint16
	IntegrityKeyLength      int
	IntegrityChecksumLength int
	PRFKeyLength            int
}

func KeyMaterialProfileFromSA

func KeyMaterialProfileFromSA(sa SecurityAssociation) (KeyMaterialProfile, error)

func (KeyMaterialProfile) RequiredLength

func (p KeyMaterialProfile) RequiredLength() int

type Message

type Message struct {
	Header   Header
	Payloads []Payload
}

func BuildInformationalRequest

func BuildInformationalRequest(init InitResult, keys IKEKeys, messageID uint32, inner []Payload, iv []byte) (Message, []byte, error)

func BuildInformationalRequestFrom

func BuildInformationalRequestFrom(init InitResult, keys IKEKeys, messageID uint32, fromInitiator bool, inner []Payload, iv []byte) (Message, []byte, error)

func BuildInformationalResponse

func BuildInformationalResponse(init InitResult, keys IKEKeys, messageID uint32, inner []Payload, iv []byte) (Message, []byte, error)

func BuildInformationalResponseFrom

func BuildInformationalResponseFrom(init InitResult, keys IKEKeys, messageID uint32, fromInitiator bool, inner []Payload, iv []byte) (Message, []byte, error)

func ParseMessage

func ParseMessage(data []byte) (Message, error)

func ProtectMessage

func ProtectMessage(header Header, keys IKEKeys, fromInitiator bool, inner []Payload, iv []byte) (Message, []byte, error)

func (Message) MarshalBinary

func (m Message) MarshalBinary() ([]byte, error)

type Notify

type Notify struct {
	ProtocolID       uint8
	NotifyType       uint16
	SPI              []byte
	NotificationData []byte
}

func FirstNotify

func FirstNotify(payloads []Payload, notifyType uint16) (Notify, bool, error)

func ParseNotify

func ParseNotify(data []byte) (Notify, error)

func (Notify) Cookie

func (n Notify) Cookie() ([]byte, bool, error)

func (Notify) InvalidKEPayloadAlternativeGroup

func (n Notify) InvalidKEPayloadAlternativeGroup() (uint16, bool, error)

InvalidKEPayloadAlternativeGroup returns the responder's suggested DH group when this notification is INVALID_KE_PAYLOAD.

func (Notify) InvalidSelectorReport

func (n Notify) InvalidSelectorReport() (InvalidSelectorReport, bool, error)

func (Notify) MarshalBinary

func (n Notify) MarshalBinary() ([]byte, error)

type NotifyAction

type NotifyAction struct {
	Notify           Notify
	Kind             NotifyActionKind
	Retry            bool
	RetryLater       bool
	RecreateIKE      bool
	RecreateChild    bool
	SuggestedDHGroup uint16
}

func ClassifyNotifyAction

func ClassifyNotifyAction(notify Notify) NotifyAction

func CreateChildSANotifyActionFromError

func CreateChildSANotifyActionFromError(err error) (NotifyAction, bool)

func NotifyActionFromError

func NotifyActionFromError(err error) (NotifyAction, bool)

type NotifyActionKind

type NotifyActionKind uint8
const (
	NotifyActionNone NotifyActionKind = iota
	NotifyActionMOBIKESupported
	NotifyActionMOBIKEUpdateAddresses
	NotifyActionMOBIKEAdditionalAddress
	NotifyActionMOBIKENoAdditionalAddresses
	NotifyActionMOBIKEEchoCookie2
	NotifyActionRekeyChildSA
	NotifyActionRetryWithSuggestedDH
	NotifyActionRetryWithDifferentProposal
	NotifyActionNarrowTrafficSelectors
	NotifyActionRecreateChildSA
	NotifyActionRecreateIKESA
	NotifyActionMOBIKEAddressRecovery
	NotifyActionWaitAndRetry
	NotifyActionReauthenticate
	NotifyActionAbort
)

type NotifyError

type NotifyError struct {
	Notify Notify
	Err    error
}

func (*NotifyError) Error

func (e *NotifyError) Error() string

func (*NotifyError) InvalidKEPayloadAlternativeGroup

func (e *NotifyError) InvalidKEPayloadAlternativeGroup() (uint16, bool, error)

InvalidKEPayloadAlternativeGroup returns the suggested DH group carried by an INVALID_KE_PAYLOAD notify error.

func (*NotifyError) InvalidSelectorReport

func (e *NotifyError) InvalidSelectorReport() (InvalidSelectorReport, bool, error)

func (*NotifyError) Is

func (e *NotifyError) Is(target error) bool

func (*NotifyError) Unwrap

func (e *NotifyError) Unwrap() error

type Payload

type Payload struct {
	Type        uint8
	NextPayload uint8
	Critical    bool
	Body        []byte
}

func AdditionalIPAddressNotify

func AdditionalIPAddressNotify(ip net.IP) (Payload, error)

func BuildCreateChildSAPayloads

func BuildCreateChildSAPayloads(cfg CreateChildSAConfig) ([]Payload, []byte, []byte, error)

func BuildIKEAuthInitialPayloads

func BuildIKEAuthInitialPayloads(cfg AuthConfig) ([]Payload, error)

func ChildSADeletePayload

func ChildSADeletePayload(child ChildSAResult) (Payload, error)

func ConfigurationPayload

func ConfigurationPayload(c Configuration) (Payload, error)

func Cookie2Notify

func Cookie2Notify(cookie []byte) (Payload, error)

func CookieNotify

func CookieNotify(cookie []byte) (Payload, error)

func DeletePayload

func DeletePayload(d Delete) (Payload, error)

func EAPPayload

func EAPPayload(packet []byte) Payload

func ESPDeletePayload

func ESPDeletePayload(spis ...[]byte) (Payload, error)

func EncryptedFragmentPayload

func EncryptedFragmentPayload(nextPayload uint8, fragment EncryptedFragment) (Payload, error)

func IKEDeletePayload

func IKEDeletePayload() Payload

func IdentityPayload

func IdentityPayload(payloadType uint8, id Identity) (Payload, error)

func KeyExchangePayload

func KeyExchangePayload(group uint16, keyData []byte) Payload

func MOBIKESupportedNotify

func MOBIKESupportedNotify() Payload

func NATDetectionNotify

func NATDetectionNotify(notifyType uint16, spiI, spiR uint64, ip net.IP, port uint16) (Payload, error)

func NoAdditionalAddressesNotify

func NoAdditionalAddressesNotify() Payload

func NoncePayload

func NoncePayload(nonce []byte) Payload

func NotifyPayload

func NotifyPayload(n Notify) (Payload, error)

func NotifyWithZeroSPI

func NotifyWithZeroSPI(notifyType uint16, data []byte) Payload

func ParsePayloads

func ParsePayloads(first uint8, data []byte) ([]Payload, error)

func SecurityAssociationPayload

func SecurityAssociationPayload(sa SecurityAssociation) (Payload, error)

func TeardownDeletePayloads

func TeardownDeletePayloads(child ChildSAResult, includeIKESA bool) ([]Payload, error)

func TrafficSelectorsPayload

func TrafficSelectorsPayload(payloadType uint8, ts TrafficSelectors) (Payload, error)

func UpdateSAAddressesNotify

func UpdateSAAddressesNotify() Payload

type Proposal

type Proposal struct {
	Number     uint8
	ProtocolID uint8
	SPI        []byte
	Transforms []Transform
}

type SecurityAssociation

type SecurityAssociation struct {
	Proposals []Proposal
}

func DefaultESPProposal

func DefaultESPProposal(spi []byte) SecurityAssociation

func DefaultIKEProposal

func DefaultIKEProposal() SecurityAssociation

func ParseSecurityAssociation

func ParseSecurityAssociation(data []byte) (SecurityAssociation, error)

func (SecurityAssociation) MarshalBinary

func (sa SecurityAssociation) MarshalBinary() ([]byte, error)

type TrafficSelector

type TrafficSelector struct {
	Type       uint8
	IPProtocol uint8
	StartPort  uint16
	EndPort    uint16
	StartAddr  net.IP
	EndAddr    net.IP
}

func (TrafficSelector) MarshalBinary

func (ts TrafficSelector) MarshalBinary() ([]byte, error)

type TrafficSelectors

type TrafficSelectors struct {
	Selectors []TrafficSelector
}

func IPv4AnyTrafficSelectors

func IPv4AnyTrafficSelectors() TrafficSelectors

func ParseTrafficSelectors

func ParseTrafficSelectors(data []byte) (TrafficSelectors, error)

func (TrafficSelectors) MarshalBinary

func (ts TrafficSelectors) MarshalBinary() ([]byte, error)

type Transform

type Transform struct {
	Type       uint8
	ID         uint16
	Attributes []TransformAttribute
}

type TransformAttribute

type TransformAttribute struct {
	Type  uint16
	Value []byte
}

func KeyLengthAttribute

func KeyLengthAttribute(bits uint16) TransformAttribute

type UDPTransport

type UDPTransport struct {
	RemoteAddr      string
	LocalAddr       string
	Timeout         time.Duration
	UseNonESPMarker bool
	ReadBufferSize  int
}

func (UDPTransport) ExchangeIKE

func (t UDPTransport) ExchangeIKE(ctx context.Context, request []byte) ([]byte, error)

Jump to

Keyboard shortcuts

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