Changeset 1357

Show
Ignore:
Timestamp:
12/14/05 11:36:27 (6 years ago)
Author:
mrenzmann
Message:

As reported by Jouni Malinen in #132, MadWifi reported only one IE
even if the AP announced both WPA IE (WPA) and RSN IE (WPA2). In
such cases MadWifi preferred WPA2, which prevents the userspace
supplicant from being able to do proper downgrade attack protection
and restricts configuration options for the user.

This is now fixed by saving and reporting both IEs if
necessary.

Signed-off-by: Charles Bovy <charles@bovy.nl>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/net80211/ieee80211_input.c

    r1336 r1357  
    16411641static int 
    16421642ieee80211_parse_wpa(struct ieee80211vap *vap, u_int8_t *frm, 
    1643         struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh) 
     1643        struct ieee80211_rsnparms *rsn_parm, const struct ieee80211_frame *wh) 
    16441644{ 
    16451645        u_int8_t len = frm[1]; 
     
    16771677 
    16781678        /* multicast/group cipher */ 
    1679         w = wpa_cipher(frm, &rsn->rsn_mcastkeylen); 
    1680         if (w != rsn->rsn_mcastcipher) { 
     1679        w = wpa_cipher(frm, &rsn_parm->rsn_mcastkeylen); 
     1680        if (w != rsn_parm->rsn_mcastcipher) { 
    16811681                IEEE80211_DISCARD_IE(vap, 
    16821682                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
    16831683                    wh, "WPA", "mcast cipher mismatch; got %u, expected %u", 
    1684                     w, rsn->rsn_mcastcipher); 
     1684                    w, rsn_parm->rsn_mcastcipher); 
    16851685                return IEEE80211_REASON_IE_INVALID; 
    16861686        } 
     
    16991699        w = 0; 
    17001700        for (; n > 0; n--) { 
    1701                 w |= 1<<wpa_cipher(frm, &rsn->rsn_ucastkeylen); 
     1701                w |= 1<<wpa_cipher(frm, &rsn_parm->rsn_ucastkeylen); 
    17021702                frm += 4, len -= 4; 
    17031703        } 
    1704         w &= rsn->rsn_ucastcipherset; 
     1704        w &= rsn_parm->rsn_ucastcipherset; 
    17051705        if (w == 0) { 
    17061706                IEEE80211_DISCARD_IE(vap, 
     
    17101710        } 
    17111711        if (w & (1<<IEEE80211_CIPHER_TKIP)) 
    1712                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
     1712                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
    17131713        else 
    1714                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
     1714                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
    17151715 
    17161716        /* key management algorithms */ 
     
    17291729                frm += 4, len -= 4; 
    17301730        } 
    1731         w &= rsn->rsn_keymgmtset; 
     1731        w &= rsn_parm->rsn_keymgmtset; 
    17321732        if (w == 0) { 
    17331733                IEEE80211_DISCARD_IE(vap, 
     
    17371737        } 
    17381738        if (w & WPA_ASE_8021X_UNSPEC) 
    1739                 rsn->rsn_keymgmt = WPA_ASE_8021X_UNSPEC; 
     1739                rsn_parm->rsn_keymgmt = WPA_ASE_8021X_UNSPEC; 
    17401740        else 
    1741                 rsn->rsn_keymgmt = WPA_ASE_8021X_PSK; 
     1741                rsn_parm->rsn_keymgmt = WPA_ASE_8021X_PSK; 
    17421742 
    17431743        if (len > 2)            /* optional capabilities */ 
    1744                 rsn->rsn_caps = LE_READ_2(frm); 
     1744                rsn_parm->rsn_caps = LE_READ_2(frm); 
    17451745 
    17461746        return 0; 
     
    18091809static int 
    18101810ieee80211_parse_rsn(struct ieee80211vap *vap, u_int8_t *frm, 
    1811         struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh) 
     1811        struct ieee80211_rsnparms *rsn_parm, const struct ieee80211_frame *wh) 
    18121812{ 
    18131813        u_int8_t len = frm[1]; 
     
    18441844 
    18451845        /* multicast/group cipher */ 
    1846         w = rsn_cipher(frm, &rsn->rsn_mcastkeylen); 
    1847         if (w != rsn->rsn_mcastcipher) { 
     1846        w = rsn_cipher(frm, &rsn_parm->rsn_mcastkeylen); 
     1847        if (w != rsn_parm->rsn_mcastcipher) { 
    18481848                IEEE80211_DISCARD_IE(vap, 
    18491849                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
    18501850                    wh, "RSN", "mcast cipher mismatch; got %u, expected %u", 
    1851                     w, rsn->rsn_mcastcipher); 
     1851                    w, rsn_parm->rsn_mcastcipher); 
    18521852                return IEEE80211_REASON_IE_INVALID; 
    18531853        } 
     
    18661866        w = 0; 
    18671867        for (; n > 0; n--) { 
    1868                 w |= 1<<rsn_cipher(frm, &rsn->rsn_ucastkeylen); 
     1868                w |= 1<<rsn_cipher(frm, &rsn_parm->rsn_ucastkeylen); 
    18691869                frm += 4, len -= 4; 
    18701870        } 
    1871         w &= rsn->rsn_ucastcipherset; 
     1871        w &= rsn_parm->rsn_ucastcipherset; 
    18721872        if (w == 0) { 
    18731873                IEEE80211_DISCARD_IE(vap, 
     
    18771877        } 
    18781878        if (w & (1<<IEEE80211_CIPHER_TKIP)) 
    1879                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
     1879                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
    18801880        else 
    1881                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
     1881                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
    18821882 
    18831883        /* key management algorithms */ 
     
    18961896                frm += 4, len -= 4; 
    18971897        } 
    1898         w &= rsn->rsn_keymgmtset; 
     1898        w &= rsn_parm->rsn_keymgmtset; 
    18991899        if (w == 0) { 
    19001900                IEEE80211_DISCARD_IE(vap, 
     
    19041904        } 
    19051905        if (w & RSN_ASE_8021X_UNSPEC) 
    1906                 rsn->rsn_keymgmt = RSN_ASE_8021X_UNSPEC; 
     1906                rsn_parm->rsn_keymgmt = RSN_ASE_8021X_UNSPEC; 
    19071907        else 
    1908                 rsn->rsn_keymgmt = RSN_ASE_8021X_PSK; 
     1908                rsn_parm->rsn_keymgmt = RSN_ASE_8021X_PSK; 
    19091909 
    19101910        /* optional RSN capabilities */ 
    19111911        if (len > 2) 
    1912                 rsn->rsn_caps = LE_READ_2(frm); 
     1912                rsn_parm->rsn_caps = LE_READ_2(frm); 
    19131913        /* XXXPMKID */ 
    19141914 
     
    22012201        struct ieee80211_frame *wh; 
    22022202        u_int8_t *frm, *efrm; 
    2203         u_int8_t *ssid, *rates, *xrates, *wpa, *wme, *ath; 
     2203        u_int8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath; 
    22042204        u_int8_t rate; 
    22052205        int reassoc, resp, allocbs; 
     
    22992299                                break; 
    23002300                        case IEEE80211_ELEMID_RSN: 
    2301                                 scan.wpa = frm; 
     2301                                scan.rsn = frm; 
    23022302                                break; 
    23032303                        case IEEE80211_ELEMID_VENDOR: 
     
    26742674        case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: { 
    26752675                u_int16_t capinfo, bintval; 
    2676                 struct ieee80211_rsnparms rsn
     2676                struct ieee80211_rsnparms rsn_parm
    26772677                u_int8_t reason; 
    26782678 
     
    27162716                if (reassoc) 
    27172717                        frm += 6;       /* ignore current AP info */ 
    2718                 ssid = rates = xrates = wpa = wme = ath = NULL; 
     2718                ssid = rates = xrates = wpa = rsn = wme = ath = NULL; 
    27192719                while (frm < efrm) { 
    27202720                        switch (*frm) { 
     
    27312731                        case IEEE80211_ELEMID_RSN: 
    27322732                                if (vap->iv_flags & IEEE80211_F_WPA2) 
    2733                                         wpa = frm; 
     2733                                        rsn = frm; 
    27342734                                else 
    27352735                                        IEEE80211_DPRINTF(vap, 
     
    27902790                } 
    27912791                                 
    2792                 if (wpa != NULL) { 
     2792                if (rsn != NULL) { 
    27932793                        /* 
    27942794                         * Parse WPA information element.  Note that 
     
    27982798                         * installed below after the association is assured. 
    27992799                         */ 
    2800                         rsn = ni->ni_rsn; 
    2801                         if (wpa[0] != IEEE80211_ELEMID_RSN) 
    2802                                 reason = ieee80211_parse_wpa(vap, wpa, &rsn, wh); 
     2800                        rsn_parm = ni->ni_rsn; 
     2801                        if (rsn[0] != IEEE80211_ELEMID_RSN) 
     2802                                reason = ieee80211_parse_wpa(vap, rsn, &rsn_parm, wh); 
    28032803                        else 
    2804                                 reason = ieee80211_parse_rsn(vap, wpa, &rsn, wh); 
     2804                                reason = ieee80211_parse_rsn(vap, rsn, &rsn_parm, wh); 
    28052805                        if (reason != 0) { 
    28062806                                IEEE80211_SEND_MGMT(ni, 
     
    28152815                            wh->i_addr2, 
    28162816                            "%s ie: mc %u/%u uc %u/%u key %u caps 0x%x", 
    2817                             wpa[0] != IEEE80211_ELEMID_RSN ?  "WPA" : "RSN", 
    2818                             rsn.rsn_mcastcipher, rsn.rsn_mcastkeylen, 
    2819                             rsn.rsn_ucastcipher, rsn.rsn_ucastkeylen, 
    2820                             rsn.rsn_keymgmt, rsn.rsn_caps); 
     2817                            rsn[0] != IEEE80211_ELEMID_RSN ?  "WPA" : "RSN", 
     2818                            rsn_parm.rsn_mcastcipher, rsn_parm.rsn_mcastkeylen, 
     2819                            rsn_parm.rsn_ucastcipher, rsn_parm.rsn_ucastkeylen, 
     2820                            rsn_parm.rsn_keymgmt, rsn_parm.rsn_caps); 
    28212821                } 
    28222822                /* discard challenge after association */ 
     
    28872887                         * for applications that require it. 
    28882888                         */ 
    2889                         ni->ni_rsn = rsn; 
    28902889                        ieee80211_saveie(&ni->ni_wpa_ie, wpa); 
    28912890                } else if (ni->ni_wpa_ie != NULL) { 
     
    28952894                        FREE(ni->ni_wpa_ie, M_DEVBUF); 
    28962895                        ni->ni_wpa_ie = NULL; 
     2896                } 
     2897                if (rsn != NULL) { 
     2898                        /* 
     2899                         * Record WPA/RSN parameters for station, mark 
     2900                         * node as using WPA and record information element 
     2901                         * for applications that require it. 
     2902                         */ 
     2903                        ni->ni_rsn = rsn_parm; 
     2904                        ieee80211_saveie(&ni->ni_rsn_ie, rsn); 
     2905                } else if (ni->ni_rsn_ie != NULL) { 
     2906                        /* 
     2907                         * Flush any state from a previous association. 
     2908                         */ 
     2909                        FREE(ni->ni_rsn_ie, M_DEVBUF); 
     2910                        ni->ni_rsn_ie = NULL; 
    28972911                } 
    28982912                if (wme != NULL) { 
  • trunk/net80211/ieee80211_node.c

    r1336 r1357  
    647647        if (se->se_wpa_ie != NULL) 
    648648                ieee80211_saveie(&ni->ni_wpa_ie, se->se_wpa_ie); 
     649        if (se->se_rsn_ie != NULL) 
     650                ieee80211_saveie(&ni->ni_rsn_ie, se->se_rsn_ie); 
    649651        if (se->se_wme_ie != NULL) 
    650652                ieee80211_saveie(&ni->ni_wme_ie, se->se_wme_ie); 
     
    792794        if (ni->ni_wpa_ie != NULL) 
    793795                FREE(ni->ni_wpa_ie, M_DEVBUF); 
     796        if (ni->ni_rsn_ie != NULL) 
     797                FREE(ni->ni_rsn_ie, M_DEVBUF); 
    794798        if (ni->ni_wme_ie != NULL) 
    795799                FREE(ni->ni_wme_ie, M_DEVBUF); 
     
    11781182                if (sp->wpa != NULL) 
    11791183                        ieee80211_saveie(&ni->ni_wpa_ie, sp->wpa); 
     1184                if (sp->rsn != NULL) 
     1185                        ieee80211_saveie(&ni->ni_rsn_ie, sp->rsn); 
    11801186                if (sp->ath != NULL) 
    11811187                        ieee80211_saveath(ni, sp->ath); 
  • trunk/net80211/ieee80211_node.h

    r1294 r1357  
    123123        u_int16_t               ni_vlan;        /* vlan tag */ 
    124124        u_int32_t               *ni_challenge;  /* shared-key challenge */ 
    125         u_int8_t                *ni_wpa_ie;     /* captured WPA/RSN ie */ 
     125        u_int8_t                *ni_wpa_ie;     /* captured WPA ie */ 
     126        u_int8_t                *ni_rsn_ie;     /* captured RSN ie */ 
    126127        u_int8_t                *ni_wme_ie;     /* captured WME ie */ 
    127128        u_int8_t                *ni_ath_ie;     /* captured Atheros ie */ 
  • trunk/net80211/ieee80211_scan.h

    r1175 r1357  
    145145        u_int8_t        *doth; 
    146146        u_int8_t        *wpa; 
     147        u_int8_t        *rsn; 
    147148        u_int8_t        *wme; 
    148149        u_int8_t        *ath; 
     
    173174        int8_t          se_rssi;        /* avg'd recv ssi */ 
    174175        u_int8_t        se_dtimperiod;  /* DTIM period */ 
    175         u_int8_t        *se_wpa_ie;     /* captured WPA/RSN ie */ 
     176        u_int8_t        *se_wpa_ie;     /* captured WPA ie */ 
     177        u_int8_t        *se_rsn_ie;     /* captured RSN ie */ 
    176178        u_int8_t        *se_wme_ie;     /* captured WME ie */ 
    177179        u_int8_t        *se_ath_ie;     /* captured Atheros ie */ 
  • trunk/net80211/ieee80211_scan_sta.c

    r1336 r1357  
    273273        saveie(&ise->se_wme_ie, sp->wme); 
    274274        saveie(&ise->se_wpa_ie, sp->wpa); 
     275        saveie(&ise->se_rsn_ie, sp->rsn); 
    275276        saveie(&ise->se_ath_ie, sp->ath); 
    276277 
  • trunk/net80211/ieee80211_wireless.c

    r1356 r1357  
    14331433        current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, buf); 
    14341434 
    1435         if (se->se_wpa_ie != NULL) { 
     1435        if (se->se_rsn_ie != NULL) { 
    14361436                static const char rsn_leader[] = "rsn_ie="; 
    1437                 static const char wpa_leader[] = "wpa_ie="; 
    14381437 
    14391438                memset(&iwe, 0, sizeof(iwe)); 
    14401439                iwe.cmd = IWEVCUSTOM; 
    1441                 if (se->se_wpa_ie[0] == IEEE80211_ELEMID_RSN) 
     1440                if (se->se_rsn_ie[0] == IEEE80211_ELEMID_RSN) 
    14421441                        iwe.u.data.length = encode_ie(buf, sizeof(buf), 
    1443                                 se->se_wpa_ie, se->se_wpa_ie[1]+2, 
     1442                                se->se_rsn_ie, se->se_rsn_ie[1]+2, 
    14441443                                rsn_leader, sizeof(rsn_leader)-1); 
    1445                 else 
     1444                if (iwe.u.data.length != 0) 
     1445                        current_ev = iwe_stream_add_point(current_ev, end_buf, 
     1446                                &iwe, buf); 
     1447        } 
     1448        if (se->se_wpa_ie != NULL) { 
     1449                static const char wpa_leader[] = "wpa_ie="; 
     1450 
     1451                memset(&iwe, 0, sizeof(iwe)); 
     1452                iwe.cmd = IWEVCUSTOM; 
    14461453                        iwe.u.data.length = encode_ie(buf, sizeof(buf), 
    14471454                                se->se_wpa_ie, se->se_wpa_ie[1]+2,