Text   |  XML   |  ReML   |   Visible Warnings:

Redundant Condition  at airpdcap.c:386

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

AirPDcapDecryptWPABroadcastKey

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/crypt/airpdcap.c)expand/collapse
Show more  
 337  AirPDcapDecryptWPABroadcastKey(P_EAPOL_RSN_KEY pEAPKey, guint8  *decryption_key, PAIRPDCAP_SEC_ASSOCIATION sa)
 338  {
 339          guint8  new_key[32];
 340          guint8 key_version;
 341          guint8  *szEncryptedKey;
 342          guint16 key_len = 0;
 343          static AIRPDCAP_KEY_ITEM dummy_key; /* needed in case AirPDcapRsnaMng() wants the key structure */
 344   
 345          /* We skip verifying the MIC of the key. If we were implementing a WPA supplicant we'd want to verify, but for a sniffer it's not needed. */
 346   
 347          /* Preparation for decrypting the group key -  determine group key data length */
 348          /* depending on whether it's a TKIP or AES encryption key */
 349          key_version = AIRPDCAP_EAP_KEY_DESCR_VER(pEAPKey->key_information[1]);
 350          if (key_version == AIRPDCAP_WPA_KEY_VER_NOT_CCMP){
 351                  /* TKIP */
 352                  key_len = pntohs(pEAPKey->key_length);
 353          }else if (key_version == AIRPDCAP_WPA_KEY_VER_AES_CCMP){
 354                  /* AES */
 355                  key_len = pntohs(pEAPKey->key_data_len);
 356          }
 357      if (key_len > sizeof(RSN_IE) || key_len == 0) { /* Don't read past the end of pEAPKey->ie */
 358          return;
 359      }
 360   
 361          /* Encrypted key is in the information element field of the EAPOL key packet */
 362          szEncryptedKey = g_memdup(pEAPKey->ie, key_len);
 363   
 364          DEBUG_DUMP("Encrypted Broadcast key:", szEncryptedKey, key_len);
 365          DEBUG_DUMP("KeyIV:", pEAPKey->key_iv, 16);
 366          DEBUG_DUMP("decryption_key:", decryption_key, 16);
 367   
 368          /* Build the full decryption key based on the IV and part of the pairwise key */
 369          memcpy(new_key, pEAPKey->key_iv, 16);
 370          memcpy(new_key+16, decryption_key, 16);
 371          DEBUG_DUMP("FullDecrKey:", new_key, 32);
 372   
 373          if (key_version == AIRPDCAP_WPA_KEY_VER_NOT_CCMP){
 374                  guint8 dummy[256];
 375                  /* TKIP key */
 376                  /* Per 802.11i, Draft 3.0 spec, section 8.5.2, p. 97, line 4-8, */
 377                  /* group key is decrypted using RC4.  Concatenate the IV with the 16 byte EK (PTK+16) to get the decryption key */
 378   
 379                  rc4_state_struct rc4_state;
 380                  crypt_rc4_init(&rc4_state, new_key, sizeof(new_key));
 381   
 382                  /* Do dummy 256 iterations of the RC4 algorithm (per 802.11i, Draft 3.0, p. 97 line 6) */
 383                  crypt_rc4(&rc4_state, dummy, 256);
 384                  crypt_rc4(&rc4_state, szEncryptedKey, key_len);
 385   
 386          } else if (key_version == AIRPDCAP_WPA_KEY_VER_AES_CCMP){
 387                  /* AES CCMP key */
 388   
 389                  guint8 key_found;
 390                  guint16 key_index;
 391                  guint8 *decrypted_data;
 392   
 393                  /* This storage is needed for the AES_unwrap function */
 394                  decrypted_data = (guint8 *) g_malloc(key_len);
 395   
 396                  AES_unwrap(decryption_key, 16, szEncryptedKey,  key_len, decrypted_data);
 397   
 398                  /* With WPA2 what we get after Broadcast Key decryption is an actual RSN structure.
 399                     The key itself is stored as a GTK KDE
 400                     WPA2 IE (1 byte) id = 0xdd, length (1 byte), GTK OUI (4 bytes), key index (1 byte) and 1 reserved byte. Thus we have to
 401                     pass pointer to the actual key with 8 bytes offset */
 402   
 403                  key_found = FALSE;
 404                  key_index = 0;
 405                  while(key_index < key_len && !key_found){
 406                          guint8 rsn_id;
 407   
 408                          /* Get RSN ID */
 409                          rsn_id = decrypted_data[key_index];
 410   
 411                          if (rsn_id != 0xdd){
 412                                  key_index += decrypted_data[key_index+1]+2;
 413                          }else{
 414                                  key_found = TRUE;
 415                          }
 416                  }
 417   
 418                  if (key_found){
 419                          /* Skip over the GTK header info, and don't copy past the end of the encrypted data */
 420                          memcpy(szEncryptedKey, decrypted_data+key_index+8, key_len-key_index-8);
 421                  }
 422   
 423                  g_free(decrypted_data);
 424          }
 425   
 426          /* Decrypted key is now in szEncryptedKey with len of key_len */
 427          DEBUG_DUMP("Broadcast key:", szEncryptedKey, key_len);
 428   
 429          /* Load the proper key material info into the SA */
 430          sa->key = &dummy_key;  /* we just need key to be not null because it is checked in AirPDcapRsnaMng().  The WPA key materials are actually in the .wpa structure */
 431          sa->validKey = TRUE;
 432          sa->wpa.key_ver = key_version;
 433   
 434          /* Since this is a GTK and it's size is only 32 bytes (vs. the 64 byte size of a PTK), we fake it and put it in at a 32-byte offset so the  */
 435          /* AirPDcapRsnaMng() function will extract the right piece of the GTK for decryption. (The first 16 bytes of the GTK are used for decryption.) */
 436          memset(sa->wpa.ptk, 0, sizeof(sa->wpa.ptk));
 437          memcpy(sa->wpa.ptk+32, szEncryptedKey, key_len);
 438          g_free(szEncryptedKey);
 439  }
Show more  




Change Warning 1096.29916 : Redundant Condition

Priority:
State:
Finding:
Owner:
Note: