LCOV - code coverage report
Current view: top level - src/eap_peer - ikev2.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 450 643 70.0 %
Date: 2014-03-02 Functions: 27 28 96.4 %
Branches: 141 280 50.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * IKEv2 responder (RFC 4306) for EAP-IKEV2
       3                 :            :  * Copyright (c) 2007, Jouni Malinen <j@w1.fi>
       4                 :            :  *
       5                 :            :  * This software may be distributed under the terms of the BSD license.
       6                 :            :  * See README for more details.
       7                 :            :  */
       8                 :            : 
       9                 :            : #include "includes.h"
      10                 :            : 
      11                 :            : #include "common.h"
      12                 :            : #include "crypto/dh_groups.h"
      13                 :            : #include "crypto/random.h"
      14                 :            : #include "ikev2.h"
      15                 :            : 
      16                 :            : 
      17                 :          4 : void ikev2_responder_deinit(struct ikev2_responder_data *data)
      18                 :            : {
      19                 :          4 :         ikev2_free_keys(&data->keys);
      20                 :          4 :         wpabuf_free(data->i_dh_public);
      21                 :          4 :         wpabuf_free(data->r_dh_private);
      22                 :          4 :         os_free(data->IDi);
      23                 :          4 :         os_free(data->IDr);
      24                 :          4 :         os_free(data->shared_secret);
      25                 :          4 :         wpabuf_free(data->i_sign_msg);
      26                 :          4 :         wpabuf_free(data->r_sign_msg);
      27                 :          4 :         os_free(data->key_pad);
      28                 :          4 : }
      29                 :            : 
      30                 :            : 
      31                 :          4 : static int ikev2_derive_keys(struct ikev2_responder_data *data)
      32                 :            : {
      33                 :            :         u8 *buf, *pos, *pad, skeyseed[IKEV2_MAX_HASH_LEN];
      34                 :            :         size_t buf_len, pad_len;
      35                 :            :         struct wpabuf *shared;
      36                 :            :         const struct ikev2_integ_alg *integ;
      37                 :            :         const struct ikev2_prf_alg *prf;
      38                 :            :         const struct ikev2_encr_alg *encr;
      39                 :            :         int ret;
      40                 :            :         const u8 *addr[2];
      41                 :            :         size_t len[2];
      42                 :            : 
      43                 :            :         /* RFC 4306, Sect. 2.14 */
      44                 :            : 
      45                 :          4 :         integ = ikev2_get_integ(data->proposal.integ);
      46                 :          4 :         prf = ikev2_get_prf(data->proposal.prf);
      47                 :          4 :         encr = ikev2_get_encr(data->proposal.encr);
      48 [ +  - ][ +  - ]:          4 :         if (integ == NULL || prf == NULL || encr == NULL) {
                 [ -  + ]
      49                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unsupported proposal");
      50                 :          0 :                 return -1;
      51                 :            :         }
      52                 :            : 
      53                 :          4 :         shared = dh_derive_shared(data->i_dh_public, data->r_dh_private,
      54                 :            :                                   data->dh);
      55         [ -  + ]:          4 :         if (shared == NULL)
      56                 :          0 :                 return -1;
      57                 :            : 
      58                 :            :         /* Construct Ni | Nr | SPIi | SPIr */
      59                 :            : 
      60                 :          4 :         buf_len = data->i_nonce_len + data->r_nonce_len + 2 * IKEV2_SPI_LEN;
      61                 :          4 :         buf = os_malloc(buf_len);
      62         [ -  + ]:          4 :         if (buf == NULL) {
      63                 :          0 :                 wpabuf_free(shared);
      64                 :          0 :                 return -1;
      65                 :            :         }
      66                 :            : 
      67                 :          4 :         pos = buf;
      68                 :          4 :         os_memcpy(pos, data->i_nonce, data->i_nonce_len);
      69                 :          4 :         pos += data->i_nonce_len;
      70                 :          4 :         os_memcpy(pos, data->r_nonce, data->r_nonce_len);
      71                 :          4 :         pos += data->r_nonce_len;
      72                 :          4 :         os_memcpy(pos, data->i_spi, IKEV2_SPI_LEN);
      73                 :          4 :         pos += IKEV2_SPI_LEN;
      74                 :          4 :         os_memcpy(pos, data->r_spi, IKEV2_SPI_LEN);
      75                 :            : #ifdef CCNS_PL
      76                 :            : #if __BYTE_ORDER == __LITTLE_ENDIAN
      77                 :            :         {
      78                 :            :                 int i;
      79                 :            :                 u8 *tmp = pos - IKEV2_SPI_LEN;
      80                 :            :                 /* Incorrect byte re-ordering on little endian hosts.. */
      81                 :            :                 for (i = 0; i < IKEV2_SPI_LEN; i++)
      82                 :            :                         *tmp++ = data->i_spi[IKEV2_SPI_LEN - 1 - i];
      83                 :            :                 for (i = 0; i < IKEV2_SPI_LEN; i++)
      84                 :            :                         *tmp++ = data->r_spi[IKEV2_SPI_LEN - 1 - i];
      85                 :            :         }
      86                 :            : #endif
      87                 :            : #endif /* CCNS_PL */
      88                 :            : 
      89                 :            :         /* SKEYSEED = prf(Ni | Nr, g^ir) */
      90                 :            :         /* Use zero-padding per RFC 4306, Sect. 2.14 */
      91                 :          4 :         pad_len = data->dh->prime_len - wpabuf_len(shared);
      92                 :            : #ifdef CCNS_PL
      93                 :            :         /* Shared secret is not zero-padded correctly */
      94                 :            :         pad_len = 0;
      95                 :            : #endif /* CCNS_PL */
      96         [ -  + ]:          4 :         pad = os_zalloc(pad_len ? pad_len : 1);
      97         [ -  + ]:          4 :         if (pad == NULL) {
      98                 :          0 :                 wpabuf_free(shared);
      99                 :          0 :                 os_free(buf);
     100                 :          0 :                 return -1;
     101                 :            :         }
     102                 :            : 
     103                 :          4 :         addr[0] = pad;
     104                 :          4 :         len[0] = pad_len;
     105                 :          4 :         addr[1] = wpabuf_head(shared);
     106                 :          4 :         len[1] = wpabuf_len(shared);
     107         [ -  + ]:          4 :         if (ikev2_prf_hash(prf->id, buf, data->i_nonce_len + data->r_nonce_len,
     108                 :            :                            2, addr, len, skeyseed) < 0) {
     109                 :          0 :                 wpabuf_free(shared);
     110                 :          0 :                 os_free(buf);
     111                 :          0 :                 os_free(pad);
     112                 :          0 :                 return -1;
     113                 :            :         }
     114                 :          4 :         os_free(pad);
     115                 :          4 :         wpabuf_free(shared);
     116                 :            : 
     117                 :            :         /* DH parameters are not needed anymore, so free them */
     118                 :          4 :         wpabuf_free(data->i_dh_public);
     119                 :          4 :         data->i_dh_public = NULL;
     120                 :          4 :         wpabuf_free(data->r_dh_private);
     121                 :          4 :         data->r_dh_private = NULL;
     122                 :            : 
     123                 :          4 :         wpa_hexdump_key(MSG_DEBUG, "IKEV2: SKEYSEED",
     124                 :            :                         skeyseed, prf->hash_len);
     125                 :            : 
     126                 :          4 :         ret = ikev2_derive_sk_keys(prf, integ, encr, skeyseed, buf, buf_len,
     127                 :            :                                    &data->keys);
     128                 :          4 :         os_free(buf);
     129                 :          4 :         return ret;
     130                 :            : }
     131                 :            : 
     132                 :            : 
     133                 :         16 : static int ikev2_parse_transform(struct ikev2_proposal_data *prop,
     134                 :            :                                  const u8 *pos, const u8 *end)
     135                 :            : {
     136                 :            :         int transform_len;
     137                 :            :         const struct ikev2_transform *t;
     138                 :            :         u16 transform_id;
     139                 :            :         const u8 *tend;
     140                 :            : 
     141         [ -  + ]:         16 :         if (end - pos < (int) sizeof(*t)) {
     142                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Too short transform");
     143                 :          0 :                 return -1;
     144                 :            :         }
     145                 :            : 
     146                 :         16 :         t = (const struct ikev2_transform *) pos;
     147                 :         16 :         transform_len = WPA_GET_BE16(t->transform_length);
     148 [ +  - ][ -  + ]:         16 :         if (transform_len < (int) sizeof(*t) || pos + transform_len > end) {
     149                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Invalid transform length %d",
     150                 :            :                            transform_len);
     151                 :          0 :                 return -1;
     152                 :            :         }
     153                 :         16 :         tend = pos + transform_len;
     154                 :            : 
     155                 :         16 :         transform_id = WPA_GET_BE16(t->transform_id);
     156                 :            : 
     157                 :         16 :         wpa_printf(MSG_DEBUG, "IKEV2:   Transform:");
     158                 :         16 :         wpa_printf(MSG_DEBUG, "IKEV2:     Type: %d  Transform Length: %d  "
     159                 :            :                    "Transform Type: %d  Transform ID: %d",
     160                 :         32 :                    t->type, transform_len, t->transform_type, transform_id);
     161                 :            : 
     162 [ +  + ][ -  + ]:         16 :         if (t->type != 0 && t->type != 3) {
     163                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unexpected Transform type");
     164                 :          0 :                 return -1;
     165                 :            :         }
     166                 :            : 
     167                 :         16 :         pos = (const u8 *) (t + 1);
     168         [ +  + ]:         16 :         if (pos < tend) {
     169                 :          4 :                 wpa_hexdump(MSG_DEBUG, "IKEV2:     Transform Attributes",
     170                 :          4 :                             pos, tend - pos);
     171                 :            :         }
     172                 :            : 
     173   [ +  +  +  +  :         16 :         switch (t->transform_type) {
                      - ]
     174                 :            :         case IKEV2_TRANSFORM_ENCR:
     175         [ +  - ]:          4 :                 if (ikev2_get_encr(transform_id)) {
     176         [ +  - ]:          4 :                         if (transform_id == ENCR_AES_CBC) {
     177         [ -  + ]:          4 :                                 if (tend - pos != 4) {
     178                 :          0 :                                         wpa_printf(MSG_DEBUG, "IKEV2: No "
     179                 :            :                                                    "Transform Attr for AES");
     180                 :          0 :                                         break;
     181                 :            :                                 }
     182                 :            : #ifdef CCNS_PL
     183                 :            :                                 if (WPA_GET_BE16(pos) != 0x001d /* ?? */) {
     184                 :            :                                         wpa_printf(MSG_DEBUG, "IKEV2: Not a "
     185                 :            :                                                    "Key Size attribute for "
     186                 :            :                                                    "AES");
     187                 :            :                                         break;
     188                 :            :                                 }
     189                 :            : #else /* CCNS_PL */
     190         [ -  + ]:          4 :                                 if (WPA_GET_BE16(pos) != 0x800e) {
     191                 :          0 :                                         wpa_printf(MSG_DEBUG, "IKEV2: Not a "
     192                 :            :                                                    "Key Size attribute for "
     193                 :            :                                                    "AES");
     194                 :          0 :                                         break;
     195                 :            :                                 }
     196                 :            : #endif /* CCNS_PL */
     197         [ -  + ]:          4 :                                 if (WPA_GET_BE16(pos + 2) != 128) {
     198                 :          0 :                                         wpa_printf(MSG_DEBUG, "IKEV2: "
     199                 :            :                                                    "Unsupported AES key size "
     200                 :            :                                                    "%d bits",
     201                 :          0 :                                                    WPA_GET_BE16(pos + 2));
     202                 :          0 :                                         break;
     203                 :            :                                 }
     204                 :            :                         }
     205                 :          4 :                         prop->encr = transform_id;
     206                 :            :                 }
     207                 :          4 :                 break;
     208                 :            :         case IKEV2_TRANSFORM_PRF:
     209         [ +  - ]:          4 :                 if (ikev2_get_prf(transform_id))
     210                 :          4 :                         prop->prf = transform_id;
     211                 :          4 :                 break;
     212                 :            :         case IKEV2_TRANSFORM_INTEG:
     213         [ +  - ]:          4 :                 if (ikev2_get_integ(transform_id))
     214                 :          4 :                         prop->integ = transform_id;
     215                 :          4 :                 break;
     216                 :            :         case IKEV2_TRANSFORM_DH:
     217         [ +  - ]:          4 :                 if (dh_groups_get(transform_id))
     218                 :          4 :                         prop->dh = transform_id;
     219                 :          4 :                 break;
     220                 :            :         }
     221                 :            : 
     222                 :         16 :         return transform_len;
     223                 :            : }
     224                 :            : 
     225                 :            : 
     226                 :          4 : static int ikev2_parse_proposal(struct ikev2_proposal_data *prop,
     227                 :            :                                 const u8 *pos, const u8 *end)
     228                 :            : {
     229                 :            :         const u8 *pend, *ppos;
     230                 :            :         int proposal_len, i;
     231                 :            :         const struct ikev2_proposal *p;
     232                 :            : 
     233         [ -  + ]:          4 :         if (end - pos < (int) sizeof(*p)) {
     234                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Too short proposal");
     235                 :          0 :                 return -1;
     236                 :            :         }
     237                 :            : 
     238                 :            :         /* FIX: AND processing if multiple proposals use the same # */
     239                 :            : 
     240                 :          4 :         p = (const struct ikev2_proposal *) pos;
     241                 :          4 :         proposal_len = WPA_GET_BE16(p->proposal_length);
     242 [ +  - ][ -  + ]:          4 :         if (proposal_len < (int) sizeof(*p) || pos + proposal_len > end) {
     243                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Invalid proposal length %d",
     244                 :            :                            proposal_len);
     245                 :          0 :                 return -1;
     246                 :            :         }
     247                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: SAi1 Proposal # %d",
     248                 :          4 :                    p->proposal_num);
     249                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2:   Type: %d  Proposal Length: %d "
     250                 :            :                    " Protocol ID: %d",
     251                 :          8 :                    p->type, proposal_len, p->protocol_id);
     252                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2:   SPI Size: %d  Transforms: %d",
     253                 :          8 :                    p->spi_size, p->num_transforms);
     254                 :            : 
     255 [ -  + ][ #  # ]:          4 :         if (p->type != 0 && p->type != 2) {
     256                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unexpected Proposal type");
     257                 :          0 :                 return -1;
     258                 :            :         }
     259                 :            : 
     260         [ -  + ]:          4 :         if (p->protocol_id != IKEV2_PROTOCOL_IKE) {
     261                 :          0 :                 wpa_printf(MSG_DEBUG, "IKEV2: Unexpected Protocol ID "
     262                 :            :                            "(only IKE allowed for EAP-IKEv2)");
     263                 :          0 :                 return -1;
     264                 :            :         }
     265                 :            : 
     266         [ -  + ]:          4 :         if (p->proposal_num != prop->proposal_num) {
     267         [ #  # ]:          0 :                 if (p->proposal_num == prop->proposal_num + 1)
     268                 :          0 :                         prop->proposal_num = p->proposal_num;
     269                 :            :                 else {
     270                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected Proposal #");
     271                 :          0 :                         return -1;
     272                 :            :                 }
     273                 :            :         }
     274                 :            : 
     275                 :          4 :         ppos = (const u8 *) (p + 1);
     276                 :          4 :         pend = pos + proposal_len;
     277         [ -  + ]:          4 :         if (ppos + p->spi_size > pend) {
     278                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Not enough room for SPI "
     279                 :            :                            "in proposal");
     280                 :          0 :                 return -1;
     281                 :            :         }
     282         [ -  + ]:          4 :         if (p->spi_size) {
     283                 :          0 :                 wpa_hexdump(MSG_DEBUG, "IKEV2:    SPI",
     284                 :          0 :                             ppos, p->spi_size);
     285                 :          0 :                 ppos += p->spi_size;
     286                 :            :         }
     287                 :            : 
     288                 :            :         /*
     289                 :            :          * For initial IKE_SA negotiation, SPI Size MUST be zero; for
     290                 :            :          * subsequent negotiations, it must be 8 for IKE. We only support
     291                 :            :          * initial case for now.
     292                 :            :          */
     293         [ -  + ]:          4 :         if (p->spi_size != 0) {
     294                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unexpected SPI Size");
     295                 :          0 :                 return -1;
     296                 :            :         }
     297                 :            : 
     298         [ -  + ]:          4 :         if (p->num_transforms == 0) {
     299                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: At least one transform required");
     300                 :          0 :                 return -1;
     301                 :            :         }
     302                 :            : 
     303         [ +  + ]:         20 :         for (i = 0; i < (int) p->num_transforms; i++) {
     304                 :         16 :                 int tlen = ikev2_parse_transform(prop, ppos, pend);
     305         [ -  + ]:         16 :                 if (tlen < 0)
     306                 :          0 :                         return -1;
     307                 :         16 :                 ppos += tlen;
     308                 :            :         }
     309                 :            : 
     310         [ -  + ]:          4 :         if (ppos != pend) {
     311                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unexpected data after "
     312                 :            :                            "transforms");
     313                 :          0 :                 return -1;
     314                 :            :         }
     315                 :            : 
     316                 :          4 :         return proposal_len;
     317                 :            : }
     318                 :            : 
     319                 :            : 
     320                 :          4 : static int ikev2_process_sai1(struct ikev2_responder_data *data,
     321                 :            :                               const u8 *sai1, size_t sai1_len)
     322                 :            : {
     323                 :            :         struct ikev2_proposal_data prop;
     324                 :            :         const u8 *pos, *end;
     325                 :          4 :         int found = 0;
     326                 :            : 
     327                 :            :         /* Security Association Payloads: <Proposals> */
     328                 :            : 
     329         [ -  + ]:          4 :         if (sai1 == NULL) {
     330                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: SAi1 not received");
     331                 :          0 :                 return -1;
     332                 :            :         }
     333                 :            : 
     334                 :          4 :         os_memset(&prop, 0, sizeof(prop));
     335                 :          4 :         prop.proposal_num = 1;
     336                 :            : 
     337                 :          4 :         pos = sai1;
     338                 :          4 :         end = sai1 + sai1_len;
     339                 :            : 
     340         [ +  + ]:          8 :         while (pos < end) {
     341                 :            :                 int plen;
     342                 :            : 
     343                 :          4 :                 prop.integ = -1;
     344                 :          4 :                 prop.prf = -1;
     345                 :          4 :                 prop.encr = -1;
     346                 :          4 :                 prop.dh = -1;
     347                 :          4 :                 plen = ikev2_parse_proposal(&prop, pos, end);
     348         [ -  + ]:          4 :                 if (plen < 0)
     349                 :          0 :                         return -1;
     350                 :            : 
     351 [ +  - ][ +  - ]:          4 :                 if (!found && prop.integ != -1 && prop.prf != -1 &&
         [ +  - ][ +  - ]
     352         [ +  - ]:          4 :                     prop.encr != -1 && prop.dh != -1) {
     353                 :          4 :                         os_memcpy(&data->proposal, &prop, sizeof(prop));
     354                 :          4 :                         data->dh = dh_groups_get(prop.dh);
     355                 :          4 :                         found = 1;
     356                 :            :                 }
     357                 :            : 
     358                 :          4 :                 pos += plen;
     359                 :            :         }
     360                 :            : 
     361         [ -  + ]:          4 :         if (pos != end) {
     362                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unexpected data after proposals");
     363                 :          0 :                 return -1;
     364                 :            :         }
     365                 :            : 
     366         [ -  + ]:          4 :         if (!found) {
     367                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: No acceptable proposal found");
     368                 :          0 :                 return -1;
     369                 :            :         }
     370                 :            : 
     371                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: Accepted proposal #%d: ENCR:%d PRF:%d "
     372                 :          4 :                    "INTEG:%d D-H:%d", data->proposal.proposal_num,
     373                 :            :                    data->proposal.encr, data->proposal.prf,
     374                 :            :                    data->proposal.integ, data->proposal.dh);
     375                 :            : 
     376                 :          4 :         return 0;
     377                 :            : }
     378                 :            : 
     379                 :            : 
     380                 :          4 : static int ikev2_process_kei(struct ikev2_responder_data *data,
     381                 :            :                              const u8 *kei, size_t kei_len)
     382                 :            : {
     383                 :            :         u16 group;
     384                 :            : 
     385                 :            :         /*
     386                 :            :          * Key Exchange Payload:
     387                 :            :          * DH Group # (16 bits)
     388                 :            :          * RESERVED (16 bits)
     389                 :            :          * Key Exchange Data (Diffie-Hellman public value)
     390                 :            :          */
     391                 :            : 
     392         [ -  + ]:          4 :         if (kei == NULL) {
     393                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: KEi not received");
     394                 :          0 :                 return -1;
     395                 :            :         }
     396                 :            : 
     397         [ -  + ]:          4 :         if (kei_len < 4 + 96) {
     398                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Too show Key Exchange Payload");
     399                 :          0 :                 return -1;
     400                 :            :         }
     401                 :            : 
     402                 :          4 :         group = WPA_GET_BE16(kei);
     403                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: KEi DH Group #%u", group);
     404                 :            : 
     405         [ -  + ]:          4 :         if (group != data->proposal.dh) {
     406                 :          0 :                 wpa_printf(MSG_DEBUG, "IKEV2: KEi DH Group #%u does not match "
     407                 :            :                            "with the selected proposal (%u)",
     408                 :            :                            group, data->proposal.dh);
     409                 :            :                 /* Reject message with Notify payload of type
     410                 :            :                  * INVALID_KE_PAYLOAD (RFC 4306, Sect. 3.4) */
     411                 :          0 :                 data->error_type = INVALID_KE_PAYLOAD;
     412                 :          0 :                 data->state = NOTIFY;
     413                 :          0 :                 return -1;
     414                 :            :         }
     415                 :            : 
     416         [ -  + ]:          4 :         if (data->dh == NULL) {
     417                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unsupported DH group");
     418                 :          0 :                 return -1;
     419                 :            :         }
     420                 :            : 
     421                 :            :         /* RFC 4306, Section 3.4:
     422                 :            :          * The length of DH public value MUST be equal to the length of the
     423                 :            :          * prime modulus.
     424                 :            :          */
     425         [ -  + ]:          4 :         if (kei_len - 4 != data->dh->prime_len) {
     426                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Invalid DH public value length "
     427                 :            :                            "%ld (expected %ld)",
     428                 :          0 :                            (long) (kei_len - 4), (long) data->dh->prime_len);
     429                 :          0 :                 return -1;
     430                 :            :         }
     431                 :            : 
     432                 :          4 :         wpabuf_free(data->i_dh_public);
     433                 :          4 :         data->i_dh_public = wpabuf_alloc(kei_len - 4);
     434         [ -  + ]:          4 :         if (data->i_dh_public == NULL)
     435                 :          0 :                 return -1;
     436                 :          4 :         wpabuf_put_data(data->i_dh_public, kei + 4, kei_len - 4);
     437                 :            : 
     438                 :          4 :         wpa_hexdump_buf(MSG_DEBUG, "IKEV2: KEi Diffie-Hellman Public Value",
     439                 :          4 :                         data->i_dh_public);
     440                 :            :         
     441                 :          4 :         return 0;
     442                 :            : }
     443                 :            : 
     444                 :            : 
     445                 :          4 : static int ikev2_process_ni(struct ikev2_responder_data *data,
     446                 :            :                             const u8 *ni, size_t ni_len)
     447                 :            : {
     448         [ -  + ]:          4 :         if (ni == NULL) {
     449                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Ni not received");
     450                 :          0 :                 return -1;
     451                 :            :         }
     452                 :            : 
     453 [ +  - ][ -  + ]:          4 :         if (ni_len < IKEV2_NONCE_MIN_LEN || ni_len > IKEV2_NONCE_MAX_LEN) {
     454                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Invalid Ni length %ld",
     455                 :            :                            (long) ni_len);
     456                 :          0 :                 return -1;
     457                 :            :         }
     458                 :            : 
     459                 :            : #ifdef CCNS_PL
     460                 :            :         /* Zeros are removed incorrectly from the beginning of the nonces */
     461                 :            :         while (ni_len > 1 && *ni == 0) {
     462                 :            :                 ni_len--;
     463                 :            :                 ni++;
     464                 :            :         }
     465                 :            : #endif /* CCNS_PL */
     466                 :            : 
     467                 :          4 :         data->i_nonce_len = ni_len;
     468                 :          4 :         os_memcpy(data->i_nonce, ni, ni_len);
     469                 :          4 :         wpa_hexdump(MSG_MSGDUMP, "IKEV2: Ni",
     470                 :          4 :                     data->i_nonce, data->i_nonce_len);
     471                 :            : 
     472                 :          4 :         return 0;
     473                 :            : }
     474                 :            : 
     475                 :            : 
     476                 :          4 : static int ikev2_process_sa_init(struct ikev2_responder_data *data,
     477                 :            :                                  const struct ikev2_hdr *hdr,
     478                 :            :                                  struct ikev2_payloads *pl)
     479                 :            : {
     480   [ +  -  +  - ]:          8 :         if (ikev2_process_sai1(data, pl->sa, pl->sa_len) < 0 ||
     481         [ -  + ]:          8 :             ikev2_process_kei(data, pl->ke, pl->ke_len) < 0 ||
     482                 :          4 :             ikev2_process_ni(data, pl->nonce, pl->nonce_len) < 0)
     483                 :          0 :                 return -1;
     484                 :            : 
     485                 :          4 :         os_memcpy(data->i_spi, hdr->i_spi, IKEV2_SPI_LEN);
     486                 :            : 
     487                 :          4 :         return 0;
     488                 :            : }
     489                 :            : 
     490                 :            : 
     491                 :          4 : static int ikev2_process_idi(struct ikev2_responder_data *data,
     492                 :            :                              const u8 *idi, size_t idi_len)
     493                 :            : {
     494                 :            :         u8 id_type;
     495                 :            : 
     496         [ -  + ]:          4 :         if (idi == NULL) {
     497                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: No IDi received");
     498                 :          0 :                 return -1;
     499                 :            :         }
     500                 :            : 
     501         [ -  + ]:          4 :         if (idi_len < 4) {
     502                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Too short IDi payload");
     503                 :          0 :                 return -1;
     504                 :            :         }
     505                 :            : 
     506                 :          4 :         id_type = idi[0];
     507                 :          4 :         idi += 4;
     508                 :          4 :         idi_len -= 4;
     509                 :            : 
     510                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: IDi ID Type %d", id_type);
     511                 :          4 :         wpa_hexdump_ascii(MSG_DEBUG, "IKEV2: IDi", idi, idi_len);
     512                 :          4 :         os_free(data->IDi);
     513                 :          4 :         data->IDi = os_malloc(idi_len);
     514         [ -  + ]:          4 :         if (data->IDi == NULL)
     515                 :          0 :                 return -1;
     516                 :          4 :         os_memcpy(data->IDi, idi, idi_len);
     517                 :          4 :         data->IDi_len = idi_len;
     518                 :          4 :         data->IDi_type = id_type;
     519                 :            : 
     520                 :          4 :         return 0;
     521                 :            : }
     522                 :            : 
     523                 :            : 
     524                 :          4 : static int ikev2_process_cert(struct ikev2_responder_data *data,
     525                 :            :                               const u8 *cert, size_t cert_len)
     526                 :            : {
     527                 :            :         u8 cert_encoding;
     528                 :            : 
     529         [ +  - ]:          4 :         if (cert == NULL) {
     530         [ -  + ]:          4 :                 if (data->peer_auth == PEER_AUTH_CERT) {
     531                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: No Certificate received");
     532                 :          0 :                         return -1;
     533                 :            :                 }
     534                 :          4 :                 return 0;
     535                 :            :         }
     536                 :            : 
     537         [ #  # ]:          0 :         if (cert_len < 1) {
     538                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: No Cert Encoding field");
     539                 :          0 :                 return -1;
     540                 :            :         }
     541                 :            : 
     542                 :          0 :         cert_encoding = cert[0];
     543                 :          0 :         cert++;
     544                 :          0 :         cert_len--;
     545                 :            : 
     546                 :          0 :         wpa_printf(MSG_DEBUG, "IKEV2: Cert Encoding %d", cert_encoding);
     547                 :          0 :         wpa_hexdump(MSG_MSGDUMP, "IKEV2: Certificate Data", cert, cert_len);
     548                 :            : 
     549                 :            :         /* TODO: validate certificate */
     550                 :            : 
     551                 :          4 :         return 0;
     552                 :            : }
     553                 :            : 
     554                 :            : 
     555                 :          0 : static int ikev2_process_auth_cert(struct ikev2_responder_data *data,
     556                 :            :                                    u8 method, const u8 *auth, size_t auth_len)
     557                 :            : {
     558         [ #  # ]:          0 :         if (method != AUTH_RSA_SIGN) {
     559                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unsupported authentication "
     560                 :            :                            "method %d", method);
     561                 :          0 :                 return -1;
     562                 :            :         }
     563                 :            : 
     564                 :            :         /* TODO: validate AUTH */
     565                 :          0 :         return 0;
     566                 :            : }
     567                 :            : 
     568                 :            : 
     569                 :          4 : static int ikev2_process_auth_secret(struct ikev2_responder_data *data,
     570                 :            :                                      u8 method, const u8 *auth,
     571                 :            :                                      size_t auth_len)
     572                 :            : {
     573                 :            :         u8 auth_data[IKEV2_MAX_HASH_LEN];
     574                 :            :         const struct ikev2_prf_alg *prf;
     575                 :            : 
     576         [ -  + ]:          4 :         if (method != AUTH_SHARED_KEY_MIC) {
     577                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unsupported authentication "
     578                 :            :                            "method %d", method);
     579                 :          0 :                 return -1;
     580                 :            :         }
     581                 :            : 
     582                 :            :         /* msg | Nr | prf(SK_pi,IDi') */
     583         [ -  + ]:          4 :         if (ikev2_derive_auth_data(data->proposal.prf, data->i_sign_msg,
     584                 :          8 :                                    data->IDi, data->IDi_len, data->IDi_type,
     585                 :          4 :                                    &data->keys, 1, data->shared_secret,
     586                 :            :                                    data->shared_secret_len,
     587                 :          4 :                                    data->r_nonce, data->r_nonce_len,
     588                 :          4 :                                    data->key_pad, data->key_pad_len,
     589                 :            :                                    auth_data) < 0) {
     590                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Could not derive AUTH data");
     591                 :          0 :                 return -1;
     592                 :            :         }
     593                 :            : 
     594                 :          4 :         wpabuf_free(data->i_sign_msg);
     595                 :          4 :         data->i_sign_msg = NULL;
     596                 :            : 
     597                 :          4 :         prf = ikev2_get_prf(data->proposal.prf);
     598         [ -  + ]:          4 :         if (prf == NULL)
     599                 :          0 :                 return -1;
     600                 :            : 
     601 [ +  - ][ +  + ]:          4 :         if (auth_len != prf->hash_len ||
     602                 :          4 :             os_memcmp(auth, auth_data, auth_len) != 0) {
     603                 :          1 :                 wpa_printf(MSG_INFO, "IKEV2: Invalid Authentication Data");
     604                 :          1 :                 wpa_hexdump(MSG_DEBUG, "IKEV2: Received Authentication Data",
     605                 :            :                             auth, auth_len);
     606                 :          1 :                 wpa_hexdump(MSG_DEBUG, "IKEV2: Expected Authentication Data",
     607                 :            :                             auth_data, prf->hash_len);
     608                 :          1 :                 data->error_type = AUTHENTICATION_FAILED;
     609                 :          1 :                 data->state = NOTIFY;
     610                 :          1 :                 return -1;
     611                 :            :         }
     612                 :            : 
     613                 :          3 :         wpa_printf(MSG_DEBUG, "IKEV2: Server authenticated successfully "
     614                 :            :                    "using shared keys");
     615                 :            : 
     616                 :          4 :         return 0;
     617                 :            : }
     618                 :            : 
     619                 :            : 
     620                 :          4 : static int ikev2_process_auth(struct ikev2_responder_data *data,
     621                 :            :                               const u8 *auth, size_t auth_len)
     622                 :            : {
     623                 :            :         u8 auth_method;
     624                 :            : 
     625         [ -  + ]:          4 :         if (auth == NULL) {
     626                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: No Authentication Payload");
     627                 :          0 :                 return -1;
     628                 :            :         }
     629                 :            : 
     630         [ -  + ]:          4 :         if (auth_len < 4) {
     631                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Too short Authentication "
     632                 :            :                            "Payload");
     633                 :          0 :                 return -1;
     634                 :            :         }
     635                 :            : 
     636                 :          4 :         auth_method = auth[0];
     637                 :          4 :         auth += 4;
     638                 :          4 :         auth_len -= 4;
     639                 :            : 
     640                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: Auth Method %d", auth_method);
     641                 :          4 :         wpa_hexdump(MSG_MSGDUMP, "IKEV2: Authentication Data", auth, auth_len);
     642                 :            : 
     643      [ -  +  - ]:          4 :         switch (data->peer_auth) {
     644                 :            :         case PEER_AUTH_CERT:
     645                 :          0 :                 return ikev2_process_auth_cert(data, auth_method, auth,
     646                 :            :                                                auth_len);
     647                 :            :         case PEER_AUTH_SECRET:
     648                 :          4 :                 return ikev2_process_auth_secret(data, auth_method, auth,
     649                 :            :                                                  auth_len);
     650                 :            :         }
     651                 :            : 
     652                 :          4 :         return -1;
     653                 :            : }
     654                 :            : 
     655                 :            : 
     656                 :          4 : static int ikev2_process_sa_auth_decrypted(struct ikev2_responder_data *data,
     657                 :            :                                            u8 next_payload,
     658                 :            :                                            u8 *payload, size_t payload_len)
     659                 :            : {
     660                 :            :         struct ikev2_payloads pl;
     661                 :            : 
     662                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: Processing decrypted payloads");
     663                 :            : 
     664         [ -  + ]:          4 :         if (ikev2_parse_payloads(&pl, next_payload, payload, payload +
     665                 :            :                                  payload_len) < 0) {
     666                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Failed to parse decrypted "
     667                 :            :                            "payloads");
     668                 :          0 :                 return -1;
     669                 :            :         }
     670                 :            : 
     671   [ +  -  +  - ]:          8 :         if (ikev2_process_idi(data, pl.idi, pl.idi_len) < 0 ||
     672         [ +  + ]:          8 :             ikev2_process_cert(data, pl.cert, pl.cert_len) < 0 ||
     673                 :          4 :             ikev2_process_auth(data, pl.auth, pl.auth_len) < 0)
     674                 :          1 :                 return -1;
     675                 :            : 
     676                 :          4 :         return 0;
     677                 :            : }
     678                 :            : 
     679                 :            : 
     680                 :          4 : static int ikev2_process_sa_auth(struct ikev2_responder_data *data,
     681                 :            :                                  const struct ikev2_hdr *hdr,
     682                 :            :                                  struct ikev2_payloads *pl)
     683                 :            : {
     684                 :            :         u8 *decrypted;
     685                 :            :         size_t decrypted_len;
     686                 :            :         int ret;
     687                 :            : 
     688                 :          4 :         decrypted = ikev2_decrypt_payload(data->proposal.encr,
     689                 :            :                                           data->proposal.integ,
     690                 :            :                                           &data->keys, 1, hdr, pl->encrypted,
     691                 :            :                                           pl->encrypted_len, &decrypted_len);
     692         [ -  + ]:          4 :         if (decrypted == NULL)
     693                 :          0 :                 return -1;
     694                 :            : 
     695                 :          4 :         ret = ikev2_process_sa_auth_decrypted(data, pl->encr_next_payload,
     696                 :            :                                               decrypted, decrypted_len);
     697                 :          4 :         os_free(decrypted);
     698                 :            : 
     699                 :          4 :         return ret;
     700                 :            : }
     701                 :            : 
     702                 :            : 
     703                 :          8 : static int ikev2_validate_rx_state(struct ikev2_responder_data *data,
     704                 :            :                                    u8 exchange_type, u32 message_id)
     705                 :            : {
     706   [ +  +  -  -  :          8 :         switch (data->state) {
                      - ]
     707                 :            :         case SA_INIT:
     708                 :            :                 /* Expect to receive IKE_SA_INIT: HDR, SAi1, KEi, Ni */
     709         [ -  + ]:          4 :                 if (exchange_type != IKE_SA_INIT) {
     710                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected Exchange Type "
     711                 :            :                                    "%u in SA_INIT state", exchange_type);
     712                 :          0 :                         return -1;
     713                 :            :                 }
     714         [ -  + ]:          4 :                 if (message_id != 0) {
     715                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected Message ID %u "
     716                 :            :                                    "in SA_INIT state", message_id);
     717                 :          0 :                         return -1;
     718                 :            :                 }
     719                 :          4 :                 break;
     720                 :            :         case SA_AUTH:
     721                 :            :                 /* Expect to receive IKE_SA_AUTH:
     722                 :            :                  * HDR, SK {IDi, [CERT,] [CERTREQ,] [IDr,]
     723                 :            :                  *      AUTH, SAi2, TSi, TSr}
     724                 :            :                  */
     725         [ -  + ]:          4 :                 if (exchange_type != IKE_SA_AUTH) {
     726                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected Exchange Type "
     727                 :            :                                    "%u in SA_AUTH state", exchange_type);
     728                 :          0 :                         return -1;
     729                 :            :                 }
     730         [ -  + ]:          4 :                 if (message_id != 1) {
     731                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected Message ID %u "
     732                 :            :                                    "in SA_AUTH state", message_id);
     733                 :          0 :                         return -1;
     734                 :            :                 }
     735                 :          4 :                 break;
     736                 :            :         case CHILD_SA:
     737         [ #  # ]:          0 :                 if (exchange_type != CREATE_CHILD_SA) {
     738                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected Exchange Type "
     739                 :            :                                    "%u in CHILD_SA state", exchange_type);
     740                 :          0 :                         return -1;
     741                 :            :                 }
     742         [ #  # ]:          0 :                 if (message_id != 2) {
     743                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected Message ID %u "
     744                 :            :                                    "in CHILD_SA state", message_id);
     745                 :          0 :                         return -1;
     746                 :            :                 }
     747                 :          0 :                 break;
     748                 :            :         case NOTIFY:
     749                 :            :         case IKEV2_DONE:
     750                 :            :         case IKEV2_FAILED:
     751                 :          0 :                 return -1;
     752                 :            :         }
     753                 :            : 
     754                 :          8 :         return 0;
     755                 :            : }
     756                 :            : 
     757                 :            : 
     758                 :          8 : int ikev2_responder_process(struct ikev2_responder_data *data,
     759                 :            :                             const struct wpabuf *buf)
     760                 :            : {
     761                 :            :         const struct ikev2_hdr *hdr;
     762                 :            :         u32 length, message_id;
     763                 :            :         const u8 *pos, *end;
     764                 :            :         struct ikev2_payloads pl;
     765                 :            : 
     766                 :          8 :         wpa_printf(MSG_MSGDUMP, "IKEV2: Received message (len %lu)",
     767                 :            :                    (unsigned long) wpabuf_len(buf));
     768                 :            : 
     769         [ -  + ]:          8 :         if (wpabuf_len(buf) < sizeof(*hdr)) {
     770                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Too short frame to include HDR");
     771                 :          0 :                 return -1;
     772                 :            :         }
     773                 :            : 
     774                 :          8 :         data->error_type = 0;
     775                 :          8 :         hdr = (const struct ikev2_hdr *) wpabuf_head(buf);
     776                 :          8 :         end = wpabuf_head_u8(buf) + wpabuf_len(buf);
     777                 :          8 :         message_id = WPA_GET_BE32(hdr->message_id);
     778                 :          8 :         length = WPA_GET_BE32(hdr->length);
     779                 :            : 
     780                 :          8 :         wpa_hexdump(MSG_DEBUG, "IKEV2:   IKE_SA Initiator's SPI",
     781                 :          8 :                     hdr->i_spi, IKEV2_SPI_LEN);
     782                 :          8 :         wpa_hexdump(MSG_DEBUG, "IKEV2:   IKE_SA Responder's SPI",
     783                 :          8 :                     hdr->r_spi, IKEV2_SPI_LEN);
     784                 :          8 :         wpa_printf(MSG_DEBUG, "IKEV2:   Next Payload: %u  Version: 0x%x  "
     785                 :            :                    "Exchange Type: %u",
     786                 :         24 :                    hdr->next_payload, hdr->version, hdr->exchange_type);
     787                 :          8 :         wpa_printf(MSG_DEBUG, "IKEV2:   Message ID: %u  Length: %u",
     788                 :            :                    message_id, length);
     789                 :            : 
     790         [ -  + ]:          8 :         if (hdr->version != IKEV2_VERSION) {
     791                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unsupported HDR version 0x%x "
     792                 :          0 :                            "(expected 0x%x)", hdr->version, IKEV2_VERSION);
     793                 :          0 :                 return -1;
     794                 :            :         }
     795                 :            : 
     796         [ -  + ]:          8 :         if (length != wpabuf_len(buf)) {
     797                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Invalid length (HDR: %lu != "
     798                 :            :                            "RX: %lu)", (unsigned long) length,
     799                 :            :                            (unsigned long) wpabuf_len(buf));
     800                 :          0 :                 return -1;
     801                 :            :         }
     802                 :            : 
     803         [ -  + ]:          8 :         if (ikev2_validate_rx_state(data, hdr->exchange_type, message_id) < 0)
     804                 :          0 :                 return -1;
     805                 :            : 
     806         [ -  + ]:          8 :         if ((hdr->flags & (IKEV2_HDR_INITIATOR | IKEV2_HDR_RESPONSE)) !=
     807                 :            :             IKEV2_HDR_INITIATOR) {
     808                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unexpected Flags value 0x%x",
     809                 :          0 :                            hdr->flags);
     810                 :          0 :                 return -1;
     811                 :            :         }
     812                 :            : 
     813         [ +  + ]:          8 :         if (data->state != SA_INIT) {
     814         [ -  + ]:          4 :                 if (os_memcmp(data->i_spi, hdr->i_spi, IKEV2_SPI_LEN) != 0) {
     815                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected IKE_SA "
     816                 :            :                                    "Initiator's SPI");
     817                 :          0 :                         return -1;
     818                 :            :                 }
     819         [ -  + ]:          4 :                 if (os_memcmp(data->r_spi, hdr->r_spi, IKEV2_SPI_LEN) != 0) {
     820                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: Unexpected IKE_SA "
     821                 :            :                                    "Responder's SPI");
     822                 :          0 :                         return -1;
     823                 :            :                 }
     824                 :            :         }
     825                 :            : 
     826                 :          8 :         pos = (const u8 *) (hdr + 1);
     827         [ -  + ]:          8 :         if (ikev2_parse_payloads(&pl, hdr->next_payload, pos, end) < 0)
     828                 :          0 :                 return -1;
     829                 :            : 
     830         [ +  + ]:          8 :         if (data->state == SA_INIT) {
     831                 :          4 :                 data->last_msg = LAST_MSG_SA_INIT;
     832         [ -  + ]:          4 :                 if (ikev2_process_sa_init(data, hdr, &pl) < 0) {
     833         [ #  # ]:          0 :                         if (data->state == NOTIFY)
     834                 :          0 :                                 return 0;
     835                 :          0 :                         return -1;
     836                 :            :                 }
     837                 :          4 :                 wpabuf_free(data->i_sign_msg);
     838                 :          4 :                 data->i_sign_msg = wpabuf_dup(buf);
     839                 :            :         }
     840                 :            : 
     841         [ +  + ]:          8 :         if (data->state == SA_AUTH) {
     842                 :          4 :                 data->last_msg = LAST_MSG_SA_AUTH;
     843         [ +  + ]:          4 :                 if (ikev2_process_sa_auth(data, hdr, &pl) < 0) {
     844         [ +  - ]:          1 :                         if (data->state == NOTIFY)
     845                 :          1 :                                 return 0;
     846                 :          0 :                         return -1;
     847                 :            :                 }
     848                 :            :         }
     849                 :            : 
     850                 :          8 :         return 0;
     851                 :            : }
     852                 :            : 
     853                 :            : 
     854                 :          8 : static void ikev2_build_hdr(struct ikev2_responder_data *data,
     855                 :            :                             struct wpabuf *msg, u8 exchange_type,
     856                 :            :                             u8 next_payload, u32 message_id)
     857                 :            : {
     858                 :            :         struct ikev2_hdr *hdr;
     859                 :            : 
     860                 :          8 :         wpa_printf(MSG_DEBUG, "IKEV2: Adding HDR");
     861                 :            : 
     862                 :            :         /* HDR - RFC 4306, Sect. 3.1 */
     863                 :          8 :         hdr = wpabuf_put(msg, sizeof(*hdr));
     864                 :          8 :         os_memcpy(hdr->i_spi, data->i_spi, IKEV2_SPI_LEN);
     865                 :          8 :         os_memcpy(hdr->r_spi, data->r_spi, IKEV2_SPI_LEN);
     866                 :          8 :         hdr->next_payload = next_payload;
     867                 :          8 :         hdr->version = IKEV2_VERSION;
     868                 :          8 :         hdr->exchange_type = exchange_type;
     869                 :          8 :         hdr->flags = IKEV2_HDR_RESPONSE;
     870                 :          8 :         WPA_PUT_BE32(hdr->message_id, message_id);
     871                 :          8 : }
     872                 :            : 
     873                 :            : 
     874                 :          4 : static int ikev2_build_sar1(struct ikev2_responder_data *data,
     875                 :            :                             struct wpabuf *msg, u8 next_payload)
     876                 :            : {
     877                 :            :         struct ikev2_payload_hdr *phdr;
     878                 :            :         size_t plen;
     879                 :            :         struct ikev2_proposal *p;
     880                 :            :         struct ikev2_transform *t;
     881                 :            : 
     882                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: Adding SAr1 payload");
     883                 :            : 
     884                 :            :         /* SAr1 - RFC 4306, Sect. 2.7 and 3.3 */
     885                 :          4 :         phdr = wpabuf_put(msg, sizeof(*phdr));
     886                 :          4 :         phdr->next_payload = next_payload;
     887                 :          4 :         phdr->flags = 0;
     888                 :            : 
     889                 :          4 :         p = wpabuf_put(msg, sizeof(*p));
     890                 :            : #ifdef CCNS_PL
     891                 :            :         /* Seems to require that the Proposal # is 1 even though RFC 4306
     892                 :            :          * Sect 3.3.1 has following requirement "When a proposal is accepted,
     893                 :            :          * all of the proposal numbers in the SA payload MUST be the same and
     894                 :            :          * MUST match the number on the proposal sent that was accepted.".
     895                 :            :          */
     896                 :            :         p->proposal_num = 1;
     897                 :            : #else /* CCNS_PL */
     898                 :          4 :         p->proposal_num = data->proposal.proposal_num;
     899                 :            : #endif /* CCNS_PL */
     900                 :          4 :         p->protocol_id = IKEV2_PROTOCOL_IKE;
     901                 :          4 :         p->num_transforms = 4;
     902                 :            : 
     903                 :          4 :         t = wpabuf_put(msg, sizeof(*t));
     904                 :          4 :         t->type = 3;
     905                 :          4 :         t->transform_type = IKEV2_TRANSFORM_ENCR;
     906                 :          4 :         WPA_PUT_BE16(t->transform_id, data->proposal.encr);
     907         [ +  - ]:          4 :         if (data->proposal.encr == ENCR_AES_CBC) {
     908                 :            :                 /* Transform Attribute: Key Len = 128 bits */
     909                 :            : #ifdef CCNS_PL
     910                 :            :                 wpabuf_put_be16(msg, 0x001d); /* ?? */
     911                 :            : #else /* CCNS_PL */
     912                 :          4 :                 wpabuf_put_be16(msg, 0x800e); /* AF=1, AttrType=14 */
     913                 :            : #endif /* CCNS_PL */
     914                 :          4 :                 wpabuf_put_be16(msg, 128); /* 128-bit key */
     915                 :            :         }
     916                 :          4 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) t;
     917                 :          4 :         WPA_PUT_BE16(t->transform_length, plen);
     918                 :            : 
     919                 :          4 :         t = wpabuf_put(msg, sizeof(*t));
     920                 :          4 :         t->type = 3;
     921                 :          4 :         WPA_PUT_BE16(t->transform_length, sizeof(*t));
     922                 :          4 :         t->transform_type = IKEV2_TRANSFORM_PRF;
     923                 :          4 :         WPA_PUT_BE16(t->transform_id, data->proposal.prf);
     924                 :            : 
     925                 :          4 :         t = wpabuf_put(msg, sizeof(*t));
     926                 :          4 :         t->type = 3;
     927                 :          4 :         WPA_PUT_BE16(t->transform_length, sizeof(*t));
     928                 :          4 :         t->transform_type = IKEV2_TRANSFORM_INTEG;
     929                 :          4 :         WPA_PUT_BE16(t->transform_id, data->proposal.integ);
     930                 :            : 
     931                 :          4 :         t = wpabuf_put(msg, sizeof(*t));
     932                 :          4 :         WPA_PUT_BE16(t->transform_length, sizeof(*t));
     933                 :          4 :         t->transform_type = IKEV2_TRANSFORM_DH;
     934                 :          4 :         WPA_PUT_BE16(t->transform_id, data->proposal.dh);
     935                 :            : 
     936                 :          4 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) p;
     937                 :          4 :         WPA_PUT_BE16(p->proposal_length, plen);
     938                 :            : 
     939                 :          4 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) phdr;
     940                 :          4 :         WPA_PUT_BE16(phdr->payload_length, plen);
     941                 :            : 
     942                 :          4 :         return 0;
     943                 :            : }
     944                 :            : 
     945                 :            : 
     946                 :          4 : static int ikev2_build_ker(struct ikev2_responder_data *data,
     947                 :            :                            struct wpabuf *msg, u8 next_payload)
     948                 :            : {
     949                 :            :         struct ikev2_payload_hdr *phdr;
     950                 :            :         size_t plen;
     951                 :            :         struct wpabuf *pv;
     952                 :            : 
     953                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: Adding KEr payload");
     954                 :            : 
     955                 :          4 :         pv = dh_init(data->dh, &data->r_dh_private);
     956         [ -  + ]:          4 :         if (pv == NULL) {
     957                 :          0 :                 wpa_printf(MSG_DEBUG, "IKEV2: Failed to initialize DH");
     958                 :          0 :                 return -1;
     959                 :            :         }
     960                 :            : 
     961                 :            :         /* KEr - RFC 4306, Sect. 3.4 */
     962                 :          4 :         phdr = wpabuf_put(msg, sizeof(*phdr));
     963                 :          4 :         phdr->next_payload = next_payload;
     964                 :          4 :         phdr->flags = 0;
     965                 :            : 
     966                 :          4 :         wpabuf_put_be16(msg, data->proposal.dh); /* DH Group # */
     967                 :          4 :         wpabuf_put(msg, 2); /* RESERVED */
     968                 :            :         /*
     969                 :            :          * RFC 4306, Sect. 3.4: possible zero padding for public value to
     970                 :            :          * match the length of the prime.
     971                 :            :          */
     972                 :          4 :         wpabuf_put(msg, data->dh->prime_len - wpabuf_len(pv));
     973                 :          4 :         wpabuf_put_buf(msg, pv);
     974                 :          4 :         wpabuf_free(pv);
     975                 :            : 
     976                 :          4 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) phdr;
     977                 :          4 :         WPA_PUT_BE16(phdr->payload_length, plen);
     978                 :          4 :         return 0;
     979                 :            : }
     980                 :            : 
     981                 :            : 
     982                 :          4 : static int ikev2_build_nr(struct ikev2_responder_data *data,
     983                 :            :                           struct wpabuf *msg, u8 next_payload)
     984                 :            : {
     985                 :            :         struct ikev2_payload_hdr *phdr;
     986                 :            :         size_t plen;
     987                 :            : 
     988                 :          4 :         wpa_printf(MSG_DEBUG, "IKEV2: Adding Nr payload");
     989                 :            : 
     990                 :            :         /* Nr - RFC 4306, Sect. 3.9 */
     991                 :          4 :         phdr = wpabuf_put(msg, sizeof(*phdr));
     992                 :          4 :         phdr->next_payload = next_payload;
     993                 :          4 :         phdr->flags = 0;
     994                 :          4 :         wpabuf_put_data(msg, data->r_nonce, data->r_nonce_len);
     995                 :          4 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) phdr;
     996                 :          4 :         WPA_PUT_BE16(phdr->payload_length, plen);
     997                 :          4 :         return 0;
     998                 :            : }
     999                 :            : 
    1000                 :            : 
    1001                 :          7 : static int ikev2_build_idr(struct ikev2_responder_data *data,
    1002                 :            :                            struct wpabuf *msg, u8 next_payload)
    1003                 :            : {
    1004                 :            :         struct ikev2_payload_hdr *phdr;
    1005                 :            :         size_t plen;
    1006                 :            : 
    1007                 :          7 :         wpa_printf(MSG_DEBUG, "IKEV2: Adding IDr payload");
    1008                 :            : 
    1009         [ -  + ]:          7 :         if (data->IDr == NULL) {
    1010                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: No IDr available");
    1011                 :          0 :                 return -1;
    1012                 :            :         }
    1013                 :            : 
    1014                 :            :         /* IDr - RFC 4306, Sect. 3.5 */
    1015                 :          7 :         phdr = wpabuf_put(msg, sizeof(*phdr));
    1016                 :          7 :         phdr->next_payload = next_payload;
    1017                 :          7 :         phdr->flags = 0;
    1018                 :          7 :         wpabuf_put_u8(msg, ID_KEY_ID);
    1019                 :          7 :         wpabuf_put(msg, 3); /* RESERVED */
    1020                 :          7 :         wpabuf_put_data(msg, data->IDr, data->IDr_len);
    1021                 :          7 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) phdr;
    1022                 :          7 :         WPA_PUT_BE16(phdr->payload_length, plen);
    1023                 :          7 :         return 0;
    1024                 :            : }
    1025                 :            : 
    1026                 :            : 
    1027                 :          3 : static int ikev2_build_auth(struct ikev2_responder_data *data,
    1028                 :            :                             struct wpabuf *msg, u8 next_payload)
    1029                 :            : {
    1030                 :            :         struct ikev2_payload_hdr *phdr;
    1031                 :            :         size_t plen;
    1032                 :            :         const struct ikev2_prf_alg *prf;
    1033                 :            : 
    1034                 :          3 :         wpa_printf(MSG_DEBUG, "IKEV2: Adding AUTH payload");
    1035                 :            : 
    1036                 :          3 :         prf = ikev2_get_prf(data->proposal.prf);
    1037         [ -  + ]:          3 :         if (prf == NULL)
    1038                 :          0 :                 return -1;
    1039                 :            : 
    1040                 :            :         /* Authentication - RFC 4306, Sect. 3.8 */
    1041                 :          3 :         phdr = wpabuf_put(msg, sizeof(*phdr));
    1042                 :          3 :         phdr->next_payload = next_payload;
    1043                 :          3 :         phdr->flags = 0;
    1044                 :          3 :         wpabuf_put_u8(msg, AUTH_SHARED_KEY_MIC);
    1045                 :          3 :         wpabuf_put(msg, 3); /* RESERVED */
    1046                 :            : 
    1047                 :            :         /* msg | Ni | prf(SK_pr,IDr') */
    1048         [ -  + ]:          3 :         if (ikev2_derive_auth_data(data->proposal.prf, data->r_sign_msg,
    1049                 :          3 :                                    data->IDr, data->IDr_len, ID_KEY_ID,
    1050                 :          3 :                                    &data->keys, 0, data->shared_secret,
    1051                 :            :                                    data->shared_secret_len,
    1052                 :          3 :                                    data->i_nonce, data->i_nonce_len,
    1053                 :          3 :                                    data->key_pad, data->key_pad_len,
    1054                 :          3 :                                    wpabuf_put(msg, prf->hash_len)) < 0) {
    1055                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Could not derive AUTH data");
    1056                 :          0 :                 return -1;
    1057                 :            :         }
    1058                 :          3 :         wpabuf_free(data->r_sign_msg);
    1059                 :          3 :         data->r_sign_msg = NULL;
    1060                 :            : 
    1061                 :          3 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) phdr;
    1062                 :          3 :         WPA_PUT_BE16(phdr->payload_length, plen);
    1063                 :          3 :         return 0;
    1064                 :            : }
    1065                 :            : 
    1066                 :            : 
    1067                 :          1 : static int ikev2_build_notification(struct ikev2_responder_data *data,
    1068                 :            :                                     struct wpabuf *msg, u8 next_payload)
    1069                 :            : {
    1070                 :            :         struct ikev2_payload_hdr *phdr;
    1071                 :            :         size_t plen;
    1072                 :            : 
    1073                 :          1 :         wpa_printf(MSG_DEBUG, "IKEV2: Adding Notification payload");
    1074                 :            : 
    1075         [ -  + ]:          1 :         if (data->error_type == 0) {
    1076                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: No Notify Message Type "
    1077                 :            :                            "available");
    1078                 :          0 :                 return -1;
    1079                 :            :         }
    1080                 :            : 
    1081                 :            :         /* Notify - RFC 4306, Sect. 3.10 */
    1082                 :          1 :         phdr = wpabuf_put(msg, sizeof(*phdr));
    1083                 :          1 :         phdr->next_payload = next_payload;
    1084                 :          1 :         phdr->flags = 0;
    1085                 :            : #ifdef CCNS_PL
    1086                 :            :         wpabuf_put_u8(msg, 1); /* Protocol ID: IKE_SA notification */
    1087                 :            : #else /* CCNS_PL */
    1088                 :          1 :         wpabuf_put_u8(msg, 0); /* Protocol ID: no existing SA */
    1089                 :            : #endif /* CCNS_PL */
    1090                 :          1 :         wpabuf_put_u8(msg, 0); /* SPI Size */
    1091                 :          1 :         wpabuf_put_be16(msg, data->error_type);
    1092                 :            : 
    1093      [ -  +  - ]:          1 :         switch (data->error_type) {
    1094                 :            :         case INVALID_KE_PAYLOAD:
    1095         [ #  # ]:          0 :                 if (data->proposal.dh == -1) {
    1096                 :          0 :                         wpa_printf(MSG_INFO, "IKEV2: No DH Group selected for "
    1097                 :            :                                    "INVALID_KE_PAYLOAD notifications");
    1098                 :          0 :                         return -1;
    1099                 :            :                 }
    1100                 :          0 :                 wpabuf_put_be16(msg, data->proposal.dh);
    1101                 :          0 :                 wpa_printf(MSG_DEBUG, "IKEV2: INVALID_KE_PAYLOAD - request "
    1102                 :            :                            "DH Group #%d", data->proposal.dh);
    1103                 :          0 :                 break;
    1104                 :            :         case AUTHENTICATION_FAILED:
    1105                 :            :                 /* no associated data */
    1106                 :          1 :                 break;
    1107                 :            :         default:
    1108                 :          0 :                 wpa_printf(MSG_INFO, "IKEV2: Unsupported Notify Message Type "
    1109                 :          0 :                            "%d", data->error_type);
    1110                 :          0 :                 return -1;
    1111                 :            :         }
    1112                 :            : 
    1113                 :          1 :         plen = (u8 *) wpabuf_put(msg, 0) - (u8 *) phdr;
    1114                 :          1 :         WPA_PUT_BE16(phdr->payload_length, plen);
    1115                 :          1 :         return 0;
    1116                 :            : }
    1117                 :            : 
    1118                 :            : 
    1119                 :          4 : static struct wpabuf * ikev2_build_sa_init(struct ikev2_responder_data *data)
    1120                 :            : {
    1121                 :            :         struct wpabuf *msg;
    1122                 :            : 
    1123                 :            :         /* build IKE_SA_INIT: HDR, SAr1, KEr, Nr, [CERTREQ], [SK{IDr}] */
    1124                 :            : 
    1125         [ -  + ]:          4 :         if (os_get_random(data->r_spi, IKEV2_SPI_LEN))
    1126                 :          0 :                 return NULL;
    1127                 :          4 :         wpa_hexdump(MSG_DEBUG, "IKEV2: IKE_SA Responder's SPI",
    1128                 :          4 :                     data->r_spi, IKEV2_SPI_LEN);
    1129                 :            : 
    1130                 :          4 :         data->r_nonce_len = IKEV2_NONCE_MIN_LEN;
    1131         [ -  + ]:          4 :         if (random_get_bytes(data->r_nonce, data->r_nonce_len))
    1132                 :          0 :                 return NULL;
    1133                 :            : #ifdef CCNS_PL
    1134                 :            :         /* Zeros are removed incorrectly from the beginning of the nonces in
    1135                 :            :          * key derivation; as a workaround, make sure Nr does not start with
    1136                 :            :          * zero.. */
    1137                 :            :         if (data->r_nonce[0] == 0)
    1138                 :            :                 data->r_nonce[0] = 1;
    1139                 :            : #endif /* CCNS_PL */
    1140                 :          4 :         wpa_hexdump(MSG_DEBUG, "IKEV2: Nr", data->r_nonce, data->r_nonce_len);
    1141                 :            : 
    1142                 :          4 :         msg = wpabuf_alloc(sizeof(struct ikev2_hdr) + data->IDr_len + 1500);
    1143         [ -  + ]:          4 :         if (msg == NULL)
    1144                 :          0 :                 return NULL;
    1145                 :            : 
    1146                 :          4 :         ikev2_build_hdr(data, msg, IKE_SA_INIT, IKEV2_PAYLOAD_SA, 0);
    1147   [ +  -  +  - ]:          8 :         if (ikev2_build_sar1(data, msg, IKEV2_PAYLOAD_KEY_EXCHANGE) ||
    1148         [ -  + ]:          8 :             ikev2_build_ker(data, msg, IKEV2_PAYLOAD_NONCE) ||
    1149         [ +  - ]:          4 :             ikev2_build_nr(data, msg, data->peer_auth == PEER_AUTH_SECRET ?
    1150                 :            :                            IKEV2_PAYLOAD_ENCRYPTED :
    1151                 :            :                            IKEV2_PAYLOAD_NO_NEXT_PAYLOAD)) {
    1152                 :          0 :                 wpabuf_free(msg);
    1153                 :          0 :                 return NULL;
    1154                 :            :         }
    1155                 :            : 
    1156         [ -  + ]:          4 :         if (ikev2_derive_keys(data)) {
    1157                 :          0 :                 wpabuf_free(msg);
    1158                 :          0 :                 return NULL;
    1159                 :            :         }
    1160                 :            : 
    1161                 :          4 :         if (data->peer_auth == PEER_AUTH_CERT) {
    1162                 :            :                 /* TODO: CERTREQ with SHA-1 hashes of Subject Public Key Info
    1163                 :            :                  * for trust agents */
    1164                 :            :         }
    1165                 :            : 
    1166         [ +  - ]:          4 :         if (data->peer_auth == PEER_AUTH_SECRET) {
    1167                 :          4 :                 struct wpabuf *plain = wpabuf_alloc(data->IDr_len + 1000);
    1168         [ -  + ]:          4 :                 if (plain == NULL) {
    1169                 :          0 :                         wpabuf_free(msg);
    1170                 :          0 :                         return NULL;
    1171                 :            :                 }
    1172         [ +  - ]:          4 :                 if (ikev2_build_idr(data, plain,
    1173         [ -  + ]:          4 :                                     IKEV2_PAYLOAD_NO_NEXT_PAYLOAD) ||
    1174                 :          4 :                     ikev2_build_encrypted(data->proposal.encr,
    1175                 :            :                                           data->proposal.integ,
    1176                 :            :                                           &data->keys, 0, msg, plain,
    1177                 :            :                                           IKEV2_PAYLOAD_IDr)) {
    1178                 :          0 :                         wpabuf_free(plain);
    1179                 :          0 :                         wpabuf_free(msg);
    1180                 :          0 :                         return NULL;
    1181                 :            :                 }
    1182                 :          4 :                 wpabuf_free(plain);
    1183                 :            :         }
    1184                 :            : 
    1185                 :          4 :         ikev2_update_hdr(msg);
    1186                 :            : 
    1187                 :          4 :         wpa_hexdump_buf(MSG_MSGDUMP, "IKEV2: Sending message (SA_INIT)", msg);
    1188                 :            : 
    1189                 :          4 :         data->state = SA_AUTH;
    1190                 :            : 
    1191                 :          4 :         wpabuf_free(data->r_sign_msg);
    1192                 :          4 :         data->r_sign_msg = wpabuf_dup(msg);
    1193                 :            : 
    1194                 :          4 :         return msg;
    1195                 :            : }
    1196                 :            : 
    1197                 :            : 
    1198                 :          3 : static struct wpabuf * ikev2_build_sa_auth(struct ikev2_responder_data *data)
    1199                 :            : {
    1200                 :            :         struct wpabuf *msg, *plain;
    1201                 :            : 
    1202                 :            :         /* build IKE_SA_AUTH: HDR, SK {IDr, [CERT,] AUTH} */
    1203                 :            : 
    1204                 :          3 :         msg = wpabuf_alloc(sizeof(struct ikev2_hdr) + data->IDr_len + 1000);
    1205         [ -  + ]:          3 :         if (msg == NULL)
    1206                 :          0 :                 return NULL;
    1207                 :          3 :         ikev2_build_hdr(data, msg, IKE_SA_AUTH, IKEV2_PAYLOAD_ENCRYPTED, 1);
    1208                 :            : 
    1209                 :          3 :         plain = wpabuf_alloc(data->IDr_len + 1000);
    1210         [ -  + ]:          3 :         if (plain == NULL) {
    1211                 :          0 :                 wpabuf_free(msg);
    1212                 :          0 :                 return NULL;
    1213                 :            :         }
    1214                 :            : 
    1215   [ +  -  +  - ]:          6 :         if (ikev2_build_idr(data, plain, IKEV2_PAYLOAD_AUTHENTICATION) ||
    1216         [ -  + ]:          6 :             ikev2_build_auth(data, plain, IKEV2_PAYLOAD_NO_NEXT_PAYLOAD) ||
    1217                 :          3 :             ikev2_build_encrypted(data->proposal.encr, data->proposal.integ,
    1218                 :            :                                   &data->keys, 0, msg, plain,
    1219                 :            :                                   IKEV2_PAYLOAD_IDr)) {
    1220                 :          0 :                 wpabuf_free(plain);
    1221                 :          0 :                 wpabuf_free(msg);
    1222                 :          0 :                 return NULL;
    1223                 :            :         }
    1224                 :          3 :         wpabuf_free(plain);
    1225                 :            : 
    1226                 :          3 :         wpa_hexdump_buf(MSG_MSGDUMP, "IKEV2: Sending message (SA_AUTH)", msg);
    1227                 :            : 
    1228                 :          3 :         data->state = IKEV2_DONE;
    1229                 :            : 
    1230                 :          3 :         return msg;
    1231                 :            : }
    1232                 :            : 
    1233                 :            : 
    1234                 :          1 : static struct wpabuf * ikev2_build_notify(struct ikev2_responder_data *data)
    1235                 :            : {
    1236                 :            :         struct wpabuf *msg;
    1237                 :            : 
    1238                 :          1 :         msg = wpabuf_alloc(sizeof(struct ikev2_hdr) + 1000);
    1239         [ -  + ]:          1 :         if (msg == NULL)
    1240                 :          0 :                 return NULL;
    1241         [ +  - ]:          1 :         if (data->last_msg == LAST_MSG_SA_AUTH) {
    1242                 :            :                 /* HDR, SK{N} */
    1243                 :          1 :                 struct wpabuf *plain = wpabuf_alloc(100);
    1244         [ -  + ]:          1 :                 if (plain == NULL) {
    1245                 :          0 :                         wpabuf_free(msg);
    1246                 :          0 :                         return NULL;
    1247                 :            :                 }
    1248                 :          1 :                 ikev2_build_hdr(data, msg, IKE_SA_AUTH,
    1249                 :            :                                 IKEV2_PAYLOAD_ENCRYPTED, 1);
    1250         [ +  - ]:          1 :                 if (ikev2_build_notification(data, plain,
    1251         [ -  + ]:          1 :                                              IKEV2_PAYLOAD_NO_NEXT_PAYLOAD) ||
    1252                 :          1 :                     ikev2_build_encrypted(data->proposal.encr,
    1253                 :            :                                           data->proposal.integ,
    1254                 :            :                                           &data->keys, 0, msg, plain,
    1255                 :            :                                           IKEV2_PAYLOAD_NOTIFICATION)) {
    1256                 :          0 :                         wpabuf_free(plain);
    1257                 :          0 :                         wpabuf_free(msg);
    1258                 :          0 :                         return NULL;
    1259                 :            :                 }
    1260                 :          1 :                 wpabuf_free(plain);
    1261                 :          1 :                 data->state = IKEV2_FAILED;
    1262                 :            :         } else {
    1263                 :            :                 /* HDR, N */
    1264                 :          0 :                 ikev2_build_hdr(data, msg, IKE_SA_INIT,
    1265                 :            :                                 IKEV2_PAYLOAD_NOTIFICATION, 0);
    1266         [ #  # ]:          0 :                 if (ikev2_build_notification(data, msg,
    1267                 :            :                                              IKEV2_PAYLOAD_NO_NEXT_PAYLOAD)) {
    1268                 :          0 :                         wpabuf_free(msg);
    1269                 :          0 :                         return NULL;
    1270                 :            :                 }
    1271                 :          0 :                 data->state = SA_INIT;
    1272                 :            :         }
    1273                 :            : 
    1274                 :          1 :         ikev2_update_hdr(msg);
    1275                 :            : 
    1276                 :          1 :         wpa_hexdump_buf(MSG_MSGDUMP, "IKEV2: Sending message (Notification)",
    1277                 :            :                         msg);
    1278                 :            : 
    1279                 :          1 :         return msg;
    1280                 :            : }
    1281                 :            : 
    1282                 :            : 
    1283                 :          8 : struct wpabuf * ikev2_responder_build(struct ikev2_responder_data *data)
    1284                 :            : {
    1285   [ +  +  -  +  :          8 :         switch (data->state) {
                   -  - ]
    1286                 :            :         case SA_INIT:
    1287                 :          4 :                 return ikev2_build_sa_init(data);
    1288                 :            :         case SA_AUTH:
    1289                 :          3 :                 return ikev2_build_sa_auth(data);
    1290                 :            :         case CHILD_SA:
    1291                 :          0 :                 return NULL;
    1292                 :            :         case NOTIFY:
    1293                 :          1 :                 return ikev2_build_notify(data);
    1294                 :            :         case IKEV2_DONE:
    1295                 :            :         case IKEV2_FAILED:
    1296                 :          0 :                 return NULL;
    1297                 :            :         }
    1298                 :          8 :         return NULL;
    1299                 :            : }

Generated by: LCOV version 1.9