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-2025 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.5.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  error_t error;
132  uint_t i;
133  systime_t time;
134  IkeSaEntry *sa;
135  IkeChildSaEntry *childSa;
136 
137  //Get current time
138  time = osGetSystemTime();
139 
140  //Loop through IKE SA entries
141  for(i = 0; i < context->numSaEntries; i++)
142  {
143  //Point to the current IKE SA
144  sa = &context->sa[i];
145 
146  //Check the state of the IKE SA
147  if(sa->state == IKE_SA_STATE_INIT_REQ)
148  {
149  //Communication using IKE always begins with IKE_SA_INIT and IKE_AUTH
150  //exchanges. These initial exchanges normally consist of four messages
151  error = ikeProcessSaInitEvent(sa);
152 
153  //Check status code code
154  if(error)
155  {
156  //Delete the IKE SA
157  ikeDeleteSaEntry(sa);
158  }
159  }
160  else if(sa->state == IKE_SA_STATE_AUTH_REQ)
161  {
162  //Delete half-open IKE SAs after timeout
163  if(timeCompare(time, sa->timestamp + IKE_HALF_OPEN_TIMEOUT) >= 0)
164  {
165  //Debug message
166  TRACE_INFO("Deleting half-open IKE SA...\r\n");
167  //Delete the IKE SA
168  ikeDeleteSaEntry(sa);
169  }
170  }
171  else if(sa->state == IKE_SA_STATE_OPEN)
172  {
173  //Process IKE SA events
174  ikeProcessSaEvents(sa);
175  }
176  else if(sa->state == IKE_SA_STATE_INIT_RESP ||
177  sa->state == IKE_SA_STATE_AUTH_RESP ||
178  sa->state == IKE_SA_STATE_DPD_RESP ||
179  sa->state == IKE_SA_STATE_REKEY_RESP ||
180  sa->state == IKE_SA_STATE_DELETE_RESP ||
181  sa->state == IKE_SA_STATE_CREATE_CHILD_RESP ||
182  sa->state == IKE_SA_STATE_REKEY_CHILD_RESP ||
183  sa->state == IKE_SA_STATE_DELETE_CHILD_RESP ||
184  sa->state == IKE_SA_STATE_AUTH_FAILURE_RESP)
185  {
186  //Check current time
187  if(timeCompare(time, sa->timestamp + sa->timeout) >= 0)
188  {
189  //The initiator must retransmit the request until it either receives
190  //a corresponding response or deems the IKE SA to have failed (refer
191  //to RFC 7296, section 2.1)
192  if(sa->retransmitCount < IKE_MAX_RETRIES)
193  {
194  //A retransmission from the initiator must be bitwise identical
195  //to the original request
197  }
198  else
199  {
200  //The initiator discards all state associated with the IKE SA
201  //and any Child SAs that were negotiated using that IKE SA
202  ikeDeleteSaEntry(sa);
203  }
204  }
205  }
206  else
207  {
208  //Just for sanity
209  }
210  }
211 
212  //Loop through Child SA entries
213  for(i = 0; i < context->numChildSaEntries; i++)
214  {
215  //Point to the current Child SA
216  childSa = &context->childSa[i];
217 
218  //Check the Child SA should be created
219  if(childSa->state == IKE_CHILD_SA_STATE_INIT &&
220  childSa->sa == NULL)
221  {
223  }
224  }
225 }
226 
227 
228 /**
229  * @brief IKE SA event processing
230  * @param[in] sa Pointer to the IKE SA
231  * @return Error code
232  **/
233 
235 {
236  error_t error;
237  uint_t i;
238  systime_t time;
239  IkeContext *context;
240  IkeChildSaEntry *childSa;
241 
242  //Initialize status code
243  error = NO_ERROR;
244 
245  //Point to the IKE context
246  context = sa->context;
247 
248  //Get current time
249  time = osGetSystemTime();
250 
251 #if (IKE_DPD_SUPPORT == ENABLED)
252  //Check the state of the IKE SA
253  if(sa->state == IKE_SA_STATE_OPEN)
254  {
255  //Check whether the dead peer detection mechanism is enabled
256  if(sa->dpdPeriod != 0)
257  {
258  //Check whether the DPD period has expired
259  if(timeCompare(time, sa->dpdStart + sa->dpdPeriod) >= 0)
260  {
261  //If no cryptographically protected messages have been received on
262  //an IKE SA or any of its Child SAs recently, the system needs to
263  //perform a liveness check in order to prevent sending messages to
264  //a dead peer liveness of the other endpoint to avoid black holes
265  error = ikeProcessSaDpdEvent(sa);
266  }
267  }
268  }
269 #endif
270 
271  //Check the state of the IKE SA
272  if(sa->state == IKE_SA_STATE_OPEN && !error)
273  {
274  //Check whether reauthentication is enabled
275  if(sa->reauthPeriod != 0)
276  {
277  //Reauthentication has to be initiated by the same party as the
278  //original IKE SA. IKEv2 does not currently allow the responder to
279  //request reauthentication (refer to RFC 7296, section 2.8.3)
280  if(sa->originalInitiator)
281  {
282  //Check whether the reauthentication period has expired
283  if(timeCompare(time, sa->lifetimeStart + sa->reauthPeriod) >= 0)
284  {
285  //IKEv2 does not have any special support for reauthentication.
286  //Reauthentication is done by creating a new IKE SA from scratch,
287  //creating new Child SAs within the new IKE SA, and finally
288  //deleting the old IKE SA
289  sa->reauthRequest = TRUE;
290  }
291 
292  //Check whether reauthentication should be initiated
293  if(sa->reauthRequest && !sa->reauthPending)
294  {
295  //Initiate reauthentication
296  error = ikeProcessSaReauthEvent(sa);
297  }
298  }
299  }
300  }
301 
302  //Check the state of the IKE SA
303  if(sa->state == IKE_SA_STATE_OPEN && !error)
304  {
305  //Check whether the IKE SA should be closed
306  if(sa->deleteRequest)
307  {
308  //Close the specified IKE SA
309  error = ikeProcessSaDeleteEvent(sa);
310  }
311  }
312 
313  //Check the state of the IKE SA
314  if(sa->state == IKE_SA_STATE_OPEN && !error)
315  {
316  //Loop through Child SA entries
317  for(i = 0; i < context->numChildSaEntries && !error; i++)
318  {
319  //Point to the current Child SA
320  childSa = &context->childSa[i];
321 
322  //Valid Child SA?
323  if(childSa->state != IKE_CHILD_SA_STATE_CLOSED &&
324  childSa->sa == sa)
325  {
326  //Process Child SA events
327  error = ikeProcessChildSaEvents(childSa);
328  }
329  }
330  }
331 
332  //Return status code
333  return error;
334 }
335 
336 
337 /**
338  * @brief Child SA event processing
339  * @param[in] childSa Pointer to the Child SA
340  * @return Error code
341  **/
342 
344 {
345  error_t error;
346  IkeSaEntry *sa;
347 
348  //Initialize status code
349  error = NO_ERROR;
350 
351  //Point to the IKE SA
352  sa = childSa->sa;
353 
354 
355  //Check the state of the IKE SA
356  if(sa->state == IKE_SA_STATE_OPEN && !error)
357  {
358  //Check whether the Child SA should be closed
359  if(childSa->deleteRequest)
360  {
361  //Close the specified Child SA
362  error = ikeProcessChildSaDeleteEvent(childSa);
363  }
364  }
365 
366  //Return status code
367  return error;
368 }
369 
370 
371 /**
372  * @brief Handle IKE SA creation event
373  * @param[in] sa Pointer to the IKE SA
374  * @return Error code
375  **/
376 
378 {
379  error_t error;
380  bool_t valid;
381  IkeContext *context;
382 
383  //Point to the IKE context
384  context = sa->context;
385 
386  //Initialize flag
387  valid = FALSE;
388 
389  //Valid entity's ID
390  if(context->idType != IKE_ID_TYPE_INVALID)
391  {
392 #if (IKE_PSK_AUTH_SUPPORT == ENABLED)
393  //Pre-shared key authentication?
394  if(context->pskLen > 0)
395  {
396  valid = TRUE;
397  }
398 #endif
399  }
400  else
401  {
402 #if (IKE_CERT_AUTH_SUPPORT == ENABLED)
403  //Certificate authentication?
404  if(context->certChain != NULL && context->certChainLen > 0)
405  {
406  valid = TRUE;
407  }
408 #endif
409  }
410 
411  //Valid credentials?
412  if(valid)
413  {
414  //Each endpoint chooses one of the two SPIs and must choose them so as to
415  //be unique identifiers of an IKE SA (refer to RFC 7296, section 2.6)
416  error = ikeGenerateSaSpi(sa, sa->initiatorSpi);
417 
418  //Check status code
419  if(!error)
420  {
421  //Nonces used in IKEv2 must be randomly chosen and must be at least
422  //128 bits in size (refer to RFC 7296, section 2.10)
423  error = ikeGenerateNonce(context, sa->initiatorNonce,
424  &sa->initiatorNonceLen);
425  }
426 
427  //Check status code
428  if(!error)
429  {
430  //Generate an ephemeral key pair
431  error = ikeGenerateDhKeyPair(sa);
432  }
433 
434  //Check status code
435  if(!error)
436  {
437  //The first exchange of an IKE session, IKE_SA_INIT, negotiates security
438  //parameters for the IKE SA, sends nonces, and sends Diffie-Hellman values
439  error = ikeSendIkeSaInitRequest(sa);
440  }
441  }
442  else
443  {
444  //No valid credentials provided
445  error = ERROR_NOT_CONFIGURED;
446  }
447 
448  //Return status code
449  return error;
450 }
451 
452 
453 /**
454  * @brief Handle IKE SA dead peer detection event
455  * @param[in] sa Pointer to the IKE SA
456  * @return Error code
457  **/
458 
460 {
461  //If no cryptographically protected messages have been received on an
462  //IKE SA or any of its Child SAs recently, the system needs to perform
463  //a liveness check in order to prevent sending messages to a dead peer
464  //(refer to RFC 7296, section 2.4)
466 
467  //An INFORMATIONAL request with no payloads is commonly used as a check
468  //for liveness (refer to RFC 7296, section 1)
469  return ikeSendInfoRequest(sa);
470 }
471 
472 
473 /**
474  * @brief Handle IKE SA rekeying event
475  * @param[in] sa Pointer to the IKE SA
476  * @return Error code
477  **/
478 
480 {
481  error_t error;
482  IkeContext *context;
483  IkeSaEntry *newSa;
484 
485  //Initialize status code
486  error = NO_ERROR;
487 
488  //Point to the IKE context
489  context = sa->context;
490 
491  //Create a new IKE SA
492  newSa = ikeCreateSaEntry(context);
493 
494  //Successful IKE SA creation?
495  if(newSa != NULL)
496  {
497  //Initialize IKE SA
498  newSa->remoteIpAddr = sa->remoteIpAddr;
499  newSa->remotePort = sa->remotePort;
500 
501  //The initiator of the rekey exchange is the new "original initiator"
502  //of the new IKE SA (refer to RFC 7296, section 1.3.2)
503  newSa->originalInitiator = TRUE;
504 
505  //Select the preferred Diffie-Hellman group number
506  newSa->dhGroupNum = context->preferredDhGroupNum;
507 
508  //Each endpoint chooses one of the two SPIs and must choose them so as to
509  //be unique identifiers of an IKE SA (refer to RFC 7296, section 2.6)
510  error = ikeGenerateSaSpi(newSa, newSa->initiatorSpi);
511 
512  //Check status code
513  if(!error)
514  {
515  //Nonces used in IKEv2 must be randomly chosen and must be at least
516  //128 bits in size (refer to RFC 7296, section 2.10)
517  error = ikeGenerateNonce(context, newSa->initiatorNonce,
518  &newSa->initiatorNonceLen);
519  }
520 
521  //Check status code
522  if(!error)
523  {
524  //Generate an ephemeral key pair
525  error = ikeGenerateDhKeyPair(newSa);
526  }
527 
528  //Check status code
529  if(!error)
530  {
531  //Acknowledge request
532  sa->rekeyRequest = FALSE;
533 
534  //Attach the newly created IKE SA
535  sa->newSa = newSa;
536 
537  //Update the state of the IKE SA
539 
540  //To rekey an IKE SA, establish a new equivalent IKE SA with the peer to
541  //whom the old IKE SA is shared using a CREATE_CHILD_SA within the existing
542  //IKE SA (refer to RFC 7296, section 2.8)
543  ikeSendCreateChildSaRequest(sa, sa->childSa);
544  }
545  }
546  else
547  {
548  //Failed to create IKE SA
549  }
550 
551  //Return status code
552  return error;
553 }
554 
555 
556 /**
557  * @brief Handle IKE SA reauthentication event
558  * @param[in] sa Pointer to the IKE SA
559  * @return Error code
560  **/
561 
563 {
564  error_t error;
565  IkeContext *context;
566  IkeSaEntry *newSa;
567  IkeChildSaEntry *childSa;
568  IkeChildSaEntry *newChildSa;
569 
570  //Initialize status code
571  error = NO_ERROR;
572 
573  //Point to the IKE context
574  context = sa->context;
575  //Point to the Child SA
576  childSa = sa->childSa;
577 
578  //Sanity check
579  if(childSa != NULL)
580  {
581  //Acknowledge request
582  sa->reauthPending = TRUE;
583 
584  //Create a new IKE SA
585  newSa = ikeCreateSaEntry(context);
586 
587  //Successful IKE SA creation?
588  if(newSa != NULL)
589  {
590  //Create a new Child SA
591  newChildSa = ikeCreateChildSaEntry(context);
592 
593  //Successful IKE SA creation?
594  if(newChildSa != NULL)
595  {
596  //Initialize IKE SA
597  newSa->remoteIpAddr = sa->remoteIpAddr;
598  newSa->remotePort = sa->remotePort;
599  newSa->remoteIpAddr = sa->remoteIpAddr;
600  newSa->remotePort = sa->remotePort;
601  newSa->childSa = newChildSa;
602 
603  //The initiator of the rekey exchange is the new "original initiator"
604  //of the new IKE SA (refer to RFC 7296, section 1.3.2)
605  newSa->originalInitiator = TRUE;
606 
607  //Select the preferred Diffie-Hellman group number
608  newSa->dhGroupNum = context->preferredDhGroupNum;
609 
610  //Initialize Child SA
611  newChildSa->sa = newSa;
612  newChildSa->mode = childSa->mode;
613  newChildSa->protocol = childSa->protocol;
614  newChildSa->initiator = TRUE;
615  newChildSa->selector = childSa->selector;
616 
617  //Each endpoint chooses one of the two SPIs and must choose them so as to
618  //be unique identifiers of an IKE SA (refer to RFC 7296, section 2.6)
619  error = ikeGenerateSaSpi(newSa, newSa->initiatorSpi);
620 
621  //Check status code
622  if(!error)
623  {
624  //Nonces used in IKEv2 must be randomly chosen and must be at least
625  //128 bits in size (refer to RFC 7296, section 2.10)
626  error = ikeGenerateNonce(context, newSa->initiatorNonce,
627  &newSa->initiatorNonceLen);
628  }
629 
630  //Check status code
631  if(!error)
632  {
633  //Generate an ephemeral key pair
634  error = ikeGenerateDhKeyPair(newSa);
635  }
636 
637  //Check status code
638  if(!error)
639  {
640  //The first exchange of an IKE session, IKE_SA_INIT, negotiates security
641  //parameters for the IKE SA, sends nonces, and sends Diffie-Hellman values
642  error = ikeSendIkeSaInitRequest(newSa);
643  }
644 
645  //Check status code
646  if(!error)
647  {
648  //Attach the old IKE SA
649  newSa->oldSa = sa;
650  }
651  else
652  {
653  //Failed to initiate reauthentication
654  ikeDeleteSaEntry(newSa);
655  }
656  }
657  else
658  {
659  //Failed to create Child SA
660  ikeDeleteSaEntry(newSa);
661  //Report en error
662  error = ERROR_OUT_OF_RESOURCES;
663  }
664  }
665  else
666  {
667  //Failed to create IKE SA
668  error = ERROR_OUT_OF_RESOURCES;
669  }
670 
671  //Failed to initiate reauthentication?
672  if(error)
673  {
674  //Close the old IKE SA
675  sa->deleteRequest = TRUE;
676  //Notify the IKE context that the IKE SA should be closed
677  osSetEvent(&context->event);
678  }
679  }
680 
681  //Return status code
682  return error;
683 }
684 
685 
686 /**
687  * @brief Handle IKE SA deletion event
688  * @param[in] sa Pointer to the IKE SA
689  * @return Error code
690  **/
691 
693 {
694  //Acknowledge request
695  sa->deleteRequest = FALSE;
696  sa->childSa = NULL;
697 
698  //Update the state of the IKE SA
700 
701  //To delete an SA, an INFORMATIONAL exchange with one or more Delete payloads
702  //is sent listing the SPIs of the SAs to be deleted
703  return ikeSendInfoRequest(sa);
704 }
705 
706 
707 /**
708  * @brief Handle Child SA creation event
709  * @param[in] childSa Pointer to the Child SA
710  * @return Error code
711  **/
712 
714 {
715  error_t error;
716  IkeContext *context;
717  IkeSaEntry *sa;
718 
719  //Initialize status code
720  error = NO_ERROR;
721 
722  //Point to the IKE context
723  context = childSa->context;
724 
725  {
726  //Create a new IKE SA
727  sa = ikeCreateSaEntry(context);
728 
729  //Successful IKE SA creation?
730  if(sa != NULL)
731  {
732  //Initialize IKE SA
733  sa->remoteIpAddr = childSa->remoteIpAddr;
734  sa->remotePort = IKE_PORT;
735  sa->childSa = childSa;
736 
737  //The original initiator always refers to the party who initiated the
738  //exchange (refer to RFC 7296, section 2.2)
739  sa->originalInitiator = TRUE;
740 
741  //Select the preferred Diffie-Hellman group number
742  sa->dhGroupNum = context->preferredDhGroupNum;
743 
744  //Attach the newly created IKE SA to the Child SA
745  childSa->sa = sa;
746 
747  //Update the state of the IKE SA
749  //Notify the IKE context that the IKE SA should be created
750  osSetEvent(&context->event);
751  }
752  else
753  {
754  //Failed to create IKE SA
755  }
756  }
757 
758  //Return status code
759  return error;
760 }
761 
762 
763 /**
764  * @brief Handle Child SA rekeying event
765  * @param[in] childSa Pointer to the Child SA
766  * @return Error code
767  **/
768 
770 {
771  error_t error;
772  IkeSaEntry *sa;
773  IkeContext *context;
774  IkeChildSaEntry *newChildSa;
775 
776  //Initialize status code
777  error = NO_ERROR;
778 
779  //Point to the IKE context
780  context = childSa->context;
781  //Point to the IKE SA
782  sa = childSa->sa;
783 
784  //Create a new Child SA
785  newChildSa = ikeCreateChildSaEntry(context);
786 
787  //Successful Child SA creation?
788  if(newChildSa != NULL)
789  {
790  //Initialize Child SA
791  newChildSa->sa = sa;
792  newChildSa->oldChildSa = childSa;
793  newChildSa->protocol = childSa->protocol;
794  newChildSa->mode = childSa->mode;
795  newChildSa->initiator = TRUE;
796  newChildSa->selector = childSa->selector;
797 
798  //Generate a new SPI for the Child SA
799  error = ikeGenerateChildSaSpi(newChildSa, newChildSa->localSpi);
800 
801  //Check status code
802  if(!error)
803  {
804  //Nonces used in IKEv2 must be randomly chosen and must be at least
805  //128 bits in size (refer to RFC 7296, section 2.10)
806  error = ikeGenerateNonce(context, newChildSa->initiatorNonce,
807  &newChildSa->initiatorNonceLen);
808  }
809 
810  //Check status code
811  if(!error)
812  {
813  //Acknowledge request
814  childSa->rekeyRequest = FALSE;
815 
816  //Attach the newly created Child SA to the IKE SA
817  sa->childSa = newChildSa;
818 
819  //Update the state of the IKE SA
821  //Update the state of the Child SA
823 
824  //To rekey a Child SA within an existing IKE SA, create a new
825  //equivalent SA, and when the new one is established, delete the
826  //old one
827  error = ikeSendCreateChildSaRequest(sa, newChildSa);
828  }
829  }
830  else
831  {
832  //Failed to create Child SA
833  }
834 
835  //Return status code
836  return error;
837 }
838 
839 
840 /**
841  * @brief Handle Child SA deletion event
842  * @param[in] childSa Pointer to the Child SA
843  * @return Error code
844  **/
845 
847 {
848  IkeSaEntry *sa;
849 
850  //Point to the IKE SA
851  sa = childSa->sa;
852 
853  //Acknowledge request
854  childSa->deleteRequest = FALSE;
855 
856  //Attach the Child SA to the IKE SA
857  sa->childSa = childSa;
858 
859  //Update the state of the IKE SA
861  //Update the state of the Child SA
863 
864  //To delete an SA, an INFORMATIONAL exchange with one or more Delete payloads
865  //is sent listing the SPIs of the SAs to be deleted
866  return ikeSendInfoRequest(sa);
867 }
868 
869 #endif
IkeSaState
IKE Security Association state.
Definition: ike.h:1284
@ IKE_CHILD_SA_STATE_DELETE
Definition: ike.h:1320
error_t ikeProcessSaReauthEvent(IkeSaEntry *sa)
Handle IKE SA reauthentication event.
Definition: ike_fsm.c:562
Diffie-Hellman key exchange.
int bool_t
Definition: compiler_port.h:61
Helper functions for IKEv2.
IKE message formatting.
error_t ikeProcessSaRekeyEvent(IkeSaEntry *sa)
Handle IKE SA rekeying event.
Definition: ike_fsm.c:479
error_t ikeGenerateSaSpi(IkeSaEntry *sa, uint8_t *spi)
Generate a new IKE SA SPI.
Definition: ike_misc.c:530
@ IKE_SA_STATE_DELETE_REQ
Definition: ike.h:1296
#define TRUE
Definition: os_port.h:50
systime_t ikeRandomizeDelay(IkeContext *context, systime_t delay)
Apply random jitter to a time interval.
Definition: ike_misc.c:723
@ ERROR_OUT_OF_RESOURCES
Definition: error.h:64
IkeChildSaEntry * ikeCreateChildSaEntry(IkeContext *context)
Create a new Child Security Association.
Definition: ike_misc.c:396
@ ERROR_NOT_CONFIGURED
Definition: error.h:218
IKEv2 finite state machine.
#define timeCompare(t1, t2)
Definition: os_port.h:40
@ IKE_CHILD_SA_STATE_REKEY
Definition: ike.h:1319
error_t ikeProcessSaDeleteEvent(IkeSaEntry *sa)
Handle IKE SA deletion event.
Definition: ike_fsm.c:692
@ IKE_SA_STATE_REKEY_REQ
Definition: ike.h:1294
error_t ikeProcessSaEvents(IkeSaEntry *sa)
IKE SA event processing.
Definition: ike_fsm.c:234
#define IKE_HALF_OPEN_TIMEOUT
Definition: ike.h:152
void ikeChangeSaState(IkeSaEntry *sa, IkeSaState newState)
Update IKE SA state.
Definition: ike_fsm.c:53
#define IkeContext
Definition: ike.h:796
@ IKE_SA_STATE_DELETE_CHILD_RESP
Definition: ike.h:1303
#define FALSE
Definition: os_port.h:46
IkeSaEntry * ikeCreateSaEntry(IkeContext *context)
Create a new IKE Security Association.
Definition: ike_misc.c:136
error_t ikeProcessSaInitEvent(IkeSaEntry *sa)
Handle IKE SA creation event.
Definition: ike_fsm.c:377
@ IKE_SA_STATE_OPEN
Definition: ike.h:1291
error_t
Error codes.
Definition: error.h:43
@ IKE_SA_STATE_AUTH_FAILURE_RESP
Definition: ike.h:1305
@ IKE_SA_STATE_REKEY_CHILD_REQ
Definition: ike.h:1300
error_t ikeRetransmitRequest(IkeSaEntry *sa)
Retransmit IKE request message.
Definition: ike_misc.c:56
IkeChildSaState
Child Security Association state.
Definition: ike.h:1314
Helper routines for IPsec.
@ IKE_SA_STATE_INIT_REQ
Definition: ike.h:1287
error_t ikeSendInfoRequest(IkeSaEntry *sa)
Send INFORMATIONAL request.
@ IKE_SA_STATE_AUTH_REQ
Definition: ike.h:1289
void ikeDeleteSaEntry(IkeSaEntry *sa)
Delete an IKE Security Association.
Definition: ike_misc.c:298
@ IKE_CHILD_SA_STATE_INIT
Definition: ike.h:1317
#define TRACE_INFO(...)
Definition: debug.h:105
void ikeChangeChildSaState(IkeChildSaEntry *childSa, IkeChildSaState newState)
Update Child SA state.
Definition: ike_fsm.c:108
@ IKE_CHILD_SA_STATE_CLOSED
Definition: ike.h:1315
error_t ikeGenerateDhKeyPair(IkeSaEntry *sa)
Diffie-Hellman key pair generation.
IKEv2 (Internet Key Exchange Protocol)
error_t ikeProcessSaDpdEvent(IkeSaEntry *sa)
Handle IKE SA dead peer detection event.
Definition: ike_fsm.c:459
uint32_t systime_t
System time.
uint32_t time
#define IkeSaEntry
Definition: ike.h:800
#define IKE_PORT
Definition: ike.h:785
@ IKE_SA_STATE_REKEY_CHILD_RESP
Definition: ike.h:1301
error_t ikeSendIkeSaInitRequest(IkeSaEntry *sa)
Send IKE_SA_INIT request.
error_t ikeGenerateChildSaSpi(IkeChildSaEntry *childSa, uint8_t *spi)
Generate a new Child SA SPI.
Definition: ike_misc.c:615
@ IKE_SA_STATE_DPD_REQ
Definition: ike.h:1292
@ IKE_SA_STATE_DELETE_RESP
Definition: ike.h:1297
@ IKE_ID_TYPE_INVALID
Definition: ike.h:1066
@ IKE_SA_STATE_AUTH_RESP
Definition: ike.h:1290
@ IKE_SA_STATE_INIT_RESP
Definition: ike.h:1288
#define IKE_INIT_TIMEOUT
Definition: ike.h:138
@ IKE_SA_STATE_REKEY_RESP
Definition: ike.h:1295
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
error_t ikeGenerateNonce(IkeContext *context, uint8_t *nonce, size_t *length)
Generate a new nonce.
Definition: ike_misc.c:689
void ikeProcessEvents(IkeContext *context)
IKE event processing.
Definition: ike_fsm.c:129
@ IKE_SA_STATE_CREATE_CHILD_RESP
Definition: ike.h:1299
#define IKE_MAX_RETRIES
Definition: ike.h:131
@ IKE_SA_STATE_DPD_RESP
Definition: ike.h:1293
unsigned int uint_t
Definition: compiler_port.h:57
error_t ikeProcessChildSaDeleteEvent(IkeChildSaEntry *childSa)
Handle Child SA deletion event.
Definition: ike_fsm.c:846
#define IkeChildSaEntry
Definition: ike.h:804
error_t ikeProcessChildSaInitEvent(IkeChildSaEntry *childSa)
Handle Child SA creation event.
Definition: ike_fsm.c:713
error_t ikeProcessChildSaEvents(IkeChildSaEntry *childSa)
Child SA event processing.
Definition: ike_fsm.c:343
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
@ IKE_SA_STATE_DELETE_CHILD_REQ
Definition: ike.h:1302
@ IKE_CHILD_SA_STATE_OPEN
Definition: ike.h:1318
systime_t osGetSystemTime(void)
Retrieve system time.
error_t ikeSendCreateChildSaRequest(IkeSaEntry *sa, IkeChildSaEntry *childSa)
Send CREATE_CHILD_SA request.
error_t ikeProcessChildSaRekeyEvent(IkeChildSaEntry *childSa)
Handle Child SA rekeying event.
Definition: ike_fsm.c:769