Go to the documentation of this file.
32 #define TRACE_LEVEL IKE_TRACE_LEVEL
48 #if (IKE_SUPPORT == ENABLED)
87 #if (IKE_DPD_SUPPORT == ENABLED)
91 #if (IKE_COOKIE_SUPPORT == ENABLED)
97 #if (IKE_CERT_AUTH_SUPPORT == ENABLED)
119 if(context == NULL || settings == NULL)
135 context->taskParams = settings->
task;
145 context->netContext = settings->
interface->netContext;
153 context->interface = settings->
interface;
156 context->prngAlgo = settings->
prngAlgo;
174 #if (IKE_DPD_SUPPORT == ENABLED)
176 context->dpdPeriod = settings->
dpdPeriod;
178 #if (IKE_COOKIE_SUPPORT == ENABLED)
184 #if (IKE_CERT_AUTH_SUPPORT == ENABLED)
195 context->netContext->ikeContext = context;
249 if(context->socket == NULL)
270 context->stop =
FALSE;
271 context->running =
TRUE;
275 &context->taskParams);
292 context->running =
FALSE;
296 context->socket = NULL;
322 #if (NET_RTOS_SUPPORT == ENABLED)
324 context->stop =
TRUE;
329 while(context->running)
337 context->socket = NULL;
363 context->preferredGroupNum = groupNum;
383 if(context == NULL ||
id == NULL)
393 context->idLen = idLen;
410 #if (IKE_PSK_AUTH_SUPPORT == ENABLED)
412 if(context == NULL || psk == NULL)
420 osMemcpy(context->psk, psk, pskLen);
421 context->pskLen = pskLen;
447 size_t certChainLen,
const char_t *privateKey,
size_t privateKeyLen,
450 #if (IKE_CERT_AUTH_SUPPORT == ENABLED)
458 if(context == NULL || certChain == NULL || certChainLen == 0)
462 if(privateKey == NULL && privateKeyLen != 0)
536 context->certType = certType;
537 context->certChain = certChain;
538 context->certChainLen = certChainLen;
539 context->privateKey = privateKey;
540 context->privateKeyLen = privateKeyLen;
545 osStrcpy(context->password, password);
583 context = sa->context;
586 sa->deleteRequest =
TRUE;
613 if(context == NULL || packet == NULL)
620 ipsecContext = context->netContext->ipsecContext;
622 if(ipsecContext == NULL)
681 childSa->remoteIpAddr = remoteIpAddr;
682 childSa->mode = spdEntry->
mode;
683 childSa->protocol = spdEntry->
protocol;
684 childSa->initiator =
TRUE;
685 childSa->packetInfo = *packet;
686 childSa->selector = selector;
690 ipsecContext->sad[childSa->outboundSa].selector = selector;
725 context = childSa->context;
728 childSa->deleteRequest =
TRUE;
748 #if (NET_RTOS_SUPPORT == ENABLED)
757 eventDesc.
socket = context->socket;
768 context->running =
FALSE;
781 &context->remotePort, &context->localIpAddr, context->message,
795 #if (NET_RTOS_SUPPORT == ENABLED)
814 netContext = context->netContext;
819 netContext->ikeContext = NULL;
error_t ikeSetPsk(IkeContext *context, const uint8_t *psk, size_t pskLen)
Set entity's pre-shared key.
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.
void netUnlock(NetContext *context)
Release exclusive access to the core of the TCP/IP stack.
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.
#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
Certificate parsing options.
IkeCertVerifyCallback certVerifyCallback
Certificate verification callback function.
uint16_t remotePort
Remote port.
uint_t numSaEntries
Number of IKE SA entries.
uint16_t ikeSelectDefaultGroup(void)
Get the default key exchange method.
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.
const X509Options X509_DEFAULT_OPTIONS
systime_t dpdPeriod
Dead peer detection period.
error_t ikeDeleteChildSa(IkeChildSaEntry *childSa)
Delete a Child SA.
void(* OsTaskCode)(void *arg)
Task routine.
error_t x509ParseCertificateEx(const uint8_t *data, size_t length, X509CertInfo *certInfo, const X509Options *options)
Parse a X.509 certificate.
IpsecPortRange remotePort
Remote port range.
bool_t ikeIsGroupSupported(uint16_t groupNum)
Check whether a given key exchange method is supported.
error_t ikeStop(IkeContext *context)
Stop IKE service.
@ ERROR_FAILURE
Generic error code.
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
NetContext * netGetDefaultContext(void)
Get default TCP/IP stack context.
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.
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
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
NetContext * netContext
TCP/IP stack context.
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
error_t ikeSetPreferredGroup(IkeContext *context, uint16_t groupNum)
Specify the preferred key exchange method.
#define IPSEC_PORT_END_OPAQUE
systime_t childSaLifetime
Lifetime of Child SAs.
IkeChildSaEntry * childSaEntries
Child SA entries.
Socket * socketOpenEx(NetContext *context, uint_t type, uint_t protocol)
Create a socket.
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.
IkeCookieVerifyCallback cookieVerifyCallback
Cookie verification callback function.
systime_t reauthPeriod
Reauthentication period.
void netLock(NetContext *context)
Get exclusive access to the core of the TCP/IP stack.
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.
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