Go to the documentation of this file.
32 #define TRACE_LEVEL IKE_TRACE_LEVEL
48 #if (IKE_SUPPORT == ENABLED)
85 #if (IKE_DPD_SUPPORT == ENABLED)
89 #if (IKE_COOKIE_SUPPORT == ENABLED)
95 #if (IKE_CERT_AUTH_SUPPORT == ENABLED)
117 if(context == NULL || settings == NULL)
133 context->taskParams = settings->
task;
137 context->interface = settings->
interface;
140 context->prngAlgo = settings->
prngAlgo;
158 #if (IKE_DPD_SUPPORT == ENABLED)
160 context->dpdPeriod = settings->
dpdPeriod;
162 #if (IKE_COOKIE_SUPPORT == ENABLED)
168 #if (IKE_CERT_AUTH_SUPPORT == ENABLED)
228 if(context->socket == NULL)
250 context->stop =
FALSE;
251 context->running =
TRUE;
255 &context->taskParams);
272 context->running =
FALSE;
276 context->socket = NULL;
302 #if (NET_RTOS_SUPPORT == ENABLED)
304 context->stop =
TRUE;
309 while(context->running)
317 context->socket = NULL;
363 if(context == NULL ||
id == NULL)
373 context->idLen = idLen;
390 #if (IKE_PSK_AUTH_SUPPORT == ENABLED)
392 if(context == NULL || psk == NULL)
400 osMemcpy(context->psk, psk, pskLen);
401 context->pskLen = pskLen;
427 size_t certChainLen,
const char_t *privateKey,
size_t privateKeyLen,
430 #if (IKE_CERT_AUTH_SUPPORT == ENABLED)
438 if(context == NULL || certChain == NULL || certChainLen == 0)
442 if(privateKey == NULL && privateKeyLen != 0)
510 context->certType = certType;
511 context->certChain = certChain;
512 context->certChainLen = certChainLen;
513 context->privateKey = privateKey;
514 context->privateKeyLen = privateKeyLen;
519 osStrcpy(context->password, password);
557 context = sa->context;
560 sa->deleteRequest =
TRUE;
587 if(context == NULL || packet == NULL)
652 childSa->remoteIpAddr = remoteIpAddr;
653 childSa->mode = spdEntry->
mode;
654 childSa->protocol = spdEntry->
protocol;
655 childSa->initiator =
TRUE;
656 childSa->packetInfo = *packet;
657 childSa->selector = selector;
661 ipsecContext->
sad[childSa->outboundSa].selector = selector;
696 context = childSa->context;
699 childSa->deleteRequest =
TRUE;
719 #if (NET_RTOS_SUPPORT == ENABLED)
728 eventDesc.
socket = context->socket;
739 context->running =
FALSE;
752 &context->remotePort, &context->localIpAddr, context->message,
766 #if (NET_RTOS_SUPPORT == ENABLED)
error_t ikeSetPsk(IkeContext *context, const uint8_t *psk, size_t pskLen)
Set entity's pre-shared key.
IpsecSadEntry * sad
Security Association Database (SAD)
IkeCertType
Certificate types.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
X.509 certificate parsing.
error_t socketBind(Socket *socket, const IpAddr *localIpAddr, uint16_t localPort)
Associate a local address with a socket.
Helper functions for IKEv2.
error_t ikeSetCertificate(IkeContext *context, const char_t *certChain, size_t certChainLen, const char_t *privateKey, size_t privateKeyLen, const char_t *password)
Load entity's certificate.
error_t ikeCreateChildSa(IkeContext *context, const IpsecPacketInfo *packet)
Create a new Child SA.
error_t ikeSetPreferredDhGroup(IkeContext *context, uint16_t dhGroupNum)
Specify the preferred Diffie-Hellman group.
#define IPSEC_PORT_START_OPAQUE
IpAddr remoteIpAddr
Remote IP address.
#define OS_INVALID_TASK_ID
void socketClose(Socket *socket)
Close an existing socket.
#define IKE_DEFAULT_SA_LIFETIME
uint_t numChildSaEntries
Number of Child SA entries.
void ikeGetDefaultSettings(IkeSettings *settings)
Initialize settings with default values.
IkeChildSaEntry * ikeCreateChildSaEntry(IkeContext *context)
Create a new Child Security Association.
error_t ikeGetCertificateType(const X509CertInfo *certInfo, IkeCertType *certType)
Retrieve the certificate type.
IKEv2 finite state machine.
Structure describing socket events.
@ IPSEC_POLICY_ACTION_PROTECT
IkeCertVerifyCallback certVerifyCallback
Certificate verification callback function.
uint16_t remotePort
Remote port.
uint_t numSaEntries
Number of IKE SA entries.
void osDeleteTask(OsTaskId taskId)
Delete a task.
error_t pemImportCertificate(const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen, size_t *consumed)
Decode a PEM file containing a certificate.
PEM file import functions.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
uint8_t nextProtocol
Next layer protocol.
Data logging functions for debugging purpose (IKEv2)
uint8_t nextProtocol
Next layer protocol.
uint16_t localPort
Local port.
systime_t dpdPeriod
Dead peer detection period.
error_t ikeDeleteChildSa(IkeChildSaEntry *childSa)
Delete a Child SA.
bool_t ikeIsDhGroupSupported(uint16_t groupNum)
Check whether a given Diffie-Hellman group is supported.
void(* OsTaskCode)(void *arg)
Task routine.
IpsecPortRange remotePort
Remote port range.
error_t ikeStop(IkeContext *context)
Stop IKE service.
NetInterface * interface
Underlying network interface.
Helper routines for IPsec.
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
IpsecProtocol protocol
Security protocol (AH or ESP)
void osDeleteEvent(OsEvent *event)
Delete an event object.
#define IKE_MAX_PASSWORD_LEN
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
@ IKE_CHILD_SA_STATE_INIT
IkeCookieGenerateCallback cookieGenerateCallback
Cookie generation callback function.
error_t ikeDeleteSa(IkeSaEntry *sa)
Delete an IKE SA.
void * prngContext
Pseudo-random number generator context.
Socket * socketOpen(uint_t type, uint_t protocol)
Create a socket (UDP or TCP)
IpsecMode mode
IPsec mode (tunnel or transport)
uint_t eventFlags
Returned events.
void ikeChangeChildSaState(IkeChildSaEntry *childSa, IkeChildSaState newState)
Update Child SA state.
@ IKE_CHILD_SA_STATE_CLOSED
void * ipsecContext
IPsec context.
error_t socketPoll(SocketEventDesc *eventDesc, uint_t size, OsEvent *extEvent, systime_t timeout)
Wait for one of a set of sockets to become ready to perform I/O.
#define socketBindToInterface
IpsecSpdEntry * ipsecFindSpdEntry(IpsecContext *context, IpsecPolicyAction policyAction, const IpsecSelector *selector)
Search the SPD database for a matching entry.
IKEv2 (Internet Key Exchange Protocol)
#define IKE_TICK_INTERVAL
uint16_t ikeSelectDefaultDhGroup(void)
Get the default Diffie-Hellman group number.
#define IPSEC_PORT_END_OPAQUE
systime_t childSaLifetime
Lifetime of Child SAs.
IkeChildSaEntry * childSaEntries
Child SA entries.
IpsecAddrRange localIpAddr
Local IP address range.
OsTaskParameters task
Task parameters.
void ikeDeinit(IkeContext *context)
Release IKE context.
IpAddr localIpAddr
Local IP address.
IpAddr remoteTunnelAddr
Remote tunnel IP address.
error_t ikeInit(IkeContext *context, const IkeSettings *settings)
IKE service initialization.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
error_t ikeSetId(IkeContext *context, IkeIdType idType, const void *id, size_t idLen)
Set entity's ID.
X.509 certificate handling.
systime_t saLifetime
Lifetime of IKE SAs.
error_t x509ParseCertificateEx(const uint8_t *data, size_t length, X509CertInfo *certInfo, bool_t ignoreUnknown)
Parse a X.509 certificate.
IkeCookieVerifyCallback cookieVerifyCallback
Cookie verification callback function.
systime_t reauthPeriod
Reauthentication period.
void osDelayTask(systime_t delay)
Delay routine.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
void ikeTask(IkeContext *context)
IKE task.
error_t socketReceiveEx(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags)
Receive a datagram.
void ikeProcessEvents(IkeContext *context)
IKE event processing.
error_t ipsecDeriveSelector(const IpsecSpdEntry *spdEntry, const IpsecPacketInfo *packet, IpsecSelector *selector)
Derive SAD selector from SPD entry and triggering packet.
error_t ikeStart(IkeContext *context)
Start IKE service.
Security Policy Database (SPD) entry.
Socket * socket
Handle to a socket to monitor.
#define osMemset(p, value, length)
IkeSaEntry * saEntries
IKE SA entries.
void * ikeContext
IKE context.
error_t ikeProcessMessage(IkeContext *context, uint8_t *message, size_t length)
Process incoming IKE message.
IpsecPortRange localPort
Local port range.
uint_t eventMask
Requested events.
IKEv2 algorithm negotiation.
IpsecAddrRange remoteIpAddr
Remote IP address range.
#define ikeAllocMem(size)
#define IKE_DEFAULT_CHILD_SA_LIFETIME