wscutil: Allow 0-length attributes in wsc_attr_builder
PATCH 1/5 wscutil: Allow 0-length attributes in wsc_attr_builder
wsc_attr_builder_start_attr and wsc_attr_builder_free look at builder->curlen to see whether the TLV's length needs to be updated to include the previous attribute. If builder->curlen is 0 wsc_attr_builder_start_attr assumes there's no previous attribute and starts writing at current builder->offset. If the previous attribute length was 0 curlen would stay at 0 and that attribute would get overwritten with the new one. To solve this add the 4 bytes of the T and L to curlen as soon as a new attribute is started, and subtract them when writing the L value. The alternative would be to set a flag to say whether an attribute was started.
The spec explicitly allows 0-length attributes in section 12:
"The variable length string attributes, e.g., Device Name, are encoded without null-termination, i.e., no 0x00 octets added to the end of the value. If the string is empty, the attribute length is set to zero."
--- src/wscutil.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
src/wscutil.c +18 -20
@@ -1634,11 +1634,12 @@ static bool wsc_attr_builder_start_attr(struct wsc_attr_builder *builder,/* Record previous attribute's length */ if (builder->curlen >0 ) { bytes = builder->buf + builder->offset; -l_put_be16 (builder->curlen, bytes +2 ); - builder->offset +=4 + builder->curlen; - builder->curlen =0 ; +l_put_be16 (builder->curlen -4 , bytes +2 ); + builder->offset += builder->curlen; } + builder->curlen =4 ; +if (builder->offset +4 >= builder->capacity)wsc_attr_builder_grow (builder);
@@ -1650,10 +1651,10 @@ static bool wsc_attr_builder_start_attr(struct wsc_attr_builder *builder,static bool wsc_attr_builder_put_u8 (struct wsc_attr_builder *builder,uint8_t v) { -if (builder->offset +4 + builder->curlen +1 >= builder->capacity) +if (builder->offset + builder->curlen +1 >= builder->capacity)wsc_attr_builder_grow (builder); - builder->buf[builder->offset +4 + builder->curlen] = v; + builder->buf[builder->offset + builder->curlen] = v; builder->curlen +=1 ;return true;
@@ -1662,10 +1663,10 @@ static bool wsc_attr_builder_put_u8(struct wsc_attr_builder *builder, uint8_t v)static bool wsc_attr_builder_put_u16 (struct wsc_attr_builder *builder,uint16_t v) { -if (builder->offset +4 + builder->curlen +2 >= builder->capacity) +if (builder->offset + builder->curlen +2 >= builder->capacity)wsc_attr_builder_grow (builder); -l_put_be16 (v, builder->buf + builder->offset +4 + builder->curlen); +l_put_be16 (v, builder->buf + builder->offset + builder->curlen); builder->curlen +=2 ;return true;
@@ -1674,10 +1675,10 @@ static bool wsc_attr_builder_put_u16(struct wsc_attr_builder *builder,static bool wsc_attr_builder_put_u32 (struct wsc_attr_builder *builder,uint32_t v) { -if (builder->offset +4 + builder->curlen +4 >= builder->capacity) +if (builder->offset + builder->curlen +4 >= builder->capacity)wsc_attr_builder_grow (builder); -l_put_be32 (v, builder->buf + builder->offset +4 + builder->curlen); +l_put_be32 (v, builder->buf + builder->offset + builder->curlen); builder->curlen +=4 ;return true;
@@ -1686,12 +1687,10 @@ static bool wsc_attr_builder_put_u32(struct wsc_attr_builder *builder,static bool wsc_attr_builder_put_bytes (struct wsc_attr_builder *builder,const void *bytes,size_t size) { -while (builder->offset +4 + builder->curlen + size >= - builder->capacity) +while (builder->offset + builder->curlen + size >= builder->capacity)wsc_attr_builder_grow (builder); -memcpy (builder->buf + builder->offset +4 + builder->curlen, - bytes, size); +memcpy (builder->buf + builder->offset + builder->curlen, bytes, size); builder->curlen += size;return true;
@@ -1700,10 +1699,10 @@ static bool wsc_attr_builder_put_bytes(struct wsc_attr_builder *builder,static bool wsc_attr_builder_put_oui (struct wsc_attr_builder *builder,const uint8_t *oui) { -if (builder->offset +4 + builder->curlen +3 >= builder->capacity) +if (builder->offset + builder->curlen +3 >= builder->capacity)wsc_attr_builder_grow (builder); -memcpy (builder->buf + builder->offset +4 + builder->curlen, oui,3 ); +memcpy (builder->buf + builder->offset + builder->curlen, oui,3 ); builder->curlen +=3 ;return true;
@@ -1721,11 +1720,10 @@ static bool wsc_attr_builder_put_string(struct wsc_attr_builder *builder, len =1 ; } -if (builder->offset +4 + builder->curlen + len >= builder->capacity) +if (builder->offset + builder->curlen + len >= builder->capacity)wsc_attr_builder_grow (builder); -memcpy (builder->buf + builder->offset +4 + builder->curlen, - string, len); +memcpy (builder->buf + builder->offset + builder->curlen, string, len); builder->curlen += len;return true;
@@ -1753,8 +1751,8 @@ static uint8_t *wsc_attr_builder_free(struct wsc_attr_builder *builder,if (builder->curlen >0 ) {uint8_t *bytes = builder->buf + builder->offset; -l_put_be16 (builder->curlen, bytes +2 ); - builder->offset +=4 + builder->curlen; +l_put_be16 (builder->curlen -4 , bytes +2 ); + builder->offset += builder->curlen; builder->curlen =0 ; }
Signature · 1 line
2.25.1
PATCH 2/5 unit: Fix a typo in test-eapol
--- unit/test-eapol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
unit/test-eapol.c +1 -1
@@ -3571,7 +3571,7 @@ static void test_ap_sta_run(struct test_ap_sta_data *s) s->sta_success = false; s->to_sta_msg_cnt =0 ; s->to_ap_msg_cnt =0 ; - s->to_sta_data_len =0 , + s->to_sta_data_len =0 ; s->ap_sm =eapol_sm_new (s->ap_hs);eapol_register (s->ap_sm);
Signature · 1 line
2.25.1
PATCH 3/5 unit: Test a EAP-WSC-R setup with WPA2 credentials
In reply to Andrew Zaborowski--- unit/test-wsc.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+)
unit/test-wsc.c +275 -0
@@ -2261,6 +2261,278 @@ static void wsc_test_pin_generate(const void *data) } } +struct test_ap_sta_data { +struct handshake_state *ap_hs; +struct handshake_state *sta_hs; +const uint8_t ap_address[6 ]; +const uint8_t sta_address[6 ]; + +uint8_t to_sta_data[1024 ]; +int to_sta_data_len; +int to_sta_msg_cnt; +int to_ap_msg_cnt; +struct eapol_sm *ap_sm; +struct eapol_sm *sta_sm; +}; + +static int test_ap_sta_eapol_tx (uint32_t ifindex, +const uint8_t *dest,uint16_t proto, +const struct eapol_frame *ef, +bool noencrypt,void *user_data) +{ +struct test_ap_sta_data *s = user_data; +size_t len =sizeof (struct eapol_header ) + +L_BE16_TO_CPU (ef->header.packet_len); + +assert (ifindex == s->ap_hs->ifindex || ifindex == s->sta_hs->ifindex); +assert (proto ==ETH_P_PAE && !noencrypt); + +if (ifindex == s->ap_hs->ifindex) {/* From AP to STA */ +assert (!memcmp (dest, s->sta_address,6 )); +assert (len <sizeof (s->to_sta_data)); +memcpy (s->to_sta_data, ef, len); + s->to_sta_data_len = len; + s->to_sta_msg_cnt++; +return 0 ; + } + +/* From STA to AP */ +assert (!memcmp (dest, s->ap_address,6 )); + s->to_ap_msg_cnt++; +__eapol_rx_packet (1 , s->sta_address, proto, (const void *) ef, len, + noencrypt); +return 0 ; +} + +static void test_ap_sta_run (struct test_ap_sta_data *s) +{ +eap_init (); +eapol_init (); +__eapol_set_tx_packet_func (test_ap_sta_eapol_tx); +__eapol_set_tx_user_data (s); + + s->to_sta_msg_cnt =0 ; + s->to_ap_msg_cnt =0 ; + s->to_sta_data_len =0 ; + + s->ap_sm =eapol_sm_new (s->ap_hs); +eapol_register (s->ap_sm); + + s->sta_sm =eapol_sm_new (s->sta_hs); +eapol_register (s->sta_sm); + +eapol_start (s->sta_sm); +eapol_start (s->ap_sm); + +while (s->to_sta_data_len) { +int len = s->to_sta_data_len; + s->to_sta_data_len =0 ; +__eapol_rx_packet (s->sta_hs->ifindex, s->ap_address,ETH_P_PAE , + s->to_sta_data, len, false); + } + +if (s->ap_sm) +eapol_sm_free (s->ap_sm); + +if (s->sta_sm) +eapol_sm_free (s->sta_sm); + +eapol_exit (); +eap_exit (); +} + +struct test_ap_sta_hs { +struct handshake_state super; +struct test_ap_sta_data *s; +}; + +static struct handshake_state *test_ap_sta_hs_new (struct test_ap_sta_data *s, +uint32_t ifindex) +{ + struct test_ap_sta_hs *ths = l_new(struct test_ap_sta_hs, 1); + + ths->super.ifindex = ifindex; + ths->super.free = (void (*)(struct handshake_state *s)) l_free; + ths->s = s; + +return &ths->super; +} + +static bool random_nonce (uint8_t nonce[]) +{ +return l_getrandom (nonce,32 ); +} + +static void test_ap_sta_install_tk (struct handshake_state *hs, +const uint8_t *tk,uint32_t cipher) +{ +assert (false); +} + +struct wsc_r_test_success_data { +bool credentials_obtained; +bool credentials_sent; +bool ap_eap_failed; +bool sta_eap_failed; +struct test_ap_sta_data *s; +}; + +static void test_ap_sta_hs_event_ap (struct handshake_state *hs, +enum handshake_event event, +void *user_data, ...) +{ +struct wsc_r_test_success_data *data = user_data; +va_list args; + +va_start (args, user_data); + +switch (event) { +case HANDSHAKE_EVENT_EAP_NOTIFY : + assert(va_arg(args, unsigned int) == +EAP_WSC_EVENT_CREDENTIAL_SENT ); +assert (!data->credentials_sent); +assert (!data->ap_eap_failed); + data->credentials_sent = true; +break ; +case HANDSHAKE_EVENT_FAILED : +assert (va_arg (args, int) == +MMPDU_REASON_CODE_IEEE8021X_FAILED ); +assert (!data->ap_eap_failed); + data->ap_eap_failed = true; + data->s->ap_sm =NULL ; +break ; +default : +break ; + } + +va_end (args); +} + +static void test_ap_sta_hs_event_sta (struct handshake_state *hs, +enum handshake_event event, +void *user_data, ...) +{ +struct wsc_r_test_success_data *data = user_data; +va_list args; + +va_start (args, user_data); + +switch (event) { +case HANDSHAKE_EVENT_EAP_NOTIFY : + { + unsigned int eap_event = va_arg(args, unsigned int); +const struct wsc_credential *cred; + +assert (eap_event ==EAP_WSC_EVENT_CREDENTIAL_OBTAINED ); + cred = va_arg(args, const struct wsc_credential *); +assert (cred->ssid_len ==7 && + !memcmp (cred->ssid,"thessid" ,7 )); +assert (cred->auth_type == +WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL ); +assert (cred->encryption_type ==WSC_ENCRYPTION_TYPE_AES_TKIP ); +assert (cred->network_key_len ==12 && + !memcmp (cred->network_key,"secretsecret" ,12 )); +assert (!memcmp (cred->addr, data->s->sta_address,6 )); +assert (!data->credentials_obtained); +assert (!data->sta_eap_failed); + data->credentials_obtained = true; +break ; + } +case HANDSHAKE_EVENT_FAILED : +assert (va_arg (args, int) == +MMPDU_REASON_CODE_IEEE8021X_FAILED ); +assert (!data->sta_eap_failed); + data->sta_eap_failed = true; + data->s->sta_sm =NULL ; +break ; +default : +break ; + } + +va_end (args); +} + +static void wsc_r_test_pbc_handshake_wpa2 (const void *data) +{ +static const unsigned char ap_rsne[] = { +0x30 ,0x12 ,0x01 ,0x00 ,0x00 ,0x0f ,0xac ,0x04 , +0x01 ,0x00 ,0x00 ,0x0f ,0xac ,0x04 ,0x01 ,0x00 , +0x00 ,0x0f ,0xac ,0x02 }; +static const char *ssid ="TestWPA2EAP" ; +static const char *ap_8021x_str ="[Security]\n" +"EAP-Method=WSC-R\n" +"[WSC]\n" +"UUID-R=00112233445566778899aabbccddeeff\n" +"WPA2-SSID=thessid\n" +"WPA2-Passphrase=secretsecret\n" +"RFBand=1\n" +"ConfigurationMethods=0x680\n" ; +static const char *sta_8021x_str ="[Security]\n" +"EAP-Identity=WFA-SimpleConfig-Enrollee-1-0\n" +"EAP-Method=WSC\n" +"[WSC]\n" +"RFBand=1\n" +"ConfigurationMethods=0x680\n" ; +struct l_settings *ap_8021x_settings =l_settings_new (); +struct l_settings *sta_8021x_settings =l_settings_new (); +struct test_ap_sta_data s = { + .ap_hs =test_ap_sta_hs_new (&s,1 ), + .sta_hs =test_ap_sta_hs_new (&s,2 ), + .ap_address = {0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 }, + .sta_address = {0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x08 }, + }; +struct wsc_r_test_success_data wsc_data = { + .s = &s, + }; +uint8_t uuid_e[16 ]; + L_AUTO_FREE_VAR(char *, uuid_e_str) = NULL; + +wsc_uuid_from_addr (s.sta_address, uuid_e); + uuid_e_str =l_util_hexstring (uuid_e,16 ); + +__handshake_set_get_nonce_func (random_nonce); +__handshake_set_install_tk_func (test_ap_sta_install_tk); +__handshake_set_install_gtk_func (NULL ); + +handshake_state_set_authenticator (s.ap_hs, true); +handshake_state_set_event_func (s.ap_hs, test_ap_sta_hs_event_ap, + &wsc_data); +handshake_state_set_authenticator_address (s.ap_hs, s.ap_address); +handshake_state_set_supplicant_address (s.ap_hs, s.sta_address); +handshake_state_set_authenticator_ie (s.ap_hs, ap_rsne); +handshake_state_set_ssid (s.ap_hs, (void *) ssid,strlen (ssid)); +l_settings_load_from_data (ap_8021x_settings, ap_8021x_str, +strlen (ap_8021x_str)); +l_settings_set_string (ap_8021x_settings,"WSC" ,"EnrolleeMAC" , +util_address_to_string (s.sta_address)); +l_settings_set_string (ap_8021x_settings,"WSC" ,"UUID-E" , uuid_e_str); +handshake_state_set_8021x_config (s.ap_hs, ap_8021x_settings); + +handshake_state_set_authenticator (s.sta_hs, false); +handshake_state_set_event_func (s.sta_hs, test_ap_sta_hs_event_sta, + &wsc_data); +handshake_state_set_authenticator_address (s.sta_hs, s.ap_address); +handshake_state_set_supplicant_address (s.sta_hs, s.sta_address); +handshake_state_set_authenticator_ie (s.sta_hs, ap_rsne); +handshake_state_set_ssid (s.sta_hs, (void *) ssid,strlen (ssid)); +l_settings_load_from_data (sta_8021x_settings, sta_8021x_str, +strlen (sta_8021x_str)); +l_settings_set_string (sta_8021x_settings,"WSC" ,"EnrolleeMAC" , +util_address_to_string (s.sta_address)); +handshake_state_set_8021x_config (s.sta_hs, sta_8021x_settings); + +test_ap_sta_run (&s); + +handshake_state_free (s.ap_hs); +handshake_state_free (s.sta_hs); +__handshake_set_install_tk_func (NULL ); +l_settings_free (ap_8021x_settings); +l_settings_free (sta_8021x_settings); + +assert (wsc_data.sta_eap_failed && wsc_data.credentials_obtained); +assert (wsc_data.ap_eap_failed && wsc_data.credentials_sent); +} +int main (int argc,char *argv[]) {l_test_init (&argc, &argv);
@@ -2374,6 +2646,9 @@ int main(int argc, char *argv[])l_test_add ("/wsc/retransmission/no fragmentation" , wsc_test_retransmission_no_fragmentation,NULL ); +l_test_add ("/wsc-r/handshake/PBC Handshake WPA2 Test" , + wsc_r_test_pbc_handshake_wpa2,NULL ); + done:return l_test_run (); }
Signature · 1 line
2.25.1
PATCH 4/5 unit: Add a WSC-R test with a raw PSK
In reply to Andrew ZaborowskiThe wsc credentials can contain the passphrase or the raw PSK bytes, now test both scenarios.
--- unit/test-wsc.c | 91 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 18 deletions(-)
unit/test-wsc.c +73 -18
@@ -2375,6 +2375,7 @@ struct wsc_r_test_success_data {bool ap_eap_failed;bool sta_eap_failed;struct test_ap_sta_data *s; +struct wsc_credential expected_creds; }; static void test_ap_sta_hs_event_ap(struct handshake_state *hs,
@@ -2425,14 +2426,7 @@ static void test_ap_sta_hs_event_sta(struct handshake_state *hs,assert (eap_event ==EAP_WSC_EVENT_CREDENTIAL_OBTAINED ); cred = va_arg(args, const struct wsc_credential *); -assert (cred->ssid_len ==7 && - !memcmp (cred->ssid,"thessid" ,7 )); -assert (cred->auth_type == -WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL ); -assert (cred->encryption_type ==WSC_ENCRYPTION_TYPE_AES_TKIP ); -assert (cred->network_key_len ==12 && - !memcmp (cred->network_key,"secretsecret" ,12 )); -assert (!memcmp (cred->addr, data->s->sta_address,6 )); +assert (!memcmp (cred, &data->expected_creds,sizeof (*cred)));assert (!data->credentials_obtained);assert (!data->sta_eap_failed); data->credentials_obtained = true;
@@ -2452,7 +2446,7 @@ static void test_ap_sta_hs_event_sta(struct handshake_state *hs,va_end (args); } -static void wsc_r_test_pbc_handshake_wpa2 (const void *data) +static void wsc_r_test_pbc_handshake (const void *data) {static const unsigned char ap_rsne[] = {0x30 ,0x12 ,0x01 ,0x00 ,0x00 ,0x0f ,0xac ,0x04 ,
@@ -2463,8 +2457,6 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data)"EAP-Method=WSC-R\n" "[WSC]\n" "UUID-R=00112233445566778899aabbccddeeff\n" -"WPA2-SSID=thessid\n" -"WPA2-Passphrase=secretsecret\n" "RFBand=1\n" "ConfigurationMethods=0x680\n" ;static const char *sta_8021x_str ="[Security]\n"
@@ -2481,15 +2473,60 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data) .ap_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, .sta_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x08 }, }; +const struct wsc_credential *expected_creds = data;struct wsc_r_test_success_data wsc_data = { .s = &s, + .expected_creds = *expected_creds, };uint8_t uuid_e[16 ]; L_AUTO_FREE_VAR(char *, uuid_e_str) = NULL; +char ssid_str[33 ];wsc_uuid_from_addr (s.sta_address, uuid_e); uuid_e_str =l_util_hexstring (uuid_e,16 ); +memcpy (wsc_data.expected_creds.addr, s.sta_address,6 ); +memset (wsc_data.expected_creds.ssid + expected_creds->ssid_len,0 , +sizeof (expected_creds->ssid) - expected_creds->ssid_len); +memset (wsc_data.expected_creds.network_key + + expected_creds->network_key_len,0 , +sizeof (expected_creds->network_key) - + expected_creds->network_key_len); + +memcpy (ssid_str, expected_creds->ssid, expected_creds->ssid_len); + ssid_str[expected_creds->ssid_len] ='\0' ; + +l_settings_load_from_data (ap_8021x_settings, ap_8021x_str, +strlen (ap_8021x_str)); +l_settings_set_string (ap_8021x_settings,"WSC" ,"EnrolleeMAC" , +util_address_to_string (s.sta_address)); +l_settings_set_string (ap_8021x_settings,"WSC" ,"UUID-E" , uuid_e_str); + +if (expected_creds->auth_type ==WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL ) { +l_settings_set_string (ap_8021x_settings,"WSC" , +"WPA2-SSID" , ssid_str); + +if (expected_creds->network_key_len <64 ) +l_settings_set_string (ap_8021x_settings,"WSC" , +"WPA2-Passphrase" , (char *) + wsc_data.expected_creds.network_key); +else { +char psk_str[65 ]; + +/* +* The PSK is 32-byte long but the setting value is +* a hexstring, same as what we expect to receive in +* the raw wsc_credential.network_key data. +*/ +memcpy (psk_str, expected_creds->network_key,64 ); + psk_str[64 ] ='\0' ; +l_settings_set_string (ap_8021x_settings,"WSC" , +"WPA2-PSK" , psk_str); + } + }else +l_settings_set_string (ap_8021x_settings,"WSC" , +"Open-SSID" , ssid_str); +__handshake_set_get_nonce_func (random_nonce);__handshake_set_install_tk_func (test_ap_sta_install_tk);__handshake_set_install_gtk_func (NULL );
@@ -2501,11 +2538,6 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data)handshake_state_set_supplicant_address (s.ap_hs, s.sta_address);handshake_state_set_authenticator_ie (s.ap_hs, ap_rsne);handshake_state_set_ssid (s.ap_hs, (void *) ssid,strlen (ssid)); -l_settings_load_from_data (ap_8021x_settings, ap_8021x_str, -strlen (ap_8021x_str)); -l_settings_set_string (ap_8021x_settings,"WSC" ,"EnrolleeMAC" , -util_address_to_string (s.sta_address)); -l_settings_set_string (ap_8021x_settings,"WSC" ,"UUID-E" , uuid_e_str);handshake_state_set_8021x_config (s.ap_hs, ap_8021x_settings);handshake_state_set_authenticator (s.sta_hs, false);
@@ -2533,6 +2565,25 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data)assert (wsc_data.ap_eap_failed && wsc_data.credentials_sent); } +struct wsc_credential wsc_r_test_wpa2_cred_passphrase = { + .ssid_len =7 , + .ssid ="thessid" , + .auth_type =WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL , + .network_key_len =12 , + .network_key ="secretsecret" , + .encryption_type =WSC_ENCRYPTION_TYPE_AES_TKIP , +}; + +struct wsc_credential wsc_r_test_wpa2_cred_psk = { + .ssid_len =7 , + .ssid ="thessid" , + .auth_type =WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL , + .network_key_len =64 , + .network_key ="2aacd631143bbc2d83fabf3febed3c45" +"6ea9f7539a1692ffb416c41cfee0c96f" , + .encryption_type =WSC_ENCRYPTION_TYPE_AES_TKIP , +}; +int main (int argc,char *argv[]) {l_test_init (&argc, &argv);
@@ -2646,8 +2697,12 @@ int main(int argc, char *argv[])l_test_add ("/wsc/retransmission/no fragmentation" , wsc_test_retransmission_no_fragmentation,NULL ); -l_test_add ("/wsc-r/handshake/PBC Handshake WPA2 Test" , - wsc_r_test_pbc_handshake_wpa2,NULL ); +l_test_add ("/wsc-r/handshake/PBC Handshake WPA2 passphrase test" , + wsc_r_test_pbc_handshake, + &wsc_r_test_wpa2_cred_passphrase); +l_test_add ("/wsc-r/handshake/PBC Handshake WPA2 PSK test" , + wsc_r_test_pbc_handshake, + &wsc_r_test_wpa2_cred_psk); done:return l_test_run ();
Signature · 1 line
2.25.1
PATCH 5/5 unit: Add a WSC-R PBC test with Open auth_type
In reply to Andrew Zaborowski--- unit/test-wsc.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
unit/test-wsc.c +11 -0
@@ -2584,6 +2584,14 @@ struct wsc_credential wsc_r_test_wpa2_cred_psk = { .encryption_type = WSC_ENCRYPTION_TYPE_AES_TKIP, }; +struct wsc_credential wsc_r_test_open_cred = { + .ssid_len =7 , + .ssid ="thessid" , + .auth_type =WSC_AUTHENTICATION_TYPE_OPEN , + .network_key_len =0 , + .encryption_type =WSC_ENCRYPTION_TYPE_NONE , +}; +int main (int argc,char *argv[]) {l_test_init (&argc, &argv);
@@ -2703,6 +2711,9 @@ int main(int argc, char *argv[])l_test_add ("/wsc-r/handshake/PBC Handshake WPA2 PSK test" , wsc_r_test_pbc_handshake, &wsc_r_test_wpa2_cred_psk); +l_test_add ("/wsc-r/handshake/PBC Handshake Open test" , + wsc_r_test_pbc_handshake, + &wsc_r_test_open_cred); done:return l_test_run ();
Signature · 1 line
2.25.1
Hi Andrew,
Quoted 11 lines · Andrew Zaborowski
wsc_attr_builder_start_attrandwsc_attr_builder_freelook atbuilder->curlento see whether the TLV's length needs to be updated to include the previous attribute. Ifbuilder->curlenis 0wsc_attr_builder_start_attrassumes there's no previous attribute and starts writing at currentbuilder->offset. If the previous attribute length was 0 curlen would stay at 0 and that attribute would get overwritten with the new one. To solve this add the 4 bytes of the T and L to curlen as soon as a new attribute is started, and subtract them when writing the L value. The alternative would be to set a flag to say whether an attribute was started.
Quoted 8 lines
The spec explicitly allows 0-length attributes in section 12:
"The variable length string attributes, e.g., Device Name, are encoded without null-termination, i.e., no0x00octets added to the end of the value. If the string is empty, the attribute length is set to zero."--- src/wscutil.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
All applied, thanks.
Regards,
-Denis