Documentation ¶
Index ¶
- Constants
- Variables
- func AddrToIp(addr net.Addr) net.IP
- func AddrToIpPort(addr net.Addr) (net.IP, int)
- func CreateSignature(algo x509.SignatureAlgorithm, authMethod protocol.AuthMethod, signed []byte, ...) ([]byte, error)
- func DecryptMessage(msg *Message, tkm *Tkm, forInitiator bool, log log.Logger) (err error)
- func FirstLastAddressToIPNet(start, end net.IP) *net.IPNet
- func IPNetToFirstLastAddress(n *net.IPNet) (first, last net.IP, err error)
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- func LoadCerts(certFile string) ([]*x509.Certificate, error)
- func LoadKey(keyFile string) (*rsa.PrivateKey, error)
- func LoadPEMCert(certFile string) (*x509.Certificate, error)
- func LoadRoot(caCert string) (*x509.CertPool, error)
- func MakeSpi() (ret protocol.Spi)
- func MatchNameFromCert(cert *CertID, name string) bool
- func NewECCA(name string) (*x509.Certificate, interface{}, error)
- func NewSignedCert(cfg CertID, publicKey interface{}, caCert *x509.Certificate, caKey interface{}) (*x509.Certificate, error)
- func RunSession(sess *Session) error
- func SpiToInt32(spi protocol.Spi) uint32
- func SpiToInt64(spi protocol.Spi) uint64
- func VerifySignature(authMethod protocol.AuthMethod, signed, signature []byte, ...) error
- func WriteData(conn Conn, data []byte, remote net.Addr, log log.Logger) (err error)
- func WriteMessage(conn Conn, msg *Message, tkm *Tkm, forInitiator bool, log log.Logger) (err error)
- type AltNames
- type Authenticator
- type CertAuthenticator
- type CertID
- type CertIdentity
- type Cmd
- type Config
- func (cfg *Config) AddHostSelectors(local, remote net.IP, forInitiator bool) error
- func (cfg *Config) AddNetworkSelectors(localnet, remotenet *net.IPNet, forInitiator bool) (err error)
- func (cfg *Config) CheckDhTransform(dhID protocol.DhTransformId) error
- func (cfg *Config) CheckProposals(prot protocol.ProtocolID, proposals protocol.Proposals) (err error)
- func (cfg *Config) CheckSelectors(tsi, tsr protocol.Selectors, isTransportMode bool) error
- func (cfg *Config) Policy() *protocol.PolicyParams
- type Conn
- type Identity
- type InformationalEvent
- type Message
- func ChildSaFromSession(sess *Session, newTkm *Tkm, isInitiator bool, espSpi []byte) *Message
- func DecodeMessage(b []byte, log log.Logger) (msg *Message, err error)
- func DeleteFromSession(sess *Session) *Message
- func EmptyFromSession(sess *Session, isResponse bool) *Message
- func InitFromSession(sess *Session) *Message
- func NotifyFromSession(sess *Session, ie protocol.IkeErrorCode, isResponse bool) *Message
- func ReadMessage(conn Conn, log log.Logger) (*Message, error)
- func (msg *Message) CheckFlags() error
- func (msg *Message) DecodeHeader(b []byte) (err error)
- func (msg *Message) DecodePayloads(b []byte, nextPayload protocol.PayloadType, log log.Logger) (err error)
- func (msg *Message) Encode(tkm *Tkm, forInitiator bool, log log.Logger) (b []byte, err error)
- func (msg *Message) EnsurePayloads(payloadTypes []protocol.PayloadType) error
- type OutgoingMessage
- type PskAuthenticator
- type PskIdentities
- type Session
- func (sess *Session) AddSa(sa *platform.SaParams) (err error)
- func (sess *Session) AuthMsg() (*OutgoingMessage, error)
- func (sess *Session) AuthReply(ie error)
- func (sess *Session) CheckError(err error, isResponse bool) error
- func (sess *Session) CreateIkeSa(init *initParams) error
- func (sess *Session) InitMsg() (*OutgoingMessage, error)
- func (sess *Session) IsInitiator() bool
- func (sess *Session) MarshalJSON() ([]byte, error)
- func (sess *Session) Notify(ie protocol.IkeErrorCode, isResponse bool)
- func (sess *Session) PostMessage(msg *Message)
- func (sess *Session) RekeyMsg(child *Message) (*OutgoingMessage, error)
- func (sess *Session) RemoveSa() (err error)
- func (sess *Session) SendEmptyInformational(isResponse bool) error
- func (sess *Session) SendMsgGetReply(genMsg func() (*OutgoingMessage, error)) (*Message, error)
- func (sess *Session) SetCookie(cn *protocol.NotifyPayload)
- func (sess *Session) Shutdown(err error)
- func (sess *Session) String() string
- type SessionCallback
- type SessionNotificationType
- type Sessions
- type Tkm
- func (t *Tkm) CryptoOverhead(b []byte) int
- func (t *Tkm) DhGenerateKey(theirPublic *big.Int) (err error)
- func (t *Tkm) EncryptMac(ike []byte, forInitiator bool) (b []byte, err error)
- func (t *Tkm) IkeSaKeys(spiI, spiR []byte, old_skD []byte)
- func (t *Tkm) IpsecSaKeys(ni, nr, dhShared *big.Int) (espEi, espAi, espEr, espAr []byte)
- func (t *Tkm) MarshalJSON() ([]byte, error)
- func (t *Tkm) SignB(initB []byte, id []byte, forInitiator bool) []byte
- func (t *Tkm) String() string
- func (t *Tkm) VerifyDecrypt(ike []byte, forInitiator bool) (dec []byte, err error)
Constants ¶
const REPLY_WAIT_TIMEOUT = 5 * time.Second
Variables ¶
var ( AsnSHA1WithRSA = "300d06092a864886f70d0101050500" AsnSHA256WithRSA = "300d06092a864886f70d01010b0500" AsnSHA384WithRSA = "300d06092a864886f70d01010c0500" AsnSHA512WithRSA = "300d06092a864886f70d01010d0500" AsnDSAWithSHA1 = "300906072a8648ce380403" AsnDSAWithSHA256 = "300b0609608648016503040302" AsnECDSAWithSHA1 = "300906072a8648ce3d0401" AsnECDSAWithSHA256 = "300a06082a8648ce3d040302" AsnECDSAWithSHA384 = "300a06082a8648ce3d040303" AsnECDSAWithSHA512 = "300a06082a8648ce3d040304" AsnRsaSsaPss = "300d06092a864886f70d01010a3000" AsnRsaSsaPssDefault = "" /* 128-byte string literal not displayed */ AsnSHA256WithRSAPSS = "" /* 144-byte string literal not displayed */ )
asn1 objects from rfc7427
var ErrorUDPOnly = errors.New("only udp is supported for now")
ErrorUDPOnly is returned if the given address is other than UDP
Functions ¶
func CreateSignature ¶
func CreateSignature(algo x509.SignatureAlgorithm, authMethod protocol.AuthMethod, signed []byte, private crypto.Signer, log log.Logger) ([]byte, error)
CreateSignature signs request using private key & configured method
func DecryptMessage ¶
DecryptMessage uses crypto keys to decode & verify the message
func IPNetToFirstLastAddress ¶
IPNetToFirstLastAddress returns the first & last address derived from the IPNet notation
func Jitter ¶
Jitter returns a time.Duration between duration and duration + maxFactor * duration, to allow clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.
func LoadPEMCert ¶
func LoadPEMCert(certFile string) (*x509.Certificate, error)
func MatchNameFromCert ¶
MatchNameFromCert checks if name is specified in Subject or Altnames
func NewECCA ¶
func NewECCA(name string) (*x509.Certificate, interface{}, error)
NewSelfSignedCACert creates a CA certificate
func NewSignedCert ¶
func NewSignedCert(cfg CertID, publicKey interface{}, caCert *x509.Certificate, caKey interface{}) (*x509.Certificate, error)
NewSignedCert creates a signed certificate using the given CA certificate and key
func RunSession ¶
RunSession starts and monitors the session returning when the session ends
func SpiToInt32 ¶
func SpiToInt64 ¶
func VerifySignature ¶
func VerifySignature(authMethod protocol.AuthMethod, signed, signature []byte, cert *x509.Certificate, log log.Logger) error
VerifySignature using certificate & configured auth method
Types ¶
type AltNames ¶
AltNames contains the domain names and IP addresses that will be added to the API Server's x509 certificate SubAltNames field. The values will be passed directly to the x509.Certificate object.
type Authenticator ¶
type Authenticator interface { Identity() Identity Sign([]byte, *protocol.IdPayload, log.Logger) ([]byte, error) Verify(initB []byte, idP *protocol.IdPayload, authMethod protocol.AuthMethod, authData []byte, inbandData interface{}, logger log.Logger) error }
Authenticator is used to authenticate & create AUTH payloads
func NewAuthenticator ¶
func NewAuthenticator(id Identity, tkm *Tkm, forInitiator, rfc7427Signatures bool) Authenticator
type CertAuthenticator ¶
type CertAuthenticator struct {
// contains filtered or unexported fields
}
CertAuthenticator is an Authenticator
func (*CertAuthenticator) Identity ¶
func (o *CertAuthenticator) Identity() Identity
func (*CertAuthenticator) Verify ¶
func (o *CertAuthenticator) Verify(initB []byte, idP *protocol.IdPayload, authMethod protocol.AuthMethod, authData []byte, inbandData interface{}, logger log.Logger) error
Verify using one of: AUTH_RSA_DIGITAL_SIGNATURE with certificates RFC 7427 - Signature Authentication in IKEv2 tkm.Auth always uses the hash negotiated with prf TODO: implement raw AUTH_RSA_DIGITAL_SIGNATURE & AUTH_DSS_DIGITAL_SIGNATURE TODO: implement ECDSA from RFC4754
type CertID ¶
type CertID struct { CommonName string Organization []string AltNames AltNames Issuer string NotBefore, NotAfter time.Time IsCA bool }
func FormatCert ¶
func FormatCert(c *x509.Certificate) (id CertID)
FormatCert receives certificate and formats in human-readable format
type CertIdentity ¶
type CertIdentity struct { Certificate *x509.Certificate PrivateKey crypto.Signer Roots *x509.CertPool Name string AuthenticationMethod protocol.AuthMethod }
func (*CertIdentity) AuthData ¶
func (c *CertIdentity) AuthData(id []byte) []byte
func (*CertIdentity) AuthMethod ¶
func (c *CertIdentity) AuthMethod() protocol.AuthMethod
func (*CertIdentity) Id ¶
func (c *CertIdentity) Id() []byte
func (*CertIdentity) IdType ¶
func (c *CertIdentity) IdType() protocol.IdType
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
Cmd provides utilities for building ike apps
func NewCmd ¶
func NewCmd(conn Conn, cb *SessionCallback) *Cmd
func (*Cmd) RunInitiator ¶
RunInitiator starts & watches over on initiator session in a separate goroutine
type Config ¶
type Config struct {
ProposalIke, ProposalEsp protocol.TransformMap
LocalID, PeerID Identity
TsI, TsR protocol.Selectors
IsTransportMode bool
ThrottleInitRequests bool
Lifetime time.Duration
}
func DefaultConfig ¶
func DefaultConfig() *Config
func (*Config) AddHostSelectors ¶
AddHostSelectors builds selectors from ip addresses
func (*Config) AddNetworkSelectors ¶
func (cfg *Config) AddNetworkSelectors(localnet, remotenet *net.IPNet, forInitiator bool) (err error)
AddNetworkSelectors builds selector from address & mask
func (*Config) CheckDhTransform ¶
func (cfg *Config) CheckDhTransform(dhID protocol.DhTransformId) error
func (*Config) CheckProposals ¶
func (cfg *Config) CheckProposals(prot protocol.ProtocolID, proposals protocol.Proposals) (err error)
CheckProposals checks if incoming proposals include our configuration
func (*Config) CheckSelectors ¶
CheckSelectors checks if incoming selectors match our configuration
func (*Config) Policy ¶
func (cfg *Config) Policy() *protocol.PolicyParams
Policy converts the selectors to policy
type Conn ¶
type InformationalEvent ¶
type InformationalEvent struct { SessionNotificationType Message interface{} }
func HandleInformationalForSession ¶
func HandleInformationalForSession(sess *Session, msg *Message) *InformationalEvent
HandleInformationalForSession handles informational from peer TODO : handles a single payload only
type Message ¶
type Message struct { IkeHeader *protocol.IkeHeader Payloads *protocol.Payloads LocalAddr, RemoteAddr net.Addr Data []byte // used to carry raw bytes Params interface{} // used to carry the parsed/source structure }
Message carries the ike packet
func ChildSaFromSession ¶
ChildSaFromSession creates CREATE_CHILD_SA messages HDR, SK {N(REKEY_SA), SA, Ni, [KEi,] TSi, TSr} --> <-- HDR, SK {SA, Nr, [KEr,] TSi, TSr}
func DecodeMessage ¶
DecodeMessage decodes an keeps the message buffer for later decryption
func DeleteFromSession ¶
DeleteFromSession builds an IKE delete Request
func EmptyFromSession ¶
EmptyFromSession can build an empty Request or a Response
func InitFromSession ¶
InitFromSession creates IKE_SA_INIT messages
func NotifyFromSession ¶
func NotifyFromSession(sess *Session, ie protocol.IkeErrorCode, isResponse bool) *Message
NotifyFromSession builds a Notification Request
func ReadMessage ¶
ReadMessage reads an IKE message from connection Connection errors are returned, protocol errors are simply logged TODO - defrag logic seems wrong; revisit
func (*Message) CheckFlags ¶
CheckFlags checks if flags are correctly set for us NOTE: To simply implementation, we do not handle the case where original responder starts transactions. In reality this only effects CHILD_SA txns so this function is not to be used for NOTIFICATIONS
func (*Message) DecodeHeader ¶
DecodeHeader decodes the ike header and replaces the IkeHeader member
func (*Message) DecodePayloads ¶
func (msg *Message) DecodePayloads(b []byte, nextPayload protocol.PayloadType, log log.Logger) (err error)
DecodePayloads decodes & replaces the payloads member with list of decoded payloads
func (*Message) EnsurePayloads ¶
func (msg *Message) EnsurePayloads(payloadTypes []protocol.PayloadType) error
EnsurePayloads checks if the needed payloads are present in the message
type OutgoingMessage ¶
type OutgoingMessage struct {
Data []byte
}
type PskAuthenticator ¶
type PskAuthenticator struct {
// contains filtered or unexported fields
}
PskAuthenticator is an Authenticator
func (*PskAuthenticator) Identity ¶
func (psk *PskAuthenticator) Identity() Identity
type PskIdentities ¶
func (*PskIdentities) AuthData ¶
func (psk *PskIdentities) AuthData(id []byte) []byte
func (*PskIdentities) AuthMethod ¶
func (psk *PskIdentities) AuthMethod() protocol.AuthMethod
func (*PskIdentities) Id ¶
func (psk *PskIdentities) Id() []byte
func (*PskIdentities) IdType ¶
func (psk *PskIdentities) IdType() protocol.IdType
type Session ¶
type Session struct { SessionID int32 IkeSpiI, IkeSpiR protocol.Spi EspSpiI, EspSpiR protocol.Spi // data from client Conn Conn Local, Remote net.Addr Cb SessionCallback Logger log.Logger // contains filtered or unexported fields }
Session stores IKE session's local state
func NewInitiator ¶
func NewInitiator(cfg *Config, localAddr, remoteAddr net.Addr, conn Conn, cb *SessionCallback, logger log.Logger) (*Session, error)
NewInitiator creates an initiator session
func NewResponder ¶
func NewResponder(cfg *Config, conn Conn, cb *SessionCallback, initI *Message, logger log.Logger) (*Session, error)
NewResponder creates a Responder session
func (*Session) AuthMsg ¶
func (sess *Session) AuthMsg() (*OutgoingMessage, error)
AuthMsg generates IKE_AUTH
func (*Session) CheckError ¶
CheckError checks error for error & sends notification within INFORMATIONAL
func (*Session) CreateIkeSa ¶
func (*Session) InitMsg ¶
func (sess *Session) InitMsg() (*OutgoingMessage, error)
InitMsg generates IKE_INIT
func (*Session) IsInitiator ¶
func (*Session) MarshalJSON ¶
func (*Session) PostMessage ¶
func (*Session) SendEmptyInformational ¶
SendEmptyInformational can be used for periodic keepalive
func (*Session) SendMsgGetReply ¶
func (sess *Session) SendMsgGetReply(genMsg func() (*OutgoingMessage, error)) (*Message, error)
SendMsgGetReply sends a request and waits for valid reply
func (*Session) SetCookie ¶
func (sess *Session) SetCookie(cn *protocol.NotifyPayload)
type SessionCallback ¶
type SessionCallback struct { InstallPolicy func(*Session, *protocol.PolicyParams) error RemovePolicy func(*Session, *protocol.PolicyParams) error InstallChildSa func(*Session, *platform.SaParams) error RemoveChildSa func(*Session, *platform.SaParams) error }
SessionCallback holds the callbacks used by the session to notify the user
type SessionNotificationType ¶
type SessionNotificationType int
const ( MSG_EMPTY_REQUEST SessionNotificationType = iota MSG_EMPTY_RESPONSE MSG_NOTIFICATION MSG_ERROR )
type Sessions ¶
type Sessions interface { Add(spi uint64, session *Session) Remove(spi uint64) Get(spi uint64) (*Session, bool) ForEach(action func(*Session)) }
func NewSessions ¶
func NewSessions() Sessions
type Tkm ¶
func (*Tkm) CryptoOverhead ¶
func (*Tkm) DhGenerateKey ¶
DhGenerateKey creates & stores the dh key upon receipt of peers resp, a dh shared secret can be calculated
func (*Tkm) EncryptMac ¶
encrypt-then-MAC
func (*Tkm) IpsecSaKeys ¶
IpsecSaKeys generates & returns Ipsec Sa keys
func (*Tkm) MarshalJSON ¶
func (*Tkm) SignB ¶
SignB gets signed data from tkm section 2.15 For the responder, the octets to be signed start with the first octet of the first SPI in the header of the second message (IKE_SA_INIT response) and end with the last octet of the last payload in the second message. => initIRB Appended to this (for the purposes of computing the signature) are the initiator's nonce Ni (just the value, not the payload containing it), and the value prf(SK_pr, IDr') so signB := responder: initRB | Ni | prf(SK_pr, IDr') initiator: initIB | Nr | prf(SK_pi, IDi') this method can be used by signer & verifier
Source Files ¶
- authenticator.go
- authenticator_cert.go
- authenticator_psk.go
- child_sa.go
- cmd.go
- config.go
- conn.go
- cookie.go
- identity.go
- ike_auth.go
- ike_messages.go
- ike_sa_init.go
- informational.go
- jitter.go
- json.go
- message.go
- msgid.go
- nat.go
- net.go
- run.go
- sa.go
- session.go
- sessions.go
- spi_utils.go
- timeout.go
- tkm.go
- x509_signature.go
- x509_utils.go