dpp-util: add dpp_point_from_asn1()
James Prestwood
PATCH v2 1/10 dpp-util: add dpp_point_from_asn1()
Given an ASN1 blob of the right form, parse and create an l_ecc_point object. The form used is specific to DPP hence why this isn't general purpose and put into dpp-util.
--- src/dpp-util.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/dpp-util.h | 1 + 2 files changed, 70 insertions(+)
src/dpp-util.c +69 -0
@@ -796,3 +796,72 @@ uint8_t *dpp_point_to_asn1(const struct l_ecc_point *p, size_t *len_out)return asn1; } + +/* +* Only checking for the ASN.1 form: +* +* SEQUENCE { +* SEQUENCE { +* OBJECT IDENTIFIER ecPublicKey +* OBJECT IDENTIFIER key type (p256/p384) +* } +* BITSTRING (key data) +* } +*/ +struct l_ecc_point *dpp_point_from_asn1 (const uint8_t *asn1,size_t len) +{ + +const uint8_t *outer_seq; +size_t outer_len; +const uint8_t *inner_seq; +size_t inner_len; +const uint8_t *elem; +const uint8_t *key_data; +size_t elen =0 ; +uint8_t tag; +unsigned int curve_num; +const struct l_ecc_curve *curve; + +/* SEQUENCE */ + outer_seq =asn1_der_find_elem (asn1, len,0 , &tag, &outer_len); +if (!outer_seq || tag !=ASN1_ID_SEQUENCE ) +return NULL ; + +/* SEQUENCE */ + inner_seq =asn1_der_find_elem (outer_seq, outer_len,0 , &tag, &inner_len); +if (!inner_seq || tag !=ASN1_ID_SEQUENCE ) +return NULL ; + +/* OBJECT IDENTIFIER (ecPublicKey) */ + elem =asn1_der_find_elem (inner_seq, inner_len,0 , &tag, &elen); +if (!elem || tag !=ASN1_ID_OID ) +return NULL ; + +/* Check that this OID is ecPublicKey */ +if (!asn1_oid_eq (&ec_oid, elen, elem)) +return NULL ; + + elem =asn1_der_find_elem (inner_seq, inner_len,1 , &tag, &elen); +if (!elem || tag !=ASN1_ID_OID ) +return NULL ; + +/* Check if ELL supports this curve */ +if (asn1_oid_eq (&ec_p256_oid, elen, elem)) + curve_num =19 ; +else if (asn1_oid_eq (&ec_p384_oid, elen, elem)) + curve_num =20 ; +else +return NULL ; + + curve =l_ecc_curve_from_ike_group (curve_num); +if (!curve) +return NULL ; + +/* BITSTRING */ + key_data =asn1_der_find_elem (outer_seq, outer_len,1 , &tag, &elen); +if (!key_data || tag !=ASN1_ID_BIT_STRING || elen >2 ) +return NULL ; + +return l_ecc_point_from_data (curve, key_data[1 ], + key_data +2 , elen -2 ); +}
src/dpp-util.h +1 -0
@@ -167,3 +167,4 @@ bool dpp_derive_ke(const uint8_t *i_nonce, const uint8_t *r_nonce, void *ke);uint8_t *dpp_point_to_asn1 (const struct l_ecc_point *p,size_t *len_out); +struct l_ecc_point *dpp_point_from_asn1 (const uint8_t *asn1,size_t len);
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 2/10 dpp-util: add URI parsing
Parses K (key), M (mac), C (class/channels), and V (version) tokens into a new structure dpp_uri_info. H/I are not parsed since there currently isn't any use for them.
--- src/dpp-util.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++++ src/dpp-util.h | 13 +++ 2 files changed, 230 insertions(+)
src/dpp-util.c +217 -0
@@ -865,3 +865,220 @@ struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len)return l_ecc_point_from_data (curve, key_data[1 ], key_data +2 , elen -2 ); } + +/* +* Advances 'p' to the next character 'sep' plus one. strchr can be trusted to +* find the next character, but we do need to check that the next character + 1 +* isn't the NULL terminator, i.e. that data actually exists past this point. +*/ +#define TOKEN_NEXT (p, sep) \ +({ \ + const char *_next = strchr((p), (sep)); \ + if (_next) { \ + if (*(_next + 1) == '\0') \ + _next = NULL; \ + else \ + _next++; \ + } \ + _next; \ +}) + +/* +* Finds the length of the current token (characters until next 'sep'). If no +* 'sep' is found zero is returned. +*/ +#define TOKEN_LEN (p, sep) \ +({ \ + const char *_next = strchr((p), (sep)); \ + if (!_next) \ + _next = (p); \ + (_next - (p)); \ +}) + +/* +* Ensures 'p' points to something resembling a single character followed by +* ':' followed by at least one non-null byte of data. This allows the parse +* loop to safely advance the pointer to each tokens data (pos + 2) +*/ +#define TOKEN_OK (p) \ + ((p) && (p)[0] != '\0' && (p)[1] == ':' && (p)[2] != '\0') \ + +static struct scan_freq_set *dpp_parse_class_and_channel (const char *token) +{ +const char *pos = token; +char *end; +struct scan_freq_set *freqs =scan_freq_set_new (); + +/* Checking for <operclass>/<channel>,<operclass>/<channel>,... */ +for (; pos; pos =TOKEN_NEXT (pos,',' )) { +uint8_t channel; +uint8_t oper_class =strtol (pos, &end,10 ); + +if (!end || end == pos || (end && *end !='/' )) + goto free_set; + + pos = end +1 ; + channel =strtol (pos, &end,10 ); + +/* Either another pair (,) or end of this token (;) */ +if (!end || end == pos || (*end !=',' && *end !=';' )) + goto free_set; + +scan_freq_set_add (freqs,oci_to_frequency (oper_class, channel)); + } + +if (scan_freq_set_isempty (freqs)) { +free_set: +scan_freq_set_free (freqs); +return NULL ; + } + +return freqs; +} + +static int dpp_parse_mac (const char *str,uint8_t *mac_out) +{ +uint8_t mac[6 ]; +unsigned int i; + +for (i =0 ; i <12 ; i +=2 ) { +if (!l_ascii_isxdigit (str[i])) +return -EINVAL ; + +if (!l_ascii_isxdigit (str[i +1 ])) +return -EINVAL ; + } + +if (sscanf (str,"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx" , + &mac[0 ], &mac[1 ], &mac[2 ], + &mac[3 ], &mac[4 ], &mac[5 ]) !=6 ) +return -EINVAL ; + +if (!util_is_valid_sta_address (mac)) +return -EINVAL ; + +memcpy (mac_out, mac,6 ); + +return 0 ; +} + +static int dpp_parse_version (const char *str,uint8_t *version_out) +{ +char *end; +uint8_t version; +size_t len =TOKEN_LEN (str,';' ); + +if (len !=1 ) +return -EINVAL ; + + version =strtol (str, &end,10 ); + +if (version !=1 && version !=2 ) +return -EINVAL ; + + *version_out = version; + +return 0 ; +} + +static struct l_ecc_point *dpp_parse_key (const char *str) +{ + _auto_(l_free) uint8_t *decoded = NULL; +size_t decoded_len; +size_t len =TOKEN_LEN (str,';' ); + +if (!len) +return NULL ; + + decoded =l_base64_decode (str, len, &decoded_len); +if (!decoded) +return NULL ; + +return dpp_point_from_asn1 (decoded, decoded_len); +} + +/* +* Parse a bootstrapping URI. This parses the tokens defined in the Easy Connect +* spec, and verifies they are the correct syntax. Some values have extra +* verification: +* - The bootstrapping key is base64 decoded and converted to an l_ecc_point +* - The operating class and channels are checked against the OCI table. +* - The version is checked to be either 1 or 2, as defined by the spec. +* - The MAC is verified to be a valid station address. +*/ +struct dpp_uri_info *dpp_parse_uri (const char *uri) +{ +struct dpp_uri_info *info; +const char *pos = uri; +const char *end = uri +strlen (uri) -1 ; +int ret =0 ; + +if (strncmp (pos,"DPP:" ,4 )) +return NULL ; + + info = l_new(struct dpp_uri_info, 1); + + pos +=4 ; + +/* EasyConnect 5.2.1 - Bootstrapping information format */ +for (;TOKEN_OK (pos); pos =TOKEN_NEXT (pos,';' )) { +switch (*pos) { +case 'C' : + info->freqs =dpp_parse_class_and_channel (pos +2 ); +if (!info->freqs) + goto free_info; +break ; +case 'M' : + ret =dpp_parse_mac (pos +2 , info->mac); +if (ret <0 ) + goto free_info; +break ; +case 'V' : + ret =dpp_parse_version (pos +2 , &info->version); +if (ret <0 ) + goto free_info; +break ; +case 'K' : + info->boot_public =dpp_parse_key (pos +2 ); +if (!info->boot_public) + goto free_info; +break ; +case 'H' : +case 'I' : +break ; +default : + goto free_info; + } + } + +/* Extra data found after last token */ +if (pos != end) + goto free_info; + +/* The public bootstrapping key is the only required token */ +if (!info->boot_public) + goto free_info; + +return info; + +free_info: +dpp_free_uri_info (info); +return NULL ; +} + +void dpp_free_uri_info (struct dpp_uri_info *info) +{ +if (info->freqs) +scan_freq_set_free (info->freqs); + +if (info->boot_public) +l_ecc_point_free (info->boot_public); + +if (info->information) +l_free (info->information); + +if (info->host) +l_free (info->host); + +l_free (info); +}
src/dpp-util.h +13 -0
@@ -22,6 +22,16 @@struct l_ecc_point ;struct l_ecc_scalar ;enum ie_rsn_akm_suite ; +struct scan_freq_set ; + +struct dpp_uri_info { +struct scan_freq_set *freqs; +struct l_ecc_point *boot_public; +uint8_t mac[6 ]; +char *information; +uint8_t version; +char *host; +};enum dpp_frame_type {DPP_FRAME_AUTHENTICATION_REQUEST =0 ,
@@ -168,3 +178,6 @@ bool dpp_derive_ke(const uint8_t *i_nonce, const uint8_t *r_nonce,uint8_t *dpp_point_to_asn1 (const struct l_ecc_point *p,size_t *len_out);struct l_ecc_point *dpp_point_from_asn1 (const uint8_t *asn1,size_t len); + +struct dpp_uri_info *dpp_parse_uri (const char *uri); +void dpp_free_uri_info (struct dpp_uri_info *info);
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 3/10 unit: add DPP unit tests for URI parsing
In reply to James Prestwood--- unit/test-dpp.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+)
unit/test-dpp.c +142 -0
@@ -33,6 +33,134 @@#include "src/util.h" #include "ell/useful.h" +struct dpp_test_info { +const char *uri; +bool expect_fail; +uint32_t expected_freqs[10 ]; +struct dpp_uri_info result; +}; + +struct dpp_test_info all_values = { + .uri ="DPP:C:81/1,115/36;I:SN=4774LH2b4044;M:5254005828e5;V:2;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .result = { + .mac = {0x52 ,0x54 ,0x00 ,0x58 ,0x28 ,0xe5 }, + .version =2 , + }, + .expected_freqs = {2412 ,5180 ,0 } +}; + +struct dpp_test_info no_type = { + .uri ="C:81/1;K:shouldnotmatter;;" , + .expect_fail = true +}; + +struct dpp_test_info empty = { + .uri ="DPP:" , + .expect_fail = true +}; + +struct dpp_test_info no_key = { + .uri ="DPP:C:81/1,115/36;I:SN=4774LH2b4044;M:5254005828e5;V:2;;" , + .expect_fail = true +}; + +struct dpp_test_info data_after_terminator = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;C:81/1;;" , + .expect_fail = true +}; + +struct dpp_test_info single_terminator = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;" , + .expect_fail = true +}; + +struct dpp_test_info no_terminator = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=" , + .expect_fail = true +}; + +struct dpp_test_info bad_key = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0;;" , + .expect_fail = true +}; + +struct dpp_test_info unexpected_id = { + .uri ="DPP:Z:somedata;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true +}; + +struct dpp_test_info bad_channels[] = { + { + .uri ="DPP:C:;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/1,;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/1,81/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/1,/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, +}; + +static bool verify_info (const struct dpp_uri_info *parsed, +const struct dpp_test_info *result) +{ +const struct dpp_uri_info *expected = &result->result; +uint32_t i; + +assert (!memcmp (parsed->mac, expected->mac,6 )); +assert (parsed->version == expected->version); +assert (parsed->boot_public !=NULL ); + +for (i =0 ; result->expected_freqs[i]; i++) +assert (scan_freq_set_contains (parsed->freqs, + result->expected_freqs[i])); + +return true; +} + +static void test_uri_parse (const void *data) +{ +const struct dpp_test_info *test_info = data; +struct dpp_uri_info *info; +int ret; + + info =dpp_parse_uri (test_info->uri); +if (test_info->expect_fail) { +assert (info ==NULL ); +return ; + } + +assert (ret ==0 ); + +assert (verify_info (info, test_info)); + +dpp_free_uri_info (info); +} + + +static void test_bad_channels (const void *data) +{ +unsigned int i; + +for (i =0 ; i <L_ARRAY_SIZE (bad_channels); i++) +test_uri_parse (&bad_channels[i]); +} +/* * B.2 Test Vectors for DPP Authentication Using P-256 for * Responder-only Authentication
@@ -148,5 +276,19 @@ int main(int argc, char *argv[])l_test_add ("DPP test key derivation" , test_key_derivation,NULL ); +l_test_add ("DPP URI parse" , test_uri_parse, &all_values); +l_test_add ("DPP URI no type" , test_uri_parse, &no_type); +l_test_add ("DPP URI empty" , test_uri_parse, &empty); +l_test_add ("DPP URI no key" , test_uri_parse, &no_key); +l_test_add ("DPP URI data after terminator" , test_uri_parse, + &data_after_terminator); +l_test_add ("DPP URI single terminator" , test_uri_parse, + &single_terminator); +l_test_add ("DPP URI no terminator" , test_uri_parse, + &no_terminator); +l_test_add ("DPP URI bad key" , test_uri_parse, &bad_key); +l_test_add ("DPP URI bad channels" , test_bad_channels, &bad_channels); +l_test_add ("DPP URI unexpected ID" , test_uri_parse, &unexpected_id); +return l_test_run (); }
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 4/10 frame-xchg: allow multicast frame watches
In reply to James PrestwoodThis adds a new boolean argument to frame_watch_add which when true will set the frame watch to forward multicast frames.
--- src/ap.c | 12 ++++++------ src/dpp.c | 10 +++++----- src/frame-xchg.c | 15 ++++++++++----- src/frame-xchg.h | 8 ++++---- src/netdev.c | 10 +++++----- src/p2p.c | 4 ++-- src/rrm.c | 4 ++-- src/station.c | 2 +- 8 files changed, 35 insertions(+), 30 deletions(-)
src/ap.c +6 -6
@@ -3221,32 +3221,32 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,l_uintset_put (ap->rates,22 );/* 11 Mbps*/ } -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_ASSOCIATION_REQUEST <<4 ),NULL ,0 , ap_assoc_req_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_REASSOCIATION_REQUEST <<4 ),NULL ,0 , ap_reassoc_req_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_PROBE_REQUEST <<4 ),NULL ,0 , ap_probe_req_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_DISASSOCIATION <<4 ),NULL ,0 , ap_disassoc_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_AUTHENTICATION <<4 ),NULL ,0 , ap_auth_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_DEAUTHENTICATION <<4 ),NULL ,0 , ap_deauth_cb, ap,NULL )) goto error;
src/dpp.c +5 -5
@@ -1687,14 +1687,14 @@ static void dpp_create(struct netdev *netdev)l_dbus_object_add_interface (dbus,netdev_get_path (netdev),IWD_DPP_INTERFACE , dpp); -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , dpp_prefix, -sizeof (dpp_prefix), dpp_handle_frame, - dpp,NULL ); -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , + dpp_prefix,sizeof (dpp_prefix), + dpp_handle_frame, dpp,NULL ); +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , dpp_conf_response_prefix,sizeof (dpp_conf_response_prefix), dpp_handle_config_response_frame, dpp,NULL ); -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , dpp_conf_request_prefix,sizeof (dpp_conf_request_prefix), dpp_handle_config_request_frame, dpp,NULL );
src/frame-xchg.c +10 -5
@@ -573,10 +573,10 @@ drop:return true; } -bool frame_watch_add (uint64_t wdev_id,uint32_t group_id,uint16_t frame_type, -const uint8_t *prefix,size_t prefix_len, -frame_watch_cb_t handler,void *user_data, -frame_xchg_destroy_func_t destroy) +bool frame_watch_add (uint64_t wdev_id,uint32_t group_id,bool mcast, +uint16_t frame_type,const uint8_t *prefix, +size_t prefix_len,frame_watch_cb_t handler, +void *user_data,frame_xchg_destroy_func_t destroy) {struct watch_group *group =frame_watch_group_get (wdev_id, group_id);struct frame_watch *watch;
@@ -611,6 +611,11 @@ bool frame_watch_add(uint64_t wdev_id, uint32_t group_id, uint16_t frame_type,l_genl_msg_append_attr (msg,NL80211_ATTR_WDEV ,8 , &wdev_id);l_genl_msg_append_attr (msg,NL80211_ATTR_FRAME_TYPE ,2 , &frame_type); + +if (mcast) +l_genl_msg_append_attr (msg,NL80211_ATTR_RECEIVE_MULTICAST , +0 ,NULL ); +l_genl_msg_append_attr (msg,NL80211_ATTR_FRAME_MATCH , prefix_len, prefix);
@@ -1193,7 +1198,7 @@ uint32_t frame_xchg_startv(uint64_t wdev_id, struct iovec *frame, uint32_t freq, watch = l_new(struct frame_xchg_watch_data, 1); watch->prefix = prefix; watch->cb = va_arg(resp_args, void *); -frame_watch_add (wdev_id, group_id,0x00d0 , +frame_watch_add (wdev_id, group_id, false,0x00d0 , prefix->data, prefix->len, frame_xchg_resp_cb, fx,NULL );
src/frame-xchg.h +4 -4
@@ -36,10 +36,10 @@ struct frame_xchg_prefix {size_t len; }; -bool frame_watch_add (uint64_t wdev_id,uint32_t group,uint16_t frame_type, -const uint8_t *prefix,size_t prefix_len, -frame_watch_cb_t handler,void *user_data, -frame_xchg_destroy_func_t destroy); +bool frame_watch_add (uint64_t wdev_id,uint32_t group,bool mcast, +uint16_t frame_type,const uint8_t *prefix, +size_t prefix_len,frame_watch_cb_t handler, +void *user_data,frame_xchg_destroy_func_t destroy);bool frame_watch_group_remove (uint64_t wdev_id,uint32_t group);bool frame_watch_wdev_remove (uint64_t wdev_id);
src/netdev.c +5 -5
@@ -5777,24 +5777,24 @@ static void netdev_add_station_frame_watches(struct netdev *netdev)uint64_t wdev = netdev->wdev_id;/* Subscribe to Management -> Action -> RM -> Neighbor Report frames */ -frame_watch_add (wdev,0 ,0x00d0 , action_neighbor_report_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_neighbor_report_prefix,sizeof (action_neighbor_report_prefix), netdev_neighbor_report_frame_event, netdev,NULL ); -frame_watch_add (wdev,0 ,0x00d0 , action_sa_query_resp_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_sa_query_resp_prefix,sizeof (action_sa_query_resp_prefix), netdev_sa_query_resp_frame_event, netdev,NULL ); -frame_watch_add (wdev,0 ,0x00d0 , action_sa_query_req_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_sa_query_req_prefix,sizeof (action_sa_query_req_prefix), netdev_sa_query_req_frame_event, netdev,NULL ); -frame_watch_add (wdev,0 ,0x00d0 , action_ft_response_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_ft_response_prefix,sizeof (action_ft_response_prefix), netdev_ft_response_frame_event, netdev,NULL );if (wiphy_supports_qos_set_map (netdev->wiphy)) -frame_watch_add (wdev,0 ,0x00d0 , action_qos_map_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_qos_map_prefix,sizeof (action_qos_map_prefix), netdev_qos_map_frame_event, netdev,NULL ); }
src/p2p.c +2 -2
@@ -4154,9 +4154,9 @@ static void p2p_device_discovery_start(struct p2p_device *dev) dev->listen_channel = channels_social[l_getrandom_uint32 () %L_ARRAY_SIZE (channels_social)]; -frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN ,0x0040 , +frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN , false,0x0040 , (uint8_t *)"" ,0 , p2p_device_probe_cb, dev,NULL ); -frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN ,0x00d0 , +frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN , false,0x00d0 , p2p_frame_go_neg_req.data, p2p_frame_go_neg_req.len, p2p_device_go_negotiation_req_cb, dev,NULL );
src/rrm.c +2 -2
@@ -793,8 +793,8 @@ static void rrm_add_frame_watches(struct rrm_state *rrm)l_debug ("" ); -frame_watch_add (rrm->wdev_id,0 , frame_type, prefix,sizeof (prefix), - rrm_frame_watch_cb, rrm,NULL ); +frame_watch_add (rrm->wdev_id,0 , false, frame_type, prefix, +sizeof (prefix), rrm_frame_watch_cb, rrm,NULL ); }static struct rrm_state *rrm_new_state (struct netdev *netdev)
src/station.c +1 -1
@@ -4460,7 +4460,7 @@ static void add_frame_watches(struct netdev *netdev)/* * register for AP roam transition watch */ -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , action_ap_roam_prefix,sizeof (action_ap_roam_prefix), ap_roam_frame_event,L_UINT_TO_PTR (netdev_get_ifindex (netdev)),NULL );
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 5/10 dpp: add support for initiating as a configurator
In reply to James PrestwoodThe difference between the existing code is that IWD will send the authentication request, making it the initiator.
This handles the use case where IWD is provided a peers URI containing its bootstrapping key rather than IWD always providing its own URI. A new DBus API was added, ConfigureEnrollee().
Using ConfigureEnrollee() IWD will act as a configurator but begin by traversing a channel list (URI provided or default) and waiting for presence announcements. When an announcement is received IWD will send an authentication request to the peer, receive its reply, and send an authentication confirm.
As with being a responder, IWD only supports configuration to the currently connected BSS and will request the enrollee switch to this BSS's frequency to preserve network performance.
--- src/dpp.c | 442 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 439 insertions(+), 3 deletions(-)
src/dpp.c +439 -3
@@ -83,20 +83,33 @@ struct dpp_sm {uint8_t *own_asn1;size_t own_asn1_len; +uint8_t *peer_asn1; +size_t peer_asn1_len;uint8_t own_boot_hash[32 ]; +uint8_t peer_boot_hash[32 ];const struct l_ecc_curve *curve;size_t key_len;size_t nonce_len;struct l_ecc_scalar *boot_private;struct l_ecc_point *boot_public; +struct l_ecc_point *peer_boot_public;enum dpp_state state; +/* +* List of frequencies to jump between. The presence of this list is +* also used to signify that a configurator is an initiator vs responder +*/ uint32_t *freqs;size_t freqs_len;size_t freqs_idx;uint32_t dwell;uint32_t current_freq; +/* +* Frequency the remainder of the auth/config protocol will run on. +* For an initiating configurator this is the frequency of the currently +* connected BSS. +*/ uint32_t new_freq;struct scan_freq_set *presence_list;
@@ -107,7 +120,9 @@ struct dpp_sm {uint8_t i_nonce[32 ];uint8_t e_nonce[32 ]; +struct l_ecc_scalar *m;uint64_t ke[L_ECC_MAX_DIGITS ]; +uint64_t k1[L_ECC_MAX_DIGITS ];uint64_t k2[L_ECC_MAX_DIGITS ];uint64_t auth_tag[L_ECC_MAX_DIGITS ];
@@ -145,6 +160,16 @@ static void dpp_free_auth_data(struct dpp_sm *dpp)l_ecc_point_free (dpp->peer_proto_public); dpp->peer_proto_public =NULL ; } + +if (dpp->peer_boot_public) { +l_ecc_point_free (dpp->peer_boot_public); + dpp->peer_boot_public =NULL ; + } + +if (dpp->m) { +l_ecc_scalar_free (dpp->m); + dpp->m =NULL ; + } }static void dpp_reset (struct dpp_sm *dpp)
@@ -188,6 +213,7 @@ static void dpp_reset(struct dpp_sm *dpp)explicit_bzero (dpp->i_nonce, dpp->nonce_len);explicit_bzero (dpp->e_nonce, dpp->nonce_len);explicit_bzero (dpp->ke, dpp->key_len); +explicit_bzero (dpp->k1, dpp->key_len);explicit_bzero (dpp->k2, dpp->key_len);explicit_bzero (dpp->auth_tag, dpp->key_len);
@@ -1260,6 +1286,49 @@ static void dpp_presence_announce(struct dpp_sm *dpp)dpp_send_frame (dpp, iov,2 , dpp->current_freq); } +static void dpp_send_authenticate_request (struct dpp_sm *dpp) +{ +uint8_t hdr[32 ]; +uint8_t attrs[256 ]; +uint8_t *ptr = attrs; +uint64_t i_proto_key[L_ECC_MAX_DIGITS *2 ]; +uint8_t version =2 ; +struct iovec iov[2 ]; + +l_ecc_point_get_data (dpp->own_proto_public, i_proto_key, +sizeof (i_proto_key)); + + iov[0 ].iov_len =dpp_build_header (netdev_get_address (dpp->netdev), + dpp->auth_addr, +DPP_FRAME_AUTHENTICATION_REQUEST , hdr); + iov[0 ].iov_base = hdr; + + ptr +=dpp_append_attr (ptr,DPP_ATTR_RESPONDER_BOOT_KEY_HASH , + dpp->peer_boot_hash,32 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_INITIATOR_BOOT_KEY_HASH , + dpp->own_boot_hash,32 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_INITIATOR_PROTOCOL_KEY , + i_proto_key, dpp->key_len *2 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_PROTOCOL_VERSION , &version,1 ); + +if (dpp->current_freq != dpp->new_freq) { +uint8_t pair[2 ] = {81 , +band_freq_to_channel (dpp->new_freq,NULL ) }; + + ptr +=dpp_append_attr (ptr,DPP_ATTR_CHANNEL , pair,2 ); + } + + ptr +=dpp_append_wrapped_data (hdr +26 ,6 , attrs, ptr - attrs, + ptr,sizeof (attrs), dpp->k1, dpp->key_len,2 , +DPP_ATTR_INITIATOR_NONCE , dpp->nonce_len, dpp->i_nonce, +DPP_ATTR_INITIATOR_CAPABILITIES ,1 , &dpp->role); + + iov[1 ].iov_base = attrs; + iov[1 ].iov_len = ptr - attrs; + +dpp_send_frame (dpp, iov,2 , dpp->current_freq); +} +static void dpp_roc_started (void *user_data) {struct dpp_sm *dpp = user_data;
@@ -1574,6 +1643,300 @@ auth_request_failed:dpp_free_auth_data (dpp); } +static void dpp_send_authenticate_confirm (struct dpp_sm *dpp) +{ +uint8_t hdr[32 ]; +struct iovec iov[2 ]; +uint8_t attrs[256 ]; +uint8_t *ptr = attrs; +uint8_t zero =0 ; + + iov[0 ].iov_len =dpp_build_header (netdev_get_address (dpp->netdev), + dpp->auth_addr, +DPP_FRAME_AUTHENTICATION_CONFIRM , hdr); + iov[0 ].iov_base = hdr; + + ptr +=dpp_append_attr (ptr,DPP_ATTR_STATUS , &zero,1 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_RESPONDER_BOOT_KEY_HASH , + dpp->peer_boot_hash,32 ); + + ptr +=dpp_append_wrapped_data (hdr +26 ,6 , attrs, ptr - attrs, ptr, +sizeof (attrs), dpp->ke, dpp->key_len,1 , +DPP_ATTR_INITIATOR_AUTH_TAG , dpp->key_len, + dpp->auth_tag); + + iov[1 ].iov_base = attrs; + iov[1 ].iov_len = ptr - attrs; + +dpp_send_frame (dpp, iov,2 , dpp->current_freq); +} + +static void authenticate_response (struct dpp_sm *dpp,const uint8_t *from, +const uint8_t *body,size_t body_len) +{ +struct dpp_attr_iter iter; +enum dpp_attribute_type type; +size_t len; +const uint8_t *data; +int status =-1 ; +const void *r_boot_hash =NULL ; +const void *r_proto =NULL ; +size_t r_proto_len =0 ; +const void *wrapped =NULL ; +size_t wrapped_len; +uint8_t *unwrapped; +const void *r_nonce =NULL ; +const void *i_nonce =NULL ; +const void *r_auth =NULL ; +struct l_ecc_point *r_proto_key; +struct l_ecc_scalar *n; +const void *ad0 = body +2 ; +const void *ad1 = body +8 ; +uint64_t r_auth_derived[L_ECC_MAX_DIGITS ]; + +l_debug ("Authenticate response" ); + +if (dpp->state !=DPP_STATE_AUTHENTICATING ) +return ; + +if (dpp->role !=DPP_CAPABILITY_CONFIGURATOR ) +return ; + +if (!dpp->freqs) +return ; + +if (memcmp (from, dpp->auth_addr,6 )) +return ; + +dpp_attr_iter_init (&iter, body +8 , body_len -8 ); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_STATUS : +if (len !=1 ) +return ; + + status =l_get_u8 (data); +break ; +case DPP_ATTR_RESPONDER_BOOT_KEY_HASH : + r_boot_hash = data; +break ; +case DPP_ATTR_RESPONDER_PROTOCOL_KEY : + r_proto = data; + r_proto_len = len; +break ; +case DPP_ATTR_PROTOCOL_VERSION : +if (len !=1 ||l_get_u8 (data) !=2 ) +return ; +break ; +case DPP_ATTR_WRAPPED_DATA : + wrapped = data; + wrapped_len = len; +break ; +default : +break ; + } + } + +if (status !=DPP_STATUS_OK || !r_boot_hash || !r_proto ) { +l_debug ("Auth response bad status or missing attributes" ); +return ; + } + + r_proto_key =l_ecc_point_from_data (dpp->curve,L_ECC_POINT_TYPE_FULL , + r_proto, r_proto_len); +if (!r_proto_key) { +l_debug ("Peers protocol key was invalid" ); +return ; + } + + n =dpp_derive_k2 (r_proto_key, dpp->proto_private, dpp->k2); + + unwrapped =dpp_unwrap_attr (ad0,6 , ad1, wrapped -4 - ad1, dpp->k2, + dpp->key_len, wrapped, wrapped_len, + &wrapped_len); +if (!unwrapped) { +l_debug ("Failed to unwrap primary data" ); +return ; + } + + wrapped =NULL ; + +dpp_attr_iter_init (&iter, unwrapped, wrapped_len); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_RESPONDER_NONCE : +if (len != dpp->nonce_len) +return ; + + r_nonce = data; +break ; +case DPP_ATTR_INITIATOR_NONCE : +if (len != dpp->nonce_len) +return ; + + i_nonce = data; +break ; +case DPP_ATTR_RESPONDER_CAPABILITIES : +break ; +case DPP_ATTR_WRAPPED_DATA : + wrapped = data; + wrapped_len = len; +break ; +default : +break ; + } + } + +if (!r_nonce || !i_nonce || !wrapped) { +l_debug ("Wrapped data missing attributes" ); +return ; + } + +if (!dpp_derive_ke (i_nonce, r_nonce, dpp->m, n, dpp->ke)) { +l_debug ("Failed to derive ke" ); +return ; + } + + unwrapped =dpp_unwrap_attr (NULL ,0 ,NULL ,0 , dpp->ke, dpp->key_len, + wrapped, wrapped_len, &wrapped_len); +if (!unwrapped) { +l_debug ("Failed to unwrap secondary data" ); +return ; + } + +dpp_attr_iter_init (&iter, unwrapped, wrapped_len); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_RESPONDER_AUTH_TAG : +if (len != dpp->key_len) +return ; + + r_auth = data; +break ; +default : +break ; + } + } + +if (!r_auth) { +l_debug ("R-Auth was not in secondary wrapped data" ); +return ; + } + +if (!dpp_derive_r_auth (i_nonce, r_nonce, dpp->nonce_len, + dpp->own_proto_public, r_proto_key, + dpp->peer_boot_public, r_auth_derived)) { +l_debug ("Failed to derive r_auth" ); +return ; + } + +if (memcmp (r_auth, r_auth_derived, dpp->key_len)) { +l_debug ("R-Auth did not verify" ); +return ; + } + +if (!dpp_derive_i_auth (r_nonce, i_nonce, dpp->nonce_len, + r_proto_key, dpp->own_proto_public, + dpp->peer_boot_public, dpp->auth_tag)) { +l_debug ("Could not derive I-Auth" ); +return ; + } + + dpp->current_freq = dpp->new_freq; + +dpp_send_authenticate_confirm (dpp); +} + +static void dpp_handle_presence_announcement (struct dpp_sm *dpp, +const uint8_t *from, +const uint8_t *body, +size_t body_len) +{ +struct dpp_attr_iter iter; +enum dpp_attribute_type type; +size_t len; +const uint8_t *data; +const void *r_boot =NULL ; +size_t r_boot_len =0 ; +uint8_t hash[32 ]; + +l_debug ("Presence announcement " MAC ,MAC_STR (from)); + +/* Must be a configurator, in an initiator role, in PRESENCE state */ +if (dpp->state !=DPP_STATE_PRESENCE ) +return ; + +if (dpp->role !=DPP_CAPABILITY_CONFIGURATOR ) +return ; + +if (!dpp->freqs) +return ; + +/* +* The URI may not have contained a MAC address, if this announcement +* verifies set auth_addr then. +*/ +if (!l_memeqzero (dpp->auth_addr,6 ) && +memcmp (from, dpp->auth_addr,6 )) { +l_debug ("Unexpected source " MAC " expected " MAC ,MAC_STR (from), +MAC_STR (dpp->auth_addr)); +return ; + } + +dpp_attr_iter_init (&iter, body +8 , body_len -8 ); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_RESPONDER_BOOT_KEY_HASH : + r_boot = data; + r_boot_len = len; +break ; +default : +break ; + } + } + +if (!r_boot || r_boot_len !=32 ) { +l_debug ("No responder boot hash" ); +return ; + } + +/* Hash what we have for the peer and check its our enrollee */ +dpp_hash (L_CHECKSUM_SHA256 , hash,2 ,"chirp" ,strlen ("chirp" ), + dpp->peer_asn1, dpp->peer_asn1_len); + +if (memcmp (hash, r_boot,sizeof (hash))) { +l_debug ("Peers boot hash did not match" ); +return ; + } + +/* +* This is the peer we expected, save away the address and derive the +* initial keys. +*/ +memcpy (dpp->auth_addr, from,6 ); + +l_ecdh_generate_key_pair (dpp->curve, &dpp->proto_private, + &dpp->own_proto_public); +l_getrandom (dpp->i_nonce, dpp->nonce_len); + + dpp->m =dpp_derive_k1 (dpp->peer_boot_public, dpp->proto_private, + dpp->k1); + + dpp->state =DPP_STATE_AUTHENTICATING ; + +dpp_send_authenticate_request (dpp); + +/* +* Should we wait for an ACK then go offchannel? +*/ +if (dpp->current_freq != dpp->new_freq) +dpp_start_offchannel (dpp, dpp->new_freq); +} +static void dpp_handle_frame (const struct mmpdu_header *frame,const void *body,size_t body_len,int rssi,void *user_data)
@@ -1595,6 +1958,9 @@ static void dpp_handle_frame(const struct mmpdu_header *frame,case DPP_FRAME_AUTHENTICATION_REQUEST :authenticate_request (dpp, frame->address_2, body, body_len);break ; +case DPP_FRAME_AUTHENTICATION_RESPONSE : +authenticate_response (dpp, frame->address_2, body, body_len); +break ;case DPP_FRAME_AUTHENTICATION_CONFIRM :authenticate_confirm (dpp, frame->address_2, body, body_len);break ;
@@ -1602,6 +1968,10 @@ static void dpp_handle_frame(const struct mmpdu_header *frame,dpp_handle_config_result_frame (dpp, frame->address_2, body, body_len);break ; +case DPP_FRAME_PRESENCE_ANNOUNCEMENT : +dpp_handle_presence_announcement (dpp, frame->address_2, + body, body_len); +break ;default :l_debug ("Unhandled DPP frame %u" , *ptr);break ;
@@ -1829,9 +2199,48 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,return NULL ; } -static struct l_dbus_message *dpp_dbus_start_configurator (struct l_dbus *dbus, +/* +* Set up the configurator for an initiator role. The configurator +* will go offchannel to frequencies advertised by the enrollees URI or, +* if no channels are provided, use a default channel list. +*/ +static bool dpp_configurator_start_presence (struct dpp_sm *dpp,const char *uri) +{ + _auto_(l_free) uint32_t *freqs = NULL; +size_t freqs_len =0 ; + L_AUTO_FREE_VAR(struct dpp_uri_info *, info) = NULL; + + info =dpp_parse_uri (uri); +if (!info) +return false; + +if (!l_memeqzero (info->mac,6 )) +memcpy (dpp->auth_addr, info->mac,6 ); + + dpp->peer_boot_public =l_ecc_point_clone (info->boot_public); + dpp->peer_asn1 =dpp_point_to_asn1 (info->boot_public, + &dpp->peer_asn1_len); +if (!dpp->peer_asn1) { +l_debug ("Peer boot key did not convert to asn1" ); +return false; + } + +dpp_hash (L_CHECKSUM_SHA256 , dpp->peer_boot_hash,1 , dpp->peer_asn1, + dpp->peer_asn1_len); + +if (info->freqs) + freqs =scan_freq_set_to_fixed_array (info->freqs, &freqs_len); + +dpp_start_presence (dpp, freqs, freqs_len); + +return true; +} + +static struct l_dbus_message *dpp_start_configurator_common ( +struct l_dbus *dbus,struct l_dbus_message *message, -void *user_data) +void *user_data, +bool responder) {struct dpp_sm *dpp = user_data;struct l_dbus_message *reply;
@@ -1840,6 +2249,7 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,struct network *network;struct l_settings *settings;struct handshake_state *hs =netdev_get_handshake (dpp->netdev); +const char *uri;/* * For now limit the configurator to only configuring enrollees to the
@@ -1863,13 +2273,23 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,if (dpp->state !=DPP_STATE_NOTHING )return dbus_error_busy (message); +if (!responder) { +if (!l_dbus_message_get_arguments (message,"s" , &uri)) +return dbus_error_invalid_args (message); + +if (!dpp_configurator_start_presence (dpp, uri)) +return dbus_error_invalid_args (message); + + dpp->new_freq = bss->frequency; + }else + dpp->current_freq = bss->frequency; + dpp->uri =dpp_generate_uri (dpp->own_asn1, dpp->own_asn1_len,2 ,netdev_get_address (dpp->netdev), &bss->frequency,1 ,NULL ,NULL ); dpp->state =DPP_STATE_PRESENCE ; dpp->role =DPP_CAPABILITY_CONFIGURATOR ; - dpp->current_freq = bss->frequency; dpp->config =dpp_configuration_new (settings,network_get_ssid (network), hs->akm_suite);
@@ -1885,6 +2305,20 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,return reply; } +static struct l_dbus_message *dpp_dbus_start_configurator (struct l_dbus *dbus, +struct l_dbus_message *message, +void *user_data) +{ +return dpp_start_configurator_common (dbus, message, user_data, true); +} + +static struct l_dbus_message *dpp_dbus_configure_enrollee (struct l_dbus *dbus, +struct l_dbus_message *message, +void *user_data) +{ +return dpp_start_configurator_common (dbus, message, user_data, false); +} +static struct l_dbus_message *dpp_dbus_stop (struct l_dbus *dbus,struct l_dbus_message *message,void *user_data)
@@ -1902,6 +2336,8 @@ static void dpp_setup_interface(struct l_dbus_interface *interface) dpp_dbus_start_enrollee, "s", "", "uri");l_dbus_interface_method (interface,"StartConfigurator" ,0 , dpp_dbus_start_configurator,"s" ,"" ,"uri" ); +l_dbus_interface_method (interface,"ConfigureEnrollee" ,0 , + dpp_dbus_configure_enrollee,"" ,"s" ,"uri" );l_dbus_interface_method (interface,"Stop" ,0 , dpp_dbus_stop,"" ,"" ); }
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 6/10 auto-t: iwd.py: allow passing uri to start_configurator
In reply to James PrestwoodIf a URI is passed this will envoke ConfigureEnrollee()
--- autotests/util/iwd.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
autotests/util/iwd.py +7 -4
@@ -280,8 +280,11 @@ class DeviceProvisioning(IWDDBusAbstract): def start_enrollee(self): return self._iface.StartEnrollee() - def start_configurator(self): - return self._iface.StartConfigurator() + def start_configurator(self, uri=None): + if uri: + return self._iface.ConfigureEnrollee(uri) + else: + return self._iface.StartConfigurator() def stop(self): self._iface.Stop()
@@ -667,8 +670,8 @@ class Device(IWDDBusAbstract): def dpp_start_enrollee(self): return self._device_provisioning.start_enrollee() - def dpp_start_configurator(self): - return self._device_provisioning.start_configurator() + def dpp_start_configurator(self, uri=None): + return self._device_provisioning.start_configurator(uri) def dpp_stop(self): return self._device_provisioning.stop()
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 7/10 auto-t: wpas.py: allow arbitrary events to be handled
In reply to James PrestwoodIf an event is in response to some command which is returning an unexpected value (unexpected with respect to wpas.py) handle_eow would raise an exception.
Specifically with DPP this was being hit when the URI was being returned.
--- autotests/util/wpas.py | 2 -- 1 file changed, 2 deletions(-)
autotests/util/wpas.py +0 -2
@@ -88,8 +88,6 @@ class Wpas: def handle_eow(): nonlocal key, value, count, event if count == 0: - if key is not None or not value: - raise Exception('Bad event name') key = 'event' elif key is None: if not value:
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 8/10 auto-t: wpas.py: handle enrollee as responder
In reply to James PrestwoodThis adds support for wpa_supplicant to generate its own URI and start presence announcements (DPP_CHIRP).
--- autotests/util/wpas.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
autotests/util/wpas.py +14 -3
@@ -239,10 +239,17 @@ class Wpas: def set(self, key, value, **kwargs): self._ctrl_request('SET ' + key + ' ' + value, **kwargs) - def dpp_enrollee_start(self, uri=None): + def dpp_enrollee_start(self, uri=None, oper_and_channel=None): + if not oper_and_channel: + oper_and_channel = '81/1' + self._rx_data = [] - self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode') - self.wait_for_result() + self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode chan=%s' % oper_and_channel) + self._dpp_qr_id = self.wait_for_result() + self._ctrl_request('DPP_BOOTSTRAP_GET_URI %s' % self._dpp_qr_id) + self._dpp_uri = self.wait_for_result() + + print("DPP Enrollee QR: %s" % self._dpp_uri) if uri: self._rx_data = []
@@ -250,6 +257,10 @@ class Wpas: self._dpp_qr_id = self.wait_for_result() self._rx_data = [] self._ctrl_request('DPP_AUTH_INIT peer=%s role=enrollee' % self._dpp_qr_id) + else: + self._ctrl_request('DPP_CHIRP own=%s iter=100' % self._dpp_qr_id) + + return self._dpp_uri def dpp_configurator_create(self, uri): self._rx_data = []
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 9/10 auto-t: add test for IWD as configurator + initiator
In reply to James Prestwood--- autotests/testDPP/connection_test.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
autotests/testDPP/connection_test.py +16 -0
@@ -82,6 +82,22 @@ class Test(unittest.TestCase): self.hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00') + def test_iwd_as_configurator_initiator(self): + self.hapd.reload() + self.hapd.wait_for_event('AP-ENABLED') + + IWD.copy_to_storage('ssidCCMP.psk') + self.device.autoconnect = True + + condition = 'obj.state == DeviceState.connected' + self.wd.wait_for_object_condition(self.device, condition) + + uri = self.wpas.dpp_enrollee_start(oper_and_channel='81/2') + + self.device.dpp_start_configurator(uri) + + self.hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00') + def setUp(self): self.wd = IWD(True) self.device = self.wd.list_devices(1)[0]
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 10/10 doc: document DPP ConfigureEnrollee()
In reply to James Prestwood--- doc/device-provisioning-api.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
doc/device-provisioning-api.txt +16 -0
@@ -37,3 +37,19 @@ Methods string StartEnrollee() net.connman.iwd.NotConfigured net.connman.iwd.NotSupported net.connman.iwd.Busy + + string ConfigureEnrollee(string uri) + + Start a DPP configurator with an enrollees URI. + Ultimately the configuration itself remains the same as + StartConfigurator(). This API is to handle the use case + where the enrollee has shared its URI to IWD. + + The URI for IWD is also returned which could be used + in the same way as it is with StartConfigurator(). + + Possible errors: net.connman.iwd.NotAvailable + net.connman.iwd.NotConnected + net.connman.iwd.NotConfigured + net.connman.iwd.NotSupported + net.connman.iwd.Busy
Signature · 1 line
2.31.1
Denis Kenzior
Hi James,
Quoted 8 lines · James Prestwood
Given an ASN1 blob of the right form, parse and create an
l_ecc_pointobject. The form used is specific to DPP hence why this isn't general purpose and put into dpp-util.--- src/dpp-util.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/dpp-util.h | 1 + 2 files changed, 70 insertions(+)
<snip>
src/dpp-util.c uint8_t *dpp_point_to_asn1(const struct l_ecc_point *p, size_t *len_out) · line 862
Quoted 3 lines
src/dpp-util.c +3
-0+/* BITSTRING */ + key_data =asn1_der_find_elem (outer_seq, outer_len,1 , &tag, &elen); +if (!key_data || tag !=ASN1_ID_BIT_STRING || elen >2 )
< 2?
also you have a line > 80 chars in this patch.
Regards,
-Denis