ike_fsm.c
Go to the documentation of this file.
1 /**
2  * @file ike_fsm.c
3  * @brief IKEv2 finite state machine
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneIPSEC Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL IKE_TRACE_LEVEL
33 
34 //Dependencies
35 #include "ipsec/ipsec_misc.h"
36 #include "ike/ike.h"
37 #include "ike/ike_fsm.h"
38 #include "ike/ike_key_exchange.h"
39 #include "ike/ike_message_format.h"
40 #include "ike/ike_misc.h"
41 #include "debug.h"
42 
43 //Check IKEv2 library configuration
44 #if (IKE_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief Update IKE SA state
49  * @param[in] sa Pointer to the IKE SA
50  * @param[in] newState New IKE SA state to switch to
51  **/
52 
54 {
55  IkeContext *context;
56 
57  //Point to the IKE context
58  context = sa->context;
59 
60  //Successful IKE SA creation?
61  if(sa->state < IKE_SA_STATE_OPEN &&
62  newState == IKE_SA_STATE_OPEN)
63  {
64  //IKE SA uses secret keys that should be used only for a limited amount
65  //of time (refer to RFC 7296, section 2.8)
66  sa->lifetimeStart = osGetSystemTime();
67 
68  //If the two ends have the same lifetime policies, it is possible that
69  //both will initiate a rekeying at the same time. To reduce the
70  //probability of this happening, the timing of rekeying requests should
71  //be jittered (refer to RFC 7296, section 2.8.1)
72  sa->lifetime = ikeRandomizeDelay(context, context->saLifetime);
73 
74  //Reauthentication period
75  sa->reauthPeriod = ikeRandomizeDelay(context, context->reauthPeriod);
76  }
77 
78 #if (IKE_DPD_SUPPORT == ENABLED)
79  //The dead peer detection mechanism is used to perform a liveness check
80  if((sa->state < IKE_SA_STATE_OPEN || sa->state == IKE_SA_STATE_DPD_RESP) &&
81  newState == IKE_SA_STATE_OPEN)
82  {
83  //Get current time
84  sa->dpdStart = osGetSystemTime();
85  //Set dead peer detection period
86  sa->dpdPeriod = ikeRandomizeDelay(context, context->dpdPeriod);
87  }
88 #endif
89 
90  //Set time stamp
91  sa->timestamp = osGetSystemTime();
92  //Set initial retransmission timeout
93  sa->timeout = IKE_INIT_TIMEOUT;
94  //Reset retransmission counter
95  sa->retransmitCount = 0;
96 
97  //Switch to the new state
98  sa->state = newState;
99 }
100 
101 
102 /**
103  * @brief Update Child SA state
104  * @param[in] childSa Pointer to the Child SA
105  * @param[in] newState New Child SA state to switch to
106  **/
107 
109 {
110  //Successful Child SA creation?
111  if(childSa->state < IKE_CHILD_SA_STATE_OPEN &&
112  newState == IKE_CHILD_SA_STATE_OPEN)
113  {
114  //ESP and AH SA use secret keys that should be used only for a limited
115  //amount of time
116  childSa->lifetimeStart = osGetSystemTime();
117  }
118 
119  //Switch to the new state
120  childSa->state = newState;
121 }
122 
123 
124 /**
125  * @brief IKE event processing
126  * @param[in] context Pointer to the IKE context
127  **/
128 
130 {
131  uint_t i;
132  systime_t time;
133  IkeSaEntry *sa;
134  IkeChildSaEntry *childSa;
135 
136  //Get current time
137  time = osGetSystemTime();
138 
139  //Loop through IKE SA entries
140  for(i = 0; i < context->numSaEntries; i++)
141  {
142  //Point to the current IKE SA
143  sa = &context->sa[i];
144 
145  //Check the state of the IKE SA
146  if(sa->state == IKE_SA_STATE_INIT_REQ)
147  {
148  //Communication using IKE always begins with IKE_SA_INIT and IKE_AUTH
149  //exchanges. These initial exchanges normally consist of four messages
151  }
152  else if(sa->state == IKE_SA_STATE_AUTH_REQ)
153  {
154  //Delete half-open IKE SAs after timeout
155  if(timeCompare(time, sa->timestamp + IKE_HALF_OPEN_TIMEOUT) >= 0)
156  {
157  //Debug message
158  TRACE_INFO("Deleting half-open IKE SA...\r\n");
159  //Delete the IKE SA
160  ikeDeleteSaEntry(sa);
161  }
162  }
163  else if(sa->state == IKE_SA_STATE_OPEN)
164  {
165  //Process IKE SA events
166  ikeProcessSaEvents(sa);
167  }
168  else if(sa->state == IKE_SA_STATE_INIT_RESP ||
169  sa->state == IKE_SA_STATE_AUTH_RESP ||
170  sa->state == IKE_SA_STATE_DPD_RESP ||
171  sa->state == IKE_SA_STATE_REKEY_RESP ||
172  sa->state == IKE_SA_STATE_DELETE_RESP ||
173  sa->state == IKE_SA_STATE_CREATE_CHILD_RESP ||
174  sa->state == IKE_SA_STATE_REKEY_CHILD_RESP ||
175  sa->state == IKE_SA_STATE_DELETE_CHILD_RESP ||
176  sa->state == IKE_SA_STATE_AUTH_FAILURE_RESP)
177  {
178  //Check current time
179  if(timeCompare(time, sa->timestamp + sa->timeout) >= 0)
180  {
181  //The initiator must retransmit the request until it either receives
182  //a corresponding response or deems the IKE SA to have failed (refer
183  //to RFC 7296, section 2.1)
184  if(sa->retransmitCount < IKE_MAX_RETRIES)
185  {
186  //A retransmission from the initiator must be bitwise identical
187  //to the original request
189  }
190  else
191  {
192  //The initiator discards all state associated with the IKE SA
193  //and any Child SAs that were negotiated using that IKE SA
194  ikeDeleteSaEntry(sa);
195  }
196  }
197  }
198  else
199  {
200  //Just for sanity
201  }
202  }
203 
204  //Loop through Child SA entries
205  for(i = 0; i < context->numChildSaEntries; i++)
206  {
207  //Point to the current Child SA
208  childSa = &context->childSa[i];
209 
210  //Check the Child SA should be created
211  if(childSa->state == IKE_CHILD_SA_STATE_INIT &&
212  childSa->sa == NULL)
213  {
215  }
216  }
217 }
218 
219 
220 /**
221  * @brief IKE SA event processing
222  * @param[in] sa Pointer to the IKE SA
223  * @return Error code
224  **/
225 
227 {
228  error_t error;
229  uint_t i;
230  systime_t time;
231  IkeContext *context;
232  IkeChildSaEntry *childSa;
233 
234  //Initialize status code
235  error = NO_ERROR;
236 
237  //Point to the IKE context
238  context = sa->context;
239 
240  //Get current time
241  time = osGetSystemTime();
242 
243 #if (IKE_DPD_SUPPORT == ENABLED)
244  //Check the state of the IKE SA
245  if(sa->state == IKE_SA_STATE_OPEN)
246  {
247  //Check whether the dead peer detection mechanism is enabled
248  if(sa->dpdPeriod != 0)
249  {
250  //Check whether the DPD period has expired
251  if(timeCompare(time, sa->dpdStart + sa->dpdPeriod) >= 0)
252  {
253  //If no cryptographically protected messages have been received on
254  //an IKE SA or any of its Child SAs recently, the system needs to
255  //perform a liveness check in order to prevent sending messages to
256  //a dead peer liveness of the other endpoint to avoid black holes
257  error = ikeProcessSaDpdEvent(sa);
258  }
259  }
260  }
261 #endif
262 
263  //Check the state of the IKE SA
264  if(sa->state == IKE_SA_STATE_OPEN && !error)
265  {
266  //Check whether reauthentication is enabled
267  if(sa->reauthPeriod != 0)
268  {
269  //Reauthentication has to be initiated by the same party as the
270  //original IKE SA. IKEv2 does not currently allow the responder to
271  //request reauthentication (refer to RFC 7296, section 2.8.3)
272  if(sa->originalInitiator)
273  {
274  //Check whether the reauthentication period has expired
275  if(timeCompare(time, sa->lifetimeStart + sa->reauthPeriod) >= 0)
276  {
277  //IKEv2 does not have any special support for reauthentication.
278  //Reauthentication is done by creating a new IKE SA from scratch,
279  //creating new Child SAs within the new IKE SA, and finally
280  //deleting the old IKE SA
281  sa->reauthRequest = TRUE;
282  }
283 
284  //Check whether reauthentication should be initiated
285  if(sa->reauthRequest && !sa->reauthPending)
286  {
287  //Initiate reauthentication
288  error = ikeProcessSaReauthEvent(sa);
289  }
290  }
291  }
292  }
293 
294  //Check the state of the IKE SA
295  if(sa->state == IKE_SA_STATE_OPEN && !error)
296  {
297  //Check whether the IKE SA should be closed
298  if(sa->deleteRequest)
299  {
300  //Close the specified IKE SA
301  error = ikeProcessSaDeleteEvent(sa);
302  }
303  }
304 
305  //Check the state of the IKE SA
306  if(sa->state == IKE_SA_STATE_OPEN && !error)
307  {
308  //Loop through Child SA entries
309  for(i = 0; i < context->numChildSaEntries && !error; i++)
310  {
311  //Point to the current Child SA
312  childSa = &context->childSa[i];
313 
314  //Valid Child SA?
315  if(childSa->state != IKE_CHILD_SA_STATE_CLOSED &&
316  childSa->sa == sa)
317  {
318  //Process Child SA events
319  error = ikeProcessChildSaEvents(childSa);
320  }
321  }
322  }
323 
324  //Return status code
325  return error;
326 }
327 
328 
329 /**
330  * @brief Child SA event processing
331  * @param[in] childSa Pointer to the Child SA
332  * @return Error code
333  **/
334 
336 {
337  error_t error;
338  IkeSaEntry *sa;
339 
340  //Initialize status code
341  error = NO_ERROR;
342 
343  //Point to the IKE SA
344  sa = childSa->sa;
345 
346 
347  //Check the state of the IKE SA
348  if(sa->state == IKE_SA_STATE_OPEN && !error)
349  {
350  //Check whether the Child SA should be closed
351  if(childSa->deleteRequest)
352  {
353  //Close the specified Child SA
354  error = ikeProcessChildSaDeleteEvent(childSa);
355  }
356  }
357 
358  //Return status code
359  return error;
360 }
361 
362 
363 /**
364  * @brief Handle IKE SA creation event
365  * @param[in] sa Pointer to the IKE SA
366  * @return Error code
367  **/
368 
370 {
371  error_t error;
372  IkeContext *context;
373 
374  //Point to the IKE context
375  context = sa->context;
376 
377  //Each endpoint chooses one of the two SPIs and must choose them so as to
378  //be unique identifiers of an IKE SA (refer to RFC 7296, section 2.6)
379  error = ikeGenerateSaSpi(sa, sa->initiatorSpi);
380 
381  //Check status code
382  if(!error)
383  {
384  //Nonces used in IKEv2 must be randomly chosen and must be at least
385  //128 bits in size (refer to RFC 7296, section 2.10)
386  error = ikeGenerateNonce(context, sa->initiatorNonce,
387  &sa->initiatorNonceLen);
388  }
389 
390  //Check status code
391  if(!error)
392  {
393  //Generate an ephemeral key pair
394  error = ikeGenerateDhKeyPair(sa);
395  }
396 
397  //Check status code
398  if(!error)
399  {
400  //The first exchange of an IKE session, IKE_SA_INIT, negotiates security
401  //parameters for the IKE SA, sends nonces, and sends Diffie-Hellman values
402  error = ikeSendIkeSaInitRequest(sa);
403  }
404 
405  //Return status code
406  return error;
407 }
408 
409 
410 /**
411  * @brief Handle IKE SA dead peer detection event
412  * @param[in] sa Pointer to the IKE SA
413  * @return Error code
414  **/
415 
417 {
418  //If no cryptographically protected messages have been received on an
419  //IKE SA or any of its Child SAs recently, the system needs to perform
420  //a liveness check in order to prevent sending messages to a dead peer
421  //(refer to RFC 7296, section 2.4)
423 
424  //An INFORMATIONAL request with no payloads is commonly used as a check
425  //for liveness (refer to RFC 7296, section 1)
426  return ikeSendInformationalRequest(sa);
427 }
428 
429 
430 /**
431  * @brief Handle IKE SA rekeying event
432  * @param[in] sa Pointer to the IKE SA
433  * @return Error code
434  **/
435 
437 {
438  error_t error;
439  IkeContext *context;
440  IkeSaEntry *newSa;
441 
442  //Initialize status code
443  error = NO_ERROR;
444 
445  //Point to the IKE context
446  context = sa->context;
447 
448  //Create a new IKE SA
449  newSa = ikeCreateSaEntry(context);
450 
451  //Successful IKE SA creation?
452  if(newSa != NULL)
453  {
454  //Initialize IKE SA
455  newSa->remoteIpAddr = sa->remoteIpAddr;
456  newSa->remotePort = sa->remotePort;
457 
458  //The initiator of the rekey exchange is the new "original initiator"
459  //of the new IKE SA (refer to RFC 7296, section 1.3.2)
460  newSa->originalInitiator = TRUE;
461 
462  //Select the preferred Diffie-Hellman group number
463  newSa->dhGroupNum = context->preferredDhGroupNum;
464 
465  //Each endpoint chooses one of the two SPIs and must choose them so as to
466  //be unique identifiers of an IKE SA (refer to RFC 7296, section 2.6)
467  error = ikeGenerateSaSpi(newSa, newSa->initiatorSpi);
468 
469  //Check status code
470  if(!error)
471  {
472  //Nonces used in IKEv2 must be randomly chosen and must be at least
473  //128 bits in size (refer to RFC 7296, section 2.10)
474  error = ikeGenerateNonce(context, newSa->initiatorNonce,
475  &newSa->initiatorNonceLen);
476  }
477 
478  //Check status code
479  if(!error)
480  {
481  //Generate an ephemeral key pair
482  error = ikeGenerateDhKeyPair(newSa);
483  }
484 
485  //Check status code
486  if(!error)
487  {
488  //Acknowledge request
489  sa->rekeyRequest = FALSE;
490 
491  //Attach the newly created IKE SA
492  sa->newSa = newSa;
493 
494  //Update the state of the IKE SA
496 
497  //To rekey an IKE SA, establish a new equivalent IKE SA with the peer to
498  //whom the old IKE SA is shared using a CREATE_CHILD_SA within the existing
499  //IKE SA (refer to RFC 7296, section 2.8)
500  ikeSendCreateChildSaRequest(sa, sa->childSa);
501  }
502  }
503  else
504  {
505  //Failed to create IKE SA
506  }
507 
508  //Return status code
509  return error;
510 }
511 
512 
513 /**
514  * @brief Handle IKE SA reauthentication event
515  * @param[in] sa Pointer to the IKE SA
516  * @return Error code
517  **/
518 
520 {
521  error_t error;
522  IkeContext *context;
523  IkeSaEntry *newSa;
524  IkeChildSaEntry *childSa;
525  IkeChildSaEntry *newChildSa;
526 
527  //Initialize status code
528  error = NO_ERROR;
529 
530  //Point to the IKE context
531  context = sa->context;
532  //Point to the Child SA
533  childSa = sa->childSa;
534 
535  //Sanity check
536  if(childSa != NULL)
537  {
538  //Acknowledge request
539  sa->reauthPending = TRUE;
540 
541  //Create a new IKE SA
542  newSa = ikeCreateSaEntry(context);
543 
544  //Successful IKE SA creation?
545  if(newSa != NULL)
546  {
547  //Create a new Child SA
548  newChildSa = ikeCreateChildSaEntry(context);
549 
550  //Successful IKE SA creation?
551  if(newChildSa != NULL)
552  {
553  //Initialize IKE SA
554  newSa->remoteIpAddr = sa->remoteIpAddr;
555  newSa->remotePort = sa->remotePort;
556  newSa->remoteIpAddr = sa->remoteIpAddr;
557  newSa->remotePort = sa->remotePort;
558  newSa->childSa = newChildSa;
559 
560  //The initiator of the rekey exchange is the new "original initiator"
561  //of the new IKE SA (refer to RFC 7296, section 1.3.2)
562  newSa->originalInitiator = TRUE;
563 
564  //Select the preferred Diffie-Hellman group number
565  newSa->dhGroupNum = context->preferredDhGroupNum;
566 
567  //Initialize Child SA
568  newChildSa->sa = newSa;
569  newChildSa->mode = childSa->mode;
570  newChildSa->protocol = childSa->protocol;
571  newChildSa->initiator = TRUE;
572  newChildSa->selector = childSa->selector;
573 
574  //Each endpoint chooses one of the two SPIs and must choose them so as to
575  //be unique identifiers of an IKE SA (refer to RFC 7296, section 2.6)
576  error = ikeGenerateSaSpi(newSa, newSa->initiatorSpi);
577 
578  //Check status code
579  if(!error)
580  {
581  //Nonces used in IKEv2 must be randomly chosen and must be at least
582  //128 bits in size (refer to RFC 7296, section 2.10)
583  error = ikeGenerateNonce(context, newSa->initiatorNonce,
584  &newSa->initiatorNonceLen);
585  }
586 
587  //Check status code
588  if(!error)
589  {
590  //Generate an ephemeral key pair
591  error = ikeGenerateDhKeyPair(newSa);
592  }
593 
594  //Check status code
595  if(!error)
596  {
597  //The first exchange of an IKE session, IKE_SA_INIT, negotiates security
598  //parameters for the IKE SA, sends nonces, and sends Diffie-Hellman values
599  error = ikeSendIkeSaInitRequest(newSa);
600  }
601 
602  //Check status code
603  if(!error)
604  {
605  //Attach the old IKE SA
606  newSa->oldSa = sa;
607  }
608  else
609  {
610  //Failed to initiate reauthentication
611  ikeDeleteSaEntry(newSa);
612  }
613  }
614  else
615  {
616  //Failed to create Child SA
617  ikeDeleteSaEntry(newSa);
618  //Report en error
619  error = ERROR_OUT_OF_RESOURCES;
620  }
621  }
622  else
623  {
624  //Failed to create IKE SA
625  error = ERROR_OUT_OF_RESOURCES;
626  }
627 
628  //Failed to initiate reauthentication?
629  if(error)
630  {
631  //Close the old IKE SA
632  sa->deleteRequest = TRUE;
633  //Notify the IKE context that the IKE SA should be closed
634  osSetEvent(&context->event);
635  }
636  }
637 
638  //Return status code
639  return error;
640 }
641 
642 
643 /**
644  * @brief Handle IKE SA deletion event
645  * @param[in] sa Pointer to the IKE SA
646  * @return Error code
647  **/
648 
650 {
651  //Acknowledge request
652  sa->deleteRequest = FALSE;
653  sa->childSa = NULL;
654 
655  //Update the state of the IKE SA
657 
658  //To delete an SA, an INFORMATIONAL exchange with one or more Delete payloads
659  //is sent listing the SPIs of the SAs to be deleted
660  return ikeSendInformationalRequest(sa);
661 }
662 
663 
664 /**
665  * @brief Handle Child SA creation event
666  * @param[in] childSa Pointer to the Child SA
667  * @return Error code
668  **/
669 
671 {
672  error_t error;
673  IkeContext *context;
674  IkeSaEntry *sa;
675 
676  //Initialize status code
677  error = NO_ERROR;
678 
679  //Point to the IKE context
680  context = childSa->context;
681 
682  {
683  //Create a new IKE SA
684  sa = ikeCreateSaEntry(context);
685 
686  //Successful IKE SA creation?
687  if(sa != NULL)
688  {
689  //Initialize IKE SA
690  sa->remoteIpAddr = childSa->remoteIpAddr;
691  sa->remotePort = IKE_PORT;
692  sa->childSa = childSa;
693 
694  //The original initiator always refers to the party who initiated the
695  //exchange (refer to RFC 7296, section 2.2)
696  sa->originalInitiator = TRUE;
697 
698  //Select the preferred Diffie-Hellman group number
699  sa->dhGroupNum = context->preferredDhGroupNum;
700 
701  //Attach the newly created IKE SA to the Child SA
702  childSa->sa = sa;
703 
704  //Update the state of the IKE SA
706 
707  //The first exchange of an IKE session, IKE_SA_INIT, negotiates
708  //security parameters for the IKE SA, sends nonces, and sends
709  //Diffie-Hellman values
710  error = ikeProcessSaInitEvent(sa);
711  }
712  else
713  {
714  //Failed to create IKE SA
715  }
716  }
717 
718  //Return status code
719  return error;
720 }
721 
722 
723 /**
724  * @brief Handle Child SA rekeying event
725  * @param[in] childSa Pointer to the Child SA
726  * @return Error code
727  **/
728 
730 {
731  error_t error;
732  IkeSaEntry *sa;
733  IkeContext *context;
734  IkeChildSaEntry *newChildSa;
735 
736  //Initialize status code
737  error = NO_ERROR;
738 
739  //Point to the IKE context
740  context = childSa->context;
741  //Point to the IKE SA
742  sa = childSa->sa;
743 
744  //Create a new Child SA
745  newChildSa = ikeCreateChildSaEntry(context);
746 
747  //Successful Child SA creation?
748  if(newChildSa != NULL)
749  {
750  //Initialize Child SA
751  newChildSa->sa = sa;
752  newChildSa->oldChildSa = childSa;
753  newChildSa->protocol = childSa->protocol;
754  newChildSa->mode = childSa->mode;
755  newChildSa->initiator = TRUE;
756  newChildSa->selector = childSa->selector;
757 
758  //Generate a new SPI for the Child SA
759  error = ikeGenerateChildSaSpi(newChildSa, newChildSa->localSpi);
760 
761  //Check status code
762  if(!error)
763  {
764  //Nonces used in IKEv2 must be randomly chosen and must be at least
765  //128 bits in size (refer to RFC 7296, section 2.10)
766  error = ikeGenerateNonce(context, newChildSa->initiatorNonce,
767  &newChildSa->initiatorNonceLen);
768  }
769 
770  //Check status code
771  if(!error)
772  {
773  //Acknowledge request
774  childSa->rekeyRequest = FALSE;
775 
776  //Attach the newly created Child SA to the IKE SA
777  sa->childSa = newChildSa;
778 
779  //Update the state of the IKE SA
781  //Update the state of the Child SA
783 
784  //To rekey a Child SA within an existing IKE SA, create a new
785  //equivalent SA, and when the new one is established, delete the
786  //old one
787  error = ikeSendCreateChildSaRequest(sa, newChildSa);
788  }
789  }
790  else
791  {
792  //Failed to create Child SA
793  }
794 
795  //Return status code
796  return error;
797 }
798 
799 
800 /**
801  * @brief Handle Child SA deletion event
802  * @param[in] childSa Pointer to the Child SA
803  * @return Error code
804  **/
805 
807 {
808  IkeSaEntry *sa;
809 
810  //Point to the IKE SA
811  sa = childSa->sa;
812 
813  //Acknowledge request
814  childSa->deleteRequest = FALSE;
815 
816  //Attach the Child SA to the IKE SA
817  sa->childSa = childSa;
818 
819  //Update the state of the IKE SA
821  //Update the state of the Child SA
823 
824  //To delete an SA, an INFORMATIONAL exchange with one or more Delete payloads
825  //is sent listing the SPIs of the SAs to be deleted
826  return ikeSendInformationalRequest(sa);
827 }
828 
829 #endif
unsigned int uint_t
Definition: compiler_port.h:50
Debugging facilities.
#define TRACE_INFO(...)
Definition: debug.h:95
uint32_t time
error_t
Error codes.
Definition: error.h:43
@ ERROR_OUT_OF_RESOURCES
Definition: error.h:64
@ NO_ERROR
Success.
Definition: error.h:44
IKEv2 (Internet Key Exchange Protocol)
IkeChildSaState
Child Security Association state.
Definition: ike.h:1193
@ IKE_CHILD_SA_STATE_OPEN
Definition: ike.h:1197
@ IKE_CHILD_SA_STATE_DELETE
Definition: ike.h:1199
@ IKE_CHILD_SA_STATE_CLOSED
Definition: ike.h:1194
@ IKE_CHILD_SA_STATE_INIT
Definition: ike.h:1196
@ IKE_CHILD_SA_STATE_REKEY
Definition: ike.h:1198
#define IKE_MAX_RETRIES
Definition: ike.h:131
#define IkeChildSaEntry
Definition: ike.h:686
#define IKE_HALF_OPEN_TIMEOUT
Definition: ike.h:152
#define IkeContext
Definition: ike.h:678
#define IKE_PORT
Definition: ike.h:667
IkeSaState
IKE Security Association state.
Definition: ike.h:1163
@ IKE_SA_STATE_CREATE_CHILD_RESP
Definition: ike.h:1178
@ IKE_SA_STATE_AUTH_FAILURE_RESP
Definition: ike.h:1184
@ IKE_SA_STATE_AUTH_RESP
Definition: ike.h:1169
@ IKE_SA_STATE_REKEY_REQ
Definition: ike.h:1173
@ IKE_SA_STATE_INIT_REQ
Definition: ike.h:1166
@ IKE_SA_STATE_DELETE_REQ
Definition: ike.h:1175
@ IKE_SA_STATE_DPD_REQ
Definition: ike.h:1171
@ IKE_SA_STATE_AUTH_REQ
Definition: ike.h:1168
@ IKE_SA_STATE_INIT_RESP
Definition: ike.h:1167
@ IKE_SA_STATE_REKEY_CHILD_RESP
Definition: ike.h:1180
@ IKE_SA_STATE_DELETE_CHILD_RESP
Definition: ike.h:1182
@ IKE_SA_STATE_DPD_RESP
Definition: ike.h:1172
@ IKE_SA_STATE_OPEN
Definition: ike.h:1170
@ IKE_SA_STATE_DELETE_CHILD_REQ
Definition: ike.h:1181
@ IKE_SA_STATE_REKEY_CHILD_REQ
Definition: ike.h:1179
@ IKE_SA_STATE_DELETE_RESP
Definition: ike.h:1176
@ IKE_SA_STATE_REKEY_RESP
Definition: ike.h:1174
#define IkeSaEntry
Definition: ike.h:682
#define IKE_INIT_TIMEOUT
Definition: ike.h:138
void ikeProcessEvents(IkeContext *context)
IKE event processing.
Definition: ike_fsm.c:129
error_t ikeProcessSaRekeyEvent(IkeSaEntry *sa)
Handle IKE SA rekeying event.
Definition: ike_fsm.c:436
void ikeChangeChildSaState(IkeChildSaEntry *childSa, IkeChildSaState newState)
Update Child SA state.
Definition: ike_fsm.c:108
error_t ikeProcessChildSaInitEvent(IkeChildSaEntry *childSa)
Handle Child SA creation event.
Definition: ike_fsm.c:670
error_t ikeProcessChildSaEvents(IkeChildSaEntry *childSa)
Child SA event processing.
Definition: ike_fsm.c:335
error_t ikeProcessSaInitEvent(IkeSaEntry *sa)
Handle IKE SA creation event.
Definition: ike_fsm.c:369
error_t ikeProcessSaReauthEvent(IkeSaEntry *sa)
Handle IKE SA reauthentication event.
Definition: ike_fsm.c:519
error_t ikeProcessChildSaDeleteEvent(IkeChildSaEntry *childSa)
Handle Child SA deletion event.
Definition: ike_fsm.c:806
void ikeChangeSaState(IkeSaEntry *sa, IkeSaState newState)
Update IKE SA state.
Definition: ike_fsm.c:53
error_t ikeProcessChildSaRekeyEvent(IkeChildSaEntry *childSa)
Handle Child SA rekeying event.
Definition: ike_fsm.c:729
error_t ikeProcessSaDpdEvent(IkeSaEntry *sa)
Handle IKE SA dead peer detection event.
Definition: ike_fsm.c:416
error_t ikeProcessSaDeleteEvent(IkeSaEntry *sa)
Handle IKE SA deletion event.
Definition: ike_fsm.c:649
error_t ikeProcessSaEvents(IkeSaEntry *sa)
IKE SA event processing.
Definition: ike_fsm.c:226
IKEv2 finite state machine.
error_t ikeRetransmitRequest(IkeSaEntry *sa)
Retransmit IKE request message.
Definition: ike_misc.c:56
error_t ikeGenerateDhKeyPair(IkeSaEntry *sa)
Diffie-Hellman key pair generation.
Diffie-Hellman key exchange.
error_t ikeSendIkeSaInitRequest(IkeSaEntry *sa)
Send IKE_SA_INIT request.
error_t ikeSendInformationalRequest(IkeSaEntry *sa)
Send INFORMATIONAL request.
error_t ikeSendCreateChildSaRequest(IkeSaEntry *sa, IkeChildSaEntry *childSa)
Send CREATE_CHILD_SA request.
IKE message formatting.
error_t ikeGenerateSaSpi(IkeSaEntry *sa, uint8_t *spi)
Generate a new IKE SA SPI.
Definition: ike_misc.c:530
void ikeDeleteSaEntry(IkeSaEntry *sa)
Delete an IKE Security Association.
Definition: ike_misc.c:298
error_t ikeGenerateChildSaSpi(IkeChildSaEntry *childSa, uint8_t *spi)
Generate a new Child SA SPI.
Definition: ike_misc.c:615
error_t ikeGenerateNonce(IkeContext *context, uint8_t *nonce, size_t *length)
Generate a new nonce.
Definition: ike_misc.c:689
IkeChildSaEntry * ikeCreateChildSaEntry(IkeContext *context)
Create a new Child Security Association.
Definition: ike_misc.c:396
systime_t ikeRandomizeDelay(IkeContext *context, systime_t delay)
Apply random jitter to a time interval.
Definition: ike_misc.c:723
IkeSaEntry * ikeCreateSaEntry(IkeContext *context)
Create a new IKE Security Association.
Definition: ike_misc.c:136
Helper functions for IKEv2.
Helper routines for IPsec.
#define timeCompare(t1, t2)
Definition: os_port.h:40
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
systime_t osGetSystemTime(void)
Retrieve system time.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
uint32_t systime_t
System time.